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

47 lines
1.5 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-09 17:34:24 +02:00
void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){
2022-06-07 14:28:32 +02:00
for(int i = 0; i < M-1; 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-07 14:28:32 +02:00
while(j < N-1){
double aire = ( pow(p[j][i+1],2) + pow(p[j+1][i+1],2) ) / 2 * period;
//printf("aire [%d,%d] : %f\n",j,i,aire);
2022-06-09 17:34:24 +02:00
powerArray[i] += aire;
2022-06-01 12:32:04 +02:00
j++;
}
2022-06-09 17:34:24 +02:00
powerArray[i] *= invTimeBandwidth;
//printf("%f\n", powerArray[i]);
2022-06-01 12:32:04 +02:00
}
}
2022-06-10 17:22:01 +02:00
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){
long **p = getRawDataArray(rawDataFileName,N, M);
double pw[8];
2022-06-07 14:28:32 +02:00
if(p !=NULL){
2022-06-09 17:34:24 +02:00
powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
2022-06-07 14:28:32 +02:00
writePowerData(pw,8);
freeArray(p,N);
2022-06-09 17:56:45 +02:00
return true;
2022-06-07 14:28:32 +02:00
}
else{
2022-06-09 17:56:45 +02:00
return false;
2022-06-07 14:28:32 +02:00
}
2022-06-10 17:22:01 +02:00
}
void *threadCalcul(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
printf("print in power of first eleme in queue : \n");
printE(firstRawDataQueue);
while(rawDataQueue == NULL || getNextE(rawDataQueue) != NULL){
//pthread_mutex_lock(&mutex);
while(power(gettabChar(rawDataQueue),nRow,nCol,period,invTimeBandWidth) == false){
remove(gettabChar(rawDataQueue));
rawDataQueue = rmFrstE(rawDataQueue);
}
//pthread_mutex_unlock(&mutex);
//delay(10);
}
2022-06-01 12:32:04 +02:00
}