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

57 lines
1.4 KiB
C

#include <math.h>
#include "include/power.h"
#include "include/getArray.h"
#include "include/fileGestion.h"
#include "include/initialParameters.h"
#include "include/queue.h"
/**
* @brief realize the powerThreadFunction calcul
*
* @param p array with all the values that will be used for the calcul
* @param powerArray array where results are stocked
*/
void powerCalculation(long **p, double powerArray[])
{
for (int i = 0; i < nCol; i++)
{
int j = 0;
powerArray[i] = 0;
while (j < nRowRawData)
{
powerArray[i] += pow(p[j][i + 1], 2);
j++;
}
powerArray[i] /= nRowRawData;
}
}
/**
* @brief function that realize all the action to write one lign in the file powerData.csv
*
* @param rawDataFileName name of the raw data file to use to realize the calcul
* @param N number of rows in the file
* @param M number of columns in the file
*/
void powerFunction(char *rawDataFileName, double **pw)
{
long **p = getRawDataArray(rawDataFileName);
// printArrayData(p, nRowRawData, nCol);
double pww[nCol - 1];
if (p != NULL)
{
if (pw == NULL)
{
powerCalculation(p, pww);
appendDataInFile("powerData.csv", pww, nCol - 1);
}
else
{
powerCalculation(p, pw[1]);
appendDataInFile("powerData.csv", pw[1], nCol - 1);
}
freeArray(p, nRowRawData);
}
}