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

50 lines
1.4 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 14:35:02 +02:00
printArrayData(p,nRow,nCol);
printf("data in pw : \n");
2022-06-14 18:01:52 +02:00
for(int i = 1; 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
while(j < nRow){
2022-06-16 14:44:31 +02:00
printf("%d , %d , %d , %d\n" , p[j][i] ,powerArray[i] , i ,j);
2022-06-16 14:35:02 +02:00
powerArray[i] + pow(p[j][i],2);
2022-06-01 12:32:04 +02:00
j++;
}
2022-06-16 14:44:31 +02:00
powerArray[i] /= nRow;
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 14:35:02 +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-15 17:50:47 +02:00
appendDataInFile("powerData.csv",*pw,nCol-1);
2022-06-15 15:45:14 +02:00
}
2022-06-14 18:01:52 +02:00
freeArray(p,nRow);
2022-06-07 14:28:32 +02:00
}
2022-06-01 12:32:04 +02:00
}