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
| #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)
{
char tampon[MAX] = {0};
int i, n = 0, j, h;
FILE *fichier = NULL;
double *tableau;
float res;
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));
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);
/* --------- CREATION HDF5 ----------- */
hid_t file_id;
hsize_t dims[RANK]={144,3};
herr_t status;
/* /\* int data[]={tableau[1]}; *\/ */
/* 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,tampon);
/* data); */
/* close file */
status = H5Fclose (file_id);
/* --------- FIN CREATION HDF5 ----------- */
}
/* for (j=0; j<n; j++) */
/* printf("%f\n", tableau[j]); */
}
else
printf("L'ouverture du fichier %s a echouee !\n", "TEST.DAT");
return tableau;
}
int main(void)
{
int i;
char nf[255] = "TEST.DAT";
double *nbre;
nbre = extract(nf);
/* for (i=0; i<MAX; i++) */
/* printf("--> %f\n", nbre[i]); */
return 0;
} |
Partager