1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include "hdf5.h"
#include "hdf5_hl.h"
#define RANK 2
#include <stdlib.h>
#include <stdio.h>
/* #include <conio.h> */
#include <string.h>
#define MAX 100
double *extract(char *TEST)
/* double *extract(char TEST[]) */
{
char tampon[MAX] = {0};
int i=0, n =0, j=0, h=0;
FILE *fichier = NULL;
float *tableau;
float *toto;
char* pEnd;
float **tab;
printf("Le fichier a ouvrir est : %s\n", "TEST.DAT");
fichier = fopen("TEST.DAT", "r");
if (fichier != NULL)
{
printf("L'ouverture du fichier %s a reussie !\n", "TEST.DAT");
while (fgets(tampon, MAX, fichier) != NULL)
n++;
printf("Le fichier contient %d valeurs.\n", n);
tableau = malloc(n * sizeof(double));
tab = malloc(n * sizeof (float*));
if (tableau == NULL)
{
printf("Erreur allocation !");
exit(0);
}
else
{
printf("Allocation reussie !\n");
}
rewind(fichier);
for (h=0; h<MAX; h++)
tableau[h] = 0.0;
for (i=0; i<n; i++)
{
fgets(tampon, MAX, fichier);
/* printf("tampon : %s\n", tampon); */
/* tableau[i] = atof (tampon); */
/* tableau[i] = strtof(tampon, NULL); */
/* Taille de chaque chaine de caractere */
/* printf("%lu", strlen(tampon)); */
float f1, f2, f3,f4,f5;
f1 = strtof (tampon, &pEnd);
f2 = strtof (pEnd, &pEnd);
f3 = strtof (pEnd, &pEnd);
f4 = strtof (pEnd, &pEnd);
f5 = strtof (pEnd, NULL );
/* /\* printf ("%f %f %f", f1 ,f2,f3); *\/ */
tab[i] = malloc(5 * sizeof (float));
/* float tab[n+50][5]; */
tab[i][0] =f1;
tab[i][1] =f2;
tab[i][2] =f3;
tab[i][3] =f4;
tab[i][4] =f5;
/* printf ("%f", tab[i][0]); */
/* --------- CREATION HDF5 ----------- */
hid_t file_id;
hsize_t dims[RANK]={n,5};
herr_t status;
/* create a HDF5 file */
file_id = H5Fcreate ("ex_lite2.h5",H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* /\* create and write an integer type dataset named "dset" *\/ */
status = H5LTmake_dataset(file_id,"/dset",RANK,dims,H5T_NATIVE_FLOAT,tab);
/* close file */
status = H5Fclose (file_id);
/* --------- FIN CREATION HDF5 ----------- */
}
}
else
printf("L'ouverture du fichier %s a echouee !\n", "TEST.DAT");
return 0;
} |
Partager