wgrib v1.6.0 Wesley Ebisuzaki Portable Grib decoder "Wgrib" is a portable program to read grib files that were created by the NCEP/NCAR Reanalysis Project. Of course, the program is not restricted to Reanalysis files but Eugenia Kalnay is happy whenever she sees the phrase "NCEP/NCAR Reanalysis". The documentation for wgrib is spread over several files, readme, readme.dos, formats.txt, grib2ieee.txt, notice, porting.txt, tricks.wgrib and usertables.txt and changes. Running wgrib without any arguments displays a short help message. Portable Grib decoder for NCEP Operations etc. it slices, dices v1.6.0 prelim 2 (7-01-97) Wesley Ebisuzaki usage: ./wgrib [grib file] [options] Inventory/diagnostic output selection -s/-v/-V short inventory/verbose inventory/very verbose non-inventory (default) regular inventory Options for inventory/diagnostic output -PDS/-PDS10/-GDS/-GDS10 print PDS/GDS in hex/dec -verf print forecast verification time -4yr/-ncep_opn/-ncep_rean see documentation Decoding Grib selection -d [record number] dump record number -p [byte position] dump record at byte position -i dump controlled by stdin (inventory list) (none) no decode .. inventory only Options for decoding Grib -text/-ieee/-bin/-grib dump to a text/ieee/bin/grib file -h/-nh dump will have headers (default)/no headers -H dump will include PDS and GDS (-bin/-ieee only) -append append to dump file -o [file] output file name, 'dump' is default *** Standard Inventory *** WGRIB's first duty is create an inventory. This inventory also serves as an index file. Using the test file land.grb you should be able to enter: % wgrib land.grb Using NCEP reanalysis table, see -ncep_opn, -ncep_rean options 1:0:d=87010100:LAND:kpds5=81:kpds6=1:kpds7=0:TR=0:P1=0:P2=0:TimeU=1:sfc:anl:NAve=1 The first line indicates that wgrib couldn't figure out whether to use the reanalysis or operational grib tables. Since land.grb is from reanalysis, we should use the reanalysis tables. Trying again, we get % wgrib land.grb -ncep_rean 1:0:d=87010100:LAND:kpds5=81:kpds6=1:kpds7=0:TR=0:P1=0:P2=0:TimeU=1:sfc:anl:NAve=1 The inventory consists of several fields separated by colons. The contents of the fields are: 1. Record number 2. Position in bytes 3. Date (YYMMDDHH). 4. Parameter name (LAND=land/sea mask) 5. Indicator of parameter and units (grib PDS octet 9) 6. Type of level/layer (grib PDS octet 10) 7. Height, pressure, etc (grib PDS octets 11-12) 8. Time Range (grib PDS octet 21) 9. Period of time 1, (grib PDS octet 19) 10. Period of time 2, (grib PDS octet 20) 11. Forecast time unit (grib PDS octet 18) 12. level 13. anl=analysis, fcst=forecast 14. NAve (number of grids used to make average) *** Short Inventory *** The short inventory can be obtained using the -s option. This inventory is easier to read the the previous inventory and can also be used as an index file. %wgrib -s land.grb -ncep_rean 1:0:d=87010100:LAND:sfc:anl:NAve=1 1. Record number 2. Position in bytes 3. Date (YYMMDDHH). 4. Parameter name (LAND=land/sea mask) 6. Type of level/layer (grib PDS octet 10) 7. Forecasts, analysis, etc 8. For an average, the number of fields averaged together *** Verbose Inventory *** The small verbose inventory can be obtained using the -v option. This inventory can be used as an index file. % wgrib -v land.grb -ncep_rean 1:0:D=1987010100:LAND:kpds=81,1,0:sfc:anl:"Land-sea mask [1=land; 0=sea] 1. Record number 2. Position in bytes 3. Date (YYYYMMDDHH). 4. Parameter name (LAND=land/sea mask) 5. KPDS5, KPDS6, KDPS7 (PDS Octets 9, 10, 11-12) 6. Type of level/layer (grib PDS octet 10) 7. Forecasts, analysis, etc 8. Description of parameter type *** Verbose Description *** The fourth type of file description can not be used as an index file. However, it is more human readable. It gives you information that is not normally available such as grid dimensions. Using the test file land.grb, you should be able to enter: %wgrib land.grb -V -ncep_rean rec 1:0:date 1987010100 LAND kpds5=81 kpds6=1 kpds7=0 levels=(0,0) grid=255 sfc anl: LAND=Land-sea mask [1=land; 0=sea] timerange 0 P1 0 P2 0 TimeU 1 nx 192 ny 94 GDS grid 4 num_in_ave 1 missing 0 center 7 subcenter 0 process 80 Table 2 gaussian: lat 88.542000 to -88.542000 long 0.000000 to -1.875000 by 1.875000, (192 x 94) scan 0 bdsgrid 1 min/max data 0 1 num bits 4 BDS_Ref 0 DecScale 1 BinScale 0 The first line states the record 1 starts at byte position 0 the initial date is January 1, 1987 at 00Z the parameter is "LAND" (numeric code 81, PDS octet 9) with a level type 1 (kdps6=1, PDS octet 10) and value 0 (PDS octets 11-12) or levels(0,0) (PDS octet 11, PDS octet 12) with a user defined grid (grid=255) and it is a surface analysis The second line is a further description of the parameter type The third line describes timerange (PDS octet 21) P1 (PDS octet 19) P2 (PDS octet 20) TimeU (PDS octet 14) nx ny grid size as used by wgrib GDS grid (GDS octet 6) num_in_ave (PDS octet 22-23) number missing from average (PDS octet 24) The fourth line describes center (PDS octet 5) subcenter (PDS octet 26) process (PDS octet 6) parameter table version (PDS octet 4) The fifth and sixth lines describe the grid type The last line describes minimum and maximum values of the data the number of bits used to store the data the minimum value the decimal and binary scaling used Most of the information within this description will only make sense if you have a copy of the GRIB definition as reference. If you want to determine the contents of record N, try the command: %wgrib land.grib -V -d N This command also writes a binary dump of the record but it's quick. If you don't want a binary dump, try (on a UNIX machine), %wgrib land.grib -V -d N -o /dev/null *** Extracting Data *** The second major function of wgrib is to extract data from a grib file. The output can be binary, IEEE (big endian), grib and text. All output formats except grib can be written with or without a header. See FORMATS.TXT for more information. The '-append' option appends the extracted data and the '-o [filename]' allows you to set the default output file which is normally "dump". Note: binary format with a header is often compatible with fortran code. Note: IEEE output is "big-endian". Note: writing in binary is faster than writing ieee. Note: using a binary format is faster, more precise and uses less disk space than the text format. Note: The standard NCEP convention is that the arrays are stored in fortran order starting from the north and 0E. The following data goes south and eastward. *** How to select data to be extracted *** 1) by record number wgrib land.grib -d 1 (extract first record) 2) by position wgrib land.grib -p 0 (extract record starting at byte 0) 3) by (machine readable) inventory (UNIX/AMIGA/MS-DOS) wgrib land.grb | wgrib -i land.grb -o output.bin The third method is the most powerful one. Suppose you have a grib file with many different fields. You want to extract all the zonal winds (UGRD in NCEP files), you could type at a Unix machine: wgrib grib_file | grep ":UGRD:" | wgrib grib_file -i Suppose you want to extract the 500 mb U winds, then you could type at a Unix machine: wgrib grib_file -s | grep ":UGRD:" | grep ":500 mb:" | wgrib -i grib_file For more information on how to write ieee, binary, text and grib files see the file FORMATS.TXT. *** Some Output Formats *** Binary with a f77-style header Suppose you wish to convert all the 500 mb heights (HGT in NCEP files) to binary with a header. The following line would convert "infile" to "outfile". % wgrib -s infile | grep ":HGT:500 mb:" | wgrib -i infile -o outfile The "outfile" is often compatible with the fortran compiler. Binary with no header Suppose you wish to convert all the 500 mb heights (HGT) to binary with a NO header. The following line would convert "infile" to "outfile". % wgrib -s infile | grep ":HGT:500 mb:" | wgrib -i -nh infile -o outfile The "outfile" is often compatible with fortran direct-access I/O. Text Converting a grib file into a text file is slow (reading and writing), takes up much more disk space and can have less precision. Nevertheless it has its uses. % wgrib -s infile | grep ":HGT:500 mb:" | wgrib -i -text infile -o outfile IEEE Most workstations computers use big-endian IEEE as their binary format. For these machines, one should not use the -ieee option as it is slower and could lose some precision. However, the following line will create a big-endian IEEE with f77-style headers. % wgrib -s infile | grep ":HGT:500 mb:" | wgrib -i -ieee infile -o outfile Without headers, one would use % wgrib -s infile | grep ":HGT:500 mb:" | wgrib -i -nh -ieee infile -o outfile GRIB Suppose you have a large file with every variable imaginable. But you are a simple person with limited means. You only want the 500 mb heights and you have limited disk space. The following will extract the 500 mb heights as a grib file. % wgrib -s infile | grep ":HGT:500 mb:" | wgrib -i -grib infile -o outfile