Traitement-signal-plantes/Code-C/average.c

45 lines
1.3 KiB
C

#include "average.h"
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
/**
* @brief realize the average calcul
*
* @param p array with all the values that will be used for the calcul
* @param averageArray array where results are stocked
*/
void averageCalculation(long **p, double averageArray[]){
for(int i = 1; i < nCol; i++){
int j = 0;
averageArray[i] = 0;
while(j < nRowRawData){
averageArray[i] += p[i][j];
j++;
}
//printf("%f , %f\n", averageArray[i] , averageArray[i] / nRowRawData);
averageArray[i] /= nRowRawData;
}
}
/**
* @brief function that realize all the action to write one lign in the file averageData.csv
*
* @param rawDataFileName name of the raw data file to use to realize the calcul
*/
void averageFunction(char* rawDataFileName , double **aver){
long **p = getRawDataArray(rawDataFileName);
double averN[nCol -1];
if(p !=NULL){
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);
}
}
}