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

47 lines
1.3 KiB
C
Raw Normal View History

2022-06-01 12:32:04 +02:00
#include "power.h"
#include "getArray.h"
2022-06-02 14:29:21 +02:00
#include "fileGestion.h"
2022-06-10 17:22:01 +02:00
#include "initialParameters.h"
#include "queue.h"
2022-06-01 12:32:04 +02:00
2022-06-14 10:46:12 +02:00
/**
2022-06-15 11:57:15 +02:00
* @brief realize the powerThreadFunction calcul
2022-06-14 10:46:12 +02:00
*
* @param p array with all the values that will be used for the calcul
* @param powerArray array where results are stocked
*/
2022-06-14 18:01:52 +02:00
void powerCalculation(long **p, double powerArray[]){
2022-06-16 15:19:07 +02:00
for(int i = 0; i < nCol; i++){
2022-06-01 12:32:04 +02:00
int j = 0;
2022-06-09 17:34:24 +02:00
powerArray[i] = 0;
2022-06-16 14:35:02 +02:00
2022-06-16 17:05:12 +02:00
while(j < nRowRawData){
2022-06-16 15:19:07 +02:00
powerArray[i] += pow(p[j][i+1],2);
2022-06-01 12:32:04 +02:00
j++;
}
2022-06-16 17:05:12 +02:00
powerArray[i] /= nRowRawData;
2022-06-01 12:32:04 +02:00
}
2022-06-16 14:35:02 +02:00
2022-06-01 12:32:04 +02:00
}
2022-06-14 10:46:12 +02:00
/**
* @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
*/
2022-06-16 17:05:12 +02:00
void powerFunction(char* rawDataFileName, double **pw){
2022-06-14 18:01:52 +02:00
long **p = getRawDataArray(rawDataFileName);
2022-06-15 15:45:14 +02:00
double pww[nCol-1];
2022-06-07 14:28:32 +02:00
if(p !=NULL){
2022-06-15 15:45:14 +02:00
if(pw == NULL){
powerCalculation(p,pww);
2022-06-15 17:50:47 +02:00
appendDataInFile("powerData.csv",pww,nCol-1);
2022-06-15 15:45:14 +02:00
}else{
2022-06-16 14:35:02 +02:00
powerCalculation(p,pw[1]);
2022-06-16 17:05:12 +02:00
appendDataInFile("powerData.csv",pw[1],nCol-1);
2022-06-15 15:45:14 +02:00
}
2022-06-16 17:05:12 +02:00
freeArray(p,nRowRawData);
2022-06-07 14:28:32 +02:00
}
2022-06-01 12:32:04 +02:00
}