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 > g2ctl
 

g2ctl

g2ctl takes GRIB2 files and makes GrADS control files. For grib-1 files, see grib2ctl. Once you have made a control file and index file, GrADS can read grib2 files. Note that whenever you update g2ctl, you must update wgrib2.

There is an alternative to the g2ctl/gribmap for making ctl/index for GrADS. alt_g2ctl/alt_gmp were written to handle large datasets and extended grib variable names.

1/25/2008 First public release

Quick Directions

For analyses:

$ g2ctl -O grib2_file >grib2_file.ctl
$ gribmap -O -i grib2_file.ctl
$ grads
Landscape mode? (no for portrait):
ga-> open grib2_file.ctl

For forecasts (end of averaging period):

$ g2ctl grib2_file >grib2_file.ctl
$ gribmap -i grib2_file.ctl
$ grads
Landscape mode? (no for portrait):
ga-> open grib2_file.ctl

For forecasts (start of averaging period):

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

Longer Directions

You run g2ctl by the following command line,

  g2ctl [options] (grib file) > (ctl file)
    or
  g2ctl [options] (grib file) (index file) > (ctl file)
    or
  g2ctl [options] (grib file) (index file) (pdef file) > (ctl file)

  [options] = list of optional options
  (grib_file) = a grib file or a restricted GrADS template
  (index file) = index file that is generated by gribmap
                 if no index file is specified, then gribmap will use
                 (grib file).idx
  (pdef file) = some grids are not natively supported by GrADS.  A pdef
                file will allow GrADS to support arbitrary grids.

Important Options

-verf .. use end of ave/acc period or fcst time (default)
run gribmap with no option
-0 .. use analysis times
run gribmap with gribmap -0
-b .. use start of averaging/accumulation period
run gribmap with gribmap -b
-365 .. use 365 day calendar
-no_profile .. no z coordinate
-raw .. use a raw grid
-ens "e1,..,en" .. a list of quoted ensemble names

Windows

g2ctl works under Windows. You just have to put a perl before g2ctl.

linux: $ g2ctl (rest of line)
windows: $ perl g2ctl (rest of line)

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.

I have tested g2ctl using the cygwin system and I had no problems. Haven't tried it using another perl and the default windows shell. Other people have done it.

Ensembles

G2ctl can support ensembles by
  1. having each ensemble member in its own file
    • g2ctl e1.grb >e1.ctl
    • g2ctl e2.grb >e2.ctl
    • g2ctl e3.grb >e3.ctl
    • gribmap -i e1.ctl
    • gribmap -i e2.ctl
    • gribmap -i e3.ctl
    • $ grads
    • ..
    • open e1.ctl
    • open e2.ctl
    • open e3.ctl
    • d ugrd.1 (note: ensemble member 1 is defined by the first open command)
  2. using a grib2 ensemble template which identifies the ensemble member and all the ensemble members are in the same file.
    • cat e1.grb e2.grb e3.grb >e_all.grb
    • g2ctl e_all.grb >e_all.ctl
    • gribmap -i e_all.ctl
    • $ grads
    • ..
    • open e_all.ctl
    • set ens 1
    • d ugrd (note: ensemble member 1 is defined by the grib metadata)
  3. using a grib2 ensemble template which identifies the ensemble member and each ensemble members is in a separate file.
    • g2ctl -ens "e1,e2,e3" %e.grb >e.ctl
    • gribmap -i e.ctl
    • $ grads
    • ..
    • open e.ctl
    • set ens 1
    • d ugrd (note: ensemble member 1 is defined by the grib metadata)

Templating

Use the GrADS templating names for creating templated ctl files. For example,
g2ctl pgb.2008010100.f%f3 >forecast.ctl
gribmap -i forecast.ctl
 
g2ctl -0 pgb.%y4%m2%d2%h2.f00 >analysis.ctl
gribmap -0 -i analysis.ctl
 
g2ctl -ens "e1,e2,e3" %e.2008010100.%f2 >ens.ctl
gribmap -i ens.ctl
The supported template names are:
%y4 - four digit year code
%y2 - two digit year code
%m2 - two digit month code
%m1 - one or two digit month code
%d1 - one or two digit day code
%d2 - two digit day code
%j3 - 3 digit julian day
%h1 - one or two digit hour code
%h2 - two digit hour code
%f2 - two to eight digit forecast hour code
%f3 - three to eight digit forecast hour code
%fn2 - two digit forecast hour code
%e - ensemble name (specified by -ens option)

However, g2ctl does a simple sort to find the old, second oldest, and youngest files. If you files "hr0", "hr2", ..., "hr8", "hr10", and "hr10". The simple sort will give the oldest file as "hr0", the second youngest as "hr10" and the oldest as "hr9". So g2ctl will be totaly confused by the expected number of files as well as the ending forecast hour. This means that numbers have to be a fixed number of digits, as well as names of the month cannot be used.

Ensemble Templating

Suppose you want to make a control file for the following files:

gec00.t00z.pgrb2.f00
gec00.t00z.pgrb2.f06
gec00.t00z.pgrb2.f12

gep01.t00z.pgrb2.f00
gep01.t00z.pgrb2.f06
gep01.t00z.pgrb2.f12

gep02.t00z.pgrb2.f00
gep02.t00z.pgrb2.f06
gep02.t00z.pgrb2.f12

gep03.t00z.pgrb2.f00
gep03.t00z.pgrb2.f06
gep03.t00z.pgrb2.f12

To make a control file,
g2ctl -ens "c00,p01,p02,p03" ge%e.t00.pgrb2.f%f2 > ge.ctl

Restriction of the Templating Option (prior to v0.1.3)

With templating, a control file can refer to a thousand files. A "careful" g2ctl would have to search all thousand files for unique variables and time stamps. However, I am impatient person and I only have g2ctl scan the first, second and last files (in the directory listing). From these three files, g2ctl finds the variables, initial time (smallest time stamp), time increment (second smallest time stamp - smallest time stamp) and the ending time (largest time time stamp). This time-saving strategy can fail for many reasons including,

  1. Templates using the names of the month (ex. Jan) is not supported.
  2. Template names when sorted must be in chronological order.
    rain%d2-%m2-%y4.grb will not work. rain.%y4%m2%d2%h2.grb will work
  3. Template names must be in one directory. For example, y%y4/rain.%y4%m2%d2.grb will not work.
  4. When GrADS wants data for %y4%m2%d2%h2, it has to be found in the file with the same %y4,%m2,%d2,%h2.
  5. land mask or an other constant field has a time stamp that is unrelated to the forecast or assimilation time stamp. This confuses g2ctl.
  6. time increament has to be fixed. For example, if the first time step is 12 hours, then the ctl file will have a 12 hour time step. This causes problem if the following data has a 3 hour time step.
  7. Templated fields can not be separated by non-digits. good=pgb%y4%m2 bad=%pgb%y4-%m2
  8. There are more situations that are not handled.

If a templated control file can not be made automatically, make the control file for one file and edit the control file to add templating.

Restriction of the Templating Option v0.1.3+

With templating, a control file can refer to a thousand files. A "careful" g2ctl would have to search all thousand files for unique variables and time stamps. However, I am impatient person and I only have g2ctl scan the first, second and last files (in chronological order). From these three files, g2ctl finds the variables, initial time (smallest time stamp), time increment (second smallest time stamp - smallest time stamp) and the ending time (largest time time stamp). This time-saving strategy can fail for many reasons including,

  1. Templates using the names of the month (ex. Jan) is not supported. (maybe in the future)
  2. All template files must be in one directory. For example, y%y4/rain.%y4%m2%d2.grb will not work.
  3. land mask or an other constant field has a time stamp that is unrelated to the forecast or assimilation time stamp. This confuses g2ctl.
  4. time increament has to be fixed. For example, if the first time step is 12 hours, then the ctl file will have a 12 hour time step. This causes problem if the following data has a 3 hour time step.
  5. If a field exceeds it normal maximum value (ex. hour=23 or minute=59), then that can be the only templated field.

Duplicate Varibles with Different Timimg (ex. FV3)

With FV3, the files may have two accumulated precipations.

$ wgrib2 BGDAWP.GrbF04 | grep APCP
881:1120744678:d=2013052000:APCP:surface:3-4 hour acc fcst:
882:1121001351:d=2013052000:APCP:surface:0-4 hour acc fcst:

Using "g2ctl BGDAWP.GrbF04" and "g2ctl -0 BGDAWP.GrbF04" will only show one APCP in the control files because both APCP fields have the same reference time and "forecast" times. Using "g2ctl -b BGDAWP.GrbF04" will allow you to display both fields because they have a different start of the averaging periods (0 and 3 hours).

Another way to display both APCP fields is to use alt_g2ctl with the -0t, -bt or -ft options. The "t" suffix makes the forecast string (like "0-4 hour acc fcst") part of the variable name. So you have to explicity state the forecast string.

$ alt_g2ctl -0t BGDAWP.GrbF04  | grep APCP
APCP04houraccfcstsfc 0 0 "APCP:0-4 hour acc fcst:surface" * APCP:0-4 hour acc fcst:surface
APCP34houraccfcstsfc 0 0 "APCP:3-4 hour acc fcst:surface" * APCP:3-4 hour acc fcst:surface

Linux/Unix Requirements

  1. wgrib2 installed and on your path.
  2. g2ctl perl script
  3. GrADS v2.0+ including gribmap

Windows Requirements

  1. Cygwin wgrib2 installed and on your path. Other versions windows versions of wgrib2 will work but will limited to 2GB files. For 32-bit windows, you have to compile wgrib2 yourself.
  2. Perl, many versions are available and I have no preference.
  3. g2ctl perl script
  4. GrADS v2.0+ including gribmap

    Checking for Aliased Variables

    The GRIB data model is larger than the GrADS data model. For example, a GrADS field has a single time value. A GRIB field could have one time value (ex. analysis), two time values (ex. 6 hour forecast: start of forecast and the valid time) or even three time values (ex. 12-24 hour precipitation forecast: start of forecast, start of valid period, and end of valid period). Consequently two different grib fields may have the same GrADS time value (ex. analysis valid at 2010-01-01-00, 6 hour forecast started from 2010-01-01-00 and a 6 hour forecast started from 2009-12-31-18 and valid at 2010-01-01-00 will have problem no matter which gribmap options are used).

    One way to deal with aliased variables is to store the variables in separate files and make separate control files. You can also try alt_g2ctl which has various options

    You can discover some types of aliasing by using the -no_profile option with grib2ctl or g2ctl. The control file will list the number of variables that it found. That number can be compared with the expected number.

    Displaying EUMETSAT grib2 files

    Many EUMETSAT grib2 files are in space view projection and can not be directly handled by GrADS. However, by doing a couple of steps using wgrib2, we can convert the files in to something that GrADS can handle using this documenation.

    Problems

    • make sure you have grib2 files (test with wgrib2)
    • make sure wgrib2 is current and on your path, alias doesn't count
    • make sure gribmap is version 2
    • make sure GrADS is version 2
    • only some grids are supported
    • Have a time series of forecasts (ex 12 hour forecast with varying starting time) which has an ensemble identifier (ex control forecast). You have to use the EDEF section in the control file but there is no fixed starting time of the control forecast.
      AFAIK you have to use alt_g2ctl and alt_gmp to handle this situation.

    Status

    Both g2ctl and alt_g2ctl are supported as most of the code is common to both control file makers. I (WNE) use alt_g2ctl more than g2ctl.

    Comments: Wesley.Ebisuzaki@noaa.gov


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: Dec 27, 2017, Sept 27, 2018, Oct 2022, Nov 2023
Disclaimer Privacy Policy