Skip Navigation Links 
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 > gribify2

gribify using import and a template


Here is another way of writing a grib2 file. Create a template grib2 file. In our example, we already created one in grib1 and then converted it to grib2 using cnvgrib. Once we have a template file, we can replace the data using one of the import options, adjust the date code, handle the undefined grid point and write it out using the -grib_out option. Here is an example script.

# example of converting a binary file to grib2
# conustemplate.grb2 is the template
#  was created in grib1 using the gribw library
#  and converted to grib2 by cnvgrib
# the data file has two records but we only want to convert the 1st record
set -x

# date=$1
# date0=`ndate -12 ${date}00`

# -no_header    .. read/write data without f77 header
# -import_bin   .. read one binary record (no header) and replace the grib data field
# -set_date     .. set a new reference time
# -undefine_val .. the binary file used -999 as the undefined flag
# -rpn          .. use the rpn calculator to convert to standard units (x=x/10/86400)
# -grib_out     .. write the data as a grib file

wgrib2 conustemplate.grb2 -no_header -import_bin PRCP_CU_GAUGE_V1.0CONUS_0.25deg.lnx.$date.RT \
  -set_date $date0 -undefine_val -999 -rpn 10:/:86400:/ -grib_out precip$date0.grb2

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: June 1, 2009
Disclaimer Privacy Policy