NOTE: The netcdf-hdf
mailing list is no longer active. The list archives are made available for historical reasons.
Hi Ed, > Do me a favor, compile and run this program. Sure, I'll let you know in a few minutes what my prognosis is... :-) Quincey > When I chage this program to use a contiguous dataset, and take out > the H5Dextend call, everything works. But using an extendable dataset, > it give me a seg fault. > > Obviously I'm doing something wrong with respect to my setting up or > using the chunked dataset. I'm going to reread the docs and see what > they say again... > > Ed > > > /* > Why doesn't this work? > */ > > #include <hdf5.h> > > int main(void); > > #define BAIL(e) do { \ > printf("Bailing out in file %s, line %d, error:%d.\n", __FILE__, __LINE__, > e); \ > goto exit; \ > } while (0) > > #define DATASET_NAME "eds_ds" > > int > main() > { > hid_t hdfid = 0, datasetid = 0, plistid = 0, type = 0; > hid_t mem_space = 0, file_space = 0; > float data = 99.9; > hssize_t ndata; > hssize_t coord[1][1]; > int retval = 0; > > /* Create a file. */ > if ((hdfid = H5Fcreate("aaa_test.h5", H5F_ACC_TRUNC, H5P_DEFAULT, > H5P_DEFAULT)) < 0) > BAIL(-1); > > /* Store floats. */ > if ((type = H5Tcopy(H5T_NATIVE_FLOAT)) < 0) > BAIL(-2); > > /* Reading and writing to memory always happens one element at a > time. */ > { > hsize_t dimsize1[] = {1}; > if ((mem_space = H5Screate_simple(1, dimsize1, NULL)) < 0) > BAIL(-3); > } > > /* Crate an extendable dataset, of rank 1, with 1 datum in it. */ > { > hsize_t maxdim = H5S_UNLIMITED, start_ndata = 1, chunk_size = 1; > if ((file_space = H5Screate_simple(1, &start_ndata, &maxdim)) < 0) > BAIL(-4); > if ((plistid = H5Pcreate(H5P_DATASET_CREATE)) < 0) > BAIL(-4); > if (H5Pset_chunk(plistid, 1, &chunk_size) < 0) > BAIL(-4); > if ((datasetid = H5Dcreate(hdfid, DATASET_NAME, > type, file_space, plistid)) < 0) > BAIL(-4); > } > > /* Write one value. */ > if ((file_space = H5Dget_space(datasetid)) < 0) > BAIL(-4); > ndata = H5Sget_simple_extent_npoints(file_space); > printf("number of data in dataset: %d\n", (int)ndata); > coord[0][0] = 0; > if (H5Sselect_elements(file_space, H5S_SELECT_SET, 1, > (const hssize_t **)coord) < 0) > BAIL(-4); > if (H5Dwrite(datasetid, type, mem_space, file_space, > H5P_DEFAULT, &data) < 0) > BAIL(-4); > H5Dclose(datasetid); > datasetid = 0; > > /* Read the value just written. */ > { > float thefloat; > > if ((datasetid = H5Dopen(hdfid, DATASET_NAME)) < 0) > BAIL(-3); > if ((file_space = H5Dget_space(datasetid)) < 0) > BAIL(-3); > ndata = H5Sget_simple_extent_npoints(file_space); > printf("number of data in dataset: %d\n", (int)ndata); > coord[0][0] = 0; > if (H5Sselect_elements(file_space, H5S_SELECT_SET, 1, > (const hssize_t **)coord) < 0) > BAIL(-4); > if (H5Dread(datasetid, type, mem_space, file_space, > H5P_DEFAULT, &thefloat) < 0) > BAIL(-3); > printf("the float: %f\n", thefloat); > H5Dclose(datasetid); > datasetid = 0; > } > > /* Add another datum. */ > { > hsize_t extend_size = 2; > float secfloat = 88.8; > if ((datasetid = H5Dopen(hdfid, DATASET_NAME)) < 0) > BAIL(-3); > if (H5Dextend(datasetid, &extend_size) < 0) > BAIL(-10); > if ((file_space = H5Dget_space(datasetid)) < 0) > BAIL(-4); > ndata = H5Sget_simple_extent_npoints(file_space); > printf("number of data in dataset: %d\n", (int)ndata); > coord[0][0] = 1; > if (H5Sselect_elements(file_space, H5S_SELECT_SET, 1, > (const hssize_t **)coord) < 0) > BAIL(-4); > if (H5Dwrite(datasetid, type, mem_space, file_space, > H5P_DEFAULT, &secfloat) < 0) > BAIL(-4); > H5Dclose(datasetid); > datasetid = 0; > } > > /* Read the value just written. */ > { > float thefloat; > > if ((datasetid = H5Dopen(hdfid, DATASET_NAME)) < 0) > BAIL(-3); > if ((file_space = H5Dget_space(datasetid)) < 0) > BAIL(-3); > ndata = H5Sget_simple_extent_npoints(file_space); > printf("number of data in dataset: %d\n", (int)ndata); > coord[0][0] = 1; > if (H5Sselect_elements(file_space, H5S_SELECT_SET, 1, > (const hssize_t **)coord) < 0) > BAIL(-4); > if (H5Dread(datasetid, type, mem_space, file_space, > H5P_DEFAULT, &thefloat) < 0) > BAIL(-3); > printf("the float: %f\n", thefloat); > H5Dclose(datasetid); > datasetid = 0; > } > > exit: > if (datasetid > 0) H5Dclose(datasetid); > if (type > 0) H5Tclose(type); > if (mem_space > 0) H5Sclose(mem_space); > if (file_space > 0) H5Sclose(file_space); > if (plistid > 0) H5Pclose(plistid); > return retval; > } >
netcdf-hdf
archives: