Using Templates

GrADS allows you use a single data descriptor file to aggregate multiple data files and handle them as if they were one individual file. The individual data files must be identical in the X, Y, and Z dimensions and have the same list of variables. The time range of each individual file must be indicated it its filename. Beginning with version 2.0, data files may also be aggregated in the ensemble dimension.

First, the DSET entry has a substitution template instead of a filename. See below for a description of all the possible components of the template. Second, the OPTIONS entry contains the template keyword. Third, the TDEF entry describes the time range for the entire set of data files.

Templating works on any GrADS data type for which you can write a descriptor file. If you specify any additional OPTIONS keywords in the data descriptor file, make sure the options apply equally to each file included in the template.

You can use the set misswarn command to alert you if any of the data files in the templated set is missing.

Templating over TIME

Valid components of the substitution template for the TIME axis are as follows:

When specifying the initial time (e.g., NWP model output), use these substitutions:

Templating over ENSEMBLE

With the introduction of the extra grid dimension for ensembles in version 2.0, support was also added for file templating over E. The sole substitution template is %e and the substitution string is the ensemble name, which is provided in the EDEF entry in the descriptor file. Note that the ensemble names are limited to 15 characters -- keep this limit in mind when designing your data directory structure and file naming conventions (or use symbolic links to create short aliases for longer filenames). If you are templating over the ensemble dimension, there can be only one ensemble member per file. If your data set has an ensemble dimension, and you are using templating over T but not E (i.e., there is no %e in the DSET entry), then all ensemble members are presumed to have identical time axes, and all members must be contained in the data file for a given time. Templating over T but not E is not supported for data sets in flat binary or GRIB1 formats.

String Substitution

The %ch template option, introduced in version 1.9b4, allows for any user-specified string substitution, not just date strings. This is useful when none of the above template options match the time ranges in the files you wish to aggregate, or if the files are located on different disk pathnames. The syntax is as follows:

If you put the %ch template in your DSET entry, then you also need to put additional CHSUB entries in the descriptor file that contain two integers (t1 and t2) followed by a string which will be substituted for %ch in the data file names for the time steps beginning with
t1 and ending with t2. The CHSUB descriptor file entries have the following syntax:

Version 2.1.a3 adds a new feature to the string substitution template: the string provided in the CHSUB entry may contain time-based template components. GrADS will do the CHSUB string substitution before the complete filename is generated by resolving all the other template substitution components. An application of this strategy might be to merge a reanalyis and forecast into one seamless time series, but the reanalyes and forecasts have different file naming conventions. See example #6 below.

Examples

  1. Here's a set of binary files spanning a single month, where each day's worth of hourly data is contained in individual files:
       1may92.dat
       2may92.dat
       ...
       31may92.dat

    Three records must be modified in the data descriptor file. Note that the TDEF entry reflects the entire month's worth of data:
       DSET ^%d1may92.dat
       OPTIONS template
       TDEF 744 linear 0z1may1992 1hr


  2. If your data set expanded, and there were more files containing hourly data for other months and years:
       1jun92.dat
       2jun92.dat
       ...
       1jan93.dat

    Then you would add a template for month and year in your DSET entry and extend the length of your TDEF:
       DSET ^%d1%mc%y2.dat
       OPTIONS template
       TDEF 6624 linear 0z1may1992 1hr


  3. Suppose you have a set of seven netcdf files, each containing monthly data spanning a decade:
       pr.1880_1889.nc
       pr.1890_1899.nc
       pr.1900_1909.nc
       pr.1910_1919.nc
       pr.1920_1929.nc
       pr.1930_1939.nc
       pr.1940_1949.nc
    Then your descriptor file would include the following entries:
       DSET ^pr.%x30_%x39.nc
       OPTIONS template
       DTYPE netcdf
       TDEF 840 linear jan1880 1mo

  4. Here are two netcdf files, one containing 50 years of monthly data (600 time steps), the other 100 years (1200 time steps):
       pr.1851-1900.nc
       pr.1901-2000.nc
    Your descriptor file should include the following entries:
       DSET ^pr.%ch.nc
       CHSUB   1  600 1851-1900
       CHSUB 601 1800 1901-2000
       OPTIONS template
       DTYPE netcdf
       TDEF 1800 linear jan1851 1mo
    If these two data files were located on different disks, you could write out the relevant descriptor file entries this way instead:
       DSET %ch
       CHSUB   1  600 /disk1/pr.1851-1900.nc
       CHSUB 601 1800 /disk2/pr.1901-2000.nc

  5. Your forecast model output looks like this:
      MMOUT_DOMAIN1_00
      MMOUT_DOMAIN1_01
      MMOUT_DOMAIN1_02
    so your DSET enry will look like this:
      DSET ^MMOUT_DOMAIN1_%tm2

  6. Here is an example of using different time template substitutions within a %ch string substitution.
      DSET /data/projects/ops/pub/%ch
      CHSUB 1    1898 das/Y%y4/M%m2/D%d2/GEOS.fp.asm.inst3_2d_smp_Nx.%y4%m2%d2_%h2%n2.V01.nc4
      CHSUB 1899 1909 forecast/Y2014/M10/D15/H06/GEOS.fp.fcst.inst3_2d_smp_Nx.20141015_06+%y4%m2%d2_%h2%n2.V01.nc4
      OPTIONS template