diff --git a/Code-C/getArray.c b/Code-C/getArray.c index eeaac8e..7284378 100644 --- a/Code-C/getArray.c +++ b/Code-C/getArray.c @@ -3,7 +3,7 @@ #include "initialParameters.h" //#include -long **get(int N, int M) /* Allocate the array */ +long **getlongArray(int N, int M) /* Allocate the array */ { /* Check if allocation succeeded. (check for NULL pointer) */ int i; @@ -14,6 +14,17 @@ long **get(int N, int M) /* Allocate the array */ return array; } +double **getDoubleArray(int N, int M) /* Allocate the array */ +{ + /* Check if allocation succeeded. (check for NULL pointer) */ + int i; + double **array; + array = (double **) malloc(N*sizeof(double *)); + for(i = 0 ; i < N ; i++) + array[i] = (double *) malloc( M*sizeof(double)); + return array; +} + void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) { int i, j; char *buffer; @@ -86,7 +97,7 @@ void freeArray(long **p, int N) { */ long **getRawDataArray(char* rawDataFileName){ long **p; - p = get(nRow, nCol); + p = getlongArray(nRow, nCol); fillArrayWithRawData(rawDataFileName,p ,nRow, nCol); //if(checkArrayFullyFill(p,nRow)){ //clearRawData(N); diff --git a/Code-C/getArray.h b/Code-C/getArray.h index 02810a9..a53bd0c 100644 --- a/Code-C/getArray.h +++ b/Code-C/getArray.h @@ -8,4 +8,5 @@ long **getRawDataArray(char *rawDataFileName); void printArrayData(long** p, int N, int M); void freeArray(long **p, int N); -bool checkArrayFullyFill(long **p, int N ); \ No newline at end of file +bool checkArrayFullyFill(long **p, int N ); +double **getDoubleArray(int N, int M); \ No newline at end of file diff --git a/Code-C/growthRate.c b/Code-C/growthRate.c index c381864..8fcca10 100644 --- a/Code-C/growthRate.c +++ b/Code-C/growthRate.c @@ -9,16 +9,17 @@ * @param gRateArray array that contaigns results of the growth ratecalculation */ void growthRateCalculation(double **dataArray , double *gRateArray){ - double gRate = 0; for(int i = 0 ; i < nCol-1 ; i++){ - gRate = (dataArray[1][i] - dataArray[2][i]) / period; + gRateArray[i] = (dataArray[0][i] - dataArray[1][i]) / period; } } - -void growthRateFunction(double *dataLign){ - double **dataArray; - //initialization + fill +/** + * @brief calcul then print differentiate in csv + * + * @param dataLign + */ +void growthRateFunction(double **dataLign){ double gRateArray[nCol-1]; - growthRateCalculation(dataArray , gRateArray); + growthRateCalculation(dataLign , gRateArray); appendDataInFile("growthRate.csv",gRateArray , nCol-1); } \ No newline at end of file diff --git a/Code-C/growthRate.h b/Code-C/growthRate.h index 1e0b201..7979f21 100644 --- a/Code-C/growthRate.h +++ b/Code-C/growthRate.h @@ -1,4 +1,4 @@ #include #include -void growthRateFunction(double *dataLign); \ No newline at end of file +void growthRateFunction(double **dataLign); \ No newline at end of file diff --git a/Code-C/main b/Code-C/main new file mode 100755 index 0000000..640008a Binary files /dev/null and b/Code-C/main differ diff --git a/Code-C/main.c b/Code-C/main.c index 1bacd00..1a42c18 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -6,14 +6,15 @@ #include "queue.h" #include "average.h" #include "growthRate.h" +#include "getArray.h" bool rawDataWriteFlag; -int nRow = 500; +int nRow = 4; int nCol = 1; double freqEch = 250; Pqueue firstRawDataQueue; - +//Captor 1 2 3 4 5 6 7 8 bool selectionCaptors[] = {true,false,true,false,false,false,true,false}; int cptData = 0; @@ -66,31 +67,29 @@ void *threadCalculGrowthRate(void * vargp){ Pqueue rawDataQueue = firstRawDataQueue; char* fileName; //double pw[nCol-1]; - double *dataLign[2][nCol-1]; + double **dataLign = getDoubleArray(2,nCol); + int i = 0; while(rawDataWriteFlag){ - //add case first file traitement - //(possibility 1: call twice powerfunction , following while strat after 2 file encountered) - //(posibilty 2 : initialiaze with a 0-fill array, move ligns for first encounter then let the following whil e do the job) while(queueGetNextE(rawDataQueue) != NULL){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); if(i < 2){ if(i == 1){ - powerFunction(fileName, dataLign[1]); - growthRateFunction(**dataLign); + powerFunction(fileName, dataLign); + growthRateFunction(dataLign); }else{ - powerFunction(fileName, dataLign[0]); + powerFunction(fileName, dataLign); } i++; }else{ for(int y = 0; y < (nCol-1); y++){ dataLign[0][y] = dataLign[1][y]; } - powerFunction(fileName, dataLign[1]); - growthRateFunction(**dataLign); + powerFunction(fileName, dataLign); + growthRateFunction(dataLign); } - remove(fileName); + //remove(fileName); } } } diff --git a/Code-C/power.c b/Code-C/power.c index 8f80d43..836bf0c 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -11,16 +11,21 @@ * @param powerArray array where results are stocked */ void powerCalculation(long **p, double powerArray[]){ + printArrayData(p,nRow,nCol); + printf("data in pw : \n"); for(int i = 1; i < nCol; i++){ int j = 0; powerArray[i] = 0; - while(j < nRow-1){ - double aire = ( pow(p[j][i],2) + pow(p[j+1][i],2) ) / 2 * period; - powerArray[i] += aire; + + while(j < nRow){ + + printf("%d , %d , %d , %d\n" , p[j][i], p[j+1][i] , i ,j); + powerArray[i] + pow(p[j][i],2); j++; } powerArray[i] *= invTimeBandWidth; } + } /** @@ -30,7 +35,7 @@ void powerCalculation(long **p, double powerArray[]){ * @param N number of rows in the file * @param M number of columns in the file */ -void powerFunction(char* rawDataFileName, double **pw){ +void powerFunction(char* rawDataFileName, double *pw[]){ long **p = getRawDataArray(rawDataFileName); double pww[nCol-1]; if(p !=NULL){ @@ -38,7 +43,7 @@ void powerFunction(char* rawDataFileName, double **pw){ powerCalculation(p,pww); appendDataInFile("powerData.csv",pww,nCol-1); }else{ - powerCalculation(p,*pw); + powerCalculation(p,pw[1]); appendDataInFile("powerData.csv",*pw,nCol-1); } freeArray(p,nRow); diff --git a/Code-C/power.h b/Code-C/power.h index 043857c..e75d948 100644 --- a/Code-C/power.h +++ b/Code-C/power.h @@ -1,4 +1,4 @@ #include #include -void powerFunction(char* rawDataFileName, double **pw); \ No newline at end of file +void powerFunction(char* rawDataFileName, double *pw[]); \ No newline at end of file diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index 0016a69..9c0fbd9 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -119,7 +119,7 @@ bool writeOneRawData(FILE *rawDataFile){ } int lastIndex = lastIndexCaptor(); for (int i = 1; i < 9; i++){ - if(selectionCaptors[i]){ + if(selectionCaptors[i-1]){ value.octet1 = buff[3*i+1]; value.octet2 = buff[3*i+2]; value.octet3 = buff[3*i+3]; @@ -128,7 +128,7 @@ bool writeOneRawData(FILE *rawDataFile){ 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(uint32_t)); - if(i==lastIndex){ + if(i-1==lastIndex){ fprintf(rawDataFile, "%d\n", values[i]/256); } else{