Skip Navigation Links weather.gov 
NOAA logo-Select to go to the NOAA homepage National Oceanic Atmospheric Administration   Select to go to the NWS homepage
     

GRIB2 Encoding Details for the National Weather Service Digital Forecast Database


Background

The National Weather Service (NWS) is creating a National Digital Forecast  Database (NDFD) which will contain gridded forecasts of several weather  elements.  In general, the weather parameters in the NDFD will be ground-based, sensible weather elements.  The forecast grids  that comprise the NDFD will come from multiple sources, including the NWS' Weather Forecast Offices   (WFO) and the National Centers for Environmental  Prediction (NCEP).  The World Meteorological Organization (WMO) has  adopted Edition 2 of the GRIB code as a standard for sharing GRI dded B inary data.  GRIB, Edition 2 (GRIB2) will be involved  in the NDFD in two ways.  First, GRIB2 will be the code form used to  transmit gridded forecasts from contributing  offices to the NDFD.  Second, GRIB2 will be one of the primary forms used to transmit the NDFD grids to NWS customers and partners.

The purpose of this document is to describe, in detail, the techniques that will be used to encode NWS forecasts into NDFD GRIB2 bulletins.  When dealing with a code as general and as flexible as GRIB2, one often encounters multiple, plausible ways to accomplish the encoding task.  It is hoped that this document will clarify the many decisions made during the creation of the NDFD.

References

This document will assume that the reader has access to and a working knowledge of the WMO publication FM 92-XII GRIB General Regularly-distributed Information in Binary Form.  This link should provide access to a version that has been formatted for web access.  Additionally, the following links provide access to several documents that describe encode/ decode routines developed by the NWS' Meteorological Development Laboratory (MDL).  These documents provide valuable commentary on some of the fields used in the GRIB2 code form.
The NWS has created an NDFD information web page.  There you will find the latest news regarding NDFD plans and recent developments.  In addition, MDL developers have written software that may be downloaded and used for accessing and decoding NDFD GRIB2 files from the NWS Telecommunications Gateway.  To obtain the latest version of this software, follow this link.

File, and Bulletin Structure

A single file will contain multiple GRIB2 bulletins.  One file will contain all forecast projections for a given weather element covering a specific geographic region.  There will be NDFD grids available for 16 different CONUS sub-sectors as well as for the CONUS itself.  See this link for a detailed list of geographic sectors, filenames, and WMO header information with regards to NDFD data.

Every NDFD GRIB file begins with a flag field separator of the format:

****nnnnnnnnnn****\lf

where the "nnnnnnnnnn" is the size in bytes of the file, (minus the separator),   right justified with leading zeroes, and with a trailing "\lf".  The "\lf" character represents a single octet with the decimal value of 10.  The size of the Flag field separator is 19 bytes.

    Following the flag field separator is a WMO super header.  Check  this  link   above  for specific format of NDFD WMO headers.  The WMO super header  is 21  bytes long, the trailing "\cr\cr\lf" inclusive.  The "\cr" character represents a single octet with the decimal value of 13.  Immediately  following the super header is another flag field separator for the first GRIB2 bulletin in the file.  It contains the size of the bulletin to follow.

The bulletin itself begins with a WMO header.  Again, refer to the link above to get detailed information regarding the format of  the header.  The header contains the valid time of the GRIB2 bulletin.  The WMO  header is also 21 bytes long, the trailing "\cr\cr\lf" inclusive.  Following the header is the packed GRIB2 grid.  It begins with the ASCII text "GRIB"  and ends with the ASCII text "7777".  The packed data contains all the GRIB2 sections for that grid, as well as the packed grid.
Here's an example of the file format (individual components are bracketed with "< >"):

<file flag field separator\lf>
<WMO super header\cr\cr\lf>
<bulletin 1 flag field separator\lf>
<WMO header 1 for bulletin\cr\cr\lf>
<"GRIB"packed data7777><bulletin 2 flag field separator\lf>
<WMO header 2 for bulletin\cr\cr\lf>
<"GRIB"packed data7777><bulletin 3 flag field separator\lf>
.
.
.
<WMO header nn for bulletin\cr\cr\lf>
<"GRIB"packed data7777>

Octet Contents

The sections that follow list the contents of the GRIB2 bulletin, octet by octet.  When contents are described as "Missing," all bits are set to "1" in accordance with regulation 92.1.4.  When contents are described by a number, that number will be stored in the apprpriate octet.

Section 0--Indicator Section


Octet No. Contents
1-4 "GRIB"
5-6 Missing
7 0 - for Meteorological Products, 10 - for Oceanographic Products
8 2
9-16 Total length of GRIB message in octets (including Section 0)

Section 1--Identification Section

In Section 1, octets 13-19 contain the reference time for the GRIB bulletin.  The NDFD is currently produced once an hour.  The reference time in Section 1 represents the day/hour of the current NDFD production cycle.
 

Octet No. Contents
1-4 21
5 1
6-7 8
8-9 Missing
10 1
11 0 - Value will be used to designate the version number of the GRIB2-encoding software that produced the bulletin.  When changes to this published format occur, this version number will be updated. 
12 1
13-14 Year (4 digits)
15 Month
16 Day
17 Hour
18 Minute
19 Second
20 0 or 1
21 1

Section 2--Local Use Section

Certain weather elements have provided particular challenges in encoding   them in GRIB2.  Using Section 2 to encode various forms of metadata provides one solution.  For the NDFD element Weather, ("Wx"), MDL GRIB2 encoding software uses the Local Use section for packing metadata unique to each grid.  At this time, for parameters other than Wx, the Local Use section is omitted.

Grids of Wx are stored as two distinct entities.  The   first entity is a grid  of small integer values that will generally  store very compactly in Section  6.  The second entity is a series  of null-terminated strings of ASCII  characters called Weather Keys.    The integers on the weather grid serve  as indices, each pointing to   one of the Weather Keys in the series.    Each Weather Key is comprised  of one or more weather subkeys, separated by  a caret "^".

Essentially, the metadata packed in the Local Use Section for the parameter Wx is a lookup table.  The ASCII characters are loaded, one per octet, and then compressed using the Simple Packing Scheme for integers defined for Section 5.  The Simple Packing Scheme treats the set of Weather Keys as an integer array.  Each integer in the array is a decimal representation that corresponds to an ASCII character.  For instance, the integer 65 translates to the ASCII character "A".  The null character is represented by the integer 0, so that whenever a 0 is encountered in the array, it marks the ending of a unique Weather Key.  The tables that follow show the specific contents of the Weather Keys and subkeys.
 


Octet No. Contents
1-4 Length of section in octets (nn)
5 2
6 Total number of characters comprising the series of Weather Keys 
7 0
8-nn The Weather Keys needed to describe the weather on the grid, packed using the Simple Packing scheme

Weather Keys and Subkeys

A weather subkey has five parts, seperated by colons ":".  These parts include
  • one weather type code.  See Weather Type Codes, below.
  • one coverage/probability code.  See Coverage/probability Codes, below.
  • one intensity code.  See Intensity Codes, below.
  • one visibility code.  See Visibility Codes, below.
  • Weather Type Codes


    Code Meaning Code Meaning
    <NoWx> No Weather T Thunder
    A Hail R Rain
    RW Rain Showers L Drizzle
    ZR Freezing Rain ZL Freezing Drizzle
    S Snow SW Snow Showers
    IP Ice Pellets (sleet) F Fog
    H Haze BS Blowing Snow
    K Smoke BD Blowing Dust
    FR Frost BN Blowing Sand
    IF Ice Fog IC Ice Crystals
    ZF Freezing Fog ZY Freezing Spray
    VA Volcanic Ash WP Water Spouts

    Coverage/probability Codes


    Code Meaning Code Meaning
    <NoCov> No Coverage/probability Iso Isolated
    Sct Scattered Num Numerous
    Wide Widespread Ocnl Occasional
    SChc Slight Chance Chc Chance
    Lkly Likely Def Definite
    Patchy Patchy Areas Areas of

    Intensity Codes


    Code Meaning Code Meaning
    <NoInten> No Intensity -- Very Light
    - Light m Moderate
    + Heavy

    Visibility Codes

    The following visibility codes may appear in WFO-generated GRIB2 bulletins.  The units are statute miles:  <NoVis>, 0SM, 1/4SM, 1/2SM, 3/4SM, 1SM, 11/2SM, 2SM, 21/2SM, 3SM, 4SM, 5SM, 6SM, P6SM.

    Attribute Codes


    Code Meaning Code Meaning
    FL Frequent Lightning GW Gusty Winds
    HvyRn Heavy Rain DmgW Damaging Winds
    SmA Small Hail LgA Large Hail
    OLA Outlying Areas OBO on Bridges and Overpasses

    Size Limitations for NDFD National Grids

    There is no (practical) limit to the number of weather keys, subkeys, etc.  For NDFD grids that are national mosaicks of WFO-generated grids, the following limitations will be applied:

    Item Maximum number that will be present
    Weather Attributes in a Weather Subkey 5
    Weather Subkeys in a Weather Key 5

    Weather Key Examples


    Sample Weather Key Meaning
    Sct:SW:-:<NoVis>: Scattered snow showers
    Ocnl:R:-:<NoVis>:^S:Ocnl:-:<NoVis>:^
    SChc:ZR:-:<NoVis>:
    Occasional rain and snow, with a slight chance of freezing rain
    Wide:FR:-:<NoVis>:OLA Widespread frost in the outlying areas
    <NoWx>:<NoCov>:<NoInten>:<NoVis>: No weather
    Sct:RW:-:<NoVis>:^T:Iso:m:<NoVis>: Scattered showers with isolated thunderstorms
    Sct:T:+:<NoVis>:DmgW,LgA Scattered severe thunderstorms with damaging winds and large hail

    Section 3--Grid Definition Section

    Section 3 will vary depending upon the  map projection the grid is  defined.  This document will be updated as these grid definitions become better defined.  Latitude and longitude values are in 10 -6 degrees.

    Lambert Conformal


    Octet No. Contents
    1-4 Length of section in octets (nn)
    5 3
    6 0
    7-10 Number of data points
    11 0
    12 0
    13-14 30 - template number
    15 1
    16 0
    17-20 6371200 - Radius of the earth
    21 Missing
    22-25 Missing
    26 Missing
    27-30 Missing
    31-34 Nx - number of points along the X-axis
    35-38 Ny - number of points along the Y-axis
    39-42 La1 - latitude of first grid point
    43-46 Lo1 - longitude of first grid point
    47 0
    48-51 25,000,000 - Latitude where grid spacing is defined
    52-55 265,000,000 - Orientation longitude
    56-59 5,079,406 - Dx, X-direction grid length
    60-63 5,079,406  - Dy, Y-direction grid length 
    64 0
    65 80 - Scanning Mode
    66-69 25,000,000 - Latin1, first secant latitude
    70-73 25,000,000 - Latin2, second secant latitude
    74-77 -90,000,000 - Latitude of southern pole 
    78-81 0 - Longitude of southern pole

    Polar Stereographic


    Octet No. Contents
    1-4 Length of section in octets (nn)
    5 3
    6 0
    7-10 Number of data points
    11 0
    12 0
    13-14 20 - template number
    15 1
    16 0
    17-20 6371200 - Radius of the earth
    21 Missing
    22-25 Missing
    26 Missing
    27-30 Missing
    31-34 Nx - number of points along the X-axis
    35-38 Ny - number of points along the Y-axis
    39-42 La1 - latitude of first grid point
    43-46 Lo1 - longitude of first grid point
    47 0
    48-51 Lat where mesh length is true
    52-55 Orientation longitude of grid
    56-59 Dx
    60-63 Dy
    64 0 - Projection center flag
    65 80 - Scanning mode

    Mercator


    Octet No. Contents
    1-4 Length of section in octets (nn)
    5 3
    6 0
    7-10 Number of data points
    11 0
    12 0
    13-14 10 - template number
    15 1
    16 0
    17-20 6371200 - Radius of the earth
    21 Missing
    22-25 Missing
    26 Missing
    27-30 Missing
    31-34 Nx - number of points along the X-axis
    35-38 Ny - number of points along the Y-axis
    39-42 La1 - latitude of first grid point
    43-46 Lo1 - longitude of first grid point
    47 0
    48-51 Lat where projection intersects the Earth (where mesh length defined)
    52-55 La2 - latitude of last gridpoint
    56-59 Lo2 - longitude of last gridpoint
    60-63 80 - Scanning mode
    61-64 Orientation angle of the grid
    65-68 Di - longitudinal direction grid length 
    69-72 Dj - latitudinal direction grid length

    Section 4--Product Definition Section

    Section 4 will vary from one weather element to the next.  The formats for the various elements are detailed in the following sections:

    Maximum Temperature (MaxT), Minimum Temperature (MinT)


    Octet No. Contents
    1-4 58
    5 4
    6-7 0
    8-9 8
    10 0
    11 4 for MaxT 
    5 for MinT
    12 2
    13 0
    14 0
    15-16 Missing
    17 Missing
    18 1
    19-22 Hours from reference time to beginning of MaxT/MinT valid period. 
    23 1
    24 Missing
    25-28 Missing
    29 Missing
    30 Missing
    31-34 Missing
    35-36 Year of end of MaxT/MinT valid period in GMT.
    37 Month of end of MaxT/MinT valid period in GMT. 
    38 Day of end of MaxT/MinT valid period in GMT.
    39 Hour of end of MaxT/MinT valid period in GMT.
    40 Minute of end of MaxT/MinT valid period in GMT.
    41 Second of end of MaxT/MinT valid period in GMT.
    42 1
    43-46 0
    47 2 for MaxT.  3 for MinT.
    48 Missing
    49 1
    50-53 12
    54 1
    55-58 0

    Twelve-hour Probability of Precipitation (PoP12)


    Octet No. Contents
    1-4 Length of section in octets (nn)
    5 4
    6-7 0
    8-9 9
    10 1
    11 8
    12 2
    13 0
    14 0
    15-16 Missing
    17 Missing
    18 1
    19-22 Hours from reference time to beginning of PoP12 valid period. 
    23 1
    24 Missing
    25-28 Missing
    29 Missing
    30 Missing
    31-34 Missing
    35 Missing
    36 Missing
    37 1
    38 Missing
    39-42 Missing
    43 -3
    44-47 254
    48-49 Year of end of PoP12 valid period in GMT.
    50 Month of end of PoP12 valid period in GMT.
    51 Day of end of PoP12 valid period in GMT.
    52 Hour of end of PoP12 valid period in GMT.
    53 Minute of end of PoP12 valid period in GMT.
    54 Second of end of PoP12 valid period in GMT.
    55 1
    56-59 0
    60 1
    61 Missing
    62 1
    63-66 12
    67 1
    68-71 0

    Temperature, Dewpoint, Sky, Wind Speed, Wind Direction, Wave Height, 20Ft Wind Speed, 20Ft Wind Direction, Weather, Wind Gust


    Octet No. Contents
    1-4 Length of section in octets (nn)
    5 4
    6-7 0
    8-9 0
    10 Parameter Category (FM 92 GRIB, Code Table 4.1) See table below for specific values
    11 Parameter Number (FM 92 GRIB, Code Table 4.2) See table below for specific values
    12 2
    13 0
    14 0
    15-16 Missing
    17 Missing
    18 1
    19-22 Forecast projection in hours
    23 1
    24 Missing
    25-28 Missing
    29 Missing
    30 Missing
    31-34 Missing

    Parameter Categories and Numbers for Product Definition Template 0 elements


    Parameter Category Number
    Temperature 0 0
    Dewpoint 0 6
    Sky 6 1
    Wind Speed 2 1
    Wind Direction 2 0
    Wave Height (see Note 1) 0 5
    Weather 1 192
    20Ft Wind Speed 2 1
    20Ft Wind Direction 2 0
    Wind Gust 2 22

    Note 1: Wave Height is defined as an Oceanographic Product in the Indicator Section, octet 7.

    QPF, and Snow Amount

     
    Octet No. Contents
    1-4 Length of section in octets (nn)
    5 4
    6-7 0
    8-9 8
    10 1
    11 8     for QPF
    29   for Snow Amount 
    12 2
    13 0
    14 0
    15-16 Missing
    17 Missing
    18 1
    19-22 Hours from reference time to beginning of valid period. 
    23 1
    24 Missing
    25-28 Missing
    29 Missing
    30 Missing
    31-34 Missing
    35-36 Year of end of valid period in GMT. 
    37 Month of end of valid period in GMT.
    38 Day of end of valid periodin GMT.
    39 Hour of end of valid period in GMT.
    40 Minute of end of valid period in GMT.
    41 Second of end of valid period in GMT. 
    42 1
    43-46 0
    47 1
    48 Missing
    49 1
    50-53 6
    54 1
    55-58 0

    Section 5--Data Representation Section

    The GRIB2 standard supports six forms of data packing.  Grids transmitted as part of the NDFD will either use complex packing and spatial differencing (Data Representation Template 5.3) or complex packing (Data Representation Template 5.2).  For each grid, the encoding software will assess the effectiveness of applying spatial differencing.  If no value is found, complex packing will be used for that grid.  Applications that decode NDFD grids should be prepared to encounter either form of data packing.

    NDFD grids will generally contain a significant number of missing values.  National mosaic grids are defined to be rectangles, and they generally extend into areas where NWS WFOs do not have forecast responsibility.


    Octet No. Contents
    1-4 47
    5 5
    6-9 Total number of data points.
    10-11 2 or 3
    12-15 Reference value (R) as an IEEE 32-bit floating-point value.  Varies from grid to grid.
    16-17 Binary scale factor (E).  Varies from weather element to weather element.  See Element Encoding Characteristics Table for values.
    18-19 Decimal scale factor (D).  Varies from weather element to weather element.  See Element Encoding Characteristics Table for values.
    20 Number of bits used for each group reference value.
    21 1 (integer) for Weather grids; 0 (floating point) for all other weather elements.
    22 1
    23 1
    24-27 Primary missing value substitute.  See Element Encoding Characteristics Table for values.  The values in the table will appear in the GRIB2 bulletins in Section 5, but will not appear with the data in section 7.  The GRIB2 standard calls for missing values to be carried as the largest value possible in a particular group.
    28-31 Missing
    32-47 See GRIB2 documentation.
    48 Order of spatial differencing

    Section 6--Bit-map Section

    Bit-maps will not be used in NDFD GRIB bulletins.  Missing values will appear in those grid locations where forecasts are not valid.
     

    Octet No. Contents
    1-4 Length of section in octets (nn)
    5 6
    6 255

    Section 7--Data Section


    Octet No. Contents
    1-4 Length of section in octets (nn)
    5 7
    6-nn See GRIB2 documentation.

    Section 8--End Section


    Octet No. Contents
    1-4 "7777"

    Element Encoding Characteristics


    Weather
    Element
    Original
    NDFD
    Units
    GRIB-
    encoded
    Units
    Binary Scale
    Factor
    Decimal Scale
    Factor
    Primary Missing 
    Value Substitute
    MaxT Fahrenheit Kelvin 0 1 9999
    MinT Fahrenheit Kelvin 0 1 9999
    PoP12 Percent Probability Percent
    Probability
    0 0 9999
    T Fahrenheit Kelvin 0 1 9999
    Td Fahrenheit Kelvin 0 1 9999
    Sky Percentage
    Total sky coverage
    Percentage
    Total sky
    coverage
    0 0 9999
    Wind Speed knots ms-1 0 1 9999
    Wind Direction degrees true degrees true 0 0 9999
    Weather N/A N/A 0 0 9999
    QPF inches kgm-2 0 1 9999
    SnowAmt inches meters 0 1 9999
    Wave Height feet meters 0 0 9999
    20Ft Wind Speed knots ms-1 0 1 9999
    20Ft Wind Direction degrees true degrees true 0 0 9999
    Wind Gust knots ms-1 0 1 9999


    US Dept of Commerce
    National Oceanic and Atmospheric Adminstration

    National Weather Service
    Office of the Chief Information Officer (OCIO11)
    1325 East West Highway
    Silver Spring, MD 20910
    Page last modified: June 10, 2003
    Page Author:
    Data Management
    Disclaimer
    Feedback
    Privacy Notice
    Credits