diff options
author | Robb Matzke <matzke@llnl.gov> | 1999-06-07 20:20:32 (GMT) |
---|---|---|
committer | Robb Matzke <matzke@llnl.gov> | 1999-06-07 20:20:32 (GMT) |
commit | 58eb9c4aa043151cf9ec77b46afb162988cc1d42 (patch) | |
tree | 19282b5d416b04a480bbcec3fd28555c7e794e01 | |
parent | 8532eb342ec94f6f7c92c73108c37228c91ee31c (diff) | |
download | hdf5-58eb9c4aa043151cf9ec77b46afb162988cc1d42.zip hdf5-58eb9c4aa043151cf9ec77b46afb162988cc1d42.tar.gz hdf5-58eb9c4aa043151cf9ec77b46afb162988cc1d42.tar.bz2 |
[svn-r1311] Changes since 19990607
----------------------
./tools/h5ls.c
./tools/h5tools.c
Added support for printing bitfields and opaque data.
./test/dsets.c
Added bitfield and opaque datasets to the output file so h5ls
has something interesting to print.
./test/trefer.c
Resync'd
./src/H5Tconv.c
Fixed bitfield conversion which resulted in possible garbage
in high-order bits of destination when the destination type is
larger than the source type. Thanks for spotting it, Quincey.
-rw-r--r-- | src/H5Tconv.c | 4 | ||||
-rw-r--r-- | test/dsets.c | 98 | ||||
-rw-r--r-- | test/trefer.c | 2 | ||||
-rw-r--r-- | tools/h5ls.c | 39 | ||||
-rw-r--r-- | tools/h5tools.c | 15 |
5 files changed, 153 insertions, 5 deletions
diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 5a84ad1..3d6bcca 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -628,7 +628,7 @@ H5T_conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, /* * Copy the significant part of the value. If the source is larger * than the destination then invoke the overflow function or copy - * as many bits as possible. + * as many bits as possible. Zero extra bits in the destination. */ if (src->u.atomic.prec>dst->u.atomic.prec) { if (!H5T_overflow_g || @@ -640,6 +640,8 @@ H5T_conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, H5T_bit_copy(d, dst->u.atomic.offset, s, src->u.atomic.offset, src->u.atomic.prec); + H5T_bit_set(d, dst->u.atomic.offset+src->u.atomic.prec, + dst->u.atomic.prec-src->u.atomic.prec, FALSE); } /* diff --git a/test/dsets.c b/test/dsets.c index a9cf40e..c8bcbc2 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -702,6 +702,103 @@ test_multiopen (hid_t file) /*------------------------------------------------------------------------- + * Function: test_types + * + * Purpose: Make some datasets with various types so we can test h5ls. + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Robb Matzke + * Monday, June 7, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +test_types(hid_t file) +{ + hid_t grp=-1, type=-1, space=-1, dset=-1; + size_t i; + hsize_t nelmts; + unsigned char buf[32]; + + TESTING("various datatypes"); + if ((grp=H5Gcreate(file, "typetests", 0))<0) goto error; + + /* bitfield_1 */ + nelmts = sizeof(buf); + if ((type=H5Tcopy(H5T_STD_B8LE))<0 || + (space=H5Screate_simple(1, &nelmts, NULL))<0 || + (dset=H5Dcreate(grp, "bitfield_1", type, space, H5P_DEFAULT))<0) + goto error; + for (i=0; i<sizeof buf; i++) buf[i] = 0xff ^ i; + if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0) + goto error; + if (H5Sclose(space)<0) goto error; + if (H5Tclose(type)<0) goto error; + if (H5Dclose(dset)<0) goto error; + + /* bitfield_2 */ + nelmts = sizeof(buf)/2; + if ((type=H5Tcopy(H5T_STD_B16LE))<0 || + (space=H5Screate_simple(1, &nelmts, NULL))<0 || + (dset=H5Dcreate(grp, "bitfield_2", type, space, H5P_DEFAULT))<0) + goto error; + for (i=0; i<sizeof buf; i++) buf[i] = 0xff ^ i; + if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0) + goto error; + if (H5Sclose(space)<0) goto error; + if (H5Tclose(type)<0) goto error; + if (H5Dclose(dset)<0) goto error; + + /* opaque_1 */ + nelmts = sizeof(buf); + if ((type=H5Tcreate(H5T_OPAQUE, 1))<0 || + H5Tset_tag(type, "testing 1-byte opaque type")<0 || + (space=H5Screate_simple(1, &nelmts, NULL))<0 || + (dset=H5Dcreate(grp, "opaque_1", type, space, H5P_DEFAULT))<0) + goto error; + for (i=0; i<sizeof buf; i++) buf[i] = 0xff ^ i; + if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0) + goto error; + if (H5Sclose(space)<0) goto error; + if (H5Tclose(type)<0) goto error; + if (H5Dclose(dset)<0) goto error; + + /* opaque_2 */ + nelmts = sizeof(buf)/4; + if ((type=H5Tcreate(H5T_OPAQUE, 4))<0 || + H5Tset_tag(type, "testing 4-byte opaque type")<0 || + (space=H5Screate_simple(1, &nelmts, NULL))<0 || + (dset=H5Dcreate(grp, "opaque_2", type, space, H5P_DEFAULT))<0) + goto error; + for (i=0; i<sizeof buf; i++) buf[i] = 0xff ^ i; + if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0) + goto error; + if (H5Sclose(space)<0) goto error; + if (H5Tclose(type)<0) goto error; + if (H5Dclose(dset)<0) goto error; + + /* Cleanup */ + if (H5Gclose(grp)<0) goto error; + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose(grp); + H5Tclose(type); + H5Sclose(space); + H5Dclose(dset); + } H5E_END_TRY; + return -1; +} + + +/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests the dataset interface (H5D) @@ -751,6 +848,7 @@ main(void) nerrors += test_tconv(file)<0 ?1:0; nerrors += test_compression(file)<0 ?1:0; nerrors += test_multiopen (file)<0 ?1:0; + nerrors += test_types(file)<0 ?1:0; if (H5Fclose(file)<0) goto error; if (nerrors) goto error; diff --git a/test/trefer.c b/test/trefer.c index bb27695..959d844 100644 --- a/test/trefer.c +++ b/test/trefer.c @@ -316,7 +316,7 @@ test_reference_region(void) MESSAGE(5, ("Testing Dataset Region Reference Functions\n")); /* Allocate write & read buffers */ - wbuf=calloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); + wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1); rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); dwbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); drbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); diff --git a/tools/h5ls.c b/tools/h5ls.c index acd8c9e..ae14077 100644 --- a/tools/h5ls.c +++ b/tools/h5ls.c @@ -923,6 +923,42 @@ display_reference_type(hid_t type, int UNUSED indent) /*------------------------------------------------------------------------- + * Function: display_opaque_type + * + * Purpose: Prints information about an opaque data type. + * + * Return: Success: TRUE + * + * Failure: FALSE, nothing printed + * + * Programmer: Robb Matzke + * Monday, June 7, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +display_opaque_type(hid_t type, int indent) +{ + char *tag; + size_t size; + + if (H5T_OPAQUE!=H5Tget_class(type)) return FALSE; + + size = H5Tget_size(type); + printf("%lu-byte opaque type", (unsigned long)size); + if ((tag=H5Tget_tag(type))) { + printf("\n%*s(tag = \"", indent, ""); + display_string(stdout, tag, FALSE); + printf("\")"); + free(tag); + } + return TRUE; +} + + +/*------------------------------------------------------------------------- * Function: display_type * * Purpose: Prints a data type definition. The definition is printed @@ -962,7 +998,8 @@ display_type(hid_t type, int indent) display_cmpd_type(type, indent) || display_enum_type(type, indent) || display_string_type(type, indent) || - display_reference_type(type, indent)) { + display_reference_type(type, indent) || + display_opaque_type(type, indent)) { return; } diff --git a/tools/h5tools.c b/tools/h5tools.c index fdc544d..d42472f 100644 --- a/tools/h5tools.c +++ b/tools/h5tools.c @@ -910,6 +910,7 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, } } else { + /* All other types get printed as hexadecimal */ h5dump_str_append(str, "0x"); n = H5Tget_size(type); for (i=0; i<n; i++) { @@ -1555,12 +1556,22 @@ h5dump_fixtype(hid_t f_type) case H5T_ENUM: case H5T_REFERENCE: + case H5T_OPAQUE: + /* Same as file type */ m_type = H5Tcopy(f_type); break; - case H5T_TIME: case H5T_BITFIELD: - case H5T_OPAQUE: + /* + * Same as the file except the offset is set to zero and the byte + * order is set to little endian. + */ + m_type = H5Tcopy(f_type); + H5Tset_offset(m_type, 0); + H5Tset_order(m_type, H5T_ORDER_LE); + break; + + case H5T_TIME: /* * These type classes are not implemented yet. */ |