diff --git a/Code-C/Makefile b/Code-C/Makefile index de97bc3..abeb975 100644 --- a/Code-C/Makefile +++ b/Code-C/Makefile @@ -1,8 +1,7 @@ CC = gcc all: -# rm powerData.csv -# $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main $(CC) fileGestion.c getArray.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main -# $(CC) queue.c -o queue + +# $(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/main b/Code-C/main index 60acc4f..f483ae6 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 88ad736..9635435 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -21,20 +21,31 @@ int cptFile = 1; double period = 0; double invTimeBandWidth = 0; +void *threadCalcul(void *vargp){ + printf("start thread calcul\n"); + Pqueue rawDataQueue = firstRawDataQueue; + while(queueGetNextE(rawDataQueue) != NULL){ + printf("wile calcul\n"); + //pthread_mutex_lock(&mutex); + power(queueGetTabChar(rawDataQueue),nRow,nCol,period,invTimeBandWidth); + /*remove(queueGetTabChar(rawDataQueue)); + rawDataQueue = queueRmFrstE(rawDataQueue);*/ + + //pthread_mutex_unlock(&mutex); + } +} int main(int argc , char** argv){ period = 1 / freqEch; invTimeBandWidth = 1 /(nRow * period); - firstRawDataQueue = NULL; // change this for create empty + firstRawDataQueue = queueCreateEmpty(); // change this for create empty pthread_t rawData; pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData); - pthread_t power; - pthread_create(&power , NULL, threadCalcul, (void *)&power); + pthread_t calcul; + pthread_create(&calcul , NULL, threadCalcul, (void *)&calcul); pthread_exit(NULL); - - } \ No newline at end of file diff --git a/Code-C/power.c b/Code-C/power.c index b0aa00c..52153ec 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -30,18 +30,4 @@ bool power(char* rawDataFileName,int N , int M, double periode , double invTimeB else{ return false; } -} -void *threadCalcul(void *vargp){ - Pqueue rawDataQueue = firstRawDataQueue; - printf("print in power of first eleme in queue : \n"); - printE(firstRawDataQueue); - while(rawDataQueue == NULL || getNextE(rawDataQueue) != NULL){ - //pthread_mutex_lock(&mutex); - while(power(gettabChar(rawDataQueue),nRow,nCol,period,invTimeBandWidth) == false){ - remove(gettabChar(rawDataQueue)); - rawDataQueue = rmFrstE(rawDataQueue); - } - //pthread_mutex_unlock(&mutex); - //delay(10); - } } \ No newline at end of file diff --git a/Code-C/power.h b/Code-C/power.h index 474b206..2e0e3ad 100644 --- a/Code-C/power.h +++ b/Code-C/power.h @@ -1,5 +1,5 @@ #include #include -//bool power(int N , int M, double periode , double timeBandwidth); +bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth); void *threadCalcul(void *vargp); \ No newline at end of file diff --git a/Code-C/queue.c b/Code-C/queue.c index 8628b4d..3aff95f 100644 --- a/Code-C/queue.c +++ b/Code-C/queue.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "queue.h" /** @@ -12,7 +13,7 @@ */ struct queue { int charLen; - char * tabChar; + char* tabChar; Pqueue pNextE; }; @@ -39,9 +40,8 @@ Pqueue queueCreateEmpty(){ * * @param elem targeted element * @param _charLen size of char array - * @return Pqueue */ -Pqueue queueSetCharLen(Pqueue elem, int _charLen){ +void queueSetCharLen(Pqueue elem, int _charLen){ assert(elem); elem->charLen = _charLen; } @@ -52,17 +52,27 @@ Pqueue queueSetCharLen(Pqueue elem, int _charLen){ * @param elem targeted element * @param _charLen char array size * @param _tabChar pointer to static char array - * @return Pqueue */ -Pqueue queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){ +void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){ assert(elem); assert(_tabChar); elem->charLen = _charLen; - elem->tabChar = (char *) malloc(_charLen * sizeof(char)); + elem->tabChar = calloc(_charLen , sizeof(char)); for(int i = 0; i < _charLen; i++){ - new->tabChar[i] = _tabChar[i]; + elem->tabChar[i] = _tabChar[i]; } } +/** + * @brief set next pqueue element + * + * @param elem target element + * @param next next element + */ +void queueSetNextE(Pqueue elem , Pqueue next){ + assert(elem); + assert(next); + elem -> pNextE = next; +} /************ GETTER ************/ @@ -115,12 +125,6 @@ Pqueue queueCreateE(int lenChar, const char* _tabChar){ return new; } -void setNextE(Pqueue elem , Pqueue next){ - assert(elem); - assert(next); - elem -> pNextE = next; -} - /** * @brief remove and free the last element of queue * @@ -175,18 +179,17 @@ Pqueue queueNextDelFrst(Pqueue elem){ * @param len the lenght of char array * @return Pqueue pointer to the last element */ -Pqueue queueAddLastQ(Pqueue elem, const char* str, int len){ +void queueAddLastQ(Pqueue elem, const char* str, int len){ assert(elem); assert(str); - Pqueue tmp = elem, previous = NULL; - while(elem->pNextE != NULL){ - previous = tmp; - tmp = queueGetNextE(tmp); + Pqueue next = elem, previous = NULL; + while(next->pNextE != NULL){ + previous = next; + next = queueGetNextE(next); } - tmp = queueCreateE(len); - tmp->tabChar = str; - tmp->charLen = len; - return tmp; + previous = next; + next = queueCreateE(len,str); + queueSetNextE(previous,next); } /** @@ -196,12 +199,21 @@ Pqueue queueAddLastQ(Pqueue elem, const char* str, int len){ */ void queuePrintE(Pqueue elem){ Pqueue next = queueGetNextE(elem); - printf("File Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen ); + printf("\nFile Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen ); if(next != NULL){ printf("Next File : %s\n", next ->tabChar); } else{ - printf("No nextFile existing\n"); + printf("No nextFile existing (null)\n"); + } +} + +void queuePrintWholeQ(Pqueue firstE){ + queuePrintE(firstE); + Pqueue elem = firstE; + while(queueGetNextE(elem) != NULL){ + elem = queueGetNextE(elem); + queuePrintE(elem); } } diff --git a/Code-C/queue.h b/Code-C/queue.h index c31f2ad..198710c 100644 --- a/Code-C/queue.h +++ b/Code-C/queue.h @@ -1,28 +1,27 @@ typedef struct queue *Pqueue; //Constructors -Pqueue createE(int lenChar, const char* _tabChar); -Pqueue createEmpty(); +Pqueue queueCreateE(int lenChar, const char* _tabChar); +Pqueue queueCreateEmpty(); + //Getters -Pqueue getNextE(Pqueue elem); -Pqueue getNextE(Pqueue elem); -char * gettabChar(Pqueue elem); +Pqueue queueGetNextE(Pqueue elem); +int queueGetCharLen(Pqueue elem); +char* queueGetTabChar(Pqueue elem); //Setters -void setCharLen(Pqueue elem , int _charLen); -void setTabChar(Pqueue elem , int _charLen , char *_tabChar); -void setNextE(Pqueue elem , Pqueue next); +void queueSetCharLen(Pqueue elem, int _charLen); +void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar); +void queueSetNextE(Pqueue elem , Pqueue next); -Pqueue addLastQ(Pqueue elem, const char* str, int len); +void queueAddLastQ(Pqueue elem, const char* str, int len); //Removers -Pqueue rmLastE(Pqueue elem); -Pqueue rmFrstE(Pqueue elem); - -Pqueue nextDelFrst(Pqueue elem); - -Pqueue nextDelFrst(Pqueue elem); +Pqueue queueRmLastE(Pqueue elem); +Pqueue queueRmFrstE(Pqueue elem); +Pqueue queueNextDelFrst(Pqueue elem); //print function -void printE(Pqueue elem); \ No newline at end of file +void queuePrintE(Pqueue elem); +void queuePrintWholeQ(Pqueue firstE); \ No newline at end of file diff --git a/Code-C/rmRawData.sh b/Code-C/rmRawData.sh new file mode 100644 index 0000000..d734d9a --- /dev/null +++ b/Code-C/rmRawData.sh @@ -0,0 +1,6 @@ +#!/bin/bash +cd ../RawDataFiles +for i in * +do + rm $i +done \ No newline at end of file diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index 0eea048..51173d8 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -30,18 +30,18 @@ char* convertIntegerToChar(int N) char *createNewRawDataFileName(){ char *fileName = "../RawDataFiles/RawData"; - char *extension = ".csv"; + char *extension = ".csv\0"; char *fileNumber = convertIntegerToChar(cptFile); char fileNameNumber[strlen(fileName)+strlen(fileNumber)]; - char *fullFileName = malloc( (strlen(fileNameNumber)+strlen(extension)) * sizeof(char*) ); + char *fullFileName = malloc((strlen(fileNameNumber)+strlen(extension)) * sizeof(char*)); strcpy( fileNameNumber, fileName ); strcat( fileNameNumber, fileNumber ); strcpy( fullFileName, fileNameNumber ); strcat( fullFileName, extension ); - + return fullFileName; } @@ -114,21 +114,21 @@ bool writeOneRawData(FILE *rawDataFile){ } void *simulateFlux(void *vargp){ + printf("start thread simul\n"); + char *fileName = createNewRawDataFileName(); FILE *rawDataFile = fopen(fileName,"w+"); - Pqueue rawDataQueue = createE(strlen(fileName)); while(writeOneRawData(rawDataFile)){ if(cptData == nRow){ - fclose(rawDataFile); + printf("in if\n"); cptData = 0; cptFile++; //create struct here - char *fileName = createNewRawDataFileName(); + queueAddLastQ(firstRawDataQueue , fileName , strlen(fileName)); + //prepare next file now + fileName = createNewRawDataFileName(); FILE *rawDataFile = fopen(fileName,"w+"); - rawDataQueue = addLastQ(rawDataQueue , fileName , strlen(fileName)); - printE(rawDataQueue); - } } } diff --git a/Code-C/simulateFlux.h b/Code-C/simulateFlux.h index dd2b3d7..de271bd 100644 --- a/Code-C/simulateFlux.h +++ b/Code-C/simulateFlux.h @@ -16,6 +16,6 @@ typedef struct { extern int cptData; extern int cptFile; -char* convertIntegerToChar(int N); +char *convertIntegerToChar(int N); bool writeOneRawData(FILE *f); void *simulateFlux(void *vargp); \ No newline at end of file