Project

General

Profile

Converting HDF format to netcdf

Added by nazanin tavakoli about 3 years ago

Hello everyone,
I want to convert the HDF file to a NetCDF which has a longitude and latitude. Is there any chance to do this in CDO?


Replies (5)

RE: Converting HDF format to netcdf - Added by nazanin tavakoli about 3 years ago

Thank you for your response. I know that we can convert hdf to nc in NCO or Gdal, but it is easy to do this in CDO (If we could):)

RE: Converting HDF format to netcdf - Added by Brendan DeTracey about 3 years ago

I don't know. But while you are waiting for an answer, why not try it and see? :)

cdo -f nc copy MCD12Q1.A2001001.h29v12.006.2018143033623.hdf test.nc

That looks like a MODIS hdf file of some sort. That means it is probably not CF-Metadata compliant. (https://cfconventions.org/) You can test for such compliance here: https://pumatest.nerc.ac.uk/cgi-bin/cf-checker.pl
The first paragraph of the introduction of the cdo documentation (https://code.mpimet.mpg.de/projects/cdo/embedded/index.html#x1-20001) states:
The Climate Data Interface [CDI] is used for the fast and file format independent access to GRIB and NetCDF datasets. The local MPI-MET data formats SERVICE, EXTRA and IEG are also supported.

There are some limitations for GRIB and NetCDF datasets:

GRIB
datasets have to be consistent, similar to NetCDF. That means all time steps need to have the same variables, and within a time step each variable may occur only once. Multiple fields in single GRIB2 messages are not supported!
NetCDF
datasets are only supported for the classic data model and arrays up to 4 dimensions. These dimensions should only be used by the horizontal and vertical grid and the time. The NetCDF attributes should follow the GDT, COARDS or CF Conventions

Does your file fit in those categories? Some netcdf file readers will read some hdf files, but only because some netcdf files are in hdf. Try it and see, but I doubt it.

RE: Converting HDF format to netcdf - Added by nazanin tavakoli about 3 years ago

I think CDO doen't support hdf4.I have tried this code (cdo -f nc copy MCD12Q1.A2001001.h29v12.006.2018143033623.hdf test.nc),but I have this error"
cdo copy/selall : UNCHANGED_RECORD=0
cdo copy/selall : cdiGribDataScanningMode=0; lcopy=0

cdo copy: Open failed on >MCD12Q1.A2001001.h29v12.006.2018143033623.hdf <
Unsupported file type

    (1-5/5)