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

55 lines
1.5 KiB
C
Raw Normal View History

2023-06-01 17:22:38 +02:00
#include "./Include/average.h"
#include "./Include/getArray.h"
#include "./Include/fileGestion.h"
#include "./Include/initialParameters.h"
#include "./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[])
{
// printArrayData(p, nRowRawData, nCol);
2022-06-24 18:30:58 +02:00
// printf("\n");
2022-06-23 16:24:47 +02:00
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)
{
2022-06-24 17:17:28 +02:00
averageArray[i - 1] += (double)p[i][j];
2022-06-14 10:24:59 +02:00
j++;
}
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
}
}