end morning 3

This commit is contained in:
quentin.perret 2022-06-01 12:32:04 +02:00
parent 2568a7b601
commit 9c721e6197
27 changed files with 1600176 additions and 84 deletions

View file

@ -7,6 +7,8 @@
"stdio.h": "c", "stdio.h": "c",
"string.h": "c", "string.h": "c",
"initialparameters.h": "c", "initialparameters.h": "c",
"filegestion.h": "c" "filegestion.h": "c",
"power.h": "c",
"getarray.h": "c"
} }
} }

View file

@ -1,7 +0,0 @@
CC = gcc
TARGET = data
all:
$(CC) b2hd.c getArray.c fileGestion.c power.c main.c -o main
clean:
rm *.txt *.o

View file

@ -1,21 +0,0 @@
#include "fileGestion.h"
void newFile(int nRow){
char buffer[256];
for(int i = 0; i < nRow; i++){
fgets(buffer , sizeof buffer , stdin);
//printf("Line contaigns: %s" , buffer);
}
while(1){
if(!fgets(buffer,sizeof buffer , stdin)) break;
printf("%s",buffer);
}
}
void copyFile(int nRow){
char buffer[256];
while(1){
if(!fgets(buffer , sizeof buffer , stdin)) break;
fprintf(stdout, "%s" , buffer);
}
}

View file

@ -1,4 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>

View file

@ -1,25 +0,0 @@
#include "getArray.h"
int getArray(int nRow){
int nCol = 9; // imposé par le nombre de sortie du capteur Vegetal Signal
int tab[nRow][nCol]; // création de la matrice contenant les valeurs , nRow définit dans les paramètre de la fonction
char buffer[200]; //200 valeur arbitraire
char *token;
for(int i = 0 ; i < nRow ; i++){
if (!fgets(buffer, sizeof buffer, stdin)) break; // condition d'arret de la boucle si fichier fini
//printf(buffer);
token = strtok(buffer, ","); // séparation valeur par virgule initiale : csv
tab[i][0] = atoi(token);
for(int j = 1 ; j < nCol ; j++){
token = strtok(NULL, ","); // séparation valeur par virgule : csv
if(token == NULL) break; // condition d'arrêt de la séparartion
tab[i][j] = atoi(token); //transtypage char to int
//printf(token);
}
}
}

View file

@ -1,2 +0,0 @@
int nRow = 100000;
int freqEch = 250;

Binary file not shown.

View file

@ -1,3 +0,0 @@
int main(int argc , char** agrv){
}

View file

@ -1,19 +0,0 @@
#include "power.h"
#include "initialParameters.h"
float power(int tab[nRow][8]){
float periode = 1 /freqEch;
float power[8];
for(int i = 0; i < 8; i++){
int j = 0;
float res = 0;
while(1){
if(tab[j+1][i]==) break;
float aire = ( pow(tab[j][i],2) + pow(tab[j+1][i],2) ) / 2 * periode;
res += aire;
j++;
}
power[i] = res;
}
return *power;
}

View file

@ -1 +0,0 @@
#include <math.h>

13
Code-C/Makefile Normal file
View file

@ -0,0 +1,13 @@
CC = gcc
TARGET = data
all:
$(CC) b2hd.c -o b2hd
$(CC) fileGestion.c getArray.c -o getArray
#$(CC) power.c -o power
#getArray.c fileGestion.c power.c main.c -o main
./b2hd < ../02400031.TXT > decValues.txt
./getArray < decValues.txt
clean:
rm *.txt *.o

BIN
Code-C/b2hd Executable file

Binary file not shown.

View file

@ -40,3 +40,6 @@ void b2hd()
} }
} }
} }
int main(int argc , char** argv){
b2hd();
}

900011
Code-C/decValues.txt Normal file

File diff suppressed because it is too large Load diff

27
Code-C/fileGestion.c Normal file
View file

@ -0,0 +1,27 @@
#include "fileGestion.h"
void newFileCut(int cutLign, FILE *f){
char buffer[256];
for(int i = 0; i < cutLign; i++){
fgets(buffer , sizeof buffer , stdin);
//printf("Line contaigns: %s" , buffer);
}
while(1){
if(!fgets(buffer,sizeof buffer , stdin)) break;
fprintf(f,"%s",buffer);
}
}
void copyFile(FILE *f , FILE *g){
char buffer[256];
while(1){
if(!fgets(buffer , sizeof buffer , f)) break;
fprintf(g, "%s" , buffer);
}
}
void replaceFile(int nRow,FILE *g){
FILE *f = fopen("newFile.txt","a+");
newFileCut(nRow,f);
copyFile(f,g);
}

8
Code-C/fileGestion.h Normal file
View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
void newFile(int nRow, FILE *f);
void copyFile(FILE *f, FILE *g);
void replaceFile(int nRow, FILE *g);

BIN
Code-C/getArray Executable file

Binary file not shown.

60
Code-C/getArray.c Normal file
View file

@ -0,0 +1,60 @@
#include "getArray.h"
#include "initialParameters.h"
#include "fileGestion.h"
int **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 *));
for(i = 0 ; i < N ; i++)
array[i] = malloc( M*sizeof(int) );
return array;
}
void fill(int** p, int N, int M) {
int i, j;
char buffer[200];
char *token;
for(i = 0 ; i < N ; i++){
if (!fgets(buffer, sizeof buffer, stdin)) 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);
for(j = 1 ; j < M ; j++){
token = strtok(NULL, ","); // séparation valeur par virgule : csv
if(token == NULL) break; // condition d'arrêt de la séparartion
p[i][j] = atoi(token); //transtypage char to int
//printf(token);
}
}
}
void print(int** p, int N, int M) {
int i, j;
for(i = 0 ; i < N ; i++)
for(j = 0 ; j < M ; j++)
printf("array[%d][%d] = %d\n", i, j, p[i][j]);
}
void freeArray(int** p, int N) {
int i;
for(i = 0 ; i < N ; i++)
free(p[i]);
free(p);
}
int main(int argc , char** argv){
int **p;
p = get(nRow, nCol);
fill(p ,nRow, nCol);
//print(p, nRow, nCol);
FILE *g = fopen(,"w"); //here to find the good one
replaceFile(nRow,g);
freeArray(p ,nRow);
return 0;
}

View file

@ -3,4 +3,4 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
int getArray(int nRow); int getArray(int nRow, FILE *f);

View file

@ -0,0 +1,3 @@
int nRow = 100000;
int nCol = 9;
int freqEch = 250;

8
Code-C/main.c Normal file
View file

@ -0,0 +1,8 @@
#include "b2hd.h"
#include "getArray.h"
#include "fileGestion.h"
#include "power.h"
int main(int argc , char** argv){
}

700011
Code-C/newFile.txt Normal file

File diff suppressed because it is too large Load diff

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

@ -0,0 +1,24 @@
#include "power.h"
#include "getArray.h"
double power(int tab[nRow][8]){
double periode = 1 /freqEch;
double power[8];
for(int i = 0; i < 8; i++){
int j = 0;
double res = 0;
while(1){
if(!tab[j+1][i]) break;
double aire = ( pow(tab[j][i],2) + pow(tab[j+1][i],2) ) / 2 * periode;
res += aire;
j++;
}
power[i] = res;
}
return *power;
}
int main(int argc , char** argv){
FILE *f = fopen(argv[1],"r");
double pw = power(getArray(nRow,f));
printf("%d" , pw);
}

4
Code-C/power.h Normal file
View file

@ -0,0 +1,4 @@
#include "math.h"
#include "initialParameters.h"
double power(int tab[nRow][8]);

0
Code-C/� �� Normal file
View file