diff --git a/Code-C/Makefile b/Code-C/Makefile index 33a1055..8a6b768 100644 --- a/Code-C/Makefile +++ b/Code-C/Makefile @@ -1,10 +1,12 @@ CC = gcc all: - rm powerData.csv +# rm powerData.csv $(CC) b2hd.c -o b2hd - $(CC) fileGestion.c getArray.c power.c -lm -o power -#getArray.c fileGestion.c power.c main.c -o main + $(CC) fileGestion.c getArray.c -o getArray +# $(CC) fileGestion.c getArray.c power.c -lm -o power +# getArray.c fileGestion.c power.c main.c -o main - ./b2hd < ../02400001.TXT > rawData.csv - ./power \ No newline at end of file + ./b2hd < ../02400031.TXT > rawData.csv + ./getArray +#./power \ No newline at end of file diff --git a/Code-C/b2hd.c b/Code-C/b2hd.c index f0a9048..81408cb 100644 --- a/Code-C/b2hd.c +++ b/Code-C/b2hd.c @@ -9,7 +9,7 @@ void b2hd() int32_t values[8]; uint32_t valbin[8]; quartet value; - + while (fread(&buff, 26, 1, stdin)) { fprintf(stdout , "%ld,", millis()); for (int i = 1; i < 9; i++){ @@ -30,7 +30,7 @@ void b2hd() value.octet4 = 0; /*memcpy(&values[i], &value, sizeof(quartet));*/ valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256; - memcpy(&values[i], &valbin[i], sizeof(int32_t)); + memcpy(&values[i], &valbin[i], sizeof(uint32_t)); if(i<8){ fprintf(stdout, "%d,", values[i]/256); } diff --git a/Code-C/divideChar.c b/Code-C/divideChar.c new file mode 100644 index 0000000..5de6b58 --- /dev/null +++ b/Code-C/divideChar.c @@ -0,0 +1,24 @@ +void divideChar(char *res[9] , char *lign , char delimiter){ + int i = 0; + int j = 0; + int cptWord = 0; + int lignSize = sizeof(lign); + char *token; + token = (char *) malloc(20 * sizeof(char)); + + char space = ' '; + + while(i < lignSize){ + if(lign[i]==delimiter){ + token[j+1] = '\0'; + res[cptWord] = token; + cptWord++; + } + else if(lign[i] == space) continue; + else{ + token[j] = lign[i]; + j++; + } + i++; + } +} \ No newline at end of file diff --git a/Code-C/getArray b/Code-C/getArray new file mode 100755 index 0000000..50f8901 Binary files /dev/null and b/Code-C/getArray differ diff --git a/Code-C/getArray.c b/Code-C/getArray.c index 4e45494..054564f 100644 --- a/Code-C/getArray.c +++ b/Code-C/getArray.c @@ -1,29 +1,37 @@ #include "getArray.h" #include "fileGestion.h" +//#include -int **get(int N, int M) /* Allocate the array */ +long **get(int N, int M) /* Allocate the array */ { /* Check if allocation succeeded. (check for NULL pointer) */ int i; - int **array; - array = malloc(N*sizeof(int *)); + long **array; + array = (long **) malloc(N*sizeof(long *)); for(i = 0 ; i < N ; i++) - array[i] = malloc( M*sizeof(int) ); + array[i] = (long *) malloc( M*sizeof(long) ); return array; } -void fillRawData(int** p, int N, int M) { +void fillRawData(long** p, int N, int M) { int i, j; - char buffer[200]; - char *token; + + char *buffer; + size_t bufsize = 200; + buffer = (char *)malloc(bufsize * sizeof(char)); + char* token; + FILE *f = fopen("rawData.csv","r"); for(i = 0 ; i < N ; i++){ - - if (!fgets(buffer, sizeof buffer, f)) break; // condition d'arret de la boucle si fichier fini - //printf(buffer); - token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv - p[i][0] = atoi(token); - + if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini + printf("%s",buffer); + j = 0; + while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv + //printf("%s ," , token); + p[i][j] = atoi(token); + j++; + } + /* for(j = 1 ; j < M ; j++){ token = strtok(NULL, ","); // séparation valeur par virgule : csv @@ -31,28 +39,33 @@ void fillRawData(int** p, int N, int M) { p[i][j] = atoi(token); //transtypage char to int //printf(token); } + */ } } -void printArray(int** p, int N, int M) { +void printArrayData(long** p, int N, int M) { int i, j; - for(i = 0 ; i < N ; i++) - printf("%d , %d , %d , %d , %d , %d , %d , %d\n",p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5],p[i][6],p[i][7]); + for(i = 0 ; i < N ; i++){ + printf("line n°%d : %d , %d , %d , %d , %d , %d , %d , %d \n" ,i,p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5],p[i][6],p[i][7]); + } } -void freeArray(int** p, int N) { +void freeArray(long **p, int N) { int i; for(i = 0 ; i < N ; i++) free(p[i]); free(p); } -int **getRawDataArray(int N , int M){ - int **p; +long **getRawDataArray(int N , int M){ + long **p; p = get(N, M); fillRawData(p ,N, M); - //printArray(p, nRow, nCol); - clearRawData(N); - //freeArray(p ,nRow); return p; +} + +void main(int argc , char argv[]){ + long **p; + p = getRawDataArray(10,9); + printArrayData(p,10,9); } \ No newline at end of file diff --git a/Code-C/getArray.h b/Code-C/getArray.h index 04ddb07..36a11ef 100644 --- a/Code-C/getArray.h +++ b/Code-C/getArray.h @@ -2,6 +2,8 @@ #include #include #include +#include -int **getRawDataArray(); -void printArray(int** p, int N, int M); \ No newline at end of file +long **getRawDataArray(); +void printArray(long** p, int N, int M); +void freeArray(long **p, int N); \ No newline at end of file diff --git a/Code-C/power.c b/Code-C/power.c index 7e62f21..24750b8 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -3,7 +3,7 @@ #include "fileGestion.h" #include "initialParameters.h" -void power(int **p, double a[]){ +void power(long **p, double a[]){ double periode = 1.0/freqEch; double temps = 1/(nRow * periode); @@ -25,9 +25,11 @@ void power(int **p, double a[]){ } } int main(int argc , char** argv){ - int **p = getRawDataArray(nRow, nCol); - printArray(p,nRow,nCol); + printf("Get raw data mat"); + int32_t **p = getRawDataArray(nRow, nCol); + //printArray(p,nRow,nCol); double pw[8]; power(p,pw); writePowerData(pw,8); + freeArray(p,nRow); } \ No newline at end of file