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

54 lines
1.4 KiB
C
Raw Normal View History

2022-06-14 10:24:59 +02:00
#include "average.h"
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
2022-06-14 10:46:04 +02:00
/**
* @brief realize the average calcul
2022-06-23 16:24:47 +02:00
*
2022-06-14 10:46:04 +02:00
* @param p array with all the values that will be used for the calcul
* @param averageArray array where results are stocked
*/
2022-06-23 16:24:47 +02:00
void averageCalculation(long **p, double averageArray[])
{
for (int i = 1; i < nCol; i++)
{
2022-06-14 10:24:59 +02:00
int j = 0;
averageArray[i] = 0;
2022-06-23 16:24:47 +02:00
while (j < nRowRawData)
{
averageArray[i - 1] += p[i][j];
2022-06-14 10:24:59 +02:00
j++;
}
2022-06-23 16:24:47 +02:00
// printf("%f , %f\n", averageArray[i] , averageArray[i] / nRowRawData);
2022-06-16 17:05:12 +02:00
averageArray[i] /= nRowRawData;
2022-06-14 10:24:59 +02:00
}
}
2022-06-14 10:46:04 +02:00
/**
* @brief function that realize all the action to write one lign in the file averageData.csv
2022-06-23 16:24:47 +02:00
*
2022-06-14 10:46:04 +02:00
* @param rawDataFileName name of the raw data file to use to realize the calcul
*/
2022-06-23 16:24:47 +02:00
void averageFunction(char *rawDataFileName, double **aver)
{
2022-06-14 18:01:52 +02:00
long **p = getRawDataArray(rawDataFileName);
2022-06-23 16:24:47 +02:00
double averN[nCol - 1];
if (p != NULL)
{
if (p != NULL)
{
if (aver == NULL)
{
averageCalculation(p, averN);
appendDataInFile("averageData.csv", averN, nCol - 1);
2022-06-16 17:05:12 +02:00
}
2022-06-23 16:24:47 +02:00
else
{
averageCalculation(p, aver[1]);
appendDataInFile("averageData.csv", aver[1], nCol - 1);
}
freeArray(p, nRowRawData);
}
2022-06-14 10:24:59 +02:00
}
}