#include #include #include #include /* DEFINE*/ #define FMTFLOAT "%5.15f" #define INMEMORY_SAMPLE /* in-memory buffer for traces */ double sample[SPL_SIZE][NBMAX_SAMPLE]; static double Time = 0.0; static unsigned int maxSimSample=NBMAX_SAMPLE; /*------------------------------------------------- getValueFromFile ----- | Function getValueFromFile | | Purpose: Read a formatted matrix (size X sizeCol) where the first column contain |timestamps, the others data values needed by inputs. The file filename is open if exist and |then values are loaded in tab, the number of line is written in the file. Then the function |behaves link a zero holder, i.e it compare the next timestamp to current time and if match |then load the new values (the line) in outs, otherwise keeps last values. Since the last line |is reached, the conresponding values will be returned in out forever. If the file could not |be open the function will always send the init values. | | Parameters: | -char* filename: IN name of the data file | -double tab[2][NBMAX_SAMPLE]: OUT storing tab for matrix, notice that first dimension should | be the same as sizeCol | -double init: IN init value of out | -int* last_sample: OUT last sample index | -double* opened: OUT file store state indicator, 0:NOT_OPEN_YET, 1:OPEN_SUCESS, 2:OPEN_FAIL | -int * size OUT: nb of matrix lines | -FILE** fichier: OUT file descriptor obtained after opening | - int sizeCol: IN nb of matrix column | - double out[]: OUT current values of line (last_sample) without timestamp | *-------------------------------------------------------------------*/ void getValueFromFile(char* fileName, double tab[2][NBMAX_SAMPLE], double init, int* last_sample, double* opened, int * size, FILE** fichier, int sizeCol, double out[]){ if(fileName==NULL || tab==NULL || last_sample==NULL || opened==NULL || size==NULL || fichier==NULL){ memcpy(&(out[0]),&init,sizeof(double)*(sizeCol-1)); return; } if(*opened==0){ *fichier=fopen(fileName,"r"); if (*fichier != NULL) { fscanf(*fichier,"%d\n",size); for(int i=0; i<*size && i=tab[0][*last_sample+1]) { *last_sample=*last_sample+1; } } for(int i=1; iNBMAX_SAMPLE)? NBMAX_SAMPLE : out[0]; fclose(*fichier); } else { printf("%s:No such file\n",fileName); } } /*------------------------------------------------- print_inmemory_sample ----- | Function print_inmemory_sample() | | Purpose: write the array sample[] in the file LOG_FILE Matlab formatted | *-------------------------------------------------------------------*/ void print_inmemory_sample() { FILE* fichier = NULL; fichier = fopen(LOG_FILE , "w+"); if (fichier != NULL) { fprintf(fichier,"Data=[\n"); for (int i=0;i