From c5d2e994172923aeee917ea6b1b21950bfabbf66 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Thu, 12 Mar 2020 15:50:24 +0000 Subject: [PATCH 1/6] Updated to use H5O_info2_t for HDF5 1.12 and the use of H5Oget_info3 instead of H5Gget_objinfo --- h5_test/tst_h_dimscales2.c | 115 +++++++++++++++++++++++++++++++++++-- h5_test/tst_h_dimscales3.c | 40 +++++++++++-- h5_test/tst_h_dimscales4.c | 8 ++- h5_test/tst_h_vl.c | 4 ++ include/ncdimscale.h | 6 ++ libhdf5/hdf5open.c | 56 ++++++++++++++++-- libhdf5/nc4hdf.c | 9 +++ 7 files changed, 224 insertions(+), 14 deletions(-) diff --git a/h5_test/tst_h_dimscales2.c b/h5_test/tst_h_dimscales2.c index 557edbe3f..08031a722 100644 --- a/h5_test/tst_h_dimscales2.c +++ b/h5_test/tst_h_dimscales2.c @@ -24,7 +24,6 @@ herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid, void *visitor_data) { char name1[STR_LEN]; - H5G_stat_t statbuf; HDF5_OBJID_T *objid = visitor_data; /* This should get "/var1", the name of the dataset that the scale @@ -33,28 +32,42 @@ herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid, if (strcmp(&name1[1], VAR1_NAME)) ERR; /* Get more info on the dimscale object.*/ +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; + if (H5Oget_info3(dsid, &statbuf, H5O_INFO_BASIC ) < 0) ERR; + objid->fileno = statbuf.fileno; + objid->token = statbuf.token; +#else + H5G_stat_t statbuf; if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR; objid->fileno[0] = statbuf.fileno[0]; objid->objno[0] = statbuf.objno[0]; objid->fileno[1] = statbuf.fileno[1]; objid->objno[1] = statbuf.objno[1]; +#endif return 0; } herr_t alien_visitor2(hid_t did, unsigned dim, hid_t dsid, void *visitor_data) { - H5G_stat_t statbuf; HDF5_OBJID_T *objid = visitor_data; /* Get obj id of the dimscale object. THis will be used later to * match dimensions to dimscales. */ +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; + if (H5Oget_info3(dsid, &statbuf, H5O_INFO_BASIC ) < 0) ERR; + objid->fileno = statbuf.fileno; + objid->token = statbuf.token; +#else + H5G_stat_t statbuf; if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR; objid->fileno[0] = statbuf.fileno[0]; objid->objno[0] = statbuf.objno[0]; objid->fileno[1] = statbuf.fileno[1]; objid->objno[1] = statbuf.objno[1]; - +#endif return 0; } @@ -112,7 +125,11 @@ main() char label[STR_LEN+1]; int num_scales; hsize_t dims[1], maxdims[1]; +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; +#else H5G_stat_t statbuf; +#endif HDF5_OBJID_T dimscale_obj, vars_dimscale_obj; /* Open the file. */ @@ -153,11 +170,17 @@ main() /* fileno and objno uniquely identify an object and a * HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + if (H5Oget_info3(datasetid, &statbuf, H5O_INFO_BASIC) < 0) ERR; + dimscale_obj.fileno = statbuf.fileno; + dimscale_obj.token = statbuf.token; +#else if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR; dimscale_obj.fileno[0] = statbuf.fileno[0]; dimscale_obj.objno[0] = statbuf.objno[0]; dimscale_obj.fileno[1] = statbuf.fileno[1]; dimscale_obj.objno[1] = statbuf.objno[1]; +#endif } else { @@ -169,11 +192,19 @@ main() /* Go through all dimscales for this var and learn about them. */ if (H5DSiterate_scales(datasetid, 0, NULL, alien_visitor, &vars_dimscale_obj) < 0) ERR; +#if H5_VERSION_GE(1,12,0) + int token_cmp; + if (H5Otoken_cmp(datasetid, + &vars_dimscale_obj.token, + &dimscale_obj.token, &token_cmp) < 0) ERR; + if (vars_dimscale_obj.fileno != dimscale_obj.fileno || + token_cmp != 0) ERR; +#else if (vars_dimscale_obj.fileno[0] != dimscale_obj.fileno[0] || vars_dimscale_obj.objno[0] != dimscale_obj.objno[0] || vars_dimscale_obj.fileno[1] != dimscale_obj.fileno[1] || vars_dimscale_obj.objno[1] != dimscale_obj.objno[1]) ERR; - +#endif /* There's also a label for dimension 0. */ if (H5DSget_label(datasetid, 0, label, STR_LEN) < 0) ERR; } @@ -259,7 +290,11 @@ main() htri_t is_scale; int num_scales; hsize_t dims[NDIMS2], maxdims[NDIMS2]; +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; +#else H5G_stat_t statbuf; +#endif HDF5_OBJID_T dimscale_obj[2], vars_dimscale_obj[2]; int dimscale_cnt = 0; int d, ndims; @@ -297,11 +332,17 @@ main() { /* fileno and objno uniquely identify an object and a * HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + if (H5Oget_info3(datasetid, &statbuf, H5O_INFO_BASIC) < 0) ERR; + dimscale_obj[dimscale_cnt].fileno = statbuf.fileno; + dimscale_obj[dimscale_cnt].token = statbuf.token; +#else if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR; dimscale_obj[dimscale_cnt].fileno[0] = statbuf.fileno[0]; dimscale_obj[dimscale_cnt].objno[0] = statbuf.objno[0]; dimscale_obj[dimscale_cnt].fileno[1] = statbuf.fileno[1]; dimscale_obj[dimscale_cnt].objno[1] = statbuf.objno[1]; +#endif dimscale_cnt++; } else @@ -322,10 +363,19 @@ main() /* Verify that the object ids passed from the * alien_visitor2 function match the ones we found * for the lat and lon datasets. */ +#if H5_VERSION_GE(1,12,0) + int token_cmp; + if (H5Otoken_cmp(datasetid, + &vars_dimscale_obj[d].token, + &dimscale_obj[d].token, &token_cmp) < 0) ERR; + if (vars_dimscale_obj[d].fileno != dimscale_obj[d].fileno || + token_cmp != 0) ERR; +#else if (vars_dimscale_obj[d].fileno[0] != dimscale_obj[d].fileno[0] || vars_dimscale_obj[d].objno[0] != dimscale_obj[d].objno[0]) ERR; if (vars_dimscale_obj[d].fileno[1] != dimscale_obj[d].fileno[1] || vars_dimscale_obj[d].objno[1] != dimscale_obj[d].objno[1]) ERR; +#endif } } if (H5Dclose(datasetid) < 0) ERR; @@ -363,7 +413,11 @@ main() char obj_name[STR_LEN + 1]; htri_t is_scale; int num_scales; +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; +#else H5G_stat_t statbuf; +#endif HDF5_OBJID_T dimscale_obj[2], vars_dimscale_obj[2]; int dimscale_cnt = 0; int d, ndims; @@ -476,11 +530,17 @@ main() { /* fileno and objno uniquely identify an object and a * HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + if (H5Oget_info3(datasetid, &statbuf, H5O_INFO_BASIC) < 0) ERR; + dimscale_obj[dimscale_cnt].fileno = statbuf.fileno; + dimscale_obj[dimscale_cnt].token = statbuf.token; +#else if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR; dimscale_obj[dimscale_cnt].fileno[0] = statbuf.fileno[0]; dimscale_obj[dimscale_cnt].objno[0] = statbuf.objno[0]; dimscale_obj[dimscale_cnt].fileno[1] = statbuf.fileno[1]; dimscale_obj[dimscale_cnt].objno[1] = statbuf.objno[1]; +#endif dimscale_cnt++; } else @@ -501,10 +561,19 @@ main() /* Verify that the object ids passed from the * alien_visitor2 function match the ones we found * for the lat and lon datasets. */ +#if H5_VERSION_GE(1,12,0) + int token_cmp; + if (H5Otoken_cmp(datasetid, + &vars_dimscale_obj[d].token, + &dimscale_obj[d].token, &token_cmp) < 0) ERR; + if (vars_dimscale_obj[d].fileno != dimscale_obj[d].fileno || + token_cmp != 0) ERR; +#else if (vars_dimscale_obj[d].fileno[0] != dimscale_obj[d].fileno[0] || vars_dimscale_obj[d].objno[0] != dimscale_obj[d].objno[0]) ERR; if (vars_dimscale_obj[d].fileno[1] != dimscale_obj[d].fileno[1] || vars_dimscale_obj[d].objno[1] != dimscale_obj[d].objno[1]) ERR; +#endif } } @@ -666,7 +735,11 @@ main() htri_t is_scale; int num_scales; hsize_t maxdims[DIMS_3]; +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; +#else H5G_stat_t statbuf; +#endif HDF5_OBJID_T dimscale_obj[NUM_DIMSCALES1], vars_dimscale_obj[NUM_DIMSCALES1]; int dimscale_cnt = 0; int d, ndims; @@ -777,11 +850,17 @@ main() { /* fileno and objno uniquely identify an object and a * HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + if (H5Oget_info3(datasetid, &statbuf, H5O_INFO_BASIC) < 0) ERR; + dimscale_obj[dimscale_cnt].fileno = statbuf.fileno; + dimscale_obj[dimscale_cnt].token = statbuf.token; +#else if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR; dimscale_obj[dimscale_cnt].fileno[0] = statbuf.fileno[0]; dimscale_obj[dimscale_cnt].objno[0] = statbuf.objno[0]; dimscale_obj[dimscale_cnt].fileno[1] = statbuf.fileno[1]; dimscale_obj[dimscale_cnt].objno[1] = statbuf.objno[1]; +#endif dimscale_cnt++; } else @@ -802,10 +881,19 @@ main() /* Verify that the object ids passed from the * alien_visitor2 function match the ones we found * for the lat and lon datasets. */ +#if H5_VERSION_GE(1,12,0) + int token_cmp; + if (H5Otoken_cmp(datasetid, + &vars_dimscale_obj[d].token, + &dimscale_obj[d].token, &token_cmp) < 0) ERR; + if (vars_dimscale_obj[d].fileno != dimscale_obj[d].fileno || + token_cmp != 0) ERR; +#else if (vars_dimscale_obj[d].fileno[0] != dimscale_obj[d].fileno[0] || vars_dimscale_obj[d].objno[0] != dimscale_obj[d].objno[0]) ERR; if (vars_dimscale_obj[d].fileno[1] != dimscale_obj[d].fileno[1] || vars_dimscale_obj[d].objno[1] != dimscale_obj[d].objno[1]) ERR; +#endif } } if (H5Dclose(datasetid) < 0) ERR; @@ -851,7 +939,11 @@ main() htri_t is_scale; int num_scales; hsize_t maxdims[DIMS_3]; +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; +#else H5G_stat_t statbuf; +#endif HDF5_OBJID_T dimscale_obj[NUM_DIMSCALES2], vars_dimscale_obj[NUM_DIMSCALES2]; int dimscale_cnt = 0; int d, ndims; @@ -962,11 +1054,17 @@ main() { /* fileno and objno uniquely identify an object and a * HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + if (H5Oget_info3(datasetid, &statbuf, H5O_INFO_BASIC) < 0) ERR; + dimscale_obj[dimscale_cnt].fileno = statbuf.fileno; + dimscale_obj[dimscale_cnt].token = statbuf.token; +#else if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR; dimscale_obj[dimscale_cnt].fileno[0] = statbuf.fileno[0]; dimscale_obj[dimscale_cnt].objno[0] = statbuf.objno[0]; dimscale_obj[dimscale_cnt].fileno[1] = statbuf.fileno[1]; dimscale_obj[dimscale_cnt].objno[1] = statbuf.objno[1]; +#endif dimscale_cnt++; } else @@ -987,10 +1085,19 @@ main() /* Verify that the object ids passed from the * alien_visitor2 function match the ones we found * for the lat and lon datasets. */ +#if H5_VERSION_GE(1,12,0) + int token_cmp; + if (H5Otoken_cmp(datasetid, + &vars_dimscale_obj[d].token, + &dimscale_obj[d].token, &token_cmp) < 0) ERR; + if (vars_dimscale_obj[d].fileno != dimscale_obj[d].fileno || + token_cmp != 0) ERR; +#else if (vars_dimscale_obj[d].fileno[0] != dimscale_obj[d].fileno[0] || vars_dimscale_obj[d].objno[0] != dimscale_obj[d].objno[0]) ERR; if (vars_dimscale_obj[d].fileno[1] != dimscale_obj[d].fileno[1] || vars_dimscale_obj[d].objno[1] != dimscale_obj[d].objno[1]) ERR; +#endif } } if (H5Dclose(datasetid) < 0) ERR; diff --git a/h5_test/tst_h_dimscales3.c b/h5_test/tst_h_dimscales3.c index 6c21f467e..880cff6c0 100644 --- a/h5_test/tst_h_dimscales3.c +++ b/h5_test/tst_h_dimscales3.c @@ -27,7 +27,6 @@ herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid, void *visitor_data) { char name1[STR_LEN]; - H5G_stat_t statbuf; HDF5_OBJID_T *objid = visitor_data; /* This should get "/var1", the name of the dataset that the scale @@ -36,27 +35,42 @@ herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid, if (strcmp(&name1[1], VAR1_NAME)) ERR; /* Get more info on the dimscale object.*/ +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; + if (H5Oget_info3(dsid, &statbuf, H5O_INFO_BASIC ) < 0) ERR; + objid->fileno = statbuf.fileno; + objid->token = statbuf.token; +#else + H5G_stat_t statbuf; if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR; objid->fileno[0] = statbuf.fileno[0]; objid->objno[0] = statbuf.objno[0]; objid->fileno[1] = statbuf.fileno[1]; objid->objno[1] = statbuf.objno[1]; +#endif return 0; } herr_t alien_visitor2(hid_t did, unsigned dim, hid_t dsid, void *visitor_data) { - H5G_stat_t statbuf; HDF5_OBJID_T *objid = visitor_data; /* Get obj id of the dimscale object. THis will be used later to * match dimensions to dimscales. */ +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; + if (H5Oget_info3(dsid, &statbuf, H5O_INFO_BASIC ) < 0) ERR; + objid->fileno = statbuf.fileno; + objid->token = statbuf.token; +#else + H5G_stat_t statbuf; if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR; objid->fileno[0] = statbuf.fileno[0]; objid->objno[0] = statbuf.objno[0]; objid->fileno[1] = statbuf.fileno[1]; objid->objno[1] = statbuf.objno[1]; +#endif return 0; } @@ -111,7 +125,11 @@ main() char label[STR_LEN+1]; int num_scales; hsize_t dims[1], maxdims[1]; - H5G_stat_t statbuf; +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; +#else + H5G_stat_t statbuf; +#endif HDF5_OBJID_T dimscale_obj, vars_dimscale_obj; /* Open the file. */ @@ -152,11 +170,17 @@ main() /* fileno and objno uniquely identify an object and a * HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + if (H5Oget_info3(datasetid, &statbuf, H5O_INFO_BASIC) < 0) ERR; + dimscale_obj.fileno = statbuf.fileno; + dimscale_obj.token = statbuf.token; +#else if (H5Gget_objinfo(datasetid, ".", 1, &statbuf) < 0) ERR; dimscale_obj.fileno[0] = statbuf.fileno[0]; dimscale_obj.objno[0] = statbuf.objno[0]; dimscale_obj.fileno[1] = statbuf.fileno[1]; dimscale_obj.objno[1] = statbuf.objno[1]; +#endif } else { @@ -168,11 +192,19 @@ main() /* Go through all dimscales for this var and learn about them. */ if (H5DSiterate_scales(datasetid, 0, NULL, alien_visitor, &vars_dimscale_obj) < 0) ERR; +#if H5_VERSION_GE(1,12,0) + int token_cmp; + if (H5Otoken_cmp(datasetid, + &vars_dimscale_obj.token, + &dimscale_obj.token, &token_cmp) < 0) ERR; + if (vars_dimscale_obj.fileno != dimscale_obj.fileno || + token_cmp != 0) ERR; +#else if (vars_dimscale_obj.fileno[0] != dimscale_obj.fileno[0] || vars_dimscale_obj.objno[0] != dimscale_obj.objno[0] || vars_dimscale_obj.fileno[1] != dimscale_obj.fileno[1] || vars_dimscale_obj.objno[1] != dimscale_obj.objno[1]) ERR; - +#endif /* There's also a label for dimension 0. */ if (H5DSget_label(datasetid, 0, label, STR_LEN) < 0) ERR; } diff --git a/h5_test/tst_h_dimscales4.c b/h5_test/tst_h_dimscales4.c index bbc169cae..f2cba404d 100644 --- a/h5_test/tst_h_dimscales4.c +++ b/h5_test/tst_h_dimscales4.c @@ -36,15 +36,21 @@ struct nc_hdf5_link_info herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid, void *visitor_data) { - H5G_stat_t statbuf; HDF5_OBJID_T *objid = visitor_data; /* Get more info on the dimscale object.*/ +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; + if (H5Oget_info3(dsid, &statbuf, H5O_INFO_BASIC ) < 0) ERR; + objid->fileno = statbuf.fileno; + objid->token = statbuf.token; +#else if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR; objid->fileno[0] = statbuf.fileno[0]; objid->objno[0] = statbuf.objno[0]; objid->fileno[1] = statbuf.fileno[1]; objid->objno[1] = statbuf.objno[1]; +#endif return 0; } diff --git a/h5_test/tst_h_vl.c b/h5_test/tst_h_vl.c index 8858b8630..e32c0dcce 100644 --- a/h5_test/tst_h_vl.c +++ b/h5_test/tst_h_vl.c @@ -80,7 +80,11 @@ main() free(data[i].p); /* HDF5 allocated memory to store the data. Free that memory. */ +#if H5_VERSION_GE(1,12,0) + if (H5Treclaim(typeid, spaceid, H5P_DEFAULT, data_in) < 0) ERR; +#else if (H5Dvlen_reclaim(typeid, spaceid, H5P_DEFAULT, data_in) < 0) ERR; +#endif /* Close everything. */ if (H5Aclose(attid) < 0 || diff --git a/include/ncdimscale.h b/include/ncdimscale.h index c34b3ffd3..70847a27e 100644 --- a/include/ncdimscale.h +++ b/include/ncdimscale.h @@ -18,9 +18,15 @@ * dimscales. */ typedef struct hdf5_objid { +#if H5_VERSION_GE(1,12,0) + unsigned long fileno; /* file number */ + H5O_token_t token; /* token */ +#else unsigned long fileno[2]; /* file number */ haddr_t objno[2]; /* object number */ +#endif } HDF5_OBJID_T; + #endif /* USE_HDF5 */ #endif diff --git a/libhdf5/hdf5open.c b/libhdf5/hdf5open.c index 52f8b6d5f..6abbac215 100644 --- a/libhdf5/hdf5open.c +++ b/libhdf5/hdf5open.c @@ -66,7 +66,11 @@ typedef struct hdf5_obj_info { hid_t oid; /* HDF5 object ID */ char oname[NC_MAX_NAME + 1]; /* Name of object */ - H5G_stat_t statbuf; /* Information about the object */ +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; +#else + H5G_stat_t statbuf; /* Information about the object */ +#endif struct hdf5_obj_info *next; /* Pointer to next node in list */ } hdf5_obj_info_t; @@ -340,11 +344,22 @@ static herr_t dimscale_visitor(hid_t did, unsigned dim, hid_t dsid, void *dimscale_hdf5_objids) { - H5G_stat_t statbuf; LOG((4, "%s", __func__)); /* Get more info on the dimscale object.*/ +#if H5_VERSION_GE(1,12,0) + H5O_info2_t statbuf; + + if (H5Oget_info3(dsid, &statbuf, H5O_INFO_BASIC) < 0) + return -1; + + /* Pass this information back to caller. */ + (*(HDF5_OBJID_T *)dimscale_hdf5_objids).fileno = statbuf.fileno; + (*(HDF5_OBJID_T *)dimscale_hdf5_objids).token = statbuf.token; +#else + H5G_stat_t statbuf; + if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) return -1; @@ -353,6 +368,7 @@ dimscale_visitor(hid_t did, unsigned dim, hid_t dsid, (*(HDF5_OBJID_T *)dimscale_hdf5_objids).fileno[1] = statbuf.fileno[1]; (*(HDF5_OBJID_T *)dimscale_hdf5_objids).objno[0] = statbuf.objno[0]; (*(HDF5_OBJID_T *)dimscale_hdf5_objids).objno[1] = statbuf.objno[1]; +#endif return 0; } @@ -570,10 +586,20 @@ rec_match_dimscales(NC_GRP_INFO_T *grp) /* Check for exact match of fileno/objid arrays * to find identical objects in HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + int token_cmp; + if (H5Otoken_cmp(hdf5_var->hdf_datasetid, + &hdf5_var->dimscale_hdf5_objids[d].token, + &hdf5_dim->hdf5_objid.token, &token_cmp) < 0) + return NC_EHDFERR; + if (hdf5_var->dimscale_hdf5_objids[d].fileno == hdf5_dim->hdf5_objid.fileno && + token_cmp == 0) +#else if (hdf5_var->dimscale_hdf5_objids[d].fileno[0] == hdf5_dim->hdf5_objid.fileno[0] && hdf5_var->dimscale_hdf5_objids[d].objno[0] == hdf5_dim->hdf5_objid.objno[0] && hdf5_var->dimscale_hdf5_objids[d].fileno[1] == hdf5_dim->hdf5_objid.fileno[1] && hdf5_var->dimscale_hdf5_objids[d].objno[1] == hdf5_dim->hdf5_objid.objno[1]) +#endif { LOG((4, "%s: for dimension %d, found dim %s", __func__, d, dim->hdr.name)); @@ -2187,7 +2213,12 @@ nc4_read_atts(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var) */ static int read_scale(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name, - const H5G_stat_t *statbuf, hsize_t scale_size, +#if H5_VERSION_GE(1,12,0) + const H5O_info2_t *statbuf, +#else + const H5G_stat_t *statbuf, +#endif + hsize_t scale_size, hsize_t max_scale_size, NC_DIM_INFO_T **dim) { NC_DIM_INFO_T *new_dim; /* Dimension added to group */ @@ -2243,12 +2274,17 @@ read_scale(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name, dimscale_created++; - /* Remember these 4 values to uniquely identify this dataset in the + /* Remember these 4 (or 2 for HDF5 1.12) values to uniquely identify this dataset in the * HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + new_hdf5_dim->hdf5_objid.fileno = statbuf->fileno; + new_hdf5_dim->hdf5_objid.token = statbuf->token; +#else new_hdf5_dim->hdf5_objid.fileno[0] = statbuf->fileno[0]; new_hdf5_dim->hdf5_objid.fileno[1] = statbuf->fileno[1]; new_hdf5_dim->hdf5_objid.objno[0] = statbuf->objno[0]; new_hdf5_dim->hdf5_objid.objno[1] = statbuf->objno[1]; +#endif /* If the dimscale has an unlimited dimension, then this dimension * is unlimited. */ @@ -2319,7 +2355,12 @@ exit: */ static int read_dataset(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name, - const H5G_stat_t *statbuf) +#if H5_VERSION_GE(1,12,0) + const H5O_info2_t *statbuf +#else + const H5G_stat_t *statbuf +#endif +) { NC_DIM_INFO_T *dim = NULL; /* Dimension created for scales */ NC_HDF5_DIM_INFO_T *hdf5_dim; @@ -2431,8 +2472,13 @@ read_hdf5_obj(hid_t grpid, const char *name, const H5L_info_t *info, BAIL(H5_ITER_ERROR); /* Get info about the object.*/ +#if H5_VERSION_GE(1,12,0) + if (H5Oget_info3(oinfo.oid, &oinfo.statbuf, H5O_INFO_BASIC) < 0) + BAIL(H5_ITER_ERROR); +#else if (H5Gget_objinfo(oinfo.oid, ".", 1, &oinfo.statbuf) < 0) BAIL(H5_ITER_ERROR); +#endif strncpy(oinfo.oname, name, NC_MAX_NAME); diff --git a/libhdf5/nc4hdf.c b/libhdf5/nc4hdf.c index 5042d5bf0..df5e493ad 100644 --- a/libhdf5/nc4hdf.c +++ b/libhdf5/nc4hdf.c @@ -2160,10 +2160,19 @@ nc4_rec_match_dimscales(NC_GRP_INFO_T *grp) /* Check for exact match of fileno/objid arrays * to find identical objects in HDF5 file. */ +#if H5_VERSION_GE(1,12,0) + int token_cmp; + if (H5Otoken_cmp(hdf5_var->hdf_datasetid, &hdf5_var->dimscale_hdf5_objids[d].token, &hdf5_dim->hdf5_objid.token, &token_cmp) < 0) + return NC_EHDFERR; + + if (hdf5_var->dimscale_hdf5_objids[d].fileno == hdf5_dim->hdf5_objid.fileno && + token_cmp == 0) +#else if (hdf5_var->dimscale_hdf5_objids[d].fileno[0] == hdf5_dim->hdf5_objid.fileno[0] && hdf5_var->dimscale_hdf5_objids[d].objno[0] == hdf5_dim->hdf5_objid.objno[0] && hdf5_var->dimscale_hdf5_objids[d].fileno[1] == hdf5_dim->hdf5_objid.fileno[1] && hdf5_var->dimscale_hdf5_objids[d].objno[1] == hdf5_dim->hdf5_objid.objno[1]) +#endif { LOG((4, "%s: for dimension %d, found dim %s", __func__, d, dim->hdr.name)); From 9ac441ad6a30f76d2b37fb88bcf1845ab580d9be Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Wed, 15 Apr 2020 05:53:59 -0600 Subject: [PATCH 2/6] cleanup --- include/nc4dispatch.h | 3 +- libdispatch/dvarinq.c | 72 ------------------------------------------- 2 files changed, 1 insertion(+), 74 deletions(-) diff --git a/include/nc4dispatch.h b/include/nc4dispatch.h index 1403c80dc..3cac0b70c 100644 --- a/include/nc4dispatch.h +++ b/include/nc4dispatch.h @@ -110,8 +110,7 @@ extern "C" { int *shufflep, int *deflatep, int *deflate_levelp, int *fletcher32p, int *contiguousp, size_t *chunksizesp, int *no_fill, void *fill_valuep, int *endiannessp, - unsigned int* idp, size_t* nparamsp, unsigned int* params - ); + unsigned int* idp, size_t* nparamsp, unsigned int* params); EXTERNL int NC4_inq_varid(int ncid, const char *name, int *varidp); diff --git a/libdispatch/dvarinq.c b/libdispatch/dvarinq.c index 5f720450c..1684c57db 100644 --- a/libdispatch/dvarinq.c +++ b/libdispatch/dvarinq.c @@ -735,76 +735,4 @@ nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp) return stat; } -/*! -Learn all about a variable. - -@param[in] ncid ncid for file. -@param[in] varid varid for variable in question. -@param[out] name Pointer to memory to contain the name of the -variable. -@param[out] xtypep Pointer to memory to contain the type of the -variable. -@param[out] ndimsp Pointer to memory to store the number of associated -dimensions for the variable. -@param[out] dimidsp Pointer to memory to store the dimids associated -with the variable. -@param[out] nattsp Pointer to memory to store the number of attributes -associated with the variable. -@param[out] shufflep Pointer to memory to store shuffle information -associated with the variable. -@param[out] deflatep Pointer to memory to store compression type -associated with the variable. -@param[out] deflate_levelp Pointer to memory to store compression -level associated with the variable. -@param[out] fletcher32p Pointer to memory to store compression -information associated with the variable. -@param[out] contiguousp Pointer to memory to store contiguous-data -information associated with the variable. -@param[out] chunksizesp Pointer to memory to store chunksize -information associated with the variable. -@param[out] no_fill Pointer to memory to store whether or not there is -a fill value associated with the variable. -@param[out] fill_valuep Pointer to memory to store the fill value (if -one exists) for the variable. -@param[out] endiannessp Pointer to memory to store endianness -value. One of ::NC_ENDIAN_BIG ::NC_ENDIAN_LITTLE ::NC_ENDIAN_NATIVE -@param[out] idp Pointer to memory to store filter id. -@param[out] nparamsp Pointer to memory to store filter parameter count. -@param[out] params Pointer to vector of unsigned integers into which -to store filter parameters. -\note Expose access to nc_inq_var_all(). - -\returns ::NC_NOERR No error. -\returns ::NC_EBADID Bad ncid. -\returns ::NC_ENOTVAR Bad varid. -\returns ::NC_ENOMEM Out of memory. -\returns ::NC_EINVAL Invalid input. -\author Ed Hartnett, Dennis Heimbigner -\internal -\ingroup variables -*/ -#if 0 -int -NC_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, - int *ndimsp, int *dimidsp, int *nattsp, - int *shufflep, int *deflatep, int *deflate_levelp, - int *fletcher32p, int *contiguousp, size_t *chunksizesp, - int *no_fill, void *fill_valuep, int *endiannessp, - unsigned int* unused1, size_t* unused2, unsigned int* unused3 - ) -{ - NC* ncp; - int stat = NC_check_id(ncid,&ncp); - if(stat != NC_NOERR) return stat; - return ncp->dispatch->inq_var_all( - ncid, varid, name, xtypep, - ndimsp, dimidsp, nattsp, - shufflep, deflatep, deflate_levelp, fletcher32p, - contiguousp, chunksizesp, - no_fill, fill_valuep, - endiannessp, - NULL, NULL, NULL); -} -#endif - /*! \} */ /* End of named group ...*/ From 2dda52efc92a62e1ac4d933b756a9fe6bce3dc43 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Wed, 15 Apr 2020 05:59:27 -0600 Subject: [PATCH 3/6] checking nc_inq_var_chunking() with classic formats --- nc_test/tst_formats.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nc_test/tst_formats.c b/nc_test/tst_formats.c index 2bf63b4be..380adc5e2 100644 --- a/nc_test/tst_formats.c +++ b/nc_test/tst_formats.c @@ -173,6 +173,7 @@ main(int argc, char **argv) int fill_value = TEST_VAL_42 * 2; int shuffle_in, deflate_in, deflate_level_in; int options_mask_in, pixels_per_block_in; + int storage_in; /* Try to set fill mode after data have been written. */ sprintf(file_name, "%s_%d_%d_%d_elatefill.nc", FILE_NAME_BASE, format[f], d, a); @@ -191,6 +192,12 @@ main(int argc, char **argv) * all formats. */ if (nc_inq_var_szip(ncid, varid, &options_mask_in, &pixels_per_block_in)) ERR; if (options_mask_in || pixels_per_block_in) ERR; + + /* Since chunking is unset for netCDF-4 files, and + * unavailable for classic formats, this will tell us + * the var is contiguous. */ + if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR; + if (storage_in != NC_CONTIGUOUS) ERR; if (nc_enddef(ncid)) ERR; /* For netCDF-4, we don't actually have to write data to From b9e16129c6574a453b0326a18b58c37bca2f8060 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Wed, 15 Apr 2020 06:07:27 -0600 Subject: [PATCH 4/6] more testing after enddef --- nc_test/tst_formats.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nc_test/tst_formats.c b/nc_test/tst_formats.c index 380adc5e2..8c9c9343d 100644 --- a/nc_test/tst_formats.c +++ b/nc_test/tst_formats.c @@ -241,6 +241,10 @@ main(int argc, char **argv) if (nc_inq_var_szip(ncid, varid, &options_mask_in, &pixels_per_block_in)) ERR; if (options_mask_in || pixels_per_block_in) ERR; + /* Storage is (still) contiguous. */ + if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR; + if (storage_in != NC_CONTIGUOUS) ERR; + if (nc_close(ncid)) ERR; /* Open the file and check data. */ From 4cdb6596b69c61ce657c0fc1c9c20bad0cad0e70 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Wed, 15 Apr 2020 06:10:12 -0600 Subject: [PATCH 5/6] whitespace cleanup of test --- nc_test/tst_formats.c | 548 +++++++++++++++++++++--------------------- 1 file changed, 274 insertions(+), 274 deletions(-) diff --git a/nc_test/tst_formats.c b/nc_test/tst_formats.c index 8c9c9343d..34d7390cf 100644 --- a/nc_test/tst_formats.c +++ b/nc_test/tst_formats.c @@ -24,237 +24,237 @@ void determine_test_formats(int *num_formats, int *format) { - int ind = 0; - int num; + int ind = 0; + int num; - /* Check inputs. */ - assert(num_formats && format); + /* Check inputs. */ + assert(num_formats && format); - /* We always have classic and 64-bit offset */ - num = 2; - format[ind++] = NC_FORMAT_CLASSIC; - format[ind++] = NC_FORMAT_64BIT_OFFSET; + /* We always have classic and 64-bit offset */ + num = 2; + format[ind++] = NC_FORMAT_CLASSIC; + format[ind++] = NC_FORMAT_64BIT_OFFSET; - /* Do we have netCDF-4 and netCDF-4 classic? */ + /* Do we have netCDF-4 and netCDF-4 classic? */ #ifdef USE_HDF5 - num += 2; - format[ind++] = NC_FORMAT_NETCDF4; - format[ind++] = NC_FORMAT_NETCDF4_CLASSIC; + num += 2; + format[ind++] = NC_FORMAT_NETCDF4; + format[ind++] = NC_FORMAT_NETCDF4_CLASSIC; #endif /* USE_HDF5 */ - /* Do we have CDF5? */ + /* Do we have CDF5? */ #ifdef ENABLE_CDF5 - num++; - format[ind++] = NC_FORMAT_CDF5; + num++; + format[ind++] = NC_FORMAT_CDF5; #endif /* ENABLE_CDF5 */ - *num_formats = num; + *num_formats = num; } /* Function to test nc_inq_format(). */ int check_inq_format(int ncid, int expected_format, int expected_extended_format, int expected_mode) { - int format; - int extended_format; - int mode; + int format; + int extended_format; + int mode; - if (nc_inq_format(ncid + 66000, NULL) != NC_EBADID) ERR; - if (nc_inq_format(ncid, NULL)) ERR; - if (nc_inq_format(ncid, &format)) ERR; - if (format != expected_format) { - printf("format %d expected_format %d\n", format, expected_format); - ERR; - } - if (nc_inq_format_extended(ncid + 66000, &extended_format, &mode) != NC_EBADID) ERR; - { - int mode; - if (nc_inq_format_extended(ncid, NULL, &mode)) ERR; - if (mode != expected_mode) { - printf("expected_mode %x mode %x\n", expected_mode, mode); - /*ERR;*/ - } - } - { - int extended_format; - if (nc_inq_format_extended(ncid, &extended_format, NULL)) ERR; - if (extended_format != expected_extended_format) ERR; - } + if (nc_inq_format(ncid + 66000, NULL) != NC_EBADID) ERR; + if (nc_inq_format(ncid, NULL)) ERR; + if (nc_inq_format(ncid, &format)) ERR; + if (format != expected_format) { + printf("format %d expected_format %d\n", format, expected_format); + ERR; + } + if (nc_inq_format_extended(ncid + 66000, &extended_format, &mode) != NC_EBADID) ERR; + { + int mode; + if (nc_inq_format_extended(ncid, NULL, &mode)) ERR; + if (mode != expected_mode) { + printf("expected_mode %x mode %x\n", expected_mode, mode); + /*ERR;*/ + } + } + { + int extended_format; + if (nc_inq_format_extended(ncid, &extended_format, NULL)) ERR; + if (extended_format != expected_extended_format) ERR; + } - if (nc_inq_format_extended(ncid, &extended_format, &mode)) ERR; - if (mode != expected_mode) ERR; - if (extended_format != expected_extended_format) ERR; + if (nc_inq_format_extended(ncid, &extended_format, &mode)) ERR; + if (mode != expected_mode) ERR; + if (extended_format != expected_extended_format) ERR; - /* Nothing to do with inq_format, but let's check the base_pe - * functions. */ - if (nc_set_base_pe(ncid, 0)) ERR; - if (nc_inq_base_pe(ncid, NULL)) ERR; + /* Nothing to do with inq_format, but let's check the base_pe + * functions. */ + if (nc_set_base_pe(ncid, 0)) ERR; + if (nc_inq_base_pe(ncid, NULL)) ERR; - return 0; + return 0; } int main(int argc, char **argv) { - printf("\n*** Testing netcdf format functions.\n"); - { - int ncid; - int f, d, a; - int format[MAX_NUM_FORMATS]; - int num_formats; - int ret; + printf("\n*** Testing netcdf format functions.\n"); + { + int ncid; + int f, d, a; + int format[MAX_NUM_FORMATS]; + int num_formats; + int ret; - /* How many formats to be tested? */ - determine_test_formats(&num_formats, format); + /* How many formats to be tested? */ + determine_test_formats(&num_formats, format); - for (f = 0; f < num_formats; f++) - { - printf("*** testing nc_inq_format() and nc_inq_format_extended() with format %d...", format[f]); - { - char file_name[NC_MAX_NAME + 1]; - int expected_mode; - int expected_extended_format; - - sprintf(file_name, "%s_%d.nc", FILE_NAME_BASE, format[f]); - - /* Set up test. */ - switch (format[f]) { - case NC_FORMAT_CLASSIC: - expected_extended_format = NC_FORMATX_NC3; - expected_mode = 0; - break; - case NC_FORMAT_64BIT_OFFSET: - expected_extended_format = NC_FORMATX_NC3; - expected_mode = NC_64BIT_OFFSET; - break; - case NC_FORMAT_CDF5: - expected_extended_format = NC_FORMATX_NC3; - expected_mode = NC_CDF5; - break; - case NC_FORMAT_NETCDF4: - expected_extended_format = NC_FORMATX_NC4; - expected_mode = NC_NETCDF4; - break; - case NC_FORMAT_NETCDF4_CLASSIC: - expected_extended_format = NC_FORMATX_NC4; - expected_mode = NC_NETCDF4|NC_CLASSIC_MODEL; - break; - } - if (nc_set_default_format(format[f], NULL)) ERR; - - /* Create a file. */ - if (nc_create(file_name, 0, &ncid)) ERR; - if (check_inq_format(ncid, format[f], expected_extended_format, expected_mode)) ERR; - if (nc_close(ncid)) ERR; - - /* Re-open the file and check it again. */ - if (nc_open(file_name, 0, &ncid)) ERR; - /* Classic flag is not set on mode in nc_open(). Not sure if - * this is a bug or not. */ - if (format[f] == NC_FORMAT_NETCDF4_CLASSIC) - expected_mode = NC_NETCDF4; - if (check_inq_format(ncid, format[f], expected_extended_format, expected_mode)) ERR; - if (nc_close(ncid)) ERR; - } - SUMMARIZE_ERR; - /* Test without and with actual data write. */ - for (d = 0; d < NUM_FILL_WRITE_TESTS; d++) - { - /* Test setting _FillValue directly or calling nc_def_var_fill(). */ - for (a = 0; a < NUM_FILL_WRITE_METHOD_TESTS; a++) + for (f = 0; f < num_formats; f++) + { + printf("*** testing nc_inq_format() and nc_inq_format_extended() with format %d...", format[f]); { - printf("*** testing late fill handling with format %d writing %d " - "using def_var_fill %d...", format[f], d, a); - char file_name[NC_MAX_NAME + 1]; - int dimid, varid; - size_t index = {DIM_LEN - 1}; - int data = TEST_VAL_42; - int data_in; - int fill_value = TEST_VAL_42 * 2; - int shuffle_in, deflate_in, deflate_level_in; - int options_mask_in, pixels_per_block_in; - int storage_in; + char file_name[NC_MAX_NAME + 1]; + int expected_mode; + int expected_extended_format; - /* Try to set fill mode after data have been written. */ - sprintf(file_name, "%s_%d_%d_%d_elatefill.nc", FILE_NAME_BASE, format[f], d, a); - if (nc_set_default_format(format[f], NULL)) ERR; - if (nc_create(file_name, 0, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME, DIM_LEN, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIM1, &dimid, &varid)) ERR; + sprintf(file_name, "%s_%d.nc", FILE_NAME_BASE, format[f]); - /* There is no deflate on this var, and that is true in - * all formats. */ - if (nc_inq_var_deflate(ncid, varid, &shuffle_in, &deflate_in, - &deflate_level_in)) ERR; - if (shuffle_in || deflate_in || deflate_level_in) ERR; - - /* There is no szip on this var, and that is true in - * all formats. */ - if (nc_inq_var_szip(ncid, varid, &options_mask_in, &pixels_per_block_in)) ERR; - if (options_mask_in || pixels_per_block_in) ERR; + /* Set up test. */ + switch (format[f]) { + case NC_FORMAT_CLASSIC: + expected_extended_format = NC_FORMATX_NC3; + expected_mode = 0; + break; + case NC_FORMAT_64BIT_OFFSET: + expected_extended_format = NC_FORMATX_NC3; + expected_mode = NC_64BIT_OFFSET; + break; + case NC_FORMAT_CDF5: + expected_extended_format = NC_FORMATX_NC3; + expected_mode = NC_CDF5; + break; + case NC_FORMAT_NETCDF4: + expected_extended_format = NC_FORMATX_NC4; + expected_mode = NC_NETCDF4; + break; + case NC_FORMAT_NETCDF4_CLASSIC: + expected_extended_format = NC_FORMATX_NC4; + expected_mode = NC_NETCDF4|NC_CLASSIC_MODEL; + break; + } + if (nc_set_default_format(format[f], NULL)) ERR; - /* Since chunking is unset for netCDF-4 files, and - * unavailable for classic formats, this will tell us - * the var is contiguous. */ - if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR; - if (storage_in != NC_CONTIGUOUS) ERR; - - if (nc_enddef(ncid)) ERR; - /* For netCDF-4, we don't actually have to write data to - * prevent future setting of the fill value. Once the user - * leaves calls enddef after defining a var, fill values - * can no longer be set. */ - if (d) - if (nc_put_var1_int(ncid, varid, &index, &data)) ERR; - if (nc_redef(ncid)) ERR; - if (a) - { - ret = nc_def_var_fill(ncid, varid, NC_FILL, &fill_value); - } - else - { - ret = nc_put_att_int(ncid, varid, "_FillValue", NC_INT, 1, - &fill_value); - } + /* Create a file. */ + if (nc_create(file_name, 0, &ncid)) ERR; + if (check_inq_format(ncid, format[f], expected_extended_format, expected_mode)) ERR; + if (nc_close(ncid)) ERR; - /* Setting the fill value after data are written is - * allowed in classic formats, but not netcdf-4. */ - if (format[f] == NC_FORMAT_CLASSIC || format[f] == NC_FORMAT_64BIT_OFFSET || - format[f] == NC_FORMAT_CDF5) - { - if (ret) ERR; - } - else - { - if (ret != (a ? NC_ELATEDEF: NC_ELATEFILL)) ERR; - } - if (nc_enddef(ncid)) ERR; + /* Re-open the file and check it again. */ + if (nc_open(file_name, 0, &ncid)) ERR; + /* Classic flag is not set on mode in nc_open(). Not sure if + * this is a bug or not. */ + if (format[f] == NC_FORMAT_NETCDF4_CLASSIC) + expected_mode = NC_NETCDF4; + if (check_inq_format(ncid, format[f], expected_extended_format, expected_mode)) ERR; + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; + /* Test without and with actual data write. */ + for (d = 0; d < NUM_FILL_WRITE_TESTS; d++) + { + /* Test setting _FillValue directly or calling nc_def_var_fill(). */ + for (a = 0; a < NUM_FILL_WRITE_METHOD_TESTS; a++) + { + printf("*** testing late fill handling with format %d writing %d " + "using def_var_fill %d...", format[f], d, a); + char file_name[NC_MAX_NAME + 1]; + int dimid, varid; + size_t index = {DIM_LEN - 1}; + int data = TEST_VAL_42; + int data_in; + int fill_value = TEST_VAL_42 * 2; + int shuffle_in, deflate_in, deflate_level_in; + int options_mask_in, pixels_per_block_in; + int storage_in; - /* There is (still!) no deflate on this var, and that - * is true in all formats. */ - if (nc_inq_var_deflate(ncid, varid, &shuffle_in, &deflate_in, - &deflate_level_in)) ERR; - if (shuffle_in || deflate_in || deflate_level_in) ERR; - - /* There is (still!) no szip on this var, and that is - * true in all formats. */ - if (nc_inq_var_szip(ncid, varid, &options_mask_in, &pixels_per_block_in)) ERR; - if (options_mask_in || pixels_per_block_in) ERR; - - /* Storage is (still) contiguous. */ - if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR; - if (storage_in != NC_CONTIGUOUS) ERR; - - if (nc_close(ncid)) ERR; + /* Try to set fill mode after data have been written. */ + sprintf(file_name, "%s_%d_%d_%d_elatefill.nc", FILE_NAME_BASE, format[f], d, a); + if (nc_set_default_format(format[f], NULL)) ERR; + if (nc_create(file_name, 0, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME, DIM_LEN, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIM1, &dimid, &varid)) ERR; - /* Open the file and check data. */ - if (nc_open(file_name, NC_NOWRITE, &ncid)) ERR; - if (nc_get_var1_int(ncid, varid, &index, &data_in)) ERR; - if (data_in != (d ? data : NC_FILL_INT)) ERR; - if (nc_close(ncid)) ERR; - SUMMARIZE_ERR; - } /* next fill value method test */ - } /* next fill val write test */ + /* There is no deflate on this var, and that is true in + * all formats. */ + if (nc_inq_var_deflate(ncid, varid, &shuffle_in, &deflate_in, + &deflate_level_in)) ERR; + if (shuffle_in || deflate_in || deflate_level_in) ERR; + + /* There is no szip on this var, and that is true in + * all formats. */ + if (nc_inq_var_szip(ncid, varid, &options_mask_in, &pixels_per_block_in)) ERR; + if (options_mask_in || pixels_per_block_in) ERR; + + /* Since chunking is unset for netCDF-4 files, and + * unavailable for classic formats, this will tell us + * the var is contiguous. */ + if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR; + if (storage_in != NC_CONTIGUOUS) ERR; + + if (nc_enddef(ncid)) ERR; + /* For netCDF-4, we don't actually have to write data to + * prevent future setting of the fill value. Once the user + * leaves calls enddef after defining a var, fill values + * can no longer be set. */ + if (d) + if (nc_put_var1_int(ncid, varid, &index, &data)) ERR; + if (nc_redef(ncid)) ERR; + if (a) + { + ret = nc_def_var_fill(ncid, varid, NC_FILL, &fill_value); + } + else + { + ret = nc_put_att_int(ncid, varid, "_FillValue", NC_INT, 1, + &fill_value); + } + + /* Setting the fill value after data are written is + * allowed in classic formats, but not netcdf-4. */ + if (format[f] == NC_FORMAT_CLASSIC || format[f] == NC_FORMAT_64BIT_OFFSET || + format[f] == NC_FORMAT_CDF5) + { + if (ret) ERR; + } + else + { + if (ret != (a ? NC_ELATEDEF: NC_ELATEFILL)) ERR; + } + if (nc_enddef(ncid)) ERR; + + /* There is (still!) no deflate on this var, and that + * is true in all formats. */ + if (nc_inq_var_deflate(ncid, varid, &shuffle_in, &deflate_in, + &deflate_level_in)) ERR; + if (shuffle_in || deflate_in || deflate_level_in) ERR; + + /* There is (still!) no szip on this var, and that is + * true in all formats. */ + if (nc_inq_var_szip(ncid, varid, &options_mask_in, &pixels_per_block_in)) ERR; + if (options_mask_in || pixels_per_block_in) ERR; + + /* Storage is (still) contiguous. */ + if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR; + if (storage_in != NC_CONTIGUOUS) ERR; + + if (nc_close(ncid)) ERR; + + /* Open the file and check data. */ + if (nc_open(file_name, NC_NOWRITE, &ncid)) ERR; + if (nc_get_var1_int(ncid, varid, &index, &data_in)) ERR; + if (data_in != (d ? data : NC_FILL_INT)) ERR; + if (nc_close(ncid)) ERR; + SUMMARIZE_ERR; + } /* next fill value method test */ + } /* next fill val write test */ #define NDIM2 2 #define DIM1_NAME "dim1" @@ -262,84 +262,84 @@ main(int argc, char **argv) #define NTYPE 6 #define DATA_LEN 4 - printf("*** testing handling of null strides with format %d... ", - format[f]); - { - char file_name[NC_MAX_NAME + 1]; - char var_name[NC_MAX_NAME + 1]; - int dimid[NDIM2]; - int xtype[NTYPE] = {NC_BYTE, NC_CHAR, NC_SHORT, NC_INT, NC_FLOAT, NC_DOUBLE}; - int type_size[NTYPE] = {1, 1, 2, 4, 4, 8}; - int varid[NTYPE]; - size_t start[NDIM2] = {0, 0}; - size_t count[NDIM2] = {2, 2}; - signed char data_byte[DATA_LEN] = {1, 2, 3, 4}; - unsigned char data_char[DATA_LEN] = {1, 2, 3, 4}; - short data_short[DATA_LEN] = {1, 2, 3, 4}; - int data_int[DATA_LEN] = {1, 2, 3, 4}; - float data_float[DATA_LEN] = {1, 2, 3, 4}; - double data_double[DATA_LEN] = {1, 2, 3, 4}; - void *data_ptr[NTYPE] = {data_byte, data_char, data_short, data_int, data_float, data_double}; - int t; - - /* Create the test file. */ - sprintf(file_name, "%s_%d_null_strides.nc", FILE_NAME_BASE, format[f]); - if (nc_set_default_format(format[f], NULL)) ERR; - if (nc_create(file_name, 0, &ncid)) ERR; - if (nc_def_dim(ncid, DIM1_NAME, DIM_LEN, &dimid[0])) ERR; - if (nc_def_dim(ncid, DIM2_NAME, DIM_LEN, &dimid[1])) ERR; - for (t = 0; t < NTYPE; t++) + printf("*** testing handling of null strides with format %d... ", + format[f]); { - sprintf(var_name, "var_%d", xtype[t]); - if (nc_def_var(ncid, var_name, xtype[t], NDIM2, dimid, &varid[t])) ERR; - } - if (nc_enddef(ncid)) ERR; + char file_name[NC_MAX_NAME + 1]; + char var_name[NC_MAX_NAME + 1]; + int dimid[NDIM2]; + int xtype[NTYPE] = {NC_BYTE, NC_CHAR, NC_SHORT, NC_INT, NC_FLOAT, NC_DOUBLE}; + int type_size[NTYPE] = {1, 1, 2, 4, 4, 8}; + int varid[NTYPE]; + size_t start[NDIM2] = {0, 0}; + size_t count[NDIM2] = {2, 2}; + signed char data_byte[DATA_LEN] = {1, 2, 3, 4}; + unsigned char data_char[DATA_LEN] = {1, 2, 3, 4}; + short data_short[DATA_LEN] = {1, 2, 3, 4}; + int data_int[DATA_LEN] = {1, 2, 3, 4}; + float data_float[DATA_LEN] = {1, 2, 3, 4}; + double data_double[DATA_LEN] = {1, 2, 3, 4}; + void *data_ptr[NTYPE] = {data_byte, data_char, data_short, data_int, data_float, data_double}; + int t; - /* Write some data. */ - for (t = 0; t < NTYPE; t++) + /* Create the test file. */ + sprintf(file_name, "%s_%d_null_strides.nc", FILE_NAME_BASE, format[f]); + if (nc_set_default_format(format[f], NULL)) ERR; + if (nc_create(file_name, 0, &ncid)) ERR; + if (nc_def_dim(ncid, DIM1_NAME, DIM_LEN, &dimid[0])) ERR; + if (nc_def_dim(ncid, DIM2_NAME, DIM_LEN, &dimid[1])) ERR; + for (t = 0; t < NTYPE; t++) + { + sprintf(var_name, "var_%d", xtype[t]); + if (nc_def_var(ncid, var_name, xtype[t], NDIM2, dimid, &varid[t])) ERR; + } + if (nc_enddef(ncid)) ERR; + + /* Write some data. */ + for (t = 0; t < NTYPE; t++) + { + if (nc_put_vars(ncid, varid[t], start, count, NULL, data_ptr[t])) ERR; + } + if (nc_close(ncid)) ERR; + + /* Open the file and check data. */ + { + int ndims, nvars, ngatts, unlimdimid; + + if (nc_open(file_name, NC_NOWRITE, &ncid)) ERR; + if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR; + if (ndims != 2 || nvars != NTYPE || ngatts != 0 || unlimdimid != -1) ERR; + for (t = 0; t < NTYPE; t++) + { + nc_type my_type; + int var_ndims, natts; + int var_dimid[NDIM2]; + void *data_in; + + if (nc_inq_var(ncid, varid[t], NULL, &my_type, &var_ndims, var_dimid, &natts)) ERR; + if (my_type != xtype[t] || var_ndims != 2 || var_dimid[0] != dimid[0] || + var_dimid[1] != dimid[1] || natts != 0) ERR; + if (!(data_in = malloc(DATA_LEN * type_size[t]))) ERR; + if (nc_get_vars(ncid, varid[t], start, count, NULL, data_in)) ERR; + if (memcmp(data_in, data_ptr[t], DATA_LEN * type_size[t])) ERR; + free(data_in); + + } + if (nc_close(ncid)) ERR; + } + + } + SUMMARIZE_ERR; + printf("*** testing bad name for nc_open/nc_create with format %d... ", format[f]); { - if (nc_put_vars(ncid, varid[t], start, count, NULL, data_ptr[t])) ERR; + int ncid; + if (nc_set_default_format(format[f], NULL)) ERR; + if (nc_create(NULL, 0, &ncid) != NC_EINVAL) ERR; + if (nc_open(NULL, NC_NOWRITE, &ncid) != NC_EINVAL) ERR; + if (nc_delete(NULL) != NC_EINVAL) ERR; } - if (nc_close(ncid)) ERR; - - /* Open the file and check data. */ - { - int ndims, nvars, ngatts, unlimdimid; - - if (nc_open(file_name, NC_NOWRITE, &ncid)) ERR; - if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR; - if (ndims != 2 || nvars != NTYPE || ngatts != 0 || unlimdimid != -1) ERR; - for (t = 0; t < NTYPE; t++) - { - nc_type my_type; - int var_ndims, natts; - int var_dimid[NDIM2]; - void *data_in; - - if (nc_inq_var(ncid, varid[t], NULL, &my_type, &var_ndims, var_dimid, &natts)) ERR; - if (my_type != xtype[t] || var_ndims != 2 || var_dimid[0] != dimid[0] || - var_dimid[1] != dimid[1] || natts != 0) ERR; - if (!(data_in = malloc(DATA_LEN * type_size[t]))) ERR; - if (nc_get_vars(ncid, varid[t], start, count, NULL, data_in)) ERR; - if (memcmp(data_in, data_ptr[t], DATA_LEN * type_size[t])) ERR; - free(data_in); - - } - if (nc_close(ncid)) ERR; - } - - } - SUMMARIZE_ERR; - printf("*** testing bad name for nc_open/nc_create with format %d... ", format[f]); - { - int ncid; - if (nc_set_default_format(format[f], NULL)) ERR; - if (nc_create(NULL, 0, &ncid) != NC_EINVAL) ERR; - if (nc_open(NULL, NC_NOWRITE, &ncid) != NC_EINVAL) ERR; - if (nc_delete(NULL) != NC_EINVAL) ERR; - } - SUMMARIZE_ERR; - } /* next format */ - } - FINAL_RESULTS; + SUMMARIZE_ERR; + } /* next format */ + } + FINAL_RESULTS; } From 1a6228f17fadfe7ced36ec6b3da3c17b9a262532 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Thu, 23 Apr 2020 23:32:29 -0500 Subject: [PATCH 6/6] fixed missing declaration --- h5_test/tst_h_dimscales4.c | 1 + 1 file changed, 1 insertion(+) diff --git a/h5_test/tst_h_dimscales4.c b/h5_test/tst_h_dimscales4.c index f2cba404d..c12ca9624 100644 --- a/h5_test/tst_h_dimscales4.c +++ b/h5_test/tst_h_dimscales4.c @@ -45,6 +45,7 @@ herr_t alien_visitor(hid_t did, unsigned dim, hid_t dsid, objid->fileno = statbuf.fileno; objid->token = statbuf.token; #else + H5G_stat_t statbuf; if (H5Gget_objinfo(dsid, ".", 1, &statbuf) < 0) ERR; objid->fileno[0] = statbuf.fileno[0]; objid->objno[0] = statbuf.objno[0];