From c0bbeb909802f33bac72cd3fabaa4311d97d38a9 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Sat, 5 Feb 2005 13:27:04 -0500 Subject: [svn-r9942] Purpose: Minor Bug fix Description: H5T_NATIVE_SCHAR, H5T_NATIVE_UCHAR were always considered as little endian due to the algorithm to detect their order in H5detect.c. This error didn't affect data but didn't look right. Solution: In H5detect.c, use native int instead to detect order if type size is only 1 byte. Platforms tested: h5committest, fuss and arabica --- src/H5detect.c | 26 +++++++++++---- tools/h5dump/h5dump.c | 55 ++++++++++++++++++++++++------- tools/h5repack/testh5repack_dset.c | 2 +- tools/testfiles/tcomp-4.ddl | 2 +- tools/testfiles/tcompound_complex.h5 | Bin 8192 -> 8192 bytes tools/testfiles/tcompound_complex.h5.xml | 2 +- tools/testfiles/test1.h5 | Bin 20944 -> 20944 bytes tools/testfiles/tstr3.h5 | Bin 8736 -> 8736 bytes tools/testfiles/tstring.ddl | 4 +-- tools/testfiles/tstring2.ddl | 2 +- tools/testfiles/tstringe.ddl | 4 +-- tools/testfiles/tvlstr.h5 | Bin 8192 -> 8192 bytes 12 files changed, 72 insertions(+), 25 deletions(-) diff --git a/src/H5detect.c b/src/H5detect.c index b79911d..73ded41 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -195,17 +195,31 @@ precision (detected_t *d) */ #define DETECT_I(TYPE,VAR,INFO) { \ TYPE _v; \ + int _int_v; \ int _i, _j; \ unsigned char *_x; \ + \ memset (&INFO, 0, sizeof(INFO)); \ INFO.varname = #VAR; \ INFO.size = sizeof(TYPE); \ - for (_i=sizeof(TYPE),_v=0; _i>0; --_i) _v = (_v<<8) + _i; \ - for (_i=0,_x=(unsigned char *)&_v; _i<(signed)sizeof(TYPE); _i++) { \ - _j = (*_x++)-1; \ - assert (_j<(signed)sizeof(TYPE)); \ - INFO.perm[_i] = _j; \ - } \ + \ + if(sizeof(TYPE)!=1) { \ + for (_i=sizeof(TYPE),_v=0; _i>0; --_i) _v = (_v<<8) + _i; \ + for (_i=0,_x=(unsigned char *)&_v; _i<(signed)sizeof(TYPE); _i++) { \ + _j = (*_x++)-1; \ + assert (_j<(signed)sizeof(TYPE)); \ + INFO.perm[_i] = _j; \ + } \ + } else { /*Not able to detect order if type size is 1 byte. Use native int \ + *instead. No effect on data, just make it look correct. */ \ + for (_i=sizeof(int),_int_v=0; _i>0; --_i) _int_v = (_int_v<<8) + _i; \ + for (_i=0,_x=(unsigned char *)&_int_v; _i<(signed)sizeof(int); _i++) { \ + _j = (*_x++)-1; \ + assert (_j<(signed)sizeof(int)); \ + INFO.perm[_i] = _j; \ + } \ + } \ + \ INFO.sign = ('U'!=*(#VAR)); \ precision (&(INFO)); \ ALIGNMENT(TYPE, INFO); \ diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index ba3e4ae..242ab67 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -654,6 +654,7 @@ print_datatype(hid_t type,unsigned in_group) hsize_t dims[H5DUMP_MAX_RANK]; H5T_str_t str_pad; H5T_cset_t cset; + H5T_order_t order; H5G_stat_t statbuf; hid_t super; hid_t tmp_type; @@ -809,26 +810,58 @@ print_datatype(hid_t type,unsigned in_group) indentation(indent + COL); printf("%s ", CTYPE); + /* Check C variable-length string first. Are the two types equal? */ if (H5Tequal(tmp_type, str_type)) { printf("H5T_C_S1;\n"); H5Tclose(str_type); - } else { + goto done; + } + + /* Change the endianness and see if they're equal. */ + order = H5Tget_order(tmp_type); + if(order==H5T_ORDER_LE) + H5Tset_order(str_type, H5T_ORDER_LE); + else if(order==H5T_ORDER_BE) + H5Tset_order(str_type, H5T_ORDER_BE); + + if (H5Tequal(tmp_type, str_type)) { + printf("H5T_C_S1;\n"); H5Tclose(str_type); - str_type = H5Tcopy(H5T_FORTRAN_S1); - H5Tset_cset(str_type, cset); - H5Tset_size(str_type, size); - H5Tset_strpad(str_type, str_pad); + goto done; + } - if (H5Tequal(tmp_type, str_type)) { - printf("H5T_FORTRAN_S1;\n"); - } else { - printf("unknown_one_character_type;\n "); - d_status = EXIT_FAILURE; - } + /* If not equal to C variable-length string, check Fortran type. */ + H5Tclose(str_type); + str_type = H5Tcopy(H5T_FORTRAN_S1); + H5Tset_cset(str_type, cset); + H5Tset_size(str_type, size); + H5Tset_strpad(str_type, str_pad); + + /* Are the two types equal? */ + if (H5Tequal(tmp_type, str_type)) { + printf("H5T_FORTRAN_S1;\n"); + H5Tclose(str_type); + goto done; + } + /* Change the endianness and see if they're equal. */ + order = H5Tget_order(tmp_type); + if(order==H5T_ORDER_LE) + H5Tset_order(str_type, H5T_ORDER_LE); + else if(order==H5T_ORDER_BE) + H5Tset_order(str_type, H5T_ORDER_BE); + + if (H5Tequal(tmp_type, str_type)) { + printf("H5T_FORTRAN_S1;\n"); H5Tclose(str_type); + goto done; } + printf("unknown_one_character_type;\n "); + d_status = EXIT_FAILURE; + H5Tclose(str_type); + +done: H5Tclose(tmp_type); indent -= COL; diff --git a/tools/h5repack/testh5repack_dset.c b/tools/h5repack/testh5repack_dset.c index 299c044..8781ae7 100644 --- a/tools/h5repack/testh5repack_dset.c +++ b/tools/h5repack/testh5repack_dset.c @@ -655,7 +655,7 @@ static void make_dset_reg_ref(hid_t loc_id) sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL); /* Create a dataset */ - dset2=H5Dcreate(loc_id,"dsetreg",H5T_STD_U8LE,sid2,H5P_DEFAULT); + dset2=H5Dcreate(loc_id,"dsetreg",H5T_NATIVE_UCHAR,sid2,H5P_DEFAULT); for(i=0; i - + diff --git a/tools/testfiles/test1.h5 b/tools/testfiles/test1.h5 index 4016565..70cea54 100644 Binary files a/tools/testfiles/test1.h5 and b/tools/testfiles/test1.h5 differ diff --git a/tools/testfiles/tstr3.h5 b/tools/testfiles/tstr3.h5 index e44e2b3..dc9a127 100644 Binary files a/tools/testfiles/tstr3.h5 and b/tools/testfiles/tstr3.h5 differ diff --git a/tools/testfiles/tstring.ddl b/tools/testfiles/tstring.ddl index 6510eaa..9189a4f 100644 --- a/tools/testfiles/tstring.ddl +++ b/tools/testfiles/tstring.ddl @@ -39,7 +39,7 @@ GROUP "/" { } DATASET "str3" { DATATYPE H5T_COMPOUND { - H5T_STD_I32LE "a"; + H5T_STD_I32BE "a"; H5T_STRING { STRSIZE 255; STRPAD H5T_STR_NULLTERM; @@ -57,7 +57,7 @@ GROUP "/" { } } DATASET "str4" { - DATATYPE H5T_STD_I8LE + DATATYPE H5T_STD_I8BE DATASPACE SIMPLE { ( 93 ) / ( 93 ) } DATA { (0): 70, 111, 117, 114, 32, 115, 99, 111, 114, 101, 32, 97, 110, 100, diff --git a/tools/testfiles/tstring2.ddl b/tools/testfiles/tstring2.ddl index c3e9844..303d5fc 100644 --- a/tools/testfiles/tstring2.ddl +++ b/tools/testfiles/tstring2.ddl @@ -3,7 +3,7 @@ Expected output for 'h5dump -r -d str4 tstr3.h5' ############################# HDF5 "tstr3.h5" { DATASET "str4" { - DATATYPE H5T_STD_I8LE + DATATYPE H5T_STD_I8BE DATASPACE SIMPLE { ( 93 ) / ( 93 ) } DATA { "Four score and seven diff --git a/tools/testfiles/tstringe.ddl b/tools/testfiles/tstringe.ddl index 1d96dbd..e16e98d 100644 --- a/tools/testfiles/tstringe.ddl +++ b/tools/testfiles/tstringe.ddl @@ -32,7 +32,7 @@ GROUP "/" { } DATASET "str3" { DATATYPE H5T_COMPOUND { - H5T_STD_I32LE "a"; + H5T_STD_I32BE "a"; H5T_STRING { STRSIZE 255; STRPAD H5T_STR_NULLTERM; @@ -49,7 +49,7 @@ GROUP "/" { } } DATASET "str4" { - DATATYPE H5T_STD_I8LE + DATATYPE H5T_STD_I8BE DATASPACE SIMPLE { ( 93 ) / ( 93 ) } DATA { (0): 70, 111, 117, 114, 32, 115, 99, 111, 114, 101, 32, 97, 110, 100, diff --git a/tools/testfiles/tvlstr.h5 b/tools/testfiles/tvlstr.h5 index c00defc..076fb3a 100644 Binary files a/tools/testfiles/tvlstr.h5 and b/tools/testfiles/tvlstr.h5 differ -- cgit v0.12