GNU Octave

GNU Octave is MATLAB-like program that can read and visualize HDF5 file and OPeNDAP data source.

Download

Downloadexternal Octave. Octave can run on most UNIX (Linux/BSD/Mac) systems. Windows users can run Octave through Cygwin or MinGW.

Downloadexternal M_Map, a mapping package for Octave.

Installation

The easiest way to install Octave is through package manager on your system. For example, on CentOS, issue the following command:

#yum install octave

OPeNDAP access requires netcdf package.

Run octave first and enter the following command at the Octave prompt:

octave:1>pkg install -forge -verbose netcdf

For M_Map package, extract the package under your current working directory to follow the examples that we provide here.

Usage

We provide two examples of accessing NASA HDF products.

How to access HDF5 file

By default, Octave can read HDF5 file without any additional package. Open the sample NASA OMI L3 HDF-EOS5 fileexternal with load command (Figure 1).

% Load file.
load OMI-Aura_L3-OMTO3e_2017m0105_v003-2017m0203t091906.he5;
Figure 1. How to load HDF5 file in Octave

To load a dataset, just specify the path to the dataset with group names separated by dot (.) character as shown in Figure 2. Please replace space with '_'. Here, we assume that you can identify all groups and datasets inside the file with HDFViewexternal or h5dumpexternal.

% Load dataset.
data = HDFEOS.GRIDS.OMI_Column_Amount_O3.Data_Fields.ColumnAmountO3;
Figure 2. How to load HDF5 file in Octave

To plot data on the map, you need to load the M_Map library at the beginning and use the following functions that start with m_ as shown in Figure 3.

% Load map package.
addpath ./m_map
addpath ./m_map/private
...
m_proj('miller');
m_pcolor(lon, lat, data'); shading flat;
m_coast;
m_grid;
Figure 3. How to plot data on map using M_Map package

The rest of code is similar to other MATLAB comprehensive examples. The complete code is available here. The code will generate the plot in Figure 4.

In the above plot, we modified the colormap to use white color for fill value. You may want to compare it with MATLAB plot from our comprehensive examples.

How to access OPeNDAP Data Source

Octave can access OPeNDAP data source through NetCDF function calls. If you haven't installed NetCDF package for Octave, please read the Installation section and install the NetCDF package package first.

To open the sample NASA AIRS L3 HDF-EOS2 OPeNDAP data source URLexternal, load the NetCDF package first and call netcdf function (Figure 5).

% Load datasets.
pkg load netcdf
h = 'NASAFILES/hdf4/AIRS.2002.08.01.L3.RetStd_H031.v4.0.21.0.G06104133732.hdf';
f = ['https://eosdap.hdfgroup.org:8080/opendap/data/', h];
data = ncread(f, 'Temperature_MW_A');
Figure 5. How to load OPeNDAP data source in Octave

Unlike HDF5 access, Octave can access both variables and attributes through NetCDF calls. You can read attribute data using variable name and attribute name in ncreadatt function (Figure 6).

% Load attribute.
fillvalue = ncreadatt(f, 'Temperature_MW_A', '_FillValue');
Figure 6. How to access OPeNDAP attributes

The rest of the code is similar to HDF5 example above. The complete code is available here. The code will generate the plot in Figure 7.

Please note that you can modify the OPeNDAP example to make it work with a local NetCDF file. For example, you can convert the sample NASA AIRS L3 HDF-EOS2 fileexternal into a NetCDF-3 fileexternal with the h4tonccf tool. Then, you can load the converted file as illustrated in Figure 8.

% Load the h4tonccf-converted NetCDF file.
f = 'AIRS.2002.08.01.L3.RetStd_H031.v4.0.21.0.G06104133732.hdf.nc';
data = ncread(f, 'Temperature_MW_A');
Figure 8. How to load NetCDF file in Octave

The rest of the code is almost identical to OPeNDAP example above. The complete code is available here. The plot in Figure 9. shows that you can get the same plot through the NetCDF conversion.

See Also

  1. MATLAB Comprehensive Examples
  2. HDF5 OPeNDAP Handler
  3. HDF4 OPeNDAP Handler
  4. HDF4 CF Conversion Toolkit

Last modified: 02/10/2023
About Us | Contact Info | Archive Info | Disclaimer
Sponsored by Subcontract number 4400528183 under Raytheon Contract number NNG15HZ39C, funded by NASA / Maintained by The HDF Group