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

47 lines
1.5 KiB
C

#include "power.h"
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){
for(int i = 0; i < M-1; i++){
int j = 0;
powerArray[i] = 0;
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);
powerArray[i] += aire;
j++;
}
powerArray[i] *= invTimeBandwidth;
//printf("%f\n", powerArray[i]);
}
}
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){
long **p = getRawDataArray(rawDataFileName,N, M);
double pw[8];
if(p !=NULL){
powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
writePowerData(pw,8);
freeArray(p,N);
return true;
}
else{
return false;
}
}
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);
}
}