From 47f2d31bbecd20d5f1b87685c525f856f4964c90 Mon Sep 17 00:00:00 2001 From: Umberto Villa Date: Tue, 29 Oct 2024 11:32:10 -0500 Subject: [PATCH] Update h5_write.c --- lectures/15_scientific_data/h5_write.c | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lectures/15_scientific_data/h5_write.c b/lectures/15_scientific_data/h5_write.c index f4b9a31..cae4b1c 100644 --- a/lectures/15_scientific_data/h5_write.c +++ b/lectures/15_scientific_data/h5_write.c @@ -17,15 +17,32 @@ #include "hdf5.h" -#define H5FILE_NAME "SDS.h5" -#define DATASETNAME "IntArray" +#define DATASETNAME "DoubleArray" #define NX 5 /* dataset dimensions */ #define NY 6 #define RANK 2 -int -main(void) + +void usage() +{ + printf("\nUsage: h5_write [filename] [val]\n\n"); + printf(" where \n"); + printf(" - filename is the name of the output file \n" + printf(" - val is the value of entry 00 \n\n"); + exit(1); +} +int main(int argc, char *argv[]) { + double data00; + char * fname; + if(argc != 3) + usage(); + else + { + fname = argv[1]; + data00 = atof(argv[2]); + } + hid_t file, dataset; /* file and dataset handles */ hid_t datatype, dataspace; /* handles */ hsize_t dimsf[2]; /* dataset dimensions */ @@ -40,7 +57,7 @@ main(void) for (i = 0; i < NY; i++) data[j][i] = i + j; - data[0][0] += 1e-6; + data[0][0] = data00; /* * 0+eps 1 2 3 4 5 * 1 2 3 4 5 6 @@ -54,7 +71,7 @@ main(void) * default file creation properties, and default file * access properties. */ - file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + file = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* * Describe the size of the array and create the data space for fixed