summaryrefslogtreecommitdiffstats
path: root/tools/h5dump
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-08-25 20:00:56 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-08-25 20:00:56 (GMT)
commit32220914a5313c0586dc59c89946d31334ad8b63 (patch)
tree8bc3eebbdb4591ea3439c20e626b7197e83c8a20 /tools/h5dump
parentf841a942427dd5d5fc139e30e07125de634e1863 (diff)
downloadhdf5-32220914a5313c0586dc59c89946d31334ad8b63.zip
hdf5-32220914a5313c0586dc59c89946d31334ad8b63.tar.gz
hdf5-32220914a5313c0586dc59c89946d31334ad8b63.tar.bz2
[svn-r7401] Purpose:
Code cleanup Description: Remove various "fixtype" routines which duplicate (and actually pre-date) the functionality in H5Tget_native_type in favor of having the tools call H5Tget_native_type(). This provides the same functionality (actually better functionality, since the old "fixtype" routines didn't handle alignment of compound fields correctly) and reduces the amount of code to maintain. Add additional tests to dump out a "complex" compound datatype which exercises more code in the library for aligning compound fields correctly. Platforms tested: FreeBSD 4.8 (sleipnir) h5committest
Diffstat (limited to 'tools/h5dump')
-rw-r--r--tools/h5dump/h5dump.c4
-rw-r--r--tools/h5dump/h5dumpgentest.c201
-rwxr-xr-xtools/h5dump/testh5dump.sh2
-rwxr-xr-xtools/h5dump/testh5dumpxml.sh1
4 files changed, 204 insertions, 4 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 4fe0092..c0841cc 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -1915,7 +1915,7 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset)
} else {
/* need to call h5tools_dump_mem for the attribute data */
type = H5Aget_type(obj_id);
- p_type = h5tools_fixtype(type);
+ p_type = H5Tget_native_type(type,H5T_DIR_DEFAULT);
space = H5Aget_space(obj_id);
ndims = H5Sget_simple_extent_dims(space, size, NULL);
@@ -4187,7 +4187,7 @@ xml_dump_data(hid_t obj_id, int obj_data, struct subset_t UNUSED * sset)
status = xml_print_strs(obj_id, ATTRIBUTE_DATA);
} else {
/* all other data */
- p_type = h5tools_fixtype(type);
+ p_type = H5Tget_native_type(type,H5T_DIR_DEFAULT);
H5Tclose(type);
space = H5Aget_space(obj_id);
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c
index b2715a1..b2edb8d 100644
--- a/tools/h5dump/h5dumpgentest.c
+++ b/tools/h5dump/h5dumpgentest.c
@@ -66,6 +66,7 @@
#define FILE38 "tvlstr.h5"
#define FILE39 "tchar.h5"
#define FILE40 "tattr2.h5"
+#define FILE41 "tcompound_complex.h5"
/* prototypes */
@@ -123,6 +124,20 @@ typedef struct s1_t {
/* VL string datatype name */
#define VLSTR_TYPE "vl_string_type"
+/* "File 41" macros */
+/* Name of dataset to create in datafile */
+#define F41_DATASETNAME "CompoundComplex"
+/* Dataset dimensions */
+#define F41_LENGTH 6
+#define F41_RANK 1
+#define F41_ARRAY_RANK 1
+#define F41_ARRAY_RANKd 2
+#define F41_DIMb 4
+#define F41_ARRAY_DIMc 6
+#define F41_ARRAY_DIMd1 5
+#define F41_ARRAY_DIMd2 6
+#define F41_ARRAY_DIMf 10
+
static void gent_group(void)
{
hid_t fid, group;
@@ -3852,8 +3867,8 @@ static void write_dset_in(hid_t loc_id,
static void gent_attr_all(void)
{
- hid_t file_id;
- hid_t dset_id;
+ hid_t file_id;
+ hid_t dset_id;
hid_t group_id;
hid_t group2_id;
hid_t root_id;
@@ -3984,6 +3999,186 @@ int write_dset( hid_t loc_id, int rank, hsize_t *dims, const char *dset_name,
}
+static void gent_compound_complex(void)
+{
+ /* Structure and array for compound types */
+ typedef struct Array1Struct {
+ int a;
+ const char *b[F41_DIMb];
+ char c[F41_ARRAY_DIMc];
+ short d[F41_ARRAY_DIMd1][F41_ARRAY_DIMd2];
+ float e;
+ double f[F41_ARRAY_DIMf];
+ char g;
+ } Array1Struct;
+ Array1Struct Array1[F41_LENGTH];
+
+ /* Define the value of the string array */
+ const char *quote [F41_DIMb] = {
+ "A fight is a contract that takes two people to honor.",
+ "A combative stance means that you've accepted the contract.",
+ "In which case, you deserve what you get.",
+ " -- Professor Cheng Man-ch'ing"
+ };
+
+ /* Define the value of the character array */
+ char chararray [F41_ARRAY_DIMc] = {'H', 'e', 'l', 'l', 'o', '!'};
+
+
+ hid_t Array1Structid; /* File datatype identifier */
+ hid_t array_tid; /* Array datatype handle */
+ hid_t array1_tid; /* Array datatype handle */
+ hid_t array2_tid; /* Array datatype handle */
+ hid_t array4_tid; /* Array datatype handle */
+ hid_t datafile, dataset; /* Datafile/dataset handles */
+ hid_t dataspace; /* Dataspace handle */
+ herr_t status; /* Error checking variable */
+ hsize_t dim[] = {F41_LENGTH}; /* Dataspace dimensions */
+ hsize_t array_dimb[] = {F41_DIMb}; /* Array dimensions */
+ hsize_t array_dimd[]={F41_ARRAY_DIMd1,F41_ARRAY_DIMd2}; /* Array dimensions */
+ hsize_t array_dimf[]={F41_ARRAY_DIMf}; /* Array dimensions */
+ hid_t str_array_id;
+
+ int m, n, o; /* Array init loop vars */
+
+ /* Initialize the data in the arrays/datastructure */
+ for (m = 0; m< F41_LENGTH; m++) {
+ Array1[m].a = m;
+
+ for (n = 0; n < F41_DIMb; n++) {
+ Array1[m].b[n] = quote[n];
+ }
+
+ for (n = 0; n < F41_ARRAY_DIMc; n++) {
+ Array1[m].c[n] = chararray[n];
+ }
+
+ for (n = 0; n < F41_ARRAY_DIMd1; n++) {
+ for (o = 0; o < F41_ARRAY_DIMd2; o++){
+ Array1[m].d[n][o] = m + n + o;
+ }
+ }
+
+ Array1[m].e = ( m * .96 );
+
+ for (n = 0; n < F41_ARRAY_DIMf; n++) {
+ Array1[m].f[n] = ( m * 1024.9637 );
+ }
+
+ Array1[m].g = 'm';
+ }
+
+ /* Create the dataspace */
+ dataspace = H5Screate_simple(F41_RANK, dim, NULL);
+ assert (dataspace >= 0);
+
+ /* Create the file */
+ datafile = H5Fcreate(FILE41, H5F_ACC_TRUNC, H5P_DEFAULT,
+ H5P_DEFAULT);
+ assert (datafile >= 0);
+
+ /* Copy the array data type for the string array */
+ array_tid = H5Tcopy (H5T_C_S1);
+ assert (array_tid >= 0);
+
+ /* Set the string array size to Variable */
+ status = H5Tset_size (array_tid,H5T_VARIABLE);
+ assert (status >= 0);
+
+ /* Create the array data type for the string array */
+ str_array_id = H5Tarray_create(array_tid, F41_ARRAY_RANK,
+ array_dimb, NULL);
+ assert (str_array_id >= 0);
+
+ /* Copy the array data type for the character array */
+ array1_tid = H5Tcopy (H5T_C_S1);
+ assert (array1_tid >= 0);
+
+ /* Set the character array size */
+ status = H5Tset_size (array1_tid, F41_ARRAY_DIMc);
+ assert (status >= 0);
+
+ /* Create the array data type for the character array */
+ array2_tid = H5Tarray_create(H5T_NATIVE_SHORT, F41_ARRAY_RANKd,
+ array_dimd, NULL);
+ assert (array2_tid >= 0);
+
+ /* Create the array data type for the character array */
+ array4_tid = H5Tarray_create(H5T_NATIVE_DOUBLE, F41_ARRAY_RANK,
+ array_dimf, NULL);
+ assert (array4_tid >= 0);
+
+ /* Create the memory data type */
+ Array1Structid = H5Tcreate (H5T_COMPOUND, sizeof(Array1Struct));
+ assert (Array1Structid >= 0);
+
+ /* Insert the arrays and variables into the structure */
+ status = H5Tinsert(Array1Structid, "a_name",
+ HOFFSET(Array1Struct, a), H5T_NATIVE_INT);
+ assert (status >= 0);
+
+ status = H5Tinsert(Array1Structid, "b_name",
+ HOFFSET(Array1Struct, b), str_array_id);
+ assert (status >= 0);
+
+ status = H5Tinsert(Array1Structid, "c_name",
+ HOFFSET(Array1Struct, c), array1_tid);
+ assert (status >= 0);
+
+ status = H5Tinsert(Array1Structid, "d_name",
+ HOFFSET(Array1Struct, d), array2_tid);
+ assert (status >= 0);
+
+ status = H5Tinsert(Array1Structid, "e_name",
+ HOFFSET(Array1Struct, e), H5T_NATIVE_FLOAT);
+ assert (status >= 0);
+
+ status = H5Tinsert(Array1Structid, "f_name",
+ HOFFSET(Array1Struct, f), array4_tid);
+ assert (status >= 0);
+
+ status = H5Tinsert(Array1Structid, "g_name",
+ HOFFSET(Array1Struct, g), H5T_NATIVE_CHAR);
+ assert (status >= 0);
+
+ /* Create the dataset */
+ dataset = H5Dcreate(datafile, F41_DATASETNAME, Array1Structid,
+ dataspace, H5P_DEFAULT);
+
+ /* Write data to the dataset */
+ status = H5Dwrite(dataset, Array1Structid, H5S_ALL, H5S_ALL,
+ H5P_DEFAULT, Array1);
+ assert (status >= 0);
+
+ /* Release resources */
+ status = H5Tclose(Array1Structid);
+ assert (status >= 0);
+
+ status = H5Tclose(array_tid);
+ assert (status >= 0);
+
+ status = H5Tclose(array1_tid);
+ assert (status >= 0);
+
+ status = H5Tclose(array2_tid);
+ assert (status >= 0);
+
+ status = H5Tclose(array4_tid);
+ assert (status >= 0);
+
+ status = H5Tclose(str_array_id);
+ assert (status >= 0);
+
+ status = H5Sclose(dataspace);
+ assert (status >= 0);
+
+ status = H5Dclose(dataset);
+ assert (status >= 0);
+
+ status = H5Fclose(datafile);
+ assert (status >= 0);
+}
+
/*-------------------------------------------------------------------------
* Function: main
@@ -4047,5 +4242,7 @@ int main(void)
gent_attr_all();
+ gent_compound_complex();
+
return 0;
}
diff --git a/tools/h5dump/testh5dump.sh b/tools/h5dump/testh5dump.sh
index 6855cba..d1dfe0c 100755
--- a/tools/h5dump/testh5dump.sh
+++ b/tools/h5dump/testh5dump.sh
@@ -119,6 +119,8 @@ TOOLTEST tcomp-1.ddl tcompound.h5
TOOLTEST tcomp-2.ddl -t /type1 --datatype /type2 --datatype=/group1/type3 tcompound.h5
# test for unamed type
TOOLTEST tcomp-3.ddl -t /#6632 -g /group2 tcompound.h5
+# test complicated compound datatype
+TOOLTEST tcomp-4.ddl tcompound_complex.h5
#test for the nested compound type
TOOLTEST tnestcomp-1.ddl tnestedcomp.h5
diff --git a/tools/h5dump/testh5dumpxml.sh b/tools/h5dump/testh5dumpxml.sh
index 9c7ef67..bd10949 100755
--- a/tools/h5dump/testh5dumpxml.sh
+++ b/tools/h5dump/testh5dumpxml.sh
@@ -100,6 +100,7 @@ TOOLTEST tloop.h5.xml --xml tloop.h5
TOOLTEST tloop2.h5.xml --xml tloop2.h5
TOOLTEST tmany.h5.xml --xml tmany.h5
TOOLTEST tnestedcomp.h5.xml --xml tnestedcomp.h5
+TOOLTEST tcompound_complex.h5.xml --xml tcompound_complex.h5
TOOLTEST tobjref.h5.xml --xml tobjref.h5
TOOLTEST topaque.h5.xml --xml topaque.h5
TOOLTEST tslink.h5.xml --xml tslink.h5