changing types

This commit is contained in:
Ed Hartnett 2018-11-20 08:00:48 -07:00
parent 7d01ffb030
commit 5104262f6b
4 changed files with 48 additions and 13 deletions

View File

@ -89,6 +89,13 @@ typedef struct NC_HDF5_FIELD_INFO
hid_t native_hdf_typeid;
} NC_HDF5_FIELD_INFO_T;
/* Struct to hold HDF5-specific info for a type. */
typedef struct NC_HDF5_TYPE_INFO
{
hid_t hdf_typeid;
hid_t native_hdf_typeid;
} NC_HDF5_TYPE_INFO_T;
/* Logging and debugging. */
void reportopenobjects(int log, hid_t);
int hdf5_set_log_level();

View File

@ -1282,12 +1282,14 @@ hdf5free(void* memory)
* @return ::NC_EBADID Bad ncid.
* @return ::NC_EHDFERR HDF5 returned error.
* @return ::NC_EBADTYPID Type not found.
* @return ::NC_ENOMEM Out of memory.
* @author Ed Hartnett
*/
static int
read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name)
{
NC_TYPE_INFO_T *type;
NC_HDF5_TYPE_INFO_T *hdf5_type;
H5T_class_t class;
hid_t native_typeid;
size_t type_size;
@ -1312,6 +1314,11 @@ read_type(NC_GRP_INFO_T *grp, hid_t hdf_typeid, char *type_name)
if ((retval = nc4_type_list_add(grp, type_size, type_name, &type)))
return retval;
/* Allocate storage for HDF5-specific type info. */
if (!(hdf5_type = calloc(1, sizeof(NC_HDF5_TYPE_INFO_T))))
return NC_ENOMEM;
type->format_type_info = hdf5_type;
/* Remember common info about this type. */
type->committed = NC_TRUE;
type->hdf_typeid = hdf_typeid;

View File

@ -82,6 +82,14 @@ NC4_inq_type_equal(int ncid1, nc_type typeid1, int ncid2,
/* Are the two types equal? */
if (equalp)
{
hid_t hid1, hid2;
/* Get the HDF5 types from the HDF5-specific type info. */
assert(type1->format_type_info && type2->format_type_info);
hid1 = ((NC_HDF5_TYPE_INFO_T *)type1->format_type_info)->native_hdf_typeid;
hid2 = ((NC_HDF5_TYPE_INFO_T *)type2->format_type_info)->native_hdf_typeid;
/* Ask HDF5 if the types are equal. */
if ((retval = H5Tequal(type1->native_hdf_typeid, type2->native_hdf_typeid)) < 0)
return NC_EHDFERR;
*equalp = 1 ? retval : 0;
@ -195,6 +203,7 @@ add_user_type(int ncid, size_t size, const char *name, nc_type base_typeid,
NC_FILE_INFO_T *h5;
NC_GRP_INFO_T *grp;
NC_TYPE_INFO_T *type;
NC_HDF5_TYPE_INFO_T *hdf5_type;
char norm_name[NC_MAX_NAME + 1];
int retval;
@ -236,6 +245,11 @@ add_user_type(int ncid, size_t size, const char *name, nc_type base_typeid,
if ((retval = nc4_type_list_add(grp, size, norm_name, &type)))
return retval;
/* Allocate storage for HDF5-specific type info. */
if (!(hdf5_type = calloc(1, sizeof(NC_HDF5_TYPE_INFO_T))))
return NC_ENOMEM;
type->format_type_info = hdf5_type;
/* Remember info about this type. */
type->nc_type_class = type_class;
if (type_class == NC_VLEN)

View File

@ -1191,13 +1191,15 @@ static int
commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
{
NC_HDF5_GRP_INFO_T *hdf5_grp;
NC_HDF5_TYPE_INFO_T *hdf5_type;
hid_t base_hdf_typeid;
int retval;
assert(grp && grp->format_grp_info && type);
assert(grp && grp->format_grp_info && type && type->format_type_info);
/* Get HDF5-specific group info. */
/* Get HDF5-specific group and type info. */
hdf5_grp = (NC_HDF5_GRP_INFO_T *)grp->format_grp_info;
hdf5_type = (NC_HDF5_TYPE_INFO_T *)type->format_type_info;
/* Did we already record this type? */
if (type->committed)
@ -1210,10 +1212,11 @@ commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
hid_t hdf_base_typeid, hdf_typeid;
int i;
if ((type->hdf_typeid = H5Tcreate(H5T_COMPOUND, type->size)) < 0)
if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_COMPOUND, type->size)) < 0)
return NC_EHDFERR;
type->hdf_typeid = hdf5_type->hdf_typeid;
LOG((4, "creating compound type %s hdf_typeid 0x%x", type->hdr.name,
type->hdf_typeid));
hdf5_type->hdf_typeid));
for(i=0;i<nclistlength(type->u.c.field);i++)
{
@ -1245,7 +1248,7 @@ commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
hdf_typeid = hdf_base_typeid;
LOG((4, "inserting field %s offset %d hdf_typeid 0x%x", field->hdr.name,
field->offset, hdf_typeid));
if (H5Tinsert(type->hdf_typeid, field->hdr.name, field->offset,
if (H5Tinsert(hdf5_type->hdf_typeid, field->hdr.name, field->offset,
hdf_typeid) < 0)
return NC_EHDFERR;
if (H5Tclose(hdf_typeid) < 0)
@ -1260,14 +1263,16 @@ commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
return retval;
/* Create a vlen type. */
if ((type->hdf_typeid = H5Tvlen_create(base_hdf_typeid)) < 0)
if ((hdf5_type->hdf_typeid = H5Tvlen_create(base_hdf_typeid)) < 0)
return NC_EHDFERR;
type->hdf_typeid = hdf5_type->hdf_typeid;
}
else if (type->nc_type_class == NC_OPAQUE)
{
/* Create the opaque type. */
if ((type->hdf_typeid = H5Tcreate(H5T_OPAQUE, type->size)) < 0)
if ((hdf5_type->hdf_typeid = H5Tcreate(H5T_OPAQUE, type->size)) < 0)
return NC_EHDFERR;
type->hdf_typeid = hdf5_type->hdf_typeid;
}
else if (type->nc_type_class == NC_ENUM)
{
@ -1283,13 +1288,14 @@ commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
return retval;
/* Create an enum type. */
if ((type->hdf_typeid = H5Tenum_create(base_hdf_typeid)) < 0)
if ((hdf5_type->hdf_typeid = H5Tenum_create(base_hdf_typeid)) < 0)
return NC_EHDFERR;
type->hdf_typeid = hdf5_type->hdf_typeid;
/* Add all the members to the HDF5 type. */
for(i=0;i<nclistlength(type->u.e.enum_member);i++) {
enum_m = (NC_ENUM_MEMBER_INFO_T*)nclistget(type->u.e.enum_member,i);
if (H5Tenum_insert(type->hdf_typeid, enum_m->name, enum_m->value) < 0)
if (H5Tenum_insert(hdf5_type->hdf_typeid, enum_m->name, enum_m->value) < 0)
return NC_EHDFERR;
}
}
@ -1300,18 +1306,19 @@ commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
}
/* Commit the type. */
if (H5Tcommit(hdf5_grp->hdf_grpid, type->hdr.name, type->hdf_typeid) < 0)
if (H5Tcommit(hdf5_grp->hdf_grpid, type->hdr.name, hdf5_type->hdf_typeid) < 0)
return NC_EHDFERR;
type->committed = NC_TRUE;
LOG((4, "just committed type %s, HDF typeid: 0x%x", type->hdr.name,
type->hdf_typeid));
hdf5_type->hdf_typeid));
/* Later we will always use the native typeid. In this case, it is
* a copy of the same type pointed to by hdf_typeid, but it's
* easier to maintain a copy. */
if ((type->native_hdf_typeid = H5Tget_native_type(type->hdf_typeid,
H5T_DIR_DEFAULT)) < 0)
if ((hdf5_type->native_hdf_typeid = H5Tget_native_type(hdf5_type->hdf_typeid,
H5T_DIR_DEFAULT)) < 0)
return NC_EHDFERR;
type->native_hdf_typeid = hdf5_type->native_hdf_typeid;
return NC_NOERR;
}