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 raw2, -rpn 2raw
 

wgrib2 macros: -rpn raw2, -rpn 2raw

Introduction

Mosts of the operators for -rpn are simple and need minimal explanation. However, the raw2, and 2raw require more explanation.

In grib2 files, the grid point data is stored sequentially and have to be mapped to the grid. Grib2 defines many methods (scan orders) of mapping the grid point. There are fortran order, C order, West to east, east to west, south to north and north to south. The rows can have a uniform direction or the even rows have a direction and the odd rows have another direction. Then you can add on the various Arakawa grids, and everything is messy.

To avoid this mess, the default mode in wgrib2 is to convert the internal grids to WE:SN order. It makes life easier for the users and easier for the developers. You are encouraged to use WE:SN order because it is a requirement for wgrib2's geolocation routines. (I.e., wgrib2 requires WE:SN order in order to calculate the grid's latitude and longitude.) The only exception to this rule is the -new_grid option which requires the data to be in raw order (output order=raw). This option is an exception because -new_grid expects that data to be in raw order.

To alter the internal scan order, you can use the -order option.

-sh-4.1$ wgrib2 gep19.t00z.pgrb2af180 -d 1 -V
1:0:vt=2009061212:200 mb:180 hour fcst:HGT Geopotential Height [gpm]:ENS=+19
    ndata=65160:undef=0:mean=11760.3:min=10393.5:max=12525
    grid_template=0:winds(N/S):
	lat-lon grid:(360 x 181) units 1e-06 input WE:NS output WE:SN res 48
	lat 90.000000 to -90.000000 by 1.000000
	lon 0.000000 to 359.000000 by 1.000000 #points=65160
 -- the grib files is WE:NS order (input WE:NS)
 -- the internal grid is WE:SN order (output WE:SN)

-sh-4.1$ wgrib2 gep19.t00z.pgrb2af180 -d 1 -V -order raw
1:0:vt=2009061212:200 mb:180 hour fcst:HGT Geopotential Height [gpm]:ENS=+19
    ndata=65160:undef=0:mean=11760.3:min=10393.5:max=12525
    grid_template=0:winds(N/S):
	lat-lon grid:(360 x 181) units 1e-06 input WE:NS output raw res 48
	lat 90.000000 to -90.000000 by 1.000000
	lon 0.000000 to 359.000000 by 1.000000 #points=65160
 -- the grib files is WE:NS order (input WE:NS)
 -- the internal grid is raw order (output raw), which means the same as input scan order

-sh-4.1$ wgrib2 gep19.t00z.pgrb2af180 -d 1 -V -order we:sn
1:0:vt=2009061212:200 mb:180 hour fcst:HGT Geopotential Height [gpm]:ENS=+19
    ndata=65160:undef=0:mean=11760.3:min=10393.5:max=12525
    grid_template=0:winds(N/S):
	lat-lon grid:(360 x 181) units 1e-06 input WE:NS output WE:SN res 48
	lat 90.000000 to -90.000000 by 1.000000
	lon 0.000000 to 359.000000 by 1.000000 #points=65160
 -- the grib files is WE:NS order (input WE:NS)
 -- the internal grid is WE:SN order (output WE:SN)

-sh-4.1$ wgrib2 gep19.t00z.pgrb2af180 -d 1 -V -order we:ns
1:0:vt=2009061212:200 mb:180 hour fcst:HGT Geopotential Height [gpm]:ENS=+19
    ndata=65160:undef=0:mean=11760.3:min=10393.5:max=12525
    grid_template=0:winds(N/S):
	lat-lon grid:(360 x 181) units 1e-06 input WE:NS output WE:NS res 48
	lat 90.000000 to -90.000000 by 1.000000
	lon 0.000000 to 359.000000 by 1.000000 #points=65160
 -- the grib files is WE:NS order (input WE:NS)
 -- the internal grid is WE:SN order (output NS)

-sh-4.1$ wgrib2 reduced_gaussian_surface_jpeg.grib2 -d 1 -V
1:0:vt=2007032312:surface:anl:TMP Temperature [K]:
    ndata=6114:undef=0:mean=285.342:min=210.255:max=317.485
    grid_template=40:winds(N/S):
	thinned global Gaussian grid: (-1 x 64) units 1e-06 input WE:NS output raw
	number of latitudes between pole-equator=32 #points=6114
	lat 87.864000 to -87.864000
	lon 0.000000 to 357.188000 
	#grid points by latitude: 20 27 36 40 45 50 60 64 72 75 80 90 90
	 96 100 108 108 120 120 120 128 128 128 128 128 128 128 128 128 128 128 128 128
	 128 128 128 128 128 128 128 128 128 128 128 120 120 120 108 108 100 96 90 90
	 80 75 72 64 60 50 45 40 36 27 20
 -- in this file, the grid dimension is -1 x 64.  This is a thinned Gaussian grid, and
    nlongitude is variable.  The output scan order is raw.

The raw2 operator is short for "raw scan order 2 output scanning order", and 2raw is short for "output scanning mode 2 raw scan mode". The raw2 applies the mapping that goes from the file's scanning mode to the interal scanning mode (default WE:SN). The 2raw applies the inverse mapping.

Example 1

$ wgrib2 IN.grb -d 1 -rpn "rcl_lon:2raw" -set_var geolon -bin out \
   -rpn "rcl_lat:2raw" -set_var geolat -bin out 

This write the longitude and latitude in binary format to file "out".
The lon/lat are written in the same format as the input file.

Example 2

SST0.grb - SST in grib format (template) in WE:NS order
SST.bin  - new SST in binary format, and WE:NS scan order
SST.grb  - new SST in grib format

$ wgrib2 SST0.grb -import_bin SST.bin -rpn "raw2" -set_date 2020010100 -grib_out SST.grb

or 

$ wgrib2 SST0.grb -order raw -import_bin SST.bin -set_date 2020010100 -grib_out SST.grb

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 created 3/30/2020
Disclaimer Privacy Policy