diff --git a/include/nc4internal.h b/include/nc4internal.h index e750ec63d..4088062b5 100644 --- a/include/nc4internal.h +++ b/include/nc4internal.h @@ -153,7 +153,7 @@ typedef struct NC_VAR_INFO nc_bool_t created; /* Variable has already been created (_not_ that it was just created) */ nc_bool_t written_to; /* True if variable has data written to it */ struct NC_TYPE_INFO *type_info; - int atts_not_read; /* If true, the atts have not yet been read. */ + int atts_read; /* If true, the atts have been read. */ nc_bool_t meta_read; /* True if this vars metadata has been completely read. */ nc_bool_t coords_read; /* True if this var has hidden coordinates att, and it has been read. */ NCindex *att; /* NCindex */ @@ -229,7 +229,7 @@ typedef struct NC_GRP_INFO void *format_grp_info; struct NC_FILE_INFO *nc4_info; struct NC_GRP_INFO *parent; - int atts_not_read; + int atts_read; /* True if atts have been read for this group. */ NCindex* children; /* NCindex */ NCindex* dim; /* NCindex * */ NCindex* att; /* NCindex * */ diff --git a/libhdf4/hdf4file.c b/libhdf4/hdf4file.c index 3d8eb4b3a..f97ff37aa 100644 --- a/libhdf4/hdf4file.c +++ b/libhdf4/hdf4file.c @@ -415,6 +415,7 @@ nc4_var_list_add_full(NC_GRP_INFO_T* grp, const char* name, int ndims, nc_type x (*var)->created = NC_TRUE; (*var)->written_to = NC_TRUE; (*var)->format_var_info = format_var_info; + (*var)->atts_read = 1; /* Fill special type_info struct for variable type information. */ if ((retval = nc4_set_var_type(xtype, endianness, type_size, type_name, @@ -630,6 +631,7 @@ NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp, assert(nc4_info && nc4_info->root_grp); h5 = nc4_info; h5->no_write = NC_TRUE; + h5->root_grp->atts_read = 1; /* Allocate data to hold HDF4 specific file data. */ if (!(hdf4_file = malloc(sizeof(NC_HDF4_FILE_INFO_T)))) diff --git a/libhdf5/hdf5attr.c b/libhdf5/hdf5attr.c index 3aeb8ce97..978c33c2b 100644 --- a/libhdf5/hdf5attr.c +++ b/libhdf5/hdf5attr.c @@ -27,13 +27,14 @@ static int getattlist(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp, NCindex **attlist) { - NC_VAR_INFO_T* var; int retval; + assert(grp && attlist); + if (varid == NC_GLOBAL) { /* Do we need to read the atts? */ - if (grp->atts_not_read) + if (!grp->atts_read) if ((retval = nc4_read_atts(grp, NULL))) return retval; @@ -43,12 +44,14 @@ getattlist(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp, } else { + NC_VAR_INFO_T *var; + if (!(var = (NC_VAR_INFO_T *)ncindexith(grp->vars, varid))) return NC_ENOTVAR; assert(var->hdr.id == varid); /* Do we need to read the atts? */ - if (var->atts_not_read) + if (!var->atts_read) if ((retval = nc4_read_atts(grp, var))) return retval; diff --git a/libhdf5/hdf5create.c b/libhdf5/hdf5create.c index b09f26fcc..cf2ef4010 100644 --- a/libhdf5/hdf5create.c +++ b/libhdf5/hdf5create.c @@ -66,6 +66,7 @@ nc4_create_file(const char *path, int cmode, size_t initialsz, BAIL(retval); nc4_info = NC4_DATA(nc); assert(nc4_info && nc4_info->root_grp); + nc4_info->root_grp->atts_read = 1; /* Add struct to hold HDF5-specific file metadata. */ if (!(nc4_info->format_file_info = calloc(1, sizeof(NC_HDF5_FILE_INFO_T)))) diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index a40c3b767..395d9fd64 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -727,7 +727,7 @@ NC4_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp) if (nattsp) { /* Do we need to read the atts? */ - if (grp->atts_not_read) + if (!grp->atts_read) if ((retval = nc4_read_atts(grp, NULL))) return retval; diff --git a/libhdf5/hdf5grp.c b/libhdf5/hdf5grp.c index 058dab6f8..588273aa5 100644 --- a/libhdf5/hdf5grp.c +++ b/libhdf5/hdf5grp.c @@ -67,6 +67,11 @@ NC4_def_grp(int parent_ncid, const char *name, int *new_ncid) return retval; if (!(g->format_grp_info = calloc(1, sizeof(NC_HDF5_GRP_INFO_T)))) return NC_ENOMEM; + + /* For new groups, there are no atts to read from file. */ + g->atts_read = 1; + + /* Return the ncid to the user. */ if (new_ncid) *new_ncid = grp->nc4_info->controller->ext_ncid | g->hdr.id; diff --git a/libhdf5/hdf5internal.c b/libhdf5/hdf5internal.c index 7b74dc7b5..42387d9b4 100644 --- a/libhdf5/hdf5internal.c +++ b/libhdf5/hdf5internal.c @@ -837,7 +837,7 @@ nc4_hdf5_find_grp_var_att(int ncid, int varid, const char *name, int attnum, if (varid == NC_GLOBAL) { /* Do we need to read the atts? */ - if (my_grp->atts_not_read) + if (!my_grp->atts_read) if ((retval = nc4_read_atts(my_grp, NULL))) return retval; @@ -849,7 +849,7 @@ nc4_hdf5_find_grp_var_att(int ncid, int varid, const char *name, int attnum, return NC_ENOTVAR; /* Do we need to read the var attributes? */ - if (my_var->atts_not_read) + if (!my_var->atts_read) if ((retval = nc4_read_atts(my_grp, my_var))) return retval; diff --git a/libhdf5/hdf5open.c b/libhdf5/hdf5open.c index b0fae521f..70d9a0cc6 100644 --- a/libhdf5/hdf5open.c +++ b/libhdf5/hdf5open.c @@ -1308,7 +1308,7 @@ read_var(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name, H5Iinc_ref(hdf5_var->hdf_datasetid); /* Increment number of objects using ID */ incr_id_rc++; /* Indicate that we've incremented the ref. count (for errors) */ var->created = NC_TRUE; - var->atts_not_read = 1; /* Don't read var atts until user asks for one. */ + var->atts_read = 0; /* Try and read the dimids from the COORDINATES attribute. If it's * not present, we will have to do dimsscale matching to locate the @@ -2112,9 +2112,9 @@ nc4_read_atts(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var) /* Remember that we have read the atts for this var or group. */ if (var) - var->atts_not_read = 0; + var->atts_read = 1; else - grp->atts_not_read = 0; + grp->atts_read = 1; return NC_NOERR; } @@ -2569,9 +2569,6 @@ rec_read_metadata(NC_GRP_INFO_T *grp) BAIL(retval); } - /* Defer the reading of global atts until someone asks for one. */ - grp->atts_not_read = 1; - /* When reading existing file, mark all variables as written. */ for (i = 0; i < ncindexsize(grp->vars); i++) ((NC_VAR_INFO_T *)ncindexith(grp->vars, i))->written_to = NC_TRUE; diff --git a/libhdf5/hdf5var.c b/libhdf5/hdf5var.c index 46a8383e8..cf32c1398 100644 --- a/libhdf5/hdf5var.c +++ b/libhdf5/hdf5var.c @@ -410,6 +410,7 @@ NC4_def_var(int ncid, const char *name, nc_type xtype, var->is_new_var = NC_TRUE; var->meta_read = NC_TRUE; + var->atts_read = NC_TRUE; /* Point to the type, and increment its ref. count */ var->type_info = type;