growth ok

This commit is contained in:
quentin.perret 2022-06-16 17:05:12 +02:00
parent efc3110b2d
commit 8ecdd37619
10 changed files with 58 additions and 34 deletions

View file

@ -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);
}
}
}

View file

@ -1,4 +1,4 @@
#include <math.h>
#include <stdbool.h>
void averageThreadFunction(char* rawDataFileName);
void averageFunction(char* rawDataFileName , double **aver);

View file

@ -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;

View file

@ -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++;
}
}
}

View file

@ -1,4 +1,4 @@
#include <math.h>
#include <stdbool.h>
void growthRateFunction(double **dataLign);
void growthRateFunction(double **dataLign , char* fileName);

View file

@ -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;

Binary file not shown.

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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++;