/*------------------------------------------------------------------------- * 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; }
//-------------------------------------------------------------------------- // Function: ArrayType::getArrayNDims ///\brief Returns the number of dimensions for an array datatype. ///\return Number of dimensions ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- int ArrayType::getArrayNDims() { // If the array's rank has not been stored, i.e. rank is init to -1, // retrieve it via the C API if (rank < 0) { rank = H5Tget_array_ndims(id); if (rank < 0) { throw DataTypeIException("ArrayType::getArrayNDims", "H5Tget_array_ndims failed"); } } return(rank); }
//-***************************************************************************** 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; }
//-------------------------------------------------------------------------- // 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"); }
static CollectionType* genType(hid_t datatype_id) { bool found = false; H5T_class_t h5_class = H5Tget_class(datatype_id); if(h5_class == H5T_ARRAY) { hid_t base = H5Tget_super(datatype_id); if(H5Tequal(base, H5T_NATIVE_HSIZE) == 1) { if(H5Tget_array_ndims(datatype_id) == 1) { hsize_t adims_out[1]; H5Tget_array_dims(datatype_id, adims_out); if(adims_out[0] == 3) found = true; } } H5Tclose(base); } if(found) return new ColTypeDimArray; else return NULL; }