wgrib2: -egrep, -egrep_v, -fgrep, -fgrep_v
When you use wgrib2 extensively, common sequences keep occuring, such as,
1: wgrib2 A.grb >A.inv
2: cat A.inv | fgrep ":HGT:" | fgrep ":500 mb:" | wgrib2 -i A.grb -grib hgt500.grb
3: cat A.inv | fgrep ":TMP:" | fgrep ":500 mb:" | wgrib2 -i A.grb -grib tmp500.grb
4: cat A.inv | egrep ":(UGRD|VGRD):" | fgrep ":500 mb:" | wgrib2 -i A.grb -grib wind500.grb
Using the various -grep, -inv and the -i_file option, the above example can
be written as
1: wgrib2 A.grb -inv A.inv
2: wgrib2 -fgrep ":HGT:" -fgrep ":500 mb:" -i_file A.inv A.grb -grib hgt500.grb
3: wgrib2 -fgrep ":TMP:" -fgrep ":500 mb:" -i_file A.inv A.grb -grib tmp500.grb
4: wgrib2 -egrep ":(UGRD|VGRD):" -fgrep ":500 mb:" -i_file A.inv A.grb -grib wind500.grb
The first version is easier to read. So why were the extra options added?
The options were added for the third reason. I wanted to have
a calls to wgrib2 that would read a selected field. The above example can be written
in fortran as,
- Some shells have problems with pipes?
- Some versions of Windows dos-prompt have problems with pipes.
- RNomads: solved Windows 7 problem by using these options
- More efficient when you avoid multiple processes and pipes?
- Every millisecond and K byte counts!
- Will test with Nomads' grib_filter to see if number of zombies is reduced.
- Callable wgrib2?
- A subroutine (wgrib2) can read a field using the index file!
i = wgrib2a('A.grb','-inv','A.inv')
i = wgrib2a('-fgrep',':HGT:','-fgrep',':500 mb:','-i_file,'A.inv','A.grb','-grib','hgt500.grb')
i = wgrib2a('-fgrep',':TMP:','-fgrep',':500 mb:','-i_file','A.inv','A.grb','-grib','tmp500.grb')
i = wgrib2a('-egrep',':(UGRD|VGRD):','-fgrep',':500','mb:','-i_file','A.inv','A.grb','-grib','wind500.grb')
The -grep options are used in wgrib2api's grb2_inq(..) function.
Definition of grep options:
(...) | wgrib2 -OP1 X (...)
(...) | OP2 X | wgrib2 (...)
if OP1 == egrep then OP2 = egrep
if OP1 == fgrep then OP2 = fgrep
if OP1 == egrep_v then OP2 = egrep -v
if OP1 == fgrep_v then OP2 = fgrep -v
X is a posix extended regular expression (egrep, egrep_v)
or a fixed string (fgrep, fgrep_v)
The number of -fgrep and -fgrep_v options is limited to 200.
The number of -egrep and -egrep_v options is limited to 200.
The wgrib2 option -set_regex does not affect the -grep options.
X is a posix extended regular expression
Y is a fixed string (not a regular expression)
Note: -set_regex does not modify the type of regex for these options