beginning change power

This commit is contained in:
quentin.perret 2022-06-16 14:35:02 +02:00
parent 7af7366247
commit e23d744cdc
9 changed files with 48 additions and 31 deletions

View file

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

View file

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

View file

@ -1,4 +1,4 @@
#include <math.h> #include <math.h>
#include <stdbool.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,14 +6,15 @@
#include "queue.h" #include "queue.h"
#include "average.h" #include "average.h"
#include "growthRate.h" #include "growthRate.h"
#include "getArray.h"
bool rawDataWriteFlag; bool rawDataWriteFlag;
int nRow = 500; int nRow = 4;
int nCol = 1; int nCol = 1;
double freqEch = 250; double freqEch = 250;
Pqueue firstRawDataQueue; Pqueue firstRawDataQueue;
//Captor 1 2 3 4 5 6 7 8
bool selectionCaptors[] = {true,false,true,false,false,false,true,false}; bool selectionCaptors[] = {true,false,true,false,false,false,true,false};
int cptData = 0; int cptData = 0;
@ -66,31 +67,29 @@ void *threadCalculGrowthRate(void * vargp){
Pqueue rawDataQueue = firstRawDataQueue; Pqueue rawDataQueue = firstRawDataQueue;
char* fileName; char* fileName;
//double pw[nCol-1]; //double pw[nCol-1];
double *dataLign[2][nCol-1]; double **dataLign = getDoubleArray(2,nCol);
int i = 0; int i = 0;
while(rawDataWriteFlag){ 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){ while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue); rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue); fileName = queueGetTabChar(rawDataQueue);
if(i < 2){ if(i < 2){
if(i == 1){ if(i == 1){
powerFunction(fileName, dataLign[1]); powerFunction(fileName, dataLign);
growthRateFunction(**dataLign); growthRateFunction(dataLign);
}else{ }else{
powerFunction(fileName, dataLign[0]); powerFunction(fileName, dataLign);
} }
i++; i++;
}else{ }else{
for(int y = 0; y < (nCol-1); y++){ for(int y = 0; y < (nCol-1); y++){
dataLign[0][y] = dataLign[1][y]; dataLign[0][y] = dataLign[1][y];
} }
powerFunction(fileName, dataLign[1]); powerFunction(fileName, dataLign);
growthRateFunction(**dataLign); growthRateFunction(dataLign);
} }
remove(fileName); //remove(fileName);
} }
} }
} }

View file

@ -11,16 +11,21 @@
* @param powerArray array where results are stocked * @param powerArray array where results are stocked
*/ */
void powerCalculation(long **p, double powerArray[]){ void powerCalculation(long **p, double powerArray[]){
printArrayData(p,nRow,nCol);
printf("data in pw : \n");
for(int i = 1; i < nCol; i++){ for(int i = 1; i < nCol; i++){
int j = 0; int j = 0;
powerArray[i] = 0; powerArray[i] = 0;
while(j < nRow-1){
double aire = ( pow(p[j][i],2) + pow(p[j+1][i],2) ) / 2 * period; while(j < nRow){
powerArray[i] += aire;
printf("%d , %d , %d , %d\n" , p[j][i], p[j+1][i] , i ,j);
powerArray[i] + pow(p[j][i],2);
j++; j++;
} }
powerArray[i] *= invTimeBandWidth; powerArray[i] *= invTimeBandWidth;
} }
} }
/** /**
@ -30,7 +35,7 @@ void powerCalculation(long **p, double powerArray[]){
* @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
*/ */
void powerFunction(char* rawDataFileName, double **pw){ void powerFunction(char* rawDataFileName, double *pw[]){
long **p = getRawDataArray(rawDataFileName); long **p = getRawDataArray(rawDataFileName);
double pww[nCol-1]; double pww[nCol-1];
if(p !=NULL){ if(p !=NULL){
@ -38,7 +43,7 @@ void powerFunction(char* rawDataFileName, double **pw){
powerCalculation(p,pww); powerCalculation(p,pww);
appendDataInFile("powerData.csv",pww,nCol-1); appendDataInFile("powerData.csv",pww,nCol-1);
}else{ }else{
powerCalculation(p,*pw); powerCalculation(p,pw[1]);
appendDataInFile("powerData.csv",*pw,nCol-1); appendDataInFile("powerData.csv",*pw,nCol-1);
} }
freeArray(p,nRow); freeArray(p,nRow);

View file

@ -1,4 +1,4 @@
#include <math.h> #include <math.h>
#include <stdbool.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(); int lastIndex = lastIndexCaptor();
for (int i = 1; i < 9; i++){ for (int i = 1; i < 9; i++){
if(selectionCaptors[i]){ if(selectionCaptors[i-1]){
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];
@ -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; 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==lastIndex){ if(i-1==lastIndex){
fprintf(rawDataFile, "%d\n", values[i]/256); fprintf(rawDataFile, "%d\n", values[i]/256);
} }
else{ else{