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

wgrib2: -rpn

Introduction

The -rpn option runs a reverse polish notation (rpn) calculator. The option is preliminary and the mode of operation may change.

The calculator includes 10 registers that are persistant. The stack is initialized with each grib message. (The grid values are put on the top of the stack.) The registers are initialized when wgrib2 is started. Consequently the registers allow you to save data between different grib messages.

Uses

  • change of units when importing data (gribifying data)
  • computations: ex, U,V -> wind speed, wind direction, potential temperature
  • merging data
  • complex masking of data
  • changing units before writing text/ieee files
  • removing extreme data values

Usage

-rpn  A:B:C:...
    A,B,C,.. = number or an operator, function or number

Operators and Functions:

  • +, -, *, /
  • <, <=, ==, !=, >=, >
  • sin, cos, tan
  • abs
  • sq, x*x
  • sqrt, square root
  • 1/x
  • floor
  • max, the maximum value of the top and top-1
  • min, the minimum value of the top and top-1
  • merge, top of the stack unless it is undefined then the top-1
  • mask
  • yrev, for nx-ny grids, we:sn -> we:ns
Stack Operators:
  • clr, clear the stack
  • dup, duplicate the top of the stack
  • pop, remove the top of the stack
  • exc, exchange the top 2 stack entries
  • pi, put pi on top of stack
Register Operators:
  • clr_I, clear register I, I=0,1..,9
  • rcl_I, push register I on top of stack, I=0,1..,9
  • sto_I, save top of stack in register I, I=0,1..,9
  • rcl_lat, push latitudes onto the top of the stack
  • rcl_lon, push longitudes onto the top of the stack
Printing Operators:
  • print_corr, write cosine weighted spatial correlation
  • print_max, print_min
  • print_rms, write cosine weighted RMS

Examples

The standard units of grib temperature is K but you want the output to be in Celcius.

$ wgrib2 a.grb -match ":TMP:850 mb:" -rpn 273.15:- -text C.dat

Fahrenheit is easy too (F = (K-273.15)*9/5+32).

$ wgrib2 a.grb -match ":TMP:850 mb:" -rpn "273.15:-:9:*:5:/:32:+" -text C.dat

Suppose someone made a mistake and the latent heat flux (LHTFL) had the wrong sign. RPN to the rescue.

$ wgrib2 a.grb -match ":LHTFL:" -rpn "-1:*" -grib_out new_lhtfl.grb
You could fix the entire file by
$ wgrib2 a.grb -if ":LHTFL:" -rpn "-1:*" -fi -grib_out new.grb
If both the latent and sensible heat fluxes needed a sign reversal, you could do,
$ wgrib2 a.grb -if ":(LHTFL|SHTFL):" -rpn "-1:*" -fi -grib_out new.grb
Don't forget to enclose the argument to rpn in quotes because the shell can do unexpect things. Printing operators
print_corr write cosine weighted spatial correlation R(TOP-1), R(TOP)
print_max write max(R(TOP)) to stdout
print_min write min(R(TOP)) to stdout
print_rms write cosine weighted RMS(R(TOP-1)-R(TOP))

See also:


NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5200 Auth Road
Camp Springs, Maryland 20746
Climate Prediction Center Web Team
Page last modified: May 15, 2005
Disclaimer Privacy Policy