Search code examples
hdf5typeconverterdm-script

How to read string stored in hdf5 format files by DM


I am scripting with DM and would like to read hdf5 file format.

I borrowed Tore Niermann's gms_HDF5_Plug-In (hdf5_GMS2X_amd64.dll) and his CMD_import_hdf5.s script. It use h5_read_dataset(filename, datapath) to read a image dataset.

I am trying to figure out the way to read a string info stored in the same file. I am particular interested to read the angle stored in string as shown in this figure.Demonstrated string to read. The h5_read_dataset(filename, datapath) function doesn't work for reading string.

There is a help file (hdf5_plugin.chm) with a list of functions but unfortunately I can't open them to see more info. hdf5_plugin.chm showing the function list.

I suppose the right function to read strings should be something like h5_read_attr() or h5_info() but I didn't test them out. DM always says the two functions doesn't exist.

After reading out the angle by string, I will also need a bit help to convert the string to a double datatype.

Thank you.


Solution

  • Converting String to Number is done with the Val() command. There is no integer/double/float concept for variables in DM-script, all are just number. ( This is different for images, where you can define the numeric type. Also: For file-inport/export a type differntiation can be made using the taggroup streaming commands in the other answer. )

    Example script:

    string numStr = "1.234e-2"
    number num = val( numStr )
    ClearResults()
    Result( "\n As string:" + numStr )
    Result( "\n As value:" + num )
    Result( "\n As value, formatted:" + Format(num,"%3.2f") )