Skip Navigation Links www.nws.noaa.gov 
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 > Grib2ctl
 

grib2ctl

Grib2ctl takes GRIB files and makes GrADS control files.
For GRIB-2 files, see g2ctl.

Grib2ctl started out as 89-line shell script (not including comments). While limited, it worked well enough to create control files for gigabytes of GRIB data. Since then, the program has grown and has been converted to perl.

Grib2ctl.pl works on unix/linux and windows 95+. I will not answer questions about using grib2ctl under windows because I lack expertise in this area. (Elves keep grib2ctl compatible with windows.) The GrADS user mailing list is a useful resource. Please check the archives before asking a question.

News

5/06: version supports for thinned (reduced) lat-lon and gaussian grids.
 
You have to upgrade to wgrib v1.8.0.12, and GrADS v1.9b4. Interpolation to the GrADS working grid (lat-lon) is done by a nearest grid point on the same latitude. People are welcome to write a better interpolation scheme.
 
12/06: over the last half year, improvements to the code that handles the vertical coordinates. Code is stable again.

Usage

For analyses:

$ grib2ctl.pl grib_file >grib_file.ctl
$ gribmap -i grib_file.ctl -0    <-- this is a zero
$ grads
Landscape mode? (no for portrait):
ga-> open grib_file.ctl

For forecasts:

$ grib2ctl.pl -verf grib_file >grib_file.ctl
$ gribmap -i grib_file.ctl
$ grads
Landscape mode? (no for portrait):
ga-> open grib_file.ctl

Note: grib files can have 1, 2 or 3 times associated with each record. For example, an analysis will have only 1 time. However, a 24 hour forecast will have two times, the start time of the forecast and the verification time (24 hours after the start time). Now the average 12-18 hour forecast precipitation will have 3 times: the start of the forecast, the start of the averaging period and the end of the averaging period.

Gribmap takes the GRIB file and finds the time and location of each grib message and writes the essential information into an index file. Now which time is used depends on the gribmap option: nothing or -0. With no gribmap option, gribmap give the verification time or the end of the averaging period. With a -0 option, gribmap uses the start time of the forecast, analyses time or the beginning of the averaging period.

Template Option

grib2ctl.pl now supports the tempplate option (v0.9.12.5p33j).

$ grib2ctl.pl cpc_mon_mean.%y4%m2 >cpc_mon.ctl
The filename uses the standard GrADS wild cards except %mc:
%y2 2 digit year
%y4 4 digit year
%m1 1 or 2 digit month (month=1..12)
%m2 2 digit month (month=01..12)
%d1 1 or 2 digit day (day=1..31)
%d2 2 digit day (day=01..31)
%h1 1 or 2 digit hour (hour=0..23)
%h2 2 digit hour (hour=0..23)
%f2 2 or 3 digit forecast hour
%f3 3 digit forecast hour
Restrictions: (1) a sort of the file names has to put the files in chronological order,
(2) missing files are not handled well.
(3) the wildcards have to form a single date code, %y4_%m2_%d2 is not allowed.
(4) filenames cannot use regular-expression special characters; i.e., +(){}?*[]\
 

Unix/Linux Installation:

  1. Install wgrib v1.8+ and make sure wgrib is on your path.
    (see http://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html)
  2. Find where they hid perl (eg. /usr/bin/perl). If necessary, obtain perl from a system tape/cd-rom or off the internet.
  3. Run perl with the -v option to determine the version (eg. /usr/bin/perl  -v)
    If you are running version 4 or earlier, curse the universe for having
    to work with obsolete gear and obtain an updated perl.
  4. Change the first line of grib2ctl.pl to
       #!(location of perl)  -w
    For example,
       #!/usr/bin/perl  -w
  5. Look for the line:
       $wgrib='wgrib';
    and change it to point to your copy of wgrib. For example,
       $wgrib='/usr/local/bin/wgrib';
  6. (Optional) Look for the line:
       $pdef_dir='/usr/local/lib/grads';
    and change it to point to your grads directory. In the future, some unviewable grids (ex. thinned grids, native eta) will be handled by interpolation files.
  7. The $pdef_dir is the directory used to store "pdef" files. As of 2/2006, only one grid (221, nearest neighbor) uses the pdef directory.

Windows Installation (not supported, YMMV):

  1. Install wgrib v1.8+ and make sure wgrib and dll is on your path.
    (see http://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html)
  2. Send an email asking when grib2ctl.pl will be converted into Visual Basic.
  3. Receive an email saying, "Never."
  4. Download perl from the web.
  5. Install perl.
  6. Follow steps 4-6 in Unix/Linux install.
  7. doesn't work? See heading: not supported

Windows Installation using cygwin (not supported, YMMV) from Efren Serra:

  1. Install cygwin
  2. Blow PCGrADS cygwin1.dll away (WNE: PCGrADS has old version?)
  3. Change grib2ctl.pl from $pdef_dir=(something); to $pdef_dir="/cygdrive/c/Program\ Files/PCGrADS';
  4. Change grib2ctl.pl from $ListA="c:\\g$$.tmp"; to $ListA="/cygdrive/c/g$$.tmp";
  5. Change grib2ctl.pl from $TmpFile="c\\h$$tmp"; to $TmpFile="/cygdrive/c/h$$$.tmp";
  6. Make sure to place grib2ctl.pl in /cygdrive/c/Program\ Files/PCGrADS/win32e
Basically Efren's modifications to grib2ctl.pl changes the default temporary directory from "c:\\" to "/cygdrive/c/".

Grib2ctl is a Perl script that tries to make a GrADS .ctl file from a GRIB
file. The script is somewhat restrictive in the form/content of the GRIB
file. Nevertheless this script and earlier versions have made .ctl files for
terrabytes of files. See the documentation for more details.

Problems:

  1. can get confused by non-NCEP grid definitions
  2. doesn't do rotating of winds with NCEP lambert conformal projections
  3. doesn't handle mixed analysis and variance files
  4. missing times are not handled well
  5. doesn't handle multiple vertical coordinates well
  6. doesn't handle "missing" vertical levels well

Files:

Questions:

  1. Why doesn't grib2ctl work?
    • for forecasts, grib2ctl.pl use -verf option, gribmap do not use -0 option
    • for analyses, grib2ctl.pl do not use -verf option, gribmap use -0 option
    • only uses variables for the 1st time step (template option)
    • gets confused by uneven time steps
    • some variables are not defined on all time steps. Example, precipitation in model forecasts.
    • unsupported grid
  2. How to get ECMWF reduced Gaussian grids to work?
    1. Get new grib2ctl.pl 5/2006+
    2. Get new wgrib 5/2006+
    3. Get new grads v1.9b4+
    4. Make sure that "wgrib" finds the new version (check your $PATH)
    5. Make sure you can write the pdef to the directory with the data file
      otherwise you will have to specify the pdef file.
  3. How to get WAFS (thinned lat-lon) grids to work?
    • See above, "How to get ECMWF reduced Gaussian grids to work"
  4. Can I recycle the pdef files generated by grib2ctl.pl?
    • Yes. The pdef file is the same for all files using the same grid.
      However, the pdef files are endian dependent.
  5. Why is the xdef and ydef missing from the .ctl file?
    • Many grids were not included in the script. Send me a copy of the GRIB file, and I see if the grid can be added to the script.
  6. I made a .ctl and .idx file with no problem. Why can't I display anything?
    • One common problem is that grib2ctl uses the initial time rather than the verification time by default. On the other hand, gribmap uses the verification time by default. To use initial time, use the "-0" (zero) option on gribmap. To use the verification time, use "-verf" option on grib2ctl.
  7. Why does grb2ctl option "-verf" require no gribmap option while no grib2ctl option require the "-0" option?
    • In hindsight, the gribmap and grib2ctl options should have been consistent.
  8. How do I get grib2ctl to use the template option?
    • Get version v0.9.12.5p33j+ and use %y4, %m2 etc in the file name.
      for example, $ grib2ctl.pl cpc_mon_mean.%y4%m2 >cpc_mon.ctl

Comments: Wesley.Ebisuzaki@noaa.gov, updated 6/2007


NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5200 Auth Road
Camp Springs, Maryland 20746
Climate Prediction Center Web Team
Page last modified: May 15, 2005
Disclaimer Privacy Policy