Title: GRIB2 usage at NCEP
1GRIB2 usage at NCEP
- Dr. V. KRISHNA KUMAR
- BOI VUONG
- NOAA/NWS/NCEP/Central Operations
NCEP WWB GRIB2 Seminar 15 June 2011
Room 707, WWB Camp Springs, MD
2Overview
- GRIB2 Sections NCEP
- GRIB2 Documentation
- GRIB2 in NCEP Operations Encoding Decoding
routines, NCEP Utilities (cnvgrib, degrib2,
overdateg2, overmodelg2, copygb2,wgrib2..) - GRIB2 Section 7 Data Section
- GRIB2 Packing Options
- How to write GRIB2 data directly? Some
specific examples
3Overview
- GRIB2 Encoding routines
- GRIB2 Decoding routines
- Declaration of Derived type gribfield
- How to use routine getgb2?
- How to use routine putgb2?
- GRIB2 read and write examples
- Summary
4GRIB1 Sections
- 0 Indicator Section
- - GRIB (octet 1-4 32bits), length of
message (octet 5-724bits), edition number -1
(octet 88bits) - - 1 octet 1byte 8bits
- - octets are numbered 1, 2, 3, etc., Bit
positions within octets are from bit 1 to bit 8. - - bit 1 most significant bit bit 8
least significant) - 1 Product Definition Section (PDS)
-
- - Length of PDS, parameter table version
number, ID of center, generating process ID, grid
identification (Table B), Ref time, parameter
and units, level, valid time - 2 Grid Definition Section (GDS) optional
- - Length of sec., sec. no, defn of grid surf
and geometry of data values within the surface - 3 Bit-Map Section (BMS) optional
- - Length of sec., sec. no, indication of
presence or absence of data at each of the grid
points, as applicable example sst - 4 Binary Data Section (BDS)
- - Length of sec., sec. no, data values
- 5 End Section 7777
5GRIB2 Sections
- 0 Indicator Section
- - GRIB, length, version,
discipline (16 octets long) - Section 1 Identification
- - Ref time, orig center, table
versions, (length of the section is expressed as
the first four octets (32 bits)
-the section number in the fifth octet and octets
beyond 21 are reserved for future use) - 2 Local Use Section optional
- 3 Grid Definition Section
- 4 Product Definition Section
- - parameter, level, valid time
- 5 Data Representation Section
- - packing algorithm used, info
needed to unpack
- 6 Bit Map Section
- 7 Data Section
- -packed data
- 8 End Section 7777
6GRIB2 Documentation
- NCEP GRIB2 Documentation (internet - www)
- http//www.nco.ncep.noaa.gov/pmb/docs/grib2/
- NCEP GRIB2 Resources (Detailed Documentation)
http//www.nco.ncep.noaa.gov/sib/grib2/ - GRIB2 specification from WMO contains template
definitions and table entries http//www.wmo.ch/w
eb/www/DPS/grib-2.html - Local Tables
- http//www.nco.ncep.noaa.gov/pmb/docs/grib2
- NCEP source files and utilities on the web for
decoding and encoding data in GRIB2 format - http//www.nco.ncep.noaa.gov/pmb/codes/GRIB2/
- NCEP wgrib2 resources
- http//www.cpc.ncep.noaa.gov/products/wesley
/wgrib2/ - See Wesleys PowerPoint presentation
4/6/2011 at NCEP under Documentation - for all the pertinent details on wgrib2
-
7GRIB2 Significant Features
- One GRIB2 message can contain multiple fields.
- Sequences of GRIB sections 2 to
7, sections 3 to 7 or sections 4 to 7 may be
repeated within a single GRIB message. - - Once a section is repeated all the
following sections must appear in order. - - A section remains in effect until
redefined. - - Could be used for vector fields such
as u v components, or ensemble members - - IEEE single precision floating point
representation used instead of standard IBM
representation. The representation occupies four
octets. - GDS, PDS, DRS, and DS are all template driven.
- Octet assignments within a section are
based on the Template specified. - Parameters are defined by three values
- Discipline (specified in Section 0)
- Category (PDS)
- Parameter number (PDS).
8GRIB2 Significant Features contd.
- All longitudes MUST be in degrees East and be
between 0 and 360 degrees. No negatives. No
degrees West. No change in latitude definitions
900 to 900. - GDS and BMS no longer optional. They must be
included. Only Section 2 (Local Use) is optional. - Latitudes, Longitudes are in units of
micro-degrees (10 6 degrees). Includes distance
between grid points for Lat/Lon grids (GRIB1 was - milli-degrees)
- All other grid point increments are in
millimeters (GRIB1 was in meters) - Floating point values are now stored in IEEE
format (GRIB1 was IBM 360/195 format HDS)
9SECTION 0 0 2 60463
10(No Transcript)
11SECTION 1 7 0 2 1 1 2010 11 9 6 0 0 0 1
Contains 0 Local Sections and 1 data fields.
12SECTION 3 0 65160 0 0 0 GRID TEMPLATE 3. 0
6 0 0 0 0 0 0 360 181 0 0 90000000 0 48 -90000000
359000000 1000000 1000000 0
13PRODUCT TEMPLATE 4. 0 3 5 2 0 96 0 0 1 36 100
0 100000 255 0 0 TEXT HGT 1000 mb valid
at 36 hr after 20101109060000
14DRS TEMPLATE 5. 3 -979087360 0 1 11 0 1 0 0 0
5124 0 4 1 1 32 5 1 2
15GRIB2 in NCEP operations
- Encoding Routines
- GRIB2 message can contain gridded fields for many
parameters on a number of different grids. - Start a new GRIB2 message with a call to
- (1) call GRIBCREATE encodes sections 0 and 1
at the beginning of message. - (2) call ADDLOCAL adds a Local Use Section
(Section 2) optional - (3) call ADDGRID encodes a grid definition
into Section 3. Defines the geometry of the - data values
in the fields that follow it. ADDGRID can be
called - again to
change the grid definition describing subsequent
data fields. - (4) call ADDFIELD adds each data field which
adds Sections 4, 5, 6, and 7 to the message. - (5) call GRIBEND adds the final section 8 to
the message which updates the length of - the
message. GRIBEND is required for each GRIB2
message. - Boi will demonstrate these routines with examples
in the latter half of this seminar
16GRIB2 in NCEP operations contd.
- Decoding Routines
- call GB_INFO finds out how many Local Use
sections and data fields are contained in a given
GRIB2 message. Also returns the number of octets
of the largest Local Use section in the message.
Ensures the dimensionality of the input array of
GETLOCAL - call GETLOCAL returns the requested occurrence
of Section 2 from a given GRIB2 message. - call GF_GETFLD gets all information pertaining
to the nth data field in the message returns
all the unpacked values for each Section and
Template in a f90 type gribfield with options
to unpack the Bit-map (if applicable) and the
data values or just return the field description
information. - call GF_FREE(gfld) frees up memory held by
gfld as many elements in derived type gribfield
are dynamically allocated when decoded. - Example
- use grib_mod
- type(gribfield) gfld
-
-
- call gf_getfld(cgrib,lengrib,1,.true.,.fa
lse.,gfld,ierr) - print,Num of grid points
,gfldngrdpts - print,First data value,gfldfld(1)
- call gf_free(gfld)
17GRIB2 in NCEP operations contd.
- Create GRIB2 Message
- call PUTGB2 if a variable of derived type of
gribfield already exists, this - subroutine can be used to pack it up and write it
to a file Boi will demonstrate this - NCEP GRIB2 Utilities
- /grb2index grib2file grib2indexfile
- - creates a GRIB2 index file
- /cnvgrib h (packing options 1 gt 2,
2gt1, 2gt2) - -converts all fields in a file between GRIB1
and GRIB2 - /degrib2 grib2file
- -dumps the meta-data for each GRIB2 field in
grib2file - - basically prints contents of each element in
derived type gribfield - /wgrib2 grib2file
- Grads for GRIB2
- sh convert_grib2_to_grads.sh
- !/bin/sh
- set -xa
-
- file_listls grib2.t00z.wafs_grbf06.45
gfs.t00z.wafs_grb45f06.grib2
18GRIB2 in NCEP Operations
/nwprod/util/exec/cnvgrib -h Usage
cnvgrib -h -g12-g21-g22 -m
-p0-p2-p31-p32-p40-p41-p40000-p40010
ingribfile outgribfile cnvgrib version
cnvgrib-1.1.1 Must use one of the following
options -g12 converts GRIB1 to GRIB2
-g21 converts GRIB2 to GRIB1 -g22
converts GRIB2 to GRIB2 (used to change packing
option) Optional packing options (for use with
-g12 and -g22 only) -p0 simple packing
-p2 complex packing -p31 complex pack
with 1st order diffs -p32 complex pack
with 2nd order diffs -p40 JPEG2000
encoding -p41 PNG encoding Other Optional
options -m Use missing values instead
of bitmap (valid with -p2, -p31 or
-p32 options only)
19GRIB2 in NCEP Operations
- /nwprod/util/sorc/overmodelg2.fd
- more sample.script
- THIS SCRIPT READS A FORECAST FILE (UNIT 11),
REPLACES MODEL INDENTIFIER IN - PRODUCT TEMPLATE 4.x FROM A ID FILE UNIT 51.
- STANDARD INPUT IS A ID (2-DIGIT INTEGER), FOR
EXAMPLE 96 (GFS Model) - set -x
- export XLFRTEOPTS"unit_varsyes" Allow
overriding default names. - export XLFUNIT_11gfs.t00z.pgrb2f12.2p5deg
- export XLFUNIT_51gfs.t00z.pgrb2f12.2p5deg.new
- overmodelg2 ltlt EOF
- 98
- EOF
- /nwprod/util/sorc/overdateg2.fd
- THIS SCRIPT READS A FORECAST FILE (UNIT 11),
MODIFIES REFERENCE TIME YEAR MONTH - DATE AND HOUR IN SECTION 1 AND IN PRODUCT
TEMPLATE 4.x TO REPLACE INTERNAL - REFERENCE TIME FROM A DATE IN FILE UNIT 51.
- STANDARD INPUT IS A YYYYMMDDHH (10-DIGIT
INTEGER), FOR EXAMPLE 2010090112 - set -x
20GRIB2 in NCEP Operations
- /nwprod/util/sorc/copygb2.fd
- NAME
- copygb2 - copies GRIB2 files
- SYNOPSIS
- copygb2 -g "kgdtn kgdt" -i "ip
ipopts" - -k "kpdtn kpdt" -v "uparms" -X
- -B mapgrib -b mapindex -A "ltgt
mapthreshold" -K "mapkpds" - -M "mask"mergegrib -m
mergeindex -a - then either
- grib2in index2in grib2out
- or
- -x grib2in grib2out
- DESCRIPTION
- The command copygb2 copies all or part of
one GRIB2 file to another - GRIB2 file, interpolating if necessary.
Unless otherwise directed - (-x option), the GRIB2 index file is also
used to speed the reading. - The fields are interpolated to an output
grid if specified (-g option). - The interpolation type defaults to bilinear
but may be specified directly - (-i option). The copying may be limited to
specific fields (-k option).
21GRIB2 in NCEP Operations
- export grid_new"30 6 0 0 0 0 0 0 1073 689
20191999 238445999 8 25000000 265000000 5079406
5079406 0 64 25000000 25000000 -90000000 0 0" - export grib_inrtma2p5.t12z.2dvaranl_ndfd.1field.
grb2 -
- Create a grib2 index file of the input grib
file -
- /nwprod/util/exec/grb2index grib_in
grib_in_ix - export grib_indexgrib_in_ix
- /nwprod/util/exec/copygb2 -g "grid_new" -i0
grib_in grib_index rtma5p0.t12z.2dvaranl_ndf
d.1field.grb2 - echo "Max Min value from the original 2p5 grid "
- /nwprod/util/exec/wgrib2 -grid -max -min
rtma2p5.t12z.2dvaranl_ndfd.1field.grb2 - echo "Max Min value from the converted 5p0 grid
" - /nwprod/util/exec/wgrib2 -grid -max -min
rtma5p0.t12z.2dvaranl_ndfd.1field.grb2 - echo " Max Min from the current operational 5
degree grid " - /nwprod/util/exec/wgrib2 -grid -max -min
rtma.t12z.2dvaranl_ndfd.1field.grb2 - exit
-
- Script to convert a RTMA 2p5 grib2 file to a
5p0 grib2 file -
- Author V. Krishna Kumar October 5, 2010
NCO/Systems Integration Branch -
- set -x
-
- clean the output file prior to running this
script -
- I created a single field grib2 file from the
original production grib2 file using - wgrib2 -d 1 in_grb2file -grib out_grb2file
-
- rm rtma5p0.t12z.2dvaranl_ndfd.1field.grb2
-
- HGT - Conversion from 2p5 to 5
- Input file rtma2p5.t12z.2dvaranl_ndfd.1field.
grb2 - Output file rtma5p0.t12z.2dvaranl_ndfd.1field.
grb2 -
- 2p5 Grid template 3.30 6 0 0 0 0 0 0 2145
1377 20191999 238445999 8 25000000 265000000
2539703 2539703 0 64 25000000 25000000 -90000000
0
22GRIB MESSAGE 1 starts at 1 SECTION 0 0 2
60463 SECTION 1 7 0 2 1 1 2010 11 9 6 0 0 0
1 Contains 0 Local Sections and 1 data
fields. FIELD 1 SECTION 0 0 2 SECTION
1 7 0 2 1 1 2010 11 9 6 0 0 0 1 SECTION 3 0
65160 0 0 0 GRID TEMPLATE 3. 0 6 0 0 0 0 0 0
360 181 0 0 90000000 0 48 -90000000 359000000
1000000 1000000 0 NO Optional List Defining
Number of Data Points. PRODUCT TEMPLATE 4. 0
3 5 2 0 96 0 0 1 36 100 0 100000 255 0 0 TEXT
HGT 1000 mb valid at 36 hr after
20101109060000 NO Optional Vertical
Coordinate List. Num. of Data Points
65160 NO BIT-MAP DRS TEMPLATE 5. 3
-979087360 0 1 11 0 1 0 0 0 5124 0 4 1 1 32 5 1
2 Data ValuesMIN -525.79998779
AVE 70.36888123 MAX
313.10000610
GRIB MESSAGE 2 starts at 60464 SECTION 0 0
2 59574 SECTION 1 7 0 2 1 1 2010 11 9 6 0 0 0
1 Contains 0 Local Sections and 1 data
fields. FIELD 1 SECTION 0 0 2 SECTION
1 7 0 2 1 1 2010 11 9 6 0 0 0 1 SECTION 3 0
65160 0 0 0 GRID TEMPLATE 3. 0 6 0 0 0 0 0 0
360 181 0 0 90000000 0 48 -90000000 359000000
1000000 1000000 0 NO Optional List Defining
Number of Data Points. PRODUCT TEMPLATE 4. 0
3 5 2 0 96 0 0 1 36 100 0 97500 255 0 0 TEXT
HGT 975 mb valid at 36 hr after
20101109060000 NO Optional Vertical
Coordinate List. Num. of Data Points
65160 NO BIT-MAP DRS TEMPLATE 5. 3
-984977408 0 1 11 0 1 0 0 0 5130 0 4 1 1 32 5 1
2 Data ValuesMIN -323.89999390
AVE 278.48535156 MAX
514.00000000
23GRIB MESSAGE 149 starts at 7050617 SECTION
0 0 2 93572 SECTION 1 7 0 2 1 1 2010 11 9 6
0 0 0 1 Contains 0 Local Sections and 2
data fields. FIELD 1 SECTION 0 0 2
SECTION 1 7 0 2 1 1 2010 11 9 6 0 0 0 1
SECTION 3 0 65160 0 0 0 GRID TEMPLATE 3. 0
6 0 0 0 0 0 0 360 181 0 0 90000000 0 48 -90000000
359000000 1000000 1000000 0 NO Optional List
Defining Number of Data Points. PRODUCT
TEMPLATE 4. 0 2 2 2 0 96 0 0 1 36 100 0 100000
255 0 0 TEXT U GRD 1000 mb valid at 36 hr
after 20101109060000 NO Optional Vertical
Coordinate List. Num. of Data Points
65160 NO BIT-MAP DRS TEMPLATE 5. 3
-1014333440 0 1 9 0 1 0 0 0 4835 0 4 1 1 32 5 1
2 Data ValuesMIN -27.70000076
AVE .24823742 MAX
27.20000076
FIELD 2 SECTION 3 0 65160 0 0 0 GRID
TEMPLATE 3. 0 6 0 0 0 0 0 0 360 181 0 0
90000000 0 48 -90000000 359000000 1000000
1000000 0 NO Optional List Defining Number of
Data Points. PRODUCT TEMPLATE 4. 0 2 3 2 0
96 0 0 1 36 100 0 100000 255 0 0 TEXT V GRD
1000 mb valid at 36 hr after 20101109060000
NO Optional Vertical Coordinate List. Num. of
Data Points 65160 NO BIT-MAP DRS
TEMPLATE 5. 3 -1015873536 0 1 9 0 1 0 0 0 4934
0 4 1 1 16 5 1 2 Data ValuesMIN
-24.30000114 AVE .03596115
MAX 30.39999962 GRIB MESSAGE 150
starts at 7144189
24GRIB2 Section 7 Data Section
- Data coded with the minimum number of bits
necessary to provide the accuracy. - Simple scaling data multiplied by an
appropriate power of 10 before forming the
non-negative differences, and then using the
binary scaling to select the precision of the
transmitted value. - Data coded in the form of non-negative scaled
differences from a reference value of the whole
field plus, if applicable, a local reference
value. (reference value is normally the minimum
value of the data set which is represented).
25GRIB2 Section 7 Data Section contd.
- Complex packing for grid-point values split the
whole set of scaled data values into groups on
which local references (local minima) are removed
pre-processing may be needed on the scaled
data. - Complex packing for spectral data.
- The original data value Y can be recovered with
the formula - Y10DR(X1X2)2E
- where EBinary scale factor, DDecimal
scale factor, RReference value of the whole
field, X10, X2Scaled (encoded) value.
26GRIB2 Packing Methods
- GRIB2_com Group packing DR Template 5.2
- GRIB2_1od Group packing with 1st order
differencing Template 5.3 - GRIB2_2od Group packing with 2nd order
differencing Template 5.3 - Image compression algorithms within the GRIB2
standard. - Both treat grid point data as a grey scale image
(single component) - JPEG_2000 (Part-1 standard) (ISO/IEC 15444-1)
- http//www.jpeg.org/JPEG2000.html
- PNG (Portable Network Graphics image compression
format) - http//www.libpng.org/pub/png/.
27How to write GRIB2 directly? An example to
convert APCP data into GRIB2
- The degrib2 diagnostic was generated from APCP
GRIB2 output and the source code is in - hostname
- c2n6.ncep.noaa.gov
- pwd
- /nco/save/sib/wx12kk/degrib2_analysis/sorc
- Input binary data file XMRG2417
- run script sh runGRIB2.sh
- output GRIB2417_grib2
- Usage HEtoGrib2_exec ltinput XMRG DIRgt ltXMRG
file namegt ltoutput GRIB DIRgt ltoutput GRIB2 file
namegt - For full details, see the source code
HEtoGrib2.f90 - call write_nesdis_grib2(gnesdis,nx,ny,nflds,
- varname,typeproc,isign,
- rtime(1),rtime(2),rtime(3),rtime(4),rtime(
5),rtime(6), - ityped,g2Path, accumHour, modelId,
subCenter) - An example of converting an ASCII data to GRIB2
format from scratch - http//www.nco.ncep.noaa.gov/sib/grib2/examples/dr
ap2g2/
28GRIB2 Encoding Routines
- The following routines are needed to write a
GRIB2 message - Gribcreate (gribcreate.f)
- This routine must be called first to
initialize a new grib2 message. It uses to - encode and pack section 0 and section 1
and it encodes at the beginning of GRIB message
(first 8-bytes) with - GRIB - - 0 2, bytes (5 and 6) reserved
for future use, byte 7 is for discipline, byte 8
is for GRIB Edition 2 and - leaves space for length of GRIB in bytes
9 to 16 - call gribcreate(cgrib,max
pts,listsec0,listsec1,ierr) - For example GRIB2 section 0 and section 1
- -GRIB2 section 0 - Indicator Section
- listsec0(1)0 Discipline
(see Code Table 0.0) ) is meteorological
products - listsec0(2)2 GRIB Edition
Number (currently 2) - -GRIB2 section 1 - Identification Section
29- GRIB2 Encoding Routines (continued)
- Addlocal (addlocal.f) Local use
section. It is optional - is used to add a Local Use Section 2
to GRIB2 message - call addlocal (cgrib,lcgrib,csec2,lcse
c2,ierr) - Addgrid (addgrid.f)
- is used to add a Grid Definition
Section (grid geometry of the data values in the
field) to a GRIB2 message. - call addgrid (cgrib, lcgrib, igds,
igdstmpl, igdstmplen, ideflist, idefnum, ierr) - For example Global Lat/Lon (1.25 degree)
41760 data points (288x145) GRIB2 section 3 -
Grid Definition Section 3.0 - igds(1)0
0 is source of grid definition (see Code
Table 3.0) - igds(2)288145
Number of grid points in the defined grid - igds(3)0
Number of octets needed for each additional
grid points definition - igds(4)0
Interpolation of list for optional points
definition (Code Table 3.11) - igds(5)0
Lat/Lon grid - Grid Definition Template
Number 0 (Code Table 3.1) - igdstmpl(1) 6
Earth assumed spherical with radius
6,371,229.0m - igdstmpl(2) 0
Scale factor of radius
30-
GRIB2 Encoding Routines (continued) - Addfield (addfield.f)
- This routine uses to add and packs up
Production Definition Section (section 4), Data
Representation - Section (section 5), Bit-Map section (section
6) and Data Section (section 7) to a GRIB2
message. - call addfield (cgrib, lcgrib, ipdsnum,
ipdstmpl, ipdstmplen, coordlist, numcoord,
idrsnum, idrstmpl, - idrstmplen, fld,
ngrdpts, ibmap, bmap, ierr) - For example GRIB2 section 4 - Product
Definition Template Number 4.0 (Analysis of
Forecast at a -
horizontal level or in a horizontal
layer at a point in time) - ipdsnum0 0 is Product
Definition Template Number 4.0 ( see Code Table
4.0) - numcoord0 Number of values
in array coordlist - coordlist0.0 Array
containing floating point values intended to
document the vertical -
discretization associated to model data on hybrid
coordinate vertical levels - ipdstmpl(1) 3 Meteorological
products, Mass Category - ipdstmpl(2) 5 Geopotential
Height (HGT) parameter number 5 (see Table
4.2-0-3)
31-
GRIB2 Encoding
Routines (continued) - -Data Representation Section (section 5)
- For example -GRIB2 section 5 - Data
Representation Section - idrsnum 40
Data Representation Template Number 40 ( see Code
Table 5.0 ) -
(40 is Grid Point Data - JPEG2000
Compression) - idrstmpl(1) 1236599024 Reference
value (R) (IEEE 32-bit floating-point value) - idrstmpl(2) 0
Binary scale factor (E) - idrstmpl(3) 2
Decimal scale factor (D) - idrstmpl(4) 18
Number of bits required to hold the resulting
scaled and referenced data values. - idrstmpl(5) 0
Type of original field values - idrstmpl(6) 0
Type of Compression used. (0 for Lossless) - idrstmpl(7) 255
Missing Target compression ratio - -GRIB2 section 6 - Bit Map Section
32-
GRIB2 Encoding Routines
(continued) - Gribend (gribend.f)
- This routine finalizes a GRIB2 message after
all grids and fields have been added. It adds - the End Section (7777) to the end of the
GRIB2 message and calculates the length of GRIB2
message - and stores it in the section 0 in (octet 9
16) - call gribend (cgrib, lcgrib,
lengrib, ierr) -
33GRIB2 Decoding Routines
- To Read a GRIB2 message with call routines are
following - Skgb (skgb.f)
- is used to search a file for the next
GRIB _ _ _ 2 (8-btyes) message in GRIB2 file. - If found, the length of message is
decoded from byte 9 to 16. (see Indicator
section 0) - call skgb(ifl1,iseek,msk1,lskip,lgrib
) - Gb_info (gb_info.f)
- is used to search through a GRIB2 message
to find out how many local use - sections and data fields found in the a
given GRIB2 message - call gb_info (cgrib, lcgrib,
listsec0, listsec1, numfields, numlocal,
maxlocal, ierr) - Gf_getfld (gf_getfld.f)
- is used to get all information of grid
definition (section 3), product template - (section 4), Bit-map (if applicable), and
the unpack data values for a given data - field. All information returned is store
in a derive type variable gfld - call gf_getfld (cgrib, lcgrib,
ifldnum, unpack, expand, gfld, ierr) - Note
- gfld is a type of gribfield which is
defined in module grib_mod (see grib_mod.f - for declaration of derive type gribfield)
34Declaration of Derived type gribfieldin Module
grib_mod
- type gribfield integer
version,discipline integer,pointer,dimen
sion() idsect integer
idsectlen character(len1),pointer,dimen
sion() local integer locallen
integer ifldnum integer
griddef,ngrdpts integer
numoct_opt,interp_opt,num_opt
integer,pointer,dimension() list_opt
integer igdtnum,igdtlen
integer,pointer,dimension() igdtmpl
integer ipdtnum,ipdtlen
integer,pointer,dimension() ipdtmpl
integer num_coord real,pointer,dimens
ion() coord_list integer
ndpts,idrtnum,idrtlen
integer,pointer,dimension() idrtmpl
logical unpacked logical
expanded integer ibmap
logical1,pointer,dimension() bmap
real,pointer,dimension() fld end type
gribfield - If variable gfld is declared of type
gribfield. - For example
- Type (gribfield) gfld
- The variable gfld would have the
following components - gfldversion GRIB edition number (
currently 2 ) -
35- Declaration of Derived Type Gribfield
- (continued)
- gflddiscipline Message Discipline ( see Code
Table 0.0) - gfldidsect() Contains the entries in the
Identification section 1 - gfldidrtmpl() Contains the data values for
the specified Data Representation Template - gfldidsectlen Number of elements in
gfldidsect(). - gfldlocal() Pointer to character array
containing contents of Local
Section 2, if included - gfldlocallen length of array gfldlocal()
- etc
-
- See routine (gribmod.f) in documentation block
for more components of - variable gfld is declared of type gribfield
-
36How to use routine getgb2?
- Getgb2 (getgb2.f)
- is used to search for selected fields
and unpack from a GRIB2 message - Call getgb2 (lugb,lugi,j,jdisc, jids,
jpdtn, jpdt, jgdtn,jgdt, unpack, k, gfld, iret) - Where
- j INTEGER NUMBER OF
FIELDS TO SKIP ( J0 search from beginning) - jdisc GRIB2 DISCIPLINE NUMBER
OF REQUESTED FIELD ( IF
-1, ACCEPT ANY DISCIPLINE) jids
INTEGER ARRAY OF VALUES IN THE IDENTIFICATION
SECTION (-9999 FOR
WILDCARD) jpdtn INTEGER PRODUCT
DEFINITION TEMPLATE NUMBER (N)
( IF -1, DON'T BOTHER MATCHING PDT - ACCEPT
ANY ) jpdt INTEGER ARRAY OF VALUES
DEFINING THE PRODUCT - DEFINITION TEMPLATE
4.N OF THE FIELD FOR WHICH - TO SEARCH (-9999
FOR WILDCARD) jgdtn INTEGER GRID
DEFINITION TEMPLATE NUMBER (M)
( IF -1, DON'T BOTHER MATCHING GDT - ACCEPT
ANY ) jgdt INTEGER ARRAY OF VALUES
DEFINING THE GRID DEFINITION
TEMPLATE 3.M OF THE FIELD FOR WHICH TO SEARCH
(-9999 FOR WILDCARD) - unpack LOGICAL VALUE INDICATING
WHETHER TO UNPACK BITMAP/DATA - .TRUE.
UNPACK BITMAP AND DATA VALUES - .FALSE. DO
NOT UNPACK BITMAP AND DATA VALUES - k INTEGER FIELD
NUMBER UNPACKED - gfld Derived type
gribfield ( defined in module grib_mod ) -
37- How to Use
Getgb2? -
- An example of using getgb2 is used to search for
field (Temperature at 100 mb level) by - product definition template.
- Initialize all variables to default -9999 or -1
for wildcard - J 0 Search from the
beginning of GRIB2 file - DJDSC-1 Discipline number
- JIDS-9999 Identification Section
- JGDTN-1 Grid Definition Template
Number - JGDT-9999 Grid Definition Template
- JPDTN-1 Product Definition
Template Number - JPDT-9999 Product Definition
Template - Search selected field by product definition
template number - and the values of product definition template 4.n
of the field - JPDTN 0 (search for production
template 4.0)
38- How to use
Getgb2? (continued) - How do we get the information of product template
4.0 for field Temperature at 100mb from - GRIB2 message ?
- We can use utility degrib2 to display the
content of GRIB2 message - degrib2 grib2file
- The content of GRIB2 file is displayed below
- GRIB MESSAGE 2 starts at 49405
- SECTION 0 0 2 17175
- SECTION 1 7 0 2 1 1 2010 12 13 0 0 0 0 1
- Contains 0 Local Sections and 1 data fields.
- FIELD 1
- SECTION 0 0 2
- SECTION 1 7 0 2 1 1 2010 12 13 0 0 0 0 1
- SECTION 3 0 41760 0 0 0
39How to use routine putgb2?
- Putgb2 routine (putgb2.f)
- is used to pack a single field into a
GRIB2 and writes out that message to the - file associated with unit number.
-
- Call putgb2
(lugb,gfld,iret) - NOTE
- The information to be packed into the GRIB
field is stored in a derived type variable, gfld. - Gfld is of type gribfield, which is defined in
module grib_mod, so users of this routine will - need to include the line "USE GRIB_MOD" in
their calling routine. Each component - of the gribfield type is described in the
subprogram documentation block of routine
gribmod.f - An example of using routine putgb2.f
- This program (g2_putgb2.f) reads an entire
GRIB2 file and find selected fields from a file
(data card) - and uses routine (putgb2.f) to pack into a
GRIB2 message and writes them out to a new GRIB2
file. -
- The content of data card is following
- GRIBIDS DESC' HGT 100 mb ',JPDTN 0 ,JPDT
3 5 2 0 96 0 0 1 6 100 0 10000 255 0 0 / - GRIBIDS DESC' HGT 100 mb ',JPDTN 0 ,JPDT
3 5 2 0 96 0 0 1 6 100 0 15000 255 0 0 /
40GRIB2 in NCEP Operations (continue)
- /nwprod/util/sorc/copygb2.fd
- The command copygb2 copies all or part of
one GRIB2 file to another GRIB2 file,
interpolating if necessary. Unless otherwise
directed (-x option), the GRIB2 index file is
also used to speed the reading. The fields are
interpolated to an output grid if specified (-g
option). The interpolation type defaults to
bilinear but may be specified directly
(-ioption). - For example 1 Script to copy all NAM GRIB2
(Regional CONUS - 40.63km - Lambert Conformal)
file - GRID TEMPLATE 3. 30
6 0 0 0 0 0 0 185 129 12190000 226541000 8
25000000 265000000 -
40635000 40635000 0 64
25000000 25000000 0 0 - to NAM GRIB2
(Regional CONUS High Resolution - 15km - Lambert
Conformal) - GRID TEMPLATE 3. 30
6 0 0 0 0 0 0 344 224 19262000 238623000 8
37500000 262000000 i -
15000000 15000000 0 64
30000000 60000000 0 0 - export grid2"30 6 0 0 0 0 0 0 344 224 19262000
238623000 8 37500000 262000000 - 15000000 1500000 0 0
64 30000000 60000000 0 0" - export g1nam.t00z.awip3d72.tm00.grib2
- export x1nam.t00z.awip3d72.tm00.grib2i
- copygb2 -g "grid2" g1 x1
nam.t00z.awip3d72.tm00.grib2.new - For example 2 Script to extract selected field
"MSLET Mean Sea Level" from NAM GRIB2 - (Regional CONUS 212 (40.63km -
Lamber Conformal) file by using the information - PRODUCT TEMPLATE
4. 0 3 192 2 0 84 0 0 1 72 101 0 0 255 0 0
41GRIB2 Reads and Writes Examples
- The program readwriteg2.f reads an entire GRIB2
file and extract selected field(s) unpacked from
GRIB2 messages and write it out to a new GRIB2
file. - The program readgrib2.f reads an entire GRIB2
file and extract selected field(s) from data
card and return packed GRIB2 message(s) to write
them out to a new GRIB2 file. - The program degrib2.f reads an entire GRIB2 file
and display the content of an entire GRIB2 file. - This program (g2_putgb2.f) reads an entire GRIB2
file and find selected fields from a file (data
card) and uses routine (putgb2.f) to pack into a
GRIB2 message and writes them out to a new GRIB2 - The program drap2g2.f reads the Global D-region
Absorption Prediction ASCII data - and write the data in GRIB2 file
- The examples of these programs are available to
download (tar file) from this url - http//www.nco.ncep.noaa.gov/sib/grib2/examples/
- Reads and displays the content of GRIB2 files
- Reads and extracts selected fields from data card
and write them out to a new file - Reads and extracts selected fields from data card
and write them out to a new file using putgb2
42SUMMARY
- NCEP GRIB2 tools hopefully will provide guidance
to all users to generate GRIB2 messages directly - WMO has mandated all operational centers to
transition to GRIB2 data for all the operational
products - Usage of CNVGRIB type of tools to convert from
GRIB1 to GRIB2 should be minimized - Generation of GRIB1 products take heavy storage
and are also computationally expensive - NCEPs parallel GRIB2 generation of NCEP POST
using NCOs g2tmpl library (under development)
for NEMS, NMMB and GFS show encouraging results
and are very valuable for NCEP's codes to run
more efficiently as well as occupy less disk and
tape space - NCO will continually improve the GRIB2 Template
source code to incorporate all the Product
Definition Templates. - NCO will improve the existing GRIB2 tools in the
future.