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

39 lines
1.4 KiB
C
Raw Normal View History

2022-06-01 12:32:04 +02:00
#include "fileGestion.h"
2022-06-09 17:34:24 +02:00
/**
* @brief function that delete nRow lign in the beginning of the file rawData.csv . This function is necessary to not deal with the same ligns over and over
*
* @param nRow number of lign in the beginning of the file rawData.csv that has to be delete
*/
void clearRawData(int nRow){
2022-06-01 12:32:04 +02:00
char buffer[256];
2022-06-02 14:29:21 +02:00
FILE *f = fopen("newFile.csv","w+");
FILE *g = fopen("rawData.csv","r");
2022-06-09 17:34:24 +02:00
for(int i = 0; i < nRow; i++){ //first the program read the first nRow ligns of the csv file but do nothing
fgets(buffer , sizeof buffer , g);
2022-06-01 12:32:04 +02:00
}
2022-06-09 17:34:24 +02:00
while(1){ //then, till the end of the csv file it copy the lign to a new csv : newFile.csv
2022-06-01 17:01:23 +02:00
if(!fgets(buffer,sizeof buffer , g)) break;
2022-06-01 12:32:04 +02:00
fprintf(f,"%s",buffer);
}
2022-06-09 17:34:24 +02:00
remove("rawData.csv"); rename("newFile.csv", "rawData.csv"); //finally we remove the original file and rename the new one to replace rawData.csv
2022-06-08 11:25:19 +02:00
fclose(f); fclose(g);
2022-06-01 12:32:04 +02:00
}
2022-06-09 17:34:24 +02:00
/**
* @brief use to write the file powerData.csv that contaign all power calculous results
*
* @param powerArray
* @param nCol size of the power array, correspond to the number of captor used
*/
void writePowerData(double powerArray[], int nCol){
2022-06-02 14:29:21 +02:00
FILE *f = fopen("powerData.csv","a+");
2022-06-09 17:34:24 +02:00
for(int i = 0 ; i < nCol ; i++){
if( i < nCol-1){
fprintf(f, "%f , ", powerArray[i]);
2022-06-02 14:29:21 +02:00
} else {
2022-06-09 17:34:24 +02:00
fprintf(f, "%f\n", powerArray[i]);
2022-06-02 14:29:21 +02:00
}
}
2022-06-08 11:25:19 +02:00
fclose(f);
2022-06-02 14:29:21 +02:00
}