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
all:
$(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
$(CC) -g fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main

View file

@ -8,18 +8,16 @@
*
* @param p array with all the values that will be used for the calcul
* @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){
for(int i = 0; i < M-1; i++){
void averageCalculation(long **p, double averageArray[]){
for(int i = 0; i < nCol-1; i++){
int j = 0;
averageArray[i] = 0;
while(j < N){
while(j < nRow){
averageArray[i] += p[i][j];
j++;
}
averageArray[i] /= N;
averageArray[i] /= nRow;
//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
*
* @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){
long **p = getRawDataArray(rawDataFileName,N, M);
double aver[8];
void average(char* rawDataFileName){
long **p = getRawDataArray(rawDataFileName);
double aver[nCol -1];
if(p !=NULL){
averageCalculation(p,aver,N,M);
writeDataInFile("averageData.csv",aver,8);
freeArray(p,N);
averageCalculation(p,aver);
appendDataInFile("averageData.csv",aver,nCol-1);
freeArray(p,nRow);
}
}

View file

@ -1,4 +1,4 @@
#include <math.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 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+");
for(int i = 0 ; i < nCol ; i++){
if( i < nCol-1){
@ -37,4 +37,3 @@ void writeDataInFile(char* fileName , double array[], int nCol){
}
fclose(f);
}

View file

@ -5,4 +5,4 @@
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 "fileGestion.h"
#include "initialParameters.h"
//#include <string.h>
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 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++){
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
* @return long** the array fill with raw data
*/
long **getRawDataArray(char* rawDataFileName , int N , int M){
long **getRawDataArray(char* rawDataFileName){
long **p;
p = get(N, M);
fillArrayWithRawData(rawDataFileName,p ,N, M);
if(checkArrayFullyFill(p,N,M)){
p = get(nRow, nCol);
printf("before fill\n");
fillArrayWithRawData(rawDataFileName,p ,nRow, nCol);
printf("after fill\n");
if(checkArrayFullyFill(p,nRow, nCol)){
//clearRawData(N);
return p;
}

View file

@ -5,7 +5,7 @@
#include <stdbool.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 freeArray(long **p, int N);
bool checkArrayFullyFill(long **p, int N , int M);

View file

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

Binary file not shown.

View file

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

View file

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

View file

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