From b98fcbf5926e81f2e4ead8daa46e650566719e1c Mon Sep 17 00:00:00 2001 From: Robb Matzke Date: Mon, 7 Jun 1999 10:05:02 -0500 Subject: [svn-r1306] Changes since 19990602 ---------------------- ./doc/html/Datatypes.html ./test/dtypes.c Added documentation and tests for opaque types. ./tools/h5ls.c Added a `-x' or `--hexdump' argument which is not fully implemented (because I want to synchronize h5tools.c first) but which will eventually print raw data in hexadecimal format without any translation from disk. This would be useful for debugging references and VL types. ./tools/h5tools.c Added support for references (not quite finished yet, but compiles -- I wanted to sync up this file before Patrick and I got too far apart...) ./src/H5R.c Checked for error return value from H5R_get_object_type() ./src/H5A.c ./src/H5D.c Changed error return values from NULL to FAIL ./test/Makefile.in ./test/trefer.c Creates trefer1.h5 and trefer2.h5 so that the second test doesn't clobber the first file since the files might be useful for debugging. --- doc/html/Datatypes.html | 62 +++++++++++++++++++++++------------------------ src/H5A.c | 5 ++-- src/H5D.c | 5 ++-- src/H5R.c | 7 ++++-- test/Makefile.in | 4 ++-- test/dtypes.c | 61 +++++++++++++++++++++++++++++++++++++++++++++- test/trefer.c | 14 ++++++----- tools/h5ls.c | 23 ++++++++++++++++-- tools/h5tools.c | 64 +++++++++++++++++++++++++++++++++++++++++-------- 9 files changed, 186 insertions(+), 59 deletions(-) diff --git a/doc/html/Datatypes.html b/doc/html/Datatypes.html index f0872b6..e6aaeb8 100644 --- a/doc/html/Datatypes.html +++ b/doc/html/Datatypes.html @@ -197,13 +197,12 @@ And in this document, the
H5T_class_t H5Tget_class (hid_t type)
This property holds one of the class names: - H5T_INTEGER, H5T_FLOAT, H5T_TIME, H5T_STRING, - H5T_BITFIELD, or H5T_OPAQUE. This - property is read-only and is set when the datatype is - created or copied (see H5Tcreate(), - H5Tcopy()). If this function fails it returns - H5T_NO_CLASS which has a negative value (all - other class constants are non-negative). + H5T_INTEGER, H5T_FLOAT, H5T_TIME, H5T_STRING, or + H5T_BITFIELD. This property is read-only and is set + when the datatype is created or copied (see + H5Tcreate(), H5Tcopy()). If this + function fails it returns H5T_NO_CLASS which has + a negative value (all other class constants are non-negative).

size_t H5Tget_size (hid_t type) @@ -218,13 +217,11 @@ And in this document, the the significant part of the data still extends beyond the edge of the data type then the precision property is decremented a bit at a time. Decreasing the size of a data - type may fail if the precesion must be decremented and the - data type is of the H5T_OPAQUE class or the - H5T_FLOAT bit fields would extend beyond the - significant part of the type. Adjusting the size of an - H5T_STRING automatically adjusts the precision - as well. On error, H5Tget_size() returns zero - which is never a valid size. + type may fail if the H5T_FLOAT bit fields would + extend beyond the significant part of the type. Adjusting the + size of an H5T_STRING automatically adjusts the + precision as well. On error, H5Tget_size() + returns zero which is never a valid size.

H5T_order_t H5Tget_order (hid_t type) @@ -486,17 +483,7 @@ And in this document, the Otherwise new bits are filled according to the msb padding type. -

3.6. Properties of Opaque Atomic Types

- -

Opaque atomic types (class=H5T_OPAQUE) act like - bit fields except conversions which change the precision are not - allowed. However, padding can be added or removed from either - end and the bytes can be reordered. Opaque types can be used to - create novel data types not directly supported by the library, - but the application is responsible for data conversion of these - types. - -

3.7 Character and String Datatype Issues

+

3.6 Character and String Datatype Issues

The H5T_NATIVE_CHAR and H5T_NATIVE_UCHAR data types are actually numeric data (1-byte integers). If the @@ -577,8 +564,19 @@ And in this document, the unsigned char (H5T_NATIVE_UCHAR) data types to the HDF5 integer type class. +

4. Properties of Opaque Types

+ +

Opaque types (class=H5T_OPAQUE) provide the + application with a mechanism for describing data which cannot be + otherwise described by HDF5. The only properties associated with + opaque types are a size in bytes and an ASCII tag which is + manipulated with H5Tset_tag() and + H5Tget_tag() functions. The library contains no + predefined conversion functions but the application is free to + register conversions between any two opaque types or between an + opaque type and some other type. -

4. Properties of Compound Types

+

5. Properties of Compound Types

A compound data type is similar to a struct in C or a common block in Fortran: it is a collection of one or more @@ -673,7 +671,7 @@ And in this document, the This makes it imposible to define recursive data structures. -

5. Predefined Atomic Data Types

+

6. Predefined Atomic Data Types

The library predefines a modest number of data types having @@ -994,7 +992,7 @@ H5Tset_size (str80, 80); -

6. Defining Compound Data Types

+

7. Defining Compound Data Types

Unlike atomic data types which are derived from other atomic data types, compound data types are created from scratch. First, @@ -1151,7 +1149,7 @@ H5Tinsert (surf_id, "y", HOFFSET(surf_t,y), complex_id);   -

7. Enumeration Data Types

+

8. Enumeration Data Types

An HDF5 enumeration data type is a 1:1 mapping between a set of symbols and a set of integer values, and an order is imposed on @@ -1164,7 +1162,7 @@ H5Tinsert (surf_id, "y", HOFFSET(surf_t,y), complex_id); are discussed on a separate Enumeration Data Types page. -

8. Sharing Data Types among Datasets

+

9. Sharing Data Types among Datasets

If a file has lots of datasets which have a common data type then the file could be made smaller by having all the datasets @@ -1210,7 +1208,7 @@ hid_t dset4 = H5Dcreate (file, "dset4", t2, space, H5P_DEFAULT); -

9. Data Conversion

+

10. Data Conversion

The library is capable of converting data from one type to @@ -1634,7 +1632,7 @@ And in this document, the -Last modified: 30 April 1999 +Last modified: Fri Jun 4 16:14:04 EDT 1999 diff --git a/src/H5A.c b/src/H5A.c index 275c350..2397b2a 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -963,8 +963,9 @@ H5Aget_type(hid_t attr_id) } /* Mark any VL datatypes as being in memory now */ if(H5T_get_class(dst)==H5T_VLEN) { - if (H5T_vlen_set_loc(dst, NULL, H5T_VLEN_MEMORY)<0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid VL location"); + if (H5T_vlen_set_loc(dst, NULL, H5T_VLEN_MEMORY)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "invalid VL location"); } } if (H5T_lock(dst, FALSE)<0) { diff --git a/src/H5D.c b/src/H5D.c index 614bda6..d84a856 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -459,8 +459,9 @@ H5Dget_type(hid_t dset_id) } /* Mark any VL datatypes as being in memory now */ if(H5T_get_class(copied_type)==H5T_VLEN) { - if (H5T_vlen_set_loc(copied_type, NULL, H5T_VLEN_MEMORY)<0) { - HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid VL location"); + if (H5T_vlen_set_loc(copied_type, NULL, H5T_VLEN_MEMORY)<0) { + HRETURN_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, + "invalid VL location"); } } if (H5T_lock (copied_type, FALSE)<0) { diff --git a/src/H5R.c b/src/H5R.c index 274b69f..6535ebf 100644 --- a/src/H5R.c +++ b/src/H5R.c @@ -733,8 +733,11 @@ H5Rget_object_type(hid_t dataset, void *_ref) "invalid reference pointer"); /* Get the object information */ - ret_value=H5R_get_object_type(dset,_ref); - + if ((ret_value=H5R_get_object_type(dset,_ref))<0) { + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, H5G_UNKNOWN, + "unable to determine object type"); + } + done: FUNC_LEAVE(ret_value); } /* end H5Rget_object_type() */ diff --git a/test/Makefile.in b/test/Makefile.in index f535942..ead1c3c 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -45,8 +45,8 @@ MOSTLYCLEAN=cmpd_dset.h5 dataset.h5 extend.h5 istore.h5 tfile1.h5 tfile2.h5 \ gheap1.h5 gheap2.h5 gheap3.h5 gheap4.h5 links.h5 chunk.h5 \ big.data big[0-9][0-9][0-9][0-9][0-9].h5 dtypes1.h5 dtypes2.h5 \ tattr.h5 tselect.h5 mtime.h5 ragged.h5 unlink.h5 overhead.h5 \ - fillval_[0-9].h5 fillval.raw mount_[0-9].h5 trefer.h5 flush.h5 \ - enum1.h5 + fillval_[0-9].h5 fillval.raw mount_[0-9].h5 trefer[12].h5 \ + flush.h5 enum1.h5 CLEAN=$(TIMINGS) # Source and object files for programs... The TEST_SRC list contains all the diff --git a/test/dtypes.c b/test/dtypes.c index eaff31d..484ca24 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -76,6 +76,9 @@ static int skip_overflow_tests_g = 0; /* Don't use hardware conversions if set */ static int without_hardware_g = 0; +/* Count opaque conversions */ +static int num_opaque_conversions_g = 0; + /* * Although we check whether a floating point overflow generates a SIGFPE and * turn off overflow tests in that case, it might still be possible for an @@ -1221,6 +1224,31 @@ test_conv_bitfield(void) /*------------------------------------------------------------------------- + * Function: convert_opaque + * + * Purpose: A fake opaque conversion functions + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Robb Matzke + * Friday, June 4, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +convert_opaque(hid_t UNUSED st, hid_t UNUSED dt, H5T_cdata_t *cdata, + size_t UNUSED nelmts, void UNUSED *_buf, void UNUSED *bkg) +{ + if (H5T_CONV_CONV==cdata->command) num_opaque_conversions_g++; + return 0; +} + + +/*------------------------------------------------------------------------- * Function: test_opaque * * Purpose: Test opaque datatypes @@ -1239,13 +1267,44 @@ test_conv_bitfield(void) static int test_opaque(void) { +#define OPAQUE_NELMTS 1000 hid_t st=-1, dt=-1; + herr_t status; + char buf[1]; /*not really used*/ + int saved = num_opaque_conversions_g; TESTING("opaque datatypes"); - + + /* Build source and destination types */ if ((st=H5Tcreate(H5T_OPAQUE, 4))<0) goto error; + if (H5Tset_tag(st, "opaque source type")<0) goto error; + if ((dt=H5Tcreate(H5T_OPAQUE, 4))<0) goto error; + if (H5Tset_tag(dt, "opaque destination type")<0) goto error; + + /* Make sure that we can't convert between the types yet */ + H5E_BEGIN_TRY { + status = H5Tconvert(st, dt, OPAQUE_NELMTS, buf, NULL); + } H5E_END_TRY; + if (status>=0) { + FAILED(); + printf(" opaque conversion should have failed but succeeded\n"); + goto error; + } + /* Register a conversion function */ + if (H5Tregister(H5T_PERS_HARD, "o_test", st, dt, convert_opaque)<0) + goto error; + + /* Try the conversion again, this time it should work */ + if (H5Tconvert(st, dt, OPAQUE_NELMTS, buf, NULL)<0) goto error; + if (saved+1 != num_opaque_conversions_g) { + FAILED(); + printf(" unexpected number of opaque conversions\n"); + goto error; + } + H5Tclose(st); + H5Tclose(dt); PASSED(); return 0; diff --git a/test/trefer.c b/test/trefer.c index f9d5ef7..651557f 100644 --- a/test/trefer.c +++ b/test/trefer.c @@ -28,7 +28,8 @@ static char RcsId[] = "$Revision$"; #include -#define FILE "trefer.h5" +#define FILE1 "trefer1.h5" +#define FILE2 "trefer2.h5" /* 1-D dataset with fixed dimensions */ #define SPACE1_NAME "Space1" @@ -86,7 +87,7 @@ test_reference_obj(void) tbuf=malloc(sizeof(hobj_ref_t)*SPACE1_DIM1); /* Create file */ - fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fcreate"); /* Create dataspace for datasets */ @@ -195,7 +196,7 @@ test_reference_obj(void) CHECK(ret, FAIL, "H5Fclose"); /* Re-open the file */ - fid1 = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT); + fid1 = H5Fopen(FILE1, H5F_ACC_RDWR, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fopen"); /* Open the dataset */ @@ -321,7 +322,7 @@ test_reference_region(void) drbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); /* Create file */ - fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + fid1 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fcreate"); /* Create dataspace for datasets */ @@ -410,7 +411,7 @@ test_reference_region(void) CHECK(ret, FAIL, "H5Fclose"); /* Re-open the file */ - fid1 = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT); + fid1 = H5Fopen(FILE2, H5F_ACC_RDWR, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fopen"); /* Open the dataset */ @@ -569,6 +570,7 @@ test_reference(void) void cleanup_reference(void) { - remove(FILE); + remove(FILE1); + remove(FILE2); } diff --git a/tools/h5ls.c b/tools/h5ls.c index 0a361c3..b4e10f7 100644 --- a/tools/h5ls.c +++ b/tools/h5ls.c @@ -25,6 +25,7 @@ static hbool_t string_g = FALSE; /*print 1-byte numbers as ASCII? */ static hbool_t fullname_g = FALSE; /*print full path names */ static hbool_t recursive_g = FALSE; /*recursive descent listing */ static hbool_t grp_literal_g = FALSE; /*list group, not contents */ +static hbool_t hexdump_g = FALSE; /*show data as raw hexadecimal */ /* Info to pass to the iteration functions */ typedef struct iter_t { @@ -94,6 +95,7 @@ usage: %s [OPTIONS] FILE [OBJECTS...]\n\ -wN, --width=N Set the number of columns of output\n\ -v, --verbose Generate more verbose output\n\ -V, --version Print version number and exit\n\ + -x, --hexdump Show raw data in hexadecimal format\n\ FILE\n\ The file name may include a printf(3C) integer format such as\n\ \"%%05d\" to open a file family.\n\ @@ -897,6 +899,8 @@ display_string_type(hid_t type, int UNUSED indent) * Thursday, November 5, 1998 * * Modifications: + * Robb Matzke, 1999-06-04 + * Knows about object and dataset region references. * *------------------------------------------------------------------------- */ @@ -905,8 +909,15 @@ display_reference_type(hid_t type, int UNUSED indent) { if (H5T_REFERENCE!=H5Tget_class(type)) return FALSE; - printf("%lu-byte unknown reference", - (unsigned long)H5Tget_size(type)); + if (H5Tequal(type, H5T_STD_REF_OBJ)) { + printf("object reference"); + } else if (H5Tequal(type, H5T_STD_REF_DSETREG)) { + printf("dataset region reference"); + } else { + printf("%lu-byte unknown reference", + (unsigned long)H5Tget_size(type)); + } + return TRUE; } @@ -1787,6 +1798,10 @@ main (int argc, char *argv[]) printf("This is %s version %u.%u release %u\n", progname, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); exit(0); + } else if (!strcmp(argv[argno], "--hexdump")) { + hexdump_g = TRUE; + fprintf(stderr, "not implemented yet: --hexdump\n"); + exit(1); } else if (!strncmp(argv[argno], "-w", 2)) { if (argv[argno][2]) { s = argv[argno]+2; @@ -1839,6 +1854,10 @@ main (int argc, char *argv[]) progname, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); exit(0); + case 'x': /* --hexdump */ + hexdump_g = TRUE; + fprintf(stderr, "not implemented yet: -x\n"); + exit(1); default: usage(progname); exit(1); diff --git a/tools/h5tools.c b/tools/h5tools.c index f61a5a5..994433a 100644 --- a/tools/h5tools.c +++ b/tools/h5tools.c @@ -454,6 +454,10 @@ h5dump_escape(char *s/*in,out*/, size_t size, int escape_spaces) * Made this function safe from overflow problems by allowing it * to reallocate the output string. * + * Robb Matzke, 1999-06-04 + * Added support for object references. The new `container' + * argument is the dataset where the reference came from. + * *------------------------------------------------------------------------- */ @@ -463,7 +467,7 @@ h5dump_escape(char *s/*in,out*/, size_t size, int escape_spaces) */ static char * h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, - hid_t type, void *vp) + hid_t container, hid_t type, void *vp) { size_t i, n, offset, size, dims[H5S_MAX_RANK], nelmts, start; char *name, quote='\0'; @@ -699,7 +703,8 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK)); } - h5dump_sprint(str, info, memb, (char*)vp+offset+i*size); + h5dump_sprint(str, info, container, memb, + (char*)vp+offset+i*size); } if (nelmts>1) { h5dump_str_append(str, "%s", OPT(info->arr_suf, "]")); @@ -720,6 +725,39 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info, } } + } else if (H5Tequal(type, H5T_STD_REF_DSETREG)) { + /* + * Dataset region reference -- show the type and OID of the + * referenced object, but we are unable to show the region yet + * because there isn't enough support in the data space layer. + * -rpm 19990604 + */ + int otype = H5Rget_object_type(container, vp); + hid_t obj = H5Rdereference(container, H5R_DATASET_REGION, vp); + switch (otype) { + case H5G_GROUP: + h5dump_str_append(str, "GRP-"); + H5Gclose(obj); + break; + case H5G_DATASET: + h5dump_str_append(str, "DSET-"); + H5Dclose(obj); + break; + case H5G_TYPE: + h5dump_str_append(str, "TYPE-"); + H5Tclose(obj); + break; + default: + h5dump_str_append(str, "%u-", otype); + /* unable to close `obj' since we don't know the type */ + break; + } + + + /* OID */ + + /* SPACE */ + } else { h5dump_str_append(str, "0x"); n = H5Tget_size(type); @@ -836,11 +874,14 @@ h5dump_simple_prefix(FILE *stream, const h5dump_t *info, * Monday, April 26, 1999 * * Modifications: + * Robb Matzke, 1999-06-04 + * The `container' argument is the optional dataset for + * reference types. * *------------------------------------------------------------------------- */ static void -h5dump_simple_data(FILE *stream, const h5dump_t *info, +h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container, h5dump_context_t *ctx/*in,out*/, unsigned flags, hsize_t nelmts, hid_t type, void *_mem) { @@ -863,7 +904,7 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, /* Render the element */ h5dump_str_reset(&buffer); - h5dump_sprint(&buffer, info, type, mem+i*size); + h5dump_sprint(&buffer, info, container, type, mem+i*size); if (i+1elmt_suf1, ",")); } @@ -1089,7 +1130,7 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset, return FAIL; } else if (programtype == H5LS){ - h5dump_simple_data(stream, info, &ctx, flags, hs_nelmts, p_type, + h5dump_simple_data(stream, info, dset, &ctx, flags, hs_nelmts, p_type, sm_buf); } else if (programtype == H5DUMP){ @@ -1198,8 +1239,8 @@ h5dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t type, size = H5Tget_size(type); /* Print it */ - h5dump_simple_data(stream, info, &ctx, START_OF_DATA|END_OF_DATA, - nelmts, type, mem); + h5dump_simple_data(stream, info, -1/*no dataset*/, &ctx, + START_OF_DATA|END_OF_DATA, nelmts, type, mem); /* Terminate the output */ if (ctx.cur_column) { @@ -1226,6 +1267,8 @@ h5dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t type, * Thursday, July 23, 1998 * * Modifications: + * Robb Matzke, 1999-06-04 + * Added support for references. * *------------------------------------------------------------------------- */ @@ -1361,6 +1404,7 @@ h5dump_fixtype(hid_t f_type) break; case H5T_ENUM: + case H5T_REFERENCE: m_type = H5Tcopy(f_type); break; @@ -1554,7 +1598,7 @@ struct h5dump_str_t tempstr; for (i=0; i (nCols-indent-COL)) { /* first row of member */ if (compound_data && (elmtno+i+1) == dim_n_size) @@ -1666,7 +1710,8 @@ static void display_string row_size++; h5dump_str_reset(&tempstr); - h5dump_sprint(&tempstr, &info,p_type, sm_buf+i*p_type_nbytes); + h5dump_sprint(&tempstr, &info, -1/*no container*/, p_type, + sm_buf+i*p_type_nbytes); memmove(tempstr.s, tempstr.s + 1, tempstr.len -1); tempstr.s[tempstr.len - 2] = '\0'; @@ -1932,7 +1977,6 @@ int nmembs, i, j, k, ndims, perm[4]; * *------------------------------------------------------------------------- */ - static int h5dump_simple(hid_t oid, hid_t p_type, int obj_data) { -- cgit v0.12