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

Grib files have several time variables: reference time, verification time, start of averaging time, and end of averaging time. The user must select which of these times will used by GrADS. The options for grib2ctl.pl and gribmap must be consistent.

For reference time: (often used by 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 end of averaging time or verification time: (often used by 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

For start of averaging time or verification time: (often used by forecasts)

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

For example, a 24 forecast started at 00Z 1/1/2013 will have a reference time of 00Z 1/1/2013. It's verification time will be 00Z 1/2/2013 (or 2/1/2013). The start/end of the averaging time will be the same as the verf time.

For another example, a 24-48 averaged precip orecast started at 00Z 1/1/2013 will have a reference time of 1/1/2013. The start of the averaging period will be 1/2/2013 and the end of the averaging period will be 1/3/2013.

I agree, the time stamp options are confusing. However, they are necessary when using templated files.

Gribmap takes the GRIB file and finds the time and location of each

Windows

Using grib2ctl.pl on windows is like using grib2ctl.pl on linux except

$ grib2ctl.pl (options, grib file and > ctl)
becomes
$ perl grib2ctl.pl (options, grib file and > ctl)
The same grib2ctl.pl and options are used for windows, unix and linux. You have to keep in mind the Window filename conventions are different from Unix/Linux. g2ctl is written for the unix standard. Windows considers upper case A to be the same as a lower case a. Unix allows multiple periods in a filename. Some Windows systems only allow one period in the filename. If you having problems with g2ctl, convert the input and output filenames to 8.3 and move all the files to the current directory.

Template Option

grib2ctl.pl now supports the tempplate option (v0.9.12.5p33j). However, grib2ctl only allows template wildcards in the filename.

$ 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.
  8. Don't forget to make the program executable (chmod 755 grib2ctl.pl) and put it on your PATH.

Windows Installation (not supported, YMMV):

  1. Install wgrib v1.8+ and make sure wgrib and dll are 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-7 in Unix/Linux install.
  7. doesn't work? See heading: not supported
  8. hint: make sure perl, wgrib and all the .dll files are on your PATH

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 handle mixed analysis and variance files
  3. missing times are not handled well
  4. doesn't handle multiple vertical coordinates well
  5. doesn't handle "missing" vertical levels well
  6. template wildcards only in the filename
  7. templated files must sort in chronological order

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.
    6. use the option -ec_gbl
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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/2009


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: 1, 2013
Disclaimer Privacy Policy