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

117 lines
3.2 KiB
C

#include <pthread.h>
#include <stdbool.h>
#include "simulateFlux.h"
#include "power.h"
#include "initialParameters.h"
#include "queue.h"
#include "average.h"
#include "growthRate.h"
#include "getArray.h"
bool rawDataWriteFlag;
int nRow = 4;
int nCol = 1;
double freqEch = 250;
Pqueue firstRawDataQueue;
//Captor 1 2 3 4 5 6 7 8
bool selectionCaptors[] = {true,false,true,false,false,false,true,false};
int cptData = 0;
int cptFile = 1;
double period = 0;
double invTimeBandWidth = 0;
void *threadCalculPower(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
powerFunction(fileName, NULL);
remove(fileName);
}
}
}
void *threadCalculAverage(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
averageThreadFunction(fileName);
remove(fileName);
}
}
}
void *threadCalculBoth(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
powerFunction(fileName, NULL);
averageThreadFunction(fileName);
remove(fileName);
}
}
}
void *threadCalculGrowthRate(void * vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
//double pw[nCol-1];
double **dataLign = getDoubleArray(2,nCol);
int i = 0;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
if(i < 2){
if(i == 1){
powerFunction(fileName, dataLign);
growthRateFunction(dataLign);
}else{
powerFunction(fileName, dataLign);
}
i++;
}else{
for(int y = 0; y < (nCol-1); y++){
dataLign[0][y] = dataLign[1][y];
}
powerFunction(fileName, dataLign);
growthRateFunction(dataLign);
}
//remove(fileName);
}
}
}
int main(int argc , char** argv){
for(int i = 0 ; i < 8 ; i++){
if(selectionCaptors[i]){
nCol++;
}
}
rawDataWriteFlag = true;
period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period);
firstRawDataQueue = queueCreateEmpty(); // change this for create empty
pthread_t rawData;
pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData);
pthread_t calcul;
pthread_create(&calcul , NULL, threadCalculGrowthRate, (void *)&calcul);
pthread_exit(NULL);
}