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 > wgrib2 -if,-not_if
 

wgrib2: -if, -not_if

Introduction

The -if option returns true or false. If true, then all the options up to and and including the next "output" option is executed. Otherwise those options are igored. The -not_if option does the opposite of -if.

Note, the effects of nesting of -if and -not_if are not defined. Future versions of wgrib2 may allow nesting.

Note, the "if" flag is reset after processing the record.

The -if option can be used to process the file once and create several output files. For example,

old: wgrib2 -match_inv gribfile  >inv
     egrep ":(UGRD|VGRD):" inv | wgrib2 -i gribfile -grib winds.grb
     grep ":TMP:" inv | wgrib2 -i gribfile -grib tmp.grb
In the above example, the UGRD/VGRD fields are written into winds.grb and the TMP is written into the tmp.grb file. The above 3 lines can be rewritten as
new:
     wgrib2 gribfile -if ":(UGRD|VGRD):" -grib winds.grb -if ":TMP:" -grib tmp.grb
In the above example, the UGRD/VGRD fields are written into winds.grb and the TMP is written into the tmp.grb file. Note that you can use any number of -if options and they use the same output file.
     wgrib2 gribfile -if ":(UGRD|VGRD):" -grib save.grb -if ":TMP:" -grib save.grb

The maximum number of -if options on a command line is limited by (1) system limit of open files (2) maximum length of a command line, (3) maximum number of regular expressions allowed MAX_MATCH (wgrib.h), and (4) maximum number of parsed arguments N_ARGLIST (wgrib.h).

The -if option can be to selectively modify grib fields. See -fi.

Usage

-if X

X is a regular expression

Future Changes

The format of the "match inventory" has evolved and will continue to evolve. The rule for future changes is that new items in the "match inventory" will be added as the second last item. Consequently the last item in the inventory will always be ":vt=YYYYMMDDHH:". In order to future proof your -match, and -not selections, you must not include any item before the ":vt=YYYYMMDD:" field.

    -match ":vt=2011111500:"                  good
    -not ":vt=2011111500:$"                   good (dollar sign matches the end of the line)
    -not ":n=10:vt=2011111500:"               bad (item before :vt=)
    -match ":RH:975 mb:anl::vt=2010050806:"   bad (item before :vt=)
Some recent changes (as of Nov 2011) to the match inventory include:
  • adding the "extended name of the variable", ex. TMP.prob_<273
  • adding the inventory number, ex. n=10
  • adding ensemble/chemical/probability information (-misc)

See also: -not, -end, -match, -i, -if. -fi. -set_regex.


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: May 15, 2005
Disclaimer Privacy Policy