How to define units for HDF5?

Hello,

how can I mark components of an compound with physical units ?

I found H5:DataType::setTag() and tried the following:
DataType *dt_unit = new DataType(Pred_Type::NATIVE_DOUBLE);
dt_unit->setTag(“m”);

Here HDF5 throws an exception, because the base type is not a OPAQUE-type.

Is there an other solution ?
Regards
Rudolf

Hi @rudolf_vinzenz_johan,

As you found out, only a member (of a compound) that is of data type opaque may have a tag attached to it. That said, one solution could be to have an additional member that describes the physical units of a certain member.

To illustrate this, here is an example in C++ using HDFql (not sure how this is done with other APIs):

// create an HDF5 file named 'test.h5' and use (i.e. open) it
HDFql::execute("CREATE AND USE FILE test.h5");

// create compound dataset named 'dset' with four members (to store two values and their physical units)
HDFql::execute("CREATE DATASET dset AS COMPOUND(m1_value AS DOUBLE, m1_unit AS VARCHAR, m2_value AS DOUBLE, m2_unit AS VARCHAR)");

// populate dataset 'dset' by assigning values to members 'm1_value' and 'm2_value' and setting their physical units in members 'm1_unit' and 'm2_unit' respectively
(...)

Hope it helps!