Traitement-signal-plantes/Code-C/average.c
Aurélien Gauthier 6b9de5f457 rebase merge
2022-06-27 16:39:21 +02:00

55 lines
1.4 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[])
{
// printArrayData(p, nRowRawData, nCol);
// printf("\n");
for (int i = 1; i < nCol; i++)
{
int j = 0;
averageArray[i] = 0;
while (j < nRowRawData)
{
averageArray[i - 1] += (double)p[i][j];
j++;
}
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);
}
}
}