Esempio n. 1
0
/*-------------------------------------------------------------------------
* subroutine for test_text_dtype(): test_arrays().
*-------------------------------------------------------------------------
*/
static int test_arrays(void)
{
    hid_t   dtype;
    int     ndims;
    hsize_t dims[3];
    H5T_class_t type_class;
    char*   dt_str;
    size_t  str_len;

    TESTING3("        text for array types");

    if((dtype = H5LTtext_to_dtype("H5T_ARRAY { [5][7][13] H5T_ARRAY { [17][19] H5T_COMPOUND { H5T_STD_I8BE \"arr_compound_1\"; H5T_STD_I32BE \"arr_compound_2\"; } } }", H5LT_DDL))<0)
        goto out;

    if((type_class = H5Tget_class(dtype))<0)
        goto out;
    if(type_class != H5T_ARRAY)
        goto out;

    if((ndims = H5Tget_array_ndims(dtype))<0)
        goto out;
    if(ndims != 3)
        goto out;

    if(H5Tget_array_dims2(dtype, dims) < 0)
        goto out;
    if(dims[0] != 5 || dims[1] != 7 || dims[2] != 13)
        goto out;

    if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
        goto out;
    dt_str = (char*)calloc(str_len, sizeof(char));
    if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0)
        goto out;
    if(strcmp(dt_str, "H5T_ARRAY {\n      [5][7][13] H5T_ARRAY {\n         [17][19] H5T_COMPOUND {\n            H5T_STD_I8BE \"arr_compound_1\" : 0;\n            H5T_STD_I32BE \"arr_compound_2\" : 1;\n         }\n      }\n   }")) {
        printf("dt=\n%s\n", dt_str);
        goto out;
    }

    free(dt_str);

    if(H5Tclose(dtype)<0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    return -1;
}
Esempio n. 2
0
//-*****************************************************************************
static void getDatatypeArrayDims( hid_t iDtype, Dimensions &dims )
{
    ABCA_ASSERT( iDtype >= 0, "Invalid datatype in getDatatypeArrayDims" );
    
    int ndims = H5Tget_array_ndims( iDtype );
    ABCA_ASSERT( ndims > 0,
                  "getDatatypeArrayDims() H5Tget_array_ndims failed" );

    HDimensions hdims( ( size_t )ndims );
    ndims = H5Tget_array_dims2( iDtype, hdims.rootPtr() );
    ABCA_ASSERT( ndims > 0,
                  "getDatatypeArrayDims() H5Tget_array_dims failed" );
    ABCA_ASSERT( ndims == hdims.rank(),
                  "getDatatypeArrayDims() inconsistent ranks" );
    dims = hdims;
}
Esempio n. 3
0
//--------------------------------------------------------------------------
// Function:	ArrayType overloaded constructor
///\brief	Creates an ArrayType object using an existing id.
///\param	existing_id - IN: Id of an existing datatype
///\exception	H5::DataTypeIException
// Programmer	Binh-Minh Ribler - May 2004
//--------------------------------------------------------------------------
ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id )
{
   // Get the rank of the existing array and store it in this array
   rank = H5Tget_array_ndims(existing_id);
   if (rank < 0)
   {
      throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_ndims failed");
   }

    // Allocate space for the dimensions
    dimensions = new hsize_t[rank];

    // Get the dimensions of the existing array and store it in this array
    int ret_value = H5Tget_array_dims2(id, dimensions);
    if (ret_value < 0)
	throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_dims2 failed");
}
Esempio n. 4
0
//--------------------------------------------------------------------------
// Function:	ArrayType::getArrayDims
///\brief	Retrieves the size of all dimensions of an array datatype.
///\param	dims - OUT: Sizes of dimensions
///\return	Number of dimensions
///\exception	H5::DataTypeIException
// Programmer	Binh-Minh Ribler - May 2004
//--------------------------------------------------------------------------
int ArrayType::getArrayDims(hsize_t* dims)
{
   // If the array's dimensions have not been stored, retrieve them via C API
   if (dimensions == NULL)
   {
      int ndims = H5Tget_array_dims2(id, dims);
      if (ndims < 0)
         throw DataTypeIException("ArrayType::getArrayDims", "H5Tget_array_dims2 failed");
      // Store the array's info in memory
      rank = ndims;
      dimensions = new hsize_t[rank];
      for (int i = 0; i < rank; i++)
         dimensions[i] = dims[i];
   }
   // Otherwise, simply copy what's in 'dimensions' to 'dims'
   for (int i = 0; i < rank; i++)
      dims[i] = dimensions[i];
   return(rank);
}