本文整理汇总了C++中H5Tget_class函数的典型用法代码示例。如果您正苦于以下问题:C++ H5Tget_class函数的具体用法?C++ H5Tget_class怎么用?C++ H5Tget_class使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了H5Tget_class函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EquivalentDatatypes
//-*****************************************************************************
bool EquivalentDatatypes( hid_t iA, hid_t iB )
{
if ( iA >= 0 && iB >= 0 )
{
if ( H5Tequal( iA, iB ) > 0 )
{
return true;
}
// If they're not equal, but they are both arrayed and
// both have the same super type
// and dimensions, they're equivalent
if ( H5Tget_class( iA ) == H5T_ARRAY &&
H5Tget_class( iB ) == H5T_ARRAY )
{
hid_t superA = H5Tget_super( iA );
hid_t superB = H5Tget_super( iB );
if ( superA >= 0 && superB >= 0 &&
H5Tequal( superA, superB ) > 0 )
{
Dimensions aDims;
getDatatypeArrayDims( iA, aDims );
Dimensions bDims;
getDatatypeArrayDims( iB, bDims );
if ( aDims == bDims )
{
return true;
}
}
}
}
return false;
}
示例2: ReadStringsT
void
ReadStringsT( hid_t iParent,
const std::string &iAttrName,
size_t iNumStrings,
StringT *oStrings )
{
ABCA_ASSERT( iParent >= 0, "Invalid parent in ReadStringsT" );
// Open the attribute.
hid_t attrId = H5Aopen( iParent, iAttrName.c_str(), H5P_DEFAULT );
ABCA_ASSERT( attrId >= 0,
"Couldn't open attribute named: " << iAttrName );
AttrCloser attrCloser( attrId );
// Checking code.
{
hid_t attrFtype = H5Aget_type( attrId );
DtypeCloser dtypeCloser( attrFtype );
hid_t nativeDtype = GetNativeDtype<CharT>();
ABCA_ASSERT( H5Tget_class( attrFtype ) ==
H5Tget_class( nativeDtype ) &&
H5Tget_sign( attrFtype ) ==
H5Tget_sign( nativeDtype ),
"Invalid datatype for stringT" );
}
hid_t attrSpace = H5Aget_space( attrId );
ABCA_ASSERT( attrSpace >= 0,
"Couldn't get dataspace for attribute: " << iAttrName );
DspaceCloser dspaceCloser( attrSpace );
hssize_t numPoints = H5Sget_simple_extent_npoints( attrSpace );
ABCA_ASSERT( numPoints > 0,
"Degenerate string dimensions in ReadStringsT" );
// Create temporary char storage buffer.
std::vector<CharT> charStorage( ( size_t )( 1 + numPoints ),
( CharT )0 );
// Read into it.
herr_t status = H5Aread( attrId, GetNativeDtype<CharT>(),
( void * )&charStorage.front() );
ABCA_ASSERT( status >= 0, "Couldn't read from attribute: " << iAttrName );
// Extract 'em.
ExtractStrings( oStrings, ( const CharT * )&charStorage.front(),
1 + numPoints, iNumStrings );
}
示例3: write
void write(const hid_attribute_adaptor& attrib, const std::string& value)
{
hid_t attr_type_id = H5CPP_ERR_ON_NEG(H5Aget_type(attrib.id()));
if(H5Tget_class(attr_type_id) != H5T_STRING)
H5CPP_THROW("Attempted to set string value on non-string attribute '"
<< object::get_name(attrib.id()) << '\'');
const char* cstr = value.c_str();
if(H5Tis_variable_str(attr_type_id))
H5CPP_ERR_ON_NEG(H5Awrite(attrib.id(), attr_type_id, &cstr));
else
{
std::size_t attriblen = H5Aget_storage_size(attrib.id());
if(attriblen > value.length())
{
// avoid reading past end of value into unalloc'd mem
std::vector<char> buf(attriblen,'\0');
std::copy(cstr, cstr+value.length(), &buf[0]);
H5CPP_ERR_ON_NEG(H5Awrite(attrib.id(), attr_type_id, &buf[0]));
}
else
H5CPP_ERR_ON_NEG(H5Awrite(attrib.id(), attr_type_id, cstr));
}
}
示例4: test_compounds
/*-------------------------------------------------------------------------
* subroutine for test_text_dtype(): test_compounds().
*-------------------------------------------------------------------------
*/
static int test_compounds(void)
{
hid_t dtype;
int nmembs;
char *memb_name = NULL;
H5T_class_t memb_class;
H5T_class_t type_class;
char* dt_str;
size_t str_len;
TESTING3(" text for compound types");
if((dtype = H5LTtext_to_dtype("H5T_COMPOUND { H5T_STD_I16BE \"one_field\" : 2; H5T_STD_U8LE \"two_field\" : 6; }", H5LT_DDL))<0)
goto out;
if((type_class = H5Tget_class(dtype))<0)
goto out;
if(type_class != H5T_COMPOUND)
goto out;
if((nmembs = H5Tget_nmembers(dtype))<0)
goto out;
if(nmembs != 2)
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_COMPOUND {\n H5T_STD_I16BE \"one_field\" : 2;\n H5T_STD_U8LE \"two_field\" : 6;\n }")) {
printf("dt=\n%s\n", dt_str);
goto out;
}
free(dt_str);
if(H5Tclose(dtype)<0)
goto out;
if((dtype = H5LTtext_to_dtype("H5T_COMPOUND { H5T_STD_I32BE \"i32_field\"; H5T_STD_I16BE \"i16_field\"; H5T_COMPOUND { H5T_STD_I16BE \"sec_field\"; H5T_COMPOUND { H5T_STD_I32BE \"thd_field\"; } \"grandchild\"; } \"child_compound\"; H5T_STD_I8BE \"i8_field\"; }", H5LT_DDL))<0)
goto out;
if((memb_name = H5Tget_member_name(dtype, 1)) == NULL)
goto out;
if(strcmp(memb_name, "i16_field"))
goto out;
free(memb_name);
if((memb_class = H5Tget_member_class(dtype, 2))<0)
goto out;
if(memb_class != H5T_COMPOUND)
goto out;
PASSED();
return 0;
out:
H5_FAILED();
return -1;
}
示例5: if
std::string hdf5attribute::read_as_string()
{
std::string result;
if(H5Tequal(_type_id, H5T_NATIVE_INT16))
result = boost::lexical_cast<std::string>(read<short>());
else if(H5Tequal(_type_id, H5T_NATIVE_INT32))
result = boost::lexical_cast<std::string>(read<int>());
else if(H5Tequal(_type_id, H5T_NATIVE_UINT32))
result = boost::lexical_cast<std::string>(read<unsigned int>());
else if(H5Tequal(_type_id, H5T_NATIVE_UINT16))
result = boost::lexical_cast<std::string>(read<unsigned short>());
else if(H5Tequal(_type_id, H5T_NATIVE_UINT8))
result = boost::lexical_cast<std::string>(read<unsigned char>());
else if(H5Tequal(_type_id, H5T_NATIVE_INT8))
result = boost::lexical_cast<std::string>(read<char>());
else if(H5Tequal(_type_id, H5T_NATIVE_FLOAT))
result = boost::lexical_cast<std::string>(read<float>());
else if(H5Tequal(_type_id, H5T_NATIVE_DOUBLE))
result = boost::lexical_cast<std::string>(read<double>());
else if(H5Tget_class(_type_id) == H5T_STRING)
result = read<std::string>();
else
throw std::runtime_error("unknown type");
return result;
}
示例6: H5Dget_type
H5T_class_t HdfDataset::type() const
{
hid_t tid = H5Dget_type( d->id );
H5T_class_t t_class = H5Tget_class( tid );
H5Tclose( tid );
return t_class;
}
示例7: getHDF5ClassID
/****************************************************************
**
** getHDF5ClassID(): Returns class ID for loc_id.name. -1 if error.
**
****************************************************************/
H5T_class_t getHDF5ClassID(hid_t loc_id,
const char *name,
H5D_layout_t *layout,
hid_t *type_id,
hid_t *dataset_id) {
H5T_class_t class_id;
hid_t plist;
/* Open the dataset. */
if ( (*dataset_id = H5Dopen( loc_id, name, H5P_DEFAULT )) < 0 )
return -1;
/* Get an identifier for the datatype. */
*type_id = H5Dget_type( *dataset_id );
/* Get the class. */
class_id = H5Tget_class( *type_id );
/* Get the layout of the datatype */
plist = H5Dget_create_plist(*dataset_id);
*layout = H5Pget_layout(plist);
H5Pclose(plist);
return class_id;
}
示例8: issue
/* This may be ultimately confused with nested types with 2 components
called 'r' and 'i' and being floats, but in that case, the user
most probably wanted to keep a complex type, so getting a complex
instead of a nested type should not be a big issue (I hope!) :-/
F. Alted 2005-05-23 */
int is_complex(hid_t type_id) {
hid_t class_id, base_type_id;
hid_t class1, class2;
char *colname1, *colname2;
int result = 0;
hsize_t nfields;
class_id = H5Tget_class(type_id);
if (class_id == H5T_COMPOUND) {
nfields = H5Tget_nmembers(type_id);
if (nfields == 2) {
colname1 = H5Tget_member_name(type_id, 0);
colname2 = H5Tget_member_name(type_id, 1);
if ((strcmp(colname1, "r") == 0) && (strcmp(colname2, "i") == 0)) {
class1 = H5Tget_member_class(type_id, 0);
class2 = H5Tget_member_class(type_id, 1);
if (class1 == H5T_FLOAT && class2 == H5T_FLOAT)
result = 1;
}
free(colname1);
free(colname2);
}
}
/* Is an Array of Complex? */
else if (class_id == H5T_ARRAY) {
/* Get the array base component */
base_type_id = H5Tget_super(type_id);
/* Call is_complex again */
result = is_complex(base_type_id);
H5Tclose(base_type_id);
}
return result;
}
示例9: H5Aget_type
// JRC: This fat interface may not scale? What about
// scalar attributes?
herr_t VsH5Attribute::getDoubleVectorValue(std::vector<double>* dvals) {
herr_t err = 0;
size_t npoints;
hid_t atype = H5Aget_type(getId());
H5T_class_t type = H5Tget_class(atype);
hid_t aspace = H5Aget_space(getId());
size_t rank = H5Sget_simple_extent_ndims(aspace);
if (type != H5T_FLOAT) {
VsLog::warningLog() <<"VsH5Attribute::getDoubleVectorValue() - Requested attribute " <<getShortName()
<<" is not a floating point vector." <<std::endl;
dvals->resize(0);
return -1;
}
if (rank == 0) {
dvals->resize(1);
double v;
err = H5Aread(getId(), H5T_NATIVE_DOUBLE, &v);
(*dvals)[0] = v;
return err;
}
// rank>0
npoints = H5Sget_simple_extent_npoints(aspace);
double* v = new double[npoints];
err = H5Aread(getId(), H5T_NATIVE_DOUBLE, v);
dvals->resize(npoints);
for (size_t i = 0; i<npoints; ++i) {
(*dvals)[i] = v[i];
}
delete [] v;
return err;
}
示例10: get_attribute_float
static herr_t get_attribute_float(hid_t input, const char *name, float *val)
{
hid_t attr_id;
hid_t type_id;
H5T_class_t type_class;
size_t type_size;
herr_t status;
char *strval;
attr_id = H5Aopen_name(input, name);
type_id = H5Aget_type(attr_id);
type_class = H5Tget_class(type_id);
type_size = H5Tget_size(type_id);
H5Tclose(type_id);
H5Aclose(attr_id);
switch(type_class)
{
case H5T_STRING:
status = get_attribute_str(input, name, &strval);
if (status < 0) return -1;
*val = atof(strval);
free(strval);
return 0;
case H5T_FLOAT:
status = get_attribute(input, name, H5T_NATIVE_FLOAT, val);
if (status < 0) return -1;
return 0;
}
return -1;
}
示例11: p_get_type
//--------------------------------------------------------------------------
// Function: AbstractDs::getTypeClass
///\brief Returns the class of the datatype that is used by this
/// object, which can be a dataset or an attribute.
///\return Datatype class identifier
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
H5T_class_t AbstractDs::getTypeClass() const
{
// Gets the datatype used by this dataset or attribute.
// p_get_type calls either H5Dget_type or H5Aget_type depending on
// which object invokes getTypeClass
hid_t datatype_id;
try {
datatype_id = p_get_type(); // returned value is already validated
}
catch (DataSetIException E) {
throw DataTypeIException("DataSet::getTypeClass", E.getDetailMsg());
}
catch (AttributeIException E) {
throw DataTypeIException("Attribute::getTypeClass", E.getDetailMsg());
}
// Gets the class of the datatype and validate it before returning
H5T_class_t type_class = H5Tget_class(datatype_id);
if( type_class != H5T_NO_CLASS )
return( type_class );
else
{
if (fromClass() == "DataSet")
throw DataTypeIException("DataSet::getTypeClass", "H5Tget_class returns H5T_NO_CLASS");
else if (fromClass() == "Attribute")
throw DataTypeIException("Attribute::getTypeClass", "H5Tget_class returns H5T_NO_CLASS");
}
}
示例12: getNestedSizeType
size_t
getNestedSizeType(hid_t type_id) {
hid_t member_type_id;
H5T_class_t class_id;
hsize_t i, nfields;
size_t itemsize, offset;
nfields = H5Tget_nmembers(type_id);
offset = 0;
// Iterate thru the members
for (i=0; i < nfields; i++) {
// Get the member type
member_type_id = H5Tget_member_type(type_id, i);
// Get the HDF5 class
class_id = H5Tget_class(member_type_id);
if (class_id == H5T_COMPOUND) {
// Get the member size for compound type
itemsize = getNestedSizeType(member_type_id);
}
else {
// Get the atomic member size
itemsize = H5Tget_size(member_type_id);
}
// Update the offset
offset = offset + itemsize;
}
return(offset);
}
示例13: validateFloat3Attribute
/*-------------------------------------------------------------*/
static void validateFloat3Attribute(pNXVcontext self,
hid_t dpField, char *name)
{
hid_t attID, attType, attSpace;
H5T_class_t h5class;
hsize_t dims[2], maxDims[2];
char fname[512];
memset(fname,0,sizeof(fname));
H5Iget_name(dpField,fname,sizeof(fname));
if(!H5LTfind_attribute(dpField,name)){
NXVsetLog(self,"sev","error");
NXVprintLog(self,"message",
"Missing attribute %s on %s",
name, fname);
NXVlog(self);
self->errCount++;
} else {
attID = H5Aopen(dpField,name,H5P_DEFAULT);
assert(attID >= 0);
attType = H5Aget_type(attID);
assert(attType >= 0);
h5class = H5Tget_class(attType);
if(h5class != H5T_FLOAT){
NXVsetLog(self,"sev","error");
NXVprintLog(self,"message",
"%s attribute on %s is of wrong type, expected float",
name, fname);
NXVlog(self);
self->errCount++;
} else {
attSpace = H5Aget_space(attID);
if(H5Sget_simple_extent_ndims(attSpace) != 1){
NXVsetLog(self,"sev","error");
NXVprintLog(self,"message",
"%s attribute on %s is of wrong rank, expected 1",
name, fname);
NXVlog(self);
self->errCount++;
} else {
H5Sget_simple_extent_dims(attSpace,dims,maxDims);
if(dims[0] != 3){
NXVsetLog(self,"sev","error");
NXVprintLog(self,"message",
"%s attribute on %s is of wrong size, expected 3",
name, fname);
NXVlog(self);
self->errCount++;
}
}
H5Sclose(attSpace);
}
H5Tclose(attType);
H5Aclose(attID);
}
}
示例14: get_cols
/* fetch num_cols and the col for a particular trackname */
void get_cols(chromosome_t *chromosome, char *trackname, hsize_t *num_cols,
hsize_t *col) {
hid_t attr, root, dataspace, datatype;
hsize_t data_size, cell_size, num_cells;
char *attr_data;
/* Tracknames are stored in the attributes of the root group of each file */
root = H5Gopen(chromosome->h5group, "/", H5P_DEFAULT);
assert(root >= 0);
attr = H5Aopen_name(root, "tracknames");
assert(attr >= 0);
dataspace = H5Aget_space(attr);
assert(dataspace >= 0);
assert(H5Sget_simple_extent_dims(dataspace, num_cols, NULL) == 1);
assert(H5Sclose(dataspace) >= 0);
if (trackname && col) {
datatype = H5Aget_type(attr);
assert(datatype >= 0);
assert(H5Tget_class(datatype) == H5T_STRING);
cell_size = H5Tget_size(datatype);
assert(cell_size > 0);
data_size = H5Aget_storage_size(attr);
assert(data_size > 0);
num_cells = data_size / cell_size;
/* allocate room for tracknames */
attr_data = xmalloc(data_size);
assert(attr_data);
assert(H5Aread(attr, datatype, attr_data) >= 0);
*col = 0;
for (*col = 0; *col <= num_cells; (*col)++) {
if (*col == num_cells) {
fprintf(stderr, "can't find trackname: %s\n", trackname);
free(attr_data);
exit(EXIT_FAILURE);
} else {
if (!strncmp(attr_data + (*col * cell_size), trackname, cell_size)) {
break;
}
}
}
/* clean up read tracknames */
free(attr_data);
}
assert(H5Aclose(attr) >= 0);
}
示例15: validateDependsOnAttributes
/*--------------------------------------------------------------
This validates the lesser depends_on chain fields like
vector, offset and transformation_type
----------------------------------------------------------------*/
static void validateDependsOnAttributes(pNXVcontext self,hid_t dpField)
{
char fname[512], transData[512];
hid_t attID, attType, attSpace;
H5T_class_t h5class;
memset(fname,0,sizeof(fname));
memset(transData,0,sizeof(transData));
H5Iget_name(dpField,fname,sizeof(fname));
/*
deal with transformation_type
*/
if(!H5LTfind_attribute(dpField,"transformation_type")){
NXVsetLog(self,"sev","error");
NXVprintLog(self,"message",
"Missing attribute transformation_type on %s",
fname);
NXVlog(self);
self->errCount++;
} else {
attID = H5Aopen(dpField,"transformation_type",H5P_DEFAULT);
assert(attID >= 0);
attType = H5Aget_type(attID);
assert(attType >= 0);
h5class = H5Tget_class(attType);
if(h5class != H5T_STRING){
NXVsetLog(self,"sev","error");
NXVprintLog(self,"message",
"transformation_type on %s is of wrong type, expected string",
fname);
NXVlog(self);
self->errCount++;
} else {
H5NXget_attribute_string(self->fileID, fname,
"transformation_type",transData);
if(strcmp(transData,"translation") != 0
&& strcmp(transData,"rotation") != 0){
NXVsetLog(self,"sev","error");
NXVprintLog(self,"message",
"transformation_type on %s contains bad data: %s",
fname,
"expected rotation or translation");
NXVlog(self);
self->errCount++;
}
}
H5Tclose(attType);
H5Aclose(attID);
}
validateFloat3Attribute(self,dpField,"offset");
validateFloat3Attribute(self,dpField,"vector");
}