summaryrefslogtreecommitdiffstats
path: root/tools/h5dump/h5dumpgentest.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-08-25 19:57:22 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-08-25 19:57:22 (GMT)
commit3bec1171088e60d6b70f50a6996b1e77b92c2c5e (patch)
tree3ce7adc20129881b76fa2582aa5d975a5f3f69d4 /tools/h5dump/h5dumpgentest.c
parent81b8f134f8fec4c637873bc7366428a8a7ce2589 (diff)
downloadhdf5-3bec1171088e60d6b70f50a6996b1e77b92c2c5e.zip
hdf5-3bec1171088e60d6b70f50a6996b1e77b92c2c5e.tar.gz
hdf5-3bec1171088e60d6b70f50a6996b1e77b92c2c5e.tar.bz2
[svn-r7399] 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/h5dumpgentest.c')
-rw-r--r--tools/h5dump/h5dumpgentest.c197
1 files changed, 197 insertions, 0 deletions
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c
index b2715a1..0cbe3e3 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;
@@ -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;
}