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

186 lines
4.9 KiB
C
Raw Normal View History

2022-06-09 17:34:24 +02:00
#include <pthread.h>
#include <stdbool.h>
2023-06-02 16:10:31 +02:00
#include <sqlite3.h>
2022-12-01 17:29:47 +01:00
2023-06-01 17:22:38 +02:00
#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"
2022-06-01 12:32:04 +02:00
2022-06-13 17:11:16 +02:00
bool rawDataWriteFlag;
2022-12-01 17:29:47 +01:00
int nRowRawData = 5000;
2022-06-16 17:05:12 +02:00
int nRowGR = 150;
2022-06-14 18:01:52 +02:00
int nCol = 1;
2022-06-09 17:34:24 +02:00
double freqEch = 250;
2022-06-17 17:38:53 +02:00
int nbRowBinFile = 900011;
int nbRowIgnore = 19;
2022-06-10 15:05:04 +02:00
2022-06-10 17:22:01 +02:00
Pqueue firstRawDataQueue;
2023-05-09 13:37:36 +02:00
// Captor 1 2 3 4 5 6 7 8
bool selectionCaptors[] = {true, false, true, false, false, false, true, false};
2022-06-10 10:10:28 +02:00
2022-06-21 15:13:10 +02:00
int cptData = 0;
2022-06-10 17:22:01 +02:00
int cptFile = 1;
2022-06-17 17:38:53 +02:00
int cptValue = 0;
2022-06-10 17:22:01 +02:00
double period = 0;
double invTimeBandWidth = 0;
2022-06-21 15:13:10 +02:00
void *threadCalculPower(void *vargp)
{
2022-06-13 15:03:51 +02:00
Pqueue rawDataQueue = firstRawDataQueue;
2022-06-21 15:13:10 +02:00
char *fileName;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
2022-06-13 17:24:53 +02:00
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-06-15 15:45:14 +02:00
powerFunction(fileName, NULL);
2022-06-14 10:24:59 +02:00
remove(fileName);
}
}
2022-06-21 17:47:27 +02:00
return NULL;
2022-06-14 10:24:59 +02:00
}
2022-06-21 15:13:10 +02:00
void *threadCalculAverage(void *vargp)
{
2022-06-14 10:24:59 +02:00
Pqueue rawDataQueue = firstRawDataQueue;
2022-06-21 15:13:10 +02:00
char *fileName;
2022-06-21 15:13:10 +02:00
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
2022-06-14 10:24:59 +02:00
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-12-01 17:29:47 +01:00
printf("%s\n", fileName);
2022-06-16 17:05:12 +02:00
averageFunction(fileName, NULL);
2022-06-14 10:24:59 +02:00
remove(fileName);
}
}
2022-06-21 17:47:27 +02:00
return NULL;
2022-06-14 10:24:59 +02:00
}
2022-06-21 15:13:10 +02:00
void *threadCalculBoth(void *vargp)
{
2022-06-14 10:24:59 +02:00
Pqueue rawDataQueue = firstRawDataQueue;
2022-06-21 15:13:10 +02:00
char *fileName;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
2022-06-14 10:24:59 +02:00
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-06-15 15:45:14 +02:00
powerFunction(fileName, NULL);
2022-06-21 15:13:10 +02:00
averageFunction(fileName, NULL);
2022-06-14 10:24:59 +02:00
remove(fileName);
2022-06-13 17:11:16 +02:00
}
2022-06-13 15:03:51 +02:00
}
2022-06-21 17:47:27 +02:00
return NULL;
2022-06-13 15:03:51 +02:00
}
2022-06-10 17:22:01 +02:00
2022-06-21 15:13:10 +02:00
void *threadCalculGrowthRate(void *vargp)
{
2022-06-15 11:57:15 +02:00
Pqueue rawDataQueue = firstRawDataQueue;
2022-06-21 15:13:10 +02:00
char *fileName;
// double pw[nCol-1];
double **dataLignPw = getDoubleArray(2, nCol);
double **dataLignAv = getDoubleArray(2, nCol);
2022-06-16 14:35:02 +02:00
2022-06-15 15:45:14 +02:00
int i = 0;
2022-06-21 15:13:10 +02:00
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
2022-06-15 11:57:15 +02:00
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-06-24 17:50:54 +02:00
printf("%s\n", fileName);
2022-06-21 15:13:10 +02:00
if (i < 2)
{
if (i == 1)
{
2022-06-16 17:05:12 +02:00
powerFunction(fileName, dataLignPw);
2022-06-21 15:13:10 +02:00
averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignAv, "growthRateAv.csv");
2022-06-21 15:13:10 +02:00
}
else
{
averageFunction(fileName, dataLignAv);
2022-06-16 17:05:12 +02:00
powerFunction(fileName, dataLignPw);
2022-06-15 15:45:14 +02:00
}
i++;
2022-06-21 15:13:10 +02:00
}
else
{
for (int y = 0; y < (nCol - 1); y++)
{
2022-06-16 17:05:12 +02:00
dataLignPw[0][y] = dataLignPw[1][y];
dataLignAv[0][y] = dataLignAv[1][y];
2022-06-15 15:45:14 +02:00
}
2022-06-16 17:05:12 +02:00
powerFunction(fileName, dataLignPw);
2022-06-21 15:13:10 +02:00
averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignPw, "growthRateAv.csv");
2022-06-15 15:45:14 +02:00
}
remove(fileName);
2022-06-15 11:57:15 +02:00
}
}
2022-06-21 17:47:27 +02:00
return NULL;
2022-06-15 11:57:15 +02:00
}
2022-06-14 18:01:52 +02:00
2022-06-21 15:13:10 +02:00
int main(int argc, char **argv)
{
2022-06-13 17:24:53 +02:00
2022-06-21 15:13:10 +02:00
for (int i = 0; i < 8; i++)
{
if (selectionCaptors[i])
{
2022-06-14 18:01:52 +02:00
nCol++;
}
}
2022-12-01 17:29:47 +01:00
printf("%d", nCol);
2022-06-13 17:24:53 +02:00
2022-06-13 17:11:16 +02:00
rawDataWriteFlag = true;
2022-06-09 17:34:24 +02:00
2022-06-10 17:22:01 +02:00
period = 1 / freqEch;
2022-06-21 15:13:10 +02:00
invTimeBandWidth = 1 / (nRowRawData * period);
2022-06-13 15:03:51 +02:00
firstRawDataQueue = queueCreateEmpty(); // change this for create empty
2022-06-15 16:27:56 +02:00
// 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);
// }
2022-06-21 17:47:27 +02:00
// pthread_t calculAverage;
// if (pthread_create(&calculAverage, NULL, threadCalculAverage, "threadCalculAverage"))
// {
// perror("threadCalculAverage() error");
// exit(1);
// }
2022-06-10 17:22:01 +02:00
2022-06-24 18:30:58 +02:00
// pthread_t calculGrowthRate;
// if (pthread_create(&calculGrowthRate, NULL, threadCalculGrowthRate, "threadCalculGrowthRate"))
// {
// perror("threadcalculGrowthRate() error");
// exit(1);
// }
2022-06-10 17:22:01 +02:00
// pthread_exit(NULL);
sqlite3_shutdown();
2022-06-01 12:32:04 +02:00
}