From bdcd6ccb6133a0f3284a1755657c9a4fdae6b6e9 Mon Sep 17 00:00:00 2001 From: "quentin.perret" Date: Fri, 3 Jun 2022 17:02:49 +0200 Subject: [PATCH] go back to morning day 5 --- Code-C/Makefile | 12 ++++++---- Code-C/b2hd.c | 4 ++-- Code-C/divideChar.c | 24 +++++++++++++++++++ Code-C/getArray | Bin 0 -> 17440 bytes Code-C/getArray.c | 57 +++++++++++++++++++++++++++----------------- Code-C/getArray.h | 6 +++-- Code-C/power.c | 8 ++++--- 7 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 Code-C/divideChar.c create mode 100755 Code-C/getArray 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 0000000000000000000000000000000000000000..50f89017547d6c3c57f56ffec7ed8f8a6dbecf9d GIT binary patch literal 17440 zcmeHPdvF`ad0!BE(6$6p@*|9`MrXxpu-tT8>b-5?NLPN#L#j@x?DPLk%)QQA%>O7e=?aVmV^8D`+bky{dV{6_U@LCMEZJ~d_KX+FFq-sZw+fi)F?MlDgSxukuw43b+CcAlUH?QrO zmZ(BVOgWwu6Z)Ode!aAtjF6a;E~Oo>XJeF~G>E&BW)&=$vfVwfqk6vA#9`m5%c~cc zHeG+Fy18O)BEDzi9cvS@_C!3H8*3liw6T5T9l=a0xL&sVI#h(l)b_gu#3PUV@r!4A zPmV8I`lA_)`j+!D%?x@Un{vxQ|1jzz7Zcru!ZAGAd#o6gvyKrt2vtxPtW&RQeUIJ~EATM$U&aiiGY z*W0ztS|3~=+#sypUHw+fPTPCqnXH}O)xRx~O4_@kdlKY+??@`C9a&1XrXrfrBu6M6 z)t^G#oNBxeBlsa?dA{Xtj9*2%Jb(E-#OIBY9^iBOJj3`i8XpfSzl<|~cB{f^uFyQ< zRC3|&^F!H%qe7K5=fb(pB%F8QJO>GH3(-*s8s9Y5I2j?8BfN=0&@~~&5YFc=LOMcp zRDR@jL9t>}NM%T$ew;!fl_QK}L5LZmqtd-vW#w^4NHL^;jmpa7$3u!Ce2L1+Ngle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XKWW0_7YcHD1T?{&%lF^GxaE?-rLmuZ!o}$=l`ernt*I+rJ6{brH>BO1!?} z|1VI|_2+J6JMPEN!iH4Xp4ZuD*OE8vuT`XSWP7G>K;pI+A+6e>=$K}iupQI4AaL9B zdSgu6b3MKG%>M)#^2PP%``k}!doG9dbvT$6myjb&t5 -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