Beispiel #1
0
//--------------------------------------------------------------------------
// 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);
}
Beispiel #2
0
/*-------------------------------------------------------------------------
 * 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.
 *     April 12, 2011: Raymond Lu
 *              Starting from the 1.8.7 release, we allow dimension
 *              size to be zero.  So I took out the test against it.
 *-------------------------------------------------------------------------
 */
static void test_h5s_basic()
{
    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("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 *tmp_str = new char[TESTFILE.length()+1];
        strcpy(tmp_str, TESTFILE.c_str());
        const char *testfile = H5_get_srcdir_filename(tmp_str);
        delete []tmp_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

    // CHECK_I(ret, "H5Fclose");  // leave this here, later, fake a failure
    // in the p_close see how this will handle it. - BMR

        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()