diff options
Diffstat (limited to 'src/H5Toffset.c')
-rw-r--r-- | src/H5Toffset.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/H5Toffset.c b/src/H5Toffset.c index 72d15fb..bd54e5c 100644 --- a/src/H5Toffset.c +++ b/src/H5Toffset.c @@ -103,9 +103,9 @@ H5Tget_offset(hid_t type_id) /* Check args */ if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an atomic data type"); - if (dt->parent) + while (dt->parent) dt = dt->parent; /*defer to parent*/ - if (H5T_COMPOUND==dt->type || H5T_OPAQUE==dt->type || H5T_ARRAY==dt->type) + if (H5T_COMPOUND==dt->type || H5T_OPAQUE==dt->type) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for specified data type"); /* Offset */ @@ -174,6 +174,8 @@ H5Tset_offset(hid_t type_id, size_t offset) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "offset must be zero for this type"); if (H5T_ENUM==dt->type && dt->u.enumer.nmembs>0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not allowed after members are defined"); + if (H5T_COMPOUND==dt->type || H5T_REFERENCE==dt->type || H5T_OPAQUE==dt->type) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for this datatype"); /* Do the real work */ if (H5T_set_offset(dt, offset)<0) @@ -233,23 +235,24 @@ H5T_set_offset(H5T_t *dt, size_t offset) /* Check args */ assert(dt); assert(H5T_STRING!=dt->type || 0==offset); - assert(H5T_ENUM!=dt->type || 0==dt->u.enumer.nmembs); + assert(H5T_REFERENCE!=dt->type); + assert(H5T_OPAQUE!=dt->type); + assert(H5T_COMPOUND!=dt->type); + assert(!(H5T_ENUM==dt->type && 0==dt->u.enumer.nmembs)); if (dt->parent) { if (H5T_set_offset(dt->parent, offset)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to set offset for base type"); - dt->size = dt->parent->size; + + /* Adjust size of datatype appropriately */ + if(dt->type==H5T_ARRAY) + dt->size = dt->parent->size * dt->u.array.nelem; + else if(dt->type!=H5T_VLEN) + dt->size = dt->parent->size; } else { - if (H5T_COMPOUND==dt->type || H5T_OPAQUE==dt->type || H5T_ARRAY==dt->type) { - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "operation not defined for specified data type"); - } else if (H5T_ENUM==dt->type) { - /*nothing*/ - } else { - if (offset+dt->u.atomic.prec > 8*dt->size) { - dt->size = (offset + dt->u.atomic.prec + 7) / 8; - } - dt->u.atomic.offset = offset; - } + if (offset+dt->u.atomic.prec > 8*dt->size) + dt->size = (offset + dt->u.atomic.prec + 7) / 8; + dt->u.atomic.offset = offset; } done: |