void cleanup_file() { HDremove(FILE1.c_str()); HDremove(FILE2.c_str()); HDremove(FILE3.c_str()); HDremove(FILE4.c_str()); } // cleanup_file
//-------------------------------------------------------------------------- // Function: Attribute::write ///\brief This is an overloaded member function, provided for convenience. /// It writes a \a H5std_string to this attribute. ///\param mem_type - IN: Attribute datatype (in memory) ///\param strg - IN: Data to be written ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - Apr, 2003 //-------------------------------------------------------------------------- void Attribute::write(const DataType& mem_type, const H5std_string& strg) const { // Check if this attribute has variable-len string or fixed-len string and // proceed appropriately. htri_t is_variable_len = H5Tis_variable_str(mem_type.getId()); if (is_variable_len < 0) { throw AttributeIException("Attribute::write", "H5Tis_variable_str failed"); } // Convert string to C-string const char* strg_C; strg_C = strg.c_str(); // strg_C refers to the contents of strg as a C-str herr_t ret_value = 0; // Pass string in differently depends on variable or fixed length if (!is_variable_len) { ret_value = H5Awrite(id, mem_type.getId(), strg_C); } else { // passing third argument by address ret_value = H5Awrite(id, mem_type.getId(), &strg_C); } if (ret_value < 0) { throw AttributeIException("Attribute::write", "H5Awrite failed"); } }
//-------------------------------------------------------------------------- // Function: Attribute::getName ///\brief Gets the name of this attribute, returning its length. ///\param attr_name - OUT: Buffer for the name string as \a H5std_string ///\param len - IN: Desired length of the name, default to 0 ///\return Actual length of the attribute name ///\exception H5::AttributeIException ///\par Description /// This function retrieves the attribute's name as a string. The /// buf_size can specify a specific length or default to 0, in /// which case the entire name will be retrieved. // Programmer Binh-Minh Ribler - Nov, 2001 // Modification // Mar 2014 - BMR // Added to replace getName(size_t, H5std_string&) so that it'll // allow the argument "len" to be skipped. //-------------------------------------------------------------------------- ssize_t Attribute::getName(H5std_string& attr_name, size_t len) const { ssize_t name_size = 0; // If no length is provided, get the entire attribute name if (len == 0) { attr_name = getName(); name_size = attr_name.length(); } // If length is provided, get that number of characters in name else { char* name_C = new char[len+1]; // temporary C-string HDmemset(name_C, 0, len+1); // clear buffer // Use overloaded function name_size = getName(name_C, len+1); // Convert the C attribute name to return attr_name = name_C; // Clean up resource delete []name_C; } // Otherwise, keep attr_name intact // Return name size return(name_size); }
//-------------------------------------------------------------------------- // Function: H5File overloaded constructor ///\brief This is another overloaded constructor. It differs from the /// above constructor only in the type of the \a name argument. ///\param name - IN: Name of the file - \c H5std_string ///\param flags - IN: File access flags ///\param create_plist - IN: File creation property list, used when /// modifying default file meta-data. Default to /// FileCreatPropList::DEFAULT ///\param access_plist - IN: File access property list. Default to /// FileAccPropList::DEFAULT // Notes With a PGI compiler (~2012-2013), the exception thrown by p_get_file // could not be caught in the applications. Added try block here // to catch then re-throw it. -BMR 2013/03/21 // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(0) { try { p_get_file(name.c_str(), flags, create_plist, access_plist); } catch (FileIException open_file) { throw open_file; } }
//-------------------------------------------------------------------------- // Function: H5Location::reference ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. ///\param ref - IN: Reference pointer ///\param name - IN: Name of the object to be referenced ///\param dataspace - IN: Dataspace with selection ///\param ref_type - IN: Type of reference to query, valid values are: /// \li \c H5R_OBJECT - Reference is an object reference. /// \li \c H5R_DATASET_REGION - Reference is a dataset region /// reference. (default) ///\exception H5::ReferenceException ///\note This method is more suitable for a dataset region reference. // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- void H5Location::reference(void* ref, const H5std_string& name, const DataSpace& dataspace, H5R_type_t ref_type) const { try { p_reference(ref, name.c_str(), dataspace.getId(), ref_type); } catch (ReferenceException E) { throw ReferenceException(inMemFunc("reference"), E.getDetailMsg()); } }
/**************************************************************** ** ** test_attr_compound_write(): Tests compound datatype attributes ** ****************************************************************/ static void test_attr_compound_write() { // Output message about test being performed SUBTEST("Multiple Attribute Functions"); try { // Create file H5File fid1(FILENAME.c_str(), H5F_ACC_TRUNC); // Create dataspace for dataset hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; DataSpace sid1(SPACE1_RANK, dims1); // Create a dataset DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR,sid1); // Create the attribute datatype. CompType comp_type(sizeof(struct attr4_struct)); attr4_field1_off = HOFFSET(struct attr4_struct, i); comp_type.insertMember(ATTR4_FIELDNAME1, attr4_field1_off, PredType::NATIVE_INT); attr4_field2_off = HOFFSET(struct attr4_struct, d); comp_type.insertMember(ATTR4_FIELDNAME2, attr4_field2_off, PredType::NATIVE_DOUBLE); attr4_field3_off = HOFFSET(struct attr4_struct, c); comp_type.insertMember(ATTR4_FIELDNAME3, attr4_field3_off, PredType::NATIVE_SCHAR); // Create dataspace for 1st attribute hsize_t dims2[] = {ATTR4_DIM1,ATTR4_DIM2}; DataSpace sid2(ATTR4_RANK, dims2); // Create complex attribute for the dataset Attribute attr = dataset.createAttribute(ATTR4_NAME, comp_type, sid2); // Try to create the same attribute again (should fail) try { Attribute invalid_attr = dataset.createAttribute (ATTR4_NAME, comp_type, sid2); } catch (AttributeIException E) // catching invalid creating attribute {} // do nothing, exception expected // Write complex attribute data attr.write(comp_type, attr_data4); PASSED(); } // end try block catch (Exception E) { issue_fail_msg("test_attr_compound_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_compound_write()
/*------------------------------------------------------------------------- * Function: test_get_objtype * * Purpose: Tests getting object type * * Return: Success: 0 * Failure: -1 * * Programmer: Binh-Minh Ribler * Friday, March 4, 2014 * * Modifications: * *------------------------------------------------------------------------- */ static void test_get_objtype() { SUBTEST("H5File::childObjType and H5Group::childObjType"); try { // Open file H5File file(FILE_OBJECTS, H5F_ACC_RDWR); // Open the top group Group grp1 = file.openGroup(GROUP1); // Create a datatype and save it DataType dtype(PredType::STD_I32LE); dtype.commit(grp1, "STD_I32LE"); // Get and verify object type with // H5O_type_t childObjType(const H5std_string& objname) H5O_type_t objtype = file.childObjType(DSET_IN_FILE); verify_val(objtype, H5O_TYPE_DATASET, "DataSet::childObjType", __LINE__, __FILE__); // Get and verify object type with // H5O_type_t childObjType(const char* objname) objtype = grp1.childObjType(GROUP1_1.c_str()); verify_val(objtype, H5O_TYPE_GROUP, "DataSet::childObjType", __LINE__, __FILE__); // Get and verify object type with // H5O_type_t childObjType(hsize_t index, H5_index_t index_type, // H5_iter_order_t order, const char* objname=".") objtype = grp1.childObjType((hsize_t)1, H5_INDEX_NAME, H5_ITER_INC); verify_val(objtype, H5O_TYPE_NAMED_DATATYPE, "DataSet::childObjType", __LINE__, __FILE__); // Get and verify object type with // H5O_type_t childObjType(hsize_t index, // H5_index_t index_type=H5_INDEX_NAME, // H5_iter_order_t order=H5_ITER_INC, const char* objname=".") objtype = grp1.childObjType((hsize_t)2); verify_val(objtype, H5O_TYPE_GROUP, "DataSet::childObjType", __LINE__, __FILE__); // Everything will be closed as they go out of scope PASSED(); } // try block // catch all other exceptions catch (Exception& E) { issue_fail_msg("test_get_objtype", __LINE__, __FILE__); } } // test_get_objtype
//-------------------------------------------------------------------------- // Function: CompType::insertMember ///\brief Inserts a new member to this compound datatype. ///\param name - IN: Name of the new member ///\param offset - IN: Offset in memory structure of the field to insert ///\param new_member - IN: New member to be inserted ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void CompType::insertMember( const H5std_string& name, size_t offset, const DataType& new_member ) const { // Convert string to C-string const char* name_C; name_C = name.c_str(); // name_C refers to the contents of name as a C-str hid_t new_member_id = new_member.getId(); // get new_member id for C API // Call C routine H5Tinsert to add the new member herr_t ret_value = H5Tinsert( id, name_C, offset, new_member_id ); if( ret_value < 0 ) { throw DataTypeIException("CompType::insertMember", "H5Tinsert failed"); } }
/*------------------------------------------------------------------------- * Function: test_read_vl_string_attribute * * Purpose: Test reading VL strings from attributes. * * Return: None * * Programmer: Binh-Minh Ribler (use C version) * January, 2007 * *------------------------------------------------------------------------- */ static void test_read_vl_string_attribute() { // Output message about test being performed SUBTEST("reading VL String as attributes"); try { // Open file H5File file1(FILENAME, H5F_ACC_RDONLY); // Create a datatype to refer to. StrType vlst(0, H5T_VARIABLE); // Open the root group and its attribute named ATTRSTR_NAME. Group root = file1.openGroup("/"); Attribute att = root.openAttribute(ATTRSTR_NAME); // Test reading "normal" sized string attribute char *string_att_check; att.read(vlst, &string_att_check); if(HDstrcmp(string_att_check,ATTRSTR_DATA.c_str())!=0) TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",ATTRSTR_DATA.c_str(),string_att_check); HDfree(string_att_check); att.close(); // Test reading "large" sized string attribute att = root.openAttribute("test_scalar_large"); att.read(vlst, &string_att_check); if(HDstrcmp(string_att_check,string_att_write)!=0) TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); HDfree(string_att_check); HDfree(string_att_write); // Free string allocated in test_write_vl_string_attribute // Close objects and file. att.close(); vlst.close(); root.close(); file1.close(); PASSED(); } // end try // Catch all exceptions. catch (Exception E) { issue_fail_msg("test_read_vl_string_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_read_vl_string_attribute
//-------------------------------------------------------------------------- // Function: DataSet::write ///\brief This is an overloaded member function, provided for convenience. /// It takes a reference to a \c H5std_string for the buffer. // Programmer Binh-Minh Ribler - 2000 // Modification // Jul 2009 // Modified to pass the buffer into H5Dwrite properly depending // whether the dataset has variable- or fixed-length string. //-------------------------------------------------------------------------- void DataSet::write( const H5std_string& strg, const DataType& mem_type, const DataSpace& mem_space, const DataSpace& file_space, const DSetMemXferPropList& xfer_plist ) const { // Check if this attribute has variable-len string or fixed-len string and // proceed appropriately. htri_t is_variable_len = H5Tis_variable_str(mem_type.getId()); if (is_variable_len < 0) { throw DataSetIException("DataSet::write", "H5Tis_variable_str failed"); } // Obtain identifiers for C API hid_t mem_type_id = mem_type.getId(); hid_t mem_space_id = mem_space.getId(); hid_t file_space_id = file_space.getId(); hid_t xfer_plist_id = xfer_plist.getId(); // Convert string to C-string const char* strg_C; strg_C = strg.c_str(); // strg_C refers to the contents of strg as a C-str herr_t ret_value = 0; // Pass string in differently depends on variable or fixed length if (!is_variable_len) { ret_value = H5Dwrite( id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg_C ); } else { // passing string argument by address ret_value = H5Dwrite( id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, &strg_C ); } if (ret_value < 0) { throw DataSetIException("DataSet::write", "H5Dwrite failed"); } }
//-------------------------------------------------------------------------- // Function: CommonFG::openVarLenType ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - Jul, 2005 //-------------------------------------------------------------------------- VarLenType CommonFG::openVarLenType( const H5std_string& name ) const { return( openVarLenType( name.c_str()) ); }
//-------------------------------------------------------------------------- // Function: CommonFG::unmount ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void CommonFG::unmount( const H5std_string& name ) const { unmount( name.c_str() ); }
static void test_file_attribute() { int rdata[ATTR1_DIM1]; int i; // Output message about test being performed SUBTEST("File Attribute"); H5std_string file_name; try { // Create a file using default properties. H5File file5(FILE5, H5F_ACC_TRUNC); // Create the data space hsize_t dims[RANK1] = {ATTR1_DIM1}; DataSpace space(RANK1, dims); // Create two attributes for the file Attribute fattr1(file5.createAttribute(FATTR1_NAME, PredType::NATIVE_FLOAT, space)); Attribute fattr2(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space)); fattr2.write(PredType::NATIVE_INT, fattr_data); try { // Try to create the same attribute again (should fail) Attribute fattr_dup(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space)); // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("H5File createAttribute", "Attempted to create an existing attribute."); } catch (AttributeIException& E) // catch creating existing attribute {} // do nothing, FAIL expected // Create a new dataset DataSet dataset(file5.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); // Create an attribute for the dataset Attribute dattr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space)); // Write data to the second file attribute dattr.write(PredType::NATIVE_INT, dattr_data); // Test flushing out the data from the attribute object dattr.flush(H5F_SCOPE_GLOBAL); // Get and verify the number of all objects in the file // Current: 1 file, 2 file attr, 1 ds, and 1 ds attr. ssize_t num_objs = file5.getObjCount(H5F_OBJ_ALL); verify_val(num_objs, 5, "H5File::getObjCount", __LINE__, __FILE__); num_objs = file5.getObjCount(H5F_OBJ_GROUP); verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_GROUP)", __LINE__, __FILE__); num_objs = file5.getObjCount(H5F_OBJ_DATASET); verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_DATASET)", __LINE__, __FILE__); num_objs = file5.getObjCount(H5F_OBJ_ATTR); verify_val(num_objs, 3, "H5File::getObjCount(H5F_OBJ_ATTR)", __LINE__, __FILE__); num_objs = file5.getObjCount(H5F_OBJ_DATATYPE); verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_DATATYPE)", __LINE__, __FILE__); num_objs = file5.getObjCount(H5F_OBJ_FILE); verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_FILE)", __LINE__, __FILE__); // Get the file name using the attributes H5std_string fname = fattr1.getFileName(); verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__); fname.clear(); fname = dattr.getFileName(); verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__); // Get the class of a file attribute's datatype H5T_class_t atclass = fattr1.getTypeClass(); verify_val(atclass, H5T_FLOAT, "Attribute::getTypeClass()", __LINE__, __FILE__); // Get and verify the number of attributes attached to a file int n_attrs = file5.getNumAttrs(); verify_val(n_attrs, 2, "H5File::getNumAttrs()", __LINE__, __FILE__); // Get and verify the number of attributes attached to a dataset n_attrs = 0; n_attrs = dataset.getNumAttrs(); verify_val(n_attrs, 1, "DataSet::getNumAttrs()", __LINE__, __FILE__); // Read back attribute's data HDmemset(rdata, 0, sizeof(rdata)); dattr.read(PredType::NATIVE_INT, rdata); /* Check results */ for (i = 0; i < ATTR1_DIM1; i++) { if (rdata[i] != dattr_data[i]) { H5_FAILED(); cerr << endl; cerr << "element [" << i << "] is " << rdata[i] << "but should have been " << dattr_data[i] << endl; } } PASSED(); } // end of try block catch (Exception& E) { issue_fail_msg("test_file_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_file_attribute()
//-------------------------------------------------------------------------- // Function: H5Object::reference ///\brief This is an overloaded function, provided for your convenience. /// It differs from the above function in that it takes an /// \c H5std_string for the object's name. ///\param ref - IN: Reference pointer ///\param name - IN: Name of the object to be referenced - \c H5std_string // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- void H5Object::reference(void* ref, const H5std_string& name) const { reference(ref, name.c_str()); }
//-------------------------------------------------------------------------- // Function: H5Object::removeAttr ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void H5Object::removeAttr( const H5std_string& name ) const { removeAttr( name.c_str() ); }
//-------------------------------------------------------------------------- // Function: H5Object::createAttribute ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- Attribute H5Object::createAttribute( const H5std_string& name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist ) const { return( createAttribute( name.c_str(), data_type, data_space, create_plist )); }
/*------------------------------------------------------------------------- * * Function: test_h5s_basic * * Purpose: Test basic H5S (dataspace) code * * Return: none * * Programmer: Binh-Minh Ribler (using C version) * Mar 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all * cases. Since there are no operator<< for 'long long' * or int64 in VS C++ ostream, I casted the hssize_t values * passed to verify_val to 'long' as well. If problems * arises later, this will have to be specificly handled * with a special routine. *------------------------------------------------------------------------- */ static void test_h5s_basic(void) { hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2, SPACE2_DIM3, SPACE2_DIM4}; hsize_t dims3[H5S_MAX_RANK+1]; hsize_t tmax[4]; // Output message about test being performed SUBTEST("Testing Dataspace Manipulation"); try { // Create simple dataspace sid1 DataSpace sid1 (SPACE1_RANK, dims1 ); // Get simple extent npoints of the dataspace sid1 and verify it hssize_t n; // Number of dataspace elements n = sid1.getSimpleExtentNpoints(); verify_val((long)n, (long)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3), "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); // Get the logical rank of dataspace sid1 and verify it int rank; // Logical rank of dataspace rank = sid1.getSimpleExtentNdims(); verify_val(rank, SPACE1_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); // Retrieves dimension size of dataspace sid1 and verify it int ndims; // Number of dimensions hsize_t tdims[4]; // Dimension array to test with ndims = sid1.getSimpleExtentDims( tdims ); verify_val(ndims, SPACE1_RANK, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); verify_val(HDmemcmp(tdims, dims1, SPACE1_RANK * sizeof(unsigned)), 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); // Create simple dataspace sid2 hsize_t max2[] = {SPACE2_MAX1, SPACE2_MAX2, SPACE2_MAX3, SPACE2_MAX4}; DataSpace sid2 (SPACE2_RANK, dims2, max2); // Get simple extent npoints of dataspace sid2 and verify it n = sid2.getSimpleExtentNpoints(); verify_val((long)n, (long)(SPACE2_DIM1 * SPACE2_DIM2 * SPACE2_DIM3 * SPACE2_DIM4), "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); // Get the logical rank of dataspace sid2 and verify it rank = sid2.getSimpleExtentNdims(); verify_val(rank, SPACE2_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); // Retrieves dimension size and max size of dataspace sid2 and // verify them ndims = sid2.getSimpleExtentDims( tdims, tmax ); verify_val(HDmemcmp(tdims, dims2, SPACE2_RANK * sizeof(unsigned)), 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); verify_val(HDmemcmp(tmax, max2, SPACE2_RANK * sizeof(unsigned)), 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); // Check to be sure we can't create a simple data space that has too // many dimensions. try { DataSpace manydims_ds(H5S_MAX_RANK+1, dims3, NULL); // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("DataSpace constructor", "Library allowed overwrite of existing dataset"); } catch( DataSpaceIException E ) // Simple data space with too many dims {} // do nothing, exception expected /* * Try reading a file that has been prepared that has a dataset with a * higher dimensionality than what the library can handle. * * If this test fails and the H5S_MAX_RANK variable has changed, follow * the instructions in space_overflow.c for regenating the th5s.h5 file. */ char testfile[512]=""; char *srcdir = getenv("srcdir"); if (srcdir && ((strlen(srcdir) + strlen(TESTFILE.c_str()) + 1) < sizeof(testfile))){ strcpy(testfile, srcdir); strcat(testfile, "/"); } strcat(testfile, TESTFILE.c_str()); // Create file H5File fid1(testfile, H5F_ACC_RDONLY); // Try to open the dataset that has higher dimensionality than // what the library can handle and this operation should fail. try { DataSet dset1 = fid1.openDataSet( "dset" ); // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("H5File::openDataSet", "Opening a dataset with higher dimensionality than what the library can handle"); } catch( FileIException E ) // catching higher dimensionality dataset {} // do nothing, exception expected // Verify that incorrect dimensions don't work dims1[0] = 0; try { DataSpace wrongdim_ds (SPACE1_RANK, dims1); // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("DataSpace constructor", "Attempted to use incorrect dimensions"); } catch( DataSpaceIException E ) // catching use of incorrect dimensions {} // do nothing, exception expected // Another incorrect dimension case DataSpace sid3 (H5S_SIMPLE); try { sid3.setExtentSimple( SPACE1_RANK, dims1 ); // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("DataSpace::setExtentSimple", "Attempted to use incorrect dimensions"); } catch (DataSpaceIException E) // catching use of incorrect dimensions {} // do nothing, exception expected PASSED(); } // end of try block catch (InvalidActionException E) { cerr << " FAILED" << endl; cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; } // catch all other exceptions catch (Exception E) { issue_fail_msg("test_h5s_basic()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_basic()
//-------------------------------------------------------------------------- // Function: CommonFG::iterateElems ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- int CommonFG::iterateElems( const H5std_string& name, int *idx, H5G_iterate_t op , void* op_data ) { return( iterateElems( name.c_str(), idx, op, op_data )); }
void cleanup_reference(void) { HDremove(FILE1.c_str()); HDremove(FILE2.c_str()); }
//-------------------------------------------------------------------------- // Function: CommonFG::getObjinfo ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - Nov, 2005 //-------------------------------------------------------------------------- void CommonFG::getObjinfo( const H5std_string& name, H5G_stat_t& statbuf ) const { getObjinfo( name.c_str(), statbuf ); }
void cleanup_h5s(void) { HDremove(DATAFILE.c_str()); } // cleanup_h5s
//-------------------------------------------------------------------------- // Function: CommonFG::getLinkval ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5std_string CommonFG::getLinkval( const H5std_string& name, size_t size ) const { return( getLinkval( name.c_str(), size )); }
//-------------------------------------------------------------------------- // Function: H5Object::openAttribute ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- Attribute H5Object::openAttribute( const H5std_string& name ) const { return( openAttribute( name.c_str()) ); }
//-------------------------------------------------------------------------- // Function: CommonFG::setComment ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name and \a comment. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void CommonFG::setComment( const H5std_string& name, const H5std_string& comment ) const { setComment( name.c_str(), comment.c_str() ); }
//-------------------------------------------------------------------------- // Function: H5Object::renameAttr ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for the names. // Programmer Binh-Minh Ribler - Mar, 2005 //-------------------------------------------------------------------------- void H5Object::renameAttr(const H5std_string& oldname, const H5std_string& newname) const { renameAttr (oldname.c_str(), newname.c_str()); }
//-------------------------------------------------------------------------- // Function: CommonFG::removeComment ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - May 2005 //-------------------------------------------------------------------------- void CommonFG::removeComment(const H5std_string& name) const { removeComment (name.c_str()); }
void cleanup_filters() { HDremove(FILE1.c_str()); }
//-------------------------------------------------------------------------- // Function: CommonFG::getComment ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5std_string CommonFG::getComment( const H5std_string& name, size_t bufsize ) const { return( getComment( name.c_str(), bufsize )); }
/*------------------------------------------------------------------------- * Function: test_file_create * * Purpose Test file and template creations * * Return None * * Programmer Binh-Minh Ribler (use C version) * January, 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all * cases. Since there are no operator<< for 'long long' * or int64 in VS C++ ostream, I casted the hsize_t values * passed to verify_val to 'long' as well. If problems * arises later, this will have to be specifically handled * with a special routine. *------------------------------------------------------------------------- */ static void test_file_create() { // Output message about test being performed SUBTEST("File Creation I/O"); // 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.c_str()); // Setting this to NULL for cleaning up in failure situations H5File* file1 = NULL; try { // Create file FILE1 file1 = new H5File (FILE1, H5F_ACC_EXCL); // Try to create the same file with H5F_ACC_TRUNC. This should fail // because file1 is the same file and is currently open. try { H5File file2 (FILE1, H5F_ACC_TRUNC); // should throw E // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("H5File constructor", "Attempted to create an existing file."); } catch (FileIException& E) // catch truncating existing file {} // do nothing, FAIL expected // Close file1 delete file1; file1 = NULL; // Try again with H5F_ACC_EXCL. This should fail because the file // already exists from the previous steps. try { H5File file2(FILE1, H5F_ACC_EXCL); // should throw E // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("H5File constructor", "File already exists."); } catch (FileIException& E) // catching creating existing file {} // do nothing, FAIL expected // Test create with H5F_ACC_TRUNC. This will truncate the existing file. file1 = new H5File (FILE1, H5F_ACC_TRUNC); // Try to create first file again. This should fail because file1 // is the same file and is currently open. try { H5File file2 (FILE1, H5F_ACC_TRUNC); // should throw E // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("H5File constructor", "H5F_ACC_TRUNC attempt on an opened file."); } catch (FileIException& E) // catching truncating opened file {} // do nothing, FAIL expected // Try with H5F_ACC_EXCL. This should fail too because the file already // exists. try { H5File file3 (FILE1, H5F_ACC_EXCL); // should throw E // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("H5File constructor", "H5F_ACC_EXCL attempt on an existing file."); } catch (FileIException& E) // catching H5F_ACC_EXCL on existing file {} // do nothing, FAIL expected // Get the file-creation template FileCreatPropList tmpl1 = file1->getCreatePlist(); hsize_t ublock = tmpl1.getUserblock(); verify_val((long)ublock, (long)F1_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); size_t parm1, parm2; // file-creation parameters tmpl1.getSizes( parm1, parm2); verify_val(parm1, F1_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); verify_val(parm2, F1_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); unsigned iparm1,iparm2; // file-creation parameters tmpl1.getSymk( iparm1, iparm2); verify_val(iparm1, F1_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); verify_val(iparm2, F1_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); // tmpl1 is automatically closed; if error occurs, it'll be // caught in the catch block // Close first file delete file1; } catch (InvalidActionException& E) { cerr << " *FAILED*" << endl; cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; if (file1 != NULL) // clean up delete file1; } // catch all other exceptions catch (Exception& E) { issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); if (file1 != NULL) // clean up delete file1; } // Setting this to NULL for cleaning up in failure situations FileCreatPropList* tmpl1 = NULL; try { // Create a new file with a non-standard file-creation template 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 file2( FILE2, H5F_ACC_TRUNC, *tmpl1 ); // Release file-creation template delete tmpl1; tmpl1 = NULL; // Get the file-creation template tmpl1 = new FileCreatPropList (file2.getCreatePlist()); // Get the file-creation parameters hsize_t ublock = tmpl1->getUserblock(); verify_val((long)ublock, (long)F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); size_t parm1, parm2; // file-creation parameters tmpl1->getSizes( parm1, parm2); verify_val(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); verify_val(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); unsigned iparm1,iparm2; // file-creation parameters tmpl1->getSymk( iparm1, iparm2); verify_val(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); verify_val(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); // Clone the file-creation template FileCreatPropList tmpl2; tmpl2.copy (*tmpl1); // Release file-creation template delete tmpl1; tmpl1 = NULL; // Set the new file-creation parameter tmpl2.setUserblock( F3_USERBLOCK_SIZE ); // Try to create second file, with non-standard file-creation template // params H5File file3( FILE3, H5F_ACC_TRUNC, tmpl2 ); // Get the file-creation template tmpl1 = new FileCreatPropList (file3.getCreatePlist()); // Get the file-creation parameters ublock = tmpl1->getUserblock(); verify_val((long)ublock, (long)F3_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); tmpl1->getSizes( parm1, parm2); verify_val(parm1, F3_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); verify_val(parm2, F3_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); tmpl1->getSymk( iparm1, iparm2); verify_val(iparm1, F3_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); verify_val(iparm2, F3_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); // Release file-creation template delete tmpl1; PASSED(); } // catch all exceptions catch (Exception& E) { issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); if (tmpl1 != NULL) // clean up delete tmpl1; } } // test_file_create()
//-------------------------------------------------------------------------- // Function: CommonFG::mount ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void CommonFG::mount( const H5std_string& name, H5File& child, PropList& plist ) const { mount( name.c_str(), child, plist ); }