hfive2structdocumentation

h5structloads HDF5 data into a Matlab stucture with the same hierarchy as the original file.

Back to Climate Data Tools Contents.

Contents

Syntax

data = hfive2struct(文件名)data = hfive2struct(filename, dataset) data = hfive2struct(filename, dataset, true) data = hfive2struct(filename, [], true)

Description

data = hfive2struct(文件名)loads all attibutes, dataset values and dataset atributes of the h5 filename into a Matlab stucture with the same hierarchy as the original file. [currenlty handles up to 11 group levels]

data = hfive2struct(filename, dataset)只加载requested dataset and associated attibutes of filename into a Matlab stucture with the same hierarchy as the original filename.datasetis the full h5 path to the desired dataset. dataset can be specified as either a string or cell array of stings e.g. /path/to/dataset or {path/to/dataset1, path/to/dataset2}.

data = hfive2struct(filename, dataset, fill_with_nan)只加载requested dataset and associated attibutes of filename into a Matlab stucture. If fill_with_nan = true, all single and double datasets having a _FillValue will have _FillValue replaced with NaNs.

User Input

Example 1

Load in all data from an h5 file:

D = h5struct('altimetry_example.h5');

Now here are the structured contents ofD

D
D = struct with fields: elevation: [1×1 struct] latitude: [1×1 struct] longitude: [1×1 struct] Attributes: [1×1 struct] ancillary_data: [1×1 struct] instrument_parameters: [1×1 struct]

To access one of the fields ofD, followDwith a.and then the field name. For example, to access the elevation data, do so like this:

D.elevation
ans = struct with fields: Value: [236379×1 single] Attributes: [1×1 struct]

The elevation measurements reside in theD.elevation.Valuefield, and information about the elevation data can be found inD.elevation.Attributes. Here are the attributes of the elevation data:

D.elevation.Attributes
ans = struct with fields: h5es_id: 4 units: 'meters' long_name: 'elevation' standard_name: 'elevation' description: 'Elevation of the laser spot above ellipsoid'

Plot elevation and signal strength as a 3D scatterplot:

figure scatter3(D.longitude.Value, D.latitude.Value, D.elevation.Value,...2, D.instrument_parameters.rcv_sigstr.Value,'filled')% Add a grid and some labels:gridonxlabel(D.longitude.Attributes.units,'interpreter','none'); ylabel(D.latitude.Attributes.units,'interpreter','none'); zlabel(D.elevation.Attributes.units,'interpreter','none'); cb = colorbar; ylabel(cb,D.instrument_parameters.rcv_sigstr.Attributes.long_name) axistight

Example 2

If you only need some of the data in an HDF5 file, you may prefer to only load the data Here's how:

dataset = {'/instrument_parameters/rel_time','/elevation'}; D = h5struct('altimetry_example.h5', dataset);

This time we only loaded the elevation data and the relative time. Here's whatDlooks like:

D
D = struct with fields: instrument_parameters: [1×1 struct] elevation: [1×1 struct]

Similar to Example 1, plot elevation vs. relative time

figure plot(D.instrument_parameters.rel_time.Value, D.elevation.Value,'.','markersize',0.5)% add a grid and some labelsgridonxlabel(D.instrument_parameters.rel_time.Attributes.units,'interpreter','none'); ylabel(D.elevation.Attributes.units,'interpreter','none'); axistight

Author Info

This function and supporting documentation were written by Alex S. Gardner, JPL-Caltech, Oct 2018.