/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the files COPYING and Copyright.html. COPYING can be found at the root * * of the source code distribution tree; Copyright.html can be found at the * * root level of an installed copy of the electronic HDF5 document set and * * is linked from the top-level documents page. It can also be found at * * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * Programmer: Robb Matzke * Friday, January 23, 1998 */ /* See H5private.h for how to include headers */ #undef NDEBUG #define H5T_PACKAGE #include "H5Tpkg.h" /*to turn off hardware conversions*/ #include "h5test.h" const char *FILENAME[] = { "cmpd_dset", NULL }; /* The first dataset */ typedef struct s1_t { unsigned int a; unsigned int b; unsigned int c[4]; unsigned int d; unsigned int e; } s1_t; /* The second dataset (same as first) */ typedef s1_t s2_t; /* The third dataset (reversed fields of s1) */ typedef struct s3_t { unsigned int e; unsigned int d; unsigned int c[4]; unsigned int b; unsigned int a; } s3_t; /* The fourth dataset (a subset of s1) */ typedef struct s4_t { unsigned int b; unsigned int d; } s4_t; /* The fifth dataset (a superset of s1) */ typedef struct s5_t { unsigned int pre; unsigned int a; unsigned int b; unsigned int mid1; unsigned int c[4]; unsigned int mid2; unsigned int d; unsigned int e; unsigned int post; } s5_t; #if 1 # define NX 100u # define NY 2000u #else # define NX 12u # define NY 9u #endif /*------------------------------------------------------------------------- * Function: main * * Purpose: Creates a simple dataset of a compound type and then reads * it back. The dataset is read back in various ways to * exercise the I/O pipeline and compound type conversion. * * Return: Success: 0 * * Failure: 1 * * Programmer: Robb Matzke * Friday, January 23, 1998 * * Modifications: * Robb Matzke, 1999-06-23 * If the command line switch `--noopt' is present then the fast * compound datatype conversion is turned off. *------------------------------------------------------------------------- */ int main (int argc, char *argv[]) { /* First dataset */ static s1_t s1[NX*NY]; hid_t s1_tid; /* Second dataset */ static s2_t s2[NX*NY]; hid_t s2_tid; /* Third dataset */ static s3_t s3[NX*NY]; hid_t s3_tid; /* Fourth dataset */ static s4_t s4[NX*NY]; hid_t s4_tid; /* Fifth dataset */ static s5_t s5[NX*NY]; hid_t s5_tid; /* Sixth dataset */ /* Seventh dataset */ hid_t s7_sid; /* Eighth dataset */ s1_t *s8 = NULL; hid_t s8_f_sid; /*file data space */ hid_t s8_m_sid; /*memory data space */ /* Ninth dataset */ /* Tenth dataset */ /* Eleventh dataset */ s4_t *s11 = NULL; /* Other variables */ unsigned int i, j; hid_t file, dataset, space, PRESERVE, fapl; hid_t array_dt; static hsize_t dim[] = {NX, NY}; hsize_t f_offset[2]; /*offset of hyperslab in file */ hsize_t h_size[2]; /*size of hyperslab */ hsize_t memb_size[1] = {4}; char filename[256]; int ret_code; h5_reset(); /* Turn off optimized compound converter? */ if (argc>1) { if (argc>2 || strcmp("--noopt", argv[1])) { fprintf(stderr, "usage: %s [--noopt]\n", argv[0]); exit(1); } H5Tunregister(H5T_PERS_DONTCARE, NULL, -1, -1, H5T_conv_struct_opt); } /* Create the file */ fapl = h5_fileaccess(); h5_fixname(FILENAME[0], fapl, filename, sizeof(filename)); if ((file = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) { goto error; } /* Create the data space */ if ((space = H5Screate_simple (2, dim, NULL))<0) goto error; /* Create xfer properties to preserve initialized data */ /* Also verify H5Pset_preserve is initially 0 and then is set to 1. */ if ((PRESERVE = H5Pcreate (H5P_DATASET_XFER))<0) goto error; if ((ret_code=H5Pget_preserve (PRESERVE)) != 0){ printf("Preserve status of dataset transfer property list should be" " 0 (FALSE), got %d\n", ret_code); goto error; } if (H5Pset_preserve (PRESERVE, 1)<0) goto error; if ((ret_code=H5Pget_preserve (PRESERVE)) != 1){ printf("Preserve status of dataset transfer property list should be" " 1 (TRUE), got %d\n", ret_code); goto error; } /* *###################################################################### * STEP 1: Save the original dataset natively. */ TESTING("basic compound write"); /* Initialize the dataset */ for (i=0; i members * stored on disk we'll read . */ TESTING("subset struct read"); /* Create a datatype for s4 */ if ((s4_tid = H5Tcreate (H5T_COMPOUND, sizeof(s4_t)))<0) goto error; if (H5Tinsert (s4_tid, "b", HOFFSET(s4_t,b), H5T_NATIVE_INT)<0) goto error; if (H5Tinsert (s4_tid, "d", HOFFSET(s4_t,d), H5T_NATIVE_INT)<0) goto error; /* Read the data */ if (H5Dread (dataset, s4_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s4)<0) { goto error; } /* Compare s4 with s1 */ for (i=0; ia != ps1->a || ps8->b != ps1->b || ps8->c[0] != ps1->c[0] || ps8->c[1] != ps1->c[1] || ps8->c[2] != ps1->c[2] || ps8->c[3] != ps1->c[3] || ps8->d != ps1->d || ps8->e != ps1->e) { H5_FAILED(); puts(" Incorrect values read from file"); goto error; } } } free (s8); s8 = NULL; PASSED(); /* *###################################################################### * STEP 9. Read a hyperslab of the file into a hyperslab of memory. The * part of memory not read is already initialized and must not change. */ TESTING("hyperslab partial read to another hyperslab"); /* Initialize */ for (i=0; i=f_offset[0] && i=f_offset[1] && ja != ps1->a || ps2->b != ps1->b || ps2->c[0] != ps1->c[0] || ps2->c[1] != ps1->c[1] || ps2->c[2] != ps1->c[2] || ps2->c[3] != ps1->c[3] || ps2->d != ps1->d || ps2->e != ps1->e) { H5_FAILED(); puts(" Memory values clobbered"); goto error; } } else { if (ps2->a != (unsigned)(-1) || ps2->b != (unsigned)(-1) || ps2->c[0] != (unsigned)(-1) || ps2->c[1] != (unsigned)(-1) || ps2->c[2] != (unsigned)(-1) || ps2->c[3] != (unsigned)(-1) || ps2->d != (unsigned)(-1) || ps2->e != (unsigned)(-1)) { H5_FAILED(); puts(" Incorrect values read from file"); goto error; } } } } PASSED(); /* *###################################################################### * STEP 10. Same as step 9 except the memory array contains some members * which are already initialized, like step 5. */ TESTING("hyperslab to hyperslab part initialized read"); /* Initialize */ for (i=0; i=f_offset[0] && i=f_offset[1] && jpre != (unsigned)(-1) || ps5->a != ps1->a || ps5->b != ps1->b || ps5->mid1 != (unsigned)(-1) || ps5->c[0] != ps1->c[0] || ps5->c[1] != ps1->c[1] || ps5->c[2] != ps1->c[2] || ps5->c[3] != ps1->c[3] || ps5->mid2 != (unsigned)(-1) || ps5->d != ps1->d || ps5->e != ps1->e || ps5->post != (unsigned)(-1)) { H5_FAILED(); puts(" Memory values clobbered"); goto error; } } else { if (ps5->pre != (unsigned)(-1) || ps5->a != (unsigned)(-1) || ps5->b != (unsigned)(-1) || ps5->mid1 != (unsigned)(-1) || ps5->c[0] != (unsigned)(-1) || ps5->c[1] != (unsigned)(-1) || ps5->c[2] != (unsigned)(-1) || ps5->c[3] != (unsigned)(-1) || ps5->mid2 != (unsigned)(-1) || ps5->d != (unsigned)(-1) || ps5->e != (unsigned)(-1) || ps5->post != (unsigned)(-1)) { H5_FAILED(); puts(" Incorrect values read from file"); goto error; } } } } PASSED(); /* *###################################################################### * Step 11: Write an array into the middle third of the dataset * initializeing only members `b' and `d' to -1. */ TESTING("hyperslab part initialized write"); /* Create the memory array and initialize all fields to zero */ f_offset[0] = NX/3; f_offset[1] = NY/3; h_size[0] = 2*NX/3 - f_offset[0]; h_size[1] = 2*NY/3 - f_offset[1]; s11 = malloc ((size_t)h_size[0]*(size_t)h_size[1]*sizeof(s4_t)); assert (s11); /* Initialize */ for (i=0; ia != 8*(i*NY+j)+0 || ps1->c[0] != 8*(i*NY+j)+2 || ps1->c[1] != 8*(i*NY+j)+3 || ps1->c[2] != 8*(i*NY+j)+4 || ps1->c[3] != 8*(i*NY+j)+5 || ps1->e != 8*(i*NY+j)+7) { H5_FAILED(); puts(" Write clobbered values"); goto error; } if (i>=f_offset[0] && i=f_offset[1] && jb != (unsigned)(-1) || ps1->d != (unsigned)(-1)) { H5_FAILED(); puts(" Wrong values written or read"); goto error; } } else { if (ps1->b != 8*(i*NY+j)+1 || ps1->d != 8*(i*NY+j)+6) { H5_FAILED(); puts(" Write clobbered values"); goto error; } } } } PASSED(); /* * Release resources. */ H5Pclose (PRESERVE); H5Dclose (dataset); H5Fclose (file); h5_cleanup(FILENAME, fapl); puts("All compound dataset tests passed."); return 0; error: puts("Remaining tests have been skipped."); puts("*** DATASET TESTS FAILED ***"); return 1; }