diff --git a/Code-C/average.c b/Code-C/average.c index e9d8706..8fef657 100644 --- a/Code-C/average.c +++ b/Code-C/average.c @@ -13,12 +13,11 @@ void averageCalculation(long **p, double averageArray[]){ for(int i = 1; i < nCol; i++){ int j = 0; averageArray[i] = 0; - while(j < nRow -1){ + while(j < nRowRawData){ averageArray[i] += p[i][j]; j++; } - averageArray[i] /= nRow; - //printf("%f\n", powerArray[i]); + averageArray[i] /= nRowRawData; } } @@ -27,12 +26,19 @@ void averageCalculation(long **p, double averageArray[]){ * * @param rawDataFileName name of the raw data file to use to realize the calcul */ -void averageThreadFunction(char* rawDataFileName){ +void averageFunction(char* rawDataFileName , double **aver){ long **p = getRawDataArray(rawDataFileName); - double aver[nCol -1]; + double averN[nCol -1]; if(p !=NULL){ - averageCalculation(p,aver); - appendDataInFile("averageData.csv",aver,nCol-1); - freeArray(p,nRow); + if(p !=NULL){ + if(aver == NULL){ + averageCalculation(p,averN); + appendDataInFile("averageData.csv",averN,nCol-1); + }else{ + averageCalculation(p,aver[1]); + appendDataInFile("averageData.csv",aver[1],nCol-1); + } + freeArray(p,nRowRawData); + } } } \ No newline at end of file diff --git a/Code-C/average.h b/Code-C/average.h index b130865..a121de4 100644 --- a/Code-C/average.h +++ b/Code-C/average.h @@ -1,4 +1,4 @@ #include #include -void averageThreadFunction(char* rawDataFileName); \ No newline at end of file +void averageFunction(char* rawDataFileName , double **aver); \ No newline at end of file diff --git a/Code-C/getArray.c b/Code-C/getArray.c index 7284378..f8c05ef 100644 --- a/Code-C/getArray.c +++ b/Code-C/getArray.c @@ -97,8 +97,8 @@ void freeArray(long **p, int N) { */ long **getRawDataArray(char* rawDataFileName){ long **p; - p = getlongArray(nRow, nCol); - fillArrayWithRawData(rawDataFileName,p ,nRow, nCol); + p = getlongArray(nRowRawData, nCol); + fillArrayWithRawData(rawDataFileName,p ,nRowRawData, nCol); //if(checkArrayFullyFill(p,nRow)){ //clearRawData(N); return p; diff --git a/Code-C/growthRate.c b/Code-C/growthRate.c index 8fcca10..64a0a2e 100644 --- a/Code-C/growthRate.c +++ b/Code-C/growthRate.c @@ -18,8 +18,19 @@ void growthRateCalculation(double **dataArray , double *gRateArray){ * * @param dataLign */ -void growthRateFunction(double **dataLign){ +void growthRateFunction(double **dataLign , char* fileName){ double gRateArray[nCol-1]; growthRateCalculation(dataLign , gRateArray); - appendDataInFile("growthRate.csv",gRateArray , nCol-1); + appendDataInFile(fileName,gRateArray , nCol-1); +} + +void sumColArray(long **p, double res[] , int N , int M){ + for(int i = 1; i < M; i++){ + int j = 0; + res[i] = 0; + while(j < N){ + res[i] += p[i][j]; + j++; + } + } } \ No newline at end of file diff --git a/Code-C/growthRate.h b/Code-C/growthRate.h index 7979f21..d68b096 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 , char* fileName); \ No newline at end of file diff --git a/Code-C/initialParameters.h b/Code-C/initialParameters.h index 96201f5..5403af0 100644 --- a/Code-C/initialParameters.h +++ b/Code-C/initialParameters.h @@ -2,7 +2,8 @@ #include "queue.h" extern bool rawDataWriteFlag; -extern int nRow; +extern int nRowRawData; +extern int nRowGR; extern int nCol; extern double freqEch; diff --git a/Code-C/main b/Code-C/main index 3cd197e..d9efec6 100755 Binary files a/Code-C/main and b/Code-C/main differ diff --git a/Code-C/main.c b/Code-C/main.c index 32e7fd7..f48a16a 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -9,7 +9,8 @@ #include "getArray.h" bool rawDataWriteFlag; -int nRow = 500; +int nRowRawData = 500; +int nRowGR = 150; int nCol = 1; double freqEch = 250; @@ -43,7 +44,7 @@ void *threadCalculAverage(void *vargp){ while(queueGetNextE(rawDataQueue) != NULL){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); - averageThreadFunction(fileName); + averageFunction(fileName, NULL); remove(fileName); } } @@ -57,7 +58,7 @@ void *threadCalculBoth(void *vargp){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); powerFunction(fileName, NULL); - averageThreadFunction(fileName); + averageFunction(fileName , NULL); remove(fileName); } } @@ -67,7 +68,8 @@ void *threadCalculGrowthRate(void * vargp){ Pqueue rawDataQueue = firstRawDataQueue; char* fileName; //double pw[nCol-1]; - double **dataLign = getDoubleArray(2,nCol); + double **dataLignPw = getDoubleArray(2,nCol); + double **dataLignAv = getDoubleArray(2,nCol); int i = 0; while(rawDataWriteFlag){ @@ -76,18 +78,24 @@ void *threadCalculGrowthRate(void * vargp){ fileName = queueGetTabChar(rawDataQueue); if(i < 2){ if(i == 1){ - powerFunction(fileName, dataLign); - growthRateFunction(dataLign); + powerFunction(fileName, dataLignPw); + averageFunction(fileName , dataLignAv); + growthRateFunction(dataLignPw , "growthRatePw.csv"); + growthRateFunction(dataLignPw,"growthRateAv.csv"); }else{ - powerFunction(fileName, dataLign); + averageFunction(fileName , dataLignAv); + powerFunction(fileName, dataLignPw); } i++; }else{ for(int y = 0; y < (nCol-1); y++){ - dataLign[0][y] = dataLign[1][y]; + dataLignPw[0][y] = dataLignPw[1][y]; + dataLignAv[0][y] = dataLignAv[1][y]; } - powerFunction(fileName, dataLign); - growthRateFunction(dataLign); + powerFunction(fileName, dataLignPw); + averageFunction(fileName , dataLignAv); + growthRateFunction(dataLignPw,"growthRatePw.csv"); + growthRateFunction(dataLignPw,"growthRateAv.csv"); } //remove(fileName); } @@ -105,7 +113,7 @@ int main(int argc , char** argv){ rawDataWriteFlag = true; period = 1 / freqEch; - invTimeBandWidth = 1 /(nRow * period); + invTimeBandWidth = 1 /(nRowRawData * period); firstRawDataQueue = queueCreateEmpty(); // change this for create empty pthread_t rawData; diff --git a/Code-C/power.c b/Code-C/power.c index 6fd69d1..ea62528 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -11,17 +11,15 @@ * @param powerArray array where results are stocked */ void powerCalculation(long **p, double powerArray[]){ - printf("data in pw : \n"); for(int i = 0; i < nCol; i++){ int j = 0; powerArray[i] = 0; - while(j < nRow){ - printf("\np[%d,%d] = %d\npwArray[%d] = %lf\n" , j,i,p[j][i+1],i,powerArray[i]); + while(j < nRowRawData){ powerArray[i] += pow(p[j][i+1],2); j++; } - powerArray[i] /= nRow; + powerArray[i] /= nRowRawData; } } @@ -33,7 +31,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){ @@ -42,8 +40,8 @@ void powerFunction(char* rawDataFileName, double *pw[]){ appendDataInFile("powerData.csv",pww,nCol-1); }else{ powerCalculation(p,pw[1]); - appendDataInFile("powerData.csv",*pw,nCol-1); + appendDataInFile("powerData.csv",pw[1],nCol-1); } - freeArray(p,nRow); + freeArray(p,nRowRawData); } } \ No newline at end of file diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index 9c0fbd9..c0183af 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -151,7 +151,7 @@ void *threadSimulateFlux(void *vargp){ FILE *rawDataFile = fopen(fileName,"w+"); while(writeOneRawData(rawDataFile)){ - if(cptData == nRow){ + if(cptData == nRowRawData){ fclose(rawDataFile); cptData = 0; cptFile++;