Skip Navigation Links 
NOAA logo - Click to go to the NOAA home page National Weather Service   NWS logo - Click to go to the NWS home page
Climate Prediction Center

About Us
   Our Mission
   Who We Are

Contact Us
   CPC Information
   CPC Web Team

HOME > Monitoring_and_Data > Oceanic and Atmospheric Data > Reanalysis: Atmospheric Data > - grib1 to grib2 converter does not work with wgrib2 v2.0.0. Please use wgrib2 v1.9.9 or v2.0.1+. converts grib1 files to grib2. This perl script uses wgrib, wgrib2 and a few minor programs that are included with the wgrib2 package (gmerge, smallest_grib2). Here are some of the advantages of,

  • Easier than some other solutions to compile.
    Many repositories include wgrib2 executables
    wgrib, gmerge and smallest_grib2 are very easy to compile C programs
  • More fields converted than some other solutions. Easy to modify code for new fields.
  • Does c0 packing, the smallest of 3 different complex packings
  • Complex packing algorithms produce fast-to-read grib2 files which are comparable in size to jpeg2000 packing.
  • Fast packing option which is optimized for 4-core CPUs
Disadvanges are
  • Ensemble metadata are not supported (grib1 ensemble metadata are locally defined)
  • POSIX2 required, no Windows support
  • limited to lat-lon, polar stereographic, Lambert conformal, Mercator, and Gaussian grids
  • other grids can be handled if the appropriate grib2 template is supplied.
  • Doesn't convert from grib2 to grib1.
  • Quits when finds a problem grid. You need to alter perl script to handle grid before continuing.
  • only simple scan mode options are handled, latlon: we:sn and we:ns, others: we:sn (needs to improved)
Requirements are
  • wgrib2 with IPOLATES enabled (-new_grid option)
  • wgrib
  • gmerge and smallest_grib2, only needed by -fast and -packing c0 (default), supplied in aux_progs directory of wgrib2
  • perl
  • POSIX2 environment

History is based on code that was written in 12/2009 at CPC and versions of the code are being used at CPC. Variants of the code were written for (1) speed, (2) large files, (3) ease of updating and/or (4) potential operational usage. The latest version (4/2014) had a name change (grib1to2 had been taken), large file support was dropped (not needed with a 64-bit OS) and most importantly installion was made easier by eliminating the need for cnvgrib. This version retains radius of the earth from the grib1 file unlike the previous versions.

How it works works by

  1. interpolating the generic template file to the same grid as the grib1 file to make the grib2 template
  2. adding metadata (center, subcenter, process, shape of earth) to the template
  3. converting grib1 file to binary
  4. making a simple inventory of grib1 file (inv1)
  5. making a long inventory of grib1 file (inv2)
  6. combines inv1 and inv2 to make a metadata file (wgrib2 inv + extra fields)
  7. wgrib2 converts binary data + metadata + template into a grib2 file

Usage [list of options] INPUT_GRIB1_FILE

Runtime Options:
   -fast                         converts the file faster by running 3 streams of processing
                                 harder to debug
   -packing [c0|c1|c2|c3|j|s]    set packing format for grib2 files
                                 s = simple packing
                                 j = jpeg2000 packing
                                 c1 = complex packing of values
                                 c2 = complex packing of increments
                                 c3 = complex packing of increments of increments
                                 c0 = best packing of c1, c2 and c3 (packing for each field is independent)
   -ncep_uv                      U and V are saved to the same grib message (typical of NCEP operations)
   -o OUTPUT_GRIB2_FILE          output file, default is INPUT_GRIB1_FILE.grb2
   -grid_template filename       location of specific grib2 file (correct grid and metadata)
                                    default for for to create the grid_template file

Configuration Options:
   -gmerge filename              set location of gmerge executable
   -smallest_grib2 filename      set location of smallest_grib2 executable
   -wgrib filename               set location of wgrib
   -wgrib2 filename              set location of wgrib2
   -template filename            set location of sample grib2 file

Note: if has been configured, the configuration options should have the
appropriate default values.  To see the default values, type

Adding Ensemble Member Number

The current grb1to2 does not handle ensemble information. You can handle this by running wgrib2 after the convertion to grib2. For example, I had ensemble members 001..080.

After conversion to grib2 by
Bash/Bourne shell script to add ENS=+N informtion
      for f in pgrbfg_1964102112_fhr00_mem???.grb2
         n=`echo $f | sed -e 's/.*mem//'  -e 's/.grb2//'`
         wgrib2 $f -set_ens_num 3 $n 80 -grib $f.ens
Results after running the above script.


The basic installation consists of wgrib, wgrib2+aux_progs and 3 new files. (See) Wgrib2 needs to be compiled with the IPOLATES option. (See wgrib2 documentation.)
  1. $HOME/bin/wgrib
  2. $HOME/bin/wgrib2
  3. $HOME/bin/gmerge (included with wgrib2), see grib2/aux_progs of the wgrib2 compilation directory
  4. $HOME/bin/small_grib2 (included with wgrib2), see grib2/aux_progs of the wgrib2 compilation directory
  5. $HOME/bin/
  6. $HOME/bin/
  7. $HOME/bin_data/global_template.g2
If you want change the default locations of these files, you have to modify This is the section to customized the stock version.
# This section needs to be customized
require ("$ENV{'HOME'}/bin/");
# end of customization
You can also modify global_template.g2 to add site specific metadata.


5/2014: v1.1 fixed Mercator conversion, dx, dy now in m instead of km

Comments:, updated 5/12/2014, 11/04/2014

NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5830 University Research Court
College Park, Maryland 20740
Climate Prediction Center Web Team
Page last modified: Oct 19, 2015
Disclaimer Privacy Policy