moving attribute HDF5 stuff to libhdf5

This commit is contained in:
Ed Hartnett 2018-11-07 14:21:57 -07:00
parent 11d725facc
commit 6f4b4ac80d
4 changed files with 29 additions and 20 deletions

View File

@ -130,7 +130,7 @@ typedef struct NC_ATT_INFO
nc_bool_t dirty; /* True if attribute modified */
nc_bool_t created; /* True if attribute already created */
nc_type nc_typeid; /* netCDF type of attribute's data */
hid_t native_hdf_typeid; /* Native HDF5 datatype for attribute's data */
/* hid_t native_hdf_typeid; /\* Native HDF5 datatype for attribute's data *\/ */
void *format_att_info;
void *data;
nc_vlen_t *vldata; /* only used for vlen */

View File

@ -258,14 +258,14 @@ nc4_close_netcdf4_file(NC_FILE_INFO_T *h5, int abort, NC_memio *memio)
int
nc4_close_hdf5_file(NC_FILE_INFO_T *h5, int abort, NC_memio *memio)
{
NC_HDF5_FILE_INFO_T *hdf5_info;
/* NC_HDF5_FILE_INFO_T *hdf5_info; */
int retval;
assert(h5 && h5->root_grp && h5->format_file_info);
LOG((3, "%s: h5->path %s abort %d", __func__, h5->controller->path, abort));
/* Get HDF5 specific info. */
hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info;
/* /\* Get HDF5 specific info. *\/ */
/* hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info; */
/* According to the docs, always end define mode on close. */
if (h5->flags & NC_INDEF)

View File

@ -510,13 +510,15 @@ nc4_rec_grp_HDF5_del(NC_GRP_INFO_T *grp)
/* Close HDF5 resources associated with global attributes. */
for (a = 0; a < ncindexsize(grp->att); a++)
{
NC_HDF5_ATT_INFO_T hdf5_att;
NC_HDF5_ATT_INFO_T *hdf5_att;
att = (NC_ATT_INFO_T *)ncindexith(grp->att, a);
assert(att);
assert(att && att->format_att_info);
hdf5_att = (NC_HDF5_ATT_INFO_T *)att->format_att_info;
/* Close the HDF5 typeid. */
if (att->native_hdf_typeid && H5Tclose(att->native_hdf_typeid) < 0)
if (hdf5_att->native_hdf_typeid &&
H5Tclose(hdf5_att->native_hdf_typeid) < 0)
return NC_EHDFERR;
}
@ -536,11 +538,14 @@ nc4_rec_grp_HDF5_del(NC_GRP_INFO_T *grp)
for (a = 0; a < ncindexsize(var->att); a++)
{
NC_HDF5_ATT_INFO_T *hdf5_att;
att = (NC_ATT_INFO_T *)ncindexith(var->att, a);
assert(att);
assert(att && att->format_att_info);
hdf5_att = (NC_HDF5_ATT_INFO_T *)att->format_att_info;
/* Close the HDF5 typeid if one is open. */
if (att->native_hdf_typeid && H5Tclose(att->native_hdf_typeid) < 0)
if (hdf5_att->native_hdf_typeid &&
H5Tclose(hdf5_att->native_hdf_typeid) < 0)
return NC_EHDFERR;
}
}

View File

@ -1033,36 +1033,40 @@ get_netcdf_type(NC_FILE_INFO_T *h5, hid_t native_typeid,
static int
read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att)
{
NC_HDF5_ATT_INFO_T *hdf5_att;
hid_t spaceid = 0, file_typeid = 0;
hsize_t dims[1] = {0}; /* netcdf attributes always 1-D. */
int retval = NC_NOERR;
size_t type_size;
int att_ndims;
hssize_t att_npoints;
H5T_class_t att_class;
int fixed_len_string = 0;
size_t fixed_size = 0;
int retval = NC_NOERR;
assert(att->hdr.name);
assert(att && att->hdr.name && att->format_att_info);
LOG((5, "%s: att->hdr.id %d att->hdr.name %s att->nc_typeid %d att->len %d",
__func__, att->hdr.id, att->hdr.name, (int)att->nc_typeid, att->len));
/* Get HDF5-sepecific info stuct for this attribute. */
hdf5_att = (NC_HDF5_ATT_INFO_T *)att->format_att_info;
/* Get type of attribute in file. */
if ((file_typeid = H5Aget_type(attid)) < 0)
return NC_EATTMETA;
if ((att->native_hdf_typeid = H5Tget_native_type(file_typeid,
if ((hdf5_att->native_hdf_typeid = H5Tget_native_type(file_typeid,
H5T_DIR_DEFAULT)) < 0)
BAIL(NC_EHDFERR);
if ((att_class = H5Tget_class(att->native_hdf_typeid)) < 0)
if ((att_class = H5Tget_class(hdf5_att->native_hdf_typeid)) < 0)
BAIL(NC_EATTMETA);
if (att_class == H5T_STRING &&
!H5Tis_variable_str(att->native_hdf_typeid))
!H5Tis_variable_str(hdf5_att->native_hdf_typeid))
{
fixed_len_string++;
if (!(fixed_size = H5Tget_size(att->native_hdf_typeid)))
if (!(fixed_size = H5Tget_size(hdf5_att->native_hdf_typeid)))
BAIL(NC_EATTMETA);
}
if ((retval = get_netcdf_type(grp->nc4_info, att->native_hdf_typeid,
if ((retval = get_netcdf_type(grp->nc4_info, hdf5_att->native_hdf_typeid,
&(att->nc_typeid))))
BAIL(retval);
@ -1139,7 +1143,7 @@ read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att)
{
if (!(att->vldata = malloc((unsigned int)(att->len * sizeof(hvl_t)))))
BAIL(NC_ENOMEM);
if (H5Aread(attid, att->native_hdf_typeid, att->vldata) < 0)
if (H5Aread(attid, hdf5_att->native_hdf_typeid, att->vldata) < 0)
BAIL(NC_EATTMETA);
}
else if (att->nc_typeid == NC_STRING)
@ -1167,7 +1171,7 @@ read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att)
BAIL(NC_ENOMEM);
/* Read the fixed-len strings as one big block. */
if (H5Aread(attid, att->native_hdf_typeid, contig_buf) < 0) {
if (H5Aread(attid, hdf5_att->native_hdf_typeid, contig_buf) < 0) {
free(contig_buf);
BAIL(NC_EATTMETA);
}
@ -1192,7 +1196,7 @@ read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att)
else
{
/* Read variable-length string atts. */
if (H5Aread(attid, att->native_hdf_typeid, att->stdata) < 0)
if (H5Aread(attid, hdf5_att->native_hdf_typeid, att->stdata) < 0)
BAIL(NC_EATTMETA);
}
}
@ -1200,7 +1204,7 @@ read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att)
{
if (!(att->data = malloc((unsigned int)(att->len * type_size))))
BAIL(NC_ENOMEM);
if (H5Aread(attid, att->native_hdf_typeid, att->data) < 0)
if (H5Aread(attid, hdf5_att->native_hdf_typeid, att->data) < 0)
BAIL(NC_EATTMETA);
}
}