summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcvs2svn <no_author@cvs2svn>2001-03-14 04:42:20 (GMT)
committercvs2svn <no_author@cvs2svn>2001-03-14 04:42:20 (GMT)
commit1c47477b05ee7190c77d63b3f35e6d5b1721b98f (patch)
treeaaa61b06d1677c5eb4ff2079592f5b84011a4e5b
parentc5adbd01ac08f77388ba0ecbac523181afd9ab35 (diff)
downloadhdf5-1c47477b05ee7190c77d63b3f35e6d5b1721b98f.zip
hdf5-1c47477b05ee7190c77d63b3f35e6d5b1721b98f.tar.gz
hdf5-1c47477b05ee7190c77d63b3f35e6d5b1721b98f.tar.bz2
[svn-r3621] This commit was manufactured by cvs2svn to create branch 'hdf5_1_4'.
-rw-r--r--c++/test/dsets.cpp1048
-rw-r--r--c++/test/testhdf5.cpp320
-rw-r--r--c++/test/tfile.cpp315
-rw-r--r--doc/html/Tutor/examples/attrexample.f9087
-rw-r--r--doc/html/Tutor/examples/chunk.f90310
-rw-r--r--doc/html/Tutor/examples/compound.f90215
-rw-r--r--doc/html/Tutor/examples/dsetexample.f9070
-rw-r--r--doc/html/Tutor/examples/fileexample.f9034
-rw-r--r--doc/html/Tutor/examples/groupexample.f9049
-rw-r--r--doc/html/Tutor/examples/grpdsetexample.f90136
-rw-r--r--doc/html/Tutor/examples/grpit.f90194
-rw-r--r--doc/html/Tutor/examples/grpsexample.f9068
-rw-r--r--doc/html/Tutor/examples/hyperslab.f90199
-rw-r--r--doc/html/Tutor/examples/java/Compound.java540
-rw-r--r--doc/html/Tutor/examples/java/Copy.java541
-rw-r--r--doc/html/Tutor/examples/java/CreateAttribute.java302
-rw-r--r--doc/html/Tutor/examples/java/CreateDataset.java210
-rw-r--r--doc/html/Tutor/examples/java/CreateFile.java83
-rw-r--r--doc/html/Tutor/examples/java/CreateFileInput.java118
-rw-r--r--doc/html/Tutor/examples/java/CreateGroup.java139
-rw-r--r--doc/html/Tutor/examples/java/CreateGroupAR.java152
-rw-r--r--doc/html/Tutor/examples/java/CreateGroupDataset.java340
-rw-r--r--doc/html/Tutor/examples/java/DatasetRdWt.java213
-rw-r--r--doc/html/Tutor/examples/java/HyperSlab.java590
-rw-r--r--doc/html/Tutor/examples/java/Makefile92
-rw-r--r--doc/html/Tutor/examples/java/README21
-rw-r--r--doc/html/Tutor/examples/java/readme.html192
-rw-r--r--doc/html/Tutor/examples/java/runCompound.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCompound.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runCopy.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCopy.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runCreateAttribute.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCreateAttribute.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runCreateDataset.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCreateDataset.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runCreateFile.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCreateFile.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runCreateFileInput.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCreateFileInput.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runCreateGroup.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCreateGroup.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runCreateGroupAR.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCreateGroupAR.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runCreateGroupDataset.sh17
-rw-r--r--doc/html/Tutor/examples/java/runCreateGroupDataset.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runDatasetRdWt.sh17
-rw-r--r--doc/html/Tutor/examples/java/runDatasetRdWt.sh.in17
-rw-r--r--doc/html/Tutor/examples/java/runHyperSlab.sh17
-rw-r--r--doc/html/Tutor/examples/java/runHyperSlab.sh.in17
-rw-r--r--doc/html/Tutor/examples/mountexample.f90187
-rw-r--r--doc/html/Tutor/examples/refobjexample.f90142
-rw-r--r--doc/html/Tutor/examples/refregexample.f90162
-rw-r--r--doc/html/Tutor/examples/rwdsetexample.f9078
-rw-r--r--doc/html/Tutor/examples/selectele.f90282
-rw-r--r--doc/html/Tutor/property.html169
-rw-r--r--doc/html/Tutor/software.html88
-rw-r--r--tools/h4toh5/h4toh5pal.c202
-rw-r--r--tools/h4toh5/h4toh5test.c3946
-rw-r--r--tools/h4toh5/h4toh5util.h232
-rw-r--r--tools/h5ls/h5ls.c2167
-rw-r--r--tools/h5toh4/h5toh4.c2587
-rw-r--r--tools/lib/Makefile.in57
-rw-r--r--tools/lib/h5tools.h474
-rw-r--r--tools/lib/h5tools_str.c999
-rw-r--r--tools/lib/h5tools_str.h32
-rw-r--r--tools/lib/h5tools_utils.h114
-rw-r--r--tools/lib/talign.c174
67 files changed, 19044 insertions, 0 deletions
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp
new file mode 100644
index 0000000..6d05f31
--- /dev/null
+++ b/c++/test/dsets.cpp
@@ -0,0 +1,1048 @@
+/****************************************************************************
+ * NCSA HDF *
+ * Software Development Group *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+/***********************************************************
+*
+* Test program: dsets
+*
+* Test the dataset interface (H5D)
+*
+*************************************************************/
+
+#include <iostream>
+#include "H5Cpp.h"
+#include "h5test.h"
+#include "testhdf5.h"
+
+#ifndef H5_NO_NAMESPACE
+using namespace H5;
+#endif
+
+const char *FILENAME[] = {
+ "dataset",
+ NULL
+};
+
+#define DSET_DEFAULT_NAME "default"
+#define DSET_CHUNKED_NAME "chunked"
+#define DSET_SIMPLE_IO_NAME "simple_io"
+#define DSET_TCONV_NAME "tconv"
+#define DSET_COMPRESS_NAME "compressed"
+#define DSET_BOGUS_NAME "bogus"
+
+#define H5Z_BOGUS 305
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_create
+ *
+ * Purpose: Attempts to create a dataset.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler
+ * Friday, January 5, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_create( H5File& file)
+{
+ TESTING("create, open, close");
+
+ try {
+ /* Create the data space */
+ hsize_t dims[2];
+ dims[0] = 256;
+ dims[1] = 512;
+ DataSpace space (2, dims, NULL);
+
+ /*
+ * Create a dataset using the default dataset creation properties.
+ * We're not sure what they are, so we won't check.
+ */
+ DataSet *dataset = new DataSet (file.createDataSet
+ (DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space));
+
+ /* Close the dataset */
+ delete dataset;
+
+ /* Add a comment to the dataset */
+ file.setComment (DSET_DEFAULT_NAME, "This is a dataset");
+
+ /*
+ * Try creating a dataset that already exists. This should fail since a
+ * dataset can only be created once. If an exception is not thrown
+ * for this action by createDataSet, then display failure information
+ * and jump to label error: to return.
+ */
+ try {
+ dataset = new DataSet (file.createDataSet
+ (DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space));
+ // continuation here, that means no exception has been thrown
+ H5_FAILED();
+ cout << " Library allowed overwrite of existing dataset." << endl;
+ goto error;
+ }
+ catch (FileIException E ) // catching invalid creating dataset
+ {
+ // Exception is expected. Do nothing here.
+ }
+ /*
+ * Open the dataset we created above and then close it. This is how
+ * existing datasets are accessed.
+ */
+ dataset = new DataSet (file.openDataSet (DSET_DEFAULT_NAME));
+ delete dataset;
+
+ /*
+ * Try opening a non-existent dataset. This should fail so if an
+ * exception is not thrown for this action by openDataSet, then
+ * display failure information and jump to label error: to return.
+ */
+ try {
+ dataset = new DataSet (file.openDataSet( "does_not_exist" ));
+ // continuation here, that means no exception has been thrown
+ H5_FAILED();
+ cout << " Opened a non-existent dataset." << endl;
+ goto error;
+ }
+ catch (FileIException E ) // catching creating non-existent dataset
+ {
+ // Exception is expected. Do nothing here.
+ }
+
+ /*
+ * Create a new dataset that uses chunked storage instead of the default
+ * layout.
+ */
+ DSetCreatPropList create_parms;
+ hsize_t csize[2];
+ csize[0] = 5;
+ csize[1] = 100;
+ create_parms.setChunk( 2, csize );
+
+ dataset = new DataSet (file.createDataSet
+ (DSET_CHUNKED_NAME, PredType::NATIVE_DOUBLE, space, create_parms));
+ // Note: this one has no error message in C when failure occurs?
+
+ /*
+ * Close the chunked dataset.
+ */
+ delete dataset;
+
+ PASSED();
+ return 0;
+ } // outer most try block
+
+ // catch all dataset, file, space, plist exceptions
+ catch (Exception E) { goto error; }
+
+ error:
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: check_values
+ *
+ * Purpose: Checks a read value against the written value. If they are
+ * different, the function will
+ * print out a message and the different values. This function
+ * is made to reuse the code segment that is used in various
+ * places throughout test_compression and in test_simple_io.
+ * Where the C version
+ * of this code segment "goto error," this function will
+ * return -1, so that the caller can "goto error."
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler (using C code segment for checking values)
+ * Friday, February 6, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+check_values (hsize_t i, hsize_t j, int apoint, int acheck)
+{
+ if (apoint != acheck)
+ {
+ H5_FAILED();
+ cout << " Read different values than written.\n" << endl;
+ cout << " At index " << (unsigned long)i << "," <<
+ (unsigned long)j << endl;
+ return -1;
+ }
+ return 0;
+} // check_values
+
+/*-------------------------------------------------------------------------
+ * Function: test_simple_io
+ *
+ * Purpose: Tests simple I/O. That is, reading and writing a complete
+ * multi-dimensional array without data type or data space
+ * conversions, without compression, and stored contiguously.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler (using Robb Matzke's C version)
+ * Friday, January 5, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_simple_io( H5File& file)
+{
+
+ TESTING("simple I/O");
+
+ int points[100][200];
+ int check[100][200];
+ int i, j, n;
+
+ /* Initialize the dataset */
+ for (i = n = 0; i < 100; i++)
+ {
+ for (j = 0; j < 200; j++) {
+ points[i][j] = n++;
+ }
+ }
+
+ char* tconv_buf = new char [1000];
+ try
+ {
+ /* Create the data space */
+ hsize_t dims[2];
+ dims[0] = 100;
+ dims[1] = 200;
+ DataSpace space (2, dims, NULL);
+
+ /* Create a small conversion buffer to test strip mining */
+ DSetMemXferPropList xfer;
+
+ //if (H5Pset_buffer (xfer, 1000, tconv_buf, NULL)<0) goto error;
+ xfer.setBuffer (1000, tconv_buf, NULL);
+
+ /* Create the dataset */
+ DataSet dataset (file.createDataSet (DSET_SIMPLE_IO_NAME, PredType::NATIVE_INT, space));
+
+ /* Write the data to the dataset */
+ dataset.write ((void*) points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ /* Read the dataset back */
+ dataset.read ((void*) check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < 100; i++)
+ for (j = 0; j < 200; j++)
+ {
+ int status = check_values (i, j, points[i][j], check[i][j]);
+ if (status == -1) goto error;
+ }
+
+ delete [] tconv_buf;
+ PASSED();
+ return 0;
+ } // end try
+
+ // catch all dataset, space, plist exceptions
+ catch (Exception E) { goto error; }
+
+ error:
+ // cleaning up
+ if (tconv_buf)
+ delete [] tconv_buf;
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: test_tconv
+ *
+ * Purpose: Test some simple data type conversion stuff.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler (using Robb Matzke's C version)
+ * Friday, January 5, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_tconv( H5File& file)
+{
+ // Prepare buffers for input/output
+ char *out=NULL, *in=NULL;
+ out = new char [4*1000000];
+ // assert (out); - should use exception handler for new - BMR
+ in = new char [4*1000000];
+ //assert (in);
+
+ TESTING("data type conversion");
+
+ /* Initialize the dataset */
+ for (int i = 0; i < 1000000; i++) {
+ out[i*4+0] = 0x11;
+ out[i*4+1] = 0x22;
+ out[i*4+2] = 0x33;
+ out[i*4+3] = 0x44;
+ }
+
+ try
+ {
+ /* Create the data space */
+ hsize_t dims[1];
+ dims[0] = 1000000;
+ DataSpace space (1, dims, NULL);
+
+ /* Create the data set */
+ DataSet dataset (file.createDataSet (DSET_TCONV_NAME, PredType::STD_I32LE, space));
+
+ /* Write the data to the dataset */
+ dataset.write ((void*) out, PredType::STD_I32LE);
+
+ /* Read data with byte order conversion */
+ dataset.read ((void*) in, PredType::STD_I32BE);
+
+ /* Check */
+ for (int i = 0; i < 1000000; i++) {
+ if (in[4*i+0]!=out[4*i+3] ||
+ in[4*i+1]!=out[4*i+2] ||
+ in[4*i+2]!=out[4*i+1] ||
+ in[4*i+3]!=out[4*i+0])
+ {
+ H5_FAILED();
+ cout << " Read with byte order conversion failed." << endl;
+ goto error;
+ }
+ }
+
+ delete [] out;
+ delete [] in;
+ cout << " PASSED" << endl;
+ return 0;
+ } // end try
+
+ // catch all dataset and space exceptions
+ catch (Exception E) { goto error; }
+
+ error:
+ delete [] out;
+ delete [] in;
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: bogus
+ *
+ * Purpose: A bogus compression method that doesn't do anything.
+ *
+ * Return: Success: Data chunk size
+ *
+ * Failure: 0
+ *
+ * Programmer: Robb Matzke
+ * Tuesday, April 21, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static size_t
+/*bogus(unsigned int UNUSED flags, size_t UNUSED cd_nelmts,
+ const unsigned int UNUSED cd_values[], size_t nbytes,
+ size_t UNUSED *buf_size, void UNUSED **buf)
+BMR: removed UNUSED for now until asking Q. or R. to pass compilation*/
+bogus(unsigned int flags, size_t cd_nelmts,
+ const unsigned int cd_values[], size_t nbytes,
+ size_t *buf_size, void **buf)
+{
+ return nbytes;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_compression
+ *
+ * Purpose: Tests dataset compression. If compression is requested when
+ * it hasn't been compiled into the library (such as when
+ * updating an existing compressed dataset) then data is sent to
+ * the file uncompressed but no errors are returned.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler (using Robb Matzke's C version)
+ * Friday, January 5, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static herr_t
+test_compression(H5File& file)
+{
+ const char *not_supported;
+ not_supported = " Deflate compression is not supported.\n"
+ " The zlib was not found when hdf5 was configured.";
+
+ TESTING("compression (setup)");
+
+ int points[100][200];
+ int check[100][200];
+ hsize_t i, j, n;
+
+ /* Initialize the dataset */
+ for (i = n = 0; i < 100; i++)
+ {
+ for (j = 0; j < 200; j++) {
+ points[i][j] = n++;
+ }
+ }
+ char* tconv_buf = new char [1000];
+
+ try
+ {
+ const hsize_t size[2] = {100, 200};
+ /* Create the data space */
+ DataSpace space1(2, size, NULL);
+
+ /*
+ * Create a small conversion buffer to test strip mining. We
+ * might as well test all we can!
+ */
+ DSetMemXferPropList xfer;
+
+ xfer.setBuffer (1000, tconv_buf, NULL);
+
+ /* Use chunked storage with compression */
+ DSetCreatPropList dscreatplist;
+
+ const hsize_t chunk_size[2] = {2, 25};
+ dscreatplist.setChunk (2, chunk_size);
+ dscreatplist.setDeflate (6);
+
+ /* Create the dataset */
+ DataSet* dataset = new DataSet (file.createDataSet
+ (DSET_COMPRESS_NAME, PredType::NATIVE_INT, space1, dscreatplist));
+
+#if defined(H5_HAVE_COMPRESS2) && defined(H5_HAVE_ZLIB_H) && defined(H5_HAVE_LIBZ)
+ PASSED();
+#else
+ SKIPPED();
+ cout << not_supported << endl;
+#endif
+
+ /*----------------------------------------------------------------------
+ * STEP 1: Read uninitialized data. It should be zero.
+ *----------------------------------------------------------------------
+ */
+ TESTING("compression (uninitialized read)");
+
+ dataset->read ((void*) check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ for (i=0; i<size[0]; i++) {
+ for (j=0; j<size[1]; j++) {
+ if (0!=check[i][j]) {
+ H5_FAILED();
+ cout << " Read a non-zero value." << endl;
+ cout << " At index " << (unsigned long)i << "," <<
+ (unsigned long)j << endl;
+ goto error;
+ }
+ }
+ }
+#if defined(H5_HAVE_COMPRESS2) && defined(H5_HAVE_ZLIB_H) && defined(H5_HAVE_LIBZ)
+ PASSED();
+#else
+ SKIPPED();
+ cout << not_supported << endl;
+#endif
+
+ /*----------------------------------------------------------------------
+ * STEP 2: Test compression by setting up a chunked dataset and writing
+ * to it.
+ *----------------------------------------------------------------------
+ */
+ TESTING("compression (write)");
+
+ for (i=n=0; i<size[0]; i++)
+ {
+ for (j=0; j<size[1]; j++)
+ {
+ points[i][j] = n++;
+ }
+ }
+
+ //if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, points)<0) goto error;
+ dataset->write ((void*) points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+#if defined(H5_HAVE_COMPRESS2) && defined(H5_HAVE_ZLIB_H) && defined(H5_HAVE_LIBZ)
+ PASSED();
+#else
+ SKIPPED();
+ cout << not_supported << endl;
+#endif
+
+ /*----------------------------------------------------------------------
+ * STEP 3: Try to read the data we just wrote.
+ *----------------------------------------------------------------------
+ */
+ TESTING("compression (read)");
+
+ /* Read the dataset back */
+ dataset->read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < size[0]; i++)
+ for (j = 0; j < size[1]; j++)
+ {
+ int status = check_values (i, j, points[i][j], check[i][j]);
+ if (status == -1) goto error;
+ }
+
+#if defined(H5_HAVE_COMPRESS2) && defined(H5_HAVE_ZLIB_H) && defined(H5_HAVE_LIBZ)
+ PASSED();
+#else
+ SKIPPED();
+ cout << not_supported << endl;
+#endif
+
+ /*----------------------------------------------------------------------
+ * STEP 4: Write new data over the top of the old data. The new data is
+ * random thus not very compressible, and will cause the chunks to move
+ * around as they grow. We only change values for the left half of the
+ * dataset although we rewrite the whole thing.
+ *----------------------------------------------------------------------
+ */
+ TESTING("compression (modify)");
+
+ for (i=0; i<size[0]; i++)
+ {
+ for (j=0; j<size[1]/2; j++)
+ {
+ points[i][j] = rand ();
+ }
+ }
+ dataset->write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ /* Read the dataset back and check it */
+ dataset->read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < size[0]; i++)
+ for (j = 0; j < size[1]; j++)
+ {
+ int status = check_values (i, j, points[i][j], check[i][j]);
+ if (status == -1) goto error;
+ }
+
+#if defined(H5_HAVE_COMPRESS2) && defined(H5_HAVE_ZLIB_H) && defined(H5_HAVE_LIBZ)
+ PASSED();
+#else
+ SKIPPED();
+ cout << not_supported << endl;
+#endif
+
+ /*----------------------------------------------------------------------
+ * STEP 5: Close the dataset and then open it and read it again. This
+ * insures that the compression message is picked up properly from the
+ * object header.
+ *----------------------------------------------------------------------
+ */
+ TESTING("compression (re-open)");
+
+ delete dataset;
+
+ //if ((dataset = H5Dopen (file, DSET_COMPRESS_NAME))<0) goto error;
+ dataset = new DataSet (file.openDataSet (DSET_COMPRESS_NAME));
+ dataset->read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < size[0]; i++)
+ for (j = 0; j < size[1]; j++)
+ {
+ int status = check_values (i, j, points[i][j], check[i][j]);
+ if (status == -1) goto error;
+ }
+
+#if defined(H5_HAVE_COMPRESS2) && defined(H5_HAVE_ZLIB_H) && defined(H5_HAVE_LIBZ)
+ PASSED();
+#else
+ SKIPPED();
+ cout << not_supported << endl;
+#endif
+
+
+ /*----------------------------------------------------------------------
+ * STEP 6: Test partial I/O by writing to and then reading from a
+ * hyperslab of the dataset. The hyperslab does not line up on chunk
+ * boundaries (we know that case already works from above tests).
+ *----------------------------------------------------------------------
+ */
+ TESTING("compression (partial I/O)");
+
+ const hsize_t hs_size[2] = {4, 50};
+ const hssize_t hs_offset[2] = {7, 30};
+ for (i = 0; i < hs_size[0]; i++) {
+ for (j = 0; j < hs_size[1]; j++) {
+ points[hs_offset[0]+i][hs_offset[1]+j] = rand ();
+ }
+ }
+ space1.selectHyperslab( H5S_SELECT_SET, hs_size, hs_offset );
+ dataset->write ((void*)points, PredType::NATIVE_INT, space1, space1, xfer);
+ dataset->read ((void*)check, PredType::NATIVE_INT, space1, space1, xfer);
+
+ /* Check that the values read are the same as the values written */
+ for (i=0; i<hs_size[0]; i++) {
+ for (j=0; j<hs_size[1]; j++) {
+ if (points[hs_offset[0]+i][hs_offset[1]+j] !=
+ check[hs_offset[0]+i][hs_offset[1]+j]) {
+ H5_FAILED();
+ cout << " Read different values than written.\n" << endl;
+ cout << " At index " << (unsigned long)(hs_offset[0]+i) <<
+ "," << (unsigned long)(hs_offset[1]+j) << endl;
+
+ cout << " At original: " << (int)points[hs_offset[0]+i][hs_offset[1]+j] << endl;
+ cout << " At returned: " << (int)check[hs_offset[0]+i][hs_offset[1]+j] << endl;
+ goto error;
+ }
+ }
+ }
+#if defined(H5_HAVE_COMPRESS2) && defined(H5_HAVE_ZLIB_H) && defined(H5_HAVE_LIBZ)
+ PASSED();
+#else
+ SKIPPED();
+ cout << not_supported << endl;
+#endif
+
+ /*----------------------------------------------------------------------
+ * STEP 7: Register an application-defined compression method and use it
+ * to write and then read the dataset.
+ *----------------------------------------------------------------------
+ */
+ TESTING("compression (app-defined method)");
+
+ // BMR: not sure how to handle this yet
+ if (H5Zregister (H5Z_BOGUS, DSET_BOGUS_NAME, bogus)<0) goto error;
+ if (H5Pset_filter (dscreatplist.getId(), H5Z_BOGUS, 0, 0, NULL)<0) goto error;
+ dscreatplist.setFilter (H5Z_BOGUS, 0, 0, NULL);
+ delete dataset;
+
+ DataSpace space2 (2, size, NULL);
+ dataset = new DataSet (file.createDataSet (DSET_BOGUS_NAME, PredType::NATIVE_INT, space2, dscreatplist));
+
+ dataset->write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+ dataset->read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < size[0]; i++)
+ for (j = 0; j < size[1]; j++)
+ {
+ int status = check_values (i, j, points[i][j], check[i][j]);
+ if (status == -1) goto error;
+ }
+
+ PASSED();
+
+ /*----------------------------------------------------------------------
+ * Cleanup
+ *----------------------------------------------------------------------
+ */
+ delete dataset;
+ delete [] tconv_buf;
+ return 0;
+ } // end try
+
+ // catch all dataset, file, space, and plist exceptions
+ catch (Exception E) { goto error; }
+
+ error:
+ // cleaning up
+ if (tconv_buf)
+ delete [] tconv_buf;
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: test_multiopen
+ *
+ * Purpose: Tests that a bug no longer exists. If a dataset is opened
+ * twice and one of the handles is used to extend the dataset,
+ * then the other handle should return the new size when
+ * queried.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler (using Robb Matzke's C version)
+ * Saturday, February 17, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_multiopen (H5File& file)
+{
+
+ TESTING("multi-open with extending");
+ try {
+
+ // Create a dataset creation property list
+ DSetCreatPropList dcpl;
+
+ // Set chunk size to given size
+ hsize_t cur_size[1] = {10};
+ dcpl.setChunk (1, cur_size);
+
+ // Create a simple data space with unlimited size
+ static hsize_t max_size[1] = {H5S_UNLIMITED};
+ DataSpace* space = new DataSpace (1, cur_size, max_size);
+
+ // Create first dataset
+ DataSet dset1 = file.createDataSet ("multiopen", PredType::NATIVE_INT, *space, dcpl);
+
+ //BMR: Quincey said Rob gave a tweak to have dataset being the first
+ // argument in this call but actually shouldn't be valid, so just
+ // ignore the argument dset1. Just open the first dataset again
+ // from the file to another DataSet object.
+ // if ((dset2=H5Dopen (dset1, "."))<0) goto error;
+ DataSet dset2 = file.openDataSet ("multiopen");
+
+ // Relieve the dataspace
+ delete space;
+
+ // Extend the dimensionality of the first dataset
+ cur_size[0] = 20;
+ dset1.extend (cur_size);
+
+ /* Get the size from the second handle */
+ //if ((space = H5Dget_space (dset2))<0) goto error;
+ space = new DataSpace (dset2.getSpace());
+
+ hsize_t tmp_size[1];
+ //if (H5Sget_simple_extent_dims (space, tmp_size, NULL)<0) goto error;
+ space->getSimpleExtentDims (tmp_size);
+ if (cur_size[0]!=tmp_size[0])
+ {
+ H5_FAILED();
+ cout << " Got " << (int)tmp_size[0] << " instead of "
+ << (int)cur_size[0] << "!" << endl;
+ delete space;
+ goto error;
+ }
+
+ delete space;
+ PASSED();
+ return 0;
+ } // end try block
+
+ // catch all dataset, file, space, and plist exceptions
+ catch (Exception E)
+ { goto error; }
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_types
+ *
+ * Purpose: Make some datasets with various types so we can test h5ls.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Binh-Minh Ribler (using Robb Matzke's C version)
+ * February 17, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_types(H5File& file)
+{
+ size_t i;
+
+ TESTING("various datatypes");
+ try {
+
+ // Create a group in the file that was passed in from the caller
+ Group grp = file.createGroup ("typetests");
+
+ /* bitfield_1 */
+ unsigned char buf[32];
+ hsize_t nelmts = sizeof(buf);
+ DataType type;
+ try { // block 1
+ type.copy (PredType::STD_B8LE);
+ DataSpace space (1, &nelmts);
+ DataSet* dset = new DataSet(grp.createDataSet("bitfield_1", type, space));
+
+ // Fill buffer
+ for (i=0; i<sizeof buf; i++)
+ buf[i] = (unsigned char)0xff ^ (unsigned char)i;
+
+ // Write data from buf using all default dataspaces and property
+ // list; if writing fails, deallocate dset and return.
+ try { dset->write (buf, type); }
+ catch(DataSetIException E)
+ {
+ delete dset;
+ goto error;
+ }
+ delete dset;
+
+ } // end try block of bitfield_1
+
+ // catch exceptions thrown in try block of bitfield_1
+ catch (Exception E) { goto error; }
+
+ /* bitfield_2 */
+ nelmts = sizeof(buf)/2;
+ try { // bitfield_2 block
+
+ type.copy (PredType::STD_B16LE);
+ DataSpace space (1, &nelmts);
+ DataSet* dset = new DataSet(grp.createDataSet("bitfield_2", type, space));
+
+ // Fill buffer
+ for (i=0; i<sizeof(buf); i++)
+ buf[i] = (unsigned char)0xff ^ (unsigned char)i;
+
+ // Write data from buf using all default dataspaces and property
+ // list; if writing fails, deallocate dset and return.
+ try { dset->write (buf, type); }
+ catch(DataSetIException E)
+ {
+ delete dset;
+ goto error;
+ }
+ delete dset;
+ } // end try block of bitfield_2
+
+ // catch exceptions thrown in try block of bitfield_2
+ catch (Exception E) { goto error; }
+
+ /* opaque_1 */
+ DataType* optype = new DataType(H5T_OPAQUE, 1);
+ try { // opaque_1 block
+ nelmts = sizeof(buf);
+ DataSpace space (1, &nelmts);
+ optype->setTag ("testing 1-byte opaque type");
+ DataSet* dset = new DataSet(grp.createDataSet("opaque_1", *optype, space));
+
+ // Fill buffer
+ for (i=0; i<sizeof buf; i++)
+ buf[i] = (unsigned char)0xff ^ (unsigned char)i;
+
+ // Write data from buf using all default dataspaces and property
+ // list; if writing fails, deallocate dset and return.
+ try { dset->write (buf, *optype); }
+ catch(DataSetIException E)
+ {
+ delete dset;
+ goto error;
+ }
+ delete dset;
+ delete optype;
+ } // end try block of opaque_1
+
+ // catch exceptions thrown in try block of opaque_1
+ catch (DataSetIException E) { delete optype; goto error; }
+ catch (Exception E) { goto error; }
+
+ /* opaque_2 */
+ try { // block opaque_2
+ nelmts = sizeof(buf)/4;
+ DataSpace space (1, &nelmts);
+ optype = new DataType(H5T_OPAQUE, 4);
+ optype->setTag ("testing 4-byte opaque type");
+ DataSet* dset = new DataSet(grp.createDataSet("opaque_2", *optype, space));
+
+ // Fill buffer
+ for (i=0; i<sizeof(buf); i++)
+ buf[i] = (unsigned char)0xff ^ (unsigned char)i;
+
+ // Write data from buf using all default dataspaces and property
+ // list; if writing fails, deallocate dset and return.
+ try { dset->write (buf, *optype); }
+ catch(DataSetIException E)
+ {
+ delete dset;
+ goto error;
+ }
+ delete dset;
+ delete optype;
+ } //end try block of opaque_2
+ catch (DataSetIException E) { delete optype; goto error; }
+ catch (Exception E) { goto error; }
+
+ PASSED();
+ return 0;
+ } // end top try block
+ catch (Exception E) { goto error; } // Group and DataType exceptions
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_report
+ *
+ * Purpose: Prints out the number of errors for dataset tests if there
+ * were any failures occurred. If no failure, test_report
+ * prints out the "All dataset tests passed" message
+ *
+ * Return: if any failure has occurred: 1
+ *
+ * if no failure occurs: 0
+ *
+ * Programmer: Binh-Minh Ribler (using C code segment for reporting tests)
+ * Friday, February 6, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int test_report( int nerrors )
+{
+ if (nerrors)
+ {
+ nerrors = MAX(1, nerrors);
+ if (1 == nerrors)
+ cout << "***** " << nerrors << " DATASET TEST"
+ << " FAILED! *****" << endl;
+ else
+ cout << "***** " << nerrors << " DATASET TESTS"
+ << " FAILED! *****" << endl;
+ return 1;
+ }
+ else
+ {
+ cout << "All dataset tests passed." << endl;
+ return 0;
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: Tests the dataset interface (H5D)
+ *
+ * Return: Success: exit(0)
+ *
+ * Failure: exit(1)
+ *
+ * Programmer: Binh-Minh Ribler (using Robb Matzke's C version)
+ * Friday, January 5, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+main(void)
+{
+
+ h5_reset(); // in h5test.c, resets the library by closing it
+
+ hid_t fapl_id;
+ fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template
+ // should create an object from this id - BMR
+
+#if 0
+/* BMR: leave paralell stuff out! */
+ {
+ // Turn off raw data cache
+ int mdc_nelmts;
+ (H5Pget_cache(fapl_id, &mdc_nelmts, NULL, NULL, NULL)<0) goto error;
+ (H5Pset_cache(fapl_id, mdc_nelmts, 0, 0, 0.0)<0) goto error;
+ }
+#endif
+
+ char filename[1024];
+ h5_fixname(FILENAME[0], fapl_id, filename, sizeof filename);
+
+ int nerrors=0; // keep track of number of failures occurr
+ try
+ {
+ // Turn of the auto-printing when failure occurs so that we can
+ // handle the errors appropriately since sometime failures are
+ // caused deliberately and expected.
+ Exception::dontPrint();
+
+ // Use the file access template id to create a file access prop.
+ // list object to pass in H5File::H5File
+ FileAccPropList* fapl = new FileAccPropList(fapl_id);
+
+ H5File file( filename, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, *fapl );
+
+ /* Cause the library to emit initial messages */
+ Group grp = file.createGroup( "emit diagnostics", 0);
+ grp.setComment( ".", "Causes diagnostic messages to be emitted");
+
+ nerrors += test_create(file)<0 ?1:0;
+ nerrors += test_simple_io(file)<0 ?1:0;
+ 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;
+
+ // BMR: this is a very unattractive workaround approach, but I used
+ // it for now, since I want to use already existing utility code from
+ // the C tests. h5_cleanup calls H5Pclose to close the fapl_id while
+ // the object 'fapl' is still opened. So, I dynamically allocated
+ // 'fapl' then deleted it before h5_cleanup, but after incrementing
+ // 'fapl's ref counter so that the prop list id will not be closed
+ // when 'fapl' is destroyed. Why did I need to create a
+ // FileCreatPropList object while I already had the prop list id?
+ // Because I need to pass it into the constructor H5File::H5File.
+ // We're trying to avoid introducing id's into the C++ API.
+ fapl->incRefCount();
+ delete fapl;
+ h5_cleanup(FILENAME, fapl_id);
+ return( test_report( nerrors ));
+ }
+ catch (FileIException error)
+ {
+ return( test_report( nerrors ));
+ }
+ catch (GroupIException error )
+ {
+ return( test_report( nerrors ));
+ }
+}
+
+
diff --git a/c++/test/testhdf5.cpp b/c++/test/testhdf5.cpp
new file mode 100644
index 0000000..eee18e3
--- /dev/null
+++ b/c++/test/testhdf5.cpp
@@ -0,0 +1,320 @@
+/*
+ * Copyright (C) 2001 National Center for Supercomputing Applications
+ * All rights reserved.
+ *
+ */
+
+/*
+ FILE
+ testhdf5.cpp - HDF5 testing framework main file.
+
+ REMARKS
+ General test wrapper for HDF5 base library test programs
+
+ DESIGN
+ Each test function should be implemented as function having no
+ parameters and returning void (i.e. no return value). They should be put
+ into the list of InitTest() calls in main() below. Functions which depend
+ on other functionality should be placed below the InitTest() call for the
+ base functionality testing.
+ Each test module should include testhdf5.h and define a unique set of
+ names for test files they create.
+
+ BUGS/LIMITATIONS
+
+ EXPORTED ROUTINES/VARIABLES:
+ Two variables are exported: num_errs, and Verbosity.
+
+ */
+
+#ifdef __MWERKS__
+#include <console.h>
+#endif /* __MWERKS__ */
+
+#include <stdarg.h>
+
+#define MAXNUMOFTESTS 30
+#define HDF5_TEST_MASTER
+
+/* Internal Variables */
+static int Index = 0;
+
+/* Global variables */
+int num_errs = 0;
+int Verbosity;
+
+// Use C version of the header file testhdf5.h instead of re-coding it
+#include "testhdf5.h"
+#include <iostream>
+#include "H5Cpp.h"
+
+#ifndef H5_NO_NAMESPACE
+using namespace H5;
+#endif /* !H5_NO_NAMESPACE */
+
+struct TestStruct {
+ int NumErrors;
+ char Description[64];
+ int SkipFlag;
+ char Name[16];
+ void (*Call) (void);
+ void (*Cleanup) (void);
+} Test[MAXNUMOFTESTS];
+
+static void InitTest(const char *, void (*) (void), void (*) (void), const char *TheDescr);
+static void usage(void);
+
+static void InitTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), const char *TheDescr)
+{
+ if (Index >= MAXNUMOFTESTS) {
+ print_func("Uh-oh, too many tests added, increase MAXNUMOFTEST!\n");
+ exit(-1);
+ }
+
+ HDstrcpy(Test[Index].Description, TheDescr);
+ HDstrcpy(Test[Index].Name, TheName);
+ Test[Index].Call = TheCall;
+ Test[Index].Cleanup = Cleanup;
+ Test[Index].NumErrors = -1;
+ Test[Index].SkipFlag = 0;
+ Index++;
+}
+
+static void
+usage(void)
+{
+ print_func("Usage: testhdf5 [-v[erbose] (l[ow]|m[edium]|h[igh]|0-10)] \n");
+ print_func(" [-[e]x[clude] name+] \n");
+ print_func(" [-o[nly] name+] \n");
+ print_func(" [-b[egin] name] \n");
+ print_func(" [-s[ummary]] \n");
+ print_func(" [-c[leanoff]] \n");
+ print_func(" [-n[ocaching]] \n");
+ print_func(" [-h[elp]] \n");
+ print_func("\n\n");
+ print_func("verbose controls the amount of information displayed\n");
+ print_func("exclude to exclude tests by name\n");
+ print_func("only to name tests which should be run\n");
+ print_func("begin start at the name of the test givin\n");
+ print_func("summary prints a summary of test results at the end\n");
+ print_func("cleanoff does not delete *.hdf files after execution of tests\n");
+ print_func("nocaching do not turn on low-level DD caching\n");
+ print_func("help print out this information\n");
+ print_func("\n\n");
+ print_func("This program currently tests the following: \n\n");
+ print_func("%16s %s\n", "Name", "Description");
+ print_func("%16s %s\n", "----", "-----------");
+
+ for (int i = 0; i < Index; i++)
+ print_func("%16s %s\n", Test[i].Name, Test[i].Description);
+
+ print_func("\n\n");
+}
+
+/*
+ * This routine is designed to provide equivalent functionality to 'printf'
+ * and allow easy replacement for environments which don't have stdin/stdout
+ * available. (i.e. Windows & the Mac)
+ */
+int
+print_func(const char *format,...)
+{
+ va_list arglist;
+ int ret_value;
+
+ va_start(arglist, format);
+ ret_value = vprintf(format, arglist);
+ va_end(arglist);
+ return ret_value;
+}
+
+void
+test_tbbt(void)
+{
+}
+
+int
+main(int argc, char *argv[])
+{
+ int CLLoop; /* Command Line Loop */
+ int Loop, Loop1;
+ int Summary = 0;
+ int CleanUp = 1;
+ int Cache = 1;
+
+#ifdef __MWERKS__
+ argc = ccommand(&argv);
+#endif /* __MWERKS__ */
+
+#if !(defined MAC || defined __MWERKS__ || defined SYMANTEC_C)
+ /* Un-buffer the stdout and stderr */
+ setbuf(stderr, NULL);
+ setbuf(stdout, NULL);
+#endif /* !(MAC || __MWERKS__ || SYMANTEC_C) */
+
+ /*
+ * Turn off automatic error reporting since we do it ourselves. Besides,
+ * half the functions this test calls are private, so automatic error
+ * reporting wouldn't do much good since it's triggered at the API layer.
+ */
+ Exception::dontPrint();
+
+ // Tests are generally arranged from least to most complexity...
+ //InitTest("metadata", test_metadata, cleanup_metadata, "Encode/decode metadata code");
+
+ // C++ API doesn't need this test */
+ InitTest("tbbt", test_tbbt, NULL, "Threaded, Balanced, Binary Trees - not tested");
+
+ // testing file creation and opening in tfile.cpp
+ InitTest("file", test_file, cleanup_file, "Low-Level File I/O");
+
+ // Comment out tests that are not done yet. - BMR, Feb 2001
+ //InitTest("h5s", test_h5s, cleanup_h5s, "Dataspaces");
+ //InitTest("attr", test_attr, cleanup_attr, "Attributes");
+ //InitTest("select", test_select, cleanup_select, "Selections");
+ //InitTest("time", test_time, cleanup_time, "Time Datatypes");
+ //InitTest("reference", test_reference, cleanup_reference, "References");
+ //InitTest("vltypes", test_vltypes, cleanup_vltypes, "Variable-Length Datatypes");
+ //InitTest("vlstrings", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings");
+ //InitTest("iterate", test_iterate, cleanup_iterate, "Group & Attribute Iteration");
+ //InitTest("array", test_array, cleanup_array, "Array Datatypes");
+ //InitTest("genprop", test_genprop, cleanup_genprop, "Generic Properties");
+
+ Verbosity = 4; /* Default Verbosity is Low */
+ uintn major, minor, release;
+ H5Library::getLibVersion( major, minor, release);
+
+ print_func("\nFor help use: testhdf5 -help\n");
+ print_func("Linked with hdf5 version %u.%u release %u\n",
+ (unsigned)major, (unsigned)minor, (unsigned)release);
+
+ for (CLLoop = 1; CLLoop < argc; CLLoop++) {
+ if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-verbose") == 0) ||
+ (HDstrcmp(argv[CLLoop], "-v") == 0))) {
+ if (argv[CLLoop + 1][0] == 'l')
+ Verbosity = 4;
+ else if (argv[CLLoop + 1][0] == 'm')
+ Verbosity = 6;
+ else if (argv[CLLoop + 1][0] == 'h')
+ Verbosity = 10;
+ else
+ Verbosity = atoi(argv[CLLoop + 1]);
+ }
+
+ if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-summary") == 0) ||
+ (HDstrcmp(argv[CLLoop], "-s") == 0)))
+ Summary = 1;
+
+ if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-help") == 0) ||
+ (HDstrcmp(argv[CLLoop], "-h") == 0))) {
+ usage();
+ exit(0);
+ }
+
+ if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-cleanoff") == 0) ||
+ (HDstrcmp(argv[CLLoop], "-c") == 0)))
+ CleanUp = 0;
+
+ if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-nocache") == 0) ||
+ (HDstrcmp(argv[CLLoop], "-n") == 0))) {
+ Cache = 0;
+ printf ("Cache = %d\n", Cache);
+ }
+
+ if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-exclude") == 0) ||
+ (HDstrcmp(argv[CLLoop], "-x") == 0))) {
+ Loop = CLLoop + 1;
+
+ while ((Loop < argc) && (argv[Loop][0] != '-')) {
+ for (Loop1 = 0; Loop1 < Index; Loop1++)
+ if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
+ Test[Loop1].SkipFlag = 1;
+
+ Loop++;
+ }
+ }
+
+ if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-begin") == 0) ||
+ (HDstrcmp(argv[CLLoop], "-b") == 0))) {
+ Loop = CLLoop + 1;
+
+ while ((Loop < argc) && (argv[Loop][0] != '-')) {
+ for (Loop1 = 0; Loop1 < Index; Loop1++) {
+ if (HDstrcmp(argv[Loop], Test[Loop1].Name) != 0)
+ Test[Loop1].SkipFlag = 1;
+ if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
+ Loop1 = Index;
+ }
+
+ Loop++;
+ }
+ }
+
+ if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-only") == 0) ||
+ (HDstrcmp(argv[CLLoop], "-o") == 0))) {
+ for (Loop = 0; Loop < Index; Loop++)
+ Test[Loop].SkipFlag = 1;
+ Loop = CLLoop + 1;
+ while ((Loop < argc) && (argv[Loop][0] != '-')) {
+ for (Loop1 = 0; Loop1 < Index; Loop1++)
+ if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
+ Test[Loop1].SkipFlag = 0;
+ Loop++;
+ }
+ }
+ }
+
+#ifdef NOT_YET
+ if (Cache) /* turn on caching, unless we were instucted not to */
+ Hcache(CACHE_ALL_FILES, TRUE);
+#endif /* NOT_YET */
+
+ for (Loop = 0; Loop < Index; Loop++) {
+ if (Test[Loop].SkipFlag) {
+ MESSAGE(2, ("Skipping -- %s \n", Test[Loop].Description));
+ } else {
+ MESSAGE(2, ("Testing -- %s (%s) \n", Test[Loop].Description,
+ Test[Loop].Name));
+ MESSAGE(5, ("===============================================\n"));
+ Test[Loop].NumErrors = num_errs;
+ (*Test[Loop].Call) ();
+ Test[Loop].NumErrors = num_errs - Test[Loop].NumErrors;
+ MESSAGE(5, ("===============================================\n"));
+ MESSAGE(5, ("There were %d errors detected.\n\n", (int) Test[Loop].NumErrors));
+ }
+ }
+
+ MESSAGE(2, ("\n\n"))
+
+ if (num_errs)
+ print_func("!!! %d Error(s) were detected !!!\n\n", (int) num_errs);
+ else
+ print_func("All tests were successful. \n\n");
+
+ if (Summary) {
+ print_func("Summary of Test Results:\n");
+ print_func("Name of Test Errors Description of Test\n");
+ print_func("---------------- ------ --------------------------------------\n");
+
+ for (Loop = 0; Loop < Index; Loop++) {
+ if (Test[Loop].NumErrors == -1)
+ print_func("%16s %6s %s\n", Test[Loop].Name, "N/A", Test[Loop].Description);
+ else
+ print_func("%16s %6d %s\n", Test[Loop].Name, (int) Test[Loop].NumErrors,
+ Test[Loop].Description);
+ }
+
+ print_func("\n\n");
+ }
+
+ if (CleanUp && !getenv("HDF5_NOCLEANUP")) {
+ MESSAGE(2, ("\nCleaning Up temp files...\n\n"));
+
+ /* call individual cleanup routines in each source module */
+ for (Loop = 0; Loop < Index; Loop++)
+ if (!Test[Loop].SkipFlag && Test[Loop].Cleanup!=NULL)
+ (*Test[Loop].Cleanup) ();
+ }
+
+ return num_errs;
+}
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp
new file mode 100644
index 0000000..3a3cb1d
--- /dev/null
+++ b/c++/test/tfile.cpp
@@ -0,0 +1,315 @@
+/*
+ * Copyright (C) 2001 National Center for Supercomputing Applications
+ * All rights reserved.
+ *
+ */
+
+/*
+ * Test program: tfile
+ *
+ * Test the low-level file I/O features.
+ */
+
+//#include "H5private.h"
+//#include "H5Bprivate.h"
+//#include "H5Pprivate.h"
+
+#include <iostream>
+#include "H5Cpp.h"
+#include "testhdf5.h"
+
+#ifndef H5_NO_NAMESPACE
+using namespace H5;
+#endif /* !H5_NO_NAMESPACE */
+
+#define F1_USERBLOCK_SIZE (hsize_t)0
+#define F1_OFFSET_SIZE sizeof(haddr_t)
+#define F1_LENGTH_SIZE sizeof(hsize_t)
+#define F1_SYM_LEAF_K 4
+#define F1_SYM_INTERN_K 16
+#define FILE1 "tfile1.h5"
+
+#define F2_USERBLOCK_SIZE (hsize_t)512
+#define F2_OFFSET_SIZE 8
+#define F2_LENGTH_SIZE 8
+#define F2_SYM_LEAF_K 8
+#define F2_SYM_INTERN_K 32
+#define FILE2 "tfile2.h5"
+
+#define F3_USERBLOCK_SIZE (hsize_t)0
+#define F3_OFFSET_SIZE F2_OFFSET_SIZE
+#define F3_LENGTH_SIZE F2_LENGTH_SIZE
+#define F3_SYM_LEAF_K F2_SYM_LEAF_K
+#define F3_SYM_INTERN_K F2_SYM_INTERN_K
+#define FILE3 "tfile3.h5"
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_file_create
+ *
+ * Purpose: Test file and template creations
+ *
+ * Return: None
+ *
+ * Programmer: Binh-Minh Ribler
+ * January, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+test_file_create(void)
+{
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Low-Level File Creation I/O\n"));
+
+ /* Test create with various sequences of H5F_ACC_EXCL and */
+ /* H5F_ACC_TRUNC flags */
+
+ /* Create with H5F_ACC_EXCL */
+ /* First ensure the file does not exist */
+ remove(FILE1);
+
+ try {
+ H5File* fid1 = new H5File (FILE1, H5F_ACC_EXCL);
+
+ /*
+ * try to create the same file with H5F_ACC_TRUNC. This should fail
+ * because fid1 is the same file and is currently open.
+ */
+ try { H5File fid2 (FILE1, H5F_ACC_TRUNC); }
+ catch( FileIException error ) {
+ // cannot use fid2 here (out of scope), but the exception was
+ // thrown only if file id was < 0, so -1 is used to verify - 1/15/01
+ VERIFY(-1, FAIL, "H5File constructor");
+ }
+ // Close file fid1
+ delete fid1;
+
+ /*
+ * Try again with H5F_ACC_EXCL. This should fail because the file already
+ * exists from the previous steps.
+ */
+ try { fid1 = new H5File( FILE1, H5F_ACC_EXCL ); }
+ catch( FileIException error ){ VERIFY(-1, FAIL, "H5File constructor"); }
+
+ // Test create with H5F_ACC_TRUNC. This will truncate the existing file.
+ fid1 = new H5File (FILE1, H5F_ACC_TRUNC);
+
+ /*
+ * Try to truncate first file again. This should fail because fid1 is the
+ * same file and is currently open.
+ */
+ try { H5File fid2 (FILE1, H5F_ACC_TRUNC); }
+ catch( FileIException error ) { VERIFY(-1, FAIL, "H5File constructor"); }
+
+ /*
+ * Try with H5F_ACC_EXCL. This should fail too because the file already
+ * exists.
+ */
+ try { H5File fid3 (FILE1, H5F_ACC_EXCL); }
+ catch( FileIException error ) { VERIFY(-1, FAIL, "H5File constructor"); }
+
+ /* Get the file-creation template */
+ FileCreatPropList tmpl1 = fid1->getCreatePlist();
+
+ hsize_t ublock = tmpl1.getUserblock();
+ VERIFY(ublock, F1_USERBLOCK_SIZE, "FileCreatPropList::H5Pget_userblock");
+
+ size_t parm1, parm2; /*file-creation parameters */
+ tmpl1.getSizes( parm1, parm2);
+ VERIFY(parm1, F1_OFFSET_SIZE, "FileCreatPropList::getSizes");
+ VERIFY(parm2, F1_LENGTH_SIZE, "FileCreatPropList::getSizes");
+
+ int iparm1, iparm2; /*file-creation parameters */
+ tmpl1.getSymk( iparm1, iparm2);
+ VERIFY(iparm1, F1_SYM_INTERN_K, "FileCreatPropList::getSymk");
+ VERIFY(iparm2, F1_SYM_LEAF_K, "FileCreatPropList::getSymk");
+
+ // tmpl1 is automatically closed; if error occurs, it'll be
+ // caught in the catch block
+
+ /* Close first file */
+ delete fid1;
+ }
+ catch( PropListIException error ) {
+ CHECK(-1, FAIL, error.getCFuncName());
+ }
+ catch( FileIException error ) {
+ CHECK(-1, FAIL, error.getCFuncName());
+ }
+
+ try
+ {
+ /* Create a new file with a non-standard file-creation template */
+ FileCreatPropList* tmpl1 = new FileCreatPropList;
+
+ /* Set the new file-creation parameters */
+ tmpl1->setUserblock (F2_USERBLOCK_SIZE);
+ tmpl1->setSizes( F2_OFFSET_SIZE, F2_LENGTH_SIZE );
+ tmpl1->setSymk( F2_SYM_INTERN_K, F2_SYM_LEAF_K );
+
+ /*
+ * Try to create second file, with non-standard file-creation template
+ * params.
+ */
+ H5File fid2( FILE2, H5F_ACC_TRUNC, *tmpl1 );
+
+ /* Release file-creation template */
+ delete tmpl1;
+// here is still good
+
+ /* Get the file-creation template */
+ tmpl1 = new FileCreatPropList (fid2.getCreatePlist());
+
+ /* Get the file-creation parameters */
+ hsize_t ublock = tmpl1->getUserblock();
+ VERIFY(ublock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock");
+
+ size_t parm1, parm2; /*file-creation parameters */
+ tmpl1->getSizes( parm1, parm2);
+ VERIFY(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes");
+ VERIFY(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes");
+
+ int iparm1, iparm2; /*file-creation parameters */
+ tmpl1->getSymk( iparm1, iparm2);
+ VERIFY(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk");
+ VERIFY(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk");
+
+ /* Clone the file-creation template */
+ FileCreatPropList tmpl2;
+ tmpl2.copy (*tmpl1);
+
+ /* Dynamically release file-creation template */
+ delete tmpl1;
+
+ /* Set the new file-creation parameter */
+ tmpl2.setUserblock( F3_USERBLOCK_SIZE );
+
+ /*
+ * Try to create second file, with non-standard file-creation template
+ * params
+ */
+ H5File fid3( FILE3, H5F_ACC_TRUNC, tmpl2 );
+
+ /* Get the file-creation template */
+ tmpl1 = new FileCreatPropList (fid3.getCreatePlist());
+
+ /* Get the file-creation parameters */
+ ublock = tmpl1->getUserblock();
+ VERIFY(ublock, F3_USERBLOCK_SIZE, "FileCreatPropList::getUserblock");
+
+ tmpl1->getSizes( parm1, parm2);
+ VERIFY(parm1, F3_OFFSET_SIZE, "FileCreatPropList::getSizes");
+ VERIFY(parm2, F3_LENGTH_SIZE, "FileCreatPropList::getSizes");
+
+ tmpl1->getSymk( iparm1, iparm2);
+ VERIFY(iparm1, F3_SYM_INTERN_K, "FileCreatPropList::getSymk");
+ VERIFY(iparm2, F3_SYM_LEAF_K, "FileCreatPropList::getSymk");
+
+ /* Dynamically release file-creation template */
+ delete tmpl1;
+ }
+ catch( PropListIException error ) {
+ CHECK(-1, FAIL, error.getCFuncName());
+ }
+} /* test_file_create() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_file_open
+ *
+ * Purpose: Test file accesses
+ *
+ * Return: None
+ *
+ * Programmer: Binh-Minh Ribler
+ * January, 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+test_file_open(void)
+{
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Low-Level File Opening I/O\n"));
+
+ try {
+
+ /* Open first file */
+ H5File fid1 (FILE2, H5F_ACC_RDWR );
+
+ /* Get the file-creation template */
+ //FileCreatPropList tmpl1;
+ FileCreatPropList tmpl1 = fid1.getCreatePlist();
+
+ /* Get the file-creation parameters */
+ hsize_t ublock = tmpl1.getUserblock();
+ VERIFY(ublock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock");
+
+ size_t parm1, parm2; /*file-creation parameters */
+ tmpl1.getSizes( parm1, parm2);
+ VERIFY(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes");
+ VERIFY(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes");
+
+ int iparm1, iparm2; /*file-creation parameters */
+ tmpl1.getSymk( iparm1, iparm2);
+ VERIFY(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk");
+ VERIFY(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk");
+ } // end of try block
+
+ catch( Exception error ) {
+ CHECK(FAIL, FAIL, error.getCFuncName());
+ }
+} /* test_file_open() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_file
+ *
+ * Purpose: Main program
+ *
+ * Return: None
+ *
+ * Programmer: Binh-Minh Ribler
+ * January 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+test_file(void)
+{
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Low-Level File I/O\n"));
+
+ test_file_create(); /* Test file creation (also creation templates) */
+ test_file_open(); /* Test file opening */
+} /* test_file() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: cleanup_file
+ *
+ * Purpose: Cleanup temporary test files
+ *
+ * Return: none
+ *
+ * Programmer: Binh-Minh Ribler
+ * January 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+cleanup_file(void)
+{
+ remove(FILE1);
+ remove(FILE2);
+ remove(FILE3);
+} /* cleanup_file */
diff --git a/doc/html/Tutor/examples/attrexample.f90 b/doc/html/Tutor/examples/attrexample.f90
new file mode 100644
index 0000000..9198eb8
--- /dev/null
+++ b/doc/html/Tutor/examples/attrexample.f90
@@ -0,0 +1,87 @@
+! This example shows how to create and write a dataset attribute.
+! It opens the existing file 'dset.h5', obtains the identifier of
+! the dataset "/dset", defines attribute's dataspace,
+! creates dataset attribute, writes the attribute, and then closes
+! the attribute's dataspace, attribute, dataset, and file.
+
+ PROGRAM ATTREXAMPLE
+
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=8), PARAMETER :: filename = "dsetf.h5" ! File name
+ CHARACTER(LEN=4), PARAMETER :: dsetname = "dset" ! Dataset name
+ CHARACTER(LEN=4), PARAMETER :: aname = "attr" ! Attribute name
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: dset_id ! Dataset identifier
+ INTEGER(HID_T) :: attr_id ! Attribute identifier
+ INTEGER(HID_T) :: aspace_id ! Attribute Dataspace identifier
+
+ INTEGER(HSIZE_T), DIMENSION(1) :: adims = (/2/) ! Attribute dimension
+ INTEGER, DIMENSION(2) :: attr_data = (/100,200/)! Attribute data
+ INTEGER :: arank = 1 ! Attribure rank
+
+ INTEGER :: error ! Error flag
+
+
+ !
+ ! Initialize FORTRAN predefined datatypes.
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Open an existing file.
+ !
+ CALL h5fopen_f (filename, H5F_ACC_RDWR_F, file_id, error)
+
+ !
+ ! Open an existing dataset.
+ !
+ CALL h5dopen_f(file_id, dsetname, dset_id, error)
+
+ !
+ ! Create the data space for the attribute.
+ !
+ CALL h5screate_simple_f(arank, adims, aspace_id, error)
+
+ !
+ ! Create dataset attribute.
+ !
+ CALL h5acreate_f(dset_id, aname, H5T_NATIVE_INTEGER,aspace_id, &
+ attr_id, error)
+
+ !
+ ! Write the attribute data.
+ !
+ CALL h5awrite_f(attr_id, H5T_NATIVE_INTEGER, attr_data, error)
+
+ !
+ ! Close the attribute.
+ !
+ CALL h5aclose_f(attr_id, error)
+
+ !
+ ! Terminate access to the data space.
+ !
+ CALL h5sclose_f(aspace_id, error)
+
+ !
+ ! End access to the dataset and release resources used by it.
+ !
+ CALL h5dclose_f(dset_id, error)
+
+ !
+ ! Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! Close FORTRAN predefined datatypes.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM ATTREXAMPLE
+
diff --git a/doc/html/Tutor/examples/chunk.f90 b/doc/html/Tutor/examples/chunk.f90
new file mode 100644
index 0000000..2810b5c
--- /dev/null
+++ b/doc/html/Tutor/examples/chunk.f90
@@ -0,0 +1,310 @@
+!
+!This example shows how to work with extendible datasets.
+!It creates a 3 x 3 extendible dataset, write to that dataset,
+!extend the dataset to 10x3, and write to the dataset again
+!
+
+
+
+
+ PROGRAM CHUNKEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ !
+ !the dataset is stored in file "extf.h5"
+ !
+ CHARACTER(LEN=7), PARAMETER :: filename = "extf.h5"
+
+ !
+ !dataset name is "ExtendibleArray"
+ !
+ CHARACTER(LEN=15), PARAMETER :: dsetname = "ExtendibleArray"
+
+ !
+ !dataset rank is 2
+ !
+ INTEGER :: RANK = 2
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: dset_id ! Dataset identifier
+ INTEGER(HID_T) :: dataspace ! Dataspace identifier
+ INTEGER(HID_T) :: filespace ! Dataspace identifier
+ INTEGER(HID_T) :: memspace ! memspace identifier
+ INTEGER(HID_T) :: cparms !dataset creatation property identifier
+
+ !
+ !dataset dimensions at creation time
+ !
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/3,3/)
+
+ !
+ !data1 dimensions
+ !
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims1 = (/3,3/)
+
+ !
+ !data2 dimensions
+ !
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims2 = (/7,1/)
+
+ !
+ !Maximum dimensions
+ !
+ INTEGER(HSIZE_T), DIMENSION(2) :: maxdims
+
+ !
+ !data1 dimensions
+ !
+ INTEGER, DIMENSION(3,3) :: data1
+
+ !
+ !data2 dimensions
+ !
+ INTEGER, DIMENSION(7,1) :: data2
+
+ !
+ !Size of the hyperslab in the file
+ !
+ INTEGER(HSIZE_T), DIMENSION(2) :: size
+
+ !
+ !hyperslab offset in the file
+ !
+ INTEGER(HSIZE_T), DIMENSION(2) :: offset
+
+ !
+ !general purpose integer
+ !
+ INTEGER :: i, j, k
+
+ !
+ !flag to check operation success
+ !
+ INTEGER :: error, error_n
+
+ !
+ !Variables used in reading data back
+ !
+ INTEGER(HSIZE_T), DIMENSION(2) :: chunk_dims = (/5,2/)
+ INTEGER(HSIZE_T), DIMENSION(2) :: chunk_dimsr
+ INTEGER(HSIZE_T), DIMENSION(2) :: dimsr, maxdimsr
+ INTEGER, DIMENSION(10,3) :: data_out
+ INTEGER :: rankr, rank_chunk
+
+ !
+ !data initialization
+ !
+ do i = 1, 3
+ do j = 1, 3
+ data1(i,j) = 1
+ end do
+ end do
+
+ do j = 1, 7
+ data2(j,1) = 2
+ end do
+
+
+ !
+ !Initialize FORTRAN predifined datatypes
+ !
+ CALL h5open_f(error)
+
+ !
+ !Create a new file using default properties.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+
+
+ !
+ !Create the data space with unlimited dimensions.
+ !
+ maxdims = (/H5S_UNLIMITED_f, H5S_UNLIMITED_f/)
+
+ CALL h5screate_simple_f(RANK, dims, dataspace, error, maxdims)
+
+ !
+ !Modify dataset creation properties, i.e. enable chunking
+ !
+ CALL h5pcreate_f(H5P_DATASET_CREATE_F, cparms, error)
+
+ CALL h5pset_chunk_f(cparms, RANK, chunk_dims, error)
+
+ !
+ !Create a new dataset within the file using cparms creation properties.
+ !
+ !CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INT_F, dataspace, &
+ CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dataspace, &
+ dset_id, error, cparms)
+
+ !
+ !Extend the dataset. This call assures that dataset is 3 x 3.
+ !
+ size(1) = 3
+ size(2) = 3
+ CALL h5dextend_f(dset_id, size, error)
+
+
+ !
+ !Select a hyperslab.
+ !
+ CALL h5dget_space_f(dset_id, filespace, error)
+ offset(1) = 0;
+ offset(2) = 0;
+ CALL h5sselect_hyperslab_f(filespace, H5S_SELECT_SET_F, &
+ offset, dims1, error)
+
+ !
+ !Write the data to the hyperslab.
+ !
+ !CALL H5Dwrite_f(dset_id, H5T_NATIVE_INT_F, data1, error, &
+ CALL H5Dwrite_f(dset_id, H5T_NATIVE_INTEGER, data1, error, &
+ filespace, dataspace)
+
+ !
+ !Extend the dataset. Dataset becomes 10 x 3.
+ !
+ dims(1) = dims1(1) + dims2(1);
+ size(1) = dims(1);
+ size(2) = dims(2);
+ CALL h5dextend_f(dset_id, size, error)
+
+ !
+ !Select a hyperslab.
+ !
+ CALL h5dget_space_f(dset_id, filespace, error)
+ offset(1) = 3;
+ offset(2) = 0;
+ CALL h5sselect_hyperslab_f(filespace, H5S_SELECT_SET_F, &
+ offset, dims2, error)
+
+ !
+ !create memory dataspace.
+ !
+ CALL h5screate_simple_f(RANK, dims2, memspace, error)
+
+ !
+ !Write the data to the hyperslab.
+ !
+ !CALL H5Dwrite_f(dset_id, H5T_NATIVE_INT_F, data2, error, &
+ CALL H5Dwrite_f(dset_id, H5T_NATIVE_INTEGER, data2, error, &
+ mem_space_id=memspace, file_space_id=filespace)
+
+ !
+ !Close the dataspace for the dataset.
+ !
+ CALL h5sclose_f(dataspace, error)
+ CALL h5sclose_f(filespace, error)
+
+ !
+ !Close the memoryspace.
+ !
+ CALL h5sclose_f(memspace, error)
+
+ !
+ !Close the dataset.
+ !
+ CALL h5dclose_f(dset_id, error)
+
+ !
+ !Close the property list.
+ !
+ CALL h5pclose_f(cparms, error)
+
+ !
+ !Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ !read the data back
+ !
+ !Open the file.
+ !
+ CALL h5fopen_f (filename, H5F_ACC_RDONLY_F, file_id, error)
+
+ !
+ !Open the dataset.
+ !
+ CALL h5dopen_f(file_id, dsetname, dset_id, error)
+
+ !
+ !Get dataset's dataspace handle.
+ !
+ CALL h5dget_space_f(dset_id, dataspace, error)
+
+ !
+ !Get dataspace's rank.
+ !
+ CALL h5sget_simple_extent_ndims_f(dataspace, rankr, error)
+
+
+ !
+ !Get dataspace's dimensinons.
+ !
+ CALL h5sget_simple_extent_dims_f(dataspace, dimsr, maxdimsr, error)
+
+
+ !
+ !Get creation property list.
+ !
+ CALL h5dget_create_plist_f(dset_id, cparms, error)
+
+ !
+ !Get chunk dimensions.
+ !
+ CALL h5pget_chunk_f(cparms, 2, chunk_dimsr, error)
+
+ !
+ !create memory dataspace.
+ !
+ CALL h5screate_simple_f(rankr, dimsr, memspace, error)
+
+ !
+ !Read data
+ !
+ !CALL H5Dread_f(dset_id, H5T_NATIVE_INT_F, data_out, error, &
+ CALL H5Dread_f(dset_id, H5T_NATIVE_INTEGER, data_out, error, &
+ memspace, dataspace)
+
+ !
+ !Print data
+ !
+ do i = 1, dimsr(1)
+ print *, (data_out(i,j), j = 1,dimsr(2))
+ end do
+
+ !
+ !Close the dataspace for the dataset.
+ !
+ CALL h5sclose_f(dataspace, error)
+
+ !
+ !Close the memoryspace.
+ !
+ CALL h5sclose_f(memspace, error)
+
+ !
+ !Close the dataset.
+ !
+ CALL h5dclose_f(dset_id, error)
+
+ !
+ !Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ !Close the property list.
+ !
+ CALL h5pclose_f(cparms, error)
+
+ !
+ ! Close FORTRAN predefined datatypes.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM CHUNKEXAMPLE
diff --git a/doc/html/Tutor/examples/compound.f90 b/doc/html/Tutor/examples/compound.f90
new file mode 100644
index 0000000..a2bd6b0
--- /dev/null
+++ b/doc/html/Tutor/examples/compound.f90
@@ -0,0 +1,215 @@
+!
+! This program creates a dataset that is one dimensional array of
+! structures {
+! character*2
+! integer
+! double precision
+! real
+! }
+! Data is written and read back by fields.
+!
+
+ PROGRAM COMPOUNDEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=11), PARAMETER :: filename = "compound.h5" ! File name
+ CHARACTER(LEN=8), PARAMETER :: dsetname = "Compound" ! Dataset name
+ INTEGER, PARAMETER :: dimsize = 6 ! Size of the dataset
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: dset_id ! Dataset identifier
+ INTEGER(HID_T) :: dspace_id ! Dataspace identifier
+ INTEGER(HID_T) :: dtype_id ! Compound datatype identifier
+ INTEGER(HID_T) :: dt1_id ! Memory datatype identifier (for character field)
+ INTEGER(HID_T) :: dt2_id ! Memory datatype identifier (for integer field)
+ INTEGER(HID_T) :: dt3_id ! Memory datatype identifier (for double precision field)
+ INTEGER(HID_T) :: dt4_id ! Memory datatype identifier (for real field)
+ INTEGER(HID_T) :: dt5_id ! Memory datatype identifier
+ INTEGER(HID_T) :: plist_id ! Dataset trasfer property
+ INTEGER(SIZE_T) :: typesize
+
+
+ INTEGER(HSIZE_T), DIMENSION(1) :: dims = (/dimsize/) ! Dataset dimensions
+ INTEGER :: rank = 1 ! Dataset rank
+
+ INTEGER :: error ! Error flag
+ INTEGER(SIZE_T) :: type_size ! Size of the datatype
+ INTEGER(SIZE_T) :: type_sizec ! Size of the character datatype
+ INTEGER(SIZE_T) :: type_sizei ! Size of the integer datatype
+ INTEGER(SIZE_T) :: type_sized ! Size of the double precision datatype
+ INTEGER(SIZE_T) :: type_sizer ! Size of the real datatype
+ INTEGER(SIZE_T) :: offset ! Member's offset
+ CHARACTER*2, DIMENSION(dimsize) :: char_member
+ CHARACTER*2, DIMENSION(dimsize) :: char_member_out ! Buffer to read data out
+ INTEGER, DIMENSION(dimsize) :: int_member
+ DOUBLE PRECISION, DIMENSION(dimsize) :: double_member
+ REAL, DIMENSION(dimsize) :: real_member
+ INTEGER :: i
+ !
+ ! Initialize data buffer.
+ !
+ do i = 1, dimsize
+ char_member(i)(1:1) = char(65+i)
+ char_member(i)(2:2) = char(65+i)
+ char_member_out(i)(1:1) = char(65)
+ char_member_out(i)(2:2) = char(65)
+ int_member(i) = i
+ double_member(i) = 2.* i
+ real_member(i) = 3. * i
+ enddo
+
+ !
+ ! Initialize FORTRAN interface.
+ !
+ CALL h5open_f(error)
+ !
+ ! Set dataset transfer property to preserve partially initialized fields
+ ! during write/read to/from dataset with compound datatype.
+ !
+ CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, error)
+ CALL h5pset_preserve_f(plist_id, 1, error)
+
+ !
+ ! Create a new file using default properties.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+
+ !
+ ! Create the dataspace.
+ !
+ CALL h5screate_simple_f(rank, dims, dspace_id, error)
+ !
+ ! Create compound datatype.
+ !
+ ! First calculate total size by calculating sizes of each member
+ !
+ CALL h5tcopy_f(H5T_NATIVE_CHARACTER, dt5_id, error)
+ typesize = 2
+ CALL h5tset_size_f(dt5_id, typesize, error)
+ CALL h5tget_size_f(dt5_id, type_sizec, error)
+ CALL h5tget_size_f(H5T_NATIVE_INTEGER, type_sizei, error)
+ CALL h5tget_size_f(H5T_NATIVE_DOUBLE, type_sized, error)
+ CALL h5tget_size_f(H5T_NATIVE_REAL, type_sizer, error)
+ type_size = type_sizec + type_sizei + type_sized + type_sizer
+ CALL h5tcreate_f(H5T_COMPOUND_F, type_size, dtype_id, error)
+ !
+ ! Insert memebers
+ !
+ ! CHARACTER*2 memeber
+ !
+ offset = 0
+ CALL h5tinsert_f(dtype_id, "char_field", offset, dt5_id, error)
+ !
+ ! INTEGER member
+ !
+ offset = offset + type_sizec ! Offset of the second memeber is 2
+ CALL h5tinsert_f(dtype_id, "integer_field", offset, H5T_NATIVE_INTEGER, error)
+ !
+ ! DOUBLE PRECISION member
+ !
+ offset = offset + type_sizei ! Offset of the third memeber is 6
+ CALL h5tinsert_f(dtype_id, "double_field", offset, H5T_NATIVE_DOUBLE, error)
+ !
+ ! REAL member
+ !
+ offset = offset + type_sized ! Offset of the last member is 14
+ CALL h5tinsert_f(dtype_id, "real_field", offset, H5T_NATIVE_REAL, error)
+
+ !
+ ! Create the dataset with compound datatype.
+ !
+ CALL h5dcreate_f(file_id, dsetname, dtype_id, dspace_id, &
+ dset_id, error)
+ !
+ ! Create memory types. We have to create a compound datatype
+ ! for each member we want to write.
+ !
+ CALL h5tcreate_f(H5T_COMPOUND_F, type_sizec, dt1_id, error)
+ offset = 0
+ CALL h5tinsert_f(dt1_id, "char_field", offset, dt5_id, error)
+ !
+ CALL h5tcreate_f(H5T_COMPOUND_F, type_sizei, dt2_id, error)
+ offset = 0
+ CALL h5tinsert_f(dt2_id, "integer_field", offset, H5T_NATIVE_INTEGER, error)
+ !
+ CALL h5tcreate_f(H5T_COMPOUND_F, type_sized, dt3_id, error)
+ offset = 0
+ CALL h5tinsert_f(dt3_id, "double_field", offset, H5T_NATIVE_DOUBLE, error)
+ !
+ CALL h5tcreate_f(H5T_COMPOUND_F, type_sizer, dt4_id, error)
+ offset = 0
+ CALL h5tinsert_f(dt4_id, "real_field", offset, H5T_NATIVE_REAL, error)
+ !
+ ! Write data by fields in the datatype. Fields order is not important.
+ !
+ CALL h5dwrite_f(dset_id, dt4_id, real_member, error, xfer_prp = plist_id)
+ CALL h5dwrite_f(dset_id, dt1_id, char_member, error, xfer_prp = plist_id)
+ CALL h5dwrite_f(dset_id, dt3_id, double_member, error, xfer_prp = plist_id)
+ CALL h5dwrite_f(dset_id, dt2_id, int_member, error, xfer_prp = plist_id)
+
+ !
+ ! End access to the dataset and release resources used by it.
+ !
+ CALL h5dclose_f(dset_id, error)
+
+ !
+ ! Terminate access to the data space.
+ !
+ CALL h5sclose_f(dspace_id, error)
+ !
+ ! Terminate access to the datatype
+ !
+ CALL h5tclose_f(dtype_id, error)
+ CALL h5tclose_f(dt1_id, error)
+ CALL h5tclose_f(dt2_id, error)
+ CALL h5tclose_f(dt3_id, error)
+ CALL h5tclose_f(dt4_id, error)
+ CALL h5tclose_f(dt5_id, error)
+
+ !
+ ! Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! Open the file.
+ !
+ CALL h5fopen_f (filename, H5F_ACC_RDWR_F, file_id, error)
+ !
+ ! Open the dataset.
+ !
+ CALL h5dopen_f(file_id, dsetname, dset_id, error)
+ !
+ ! Create memeory datatyoe to read character member of the compound datatype.
+ !
+ CALL h5tcopy_f(H5T_NATIVE_CHARACTER, dt2_id, error)
+ typesize = 2
+ CALL h5tset_size_f(dt2_id, typesize, error)
+ CALL h5tget_size_f(dt2_id, type_size, error)
+ CALL h5tcreate_f(H5T_COMPOUND_F, type_size, dt1_id, error)
+ offset = 0
+ CALL h5tinsert_f(dt1_id, "char_field", offset, dt2_id, error)
+ !
+ ! Read part of the datatset and display it.
+ !
+ CALL h5dread_f(dset_id, dt1_id, char_member_out, error)
+ write(*,*) (char_member_out(i), i=1, dimsize)
+
+ !
+ ! Close all open objects.
+ !
+ CALL h5dclose_f(dset_id, error)
+ CALL h5tclose_f(dt1_id, error)
+ CALL h5tclose_f(dt2_id, error)
+ CALL h5fclose_f(file_id, error)
+ !
+ ! Close FORTRAN interface.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM COMPOUNDEXAMPLE
+
+
diff --git a/doc/html/Tutor/examples/dsetexample.f90 b/doc/html/Tutor/examples/dsetexample.f90
new file mode 100644
index 0000000..9b69a3f
--- /dev/null
+++ b/doc/html/Tutor/examples/dsetexample.f90
@@ -0,0 +1,70 @@
+!
+! The following example shows how to create an empty dataset.
+! It creates a file called 'dsetf.h5', defines the
+! dataset dataspace, creates a dataset which is a 4x6 integer array,
+! and then closes the dataspace, the dataset, and the file.
+!
+
+ PROGRAM DSETEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=8), PARAMETER :: filename = "dsetf.h5" ! File name
+ CHARACTER(LEN=4), PARAMETER :: dsetname = "dset" ! Dataset name
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: dset_id ! Dataset identifier
+ INTEGER(HID_T) :: dspace_id ! Dataspace identifier
+
+
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/4,6/) ! Dataset dimensions
+ INTEGER :: rank = 2 ! Dataset rank
+
+ INTEGER :: error ! Error flag
+
+ !
+ ! Initialize FORTRAN predefined datatypes.
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Create a new file using default properties.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+
+ !
+ ! Create the dataspace.
+ !
+ CALL h5screate_simple_f(rank, dims, dspace_id, error)
+
+ !
+ ! Create the dataset with default properties.
+ !
+ CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dspace_id, &
+ dset_id, error)
+
+ !
+ ! End access to the dataset and release resources used by it.
+ !
+ CALL h5dclose_f(dset_id, error)
+
+ !
+ ! Terminate access to the data space.
+ !
+ CALL h5sclose_f(dspace_id, error)
+
+ !
+ ! Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! Close FORTRAN predefined datatypes.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM DSETEXAMPLE
+
+
diff --git a/doc/html/Tutor/examples/fileexample.f90 b/doc/html/Tutor/examples/fileexample.f90
new file mode 100644
index 0000000..e11dcaa
--- /dev/null
+++ b/doc/html/Tutor/examples/fileexample.f90
@@ -0,0 +1,34 @@
+!
+! The following example demonstrates how to create and close an HDF5 file.
+! It creates a file called 'file.h5', and then closes the file.
+!
+
+ PROGRAM FILEEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=8), PARAMETER :: filename = "filef.h5" ! File name
+ INTEGER(HID_T) :: file_id ! File identifier
+
+ INTEGER :: error ! Error flag
+
+!
+! Initialize FORTRAN interface.
+!
+ CALL h5open_f (error)
+ !
+ ! Create a new file using default properties.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+
+ !
+ ! Terminate access to the file.
+ !
+ CALL h5fclose_f(file_id, error)
+!
+! Close FORTRAN interface.
+!
+ CALL h5close_f(error)
+ END PROGRAM FILEEXAMPLE
diff --git a/doc/html/Tutor/examples/groupexample.f90 b/doc/html/Tutor/examples/groupexample.f90
new file mode 100644
index 0000000..d98d7cd
--- /dev/null
+++ b/doc/html/Tutor/examples/groupexample.f90
@@ -0,0 +1,49 @@
+!
+! The following example shows how to create and close a group.
+! It creates a file called 'group.h5', creates a group
+! called MyGroup in the root group, and then closes the group and file.
+!
+
+
+ PROGRAM GROUPEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=9), PARAMETER :: filename = "groupf.h5" ! File name
+ CHARACTER(LEN=7), PARAMETER :: groupname = "MyGroup" ! Group name
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: group_id ! Group identifier
+
+ INTEGER :: error ! Error flag
+!
+! Initialize FORTRAN interface.
+!
+ CALL h5open_f(error)
+ !
+ ! Create a new file using default properties.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+
+ !
+ ! Create a group named "/MyGroup" in the file.
+ !
+ CALL h5gcreate_f(file_id, groupname, group_id, error)
+
+ !
+ ! Close the group.
+ !
+ CALL h5gclose_f(group_id, error)
+
+ !
+ ! Terminate access to the file.
+ !
+ CALL h5fclose_f(file_id, error)
+!
+! Close FORTRAN interface.
+!
+ CALL h5close_f(error)
+
+ END PROGRAM GROUPEXAMPLE
diff --git a/doc/html/Tutor/examples/grpdsetexample.f90 b/doc/html/Tutor/examples/grpdsetexample.f90
new file mode 100644
index 0000000..ceb2fe9
--- /dev/null
+++ b/doc/html/Tutor/examples/grpdsetexample.f90
@@ -0,0 +1,136 @@
+!
+! This example shows how to create a dataset in a particular group.
+! It opens the file created in the previous example and creates two datasets.
+! Absolute and relative dataset names are used.
+!
+
+
+ PROGRAM GRPDSETEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=10), PARAMETER :: filename = "groupsf.h5" ! File name
+ CHARACTER(LEN=15), PARAMETER :: groupname = "MyGroup/Group_A" ! Group name
+ CHARACTER(LEN=13), PARAMETER :: dsetname1 = "MyGroup/dset1" ! Dataset name
+ CHARACTER(LEN=5), PARAMETER :: dsetname2 = "dset2" ! dataset name
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: group_id ! Group identifier
+ INTEGER(HID_T) :: dataset_id ! Dataset identifier
+ INTEGER(HID_T) :: dataspace_id ! Data space identifier
+
+ INTEGER :: i, j
+ INTEGER :: error ! Error flag
+
+ INTEGER, DIMENSION(3,3) :: dset1_data ! Data arrays
+ INTEGER, DIMENSION(2,10) :: dset2_data !
+
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims1 = (/3,3/) ! Datasets dimensions
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims2 = (/2,10/)!
+
+ INTEGER :: rank = 2 ! Datasets rank
+
+ !
+ !Initialize dset1_data array
+ !
+ do i = 1, 3
+ do j = 1, 3
+ dset1_data(i,j) = j;
+ end do
+ end do
+
+
+ !
+ !Initialize dset2_data array
+ !
+ do i = 1, 2
+ do j = 1, 10
+ dset2_data(i,j) = j;
+ end do
+ end do
+
+ !
+ ! Initialize FORTRAN predefined datatypes.
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Open an existing file.
+ !
+ CALL h5fopen_f (filename, H5F_ACC_RDWR_F, file_id, error)
+
+ !
+ ! Create the data space for the first dataset.
+ !
+ CALL h5screate_simple_f(rank, dims1, dataspace_id, error)
+
+ !
+ ! Create a dataset in group "MyGroup" with default properties.
+ !
+ CALL h5dcreate_f(file_id, dsetname1, H5T_NATIVE_INTEGER, dataspace_id, &
+ dataset_id, error)
+
+ !
+ ! Write the first dataset.
+ !
+ CALL h5dwrite_f(dataset_id, H5T_NATIVE_INTEGER, dset1_data, error)
+
+ !
+ ! Close the dataspace for the first dataset.
+ !
+ CALL h5sclose_f(dataspace_id, error)
+
+ !
+ ! Close the first dataset.
+ !
+ CALL h5dclose_f(dataset_id, error)
+
+ !
+ ! Open an existing group in the specified file.
+ !
+ CALL h5gopen_f(file_id, groupname, group_id, error)
+
+ !
+ !Create the data space for the second dataset.
+ !
+ CALL h5screate_simple_f(rank, dims2, dataspace_id, error)
+
+ !
+ ! Create the second dataset in group "Group_A" with default properties.
+ !
+ CALL h5dcreate_f(group_id, dsetname2, H5T_NATIVE_INTEGER, dataspace_id, &
+ dataset_id, error)
+
+ !
+ ! Write the second dataset.
+ !
+ CALL h5dwrite_f(dataset_id, H5T_NATIVE_INTEGER, dset2_data, error)
+
+ !
+ ! Close the dataspace for the second dataset.
+ !
+ CALL h5sclose_f(dataspace_id, error)
+
+ !
+ ! Close the second dataset.
+ !
+ CALL h5dclose_f(dataset_id, error)
+
+ !
+ ! Close the group.
+ !
+ CALL h5gclose_f(group_id, error)
+
+ !
+ ! Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! Close FORTRAN predefined datatypes.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM GRPDSETEXAMPLE
diff --git a/doc/html/Tutor/examples/grpit.f90 b/doc/html/Tutor/examples/grpit.f90
new file mode 100644
index 0000000..3aff2ad
--- /dev/null
+++ b/doc/html/Tutor/examples/grpit.f90
@@ -0,0 +1,194 @@
+!
+! In this example we iterate through the members of the groups.
+!
+
+
+ PROGRAM GRPITEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=11), PARAMETER :: filename = "iteratef.h5" ! File name
+ CHARACTER(LEN=7), PARAMETER :: groupname1 = "MyGroup" ! Group name
+ CHARACTER(LEN=15), PARAMETER :: groupname2 = "Group_A" ! Group name
+ CHARACTER(LEN=13), PARAMETER :: dsetname1 = "dset1" ! Dataset name
+ CHARACTER(LEN=5), PARAMETER :: dsetname2 = "dset2" !
+
+ CHARACTER(LEN=20) :: name_buffer ! Buffer to hold object's name
+ INTEGER :: type ! Type of the object
+ INTEGER :: nmembers ! Number of group members
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: dataset1_id ! Dataset1 identifier
+ INTEGER(HID_T) :: dataset2_id ! Dataset2 identifier
+ INTEGER(HID_T) :: dataspace1_id ! Data space identifier
+ INTEGER(HID_T) :: dataspace2_id ! Data space identifier
+ INTEGER(HID_T) :: group1_id, group2_id ! Group identifiers
+
+ INTEGER :: i, j
+
+ INTEGER :: error ! Error flag
+
+ INTEGER, DIMENSION(3,3) :: dset1_data ! Arrays to hold data
+ INTEGER, DIMENSION(2,10) :: dset2_data !
+
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims1 = (/3,3/) ! Dataset dimensions
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims2 = (/2,10/)!
+ INTEGER :: rank = 2 ! Datasets rank
+
+ !
+ ! Initialize dset1_data array.
+ !
+ do i = 1, 3
+ do j = 1, 3
+ dset1_data(i,j) = j;
+ end do
+ end do
+
+
+ !
+ ! Initialize dset2_data array.
+ !
+ do i = 1, 2
+ do j = 1, 10
+ dset2_data(i,j) = j;
+ end do
+ end do
+
+ !
+ ! Initialize FORTRAN interface.
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Create a new file using default properties.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+
+ !
+ ! Create group "MyGroup" in the root group using absolute name.
+ !
+ CALL h5gcreate_f(file_id, groupname1, group1_id, error)
+
+ !
+ ! Create group "Group_A" in group "MyGroup" using relative name.
+ !
+ CALL h5gcreate_f(group1_id, groupname2, group2_id, error)
+
+ !
+ ! Create the data space for the first dataset.
+ !
+ CALL h5screate_simple_f(rank, dims1, dataspace1_id, error)
+
+ !
+ ! Create a dataset in group "MyGroup" with default properties.
+ !
+ CALL h5dcreate_f(group1_id, dsetname1, H5T_NATIVE_INTEGER, dataspace1_id, &
+ dataset1_id, error)
+
+ !
+ ! Write the first dataset.
+ !
+ CALL h5dwrite_f(dataset1_id, H5T_NATIVE_INTEGER, dset1_data, error)
+
+ !
+ ! Create the data space for the second dataset.
+ !
+ CALL h5screate_simple_f(rank, dims2, dataspace2_id, error)
+
+ !
+ ! Create the second dataset in group "Group_A" with default properties
+ !
+ CALL h5dcreate_f(group2_id, dsetname2, H5T_NATIVE_INTEGER, dataspace2_id, &
+ dataset2_id, error)
+
+ !
+ ! Write the second dataset
+ !
+ CALL h5dwrite_f(dataset2_id, H5T_NATIVE_INTEGER, dset2_data, error)
+
+ !
+ ! Get number of members in the root group.
+ !
+ CALL h5gn_members_f(file_id, "/", nmembers, error)
+ write(*,*) "Number of root group member is " , nmembers
+
+ !
+ ! Print each group member's name and type.
+ !
+ do i = 0, nmembers - 1
+ CALL h5gget_obj_info_idx_f(file_id, "/", i, name_buffer, type, &
+ error)
+ write(*,*) name_buffer, type
+ end do
+
+ !
+ ! Get number of members in MyGroup.
+ !
+ CALL h5gn_members_f(file_id, "MyGroup", nmembers, error)
+ write(*,*) "Number of group MyGroup member is ", nmembers
+
+ !
+ ! Print each group member's name and type in "MyGroup" group.
+ !
+ do i = 0, nmembers - 1
+ CALL h5gget_obj_info_idx_f(file_id, groupname1, i, name_buffer, type, &
+ error)
+ write(*,*) name_buffer, type
+ end do
+
+
+ !
+ ! Get number of members in MyGroup/Group_A.
+ !
+ CALL h5gn_members_f(file_id, "MyGroup/Group_A", nmembers, error)
+ write(*,*) "Number of group MyGroup/Group_A member is ", nmembers
+
+ !
+ ! Print each group member's name and type in "MyGroup/Group_A" group.
+ !
+ do i = 0, nmembers - 1
+ CALL h5gget_obj_info_idx_f(file_id,"MyGroup/Group_A" , i, name_buffer, type, &
+ error)
+ write(*,*) name_buffer, type
+ end do
+
+ !
+ ! Close the dataspace for the first dataset.
+ !
+ CALL h5sclose_f(dataspace1_id, error)
+
+ !
+ ! Close the first dataset.
+ !
+ CALL h5dclose_f(dataset1_id, error)
+
+ !
+ ! Close the dataspace for the second dataset.
+ !
+ CALL h5sclose_f(dataspace2_id, error)
+
+ !
+ ! Close the second dataset.
+ !
+ CALL h5dclose_f(dataset2_id, error)
+
+ !
+ ! Close the groups.
+ !
+ CALL h5gclose_f(group1_id, error)
+
+ CALL h5gclose_f(group2_id, error)
+
+ !
+ ! Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! Close FORTRAN interface.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM GRPITEXAMPLE
diff --git a/doc/html/Tutor/examples/grpsexample.f90 b/doc/html/Tutor/examples/grpsexample.f90
new file mode 100644
index 0000000..4b53bf0
--- /dev/null
+++ b/doc/html/Tutor/examples/grpsexample.f90
@@ -0,0 +1,68 @@
+!
+! The following example code shows how to create groups
+! using absolute and relative names. It creates three groups:
+! the first two groups are created using the file identifier and
+! the group absolute names, and the third group is created using
+! a group identifier and the name relative to the specified group.
+!
+
+
+ PROGRAM GRPSEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=10), PARAMETER :: filename = "groupsf.h5" ! File name
+ CHARACTER(LEN=8), PARAMETER :: groupname1 = "/MyGroup" ! Group name
+ CHARACTER(LEN=16), PARAMETER :: groupname2 = "/MyGroup/Group_A"
+ ! Group name
+ CHARACTER(LEN=7), PARAMETER :: groupname3 = "Group_B" ! Group name
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: group1_id, group2_id, group3_id ! Group identifiers
+
+ INTEGER :: error ! Error flag
+ !
+ ! Initialize FORTRAN interface.
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Create a new file using default properties.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+
+ !
+ ! Create group "MyGroup" in the root group using absolute name.
+ !
+ CALL h5gcreate_f(file_id, groupname1, group1_id, error)
+
+ !
+ ! Create group "Group_A" in group "MyGroup" using absolute name.
+ !
+ CALL h5gcreate_f(file_id, groupname2, group2_id, error)
+
+ !
+ ! Create group "Group_B" in group "MyGroup" using relative name.
+ !
+ CALL h5gcreate_f(group1_id, groupname3, group3_id, error)
+
+ !
+ ! Close the groups.
+ !
+ CALL h5gclose_f(group1_id, error)
+ CALL h5gclose_f(group2_id, error)
+ CALL h5gclose_f(group3_id, error)
+
+ !
+ ! Terminate access to the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! Close FORTRAN interface.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM GRPSEXAMPLE
diff --git a/doc/html/Tutor/examples/hyperslab.f90 b/doc/html/Tutor/examples/hyperslab.f90
new file mode 100644
index 0000000..e49f18b
--- /dev/null
+++ b/doc/html/Tutor/examples/hyperslab.f90
@@ -0,0 +1,199 @@
+!
+! This example shows how to write and read a hyperslab.
+!
+
+ PROGRAM SELECTEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=7), PARAMETER :: filename = "sdsf.h5" ! File name
+ CHARACTER(LEN=8), PARAMETER :: dsetname = "IntArray" ! Dataset name
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: dset_id ! Dataset identifier
+ INTEGER(HID_T) :: dataspace ! Dataspace identifier
+ INTEGER(HID_T) :: memspace ! memspace identifier
+
+ INTEGER(HSIZE_T), DIMENSION(3) :: dimsm = (/7,7,3/) ! Dataset dimensions
+ ! in memory
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims_out ! Buffer to read in dataset
+ ! dimesions
+ INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/5,6/) ! Dataset dimensions.
+
+ INTEGER(HSIZE_T), DIMENSION(2) :: count = (/3,4/)
+ ! Size of the hyperslab in the file
+ INTEGER(HSIZE_T), DIMENSION(2) :: offset = (/1,2/)
+ !hyperslab offset in the file
+ INTEGER(HSIZE_T), DIMENSION(3) :: count_out = (/3,4,1/)
+ !Size of the hyperslab in memory
+ INTEGER(HSIZE_T), DIMENSION(3) :: offset_out = (/3,0,0/)
+ !hyperslab offset in memory
+ INTEGER, DIMENSION(5,6) :: data ! Data to write
+ INTEGER, DIMENSION(7,7,3) :: data_out ! Output buffer
+ INTEGER :: dsetrank = 2 ! Dataset rank ( in file )
+ INTEGER :: memrank = 3 ! Dataset rank ( in memory )
+ INTEGER :: rank
+ INTEGER :: i, j, k
+
+ INTEGER :: error, error_n ! Error flags
+
+
+ !
+ ! Write data to the HDF5 file.
+ !
+
+ !
+ ! Data initialization.
+ !
+ do i = 1, 5
+ do j = 1, 6
+ data(i,j) = (i-1) + (j-1);
+ end do
+ end do
+ !
+ ! 0, 1, 2, 3, 4, 5
+ ! 1, 2, 3, 4, 5, 6
+ ! 2, 3, 4, 5, 6, 7
+ ! 3, 4, 5, 6, 7, 8
+ ! 4, 5, 6, 7, 8, 9
+ !
+
+ !
+ ! Initialize FORTRAN predefined datatypes
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Create a new file using default properties.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+
+ !
+ ! Create the data space for the dataset.
+ !
+ CALL h5screate_simple_f(dsetrank, dimsf, dataspace, error)
+
+ !
+ ! Create the dataset with default properties.
+ !
+ CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dataspace, &
+ dset_id, error)
+
+ !
+ ! Write the dataset.
+ !
+ CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, error)
+
+ !
+ ! Close the dataspace for the dataset.
+ !
+ CALL h5sclose_f(dataspace, error)
+
+ !
+ ! Close the dataset.
+ !
+ CALL h5dclose_f(dset_id, error)
+
+ !
+ ! Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! This part of the code reads the hyperslab from the sds.h5 file just
+ ! created, into a 2-dimensional plane of the 3-dimensional dataset.
+ !
+
+ !
+ ! Initialize data_out array.
+ !
+ do i = 1, 7
+ do j = 1, 7
+ do k = 1,3
+ data_out(i,j,k) = 0;
+ end do
+ end do
+ end do
+
+ !
+ ! Open the file.
+ !
+ CALL h5fopen_f (filename, H5F_ACC_RDONLY_F, file_id, error)
+
+ !
+ ! Open the dataset.
+ !
+ CALL h5dopen_f(file_id, dsetname, dset_id, error)
+
+ !
+ ! Get dataset's dataspace identifier.
+ !
+ CALL h5dget_space_f(dset_id, dataspace, error)
+
+ !
+ ! Select hyperslab in the dataset.
+ !
+ CALL h5sselect_hyperslab_f(dataspace, H5S_SELECT_SET_F, &
+ offset, count, error)
+ !
+ ! Create memory dataspace.
+ !
+ CALL h5screate_simple_f(memrank, dimsm, memspace, error)
+
+ !
+ ! Select hyperslab in memory.
+ !
+ CALL h5sselect_hyperslab_f(memspace, H5S_SELECT_SET_F, &
+ offset_out, count_out, error)
+
+ !
+ ! Read data from hyperslab in the file into the hyperslab in
+ ! memory and display.
+ !
+ CALL H5Dread_f(dset_id, H5T_NATIVE_INTEGER, data_out, error, &
+ memspace, dataspace)
+
+ !
+ ! Display data_out array
+ !
+ do i = 1, 7
+ print *, (data_out(i,j,1), j = 1,7)
+ end do
+
+ ! 0 0 0 0 0 0 0
+ ! 0 0 0 0 0 0 0
+ ! 0 0 0 0 0 0 0
+ ! 3 4 5 6 0 0 0
+ ! 4 5 6 7 0 0 0
+ ! 5 6 7 8 0 0 0
+ ! 0 0 0 0 0 0 0
+ !
+
+ !
+ ! Close the dataspace for the dataset.
+ !
+ CALL h5sclose_f(dataspace, error)
+
+ !
+ ! Close the memoryspace.
+ !
+ CALL h5sclose_f(memspace, error)
+
+ !
+ ! Close the dataset.
+ !
+ CALL h5dclose_f(dset_id, error)
+
+ !
+ ! Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! Close FORTRAN predefined datatypes.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM SELECTEXAMPLE
diff --git a/doc/html/Tutor/examples/java/Compound.java b/doc/html/Tutor/examples/java/Compound.java
new file mode 100644
index 0000000..219e1c1
--- /dev/null
+++ b/doc/html/Tutor/examples/java/Compound.java
@@ -0,0 +1,540 @@
+/******************************************************************
+ * Compound.java (for HDF5 tutorial lesson 11)
+ *
+ * -- Creating a compound data type
+ * (a java conversion from compound.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class Compound
+{
+ public static void main (String []argv)
+ {
+ final String FILE = "SDScompound.h5";
+ final String DATASETNAME = "ArrayOfStructures";
+ final int LENGTH = 10;
+ final int RANK = 1;
+
+ /* First structure and dataset */
+ /* an array of LENGTH 'complex' numbers */
+ byte[] data1 = new byte[LENGTH * 16];
+
+ int[] AR = new int[1];
+ float[] BR = new float[1];
+ double[] CR = new double[1];
+
+ byte [] ARec = new byte[4];
+ byte [] BRec = new byte[4];
+ byte [] CRec = new byte[8];
+
+ int s1_tid; /* File datatype identifier */
+
+ /* Second structure (subset of s1_t) and dataset*/
+ byte[] data2 = new byte[LENGTH * 12];
+ int s2_tid; /* Memory datatype handle */
+
+ /* Third "structure" ( will be used to read float field of s1) */
+ int s3_tid; /* Memory datatype handle */
+ float[] s3 = new float[LENGTH];
+
+ int i;
+ int file, dataset, space; /* Handles */
+ int status;
+ long[] dim = new long[1]; /* Dataspace dimensions */
+ dim[0] = LENGTH;
+
+ /*
+ * Initialize the data
+ */
+ for (i = 0; i < LENGTH; i++)
+ {
+ AR[0] = (int) i;
+ BR[0] = (float) i * i;
+ CR[0] = (double) 1. / (i + 1);
+
+ ARec = HDFNativeData.intToByte (0, 1, AR);
+ BRec = HDFNativeData.floatToByte (0, 1, BR);
+ CRec = HDFNativeData.doubleToByte (0, 1, CR);
+
+ System.arraycopy (ARec, 0, data1, (i * 16), 4);
+ System.arraycopy (BRec, 0, data1, (i * 16) + 4, 4);
+ System.arraycopy (CRec, 0, data1, (i * 16) + 8, 8);
+ }
+
+ /*
+ * Create the data space.
+ */
+ space = H5Screate_simple_wrap (RANK, dim, null);
+
+ /*
+ * Create the file.
+ */
+ file = H5Fcreate_wrap (FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ /*
+ * Create the memory data type.
+ */
+ s1_tid = H5Tcreate_wrap (HDF5Constants.H5T_COMPOUND, 16);
+ H5Tinsert_wrap (s1_tid, "a_name", 0,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT));
+ H5Tinsert_wrap (s1_tid, "b_name", 4,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_FLOAT));
+ H5Tinsert_wrap (s1_tid, "c_name", 8,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_DOUBLE));
+
+ /*
+ * Create the dataset.
+ */
+ dataset = H5Dcreate_wrap (file, DATASETNAME, s1_tid,
+ space, HDF5Constants.H5P_DEFAULT);
+
+ /*
+ * Wtite data to the dataset;
+ */
+ status = H5Dwrite_wrap (dataset, s1_tid,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, data1);
+
+ /*
+ * Release resources
+ */
+ H5Tclose_wrap (s1_tid);
+ H5Sclose_wrap (space);
+ H5Dclose_wrap (dataset);
+ H5Fclose_wrap (file);
+
+ /*
+ * Open the file and the dataset.
+ */
+ file = H5Fopen_wrap (FILE, HDF5Constants.H5F_ACC_RDONLY,
+ HDF5Constants.H5P_DEFAULT);
+
+ dataset = H5Dopen_wrap (file, DATASETNAME);
+
+ /*
+ * Create a data type for s2
+ */
+ s2_tid = H5Tcreate_wrap (HDF5Constants.H5T_COMPOUND, 12);
+ H5Tinsert_wrap (s2_tid, "c_name", 0,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_DOUBLE));
+ H5Tinsert_wrap (s2_tid, "a_name", 8,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT));
+
+ /*
+ * Read two fields c and a from s1 dataset. Fields in the file
+ * are found by their names "c_name" and "a_name".
+ */
+ status = H5Dread_wrap (dataset, s2_tid, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, data2);
+
+ /*
+ * Display the fields. Convert from bytes into numbers.
+ */
+ System.out.println ("\nField c : ");
+ for( i = 0; i < LENGTH; i++) {
+ System.arraycopy (data2, (i*12), CRec, 0, 8);
+ CR = HDFNativeData.byteToDouble(0, 1, CRec);
+ System.out.print (CR[0]+" ");
+ }
+ System.out.println ();
+
+ System.out.println("\nField a :");
+ for( i = 0; i < LENGTH; i++) {
+ System.arraycopy (data2, (i*12)+8, ARec, 0, 4);
+ AR = HDFNativeData.byteToInt(0, 1, ARec);
+ System.out.print (AR[0]+" ");
+ }
+ System.out.println ();
+
+ /*
+ * Create a data type for s3.
+ */
+ s3_tid = H5Tcreate_wrap (HDF5Constants.H5T_COMPOUND, 4);
+
+ status =
+ H5Tinsert_wrap (s3_tid, "b_name", 0,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_FLOAT));
+
+ /*
+ * Read field b from s1 dataset. Field in the file is found by its name.
+ */
+ status = H5Dread_wrap (dataset, s3_tid, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, s3);
+
+ /*
+ * Display the field. Data is read directly into array of 'float'.
+ */
+ System.out.println ();
+ System.out.println ("Field b :");
+ for( i = 0; i < LENGTH; i++) {
+ System.out.print (s3[i]+" ");
+ }
+ System.out.println ();
+
+ /*
+ * Release resources
+ */
+ H5Tclose_wrap (s2_tid);
+ H5Tclose_wrap (s3_tid);
+ H5Dclose_wrap (dataset);
+ H5Fclose_wrap (file);
+ }
+
+
+ // Help function for creating a new file
+ public static int H5Fcreate_wrap (String name, int flags,
+ int create_id, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fcreate (name, flags, create_id, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Fcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Fcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for adding another member to the compound
+ // datatype datatype_id.
+ public static int H5Tinsert_wrap (int type_id, String name,
+ long offset, int field_id)
+ {
+ int status = -1;
+ try
+ {
+ // Adding another member to the compound datatype datatype_id.
+ status = H5.H5Tinsert (type_id, name, offset, field_id);
+
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Tinsert_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Tinsert_wrap() with HDF5Exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for creating the memory data type.
+ public static int H5Tcreate_wrap (int dclass, int size)
+ {
+ int datatype_id = -1; // memory data type identifier
+ try
+ {
+ // Create the memory data type.
+ datatype_id = H5.H5Tcreate (dclass, size);
+
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Tcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Tcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return datatype_id;
+ }
+
+
+ // Help function for opening an existing file
+ public static int H5Fopen_wrap (String name, int flags, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fopen (name, flags, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Fopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Fopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for opening an existing dataset
+ public static int H5Dopen_wrap (int loc_id, String name)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Opening an existing dataset
+ dataset_id = H5.H5Dopen (loc_id, name);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Dopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Dopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for creating a new simple dataspace and opening it
+ // for access
+ public static int H5Screate_simple_wrap (int rank, long dims[],
+ long maxdims[])
+ {
+ int dataspace_id = -1; // dataspace identifier
+
+ try
+ {
+ // Create the data space for the dataset.
+ dataspace_id = H5.H5Screate_simple (rank, dims, maxdims);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Screate_simple_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Screate_simple_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for creating a dataset
+ public static int H5Dcreate_wrap (int loc_id, String name, int type_id,
+ int space_id, int create_plist_id)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Create the dataset
+ dataset_id = H5.H5Dcreate (loc_id, name, type_id, space_id,
+ create_plist_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Dcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Dcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for writing the dataset
+ public static int H5Dwrite_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object buf)
+ {
+ int status = -1;
+
+ try
+ {
+ // Write the dataset.
+ status = H5.H5Dwrite (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, buf);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Dwrite_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Dwrite_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for reading the dataset
+ public static int H5Dread_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object obj)
+ {
+ int status = -1;
+
+ try
+ {
+ // Read the dataset.
+ status = H5.H5Dread (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, obj);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Dread_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Dread_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+
+ // Help function for terminating access to the data space.
+ public static int H5Sclose_wrap (int dataspace_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the data space.
+ status = H5.H5Sclose (dataspace_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Sclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Sclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for releasing a datatype.
+ public static int H5Tclose_wrap (int type_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Releasing a datatype.
+ status = H5.H5Tclose (type_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Tclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Tclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for ending access to the dataset and releasing
+ // resources used by it.
+ public static int H5Dclose_wrap (int dataset_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // End access to the dataset and release resources used by it.
+ status = H5.H5Dclose (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Dclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Dclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Compound.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Compound.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
diff --git a/doc/html/Tutor/examples/java/Copy.java b/doc/html/Tutor/examples/java/Copy.java
new file mode 100644
index 0000000..f174210
--- /dev/null
+++ b/doc/html/Tutor/examples/java/Copy.java
@@ -0,0 +1,541 @@
+/******************************************************************
+ * Copy.java (for HDF5 tutorial lesson 13)
+ *
+ * -- Showing how to use the H5SCOPY function.
+ * (a java conversion from h5_copy.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class Copy
+{
+ public static void main (String []argv)
+ {
+ final String FILE1 = "copy1.h5";
+ final String FILE2 = "copy2.h5";
+
+ final int RANK = 2;
+ final int DIM1 = 3;
+ final int DIM2 = 4;
+ final int NUMP = 2;
+
+ int file1, file2, dataset1, dataset2;
+ int mid1, mid2, fid1, fid2;
+ long[] fdim = new long[2];
+ fdim[0] = DIM1;
+ fdim[1] = DIM2;
+ long[] mdim = new long[2];
+ fdim[0] = DIM1;
+ fdim[1] = DIM2;
+
+ long[] start = new long[2];
+ long[] stride = new long[2];
+ long[] count = new long[2];
+ long[] block = new long[2];
+
+ int[][] buf1 = new int[DIM1][DIM2];
+ int[][] buf2 = new int[DIM1][DIM2];
+ int[][] bufnew = new int[DIM1][DIM2];
+
+ int[] val = new int[2];
+ val[0] = 53;
+ val[1] = 59;
+
+ long[] marray = {2};
+ long[][] coord = new long[NUMP][RANK];
+ int ret;
+ int i, j;
+
+
+/***********************************************************************/
+/* */
+/* Create two files containing identical datasets. Write 0's to one */
+/* and 1's to the other. */
+/* */
+/***********************************************************************/
+
+ for ( i = 0; i < DIM1; i++ )
+ for ( j = 0; j < DIM2; j++ )
+ buf1[i][j] = 0;
+
+ for ( i = 0; i < DIM1; i++ )
+ for ( j = 0; j < DIM2; j++ )
+ buf2[i][j] = 1;
+
+ file1 = H5Fcreate_wrap (FILE1, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ file2 = H5Fcreate_wrap (FILE2, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ fid1 = H5Screate_simple_wrap (RANK, fdim, null);
+ fid2 = H5Screate_simple_wrap (RANK, fdim, null);
+
+ dataset1 = H5Dcreate_wrap
+ (file1, "Copy1", H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT), fid1,
+ HDF5Constants.H5P_DEFAULT);
+
+ dataset2 = H5Dcreate_wrap
+ (file2, "Copy2", H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT), fid2,
+ HDF5Constants.H5P_DEFAULT);
+
+
+ ret = H5Dwrite_wrap (dataset1, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, buf1);
+
+ ret = H5Dwrite_wrap (dataset2, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, buf2);
+
+ ret = H5Dclose_wrap (dataset1);
+ ret = H5Dclose_wrap (dataset2);
+
+ ret = H5Sclose_wrap (fid1);
+ ret = H5Sclose_wrap (fid2);
+
+ ret = H5Fclose_wrap (file1);
+ ret = H5Fclose_wrap (file2);
+
+
+/***********************************************************************/
+/* */
+/* Open the two files. Select two points in one file, write values to */
+/* those point locations, then do H5Scopy and write the values to the */
+/* other file. Close files. */
+/* */
+/***********************************************************************/
+
+ file1 = H5Fopen_wrap (FILE1, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+
+ file2 = H5Fopen_wrap (FILE2, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+
+ dataset1 = H5Dopen_wrap (file1, "Copy1");
+ dataset2 = H5Dopen_wrap (file2, "Copy2");
+
+ fid1 = H5Dget_space_wrap (dataset1);
+ mid1 = H5Screate_simple_wrap (1, marray, null);
+
+ coord[0][0] = 0; coord[0][1] = 3;
+ coord[1][0] = 0; coord[1][1] = 1;
+
+ ret = H5Sselect_elements_wrap (fid1, HDF5Constants.H5S_SELECT_SET,
+ NUMP, coord);
+
+ ret = H5Dwrite_wrap (dataset1, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ mid1, fid1, HDF5Constants.H5P_DEFAULT, val);
+
+ fid2 = H5Scopy_wrap (fid1);
+
+ ret = H5Dwrite_wrap (dataset2, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ mid1, fid2, HDF5Constants.H5P_DEFAULT, val);
+
+ ret = H5Dclose_wrap (dataset1);
+ ret = H5Dclose_wrap (dataset2);
+ ret = H5Sclose_wrap (fid1);
+ ret = H5Sclose_wrap (fid2);
+ ret = H5Fclose_wrap (file1);
+ ret = H5Fclose_wrap (file2);
+ ret = H5Sclose_wrap (mid1);
+
+
+/***********************************************************************/
+/* */
+/* Open both files and print the contents of the datasets. */
+/* */
+/***********************************************************************/
+
+ file1 = H5Fopen_wrap (FILE1, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+ file2 = H5Fopen_wrap (FILE2, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+ dataset1 = H5Dopen_wrap (file1, "Copy1");
+ dataset2 = H5Dopen_wrap (file2, "Copy2");
+
+ ret = H5Dread_wrap (dataset1, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, bufnew);
+
+ System.out.println ("\nDataset 'Copy1' in file 'copy1.h5' contains: ");
+
+ for (i = 0;i < DIM1; i++)
+ {
+ for (j = 0;j < DIM2; j++)
+ System.out.print (bufnew[i][j]);
+ System.out.println ();
+ }
+
+ System.out.println ("\nDataset 'Copy2' in file 'copy2.h5' contains: ");
+
+ ret = H5Dread_wrap (dataset2, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, bufnew);
+
+ for (i = 0;i < DIM1; i++)
+ {
+ for (j = 0;j < DIM2; j++)
+ System.out.print (bufnew[i][j]);
+ System.out.println ();
+ }
+
+ ret = H5Dclose_wrap (dataset1);
+ ret = H5Dclose_wrap (dataset2);
+ ret = H5Fclose_wrap (file1);
+ ret = H5Fclose_wrap (file2);
+ }
+
+
+ // Help function for creating a new file
+ public static int H5Fcreate_wrap (String name, int flags,
+ int create_id, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fcreate (name, flags, create_id, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Fcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Fcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for opening an existing file
+ public static int H5Fopen_wrap (String name, int flags, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fopen (name, flags, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Fopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Fopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for opening an existing dataset
+ public static int H5Dopen_wrap (int loc_id, String name)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Opening an existing dataset
+ dataset_id = H5.H5Dopen (loc_id, name);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Dopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Dopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for creating a new simple dataspace and opening it
+ // for access
+ public static int H5Screate_simple_wrap (int rank, long dims[],
+ long maxdims[])
+ {
+ int dataspace_id = -1; // dataspace identifier
+
+ try
+ {
+ // Create the data space for the dataset.
+ dataspace_id = H5.H5Screate_simple (rank, dims, maxdims);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Screate_simple_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Screate_simple_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for getting an identifier for a copy of
+ // the dataspace for a dataset
+ public static int H5Dget_space_wrap (int dataset_id)
+ {
+ int dataspace_id = -1;
+
+ try
+ {
+ // Returning an identifier for a copy of the dataspace for a dataset
+ dataspace_id = H5.H5Dget_space (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Dget_space_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Dget_space_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for selecting array elements to be included in
+ // the selection for the space_id dataspace.
+ public static int H5Sselect_elements_wrap (int space_id, int op,
+ int num_elements,
+ long coord2D[][])
+ {
+ int status = -1;
+
+ try
+ {
+ status = H5.H5Sselect_elements (space_id, op, num_elements,
+ coord2D);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Sselect_elements_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Sselect_elements_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for creating a new dataspace which is an exact
+ // copy of the dataspace identified by space_id.
+ public static int H5Scopy_wrap (int space_id)
+ {
+ int dataspace_id = -1;
+
+ try
+ {
+ dataspace_id = H5.H5Scopy(space_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println ("Copy.H5Scopy_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println ("Copy.H5Scopy_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for creating a dataset
+ public static int H5Dcreate_wrap (int loc_id, String name, int type_id,
+ int space_id, int create_plist_id)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Create the dataset
+ dataset_id = H5.H5Dcreate (loc_id, name, type_id, space_id,
+ create_plist_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Dcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Dcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for writing the dataset
+ public static int H5Dwrite_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object buf)
+ {
+ int status = -1;
+
+ try
+ {
+ // Write the dataset.
+ status = H5.H5Dwrite (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, buf);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Dwrite_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Dwrite_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for reading the dataset
+ public static int H5Dread_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object obj)
+ {
+ int status = -1;
+
+ try
+ {
+ // Read the dataset.
+ status = H5.H5Dread (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, obj);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Dread_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Dread_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the data space.
+ public static int H5Sclose_wrap (int dataspace_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the data space.
+ status = H5.H5Sclose (dataspace_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Sclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Sclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for ending access to the dataset and releasing
+ // resources used by it.
+ public static int H5Dclose_wrap (int dataset_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // End access to the dataset and release resources used by it.
+ status = H5.H5Dclose (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Dclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Dclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("Copy.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("Copy.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
diff --git a/doc/html/Tutor/examples/java/CreateAttribute.java b/doc/html/Tutor/examples/java/CreateAttribute.java
new file mode 100644
index 0000000..c926422
--- /dev/null
+++ b/doc/html/Tutor/examples/java/CreateAttribute.java
@@ -0,0 +1,302 @@
+/******************************************************************
+ * CreateAttribute.java (for HDF5 tutorial lesson 7)
+ *
+ * -- Creating and Writing a dataset attribute
+ * (a java conversion from h5_crtatt.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class CreateAttribute
+{
+ public static void main(String []argv)
+ {
+ final String FILE = "dset.h5";
+ int file_id = -1; // file identifier
+ int dataset_id = -1; // dataset identifier
+ int attribute_id = -1;
+ int dataspace_id = -1; // dataspace identifier
+ long[] dims = new long[1];
+ int[] attr_data = new int[2];
+ int status = -1;
+
+ // Initialize the attribute data.
+ attr_data[0] = 100;
+ attr_data[1] = 200;
+
+ // Open an existing file.
+ file_id = H5Fopen_wrap (FILE, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Open an existing dataset.
+ dataset_id = H5Dopen_wrap (file_id, "/dset");
+
+ // Create the data space for the attribute.
+ dims[0] = 2;
+ dataspace_id = H5Screate_simple_wrap (1, dims, null);
+
+ // Create a dataset attribute.
+ attribute_id = H5Acreate_wrap
+ (dataset_id, "attr",
+ H5.J2C (HDF5CDataTypes.JH5T_STD_I32BE),
+ dataspace_id, HDF5Constants.H5P_DEFAULT);
+
+ // Write the attribute data.
+ status = H5Awrite_wrap
+ (attribute_id,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ attr_data);
+
+ // Close the attribute.
+ status = H5Aclose_wrap (attribute_id);
+
+ // Close the dataspace.
+ status = H5Sclose_wrap (dataspace_id);
+
+ // Close to the dataset.
+ status = H5Dclose_wrap (dataset_id);
+
+ // Close the file.
+ status = H5Fclose_wrap (file_id);
+ }
+
+
+ // Help function for opening an existing file
+ public static int H5Fopen_wrap (String name, int flags, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fopen (name, flags, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Fopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Fopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for opening an existing dataset
+ public static int H5Dopen_wrap (int loc_id, String name)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Opening an existing dataset
+ dataset_id = H5.H5Dopen (loc_id, name);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Dopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Dopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Create the data space for the attribute.
+ public static int H5Screate_simple_wrap (int rank, long dims[],
+ long maxdims[])
+ {
+ int dataspace_id = -1; // dataspace identifier
+
+ try
+ {
+ // Create the data space for the dataset.
+ dataspace_id = H5.H5Screate_simple (rank, dims, maxdims);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Screate_simple_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Screate_simple_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for creating a dataset attribute.
+ public static int H5Acreate_wrap (int loc_id, String name, int type_id,
+ int space_id, int create_plist)
+ {
+ int attribute_id = -1; // attribute identifier
+
+ try
+ {
+ // Create the dataset
+ attribute_id = H5.H5Acreate (loc_id, name, type_id, space_id,
+ create_plist);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Acreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Acreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return attribute_id;
+ }
+
+
+ // Help function for writing the attribute data.
+ public static int H5Awrite_wrap (int attr_id, int mem_type_id,
+ Object buf)
+ {
+ int status = -1;
+
+ try
+ {
+ // Write the attribute data.
+ status = H5.H5Awrite (attr_id, mem_type_id, buf);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Awrite_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Awrite_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for closing the attribute
+ public static int H5Aclose_wrap (int attribute_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Close the dataset
+ status = H5.H5Aclose (attribute_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Aclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Aclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for closing the dataset
+ public static int H5Dclose_wrap (int dataset_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Close the dataset
+ status = H5.H5Dclose (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Dclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Dclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for closing the dataspace
+ public static int H5Sclose_wrap (int dataspace_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the data space.
+ status = H5.H5Sclose (dataspace_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Sclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Sclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateAttribute.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
diff --git a/doc/html/Tutor/examples/java/CreateDataset.java b/doc/html/Tutor/examples/java/CreateDataset.java
new file mode 100644
index 0000000..05f3f6b
--- /dev/null
+++ b/doc/html/Tutor/examples/java/CreateDataset.java
@@ -0,0 +1,210 @@
+/******************************************************************
+ * CreateDataset.java (for HDF5 tutorial lesson 5)
+ *
+ * -- Creating a HDF5 Dataset
+ * (a java conversion from h5_crtdat.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class CreateDataset
+{
+ public static void main(String []argv)
+ {
+ final String FILE = "dset.h5";
+ int file_id = -1; // file identifier
+ int dataset_id = -1; // dataset identifier
+ int dataspace_id = -1; // dataspace identifier
+ long[] dims = new long[2];
+ int status = -1;
+
+ // Create a new file using default properties.
+ file_id = H5Fcreate_wrap (FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Create the data space for the dataset.
+ dims[0] = 4;
+ dims[1] = 6;
+ dataspace_id = H5Screate_simple_wrap (2, dims, null);
+
+ // Create the dataset.
+ dataset_id =
+ H5Dcreate_wrap (file_id, "/dset",
+ H5.J2C (HDF5CDataTypes.JH5T_STD_I32BE),
+ dataspace_id, HDF5Constants.H5P_DEFAULT);
+
+ // End access to the dataset and release resources used by it.
+ status = H5Dclose_wrap (dataset_id);
+
+ // Terminate access to the data space.
+ status = H5Sclose_wrap (dataspace_id);
+
+ // Close the file.
+ status = H5Fclose_wrap (file_id);
+ }
+
+
+ // Help function for creating a new file
+ public static int H5Fcreate_wrap (String name, int flags,
+ int create_id, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fcreate (name, flags, create_id, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateDataset.H5Fcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateDataset.H5Fcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for creating a new simple dataspace and opening it
+ // for access
+ public static int H5Screate_simple_wrap (int rank, long dims[],
+ long maxdims[])
+ {
+ int dataspace_id = -1; // dataspace identifier
+
+ try
+ {
+ // Create the data space for the dataset.
+ dataspace_id = H5.H5Screate_simple (rank, dims, maxdims);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateDataset.H5Screate_simple_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateDataset.H5Screate_simple_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for creating a dataset
+ public static int H5Dcreate_wrap (int loc_id, String name, int type_id,
+ int space_id, int create_plist_id)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Create the dataset
+ dataset_id = H5.H5Dcreate (loc_id, name, type_id, space_id,
+ create_plist_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateDataset.H5Dcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateDataset.H5Dcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for ending access to the dataset and releasing
+ // resources used by it.
+ public static int H5Dclose_wrap (int dataset_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // End access to the dataset and release resources used by it.
+ status = H5.H5Dclose (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateDataset.H5Dclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateDataset.H5Dclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the data space.
+ public static int H5Sclose_wrap (int dataspace_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the data space.
+ status = H5.H5Sclose (dataspace_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateDataset.H5Sclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateDataset.H5Sclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateDataset.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateDataset.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
+
diff --git a/doc/html/Tutor/examples/java/CreateFile.java b/doc/html/Tutor/examples/java/CreateFile.java
new file mode 100644
index 0000000..550b263
--- /dev/null
+++ b/doc/html/Tutor/examples/java/CreateFile.java
@@ -0,0 +1,83 @@
+/******************************************************************
+ * CreateFile.java (for HDF5 tutorial lesson 4)
+ *
+ * -- Creating a HDF5 file
+ * (a java conversion from h5_crtfile.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class CreateFile
+{
+ public static void main(String []argv)
+ {
+ final String FILE = "file.h5";
+ int file_id = -1; // file identifier
+ int status = -1;
+
+ file_id = H5Fcreate_wrap (FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ status = H5Fclose_wrap (file_id);
+ }
+
+
+ // Help function for creating a new file
+ public static int H5Fcreate_wrap (String name, int flags,
+ int create_id, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fcreate (name, flags, create_id, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateFile.H5Fcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateFile.H5Fcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+
+ System.out.println ("\nThe file name is: " + name);
+ System.out.println ("The file ID is: " + file_id);
+
+ return file_id;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateFile.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateFile.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
+
+
diff --git a/doc/html/Tutor/examples/java/CreateFileInput.java b/doc/html/Tutor/examples/java/CreateFileInput.java
new file mode 100644
index 0000000..0e7fd4d
--- /dev/null
+++ b/doc/html/Tutor/examples/java/CreateFileInput.java
@@ -0,0 +1,118 @@
+/******************************************************************
+ * CreateFileInput.java (for HDF5 tutorial Lesson 4)
+ *
+ * -- Creating a HDF5 file
+ * (another java conversion from h5_crtfile.c, give user two options:
+ * one for library path and one for file name, if user chooses
+ * nothing, then the default file name is used.)
+ *
+ ******************************************************************/
+
+import java.lang.System;
+import java.util.*;
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class CreateFileInput
+{
+ // The run command should be like:
+ // "./runCreateFileInput -l /usr/lib/hdf5.dll -f ./open.h5"
+ public static void main(String []argv)
+ {
+ int file_id = -1; // file identifier
+ int status = -1;
+ String libpath = null;
+ String filename = null;
+
+ for (int i = 0; i < argv.length; i++)
+ {
+ if ("-l".equalsIgnoreCase (argv[i]))
+ libpath = argv[++i];
+
+ if ("-f".equalsIgnoreCase (argv[i]))
+ filename = argv[++i];
+ }
+
+ if (libpath != null)
+ {
+ Properties pros = System.getProperties ();
+ pros.put (H5.H5PATH_PROPERTY_KEY, libpath);
+
+ /*
+ this function call could be used in Java 1.2
+ System.setProperty (H5.H5PATH_PROPERTY_KEY, libpath);
+ */
+ }
+
+ if (filename == null)
+ {
+ filename = "file.h5"; // if no input file name, use the default name
+ }
+
+ file_id = H5Fcreate_wrap (filename,
+ HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ status = H5Fclose_wrap (filename, file_id);
+ }
+
+
+ // Help function for creating a new file
+ public static int H5Fcreate_wrap (String name, int flags,
+ int create_id, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fcreate (name, flags, create_id, access_id);
+
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateFileInput.H5Fcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateFileInput.H5Fcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+
+ System.out.println ("\nThe file name is: " + name);
+ System.out.println ("The file ID is: " + file_id);
+
+ return file_id;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (String name, int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateFileInput.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateFileInput.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+
+ return status;
+ }
+}
+
+
diff --git a/doc/html/Tutor/examples/java/CreateGroup.java b/doc/html/Tutor/examples/java/CreateGroup.java
new file mode 100644
index 0000000..48ef4af
--- /dev/null
+++ b/doc/html/Tutor/examples/java/CreateGroup.java
@@ -0,0 +1,139 @@
+/******************************************************************
+ * CreateGroup.java (for HDF5 tutorial lesson 8)
+ *
+ * -- Creating and closing a group
+ * (a java conversion from h5_crtgrp.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class CreateGroup
+{
+ public static void main(String []argv)
+ {
+ final String FILE = "group.h5";
+ int file_id = -1; // file identifier
+ int group_id = -1; // group identifier
+ int status = -1;
+
+ // Create a new file using default properties.
+ file_id = H5Fcreate_wrap (FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Create a group named "/MyGroup" in the file.
+ group_id = H5Gcreate_wrap (file_id, "/MyGroup", 0);
+
+ // Close the group.
+ status = H5Gclose_wrap (group_id);
+
+ // Close the file.
+ status = H5Fclose_wrap (file_id);
+ }
+
+
+ // Help function for creating a new file
+ public static int H5Fcreate_wrap (String name, int flags,
+ int create_id, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fcreate (name, flags, create_id, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroup.H5Fcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroup.H5Fcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for creating a group named "/MyGroup" in the file.
+ public static int H5Gcreate_wrap (int loc_id, String name, int size_hint)
+ {
+ int group_id = -1; // group identifier
+ try
+ {
+ // Create a group
+ group_id = H5.H5Gcreate (loc_id, name, size_hint);
+
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroup.H5Gcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroup.H5Gcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return group_id;
+ }
+
+
+ // Help function for closing the group
+ public static int H5Gclose_wrap (int group_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Close the group
+ status = H5.H5Gclose (group_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroup.H5Gclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroup.H5Gclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroup.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroup.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
diff --git a/doc/html/Tutor/examples/java/CreateGroupAR.java b/doc/html/Tutor/examples/java/CreateGroupAR.java
new file mode 100644
index 0000000..672f1d1
--- /dev/null
+++ b/doc/html/Tutor/examples/java/CreateGroupAR.java
@@ -0,0 +1,152 @@
+/******************************************************************
+ * CreateGroupAR.java (for HDF5 tutorial lesson 9)
+ *
+ * -- Creating groups using absolute and relative names.
+ * (a java conversion from h5_crtgrpar.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class CreateGroupAR
+{
+ public static void main(String []argv)
+ {
+ final String FILE = "groups.h5";
+ int file_id = -1; // file identifier
+ int group1_id = -1; // group identifier
+ int group2_id = -1;
+ int group3_id = -1;
+
+ int status = -1;
+
+ // Create a new file using default properties.
+ file_id = H5Fcreate_wrap (FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Create group "MyGroup" in the root group using absolute name.
+ group1_id = H5Gcreate_wrap (file_id, "/MyGroup", 0);
+
+
+ // Create group "Group_A" in group "MyGroup" using absolute name.
+ group2_id = H5Gcreate_wrap (file_id, "/MyGroup/Group_A", 0);
+
+ // Create group "Group_B" in group "MyGroup" using relative name.
+ group3_id = H5Gcreate_wrap (group1_id, "Group_B", 0);
+
+ // Close groups.
+ status = H5Gclose_wrap (group1_id);
+ status = H5Gclose_wrap (group2_id);
+ status = H5Gclose_wrap (group3_id);
+
+ // Close the file.
+ status = H5Fclose_wrap (file_id);
+ }
+
+
+ // Help function for creating a new file
+ public static int H5Fcreate_wrap (String name, int flags,
+ int create_id, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fcreate (name, flags, create_id, access_id);
+
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupAR.H5Fcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupAR.H5Fcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for creating a group named "/MyGroup" in the file.
+ public static int H5Gcreate_wrap (int loc_id, String name, int size_hint)
+ {
+ int group_id = -1; // group identifier
+ try
+ {
+ // Create a group
+ group_id = H5.H5Gcreate (loc_id, name, size_hint);
+
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupAR.H5Gcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupAR.H5Gcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return group_id;
+ }
+
+
+ // Help function for closing the group
+ public static int H5Gclose_wrap (int group_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Close the group
+ status = H5.H5Gclose (group_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupAR.H5Gclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupAR.H5Gclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupAR.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupAR.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
diff --git a/doc/html/Tutor/examples/java/CreateGroupDataset.java b/doc/html/Tutor/examples/java/CreateGroupDataset.java
new file mode 100644
index 0000000..f0fbeaa
--- /dev/null
+++ b/doc/html/Tutor/examples/java/CreateGroupDataset.java
@@ -0,0 +1,340 @@
+/******************************************************************
+ * CreateGroupDataset.java (for HDF5 tutorial lesson 10)
+ *
+ * -- Creating a dataset in a particular group
+ * (a java conversion from h5_crtgrpd.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class CreateGroupDataset
+{
+ public static void main(String []argv)
+ {
+ final String FILE = "groups.h5";
+ int file_id = -1; // file identifier
+ int group_id = -1; // group identifier
+ int dataset_id;
+ int dataspace_id;
+ int status = -1;
+
+ long[] dims = new long[2];
+ int[][] dset1_data = new int[3][3];
+ int[][] dset2_data = new int[2][10];
+ int i = -1, j = -1;
+
+ // Initialize the first dataset.
+ for (i = 0; i < 3; i++)
+ for (j = 0; j < 3; j++)
+ dset1_data[i][j] = j + 1;
+
+ // Initialize the second dataset.
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 10; j++)
+ dset2_data[i][j] = j + 1;
+
+ // Open an existing file.
+ file_id = H5Fopen_wrap (FILE, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Create the data space for the first dataset.
+ dims[0] = 3;
+ dims[1] = 3;
+ dataspace_id = H5Screate_simple_wrap (2, dims, null);
+
+ // Create a dataset in group "MyGroup".
+ dataset_id =
+ H5Dcreate_wrap (file_id, "/MyGroup/dset1",
+ H5.J2C (HDF5CDataTypes.JH5T_STD_I32BE),
+ dataspace_id, HDF5Constants.H5P_DEFAULT);
+
+ // Write the first dataset.
+ status = H5Dwrite_wrap
+ (dataset_id,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, dset1_data);
+
+ // Close the data space for the first dataset.
+ status = H5Sclose_wrap (dataspace_id);
+
+ // Close the first dataset.
+ status = H5Dclose_wrap (dataset_id);
+
+ // Open an existing group of the specified file.
+ group_id = H5Gopen_wrap (file_id, "/MyGroup/Group_A");
+
+ // Create the data space for the second dataset.
+ dims[0] = 2;
+ dims[1] = 10;
+ dataspace_id = H5Screate_simple_wrap (2, dims, null);
+
+ // Create the second dataset in group "Group_A".
+ dataset_id =
+ H5Dcreate_wrap (group_id, "dset2",
+ H5.J2C (HDF5CDataTypes.JH5T_STD_I32BE),
+ dataspace_id, HDF5Constants.H5P_DEFAULT);
+
+ // Write the second dataset.
+ status = H5Dwrite_wrap
+ (dataset_id,
+ H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, dset2_data);
+
+ // Close the data space for the second dataset.
+ status = H5Sclose_wrap (dataspace_id);
+
+ // Close the second dataset
+ status = H5Dclose_wrap (dataset_id);
+
+ // Close the group.
+ status = H5Gclose_wrap (group_id);
+
+ // Close the file.
+ status = H5Fclose_wrap (file_id);
+ }
+
+
+ // Help function for opening an existing file
+ public static int H5Fopen_wrap (String name, int flags, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fopen (name, flags, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Fopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Fopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for creating a new simple dataspace and opening it
+ // for access
+ public static int H5Screate_simple_wrap (int rank, long dims[],
+ long maxdims[])
+ {
+ int dataspace_id = -1; // dataspace identifier
+
+ try
+ {
+ // Create the data space for the dataset.
+ dataspace_id = H5.H5Screate_simple (rank, dims, maxdims);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Screate_simple_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Screate_simple_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for creating a dataset
+ public static int H5Dcreate_wrap (int loc_id, String name, int type_id,
+ int space_id, int create_plist_id)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Create the dataset
+ dataset_id = H5.H5Dcreate (loc_id, name, type_id, space_id,
+ create_plist_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Dcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Dcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for writing the dataset
+ public static int H5Dwrite_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object buf)
+ {
+ int status = -1;
+
+ try
+ {
+ // Write the dataset.
+ status = H5.H5Dwrite (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, buf);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Dwrite_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Dwrite_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the data space.
+ public static int H5Sclose_wrap (int dataspace_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the data space.
+ status = H5.H5Sclose (dataspace_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Sclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Sclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for ending access to the dataset and releasing
+ // resources used by it.
+ public static int H5Dclose_wrap (int dataset_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // End access to the dataset and release resources used by it.
+ status = H5.H5Dclose (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Dclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Dclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for opening a group
+ public static int H5Gopen_wrap (int loc_id, String name)
+ {
+ int group_id = -1; // group identifier
+ try
+ {
+ // Create a group
+ group_id = H5.H5Gopen (loc_id, name);
+
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Gopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Gopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return group_id;
+ }
+
+
+ // Help function for closing the group
+ public static int H5Gclose_wrap (int group_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Close the group
+ status = H5.H5Gclose (group_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Gclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Gclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("CreateGroupDataset.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
diff --git a/doc/html/Tutor/examples/java/DatasetRdWt.java b/doc/html/Tutor/examples/java/DatasetRdWt.java
new file mode 100644
index 0000000..4c26d0f
--- /dev/null
+++ b/doc/html/Tutor/examples/java/DatasetRdWt.java
@@ -0,0 +1,213 @@
+/******************************************************************
+ * DatasetRdWt.java (for HDF5 tutorial lesson 6)
+ *
+ * -- Reading and Writing an existing Dataset
+ * (a java conversion from h5_rdwt.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class DatasetRdWt
+{
+ public static void main(String []argv)
+ {
+ final String FILE = "dset.h5";
+ int file_id = -1; // file identifier
+ int dataset_id = -1; // dataset identifier
+ int status = -1;
+ int[][] dset_data = new int[4][6];
+
+ // Initialize the dataset.
+ for (int i = 0; i < 4; i++)
+ for (int j = 0; j < 6; j++)
+ dset_data[i][j] = i * 6 + j + 1;
+
+ // Open an existing file
+ file_id = H5Fopen_wrap (FILE, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Open an existing dataset.
+ dataset_id = H5Dopen_wrap (file_id, "/dset");
+
+ // Write the dataset.
+ status = H5Dwrite_wrap
+ (dataset_id, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, dset_data);
+
+ status = H5Dread_wrap
+ (dataset_id, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, dset_data);
+
+ // Close the dataset.
+ status = H5Dclose_wrap (dataset_id);
+
+ // Close the file.
+ status = H5Fclose_wrap (file_id);
+ }
+
+
+ // Help function for opening an existing file
+ public static int H5Fopen_wrap (String name, int flags, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fopen (name, flags, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Fopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Fopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for opening an existing dataset
+ public static int H5Dopen_wrap (int loc_id, String name)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Opening an existing dataset
+ dataset_id = H5.H5Dopen (loc_id, name);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Dopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Dopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for writing the dataset
+ public static int H5Dwrite_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object buf)
+ {
+ int status = -1;
+
+ try
+ {
+ // Write the dataset.
+ status = H5.H5Dwrite (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, buf);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Dwrite_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Dwrite_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for reading the dataset
+ public static int H5Dread_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object obj)
+ {
+ int status = -1;
+
+ try
+ {
+ // Read the dataset.
+ status = H5.H5Dread (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, obj);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Dread_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Dread_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for ending access to the dataset and releasing
+ // resources used by it.
+ public static int H5Dclose_wrap (int dataset_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // End access to the dataset and release resources used by it.
+ status = H5.H5Dclose (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Dclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Dclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("DatasetRdWt.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
diff --git a/doc/html/Tutor/examples/java/HyperSlab.java b/doc/html/Tutor/examples/java/HyperSlab.java
new file mode 100644
index 0000000..5f8818d
--- /dev/null
+++ b/doc/html/Tutor/examples/java/HyperSlab.java
@@ -0,0 +1,590 @@
+/******************************************************************
+ * HyperSlab.java (for HDF5 tutorial lesson 12)
+ *
+ * -- Writing and reading a hyperslab
+ * (a java conversion from h5_hyperslab.c)
+ *
+ ******************************************************************/
+
+import ncsa.hdf.hdf5lib.*;
+import ncsa.hdf.hdf5lib.exceptions.*;
+
+public class HyperSlab
+{
+ public static void main (String []argv)
+ {
+ final String FILE = "sds.h5";
+ final String DATASETNAME = "IntArray";
+ final int NX_SUB = 3; /* hyperslab dimensions */
+ final int NY_SUB = 4;
+ final int NX = 7; /* output buffer dimensions */
+ final int NY = 7;
+ final int NZ = 3;
+ final int RANK = 2;
+ final int RANK_OUT = 3;
+ final int X = 5; /* dataset dimensions */
+ final int Y = 6;
+
+ long[] dimsf = new long[2]; /* dataset dimensions */
+ int[][] data = new int[X][Y]; /* data to write */
+
+ /*
+ * Data and output buffer initialization.
+ */
+ int file, dataset; /* handles */
+ int dataspace;
+ int memspace;
+ long[] dimsm = new long[3]; /* memory space dimensions */
+ long[] dims_out = new long[2]; /* dataset dimensions */
+ int status;
+
+ int[][][] data_out = new int[NX][NY][NZ]; /* output buffer */
+
+ long[] count = new long[2]; /* size of the hyperslab in the file */
+ long[] offset = new long[2]; /* hyperslab offset in the file */
+ long[] count_out = new long[3]; /* size of the hyperslab in memory */
+ long[] offset_out = new long[3]; /* hyperslab offset in memory */
+ int i, j, k, status_n, rank;
+
+ /*********************************************************
+ This writes data to the HDF5 file.
+ *********************************************************/
+
+ /*
+ * Data and output buffer initialization.
+ */
+ for (j = 0; j < X; j++)
+ {
+ for (i = 0; i < Y; i++)
+ data[j][i] = i + j;
+ }
+ /*
+ * 0 1 2 3 4 5
+ * 1 2 3 4 5 6
+ * 2 3 4 5 6 7
+ * 3 4 5 6 7 8
+ * 4 5 6 7 8 9
+ */
+
+ /*
+ * Create a new file using H5F_ACC_TRUNC access,
+ * the default file creation properties, and the default file
+ * access properties.
+ */
+ file = H5Fcreate_wrap (FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ /*
+ * Describe the size of the array and create the data space for fixed
+ * size dataset.
+ */
+ dimsf[0] = X;
+ dimsf[1] = Y;
+ dataspace = H5Screate_simple_wrap (RANK, dimsf, null);
+
+ /*
+ * Create a new dataset within the file using defined dataspace and
+ * default dataset creation properties.
+ */
+ dataset = H5Dcreate_wrap
+ (file, DATASETNAME, H5.J2C (HDF5CDataTypes.JH5T_STD_I32BE),
+ dataspace, HDF5Constants.H5P_DEFAULT);
+
+ /*
+ * Write the data to the dataset using default transfer properties.
+ */
+ status = H5Dwrite_wrap
+ (dataset, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, data);
+
+ /*
+ * Close/release resources.
+ */
+ H5Sclose_wrap (dataspace);
+ H5Dclose_wrap (dataset);
+ H5Fclose_wrap (file);
+
+ /*************************************************************
+
+ This reads the hyperslab from the sds.h5 file just
+ created, into a 2-dimensional plane of the 3-dimensional
+ array.
+
+ ************************************************************/
+
+ for (j = 0; j < NX; j++)
+ {
+ for (i = 0; i < NY; i++)
+ {
+ for (k = 0; k < NZ ; k++)
+ data_out[j][i][k] = 0;
+ }
+ }
+
+ /*
+ * Open the file and the dataset.
+ */
+ file = H5Fopen_wrap (FILE, HDF5Constants.H5F_ACC_RDONLY,
+ HDF5Constants.H5P_DEFAULT);
+ dataset = H5Dopen_wrap (file, DATASETNAME);
+
+ dataspace = H5Dget_space_wrap (dataset); /* dataspace handle */
+ rank = H5Sget_simple_extent_ndims_wrap (dataspace);
+ status_n = H5Sget_simple_extent_dims_wrap (dataspace, dims_out, null);
+
+ System.out.println ("Rank: " + rank);
+ System.out.println ("Dimensions: "+ dims_out[0] + " x " + dims_out[1]);
+
+ /*
+ * Define hyperslab in the dataset.
+ */
+ offset[0] = 1;
+ offset[1] = 2;
+ count[0] = NX_SUB;
+ count[1] = NY_SUB;
+ status = H5Sselect_hyperslab_wrap (dataspace,
+ HDF5Constants.H5S_SELECT_SET,
+ offset, null, count, null);
+
+ /*
+ * Define the memory dataspace.
+ */
+ dimsm[0] = NX;
+ dimsm[1] = NY;
+ dimsm[2] = NZ;
+ memspace = H5Screate_simple_wrap (RANK_OUT, dimsm, null);
+
+ /*
+ * Define memory hyperslab.
+ */
+ offset_out[0] = 3;
+ offset_out[1] = 0;
+ offset_out[2] = 0;
+ count_out[0] = NX_SUB;
+ count_out[1] = NY_SUB;
+ count_out[2] = 1;
+ status = H5Sselect_hyperslab_wrap (memspace,
+ HDF5Constants.H5S_SELECT_SET,
+ offset_out, null, count_out, null);
+
+ /*
+ * Read data from hyperslab in the file into the hyperslab in
+ * memory and display.
+ */
+ status =
+ H5Dread_wrap (dataset, H5.J2C (HDF5CDataTypes.JH5T_NATIVE_INT),
+ memspace, dataspace, HDF5Constants.H5P_DEFAULT,
+ data_out);
+
+ System.out.println ("Data:");
+ for (j = 0; j < NX; j++)
+ {
+ for (i = 0; i < NY; i++)
+ System.out.print (data_out[j][i][0]);
+ System.out.println ();
+ }
+ System.out.println ();
+
+ /*
+ * 0 0 0 0 0 0 0
+ * 0 0 0 0 0 0 0
+ * 0 0 0 0 0 0 0
+ * 3 4 5 6 0 0 0
+ * 4 5 6 7 0 0 0
+ * 5 6 7 8 0 0 0
+ * 0 0 0 0 0 0 0
+ */
+
+ /*
+ * Close and release resources.
+ */
+ H5Dclose_wrap (dataset);
+ H5Sclose_wrap (dataspace);
+ H5Sclose_wrap (memspace);
+ H5Fclose_wrap (file);
+ }
+
+
+ // Help function for creating a new file
+ public static int H5Fcreate_wrap (String name, int flags,
+ int create_id, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fcreate (name, flags, create_id, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Fcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Fcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for opening an existing file
+ public static int H5Fopen_wrap (String name, int flags, int access_id)
+ {
+ int file_id = -1; // file identifier
+ try
+ {
+ // Create a new file using default file properties.
+ file_id = H5.H5Fopen (name, flags, access_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Fopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Fopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return file_id;
+ }
+
+
+ // Help function for opening an existing dataset
+ public static int H5Dopen_wrap (int loc_id, String name)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Opening an existing dataset
+ dataset_id = H5.H5Dopen (loc_id, name);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dopen_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dopen_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for creating a new simple dataspace and opening it
+ // for access
+ public static int H5Screate_simple_wrap (int rank, long dims[],
+ long maxdims[])
+ {
+ int dataspace_id = -1; // dataspace identifier
+
+ try
+ {
+ // Create the data space for the dataset.
+ dataspace_id = H5.H5Screate_simple (rank, dims, maxdims);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Screate_simple_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Screate_simple_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for getting an identifier for a copy of
+ // the dataspace for a dataset
+ public static int H5Dget_space_wrap (int dataset_id)
+ {
+ int dataspace_id = -1;
+
+ try
+ {
+ // Returning an identifier for a copy of the dataspace for a dataset
+ dataspace_id = H5.H5Dget_space (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dget_space_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dget_space_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataspace_id;
+ }
+
+
+ // Help function for determining the dimensionality (or rank) of
+ // a dataspace
+ public static int H5Sget_simple_extent_ndims_wrap (int space_id)
+ {
+ int rank = -1;
+
+ try
+ {
+ // Determine the dimensionality (or rank) of a dataspace.
+ rank = H5.H5Sget_simple_extent_ndims (space_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Sget_simple_extent_ndims_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Sget_simple_extent_ndims_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return rank;
+ }
+
+
+ // Help function for returning the size and maximum sizes of each
+ // dimension of a dataspace through the dims and maxdims parameters.
+ public static int H5Sget_simple_extent_dims_wrap (int space_id,
+ long dims[],
+ long maxdims[])
+ {
+ int dimension_number = -1;
+
+ try
+ {
+ dimension_number = H5.H5Sget_simple_extent_dims (space_id, dims,
+ maxdims);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Sget_simple_extent_dims_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Sget_simple_extent_dims_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dimension_number;
+ }
+
+
+ // Help function for selecting a hyperslab region to add to the
+ // current selected region for the dataspace specified by space_id.
+ public static int H5Sselect_hyperslab_wrap (int space_id, int op,
+ long start[], long stride[],
+ long count[], long block[])
+ {
+ int status = -1;
+
+ try
+ {
+ status = H5.H5Sselect_hyperslab (space_id, op, start, stride,
+ count, block);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Sselect_hyperslab_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Sselect_hyperslab_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for creating a dataset
+ public static int H5Dcreate_wrap (int loc_id, String name, int type_id,
+ int space_id, int create_plist_id)
+ {
+ int dataset_id = -1; // dataset identifier
+
+ try
+ {
+ // Create the dataset
+ dataset_id = H5.H5Dcreate (loc_id, name, type_id, space_id,
+ create_plist_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dcreate_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dcreate_wrap() with other Exception: "
+ + e.getMessage());
+ }
+ return dataset_id;
+ }
+
+
+ // Help function for writing the dataset
+ public static int H5Dwrite_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object buf)
+ {
+ int status = -1;
+
+ try
+ {
+ // Write the dataset.
+ status = H5.H5Dwrite (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, buf);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dwrite_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dwrite_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for reading the dataset
+ public static int H5Dread_wrap (int dataset_id, int mem_type_id,
+ int mem_space_id, int file_space_id,
+ int xfer_plist_id, Object obj)
+ {
+ int status = -1;
+
+ try
+ {
+ // Read the dataset.
+ status = H5.H5Dread (dataset_id, mem_type_id, mem_space_id,
+ file_space_id, xfer_plist_id, obj);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dread_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dread_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the data space.
+ public static int H5Sclose_wrap (int dataspace_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the data space.
+ status = H5.H5Sclose (dataspace_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Sclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Sclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for ending access to the dataset and releasing
+ // resources used by it.
+ public static int H5Dclose_wrap (int dataset_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // End access to the dataset and release resources used by it.
+ status = H5.H5Dclose (dataset_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Dclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+
+
+ // Help function for terminating access to the file.
+ public static int H5Fclose_wrap (int file_id)
+ {
+ int status = -1;
+
+ try
+ {
+ // Terminate access to the file.
+ status = H5.H5Fclose (file_id);
+ }
+ catch (HDF5Exception hdf5e)
+ {
+ System.out.println
+ ("HyperSlab.H5Fclose_wrap() with HDF5Exception: "
+ + hdf5e.getMessage());
+ }
+ catch (Exception e)
+ {
+ System.out.println
+ ("HyperSlab.H5Fclose_wrap() with other exception: "
+ + e.getMessage());
+ }
+ return status;
+ }
+}
diff --git a/doc/html/Tutor/examples/java/Makefile b/doc/html/Tutor/examples/java/Makefile
new file mode 100644
index 0000000..a70ab0b
--- /dev/null
+++ b/doc/html/Tutor/examples/java/Makefile
@@ -0,0 +1,92 @@
+# Generated automatically from Makefile.in by configure.
+# /*=======================================================================
+# UNIVERSITY OF ILLINOIS (UI), NATIONAL CENTER FOR SUPERCOMPUTING
+# APPLICATIONS (NCSA), Software Distribution Policy for Public Domain
+# Software
+#
+# NCSA HDF Version 5 source code and documentation are in the public
+# domain, available without fee for education, research, non-commercial and
+# commercial purposes. Users may distribute the binary or source code to
+# third parties provided that this statement appears on all copies and that
+# no charge is made for such copies.
+#
+# UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY
+# PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. THE
+# UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE USER OF THIS
+# SOFTWARE. The software may have been developed under agreements between
+# the UI and the Federal Government which entitle the Government to certain
+# rights.
+#
+# We ask, but do not require that the following message be include in all
+# derived works:
+#
+# Portions developed at the National Center for Supercomputing Applications
+# at the University of Illinois at Urbana-Champaign.
+#
+# By copying this program, you, the user, agree to abide by the conditions
+# and understandings with respect to any software which is marked with a
+# public domain notice.
+#
+# =======================================================================*/
+#
+
+
+JAVAC = /usr/java1.2/bin/javac
+FIND = /bin/find
+
+CLASSPATH=/usr/java1.2/jre/lib/rt.jar:/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+
+
+.SUFFIXES: .java .class
+
+.java.class:
+ $(JAVAC) -classpath $(CLASSPATH) $<
+
+tutorial: ./Compound.class \
+ ./Copy.class \
+ ./CreateAttribute.class \
+ ./CreateDataset.class \
+ ./CreateFile.class \
+ ./CreateFileInput.class \
+ ./CreateGroup.class \
+ ./CreateGroupAR.class \
+ ./CreateGroupDataset.class \
+ ./DatasetRdWt.class \
+ ./HyperSlab.class
+ chmod u+x *.sh
+
+clean: clean-classes
+
+distclean: clean-classes clean-data
+ rm config.cache config.status config.log
+ rm -rf ./Makefile
+
+clean-classes:
+ $(FIND) . \( -name '#*' -o -name '*~' -o -name '*.class' \) -exec rm -f {} \; ;\
+
+clean-data:
+ rm -rf *.h5
+
+Compound: ./Compound.class
+Copy: ./Copy.class
+CreateAttribute: ./CreateAttribute.class
+CreateDataset: ./CreateDataset.class
+CreateFile: ./CreateFile.class
+CreateFileInput: ./CreateFileInput.class
+CreateGroup: ./CreateGroup.class
+CreateGroupAR: ./CreateGroupAR.class
+CreateGroupDataset: ./CreateGroupDataset.class
+DatasetRdWt: ./DatasetRdWt.class
+HyperSlab: ./HyperSlab.class
+
+CLASSES= ./Compound.class \
+ ./Copy.class \
+ ./CreateAttribute.class \
+ ./CreateDataset.class \
+ ./CreateFileInput.class \
+ ./CreateFile.class \
+ ./CreateGroup.class \
+ ./CreateGroupAR.class \
+ ./CreateGroupDataset.class \
+ ./DatasetRdWt.class \
+ ./HyperSlab.class
diff --git a/doc/html/Tutor/examples/java/README b/doc/html/Tutor/examples/java/README
new file mode 100644
index 0000000..95c9360
--- /dev/null
+++ b/doc/html/Tutor/examples/java/README
@@ -0,0 +1,21 @@
+These files are Java versions of the example programs used in
+the HDF-5 tutoral:
+ http://hdf.ncsa.uiuc.edu/training/hdf5/
+
+The examples here correspond to the examples explained in the first 13
+sections of the tutorial.
+
+Lesson C program Java program Topic
+
+4 h5_crtfile.c CreateFile.java Create an HDF-5 file.
+5 h5_crtdat.c CreateDataset.java Create a dataset.
+6 h5_rdwt.c DatasetRdWt.java Write/Read a dataset.
+7 h5_crtatt.c CreateAttribute.java Create an attribute.
+8 h5_crtgrp.c CreateGroup.java Create a group.
+9 h5_crtgrpar.c CreateGroupAR.java Abs. and Rel. paths.
+10 h5_crtgrpd.c CreateGroupDataset.java Create dataset in grp.
+
+11 h5_compound.c Compound.java Compound datatype
+12 h5_hyperslab.c Hyperslab.java Selection of hyperslab
+13 h5_copy.c Copy.java Selection of elements
+
diff --git a/doc/html/Tutor/examples/java/readme.html b/doc/html/Tutor/examples/java/readme.html
new file mode 100644
index 0000000..ac96004
--- /dev/null
+++ b/doc/html/Tutor/examples/java/readme.html
@@ -0,0 +1,192 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="GENERATOR" content="Mozilla/4.61 [en] (WinNT; I) [Netscape]">
+ <title>readme</title>
+</head>
+<body text="#000000" bgcolor="#FFFFFF" link="#0000EE" vlink="#551A8B" alink="#FF0000">
+
+<h3>
+<b>HDF 5 Tutorial Examples in Java</b></h3>
+
+<p><br>These files are Java versions of the example programs used in the
+HDF-5 tutoral:
+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://hdf.ncsa.uiuc.edu/training/hdf5/">http://hdf.ncsa.uiuc.edu/training/hdf5/</a>
+<p>The examples here correspond to the examples explained in the first
+13 sections of the tutorial.
+<br>&nbsp;
+<br>&nbsp;
+<table BORDER CELLPADDING=2 WIDTH="100%" >
+<tr>
+<td>
+<center><b>Lesson</b></center>
+</td>
+
+<td>
+<center><b>Topic</b></center>
+</td>
+
+<td>
+<center><b>C file</b></center>
+</td>
+
+<td>
+<center><b>Java file</b></center>
+</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/crtfile.html">Lesson
+4</a></td>
+
+<td>Create an HDF-5 file.</td>
+
+<td>h5_crtfile.c</td>
+
+<td>CreateFile.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/crtdat.html">Lesson
+5</a></td>
+
+<td>Create a Dataset in an HDF-5 file</td>
+
+<td>h5_crtdat.c</td>
+
+<td>CreateDataset.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/rdwt.html">Lesson 6</a></td>
+
+<td>Write and Read data in a dataset</td>
+
+<td>h5_rdwt.c</td>
+
+<td>DatasetRdWt.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/crtatt.html">Lesson
+7</a></td>
+
+<td>Create an attribute.</td>
+
+<td>h5_crtatt.c</td>
+
+<td>CreateAttribute.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/crtgrp.html">Lesson
+8</a></td>
+
+<td>Create a group.</td>
+
+<td>h5_crtgrp.c</td>
+
+<td>CreateGroup.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/crtgrpar.html">Lesson
+9</a></td>
+
+<td>Using Absolute and relative paths</td>
+
+<td>h5_crtgrpar.c</td>
+
+<td>CreateGroupAR.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/crtgrpd.html">Lesson
+10</a></td>
+
+<td>Create a dataset in a group.</td>
+
+<td>h5_crtgrpd.c</td>
+
+<td>CreateGroupDataset.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/compound.html">Lesson
+11</a></td>
+
+<td>Using Compound Datatypes</td>
+
+<td>h5_compound.c</td>
+
+<td>Compound.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/select.html">Lesson
+12</a></td>
+
+<td>Selection of a hyperslab.</td>
+
+<td>h5_hyperslab.c</td>
+
+<td>Hyperslab.java</td>
+</tr>
+
+<tr>
+<td><a href="http://hdf.ncsa.uiuc.edu/training/hdf5/selectc.html">Lesson
+13</a></td>
+
+<td>Selection of elements.</td>
+
+<td>h5_copy.c</td>
+
+<td>Copy.java</td>
+</tr>
+</table>
+
+<p>
+<hr><b>Some Explanation About Tutorial Examples</b>
+<p>The Java tutorial programs try to stay close to the corresponding C
+program. The main function's structure almost same as C program, with one
+call for each HDF5 library function. For example, where the C program has
+a call to <b>H5Fopen()</b>, the Java program has a call to <b>H5Fopen_wrap()</b>.
+<p>The wrapper functions call the HDF-5 library using the Java HDF-5 Interface
+(JHI5). The HDF-5 C interface returns error codes; these are represented
+by Java Exceptions in the JHI5. The wrapper function catches the exception
+and prints a message.
+<p>For example, the <b>H5Fopen_wrap() </b>method calls the JHI5, and catches
+any exceptions which may occur:
+<pre>&nbsp;&nbsp; <b>public static int H5Fopen_wrap (String name, int flags, int access_id)
+&nbsp;&nbsp; {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int file_id = -1;&nbsp;&nbsp;&nbsp; // file identifier&nbsp;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try&nbsp;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Create a new file using default file properties.
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file_id = H5.H5Fopen (name, flags, access_id);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (HDF5Exception hdf5e)
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println&nbsp;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ("DatasetRdWt.H5Fopen_wrap() with HDF5Exception: "
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + hdf5e.getMessage());
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (Exception e)
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println&nbsp;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ("DatasetRdWt.H5Fopen_wrap() with other Exception: "&nbsp;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + e.getMessage());
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return file_id;
+&nbsp;&nbsp; }</b></pre>
+
+<p><br>
+<hr noshade size=1><a href="http://www.ncsa.uiuc.edu/"><img SRC="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif" ALT="NCSA" BORDER=0 ></a>
+<br><font face="arial,helvetica"><font size=-1><a href="http://www.ncsa.uiuc.edu/">The
+National Center for Supercomputing Applications</a></font></font>
+<br><font face="arial,helvetica"><font size=-1><a href="http://www.uiuc.edu/">University
+of Illinois at Urbana-Champaign</a></font></font>
+<p><font face="arial,helvetica"><font size=-1><a href="mailto:hdfhelp@ncsa.uiuc.edu">hdfhelp@ncsa.uiuc.edu</a></font></font>
+</body>
+</html>
diff --git a/doc/html/Tutor/examples/java/runCompound.sh b/doc/html/Tutor/examples/java/runCompound.sh
new file mode 100644
index 0000000..ef2be38
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCompound.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java Compound $*
diff --git a/doc/html/Tutor/examples/java/runCompound.sh.in b/doc/html/Tutor/examples/java/runCompound.sh.in
new file mode 100644
index 0000000..bc58088
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCompound.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ Compound $*
diff --git a/doc/html/Tutor/examples/java/runCopy.sh b/doc/html/Tutor/examples/java/runCopy.sh
new file mode 100644
index 0000000..de71783
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCopy.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java Copy $*
diff --git a/doc/html/Tutor/examples/java/runCopy.sh.in b/doc/html/Tutor/examples/java/runCopy.sh.in
new file mode 100644
index 0000000..2fd8a46
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCopy.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ Copy $*
diff --git a/doc/html/Tutor/examples/java/runCreateAttribute.sh b/doc/html/Tutor/examples/java/runCreateAttribute.sh
new file mode 100644
index 0000000..419abce
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateAttribute.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java CreateAttribute $*
diff --git a/doc/html/Tutor/examples/java/runCreateAttribute.sh.in b/doc/html/Tutor/examples/java/runCreateAttribute.sh.in
new file mode 100644
index 0000000..83bcdc7
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateAttribute.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ CreateAttribute $*
diff --git a/doc/html/Tutor/examples/java/runCreateDataset.sh b/doc/html/Tutor/examples/java/runCreateDataset.sh
new file mode 100644
index 0000000..371e811
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateDataset.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java CreateDataset $*
diff --git a/doc/html/Tutor/examples/java/runCreateDataset.sh.in b/doc/html/Tutor/examples/java/runCreateDataset.sh.in
new file mode 100644
index 0000000..606e153
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateDataset.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ CreateDataset $*
diff --git a/doc/html/Tutor/examples/java/runCreateFile.sh b/doc/html/Tutor/examples/java/runCreateFile.sh
new file mode 100644
index 0000000..e32c0ab
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateFile.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java CreateFile $*
diff --git a/doc/html/Tutor/examples/java/runCreateFile.sh.in b/doc/html/Tutor/examples/java/runCreateFile.sh.in
new file mode 100644
index 0000000..bf48b9c
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateFile.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ CreateFile $*
diff --git a/doc/html/Tutor/examples/java/runCreateFileInput.sh b/doc/html/Tutor/examples/java/runCreateFileInput.sh
new file mode 100644
index 0000000..fa12f06
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateFileInput.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java CreateFileInput $*
diff --git a/doc/html/Tutor/examples/java/runCreateFileInput.sh.in b/doc/html/Tutor/examples/java/runCreateFileInput.sh.in
new file mode 100644
index 0000000..776eac5
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateFileInput.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ CreateFileInput $*
diff --git a/doc/html/Tutor/examples/java/runCreateGroup.sh b/doc/html/Tutor/examples/java/runCreateGroup.sh
new file mode 100644
index 0000000..ee9deee
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateGroup.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java CreateGroup $*
diff --git a/doc/html/Tutor/examples/java/runCreateGroup.sh.in b/doc/html/Tutor/examples/java/runCreateGroup.sh.in
new file mode 100644
index 0000000..e2eadb5
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateGroup.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ CreateGroup $*
diff --git a/doc/html/Tutor/examples/java/runCreateGroupAR.sh b/doc/html/Tutor/examples/java/runCreateGroupAR.sh
new file mode 100644
index 0000000..2619a11
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateGroupAR.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java CreateGroupAR $*
diff --git a/doc/html/Tutor/examples/java/runCreateGroupAR.sh.in b/doc/html/Tutor/examples/java/runCreateGroupAR.sh.in
new file mode 100644
index 0000000..d61d852
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateGroupAR.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ CreateGroupAR $*
diff --git a/doc/html/Tutor/examples/java/runCreateGroupDataset.sh b/doc/html/Tutor/examples/java/runCreateGroupDataset.sh
new file mode 100644
index 0000000..15b7bfa
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateGroupDataset.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java CreateGroupDataset $*
diff --git a/doc/html/Tutor/examples/java/runCreateGroupDataset.sh.in b/doc/html/Tutor/examples/java/runCreateGroupDataset.sh.in
new file mode 100644
index 0000000..af2b4b5
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runCreateGroupDataset.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ CreateGroupDataset $*
diff --git a/doc/html/Tutor/examples/java/runDatasetRdWt.sh b/doc/html/Tutor/examples/java/runDatasetRdWt.sh
new file mode 100644
index 0000000..a049ea8
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runDatasetRdWt.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java DatasetRdWt $*
diff --git a/doc/html/Tutor/examples/java/runDatasetRdWt.sh.in b/doc/html/Tutor/examples/java/runDatasetRdWt.sh.in
new file mode 100644
index 0000000..ad3a049
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runDatasetRdWt.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ DatasetRdWt $*
diff --git a/doc/html/Tutor/examples/java/runHyperSlab.sh b/doc/html/Tutor/examples/java/runHyperSlab.sh
new file mode 100644
index 0000000..549f807
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runHyperSlab.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=/afs/ncsa/projects/hdf/java/java2/mcgrath/arabica/New5
+HDF5LIB=/afs/ncsa/projects/hdf/release/prehdf5-1.2.1/SunOS_5.7/lib
+
+#make this relative to the source root...
+PWD=/afs/ncsa.uiuc.edu/projects/hdf/java/java2/mcgrath/arabica/java-hdf5
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/solaris"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+/usr/java1.2/bin/java HyperSlab $*
diff --git a/doc/html/Tutor/examples/java/runHyperSlab.sh.in b/doc/html/Tutor/examples/java/runHyperSlab.sh.in
new file mode 100644
index 0000000..f515fc9
--- /dev/null
+++ b/doc/html/Tutor/examples/java/runHyperSlab.sh.in
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+JH5INSTALLDIR=@JH5INST@
+HDF5LIB=@HDF5LIB@
+
+#make this relative to the source root...
+PWD=@PWD@
+LIBDIR=$JH5INSTALLDIR"/lib"
+
+CLASSPATH=".:"$LIBDIR"/jhdf5.jar"
+
+LD_LIBRARY_PATH=$HDF5LIB":"$LIBDIR"/@JAVATARG@"
+
+export CLASSPATH
+export LD_LIBRARY_PATH
+
+@JAVA@ HyperSlab $*
diff --git a/doc/html/Tutor/examples/mountexample.f90 b/doc/html/Tutor/examples/mountexample.f90
new file mode 100644
index 0000000..f4341b2
--- /dev/null
+++ b/doc/html/Tutor/examples/mountexample.f90
@@ -0,0 +1,187 @@
+!
+!In the following example we create one file with a group in it,
+!and another file with a dataset. Mounting is used to
+!access the dataset from the second file as a member of a group
+!in the first file.
+!
+
+ PROGRAM MOUNTEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ !
+ ! Filenames are "mount1.h5" and "mount2.h5"
+ !
+ CHARACTER(LEN=9), PARAMETER :: filename1 = "mount1.h5"
+ CHARACTER(LEN=9), PARAMETER :: filename2 = "mount2.h5"
+
+ !
+ !data space rank and dimensions
+ !
+ INTEGER, PARAMETER :: RANK = 2
+ INTEGER, PARAMETER :: NX = 4
+ INTEGER, PARAMETER :: NY = 5
+
+ !
+ ! File identifiers
+ !
+ INTEGER(HID_T) :: file1_id, file2_id
+
+ !
+ ! Group identifier
+ !
+ INTEGER(HID_T) :: gid
+
+ !
+ ! Dataset identifier
+ !
+ INTEGER(HID_T) :: dset_id
+
+ !
+ ! Data space identifier
+ !
+ INTEGER(HID_T) :: dataspace
+
+ !
+ ! Data type identifier
+ !
+ INTEGER(HID_T) :: dtype_id
+
+ !
+ ! The dimensions for the dataset.
+ !
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/NX,NY/)
+
+ !
+ ! Flag to check operation success
+ !
+ INTEGER :: error
+
+ !
+ ! General purpose integer
+ !
+ INTEGER :: i, j
+
+ !
+ ! Data buffers
+ !
+ INTEGER, DIMENSION(NX,NY) :: data_in, data_out
+
+ !
+ ! Initialize FORTRAN interface.
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Initialize data_in buffer
+ !
+ do i = 1, NX
+ do j = 1, NY
+ data_in(i,j) = (i-1) + (j-1)
+ end do
+ end do
+
+ !
+ ! Create first file "mount1.h5" using default properties.
+ !
+ CALL h5fcreate_f(filename1, H5F_ACC_TRUNC_F, file1_id, error)
+
+ !
+ ! Create group "/G" inside file "mount1.h5".
+ !
+ CALL h5gcreate_f(file1_id, "/G", gid, error)
+
+ !
+ ! Close file and group identifiers.
+ !
+ CALL h5gclose_f(gid, error)
+ CALL h5fclose_f(file1_id, error)
+
+ !
+ ! Create second file "mount2.h5" using default properties.
+ !
+ CALL h5fcreate_f(filename2, H5F_ACC_TRUNC_F, file2_id, error)
+
+ !
+ ! Create data space for the dataset.
+ !
+ CALL h5screate_simple_f(RANK, dims, dataspace, error)
+
+ !
+ ! Create dataset "/D" inside file "mount2.h5".
+ !
+ CALL h5dcreate_f(file2_id, "/D", H5T_NATIVE_INTEGER, dataspace, &
+ dset_id, error)
+
+ !
+ ! Write data_in to the dataset
+ !
+ CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data_in, error)
+
+ !
+ ! Close file, dataset and dataspace identifiers.
+ !
+ CALL h5sclose_f(dataspace, error)
+ CALL h5dclose_f(dset_id, error)
+ CALL h5fclose_f(file2_id, error)
+
+ !
+ ! Reopen both files.
+ !
+ CALL h5fopen_f (filename1, H5F_ACC_RDWR_F, file1_id, error)
+ CALL h5fopen_f (filename2, H5F_ACC_RDWR_F, file2_id, error)
+
+ !
+ ! Mount the second file under the first file's "/G" group.
+ !
+ CALL h5fmount_f (file1_id, "/G", file2_id, error)
+
+
+ !
+ ! Access dataset D in the first file under /G/D name.
+ !
+ CALL h5dopen_f(file1_id, "/G/D", dset_id, error)
+
+ !
+ ! Get dataset's data type.
+ !
+ CALL h5dget_type_f(dset_id, dtype_id, error)
+
+ !
+ ! Read the dataset.
+ !
+ CALL h5dread_f(dset_id, dtype_id, data_out, error)
+
+ !
+ ! Print out the data.
+ !
+ do i = 1, NX
+ print *, (data_out(i,j), j = 1, NY)
+ end do
+
+
+ !
+ !Close dset_id and dtype_id.
+ !
+ CALL h5dclose_f(dset_id, error)
+ CALL h5tclose_f(dtype_id, error)
+
+ !
+ ! Unmount the second file.
+ !
+ CALL h5funmount_f(file1_id, "/G", error);
+
+ !
+ ! Close both files.
+ !
+ CALL h5fclose_f(file1_id, error)
+ CALL h5fclose_f(file2_id, error)
+ !
+ ! Close FORTRAN interface.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM MOUNTEXAMPLE
+
diff --git a/doc/html/Tutor/examples/refobjexample.f90 b/doc/html/Tutor/examples/refobjexample.f90
new file mode 100644
index 0000000..fdbb26d
--- /dev/null
+++ b/doc/html/Tutor/examples/refobjexample.f90
@@ -0,0 +1,142 @@
+!
+! This program shows how to create and store references to the objects.
+! Program creates a file, two groups, a dataset to store integer data and
+! a dataset to store references to the objects.
+! Stored references are used to open the objects they are point to.
+! Data is written to the dereferenced dataset, and class type is displayed for
+! the shared datatype.
+!
+ PROGRAM OBJ_REFERENCES
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+ CHARACTER(LEN=10), PARAMETER :: filename = "FORTRAN.h5" ! File
+ CHARACTER(LEN=8), PARAMETER :: dsetnamei = "INTEGERS" ! Dataset with the integer data
+ CHARACTER(LEN=17), PARAMETER :: dsetnamer = "OBJECT_REFERENCES" ! Dataset wtih object
+ ! references
+ CHARACTER(LEN=6), PARAMETER :: groupname1 = "GROUP1" ! Groups in the file
+ CHARACTER(LEN=6), PARAMETER :: groupname2 = "GROUP2" !
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: grp1_id ! Group identifiers
+ INTEGER(HID_T) :: grp2_id !
+ INTEGER(HID_T) :: dset_id ! Dataset identifiers
+ INTEGER(HID_T) :: dsetr_id !
+ INTEGER(HID_T) :: type_id ! Type identifier
+ INTEGER(HID_T) :: space_id ! Dataspace identifiers
+ INTEGER(HID_T) :: spacer_id !
+ INTEGER :: error
+ INTEGER(HSIZE_T), DIMENSION(1) :: dims = (/5/)
+ INTEGER(HSIZE_T), DIMENSION(1) :: dimsr= (/4/)
+ INTEGER(HSIZE_T), DIMENSION(1) :: my_maxdims = (/5/)
+ INTEGER :: rank = 1
+ INTEGER :: rankr = 1
+ TYPE(hobj_ref_t_f), DIMENSION(4) :: ref
+ TYPE(hobj_ref_t_f), DIMENSION(4) :: ref_out
+ INTEGER, DIMENSION(5) :: data = (/1, 2, 3, 4, 5/)
+ INTEGER :: class, ref_size
+ !
+ ! Initialize FORTRAN interface.
+ !
+ CALL h5open_f(error)
+ !
+ ! Create a file
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+ ! Default file access and file creation
+ ! properties are used.
+ !
+ ! Create a group in the file
+ !
+ CALL h5gcreate_f(file_id, groupname1, grp1_id, error)
+ !
+ ! Create a group inside the created gorup
+ !
+ CALL h5gcreate_f(grp1_id, groupname2, grp2_id, error)
+ !
+ ! Create dataspaces for datasets
+ !
+ CALL h5screate_simple_f(rank, dims, space_id, error, maxdims=my_maxdims)
+ CALL h5screate_simple_f(rankr, dimsr, spacer_id, error)
+ !
+ ! Create integer dataset
+ !
+ CALL h5dcreate_f(file_id, dsetnamei, H5T_NATIVE_INTEGER, space_id, &
+ dset_id, error)
+ !
+ ! Create dataset to store references to the objects
+ !
+ CALL h5dcreate_f(file_id, dsetnamer, H5T_STD_REF_OBJ, spacer_id, &
+ dsetr_id, error)
+ !
+ ! Create a datatype and store in the file
+ !
+ CALL h5tcopy_f(H5T_NATIVE_REAL, type_id, error)
+ CALL h5tcommit_f(file_id, "MyType", type_id, error)
+ !
+ ! Close dataspaces, groups and integer dataset
+ !
+ CALL h5sclose_f(space_id, error)
+ CALL h5sclose_f(spacer_id, error)
+ CALL h5tclose_f(type_id, error)
+ CALL h5dclose_f(dset_id, error)
+ CALL h5gclose_f(grp1_id, error)
+ CALL h5gclose_f(grp2_id, error)
+ !
+ ! Create references to two groups, integer dataset and shared datatype
+ ! and write it to the dataset in the file
+ !
+ CALL h5rcreate_f(file_id, groupname1, ref(1), error)
+ CALL h5rcreate_f(file_id, "/GROUP1/GROUP2", ref(2), error)
+ CALL h5rcreate_f(file_id, dsetnamei, ref(3), error)
+ CALL h5rcreate_f(file_id, "MyType", ref(4), error)
+ ref_size = size(ref)
+ CALL h5dwrite_f(dsetr_id, H5T_STD_REF_OBJ, ref, ref_size, error)
+ !
+ ! Close the dataset
+ !
+ CALL h5dclose_f(dsetr_id, error)
+ !
+ ! Reopen the dataset with object references and read references to the buffer
+ !
+ CALL h5dopen_f(file_id, dsetnamer,dsetr_id,error)
+ ref_size = size(ref_out)
+ CALL h5dread_f(dsetr_id, H5T_STD_REF_OBJ, ref_out, ref_size, error)
+ !
+ ! Dereference the third reference. We know that it is a dataset. On practice
+ ! one should use h5rget_object_type_f function to find out
+ ! the type of an object the reference points to.
+ !
+ CALL h5rdereference_f(dsetr_id, ref(3), dset_id, error)
+ !
+ ! Write data to the dataset.
+ !
+ CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, error)
+ if (error .eq. 0) write(*,*) "Data has been successfully written to the dataset "
+ !
+ ! Dereference the fourth reference. We know that it is a datatype. On practice
+ ! one should use h5rget_object_type_f function to find out
+ ! the type of an object the reference points to.
+ !
+ CALL h5rdereference_f(dsetr_id, ref(4), type_id, error)
+ !
+ ! Get datatype class and display it if it is of a FLOAT class.
+ !
+ CALL h5tget_class_f(type_id, class, error)
+ if(class .eq. H5T_FLOAT_F) write(*,*) "Stored datatype is of a FLOAT class"
+ !
+ ! Close all objects.
+ !
+ CALL h5dclose_f(dset_id, error)
+ CALL h5tclose_f(type_id, error)
+ CALL h5dclose_f(dsetr_id, error)
+ CALL h5fclose_f(file_id, error)
+ !
+ ! Close FORTRAN interface.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM OBJ_REFERENCES
+
+
diff --git a/doc/html/Tutor/examples/refregexample.f90 b/doc/html/Tutor/examples/refregexample.f90
new file mode 100644
index 0000000..05fcf3f
--- /dev/null
+++ b/doc/html/Tutor/examples/refregexample.f90
@@ -0,0 +1,162 @@
+!
+! This program shows how to create, store and dereference references
+! to the dataset regions.
+! Program creates a file and writes two dimensional integer dataset
+! to it. Then program creates and stores references to the hyperslab
+! and 3 points selected in the integer dataset, in the second dataset.
+! Program reopens the second dataset, reads and dereferences region
+! references, and then reads and displays selected data from the
+! integer dataset.
+!
+ PROGRAM REG_REFERENCE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+ CHARACTER(LEN=10), PARAMETER :: filename = "FORTRAN.h5"
+ CHARACTER(LEN=6), PARAMETER :: dsetnamev = "MATRIX"
+ CHARACTER(LEN=17), PARAMETER :: dsetnamer = "REGION_REFERENCES"
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: space_id ! Dataspace identifier
+ INTEGER(HID_T) :: spacer_id ! Dataspace identifier
+ INTEGER(HID_T) :: dsetv_id ! Dataset identifier
+ INTEGER(HID_T) :: dsetr_id ! Dataset identifier
+ INTEGER :: error
+ TYPE(hdset_reg_ref_t_f) , DIMENSION(2) :: ref ! Buffers to store references
+ TYPE(hdset_reg_ref_t_f) , DIMENSION(2) :: ref_out !
+ INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/2,9/) ! Datasets dimensions
+ INTEGER(HSIZE_T), DIMENSION(1) :: dimsr = (/2/) !
+ INTEGER(HSSIZE_T), DIMENSION(2) :: start
+ INTEGER(HSIZE_T), DIMENSION(2) :: count
+ INTEGER :: rankr = 1
+ INTEGER :: rank = 2
+ INTEGER , DIMENSION(2,9) :: data
+ INTEGER , DIMENSION(2,9) :: data_out = 0
+ INTEGER(HSSIZE_T) , DIMENSION(2,3) :: coord
+ INTEGER(SIZE_T) ::num_points = 3 ! Number of selected points
+ INTEGER :: i, j
+ INTEGER :: ref_size
+ coord = reshape((/1,1,2,7,1,9/), (/2,3/)) ! Coordinates of selected points
+ data = reshape ((/1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6/), (/2,9/))
+ !
+ ! Initialize FORTRAN interface.
+ !
+ CALL h5open_f(error)
+ !
+ ! Create a new file.
+ !
+ CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
+ ! Default file access and file creation
+ ! properties are used.
+ !
+ ! Create dataspaces:
+ !
+ ! for dataset with references to dataset regions
+ !
+ CALL h5screate_simple_f(rankr, dimsr, spacer_id, error)
+ !
+ ! for integer dataset
+ !
+ CALL h5screate_simple_f(rank, dims, space_id, error)
+ !
+ ! Create and write datasets:
+ !
+ ! Integer dataset
+ !
+ CALL h5dcreate_f(file_id, dsetnamev, H5T_NATIVE_INTEGER, space_id, &
+ dsetv_id, error)
+ CALL h5dwrite_f(dsetv_id, H5T_NATIVE_INTEGER, data, error)
+ CALL h5dclose_f(dsetv_id, error)
+ !
+ ! Dataset with references
+ !
+ CALL h5dcreate_f(file_id, dsetnamer, H5T_STD_REF_DSETREG, spacer_id, &
+ dsetr_id, error)
+ !
+ ! Create a reference to the hyperslab selection.
+ !
+ start(1) = 0
+ start(2) = 3
+ count(1) = 2
+ count(2) = 3
+ CALL h5sselect_hyperslab_f(space_id, H5S_SELECT_SET_F, &
+ start, count, error)
+ CALL h5rcreate_f(file_id, dsetnamev, space_id, ref(1), error)
+ !
+ ! Create a reference to elements selection.
+ !
+ CALL h5sselect_none_f(space_id, error)
+ CALL h5sselect_elements_f(space_id, H5S_SELECT_SET_F, rank, num_points,&
+ coord, error)
+ CALL h5rcreate_f(file_id, dsetnamev, space_id, ref(2), error)
+ !
+ ! Write dataset with the references.
+ !
+ ref_size = size(ref)
+ CALL h5dwrite_f(dsetr_id, H5T_STD_REF_DSETREG, ref, ref_size, error)
+ !
+ ! Close all objects.
+ !
+ CALL h5sclose_f(space_id, error)
+ CALL h5sclose_f(spacer_id, error)
+ CALL h5dclose_f(dsetr_id, error)
+ CALL h5fclose_f(file_id, error)
+ !
+ ! Reopen the file to test selections.
+ !
+ CALL h5fopen_f (filename, H5F_ACC_RDWR_F, file_id, error)
+ CALL h5dopen_f(file_id, dsetnamer, dsetr_id, error)
+ !
+ ! Read references to the dataset regions.
+ !
+ ref_size = size(ref_out)
+ CALL h5dread_f(dsetr_id, H5T_STD_REF_DSETREG, ref_out, ref_size, error)
+ !
+ ! Dereference the first reference.
+ !
+ CALL H5rdereference_f(dsetr_id, ref_out(1), dsetv_id, error)
+ CALL H5rget_region_f(dsetr_id, ref_out(1), space_id, error)
+ !
+ ! Read selected data from the dataset.
+ !
+ CALL h5dread_f(dsetv_id, H5T_NATIVE_INTEGER, data_out, error, &
+ mem_space_id = space_id, file_space_id = space_id)
+ write(*,*) "Hypeslab selection"
+ write(*,*)
+ do i = 1,2
+ write(*,*) (data_out (i,j), j = 1,9)
+ enddo
+ write(*,*)
+ CALL h5sclose_f(space_id, error)
+ CALL h5dclose_f(dsetv_id, error)
+ data_out = 0
+ !
+ ! Dereference the second reference.
+ !
+ CALL H5rdereference_f(dsetr_id, ref_out(2), dsetv_id, error)
+ CALL H5rget_region_f(dsetr_id, ref_out(2), space_id, error)
+ !
+ ! Read selected data from the dataset.
+ !
+ CALL h5dread_f(dsetv_id, H5T_NATIVE_INTEGER, data_out, error, &
+ mem_space_id = space_id, file_space_id = space_id)
+ write(*,*) "Point selection"
+ write(*,*)
+ do i = 1,2
+ write(*,*) (data_out (i,j), j = 1,9)
+ enddo
+ !
+ ! Close all objects
+ !
+ CALL h5sclose_f(space_id, error)
+ CALL h5dclose_f(dsetv_id, error)
+ CALL h5dclose_f(dsetr_id, error)
+ !
+ ! Close FORTRAN interface.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM REG_REFERENCE
+
+
diff --git a/doc/html/Tutor/examples/rwdsetexample.f90 b/doc/html/Tutor/examples/rwdsetexample.f90
new file mode 100644
index 0000000..729e84d
--- /dev/null
+++ b/doc/html/Tutor/examples/rwdsetexample.f90
@@ -0,0 +1,78 @@
+!
+! The following example shows how to write and read to/from an existing dataset.
+! It opens the file created in the previous example, obtains the dataset
+! identifier, writes the data to the dataset in the file,
+! then reads the dataset to memory.
+!
+
+
+ PROGRAM RWDSETEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=8), PARAMETER :: filename = "dsetf.h5" ! File name
+ CHARACTER(LEN=4), PARAMETER :: dsetname = "dset" ! Dataset name
+
+ INTEGER(HID_T) :: file_id ! File identifier
+ INTEGER(HID_T) :: dset_id ! Dataset identifier
+
+ INTEGER :: error ! Error flag
+ INTEGER :: i, j
+
+ INTEGER, DIMENSION(4,6) :: dset_data, data_out ! Data buffers
+
+ !
+ ! Initialize the dset_data array.
+ !
+ do i = 1, 4
+ do j = 1, 6
+ dset_data(i,j) = (i-1)*6 + j;
+ end do
+ end do
+
+ !
+ ! Initialize FORTRAN predefined datatypes
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Open an existing file.
+ !
+ CALL h5fopen_f (filename, H5F_ACC_RDWR_F, file_id, error)
+
+ !
+ ! Open an existing dataset.
+ !
+ CALL h5dopen_f(file_id, dsetname, dset_id, error)
+
+ !
+ ! Write the dataset.
+ !
+ CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, dset_data, error)
+
+ !
+ ! Read the dataset.
+ !
+ CALL h5dread_f(dset_id, H5T_NATIVE_INTEGER, data_out, error)
+
+ !
+ ! Close the dataset.
+ !
+ CALL h5dclose_f(dset_id, error)
+
+ !
+ ! Close the file.
+ !
+ CALL h5fclose_f(file_id, error)
+
+ !
+ ! Close FORTRAN predefined datatypes.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM RWDSETEXAMPLE
+
+
+
diff --git a/doc/html/Tutor/examples/selectele.f90 b/doc/html/Tutor/examples/selectele.f90
new file mode 100644
index 0000000..c75958c
--- /dev/null
+++ b/doc/html/Tutor/examples/selectele.f90
@@ -0,0 +1,282 @@
+!
+! This program creates two files, copy1.h5, and copy2.h5.
+! In copy1.h5, it creates a 3x4 dataset called 'Copy1',
+! and write 0's to this dataset.
+! In copy2.h5, it create a 3x4 dataset called 'Copy2',
+! and write 1's to this dataset.
+! It closes both files, reopens both files, selects two
+! points in copy1.h5 and writes values to them. Then it
+! uses an H5Scopy to write the same selection to copy2.h5.
+! Program reopens the files, and reads and prints the contents of
+! the two datasets.
+!
+
+ PROGRAM SELECTEXAMPLE
+
+ USE HDF5 ! This module contains all necessary modules
+
+ IMPLICIT NONE
+
+ CHARACTER(LEN=8), PARAMETER :: filename1 = "copy1.h5" ! File name
+ CHARACTER(LEN=8), PARAMETER :: filename2 = "copy2.h5" !
+ CHARACTER(LEN=5), PARAMETER :: dsetname1 = "Copy1" ! Dataset name
+ CHARACTER(LEN=5), PARAMETER :: dsetname2 = "Copy2" !
+
+ INTEGER, PARAMETER :: RANK = 2 ! Dataset rank
+
+ INTEGER(SIZE_T), PARAMETER :: NUMP = 2 ! Number of points selected
+
+ INTEGER(HID_T) :: file1_id ! File1 identifier
+ INTEGER(HID_T) :: file2_id ! File2 identifier
+ INTEGER(HID_T) :: dset1_id ! Dataset1 identifier
+ INTEGER(HID_T) :: dset2_id ! Dataset2 identifier
+ INTEGER(HID_T) :: dataspace1 ! Dataspace identifier
+ INTEGER(HID_T) :: dataspace2 ! Dataspace identifier
+ INTEGER(HID_T) :: memspace ! memspace identifier
+
+ INTEGER(HSIZE_T), DIMENSION(1) :: dimsm = (/2/)
+ ! Memory dataspace dimensions
+ INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/3,4/)
+ ! File dataspace dimensions
+ INTEGER(HSSIZE_T), DIMENSION(RANK,NUMP) :: coord ! Elements coordinates
+ ! in the file
+
+ INTEGER, DIMENSION(3,4) :: buf1, buf2, bufnew ! Data buffers
+ INTEGER, DIMENSION(2) :: val = (/53, 59/) ! Values to write
+
+ INTEGER :: memrank = 1 ! Rank of the dataset in memory
+
+ INTEGER :: i, j
+
+ INTEGER :: error ! Error flag
+ LOGICAL :: status
+
+
+ !
+ ! Create two files containing identical datasets. Write 0's to one
+ ! and 1's to the other.
+ !
+
+ !
+ ! Data initialization.
+ !
+ do i = 1, 3
+ do j = 1, 4
+ buf1(i,j) = 0;
+ end do
+ end do
+
+ do i = 1, 3
+ do j = 1, 4
+ buf2(i,j) = 1;
+ end do
+ end do
+
+ !
+ ! Initialize FORTRAN predefined datatypes
+ !
+ CALL h5open_f(error)
+
+ !
+ ! Create file1, file2 using default properties.
+ !
+ CALL h5fcreate_f(filename1, H5F_ACC_TRUNC_F, file1_id, error)
+
+ CALL h5fcreate_f(filename2, H5F_ACC_TRUNC_F, file2_id, error)
+
+ !
+ ! Create the data space for the datasets.
+ !
+ CALL h5screate_simple_f(RANK, dimsf, dataspace1, error)
+
+ CALL h5screate_simple_f(RANK, dimsf, dataspace2, error)
+
+ !
+ ! Create the datasets with default properties.
+ !
+ CALL h5dcreate_f(file1_id, dsetname1, H5T_NATIVE_INTEGER, dataspace1, &
+ dset1_id, error)
+
+ CALL h5dcreate_f(file2_id, dsetname2, H5T_NATIVE_INTEGER, dataspace2, &
+ dset2_id, error)
+
+ !
+ ! Write the datasets.
+ !
+ CALL h5dwrite_f(dset1_id, H5T_NATIVE_INTEGER, buf1, error)
+
+ CALL h5dwrite_f(dset2_id, H5T_NATIVE_INTEGER, buf2, error)
+
+ !
+ ! Close the dataspace for the datasets.
+ !
+ CALL h5sclose_f(dataspace1, error)
+
+ CALL h5sclose_f(dataspace2, error)
+
+ !
+ ! Close the datasets.
+ !
+ CALL h5dclose_f(dset1_id, error)
+
+ CALL h5dclose_f(dset2_id, error)
+
+ !
+ ! Close the files.
+ !
+ CALL h5fclose_f(file1_id, error)
+
+ CALL h5fclose_f(file2_id, error)
+
+ !
+ ! Open the two files. Select two points in one file, write values to
+ ! those point locations, then do H5Scopy and write the values to the
+ ! other file. Close files.
+ !
+
+ !
+ ! Open the files.
+ !
+ CALL h5fopen_f (filename1, H5F_ACC_RDWR_F, file1_id, error)
+
+ CALL h5fopen_f (filename2, H5F_ACC_RDWR_F, file2_id, error)
+
+ !
+ ! Open the datasets.
+ !
+ CALL h5dopen_f(file1_id, dsetname1, dset1_id, error)
+
+ CALL h5dopen_f(file2_id, dsetname2, dset2_id, error)
+
+ !
+ ! Get dataset1's dataspace identifier.
+ !
+ CALL h5dget_space_f(dset1_id, dataspace1, error)
+
+ !
+ ! Create memory dataspace.
+ !
+ CALL h5screate_simple_f(memrank, dimsm, memspace, error)
+
+ !
+ ! Set the selected point positions. Because Fortran array index starts
+ ! from 1, so add one to the actual select points in C.
+ !
+ coord(1,1) = 1
+ coord(2,1) = 2
+ coord(1,2) = 1
+ coord(2,2) = 4
+
+ !
+ ! Select the elements in file space.
+ !
+ CALL h5sselect_elements_f(dataspace1, H5S_SELECT_SET_F, RANK, NUMP,&
+ coord, error)
+
+ !
+ ! Write value into the selected points in dataset1.
+ !
+ CALL H5dwrite_f(dset1_id, H5T_NATIVE_INTEGER, val, error, &
+ mem_space_id=memspace, file_space_id=dataspace1)
+
+ !
+ ! Copy the daspace1 into dataspace2.
+ !
+ CALL h5scopy_f(dataspace1, dataspace2, error)
+
+ !
+ ! Write value into the selected points in dataset2.
+ !
+ CALL H5dwrite_f(dset2_id, H5T_NATIVE_INTEGER, val, error, &
+ mem_space_id=memspace, file_space_id=dataspace2)
+
+ !
+ ! Close the dataspace for the datasets.
+ !
+ CALL h5sclose_f(dataspace1, error)
+
+ CALL h5sclose_f(dataspace2, error)
+
+ !
+ ! Close the memoryspace.
+ !
+ CALL h5sclose_f(memspace, error)
+
+ !
+ ! Close the datasets.
+ !
+ CALL h5dclose_f(dset1_id, error)
+
+ CALL h5dclose_f(dset2_id, error)
+
+ !
+ ! Close the files.
+ !
+ CALL h5fclose_f(file1_id, error)
+
+ CALL h5fclose_f(file2_id, error)
+
+ !
+ ! Open both files and print the contents of the datasets.
+ !
+
+ !
+ ! Open the files.
+ !
+ CALL h5fopen_f (filename1, H5F_ACC_RDWR_F, file1_id, error)
+
+ CALL h5fopen_f (filename2, H5F_ACC_RDWR_F, file2_id, error)
+
+ !
+ ! Open the datasets.
+ !
+ CALL h5dopen_f(file1_id, dsetname1, dset1_id, error)
+
+ CALL h5dopen_f(file2_id, dsetname2, dset2_id, error)
+
+ !
+ ! Read dataset from the first file.
+ !
+ CALL h5dread_f(dset1_id, H5T_NATIVE_INTEGER, bufnew, error)
+
+ !
+ ! Display the data read from dataset "Copy1"
+ !
+ write(*,*) "The data in dataset Copy1 is: "
+ do i = 1, 3
+ print *, (bufnew(i,j), j = 1,4)
+ end do
+
+ !
+ ! Read dataset from the second file.
+ !
+ CALL h5dread_f(dset2_id, H5T_NATIVE_INTEGER, bufnew, error)
+
+ !
+ ! Display the data read from dataset "Copy2"
+ !
+ write(*,*) "The data in dataset Copy2 is: "
+ do i = 1, 3
+ print *, (bufnew(i,j), j = 1,4)
+ end do
+
+ !
+ ! Close datasets.
+ !
+ CALL h5dclose_f(dset1_id, error)
+
+ CALL h5dclose_f(dset2_id, error)
+
+ !
+ ! Close files.
+ !
+ CALL h5fclose_f(file1_id, error)
+
+ CALL h5fclose_f(file2_id, error)
+
+ !
+ ! Close FORTRAN predefined datatypes.
+ !
+ CALL h5close_f(error)
+
+ END PROGRAM SELECTEXAMPLE
diff --git a/doc/html/Tutor/property.html b/doc/html/Tutor/property.html
new file mode 100644
index 0000000..9d40d44
--- /dev/null
+++ b/doc/html/Tutor/property.html
@@ -0,0 +1,169 @@
+<HTML><HEAD>
+<TITLE>HDF5 Tutorial - Property Lists
+</TITLE>
+</HEAD>
+
+<body bgcolor="#ffffff">
+
+<!-- BEGIN MAIN BODY -->
+
+<A HREF="http://www.ncsa.uiuc.edu/"><img border=0
+src="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif"
+width=78 height=27 alt="NCSA"><P></A>
+
+ [ <A HREF="title.html"><I>HDF5 Tutorial Top</I></A> ]
+<H1>
+<BIG><BIG><BIG><FONT COLOR="#c101cd">Property Lists</FONT>
+</BIG></BIG></BIG></H1>
+
+<hr noshade size=1>
+
+<BODY>
+<!--
+<H2>Contents:</H2>
+<UL>
+ <LI> <A HREF="#def">Definition of Property Lists</A>
+</UL>
+<HR>
+<A NAME="def">
+-->
+<P>
+The property list interface provides a mechanism for adding functionality
+to HDF5 calls, without increasing the number of arguments used
+for a given call.
+<P>
+A property list is a collection of values which can
+be passed to various HDF5 functions to control features that
+are typically unimportant or whose default values are usually used
+(by specifying <code>H5P_DEFAULT</code> / <CODE>H5P_DEFAULT_F</CODE>).
+<P>
+It supports unusual cases when:
+
+<UL>
+<LI><A HREF="#cf">Creating Files</A>
+<LI><A HREF="#fa">Accessing Files</A>
+<LI><A HREF="#cd">Creating Datasets</A>
+<LI><A HREF="#rdwt">Reading or Writing Data</A>
+</UL>
+
+
+<A NAME="cf">
+<H3>Creating Files</H3>
+The File Creation property list, H5P_FILE_CREATE, applies to H5Fcreate()
+only and is used to control the file metadata which is maintained in the
+super block of the file. The parameters that can be modified are:
+user-block size, offset and length sizes, symbol table parameters,
+and index storage parameters.
+<P>
+The following example shows how to create a file with 64-bit object
+offsets and lengths:
+<PRE>
+ hid_t create_plist;
+ hid_t file_id;
+
+ create_plist = H5Pcreate(H5P_FILE_CREATE);
+ H5Pset_sizes(create_plist, 8, 8);
+
+ file_id = H5Fcreate("test.h5", H5F_ACC_TRUNC,
+ create_plist, H5P_DEFAULT);
+ .
+ .
+ .
+ H5Fclose(file_id);
+</PRE>
+
+<A NAME="fa">
+<H3>Accessing Files</H3>
+The File Access property list, H5P_FILE_ACCESS, applies to H5Fcreate() and
+H5Fopen() and is used to control different methods of
+performing I/O on files. The different types of I/O are: unbuffered I/O,
+buffered I/O, memory I/O, parallel files using MPI I/O, and data alignment.
+<P>
+Following is an example of using the H5P_FILE_ACCESS property list for creating
+HDF5 files with the metadata and data split into different files:
+<BR> &nbsp; &nbsp; &nbsp;
+[ <A HREF="examples/h5split.c">C program</A> ]
+ - <code>h5split.c</code><BR>
+<P>
+
+<A NAME="cd">
+<h3>Creating Datasets</H3>
+The Dataset Creation property list, H5P_DATASET_CREATE, applies to
+H5Dcreate() and controls information on how raw data
+is organized on disk and how the raw data is compressed. The dataset API
+partitions these terms by layout, compression, and external storage:
+<P>
+<UL>
+ <LI>Layout:
+<UL>
+<LI>H5D_COMPACT: Data is small and can be stored in object header (<I>not
+ implemented yet</I>). This eliminates disk seek/read requests.
+<P>
+<LI>H5D_CONTIGUOUS: (default) The data is large, non-extendible,
+non-compressible, non-sparse, and can be stored externally.
+<P>
+<LI>H5D_CHUNKED: The data is large and can be extended in any dimension.
+It is partitioned into chunks so each chunk is the same logical size.
+Following is an example that uses the H5P_DATASET_CREATE property list to create
+a chunked and extendible dataset:
+<BR> &nbsp; &nbsp; &nbsp;
+[ <A HREF="examples/h5_extend.c">C program</A> ]
+ - <code>h5_extend.c</code><BR>
+<P>
+</UL>
+<LI>Compression: (gzip compression)
+<LI>External Storage Properties: The data must be contiguous to be stored
+ externally. It allows you to store the data in one or more non-HDF5 files.
+Following is an example of using the H5P_DATASET_CREATE property list to
+create a dataset in an external file:
+<BR> &nbsp; &nbsp; &nbsp;
+[ <A HREF="examples/h5_crtextd.c">C program</A> ]
+ - <code>h5_crtextd.c</code><BR>
+<P>
+</UL>
+</UL>
+<A NAME="rdwt">
+<H3>Reading or Writing Data</H3>
+
+The Data Transfer property list, H5P_DATASET_XFER, is used to control
+various aspects of I/O, such as caching hints or collective I/O information.
+<P>
+The following code sets the maximum size for the type conversion buffer
+and background buffer:
+<PRE>
+ plist_xfer = H5Pcreate (H5P_DATASET_XFER);
+ H5Pset_buffer(plist_xfer, (hsize_t)NX*NY*NZ, NULL, NULL);
+ status = H5Dread (dataset, H5T_NATIVE_UCHAR, memspace, dataspace,
+ plist_xfer);
+</PRE>
+See:<BR>
+ [ <A HREF="examples/h5_xfer.c">C program</A> ]
+ - <code> h5_xfer.c</code><BR>
+
+
+<!-- BEGIN FOOTER INFO -->
+
+<P><hr noshade size=1>
+<font face="arial,helvetica" size="-1">
+ <a href="http://www.ncsa.uiuc.edu/"><img border=0
+ src="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif"
+ width=78 height=27 alt="NCSA"><br>
+ The National Center for Supercomputing Applications</A><br>
+ <a href="http://www.uiuc.edu/">University of Illinois
+ at Urbana-Champaign</a><br>
+ <br>
+<!-- <A HREF="helpdesk.mail.html"> -->
+<A HREF="mailto:hdfhelp@ncsa.uiuc.edu">
+hdfhelp@ncsa.uiuc.edu</A>
+<br>
+<BR> <H6>Last Modified: February 12, 2001</H6><BR>
+<!-- modified by Barbara Jones - bljones@ncsa.uiuc.edu -->
+</FONT>
+<BR>
+<!-- <A HREF="mailto:hdfhelp@ncsa.uiuc.edu"> -->
+
+</BODY>
+</HTML>
+
+
+
diff --git a/doc/html/Tutor/software.html b/doc/html/Tutor/software.html
new file mode 100644
index 0000000..9802845
--- /dev/null
+++ b/doc/html/Tutor/software.html
@@ -0,0 +1,88 @@
+<HTML><HEAD>
+<TITLE>HDF5 Tutorial - Obtaining HDF5 Software</TITLE>
+</HEAD>
+
+<body bgcolor="#ffffff">
+
+<!-- BEGIN MAIN BODY -->
+
+<A HREF="http://www.ncsa.uiuc.edu/"><img border=0
+src="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif"
+width=78 height=27 alt="NCSA"><P></A>
+
+ [ <A HREF="title.html"><I>HDF5 Tutorial Top</I></A> ]
+<H1>
+<BIG><BIG><BIG><FONT COLOR="#c101cd">Obtaining HDF5 Software</FONT>
+</BIG></BIG></BIG></H1>
+
+<hr noshade size=1>
+
+<BODY>
+If you will be compiling in:
+<DL>
+<DT><B>C:</B>
+<DD>You will need the HDF5 library. We provide pre-compiled binaries
+for the platforms on which we tested at:
+<BR>&nbsp; &nbsp; &nbsp; &nbsp;
+<A HREF="ftp://ftp.ncsa.uiuc.edu/HDF/HDF5/current/bin/">ftp://ftp.ncsa.uiuc.edu/HDF/HDF5/current/bin/</A>
+<P>
+If using the pre-compiled binaries you must
+also obtain the GZIP library, as they were compiled with GZIP included, but do
+not include this library. We provide the GZIP library for the platforms on
+which we tested at:
+<BR>&nbsp; &nbsp; &nbsp; &nbsp;
+<A HREF="ftp://ftp.ncsa.uiuc.edu/HDF/gzip/">ftp://ftp.ncsa.uiuc.edu/HDF/gzip/</A>
+<P>
+You can build the HDF5 library yourself, if need be. The source code
+can be obtained from:
+<BR>&nbsp; &nbsp; &nbsp; &nbsp;
+<A HREF="ftp://ftp.ncsa.uiuc.edu/HDF/HDF5/current/src/">ftp://ftp.ncsa.uiuc.edu/HDF/HDF5/current/src/</A>
+<P>
+For further information regarding HDF5, check the HDF5 home page:
+<BR>&nbsp; &nbsp; &nbsp; &nbsp;
+<A HREF="http://hdf.ncsa.uiuc.edu/HDF5/">http://hdf.ncsa.uiuc.edu/HDF5/</A>
+<P>
+<DT><B>FORTRAN 90:</B>
+<DD> With HDF5-1.4.0, support for Fortran 90 is included as part of
+the installation of the HDF5 library. The pre-compiled binaries include
+the Fortran library. If you need to build from source, download the
+HDF5-1.4.0 source code and compile it with the <I>--enable-fortran</I> flag.
+Read the instructions in the
+<A HREF="ftp://ftp.ncsa.uiuc.edu/HDF/HDF5/current/src/unpacked/RELEASE.txt">RELEASE.txt</A>
+file for further details.
+
+<P>
+<DT><B>Java:</B>
+<DD>You will need the JHI5 code. Go to the
+<A HREF="http://hdf.ncsa.uiuc.edu/java-hdf5-html">Java HDF5 web page</A>
+for information on the Java-HDF5 software. The Java Tutorial examples
+are included with this tutorial:
+<BR>&nbsp; &nbsp; &nbsp; &nbsp;
+ <A HREF="./examples/java/">./examples/java/</A>
+</DL>
+
+
+<!-- BEGIN FOOTER INFO -->
+
+<P><hr noshade size=1>
+<font face="arial,helvetica" size="-1">
+ <a href="http://www.ncsa.uiuc.edu/"><img border=0
+ src="http://www.ncsa.uiuc.edu/Images/NCSAhome/footerlogo.gif"
+ width=78 height=27 alt="NCSA"><br>
+ The National Center for Supercomputing Applications</A><br>
+ <a href="http://www.uiuc.edu/">University of Illinois
+ at Urbana-Champaign</a><br>
+ <br>
+<!-- <A HREF="helpdesk.mail.html"> -->
+<A HREF="mailto:hdfhelp@@ncsa.uiuc.edu">
+hdfhelp@@ncsa.uiuc.edu</A>
+<BR> <H6>Last Modified: March 8, 2001</H6><BR>
+<!-- modified by Barbara Jones - bljones@@ncsa.uiuc.edu -->
+<!-- modified by Frank Baker - fbaker@@ncsa.uiuc.edu -->
+</FONT>
+<BR>
+<!-- <A HREF="mailto:hdfhelp@@ncsa.uiuc.edu"> -->
+
+</BODY>
+</HTML>
+
diff --git a/tools/h4toh5/h4toh5pal.c b/tools/h4toh5/h4toh5pal.c
new file mode 100644
index 0000000..bf90acd
--- /dev/null
+++ b/tools/h4toh5/h4toh5pal.c
@@ -0,0 +1,202 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+Converting an hdf4 palette object into a hdf5 dataset.
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
+#include "h4toh5main.h"
+
+
+/*-------------------------------------------------------------------------
+ * Function: Palette_h4_to_h5
+ *
+ * Purpose: translate palette into hdf5 dataset
+ *
+ * Return: FAIL if failed, SUCCEED if successful.
+ *
+ * In :
+ file_id: file id
+ pal_id: PALETTE identifier
+ h5_g: hdf5 group id
+ pal_name: path name of the group where all palettes are in
+
+ *-------------------------------------------------------------------------
+ */
+
+int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name) {
+
+ int32 ncomp;
+ int32 pal_ref;
+ int32 pal_type;
+ int32 interlace_mode;
+ int32 num_entries;
+ void* pal_data;
+ size_t h4memsize;
+ size_t h4size;
+
+ char palette_label[MAX_PAL_NAME];
+ char palette_class[MAX_PAL_NAME];
+ char palette_type[MAX_PAL_NAME];
+ char palette_colormodel[MAX_PAL_NAME];
+
+ hid_t h5memtype;
+ hid_t h5type;
+ hid_t h5d_sid;
+ hid_t h5dset;
+ hsize_t h5dims[2];
+
+ pal_ref = GRluttoref(pal_id);
+
+ if(pal_ref <0) {
+ printf("error in obtaining palette.\n");
+ return FAIL;
+ }
+
+ /* no palette, just return. */
+ if(pal_ref == 0) return SUCCEED;
+
+ if(GRgetlutinfo(pal_id,&ncomp,&pal_type,&interlace_mode,&num_entries)==FAIL) {
+ printf("error in getting palette information.\n");
+ return FAIL;
+ }
+
+ if(h4type_to_h5type(pal_type,&h5memtype,&h4memsize,&h4size,&h5type)== FAIL) {
+ fprintf(stderr,"failed to translate image datatype. \n");
+ return FAIL;
+ }
+
+ /* according to mapping document, data type for palette will always be
+ uint8. */
+
+ if (h5type == H5T_STRING) {
+ if(h5string_to_int(pal_type,&h5memtype,h4memsize,&h5type)==FAIL) {
+ fprintf(stderr,"failed to translate H5T_STRING to int8.");
+ return FAIL;
+ }
+ }
+
+ h5dims[0] = num_entries;
+ h5dims[1] = ncomp;
+
+ pal_data = malloc(h4memsize*ncomp*num_entries);
+
+ if (pal_data == NULL) {
+ printf("error in allocating memory for palette data.\n");
+ return FAIL;
+ }
+
+ if (GRreadlut(pal_id,(VOIDP)pal_data)==FAIL) {
+ printf("error in reading palette data. \n");
+ free(pal_data);
+ return FAIL;
+ }
+
+ h5d_sid = H5Screate_simple(2,h5dims,NULL);
+
+ if (h5d_sid <0) {
+ printf("error in creating space.\n");
+ free(pal_data);
+ return FAIL;
+ }
+
+ h5dset = H5Dcreate(h5g,pal_name,h5type,h5d_sid,H5P_DEFAULT);
+
+ if (h5dset < 0) {
+ printf("error in creating dataset. \n");
+ free(pal_data);
+ H5Sclose(h5d_sid);
+ return FAIL;
+ }
+
+ if (H5Dwrite(h5dset,h5memtype,h5d_sid,h5d_sid,H5P_DEFAULT,
+ (void *)pal_data)<0) {
+ fprintf(stdout,"error writing data for palette data\n");
+ free(pal_data);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+ free(pal_data);
+
+
+ strcpy(palette_label,PALABEL);
+ strcpy(palette_class,PALETTE);
+ strcpy(palette_type,PAL_TYPE);
+ strcpy(palette_colormodel,HDF5_RGB);
+ /* convert palette annotation into attribute of palette dataset.
+ Since there are no routines to find the exact tag of palette object,
+ we will check three possible object tags of palette objects, that is:
+ DFTAG_LUT. If the object tag of palette object is
+ falling out of this scope, we will not convert annotations into
+ hdf5 attributes; it is user's responsibility to make sure that object tags
+ for palette objects are DFTAG_LUT.*/
+
+ if(Annoobj_h4_to_h5(file_id,pal_ref,DFTAG_LUT,h5dset)== FAIL){
+ printf("failed to convert palette annotation into hdf5 attribute.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+
+ if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,palette_label)==FAIL) {
+ printf("unable to transfer palette label to HDF4 OBJECT TYPE.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+
+ if(h4_transpredattrs(h5dset,HDF4_PALETTE_CLASS,palette_class)==FAIL){
+ printf("unable to transfer palette class to HDF4 PALETTE CLASS.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+
+ if(h4_transpredattrs(h5dset,HDF4_PALETTE_TYPE,palette_type)==FAIL){
+ printf("unable to transfer palette type to HDF4 PALETTE TYPE.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+
+ if(h4_transpredattrs(h5dset,PAL_COLORMODEL,palette_colormodel)==FAIL){
+ printf("unable to transfer palette type to HDF4 PALETTE TYPE.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+ if(h4_transnumattr(h5dset,HDF4_REF_NUM,pal_ref)==FAIL) {
+ printf("unable to transfer palette reference number to HDF4 REF. NUM.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+ return SUCCEED;
+}
+
+
+
+
+
diff --git a/tools/h4toh5/h4toh5test.c b/tools/h4toh5/h4toh5test.c
new file mode 100644
index 0000000..333d49f
--- /dev/null
+++ b/tools/h4toh5/h4toh5test.c
@@ -0,0 +1,3946 @@
+/*** this code is to generate various hdf files to test h4toh5 converter and h4toh5 lib API. The code itself is NOT optimizied but try to consider various cases that examine how converter works. */
+
+#include "hdf.h"
+#include "mfhdf.h"
+#include <stdio.h>
+
+
+#define FILESDS1 "sds_typ_test.hdf"
+#define FILESDS2 "sds_dim_test.hdf"
+#define FILESDS3 "sds_attr_test.hdf"
+#define FILEGR "gr_typ_test.hdf"
+#define FILERAS8 "ras_8_test.hdf"
+#define FILERAS24 "ras_24_test.hdf"
+#define FILEGRPAL "image_attr_test.hdf"
+#define FILEVD "vdata_test.hdf"
+#define FILECLASHVG "vgnameclash_test.hdf"
+#define FILECLASHSDS "sdsnameclash_test.hdf"
+#define FILECLASHVD "vdnameclash_test.hdf"
+#define FILECLASHGR "grnameclash_test.hdf"
+#define FILELOOP "vg_loop_test.hdf"
+#define FILEHL "vg_hl_test.hdf"
+#define FILEVG "vg_all_test.hdf"
+#define FILEANNO "anno_test.hdf"
+
+/* for testing sds*/
+#define TYP_RANK 3
+#define TYP_DIMSIZE 4
+#define INT8_UPLIMIT 0x7E
+#define UINT8_UPLIMIT 0xFC
+#define INT16_UPLIMIT 0x7FFE
+#define UINT16_UPLIMIT 0xFFFC
+#define INT32_UPLIMIT 0x7FFFFFFE
+#define UINT32_UPLIMIT 0xFFFFFFFC
+#define ATT_SIZE 10
+
+/* for testing image*/
+#define X_LENGTH 10
+#define Y_LENGTH 5
+#define NUM_COLORS 256
+#define F_ATT1_NAME "File Attribute"
+#define RI_ATT1_NAME "Image Attribute"
+#define F_ATT1_VAL "Contents of First FILE Attribute"
+#define F_ATT1_N_VALUES 32
+#define RI_ATT1_VAL "Contents of IMAGE's First Attribute"
+#define RI_ATT1_N_VALUES 35
+
+/* for testing vdata*/
+#define NRECORDS 10
+#define FIELD_1 "Temp"
+#define FIELD_2 "Height"
+#define FIELD_3 "Speed"
+#define FIELD_4 "Ident"
+#define FIELD_5 "Position"
+#define FIELD_NAMES "Temp,Height,Speed,Ident,Position"
+#define FIELD_VDNAMES "Temp,Height"
+
+/*for testing vgroup*/
+#define VGATTR_NAME "Vgroup attribute 1"
+int test_sdstyp(void);
+int test_sdsdim(void);
+int test_sdsattr(void);
+int test_grtyp(void);
+int test_ras8(void);
+int test_ras24(void);
+int test_imageattr(void);
+int test_vdata(void);
+int test_vgnameclash(void);
+int test_sdsnameclash(void);
+int test_grnameclash(void);
+int test_vdnameclash(void);
+int test_vgloop(void);
+int test_vghl(void);
+int test_vgall(void);
+int test_anno(void);
+
+int main(void) {
+ if(test_sdstyp()== FAIL) {
+ printf("failed to create sds_typ_test.hdf file.\n");
+ return FAIL;
+ }
+ if(test_sdsdim()== FAIL) {
+ printf("failed to create sds_dim_test.hdf file. \n");
+ return FAIL;
+ }
+ if(test_sdsattr()== FAIL) {
+ printf("failed to create sds_attr_test.hdf file. \n");
+ return FAIL;
+ }
+ if(test_grtyp()==FAIL) {
+ printf("failed to create gr_typ_test.hdf file. \n");
+ return FAIL;
+ }
+
+ if(test_ras8()==FAIL) {
+ printf("failed to create ras8_test.hdf file.\n");
+ return FAIL;
+ }
+
+ if(test_ras24()==FAIL) {
+ printf("failed to create ras24_test.hdf file.\n");
+ return FAIL;
+ }
+
+ if(test_imageattr()== FAIL) {
+ printf("failed to create image_attr_test.hdf file.\n");
+ return FAIL;
+ }
+
+ if(test_vdata()== FAIL) {
+ printf("failed to create vdata_test.hdf file.\n");
+ return FAIL;
+ }
+
+ if(test_vgnameclash()==FAIL) {
+ printf("failed to create vg_nameclash.hdf file.\n");
+ return FAIL;
+ }
+
+ if(test_sdsnameclash()==FAIL) {
+ printf("failed to create sds_nameclash.hdf file.\n");
+ return FAIL;
+ }
+
+ if(test_grnameclash()==FAIL) {
+ printf("failed to create gr_nameclash.hdf file. \n");
+ return FAIL;
+ }
+
+ if(test_vdnameclash()==FAIL) {
+ printf("failed to create vd_nameclash.hdf file.\n");
+ return FAIL;
+ }
+ if(test_vgloop()==FAIL) {
+ printf("failed to create vg_loop.hdf file. \n");
+ return FAIL;
+ }
+ if(test_vghl()==FAIL) {
+ printf("failed to create vg_hl.hdf file. \n");
+ return FAIL;
+ }
+ if(test_vgall()==FAIL) {
+ printf("failed to create vg_all.hdf file. \n");
+ return FAIL;
+ }
+ if(test_anno()==FAIL) {
+ printf("failed to create vg_anno.hdf file. \n");
+ return FAIL;
+ }
+ return 0;
+}
+
+/* this subroutine will hdf file with typical sds objects,
+
+ The rank is TYP_RANK, each dimensional size is TYP_DIMSIZE.
+ Datatype we are testing is:
+ char,
+ int8,
+ int16,
+ int32,
+ uint16,
+ uint32,
+ lint16,
+ lint32,
+ luint32,
+ float32,
+ float64,
+
+*/
+int test_sdstyp(){
+
+ int32 file_id,sds_id;
+ int32 i,j,k;
+ int32 typ_start[TYP_RANK],typ_edges[TYP_RANK],typ_stride[TYP_RANK];
+ char8 typchar_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int8 typint8_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int16 typint16_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int32 typint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ uint16 typuint16_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int32 typlint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ uint32 typluint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ float32 typfloat32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ float64 typfloat64_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ float64 typlfloat64_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int32 typ_dims[TYP_RANK];
+ int32 CUB_SIZE;
+ int istat;
+ /* TYPICAL sds array, we limit the dimensional size for testing purpose. */
+
+ CUB_SIZE = (TYP_DIMSIZE-1)*(TYP_DIMSIZE-1)*(TYP_DIMSIZE-1);
+
+ /* 1. data type is char */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++){
+ typchar_array[i][j][k]=(char) (i+j+k);
+ }
+
+ /* data type is int8 */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typint8_array[i][j][k]= (int8)(INT8_UPLIMIT-i*j*k*2/CUB_SIZE*INT8_UPLIMIT +1);
+
+ /* data type is int16 */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typint16_array[i][j][k]= (int16)(INT16_UPLIMIT-i*j*k*2/CUB_SIZE*INT16_UPLIMIT +1);
+
+ /* data type is uint16 */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typuint16_array[i][j][k]= (uint16)(UINT16_UPLIMIT-i*j*k*2/CUB_SIZE*(UINT16_UPLIMIT/2)+1);
+
+ /* data type is int32 */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typint32_array[i][j][k]= INT32_UPLIMIT-i*j*k*2/CUB_SIZE*INT32_UPLIMIT +1;
+
+ /*data type is little-endian int32*/
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typlint32_array[i][j][k]= INT32_UPLIMIT-i*j*k*2/CUB_SIZE*INT32_UPLIMIT +1;
+
+ /* data type is unsigned little-endian int32*/
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typluint32_array[i][j][k]= (uint32)(UINT32_UPLIMIT-i*j*k/CUB_SIZE*UINT32_UPLIMIT+1);
+
+ /* data type is float32 */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typfloat32_array[i][j][k]= 1.0+i+j+k;
+
+ /* data type is float64 */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typfloat64_array[i][j][k]= 1.0+i+j+k;
+
+ /* data type is lfloat64 */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typlfloat64_array[i][j][k]= 1.0+i+j+k;
+
+ for(i=0;i<TYP_RANK;i++){
+ typ_dims[i] = TYP_DIMSIZE;
+ typ_start[i] = 0;
+ typ_edges[i] = TYP_DIMSIZE;
+ typ_stride[i] = 1;
+ }
+
+ file_id = SDstart(FILESDS1,DFACC_CREATE);
+
+ if(file_id == FAIL) {
+ printf (" open file failed\n");
+ return FAIL;
+ }
+
+ /* we also test different dimensional scale setting for typical array. */
+ sds_id = SDcreate(file_id,"sds_char",DFNT_CHAR8,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typchar_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_int8",DFNT_INT8,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typint8_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_int16",DFNT_INT16,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typint16_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_int32",DFNT_INT32,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typint32_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_uint16",DFNT_UINT16,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typuint16_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_lint32",DFNT_LINT32,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typlint32_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_luint32",DFNT_LUINT32,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typluint32_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_float32",DFNT_FLOAT32,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typfloat32_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_float64",DFNT_FLOAT64,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typfloat64_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(file_id,"sds_lfloat64",DFNT_LFLOAT64,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typlfloat64_array);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+ SDend(file_id);
+ return 0;
+}
+/* generating a hdf file with sds dimensional scale dataset in it.
+ both limited and unlimited dimensions are provided.*/
+int test_sdsdim() {
+
+ int32 file_id,sds_id,dim_id;
+ int32 i,j,k;
+ int32 typ_start[TYP_RANK],typ_edges[TYP_RANK],typ_stride[TYP_RANK];
+ int32 typ_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int32 typ_dims[TYP_RANK];
+ int32 dim_sca0[TYP_DIMSIZE];
+ int32 istat;
+
+ char dim_name0[] = "dim0";
+ char dim_name1[] = "dim1";
+ char dim_name2[] = "dim2";
+
+ char unldim_name0[] ="unldim0";
+ char unldim_name1[]="unldim1";
+ char unldim_name2[]="unldim2";
+
+ /* typical sds array. */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typ_array[i][j][k] = i+j+k;
+
+ for (i=0;i<TYP_DIMSIZE;i++)
+ dim_sca0[i] = i;
+
+
+ for(i=0;i<TYP_RANK;i++){
+ typ_dims[i] = TYP_DIMSIZE;
+ typ_start[i] = 0;
+ typ_edges[i] = TYP_DIMSIZE;
+ typ_stride[i] = 1;
+ }
+
+ file_id = SDstart(FILESDS2,DFACC_CREATE);
+
+ if(file_id == FAIL){
+ printf (" open file failed\n");
+ return FAIL;
+ }
+
+ /* testing for normal dimensional scale dataset. */
+ sds_id = SDcreate(file_id,"sds_dimnor",DFNT_INT32,TYP_RANK,typ_dims);
+
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+
+
+ istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typ_array);
+
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+
+ for (i =0;i<TYP_RANK;i++){
+ dim_id = SDgetdimid(sds_id,i);
+
+ if(dim_id == FAIL) {
+ printf("failed to generate dimensional id.\n");
+ return FAIL;
+ }
+
+ switch(i) {
+
+ case 0:
+ istat = SDsetdimname(dim_id,dim_name0);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat =SDsetdimscale(dim_id,typ_dims[0],DFNT_INT32,(VOIDP)dim_sca0);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ break;
+ case 1:
+ istat = SDsetdimname(dim_id,dim_name1);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat = SDsetdimscale(dim_id,typ_dims[1],DFNT_INT32,(VOIDP)dim_sca0);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ break;
+ case 2:
+ istat = SDsetdimname(dim_id,dim_name2);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat = SDsetdimscale(dim_id,typ_dims[2],DFNT_INT32,(VOIDP)dim_sca0);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ break;
+ }
+
+ }
+ SDendaccess(sds_id);
+
+ /* for unlimited dimensional scale data. */
+
+ typ_dims[0] = SD_UNLIMITED;
+
+ sds_id = SDcreate(file_id,"sds_dimunl",DFNT_INT32,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+
+ istat =SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typ_array);
+ if(istat == FAIL) {
+ printf("failed to write sds object. \n");
+ return FAIL;
+ }
+ for (i =0;i<TYP_RANK;i++){
+ dim_id = SDgetdimid(sds_id,i);
+ if(dim_id == FAIL) {
+ printf("failed to generate dimensional id.\n");
+ return FAIL;
+ }
+ switch(i) {
+
+ case 0:
+ istat= SDsetdimname(dim_id,unldim_name0);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ /* SDsetdimscale(dim_id,typ_dims[0],DFNT_INT32,(VOIDP)dim_sca0);*/
+ istat= SDsetdimscale(dim_id,TYP_DIMSIZE,DFNT_INT32,(VOIDP)dim_sca0);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ break;
+ case 1:
+ istat= SDsetdimname(dim_id,unldim_name1);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat = SDsetdimscale(dim_id,typ_dims[1],DFNT_INT32,(VOIDP)dim_sca0);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ break;
+ case 2:
+ istat = SDsetdimname(dim_id,unldim_name2);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat = SDsetdimscale(dim_id,typ_dims[2],DFNT_INT32,(VOIDP)dim_sca0);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ break;
+ }
+ }
+ SDendaccess(sds_id);
+
+ SDend(file_id);
+ return 0;
+}
+
+/* a hdf file that includes sds predefined attributes, dimensional
+ scale attributes and chunking and compress information*/
+int test_sdsattr() {
+
+ int32 file_id,sds_id,dim_id;
+ int32 i,j,k,comp_flag;
+ int32 typ_start[TYP_RANK],typ_edges[TYP_RANK],typ_stride[TYP_RANK];
+ int32 typ_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int32 typ_dims[TYP_RANK];
+ int32 fill_value;
+ int32 dim_sca0[TYP_DIMSIZE],dim_sca1[TYP_DIMSIZE];
+
+ HDF_CHUNK_DEF c_def;
+ int32 comp_type;
+ comp_info c_info;
+ int32 istat;
+ float64 cal;
+ float64 cal_err;
+ float64 offset;
+ float64 offset_err;
+
+ char* attr_value;
+ char* gloattr_value;
+ char label[] = "sds.label";
+ char unit[] = "sds.unit";
+ char format[] = "sds.format";
+ char coordsys[] = "sds.coord";
+
+ char dim_name0[] ="dim0";
+ char dim_name1[] ="dim1";
+ char dim_label[] ="dim.label";
+ char dim_unit[] ="dim.unit";
+ char dim_format[] ="dim.format";
+
+ /**** initial setting. ****/
+ cal = 1.0;
+ cal_err = 0.0;
+ offset = 0.0;
+ offset_err = 0.0;
+ fill_value = 999;
+
+
+ /* typical sds array. */
+ for (i=0;i<TYP_DIMSIZE;i++)
+ for (j=0;j<TYP_DIMSIZE;j++)
+ for (k=0;k<TYP_DIMSIZE;k++)
+ typ_array[i][j][k]= i+j+k;
+
+ attr_value = malloc(ATT_SIZE*sizeof(char));
+ if(attr_value == NULL) {
+ printf("failed to allocate memory. \n");
+ return FAIL;
+ }
+
+ gloattr_value = malloc(ATT_SIZE*sizeof(char));
+ if(gloattr_value == NULL) {
+ printf("failed to allocate memory. \n");
+ return FAIL;
+ }
+
+ strcpy(gloattr_value,"glo attr");
+ strcpy(attr_value,"test attr");
+
+ for(i=0;i<TYP_RANK;i++){
+ typ_dims[i] = TYP_DIMSIZE;
+ typ_start[i] = 0;
+ typ_edges[i] = TYP_DIMSIZE;
+ typ_stride[i] = 1;
+ }
+
+ for (i=0;i<TYP_DIMSIZE;i++){
+ dim_sca0[i] = i;
+ dim_sca1[i] = 2*i;
+ }
+ file_id = SDstart(FILESDS3,DFACC_CREATE);
+
+ if(file_id == FAIL) {
+ printf (" open file failed\n");
+ return FAIL;
+ }
+
+ istat = SDsetattr(file_id,"sds.gloattr",DFNT_CHAR8,10,(VOIDP)gloattr_value);
+ if(istat == FAIL) {
+ printf("failed to set attribute.\n");
+ return FAIL;
+ }
+
+ istat = SDsetfillmode(file_id,SD_NOFILL);
+
+ if (istat == FAIL) {
+ printf("error setting fill mode\n");
+ return FAIL;
+ }
+
+ sds_id = SDcreate(file_id,"sds_attr",DFNT_INT32,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+
+ istat = SDsetfillvalue(sds_id,(VOIDP)(&fill_value));
+ if (istat == FAIL){
+ printf("error setting fill value\n");
+ return FAIL;
+ }
+
+ istat = SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typ_array);
+
+ if(istat == FAIL) {
+ printf("failed to write sds data.\n");
+ return FAIL;
+ }
+ /*** write dataset attribute ***/
+
+ istat = SDsetattr(sds_id,"sds.attr",DFNT_CHAR8,10,(VOIDP)attr_value);
+ if(istat == FAIL) {
+ printf(" sds data attr. setting failed. \n");
+ return FAIL;
+ }
+ /*** write dataset predefined attribute ***/
+
+ istat = SDsetdatastrs(sds_id,label,unit,format,coordsys);
+ if(istat == FAIL) {
+ printf(" sds data predefined attr. setting failed. \n");
+ return FAIL;
+ }
+ /*** set calibration information. ***/
+
+ istat = SDsetcal(sds_id,cal,cal_err,offset,offset_err,DFNT_INT32);
+ if(istat == FAIL) {
+ printf(" sds data calibrating attr. setting failed. \n");
+ return FAIL;
+ }
+ for (i =0; i<TYP_RANK;i++) {
+ dim_id = SDgetdimid(sds_id,i);
+ if(dim_id == FAIL) {
+ printf("sds set dim id failed. \n");
+ return FAIL;
+ }
+ if (i==0) {
+ istat = SDsetdimname(dim_id,dim_name0);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat=SDsetdimscale(dim_id,typ_dims[0],DFNT_INT32,(VOIDP)dim_sca0);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ }
+ else {
+ istat = SDsetdimname(dim_id,dim_name1);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat = SDsetdimscale(dim_id,typ_dims[1],DFNT_INT32,(VOIDP)dim_sca1);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ }
+
+ istat = SDsetdimstrs(dim_id,dim_label,dim_unit,dim_format);
+ if(istat == FAIL) {
+ printf("sds set dim. predefined attr. failed. \n");
+ return FAIL;
+ }
+ istat = SDsetattr(dim_id,"sdsdim.attr",DFNT_CHAR8,10,(VOIDP)attr_value);
+
+ if(istat == FAIL) {
+ printf(" sds dim data attr. setting failed. \n");
+ return FAIL;
+ }
+ SDendaccess(dim_id);
+ }
+
+ SDendaccess(sds_id);
+
+
+ sds_id = SDcreate(file_id,"sds_compress",DFNT_INT32,TYP_RANK,typ_dims);
+ if(sds_id == FAIL) {
+ printf("failed to create object.\n");
+ return FAIL;
+ }
+ comp_type = COMP_CODE_DEFLATE;
+ c_info.deflate.level = 3;
+
+ c_def.comp.chunk_lengths[0] = 2;
+ c_def.comp.chunk_lengths[1] = 2;
+ c_def.comp.chunk_lengths[2] = 2;
+ c_def.comp.comp_type = COMP_CODE_DEFLATE;
+
+ comp_flag = HDF_CHUNK;
+
+ c_def.comp.cinfo.deflate.level = 3;
+
+ istat = SDsetchunk(sds_id,c_def,comp_flag);
+ if(istat == FAIL) {
+ printf("chunking is not setting properly. \n");
+ return FAIL;
+ }
+
+
+ istat = SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typ_array);
+ if(istat == FAIL) {
+ printf("SDS cannot write chunking and compression mode. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ SDend(file_id);
+ free(attr_value);
+ free(gloattr_value);
+ return 0;
+}
+
+/***** routines for generating gr datatype hdf testing file.
+ we are only generating one and three components for
+ datatype
+ uint32 and int16. ****/
+int test_grtyp() {
+
+ int32 gr_id, ri_id, file_id, il;
+ int32 ncomp;
+ int32 start[2], edges[2],dims[2];
+ uint32 image_data32[Y_LENGTH][X_LENGTH][3];
+ uint32 image_data321[Y_LENGTH][X_LENGTH];
+ int16 image_data16[Y_LENGTH][X_LENGTH][3];
+ int16 image_data161[Y_LENGTH][X_LENGTH];
+ intn i, j;
+ int32 CUB_SIZE;
+ int istat;
+
+ CUB_SIZE = (X_LENGTH-1)*(Y_LENGTH-1);
+
+ /* 3-component GR image data type UINT32*/
+ for (j = 0; j < Y_LENGTH; j++) {
+ for (i = 0; i < X_LENGTH; i++) {
+ image_data32[j][i][0] = UINT32_UPLIMIT - i*j*0/CUB_SIZE*(UINT32_UPLIMIT/2)+1;
+ image_data32[j][i][1] = UINT32_UPLIMIT - i*j*1/CUB_SIZE*(UINT32_UPLIMIT/2)+1;
+ image_data32[j][i][2] = UINT32_UPLIMIT - i*j*2/CUB_SIZE*(UINT32_UPLIMIT/2)+1;
+
+ }
+ }
+
+ /* 3-component GR image data type int16*/
+ for (j = 0; j < Y_LENGTH; j++) {
+ for (i = 0; i < X_LENGTH; i++) {
+ image_data16[j][i][0] = INT16_UPLIMIT - i*j*0/CUB_SIZE*(INT16_UPLIMIT/2)+1;
+ image_data16[j][i][1] = INT16_UPLIMIT - i*j*1/CUB_SIZE*(INT16_UPLIMIT/2)+1;
+ image_data16[j][i][2] = INT16_UPLIMIT - i*j*2/CUB_SIZE*(INT16_UPLIMIT/2)+1;
+
+ }
+ }
+
+ /* 1-component GR image data type uint32 */
+ for (j = 0; j < Y_LENGTH; j++)
+ for (i = 0; i < X_LENGTH; i++)
+ image_data321[j][i] = UINT32_UPLIMIT - i*j/CUB_SIZE*UINT32_UPLIMIT+1;
+
+ /* 1-component GR image data type int16*/
+ for (j = 0; j < Y_LENGTH; j++)
+ for (i = 0; i < X_LENGTH; i++)
+ image_data161[j][i] = INT16_UPLIMIT - i*j/CUB_SIZE*INT16_UPLIMIT+1;
+
+
+ /* Open the file. */
+ file_id = Hopen(FILEGR, DFACC_CREATE, 0);
+
+ if(file_id == FAIL) {
+ printf("fail to create GR file.\n");
+ return FAIL;
+ }
+ /* Initiate the GR interface. */
+ gr_id = GRstart(file_id);
+
+ if(gr_id == FAIL) {
+ printf("fail to start GR interface.\n");
+ return FAIL;
+ }
+
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_uint32", ncomp, DFNT_UINT32, il, dims);
+
+ if(ri_id == FAIL) {
+ printf("fail to create RI interface.\n");
+ return FAIL;
+ }
+
+ /* Define the location, pattern, and size of the data set */
+ for (i = 0; i < 2; i++) {
+ start[i] = 0;
+ edges[i] = dims[i];
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
+
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ /* Terminate access to the image. */
+ GRendaccess(ri_id);
+
+ /* For number of components =3, data type is int16*/
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_int16", ncomp, DFNT_INT16, il, dims);
+
+ if(ri_id == FAIL) {
+ printf("fail to create RI interface.\n");
+ return FAIL;
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data16);
+
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ /* Terminate access to the image. */
+ GRendaccess(ri_id);
+
+ /* For number of components =1, data type is uint32*/
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 1;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_uint321", ncomp, DFNT_UINT32, il, dims);
+ if(ri_id == FAIL) {
+ printf("fail to create RI interface.\n");
+ return FAIL;
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data321);
+
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ /* Terminate access to the image. */
+ GRendaccess(ri_id);
+
+
+ /* For number of components = 1, data type is int16*/
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 1;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_int161", ncomp, DFNT_INT16, il, dims);
+
+ if(ri_id == FAIL) {
+ printf("fail to create RI interface.\n");
+ return FAIL;
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data161);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ /* Terminate access to the image. */
+ GRendaccess(ri_id);
+ /* Terminate access to the GR interface. */
+ GRend(gr_id);
+
+ /* Close the file. */
+ Hclose(file_id);
+ return 0;
+}
+
+
+/***** routine to generate raster 8 bit data type hdf file. ****/
+int test_ras8() {
+
+ int32 gr_id, ri_id, file_id, il,istat;
+ int32 ncomp;
+ int32 start[2], edges[2],dims[2];
+ int8 image_data8[Y_LENGTH][X_LENGTH];
+ uint8 image_datau8[Y_LENGTH][X_LENGTH];
+ intn i, j;
+ int32 CUB_SIZE;
+
+ CUB_SIZE = (X_LENGTH-1)*(Y_LENGTH-1);
+
+ /* 1-component Raster-8 image data type uint8 */
+ for (j = 0; j < Y_LENGTH; j++)
+ for (i = 0; i < X_LENGTH; i++)
+ image_datau8[j][i] = UINT8_UPLIMIT - i*j/CUB_SIZE*UINT8_UPLIMIT+1;
+
+ /* 1-component Raster-8 image data type int8*/
+ for (j = 0; j < Y_LENGTH; j++)
+ for (i = 0; i < X_LENGTH; i++)
+ image_data8[j][i] = INT8_UPLIMIT - i*j/CUB_SIZE*INT8_UPLIMIT+1;
+
+ /* Open the file. */
+ file_id = Hopen(FILERAS8, DFACC_CREATE, 0);
+
+ if(file_id == FAIL) {
+ printf("fail to open raster 8 file.\n");
+ return FAIL;
+ }
+ /* Initiate the GR interface. */
+ gr_id = GRstart(file_id);
+ if(gr_id == FAIL) {
+ printf("fail to start GR interface.\n");
+ return FAIL;
+ }
+
+ /* For number of components = 1, data type is uint8*/
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 1;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+ /* define start and edges value. */
+ for (i =0;i<2;i++) {
+ start[i] = 0;
+ edges[i] = dims[i];
+ }
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_uint8", ncomp, DFNT_UINT8, il, dims);
+ if(ri_id == FAIL) {
+ printf("fail to create GR object.\n");
+ return FAIL;
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_datau8);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the image. */
+ istat = GRendaccess(ri_id);
+ if(istat == FAIL) {
+ printf("fail in ending RI interface.\n");
+ return FAIL;
+ }
+
+ /* For number of components = 1, data type is int8*/
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 1;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_int8", ncomp, DFNT_INT8, il, dims);
+ if(ri_id == FAIL) {
+ printf("fail to create GR object.\n");
+ return FAIL;
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data8);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the image. */
+ GRendaccess(ri_id);
+ /* Terminate access to the GR interface. */
+ GRend(gr_id);
+
+ /* Close the file. */
+ Hclose(file_id);
+ return 0;
+}
+
+/***** routine to generate raster 24 bit data type hdf file. ****/
+int test_ras24() {
+
+ int32 gr_id, ri_id, file_id, il;
+ int32 ncomp,istat;
+ int32 start[2], edges[2],dims[2];
+ int8 image_data24[Y_LENGTH][X_LENGTH][3];
+ uint8 image_datau24[Y_LENGTH][X_LENGTH][3];
+ intn i, j;
+ int32 CUB_SIZE;
+
+
+ CUB_SIZE = (X_LENGTH-1)*(Y_LENGTH-1);
+
+ /* 3-component Raster-8 image data type uint8 */
+ for (j = 0; j < Y_LENGTH; j++) {
+ for (i = 0; i < X_LENGTH; i++) {
+ image_datau24[j][i][0] = UINT8_UPLIMIT - i*j*0/CUB_SIZE*UINT8_UPLIMIT+1;
+ image_datau24[j][i][1] = UINT8_UPLIMIT - i*j*1/CUB_SIZE*(UINT8_UPLIMIT/2)+1;
+ image_datau24[j][i][2] = UINT8_UPLIMIT - i*j*2/CUB_SIZE*(UINT8_UPLIMIT/2)+1;
+ }
+ }
+ /* 3-component Raster-8 image data type int8*/
+ for (j = 0; j < Y_LENGTH; j++) {
+ for (i = 0; i < X_LENGTH; i++) {
+ image_data24[j][i][0] = INT8_UPLIMIT - i*j*0/CUB_SIZE*INT8_UPLIMIT+1;
+ image_data24[j][i][1] = INT8_UPLIMIT - i*j*1/CUB_SIZE*(INT8_UPLIMIT/2)+1;
+ image_data24[j][i][2] = INT8_UPLIMIT - i*j*2/CUB_SIZE*(INT8_UPLIMIT/2)+1;
+
+ }
+ }
+
+ /* Open the file. */
+ file_id = Hopen(FILERAS24, DFACC_CREATE, 0);
+
+ if(file_id == FAIL) {
+ printf("fail to open the file. \n");
+ return FAIL;
+ }
+
+ /* Initiate the GR interface. */
+ gr_id = GRstart(file_id);
+ if(gr_id == FAIL) {
+ printf("fail to start GR interface.\n");
+ return FAIL;
+ }
+
+
+ /* For number of components = 3, data type is uint8*/
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+ for(i=0;i<2;i++) {
+ start[i] = 0;
+ edges[i] = dims[i];
+ }
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_uint24", ncomp, DFNT_UINT8, il, dims);
+ if(ri_id == FAIL) {
+ printf("fail to create GR object.\n");
+ return FAIL;
+ }
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_datau24);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ /* Terminate access to the image. */
+ GRendaccess(ri_id);
+
+
+ /* For number of components = 3, data type is int8*/
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_int24", ncomp, DFNT_INT8, il, dims);
+ if(ri_id == FAIL) {
+ printf("fail to create GR object.\n");
+ return FAIL;
+ }
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data24);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the image. */
+ GRendaccess(ri_id);
+ /* Terminate access to the GR interface. */
+ GRend(gr_id);
+
+ /* Close the file. */
+ Hclose(file_id);
+ return 0;
+}
+
+/* routine to generate image attribute file.*/
+int test_imageattr() {
+
+ int32 gr_id, ri_id, file_id, il,pal_id,istat;
+ int32 ncomp,data_type;
+ int32 start[2], edges[2],dims[2];
+ uint16 image_data[Y_LENGTH][X_LENGTH][3];
+
+ uint8 palette_data[NUM_COLORS * 3];
+ int32 num_comp,num_entries;
+ intn i, j;
+
+ /* Open the file. */
+ file_id = Hopen(FILEGRPAL, DFACC_CREATE, 0);
+
+ /* Initiate the GR interface. */
+ gr_id = GRstart(file_id);
+ if(gr_id == FAIL) {
+ printf("fail to start GR interface.\n");
+ return FAIL;
+ }
+
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+ dims[0] = X_LENGTH;
+ dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_1", ncomp, DFNT_UINT16, il, dims);
+ if(ri_id == FAIL) {
+ printf("fail to create GR object.\n");
+ return FAIL;
+ }
+ /* Fill the stored-data array with values. */
+ for (j = 0; j < Y_LENGTH; j++) {
+ for (i = 0; i < X_LENGTH; i++) {
+ image_data[j][i][0] = i+j+1;
+ image_data[j][i][1] = (i+j)*2;
+ image_data[j][i][2] = (i+j)*3;
+ }
+ }
+
+ /* Define the location, pattern, and size of the data set */
+ for (i = 0; i < 2; i++) {
+ start[i] = 0;
+ edges[i] = dims[i];
+ }
+
+ /* set GR global attribute. */
+
+ istat = GRsetattr(gr_id,"File Attribute",DFNT_CHAR8,F_ATT1_N_VALUES,(VOIDP)F_ATT1_VAL);
+ if(istat == FAIL) {
+ printf("fail to set GR global attribute.\n");
+ return FAIL;
+ }
+ /* set GR attribute. */
+ istat = GRsetattr(ri_id,"Image Attribute",DFNT_CHAR8,RI_ATT1_N_VALUES,(VOIDP)RI_ATT1_VAL);
+ if(istat == FAIL) {
+ printf("fail to set GR attribute.\n");
+ return FAIL;
+ }
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+
+ /* Initialize the palette to grayscale. */
+ for (i = 0; i < NUM_COLORS; i++) {
+ palette_data[i * 3] = i;
+ palette_data[i * 3 + 1] = i;
+ palette_data[i * 3 + 2] = i;
+ }
+
+ /* Set palette characteristics. */
+ data_type = DFNT_UINT8;
+ num_entries = NUM_COLORS;
+ num_comp = 3;
+
+ /* Get the id for the palette. */
+ pal_id = GRgetlutid(ri_id,0 );
+ if(pal_id == FAIL) {
+ printf("fail to obtain palette id.\n");
+ return FAIL;
+ }
+
+ /* Write the palette to file. */
+ istat = GRwritelut(pal_id, num_comp, data_type,
+ 0, num_entries,
+ (VOIDP)palette_data);
+ if(istat == FAIL) {
+ printf("fail to write lookup table.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the image. */
+ GRendaccess(ri_id);
+
+ /* Terminate access to the GR interface. */
+ GRend(gr_id);
+
+ /* Close the file. */
+ Hclose(file_id);
+ return 0;
+}
+
+/* routines to generate vdata hdf testing file. */
+int test_vdata( )
+{
+
+ struct {
+ float32 temp;
+ int16 height;
+ float32 speed;
+ char ident[3];
+ float32 position[2];
+ } source[NRECORDS];
+
+ int32 file_id, vdata_id, istat, values[4] ={32, 16, 32, 8};
+ uint8 *databuf, *pntr;
+ int i,j, bufsize, recsize;
+ VOIDP fldbufpt[5];
+
+ /* Open the HDF file. */
+ file_id = Hopen(FILEVD, DFACC_CREATE, 0);
+ if(file_id == FAIL) {
+ printf("fail to open HDF file.\n");
+ return FAIL;
+ }
+
+ /* Initialize the Vset interface. */
+ istat = Vstart(file_id);
+ if(istat == FAIL) {
+ printf("fail to start V interface.\n");
+ return FAIL;
+ }
+
+ /* Create a new Vdata. */
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach Vdata.\n");
+ return FAIL;
+ }
+ /* Define the field to write. */
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define field1 \n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define field2 \n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_3, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define field3 \n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_4, DFNT_CHAR8, 3);
+ if(istat == FAIL) {
+ printf("fail to define field4 \n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_5, DFNT_FLOAT32,2);
+ if(istat == FAIL) {
+ printf("fail to define field5 \n");
+ return FAIL;
+ }
+
+ /* Set the Vdata name. */
+ istat=VSsetname(vdata_id, "Test Vset Name");
+ if(istat == FAIL) {
+ printf("fail to set vdata name\n");
+ return FAIL;
+ }
+
+ /* Set the Vdata class. */
+ istat=VSsetclass(vdata_id, "Test Vset Class");
+ if(istat == FAIL) {
+ printf("fail to set vdata class\n");
+ return FAIL;
+ }
+
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_NAMES);
+ if(istat == FAIL) {
+ printf("fail to set fields of vdata.\n");
+ return FAIL;
+ }
+
+ recsize = (2 * sizeof(float32) + sizeof(int16))+ 2* sizeof(float32)
+ +3*sizeof(char);
+
+ bufsize = recsize * NRECORDS;
+ databuf = (uint8 *) malloc((size_t)bufsize);
+ if (databuf == NULL) {
+ printf("malloc memory for vdata failed\n");
+ return FAIL;
+ }
+ pntr = databuf;
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+ source[i].speed = 1.11 * (i+1);
+ source[i].ident[0] = 'A' + i;
+ source[i].ident[1] = 'a' + i;
+ source[i].ident[2] ='0'+i;
+ for (j=0; j< 2; j++)
+ source[i].position[j] = 1.0+j;
+ }
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ fldbufpt[2] = &source[i].speed;
+ fldbufpt[3] = &source[i].ident[0];
+ fldbufpt[4] = &source[i].position[0];
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+ /* Set Vdata attribute */
+ istat = VSsetattr (vdata_id, _HDF_VDATA, "vdata attr", DFNT_INT32, 4, (VOIDP)values);
+ if(istat == FAIL) {
+ printf("fail to set vdata attribute.\n");
+ return FAIL;
+ }
+ /* Set attribute for "speed" field */
+ istat = VSsetattr (vdata_id, 2, "field attr", DFNT_CHAR, 3, "MAX");
+ if(istat == FAIL) {
+ printf("fail to set vdata field attribute.\n");
+ return FAIL;
+ }
+ /*
+ * Terminate access to the Vdata, the Vset interface
+ * and the HDF file.
+ */
+ VSdetach(vdata_id);
+ Vend(file_id);
+ Hclose(file_id);
+ free(databuf);
+ return 0;
+}
+
+/* this routine will generate hdf file that has name clashings for different
+ vgroups.
+
+ two situations:
+ 1. two groups share the same name.
+ 2. one group doesn't have name.
+
+ */
+int test_vgnameclash() {
+
+ int32 file_id, vgroupa_ref, vgroupa_id,vgroupb_ref,vgroupb_id;
+ int32 vgroupc_id,vgroupc_ref;
+ int32 dim_sizes[TYP_RANK];
+ intn i, j;
+ int32 sd_id,sds_id;
+ int32 sds_ref;
+ int32 array_data[X_LENGTH][Y_LENGTH];
+ int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
+ int istat;
+
+ for (i=0;i<X_LENGTH;i++){
+ for(j=0;j<Y_LENGTH;j++) {
+ array_data[i][j] =i+j;
+ }
+ }
+
+ dim_sizes[0] = X_LENGTH;
+ dim_sizes[1] = Y_LENGTH;
+
+ for (i=0;i<TYP_RANK;i++){
+ stride[i]=1;
+ start[i]=0;
+ edges[i]=dim_sizes[i];
+
+ }
+
+ /* Open the HDF file. */
+
+ /* We are testing name clashings for vgroups.*/
+
+ /* two situations:
+ 1. two groups share the same name.
+ 2. one group doesn't have name. */
+
+ file_id = Hopen(FILECLASHVG, DFACC_CREATE, 0);
+ if (file_id == FAIL) {
+ printf("fail to open vg_clash.hdf.\n");
+ return FAIL;
+ }
+
+ istat = Vstart(file_id);
+ if(istat == FAIL) {
+ printf("fail to start vgroup interface.\n");
+ return FAIL;
+ }
+ vgroupa_ref = -1;
+ vgroupb_ref = -1;
+ vgroupc_ref = -1;
+ vgroupa_id = Vattach(file_id, vgroupa_ref, "w");
+ if(vgroupa_id == FAIL) {
+ printf("fail to attach groupa.\n");
+ return FAIL;
+ }
+ vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
+ if(vgroupb_id == FAIL) {
+ printf("fail to attach groupb.\n");
+ return FAIL;
+ }
+ vgroupc_id = Vattach(file_id,vgroupc_ref,"w");
+ if(vgroupc_id == FAIL) {
+ printf("fail to attach groupc.\n");
+ return FAIL;
+ }
+ istat=Vsetname(vgroupa_id,"groupA");
+ if(istat == FAIL) {
+ printf("fail to set name for groupa.\n");
+ return FAIL;
+ }
+
+ istat=Vsetname(vgroupb_id,"groupA");
+ if(istat == FAIL) {
+ printf("fail to set name for groupb.\n");
+ return FAIL;
+ }
+ sd_id = SDstart(FILECLASHVG,DFACC_WRITE);
+ if(sd_id == FAIL) {
+ printf("fail to start SD interface.\n");
+ return FAIL;
+ }
+
+ sds_id = SDcreate(sd_id,"sds",DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("failed to transfer sds id to reference number.\n");
+ return FAIL;
+ }
+
+ istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add tag for reference.\n");
+ return FAIL;
+ }
+
+ SDendaccess(sds_id);
+ SDend(sd_id);
+ Vdetach(vgroupa_id);
+ istat = Vdetach(vgroupb_id);
+ istat = Vdetach(vgroupc_id);
+ istat = Vend(file_id);
+ istat = Hclose(file_id);
+ return 0;
+}
+
+/* This routine creates different SDS objects with name clashing.
+We are testing different SDS
+ 1. under the same group sharing the same name.
+ 2. one sds doesn't have name.
+ 3. different sds objects under different vgroups sharing the same name.
+ 4. sds objects under no specific groups share the same name.
+ 5. sds objects under no specific groups with no name. */
+
+
+int test_sdsnameclash() {
+
+
+ int32 file_id, vgroupa_ref, vgroupa_id,vgroupb_ref,vgroupb_id;
+ int32 dim_sizes[TYP_RANK];
+ int32 vgroupc_ref,vgroupc_id;
+ intn i, j,istat;
+ int32 sd_id,sds_id;
+ int32 sds_ref;
+ int32 array_data[X_LENGTH][Y_LENGTH];
+ int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
+
+
+ for (i=0;i<X_LENGTH;i++){
+ for(j=0;j<Y_LENGTH;j++) {
+ array_data[i][j] =i+j;
+ }
+ }
+
+ dim_sizes[0] = X_LENGTH;
+ dim_sizes[1] = Y_LENGTH;
+
+ for (i=0;i<TYP_RANK;i++){
+ stride[i]=1;
+ start[i]=0;
+ edges[i]=dim_sizes[i];
+
+ }
+
+ /* Open the HDF file. */
+
+ file_id = Hopen(FILECLASHSDS, DFACC_CREATE, 0);
+ istat = Vstart(file_id);
+ vgroupa_ref = -1;
+ vgroupb_ref = -1;
+ vgroupc_ref = -1;
+ vgroupa_id = Vattach(file_id,vgroupa_ref,"w");
+ if(vgroupa_id == FAIL) {
+ printf("fail to attach groupa.\n");
+ return FAIL;
+ }
+ vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
+ if(vgroupb_id == FAIL) {
+ printf("fail to attach groupb.\n");
+ return FAIL;
+ }
+ vgroupc_id = Vattach(file_id,vgroupc_ref,"w");
+ if(vgroupc_id == FAIL) {
+ printf("fail to attach groupc.\n");
+ return FAIL;
+ }
+ istat=Vsetname(vgroupa_id,"groupA");
+ if(istat == FAIL) {
+ printf("fail to set name for groupa.\n");
+ return FAIL;
+ }
+ istat=Vsetname(vgroupb_id,"groupB");
+ if(istat == FAIL) {
+ printf("fail to set name for groupb.\n");
+ return FAIL;
+ }
+ Vsetname(vgroupc_id,"groupC");
+ if(istat == FAIL) {
+ printf("fail to set name for groupc.\n");
+ return FAIL;
+ }
+ sd_id = SDstart(FILECLASHSDS,DFACC_WRITE);
+ if(sd_id == FAIL) {
+ printf("fail to start SD interface.\n");
+ return FAIL;
+ }
+ /* putting one sds object under groupa. */
+ sds_id = SDcreate(sd_id,"sds",DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("failed to transfer sds id to reference number.\n");
+ return FAIL;
+ }
+ /* a sds object with the name "sds" is put under group a.*/
+ istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add tag for reference.\n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ /* putting another sds with the same same "sds" under groupa.
+ It is legal for hdf lib. */
+
+ sds_id = SDcreate(sd_id,"sds",DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("failed to transfer sds id to reference number.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add tag for reference.\n");
+ return FAIL;
+ }
+
+ SDendaccess(sds_id);
+
+ /* no sds name is given under groupc*/
+ sds_id = SDcreate(sd_id,NULL,DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("failed to transfer sds id to reference number.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupc_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add tag for reference.\n");
+ return FAIL;
+ }
+
+ SDendaccess(sds_id);
+
+ /* another no name sds object is put under group c. */
+ sds_id = SDcreate(sd_id,NULL,DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("failed to transfer sds id to reference number.\n");
+ return FAIL;
+ }
+
+ istat = Vaddtagref(vgroupc_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add tag for reference.\n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ /* another sds with the same name under groupb is given.*/
+ sds_id = SDcreate(sd_id,"sds",DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("failed to transfer sds id to reference number.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupb_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add tag for reference.\n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ /* two sds share the same name under no specific groups.*/
+ sds_id = SDcreate(sd_id,"sds_independent",DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ sds_id = SDcreate(sd_id,"sds_independent",DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ /* another sds with no name and is not tagged with any group. */
+ sds_id = SDcreate(sd_id,NULL,DFNT_INT32,2,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("failed to create sds object.\n");
+ return FAIL;
+ }
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("failed to write sds data. \n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+
+ SDend(sd_id);
+ istat = Vdetach(vgroupa_id);
+ istat = Vdetach(vgroupb_id);
+ istat = Vdetach(vgroupc_id);
+ istat = Vend(file_id);
+ istat = Hclose(file_id);
+ return 0;
+}
+
+/*A routine to generate a testing file that deals with different
+name clashings for image.
+We are testing different Image
+ 1. under the same group sharing the same name.
+ 2. one image doesn't have name(not allowed)
+ 3. different image objects under different vgroups sharing the same name.
+ 4. image objects under no specific groups share the same name.
+ 5. image objects under no specific groups with no name(not allowed). */
+
+
+int test_grnameclash() {
+
+
+ int32 file_id, vgroupa_ref, vgroupa_id,vgroupb_ref,vgroupb_id,istat;
+ int32 dim_sizes[2];
+
+ int i, j;
+ int32 gr_id,ri_id,il,ncomp;
+ int32 gr_ref;
+ int32 start[2], edges[2];
+ uint32 image_data32[Y_LENGTH][X_LENGTH][3];
+
+ for (j=0;j<Y_LENGTH;j++){
+ for(i=0;i<X_LENGTH;i++) {
+ image_data32[j][i][0] = i;
+ image_data32[j][i][1] = j;
+ image_data32[j][i][2] = i+j;
+ }
+ }
+
+ dim_sizes[0] = X_LENGTH;
+ dim_sizes[1] = Y_LENGTH;
+
+
+ /* Open the HDF file. */
+
+ file_id = Hopen(FILECLASHGR, DFACC_CREATE, 0);
+ if(file_id == FAIL) {
+ printf("fail to open the file.\n");
+ return FAIL;
+ }
+ istat = Vstart(file_id);
+ if(istat == FAIL) {
+ printf("fail to start vgroup interface.\n");
+ return FAIL;
+ }
+ vgroupa_ref = -1;
+ vgroupb_ref = -1;
+
+ vgroupa_id = Vattach(file_id,vgroupa_ref,"w");
+ if(vgroupa_id == FAIL) {
+ printf("fail to attach groupa.\n");
+ return FAIL;
+ }
+ vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
+ if(vgroupb_id == FAIL) {
+ printf("fail to attach groupb.\n");
+ return FAIL;
+ }
+
+ istat=Vsetname(vgroupa_id,"groupA");
+ if(istat == FAIL) {
+ printf("fail to set name for groupa.\n");
+ return FAIL;
+ }
+
+ istat=Vsetname(vgroupb_id,"groupB");
+ if(istat == FAIL) {
+ printf("fail to set name for groupb.\n");
+ return FAIL;
+ }
+
+ gr_id = GRstart(file_id);
+
+ if(gr_id == FAIL) {
+ printf("fail to start GR interface.\n");
+ return FAIL;
+ }
+
+ /* Define the location, pattern, and size of the data set */
+ for (i = 0; i < 2; i++) {
+ start[i] = 0;
+ edges[i] = dim_sizes[i];
+ }
+ /* Define the number of components and dimensions of the image. */
+ ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+
+ /* Create the array. */
+ /* 1.1. put one image with the name "Imagea" under groupa.*/
+ ri_id = GRcreate(gr_id, "Imagea", ncomp, DFNT_UINT32, il, dim_sizes);
+ if(ri_id == FAIL) {
+ printf("fail to create GR interface.\n");
+ return FAIL;
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+
+ gr_ref = GRidtoref(ri_id);
+ if(gr_ref == FAIL) {
+ printf("fail to convert ri_id into reference.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupa_id,DFTAG_RIG,gr_ref);
+ if(istat == FAIL) {
+ printf("fail to add gr object into vgroup a.\n");
+ return FAIL;
+ }
+ GRendaccess(ri_id);
+
+ /* 1.2 putting the same same image object under groupa. */
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Imagea", ncomp, DFNT_UINT32, il, dim_sizes);
+ if(ri_id == FAIL) {
+ printf("fail to create GR interface.\n");
+ return FAIL;
+ }
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ gr_ref = GRidtoref(ri_id);
+ if(gr_ref == FAIL) {
+ printf("fail to convert ri_id into reference.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupa_id,DFTAG_RIG,gr_ref);
+ if(istat == FAIL) {
+ printf("fail to add gr object into vgroup a.\n");
+ return FAIL;
+ }
+ GRendaccess(ri_id);
+
+
+ /* 2.0 no image name is given, it is illegal for hdf4 lib; therefore;
+ no test cases are given. */
+
+
+ /* 3.1 another image with the "imagea" under groupb is given.*/
+ ri_id = GRcreate(gr_id,"imagea", ncomp, DFNT_UINT32, il, dim_sizes);
+ if(ri_id == FAIL) {
+ printf("fail to create GR interface.\n");
+ return FAIL;
+ }
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ gr_ref = GRidtoref(ri_id);
+ if(gr_ref == FAIL) {
+ printf("fail to convert ri_id into reference.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupb_id,DFTAG_RIG,gr_ref);
+ if(istat == FAIL) {
+ printf("fail to add gr object into vgroup a.\n");
+ return FAIL;
+ }
+ GRendaccess(ri_id);
+
+ /* 4.0 two images share the same name under no specific groups.*/
+
+ ri_id = GRcreate(gr_id, "Image_independent", ncomp, DFNT_UINT32, il, dim_sizes);
+
+ if(ri_id == FAIL) {
+ printf("fail to create GR interface.\n");
+ return FAIL;
+ }
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ GRendaccess(ri_id);
+
+ ri_id = GRcreate(gr_id, "Image_independent", ncomp, DFNT_UINT32, il, dim_sizes);
+ if(ri_id == FAIL) {
+ printf("fail to create GR interface.\n");
+ return FAIL;
+ }
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+ GRendaccess(ri_id);
+ GRend(gr_id);
+ istat = Vdetach(vgroupa_id);
+ istat = Vdetach(vgroupb_id);
+
+ istat = Vend(file_id);
+ istat = Hclose(file_id);
+ return 0;
+}
+/* a routine that generates the name clashing for vdata object. some
+ redundant codes can found in this routine, it should be corrected later.
+
+ Cases:
+
+ 1. two independent Vdata with the same name not under any user-specified group.
+ 2. vdata without any names and not under any user-specified groups.
+ 3. different Vdata objects under the same vgroup sharing the same name.
+ 4. different Vdata objects under different vgroups sharing the same name.
+ 5. Vdata without any names under one user-specified group*/
+
+int test_vdnameclash() {
+
+ int32 file_id, vgroupa_ref, vgroupa_id,vgroupb_ref,vgroupb_id;
+ int32 vgroupc_id,vgroupc_ref,vd_ref;
+
+ struct {
+ float32 temp;
+ int16 height;
+ } source[NRECORDS];
+
+ int32 vdata_id, istat;
+ uint8 *databuf, *pntr;
+ int i, bufsize, recsize;
+ VOIDP fldbufpt[2];
+
+ /* Open the HDF file. */
+ file_id = Hopen(FILECLASHVD, DFACC_CREATE, 0);
+ if(file_id == FAIL) {
+ printf("fail to open the file.\n");
+ return FAIL;
+ }
+ /* Initialize the Vset interface. */
+ istat = Vstart(file_id);
+ if(istat == FAIL) {
+ printf("fail to start vgroup interface.\n");
+ return FAIL;
+ }
+
+ /* 1.0
+ Create an independent new Vdata with the name "Test Vset Name". */
+
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach vdata id.\n");
+ return FAIL;
+ }
+ /* Define the field to write. */
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 1.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 2.\n");
+ return FAIL;
+ }
+
+ /* Set the Vdata name. */
+ istat=VSsetname(vdata_id, "Test Vset Name");
+ if(istat == FAIL) {
+ printf("fail to set vdata name.\n");
+ return FAIL;
+ }
+
+ /* Set the Vdata class. */
+ istat=VSsetclass(vdata_id, "Test Vset Class");
+ if(istat == FAIL) {
+ printf("fail to set vdata class.\n");
+ return FAIL;
+ }
+
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_VDNAMES);
+ if(istat == FAIL) {
+ printf("fail to set fields.\n");
+ return FAIL;
+ }
+ recsize = sizeof(float32) + sizeof(int16);
+
+ bufsize = recsize * NRECORDS;
+ databuf = (uint8 *) malloc((size_t)bufsize);
+ if (databuf == NULL) {
+ printf("fail to allocate memory for databuf");
+ return FAIL;
+ }
+ pntr = databuf;
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+
+ }
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+
+ free(databuf);
+ VSdetach(vdata_id);
+
+ /* 1.1
+ Create another independent Vdata with the name "Test Vset Name" */
+
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach vdata.\n");
+ return FAIL;
+ }
+ /* Define the field to write. */
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 1.\n");
+ return FAIL;
+ }
+
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 2.\n");
+ return FAIL;
+ }
+ /* Set the Vdata name. */
+ istat=VSsetname(vdata_id, "Test Vset Name");
+ if(istat == FAIL) {
+ printf("fail to set vdata name.\n");
+ return FAIL;
+ }
+ /* Set the Vdata class. */
+ istat=VSsetclass(vdata_id, "Test Vset Class");
+ if(istat == FAIL) {
+ printf("fail to set vdata class.\n");
+ return FAIL;
+ }
+
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_VDNAMES);
+ if(istat == FAIL) {
+ printf("fail to set fields.\n");
+ return FAIL;
+ }
+ recsize = sizeof(float32) + sizeof(int16);
+
+ bufsize = recsize * NRECORDS;
+ databuf = (uint8 *) malloc((size_t)bufsize);
+ if (databuf == NULL) {
+ printf("malloc failed\n");
+ return FAIL;
+ }
+ pntr = databuf;
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+
+ }
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+ free(databuf);
+ VSdetach(vdata_id);
+
+ /* An independent Vdata without name not under any user-specified vgroup. */
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach vdata id.\n");
+ return FAIL;
+ }
+ /* Define the field to write. */
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 1.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 2.\n");
+ return FAIL;
+ }
+ /* Set the Vdata class.
+ istat=VSsetclass(vdata_id, "Test Vset Class");*/
+ if(istat == FAIL) {
+ printf("fail to set vdata class.\n");
+ return FAIL;
+ }
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_VDNAMES);
+ if(istat == FAIL) {
+ printf("fail to set fields.\n");
+ return FAIL;
+ }
+ recsize = sizeof(float32) + sizeof(int16);
+
+ bufsize = recsize * NRECORDS;
+ databuf = (uint8 *) malloc((size_t)bufsize);
+ if (databuf == NULL) {
+ printf("malloc failed\n");
+ return FAIL;
+ }
+ pntr = databuf;
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+
+ }
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+ free(databuf);
+ VSdetach(vdata_id);
+
+ vgroupa_ref = -1;
+ vgroupb_ref = -1;
+ vgroupc_ref = -1;
+
+ /* 3. two vdata with the same name under groupa. */
+ vgroupa_id = Vattach(file_id, vgroupa_ref,"w");
+
+ Vsetname(vgroupa_id,"groupA");
+ /* Create a new Vdata. */
+ vdata_id = VSattach(file_id, -1, "w");
+
+ /* Define the field to write. */
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 1.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 2.\n");
+ return FAIL;
+ }
+ /* Set the Vdata name. */
+ istat=VSsetname(vdata_id, "Test Vset Name");
+ if(istat == FAIL) {
+ printf("fail to set vdata name. \n");
+ return FAIL;
+ }
+
+ /* Set the Vdata class. */
+ istat=VSsetclass(vdata_id, "Test Vset Class");
+ if(istat == FAIL) {
+ printf("fail to set vdata class.\n");
+ return FAIL;
+ }
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_VDNAMES);
+ if(istat == FAIL) {
+ printf("fail to set fields.\n");
+ return FAIL;
+ }
+ recsize = sizeof(float32) + sizeof(int16);
+
+ bufsize = recsize * NRECORDS;
+ databuf = (uint8 *) malloc((size_t)bufsize);
+ if (databuf == NULL) {
+ printf("malloc failed\n");
+ return FAIL;
+ }
+ pntr = databuf;
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+
+ }
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+ free(databuf);
+ vd_ref = VSQueryref(vdata_id);
+ if(vd_ref == FAIL) {
+ printf("fail to query vdata.\n");
+ return FAIL;
+ }
+
+ istat = Vaddtagref(vgroupa_id,DFTAG_VH,vd_ref);
+ if(istat == FAIL){
+ printf("fail to add vdata into vgroup.\n");
+ return FAIL;
+ }
+ VSdetach(vdata_id);
+
+ /* Create a new Vdata. */
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach vdata.\n");
+ return FAIL;
+ }
+ /* Define the field to write. */
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 1.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 2.\n");
+ return FAIL;
+ }
+
+ /* Set the Vdata name. */
+ istat=VSsetname(vdata_id, "Test Vset Name");
+ if(istat == FAIL) {
+ printf("fail to set vdata name.\n");
+ return FAIL;
+ }
+ /* Set the Vdata class. */
+ istat=VSsetclass(vdata_id, "Test Vset Class");
+ if(istat == FAIL) {
+ printf("fail to set vdata class.\n");
+ return FAIL;
+ }
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_VDNAMES);
+ if(istat == FAIL) {
+ printf("fail to set fields.\n");
+ return FAIL;
+ }
+ recsize = sizeof(float32) + sizeof(int16);
+
+ bufsize = recsize * NRECORDS;
+ databuf = (uint8 *) malloc((size_t)bufsize);
+ if (databuf == NULL) {
+ printf("malloc failed\n");
+ return FAIL;
+
+ }
+ pntr = databuf;
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+
+ }
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+ free(databuf);
+ vd_ref = VSQueryref(vdata_id);
+ if(vd_ref== FAIL) {
+ printf("fail to query reference.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupa_id,DFTAG_VH,vd_ref);
+ if(istat == FAIL) {
+ printf("fail to add vdata into vgroup a.\n");
+ return FAIL;
+ }
+ VSdetach(vdata_id);
+
+
+ /*4. another vdata with the same name under groupb.*/
+ vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
+ if(vgroupb_id == FAIL) {
+ printf("fail to attach vgroup b.\n");
+ return FAIL;
+ }
+
+ istat=Vsetname(vgroupb_id,"groupB");
+ if(istat == FAIL) {
+ printf("fail to set group b name.\n");
+ return FAIL;
+ }
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach vdata.\n");
+ return FAIL;
+ }
+ /* Define the field to write. */
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 1.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 2.\n");
+ return FAIL;
+ }
+ /* Set the Vdata name. */
+ istat=VSsetname(vdata_id, "Test Vset Name");
+ if(istat == FAIL) {
+ printf("fail to set vdata name.\n");
+ return FAIL;
+ }
+ /* Set the Vdata class. */
+ istat=VSsetclass(vdata_id, "Test Vset Class");
+ if(istat == FAIL) {
+ printf("fail to set vdata class.\n");
+ return FAIL;
+ }
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_VDNAMES);
+ if(istat == FAIL) {
+ printf("fail to set fields.\n");
+ return FAIL;
+ }
+ recsize = sizeof(float32) + sizeof(int16);
+
+ bufsize = recsize * NRECORDS;
+ databuf = (uint8 *) malloc((size_t)bufsize);
+ if (databuf == NULL) {
+ printf("malloc failed\n");
+ return FAIL;
+ }
+ pntr = databuf;
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+
+ }
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+
+ free(databuf);
+ vd_ref = VSQueryref(vdata_id);
+ if(vd_ref == FAIL) {
+ printf("fail to query reference.\n");
+ return FAIL;
+ }
+
+ istat = Vaddtagref(vgroupb_id,DFTAG_VH,vd_ref);
+ if(istat == FAIL) {
+ printf("fail to add vdata into vgroup.\n");
+ return FAIL;
+ }
+
+ VSdetach(vdata_id);
+
+ /* 5. vdata without name under groupc. */
+ vgroupc_id = Vattach(file_id,vgroupc_ref,"w");
+ if(vgroupc_id == FAIL) {
+ printf("fail to attach vgroup c.\n");
+ return FAIL;
+ }
+ istat = Vsetname(vgroupc_id,"groupC");
+ if(istat == FAIL) {
+ printf("fail to set group c name.\n");
+ return FAIL;
+ }
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach vdata.\n");
+ return FAIL;
+ }
+ /* Define the field to write. */
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 1.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 2.\n");
+ return FAIL;
+ }
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_VDNAMES);
+ if(istat == FAIL) {
+ printf("fail to set field name.\n");
+ return FAIL;
+ }
+
+ recsize = sizeof(float32) + sizeof(int16);
+
+ bufsize = recsize * NRECORDS;
+ databuf = (uint8 *) malloc((size_t)bufsize);
+ if (databuf == NULL) {
+ printf("malloc failed\n");
+ return FAIL;
+ }
+ pntr = databuf;
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+
+ }
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+
+ free(databuf);
+ vd_ref = VSQueryref(vdata_id);
+ if(vd_ref == FAIL) {
+ printf("fail to get reference number for vata.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupc_id,DFTAG_VH,vd_ref);
+ if(istat == FAIL) {
+ printf("fail to add vdata into groupc.\n");
+ return FAIL;
+ }
+ VSdetach(vdata_id);
+
+ istat = Vdetach(vgroupa_id);
+ istat = Vdetach(vgroupb_id);
+ istat = Vdetach(vgroupc_id);
+ istat = Vend(file_id);
+ istat = Hclose(file_id);
+ return 0;
+}
+
+/* a routine that generates a hdf file with vgroup loops.va->vb and vb->va */
+
+int test_vgloop() {
+
+ int32 file_id, vgroupa_ref, vgroupa_id, vgroupb_ref,vgroupb_id;
+ int32 istat,dims[TYP_RANK];
+ int i,j,k;
+
+ /*2. for sds */
+ int32 sd_id,sds_id;
+ int32 sds_ref;
+ int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
+
+
+ for (i=0;i<TYP_DIMSIZE;i++){
+ for(j=0;j<TYP_DIMSIZE;j++) {
+ for(k=0;k<TYP_DIMSIZE;k++){
+ array_data[i][j][k] =i+j;
+ }
+ }
+ }
+
+ dims[0] = TYP_DIMSIZE;
+ dims[1] = TYP_DIMSIZE;
+ dims[2] = TYP_DIMSIZE;
+ for (i=0;i<TYP_RANK;i++){
+ stride[i]=1;
+ start[i]=0;
+ edges[i]=dims[i];
+
+ }
+
+ /* Open the HDF file. */
+
+ file_id = Hopen(FILELOOP, DFACC_CREATE, 0);
+ if(file_id == FAIL) {
+ printf("fail to open the file.\n");
+ return FAIL;
+ }
+ istat = Vstart(file_id);
+ if(istat == FAIL) {
+ printf("fail to start vdata interface.\n");
+ return FAIL;
+ }
+
+ vgroupa_ref = -1;
+ vgroupb_ref = -1;
+ vgroupa_id = Vattach(file_id, vgroupa_ref, "w");
+ if(vgroupa_id == FAIL) {
+ printf("fail to attach group a.\n");
+ return FAIL;
+ }
+ vgroupb_id = Vattach(file_id, vgroupb_ref, "w");
+ if(vgroupb_id == FAIL) {
+ printf("fail to attach groupb.\n");
+ return FAIL;
+ }
+ istat = Vsetname(vgroupa_id,"groupA");
+ if(istat == FAIL) {
+ printf("fail to set name for groupa.\n");
+ return FAIL;
+ }
+ istat = Vsetname(vgroupb_id,"groupB");
+ if(istat == FAIL) {
+ printf("fail to set name for groupa.\n");
+ return FAIL;
+ }
+ istat = Vinsert(vgroupa_id,vgroupb_id);
+ if(istat == FAIL) {
+ printf("fail to insert groupb into groupa.\n");
+ return FAIL;
+ }
+
+ istat = Vinsert(vgroupb_id,vgroupa_id);
+ if(istat == FAIL) {
+ printf("fail to insert groupa into groupb.\n");
+ return FAIL;
+ }
+ sd_id = SDstart(FILELOOP,DFACC_WRITE);
+ if(sd_id == FAIL) {
+ printf("fail to start sd interface.\n");
+ return FAIL;
+ }
+
+ sds_id = SDcreate(sd_id,"sds",DFNT_INT32,TYP_RANK,dims);
+ if(sds_id == FAIL) {
+ printf("fail to create sds interface.\n");
+ return FAIL;
+ }
+
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("fail to write sds data.\n");
+ return FAIL;
+ }
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("fail to create sds reference.\n");
+ return FAIL;
+ }
+
+ istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add sds into vgroupa\n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+ SDend(sd_id);
+ istat = Vdetach(vgroupa_id);
+ istat = Vdetach(vgroupb_id);
+ istat = Vend(file_id);
+ istat = Hclose(file_id);
+ return 0;
+}
+
+/* a routine that creates a hdf file which has one sds under two
+ different vgroups. */
+int test_vghl() {
+
+ int32 file_id, vgroupa_ref, vgroupa_id, vgroupb_ref,vgroupb_id;
+ int32 istat,dims[TYP_RANK];
+ int i,j,k;
+
+ /*2. for sds */
+ int32 sd_id,sds_id;
+ int32 sds_ref;
+ int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
+
+ for (i=0;i<TYP_DIMSIZE;i++){
+ for(j=0;j<TYP_DIMSIZE;j++) {
+ for(k=0;k<TYP_DIMSIZE;k++){
+ array_data[i][j][k] =i+j;
+ }
+ }
+ }
+
+ dims[0] = TYP_DIMSIZE;
+ dims[1] = TYP_DIMSIZE;
+ dims[2] = TYP_DIMSIZE;
+ for (i=0;i<TYP_RANK;i++){
+ stride[i]=1;
+ start[i]=0;
+ edges[i]=dims[i];
+
+ }
+
+ /* Open the HDF file. */
+
+ file_id = Hopen(FILEHL, DFACC_CREATE, 0);
+ if(file_id == FAIL) {
+ printf("fail to open hdf file.\n");
+ return FAIL;
+ }
+
+ istat = Vstart(file_id);
+ if(istat == FAIL) {
+ printf("fail to start vdata interface.\n");
+ return FAIL;
+ }
+ vgroupa_ref = -1;
+ vgroupb_ref = -1;
+ vgroupa_id = Vattach(file_id, vgroupa_ref, "w");
+ if(vgroupa_id == FAIL) {
+ printf("fail to attach group a.\n");
+ return FAIL;
+ }
+ vgroupb_id = Vattach(file_id, vgroupb_ref, "w");
+ if(vgroupb_id == FAIL) {
+ printf("fail to attach groupb.\n");
+ return FAIL;
+ }
+ istat = Vsetname(vgroupa_id,"groupA");
+ if(istat == FAIL) {
+ printf("fail to set name for groupa.\n");
+ return FAIL;
+ }
+ istat = Vsetname(vgroupb_id,"groupB");
+ if(istat == FAIL) {
+ printf("fail to set name for groupa.\n");
+ return FAIL;
+ }
+ sd_id = SDstart(FILEHL,DFACC_WRITE);
+ if(sd_id == FAIL) {
+ printf("fail to start sd interface.\n");
+ return FAIL;
+ }
+ sds_id = SDcreate(sd_id,"sds",DFNT_INT32,TYP_RANK,dims);
+ if(sds_id == FAIL) {
+ printf("fail to create sds interface.\n");
+ return FAIL;
+ }
+
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("fail to write sds data.\n");
+ return FAIL;
+ }
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("fail to create sds reference.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add sds into vgroupa\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupb_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add sds into vgroupb\n");
+ return FAIL;
+ }
+ SDendaccess(sds_id);
+ SDend(sd_id);
+ istat = Vdetach(vgroupa_id);
+ istat = Vdetach(vgroupb_id);
+ istat = Vend(file_id);
+ istat = Hclose(file_id);
+ return 0;
+}
+/* this is a comprehensive testing file for h4-h5 converter. It includes
+ annotation,vdata,image,sds,palette and vgroup objects*/
+/* the structure of the hdf5 file is as follows:
+ root
+ / \
+ gc ga<--
+ / \ |
+ gd gb--
+ /
+ ge
+
+ This file includes vdata,image and sds.
+
+*/
+int test_vgall() {
+
+ typedef struct {
+ float32 temp;
+ int16 height;
+ float32 speed;
+ char ident;
+ float32 position[2];
+ } source_t;
+
+ source_t source[NRECORDS];
+
+ int32 file_id, vgroupa_ref, vgroupa_id,istat;
+ int32 vgroupc_ref, vgroupc_id,vgroupb_ref,vgroupb_id;
+ int32 vgroupd_ref, vgroupd_id,vgroupe_ref,vgroupe_id;
+ int32 vdata_id,values[4]={32, 16, 32, 8};
+
+ intn i, j,k;
+
+ uint8 *databuf, *pntr;
+ int bufsize, recsize;
+ VOIDP fldbufpt[5];
+
+ /*2. for sds */
+ int32 sd_id,sds_id,dim_id;
+ int32 sds_ref;
+ int32 fill_value;
+ int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
+ int32 dimo_sca[TYP_DIMSIZE];
+ int32 dim_sizes[TYP_RANK];
+ int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
+ float64 cal;
+ float64 cal_err;
+ float64 offset;
+ float64 offset_err;
+
+ /*3. for image. */
+
+ int32 gr_id, ri_id, il,pal_id;
+ int32 image_ncomp,image_data_type;
+ int32 image_start[2], image_edges[2],image_dims[2];
+ int16 image_data[Y_LENGTH][X_LENGTH][3];
+ uint8 palette_data[NUM_COLORS*3];
+ int32 image_num_comp;
+ int32 image_num_entries;
+ int32 image_ref;
+
+ char* attr_value;
+
+ /*4. for annotation. */
+ int32 an_id,ann_id;
+ int32 group_tag,group_ref;
+
+ static char file_label[] = "This is a file label.";
+ static char file_desc[] = "This is a file description.";
+ static char data_label[] = "This is a data label.";
+ static char data_desc[] = "This is a data description.";
+
+ char label[] = "sds.label";
+ char unit[] = "sds.unit";
+ char format[] = "sds.format";
+ char coordsys[] = "sds.coord";
+
+ char dim_name0[] ="dim0";
+ char dim_name1[] ="dim1";
+ char dim_label[] ="dim.label";
+ char dim_unit[] ="dim.unit";
+ char dim_format[] ="dim.format";
+
+ /**** initial setting. ****/
+ cal = 1.0;
+ cal_err = 0.0;
+ offset = 0.0;
+ offset_err = 0.0;
+ fill_value = 999;
+
+ attr_value = malloc(ATT_SIZE*sizeof(char));
+ if(attr_value == NULL) {
+ printf("fail to allocate memory.\n");
+ return FAIL;
+ }
+ strcpy(attr_value,"test attr");
+
+ for (i=0;i<TYP_DIMSIZE;i++){
+ for(j=0;j<TYP_DIMSIZE;j++) {
+ for(k=0;k<TYP_DIMSIZE;k++) {
+ array_data[i][j][k]=i+j;
+ }
+ }
+ }
+
+ for (i=0;i<TYP_DIMSIZE;i++)
+ dimo_sca[i]= 2*i;
+
+ for (i=0;i<TYP_RANK;i++){
+ stride[i]=1;
+ start[i]=0;
+ dim_sizes[i] = TYP_DIMSIZE;
+ edges[i]=dim_sizes[i];
+
+ }
+
+ /* Open the HDF file. */
+
+ file_id = Hopen(FILEVG, DFACC_CREATE, 0);
+ if(file_id == FAIL) {
+ printf("fail to open the file.\n");
+ return FAIL;
+ }
+
+ /* create annotations. */
+
+ /* Initialize the AN interface and obtain an interface id. */
+ an_id = ANstart(file_id);
+ if(an_id == FAIL) {
+ printf("fail to start annotation interface.\n");
+ return FAIL;
+ }
+ /* Create a file label and obtain an annotation id. */
+ ann_id = ANcreatef(an_id, AN_FILE_LABEL);
+ if(ann_id == FAIL) {
+ printf("fail to create file annotion interface.\n");
+ return FAIL;
+ }
+
+ /* Write the file label to the file. */
+ istat = ANwriteann(ann_id, file_label, (int32)(strlen(file_label)));
+ if(istat == FAIL) {
+ printf("fail to write file annotation.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the annotation. */
+ istat = ANendaccess(ann_id);
+
+ /* Create a file description. */
+ ann_id = ANcreatef(an_id, AN_FILE_DESC);
+ if(ann_id == FAIL) {
+ printf("fail to create file annotion interface.\n");
+ return FAIL;
+ }
+ /* Write the file description to the file. */
+ istat = ANwriteann(ann_id, file_desc, (int32)(strlen(file_desc)));
+ if(istat == FAIL) {
+ printf("fail to write file annotation.\n");
+ return FAIL;
+ }
+ /* Terminate access to the annotation. */
+ istat = ANendaccess(ann_id);
+
+ /* Initialize the Vset interface. */
+
+ istat = Vstart(file_id);
+ if(istat == FAIL) {
+ printf("fail to start vdata interface.\n");
+ return FAIL;
+ }
+ /** Create Vgroup VA and VB***/
+ vgroupa_ref = -1;
+ vgroupb_ref = -1;
+
+ /* Attach to the target vgroup. */
+ vgroupa_id = Vattach(file_id, vgroupa_ref, "w");
+ if(vgroupa_id == FAIL) {
+ printf("fail to attach group a.\n");
+ return FAIL;
+ }
+ istat=Vsetname(vgroupa_id,"groupA");
+ if(istat == FAIL) {
+ printf("fail to set name for groupa.\n");
+ return FAIL;
+ }
+ /* Attach an attribute to the vgroup. */
+
+ istat = Vsetattr(vgroupa_id,"vgattr",DFNT_CHAR,5,"TESTa");
+ if(istat == FAIL) {
+ printf("fail to set attribute.\n");
+ return FAIL;
+ }
+
+ vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
+ if(vgroupb_id == FAIL) {
+ printf("fail to attach group b.\n");
+ return FAIL;
+ }
+ Vsetname(vgroupb_id,"groupB");
+ if(istat == FAIL) {
+ printf("fail to set name for groupb.\n");
+ return FAIL;
+ }
+ /* adding annotation into the file. */
+ group_tag = VQuerytag(vgroupb_id);
+ if(group_tag == FAIL) {
+ printf("query groupb tag failed.\n");
+ return FAIL;
+ }
+ group_ref = VQueryref(vgroupb_id);
+ if(group_ref == FAIL) {
+ printf("query groupb ref failed.\n");
+ return FAIL;
+ }
+
+ /* Create a data label for the Vgroup just created. */
+ ann_id = ANcreate(an_id, (uint16)group_tag,(uint16)group_ref, AN_DATA_LABEL);
+ if(ann_id == FAIL) {
+ printf("AN create interface failed.\n");
+ return FAIL;
+ }
+
+ /* Write the data label to the file. */
+ istat = ANwriteann(ann_id, data_label, (int32)(strlen(data_label)));
+ if(istat == FAIL) {
+ printf("fail to write annotation.\n");
+ return FAIL;
+ }
+ /* Terminate access to the annotation. */
+ istat = ANendaccess(ann_id);
+
+ /* Create a data description for the Vgroup just created.*/
+ ann_id = ANcreate(an_id, (uint16)group_tag, (uint16)group_ref, AN_DATA_DESC);
+ if(ann_id == FAIL) {
+ printf("AN create interface failed.\n");
+ return FAIL;
+ }
+ /* Write the data description to the file. */
+ istat = ANwriteann(ann_id, data_desc, (int32)(strlen(data_desc)));
+ if(istat == FAIL) {
+ printf("fail to write annotation.\n");
+ return FAIL;
+ }
+ /* Terminate access to the annotation. */
+ istat = ANendaccess(ann_id);
+
+ /* Terminate access to the AN interface. */
+ istat = ANend(an_id);
+ /* end of annotations. */
+
+ istat = Vsetattr(vgroupb_id, VGATTR_NAME, DFNT_CHAR, 5, "TESTb");
+ if(istat == FAIL) {
+ printf("fail to set attribute.\n");
+ return FAIL;
+ }
+ istat = Vinsert(vgroupa_id,vgroupb_id);
+ if(istat == FAIL) {
+ printf("fail to insert groupb into groupa. \n");
+ return FAIL;
+ }
+
+ vgroupc_ref = -1;
+ vgroupd_ref = -1;
+ vgroupe_ref = -1;
+ vgroupc_id = Vattach(file_id,vgroupc_ref,"w");
+ if(vgroupc_id == FAIL) {
+ printf("fail to attach groupc into file.\n");
+ return FAIL;
+ }
+
+ istat= Vsetname(vgroupc_id,"groupA");
+ if(istat == FAIL) {
+ printf("fail to set name for groupA.\n");
+ return FAIL;
+ }
+
+ vgroupd_id = Vattach(file_id,vgroupd_ref,"w");
+ if(vgroupd_id == FAIL) {
+ printf("fail to attach groupd into the file.\n");
+ return FAIL;
+ }
+
+ istat= Vsetname(vgroupd_id,"groupD");
+ if(istat == FAIL) {
+ printf("fail to set name for groupD.\n");
+ return FAIL;
+ }
+ vgroupe_id = Vattach(file_id,vgroupe_ref,"w");
+ if(vgroupe_id == FAIL) {
+ printf("fail to attach groupe into the file.\n");
+ return FAIL;
+ }
+ istat=Vsetname(vgroupe_id,"groupE");
+ if(istat == FAIL) {
+ printf("fail to set name for groupD.\n");
+ return FAIL;
+ }
+ istat = Vinsert(vgroupc_id,vgroupd_id);
+ if(istat == FAIL) {
+ printf("fail to insert groupd into groupc.\n");
+ return FAIL;
+ }
+
+ istat = Vinsert(vgroupd_id,vgroupe_id);
+ if(istat == FAIL) {
+ printf("fail to insert groupe into groupd.\n");
+ return FAIL;
+ }
+ istat = Vinsert(vgroupe_id,vgroupc_id);
+ if(istat == FAIL) {
+ printf("fail to insert groupc into groupe.\n");
+ return FAIL;
+ }
+ /* Create a new Vdata. */
+
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach vdata.\n");
+ return FAIL;
+ }
+ /* Define the field to write. */
+
+ istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 1.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 2.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_3, DFNT_FLOAT32, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 3.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_4, DFNT_CHAR8, 1);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 4.\n");
+ return FAIL;
+ }
+ istat = VSfdefine(vdata_id, FIELD_5, DFNT_FLOAT32,2);
+ if(istat == FAIL) {
+ printf("fail to define vdata field 5.\n");
+ return FAIL;
+ }
+ /* Set the Vdata name. */
+ istat = VSsetname(vdata_id, "Example Vset Name");
+ if(istat == FAIL) {
+ printf("fail to set vdata name.\n");
+ return FAIL;
+ }
+ /* Set the Vdata class. */
+ istat = VSsetclass(vdata_id, "Example Vset Class");
+ if(istat == FAIL) {
+ printf("fail to set vdata class.\n");
+ return FAIL;
+ }
+ /* Set the field names. */
+ istat = VSsetfields(vdata_id, FIELD_NAMES);
+ if(istat == FAIL) {
+ printf("fail to set fields.\n");
+ return FAIL;
+ }
+ recsize = (2 * sizeof(float32) + sizeof(int16)) +2* sizeof(float32)
+ +sizeof(char);
+ /********************debugging *********************/
+ /* + sizeof(char)); */
+
+ bufsize = recsize * NRECORDS;
+
+ databuf = (uint8 *) malloc((size_t)bufsize);
+
+ if (databuf == NULL) {
+ printf("malloc failed\n");
+ return FAIL;
+ }
+ pntr = databuf;
+
+ /* set record values */
+ for (i = 0; i < NRECORDS; i++) {
+ source[i].temp = 1.11 * (i+1);
+ source[i].height = i;
+ source[i].speed = 1.11 * (i+1);
+ source[i].ident = 'A' + i;
+ for (j=0; j< 2; j++)
+ source[i].position[j] = 1.0+j;
+
+ }
+
+ /* pack one record at a time */
+ for (i = 0; i< NRECORDS; i++) {
+ /* set field buf address */
+ fldbufpt[0] = &source[i].temp;
+ fldbufpt[1] = &source[i].height;
+ fldbufpt[2] = &source[i].speed;
+ fldbufpt[3] = &source[i].ident;
+ fldbufpt[4] = &source[i].position[0];
+ /* pack field data into databuf */
+ istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
+ recsize, 1, NULL, fldbufpt);
+ if (istat == FAIL) {
+ printf("VSfpack failed in packing record %d\n", i);
+ return FAIL;
+ }
+ pntr = pntr + recsize;
+ }
+
+ /* Write the data to the Vset object. */
+ istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
+ if(istat == FAIL) {
+ printf("fail to write vdata.\n");
+ return FAIL;
+ }
+ /* Set Vdata attribute */
+ istat = VSsetattr (vdata_id, _HDF_VDATA, "Fixed_type", DFNT_INT32, 4,
+ (VOIDP)values);
+ if(istat == FAIL) {
+ printf("fail to set vdata attribute.\n");
+ return FAIL;
+ }
+ /* Set attribute for "speed" field */
+ istat = VSsetattr (vdata_id, 2, "Symbol", DFNT_CHAR, 3, "MAX");
+ if(istat == FAIL) {
+ printf("fail to set speed attribute.\n");
+ return FAIL;
+ }
+
+ istat = VSdetach(vdata_id);
+ if(istat == FAIL) {
+ printf("fail to detach vdata.\n");
+ return FAIL;
+ }
+
+ /*** initialize another empty vdata set to test name clashings ***/
+
+ vdata_id = VSattach(file_id, -1, "w");
+ if(vdata_id == FAIL) {
+ printf("fail to attach vdata_id into file_id.\n");
+ return FAIL;
+ }
+
+ /* Set the Vdata name. */
+
+ istat = VSsetname(vdata_id, "Example Vset Name");
+ if(istat == FAIL) {
+ printf("fail to set vdata name.\n");
+ return FAIL;
+ }
+ istat = VSdetach(vdata_id);
+ if(istat == FAIL) {
+ printf("fail to detach vdata.\n");
+ return FAIL;
+ }
+
+ /* Initialize an independent Image interface. */
+ /************************************************/
+ gr_id = GRstart(file_id);
+ if(gr_id == FAIL) {
+ printf("fail to start GR interface.\n");
+ return FAIL;
+ }
+ image_ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+ image_dims[0] = X_LENGTH;
+ image_dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_1", image_ncomp, DFNT_INT16, il,
+ image_dims);
+ if(ri_id == FAIL) {
+ printf("fail to create GR object.\n");
+ return FAIL;
+ }
+
+ /* Fill the stored-data array with values. */
+
+ for (j = 0; j < Y_LENGTH; j++) {
+ for (i = 0; i < X_LENGTH; i++) {
+ image_data[j][i][0] = (i + j) + 1;
+ image_data[j][i][1] = (i + j) + 1;
+ image_data[j][i][2] =(i+j)+1;
+ }
+ }
+
+ /* Define the location, pattern, and size of the data set */
+
+ for (i = 0; i < 2; i++) {
+ image_start[i] = 0;
+ image_edges[i] = image_dims[i];
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, image_start, NULL, image_edges,
+ (VOIDP)image_data);
+
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+
+ /* Initialize the palette to grayscale. */
+ for (i = 0; i < NUM_COLORS; i++) {
+ palette_data[i * 3] = i;
+ palette_data[i * 3 + 1] = i;
+ palette_data[i * 3 + 2] = i;
+ }
+
+ /* Set palette characteristics. */
+
+ image_data_type = DFNT_UINT8;
+ image_num_entries = NUM_COLORS;
+ image_num_comp = 3;
+
+
+ /* Get the id for the palette. */
+ pal_id = GRgetlutid(ri_id,0 );
+ if(pal_id == FAIL) {
+ printf("fail to get palette id.\n");
+ return FAIL;
+ }
+
+ /* Write the palette to file. */
+ istat = GRwritelut(pal_id, image_num_comp, image_data_type,
+ 0, image_num_entries,(VOIDP)palette_data);
+ if(istat == FAIL) {
+ printf("fail to write palette.\n");
+ return FAIL;
+ }
+ image_ref = GRidtoref(ri_id);
+ if(image_ref == FAIL) {
+ printf("fail to get reference of image.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the image. */
+ istat = GRendaccess(ri_id);
+
+ /* Terminate access to the GR interface. */
+ istat = GRend(gr_id);
+
+
+ /*** III. setting SDS data and all SDS attributes. ***/
+
+ sd_id = SDstart(FILEVG,DFACC_WRITE);
+
+ if (sd_id == FAIL){
+ printf (" fail to open sd interface. \n");
+ return FAIL;
+ }
+
+ istat = SDsetfillmode(sd_id,SD_NOFILL);
+
+ if (istat == FAIL) {
+ printf("error setting fill mode\n");
+ return FAIL;
+ }
+ sds_id = SDcreate(sd_id,"sds",DFNT_INT32,3,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("fail to create sds objects.\n");
+ return FAIL;
+ }
+
+ istat = SDsetfillvalue(sds_id,(VOIDP)(&fill_value));
+
+ if (istat == FAIL){
+ printf("error setting fill value\n");
+ return FAIL;
+ }
+
+ /*** 3.1 write data. ***/
+
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+
+ if(istat == FAIL) {
+ printf(" sds data written failed. \n");
+ return FAIL;
+ }
+ /*** 3.2 write dataset attribute ***/
+
+ istat = SDsetattr(sds_id,"sds.attr",DFNT_CHAR8,10,(VOIDP)attr_value);
+ if(istat == FAIL) {
+ printf(" sds data attr. setting failed. \n");
+ return FAIL;
+ }
+ /*** 3.3 write dataset predefined attribute ***/
+
+ istat = SDsetdatastrs(sds_id,label,unit,format,coordsys);
+ if(istat == FAIL) {
+ printf(" sds data predefined attr. setting failed. \n");
+ return FAIL;
+ }
+ /*** 3.4 set calibration information. ***/
+
+ istat = SDsetcal(sds_id,cal,cal_err,offset,offset_err,DFNT_INT32);
+ if(istat == FAIL) {
+ printf(" sds data calibrating attr. setting failed. \n");
+ return FAIL;
+ }
+
+ /*** 3.5 write down dimension scale dataset. ***/
+
+ for (i =0; i<TYP_RANK;i++) {
+ dim_id = SDgetdimid(sds_id,i);
+ if(dim_id <0) {
+ printf("sds set dim id failed. \n");
+ return FAIL;
+ }
+ if (i==0) {
+ istat = SDsetdimname(dim_id,dim_name0);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat= SDsetdimscale(dim_id,dim_sizes[0],DFNT_INT32,(VOIDP)dimo_sca);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ }
+ else {
+ istat = SDsetdimname(dim_id,dim_name1);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat = SDsetdimscale(dim_id,dim_sizes[1],DFNT_INT32,(VOIDP)dimo_sca);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ }
+
+ istat=SDsetdimstrs(dim_id,dim_label,dim_unit,dim_format);
+ if(istat == FAIL) {
+ printf("sds set dim. predefined attr. failed. \n");
+ return FAIL;
+ }
+ istat = SDsetattr(dim_id,"sdsdim.attr",DFNT_CHAR8,10,(VOIDP)attr_value);
+
+ if(istat == FAIL) {
+ printf(" sds dim data attr. setting failed. \n");
+ return FAIL;
+ }
+ SDendaccess(dim_id);
+ }
+
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("fail to transfer id to reference.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupb_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add reference into vgroup.\n");
+ return FAIL;
+ }
+
+ SDendaccess(sds_id);
+ SDend(sd_id);
+
+ sd_id = SDstart(FILEVG,DFACC_WRITE);
+
+ if (sd_id == FAIL){
+ printf (" open file failed\n");
+ return FAIL;
+ }
+ istat = SDsetfillmode(sd_id,SD_NOFILL);
+
+ if (istat == FAIL){
+ printf("error setting fill mode\n");
+ return FAIL;
+ }
+ sds_id = SDcreate(sd_id,"sds2",DFNT_INT32,3,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("fail to create sds id.\n");
+ return FAIL;
+ }
+ istat = SDsetfillvalue(sds_id,(VOIDP)(&fill_value));
+
+ if (istat == FAIL){
+ printf("error setting fill value\n");
+ return FAIL;
+ }
+ /*** 3.1 write data. ***/
+
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+ if(istat == FAIL) {
+ printf("fail to write sds data.\n");
+ return FAIL;
+ }
+
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("fail to generate reference number.\n");
+ return FAIL;
+ }
+
+ istat = Vaddtagref(vgroupd_id,DFTAG_NDG,sds_ref);
+ if(istat == FAIL) {
+ printf("fail to add sds reference into groupd.\n");
+ return FAIL;
+ }
+
+ SDendaccess(sds_id);
+ SDend(sd_id);
+
+ sd_id = SDstart(FILEVG,DFACC_WRITE);
+ if (sd_id == FAIL) {
+ printf (" open file failed\n");
+ return FAIL;
+ }
+
+ istat = SDsetfillmode(sd_id,SD_NOFILL);
+
+ if (istat == FAIL) {
+ printf("error setting fill mode. \n");
+ return FAIL;
+ }
+
+ sds_id = SDcreate(sd_id,"sds2",DFNT_INT32,3,dim_sizes);
+ if(sds_id == FAIL) {
+ printf("error creating sds objects.\n");
+ return FAIL;
+ }
+
+ istat = SDsetfillvalue(sds_id,(VOIDP)(&fill_value));
+
+ if (istat == FAIL) {
+ printf("error setting fill value\n");
+ return FAIL;
+ }
+
+ /*** 3.1 write data. ***/
+
+ istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
+
+ if(istat == FAIL) {
+ printf("error writing sds object.\n");
+ return FAIL;
+ }
+
+ SDendaccess(sds_id);
+ SDend(sd_id);
+
+ gr_id = GRstart(file_id);
+ if(gr_id == FAIL) {
+ printf("error starting gr interface.\n");
+ return FAIL;
+ }
+
+ image_ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+ image_dims[0] = X_LENGTH;
+ image_dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_1", image_ncomp, DFNT_INT16, il,
+ image_dims);
+
+ if(ri_id == FAIL) {
+ printf("fail to creat GR interface.\n");
+ return FAIL;
+ }
+
+ /* Fill the stored-data array with values. */
+
+ for (j = 0; j < Y_LENGTH; j++) {
+ for (i = 0; i < X_LENGTH; i++) {
+ image_data[j][i][0] = (i + j) + 2;
+ image_data[j][i][1] = (i + j) + 3;
+ image_data[j][i][2] =(i+j)+1;
+ }
+ }
+
+ /* Define the location, pattern, and size of the data set */
+
+ for (i = 0; i < 2; i++) {
+ image_start[i] = 0;
+ image_edges[i] = image_dims[i];
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, image_start, NULL, image_edges,
+ (VOIDP)image_data);
+
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+
+ /* Initialize the palette to grayscale. */
+ for (i = 0; i < NUM_COLORS; i++) {
+ palette_data[i * 3] = i;
+ palette_data[i * 3 + 1] = i;
+ palette_data[i * 3 + 2] = i;
+ }
+
+ /* Set palette characteristics. */
+
+ image_data_type = DFNT_UINT8;
+ image_num_entries = NUM_COLORS;
+ image_num_comp = 3;
+
+
+ /* Get the id for the palette. */
+ pal_id = GRgetlutid(ri_id,0 );
+
+ if(pal_id == FAIL) {
+ printf("fail to get palette id.\n");
+ return FAIL;
+ }
+
+ /* Write the palette to file. */
+ istat = GRwritelut(pal_id, image_num_comp, image_data_type,
+ 0, image_num_entries,(VOIDP)palette_data);
+ if(istat == FAIL) {
+ printf("fail to write palette data.\n");
+ return FAIL;
+ }
+
+ image_ref = GRidtoref(ri_id);
+ if(image_ref == FAIL) {
+ printf("fail to obtain image reference number.\n");
+ return FAIL;
+ }
+ istat = Vaddtagref(vgroupd_id,DFTAG_RIG,image_ref);
+ if(istat == FAIL) {
+ printf("fail to add image into group vgroupd\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the image. */
+ istat = GRendaccess(ri_id);
+ if(istat == FAIL) {
+ printf("fail to end GR interface.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the GR interface. */
+ istat = GRend(gr_id);
+
+ gr_id = GRstart(file_id);
+ if(gr_id == FAIL) {
+ printf("fail to start GR interface.\n");
+ return FAIL;
+ }
+
+ image_ncomp = 3;
+ il = MFGR_INTERLACE_PIXEL;
+ image_dims[0] = X_LENGTH;
+ image_dims[1] = Y_LENGTH;
+
+ /* Create the array. */
+ ri_id = GRcreate(gr_id, "Image_2", image_ncomp, DFNT_INT16, il,
+ image_dims);
+ if(ri_id == FAIL) {
+ printf("fail to create GR interface.\n");
+ return FAIL;
+ }
+
+ /* Fill the stored-data array with values. */
+
+ for (j = 0; j < Y_LENGTH; j++) {
+ for (i = 0; i < X_LENGTH; i++) {
+ image_data[j][i][0] = (i + j) + 2;
+ image_data[j][i][1] = (i + j) + 3;
+ image_data[j][i][2] =(i+j)+1;
+ }
+ }
+
+ /* Define the location, pattern, and size of the data set */
+
+ for (i = 0; i < 2; i++) {
+ image_start[i] = 0;
+ image_edges[i] = image_dims[i];
+ }
+
+ /* Write the stored data to the image array. */
+ istat = GRwriteimage(ri_id, image_start, NULL, image_edges,
+ (VOIDP)image_data);
+
+ if(istat == FAIL) {
+ printf("fail to write image.\n");
+ return FAIL;
+ }
+
+ /* Initialize the palette to grayscale. */
+ for (i = 0; i < NUM_COLORS; i++) {
+ palette_data[i * 3] = i;
+ palette_data[i * 3 + 1] = i;
+ palette_data[i * 3 + 2] = i;
+ }
+
+ /* Set palette characteristics. */
+
+ image_data_type = DFNT_UINT8;
+ image_num_entries = NUM_COLORS;
+ image_num_comp = 3;
+
+
+ /* Get the id for the palette. */
+ pal_id = GRgetlutid(ri_id,0 );
+ if(pal_id == FAIL) {
+ printf("fail to obtain palette id.\n");
+ return FAIL;
+ }
+
+ /* Write the palette to file. */
+ istat = GRwritelut(pal_id, image_num_comp, image_data_type,
+ 0, image_num_entries,(VOIDP)palette_data);
+
+ if(istat == FAIL) {
+ printf("fail to write GR image.\n");
+ return FAIL;
+ }
+
+ image_ref = GRidtoref(ri_id);
+ if(image_ref == FAIL) {
+ printf("fail to generate image reference number.\n");
+ return FAIL;
+ }
+
+ istat = Vaddtagref(vgroupa_id,DFTAG_RIG,image_ref);
+ if(istat == FAIL) {
+ printf("fail to add image into vgroupa\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the image. */
+ istat = GRendaccess(ri_id);
+
+ /* Terminate access to the GR interface. */
+ istat = GRend(gr_id);
+
+ istat =Vdetach(vgroupb_id);
+ /* Detach from the vgroup, close the V interface and the file. */
+ istat = Vdetach(vgroupa_id);
+ istat = Vdetach(vgroupc_id);
+ istat = Vdetach(vgroupd_id);
+ istat = Vdetach(vgroupe_id);
+ istat = Vend(file_id);
+
+ istat = Hclose(file_id);
+ return 0;
+}
+/* this routine creates annotation for four cases:
+
+1. file label
+2. file description
+3. object label(vgroup)
+4. object description(vgroup)
+
+*/
+
+int test_anno() {
+
+ int32 file_id, an_id, ann_id, vgroup_id,istat;
+ uint16 obj_tag, obj_ref;
+ static char file_label[] = "This is a file label.";
+ static char file_desc[] = "This is a file description.";
+ static char data_labelvg[] = "This is a vgroup data label.";
+ static char data_descvg[] = "This is a vgroup data description.";
+
+ /* Create the HDF file. */
+ file_id = Hopen(FILEANNO, DFACC_CREATE, 0);
+ if(file_id == FAIL) {
+ printf("fail to open HDF file \n");
+ return FAIL;
+ }
+ /* Initialize the AN interface and obtain an interface id. */
+ an_id = ANstart(file_id);
+ if(an_id == FAIL) {
+ printf("fail to start annotation interface.\n");
+ return FAIL;
+ }
+
+ /* Create a file label and obtain an annotation id. */
+ ann_id = ANcreatef(an_id, AN_FILE_LABEL);
+ if(ann_id == FAIL) {
+ printf("fail to create annotation id.\n");
+ return FAIL;
+ }
+
+ /* Write the file label to the file. */
+ istat = ANwriteann(ann_id, file_label, (int32)(strlen(file_label)));
+ if(istat == FAIL) {
+ printf("fail to write annotation.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the annotation. */
+ istat = ANendaccess(ann_id);
+
+ /* Create a file description. */
+ ann_id = ANcreatef(an_id, AN_FILE_DESC);
+ if(ann_id == FAIL) {
+ printf("fail to create annotation\n");
+ return FAIL;
+ }
+
+ /* Write the file description to the file. */
+ istat = ANwriteann(ann_id, file_desc, (int32)(strlen(file_desc)));
+ if(istat == FAIL) {
+ printf("fail to write annotation.\n");
+ return FAIL;
+ }
+
+ /* Terminate access to the annotation. */
+ istat = ANendaccess(ann_id);
+
+ /* Create a vgroup. */
+ istat = Vstart(file_id);
+ if(istat == FAIL) {
+ printf("fail to start v interface.\n");
+ return FAIL;
+ }
+
+ vgroup_id = Vattach(file_id, -1, "w");
+ if(vgroup_id == FAIL) {
+ printf("fail to attach vgroup \n");
+ return FAIL;
+ }
+
+ istat = Vsetname (vgroup_id, "Vgroup w/Annotations");
+ if(istat == FAIL) {
+ printf("fail to set group name\n");
+ return FAIL;
+ }
+ /* Get reference number of vgroup just created. */
+ obj_ref = Vfind (file_id, "Vgroup w/Annotations");
+ if(obj_ref == 0) {
+ printf("fail to set object reference.\n");
+ return FAIL;
+ }
+ obj_tag = DFTAG_VG;
+
+ /* Create a data label for the Vgroup just created. */
+ ann_id = ANcreate(an_id, (uint16)obj_tag, (uint16)obj_ref, AN_DATA_LABEL);
+ if(ann_id == FAIL) {
+ printf("fail to create annotation.\n");
+ return FAIL;
+ }
+ /* Write the data label to the file. */
+ istat = ANwriteann(ann_id, data_labelvg, (int)(strlen(data_labelvg)));
+ if(istat == FAIL){
+ printf("fail to write annotation.\n");
+ return FAIL;
+ }
+ istat = ANendaccess(ann_id);
+
+ obj_tag = DFTAG_VG;
+
+ /* Create a data description for the Vgroup just created.*/
+ ann_id = ANcreate(an_id, (uint16)obj_tag, (uint16)obj_ref, AN_DATA_DESC);
+ if(ann_id == FAIL) {
+ printf("fail to create annotation.\n");
+ return FAIL;
+ }
+
+ /* Write the data description to the file. */
+ istat = ANwriteann(ann_id, data_descvg, (int)(strlen(data_descvg)));
+ if(istat == FAIL) {
+ printf("fail to write annotation.\n");
+ return FAIL;
+ }
+ /* Terminate access to the annotation. */
+ istat = ANendaccess(ann_id);
+ istat = Vdetach(vgroup_id);
+ istat = Vend(file_id);
+ /* Close the file. */
+
+ /* Terminate access to the AN interface. */
+ istat = ANend(an_id);
+ istat = Hclose(file_id);
+ return 0;
+}
+
+
+
+
+
+
+
diff --git a/tools/h4toh5/h4toh5util.h b/tools/h4toh5/h4toh5util.h
new file mode 100644
index 0000000..ba2420f
--- /dev/null
+++ b/tools/h4toh5/h4toh5util.h
@@ -0,0 +1,232 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+Including declarations of global variables,global hashtables,constant
+and utility subroutines of h4toh5util.c
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
+
+#ifndef UTILITY_H
+#define UTILITY_H
+#include "hdf5.h"
+#include "hdf.h"
+
+/**********************************************/
+/*************** section I *******************/
+/*This section of the file describes reserved
+name and global parameters used in h4-h5
+converter.*/
+/*********************************************/
+
+/* 0. if "/" is found in hdf4 object name, we will use another
+ character "_" to replace it, since "/" is a reserved symbol for hdf5. */
+
+#define ORI_SLASH '/'
+#define CHA_SLASH '_'
+
+/* 1. character string used for default attribute name. */
+#define ATTR "ATTR"
+
+/* 2. Predefined HDF5 Attribute name for HDF4 file */
+
+#define HDF4_OBJECT_NAME "HDF4_OBJECT_NAME"
+#define HDF4_OBJECT_TYPE "HDF4_OBJECT_TYPE"
+#define HDF4_REF_NUM "HDF4_REF_NUM"
+#define HDF4_VGROUP_CLASS "HDF4_VGROUP_CLASS"
+#define HDF4_IMAGE_CLASS "CLASS"
+#define HDF4_IMAGE_SUBCLASS "IMAGE_SUBCLASS"
+#define HDF4_PALETTE_CLASS "CLASS"
+#define HDF4_PALETTE_TYPE "PAL_TYPE"
+#define PAL_TYPE "STANDARD8"
+#define PAL_COLORMODEL "PAL_COLORMODEL"
+#define HDF5_RGB "RGB"
+/* 3. reserved name for HDF5 object name when meeting with name clashing. */
+
+#define HDF4_VGROUP "HDF4_VGROUP"
+#define HDF4_PALETTE "HDF4_PALETTE"
+#define HDF4_SDS "HDF4_SDS"
+#define HDF4_VDATA "HDF4_VDATA"
+#define HDF4_IMAGE "HDF4_IMAGE"
+#define HDF4_DIMSCALE "HDF4_DIMSCALE"
+
+/* 4. global palette and dimension_list name. */
+#define HDF4_IMAGE_PALETTE "HDF4_IMAGE_PALETTE"
+#define HDF4_DIMENSION_LIST "HDF4_DIMENSION_LIST"
+#define PALETTE "PALETTE"
+
+#define DIMSCALE "DIMSCALE"
+
+/* 5. define affix GLO for sds and image file attributes. these file attributes
+ will be put under root group. */
+#define GLOSDS "GLOSDS"
+#define GLOIMAGE "GLOIMAGE"
+
+/* 6. define HDF object label.*/
+#define SDSLABEL "SDS"
+#define VDATALABEL "Vdata"
+#define VGROUPLABEL "Vgroup"
+#define GRLABEL "GR"
+#define RAST8LABEL "raster8"
+#define RAST24LABEL "raster24"
+#define PALABEL "palette"
+
+/* 7. define "IMAGE" CLASS required by image spec. */
+#define IM_CLASS "IMAGE"
+
+/* 8. reserved group name for HDF4 dimensional scale and palette. */
+#define HDF4_DIMG "/HDF4_DIMGROUP"
+#define HDF4_PALG "/HDF4_PALGROUP"
+
+/* 9. reserved name for hdf4 file label,file description, object label,
+ object description. */
+#define HDF4_FILE_LABEL "HDF4_FILE_LABEL"
+#define HDF4_FILE_DESC "HDF4_FILE_DESCRIPTION"
+#define HDF4_OBJECT_LABEL "HDF4_OBJECT_LABEL"
+#define HDF4_OBJECT_DESC "HDF4_OBJECT_DESCRIPTION"
+#define HDF4_SDS_LABEL "HDF4_SDS_LABEL"
+#define HDF4_SDS_DESC "HDF4_SDS_DESC"
+#define HDF4_IMAGE_LABEL "HDF4_IMAGE_LABEL"
+#define HDF4_IMAGE_DESC "HDF4_IMAGE_DESC"
+#define HDF4_VDATA_LABEL "HDF4_VDATA_LABEL"
+#define HDF4_VDATA_DESC "HDF4_VDATA_DESC"
+#define HDF4_VGROUP_LABEL "HDF4_VGROUP_LABEL"
+#define HDF4_VGROUP_DESC "HDF4_VGROUP_DESC"
+#define HDF4_PAL_LABEL "HDF4_PAL_LABEL"
+#define HDF4_PAL_DESC "HDF4_PAL_DESC"
+#define HDF4_IMAGE_INDEXED "HDF4_IMAGE_INDEXED"
+
+/*10. palette and dimensional scale hash size and the
+ maximum length of object reference number in string format.
+ global variables of vgroup, vdata, sds, image and total number of
+ the object, number of global sds attributes and GR attributes.*/
+
+#define PAL_HASHSIZE 64
+#define DIM_HASHSIZE 64
+#define VG_DEFHASHSIZE 64
+#define VD_DEFHASHSIZE 64
+#define MAXREF_LENGTH 5
+/*considering the string size of HDF4_DIMGROUP. we add this into 276.*/
+#define MAX_DIM_NAME 276
+#define MAX_PAL_NAME 32
+/*11. adding a specified vdata class name to deal with the situation when
+independent vdata is hdf chunking table _HDF_CHK_TBL_CLASS, if it becomes
+public constant for hdf lib, this constant can be released.*/
+#define _HDF_CHK_TBL_CLASS "_HDF_CHK_TBL_"
+
+extern int32 estnum_vg;
+extern int32 estnum_vd;
+extern int32 num_sds;
+extern int32 num_images;
+extern int num_objects;
+extern int32 num_glsdsattrs;
+extern int32 num_glgrattrs;
+
+/**********************************************/
+/*************** section II *******************/
+/*This section describes hash tables and their
+ functions used in h4-h5 converter.*/
+/*********************************************/
+/*define two kinds of hashtables.
+ 1. struct table uses object reference as the key to handle whether this
+ object is visited or not.
+ 2. struct name_table uses object name as the key to handle name clashings and
+ dimensional scale dataset.
+*/
+
+struct table {
+ int ref;
+ struct table *next;
+ char *name;
+};
+
+struct name_table {
+ char *name;
+ struct name_table *next;
+};
+
+extern struct table* sds_hashtab;
+extern struct table* gr_hashtab;
+extern struct table* vg_hashtab;
+extern struct table* vd_hashtab;
+extern struct table* pal_hashtab;
+extern struct name_table* name_hashtab;
+extern struct name_table* dim_hashtab;
+
+/* routine for zeroing out the memory. */
+void h4toh5_ZeroMemory(void*s,size_t n);
+
+/* look-up table, object reference is the key.*/
+int lookup(int,int,struct table*);
+
+/*look-up table, key is name. */
+int hash_fun(char*name,int size);
+int lookup_name(char*, int,struct name_table*);
+
+/* routines that initialize the tables and name tables.*/
+int init_tab(int,struct table*);
+int init_nametab(int,struct name_table*);
+
+/* get name and set name for table. */
+char* get_name(int,int,struct table *,int*);
+int set_name(int,int,struct table *,char*);
+
+/* free table routines. */
+int freetable(int,struct table *);
+int freenametable(int, struct name_table*);
+void freehashmemory(void);
+
+/**********************************************/
+/*************** section III *******************/
+/*This section describes other common routines and their
+ functions used in h4-h5 converter.*/
+/*********************************************/
+
+/* this routine defines the conversion of data type from h4 to h5. */
+herr_t h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
+ size_t* h4memsize, size_t* h4size, hid_t *h5type);
+
+/* routines for translating predefined hdf4 attributes into hdf5 attributes*/
+int h4_transpredattrs(hid_t ,const char *,char*data);
+int h4_transnumattr(hid_t h5g,const char *,uint16 group_ref);
+int vg_transattrs(int32,hid_t);
+
+/*string and int conversion routines.*/
+hid_t mkstr(int size, H5T_str_t pad);
+herr_t h5string_to_int(const int32, hid_t*,const size_t,hid_t* );
+int conv_int_str(uint16, char*);
+
+/* these routines were utility functions for other routines at h4toh5util.c */
+char* trans_obj_name(int32,int32);
+char* get_obj_aboname(char*,char*,char*,const char*);
+char* make_objname_no(char*,char*,const char*);
+char* make_objname_yes(char*,char*);
+char* correct_name(char*);
+
+#endif
+
+
+
+
diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c
new file mode 100644
index 0000000..45a726f
--- /dev/null
+++ b/tools/h5ls/h5ls.c
@@ -0,0 +1,2167 @@
+/*
+ * Copyright (C) 1998 NCSA
+ * All rights reserved.
+ *
+ * Programmer: Robb Matzke <matzke@llnl.gov>
+ * Monday, March 23, 1998
+ */
+
+
+/*
+ * We include the private header file so we can get to the uniform
+ * programming environment it declares. Other than that, h5ls only calls
+ * HDF5 API functions (except for H5G_basename())
+ */
+#include <H5private.h>
+#include <h5tools.h>
+
+/*
+ * If defined then include the file name as part of the object name when
+ * printing full object names. Otherwise leave the file name off.
+ */
+#define H5LS_PREPEND_FILENAME
+
+/* Command-line switches */
+static int verbose_g = 0; /*lots of extra output */
+static int width_g = 80; /*output width in characters */
+static hbool_t address_g = FALSE; /*print raw data addresses */
+static hbool_t data_g = FALSE; /*display dataset values? */
+static hbool_t label_g = FALSE; /*label compound values? */
+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 */
+static hbool_t show_errors_g = FALSE; /*print HDF5 error messages */
+static hbool_t simple_output_g = FALSE; /*make output more machine-readable */
+
+/* Info to pass to the iteration functions */
+typedef struct iter_t {
+ const char *container; /*full name of the container object */
+} iter_t;
+
+/* Table containing object id and object name */
+static struct {
+ int nalloc; /*number of slots allocated */
+ int nobjs; /*number of objects */
+ struct {
+ unsigned long id[2]; /*object number */
+ char *name; /*full object name */
+ } *obj;
+} idtab_g;
+
+/* Information about how to display each type of object */
+static struct dispatch_t {
+ const char *name;
+ hid_t (*open)(hid_t loc, const char *name);
+ herr_t (*close)(hid_t obj);
+ herr_t (*list1)(hid_t obj);
+ herr_t (*list2)(hid_t obj, const char *name);
+} dispatch_g[H5G_NTYPES];
+
+#define DISPATCH(TYPE,NAME,OPEN,CLOSE,LIST1,LIST2) { \
+ dispatch_g[TYPE].name = (NAME); \
+ dispatch_g[TYPE].open = (OPEN); \
+ dispatch_g[TYPE].close = (CLOSE); \
+ dispatch_g[TYPE].list1 = (LIST1); \
+ dispatch_g[TYPE].list2 = (LIST2); \
+}
+
+static herr_t list (hid_t group, const char *name, void *cd);
+static void display_type(hid_t type, int ind);
+static char *fix_name(const char *path, const char *base);
+
+
+/*-------------------------------------------------------------------------
+ * Function: usage
+ *
+ * Purpose: Prints a usage message on stderr and then returns.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Thursday, July 16, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+usage (const char *progname)
+{
+ fprintf(stderr, "\
+usage: %s [OPTIONS] [OBJECTS...]\n\
+ OPTIONS\n\
+ -h, -?, --help Print a usage message and exit\n\
+ -a, --address Print addresses for raw data\n\
+ -d, --data Print the values of datasets\n\
+ -e, --errors Show all HDF5 error reporting\n\
+ -f, --full Print full path names instead of base names\n\
+ -g, --group Show information about a group, not its contents\n\
+ -l, --label Label members of compound datasets\n\
+ -r, --recursive List all groups recursively, avoiding cycles\n\
+ -s, --string Print 1-byte integer datasets as ASCII\n\
+ -S, --simple Use a machine-readable output format\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\
+\n\
+ OBJECTS\n\
+ Each object consists of an HDF5 file name optionally followed by a\n\
+ slash and an object name within the file (if no object is specified\n\
+ within the file then the contents of the root group are displayed).\n\
+ The file name may include a printf(3C) integer format such as\n\
+ \"%%05d\" to open a file family.\n",
+ progname);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: sym_insert
+ *
+ * Purpose: Add a symbol to the table.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Thursday, January 21, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+sym_insert(H5G_stat_t *sb, const char *name)
+{
+ int n;
+
+ /*
+ * Don't add it if the link count is 1 because such an object can only
+ * have one name.
+ */
+ if (sb->nlink<2) return;
+
+ /* Extend the table */
+ if (idtab_g.nobjs>=idtab_g.nalloc) {
+ idtab_g.nalloc = MAX(256, 2*idtab_g.nalloc);
+ idtab_g.obj = realloc(idtab_g.obj,
+ idtab_g.nalloc*sizeof(idtab_g.obj[0]));
+ }
+
+ /* Insert the entry */
+ n = idtab_g.nobjs++;
+ idtab_g.obj[n].id[0] = sb->objno[0];
+ idtab_g.obj[n].id[1] = sb->objno[1];
+ idtab_g.obj[n].name = malloc(strlen(name)+1);
+ strcpy(idtab_g.obj[n].name, name);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: sym_lookup
+ *
+ * Purpose: Find another name for the specified object.
+ *
+ * Return: Success: Ptr to another name.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Thursday, January 21, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static char *
+sym_lookup(H5G_stat_t *sb)
+{
+ int n;
+
+ if (sb->nlink<2) return NULL; /*only one name possible*/
+ for (n=0; n<idtab_g.nobjs; n++) {
+ if (idtab_g.obj[n].id[0]==sb->objno[0] &&
+ idtab_g.obj[n].id[1]==sb->objno[1]) {
+ return idtab_g.obj[n].name;
+ }
+ }
+ return NULL;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_string
+ *
+ * Purpose: Print a string value by escaping unusual characters. If
+ * STREAM is null then we only count how large the output would
+ * be.
+ *
+ * Return: Number of characters printed.
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+display_string(FILE *stream, const char *s, hbool_t escape_spaces)
+{
+ int nprint=0;
+
+ for (/*void*/; s && *s; s++) {
+ switch (*s) {
+ case '"':
+ if (stream) fprintf(stream, "\\\"");
+ nprint += 2;
+ break;
+ case '\\':
+ if (stream) fprintf(stream, "\\\\");
+ nprint += 2;
+ break;
+ case '\b':
+ if (stream) fprintf(stream, "\\b");
+ nprint += 2;
+ break;
+ case '\f':
+ if (stream) fprintf(stream, "\\f");
+ nprint += 2;
+ break;
+ case '\n':
+ if (stream) fprintf(stream, "\\n");
+ nprint += 2;
+ break;
+ case '\r':
+ if (stream) fprintf(stream, "\\r");
+ nprint += 2;
+ break;
+ case '\t':
+ if (stream) fprintf(stream, "\\t");
+ nprint += 2;
+ break;
+ case ' ':
+ if (escape_spaces) {
+ if (stream) fprintf(stream, "\\ ");
+ nprint += 2;
+ } else {
+ if (stream) fprintf(stream, " ");
+ nprint++;
+ }
+ break;
+ default:
+ if (isprint((int)*s)) {
+ if (stream) putc(*s, stream);
+ nprint++;
+ } else {
+ if (stream) {
+ fprintf(stream, "\\%03o", *((const unsigned char*)s));
+ }
+ nprint += 4;
+ }
+ break;
+ }
+ }
+ return nprint;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_native_type
+ *
+ * Purpose: Prints the name of a native C data type.
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE, nothing printed.
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ * Robb Matzke, 1999-06-11
+ * Added the C9x types, but we still prefer to display the types
+ * from the C language itself (like `int' vs. `int32_t').
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_native_type(hid_t type, int UNUSED ind)
+{
+ if (H5Tequal(type, H5T_NATIVE_SCHAR)) {
+ printf("native signed char");
+ } else if (H5Tequal(type, H5T_NATIVE_UCHAR)) {
+ printf("native unsigned char");
+ } else if (H5Tequal(type, H5T_NATIVE_INT)) {
+ printf("native int");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
+ printf("native unsigned int");
+ } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
+ printf("native short");
+ } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
+ printf("native unsigned short");
+ } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
+ printf("native long");
+ } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
+ printf("native unsigned long");
+ } else if (H5Tequal(type, H5T_NATIVE_LLONG)) {
+ printf("native long long");
+ } else if (H5Tequal(type, H5T_NATIVE_ULLONG)) {
+ printf("native unsigned long long");
+ } else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
+ printf("native float");
+ } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
+ printf("native double");
+ } else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)) {
+ printf("native long double");
+ } else if (H5Tequal(type, H5T_NATIVE_INT8)) {
+ printf("native int8_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT8)) {
+ printf("native uint8_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT16)) {
+ printf("native int16_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT16)) {
+ printf("native uint16_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT32)) {
+ printf("native int32_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT32)) {
+ printf("native uint32_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT64)) {
+ printf("native int64_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT64)) {
+ printf("native uint64_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST8)) {
+ printf("native int_least8_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST8)) {
+ printf("native uint_least8_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST16)) {
+ printf("native int_least16_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST16)) {
+ printf("native uint_least16_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST32)) {
+ printf("native int_least32_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST32)) {
+ printf("native uint_least32_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST64)) {
+ printf("native int_least64_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST64)) {
+ printf("native uint_least64_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT_FAST8)) {
+ printf("native int_fast8_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST8)) {
+ printf("native uint_fast8_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT_FAST16)) {
+ printf("native int_fast16_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST16)) {
+ printf("native uint_fast16_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT_FAST32)) {
+ printf("native int_fast32_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST32)) {
+ printf("native uint_fast32_t");
+ } else if (H5Tequal(type, H5T_NATIVE_INT_FAST64)) {
+ printf("native int_fast64_t");
+ } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST64)) {
+ printf("native uint_fast64_t");
+ } else if (H5Tequal(type, H5T_NATIVE_B8)) {
+ printf("native 8-bit field");
+ } else if (H5Tequal(type, H5T_NATIVE_B16)) {
+ printf("native 16-bit field");
+ } else if (H5Tequal(type, H5T_NATIVE_B32)) {
+ printf("native 32-bit field");
+ } else if (H5Tequal(type, H5T_NATIVE_B64)) {
+ printf("native 64-bit field");
+ } else if (H5Tequal(type, H5T_NATIVE_HSIZE)) {
+ printf("native hsize_t");
+ } else if (H5Tequal(type, H5T_NATIVE_HSSIZE)) {
+ printf("native hssize_t");
+ } else if (H5Tequal(type, H5T_NATIVE_HERR)) {
+ printf("native herr_t");
+ } else if (H5Tequal(type, H5T_NATIVE_HBOOL)) {
+ printf("native hbool_t");
+ } else {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_ieee_type
+ *
+ * Purpose: Print the name of an IEEE floating-point data type.
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE, nothing printed
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_ieee_type(hid_t type, int UNUSED ind)
+{
+ if (H5Tequal(type, H5T_IEEE_F32BE)) {
+ printf("IEEE 32-bit big-endian float");
+ } else if (H5Tequal(type, H5T_IEEE_F32LE)) {
+ printf("IEEE 32-bit little-endian float");
+ } else if (H5Tequal(type, H5T_IEEE_F64BE)) {
+ printf("IEEE 64-bit big-endian float");
+ } else if (H5Tequal(type, H5T_IEEE_F64LE)) {
+ printf("IEEE 64-bit little-endian float");
+ } else {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_precision
+ *
+ * Purpose: Prints information on the next line about precision and
+ * padding if the precision is less than the total data type
+ * size.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+display_precision(hid_t type, int ind)
+{
+ size_t prec; /*precision */
+ H5T_pad_t plsb, pmsb; /*lsb and msb padding */
+ const char *plsb_s=NULL; /*lsb padding string */
+ const char *pmsb_s=NULL; /*msb padding string */
+ size_t nbits; /*number of bits */
+
+ /*
+ * If the precision is less than the total size then show the precision
+ * and offset on the following line. Also display the padding
+ * information.
+ */
+ if (8*H5Tget_size(type)!=(prec=H5Tget_precision(type))) {
+ printf("\n%*s(%lu bit%s of precision beginning at bit %lu)",
+ ind, "", (unsigned long)prec, 1==prec?"":"s",
+ (unsigned long)H5Tget_offset(type));
+
+ H5Tget_pad(type, &plsb, &pmsb);
+ if (H5Tget_offset(type)>0) {
+ switch (plsb) {
+ case H5T_PAD_ZERO:
+ plsb_s = "zero";
+ break;
+ case H5T_PAD_ONE:
+ plsb_s = "one";
+ break;
+ case H5T_PAD_BACKGROUND:
+ plsb_s = "bkg";
+ break;
+ case H5T_PAD_ERROR:
+ case H5T_NPAD:
+ plsb_s = "unknown";
+ break;
+ }
+ }
+ if (H5Tget_offset(type)+prec<8*H5Tget_size(type)) {
+ switch (pmsb) {
+ case H5T_PAD_ZERO:
+ pmsb_s = "zero";
+ break;
+ case H5T_PAD_ONE:
+ pmsb_s = "one";
+ break;
+ case H5T_PAD_BACKGROUND:
+ pmsb_s = "bkg";
+ break;
+ case H5T_PAD_ERROR:
+ case H5T_NPAD:
+ pmsb_s = "unknown";
+ break;
+ }
+ }
+ if (plsb_s || pmsb_s) {
+ printf("\n%*s(", ind, "");
+ if (plsb_s) {
+ nbits = H5Tget_offset(type);
+ printf("%lu %s bit%s at bit 0",
+ (unsigned long)nbits, plsb_s, 1==nbits?"":"s");
+ }
+ if (plsb_s && pmsb_s) printf(", ");
+ if (pmsb_s) {
+ nbits = 8*H5Tget_size(type)-(H5Tget_offset(type)+prec);
+ printf("%lu %s bit%s at bit %lu",
+ (unsigned long)nbits, pmsb_s, 1==nbits?"":"s",
+ (unsigned long)(8*H5Tget_size(type)-nbits));
+ }
+ printf(")");
+ }
+ }
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_int_type
+ *
+ * Purpose: Print the name of an integer data type. Common information
+ * like number of bits, byte order, and sign scheme appear on
+ * the first line. Additional information might appear in
+ * parentheses on the following lines.
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE, nothing printed
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_int_type(hid_t type, int ind)
+{
+ H5T_order_t order; /*byte order value */
+ const char *order_s=NULL; /*byte order string */
+ H5T_sign_t sign; /*sign scheme value */
+ const char *sign_s=NULL; /*sign scheme string */
+
+ if (H5T_INTEGER!=H5Tget_class(type)) return FALSE;
+
+ /* Byte order */
+ if (H5Tget_size(type)>1) {
+ order = H5Tget_order(type);
+ if (H5T_ORDER_LE==order) {
+ order_s = " little-endian";
+ } else if (H5T_ORDER_BE==order) {
+ order_s = " big-endian";
+ } else if (H5T_ORDER_VAX==order) {
+ order_s = " mixed-endian";
+ } else {
+ order_s = " unknown-byte-order";
+ }
+ } else {
+ order_s = "";
+ }
+
+ /* Sign */
+ if ((sign=H5Tget_sign(type))>=0) {
+ if (H5T_SGN_NONE==sign) {
+ sign_s = " unsigned";
+ } else if (H5T_SGN_2==sign) {
+ sign_s = "";
+ } else {
+ sign_s = " unknown-sign";
+ }
+ } else {
+ sign_s = " unknown-sign";
+ }
+
+ /*
+ * Print size, order, and sign on first line, precision and padding
+ * information on the subsequent lines
+ */
+ printf("%lu-bit%s%s integer",
+ (unsigned long)(8*H5Tget_size(type)), order_s, sign_s);
+ display_precision(type, ind);
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_float_type
+ *
+ * Purpose: Print info about a floating point data type.
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE, nothing printed
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_float_type(hid_t type, int ind)
+{
+ H5T_order_t order; /*byte order value */
+ const char *order_s=NULL; /*byte order string */
+ size_t spos; /*sign bit position */
+ size_t esize, epos; /*exponent size and position */
+ size_t msize, mpos; /*significand size and position */
+ size_t ebias; /*exponent bias */
+ H5T_norm_t norm; /*significand normalization */
+ const char *norm_s=NULL; /*normalization string */
+ H5T_pad_t pad; /*internal padding value */
+ const char *pad_s=NULL; /*internal padding string */
+
+ if (H5T_FLOAT!=H5Tget_class(type)) return FALSE;
+
+ /* Byte order */
+ if (H5Tget_size(type)>1) {
+ order = H5Tget_order(type);
+ if (H5T_ORDER_LE==order) {
+ order_s = " little-endian";
+ } else if (H5T_ORDER_BE==order) {
+ order_s = " big-endian";
+ } else if (H5T_ORDER_VAX==order) {
+ order_s = " mixed-endian";
+ } else {
+ order_s = " unknown-byte-order";
+ }
+ } else {
+ order_s = "";
+ }
+
+ /*
+ * Print size and byte order on first line, precision and padding on
+ * subsequent lines.
+ */
+ printf("%lu-bit%s floating-point",
+ (unsigned long)(8*H5Tget_size(type)), order_s);
+ display_precision(type, ind);
+
+ /* Print sizes, locations, and other information about each field */
+ H5Tget_fields (type, &spos, &epos, &esize, &mpos, &msize);
+ ebias = H5Tget_ebias(type);
+ norm = H5Tget_norm(type);
+ switch (norm) {
+ case H5T_NORM_IMPLIED:
+ norm_s = ", msb implied";
+ break;
+ case H5T_NORM_MSBSET:
+ norm_s = ", msb always set";
+ break;
+ case H5T_NORM_NONE:
+ norm_s = ", no normalization";
+ break;
+ case H5T_NORM_ERROR:
+ norm_s = ", unknown normalization";
+ break;
+ }
+ printf("\n%*s(significant for %lu bit%s at bit %lu%s)", ind, "",
+ (unsigned long)msize, 1==msize?"":"s", (unsigned long)mpos,
+ norm_s);
+ printf("\n%*s(exponent for %lu bit%s at bit %lu, bias is 0x%lx)",
+ ind, "", (unsigned long)esize, 1==esize?"":"s",
+ (unsigned long)epos, (unsigned long)ebias);
+ printf("\n%*s(sign bit at %lu)", ind, "", (unsigned long)spos);
+
+ /* Display internal padding */
+ if (1+esize+msize<H5Tget_precision(type)) {
+ pad = H5Tget_inpad(type);
+ switch (pad) {
+ case H5T_PAD_ZERO:
+ pad_s = "zero";
+ break;
+ case H5T_PAD_ONE:
+ pad_s = "one";
+ break;
+ case H5T_PAD_BACKGROUND:
+ pad_s = "bkg";
+ break;
+ case H5T_PAD_ERROR:
+ case H5T_NPAD:
+ pad_s = "unknown";
+ break;
+ }
+ printf("\n%*s(internal padding bits are %s)", ind, "", pad_s);
+ }
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_cmpd_type
+ *
+ * Purpose: Print info about a compound data type.
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE, nothing printed
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_cmpd_type(hid_t type, int ind)
+{
+ char *name=NULL; /*member name */
+ int ndims; /*dimensionality */
+ hsize_t dims[H5S_MAX_RANK]; /*dimensions */
+ size_t size; /*total size of type in bytes */
+ int perm[H5S_MAX_RANK]; /*index permutation */
+ hid_t subtype; /*member data type */
+ int i, j, n; /*miscellaneous counters */
+
+
+ if (H5T_COMPOUND!=H5Tget_class(type)) return FALSE;
+ printf("struct {");
+ for (i=0; i<H5Tget_nmembers(type); i++) {
+
+ /* Name and offset */
+ name = H5Tget_member_name(type, i);
+ printf("\n%*s\"", ind+4, "");
+ n = display_string(stdout, name, FALSE);
+ printf("\"%*s +%-4lu ", MAX(0, 16-n), "",
+ (unsigned long)H5Tget_member_offset(type, i));
+ free(name);
+
+ /* Grab member's type */
+ subtype = H5Tget_member_type(type, i);
+
+ /* Dimensions and permutation */
+ if(H5Tget_class(subtype)==H5T_ARRAY) {
+ ndims = H5Tget_array_ndims(subtype);
+ H5Tget_array_dims(subtype, dims, perm);
+ } /* end if */
+ else
+ ndims=0;
+
+ if (ndims>0) {
+ printf("[");
+ for (j=0; j<ndims; j++)
+ printf("%s%lu", j?",":"", (unsigned long)(dims[j]));
+ printf("]");
+
+ for (j=0; j<ndims; j++)
+ if (perm[j]!=j)
+ break;
+
+ if (j<ndims) {
+ printf("x[");
+ for (j=0; j<ndims; j++)
+ printf("%s%d", j?",":"", perm[j]);
+ printf("]");
+ }
+ printf(" ");
+ }
+
+ /* Data type */
+ display_type(subtype, ind+4);
+ H5Tclose(subtype);
+ }
+ size = H5Tget_size(type);
+ printf("\n%*s} %lu byte%s",
+ ind, "", (unsigned long)size, 1==size?"":"s");
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_enum_type
+ *
+ * Purpose: Print info about an enumeration data type.
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE, nothing printed
+ *
+ * Programmer: Robb Matzke
+ * Wednesday, December 23, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_enum_type(hid_t type, int ind)
+{
+ char **name=NULL; /*member names */
+ unsigned char *value=NULL; /*value array */
+ int nmembs; /*number of members */
+ int nchars; /*number of output characters */
+ hid_t super; /*enum base integer type */
+ hid_t native=-1; /*native integer data type */
+ size_t dst_size; /*destination value type size */
+ int i; /*miscellaneous counters */
+ size_t j;
+
+ if (H5T_ENUM!=H5Tget_class(type)) return FALSE;
+ nmembs = H5Tget_nmembers(type);
+ super = H5Tget_super(type);
+ printf("enum ");
+ display_type(super, ind+4);
+ printf(" {");
+
+ /*
+ * Determine what data type to use for the native values. To simplify
+ * things we entertain three possibilities:
+ * 1. long_long -- the largest native signed integer
+ * 2. unsigned long_long -- the largest native unsigned integer
+ * 3. raw format
+ */
+ if (H5Tget_size(type)<=sizeof(long_long)) {
+ dst_size = sizeof(long_long);
+ if (H5T_SGN_NONE==H5Tget_sign(type)) {
+ native = H5T_NATIVE_ULLONG;
+ } else {
+ native = H5T_NATIVE_LLONG;
+ }
+ } else {
+ dst_size = H5Tget_size(type);
+ }
+
+ /* Get the names and raw values of all members */
+ assert(nmembs>0);
+ name = calloc((size_t)nmembs, sizeof(char*));
+ value = calloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size));
+ for (i=0; i<nmembs; i++) {
+ name[i] = H5Tget_member_name(type, i);
+ H5Tget_member_value(type, i, value+i*H5Tget_size(type));
+ }
+
+ /* Convert values to native data type */
+ if (native>0) H5Tconvert(super, native, (hsize_t)nmembs, value, NULL, H5P_DEFAULT);
+
+ /* Sort members by increasing value */
+ /*not implemented yet*/
+
+ /* Print members */
+ for (i=0; i<nmembs; i++) {
+ printf("\n%*s", ind+4, "");
+ nchars = display_string(stdout, name[i], TRUE);
+ printf("%*s = ", MAX(0, 16-nchars), "");
+
+ if (native<0) {
+ printf("0x");
+ for (j=0; j<dst_size; j++) {
+ printf("%02x", value[i*dst_size+j]);
+ }
+ } else if (H5T_SGN_NONE==H5Tget_sign(native)) {
+ printf("%"PRINTF_LL_WIDTH"u",
+ *((unsigned long_long*)((void*)(value+i*dst_size))));
+ } else {
+ printf("%"PRINTF_LL_WIDTH"d",
+ *((long_long*)((void*)(value+i*dst_size))));
+ }
+ }
+
+ /* Release resources */
+ for (i=0; i<nmembs; i++) free(name[i]);
+ free(name);
+ free(value);
+ H5Tclose(super);
+
+ if (0==nmembs) printf("\n%*s <empty>", ind+4, "");
+ printf("\n%*s}", ind, "");
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_string_type
+ *
+ * Purpose: Print information about a string data type.
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE, nothing printed
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_string_type(hid_t type, int UNUSED ind)
+{
+ H5T_str_t pad;
+ const char *pad_s=NULL;
+ H5T_cset_t cset;
+ const char *cset_s=NULL;
+
+ if (H5T_STRING!=H5Tget_class(type)) return FALSE;
+
+ /* Padding */
+ pad = H5Tget_strpad(type);
+ switch (pad) {
+ case H5T_STR_NULLTERM:
+ pad_s = "null-terminated";
+ break;
+ case H5T_STR_NULLPAD:
+ pad_s = "null-padded";
+ break;
+ case H5T_STR_SPACEPAD:
+ pad_s = "space-padded";
+ break;
+ case H5T_STR_RESERVED_3:
+ case H5T_STR_RESERVED_4:
+ case H5T_STR_RESERVED_5:
+ case H5T_STR_RESERVED_6:
+ case H5T_STR_RESERVED_7:
+ case H5T_STR_RESERVED_8:
+ case H5T_STR_RESERVED_9:
+ case H5T_STR_RESERVED_10:
+ case H5T_STR_RESERVED_11:
+ case H5T_STR_RESERVED_12:
+ case H5T_STR_RESERVED_13:
+ case H5T_STR_RESERVED_14:
+ case H5T_STR_RESERVED_15:
+ case H5T_STR_ERROR:
+ pad_s = "unknown-format";
+ break;
+ }
+
+ /* Character set */
+ cset = H5Tget_cset(type);
+ switch (cset) {
+ case H5T_CSET_ASCII:
+ cset_s = "ASCII";
+ break;
+ case H5T_CSET_RESERVED_1:
+ case H5T_CSET_RESERVED_2:
+ case H5T_CSET_RESERVED_3:
+ case H5T_CSET_RESERVED_4:
+ case H5T_CSET_RESERVED_5:
+ case H5T_CSET_RESERVED_6:
+ case H5T_CSET_RESERVED_7:
+ case H5T_CSET_RESERVED_8:
+ case H5T_CSET_RESERVED_9:
+ case H5T_CSET_RESERVED_10:
+ case H5T_CSET_RESERVED_11:
+ case H5T_CSET_RESERVED_12:
+ case H5T_CSET_RESERVED_13:
+ case H5T_CSET_RESERVED_14:
+ case H5T_CSET_RESERVED_15:
+ case H5T_CSET_ERROR:
+ cset_s = "unknown-character-set";
+ break;
+ }
+
+ printf("%lu-byte %s %s string",
+ (unsigned long)H5Tget_size(type), pad_s, cset_s);
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_reference_type
+ *
+ * Purpose: Prints information about a reference data type.
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE, nothing printed
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ * Robb Matzke, 1999-06-04
+ * Knows about object and dataset region references.
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_reference_type(hid_t type, int UNUSED ind)
+{
+ if (H5T_REFERENCE!=H5Tget_class(type)) return FALSE;
+
+ 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;
+}
+
+
+/*-------------------------------------------------------------------------
+ * 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 ind)
+{
+ 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 = \"", ind, "");
+ display_string(stdout, tag, FALSE);
+ printf("\")");
+ free(tag);
+ }
+ return TRUE;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: display_vlen_type
+ *
+ * Purpose: Print information about a variable-length type
+ *
+ * Return: Success: TRUE
+ *
+ * Failure: FALSE
+ *
+ * Programmer: Robb Matzke
+ * Friday, December 1, 2000
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+display_vlen_type(hid_t type, int ind)
+{
+ hid_t super;
+
+ if (H5T_VLEN!=H5Tget_class(type)) return FALSE;
+
+ printf("variable length of\n%*s", ind+4, "");
+ super = H5Tget_super(type);
+ display_type(super, ind+4);
+ H5Tclose(super);
+ return TRUE;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: display_type
+ *
+ * Purpose: Prints a data type definition. The definition is printed
+ * without any leading space or trailing line-feed (although
+ * there might be line-feeds inside the type definition). The
+ * first line is assumed to have IND characters before it on
+ * the same line (printed by the caller).
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ * Robb Matzke, 1999-06-11
+ * Prints the OID of shared data types.
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+display_type(hid_t type, int ind)
+{
+ H5T_class_t data_class = H5Tget_class(type);
+ H5G_stat_t sb;
+
+ /* Bad data type */
+ if (type<0) {
+ printf("<ERROR>");
+ return;
+ }
+
+ /* Shared? If so then print the type's OID */
+ if (H5Tcommitted(type)) {
+ if (H5Gget_objinfo(type, ".", FALSE, &sb)>=0) {
+ printf("shared-%lu:%lu:%lu:%lu ",
+ sb.fileno[1], sb.fileno[0],
+ sb.objno[1], sb.objno[0]);
+ } else {
+ printf("shared ");
+ }
+ }
+
+ /* Print the type */
+ if (display_native_type(type, ind) ||
+ display_ieee_type(type, ind) ||
+ display_int_type(type, ind) ||
+ display_float_type(type, ind) ||
+ display_cmpd_type(type, ind) ||
+ display_enum_type(type, ind) ||
+ display_string_type(type, ind) ||
+ display_reference_type(type, ind) ||
+ display_vlen_type(type, ind) ||
+ display_opaque_type(type, ind)) {
+ return;
+ }
+
+ /* Unknown type */
+ printf("%lu-byte class-%u unknown",
+ (unsigned long)H5Tget_size(type),
+ (unsigned)data_class);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: dump_dataset_values
+ *
+ * Purpose: Prints all values of a dataset.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Tuesday, July 21, 1998
+ *
+ * Modifications:
+ * Robb Matzke, 1999-09-27
+ * Understands the simple_output_g switch which causes data to
+ * be displayed in a more machine-readable format.
+ *-------------------------------------------------------------------------
+ */
+static void
+dump_dataset_values(hid_t dset)
+{
+ hid_t f_type = H5Dget_type(dset);
+ size_t size = H5Tget_size(f_type);
+ h5dump_t info;
+ char string_prefix[64];
+ static char fmt_double[16], fmt_float[16];
+
+ /* Set to all default values and then override */
+ memset(&info, 0, sizeof info);
+
+ if (simple_output_g) {
+ info.idx_fmt = "";
+ info.line_ncols = 65535; /*something big*/
+ info.line_per_line = 1;
+ info.line_multi_new = 0;
+ info.line_pre = " ";
+ info.line_cont = " ";
+
+ info.arr_pre = "";
+ info.arr_suf = "";
+ info.arr_sep = " ";
+
+ info.cmpd_pre = "";
+ info.cmpd_suf = "";
+ info.cmpd_sep = " ";
+
+ if (label_g) info.cmpd_name = "%s=";
+
+ info.elmt_suf1 = " ";
+ info.str_locale = ESCAPE_HTML;
+
+ } else {
+ info.idx_fmt = "(%s)";
+ info.line_ncols = width_g;
+ info.line_multi_new = 1;
+ if (label_g) info.cmpd_name = "%s=";
+ info.line_pre = " %s ";
+ info.line_cont = " %s ";
+ info.str_repeat = 8;
+ }
+
+ /* Floating point types should display full precision */
+ sprintf(fmt_float, "%%1.%dg", FLT_DIG);
+ info.fmt_float = fmt_float;
+ sprintf(fmt_double, "%%1.%dg", DBL_DIG);
+ info.fmt_double = fmt_double;
+
+ info.dset_format = "DSET-%lu:%lu:%lu:%lu-";
+ info.dset_hidefileno = 0;
+
+ info.obj_format = "-%lu:%lu:%lu:%lu";
+ info.obj_hidefileno = 0;
+
+ info.dset_blockformat_pre = "%sBlk%lu: ";
+ info.dset_ptformat_pre = "%sPt%lu: ";
+
+ info.line_indent = "";
+
+ if (hexdump_g) {
+ /*
+ * Print all data in hexadecimal format if the `-x' or `--hexdump'
+ * command line switch was given.
+ */
+ info.raw = TRUE;
+ } else if (string_g && 1==size && H5T_INTEGER==H5Tget_class(f_type)) {
+ /*
+ * Print 1-byte integer data as an ASCI character string instead of
+ * integers if the `-s' or `--string' command-line option was given.
+ */
+ info.ascii = TRUE;
+ info.elmt_suf1 = "";
+ info.elmt_suf2 = "";
+ strcpy(string_prefix, info.line_pre);
+ strcat(string_prefix, "\"");
+ info.line_pre = string_prefix;
+ info.line_suf = "\"";
+ }
+
+ /*
+ * Print all the values.
+ */
+ printf(" Data:\n");
+ if (h5tools_dump_dset(stdout, &info, dset, -1, NULL, -1) < 0) {
+ printf(" Unable to print data.\n");
+ }
+
+ H5Tclose(f_type);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: list_attr
+ *
+ * Purpose: Prints information about attributes.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Friday, June 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+list_attr (hid_t obj, const char *attr_name, void UNUSED *op_data)
+{
+ hid_t attr, space, type, p_type;
+ hsize_t size[64], nelmts=1;
+ int ndims, i, n;
+ size_t need;
+ void *buf;
+ h5dump_t info;
+
+ printf(" Attribute: ");
+ n = display_string(stdout, attr_name, TRUE);
+ printf("%*s", MAX(0, 9-n), "");
+ if ((attr = H5Aopen_name(obj, attr_name))) {
+ space = H5Aget_space(attr);
+ type = H5Aget_type(attr);
+
+ /* Data space */
+ ndims = H5Sget_simple_extent_dims(space, size, NULL);
+ if (0==ndims) {
+ puts(" scalar");
+ } else {
+ printf(" {");
+ for (i=0; i<ndims; i++) {
+ HDfprintf(stdout, "%s%Hu", i?", ":"", size[i]);
+ nelmts *= size[i];
+ }
+ puts("}");
+ }
+
+ /* Data type */
+ printf(" Type: ");
+ display_type(type, 15);
+ putchar('\n');
+
+ /* Data */
+ memset(&info, 0, sizeof info);
+ info.line_multi_new = 1;
+ if (nelmts<5) {
+ info.idx_fmt = "";
+ info.line_1st = " Data: ";
+ info.line_pre = " ";
+ info.line_cont = " ";
+ info.str_repeat = 8;
+
+ } else {
+ printf(" Data:\n");
+ info.idx_fmt = "(%s)";
+ info.line_pre = " %s ";
+ info.line_cont = " %s ";
+ info.str_repeat = 8;
+ }
+ info.line_ncols = width_g;
+ if (label_g) info.cmpd_name = "%s=";
+ if (string_g && 1==H5Tget_size(type) &&
+ H5T_INTEGER==H5Tget_class(type)) {
+ info.ascii = TRUE;
+ info.elmt_suf1 = "";
+ info.elmt_suf2 = "";
+ info.idx_fmt = "(%s)";
+ info.line_pre = " %s \"";
+ info.line_suf = "\"";
+ }
+ if (hexdump_g) {
+ p_type = H5Tcopy(type);
+ } else {
+ p_type = h5tools_fixtype(type);
+ }
+ if (p_type>=0) {
+ need = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type));
+ buf = malloc(need);
+ assert(buf);
+ if (H5Aread(attr, p_type, buf)>=0) {
+ h5tools_dump_mem(stdout, &info, attr, p_type, space, buf, -1);
+ }
+ free(buf);
+ H5Tclose(p_type);
+ }
+
+ H5Sclose(space);
+ H5Tclose(type);
+ H5Aclose(attr);
+ } else {
+ putchar('\n');
+ }
+
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: dataset_list1
+ *
+ * Purpose: List information about a dataset which should appear on the
+ * same line as the dataset name. This information will precede
+ * information which is applicable to all objects which will be
+ * printed by the caller.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Thursday, August 27, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+dataset_list1(hid_t dset)
+{
+ hsize_t cur_size[64]; /*current dataset dimensions */
+ hsize_t max_size[64]; /*maximum dataset dimensions */
+ hid_t space; /*data space */
+ int ndims; /*dimensionality */
+ int i;
+
+ /*
+ * Information that goes on the same row as the name. The name has
+ * already been printed.
+ */
+ space = H5Dget_space(dset);
+ ndims = H5Sget_simple_extent_dims(space, cur_size, max_size);
+ printf (" {");
+ for (i=0; i<ndims; i++) {
+ HDfprintf (stdout, "%s%Hu", i?", ":"", cur_size[i]);
+ if (max_size[i]==H5S_UNLIMITED) {
+ HDfprintf (stdout, "/%s", "Inf");
+ } else if (max_size[i]!=cur_size[i] || verbose_g>0) {
+ HDfprintf(stdout, "/%Hu", max_size[i]);
+ }
+ }
+ if (0==ndims) printf("SCALAR");
+ putchar('}');
+ H5Sclose (space);
+
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: dataset_list2
+ *
+ * Purpose: List information about a dataset which should appear after
+ * information which is general to all objects.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Thursday, August 27, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+dataset_list2(hid_t dset, const char UNUSED *name)
+{
+ hid_t dcpl; /*dataset creation property list*/
+ hid_t type; /*data type of dataset */
+ hid_t space; /*data space of dataset */
+ int nf; /*number of filters */
+ unsigned filt_flags; /*filter flags */
+ H5Z_filter_t filt_id; /*filter identification number */
+ unsigned cd_values[20]; /*filter client data values */
+ size_t cd_nelmts; /*filter client number of values*/
+ size_t cd_num; /*filter client data counter */
+ char f_name[256]; /*filter/file name */
+ char s[64]; /*temporary string buffer */
+ off_t f_offset; /*offset in external file */
+ hsize_t f_size; /*bytes used in external file */
+ hsize_t total, used; /*total size or offset */
+ hsize_t chsize[64]; /*chunk size in elements */
+ int ndims; /*dimensionality */
+ int n, max_len; /*max extern file name length */
+ double utilization; /*percent utilization of storage*/
+ int i;
+
+ if (verbose_g>0) {
+ dcpl = H5Dget_create_plist(dset);
+ space = H5Dget_space(dset);
+ type = H5Dget_type(dset);
+
+ /* Print information about chunked storage */
+ if (H5D_CHUNKED==H5Pget_layout(dcpl)) {
+ ndims = H5Pget_chunk(dcpl, NELMTS(chsize), chsize/*out*/);
+ printf(" %-10s {", "Chunks:");
+ total = H5Tget_size(type);
+ for (i=0; i<ndims; i++) {
+ printf("%s%lu", i?", ":"", (unsigned long)(chsize[i]));
+ total *= chsize[i];
+ }
+ printf("} %lu bytes\n", (unsigned long)total);
+ }
+
+ /* Print total raw storage size */
+ used = H5Sget_simple_extent_npoints(space) * H5Tget_size(type);
+ total = H5Dget_storage_size(dset);
+ printf(" %-10s ", "Storage:");
+ printf("%lu logical byte%s, %lu allocated byte%s",
+ (unsigned long)used, 1==used?"":"s",
+ (unsigned long)total, 1==total?"":"s");
+ if (total>0) {
+#ifdef WIN32
+ hsize_t mask = (hsize_t)1 << (8*sizeof(hsize_t)-1);
+ if ((used & mask) || (total & mask)) {
+ total = 0; /*prevent utilization printing*/
+ } else {
+ utilization = (hssize_t)used*100.0 /(hssize_t)total;
+ }
+#else
+ utilization = (used*100.0)/total;
+#endif
+ printf(", %1.2f%% utilization", utilization/*(used*100.0)/total*/);
+ }
+ putchar('\n');
+
+ /* Print information about external strorage */
+ if ((nf = H5Pget_external_count(dcpl))>0) {
+ for (i=0, max_len=0; i<nf; i++) {
+ H5Pget_external(dcpl, i, sizeof(f_name), f_name, NULL, NULL);
+ n = display_string(NULL, f_name, TRUE);
+ max_len = MAX(max_len, n);
+ }
+ printf(" %-10s %d external file%s\n",
+ "Extern:", nf, 1==nf?"":"s");
+ printf(" %4s %10s %10s %10s %s\n",
+ "ID", "DSet-Addr", "File-Addr", "Bytes", "File");
+ printf(" %4s %10s %10s %10s ",
+ "----", "----------", "----------", "----------");
+ for (i=0; i<max_len; i++) putchar('-');
+ putchar('\n');
+ for (i=0, total=0; i<nf; i++) {
+ if (H5Pget_external(dcpl, i, sizeof(f_name), f_name, &f_offset,
+ &f_size)<0) {
+ HDfprintf(stdout,
+ " #%03d %10Hu %10s %10s ***ERROR*** %s\n",
+ i, total, "", "",
+ i+1<nf?"Following addresses are incorrect":"");
+ } else if (H5S_UNLIMITED==f_size) {
+ HDfprintf(stdout, " #%03d %10Hu %10Hu %10s ",
+ i, total, (hsize_t)f_offset, "INF");
+ display_string(stdout, f_name, TRUE);
+ } else {
+ HDfprintf(stdout, " #%03d %10Hu %10Hu %10Hu ",
+ i, total, (hsize_t)f_offset, f_size);
+ display_string(stdout, f_name, TRUE);
+ }
+ putchar('\n');
+ total += f_size;
+ }
+ printf(" %4s %10s %10s %10s ",
+ "----", "----------", "----------", "----------");
+ for (i=0; i<max_len; i++) putchar('-');
+ putchar('\n');
+ }
+
+ /* Print information about raw data filters */
+ if ((nf = H5Pget_nfilters(dcpl))>0) {
+ for (i=0; i<nf; i++) {
+ cd_nelmts = NELMTS(cd_values);
+ filt_id = H5Pget_filter(dcpl, i, &filt_flags, &cd_nelmts,
+ cd_values, sizeof(f_name), f_name);
+ f_name[sizeof(f_name)-1] = '\0';
+ sprintf(s, "Filter-%d:", i);
+ printf(" %-10s %s-%u %s {", s,
+ f_name[0]?f_name:"method",
+ (unsigned)filt_id,
+ filt_flags & H5Z_FLAG_OPTIONAL?"OPT":"");
+ for (cd_num=0; cd_num<cd_nelmts; cd_num++) {
+ printf("%s%u", cd_num?", ":"", cd_values[cd_num]);
+ }
+ printf("}\n");
+ }
+ }
+
+ /* Print data type */
+ printf(" %-10s ", "Type:");
+ display_type(type, 15);
+ printf("\n");
+
+ /* Print address information */
+ if (address_g) H5Ddebug(dset, 0);
+
+ /* Close stuff */
+ H5Tclose(type);
+ H5Sclose(space);
+ H5Pclose(dcpl);
+ }
+
+ if (data_g) dump_dataset_values(dset);
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: group_list2
+ *
+ * Purpose: List information about a group which should appear after
+ * information which is general to all objects.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Thursday, January 21, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+group_list2(hid_t grp, const char *name)
+{
+ iter_t iter;
+
+ if (recursive_g) {
+ iter.container = name;
+ H5Giterate(grp, ".", NULL, list, &iter);
+ }
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: datatype_list2
+ *
+ * Purpose: List information about a data type which should appear after
+ * information which is general to all objects.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Thursday, November 5, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+datatype_list2(hid_t type, const char UNUSED *name)
+{
+ if (verbose_g>0) {
+ printf(" %-10s ", "Type:");
+ display_type(type, 15);
+ printf("\n");
+ }
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: link_open
+ *
+ * Purpose: This gets called to open a symbolic link. Since symbolic
+ * links don't correspond to actual objects we simply print the
+ * link information and return failure.
+ *
+ * Return: Success: 0 - an invalid object but successful return
+ * of this function.
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Thursday, August 27, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hid_t
+link_open(hid_t location, const char *name)
+{
+ char buf[64];
+
+ if (H5Gget_linkval (location, name, sizeof(buf), buf)<0) return -1;
+ if (NULL==HDmemchr(buf, 0, sizeof(buf))) {
+ strcpy(buf+sizeof(buf)-4, "...");
+ }
+ fputs(buf, stdout);
+
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: list
+ *
+ * Purpose: Prints the group member name.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Monday, March 23, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+list (hid_t group, const char *name, void *_iter)
+{
+ hid_t obj=-1;
+ char buf[512], comment[50], *fullname=NULL, *s=NULL;
+ H5G_stat_t sb;
+ struct tm *tm;
+ herr_t status;
+ iter_t *iter = (iter_t*)_iter;
+ int n;
+
+ /* Print the object name, either full name or base name */
+ fullname = fix_name(iter->container, name);
+ if (fullname_g) {
+ n = display_string(stdout, fullname, TRUE);
+ printf("%*s ", MAX(0, 24-n), "");
+ } else {
+ n = display_string(stdout, name, TRUE);
+ printf("%*s ", MAX(0, 24-n), "");
+ }
+
+ /* Get object information */
+ H5E_BEGIN_TRY {
+ status = H5Gget_objinfo(group, name, FALSE, &sb);
+ } H5E_END_TRY;
+ if (status<0) {
+ puts("**NOT FOUND**");
+ return 0;
+ } else if (sb.type<0 || sb.type>=H5G_NTYPES) {
+ printf("Unknown type(%d)", sb.type);
+ sb.type = -1;
+ }
+ if (sb.type>=0 && dispatch_g[sb.type].name) {
+ fputs(dispatch_g[sb.type].name, stdout);
+ }
+
+ /*
+ * If the object has already been printed then just show the object ID
+ * and return.
+ */
+ if ((s=sym_lookup(&sb))) {
+ printf(", same as ");
+ display_string(stdout, s, TRUE);
+ printf("\n");
+ goto done;
+ } else {
+ sym_insert(&sb, fullname);
+ }
+
+ /*
+ * Open the object. Not all objects can be opened. If this is the case
+ * then return right away.
+ */
+ if (sb.type>=0 &&
+ (NULL==dispatch_g[sb.type].open ||
+ (obj=(dispatch_g[sb.type].open)(group, name))<0)) {
+ printf(" *ERROR*\n");
+ goto done;
+ }
+
+ /*
+ * List the first line of information for the object.
+ */
+ if (sb.type>=0 && dispatch_g[sb.type].list1) {
+ (dispatch_g[sb.type].list1)(obj);
+ }
+ putchar('\n');
+
+ /*
+ * Show detailed information about the object, beginning with information
+ * which is common to all objects.
+ */
+ if (verbose_g>0 && H5G_LINK!=sb.type) {
+ if (sb.type>=0) H5Aiterate(obj, NULL, list_attr, NULL);
+ printf(" %-10s %lu:%lu:%lu:%lu\n", "Location:",
+ sb.fileno[1], sb.fileno[0], sb.objno[1], sb.objno[0]);
+ printf(" %-10s %u\n", "Links:", sb.nlink);
+ if (sb.mtime>0 && NULL!=(tm=localtime(&(sb.mtime)))) {
+ strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
+ printf(" %-10s %s\n", "Modified:", buf);
+ }
+ comment[0] = '\0';
+ H5Gget_comment(group, name, sizeof(comment), comment);
+ strcpy(comment+sizeof(comment)-4, "...");
+ if (comment[0]) {
+ printf(" %-10s \"", "Comment:");
+ display_string(stdout, comment, FALSE);
+ puts("\"");
+ }
+ }
+ if (sb.type>=0 && dispatch_g[sb.type].list2) {
+ (dispatch_g[sb.type].list2)(obj, fullname);
+ }
+
+ /*
+ * Close the object.
+ */
+ done:
+ if (sb.type>=0 && obj>=0 && dispatch_g[sb.type].close) {
+ (dispatch_g[sb.type].close)(obj);
+ }
+ if (fullname) free(fullname);
+ return 0;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: fix_name
+ *
+ * Purpose: Returns a malloc'd buffer that contains the PATH and BASE
+ * names separated by a single slash. It also removes duplicate
+ * and trailing slashes.
+ *
+ * Return: Success: Ptr to fixed name from malloc()
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Thursday, January 21, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static char *
+fix_name(const char *path, const char *base)
+{
+ size_t n = (path?strlen(path):0) + (base?strlen(base):0) + 3;
+ char *s = malloc(n), prev='\0';
+ int len=0;
+
+ if (path) {
+ /* Path, followed by slash */
+#ifdef H5LS_PREPEND_FILENAME
+ if ('/'!=*path) s[len++] = '/';
+#endif
+ for (/*void*/; *path; path++) {
+ if ('/'!=*path || '/'!=prev) prev = s[len++] = *path;
+ }
+ if ('/'!=prev) prev = s[len++] = '/';
+ }
+
+ if (base) {
+ /* Base name w/o trailing slashes */
+ const char *end = base + strlen(base);
+ while (end>base && '/'==end[-1]) --end;
+ for (/*void*/; base<end; base++) {
+ if ('/'!=*base || '/'!=prev) prev = s[len++] = *base;
+ }
+ }
+
+ s[len] = '\0';
+ return s;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: get_width
+ *
+ * Purpose: Figure out how wide the screen is. This is highly
+ * unportable, but the user can always override the width we
+ * detect by giving a command-line option. These code snippets
+ * were borrowed from the GNU less(1).
+ *
+ * Return: Success: Number of columns.
+ *
+ * Failure: Some default number of columms.
+ *
+ * Programmer: Robb Matzke
+ * Friday, November 6, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+get_width(void)
+{
+ int width = 80; /*the default */
+ char *s;
+
+ /*
+ * Try to get it from the COLUMNS environment variable first since it's
+ * value is sometimes wrong.
+ */
+ if ((s=getenv("COLUMNS")) && *s && isdigit((int)*s)) {
+ width = (int)strtol(s, NULL, 0);
+ }
+
+#if defined(H5_HAVE_STRUCT_VIDEOCONFIG) && defined(H5_HAVE__GETVIDEOCONFIG)
+ {
+ /* Microsoft C */
+ struct videoconfig w;
+ _getvideoconfig(&w);
+ width = w.numtextcols;
+ }
+#elif defined(H5_HAVE_STRUCT_TEXT_INFO) && defined(H5_HAVE_GETTEXTINFO)
+ {
+ /* Borland C or DJGPPC */
+ struct text_info w;
+ gettextinfo(&w);
+ width = w.screenwidth;
+ }
+#elif defined(H5_HAVE_GETCONSOLESCREENBUFFERINFO)
+ {
+ /* Win32 C */
+ CONSOLE_SCREEN_BUFFER_INFO scr;
+ GetConsoleScreenBufferInfo(con_out, &scr);
+ width = scr.srWindow.Right - scr.srWindow.Left + 1;
+ }
+#elif defined(H5_HAVE__SCRSIZE)
+ {
+ /* OS/2 */
+ int w[2];
+ _scrsize(w);
+ width = w[0];
+ }
+#elif defined(H5_HAVE_TIOCGWINSZ) && defined(H5_HAVE_IOCTL)
+#ifndef __PUMAGON__
+/* the ioctl() call coredump on TFLOPS. Turn it off for now. */
+ {
+ /* Unix with ioctl(TIOCGWINSZ) */
+ struct winsize w;
+ if (ioctl(2, TIOCGWINSZ, &w)>=0 && w.ws_col>0) {
+ width = w.ws_col;
+ }
+ }
+#endif
+#elif defined(H5_HAVE_TIOCGETD) && defined(H5_HAVE_IOCTL)
+ {
+ /* Unix with ioctl(TIOCGETD) */
+ struct uwdata w;
+ if (ioctl(2, WIOCGETD, &w)>=0 && w.uw_width>0) {
+ width = w.uw_width / w.uw_hs;
+ }
+ }
+#endif
+
+ /* Set to at least 1 */
+ if (width<1) width = 1;
+ return width;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: Opens a file and lists the specified group
+ *
+ * Return: Success: 0
+ *
+ * Failure: 1
+ *
+ * Programmer: Robb Matzke
+ * Monday, March 23, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+main (int argc, char *argv[])
+{
+ hid_t file=-1, root=-1;
+ char *fname=NULL, *oname=NULL, *x;
+ const char *progname="h5ls";
+ const char *s = NULL;
+ char *rest, *container=NULL;
+ int argno;
+ H5G_stat_t sb;
+ iter_t iter;
+ static char root_name[] = "/";
+ char drivername[50];
+
+ /* Initialize h5tools lib */
+ h5tools_init();
+
+ /* Build display table */
+ DISPATCH(H5G_DATASET, "Dataset", H5Dopen, H5Dclose,
+ dataset_list1, dataset_list2);
+ DISPATCH(H5G_GROUP, "Group", H5Gopen, H5Gclose,
+ NULL, group_list2);
+ DISPATCH(H5G_TYPE, "Type", H5Topen, H5Tclose,
+ NULL, datatype_list2);
+ DISPATCH(H5G_LINK, "-> ", link_open, NULL,
+ NULL, NULL);
+
+#if 0
+ /* Name of this program without the path */
+ if ((progname=strrchr(argv[0], '/'))) progname++;
+ else progname = argv[0];
+#endif
+
+ /* Default output width */
+ width_g = get_width();
+
+ /* Switches come before non-switch arguments */
+ for (argno=1; argno<argc && '-'==argv[argno][0]; argno++) {
+ if (!strcmp(argv[argno], "--")) {
+ /* Last switch */
+ argno++;
+ break;
+ } else if (!strcmp(argv[argno], "--help")) {
+ usage(progname);
+ exit(0);
+ } else if (!strcmp(argv[argno], "--address")) {
+ address_g = TRUE;
+ } else if (!strcmp(argv[argno], "--data")) {
+ data_g = TRUE;
+ } else if (!strcmp(argv[argno], "--errors")) {
+ show_errors_g = TRUE;
+ } else if (!strcmp(argv[argno], "--full")) {
+ fullname_g = TRUE;
+ } else if (!strcmp(argv[argno], "--group")) {
+ grp_literal_g = TRUE;
+ } else if (!strcmp(argv[argno], "--label")) {
+ label_g = TRUE;
+ } else if (!strcmp(argv[argno], "--recursive")) {
+ recursive_g = TRUE;
+ fullname_g = TRUE;
+ } else if (!strcmp(argv[argno], "--simple")) {
+ simple_output_g = TRUE;
+ } else if (!strcmp(argv[argno], "--string")) {
+ string_g = TRUE;
+ } else if (!strncmp(argv[argno], "--width=", 8)) {
+ width_g = (int)strtol(argv[argno]+8, &rest, 0);
+ if (width_g<=0 || *rest) {
+ usage(progname);
+ exit(1);
+ }
+ } else if (!strcmp(argv[argno], "--width")) {
+ if (argno+1>=argc) {
+ usage(progname);
+ exit(1);
+ } else {
+ s = argv[++argno];
+ }
+ width_g = (int)strtol(s, &rest, 0);
+ if (width_g<=0 || *rest) {
+ usage(progname);
+ exit(1);
+ }
+ } else if (!strcmp(argv[argno], "--verbose")) {
+ verbose_g++;
+ } else if (!strcmp(argv[argno], "--version")) {
+ print_version(progname);
+ exit(0);
+ } else if (!strcmp(argv[argno], "--hexdump")) {
+ hexdump_g = TRUE;
+ } else if (!strncmp(argv[argno], "-w", 2)) {
+ if (argv[argno][2]) {
+ s = argv[argno]+2;
+ } else if (argno+1>=argc) {
+ usage(progname);
+ exit(1);
+ } else {
+ s = argv[++argno];
+ }
+ width_g = (int)strtol(s, &rest, 0);
+ if (width_g<=0 || *rest) {
+ usage(progname);
+ exit(1);
+ }
+ } else if ('-'!=argv[argno][1]) {
+ /* Single-letter switches */
+ for (s=argv[argno]+1; *s; s++) {
+ switch (*s) {
+ case '?':
+ case 'h': /* --help */
+ usage(progname);
+ exit(0);
+ case 'a': /* --address */
+ address_g = TRUE;
+ break;
+ case 'd': /* --data */
+ data_g = TRUE;
+ break;
+ case 'e': /* --errors */
+ show_errors_g = TRUE;
+ break;
+ case 'f': /* --full */
+ fullname_g = TRUE;
+ break;
+ case 'g': /* --group */
+ grp_literal_g = TRUE;
+ break;
+ case 'l': /* --label */
+ label_g = TRUE;
+ break;
+ case 'r': /* --recursive */
+ recursive_g = TRUE;
+ fullname_g = TRUE;
+ break;
+ case 'S': /* --simple */
+ simple_output_g = TRUE;
+ break;
+ case 's': /* --string */
+ string_g = TRUE;
+ break;
+ case 'v': /* --verbose */
+ verbose_g++;
+ break;
+ case 'V': /* --version */
+ print_version(progname);
+ exit(0);
+ case 'x': /* --hexdump */
+ hexdump_g = TRUE;
+ break;
+ default:
+ usage(progname);
+ exit(1);
+ }
+ }
+ } else {
+ usage(progname);
+ exit(1);
+ }
+ }
+
+ /*
+ * If no arguments remain then print a usage message (instead of doing
+ * absolutely nothing ;-)
+ */
+ if (argno>=argc) {
+ usage(progname);
+ exit(1);
+ }
+
+ /* Turn off HDF5's automatic error printing unless you're debugging h5ls */
+ if (!show_errors_g) H5Eset_auto(NULL, NULL);
+
+
+ /*
+ * Each remaining argument is an hdf5 file followed by an optional slash
+ * and object name.
+ *
+ * Example: ../dir1/foo/bar/baz
+ * \_________/\______/
+ * file obj
+ *
+ * The dichotomy is determined by calling H5Fopen() repeatedly until it
+ * succeeds. The first call uses the entire name and each subsequent call
+ * chops off the last component. If we reach the beginning of the name
+ * then there must have been something wrong with the file (perhaps it
+ * doesn't exist).
+ */
+ while (argno<argc) {
+ fname = argv[argno++];
+ oname = NULL;
+ file = -1;
+
+ while (fname && *fname) {
+ file = h5tools_fopen(fname, drivername, sizeof drivername);
+
+ if (file>=0) {
+ if (verbose_g) {
+ printf("Opened \"%s\" with %s driver.\n",
+ fname, drivername);
+ }
+ break; /*success*/
+ }
+
+ /* Shorten the file name; lengthen the object name */
+ x = oname;
+ oname = strrchr(fname, '/');
+ if (x) *x = '/';
+ if (!oname) break;
+ *oname = '\0';
+ }
+ if (file<0) {
+ fprintf(stderr, "%s: unable to open file\n", argv[argno-1]);
+ continue;
+ }
+ if (oname) oname++;
+ if (!oname || !*oname) oname = root_name;
+
+ /* Open the object and display it's information */
+ if (H5Gget_objinfo(file, oname, TRUE, &sb)>=0 &&
+ H5G_GROUP==sb.type && !grp_literal_g) {
+ /*
+ * Specified name is a group. List the complete contents of the
+ * group.
+ */
+ sym_insert(&sb, oname);
+#ifdef H5LS_PREPEND_FILENAME
+ iter.container = container = fix_name(fname, oname);
+#else
+ iter.container = container = fix_name("", oname);
+#endif
+ H5Giterate(file, oname, NULL, list, &iter);
+ free(container);
+
+ } else if ((root=H5Gopen(file, "/"))<0) {
+ exit(1); /*major problem!*/
+
+ } else {
+ /*
+ * Specified name is a non-group object -- list that object. The
+ * container for the object is everything up to the base name.
+ */
+#ifdef H5LS_PREPEND_FILENAME
+ iter.container = fname;
+#else
+ iter.container = "/";
+#endif
+ list(root, oname, &iter);
+ if (H5Gclose(root)<0) exit(1);
+ }
+ H5Fclose(file);
+ }
+ h5tools_close();
+
+ return 0;
+}
diff --git a/tools/h5toh4/h5toh4.c b/tools/h5toh4/h5toh4.c
new file mode 100644
index 0000000..853bfd8
--- /dev/null
+++ b/tools/h5toh4/h5toh4.c
@@ -0,0 +1,2587 @@
+/******************************************************************************
+
+ Description: This file contains routines to translate H5 files to H4 files.
+
+ Author: Paul Harten for the University of Illinois, NCSA
+
+ Creation Date: 04 October 1998
+
+ History:
+
+
+*****************************************************************************/
+
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "h5toh4.h"
+#include "h5tools.h"
+#include "h5tools_utils.h"
+
+
+#ifdef WIN32
+typedef unsigned int mode_t;
+#endif /* WIN32 */
+
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode)&0xF000) == S_IFDIR)
+#endif
+extern void PrintOptions_h5toh4(void);
+extern char *BuildFilename(char *h5_filename, char *h4_extension);
+extern int test_file(char *filename, int oflag, mode_t mode);
+extern int test_dir(char *);
+extern int h5toh4(char *, char *);
+
+extern herr_t convert_group(hid_t, char *, op_data_t *);
+extern herr_t convert_dataset(hid_t, char *, op_data_t *);
+extern herr_t convert_all(hid_t, char *, op_data_t *);
+extern herr_t convert_attr(hid_t, char *, op_data_t *);
+extern herr_t convert_shared_dataset(hid_t, int, op_data_t *);
+extern herr_t convert_shared_group(hid_t, int, op_data_t *);
+extern herr_t convert_dataset_string(hid_t, char *, op_data_t *);
+extern int32 h5type_to_h4type(hid_t);
+extern hid_t h4type_to_memtype(int32);
+
+typedef herr_t (*H5G_operator_t)(hid_t, const char*, void*);
+
+static int prefix_len = 1024;
+static char *prefix;
+static table_t *group_table, *dset_table, *type_table;
+
+static herr_t h5atomic_type_to_h4type(const hid_t h5type, hid_t* h5memtype, size_t* h5memsize, int32* h4type);
+
+
+/*****************************************************************************
+
+ Routine: main()
+
+ Description: This routine check out arguments sent, makes sure everything is
+ ok, chooses between the acceptable argument formats and then
+ calls h5toh4().
+
+ Input: arg - the number of arguments from the call + 1;
+ argv - a pointer to an array of strings which are the arguments.
+ This includes the routine name as the first string.
+
+ Output: function return - error status
+
+*****************************************************************************/
+
+int
+main(int argc, char *argv[])
+{
+ char *h5_filename=NULL;
+ char *h4_filename=NULL;
+ char *h4_extension;
+ int status = 0;
+ int status2 = 0;
+
+
+ argc--;
+ argv++;
+
+ if (argc == 0) {
+ fprintf(stderr,"\nError: Invalid Arguments\n");
+ PrintOptions_h5toh4();
+ return -1;
+ }
+
+ /* take care -h (help) option first */
+ { int i;
+ for (i=0; i < argc; i++)
+ if ( HDstrcmp(argv[i],"-h") == 0 ) {
+ PrintOptions_h5toh4();
+ return 0;
+ }
+ }
+
+ /*fargv = argv; */
+
+ /* Change -m with 1 filename to as 1 filename case */
+ if (argc == 2 && HDstrcmp(argv[0],"-m") == 0) {
+ argv++;
+ argc--;
+ }
+
+ switch(argc) {
+
+ case 0:
+
+ PrintOptions_h5toh4();
+ break;
+
+ case 1: /* h5toh4 file1 */
+ h5_filename = argv[0];
+
+ if (HDstrcmp(h5_filename,"-m") == 0) {
+ fprintf(stderr,"\nError: Invalid Arguments\n");
+ PrintOptions_h5toh4();
+ status = -1;
+ break;
+ }
+#ifndef WIN32
+ if (test_file(h5_filename,O_EXCL,(mode_t)(S_IRUSR|S_IRGRP|S_IROTH)) != 0 ) { /* 292 Decimal - 0444 Octal, a+r */
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status = -1;
+ break;
+ }
+ if (test_dir(h5_filename) != 0 ) {
+ fprintf(stderr,"%s: Is a directory\n",h5_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status = -1;
+ break;
+ }
+#endif
+ h4_extension = HDstrdup("hdf");
+
+ h4_filename = BuildFilename(h5_filename,h4_extension);
+ if (h4_filename == NULL) {
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status = -1;
+ break;
+ }
+#ifndef WIN32
+ if (test_file(h4_filename,O_CREAT|O_EXCL,(mode_t)(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status = -1;
+ break;
+ }
+#endif
+ status = h5toh4(h5_filename, h4_filename);
+ if ( status != 0 ) {
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ }
+ if (h4_filename != NULL) {
+ HDfree(h4_filename);
+ }
+
+ break;
+
+ case 2: /* h5toh4 file_in file_out */
+ h5_filename = argv[0];
+ h4_filename = argv[1];
+
+ if (HDstrcmp(h4_filename,"-m") == 0) {
+ fprintf(stderr,"\nError: Invalid Arguments\n");
+ PrintOptions_h5toh4();
+ status = -1;
+ break;
+ }
+#ifndef WIN32
+ if (test_file(h5_filename,O_EXCL,292) != 0 ) { /* 292 Decimal - 0444 Octal, a+r */
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status = -1;
+ break;
+ }
+ if (test_dir(h5_filename) != 0 ) {
+ fprintf(stderr,"%s: Is a directory\n",h5_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status = -1;
+ break;
+ }
+ if (test_file(h4_filename,O_CREAT|O_RDWR,436) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status = -1;
+ break;
+ }
+ if (test_dir(h4_filename) != 0 ) {
+ fprintf(stderr,"%s: Is a directory\n",h4_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status = -1;
+ break;
+ }
+#endif
+ status = h5toh4(h5_filename, h4_filename);
+ if ( status != 0 ) {
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ }
+ break;
+
+ default: /* h5toh4 -m file1 file2 file3 ... */
+ if (HDstrcmp(argv[0],"-m") != 0) {
+ fprintf(stderr,"\nError: Invalid Arguments\n");
+ PrintOptions_h5toh4();
+ status = -1;
+ break;
+ }
+ argv++;
+ argc--;
+
+ while ( argc > 0 ) {
+ h5_filename = argv[0];
+ argv++;
+ argc--;
+
+ if (HDstrcmp(h5_filename,"-m") == 0) {
+ fprintf(stderr,"\nError: Invalid Arguments\n");
+ PrintOptions_h5toh4();
+ status2 = -1;
+ break;
+ }
+#ifndef WIN32
+ if (test_file(h5_filename,O_EXCL,292) != 0 ) { /* 292 Decimal - 0444 Octal, a+r */
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status2 = -1;
+ continue;
+ }
+ if (test_dir(h5_filename) != 0 ) {
+ fprintf(stderr,"%s: Is a directory\n",h5_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status2 = -1;
+ continue;
+ }
+#endif
+ h4_extension = HDstrdup("hdf");
+
+ h4_filename = BuildFilename(h5_filename,h4_extension);
+ if (h4_filename == NULL) {
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status2 = -1;
+ continue;
+ }
+#ifndef WIN32
+ if (test_file(h4_filename,O_CREAT|O_EXCL,436) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status2 = -1;
+ continue;
+ }
+#endif
+ status = h5toh4(h5_filename, h4_filename);
+ if ( status != 0 ) {
+ fprintf(stderr,"Error: Problem with %s\n",h5_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
+ status2 = status;
+ }
+ if (h4_filename != NULL) {
+ HDfree(h4_filename);
+ }
+
+ }
+ status = status2;
+ break;
+ }
+
+ return status;
+
+}
+
+
+/*****************************************************************************
+
+ Routine: PrintOptions_h5toh4()
+
+ Description: This routine prints the acceptable argument formats out to stderr.
+
+ Input: None
+
+ Output: output to stderr
+
+*****************************************************************************/
+
+void PrintOptions_h5toh4(void)
+{
+ fprintf(stderr,"\nh5toh4 -h (gives this print-out)\n");
+ fprintf(stderr,"h5toh4 file.h5 file.hdf\n");
+ fprintf(stderr,"h5toh4 file.h5\n");
+ fprintf(stderr,"h5toh4 -m file1.h5 file2.h5 ...\n\n");
+}
+
+
+/*****************************************************************************
+
+ Routine: h5toh4()
+
+ Description: This routine translates information from a HDF5 file into a
+ HDF4 file.
+
+ Input: h5_filename - filename of HDF5 file,
+ h4_filename - filename of HDF4 file
+
+ Output: function return - error status
+
+*****************************************************************************/
+
+int h5toh4(char *h5_filename, char *h4_filename)
+{
+
+ hid_t fid, gid;
+ hid_t plist=H5P_DEFAULT;
+ int status = 0;
+ int32 hfile_id;
+ int32 sd_id;
+ op_data_t op_data;
+ void *edata;
+ hid_t (*func)(void*);
+
+
+ find_objs_t *info = malloc(sizeof(find_objs_t));
+
+
+
+ /* open hdf5 file */
+ if ((fid = H5Fopen (h5_filename, H5F_ACC_RDONLY, plist)) <= 0) {
+ fprintf(stderr,"Error: Unable to open file %s\n",h5_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ return (fid);
+ }
+
+ /* open root group */
+ if ((gid = H5Gopen (fid, "/")) <= 0 ) {
+ fprintf(stderr,"Error: Unable to open root group\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ return (gid);
+ } else {
+
+ /* open hdf4 file */
+ if ((hfile_id = Hopen(h4_filename, DFACC_CREATE, 0)) <= 0) {
+ fprintf(stderr,"Error: Unable to open file %s\n", h4_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ return (hfile_id);
+ } else {
+
+ if ((sd_id = SDstart(h4_filename, DFACC_RDWR)) <= 0) {
+ fprintf(stderr,"Error: Unable to open file %s, using SDstart\n", h4_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ return (sd_id);
+ } else {
+
+ /* Initialize Vgroup interface */
+ if ((status = Vstart(hfile_id)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to initialize Vgroup interface\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ /* allocate and initialize internal data structure */
+ init_table(&group_table);
+ init_table(&type_table);
+ init_table(&dset_table);
+ init_prefix(&prefix, prefix_len);
+
+ /* init the find_objs_t*/
+ info->threshold = 0;
+ info->prefix_len = prefix_len;
+ info->prefix = prefix;
+ info->group_table = group_table;
+ info->type_table = type_table;
+ info->dset_table = dset_table;
+ info->status = status;
+
+
+
+ /* Disable error reporting */
+ H5Eget_auto (&func, &edata);
+ H5Eset_auto (NULL, NULL);
+
+ /* find all objects one time */
+ if ((status = H5Giterate(fid, "/", NULL, (H5G_operator_t)find_objs, (void*)info)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ }
+
+ /* Enable error reporting */
+ H5Eset_auto (func, edata);
+
+#ifdef H5DUMP_DEBUG
+ dump_tables();
+#endif
+
+ if (status != SUCCEED) {
+ fprintf(stderr,"Error: internal error! \n");
+ goto done;
+ }
+
+ op_data.hfile_id = hfile_id;
+ op_data.sd_id = sd_id;
+ op_data.vgroup_id = 0;
+
+ /* start at root group */
+ if (( status = convert_group (gid, HDstrdup("/"), &op_data)) != SUCCEED) {
+ fprintf(stderr,"Error: convert_group did not work for %s\n","/");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ /* Terminate access to Vgroup interface */
+ if ((status = Vend(hfile_id)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to terminate Vgroup interface\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ status = FAIL;
+ }
+ }
+
+ /* close hdf4 SDS */
+ if ((status = SDend(sd_id)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close file %s, from SDstart\n", h4_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ }
+
+ /* close hdf4 file */
+ if ((status = Hclose(hfile_id)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close file %s\n", h4_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ }
+
+ if ((status = H5Gclose (gid)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close root group\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ if ((status = H5Fclose (fid)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close file %s\n", h5_filename);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+done:
+ free_table(&group_table);
+ free_table(&dset_table);
+ free_table(&type_table);
+
+ return status;
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: convert_group
+ *
+ * Purpose: Dump everything within the specified group
+ *
+ * Return: status
+ *
+ * Programmer: Paul Harten
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t
+convert_group (hid_t gid, char *name, op_data_t *op_data) {
+H5G_stat_t statbuf;
+
+ int32 hfile_id;
+ int32 vgroup_id;
+ int32 obj_idx;
+ int32 status;
+ int idx, flag;
+
+ hfile_id = op_data->hfile_id;
+
+ if ((vgroup_id = Vattach(hfile_id, -1, "w")) <= 0 ) {
+ fprintf(stderr,"Error: Unable to create new vgroup\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(vgroup_id);
+ }
+
+ if ((status = Vsetname(vgroup_id, name)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to set name on new vgroup\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(status);
+ }
+
+ if ((status = Vsetclass(vgroup_id, "HDF5")) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to set class on new vgroup\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(status);
+ }
+
+ if (op_data->vgroup_id == 0) {
+ obj_idx = -1; /* Indexes assigned below start from 0 */
+ } else {
+ if ((obj_idx = Vinsert(op_data->vgroup_id, vgroup_id)) < 0) {
+ fprintf(stderr,"Error: Index %d of the new vgroup is illegal\n",(int)obj_idx);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(obj_idx);
+ }
+ }
+ op_data->vgroup_id = vgroup_id;
+ op_data->sds_id = 0;
+ op_data->vdata_id = 0;
+ op_data->obj_idx = obj_idx;
+
+
+ /* hard link */
+ if ((status = H5Gget_objinfo(gid, ".", TRUE, &statbuf)) != SUCCEED ) {
+ fprintf(stderr,"Error: H5Gget_objinfo() did not work\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return (status);
+ }
+
+ if (HDstrcmp(name,"/") == 0) { /* this is the root group, just iterate */
+
+ if ((status = H5Aiterate(gid, NULL, (H5A_operator_t)convert_attr, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to iterate over all of the attributes\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(status);
+ }
+
+ if ((status = H5Giterate(gid, ".", NULL, (H5G_operator_t)convert_all, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(status);
+ }
+
+ } else {
+
+ if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
+
+ fprintf(stderr,"Error: object not found, %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
+
+ fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if(flag == TRUE ) { /* this has already been converted, don't convert the attributes again */
+
+ if ((status = H5Giterate(gid, ".", NULL, (H5G_operator_t)convert_all, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(status);
+ }
+
+ } else { /* flag == FALSE */
+
+ /* this is now being converted */
+ if ((status = set_tableflag(group_table,idx)) < 0 ) {
+ fprintf(stderr,"Error: set_tableflag should never return < 0\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(status);
+ }
+
+ if ((status = H5Aiterate(gid, NULL, (H5A_operator_t)convert_attr, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to iterate over all of the attributes\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(status);
+ }
+
+ if ((status = H5Giterate(gid, ".", NULL, (H5G_operator_t)convert_all, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ return(status);
+ }
+
+ }
+
+ }
+
+
+ if ((status = Vdetach(vgroup_id)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to detach the new Vgroup\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ return status;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: convert_dataset
+ *
+ * Purpose: Convert the specified data set
+ *
+ * Return: status
+ *
+ * Programmer: Paul Harten
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t
+convert_dataset (hid_t did, char *name, op_data_t *op_data) {
+hid_t type, space, class, mem_type, type2;
+/* H5G_stat_t statbuf; */
+size_t typesize;
+int i, idx;
+int32 dim_sizes[32], start[32], edges[32];
+int ndims;
+int ndimf;
+hsize_t dims[32], maxdims[32];
+hsize_t dimf[4];
+int permf[4];
+int32 hfile_id;
+int32 sd_id;
+int32 sds_id;
+int32 vdata_id;
+int32 vgroup_id;
+int32 n_values;
+int32 status;
+int32 h4_type;
+int32 recsize;
+int32 n_records, num_of_recs, record_pos;
+intn nmembers;
+char *buffer=NULL; /* read/write buffer*/
+char fieldname_list[4096] = "\0";
+char *fieldname=NULL;
+hid_t fieldtype;
+int32 order;
+off_t offset;
+off_t offset_array[512];
+hid_t h4type_array[512], memtype_array[512];
+int32 order_array[512];
+
+
+ /* hard link */
+/*
+ if ((status = H5Gget_objinfo(did, ".", TRUE, &statbuf)) != SUCCEED ) {
+ fprintf(stderr,"Error: H5Gget_objinfo() did not work\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return (status);
+ }
+*/
+
+ if ((type = H5Dget_type(did)) <= 0) {
+ fprintf(stderr, "Error: H5Dget_type() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((space = H5Dget_space(did)) <= 0) {
+ fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
+ fprintf(stderr, "Error: H5Sget_simple_extent_npoints() returned inappropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((ndims = H5Sget_simple_extent_dims(space,dims,maxdims)) < 0 ) {
+ fprintf(stderr, "Error: Problems getting ndims, dims, and maxdims of dataset\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = ndims;
+ return status;
+ }
+
+ if ((class = H5Tget_class(type)) < 0 ) {
+ fprintf(stderr,"Error: problem with getting class\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = class;
+ return status;
+ }
+
+ switch (class) {
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ sd_id = op_data->sd_id;
+#define NEWWAY
+#ifdef NEWWAY
+ if (FAIL==h5atomic_type_to_h4type(type, &mem_type, &typesize, &h4_type)){
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+#else
+ if ((h4_type = h5type_to_h4type(type)) == FAIL ) {
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ if ((mem_type = h4type_to_memtype(h4_type)) == FAIL ) {
+ fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ if ((typesize = H5Tget_size(mem_type)) <= 0) {
+ fprintf(stderr, "Error: H5Tget_size() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+#endif
+ if ((buffer = HDmalloc(n_values*typesize)) == NULL) {
+ fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ if ((status = H5Dread(did, mem_type, space, space, H5P_DEFAULT, buffer)) != SUCCEED) {
+ fprintf(stderr, "Error: Problems with H5Dread\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ for (i=0;i<ndims;i++) {
+ if (maxdims[i] == H5S_UNLIMITED) {
+ if ( i == 0 ) {
+ dim_sizes[0] = 0; /* this is how HDF4 communicates unlimited dimension */
+ } else {
+ dim_sizes[i] = (int32)dims[i];
+ }
+ } else {
+ dim_sizes[i] = (int32)maxdims[i];
+ }
+ start[i] = 0;
+ edges[i] = (int32)dims[i];
+ }
+ if ((sds_id = SDcreate(sd_id, name, h4_type, ndims, dim_sizes)) <= 0 ) {
+ fprintf(stderr, "Error: Unable to create SDS %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ op_data->sds_id = sds_id;
+ if ((status = SDwritedata(sds_id, start, NULL, edges, buffer)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to write SDS %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ }
+ if ((status = H5Aiterate(did, NULL, (H5A_operator_t)convert_attr, op_data)) < 0 ) {
+ fprintf(stderr,"Error: iterate over attributes\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ }
+ if ((status = SDendaccess(sds_id)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to end access to SDS %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ }
+ break;
+ case H5T_TIME:
+ fprintf(stderr,"Warning: H5T_TIME not yet implemented.\n");
+ break;
+ case H5T_STRING:
+ if (ndims==1) {
+ convert_dataset_string(did, name, op_data);
+ } else {
+ fprintf(stderr,"Warning: HDF5 datasets of H5T_STRING type with ndims > 1 are not converted.\n");
+ }
+ break;
+ case H5T_BITFIELD:
+ fprintf(stderr,"Warning: H5T_BITFIELD not yet implemented.\n");
+ break;
+ case H5T_OPAQUE:
+ fprintf(stderr,"Warning: H5T_OPAQUE not yet implemented.\n");
+ break;
+ case H5T_ARRAY:
+ fprintf(stderr,"Warning: H5T_OPAQUE not yet implemented.\n");
+ break;
+ case H5T_COMPOUND:
+ if (ndims==1) {
+ if ((nmembers = H5Tget_nmembers(type)) <= 0 ) {
+ fprintf(stderr, "Error: Unable to get information about compound datatype %d\n",nmembers);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+
+ offset = 0;
+ for (idx=0;idx<nmembers;idx++) {
+ if ((fieldtype = H5Tget_member_type(type, idx)) < 0 ) {
+ fprintf(stderr,"Error: H5 datasets of H5T_COMPOUND type with fieldtype %d, idx %d.\n",fieldtype,idx);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ /* Special case for array fields */
+ if(H5Tget_class(fieldtype)==H5T_ARRAY) {
+ hid_t arr_base_type;
+
+ /* Get the number of dimensions */
+ if ((ndimf = H5Tget_array_ndims(fieldtype)) < 0 || ndimf > H5S_MAX_RANK ) {
+ fprintf(stderr, "Error: rank of members of compound type should not be %d\n",ndimf);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* Get the dimensions and dimension permutations */
+ if (H5Tget_array_dims(fieldtype,dimf,permf) < 0) {
+ fprintf(stderr, "Error: cannot retrieve dimensions for array\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* Get the 'real' field type */
+ if ((arr_base_type=H5Tget_super(fieldtype)) < 0) {
+ fprintf(stderr, "Error: cannot retrieve base type for array\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ if (H5Tclose(fieldtype) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+
+ /* Assign the array's base type as the field type for future use */
+ fieldtype=arr_base_type;
+ } /* end if */
+ else
+ ndimf=0;
+#ifdef NEWWAY
+ if (FAIL==h5atomic_type_to_h4type(fieldtype, &mem_type, &typesize, &h4_type)){
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+#else
+ if ((h4_type = h5type_to_h4type(fieldtype)) < 0 ) {
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ if ((mem_type = h4type_to_memtype(h4_type)) == FAIL ) {
+ fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ if ((typesize = H5Tget_size(mem_type)) <= 0) {
+ fprintf(stderr, "Error: H5Tget_size() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+#endif
+ order = 1;
+ if (ndimf > 0) {
+ order *= dimf[permf[0]];
+ if (ndimf > 1) {
+ order *= dimf[permf[1]];
+ if (ndimf > 2) {
+ order *= dimf[permf[2]];
+ if (ndimf > 3) {
+ order *= dimf[permf[3]];
+ }
+ }
+ }
+ }
+ h4type_array[idx] = h4_type; /* used for VSfdefine */
+ memtype_array[idx] = mem_type; /* used during the build of the memory compound type */
+ offset_array[idx] = offset; /* used during the build of the memory compound type */
+ order_array[idx] = order; /* used for VSfdefine */
+
+ offset += order * typesize; /* calculating packed size of memory compound type */
+ }
+ hfile_id = op_data->hfile_id;
+ vgroup_id = op_data->vgroup_id;
+ if ((vdata_id = VSattach(hfile_id, -1, "w")) <= 0 ) {
+ fprintf(stderr, "Error: Unable to create vdata %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+/*
+ * This step is done during the convert_shared_dataset() call instead of here.
+ *
+ if ((idx = Vinsert(vgroup_id, vdata_id)) < 0 ) {
+ fprintf(stderr, "Error: Unable to insert vdata %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+*/
+ op_data->vdata_id = vdata_id;
+ if ((status = VSsetname(vdata_id, name)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set vdata name %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ if ((status = VSsetclass(vdata_id, "HDF5")) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set class on vdata %s\n", name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ if ((type2 = H5Tcreate(H5T_COMPOUND, (size_t)offset)) <= 0 ) {
+ fprintf(stderr, "Error: unable to execute H5Tcreate()\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ for (idx=0;idx<nmembers;idx++) {
+ /* Special case for array fields */
+ if(H5Tget_member_class(type,idx)==H5T_ARRAY) {
+ hid_t arr_type;
+
+ if ((arr_type = H5Tget_member_type(type, idx)) < 0 ) {
+ fprintf(stderr,"Error: H5 datasets of H5T_COMPOUND type with fieldtype %d, idx %d.\n",arr_type,idx);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ /* Get the number of dimensions */
+ if ((ndimf = H5Tget_array_ndims(arr_type)) < 0 || ndimf > H5S_MAX_RANK ) {
+ fprintf(stderr, "Error: rank of members of compound type should not be %d\n",ndimf);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* Get the dimensions and dimension permutations */
+ if (H5Tget_array_dims(arr_type,dimf,permf) < 0) {
+ fprintf(stderr, "Error: cannot retrieve dimensions for array\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ if (H5Tclose(arr_type) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ } /* end if */
+ else
+ ndimf=0;
+
+ if ((fieldname = H5Tget_member_name(type, idx)) == NULL ) {
+ fprintf(stderr, "Error: Unable to get fieldname for compound type %d, idx %d\n", type, idx);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ if ((offset = H5Tget_offset(memtype_array[idx])) < 0 || offset >= 128 ) {
+ fprintf(stderr, "Error: H5Tget_offset() is returning a bad value %d\n",(int)offset);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ if (ndimf == 0 ) {
+ if ((status = H5Tinsert(type2,fieldname,offset_array[idx]+offset,memtype_array[idx])) != SUCCEED ) {
+ fprintf(stderr, "Error: Problems inserting field into compound datatype\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ } else {
+ hid_t arr_type;
+
+ /* Create the array datatype */
+ if ((arr_type = H5Tarray_create(memtype_array[idx], ndimf, dimf, permf)) < 0 ) {
+ fprintf(stderr,"Error: cannot create array datatype\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+
+ if ((status = H5Tinsert(type2,fieldname,offset_array[idx]+offset,arr_type)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problems inserting field into compound datatype\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+
+ if (H5Tclose(arr_type) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ }
+ if ((status = VSfdefine(vdata_id, fieldname, h4type_array[idx], order_array[idx])) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set field %d\n", idx);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ strcat(fieldname_list,fieldname);
+ if (idx<nmembers-1) {
+ strcat(fieldname_list,", ");
+ }
+
+ if (fieldname != NULL) {
+ HDfree(fieldname);
+ }
+ }
+ if ((status = VSsetfields(vdata_id, fieldname_list)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set fieldname list %s\n", name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ if ((status = VSsetinterlace(vdata_id, FULL_INTERLACE)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set FULL_INTERLACE mode, status %d\n", (int)status);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ if ((recsize = H5Tget_size(type2)) <= 0 ) {
+ fprintf(stderr, "Error: Unable to get record size %d\n", (int)recsize);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+/*
+ Since the space is rank 1, n_records does not depend on maxdims.
+*/
+ n_records = n_values;
+ if ((buffer = HDmalloc(n_records*recsize)) == NULL) {
+ fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ if ((status = H5Dread(did, type2, space, space, H5P_DEFAULT, buffer)) != SUCCEED) {
+ fprintf(stderr, "Error: Problems with H5Dread\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ if ((status = H5Tclose(type2)) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ if ((record_pos = VSseek(vdata_id, 0)) != 0 ) {
+ fprintf(stderr, "Error: Could not seek the beginning of the Vdata, %d\n", (int)record_pos);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = record_pos;
+ break;
+ }
+ if ((num_of_recs = VSwrite(vdata_id, (void *)buffer, n_records, FULL_INTERLACE)) != n_records ) {
+ fprintf(stderr, "Error: Only able to write %d of %d records\n", (int)num_of_recs, (int)n_records);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = num_of_recs;
+ break;
+ }
+
+ /* there are only vdata attributes, no field attributes */
+ if ((status = H5Aiterate(did, NULL, (H5A_operator_t)convert_attr, op_data)) < 0 ) {
+ fprintf(stderr,"Error: iterate over attributes\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ if ((status = VSdetach(vdata_id)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to detach to vdata %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+
+ } else {
+
+ fprintf(stderr,"Warning: HDF5 datasets of H5T_COMPOUND type with ndims > 1 are not converted.\n");
+
+ }
+ break;
+ default:
+ fprintf(stderr,"Error: %d class not found\n",class);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ }
+
+ if ((status = H5Tclose(type)) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ }
+
+ if ((status = H5Sclose(space)) < 0 ) {
+ fprintf(stderr,"Error: closing space\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ }
+
+ if (buffer != NULL) {
+ HDfree(buffer);
+ }
+
+ return status;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: convert_attr
+ *
+ * Purpose: dump the attribute
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Paul Harten
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+
+herr_t
+convert_attr (hid_t attr, char *attr_name, op_data_t *op_data)
+{
+hid_t attr_id, type, space, mem_type, class;
+size_t typesize;
+char *attr_values=NULL;
+int32 status;
+int32 h4_type;
+int32 sds_id;
+int32 vdata_id;
+int32 vgroup_id;
+int32 n_values;
+int32 order;
+hid_t fxdlenstr;
+size_t lenstr;
+H5T_cset_t cset;
+H5T_str_t strpad;
+
+ sds_id = op_data->sds_id;
+ vdata_id = op_data->vdata_id;
+ vgroup_id = op_data->vgroup_id;
+
+ if ((attr_id = H5Aopen_name (attr, attr_name))>= 0) {
+
+ if ((type = H5Aget_type(attr_id)) <= 0) {
+ fprintf(stderr, "Error: H5Aget_type() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((class = H5Tget_class(type)) < 0 ) {
+ fprintf(stderr,"Error: problem with getting class\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = class;
+ return status;
+ }
+
+ switch (class) {
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+
+
+ if ((space = H5Aget_space(attr_id)) <= 0) {
+ fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
+ fprintf(stderr, "Error: H5sget_simple_extent_npoints() didn't return correct value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+#ifdef NEWWAY
+ if (FAIL==h5atomic_type_to_h4type(type, &mem_type, &typesize, &h4_type)){
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+#else
+ if ((h4_type = h5type_to_h4type(type)) == FAIL ) {
+ fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((mem_type = h4type_to_memtype(h4_type)) == FAIL ) {
+ fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((typesize = H5Tget_size(mem_type)) <= 0) {
+ fprintf(stderr, "Error: H5Tget_size() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+#endif
+
+ if ((attr_values = HDmalloc(n_values*typesize)) == NULL) {
+ fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((status = H5Aread(attr_id, mem_type, attr_values)) != SUCCEED) {
+ fprintf(stderr, "Error: Problems with H5Aread\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if (sds_id != 0) {
+ if ((status = SDsetattr(sds_id, attr_name, h4_type, n_values, attr_values)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ } else if (vdata_id != 0) {
+ if ((status = VSsetattr(vdata_id, -1, attr_name, h4_type, n_values, attr_values)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ } else {
+ if ((status = Vsetattr(vgroup_id, attr_name, h4_type, n_values, attr_values)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ }
+
+ if ((status = H5Sclose(space)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problems closing H5Sclose\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ if ((status = H5Aclose(attr_id)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problems closing H5Aclose\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if (attr_values != NULL) {
+ HDfree(attr_values);
+ }
+
+ status = SUCCEED;
+ break;
+
+ case H5T_TIME:
+ fprintf(stderr,"Warning: H5T_TIME attribute not yet implemented.\n");
+ break;
+ case H5T_STRING:
+
+ fxdlenstr = type;
+ h4_type = DFNT_CHAR;
+
+ if ((space = H5Aget_space(attr_id)) <= 0) {
+ fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
+ fprintf(stderr, "Error: H5sget_simple_extent_npoints() didn't return correct value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((mem_type = H5Tcopy(H5T_C_S1)) == FAIL ) {
+ fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = mem_type;
+ return status;
+ }
+ if ((lenstr = H5Tget_size(fxdlenstr)) <= 0 ) {
+ fprintf(stderr, "Error: size of fixed length string type should not be %d\n",(int)lenstr);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ return lenstr;
+ }
+ if ((status = H5Tset_size(mem_type,lenstr)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problem with H5Tset_size()\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ return status;
+ }
+
+ strpad = H5Tget_strpad(fxdlenstr);
+ if ((strpad != H5T_STR_NULLTERM) && (strpad != H5T_STR_NULLPAD) && (strpad != H5T_STR_SPACEPAD)) {
+ fprintf(stderr, "Error: Invalid string padding value, %d\n",(int)strpad);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ return strpad;
+ }
+ if ((status = H5Tset_strpad(mem_type, H5T_STR_SPACEPAD)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problem with H5Tset_strpad()\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ return status;
+ }
+
+ if ((cset = H5Tget_cset(fxdlenstr)) != H5T_CSET_ASCII ) {
+ fprintf(stderr, "Error: cset value != %d\n",(int)H5T_CSET_ASCII);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ return cset;
+ }
+ if ((status = H5Tset_cset(mem_type,cset)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problem with H5Tset_cset()\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ return status;
+ }
+
+ order = n_values * lenstr;
+ if ((attr_values = HDmalloc(order)) == NULL) {
+ fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((status = H5Aread(attr_id, mem_type, attr_values)) != SUCCEED) {
+ fprintf(stderr, "Error: Problems with H5Aread\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if (sds_id != 0) {
+ if ((status = SDsetattr(sds_id, attr_name, h4_type, order, attr_values)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ } else if (vdata_id != 0) {
+ if ((status = VSsetattr(vdata_id, -1, attr_name, h4_type, order, attr_values)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ } else {
+ if ((status = Vsetattr(vgroup_id, attr_name, h4_type, order, attr_values)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ }
+
+ if ((status = H5Sclose(space)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problems closing H5Sclose\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ if ((status = H5Aclose(attr_id)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problems closing H5Aclose\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if (attr_values != NULL) {
+ HDfree(attr_values);
+ }
+
+ status = SUCCEED;
+ break;
+ case H5T_BITFIELD:
+ fprintf(stderr,"Warning: H5T_BITFIELD attribute not yet implemented.\n");
+ break;
+ case H5T_OPAQUE:
+ fprintf(stderr,"Warning: H5T_OPAQUE attribute not yet implemented.\n");
+ break;
+ case H5T_COMPOUND:
+ fprintf(stderr,"Warning: H5T_COMPOUND attribute not implemented.\n");
+ break;
+ default:
+ fprintf(stderr,"Error: %d class not found\n",class);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ if ((status = H5Tclose(type)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problems closing H5Tclose\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ } else {
+
+ status = FAIL;
+
+ }
+
+ return status;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: convert_all
+ *
+ * Purpose: Dump everything in the specified object
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Paul Harten
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t
+convert_all (hid_t group, char *name, op_data_t *op_data)
+{
+ hid_t obj;
+ H5G_stat_t statbuf, statbuf2;
+ int status;
+ op_data_t op_data_save;
+ int32 vgroup_id;
+ int32 sd_id;
+ int32 sds_id;
+ int idx, flag;
+ void *edata;
+ hid_t (*func)(void*);
+
+ op_data_save = *op_data;
+
+ vgroup_id = op_data->vgroup_id;
+ sd_id = op_data->sd_id;
+ sds_id = op_data->sds_id;
+
+ if ((status = H5Gget_objinfo(group, name, FALSE, &statbuf)) != SUCCEED ) {
+ fprintf(stderr,"Error: H5Gget_objinfo() did not work\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ return (status);
+ }
+ statbuf2 = statbuf;
+
+ switch (statbuf.type) {
+
+ case H5G_LINK: /* this is a soft link only */
+
+
+ /* Disable error reporting */
+ H5Eget_auto (&func, &edata);
+ H5Eset_auto (NULL, NULL);
+
+ /* test to see if object exists */
+ if ((status = H5Gget_objinfo(group, name, TRUE, NULL)) != SUCCEED ) {
+ fprintf(stderr,"Warning: the object pointed to by the symbolic link \"%s\" does not exist.\n",name);
+ }
+
+ /* Enable error reporting */
+ H5Eset_auto (func, edata);
+
+ if (status != SUCCEED) {
+ break;
+ }
+
+ /* follow link for type */
+ if ((status = H5Gget_objinfo(group, name, TRUE, &statbuf)) != SUCCEED ) {
+ fprintf(stderr,"Error: H5Gget_objinfo() did not work\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ return (status);
+ }
+
+ if (statbuf.type==H5G_DATASET ) {
+
+ if ((idx = get_table_idx(dset_table, statbuf.objno)) < 0 ) {
+
+ fprintf(stderr,"Error: object not found\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if((flag = get_tableflag(dset_table,idx)) < 0 ) {
+
+ fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if(flag == TRUE ) { /* this has already been converted, add as a tag/ref */
+
+ if ((obj = H5Dopen (group, name)) <= 0 ) {
+ fprintf(stderr,"Error: Unable to open H5 dataset\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ return (obj);
+ } else {
+ if ((status = convert_shared_dataset(obj, idx, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to convert to tag/ref\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ }
+ }
+ if ((status = H5Dclose(obj)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close H5 dataset %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ } else { /* flag == FALSE */
+
+ if ((obj = H5Dopen (group, name)) <= 0 ) {
+ fprintf(stderr,"Error: Unable to open H5 dataset\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ return (obj);
+ } else {
+ if (( status = convert_dataset (obj, name, op_data)) != SUCCEED) {
+ fprintf(stderr,"Error: convert_dataset did not work for %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ if ((status = convert_shared_dataset(obj, idx, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to convert to tag/ref\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ }
+ if(( status = set_tableflag(dset_table,idx)) != SUCCEED ) {
+ fprintf(stderr,"Error: set_tableflag() did not work for %s\n", name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ break;
+ }
+ }
+ if ((status = H5Dclose(obj)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close H5 dataset %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ }
+
+ } else if (statbuf.type==H5G_GROUP ) {
+
+ if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
+
+ fprintf(stderr,"Error: object not found\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
+
+ fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if(flag == TRUE ) {
+
+ if (( status = convert_shared_group (group, idx, op_data)) != SUCCEED) {
+ fprintf(stderr,"Error: convert_group did not work for %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ } else { /* flag == FALSE */
+
+ if ((obj = H5Gopen (group, name)) <= 0 ) {
+ fprintf(stderr,"Error: Unable to open group\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ return (obj);
+ } else {
+ if (( status = convert_group (obj, name, op_data)) != SUCCEED) {
+ fprintf(stderr,"Error: convert_group did not work for %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ }
+ if ((status = H5Gclose(obj)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close group %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ }
+
+ }
+
+ break;
+
+ case H5G_GROUP:
+
+ if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
+
+ fprintf(stderr,"Error: object not found\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
+
+ fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if(flag == TRUE ) {
+
+ if (( status = convert_shared_group (group, idx, op_data)) != SUCCEED) {
+ fprintf(stderr,"Error: convert_group did not work for %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ } else { /* flag == FALSE */
+
+ if ((obj = H5Gopen (group, name)) <= 0 ) {
+ fprintf(stderr,"Error: Unable to open group\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ return (obj);
+ } else {
+ if (( status = convert_group (obj, name, op_data)) != SUCCEED) {
+ fprintf(stderr,"Error: convert_group did not work for %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ }
+ if ((status = H5Gclose(obj)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close group %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ }
+
+ break;
+
+ case H5G_DATASET:
+
+ if ((idx = get_table_idx(dset_table, statbuf.objno)) < 0 ) {
+
+ fprintf(stderr,"Error: object not found\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if((flag = get_tableflag(dset_table,idx)) < 0 ) {
+
+ fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+
+ } else if(flag == TRUE ) { /* this has already been converted, add as a tag/ref */
+
+ if ((obj = H5Dopen (group, name)) <= 0 ) {
+ fprintf(stderr,"Error: Unable to open H5 dataset\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ return (obj);
+ } else {
+ if ((status = convert_shared_dataset(obj, idx, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to convert to tag/ref\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ }
+ }
+ if ((status = H5Dclose(obj)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close H5 dataset %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ } else { /* flag == FALSE */
+
+ if ((obj = H5Dopen (group, name)) <= 0 ) {
+ fprintf(stderr,"Error: Unable to open H5 dataset\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ return (obj);
+ } else {
+ if (( status = convert_dataset (obj, name, op_data)) != SUCCEED) {
+ fprintf(stderr,"Error: convert_dataset did not work for %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+ if ((status = convert_shared_dataset(obj, idx, op_data)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to convert to tag/ref\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ }
+ if(( status = set_tableflag(dset_table,idx)) != SUCCEED ) {
+ fprintf(stderr,"Error: set_tableflag() did not work for %s\n", name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ break;
+ }
+ }
+ if ((status = H5Dclose(obj)) != SUCCEED) {
+ fprintf(stderr,"Error: Unable to close H5 dataset %s\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
+ status = FAIL;
+ break;
+ }
+
+ }
+
+ break;
+
+ case H5G_TYPE:
+ /* object is ignored */
+ break;
+
+ default:
+ fprintf (stderr,"Unknown Object %s\n", name);
+ status = FAIL;
+ break;
+
+ }
+
+ *op_data = op_data_save;
+
+ return SUCCEED;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: convert_shared_dataset
+ *
+ * Purpose: Handle a shared dataset which has already been converted.
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Paul Harten
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t
+convert_shared_dataset(hid_t did, int idx, op_data_t *op_data)
+{
+ int status=SUCCEED;
+ int32 vgroup_id;
+ char *dataset_name=NULL;
+ char *dataset_name2=NULL;
+ int32 hfile_id;
+ int32 sd_id;
+ int32 sds_id;
+ int32 sds_ref;
+ int32 vdata_ref;
+ int32 sds_index;
+ int32 numtagref;
+ hid_t type, space, class;
+ hsize_t dims[32], maxdims[32];
+ int n_values, ndims;
+
+ vgroup_id = op_data->vgroup_id;
+
+ if ((dataset_name = get_objectname(dset_table, idx)) == NULL ) {
+ fprintf(stderr,"Error: get_objectname() did not work\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (status);
+ }
+
+ if ((dataset_name2 = strrchr(dataset_name,'/')) == NULL) { /* find last "/" in dataset_name */
+ dataset_name2 = dataset_name; /* no "/"s were found */
+ } else {
+ dataset_name2 = dataset_name2 + sizeof(char); /* 1 character past last "/" */
+ }
+
+ if ((type = H5Dget_type(did)) <= 0) {
+ fprintf(stderr, "Error: H5Dget_type() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((space = H5Dget_space(did)) <= 0) {
+ fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
+ fprintf(stderr, "Error: H5Sget_simple_extent_npoints() returned inappropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((ndims = H5Sget_simple_extent_dims(space,dims,maxdims)) < 0 ) {
+ fprintf(stderr, "Error: Problems getting ndims, dims, and maxdims of dataset\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ status = ndims;
+ return status;
+ }
+
+ if ((class = H5Tget_class(type)) < 0 ) {
+ fprintf(stderr,"Error: problem with getting class\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ status = class;
+ return status;
+ }
+
+ switch (class) {
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ sd_id = op_data->sd_id;
+ if ((sds_index = SDnametoindex(sd_id, dataset_name2)) < 0 ) {
+ fprintf (stderr,"Error: Problem with SDnametoindex().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (sds_index);
+ }
+ if ((sds_id = SDselect(sd_id, sds_index)) < 0 ) {
+ fprintf (stderr,"Error: Problem with SDselect().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (sds_id);
+ }
+ if ((sds_ref = SDidtoref(sds_id)) < 0 ) {
+ fprintf (stderr,"Error: Problem with SDidtoref().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (sds_ref);
+ }
+ if ((numtagref = Vaddtagref(vgroup_id, DFTAG_NDG, sds_ref)) < 0 ) {
+ fprintf (stderr,"Error: Problem with Vaddtagref().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (numtagref);
+ }
+ break;
+ case H5T_TIME:
+ fprintf(stderr,"Error: H5T_TIME not yet implemented.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ break;
+ case H5T_STRING:
+ hfile_id = op_data->hfile_id;
+ if (ndims==1) {
+ if ((vdata_ref = VSfind(hfile_id,dataset_name2)) <= 0 ) {
+ fprintf (stderr,"Error: Problem with VSfind().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (vdata_ref);
+ }
+ if ((numtagref = Vaddtagref(vgroup_id, DFTAG_VH, vdata_ref)) < 0 ) {
+ fprintf (stderr,"Error: Problem with Vaddtagref().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (numtagref);
+ }
+ }
+ break;
+ case H5T_BITFIELD:
+ fprintf(stderr,"Error: H5T_BITFIELD not yet implemented.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ break;
+ case H5T_OPAQUE:
+ fprintf(stderr,"Error: H5T_OPAQUE not yet implemented.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ break;
+ case H5T_COMPOUND:
+ hfile_id = op_data->hfile_id;
+ if (ndims==1) {
+ if ((vdata_ref = VSfind(hfile_id,dataset_name2)) <= 0 ) {
+ fprintf (stderr,"Error: Problem with VSfind().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (vdata_ref);
+ }
+ if ((numtagref = Vaddtagref(vgroup_id, DFTAG_VH, vdata_ref)) < 0 ) {
+ fprintf (stderr,"Error: Problem with Vaddtagref().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ return (numtagref);
+ }
+ }
+ break;
+ default:
+ fprintf(stderr,"Error: %d class not found\n",class);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ if ((status = H5Tclose(type)) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ if (dataset_name != NULL) {
+ HDfree (dataset_name);
+ }
+
+ return status;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: convert_shared_group
+ *
+ * Purpose: Handle a shared group which has already been converted.
+ *
+ * Return: status
+ *
+ * Programmer: Paul Harten
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t
+convert_shared_group (hid_t group, int idx, op_data_t *op_data) {
+
+ int32 hfile_id;
+ int32 vgroup_id;
+ int32 vgroup_ref;
+ int32 numtagref;
+ int32 status = SUCCEED;
+ hid_t group2;
+ char *group_name=NULL;
+ char *group_name2=NULL;
+ char vgroup_name[VGNAMELENMAX];
+
+ group2 = group;
+ hfile_id = op_data->hfile_id;
+
+ if ((group_name = get_objectname(group_table, idx)) == NULL ) {
+ fprintf(stderr,"Error: get_objectname() did not work\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
+ status = FAIL;
+ return (status);
+ }
+
+ if ((group_name2 = strrchr(group_name,'/')) == NULL) { /* find last "/" in group_name */
+ group_name2 = group_name; /* no "/"s were found */
+ } else {
+ group_name2 = group_name2 + sizeof(char); /* 1 character past last "/" */
+ }
+
+ if ((status = Vgetname(op_data->vgroup_id,vgroup_name)) < 0 ) {
+ fprintf (stderr,"Error: Problem with Vfind().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
+ return (status);
+ }
+
+ if ((vgroup_ref = Vfind(hfile_id,vgroup_name)) <= 0 ) {
+ fprintf (stderr,"Error: Problem with Vfind().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
+ return (vgroup_ref);
+ }
+
+ if ((vgroup_id = Vattach(hfile_id, vgroup_ref, "w")) <= 0 ) {
+ fprintf(stderr,"Error: Unable to create new vgroup\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
+ return(vgroup_id);
+ }
+
+ if ((vgroup_ref = Vfind(hfile_id,group_name2)) <= 0 ) {
+ fprintf (stderr,"Error: Problem with Vfind().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
+ return (vgroup_ref);
+ }
+
+ if ((numtagref = Vaddtagref(vgroup_id, DFTAG_VG, vgroup_ref)) < 0 ) {
+ fprintf (stderr,"Error: Problem with Vaddtagref().\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
+ return (numtagref);
+ }
+
+ if ((status = Vdetach(vgroup_id)) != SUCCEED ) {
+ fprintf(stderr,"Error: Unable to detach the new Vgroup\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
+ status = FAIL;
+ }
+
+ if (group_name != NULL) {
+ HDfree(group_name);
+ }
+
+ return status;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: convert_dataset_string
+ *
+ * Purpose: convert a dataset with string elements.
+ *
+ * Return: status
+ *
+ * Programmer: Paul Harten
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t
+convert_dataset_string (hid_t did, char *name, op_data_t *op_data) {
+
+ int32 hfile_id;
+ int32 vgroup_id;
+ int32 vdata_id;
+hid_t fxdlenstr, space, class, mem_type;
+const char* fieldname = {"string"};
+const char* fieldname_list = fieldname;
+char *buffer;
+int32 status;
+int32 h4_type;
+int32 recsize, n_records, n_values, num_of_recs, record_pos;
+size_t lenstr;
+H5T_cset_t cset;
+H5T_str_t strpad;
+
+ if ((fxdlenstr = H5Dget_type(did)) <= 0) {
+ fprintf(stderr, "Error: H5Dget_type() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((class = H5Tget_class(fxdlenstr)) != H5T_STRING ) {
+ fprintf(stderr,"Error: problem with getting class\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
+ status = class;
+ return status;
+ }
+
+ if ((space = H5Dget_space(did)) <= 0) {
+ fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
+ fprintf(stderr, "Error: H5Sget_simple_extent_npoints() returned inappropriate value.\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ h4_type = DFNT_CHAR;
+ if ((mem_type = H5Tcopy(H5T_C_S1)) == FAIL ) {
+ fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = mem_type;
+ return status;
+ }
+ if ((lenstr = H5Tget_size(fxdlenstr)) <= 0 ) {
+ fprintf(stderr, "Error: size of fixed length string type should not be %d\n",(int)lenstr);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return lenstr;
+ }
+ if ((status = H5Tset_size(mem_type,lenstr)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problem with H5Tset_size()\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+
+ strpad = H5Tget_strpad(fxdlenstr);
+ if ((strpad != H5T_STR_NULLTERM) && (strpad != H5T_STR_NULLPAD) && (strpad != H5T_STR_SPACEPAD)) {
+ fprintf(stderr, "Error: Invalid string padding value, %d\n",(int)strpad);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return strpad;
+ }
+ if ((status = H5Tset_strpad(mem_type, strpad)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problem with H5Tset_strpad()\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+
+ if ((cset = H5Tget_cset(fxdlenstr)) != H5T_CSET_ASCII ) {
+ fprintf(stderr, "Error: cset value != %d\n",(int)H5T_CSET_ASCII);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return cset;
+ }
+ if ((status = H5Tset_cset(mem_type,cset)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problem with H5Tset_cset()\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+
+ hfile_id = op_data->hfile_id;
+ vgroup_id = op_data->vgroup_id;
+ if ((vdata_id = VSattach(hfile_id, -1, "w")) <= 0 ) {
+ fprintf(stderr, "Error: Unable to create vdata %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+
+ op_data->vdata_id = vdata_id;
+ if ((status = VSsetname(vdata_id, name)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set vdata name %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+ if ((status = VSsetclass(vdata_id, "HDF5")) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set class on vdata %s\n", name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+
+ if ((status = VSfdefine(vdata_id, fieldname, h4_type, lenstr)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to VSfdefine() field\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+
+ if ((status = VSsetfields(vdata_id, fieldname_list)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set fieldname list %s\n", fieldname_list);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+ if ((status = VSsetinterlace(vdata_id, FULL_INTERLACE)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to set FULL_INTERLACE mode, status %d\n", (int)status);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+ if ((recsize = H5Tget_size(mem_type)) <= 0 ) {
+ fprintf(stderr, "Error: Unable to get record size %d\n", (int)recsize);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = recsize;
+ return status;
+ }
+/*
+ Since the space is rank 1, n_records does not depend on maxdims.
+*/
+ n_records = n_values;
+ if ((buffer = HDmalloc(n_records*recsize)) == NULL) {
+ fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = FAIL;
+ return status;
+ }
+ if ((status = H5Dread(did, mem_type, space, space, H5P_DEFAULT, buffer)) != SUCCEED) {
+ fprintf(stderr, "Error: Problems with H5Dread\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+
+ if ((record_pos = VSseek(vdata_id, 0)) != 0 ) {
+ fprintf(stderr, "Error: Could not seek the beginning of the Vdata, %d\n", (int)record_pos);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = record_pos;
+ return status;
+ }
+ if ((num_of_recs = VSwrite(vdata_id, (void *)buffer, n_records, FULL_INTERLACE)) != n_records ) {
+ fprintf(stderr, "Error: Only able to write %d of %d records\n", (int)num_of_recs, (int)n_records);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ status = num_of_recs;
+ return status;
+ }
+
+ /* there are only vdata attributes, no field attributes */
+ if ((status = H5Aiterate(did, NULL, (H5A_operator_t)convert_attr, op_data)) < 0 ) {
+ fprintf(stderr,"Error: iterate over attributes\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+ if ((status = VSdetach(vdata_id)) != SUCCEED ) {
+ fprintf(stderr, "Error: Unable to detach to vdata %s.\n",name);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
+ return status;
+ }
+
+ if (buffer != NULL) {
+ HDfree(buffer);
+ }
+
+ return status;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: h5atomic_type_to_h4type
+ *
+ * Purpose: Match an H5 atomic type to an appropriate H4 type.
+ * Assign an appropirate H5 memory type that matches the H4 type.
+ * Return the H5 memory type, H4 type and sizeof H4 via pointers.
+ *
+ * Return: SUCCEED on suceed, FAIL on failure.
+ * When fail, pointer values of h5memtype, h5memsize and h4_type
+ * may have changed and are undefined.
+ *
+ * Programmer: Albert Cheng, March 2000
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+static herr_t h5atomic_type_to_h4type(const hid_t h5type, hid_t* h5memtype, size_t* h5memsize, int32* h4type)
+{
+ H5T_class_t class;
+ size_t h5typesize, h4typesize;
+ H5T_sign_t sign;
+ hid_t mem_datatype = FAIL;
+
+ if ((class = H5Tget_class(h5type)) < 0 ) {
+ fprintf(stderr,"Error: problem with getting type class\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+
+ switch(class){
+ case H5T_INTEGER:
+ if ((h5typesize = H5Tget_size(h5type)) == 0 ) {
+ fprintf(stderr,"Error: problem with getting type size\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ if ((sign = H5Tget_sign(h5type)) == H5T_SGN_ERROR) {
+ fprintf(stderr,"Error: problem with getting type sign\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* deduce the proper HDF4 integer type to use according to the size of the HDF5 type. */
+ /* Current HDF4 types can be 8, 16, 32 bits (1, 2, 4 bytes). */
+ switch(h5typesize){
+ case 1:
+ *h4type = (sign == H5T_SGN_2 ? DFNT_INT8 : DFNT_UINT8);
+ h4typesize = sizeof(int8);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
+ }else
+ return(FAIL);
+ break;
+ case 2:
+ *h4type = (sign == H5T_SGN_2 ? DFNT_INT16 : DFNT_UINT16);
+ h4typesize = sizeof(int16);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
+ }else
+ return(FAIL);
+ break;
+ case 4:
+ *h4type = (sign == H5T_SGN_2 ? DFNT_INT32 : DFNT_UINT32);
+ h4typesize = sizeof(int32);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
+ mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
+ }else
+ return(FAIL);
+ break;
+ default:
+ fprintf(stderr,"Error: unmatchable integer type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ break;
+ /* end of case H5T_INTEGER */
+
+ case H5T_FLOAT:
+ if ((h5typesize = H5Tget_size(h5type)) == 0 ) {
+ fprintf(stderr,"Error: problem with getting type size\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* deduce the proper HDF4 floating point type to use according to the size of the HDF5 type. */
+ /* Current HDF4 types can be 32 or 64 bits (4 or 8 bytes). */
+ switch(h5typesize){
+ case 4:
+ *h4type = DFNT_FLOAT32;
+ h4typesize = sizeof(float32);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_FLOAT)){
+ mem_datatype = H5T_NATIVE_FLOAT;
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_DOUBLE)){
+ mem_datatype = H5T_NATIVE_DOUBLE;
+ }else
+ return(FAIL);
+ break;
+ case 8:
+ *h4type = DFNT_FLOAT64;
+ h4typesize = sizeof(float64);
+ if (h4typesize == H5Tget_size(H5T_NATIVE_FLOAT)){
+ mem_datatype = H5T_NATIVE_FLOAT;
+ }else if (h4typesize == H5Tget_size(H5T_NATIVE_DOUBLE)){
+ mem_datatype = H5T_NATIVE_DOUBLE;
+ }else
+ return(FAIL);
+ break;
+ default:
+ fprintf(stderr,"Error: unmatchable H5 float type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
+ return FAIL;
+ }
+ break;
+ /* end of case H5T_FLOAT */
+
+ default:
+ return FAIL;
+ }
+
+ *h5memsize = h4typesize;
+ *h5memtype = mem_datatype;
+ return(SUCCEED);
+}
+#ifndef NEWWAY
+/*****************************************************************************
+
+ Routine: h5type_to_h4type(h5type)
+
+ Description: Translate h5 datatype into h4 datatype
+
+ Input: h5 datatype
+
+ Output: function return, h4 datatype
+
+*****************************************************************************/
+
+int32 h5type_to_h4type(hid_t h5_datatype)
+{
+ int32 h4_datatype;
+
+ if (H5Tequal(h5_datatype,H5T_STD_I8BE)) {
+ h4_datatype = DFNT_INT8;
+ } else if (H5Tequal(h5_datatype,H5T_STD_I16BE)) {
+ h4_datatype = DFNT_INT16;
+ } else if (H5Tequal(h5_datatype,H5T_STD_I32BE)) {
+ h4_datatype = DFNT_INT32;
+/*
+ * This is not supported by HDF4
+ *
+ } else if (H5Tequal(h5_datatype,H5T_STD_I64BE)) {
+ h4_datatype = DFNT_INT64;
+*/
+ } else if (H5Tequal(h5_datatype,H5T_STD_U8BE)) {
+ h4_datatype = DFNT_UINT8;
+ } else if (H5Tequal(h5_datatype,H5T_STD_U16BE)) {
+ h4_datatype = DFNT_UINT16;
+ } else if (H5Tequal(h5_datatype,H5T_STD_U32BE)) {
+ h4_datatype = DFNT_UINT32;
+ } else if (H5Tequal(h5_datatype,H5T_STD_U64BE)) {
+ h4_datatype = DFNT_UINT64;
+ } else if (H5Tequal(h5_datatype,H5T_IEEE_F32BE)) {
+ h4_datatype = DFNT_FLOAT32;
+ } else if (H5Tequal(h5_datatype,H5T_IEEE_F64BE)) {
+ h4_datatype = DFNT_FLOAT64;
+ } else if (H5Tequal(h5_datatype,H5T_STD_I8LE)) {
+ h4_datatype = DFNT_INT8;
+ } else if (H5Tequal(h5_datatype,H5T_STD_I16LE)) {
+ h4_datatype = DFNT_INT16;
+ } else if (H5Tequal(h5_datatype,H5T_STD_I32LE)) {
+ h4_datatype = DFNT_INT32;
+/*
+ * This is not supported by HDF4
+ *
+ } else if (H5Tequal(h5_datatype,H5T_STD_I64LE)) {
+ h4_datatype = DFNT_INT64;
+*/
+ } else if (H5Tequal(h5_datatype,H5T_STD_U8LE)) {
+ h4_datatype = DFNT_UINT8;
+ } else if (H5Tequal(h5_datatype,H5T_STD_U16LE)) {
+ h4_datatype = DFNT_UINT16;
+ } else if (H5Tequal(h5_datatype,H5T_STD_U32LE)) {
+ h4_datatype = DFNT_UINT32;
+ } else if (H5Tequal(h5_datatype,H5T_STD_U64LE)) {
+ h4_datatype = DFNT_UINT64;
+ } else if (H5Tequal(h5_datatype,H5T_IEEE_F32LE)) {
+ h4_datatype = DFNT_FLOAT32;
+ } else if (H5Tequal(h5_datatype,H5T_IEEE_F64LE)) {
+ h4_datatype = DFNT_FLOAT64;
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_SCHAR)) {
+ h4_datatype = DFNT_INT8;
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_UCHAR)) {
+ h4_datatype = DFNT_UINT8;
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_SHORT)) {
+ h4_datatype = DFNT_INT16;
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_USHORT)) {
+ h4_datatype = DFNT_UINT16;
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_INT)) {
+ h4_datatype = DFNT_INT32;
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_UINT)) {
+ h4_datatype = DFNT_UINT32;
+/*
+ * This is not supported by HDF4
+ *
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_LONG)) {
+ h4_datatype = DFNT_INT64;
+*/
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_ULONG)) {
+ h4_datatype = DFNT_UINT64;
+/*
+ * This is not supported by HDF4
+ *
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_LLONG)) {
+ h4_datatype = DFNT_INT128;
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_ULLONG)) {
+ h4_datatype = DFNT_UINT128;
+*/
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_FLOAT)) {
+ h4_datatype = DFNT_FLOAT32;
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_DOUBLE)) {
+ h4_datatype = DFNT_FLOAT64;
+/*
+ * This is not supported by HDF4
+ *
+ } else if (H5Tequal(h5_datatype,H5T_NATIVE_LDOUBLE)) {
+ h4_datatype = DFNT_FLOAT128;
+*/
+ } else {
+ h4_datatype = FAIL;
+ }
+
+ return h4_datatype;
+
+}
+
+
+/*****************************************************************************
+
+ Routine: h4type_to_memtype(h4type)
+
+ Description: Translate h4 datatype into mem datatype
+
+ Input: h4 datatype
+
+ Output: function return, mem datatype
+
+*****************************************************************************/
+
+hid_t h4type_to_memtype(int32 h4_datatype)
+{
+ hid_t mem_datatype;
+
+ switch (h4_datatype) {
+ case DFNT_INT8:
+ case DFNT_NINT8:
+ case DFNT_LINT8:
+ mem_datatype = H5T_NATIVE_SCHAR; break;
+ case DFNT_UINT8:
+ case DFNT_NUINT8:
+ case DFNT_LUINT8:
+ mem_datatype = H5T_NATIVE_UCHAR; break;
+ case DFNT_INT16:
+ case DFNT_NINT16:
+ case DFNT_LINT16:
+ mem_datatype = H5T_NATIVE_SHORT; break;
+ case DFNT_UINT16:
+ case DFNT_NUINT16:
+ case DFNT_LUINT16:
+ mem_datatype = H5T_NATIVE_USHORT; break;
+ case DFNT_INT32:
+ case DFNT_NINT32:
+ case DFNT_LINT32:
+ mem_datatype = H5T_NATIVE_INT; break;
+ case DFNT_UINT32:
+ case DFNT_NUINT32:
+ case DFNT_LUINT32:
+ mem_datatype = H5T_NATIVE_UINT; break;
+ case DFNT_INT64:
+ case DFNT_NINT64:
+ case DFNT_LINT64:
+ mem_datatype = H5T_NATIVE_LONG; break;
+ case DFNT_UINT64:
+ case DFNT_NUINT64:
+ case DFNT_LUINT64:
+ mem_datatype = H5T_NATIVE_ULONG; break;
+ case DFNT_INT128:
+ case DFNT_NINT128:
+ case DFNT_LINT128:
+ mem_datatype = H5T_NATIVE_LLONG; break;
+ case DFNT_UINT128:
+ case DFNT_NUINT128:
+ case DFNT_LUINT128:
+ mem_datatype = H5T_NATIVE_ULLONG; break;
+ case DFNT_FLOAT32:
+ case DFNT_NFLOAT32:
+ case DFNT_LFLOAT32:
+ mem_datatype = H5T_NATIVE_FLOAT; break;
+ case DFNT_FLOAT64:
+ case DFNT_NFLOAT64:
+ case DFNT_LFLOAT64:
+ mem_datatype = H5T_NATIVE_DOUBLE; break;
+ case DFNT_FLOAT128:
+ case DFNT_NFLOAT128:
+ case DFNT_LFLOAT128:
+ mem_datatype = H5T_NATIVE_LDOUBLE; break;
+ default:
+ mem_datatype = FAIL;
+ }
+
+ return mem_datatype;
+
+}
+#endif
+
+
+/*****************************************************************************
+
+ Routine: test_file
+
+ Description: Test a file for read/write - ability.
+
+ Input: filename - Unix filename
+
+ Output: function return, global variable - errno
+
+*****************************************************************************/
+
+int test_file(char *filename,int oflag,mode_t mode)
+{
+ int fid;
+
+ errno = 0;
+
+ fid = open(filename, oflag, mode);
+ if (fid < 0) {
+ perror(filename);
+ }
+ close(fid);
+
+ return errno;
+
+}
+
+
+/*****************************************************************************
+
+ Routine: test_dir
+
+ Description: Test pathway to determine if it is a directory
+
+ Input: path - pathname given
+
+ Output: function return TRUE/FALSE
+
+*****************************************************************************/
+
+int test_dir(char *path)
+{
+
+ struct stat buf;
+ struct stat *buf_ptr;
+ int idir;
+
+ buf_ptr = &buf;
+
+ idir = stat(path, buf_ptr);
+ if (idir < 0) {
+ if (errno == 2) {
+ return 0;
+ } else {
+ perror(path);
+ }
+ }
+
+ return S_ISDIR(buf_ptr->st_mode);
+}
+
+/*****************************************************************************
+
+ Routine: BuildFilename()
+
+ Description: Build a filename with new extension
+
+ Input: filename - present filename
+ ext - extension to root of filename
+
+ Output: (filename:r).ext
+
+*****************************************************************************/
+
+char *BuildFilename(char *filename, char *ext)
+{
+ /* build outgoing filename */
+
+ char *filename_out;
+ char *lastper_ptr, *lastdir_ptr;
+ int root_len;
+
+ lastper_ptr = strrchr(filename,'.');
+ lastdir_ptr = strrchr(filename,'/');
+
+ if ( lastper_ptr <= lastdir_ptr ) { /* no extension */
+ root_len = strlen(filename);
+ } else { /* existing extension */
+ root_len = (int)(lastper_ptr - filename);
+ }
+
+ filename_out = (char *)HDmalloc(root_len + strlen(ext) + 2);
+ filename_out = strncpy(filename_out, filename, (size_t)root_len);
+ filename_out[root_len] = '\0';
+ filename_out = strcat(filename_out,".");
+ filename_out = strcat(filename_out,ext);
+
+ return filename_out;
+}
+
diff --git a/tools/lib/Makefile.in b/tools/lib/Makefile.in
new file mode 100644
index 0000000..d620d7f
--- /dev/null
+++ b/tools/lib/Makefile.in
@@ -0,0 +1,57 @@
+## HDF5 Library Makefile(.in)
+##
+## Copyright (C) 2001 National Center for Supercomputing Applications.
+## All rights reserved.
+##
+##
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+SUBDIRS=
+@COMMENCE@
+
+## Add include directory to the C preprocessor flags, add -lh5tools and
+## -lhdf5 to the list of libraries.
+##
+CPPFLAGS=-I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src \
+ -I$(top_srcdir)/tools/lib @CPPFLAGS@
+
+## Test programs and scripts.
+##
+TEST_PROGS=talign
+TEST_SCRIPTS=
+
+## These are our main targets: library and tools. We link this library
+## statically because some systems can only link executables to a single
+## shared library and libhdf5 is much bigger than libh5tools.
+##
+LT_LINK_LIB=$(LT) --mode=link $(CC) -static -rpath $(libdir)
+LIB=libh5tools.la
+LIBHDF5=$(top_builddir)/src/libhdf5.la
+PUB_PROGS=
+PROGS=$(PUB_PROGS) $(TEST_PROGS)
+
+## Source and object files for the library; do not install
+##
+LIB_SRC=h5tools.c h5tools_str.c h5tools_utils.c
+LIB_OBJ=$(LIB_SRC:.c=.lo)
+PUB_LIB=
+
+TEST_SRC=talign.c
+TEST_OBJ=$(TEST_SRC:.c=.lo)
+
+PRIVATE_HDR=h5tools.h h5tools_str.h
+
+## Programs have to be built before they can be tested!
+##
+check test _test: $(PROGS)
+
+## How to build the programs... They all depend on the hdf5 library and
+## the tools library compiled in this directory.
+##
+$(PROGS): $(LIB) $(LIBHDF5)
+
+talign: talign.lo
+ @$(LT_LINK_EXE) $(CFLAGS) -o $@ talign.lo $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS)
+
+@CONCLUDE@
diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h
new file mode 100644
index 0000000..6a6f859
--- /dev/null
+++ b/tools/lib/h5tools.h
@@ -0,0 +1,474 @@
+/*
+ * Copyright (c) 1998-2001 National Center for Supercomputing Applications
+ * All rights reserved.
+ *
+ * Programmer: Robb Matzke <matzke@llnl.gov>
+ * Thursday, July 23, 1998
+ *
+ * Purpose: Support functions for the various tools.
+ */
+#ifndef H5TOOLS_H__
+#define H5TOOLS_H__
+
+#include "hdf5.h"
+
+#if H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 2
+#define VERSION12
+#endif /* H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 2 */
+
+#define ESCAPE_HTML 1
+#define OPT(X,S) ((X) ? (X) : (S))
+#define OPTIONAL_LINE_BREAK "\001" /* Special strings embedded in the output */
+
+/*
+ * Information about how to format output.
+ */
+typedef struct h5dump_t {
+ /*
+ * Fields associated with formatting numeric data. If a datatype matches
+ * multiple formats based on its size, then the first applicable format
+ * from this list is used. However, if `raw' is non-zero then dump all
+ * data in hexadecimal format without translating from what appears on
+ * disk.
+ *
+ * raw: If set then print all data as hexadecimal without
+ * performing any conversion from disk.
+ *
+ * fmt_raw: The printf() format for each byte of raw data. The
+ * default is `%02x'.
+ *
+ * fmt_int: The printf() format to use when rendering data which is
+ * typed `int'. The default is `%d'.
+ *
+ * fmt_uint: The printf() format to use when rendering data which is
+ * typed `unsigned'. The default is `%u'.
+ *
+ * fmt_schar: The printf() format to use when rendering data which is
+ * typed `signed char'. The default is `%d'. This format is
+ * used ony if the `ascii' field is zero.
+ *
+ * fmt_uchar: The printf() format to use when rendering data which is
+ * typed `unsigned char'. The default is `%u'. This format
+ * is used only if the `ascii' field is zero.
+ *
+ * fmt_short: The printf() format to use when rendering data which is
+ * typed `short'. The default is `%d'.
+ *
+ * fmt_ushort: The printf() format to use when rendering data which is
+ * typed `unsigned short'. The default is `%u'.
+ *
+ * fmt_long: The printf() format to use when rendering data which is
+ * typed `long'. The default is `%ld'.
+ *
+ * fmt_ulong: The printf() format to use when rendering data which is
+ * typed `unsigned long'. The default is `%lu'.
+ *
+ * fmt_llong: The printf() format to use when rendering data which is
+ * typed `long long'. The default depends on what printf()
+ * format is available to print this datatype.
+ *
+ * fmt_ullong: The printf() format to use when rendering data which is
+ * typed `unsigned long long'. The default depends on what
+ * printf() format is available to print this datatype.
+ *
+ * fmt_double: The printf() format to use when rendering data which is
+ * typed `double'. The default is `%g'.
+ *
+ * fmt_float: The printf() format to use when rendering data which is
+ * typed `float'. The default is `%g'.
+ *
+ * ascii: If set then print 1-byte integer values as an ASCII
+ * character (no quotes). If the character is one of the
+ * standard C escapes then print the escaped version. If
+ * the character is unprintable then print a 3-digit octal
+ * escape. If `ascii' is zero then then 1-byte integers are
+ * printed as numeric values. The default is zero.
+ *
+ * str_locale: Determines how strings are printed. If zero then strings
+ * are printed like in C except. If set to ESCAPE_HTML then
+ * strings are printed using HTML encoding where each
+ * character not in the class [a-zA-Z0-9] is substituted
+ * with `%XX' where `X' is a hexadecimal digit.
+ *
+ * str_repeat: If set to non-zero then any character value repeated N
+ * or more times is printed as 'C'*N
+ *
+ * Numeric data is also subject to the formats for individual elements.
+ */
+ hbool_t raw;
+ const char *fmt_raw;
+ const char *fmt_int;
+ const char *fmt_uint;
+ const char *fmt_schar;
+ const char *fmt_uchar;
+ const char *fmt_short;
+ const char *fmt_ushort;
+ const char *fmt_long;
+ const char *fmt_ulong;
+ const char *fmt_llong;
+ const char *fmt_ullong;
+ const char *fmt_double;
+ const char *fmt_float;
+ int ascii;
+ int str_locale;
+ int str_repeat;
+
+ /*
+ * Fields associated with compound array members.
+ *
+ * pre: A string to print at the beginning of each array. The
+ * default value is the left square bracket `['.
+ *
+ * sep: A string to print between array values. The default
+ * value is a ",\001" ("\001" indicates an optional line
+ * break).
+ *
+ * suf: A string to print at the end of each array. The default
+ * value is a right square bracket `]'.
+ *
+ * linebreaks: a boolean value to determine if we want to break the line
+ * after each row of an array.
+ */
+ const char *arr_pre;
+ const char *arr_sep;
+ const char *arr_suf;
+ int arr_linebreak;
+
+ /*
+ * Fields associated with compound data types.
+ *
+ * name: How the name of the struct member is printed in the
+ * values. By default the name is not printed, but a
+ * reasonable setting might be "%s=" which prints the name
+ * followed by an equal sign and then the value.
+ *
+ * sep: A string that separates one member from another. The
+ * default is ", \001" (the \001 indicates an optional
+ * line break to allow structs to span multiple lines of
+ * output).
+ *
+ * pre: A string to print at the beginning of a compound type.
+ * The default is a left curly brace.
+ *
+ * suf: A string to print at the end of each compound type. The
+ * default is right curly brace.
+ *
+ * end: a string to print after we reach the last element of
+ * each compound type. prints out before the suf.
+ */
+ const char *cmpd_name;
+ const char *cmpd_sep;
+ const char *cmpd_pre;
+ const char *cmpd_suf;
+ const char *cmpd_end;
+
+ /*
+ * Fields associated with vlen data types.
+ *
+ * sep: A string that separates one member from another. The
+ * default is ", \001" (the \001 indicates an optional
+ * line break to allow structs to span multiple lines of
+ * output).
+ *
+ * pre: A string to print at the beginning of a vlen type.
+ * The default is a left parentheses.
+ *
+ * suf: A string to print at the end of each vlen type. The
+ * default is a right parentheses.
+ *
+ * end: a string to print after we reach the last element of
+ * each compound type. prints out before the suf.
+ */
+ const char *vlen_sep;
+ const char *vlen_pre;
+ const char *vlen_suf;
+ const char *vlen_end;
+
+ /*
+ * Fields associated with the individual elements.
+ *
+ * fmt: A printf(3c) format to use to print the value string
+ * after it has been rendered. The default is "%s".
+ *
+ * suf1: This string is appended to elements which are followed by
+ * another element whether the following element is on the
+ * same line or the next line. The default is a comma.
+ *
+ * suf2: This string is appended (after `suf1') to elements which
+ * are followed on the same line by another element. The
+ * default is a single space.
+ */
+ const char *elmt_fmt;
+ const char *elmt_suf1;
+ const char *elmt_suf2;
+
+ /*
+ * Fields associated with the index values printed at the left edge of
+ * each line of output.
+ *
+ * n_fmt: Each index value is printed according to this printf(3c)
+ * format string which should include a format for a long
+ * integer. The default is "%lu".
+ *
+ * sep: Each integer in the index list will be separated from the
+ * others by this string, which defaults to a comma.
+ *
+ * fmt: After the index values are formated individually and
+ * separated from one another by some string, the entire
+ * resulting string will be formated according to this
+ * printf(3c) format which should include a format for a
+ * character string. The default is "%s".
+ */
+ const char *idx_n_fmt; /*index number format */
+ const char *idx_sep; /*separator between numbers */
+ const char *idx_fmt; /*entire index format */
+
+ /*
+ * Fields associated with entire lines.
+ *
+ * ncols: Number of columns per line defaults to 80.
+ *
+ * per_line: If this field has a positive value then every Nth element
+ * will be printed at the beginning of a line.
+ *
+ * pre: Each line of output contains an optional prefix area
+ * before the data. This area can contain the index for the
+ * first datum (represented by `%s') as well as other
+ * constant text. The default value is `%s'.
+ *
+ * 1st: This is the format to print at the beginning of the first
+ * line of output. The default value is the current value of
+ * `pre' described above.
+ *
+ * cont: This is the format to print at the beginning of each line
+ * which was continued because the line was split onto
+ * multiple lines. This often happens with compound
+ * data which is longer than one line of output. The default
+ * value is the current value of the `pre' field
+ * described above.
+ *
+ * suf: This character string will be appended to each line of
+ * output. It should not contain line feeds. The default
+ * is the empty string.
+ *
+ * sep: A character string to be printed after every line feed
+ * defaulting to the empty string. It should end with a
+ * line feed.
+ *
+ * multi_new: Indicates the algorithm to use when data elements tend to
+ * occupy more than one line of output. The possible values
+ * are (zero is the default):
+ *
+ * 0: No consideration. Each new element is printed
+ * beginning where the previous element ended.
+ *
+ * 1: Print the current element beginning where the
+ * previous element left off. But if that would result
+ * in the element occupying more than one line and it
+ * would only occupy one line if it started at the
+ * beginning of a line, then it is printed at the
+ * beginning of the next line.
+ *
+ * multi_new: If an element is continued onto additional lines then
+ * should the following element begin on the next line? The
+ * default is to start the next element on the same line
+ * unless it wouldn't fit.
+ *
+ * indentlevel: a string that shows how far to indent if extra spacing
+ * is needed. dumper uses it.
+ */
+ int line_ncols; /*columns of output */
+ size_t line_per_line; /*max elements per line */
+ const char *line_pre; /*prefix at front of each line */
+ const char *line_1st; /*alternate pre. on first line */
+ const char *line_cont; /*alternate pre. on continuation*/
+ const char *line_suf; /*string to append to each line */
+ const char *line_sep; /*separates lines */
+ int line_multi_new; /*split multi-line outputs? */
+ const char *line_indent; /*for extra identation if we need it*/
+
+ /*used to skip the first set of checks for line length*/
+ int skip_first;
+
+ /*flag used to hide or show the file number for obj refs*/
+ int obj_hidefileno;
+
+ /*string used to format the output for the obje refs*/
+ const char *obj_format;
+
+ /*flag used to hide or show the file number for dataset regions*/
+ int dset_hidefileno;
+
+ /*string used to format the output for the dataset regions*/
+ const char *dset_format;
+
+ const char *dset_blockformat_pre;
+ const char *dset_ptformat_pre;
+ const char *dset_ptformat;
+
+} h5dump_t;
+
+typedef struct dump_header{
+ const char *name;
+ const char *filebegin;
+ const char *fileend;
+ const char *bootblockbegin;
+ const char *bootblockend;
+ const char *groupbegin;
+ const char *groupend;
+ const char *datasetbegin;
+ const char *datasetend;
+ const char *attributebegin;
+ const char *attributeend;
+ const char *datatypebegin;
+ const char *datatypeend;
+ const char *dataspacebegin;
+ const char *dataspaceend;
+ const char *databegin;
+ const char *dataend;
+ const char *softlinkbegin;
+ const char *softlinkend;
+ const char *subsettingbegin;
+ const char *subsettingend;
+ const char *startbegin;
+ const char *startend;
+ const char *stridebegin;
+ const char *strideend;
+ const char *countbegin;
+ const char *countend;
+ const char *blockbegin;
+ const char *blockend;
+
+ const char *fileblockbegin;
+ const char *fileblockend;
+ const char *bootblockblockbegin;
+ const char *bootblockblockend;
+ const char *groupblockbegin;
+ const char *groupblockend;
+ const char *datasetblockbegin;
+ const char *datasetblockend;
+ const char *attributeblockbegin;
+ const char *attributeblockend;
+ const char *datatypeblockbegin;
+ const char *datatypeblockend;
+ const char *dataspaceblockbegin;
+ const char *dataspaceblockend;
+ const char *datablockbegin;
+ const char *datablockend;
+ const char *softlinkblockbegin;
+ const char *softlinkblockend;
+ const char *strblockbegin;
+ const char *strblockend;
+ const char *enumblockbegin;
+ const char *enumblockend;
+ const char *structblockbegin;
+ const char *structblockend;
+ const char *vlenblockbegin;
+ const char *vlenblockend;
+ const char *subsettingblockbegin;
+ const char *subsettingblockend;
+ const char *startblockbegin;
+ const char *startblockend;
+ const char *strideblockbegin;
+ const char *strideblockend;
+ const char *countblockbegin;
+ const char *countblockend;
+ const char *blockblockbegin;
+ const char *blockblockend;
+
+ const char *dataspacedescriptionbegin;
+ const char *dataspacedescriptionend;
+ const char *dataspacedimbegin;
+ const char *dataspacedimend;
+
+} dump_header;
+
+typedef struct h5tools_context_t {
+ size_t cur_column; /*current column for output */
+ size_t cur_elmt; /*current element/output line */
+ int need_prefix; /*is line prefix needed? */
+ int ndims; /*dimensionality */
+ hsize_t p_min_idx[H5S_MAX_RANK]; /*min selected index */
+ hsize_t p_max_idx[H5S_MAX_RANK]; /*max selected index */
+ int prev_multiline; /*was prev datum multiline? */
+ size_t prev_prefix_len;/*length of previous prefix */
+ int continuation; /*continuation of previous data?*/
+ int size_last_dim; /*the size of the last dimension,
+ *needed so we can break after each
+ *row */
+ int indent_level; /*the number of times we need some
+ *extra indentation */
+ int default_indent_level; /*this is used when the indent
+ *level gets changed */
+} h5tools_context_t;
+
+/* a structure to hold the subsetting particulars for a dataset */
+struct subset_t {
+ hsize_t *start;
+ hsize_t *stride;
+ hsize_t *count;
+ hsize_t *block;
+};
+
+/*if we get a new program that needs to use the library add its name here*/
+typedef enum {
+ UNKNOWN = 0,
+ H5LS,
+ H5DUMP
+} ProgType;
+
+/* taken from h5dump.h */
+#define ATTRIBUTE_DATA 0
+#define DATASET_DATA 1
+#define ENUM_DATA 2
+
+#define COL 3
+
+extern int indent; /*how far in to indent the line */
+extern FILE *rawdatastream; /*output stream for raw data */
+
+/* taken from h5dump.h*/
+#define ATTRIBUTE "ATTRIBUTE"
+#define BLOCK "BLOCK"
+#define BOOT_BLOCK "BOOT_BLOCK"
+#define COMPRESSION "COMPRESSION"
+#define CONCATENATOR "//"
+#define COMPLEX "COMPLEX"
+#define COUNT "COUNT"
+#define CSET "CSET"
+#define CTYPE "CTYPE"
+#define DATA "DATA"
+#define DATASET "DATASET"
+#define DATASPACE "DATASPACE"
+#define DATATYPE "DATATYPE"
+#define EXTERNAL "EXTERNAL"
+#define FILENO "FILENO"
+#define GROUPNAME "GROUP"
+#define HARDLINK "HARDLINK"
+#define NLINK "NLINK"
+#define OBJID "OBJECTID"
+#define OBJNO "OBJNO"
+#define SCALAR "SCALAR"
+#define SIMPLE "SIMPLE"
+#define SOFTLINK "SOFTLINK"
+#define STORAGELAYOUT "STORAGELAYOUT"
+#define START "START"
+#define STRIDE "STRIDE"
+#define STRSIZE "STRSIZE"
+#define STRPAD "STRPAD"
+#define SUBSET "SUBSET"
+
+#define BEGIN "{"
+#define END "}"
+
+/* Definitions of useful routines */
+extern void h5tools_init(void);
+extern void h5tools_close(void);
+extern hid_t h5tools_fopen(const char *fname, char *drivername, size_t drivername_len);
+extern hid_t h5tools_fixtype(hid_t f_type);
+extern int h5tools_dump_dset(FILE *stream, const h5dump_t *info, hid_t dset,
+ hid_t p_typ, struct subset_t *sset, int indentlevel);
+extern int h5tools_dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id,
+ hid_t type, hid_t space, void *mem, int indentlevel);
+
+#endif /* H5TOOLS_H__ */
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c
new file mode 100644
index 0000000..e594ebd
--- /dev/null
+++ b/tools/lib/h5tools_str.c
@@ -0,0 +1,999 @@
+/*
+ * Copyright (c) 2001 National Center for Supercomputing Applications
+ * All rights reserved.
+ *
+ * Programmer: Bill Wendling <wendling@ncsa.uiuc.edu>
+ * Monday, 19. February 2001
+ *
+ * Purpose: These are string functions for us to use and abuse.
+ */
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "H5private.h"
+#include "h5tools.h" /*for h5dump_t structure */
+#include "h5tools_str.h" /*function prototypes */
+
+/*
+ * If REPEAT_VERBOSE is defined then character strings will be printed so
+ * that repeated character sequences like "AAAAAAAAAA" are displayed as
+ *
+ * 'A' repeates 9 times
+ *
+ * Otherwise the format is more Perl-like
+ *
+ * 'A'*10
+ *
+ */
+#define REPEAT_VERBOSE
+
+/* Variable length string datatype */
+#define STR_INIT_LEN 4096 /*initial length */
+
+static char *h5tools_escape(char *s, size_t size, int escape_spaces);
+static hbool_t h5tools_is_zero(const void *_mem, size_t size);
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_close
+ *
+ * Purpose: Closes a string by releasing it's memory and setting the size
+ * information to zero.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Monday, April 26, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+h5tools_str_close(h5tools_str_t *str)
+{
+ if (str && str->nalloc) {
+ free(str->s);
+ memset(str, 0, sizeof(h5tools_str_t));
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_len
+ *
+ * Purpose: Returns the length of the string, not counting the null
+ * terminator.
+ *
+ * Return: Success: Length of string
+ *
+ * Failure: 0
+ *
+ * Programmer: Robb Matzke
+ * Monday, April 26, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+size_t
+h5tools_str_len(h5tools_str_t *str)
+{
+ return str->len;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_append
+ *
+ * Purpose: Formats variable arguments according to printf() format
+ * string and appends the result to variable length string STR.
+ *
+ * Return: Success: Pointer to buffer containing result.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Monday, April 26, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+char *
+h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+
+ /* Make sure we have some memory into which to print */
+ if (!str->s || str->nalloc <= 0) {
+ str->nalloc = STR_INIT_LEN;
+ str->s = malloc(str->nalloc);
+ assert(str->s);
+ str->s[0] = '\0';
+ str->len = 0;
+ }
+
+ while (1) {
+ size_t avail = str->nalloc - str->len;
+ size_t nchars = (size_t)HDvsnprintf(str->s + str->len, avail, fmt, ap);
+
+ if (nchars < avail) {
+ /* success */
+ str->len += nchars;
+ break;
+ }
+
+ /* Try again with twice as much space */
+ str->nalloc *= 2;
+ str->s = realloc(str->s, str->nalloc);
+ assert(str->s);
+ }
+
+ va_end(ap);
+ return str->s;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_reset
+ *
+ * Purpose: Reset the string to the empty value. If no memory is
+ * allocated yet then initialize the h5tools_str_t struct.
+ *
+ * Return: Success: Ptr to the buffer which contains a null
+ * character as the first element.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Monday, April 26, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+char *
+h5tools_str_reset(h5tools_str_t *str/*in,out*/)
+{
+ if (!str->s || str->nalloc <= 0) {
+ str->nalloc = STR_INIT_LEN;
+ str->s = malloc(str->nalloc);
+ assert(str->s);
+ }
+
+ str->s[0] = '\0';
+ str->len = 0;
+ return str->s;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_trunc
+ *
+ * Purpose: Truncate a string to be at most SIZE characters.
+ *
+ * Return: Success: Pointer to the string
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Monday, April 26, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+char *
+h5tools_str_trunc(h5tools_str_t *str/*in,out*/, size_t size)
+{
+ if (size < str->len) {
+ str->len = size;
+ str->s[size] = '\0';
+ }
+
+ return str->s;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_fmt
+ *
+ * Purpose: Reformat a string contents beginning at character START
+ * according to printf format FMT. FMT should contain no format
+ * specifiers except possibly the `%s' variety. For example, if
+ * the input string is `hello' and the format is "<<%s>>" then
+ * the output value will be "<<hello>>".
+ *
+ * Return: Success: A pointer to the resulting string.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Monday, April 26, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+char *
+h5tools_str_fmt(h5tools_str_t *str/*in,out*/, size_t start, const char *fmt)
+{
+ char _temp[1024], *temp = _temp;
+
+ /* If the format string is simply "%s" then don't bother doing anything */
+ if (!strcmp(fmt, "%s"))
+ return str->s;
+
+ /*
+ * Save the input value if there is a `%' anywhere in FMT. Otherwise
+ * don't bother because we don't need a temporary copy.
+ */
+ if (strchr(fmt, '%')) {
+ if (str->len - start + 1 > sizeof(_temp)) {
+ temp = malloc(str->len-start + 1);
+ assert(temp);
+ }
+
+ strcpy(temp, str->s + start);
+ }
+
+ /* Reset the output string and append a formatted version */
+ h5tools_str_trunc(str, start);
+ h5tools_str_append(str, fmt, temp);
+
+ /* Free the temp buffer if we allocated one */
+ if (temp != _temp)
+ free(temp);
+
+ return str->s;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_prefix
+ *
+ * Purpose: Renders the line prefix value into string STR.
+ *
+ * Return: Success: Pointer to the prefix.
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Thursday, July 23, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+char *
+h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5dump_t *info,
+ hsize_t elmtno, int ndims, hsize_t min_idx[],
+ hsize_t max_idx[])
+{
+ hsize_t p_prod[H5S_MAX_RANK], p_idx[H5S_MAX_RANK];
+ hsize_t n, i = 0;
+
+ h5tools_str_reset(str);
+
+ if (ndims > 0) {
+ /*
+ * Calculate the number of elements represented by a unit change in a
+ * certain index position.
+ */
+ for (i = ndims - 1, p_prod[ndims - 1] = 1; i > 0; --i)
+ p_prod[i - 1] = (max_idx[i] - min_idx[i]) * p_prod[i];
+
+ /* Calculate the index values from the element number. */
+ for (i = 0, n = elmtno; i < (hsize_t)ndims; i++) {
+ p_idx[i] = n / p_prod[i] + min_idx[i];
+ n %= p_prod[i];
+ }
+
+ /* Print the index values */
+ for (i = 0; i < (hsize_t)ndims; i++) {
+ if (i)
+ h5tools_str_append(str, "%s", OPT(info->idx_sep, ","));
+
+ h5tools_str_append(str, OPT(info->idx_n_fmt, "%lu"),
+ (unsigned long)p_idx[i]);
+ }
+ } else {
+ /* Scalar */
+ h5tools_str_append(str, OPT(info->idx_n_fmt, "%lu"), (unsigned long)0);
+ }
+
+ /* Add prefix and suffix to the index */
+ return h5tools_str_fmt(str, 0, OPT(info->idx_fmt, "%s: "));
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_dump_region
+ *
+ * Purpose: Prints information about a dataspace region by appending
+ * the information to the specified string.
+ *
+ * Return: Success: 0
+ *
+ * Failure: NULL
+ *
+ * Programmer: Robb Matzke
+ * Monday, June 7, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5tools_str_dump_region(h5tools_str_t *str, hid_t region, const h5dump_t *info)
+{
+ hssize_t nblocks, npoints;
+ hsize_t alloc_size;
+ hsize_t *ptdata;
+ int ndims = H5Sget_simple_extent_ndims(region);
+
+ /*
+ * These two functions fail if the region does not have blocks or points,
+ * respectively. They do not currently know how to translate from one to
+ * the other.
+ */
+ H5E_BEGIN_TRY {
+ nblocks = H5Sget_select_hyper_nblocks(region);
+ npoints = H5Sget_select_elem_npoints(region);
+ } H5E_END_TRY;
+
+ h5tools_str_append(str, "{");
+
+ /* Print block information */
+ if (nblocks > 0) {
+ int i;
+
+ alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]);
+ assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
+ ptdata = malloc((size_t)alloc_size);
+ H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t);
+ H5Sget_select_hyper_blocklist(region, (hsize_t)0, (hsize_t)nblocks, ptdata);
+
+ for (i = 0; i < nblocks; i++) {
+ int j;
+
+ h5tools_str_append(str, info->dset_blockformat_pre,
+ i ? "," OPTIONAL_LINE_BREAK " " : "",
+ (unsigned long)i);
+
+ /* Start coordinates and opposite corner */
+ for (j = 0; j < ndims; j++)
+ h5tools_str_append(str, "%s%lu", j ? "," : "(",
+ (unsigned long)ptdata[i * 2 * ndims + j]);
+
+ for (j = 0; j < ndims; j++)
+ h5tools_str_append(str, "%s%lu", j ? "," : ")-(",
+ (unsigned long)ptdata[i * 2 * ndims + j + ndims]);
+
+ h5tools_str_append(str, ")");
+ }
+
+ free(ptdata);
+ }
+
+ /* Print point information */
+ if (npoints > 0) {
+ int i;
+
+ alloc_size = npoints * ndims * sizeof(ptdata[0]);
+ assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
+ ptdata = malloc((size_t)alloc_size);
+ H5_CHECK_OVERFLOW(npoints,hssize_t,hsize_t);
+ H5Sget_select_elem_pointlist(region, (hsize_t)0, (hsize_t)npoints, ptdata);
+
+ for (i = 0; i < npoints; i++) {
+ int j;
+
+ h5tools_str_append(str, info->dset_ptformat_pre ,
+ i ? "," OPTIONAL_LINE_BREAK " " : "",
+ (unsigned long)i);
+
+ for (j = 0; j < ndims; j++)
+ h5tools_str_append(str, "%s%lu", j ? "," : "(",
+ (unsigned long)(ptdata[i * ndims + j]));
+
+ h5tools_str_append(str, ")");
+ }
+
+ free(ptdata);
+ }
+
+ h5tools_str_append(str, "}");
+ return 0;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_print_char
+ *
+ * Purpose: Shove a character into the STR.
+ *
+ * Return: Nothing
+ *
+ * Programmer: Bill Wendling
+ * Tuesday, 20. February 2001
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+h5tools_print_char(h5tools_str_t *str, const h5dump_t *info, unsigned char ch)
+{
+ if (info->str_locale == ESCAPE_HTML) {
+ if (ch <= ' ' || ch > '~')
+ h5tools_str_append(str, "%%%02x", ch);
+ else
+ h5tools_str_append(str, "%c", (char)ch);
+ } else {
+ switch (ch) {
+ case '"':
+ h5tools_str_append(str, "\\\"");
+ break;
+ case '\\':
+ h5tools_str_append(str, "\\\\");
+ break;
+ case '\b':
+ h5tools_str_append(str, "\\b");
+ break;
+ case '\f':
+ h5tools_str_append(str, "\\f");
+ break;
+ case '\n':
+ h5tools_str_append(str, "\\n");
+ break;
+ case '\r':
+ h5tools_str_append(str, "\\r");
+ break;
+ case '\t':
+ h5tools_str_append(str, "\\t");
+ break;
+ default:
+ if (isprint(ch))
+ h5tools_str_append(str, "%c", (char)ch);
+ else
+ h5tools_str_append(str, "\\%03o", ch);
+
+ break;
+ }
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_str_sprint
+ *
+ * Purpose: Renders the value pointed to by VP of type TYPE into variable
+ * length string STR.
+ *
+ * Return: A pointer to memory containing the result or NULL on error.
+ *
+ * Programmer: Robb Matzke
+ * Thursday, July 23, 1998
+ *
+ * Modifications:
+ * Robb Matzke, 1999-04-26
+ * 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.
+ *
+ * Robb Matzke, 1999-06-07
+ * Added support for printing raw data. If info->raw is non-zero
+ * then data is printed in hexadecimal format.
+ *
+ *-------------------------------------------------------------------------
+ */
+char *
+h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container,
+ hid_t type, void *vp, h5tools_context_t *ctx)
+{
+ size_t n, offset, size, nelmts, start;
+ char *name, quote = '\0';
+ unsigned char *ucp_vp = (unsigned char *)vp;
+ char *cp_vp = (char *)vp;
+ hid_t memb, obj, region;
+ int nmembs, otype;
+ static char fmt_llong[8], fmt_ullong[8];
+ H5T_str_t pad;
+ H5G_stat_t sb;
+
+ /*
+ * some tempvars to store the value before we append it to the string to
+ * get rid of the memory alignment problem
+ */
+ double tempdouble;
+ float tempfloat;
+ unsigned long_long tempullong;
+ long_long templlong;
+ unsigned long tempulong;
+ long templong;
+ unsigned int tempuint;
+ int tempint;
+ unsigned short tempushort;
+ short tempshort;
+
+ /* Build default formats for long long types */
+ if (!fmt_llong[0]) {
+ sprintf(fmt_llong, "%%%sd", PRINTF_LL_WIDTH);
+ sprintf(fmt_ullong, "%%%su", PRINTF_LL_WIDTH);
+ }
+
+ /* Append value depending on data type */
+ start = h5tools_str_len(str);
+
+ if (info->raw) {
+ size_t i;
+
+ h5tools_str_append(str, "0x");
+ n = H5Tget_size(type);
+
+ for (i = 0; i < n; i++)
+ h5tools_str_append(str, OPT(info->fmt_raw, "%02x"), ucp_vp[i]);
+ } else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
+ memcpy(&tempfloat, vp, sizeof(float));
+ h5tools_str_append(str, OPT(info->fmt_float, "%g"), tempfloat);
+ } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
+ memcpy(&tempdouble, vp, sizeof(double));
+ h5tools_str_append(str, OPT(info->fmt_double, "%g"), tempdouble);
+ } else if (info->ascii && (H5Tequal(type, H5T_NATIVE_SCHAR) ||
+ H5Tequal(type, H5T_NATIVE_UCHAR))) {
+ h5tools_print_char(str, info, *ucp_vp);
+ } else if (H5T_STRING == H5Tget_class(type)) {
+ unsigned int i;
+
+ quote = '\0';
+ size = H5Tget_size(type);
+ pad = H5Tget_strpad(type);
+
+ for (i = 0; i < size && (cp_vp[i] != '\0' || pad != H5T_STR_NULLTERM); i++) {
+ int j = 1;
+
+ /*
+ * Count how many times the next character repeats. If the
+ * threshold is zero then that means it can repeat any number
+ * of times.
+ */
+ if (info->str_repeat > 0)
+ while (i + j < size && cp_vp[i] == cp_vp[i + j])
+ j++;
+
+ /*
+ * Print the opening quote. If the repeat count is high enough to
+ * warrant printing the number of repeats instead of enumerating
+ * the characters, then make sure the character to be repeated is
+ * in it's own quote.
+ */
+ if (info->str_repeat > 0 && j > info->str_repeat) {
+ if (quote)
+ h5tools_str_append(str, "%c", quote);
+
+ quote = '\'';
+ h5tools_str_append(str, "%s%c", i ? " " : "", quote);
+ } else if (!quote) {
+ quote = '"';
+ h5tools_str_append(str, "%s%c", i ? " " : "", quote);
+ }
+
+ /* Print the character */
+ h5tools_print_char(str, info, ucp_vp[i]);
+
+ /* Print the repeat count */
+ if (info->str_repeat && j > info->str_repeat) {
+#ifdef REPEAT_VERBOSE
+ h5tools_str_append(str, "%c repeats %d times", quote, j - 1);
+#else
+ h5tools_str_append(str, "%c*%d", quote, j - 1);
+#endif /* REPEAT_VERBOSE */
+ quote = '\0';
+ i += j - 1;
+ }
+
+ }
+
+ if (quote)
+ h5tools_str_append(str, "%c", quote);
+
+ if (i == 0)
+ /*empty string*/
+ h5tools_str_append(str, "\"\"");
+ } else if (H5Tequal(type, H5T_NATIVE_INT)) {
+ memcpy(&tempint, vp, sizeof(int));
+ h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint);
+ } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
+ memcpy(&tempuint, vp, sizeof(unsigned int));
+ h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint);
+ } else if (H5Tequal(type, H5T_NATIVE_SCHAR)) {
+ h5tools_str_append(str, OPT(info->fmt_schar, "%d"), *cp_vp);
+ } else if (H5Tequal(type, H5T_NATIVE_UCHAR)) {
+ h5tools_str_append(str, OPT(info->fmt_uchar, "%u"), *ucp_vp);
+ } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
+ memcpy(&tempshort, vp, sizeof(short));
+ h5tools_str_append(str, OPT(info->fmt_short, "%d"), tempshort);
+ } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
+ memcpy(&tempushort, vp, sizeof(unsigned short));
+ h5tools_str_append(str, OPT(info->fmt_ushort, "%u"), tempushort);
+ } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
+ memcpy(&templong, vp, sizeof(long));
+ h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong);
+ } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
+ memcpy(&tempulong, vp, sizeof(unsigned long));
+ h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong);
+ } else if (H5Tequal(type, H5T_NATIVE_LLONG)) {
+ memcpy(&templlong, vp, sizeof(long_long));
+ h5tools_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong);
+ } else if (H5Tequal(type, H5T_NATIVE_ULLONG)) {
+ memcpy(&tempullong, vp, sizeof(unsigned long_long));
+ h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong);
+ } else if (H5Tequal(type, H5T_NATIVE_HSSIZE)) {
+ if (sizeof(hssize_t) == sizeof(int)) {
+ memcpy(&tempint, vp, sizeof(int));
+ h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint);
+ } else if (sizeof(hssize_t) == sizeof(long)) {
+ memcpy(&templong, vp, sizeof(long));
+ h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong);
+ } else {
+ memcpy(&templlong, vp, sizeof(long_long));
+ h5tools_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong);
+ }
+ } else if (H5Tequal(type, H5T_NATIVE_HSIZE)) {
+ if (sizeof(hsize_t) == sizeof(int)) {
+ memcpy(&tempuint, vp, sizeof(unsigned int));
+ h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint);
+ } else if (sizeof(hsize_t) == sizeof(long)) {
+ memcpy(&tempulong, vp, sizeof(long));
+ h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong);
+ } else {
+ memcpy(&tempullong, vp, sizeof(unsigned long_long));
+ h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong);
+ }
+ } else if (H5Tget_class(type) == H5T_COMPOUND) {
+ int j;
+
+ nmembs = H5Tget_nmembers(type);
+ h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{"));
+
+ for (j = 0; j < nmembs; j++) {
+ if (j)
+ h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", " OPTIONAL_LINE_BREAK));
+
+ /* RPM 2000-10-31
+ * If the previous character is a line-feed (which is true when
+ * h5dump is running) then insert some white space for
+ * indentation. Be warned that column number calculations will be
+ * incorrect and that object indices at the beginning of the line
+ * will be missing (h5dump doesn't display them anyway). */
+ if (ctx->indent_level >= 0 && str->len && str->s[str->len - 1] == '\n') {
+ int x;
+
+ h5tools_str_append(str, OPT(info->line_pre, ""), "");
+
+ for (x = 0; x < ctx->indent_level + 1; x++)
+ h5tools_str_append(str, "%s", OPT(info->line_indent, ""));
+ }
+
+ /* The name */
+ name = H5Tget_member_name(type, j);
+ h5tools_str_append(str, OPT(info->cmpd_name, ""), name);
+ free(name);
+
+ /* The value */
+ offset = H5Tget_member_offset(type, j);
+ memb = H5Tget_member_type(type, j);
+
+ ctx->indent_level++;
+ h5tools_str_sprint(str, info, container, memb, cp_vp + offset , ctx);
+ ctx->indent_level--;
+
+ H5Tclose(memb);
+ }
+
+ /* RPM 2000-10-31
+ * If the previous character is a line feed (which is true when
+ * h5dump is running) then insert some white space for indentation.
+ * Be warned that column number calculations will be incorrect and
+ * that object indices at the beginning of the line will be missing
+ * (h5dump doesn't display them anyway). */
+ h5tools_str_append(str, "%s", OPT(info->cmpd_end, ""));
+
+ if (ctx->indent_level >= 0 && str->len && str->s[str->len - 1] == '\n') {
+ int x;
+
+ h5tools_str_append(str, OPT(info->line_pre, ""), "");
+
+ for (x = 0; x < ctx->indent_level; x++)
+ h5tools_str_append(str, "%s", OPT(info->line_indent, ""));
+ }
+
+ h5tools_str_append(str, "%s", OPT(info->cmpd_suf, "}"));
+ } else if (H5Tget_class(type) == H5T_ENUM) {
+ char enum_name[1024];
+
+ if (H5Tenum_nameof(type, vp, enum_name, sizeof enum_name) >= 0) {
+ h5tools_str_append(str, h5tools_escape(enum_name, sizeof(enum_name), TRUE));
+ } else {
+ size_t i;
+
+ h5tools_str_append(str, "0x");
+ n = H5Tget_size(type);
+
+ for (i = 0; i < n; i++)
+ h5tools_str_append(str, "%02x", ucp_vp[i]);
+ }
+ } 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
+ */
+ if (h5tools_is_zero(vp, H5Tget_size(type))) {
+ h5tools_str_append(str, "NULL");
+ } else {
+ obj = H5Rdereference(container, H5R_DATASET_REGION, vp);
+ region = H5Rget_region(container, H5R_DATASET_REGION, vp);
+ H5Gget_objinfo(obj, ".", FALSE, &sb);
+
+ if (info->dset_hidefileno)
+ h5tools_str_append(str, info->dset_format, sb.objno[1], sb.objno[0]);
+ else
+ h5tools_str_append(str, info->dset_format,
+ sb.fileno[1], sb.fileno[0], sb.objno[1], sb.objno[0]);
+
+ h5tools_str_dump_region(str, region, info);
+ H5Sclose(region);
+ H5Dclose(obj);
+ }
+ } else if (H5Tequal(type, H5T_STD_REF_OBJ)) {
+ /*
+ * Object references -- show the type and OID of the referenced
+ * object.
+ */
+ if (h5tools_is_zero(vp, H5Tget_size(type))) {
+ h5tools_str_append(str, "NULL");
+ } else {
+ otype = H5Rget_object_type(container, vp);
+ obj = H5Rdereference(container, H5R_OBJECT, vp);
+ H5Gget_objinfo(obj, ".", FALSE, &sb);
+
+ /* Print object type and close object */
+ switch (otype) {
+ case H5G_GROUP:
+ h5tools_str_append(str, GROUPNAME);
+ H5Gclose(obj);
+ break;
+ case H5G_DATASET:
+ h5tools_str_append(str, DATASET);
+ H5Dclose(obj);
+ break;
+ case H5G_TYPE:
+ h5tools_str_append(str, DATATYPE);
+ H5Tclose(obj);
+ break;
+ default:
+ h5tools_str_append(str, "%u-", otype);
+ break;
+ }
+
+ /* Print OID */
+ if (info->obj_hidefileno) {
+ h5tools_str_append(str, info->obj_format, sb.objno[1], sb.objno[0]);
+ } else {
+ h5tools_str_append(str, info->obj_format,
+ sb.fileno[1], sb.fileno[0], sb.objno[1], sb.objno[0]);
+ }
+ }
+ } else if (H5Tget_class(type) == H5T_ARRAY) {
+ int k, ndims;
+ hsize_t i, dims[H5S_MAX_RANK];
+
+ /* Get the array's base datatype for each element */
+ memb = H5Tget_super(type);
+ size = H5Tget_size(memb);
+ ndims = H5Tget_array_ndims(type);
+ H5Tget_array_dims(type, dims, NULL);
+ assert(ndims >= 1 && ndims <= H5S_MAX_RANK);
+
+ /* Calculate the number of array elements */
+ for (k = 0, nelmts = 1; k < ndims; k++)
+ nelmts *= dims[k];
+
+ /* Print the opening bracket */
+ h5tools_str_append(str, "%s", OPT(info->arr_pre, "["));
+
+ for (i = 0; i < nelmts; i++) {
+ if (i)
+ h5tools_str_append(str, "%s",
+ OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK));
+
+ if (info->arr_linebreak && i && i % dims[ndims - 1] == 0) {
+ int x;
+
+ h5tools_str_append(str, "%s", "\n");
+
+ /*need to indent some more here*/
+ if (ctx->indent_level >= 0)
+ h5tools_str_append(str, "%s", OPT(info->line_pre, ""));
+
+ for (x = 0; x < ctx->indent_level + 1; x++)
+ h5tools_str_append(str,"%s",OPT(info->line_indent,""));
+ } /* end if */
+
+ ctx->indent_level++;
+
+ /* Dump the array element */
+ h5tools_str_sprint(str, info, container, memb, cp_vp + i * size, ctx);
+
+ ctx->indent_level--;
+ } /* end for */
+
+ /* Print the closing bracket */
+ h5tools_str_append(str, "%s", OPT(info->arr_suf, "]"));
+ H5Tclose(memb);
+ } else if (H5Tget_class(type) == H5T_VLEN) {
+ unsigned int i;
+
+ /* Get the VL sequences's base datatype for each element */
+ memb = H5Tget_super(type);
+ size = H5Tget_size(memb);
+
+ /* Print the opening bracket */
+ h5tools_str_append(str, "%s", OPT(info->vlen_pre, "("));
+
+ /* Get the number of sequence elements */
+ nelmts = ((hvl_t *)cp_vp)->len;
+
+ for (i = 0; i < nelmts; i++) {
+ if (i)
+ h5tools_str_append(str, "%s",
+ OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK));
+
+#ifdef LATER
+/* Need to fix so VL data breaks at correct location on end of line -QAK */
+ if (info->arr_linebreak && h5tools_str_len(str)>=info->line_ncols) {
+ int x;
+
+ h5tools_str_append(str, "%s", "\n");
+
+ /* need to indent some more here */
+ if (ctx->indent_level >= 0)
+ h5tools_str_append(str, "%s", OPT(info->line_pre, ""));
+
+ for (x = 0; x < ctx->indent_level + 1; x++)
+ h5tools_str_append(str,"%s",OPT(info->line_indent,""));
+ } /* end if */
+#endif /* LATER */
+
+ ctx->indent_level++;
+
+ /* Dump the array element */
+ h5tools_str_sprint(str, info, container, memb,
+ ((char *)(((hvl_t *)cp_vp)->p)) + i * size, ctx);
+
+ ctx->indent_level--;
+ } /* end for */
+
+ h5tools_str_append(str, "%s", OPT(info->vlen_suf, ")"));
+ H5Tclose(memb);
+ } else {
+ /* All other types get printed as hexadecimal */
+ size_t i;
+
+ h5tools_str_append(str, "0x");
+ n = H5Tget_size(type);
+
+ for (i = 0; i < n; i++)
+ h5tools_str_append(str, "%02x", ucp_vp[i]);
+ }
+
+ return h5tools_str_fmt(str, start, OPT(info->elmt_fmt, "%s"));
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_escape
+ *
+ * Purpose: Changes all "funny" characters in S into standard C escape
+ * sequences. If ESCAPE_SPACES is non-zero then spaces are
+ * escaped by prepending a backslash.
+ *
+ * Return: Success: S
+ *
+ * Failure: NULL if the buffer would overflow. The
+ * buffer has as many left-to-right escapes as
+ * possible before overflow would have happened.
+ *
+ * Programmer: Robb Matzke
+ * Monday, April 26, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static char *
+h5tools_escape(char *s/*in,out*/, size_t size, int escape_spaces)
+{
+ register size_t i;
+ size_t n = strlen(s);
+ const char *escape;
+ char octal[8];
+
+ for (i = 0; i < n; i++) {
+ switch (s[i]) {
+ case '"':
+ escape = "\\\"";
+ break;
+ case '\\':
+ escape = "\\\\";
+ break;
+ case '\b':
+ escape = "\\b";
+ break;
+ case '\f':
+ escape = "\\f";
+ break;
+ case '\n':
+ escape = "\\n";
+ break;
+ case '\r':
+ escape = "\\r";
+ break;
+ case '\t':
+ escape = "\\t";
+ break;
+ case ' ':
+ escape = escape_spaces ? "\\ " : NULL;
+ break;
+ default:
+ if (!isprint((int)*s)) {
+ sprintf(octal, "\\%03o", (unsigned char)s[i]);
+ escape = octal;
+ } else {
+ escape = NULL;
+ }
+
+ break;
+ }
+
+ if (escape) {
+ size_t esc_size = strlen(escape);
+
+ if (n + esc_size + 1 > size)
+ /*would overflow*/
+ return NULL;
+
+ memmove(s + i + esc_size, s + i, (n - i) + 1); /*make room*/
+ memcpy(s + i, escape, esc_size); /*insert*/
+ n += esc_size;
+ i += esc_size - 1;
+ }
+ }
+
+ return s;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_is_zero
+ *
+ * Purpose: Determines if memory is initialized to all zero bytes.
+ *
+ * Return: TRUE if all bytes are zero; FALSE otherwise
+ *
+ * Programmer: Robb Matzke
+ * Monday, June 7, 1999
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hbool_t
+h5tools_is_zero(const void *_mem, size_t size)
+{
+ const unsigned char *mem = (const unsigned char *)_mem;
+
+ while (size-- > 0)
+ if (mem[size])
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/tools/lib/h5tools_str.h b/tools/lib/h5tools_str.h
new file mode 100644
index 0000000..58b5ba9
--- /dev/null
+++ b/tools/lib/h5tools_str.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2001 National Center for Supercomputing Applications
+ * All rights reserved.
+ *
+ * Programmer: Bill Wendling <wendling@ncsa.uiuc.edu>
+ * Monday, 19. February 2001
+ */
+#ifndef H5TOOLS_STR_H__
+#define H5TOOLS_STR_H__
+
+typedef struct h5tools_str_t {
+ char *s; /*allocate string */
+ size_t len; /*length of actual value */
+ size_t nalloc; /*allocated size of string */
+} h5tools_str_t;
+
+extern void h5tools_str_close(h5tools_str_t *str);
+extern size_t h5tools_str_len(h5tools_str_t *str);
+extern char *h5tools_str_append(h5tools_str_t *str, const char *fmt, ...);
+extern char *h5tools_str_reset(h5tools_str_t *str);
+extern char *h5tools_str_trunc(h5tools_str_t *str, size_t size);
+extern char *h5tools_str_fmt(h5tools_str_t *str, size_t start, const char *fmt);
+extern char *h5tools_str_prefix(h5tools_str_t *str, const h5dump_t *info,
+ hsize_t elmtno, int ndims, hsize_t min_idx[],
+ hsize_t max_idx[]);
+extern int h5tools_str_dump_region(h5tools_str_t *, hid_t, const h5dump_t *);
+extern void h5tools_print_char(h5tools_str_t *, const h5dump_t *, unsigned char);
+extern char *h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info,
+ hid_t container, hid_t type, void *vp,
+ h5tools_context_t *ctx);
+
+#endif /* H5TOOLS_STR_H__ */
diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h
new file mode 100644
index 0000000..eda8e00b
--- /dev/null
+++ b/tools/lib/h5tools_utils.h
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2001 National Center for Supercomputing Applications
+ * All rights reserved.
+ *
+ * Programmer: Bill Wendling <wendling@ncsa.uiuc.edu>
+ * Tuesday, 6. March 2001
+ *
+ * Purpose: Support functions for the various tools.
+ */
+#ifndef H5TOOLS_UTILS_H__
+#define H5TOOLS_UTILS_H__
+
+#include "hdf5.h"
+
+/*
+ * begin get_option section
+ */
+extern int opt_err; /* getoption prints errors if this is on */
+extern int opt_ind; /* token pointer */
+extern const char *opt_arg; /* flag argument (or value) */
+
+enum {
+ no_arg = 0, /* doesn't take an argument */
+ require_arg, /* requires an argument */
+ optional_arg /* argument is optional */
+};
+
+/*
+ * get_option determines which options are specified on the command line and
+ * returns a pointer to any arguments possibly associated with the option in
+ * the ``opt_arg'' variable. get_option returns the shortname equivalent of
+ * the option. The long options are specified in the following way:
+ *
+ * struct long_options foo[] = {
+ * { "filename", require_arg, 'f' },
+ * { "append", no_arg, 'a' },
+ * { "width", require_arg, 'w' },
+ * { NULL, 0, 0 }
+ * };
+ *
+ * Long named options can have arguments specified as either:
+ *
+ * ``--param=arg'' or ``--param arg''
+ *
+ * Short named options can have arguments specified as either:
+ *
+ * ``-w80'' or ``-w 80''
+ *
+ * and can have more than one short named option specified at one time:
+ *
+ * -aw80
+ *
+ * in which case those options which expect an argument need to come at the
+ * end.
+ */
+typedef struct long_options {
+ const char *name; /* name of the long option */
+ int has_arg; /* whether we should look for an arg */
+ char shortval; /* the shortname equivalent of long arg
+ * this gets returned from get_option */
+} long_options;
+
+extern int get_option(int argc, const char **argv, const char *opt,
+ const struct long_options *l_opt);
+/*
+ * end get_option section
+ */
+
+/*struct taken from the dumper. needed in table struct*/
+typedef struct obj_t {
+ unsigned long objno[2];
+ char objname[1024];
+ int displayed;
+ int recorded;
+ int objflag;
+} obj_t;
+
+/*struct for the tables that the find_objs function uses*/
+typedef struct table_t {
+ int size;
+ int nobjs;
+ obj_t *objs;
+} table_t;
+
+/*this struct stores the information that is passed to the find_objs function*/
+typedef struct find_objs_t {
+ int prefix_len;
+ char *prefix;
+ unsigned int threshold; /* should be 0 or 1 */
+ table_t *group_table;
+ table_t *type_table;
+ table_t *dset_table;
+ int status;
+} find_objs_t;
+
+extern int nCols; /*max number of columns for outputting */
+
+/* Definitions of useful routines */
+extern void indentation(int);
+extern void print_version(const char *progname);
+extern void error_msg(const char *progname, const char *fmt, ...);
+extern void warn_msg(const char *progname, const char *fmt, ...);
+extern void free_table(table_t **table);
+extern void dump_table(char *name, table_t *table);
+extern int get_table_idx(table_t *table, unsigned long *);
+extern int get_tableflag(table_t*, int);
+extern int set_tableflag(table_t*, int);
+extern char *get_objectname(table_t*, int);
+extern herr_t find_objs(hid_t group, const char *name, void *op_data);
+extern int search_obj(table_t *temp, unsigned long *);
+extern void init_table(table_t **tbl);
+extern void init_prefix(char **temp, int);
+
+#endif /* H5TOOLS_UTILS_H__ */
diff --git a/tools/lib/talign.c b/tools/lib/talign.c
new file mode 100644
index 0000000..5c4f88d
--- /dev/null
+++ b/tools/lib/talign.c
@@ -0,0 +1,174 @@
+/*
+ * Small program to illustrate the "misalignment" of members within a compound
+ * datatype, in a datatype fixed by h5tools_fixtype().
+ */
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h> /* Required for unlink() */
+
+#include "hdf5.h"
+#include "h5tools.h"
+
+const char *fname = "talign.h5";
+const char *setname = "align";
+
+/*
+ * This program assumes that there is no extra space between the members 'Ok'
+ * and 'Not Ok', (there shouldn't be because they are of the same atomic type
+ * H5T_NATIVE_FLOAT, and they are placed within the compound next to one
+ * another per construction)
+ */
+
+int main(void)
+{
+ hid_t fil,spc,set;
+ hid_t cs6, cmp, fix;
+ hid_t cmp1, cmp2, cmp3;
+ hid_t plist;
+ hid_t array_dt;
+
+ hsize_t dim[2];
+ hsize_t cdim[4];
+
+ char string5[5];
+ float fok[2] = {1234., 2341.};
+ float fnok[2] = {5678., 6785.};
+ float *fptr;
+
+ char *data;
+ char *mname;
+
+ int result = 0;
+
+ printf("%-70s", "Testing alignment in compound datatypes");
+
+ strcpy(string5, "Hi!");
+ unlink(fname);
+ fil = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ if (fil < 0) {
+ puts("*FAILED*");
+ return 1;
+ }
+
+ H5E_BEGIN_TRY {
+ H5Gunlink(fil, setname);
+ } H5E_END_TRY;
+
+ cs6 = H5Tcopy(H5T_C_S1);
+ H5Tset_size(cs6, sizeof(string5));
+ H5Tset_strpad(cs6, H5T_STR_NULLPAD);
+
+ cmp = H5Tcreate(H5T_COMPOUND, sizeof(fok) + sizeof(string5) + sizeof(fnok));
+ H5Tinsert(cmp, "Awkward length", 0, cs6);
+
+ cdim[0] = sizeof(fok) / sizeof(float);
+ array_dt=H5Tarray_create(H5T_NATIVE_FLOAT,1,cdim,NULL);
+ H5Tinsert(cmp, "Ok", sizeof(string5), array_dt);
+ H5Tclose(array_dt);
+
+ cdim[0] = sizeof(fnok) / sizeof(float);
+ array_dt=H5Tarray_create(H5T_NATIVE_FLOAT,1,cdim,NULL);
+ H5Tinsert(cmp, "Not Ok", sizeof(fok) + sizeof(string5), array_dt);
+ H5Tclose(array_dt);
+
+ fix = h5tools_fixtype(cmp);
+
+ cmp1 = H5Tcreate(H5T_COMPOUND, sizeof(fok));
+
+ cdim[0] = sizeof(fok) / sizeof(float);
+ array_dt=H5Tarray_create(H5T_NATIVE_FLOAT,1,cdim,NULL);
+ H5Tinsert(cmp1, "Ok", 0, array_dt);
+ H5Tclose(array_dt);
+
+ cmp2 = H5Tcreate(H5T_COMPOUND, sizeof(string5));
+ H5Tinsert(cmp2, "Awkward length", 0, cs6);
+
+ cmp3 = H5Tcreate(H5T_COMPOUND, sizeof(fnok));
+
+ cdim[0] = sizeof(fnok) / sizeof(float);
+ array_dt=H5Tarray_create(H5T_NATIVE_FLOAT,1,cdim,NULL);
+ H5Tinsert(cmp3, "Not Ok", 0, array_dt);
+ H5Tclose(array_dt);
+
+ plist = H5Pcreate(H5P_DATASET_XFER);
+ H5Pset_preserve(plist, 1);
+
+ /*
+ * Create a small dataset, and write data into it we write each field
+ * in turn so that we are avoid alignment issues at this point
+ */
+ dim[0] = 1;
+ spc = H5Screate_simple(1, dim, NULL);
+ set = H5Dcreate(fil, setname, cmp, spc, H5P_DEFAULT);
+
+ H5Dwrite(set, cmp1, spc, H5S_ALL, plist, fok);
+ H5Dwrite(set, cmp2, spc, H5S_ALL, plist, string5);
+ H5Dwrite(set, cmp3, spc, H5S_ALL, plist, fnok);
+
+ H5Dclose(set);
+
+ /* Now open the set, and read it back in */
+ data = malloc(H5Tget_size(fix));
+
+ if (!data) {
+ perror("malloc() failed");
+ abort();
+ }
+
+ set = H5Dopen(fil, setname);
+
+ H5Dread(set, fix, spc, H5S_ALL, H5P_DEFAULT, data);
+ fptr = (float *)(data + H5Tget_member_offset(fix, 1));
+
+ if (fok[0] != fptr[0] || fok[1] != fptr[1]
+ || fnok[0] != fptr[2] || fnok[1] != fptr[3]) {
+ result = 1;
+ printf("%14s (%2d) %6s = %s\n",
+ mname = H5Tget_member_name(fix, 0), (int)H5Tget_member_offset(fix,0),
+ string5, (char *)(data + H5Tget_member_offset(fix, 0)));
+ free(mname);
+ fptr = (float *)(data + H5Tget_member_offset(fix, 1));
+ printf("Data comparison:\n"
+ "%14s (%2d) %6f = %f\n"
+ " %6f = %f\n",
+ mname = H5Tget_member_name(fix, 1), (int)H5Tget_member_offset(fix,1),
+ fok[0], fptr[0],
+ fok[1], fptr[1]);
+ free(mname);
+ fptr = (float *)(data + H5Tget_member_offset(fix, 2));
+ printf("%14s (%2d) %6f = %f\n"
+ " %6f = %6f\n",
+ mname = H5Tget_member_name(fix, 2), (int)H5Tget_member_offset(fix,2),
+ fnok[0], fptr[0],
+ fnok[1], fptr[1]);
+ free(mname);
+
+ fptr = (float *)(data + H5Tget_member_offset(fix, 1));
+ printf("\n"
+ "Short circuit\n"
+ " %6f = %f\n"
+ " %6f = %f\n"
+ " %6f = %f\n"
+ " %6f = %f\n",
+ fok[0], fptr[0],
+ fok[1], fptr[1],
+ fnok[0], fptr[2],
+ fnok[1], fptr[3]);
+ puts("*FAILED*");
+ } else {
+ puts(" PASSED");
+ }
+
+ free(data);
+ H5Sclose(spc);
+ H5Tclose(cmp);
+ H5Tclose(cmp1);
+ H5Tclose(cmp2);
+ H5Tclose(cmp3);
+ H5Pclose(plist);
+ H5Fclose(fil);
+ unlink(fname);
+ fflush(stdout);
+ return result;
+}