Hi Roland,
This is the function I use to write an N-dim array of strings (String is std::string).
(it encapsulates a hid_t in an object, but I have removed that; hence you do not see close functions for a hid_t).
I hope it is clear.
Cheers,
Ger
void HDF5Record::writeArrayString (hid_t groupHid, const String& name,
const Array<String>& value)
{
// It seems that HDF5 cannot handle empty strings.
char* emptystr = "__empty__";
std::vector<char*> ptrs(value.nelements());
// Copy the string pointers to a vector.
Array<String>::const_iterator aiter=value.begin();
for (std::vector<char*>::iterator viter = ptrs.begin();
viter!=ptrs.end();
++aiter, ++viter) {
if (aiter->empty()) {
*viter = emptystr;
} else {
*viter = (char*)(aiter->c_str());
}
}
// Create the data space for the array.
const IPosition& shape = value.shape();
int rank = shape.nelements();
// Convert the shape to a vector of hsize_t.
std::vector<hsize_t> ls = HDF5DataSet::fromShape (shape);
hid_t dsid = H5Screate_simple(rank, &(ls[0]), NULL));
// Create the attribute.
hid_t dtid = H5Tcopy (H5T_C_S1);
H5Tset_size (dtid, H5T_VARIABLE);
hid_t id = H5Acreate(groupHid, name.c_str(), dtid,
dsid, H5P_DEFAULT, H5P_DEFAULT);
H5Awrite(id, dtid, &(ptrs[0]);
}
Roland Schwarz <roland.schwarz@chello.at> 05/09/08 11:47 AM >>>
I am trying to specify my data as a "ragged array" as
mentioned in the hdf documentation.
I.e. I create a 2-d dataspace containing elements of
compound type: "variable length". This shall give me
efectively a 3-d array with the third dimension of
variable length.
However I cannot find out, how I would specify the actual
length of the variable length. I cannot find anything
in the docs, nor can I find an example. I looked both
in the C and C++ API descriptions.
Could someone possibly point me to something that
is of help in this matter?
Thank you,
···
--
_________________________________________
_ _ | Roland Schwarz
>_)(_ | aka. speedsnail
> \__) | mailto:roland.schwarz@chello.at
________| http://www.blackspace.at
----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.
----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.