#ifdef OLD_HEADER_FILENAME
#include <iostream.h>
#else
#include <iostream>
#endif
using std::cout;
using std::endl;
#include <string>
#include "H5Cpp.h"
const H5std_string FILE_NAME( "SDScompound.h5" );
const H5std_string DATASET_NAME( "ArrayOfStructures" );
const H5std_string MEMBER1( "a_name" );
const H5std_string MEMBER2( "b_name" );
const H5std_string MEMBER3( "c_name" );
const int LENGTH = 10;
const int RANK = 1;
int main(void)
{
typedef struct s1_t {
int a;
float b;
double c;
} s1_t;
typedef struct s2_t {
double c;
int a;
} s2_t;
try
{
int i;
s1_t s1[LENGTH];
for (i = 0; i< LENGTH; i++)
{
s1[i].a = i;
s1[i].b = i*i;
s1[i].c = 1./(i+1);
}
Exception::dontPrint();
hsize_t dim[] = {LENGTH};
mtype1.insertMember( MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT);
mtype1.insertMember( MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_DOUBLE);
mtype1.insertMember( MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_FLOAT);
dataset->
write( s1, mtype1 );
delete dataset;
delete file;
file =
new H5File( FILE_NAME, H5F_ACC_RDONLY );
mtype2.insertMember( MEMBER3, HOFFSET(s2_t, c), PredType::NATIVE_DOUBLE);
mtype2.insertMember( MEMBER1, HOFFSET(s2_t, a), PredType::NATIVE_INT);
s2_t s2[LENGTH];
dataset->
read( s2, mtype2 );
cout << endl << "Field c : " << endl;
for( i = 0; i < LENGTH; i++)
cout << s2[i].c << " ";
cout << endl;
cout << endl << "Field a : " << endl;
for( i = 0; i < LENGTH; i++)
cout << s2[i].a << " ";
cout << endl;
mtype3.insertMember( MEMBER2, 0, PredType::NATIVE_FLOAT);
float s3[LENGTH];
dataset->
read( s3, mtype3 );
cout << endl << "Field b : " << endl;
for( i = 0; i < LENGTH; i++)
cout << s3[i] << " ";
cout << endl;
delete dataset;
delete file;
}
{
return -1;
}
{
return -1;
}
{
return -1;
}
{
return -1;
}
return 0;
}
CompType is a derivative of a DataType and operates on HDF5 compound datatypes.
Definition H5CompType.h:25
Class DataSet operates on HDF5 datasets.
Definition H5DataSet.h:28
void write(const void *buf, const DataType &mem_type, const DataSpace &mem_space=DataSpace::ALL, const DataSpace &file_space=DataSpace::ALL, const DSetMemXferPropList &xfer_plist=DSetMemXferPropList::DEFAULT) const
Writes raw data from an application buffer to a dataset.
Definition H5DataSet.cpp:498
void read(void *buf, const DataType &mem_type, const DataSpace &mem_space=DataSpace::ALL, const DataSpace &file_space=DataSpace::ALL, const DSetMemXferPropList &xfer_plist=DSetMemXferPropList::DEFAULT) const
Reads raw data from the specified dataset.
Definition H5DataSet.cpp:422
Definition H5Exception.h:137
Class DataSpace inherits from IdComponent and provides wrappers for the HDF5's dataspaces.
Definition H5DataSpace.h:25
Definition H5Exception.h:109
Definition H5Exception.h:116
static void printErrorStack(FILE *stream=stderr, hid_t err_stack=H5E_DEFAULT)
Prints the error stack in a default manner.
Definition H5Exception.cpp:302
Definition H5Exception.h:95
Class H5File represents an HDF5 file and inherits from class Group as file is a root group.
Definition H5File.h:25
DataSet openDataSet(const char *name, const DSetAccPropList &dapl=DSetAccPropList::DEFAULT) const
DataSet createDataSet(const char *name, const DataType &data_type, const DataSpace &data_space, const DSetCreatPropList &create_plist=DSetCreatPropList::DEFAULT, const DSetAccPropList &dapl=DSetAccPropList::DEFAULT, const LinkCreatPropList &lcpl=LinkCreatPropList::DEFAULT) const
Definition H5AbstractDs.cpp:34