Compare commits

...

3 commits

Author SHA1 Message Date
quentin.perret efc3110b2d power debug (column = 0) 2022-06-16 15:19:07 +02:00
quentin.perret 479289a365 vide 2022-06-16 14:44:31 +02:00
quentin.perret e23d744cdc beginning change power 2022-06-16 14:35:02 +02:00
9 changed files with 47 additions and 32 deletions

View file

@ -3,7 +3,7 @@
#include "initialParameters.h"
//#include <string.h>
long **get(int N, int M) /* Allocate the array */
long **getlongArray(int N, int M) /* Allocate the array */
{
/* Check if allocation succeeded. (check for NULL pointer) */
int i;
@ -14,6 +14,17 @@ long **get(int N, int M) /* Allocate the array */
return array;
}
double **getDoubleArray(int N, int M) /* Allocate the array */
{
/* Check if allocation succeeded. (check for NULL pointer) */
int i;
double **array;
array = (double **) malloc(N*sizeof(double *));
for(i = 0 ; i < N ; i++)
array[i] = (double *) malloc( M*sizeof(double));
return array;
}
void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) {
int i, j;
char *buffer;
@ -86,7 +97,7 @@ void freeArray(long **p, int N) {
*/
long **getRawDataArray(char* rawDataFileName){
long **p;
p = get(nRow, nCol);
p = getlongArray(nRow, nCol);
fillArrayWithRawData(rawDataFileName,p ,nRow, nCol);
//if(checkArrayFullyFill(p,nRow)){
//clearRawData(N);

View file

@ -8,4 +8,5 @@
long **getRawDataArray(char *rawDataFileName);
void printArrayData(long** p, int N, int M);
void freeArray(long **p, int N);
bool checkArrayFullyFill(long **p, int N );
bool checkArrayFullyFill(long **p, int N );
double **getDoubleArray(int N, int M);

View file

@ -9,16 +9,17 @@
* @param gRateArray array that contaigns results of the growth ratecalculation
*/
void growthRateCalculation(double **dataArray , double *gRateArray){
double gRate = 0;
for(int i = 0 ; i < nCol-1 ; i++){
gRate = (dataArray[1][i] - dataArray[2][i]) / period;
gRateArray[i] = (dataArray[0][i] - dataArray[1][i]) / period;
}
}
void growthRateFunction(double *dataLign){
double **dataArray;
//initialization + fill
/**
* @brief calcul then print differentiate in csv
*
* @param dataLign
*/
void growthRateFunction(double **dataLign){
double gRateArray[nCol-1];
growthRateCalculation(dataArray , gRateArray);
growthRateCalculation(dataLign , gRateArray);
appendDataInFile("growthRate.csv",gRateArray , nCol-1);
}

View file

@ -1,4 +1,4 @@
#include <math.h>
#include <stdbool.h>
void growthRateFunction(double *dataLign);
void growthRateFunction(double **dataLign);

BIN
Code-C/main Executable file

Binary file not shown.

View file

@ -6,6 +6,7 @@
#include "queue.h"
#include "average.h"
#include "growthRate.h"
#include "getArray.h"
bool rawDataWriteFlag;
int nRow = 500;
@ -13,7 +14,7 @@ int nCol = 1;
double freqEch = 250;
Pqueue firstRawDataQueue;
//Captor 1 2 3 4 5 6 7 8
bool selectionCaptors[] = {true,false,true,false,false,false,true,false};
int cptData = 0;
@ -66,31 +67,29 @@ void *threadCalculGrowthRate(void * vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
//double pw[nCol-1];
double *dataLign[2][nCol-1];
double **dataLign = getDoubleArray(2,nCol);
int i = 0;
while(rawDataWriteFlag){
//add case first file traitement
//(possibility 1: call twice powerfunction , following while strat after 2 file encountered)
//(posibilty 2 : initialiaze with a 0-fill array, move ligns for first encounter then let the following whil e do the job)
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
if(i < 2){
if(i == 1){
powerFunction(fileName, dataLign[1]);
growthRateFunction(**dataLign);
powerFunction(fileName, dataLign);
growthRateFunction(dataLign);
}else{
powerFunction(fileName, dataLign[0]);
powerFunction(fileName, dataLign);
}
i++;
}else{
for(int y = 0; y < (nCol-1); y++){
dataLign[0][y] = dataLign[1][y];
}
powerFunction(fileName, dataLign[1]);
growthRateFunction(**dataLign);
powerFunction(fileName, dataLign);
growthRateFunction(dataLign);
}
remove(fileName);
//remove(fileName);
}
}
}

View file

@ -11,16 +11,19 @@
* @param powerArray array where results are stocked
*/
void powerCalculation(long **p, double powerArray[]){
for(int i = 1; i < nCol; i++){
printf("data in pw : \n");
for(int i = 0; i < nCol; i++){
int j = 0;
powerArray[i] = 0;
while(j < nRow-1){
double aire = ( pow(p[j][i],2) + pow(p[j+1][i],2) ) / 2 * period;
powerArray[i] += aire;
while(j < nRow){
printf("\np[%d,%d] = %d\npwArray[%d] = %lf\n" , j,i,p[j][i+1],i,powerArray[i]);
powerArray[i] += pow(p[j][i+1],2);
j++;
}
powerArray[i] *= invTimeBandWidth;
powerArray[i] /= nRow;
}
}
/**
@ -30,7 +33,7 @@ void powerCalculation(long **p, double powerArray[]){
* @param N number of rows in the file
* @param M number of columns in the file
*/
void powerFunction(char* rawDataFileName, double **pw){
void powerFunction(char* rawDataFileName, double *pw[]){
long **p = getRawDataArray(rawDataFileName);
double pww[nCol-1];
if(p !=NULL){
@ -38,7 +41,7 @@ void powerFunction(char* rawDataFileName, double **pw){
powerCalculation(p,pww);
appendDataInFile("powerData.csv",pww,nCol-1);
}else{
powerCalculation(p,*pw);
powerCalculation(p,pw[1]);
appendDataInFile("powerData.csv",*pw,nCol-1);
}
freeArray(p,nRow);

View file

@ -1,4 +1,4 @@
#include <math.h>
#include <stdbool.h>
void powerFunction(char* rawDataFileName, double **pw);
void powerFunction(char* rawDataFileName, double *pw[]);

View file

@ -119,7 +119,7 @@ bool writeOneRawData(FILE *rawDataFile){
}
int lastIndex = lastIndexCaptor();
for (int i = 1; i < 9; i++){
if(selectionCaptors[i]){
if(selectionCaptors[i-1]){
value.octet1 = buff[3*i+1];
value.octet2 = buff[3*i+2];
value.octet3 = buff[3*i+3];
@ -128,7 +128,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==lastIndex){
if(i-1==lastIndex){
fprintf(rawDataFile, "%d\n", values[i]/256);
}
else{