NCL Website header
NCL Home> Application examples> File IO || Data files for some examples

Example pages containing: tips | resources | functions/procedures > GRIB to netCDF

Converting GRIB (1 or 2) to netCDF

Note: Support for GRIB2 files was added in version 4.3.0.

Copy entire file

Some things to note for both methods list below:

  • NCL's assigned variable names may be long.
  • Coordinate variables will be added: gridlat_6, gridlon_6, gridlat_101, gridlon_101, etc.
  • GRIB parameter information is added as attributes of the variables.

Using ncl_convert2nc - the preferred method

In version 4.2.0.a034, a tool called ncl_convert2nc was created to convert all or part of a GRIB file to netCDF.

Here is the simplest usage:

    ncl_convert2nc ced1.lf00.t00z.eta.grb     ; version 4.2.0.a34
The above will create a netCDF file called "ced1.lf00.t00z.eta.nc".

Using an NCL script

Using an NCL script is useful if you need more control over the reading or writing of your files than what ncl_convert2nc can provide:

begin
;***********************************************
; get variable names from grib file
;***********************************************
   grib_in  = addfile("./ced1.lf00.t00z.eta.grb","r")   
   names    = getfilevarnames(grib_in); extract all variable names 
;***********************************************
; create output netcdf file
;*********************************************** 
   system("rm out.nc") ; remove any pre-existing file
   ncdf_out = addfile("out.nc" ,"c")       ; create output netCDF file
;***********************************************
; loop through variables and output each to netcdf
;***********************************************
   do i = 0, dimsizes(names)-1  
   ncdf_out->$names(i)$ = grib_in->$names(i)$
   end do   
end 
View the results from either method using ncl_filedump, or "ncdump" from the netCDF suite of tools:

    ncl_filedump out.nc

    ncdump -h out.nc
Click here for sample output.