diff --git a/libhdf5/hdf5var.c b/libhdf5/hdf5var.c index adbbdd3..01cd90c 100644 --- a/libhdf5/hdf5var.c +++ b/libhdf5/hdf5var.c @@ -106,6 +105,38 @@ nc4_reopen_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var) return NC_NOERR; } +int +nc4_open_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var) +{ + NC_HDF5_VAR_INFO_T *hdf5_var; + hid_t access_pid; + hid_t grpid; + + assert(var && var->format_var_info && grp && grp->format_grp_info); + + /* Get the HDF5-specific var info. */ + hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info; + + if (hdf5_var->hdf_datasetid) + { + /* Get the HDF5 group id. */ + grpid = ((NC_HDF5_GRP_INFO_T *)(grp->format_grp_info))->hdf_grpid; + + if ((access_pid = H5Pcreate(H5P_DATASET_ACCESS)) < 0) + return NC_EHDFERR; + if (H5Pset_chunk_cache(access_pid, var->chunk_cache_nelems, + var->chunk_cache_size, + var->chunk_cache_preemption) < 0) + return NC_EHDFERR; + if ((hdf5_var->hdf_datasetid = H5Dopen2(grpid, var->hdr.name, access_pid)) < 0) + return NC_EHDFERR; + if (H5Pclose(access_pid) < 0) + return NC_EHDFERR; + } + + return NC_NOERR; +} + /** * @internal Check a set of chunksizes to see if they specify a chunk * that is too big. @@ -1770,6 +1801,11 @@ NC4_put_vars(int ncid, int varid, const size_t *startp, const size_t *countp, mem_spaceid, file_spaceid, xfer_plistid, bufr) < 0) BAIL(NC_EHDFERR); + if (H5Dclose(hdf5_var->hdf_datasetid) < 0) + return NC_EHDFERR; + nc4_open_dataset(grp, var); /* Remember that we have written to this var so that Fill Value * can't be set for it. */ if (!var->written_to)