trying to debug power

This commit is contained in:
quentin.perret 2022-06-14 18:01:52 +02:00
parent 9bb5e5e99d
commit f9a6f00972
13 changed files with 58 additions and 66 deletions

View file

@ -1,7 +1,4 @@
CC = gcc CC = gcc
all: all:
$(CC) fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main $(CC) -g 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

View file

@ -8,18 +8,16 @@
* *
* @param p array with all the values that will be used for the calcul * @param p array with all the values that will be used for the calcul
* @param averageArray array where results are stocked * @param averageArray array where results are stocked
* @param N number of rows in p
* @param M number of columns in p
*/ */
void averageCalculation(long **p, double averageArray[] , int N, int M){ void averageCalculation(long **p, double averageArray[]){
for(int i = 0; i < M-1; i++){ for(int i = 0; i < nCol-1; i++){
int j = 0; int j = 0;
averageArray[i] = 0; averageArray[i] = 0;
while(j < N){ while(j < nRow){
averageArray[i] += p[i][j]; averageArray[i] += p[i][j];
j++; j++;
} }
averageArray[i] /= N; averageArray[i] /= nRow;
//printf("%f\n", powerArray[i]); //printf("%f\n", powerArray[i]);
} }
} }
@ -28,15 +26,13 @@ void averageCalculation(long **p, double averageArray[] , int N, int M){
* @brief function that realize all the action to write one lign in the file averageData.csv * @brief function that realize all the action to write one lign in the file averageData.csv
* *
* @param rawDataFileName name of the raw data file to use to realize the calcul * @param rawDataFileName name of the raw data file to use to realize the calcul
* @param N number of rows in the file
* @param M number of columns in the file
*/ */
void average(char* rawDataFileName,int N , int M){ void average(char* rawDataFileName){
long **p = getRawDataArray(rawDataFileName,N, M); long **p = getRawDataArray(rawDataFileName);
double aver[8]; double aver[nCol -1];
if(p !=NULL){ if(p !=NULL){
averageCalculation(p,aver,N,M); averageCalculation(p,aver);
writeDataInFile("averageData.csv",aver,8); appendDataInFile("averageData.csv",aver,nCol-1);
freeArray(p,N); freeArray(p,nRow);
} }
} }

View file

@ -1,4 +1,4 @@
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
void average(char* rawDataFileName,int N , int M); void average(char* rawDataFileName);

View file

@ -26,7 +26,7 @@ void clearRawData(int nRow){
* @param array array that contaign all the values to write in the file * @param array array that contaign all the values to write in the file
* @param nCol size of the array (correspond to the number of captor used) * @param nCol size of the array (correspond to the number of captor used)
*/ */
void writeDataInFile(char* fileName , double array[], int nCol){ void appendDataInFile(char* fileName , double array[], int nCol){
FILE *f = fopen(fileName,"a+"); FILE *f = fopen(fileName,"a+");
for(int i = 0 ; i < nCol ; i++){ for(int i = 0 ; i < nCol ; i++){
if( i < nCol-1){ if( i < nCol-1){
@ -37,4 +37,3 @@ void writeDataInFile(char* fileName , double array[], int nCol){
} }
fclose(f); fclose(f);
} }

View file

@ -5,4 +5,4 @@
void clearRawData(int N); void clearRawData(int N);
void writeDataInFile(char* fileName , double a[], int N); void appendDataInFile(char* fileName , double a[], int N);

View file

@ -1,5 +1,6 @@
#include "getArray.h" #include "getArray.h"
#include "fileGestion.h" #include "fileGestion.h"
#include "initialParameters.h"
//#include <string.h> //#include <string.h>
long **get(int N, int M) /* Allocate the array */ long **get(int N, int M) /* Allocate the array */
@ -55,7 +56,7 @@ void printArrayData(long** p, int N, int M) {
* @return true if the array contaign no NULL element * @return true if the array contaign no NULL element
* @return false if at least one element is null * @return false if at least one element is null
*/ */
bool checkArrayFullyFill(long **p, int N , int M){ bool checkArrayFullyFill(long **p, int N){
for(int i = 0 ; i < N ; i++){ for(int i = 0 ; i < N ; i++){
if(p[i][0] == '\0'){ return false; } if(p[i][0] == '\0'){ return false; }
} }
@ -83,11 +84,13 @@ void freeArray(long **p, int N) {
* @param M numbers of columns to have i the array * @param M numbers of columns to have i the array
* @return long** the array fill with raw data * @return long** the array fill with raw data
*/ */
long **getRawDataArray(char* rawDataFileName , int N , int M){ long **getRawDataArray(char* rawDataFileName){
long **p; long **p;
p = get(N, M); p = get(nRow, nCol);
fillArrayWithRawData(rawDataFileName,p ,N, M); printf("before fill\n");
if(checkArrayFullyFill(p,N,M)){ fillArrayWithRawData(rawDataFileName,p ,nRow, nCol);
printf("after fill\n");
if(checkArrayFullyFill(p,nRow, nCol)){
//clearRawData(N); //clearRawData(N);
return p; return p;
} }

View file

@ -5,7 +5,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <inttypes.h> #include <inttypes.h>
long **getRawDataArray(char *rawDataFileName, int N , int M); long **getRawDataArray(char *rawDataFileName);
void printArrayData(long** p, int N, int M); void printArrayData(long** p, int N, int M);
void freeArray(long **p, int N); void freeArray(long **p, int N);
bool checkArrayFullyFill(long **p, int N , int M); bool checkArrayFullyFill(long **p, int N , int M);

View file

@ -9,7 +9,6 @@ extern double freqEch;
extern double period; extern double period;
extern double invTimeBandWidth; extern double invTimeBandWidth;
extern int selectionCaptors[]; extern bool selectionCaptors[];
extern int sizeSelectionArray;
extern Pqueue firstRawDataQueue; extern Pqueue firstRawDataQueue;

Binary file not shown.

View file

@ -8,13 +8,12 @@
bool rawDataWriteFlag; bool rawDataWriteFlag;
int nRow = 500; int nRow = 500;
int nCol = 9; int nCol = 1;
double freqEch = 250; double freqEch = 250;
Pqueue firstRawDataQueue; Pqueue firstRawDataQueue;
int selectionCaptors[] = {1,2,3,4,5,6,7,8}; bool selectionCaptors[] = {true,false,true,false,false,false,true,false};
int sizeSelectionArray = 8;
int cptData = 0; int cptData = 0;
int cptFile = 1; int cptFile = 1;
@ -29,7 +28,7 @@ void *threadCalculPower(void *vargp){
while(queueGetNextE(rawDataQueue) != NULL){ while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue); rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue); fileName = queueGetTabChar(rawDataQueue);
power(fileName,nRow,nCol,period,invTimeBandWidth); power(fileName);
remove(fileName); remove(fileName);
} }
} }
@ -42,7 +41,7 @@ void *threadCalculAverage(void *vargp){
while(queueGetNextE(rawDataQueue) != NULL){ while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue); rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue); fileName = queueGetTabChar(rawDataQueue);
average(fileName,nRow,nCol); average(fileName);
remove(fileName); remove(fileName);
} }
} }
@ -55,15 +54,23 @@ void *threadCalculBoth(void *vargp){
while(queueGetNextE(rawDataQueue) != NULL){ while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue); rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue); fileName = queueGetTabChar(rawDataQueue);
power(fileName,nRow,nCol,period,invTimeBandWidth); power(fileName);
average(fileName,nRow,nCol); average(fileName);
remove(fileName); remove(fileName);
} }
} }
} }
int main(int argc , char** argv){ int main(int argc , char** argv){
for(int i = 0 ; i < 8 ; i++){
if(selectionCaptors[i]){
nCol++;
}
}
printf("%d\n" , nCol);
rawDataWriteFlag = true; rawDataWriteFlag = true;
period = 1 / freqEch; period = 1 / freqEch;
@ -74,7 +81,7 @@ int main(int argc , char** argv){
pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData); pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData);
pthread_t calcul; pthread_t calcul;
pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul); pthread_create(&calcul , NULL, threadCalculPower, (void *)&calcul);
pthread_exit(NULL); pthread_exit(NULL);
} }

View file

@ -9,21 +9,17 @@
* *
* @param p array with all the values that will be used for the calcul * @param p array with all the values that will be used for the calcul
* @param powerArray array where results are stocked * @param powerArray array where results are stocked
* @param N number of rows in p
* @param M number of columns in p
*/ */
void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){ void powerCalculation(long **p, double powerArray[]){
for(int i = 0; i < M-1; i++){ for(int i = 1; i < nCol; i++){
int j = 0; int j = 0;
powerArray[i] = 0; powerArray[i] = 0;
while(j < N-1){ while(j < nRow-1){
double aire = ( pow(p[j][i+1],2) + pow(p[j+1][i+1],2) ) / 2 * period; double aire = ( pow(p[j][i],2) + pow(p[j+1][i],2) ) / 2 * period;
//printf("aire [%d,%d] : %f\n",j,i,aire);
powerArray[i] += aire; powerArray[i] += aire;
j++; j++;
} }
powerArray[i] *= invTimeBandwidth; powerArray[i] *= invTimeBandWidth;
//printf("%f\n", powerArray[i]);
} }
} }
@ -34,16 +30,12 @@ void powerCalculation(long **p, double powerArray[] , int N, int M , double peri
* @param N number of rows in the file * @param N number of rows in the file
* @param M number of columns in the file * @param M number of columns in the file
*/ */
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){ void power(char* rawDataFileName){
long **p = getRawDataArray(rawDataFileName,N, M); long **p = getRawDataArray(rawDataFileName);
double pw[8]; double pw[nCol-1];
if(p !=NULL){ if(p !=NULL){
powerCalculation(p,pw,N,M,periode,invTimeBandwidth); powerCalculation(p,pw);
writeDataInFile("powerData.csv",pw,8); appendDataInFile("powerData.csv",pw,nCol-1);
freeArray(p,N); freeArray(p,nRow);
return true;
}
else{
return false;
} }
} }

View file

@ -1,4 +1,4 @@
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth); void power(char* rawDataFileName);

View file

@ -19,7 +19,7 @@ char* convertIntegerToChar(int N)
} }
char* arr; char* arr;
char arr1[digit]; char arr1[digit];
arr = (char*)malloc(digit); arr = (char*)malloc(digit*sizeof(char));
int index = 0; int index = 0;
while (N) { while (N) {
arr1[++index] = N % 10 + '0'; arr1[++index] = N % 10 + '0';
@ -42,6 +42,9 @@ char *createNewRawDataFileName(){
char *fileName = "../RawDataFiles/RawData"; char *fileName = "../RawDataFiles/RawData";
char *extension = ".csv\0"; char *extension = ".csv\0";
char *fileNumber = convertIntegerToChar(cptFile); char *fileNumber = convertIntegerToChar(cptFile);
//char *fileNumber;
//sprintf(fileNumber, "%d", cptFile);
//printf("%s\n" , fileNumber);
char fileNameNumber[strlen(fileName)+strlen(fileNumber)]; char fileNameNumber[strlen(fileName)+strlen(fileNumber)];
char *fullFileName = malloc((strlen(fileNameNumber)+strlen(extension)) * sizeof(char*)); char *fullFileName = malloc((strlen(fileNameNumber)+strlen(extension)) * sizeof(char*));
@ -94,21 +97,18 @@ bool writeOneRawData(FILE *rawDataFile){
uint32_t valbin[8]; uint32_t valbin[8];
quartet value; quartet value;
if(fread(&buff, 26, 1, stdin)) { if(fread(&buff, 26, 1, stdin)) {
fprintf(rawDataFile , "%d,", millis()); fprintf(rawDataFile , "%d,", millis());
if (strncmp(buff, "#################\n", (size_t)18) == 0) { if (strncmp(buff, "#################\n", (size_t)18) == 0) {
if (!(fread(&buff2, 18, 1, stdin))) { if (!(fread(&buff2, 18, 1, stdin))) {
fprintf(stderr, "Erreur lecture après ###...#"); fprintf(stderr, "Erreur lecture après ###...#");
return 2;
} else { } else {
strncpy(buff, &buff[18], 8); strncpy(buff, &buff[18], 8);
strncpy(&buff[8], buff2, 18); strncpy(&buff[8], buff2, 18);
} }
} }
int maxCApteurNb = maxInArray(selectionCaptors,sizeSelectionArray);
for (int i = 1; i < 9; i++){ for (int i = 1; i < 9; i++){
if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){ if(selectionCaptors[i]){
value.octet1 = buff[3*i+1]; value.octet1 = buff[3*i+1];
value.octet2 = buff[3*i+2]; value.octet2 = buff[3*i+2];
value.octet3 = buff[3*i+3]; value.octet3 = buff[3*i+3];
@ -117,8 +117,7 @@ bool writeOneRawData(FILE *rawDataFile){
valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256; valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256;
memcpy(&values[i], &valbin[i], sizeof(uint32_t)); memcpy(&values[i], &valbin[i], sizeof(uint32_t));
if(i==8){
if(i==maxCApteurNb){
fprintf(rawDataFile, "%d\n", values[i]/256); fprintf(rawDataFile, "%d\n", values[i]/256);
} }
else{ else{