go back to morning day 5

This commit is contained in:
quentin.perret 2022-06-03 17:02:49 +02:00
parent 7773288b49
commit bdcd6ccb61
7 changed files with 77 additions and 34 deletions

View file

@ -1,10 +1,12 @@
CC = gcc CC = gcc
all: all:
rm powerData.csv # rm powerData.csv
$(CC) b2hd.c -o b2hd $(CC) b2hd.c -o b2hd
$(CC) fileGestion.c getArray.c power.c -lm -o power $(CC) fileGestion.c getArray.c -o getArray
#getArray.c fileGestion.c power.c main.c -o main # $(CC) fileGestion.c getArray.c power.c -lm -o power
# getArray.c fileGestion.c power.c main.c -o main
./b2hd < ../02400001.TXT > rawData.csv ./b2hd < ../02400031.TXT > rawData.csv
./power ./getArray
#./power

View file

@ -9,7 +9,7 @@ void b2hd()
int32_t values[8]; int32_t values[8];
uint32_t valbin[8]; uint32_t valbin[8];
quartet value; quartet value;
while (fread(&buff, 26, 1, stdin)) { while (fread(&buff, 26, 1, stdin)) {
fprintf(stdout , "%ld,", millis()); fprintf(stdout , "%ld,", millis());
for (int i = 1; i < 9; i++){ for (int i = 1; i < 9; i++){
@ -30,7 +30,7 @@ void b2hd()
value.octet4 = 0; value.octet4 = 0;
/*memcpy(&values[i], &value, sizeof(quartet));*/ /*memcpy(&values[i], &value, sizeof(quartet));*/
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(int32_t)); memcpy(&values[i], &valbin[i], sizeof(uint32_t));
if(i<8){ if(i<8){
fprintf(stdout, "%d,", values[i]/256); fprintf(stdout, "%d,", values[i]/256);
} }

24
Code-C/divideChar.c Normal file
View file

@ -0,0 +1,24 @@
void divideChar(char *res[9] , char *lign , char delimiter){
int i = 0;
int j = 0;
int cptWord = 0;
int lignSize = sizeof(lign);
char *token;
token = (char *) malloc(20 * sizeof(char));
char space = ' ';
while(i < lignSize){
if(lign[i]==delimiter){
token[j+1] = '\0';
res[cptWord] = token;
cptWord++;
}
else if(lign[i] == space) continue;
else{
token[j] = lign[i];
j++;
}
i++;
}
}

BIN
Code-C/getArray Executable file

Binary file not shown.

View file

@ -1,29 +1,37 @@
#include "getArray.h" #include "getArray.h"
#include "fileGestion.h" #include "fileGestion.h"
//#include <string.h>
int **get(int N, int M) /* Allocate the array */ long **get(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;
int **array; long **array;
array = malloc(N*sizeof(int *)); array = (long **) malloc(N*sizeof(long *));
for(i = 0 ; i < N ; i++) for(i = 0 ; i < N ; i++)
array[i] = malloc( M*sizeof(int) ); array[i] = (long *) malloc( M*sizeof(long) );
return array; return array;
} }
void fillRawData(int** p, int N, int M) { void fillRawData(long** p, int N, int M) {
int i, j; int i, j;
char buffer[200];
char *token; char *buffer;
size_t bufsize = 200;
buffer = (char *)malloc(bufsize * sizeof(char));
char* token;
FILE *f = fopen("rawData.csv","r"); FILE *f = fopen("rawData.csv","r");
for(i = 0 ; i < N ; i++){ for(i = 0 ; i < N ; i++){
if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini
if (!fgets(buffer, sizeof buffer, f)) break; // condition d'arret de la boucle si fichier fini printf("%s",buffer);
//printf(buffer); j = 0;
token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv
p[i][0] = atoi(token); //printf("%s ," , token);
p[i][j] = atoi(token);
j++;
}
/*
for(j = 1 ; j < M ; j++){ for(j = 1 ; j < M ; j++){
token = strtok(NULL, ","); // séparation valeur par virgule : csv token = strtok(NULL, ","); // séparation valeur par virgule : csv
@ -31,28 +39,33 @@ void fillRawData(int** p, int N, int M) {
p[i][j] = atoi(token); //transtypage char to int p[i][j] = atoi(token); //transtypage char to int
//printf(token); //printf(token);
} }
*/
} }
} }
void printArray(int** p, int N, int M) { void printArrayData(long** p, int N, int M) {
int i, j; int i, j;
for(i = 0 ; i < N ; i++) for(i = 0 ; i < N ; i++){
printf("%d , %d , %d , %d , %d , %d , %d , %d\n",p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5],p[i][6],p[i][7]); printf("line n°%d : %d , %d , %d , %d , %d , %d , %d , %d \n" ,i,p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5],p[i][6],p[i][7]);
}
} }
void freeArray(int** p, int N) { void freeArray(long **p, int N) {
int i; int i;
for(i = 0 ; i < N ; i++) for(i = 0 ; i < N ; i++)
free(p[i]); free(p[i]);
free(p); free(p);
} }
int **getRawDataArray(int N , int M){ long **getRawDataArray(int N , int M){
int **p; long **p;
p = get(N, M); p = get(N, M);
fillRawData(p ,N, M); fillRawData(p ,N, M);
//printArray(p, nRow, nCol);
clearRawData(N);
//freeArray(p ,nRow);
return p; return p;
}
void main(int argc , char argv[]){
long **p;
p = getRawDataArray(10,9);
printArrayData(p,10,9);
} }

View file

@ -2,6 +2,8 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h>
int **getRawDataArray(); long **getRawDataArray();
void printArray(int** p, int N, int M); void printArray(long** p, int N, int M);
void freeArray(long **p, int N);

View file

@ -3,7 +3,7 @@
#include "fileGestion.h" #include "fileGestion.h"
#include "initialParameters.h" #include "initialParameters.h"
void power(int **p, double a[]){ void power(long **p, double a[]){
double periode = 1.0/freqEch; double periode = 1.0/freqEch;
double temps = 1/(nRow * periode); double temps = 1/(nRow * periode);
@ -25,9 +25,11 @@ void power(int **p, double a[]){
} }
} }
int main(int argc , char** argv){ int main(int argc , char** argv){
int **p = getRawDataArray(nRow, nCol); printf("Get raw data mat");
printArray(p,nRow,nCol); int32_t **p = getRawDataArray(nRow, nCol);
//printArray(p,nRow,nCol);
double pw[8]; double pw[8];
power(p,pw); power(p,pw);
writePowerData(pw,8); writePowerData(pw,8);
freeArray(p,nRow);
} }