Compare commits

..

No commits in common. "ee3d1315c0d2cb409f7f2219c514701ff001123f" and "8bd977ba6220aff94ef13a939853aa74267ad074" have entirely different histories.

8 changed files with 57 additions and 241 deletions

View file

@ -5,12 +5,9 @@ include(CTest)
enable_testing()
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
file(MAKE_DIRECTORY RawDataFiles)
file(MAKE_DIRECTORY Executable)
add_executable(exect fileGestion.c getArray.c average.c growthRate.c power.c queue.c simulateFlux.c main.c)
# add_executable(exect main.c simulateFlux.c queue.c power.c growthRate.c average.c getArray.c fileGestion.c)
# add_executable(exect main.c simulateFlux.c queue.c power.c growthRate.c average.c getArray.c fileGestion.c)
find_package(Threads)
target_link_libraries(exect ${CMAKE_THREAD_LIBS_INIT} m)
@ -21,19 +18,10 @@ add_executable(ctest fileGestion.c getArray.c average.c growthRate.c queue.c sim
target_link_libraries(ctest ${CMAKE_THREAD_LIBS_INIT} m)
add_test(test_queueCreateEmpty ./ctest queueCreateEmpty)
add_test(test_queueCreateE ./ctest queueCreateE)
add_test(test_queueSetCharLen ./ctest queueSetCharLen)
add_test(test_queueGetCharLen ./ctest queueGetCharLen)
add_test(test_queueSetTabChar ./ctest queueSetTabChar)
add_test(test_queueGetTabChar ./ctest queueGetTabChar)
# add_test(test_queueGetTabChar ./ctest queueGetTabChar)
add_test(test_queueSetNextE ./ctest queueSetNextE)
add_test(test_queueGetNextE ./ctest queueGetNextE)
add_test(test_queueAddLastQ ./ctest queueAddLastQ)
add_test(test_queueRmLastE ./ctest queueRmLastE)
add_test(test_queueRmFrstE ./ctest queueRmFrstE)
add_test(test_queueNextDelFrst ./ctest queueNextDelFrst)
add_test(test_queueGetCharLen ./ctest queueGetCharLen)

View file

@ -9,15 +9,12 @@
* @param p array with all the values that will be used for the calcul
* @param averageArray array where results are stocked
*/
void averageCalculation(long **p, double averageArray[])
{
for (int i = 1; i < nCol; i++)
{
void averageCalculation(long **p, double averageArray[]){
for(int i = 1; i < nCol; i++){
int j = 0;
averageArray[i] = 0;
while (j < nRowRawData)
{
averageArray[i - 1] += p[i][j];
while(j < nRowRawData){
averageArray[i] += p[i][j];
j++;
}
//printf("%f , %f\n", averageArray[i] , averageArray[i] / nRowRawData);
@ -30,21 +27,15 @@ void averageCalculation(long **p, double averageArray[])
*
* @param rawDataFileName name of the raw data file to use to realize the calcul
*/
void averageFunction(char *rawDataFileName, double **aver)
{
void averageFunction(char* rawDataFileName , double **aver){
long **p = getRawDataArray(rawDataFileName);
double averN[nCol -1];
if (p != NULL)
{
if (p != NULL)
{
if (aver == NULL)
{
if(p !=NULL){
if(p !=NULL){
if(aver == NULL){
averageCalculation(p,averN);
appendDataInFile("averageData.csv",averN,nCol-1);
}
else
{
}else{
averageCalculation(p,aver[1]);
appendDataInFile("averageData.csv",aver[1],nCol-1);
}

View file

@ -48,22 +48,6 @@ bool test_queueCreateEmpty()
return EXIT_SUCCESS;
}
bool test_queueCreateE()
{
const char tabChar[12] = "PetitNavire\0";
Pqueue new = queueCreateE(12, tabChar);
const char *test = queueGetTabChar(new);
assert(queueGetCharLen(new) == 12);
assert(test != NULL);
assert(strcmp(test, tabChar) == 0);
assert(queueGetNextE(new) == NULL);
queueRmFrstE(new);
return EXIT_SUCCESS;
}
bool test_queueSetCharLen()
{
Pqueue new = queueCreateEmpty();
@ -79,38 +63,20 @@ bool test_queueSetCharLen()
return EXIT_SUCCESS;
}
bool test_queueSetTabChar()
{
// Set and Get tabChar are similar because use for same test
Pqueue new = queueCreateEmpty();
const char tabChar[12] = "PetitNavire\0";
queueSetTabChar(new, 12, tabChar);
const char *test = queueGetTabChar(new);
assert(queueGetCharLen(new) == 12);
assert(test != NULL);
assert(strcmp(test, tabChar) == 0);
assert(queueGetNextE(new) == NULL);
queueRmFrstE(new);
return EXIT_SUCCESS;
}
bool test_queueGetTabChar()
{
{ // Define later
Pqueue new = queueCreateEmpty();
const char tabChar[12] = "PetitNavire\0";
queueSetTabChar(new, 12, tabChar);
const char *test = queueGetTabChar(new);
// const char tabChar[12] = "PetitNavire\0"
queueSetTabChar(new, 13, NULL);
assert(queueGetCharLen(new) == 12);
assert(test != NULL);
assert(strcmp(test, tabChar) == 0);
assert(queueGetCharLen(new) == 13);
assert(queueGetTabChar(new) == NULL);
assert(queueGetNextE(new) == NULL);
// queueDelAll(new);
queueRmFrstE(new);
return EXIT_SUCCESS;
}
@ -154,70 +120,6 @@ bool test_queueGetCharLen()
return EXIT_SUCCESS;
}
bool test_queueAddLastQ()
{
Pqueue new = queueCreateEmpty(), next = NULL;
const char tabChar[12] = "PetitNavire\0";
queueAddLastQ(new, tabChar, 12);
next = queueGetNextE(new);
assert(next != NULL);
assert(queueGetCharLen(next) == 12);
assert(strcmp(queueGetTabChar(next), tabChar) == 0);
assert(queueGetNextE(next) == NULL);
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueRmLastE()
{
Pqueue new = queueCreateEmpty();
const char tabChar[12] = "PetitNavire\0";
queueAddLastQ(new, tabChar, 12);
queueAddLastQ(new, tabChar, 12);
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
queueRmLastE(new);
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) == NULL);
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueRmFrstE()
{
Pqueue new = queueCreateEmpty(), second;
const char tabChar[12] = "PetitNavire\0";
queueAddLastQ(new, tabChar, 12);
queueAddLastQ(new, tabChar, 12);
second = queueGetNextE(new);
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
new = queueRmFrstE(new);
assert((new == second) && (queueGetNextE(new) != NULL) && (queueGetNextE(queueGetNextE(new)) == NULL));
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueNextDelFrst()
{
Pqueue new = queueCreateEmpty(), second;
const char tabChar[12] = "PetitNavire\0";
queueAddLastQ(new, tabChar, 12);
queueAddLastQ(new, tabChar, 12);
second = queueGetNextE(new);
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
new = queueNextDelFrst(new);
assert((new == second) && (queueGetNextE(new) != NULL) && (queueGetNextE(queueGetNextE(new)) == NULL));
queueDelAll(new);
return EXIT_SUCCESS;
}
/***************** Main test start *****************/
void usage(int argc, char *argv[])
{
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
@ -233,13 +135,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "=> Start test \"%s\"\n", argv[1]);
int ok = 1;
if (strcmp("queueCreateEmpty", argv[1]) == 0)
{
ok = test_queueCreateEmpty();
}
else if (strcmp("queueCreateE", argv[1]) == 0)
{
ok = test_queueCreateE();
}
else if (strcmp("queueSetCharLen", argv[1]) == 0)
{
ok = test_queueSetCharLen();
@ -263,28 +159,8 @@ int main(int argc, char *argv[])
else if (strcmp("queueGetTabChar", argv[1]) == 0)
{
ok = test_queueGetTabChar();
}
else if (strcmp("queueSetTabChar", argv[1]) == 0)
{
ok = test_queueSetTabChar();
}
else if (strcmp("queueAddLastQ", argv[1]) == 0)
{
ok = test_queueAddLastQ();
}
else if (strcmp("queueRmLastE", argv[1]) == 0)
{
ok = test_queueRmLastE();
}
else if (strcmp("queueRmFrstE", argv[1]) == 0)
{
ok = test_queueRmFrstE();
}
else if (strcmp("queueNextDelFrst", argv[1]) == 0)
{
ok = test_queueNextDelFrst();
// }else if(strcmp("default_solution",argv[1]) == 0){
// ok = test_game_default_solution();
// }else if(strcmp("update_flags",argv[1]) == 0){
// ok = test_game_update_flags();
// }else if(strcmp("default_solution",argv[1]) == 0){
// ok = test_game_default_solution();
}

View file

@ -49,7 +49,6 @@ void *threadCalculAverage(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char *fileName;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
@ -125,7 +124,7 @@ void *threadCalculGrowthRate(void *vargp)
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignPw, "growthRateAv.csv");
}
// remove(fileName);
remove(fileName);
}
}
return NULL;
@ -151,23 +150,12 @@ int main(int argc, char **argv)
pthread_t rawData;
if (pthread_create(&rawData, NULL, threadSimulateFlux, "threadSimulflux") != 0)
{
perror("threadSimulflux() error");
perror("pthread_create() 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_t calcul;
pthread_create(&calcul, NULL, threadCalculGrowthRate, "threadCalcul");
pthread_exit(NULL);
}

View file

@ -37,7 +37,7 @@ void powerCalculation(long **p, double powerArray[])
void powerFunction(char *rawDataFileName, double **pw)
{
long **p = getRawDataArray(rawDataFileName);
// printArrayData(p, nRowRawData, nCol);
printArrayData(p, nRowRawData, nCol);
double pww[nCol - 1];
if (p != NULL)
{

View file

@ -2,7 +2,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "queue.h"
/**
@ -145,15 +144,15 @@ Pqueue queueCreateE(int lenChar, const char *_tabChar)
Pqueue queueRmLastE(Pqueue elem)
{
assert(elem);
Pqueue tmp = elem, current = NULL;
while (tmp->pNextE != NULL)
Pqueue tmp = elem, previous = NULL;
while (elem->pNextE != NULL)
{
current = tmp;
previous = tmp;
tmp = queueGetNextE(tmp);
}
free(tmp->tabChar);
free(tmp);
current->pNextE = NULL;
previous->pNextE = NULL;
return elem;
}
@ -161,18 +160,15 @@ Pqueue queueRmLastE(Pqueue elem)
* @brief remove and free the first element of queue
*
* @param elem target to remove (the element need to be the first)
* @return next element of the queue
*/
Pqueue queueRmFrstE(Pqueue elem)
void queueRmFrstE(Pqueue elem)
{
assert(elem);
Pqueue next = queueGetNextE(elem);
if (elem->tabChar != NULL)
{
free(elem->tabChar);
}
free(elem);
return next;
}
/**
@ -199,31 +195,16 @@ Pqueue queueNextDelFrst(Pqueue elem)
void queueAddLastQ(Pqueue elem, const char *str, int len)
{
assert(elem);
bool str1 = true;
if (len == 0)
{
str = false;
}
else
{
assert(str);
}
Pqueue current = elem, next = NULL;
while (current->pNextE != NULL)
Pqueue next = elem, previous = NULL;
while (next->pNextE != NULL)
{
current = queueGetNextE(current);
previous = next;
next = queueGetNextE(next);
}
if (str1 == true)
{
previous = next;
next = queueCreateE(len, str);
}
else
{
next = queueCreateEmpty();
}
queueSetNextE(current, next);
queueSetNextE(previous, next);
}
/**

View file

@ -91,9 +91,8 @@ Pqueue queueRmLastE(Pqueue elem);
* @brief remove and free the first element of queue
*
* @param elem target to remove (the element need to be the first)
* @return the next element of elem
*/
Pqueue queueRmFrstE(Pqueue elem); // same of queueNextDelFrst()
void queueRmFrstE(Pqueue elem);
/**
* @brief delete the first value and return the next value
@ -101,7 +100,7 @@ Pqueue queueRmFrstE(Pqueue elem); // same of queueNextDelFrst()
* @param elem
* @return Pqueue
*/
Pqueue queueNextDelFrst(Pqueue elem); // same of queueRmFrstE()
Pqueue queueNextDelFrst(Pqueue elem);
/************** print function **************/

View file

@ -1,9 +1,9 @@
#include "simulateFlux.h"
#include "initialParameters.h"
#include "queue.h"
//#include <linux/time.h>
#include <time.h>
#include <errno.h>
#include "time.h"
/**
* @brief convert an interger N into a char*
@ -46,7 +46,7 @@ char *convertIntegerToChar(int N)
*/
char *createNewRawDataFileName()
{
char *fileName = "RawDataFiles/RawData";
char *fileName = "../RawDataFiles/RawData";
char *extension = ".csv\0";
char *fileNumber = convertIntegerToChar(cptFile);
// char *fileNumber;
@ -94,7 +94,7 @@ int64_t millis()
{
struct timespec now;
timespec_get(&now, TIME_UTC);
return ((int64_t)((int64_t)now.tv_sec) * 1000 + ((int64_t)now.tv_nsec) / 1000000);
return ((int64_t)now.tv_sec) * 1000 + ((int64_t)now.tv_nsec) / 1000000;
}
int lastIndexCaptor()
@ -133,7 +133,6 @@ bool writeOneRawData(FILE *rawDataFile)
fprintf(timeFile, "%ld\n", millis());
fclose(timeFile);
fprintf(rawDataFile, "%ld,", millis());
if (strncmp(buff, "#################\n", (size_t)18) == 0)
{
if (!(fread(&buff2, 18, 1, stdin)))
@ -175,12 +174,7 @@ bool writeOneRawData(FILE *rawDataFile)
}
}
cptData++;
// simul freq here
// struct timespec ts;
// ts.tv_sec = 0;
// ts.tv_nsec = 4 * 1000000;
// nanosleep(&ts, &ts);
// sleep(0.004); //simul freq here
cptValue++;
return true;
@ -201,7 +195,6 @@ void *threadSimulateFlux(void *vargp)
while (writeOneRawData(rawDataFile))
{
if (cptData == nRowRawData)
{
fclose(rawDataFile);