From 3ec8b34bfb3bf6d82f8873d833db485f35e56d22 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 19 Nov 2018 09:23:43 -0700 Subject: [PATCH] removed unneeded HDF5 fields --- include/nc4internal.h | 2 -- libhdf5/hdf5internal.c | 20 -------------- libhdf5/hdf5open.c | 63 ++++++++++++++---------------------------- libhdf5/nc4hdf.c | 9 +++--- 4 files changed, 25 insertions(+), 69 deletions(-) diff --git a/include/nc4internal.h b/include/nc4internal.h index fdde906c8..48b8ec66e 100644 --- a/include/nc4internal.h +++ b/include/nc4internal.h @@ -232,14 +232,12 @@ typedef struct NC_TYPE_INFO struct { NClist* enum_member; /* */ nc_type base_nc_typeid; - hid_t base_hdf_typeid; } e; /* Enum */ struct Fields { NClist* field; /* */ } c; /* Compound */ struct { nc_type base_nc_typeid; - hid_t base_hdf_typeid; } v; /* Variable-length */ } u; /* Union of structs, for each type/class */ } NC_TYPE_INFO_T; diff --git a/libhdf5/hdf5internal.c b/libhdf5/hdf5internal.c index c28dfd0f7..e1854ef19 100644 --- a/libhdf5/hdf5internal.c +++ b/libhdf5/hdf5internal.c @@ -602,26 +602,6 @@ nc4_rec_grp_HDF5_del(NC_GRP_INFO_T *grp) if (type->native_hdf_typeid && H5Tclose(type->native_hdf_typeid) < 0) return NC_EHDFERR; type->native_hdf_typeid = 0; - - /* Class-specific cleanup. Only enums and vlens have HDF5 - * resources to close. */ - switch (type->nc_type_class) - { - case NC_ENUM: - if (type->u.e.base_hdf_typeid && H5Tclose(type->u.e.base_hdf_typeid) < 0) - return NC_EHDFERR; - type->u.e.base_hdf_typeid = 0; - break; - - case NC_VLEN: - if (type->u.v.base_hdf_typeid && H5Tclose(type->u.v.base_hdf_typeid) < 0) - return NC_EHDFERR; - type->u.v.base_hdf_typeid = 0; - break; - - default: /* Do nothing. */ - break; - } } /* Close the HDF5 group. */ diff --git a/libhdf5/hdf5open.c b/libhdf5/hdf5open.c index c43d267d2..cea03b8ff 100644 --- a/libhdf5/hdf5open.c +++ b/libhdf5/hdf5open.c @@ -1278,8 +1278,8 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name) H5T_class_t class; hid_t native_typeid; size_t type_size; - int retval = NC_NOERR; int nmembers; + int retval; assert(grp && type_name); @@ -1373,50 +1373,43 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name) hsize_t dims[NC_MAX_VAR_DIMS]; int d; - if ((ndims = H5Tget_array_ndims(member_hdf_typeid)) < 0) { - retval = NC_EHDFERR; - break; - } - if (H5Tget_array_dims(member_hdf_typeid, dims, NULL) != ndims) { - retval = NC_EHDFERR; - break; - } + if ((ndims = H5Tget_array_ndims(member_hdf_typeid)) < 0) + return NC_EHDFERR; + + if (H5Tget_array_dims(member_hdf_typeid, dims, NULL) != ndims) + return NC_EHDFERR; + for (d = 0; d < ndims; d++) dim_size[d] = dims[d]; /* What is the netCDF typeid of this member? */ if ((retval = get_netcdf_type(grp->nc4_info, H5Tget_super(member_hdf_typeid), &member_xtype))) - break; + return retval; /* Add this member to our list of fields in this compound type. */ if ((retval = nc4_field_list_add(type, member_name, member_offset, H5Tget_super(member_hdf_typeid), H5Tget_super(member_native_typeid), member_xtype, ndims, dim_size))) - break; + return retval; } else { /* What is the netCDF typeid of this member? */ if ((retval = get_netcdf_type(grp->nc4_info, member_native_typeid, &member_xtype))) - break; + return retval; /* Add this member to our list of fields in this compound type. */ if ((retval = nc4_field_list_add(type, member_name, member_offset, member_hdf_typeid, member_native_typeid, member_xtype, 0, NULL))) - break; + return retval; } hdf5free(member_name); - member_name = NULL; } - hdf5free(member_name); - member_name = NULL; - if(retval) /* error exit from loop */ - return retval; } break; @@ -1455,9 +1448,8 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name) LOG((5, "base_hdf_typeid 0x%x type_size %d base_nc_type %d", base_hdf_typeid, type_size, base_nc_type)); - /* Remember the base types for this vlen */ + /* Remember the base type for this vlen. */ type->u.v.base_nc_typeid = base_nc_type; - type->u.v.base_hdf_typeid = base_hdf_typeid; } } break; @@ -1493,9 +1485,8 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name) LOG((5, "base_hdf_typeid 0x%x type_size %d base_nc_type %d", base_hdf_typeid, type_size, base_nc_type)); - /* Remember the base types for this enum */ + /* Remember the base type for this enum. */ type->u.e.base_nc_typeid = base_nc_type; - type->u.e.base_hdf_typeid = base_hdf_typeid; /* Find out how many member are in the enum. */ if ((nmembers = H5Tget_nmembers(hdf_typeid)) < 0) @@ -1512,41 +1503,27 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name) { /* Get the name and value from HDF5. */ if (!(member_name = H5Tget_member_name(hdf_typeid, i))) - { - retval = NC_EHDFERR; - break; - } + return NC_EHDFERR; + #ifdef JNA strncpy(jna,member_name,1000); member_name = jna; #endif if (strlen(member_name) > NC_MAX_NAME) - { - retval = NC_EBADNAME; - break; - } + return NC_EBADNAME; + if (H5Tget_member_value(hdf_typeid, i, value) < 0) - { - retval = NC_EHDFERR; - break; - } + return NC_EHDFERR; /* Insert new field into this type's list of fields. */ if ((retval = nc4_enum_member_add(type, type->size, member_name, value))) - { - break; - } + return retval; hdf5free(member_name); - member_name = NULL; } - hdf5free(member_name); - member_name = NULL; - if(value) free(value); - if(retval) /* error exit from loop */ - return retval; + free(value); } break; diff --git a/libhdf5/nc4hdf.c b/libhdf5/nc4hdf.c index d4d05a0f6..2cb0cd0fa 100644 --- a/libhdf5/nc4hdf.c +++ b/libhdf5/nc4hdf.c @@ -1164,6 +1164,7 @@ static int commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type) { NC_HDF5_GRP_INFO_T *hdf5_grp; + hid_t base_hdf_typeid; int retval; assert(grp && grp->format_grp_info && type); @@ -1228,11 +1229,11 @@ commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type) { /* Find the HDF typeid of the base type of this vlen. */ if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.v.base_nc_typeid, - &type->u.v.base_hdf_typeid, type->endianness))) + &base_hdf_typeid, type->endianness))) return retval; /* Create a vlen type. */ - if ((type->hdf_typeid = H5Tvlen_create(type->u.v.base_hdf_typeid)) < 0) + if ((type->hdf_typeid = H5Tvlen_create(base_hdf_typeid)) < 0) return NC_EHDFERR; } else if (type->nc_type_class == NC_OPAQUE) @@ -1251,11 +1252,11 @@ commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type) /* Find the HDF typeid of the base type of this enum. */ if ((retval = nc4_get_hdf_typeid(grp->nc4_info, type->u.e.base_nc_typeid, - &type->u.e.base_hdf_typeid, type->endianness))) + &base_hdf_typeid, type->endianness))) return retval; /* Create an enum type. */ - if ((type->hdf_typeid = H5Tenum_create(type->u.e.base_hdf_typeid)) < 0) + if ((type->hdf_typeid = H5Tenum_create(base_hdf_typeid)) < 0) return NC_EHDFERR; /* Add all the members to the HDF5 type. */