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

wgrib2: -set_var

Introduction

Please see new grib for the basic concepts of making new grib files.

The -set_var option changes the variable name of the in-memory grib (sub-)message. You can write out the message with the new name by the -grib (fast) and -grib_out (slow) options. Of course if the in-memory grid values have changed, you have to use the latter option.

You can set the name to a locally defined variable name only if the center is set correctly. For example, you can use an NCEP-defined variable name only if the center is already defined as NCEP. If the center is undefined, you cannot use any locally defined names.

The search order is for WMO definitions and then the locally defined definitions. The search order has implications for NCEP users. NCEP often have WMO and NCEP definitions for the same variable name/type. The -set_var option will choose the WMO definition. This will cause problems with programs that expect the NCEP definition.

The default is to search the NCEP defined names. However, wgrib2 will use the dwd or ecmwf names if the -set_names dwd or -set_names ecmwf options are used.

The -set_var option will alter the master table. The grib2 standard says that variable definitions are only valid for specified master tables. Wgrib2 keeps track of range of tables for which each variable name is valid. In addition, there is an entry for the master table used by the -set_var option.

Usage

-set_var X              X=valid grib variable name such
                        1. text name such as HGT or TMP
			   For WMO defined variables, either DWD, ECMWF, NCEP names are used
			      depending on -set_names  (default is NCEP)
                            local variable names have to consistent with the local center
                        2. varA_B_C_D_E_F
                        3. var discipline=A master_table=B parmcat=E parm=F
                        4. var discipline=A center=D local_table=C parmcat=E parm=F
                           use 3 for WMO defined variables, 4 for locally defined variables 

                           A = discipline
                           B = version of master table
                           C = version of local table
                           D = center
                           E = parameter category
                           F = parameter

                        formats 2-4 were introduced with wgrib2 v2.0.7
			they intended to allow manipulation of variables which are not
			in the grib table.  Format 2 is the inverse of -set_varX
			and formats 3 and 4 are the inverse of the verbose -set_varX

Example

$ wgrib2 p.grb
1:0:d=2009072100:PRES:mean sea level:anl:
$ wgrib2 p.grb -set_var TMP -grib out.grb
1:0:d=2009072100:TMP:mean sea level:anl:
$ wgrib2 out.grb
1:0:d=2009072100:TMP:mean sea level:anl:

You can use -set_var to change from old variable names to the new variable names
by the appropriate use of the -if option.
Convert TSOIL (old) to SOILTMP (new)

$ wgrib2 old.grb -if ":TSOIL:" -set_var SOILTMP -fi -grib new.grb

The -set_var option will rename all the fields in a grib file. If you only want to rename specific fields, you will have to use the -if and -fi options. See also: -fi, -grib, -grib_out, -if -set_metadata -set_var -set_varX

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: April 28, 2017 April 12, 2018, 10/2023
Disclaimer Privacy Policy