From ea7f4421f9b61f0cbe2975f8da6897be5a67111c Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 5 Oct 2000 11:56:30 -0500 Subject: [svn-r2634] Purpose: Bug fix Description: In the h5dump_fixtype function, when users created a COMPOUND datatype, the alignment would be off somewhat. Solution: The alignment was being set after insertion. I changed this code: for (i = 0, offset = 0; i < nmembs; i++) { H5Tinsert_array(m_type, name[i], offset, ndims[i], dims + i * 4, NULL, memb[i]); for (j = 0, nelmts = 1; j < ndims[i]; j++) nelmts *= dims[i * 4 + j]; offset = ALIGN(offset, H5Tget_size(memb[i])) + nelmts * H5Tget_size(memb[i]); } to: for (i = 0, offset = 0; i < nmembs; i++) { if (offset) offset = ALIGN(offset, H5Tget_size(memb[i])); H5Tinsert_array(m_type, name[i], offset, ndims[i], dims + i * 4, NULL, memb[i]); for (j = 0, nelmts = 1; j < ndims[i]; j++) nelmts *= dims[i * 4 + j]; offset += nelmts * H5Tget_size(memb[i]); } The alignment is now calculated before the insertion. Platforms tested: Solaris, Linux --- tools/h5tools.c | 58 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/tools/h5tools.c b/tools/h5tools.c index 197fc2f..a938476 100644 --- a/tools/h5tools.c +++ b/tools/h5tools.c @@ -1542,17 +1542,18 @@ h5dump_fixtype(hid_t f_type) * If there is no memory type large enough then use the largest * memory type available. */ - if (size<=sizeof(char)) { + if (size <= sizeof(char)) { m_type = H5Tcopy(H5T_NATIVE_SCHAR); - } else if (size<=sizeof(short)) { + } else if (size <= sizeof(short)) { m_type = H5Tcopy(H5T_NATIVE_SHORT); - } else if (size<=sizeof(int)) { + } else if (size <= sizeof(int)) { m_type = H5Tcopy(H5T_NATIVE_INT); - } else if (size<=sizeof(long)) { + } else if (size <= sizeof(long)) { m_type = H5Tcopy(H5T_NATIVE_LONG); } else { m_type = H5Tcopy(H5T_NATIVE_LLONG); } + H5Tset_sign(m_type, H5Tget_sign(f_type)); break; @@ -1562,13 +1563,14 @@ h5dump_fixtype(hid_t f_type) * its size is at least as large as the file type. If there is not * native type large enough then use the largest native type. */ - if (size<=sizeof(float)) { + if (size <= sizeof(float)) { m_type = H5Tcopy(H5T_NATIVE_FLOAT); - } else if (size<=sizeof(double)) { + } else if (size <= sizeof(double)) { m_type = H5Tcopy(H5T_NATIVE_DOUBLE); } else { m_type = H5Tcopy(H5T_NATIVE_LDOUBLE); } + break; case H5T_STRING: @@ -1577,8 +1579,8 @@ h5dump_fixtype(hid_t f_type) * strDUAction == TRUE. if it is false we will do the original action * here. */ - m_type = H5Tcopy(f_type); - H5Tset_cset(m_type, H5T_CSET_ASCII); + m_type = H5Tcopy(f_type); + H5Tset_cset(m_type, H5T_CSET_ASCII); break; case H5T_COMPOUND: @@ -1591,43 +1593,55 @@ h5dump_fixtype(hid_t f_type) */ nmembs = H5Tget_nmembers(f_type); memb = calloc(nmembs, sizeof(hid_t)); - name = calloc(nmembs, sizeof(char*)); + name = calloc(nmembs, sizeof(char *)); ndims = calloc(nmembs, sizeof(int)); dims = calloc(nmembs*4, sizeof(size_t)); - for (i=0, size=0; i=0 && ndims[i]<=4); - for (j=0, nelmts=1; j= 0 && ndims[i] <= 4); + + for (j = 0, nelmts = 1; j < ndims[i]; j++) + nelmts *= dims[i * 4 + j]; /* Get the member name */ name[i] = H5Tget_member_name(f_type, i); - if (NULL==name[i]) goto done; + + if (NULL == name[i]) + goto done; /* * Compute the new offset so each member is aligned on a byte * boundary which is the same as the member size. */ size = ALIGN(size, H5Tget_size(memb[i])) + - nelmts * H5Tget_size(memb[i]); + nelmts * H5Tget_size(memb[i]); } m_type = H5Tcreate(H5T_COMPOUND, size); - for (i=0, offset=0; i