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
all:
rm powerData.csv
# rm powerData.csv
$(CC) b2hd.c -o b2hd
$(CC) fileGestion.c getArray.c power.c -lm -o power
#getArray.c fileGestion.c power.c main.c -o main
$(CC) fileGestion.c getArray.c -o getArray
# $(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
./power
./b2hd < ../02400031.TXT > rawData.csv
./getArray
#./power

View file

@ -9,7 +9,7 @@ void b2hd()
int32_t values[8];
uint32_t valbin[8];
quartet value;
while (fread(&buff, 26, 1, stdin)) {
fprintf(stdout , "%ld,", millis());
for (int i = 1; i < 9; i++){
@ -30,7 +30,7 @@ void b2hd()
value.octet4 = 0;
/*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;
memcpy(&values[i], &valbin[i], sizeof(int32_t));
memcpy(&values[i], &valbin[i], sizeof(uint32_t));
if(i<8){
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 "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) */
int i;
int **array;
array = malloc(N*sizeof(int *));
long **array;
array = (long **) malloc(N*sizeof(long *));
for(i = 0 ; i < N ; i++)
array[i] = malloc( M*sizeof(int) );
array[i] = (long *) malloc( M*sizeof(long) );
return array;
}
void fillRawData(int** p, int N, int M) {
void fillRawData(long** p, int N, int M) {
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");
for(i = 0 ; i < N ; i++){
if (!fgets(buffer, sizeof buffer, f)) break; // condition d'arret de la boucle si fichier fini
//printf(buffer);
token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv
p[i][0] = atoi(token);
if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini
printf("%s",buffer);
j = 0;
while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv
//printf("%s ," , token);
p[i][j] = atoi(token);
j++;
}
/*
for(j = 1 ; j < M ; j++){
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
//printf(token);
}
*/
}
}
void printArray(int** p, int N, int M) {
void printArrayData(long** p, int N, int M) {
int i, j;
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]);
for(i = 0 ; i < N ; i++){
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;
for(i = 0 ; i < N ; i++)
free(p[i]);
free(p);
}
int **getRawDataArray(int N , int M){
int **p;
long **getRawDataArray(int N , int M){
long **p;
p = get(N, M);
fillRawData(p ,N, M);
//printArray(p, nRow, nCol);
clearRawData(N);
//freeArray(p ,nRow);
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 <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
int **getRawDataArray();
void printArray(int** p, int N, int M);
long **getRawDataArray();
void printArray(long** p, int N, int M);
void freeArray(long **p, int N);

View file

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