readhdf5

Reads data from a given HDF5 file.

Syntax

output = readhdf5(filename, datasetPath, dataPointsCoordinates)

Inputs

filename
Path to the HDF5 file.
Type: string
datasetPath
Fully qualified path of the dataset in the file.
Type: string
dataPointsCoordinates (optional)
Reads all data points if no data points are provided.
2D matrix – Each row corresponding to a point in the data space and each column corresponding to the data point coordinate the data dimension. For example, in N dimensional dataset, each row contains N columns.
Type: matrix

Outputs

output
Type: cell
When data is requested using dataPointsCoordinates, the output cell contains N*1 Matrix/Cell, where N is the number of points requested
Table 1. Data Type Mapping: Output Cell Contains the Following OML Data Types:
HDF Data Type OML Variable Type Limitation
Integer/Float Number/ND matrix  
String String/ND Cell  
Compound Struct Field name as key and data as value associated with key (field name). Integer, Float and String data only read from Compound data.
Bitfield   Not supported.
Opaque   Not supported.
Reference Number/ND matrix Only object references are supported.
Enum   Not supported.
Variable length   Not supported.
Array   Not supported.
Images Number/ND matrix  
Time Number/ND matrix  
Other Data   Not yet supported.

Example 1

The returned cell with compound data in it.
output=readhdf5('plate_linear_static.hdf5','/OptiStruct/RESULT/Subcase 1/ELEMENT_FORCE/QUAD4')
      output = 
        {
          [1,1] struct [
          BMX: [Matrix] 10000 x 1 Rows[1:30] Column[1]
           151.80786
           156.49155
           161.25160
           147.32631
           149.64325
           156.68770
           ....
           -11.56703
            11.37910
          ]
        }

Example 2

The returned cell with requested data points.
output=readhdf5('plate_linear_static.hdf5','/OptiStruct/RESULT/Subcase 1/ELEMENT_FORCE/QUAD4',[1;3])
      output = 
        {
          [1,1] struct [
          BMX: [Matrix] 2 x 1
          151.80786
          161.25160
          BMXY: [Matrix] 2 x 1
          18.95139
          19.64923
          BMY: [Matrix] 2 x 1
          666.46246
          687.50623
          Element ID: [Matrix] 2 x 1
          1
          3
          MX: [Matrix] 2 x 1
          0
          0
          MXY: [Matrix] 2 x 1
          0
          0
          MY: [Matrix] 2 x 1
          0
          0
          TX: [Matrix] 2 x 1
          1.70260
          1.81525
          TY: [Matrix] 2 x 1
          -11.61858
          -11.83540
          ]
        }

Example 3

The returned cell with requested data points.
output=readhdf5('plate_linear_static.hdf5','/OptiStruct/RESULT/Subcase 1/ELEMENT_FORCE/QUAD4',[1:3]')
      output = 
        {
          [1,1] struct [
          BMX: [Matrix] 3 x 1
          151.80786
          156.49155
          161.25160
          BMXY: [Matrix] 3 x 1
          18.95139
          19.32002
          19.64923
          BMY: [Matrix] 3 x 1
          666.46246
          676.95209
          687.50623
          Element ID: [Matrix] 3 x 1
          1
          2
          3
          MX: [Matrix] 3 x 1
          0
          0
          0
          MXY: [Matrix] 3 x 1
          0
          0
          0
          MY: [Matrix] 3 x 1
          0
          0
          0
          TX: [Matrix] 3 x 1
          1.70260
          1.75885
          1.81525
          TY: [Matrix] 3 x 1
          -11.61858
          -11.72467
          -11.83540
          ]
        }

Example 4

Compound data with object reference.
output=readhdf5('spice_inv2.dhdf','/Model/Variables')
      output = 
    {
      [1,1] struct [
        BlockNumber: [Matrix] 71 x 1 Rows[1:20] Column[1]
        0
        0
        0
        ...
        name: 
        {
          [1,1] CheckPoint pointer
          [2,1] Checkpoint depth
          ...
        objectId: [Matrix] 71 x 1 Rows[1:20] Column[1]
        68928
        68928
        69528
        69800
        70400
        71000
        ...
      ]
    }

Comments

Known limitations include:
  • Committed datatype is not supported.
  • Data points selection from previous readhdf5 command is not retained.
  • Hyper slabs selection is not supported.
  • Data with more than seven dimensions is not supported. However, data with more than seven dimensions can be read by inputting dataPointsCoordinates.
  • Nested compound data with int/float only supported.

To read HDF4 files, use an HDF4 to HDF5 converter and use the converted file with HDF5 reader commands. Go to the following location to download the converter: https://support.hdfgroup.org/products/hdf5_tools/h4toh5/download.html

Help: https://support.hdfgroup.org/ftp/HDF5/releases/tools/h4toh5/h4toh5-2.2.3/src/unpacked/doc/h4toh5lib_RM.html#Tools-h4toh5