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

186 lines
4.9 KiB
C

#include <pthread.h>
#include <stdbool.h>
#include <sqlite3.h>
#include "./Include/simulateFlux.h"
#include "./Include/power.h"
#include "./Include/initialParameters.h"
#include "./Include/queue.h"
#include "./Include/average.h"
#include "./Include/growthRate.h"
#include "./Include/getArray.h"
#include "./Include/database.h"
bool rawDataWriteFlag;
int nRowRawData = 5000;
int nRowGR = 150;
int nCol = 1;
double freqEch = 250;
int nbRowBinFile = 900011;
int nbRowIgnore = 19;
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;
int cptValue = 0;
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);
}
}
return NULL;
}
void *threadCalculAverage(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char *fileName;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
printf("%s\n", fileName);
averageFunction(fileName, NULL);
remove(fileName);
}
}
return NULL;
}
void *threadCalculBoth(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char *fileName;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
powerFunction(fileName, NULL);
averageFunction(fileName, NULL);
remove(fileName);
}
}
return NULL;
}
void *threadCalculGrowthRate(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char *fileName;
// double pw[nCol-1];
double **dataLignPw = getDoubleArray(2, nCol);
double **dataLignAv = getDoubleArray(2, nCol);
int i = 0;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
printf("%s\n", fileName);
if (i < 2)
{
if (i == 1)
{
powerFunction(fileName, dataLignPw);
averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignAv, "growthRateAv.csv");
}
else
{
averageFunction(fileName, dataLignAv);
powerFunction(fileName, dataLignPw);
}
i++;
}
else
{
for (int y = 0; y < (nCol - 1); y++)
{
dataLignPw[0][y] = dataLignPw[1][y];
dataLignAv[0][y] = dataLignAv[1][y];
}
powerFunction(fileName, dataLignPw);
averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignPw, "growthRateAv.csv");
}
remove(fileName);
}
}
return NULL;
}
int main(int argc, char **argv)
{
for (int i = 0; i < 8; i++)
{
if (selectionCaptors[i])
{
nCol++;
}
}
printf("%d", nCol);
rawDataWriteFlag = true;
period = 1 / freqEch;
invTimeBandWidth = 1 / (nRowRawData * period);
firstRawDataQueue = queueCreateEmpty(); // change this for create empty
// launch DB related function
sqlite3_initialize();
createDb(); // Created the Db if not exist
initiaizeNewTrial("test", freqEch, selectionCaptors); // Initialize Trials data and tables
// pthread_t rawData;
// if (pthread_create(&rawData, NULL, threadSimulateFlux, "threadSimulflux") != 0)
// {
// perror("threadSimulflux() error");
// exit(1);
// }
// pthread_t calculAverage;
// if (pthread_create(&calculAverage, NULL, threadCalculAverage, "threadCalculAverage"))
// {
// perror("threadCalculAverage() error");
// exit(1);
// }
// pthread_t calculGrowthRate;
// if (pthread_create(&calculGrowthRate, NULL, threadCalculGrowthRate, "threadCalculGrowthRate"))
// {
// perror("threadcalculGrowthRate() error");
// exit(1);
// }
// pthread_exit(NULL);
sqlite3_shutdown();
}