1. Definitions

A "grib file" is a collection of grib records in the GRIB format that contains Meteorological
parameters.

A "grib file index" (gbx8) is an index for the grib file that contains global attributes about
the file, metadata for the parameters including data offsets, and the grid information.

2. Binary Index(gbx8) Structure

The gbx8 structure has three sections:
 - global attributes for the file
 - the definition of the parameter from the Production Definition Section(PDS), time information,
   and offsets to the data for each individual parameter.
 - Grid Definition Section(GDS) for the file

Since the index is in binary format, the ShowGribIndex method displays the contents of the
index, it's invoked by ucar.grib.ShowGribIndex <indexfile>.

Sample output for a GFS_Global_2p5deg.gbx8 index using ShowGribIndex.

index_version = 8.0
grid_edition = 2
location = /local/robb/data/grib/GFS_Global_2p5deg.grib2
length = 61566990
created = 2010-03-31T20:56:04Z
center = 7
sub_center = 0
table_version = 1
basetime = 2009-02-04T12:00:00Z
ensemble = false
-----------------------------------------------------------------
0 0 2 2 2 100 1000.0 255 0.0 2009-02-04T12:00:00Z 192 51437077 37 109 -9999 true 7 0 1 -9999 -9999 -9999.0 -9999.0
0 0 2 3 2 100 1000.0 255 0.0 2009-02-04T12:00:00Z 192 51437077 37 12658 -9999 true 7 0 1 -9999 -9999 -9999.0 -9999.0
0 0 2 2 2 100 2000.0 255 0.0 2009-02-04T12:00:00Z 192 51437077 25076 25148 -9999 true 7 0 1 -9999 -9999 -9999.0 -9999.0
0 0 2 3 2 100 2000.0 255 0.0 2009-02-04T12:00:00Z 192 51437077 25076 37646 -9999 true 7 0 1 -9999 -9999 -9999.0 -9999.0
...
...
...
-----------------------------------------------------------------
GDSkey = 51437077
grid_type = 0
grid_name = Latitude_Longitude
grid_shape_code = 6
grid_shape = Earth spherical with radius of 6,371,229.0 m
grid_radius_spherical_earth = 6371229.0
Nx = 144
Ny = 73
La1 = 90.0
Lo1 = 0.0
Dx = 2.5
Dy = 2.5
La2 = -90.0
Lo2 = 357.5
Quasi = false
ResCompFlag = 48
VectorComponentFlag = 0
Winds = True
scanning_mode = 0
grid_units = degrees

3. Documentation

The official WMO Grib documentation is located at:
Brief document:
http://www.wmo.int/pages/prog/www/WDM/Guides/Guide-binary-2.html
Detailed document
http://www.wmo.int/pages/prog/www/WMOCodes.html
NCEP documentation:
GRIB2 documentation:
http://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc.shtml
GRIB1 documentation:
http://www.nco.ncep.noaa.gov/pmb/docs/on388/

4. Binary Index(gbx8) Dump Explanation.

First section is self explanatory.

index_version = 8.0
grid_edition = 2
location = /local/robb/data/grib/GFS_Global_2p5deg.grib2
length = 61566990
created = 2010-03-31T20:56:04Z
center = 7
sub_center = 0
table_version = 1
basetime = 2009-02-04T12:00:00Z
ensemble = false


Second section has one line of metadata about each parameter in the file. Most of the
information is obtained from the Production Definition Section(PDS) in the record.

Using the first line in the second section above as a sample:

0 0 2 2 2 100 1000.0 255 0.0 2009-02-04T12:00:00Z 192 51437077 37 109 -9999 true 7 0 1 -9999 -9999 -9999.0 -9999.0

A description of the above numbers by row position follows:

1 The Product template number used to encode the PDS.
2-4 A parameter is referenced by a Discipline, Category, and a Parameter number from a
    parameter table.
5 Type of Generating process, for example 2 = Forecast. Complete table referenced in documentation.
6-7 First level type and value. Level types referenced in documentation.
8-9 Second level type and value. 255 is for missing data.
10 Reference time for the model
11 Valid time, offset from Reference time
12 The GDS Key. Since most of the models have the same Grid Definition Section(GDS) only one
   copy of each GDS is stored in the index to save space. The GDS is encoded as a number that
   is referenced by each record as the GDS key
13 The GDS offset in the file for this record.
14 The PDS offset in the file for this record.
15 The Decimal scale. In Grib1 used to decode the data, not used in Grib2
16 Boolean used to determine if a Bit Map exists for the Grib1 data, not used in Grib2
17 Center that created the data.
18 Sub-Center for the center.
19 Table version number.
20 Is parameter an Ensemble, Probability, or Derived Type. Usually set to -9999.
21 Number of forecast in an Ensemble, Usually set to -9999.
22 Lower Limit of a Probability. Usually set to -9999.
23 Upper Limit of a Probability. Usually set to -9999.

Third section is the metadata about the Grid Definition Section(GDS) for the file. Most
files only have one but it's possible to have more. Since there are many different GDS's
available, the definitions are available in the documentation with descriptions.
For the above sample, using grid_name = Latitude_Longitude as a reference for which type of
grid parameters are referenced.

GDSkey = 51437077
grid_type = 0
grid_name = Latitude_Longitude
grid_shape_code = 6
grid_shape = Earth spherical with radius of 6,371,229.0 m
grid_radius_spherical_earth = 6371229.0
Nx = 144
Ny = 73
La1 = 90.0
Lo1 = 0.0
Dx = 2.5
Dy = 2.5
La2 = -90.0
Lo2 = 357.5
Quasi = false
ResCompFlag = 48
VectorComponentFlag = 0
Winds = True
scanning_mode = 0
grid_units = degrees


5. The actual sequence of data in the gbx8 index.

// Section 1 Global attributes
- One string separated by spaces that contains:
       index_version, grid_edition, location, file length, created date, center, sub_center
       table_version, baseTime, basetime, and if ensemble data.

// Section 2 Individual record information
- Number of records

- One line for each record containing:
 Discipline, RefTime, GDSkey, GdsOffset, PdsOffset, PDS length, PDSBytes


// section 3: GDSs in this File

- Number of GDSs in file

- For each GDS: length, GDS Bytes



