00001 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00002 * 00003 * Redistribution and use in source and binary forms, with or without 00004 * modification, are permitted provided that the following conditions are met: 00005 * 00006 * 1. Redistributions of source code must retain the above copyright notice, this 00007 * list of conditions and the following disclaimer. 00008 * 00009 * 2. Redistributions in binary form must reproduce the above copyright notice, 00010 * this list of conditions and the following disclaimer in the documentation 00011 * and/or other materials provided with the distribution. 00012 * 00013 * 3. The name of Atmel may not be used to endorse or promote products derived 00014 * from this software without specific prior written permission. 00015 * 00016 * 4. This software may only be redistributed and used in connection with an Atmel 00017 * AVR product. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00020 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00021 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00022 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00029 * 00030 */ 00031 #include <stdlib.h> 00032 #include "error_management.h" 00033 #include "format_data.h" 00034 00035 void format_data(char *_path, char *_pattern, int n_arg) 00036 { 00037 char *_buffer; 00038 int n, n_data; 00039 FILE *_file; 00040 float *_data; 00041 00042 ASSERT(_path); 00043 00044 // Open the file 00045 _file = fopen(_path, "rb"); 00046 ASSERT(_file); 00047 // Get the length of the file and store it into n 00048 fseek(_file, 0, SEEK_END); 00049 n = ftell(_file); 00050 // allocate a buffer of the size of the file 00051 _buffer = (char *) malloc(n + 1); 00052 ASSERT(_buffer); 00053 _buffer[n] = '\0'; 00054 // Go to the beginning of the file 00055 fseek(_file, 0, SEEK_SET); 00056 // Read it 00057 fread(_buffer, 1, n, _file); 00058 fclose(_file); 00059 00060 // Extract data from a buffer 00061 n_data = format_data_get_data(_buffer, _pattern, n_arg); 00062 00063 free(_buffer); 00064 } 00065 00066 // Main function 00067 int main(int argc, char *argv[]) 00068 { 00069 00070 // If there arguments passed to this program 00071 if (argc == 4) 00072 format_data(argv[1], argv[2], atoi(argv[3])); 00073 // Else print the usage 00074 else 00075 printf("Usage: DataExtract input_buffer_file_path pattern n_arg\n\r"); 00076 00077 return 0; 00078 }