diff --git a/Code-C/Makefile b/Code-C/Makefile index abeb975..6107882 100644 --- a/Code-C/Makefile +++ b/Code-C/Makefile @@ -1,7 +1,7 @@ CC = gcc all: - $(CC) fileGestion.c getArray.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main + $(CC) fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main # $(CC) 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 new file mode 100644 index 0000000..7d228fd --- /dev/null +++ b/Code-C/average.c @@ -0,0 +1,32 @@ +#include "average.h" +#include "getArray.h" +#include "fileGestion.h" +#include "initialParameters.h" +#include "queue.h" +#include + +void averageCalculation(long **p, double averageArray[] , int N, int M){ + for(int i = 0; i < M-1; i++){ + int j = 0; + averageArray[i] = 0; + while(j < N){ + averageArray[i] += p[i][j]; + j++; + } + averageArray[i] /= N; + //printf("%f\n", powerArray[i]); + } +} +bool average(char* rawDataFileName,int N , int M){ + long **p = getRawDataArray(rawDataFileName,N, M); + double aver[8]; + if(p !=NULL){ + averageCalculation(p,aver,N,M); + writeDataInFile("averageData.csv",aver,8); + freeArray(p,N); + return true; + } + else{ + return false; + } +} \ No newline at end of file diff --git a/Code-C/average.h b/Code-C/average.h new file mode 100644 index 0000000..7ae6f90 --- /dev/null +++ b/Code-C/average.h @@ -0,0 +1,4 @@ +#include +#include + +bool average(char* rawDataFileName,int N , int M); \ No newline at end of file diff --git a/Code-C/fileGestion.c b/Code-C/fileGestion.c index 5a54c0c..1d1d73d 100644 --- a/Code-C/fileGestion.c +++ b/Code-C/fileGestion.c @@ -26,8 +26,8 @@ void clearRawData(int nRow){ * @param powerArray * @param nCol size of the power array, correspond to the number of captor used */ -void writePowerData(double powerArray[], int nCol){ - FILE *f = fopen("powerData.csv","a+"); +void writeDataInFile(char* fileName , double powerArray[], int nCol){ + FILE *f = fopen(fileName,"a+"); for(int i = 0 ; i < nCol ; i++){ if( i < nCol-1){ fprintf(f, "%f , ", powerArray[i]); diff --git a/Code-C/fileGestion.h b/Code-C/fileGestion.h index afebd10..b001d93 100644 --- a/Code-C/fileGestion.h +++ b/Code-C/fileGestion.h @@ -5,4 +5,4 @@ void clearRawData(int N); -void writePowerData(double a[], int N); \ No newline at end of file +void writeDataInFile(char* fileName , double a[], int N); \ No newline at end of file diff --git a/Code-C/main b/Code-C/main index b7250cc..45755a3 100755 Binary files a/Code-C/main and b/Code-C/main differ diff --git a/Code-C/main.c b/Code-C/main.c index 86ff80a..de1b7eb 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -4,9 +4,10 @@ #include "power.h" #include "initialParameters.h" #include "queue.h" +#include "average.h" bool rawDataWriteFlag; -int nRow = 100000; +int nRow = 500; int nCol = 9; double freqEch = 250; @@ -21,7 +22,7 @@ int cptFile = 1; double period = 0; double invTimeBandWidth = 0; -void *threadCalcul(void *vargp){ +void *threadCalculPower(void *vargp){ Pqueue rawDataQueue = firstRawDataQueue; char* fileName; while(rawDataWriteFlag){ @@ -29,6 +30,34 @@ void *threadCalcul(void *vargp){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); power(fileName,nRow,nCol,period,invTimeBandWidth); + remove(fileName); + } + } +} + +void *threadCalculAverage(void *vargp){ + Pqueue rawDataQueue = firstRawDataQueue; + char* fileName; + while(rawDataWriteFlag){ + while(queueGetNextE(rawDataQueue) != NULL){ + rawDataQueue = queueGetNextE(rawDataQueue); + fileName = queueGetTabChar(rawDataQueue); + average(fileName,nRow,nCol); + remove(fileName); + } + } +} + +void *threadCalculBoth(void *vargp){ + Pqueue rawDataQueue = firstRawDataQueue; + char* fileName; + while(rawDataWriteFlag){ + while(queueGetNextE(rawDataQueue) != NULL){ + rawDataQueue = queueGetNextE(rawDataQueue); + fileName = queueGetTabChar(rawDataQueue); + power(fileName,nRow,nCol,period,invTimeBandWidth); + average(fileName,nRow,nCol); + remove(fileName); } } } @@ -45,7 +74,7 @@ int main(int argc , char** argv){ pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData); pthread_t calcul; - pthread_create(&calcul , NULL, threadCalcul, (void *)&calcul); + pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul); pthread_exit(NULL); } \ No newline at end of file diff --git a/Code-C/power.c b/Code-C/power.c index 7852277..6d836e6 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -24,9 +24,8 @@ bool power(char* rawDataFileName,int N , int M, double periode , double invTimeB double pw[8]; if(p !=NULL){ powerCalculation(p,pw,N,M,periode,invTimeBandwidth); - writePowerData(pw,8); + writeDataInFile("powerData.csv",pw,8); freeArray(p,N); - remove(rawDataFileName); return true; } else{ diff --git a/Code-C/power.h b/Code-C/power.h index 2e0e3ad..51e4dae 100644 --- a/Code-C/power.h +++ b/Code-C/power.h @@ -1,5 +1,4 @@ #include #include -bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth); -void *threadCalcul(void *vargp); \ No newline at end of file +bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth); \ No newline at end of file diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index 28e1980..92935c9 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -105,7 +105,7 @@ bool writeOneRawData(FILE *rawDataFile){ } } cptData++; - //sleep(0.004); //simul la freq ech + sleep(0.004); //simul la freq ech return true; } else {