/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the files COPYING and Copyright.html. COPYING can be found at the root * * of the source code distribution tree; Copyright.html can be found at the * * root level of an installed copy of the electronic HDF5 document set and * * is linked from the top-level documents page. It can also be found at * * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /***************************************************************************** FILE trefer.cpp - HDF5 C++ testing the functionalities associated with the C Reference interface (H5R) ***************************************************************************/ #ifdef OLD_HEADER_FILENAME #include #else #include #endif #include #ifndef H5_NO_NAMESPACE #ifndef H5_NO_STD using std::cerr; using std::endl; #endif // H5_NO_STD #endif #include "testhdf5.h" // C test header file #include "H5Cpp.h" // C++ API header file #ifndef H5_NO_NAMESPACE using namespace H5; #endif #include "h5cpputil.h" // C++ utilility header file const H5std_string FILE1("trefer1.h5"); const H5std_string FILE2("trefer2.h5"); const H5std_string FILE3("trefer3.h5"); const H5std_string DSET_DEFAULT_NAME("default"); const H5std_string MEMBER1( "a_name" ); const H5std_string MEMBER2( "b_name" ); const H5std_string MEMBER3( "c_name" ); // 1-D dataset with fixed dimensions const H5std_string SPACE1_NAME("Space1"); const int SPACE1_RANK = 1; const int SPACE1_DIM1 = 4; // 2-D dataset with fixed dimensions const H5std_string SPACE2_NAME("Space2"); const int SPACE2_RANK = 2; const int SPACE2_DIM1 = 10; const int SPACE2_DIM2 = 10; // Larger 1-D dataset with fixed dimensions const H5std_string SPACE3_NAME("Space3"); const int SPACE3_RANK = 1; const int SPACE3_DIM1 = 100; // Element selection information const int POINT1_NPOINTS = 10; // Compound datatype typedef struct s1_t { unsigned int a; unsigned int b; float c; } s1_t; /**************************************************************** ** ** test_reference_obj(): Test basic object reference functionality. ** Tests references to various kinds of objects ** ****************************************************************/ static void test_reference_obj(void) { int i; // counting variables const H5std_string write_comment="Foo!"; // Comments for group // Output message about test being performed MESSAGE(5, ("Testing Object Reference Functions\n")); H5File* file1 = NULL; try { hobj_ref_t *wbuf, // buffer to write to disk *rbuf, // buffer read from disk *tbuf; // temp. buffer read from disk // Allocate write & read buffers int temp_size = MAX(sizeof(unsigned),sizeof(hobj_ref_t)); wbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1); rbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1); tbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1); // Create file FILE1 file1 = new H5File (FILE1, H5F_ACC_TRUNC); // Create dataspace for datasets hsize_t dims1[] = {SPACE1_DIM1}; DataSpace sid1(SPACE1_RANK, dims1); // Create a group Group group = file1->createGroup("Group1", (size_t)-1); // Set group's comment group.setComment(".", write_comment); // Create a dataset (inside /Group1) DataSet dataset = group.createDataSet("Dataset1", PredType::NATIVE_UINT, sid1); unsigned *tu32; // Temporary pointer to uint32 data for (tu32=(unsigned *)wbuf, i=0; icreateDataSet("Dataset3", PredType::STD_REF_OBJ, sid1); // Create reference to dataset file1->reference(&wbuf[0], "/Group1/Dataset1"); H5G_obj_t obj_type = dataset.getObjType(&wbuf[0], H5R_OBJECT); verify_val(obj_type, H5G_DATASET, "DataSet::getObjType", __LINE__, __FILE__); // Create reference to dataset file1->reference(&wbuf[1], "/Group1/Dataset2"); obj_type = dataset.getObjType(&wbuf[1], H5R_OBJECT); verify_val(obj_type, H5G_DATASET, "DataSet::getObjType", __LINE__, __FILE__); // Create reference to group file1->reference(&wbuf[2], "/Group1"); obj_type = dataset.getObjType(&wbuf[2], H5R_OBJECT); verify_val(obj_type, H5G_GROUP, "DataSet::getObjType", __LINE__, __FILE__); // Create reference to named datatype file1->reference(&wbuf[3], "/Group1/Datatype1"); obj_type = dataset.getObjType(&wbuf[3], H5R_OBJECT); verify_val(obj_type, H5G_TYPE, "DataSet::getObjType", __LINE__, __FILE__); // Write selection to disk dataset.write(wbuf, PredType::STD_REF_OBJ); // Close disk dataspace, dataset, and file sid1.close(); dataset.close(); delete file1; // Re-open the file file1 = new H5File(FILE1, H5F_ACC_RDWR); // Open the dataset dataset = file1->openDataSet("/Dataset3"); // Read selection from disk dataset.read(rbuf, PredType::STD_REF_OBJ); // Dereference dataset object by ctor, from the location where // 'dataset' is located DataSet dset2(dataset, &rbuf[0]); // Check information in the referenced dataset sid1 = dset2.getSpace(); hssize_t n_elements = sid1.getSimpleExtentNpoints(); verify_val((long)n_elements, (long)4, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); // Read from disk dset2.read(tbuf, PredType::NATIVE_UINT); for(tu32=(unsigned *)tbuf,i=0; iclose(); // Free memory buffers free(wbuf); free(rbuf); free(tbuf); } // end try catch (Exception E) { issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } // test_reference_obj() /**************************************************************** ** ** test_reference(): Main reference testing routine. ** ****************************************************************/ #ifdef __cplusplus extern "C" #endif void test_reference(void) { // Output message about test being performed MESSAGE(5, ("Testing References\n")); test_reference_obj(); // Test basic object reference functionality } // test_reference() /**************************************************************** ** Function: cleanup_reference ** Purpose: Cleanup temporary test files ** Return: none ****************************************************************/ void cleanup_reference(void) { remove(FILE1.c_str()); }