Norwegian Service Centre for Climate Modelling -> Format Conversion Tools -> gribtonc User Guide
 
 

 

     

GRIB to netCDF

The conversion is performed with the program gribtonc from UCAR. This conversion program requires that the netCDF-file exists already (in case of add/update) or that a special CDL-file is used in the creation of a new netCDF-file. CDL-files are awkward to write, so a special tool is provided by NoSerC to assist in the process. With the program gribtocdl the user can have the CDL-file created based on the content of the GRIB-file. This CDL-file may then be manually edited or used directly in the actual conversion to netCDF.

To ease the process when converting GRIB data where the UCAR GRIB definition is not used, a special version of gribtonc has been prepared by NoSerC. A new option -g tabfile allows the user to supply a translation table so that GRIB codes can be correctly named in netCDF. See also explanation under gribtocdl below.

The gribtonc manpage is provided for explanation of usage.

The modified version of gribtonc and the new gribtocdl are available for download, see References/downloads.

GRIB to CDL

This program, gribtocdl, developed by NoSerC based on the program gribdump from UCAR, will try to read GRIB-files and generate a CDL-file with the information necessary to convert from GRIB to netCDF. The actual conversion to netCDF is then performed by gribtonc.

Usage of the program is simple:

gribtocdl [options] [gribfiles] > cdlfile

Valid options are:
 -v           Verbose, report decoding steps to stderr
 -g tabfile   Use grib-netcdf translation defined in this file

The gribtocdl manpage is also provided.

The interpretation of GRIB is based on WMO GRIB with extensions. For an explanation of the GRIB parameters recognized and how the netCDF parameter names are constructed, see the default parameter table. The different levels recognized are detailed in the levels table.
It is also possible to declare your own translation table for the conversion from grib to netCDF; edit a separate file and use this as input with the -g tabfile option. This must be done for both gribtocdl and gribtonc!
The format of the translation table is as follows:
Each line contains

  • grib parameter number
  • netCDF parameter name
  • netCDF long description
  • netCDF units
  • An optional comment
These are all separated by semicolon (";"). To comment a whole line, put any letter or special character (i.e. not a digit) in front of it. Trailing spaces are ignored before each semicolon, but not after.
The grib number may have spaces in front.
Parameters found in the separate file take presedence over the default parameter table, those not listed in the separate file are unchanged.
All parameters will be named with a level suffix in addition to the name assigned in the separate file. See the levels table for explanation of level suffix.
A sample translation file that shows the ECMWF local table 2 version 128 has been provided to show how you may write your own translation table.

Note that GRIB-files exist in many flavours, so always verify that the generated CDL-file is valid before starting large-scale conversions. It may be that a specific parameter or grid definition is not recognized, or incorrectly translated to netCDF. First take a look at the generated CDL-file, then try to convert the GRIB-file as shown below. Inspect the log-file to ensure that the conversion really was done. In many cases the CDL-file can be edited to overcome limitiations in gribtocdl, if in doubt, contact NoSerC. To change parameter names, edit the translation file and use option -g tabfile.

Also remember that the CDL-file may only need to be generated once, to create a template for netCDF-files, when there are many GRIB-files to be converted. If you have one GRIB-file for each time-period, then you only need to use gribtocdl for the first file. Each similar file conversion may then re-use the CDL-file. Also, if you want to merge files, it is possible to manually edit in the CDL-file new parameters. Use gribtocdl on each GRIB-file and manually merge the generated CDL-files before converting each GRIB-file to a single netCDF-file.

A sample run of the tools is shown below along with the generated files. In this example, a GRIB-file grdh12r.grb is converted to netCDF (grdh12r.nc) by first generating the corresponding CDL-file (grdh12r.cdl) with gribtocdl and then using this file with gribtonc to generate the netCDF-file:

rm g2nc.log grdh12r.nc
gribtocdl grdh12r.grb > grdh12r.cdl
gribtonc -l g2nc.log -v grdh12r.cdl grdh12r.nc < grdh12r.grb

Note that the generated netCDF-file is manually deleted before the conversion, as the default action in gribtonc is to append data.
The CDL-file was generated as grdh12r.cdl

The conversion to netCDF produced a logfile g2nc.log
 


Send comments to webmaster