#ifdef OLD_HEADER_FILENAME #include #else #include #endif #include #ifndef H5_NO_NAMESPACE #ifndef H5_NO_STD using std::cerr; using std::cout; using std::endl; #endif // H5_NO_STD #endif #include "testhdf5.h" // C test header file #include "H5Cpp.h" // C++ API header file #ifndef H5_NO_NAMESPACE using namespace H5; #endif #define SPACE1_DIM1 4 #define SPACE1_RANK 1 #define DSET_VLSTR_NAME "vlstr_type" static int test_vlstr_dtype() { const char *wdata[SPACE1_DIM1]= { "Four score and seven years ago our forefathers brought forth on this continent a new nation,", "conceived in liberty and dedicated to the proposition that all men are created equal.", "Now we are engaged in a great civil war,", "testing whether that nation or any nation so conceived and so dedicated can long endure." }; /* Information to write */ char *rdata[SPACE1_DIM1]; /* Information read in */ hid_t native_type; /* Datatype ID */ hsize_t dims1[] = {SPACE1_DIM1}; H5File file("varlen.h5", H5F_ACC_TRUNC); /* Create dataspace for datasets */ DataSpace sid1(SPACE1_RANK, dims1); /* Create a datatype to refer to */ StrType tid1(0, H5T_VARIABLE); if(H5T_STRING!=H5Tget_class(tid1.getId()) || !H5Tis_variable_str(tid1.getId())) cerr << "this is not a variable length string type!!!" << endl; /* Create a dataset */ DataSet dataset = file.createDataSet(DSET_VLSTR_NAME, tid1, sid1); /* Write dataset to disk */ dataset.write((void*)wdata, tid1); /* Close Dataset */ dataset.close(); /* Open a dataset */ dataset = file.openDataSet(DSET_VLSTR_NAME); /* Get datatype for dataset */ DataType dtype = dataset.getDataType(); /* Construct native type */ if((native_type=H5Tget_native_type(dtype.getId(), H5T_DIR_DEFAULT))<0) cerr << "H5Tget_native_type failed!!! " << endl; /* Check if the data type is equal */ if(!H5Tequal(native_type, tid1.getId())) cerr << "native type is not tid1!!!" << endl; /* Read dataset from disk */ dataset.read((void*)rdata, dtype); /* Validate and print data read in */ cout << "data read:" << endl; for(unsigned i=0; i