From 9cd8d2bc7e41a15726775b0bef22d597fda8acce Mon Sep 17 00:00:00 2001 From: "quentin.perret" Date: Wed, 15 Jun 2022 11:57:15 +0200 Subject: [PATCH] add new thread growth rate --- Code-C/Makefile | 3 ++- Code-C/average.c | 2 +- Code-C/average.h | 2 +- Code-C/growthRate.c | 23 +++++++++++++++++++++++ Code-C/growthRate.h | 1 + Code-C/main.c | 22 ++++++++++++++++++---- Code-C/power.c | 5 +++-- Code-C/power.h | 2 +- 8 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 Code-C/growthRate.c create mode 100644 Code-C/growthRate.h diff --git a/Code-C/Makefile b/Code-C/Makefile index 0328aff..8b874a0 100644 --- a/Code-C/Makefile +++ b/Code-C/Makefile @@ -1,4 +1,5 @@ CC = gcc all: - $(CC) -g fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main \ No newline at end of file + $(CC) -g fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main + ./main < ../02400031.TXT \ No newline at end of file diff --git a/Code-C/average.c b/Code-C/average.c index 425419c..e9d8706 100644 --- a/Code-C/average.c +++ b/Code-C/average.c @@ -27,7 +27,7 @@ void averageCalculation(long **p, double averageArray[]){ * * @param rawDataFileName name of the raw data file to use to realize the calcul */ -void average(char* rawDataFileName){ +void averageThreadFunction(char* rawDataFileName){ long **p = getRawDataArray(rawDataFileName); double aver[nCol -1]; if(p !=NULL){ diff --git a/Code-C/average.h b/Code-C/average.h index 25be1e0..b130865 100644 --- a/Code-C/average.h +++ b/Code-C/average.h @@ -1,4 +1,4 @@ #include #include -void average(char* rawDataFileName); \ No newline at end of file +void averageThreadFunction(char* rawDataFileName); \ No newline at end of file diff --git a/Code-C/growthRate.c b/Code-C/growthRate.c new file mode 100644 index 0000000..951e2c2 --- /dev/null +++ b/Code-C/growthRate.c @@ -0,0 +1,23 @@ +#include "initialParameters.h" +#include "fileGestion.h" +#include "getArray.h" +/** + * @brief calculate de growth rate between to point next to each other + * + * @param dataArray array with data of points next to each other for each captor (dim : 2 * nCols) + * @param gRateArray array that contaigns results of the growth ratecalculation + */ +void growthRateCalculation(double **dataArray , double *gRateArray){ + double gRate = 0; + for(int i = 0 ; i < nCol-1 ; i++){ + gRate = (dataArray[1][i] - dataArray[2][i]) / period; + } +} + +void growthRateFunction(double *dataLign){ + double **dataArray; + //initialization + fill + double gRateArray[nCol-1]; + growthRateCalculation(dataArray , gRateArray); + appendDataInFile("growthRate.csv",gRateArray , nCol-1); +} \ No newline at end of file diff --git a/Code-C/growthRate.h b/Code-C/growthRate.h new file mode 100644 index 0000000..3a1f118 --- /dev/null +++ b/Code-C/growthRate.h @@ -0,0 +1 @@ +void growthRateFunction(); \ No newline at end of file diff --git a/Code-C/main.c b/Code-C/main.c index a66d853..dcefc4b 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -5,6 +5,7 @@ #include "initialParameters.h" #include "queue.h" #include "average.h" +#include "growthRate.h" bool rawDataWriteFlag; int nRow = 500; @@ -28,7 +29,7 @@ void *threadCalculPower(void *vargp){ while(queueGetNextE(rawDataQueue) != NULL){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); - power(fileName); + powerFunction(fileName); remove(fileName); } } @@ -41,7 +42,7 @@ void *threadCalculAverage(void *vargp){ while(queueGetNextE(rawDataQueue) != NULL){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); - average(fileName); + averageThreadFunction(fileName); remove(fileName); } } @@ -54,13 +55,26 @@ void *threadCalculBoth(void *vargp){ while(queueGetNextE(rawDataQueue) != NULL){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); - power(fileName); - average(fileName); + powerFunction(fileName); + averageThreadFunction(fileName); remove(fileName); } } } +void *threadCalculGrowthRate(void * vargp){ + Pqueue rawDataQueue = firstRawDataQueue; + char* fileName; + while(rawDataWriteFlag){ + while(queueGetNextE(rawDataQueue) != NULL){ + rawDataQueue = queueGetNextE(rawDataQueue); + fileName = queueGetTabChar(rawDataQueue); + double *dataLign = powerFunction(fileName); + growthRateFunction(dataLign); + remove(fileName); + } + } +} int main(int argc , char** argv){ diff --git a/Code-C/power.c b/Code-C/power.c index 66f4f75..7e6b1b3 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -5,7 +5,7 @@ #include "queue.h" /** - * @brief realize the power calcul + * @brief realize the powerThreadFunction calcul * * @param p array with all the values that will be used for the calcul * @param powerArray array where results are stocked @@ -30,7 +30,7 @@ void powerCalculation(long **p, double powerArray[]){ * @param N number of rows in the file * @param M number of columns in the file */ -void power(char* rawDataFileName){ +double *powerFunction(char* rawDataFileName){ long **p = getRawDataArray(rawDataFileName); double pw[nCol-1]; if(p !=NULL){ @@ -38,4 +38,5 @@ void power(char* rawDataFileName){ appendDataInFile("powerData.csv",pw,nCol-1); freeArray(p,nRow); } + return pw; } \ No newline at end of file diff --git a/Code-C/power.h b/Code-C/power.h index 85480f9..a2a134e 100644 --- a/Code-C/power.h +++ b/Code-C/power.h @@ -1,4 +1,4 @@ #include #include -void power(char* rawDataFileName); \ No newline at end of file +double *powerFunction(char* rawDataFileName); \ No newline at end of file