wgrib v1.6 7/97 Wesley Ebisuzaki Portable Grib decoder Introduction: The program wgrib is written in standard (ANSI/ISO) C. It has been tested on supercomputers, workstations, and home computers. If you are running MS-DOS on a 386 or higher with a math coprocessor, there is already a compiled version (WGRIB.EXE). Others will have supply an ANSI/ISO C compiler. This version will not compile correctly with a K&R C compiler nor will it work with a 16-bit compiler. Compiling: Version 1.6 introduces a compile-time option "DEF_T62_NCEP_TABLE". For the operational version of wgrib, DEF_T62_NCEP_TABLE=opn while Reanalysis uses DEF_T62_NCEP_TABLE=rean. For compatibility with earlier versions, the default is "reanalysis". The compile-time option determines whether to use the operational or reanalysis GRIB table for the T62 model when the subcenter is zero. Of course, the default can be changed at run time by the -ncep_opn and -ncep_rean options. Compiling wgrib with the default option (Reanalysis) can be done by: sun: acc -o wgrib wgrib.c -lm sun: gcc -o wgrib wgrib.c -lm (note: sun's cc is not an ANSI C compiler) (note: gcc should use gcc's includes not cc's includes. cc is sun's K&R C compiler.) cray: cc -o wgrib wgrib.c sgi: cc -o wgrib wgrib.c -lm hp: gcc -o wgrib wgib.c -lm hp: cc -Aa -o wgrib wgrib.c -lm amiga: sc link math=ieee output=wgrib all.c For the operational version on can compile by: sun: acc -o wgrib -DDEF_T62_NCEP_TABLE=opn wgrib.c -lm sun: gcc -o wgrib -DDEF_T62_NCEP_TABLE=opn wgrib.c -lm (note: sun's cc is not an ANSI C compiler) cray: cc -o wgrib -DDEF_T62_NCEP_TABLE=opn wgrib.c sgi: cc -o wgrib -DDEF_T62_NCEP_TABLE=opn wgrib.c -lm hp: gcc -o wgrib -DDEF_T62_NCEP_TABLE=opn wgib.c -lm hp: cc -Aa -o wgrib -DDEF_T62_NCEP_TABLE=opn wgrib.c -lm Optimization: You may have noticed that the previous compilation command lines did not include any optimizations. My suggestion is that one should avoid the compiler optimizations unless one is willing to make sure that the compiler optimizations didn't break the code. Sure compilers are better than before but optimization bugs still occur (ex. gcc 2.7.0 on a local HP workstation). Porting: Versions of wgrib have been ported to the Macintosh and to a 16-bin Windows compiler. Check the web page, for more information. Problems Compiling: If you have problems with compiling, you probably using a non-Standard C compiler or the compiler has been improperly set up. A number of companies have been making a standard C compiler an option. If you need a C compiler, check out the GNU C compiler (gcc). It has been ported to many machines and is fast and free. If you have problems linking ("undefined ....") then you are not including a necessary library. On many UNIX machines, you need to include the math library ('-lm' option). If you have problems compiling wgrib, consult a local wizard. I only have access to suns, crays, sgi, hp, linux boxes, and amigas. If you ask for help compiling on a Moon8 workstation using the VenusII v1.2 C compiler under the Marsix 4.3 operating system, I really can't help. Testing wgrib: Test 1: After you've compiled wgrib is simply type "wgrib." You should see the help screen which should be similar to the following: 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 The first line of the "help" page should include the phrase "NCEP Operations" or "NCEP/NCAR Reanalysis" which indicates the default GRIB table (see "Compiling.") Test 2: The second test is to see if wgrib will read a grib file. If the file "land.grb" is not with the source code, a copy can be obtained from ftp://wesley.wwb.noaa.gov/pub/wgrib/land.grb. 'land.grb' is the land-sea mask used by Reanalysis. enter: wgrib land.grb -ncep_rean see: 1:0:d=87010100:LAND:kpds5=81:kpds6=1:kpds7=0:TR=0:P1=0:P2=0:TimeU=1:sfc:anl:NAve=1 Test 3 The third test is read the grib file and decode the numeric data. enter: wgrib land.grb -V -ncep_rean see: 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 Test 4: This tests the wgrib's ability to extract a record and write it as a text file. enter: wgrib land.grb -d 1 -text see: 1:0:d=87010100:LAND:sfc:anl:NAve=1 The first 10 lines of the file 'dump' should be: 192 94 0 0 0 0 0 0 0 0 0 Text 5 In this test a record is written as a f77 big-endian IEEE file. enter: wgrib land.grb -d 1 -ieee -s -ncep_rean see: 1:0:d=87010100:LAND:sfc:anl:NAve=1 Should find a file 'dump' which is which is 72200 bytes long. Test 6 In this test a record is written as native-format binary file. enter: wgrib land.grb -d 1 -s -ncep_rean see: 1:0:d=87010100:LAND:sfc:anl:NAve=1 Should find a new file 'dump' which is often 72200 bytes long. Test 7 Reading a binary file using a C program. Run test 6 to convert the land mask into a binary file. Compile the program testbin.c using a C compiler. Some possible compilation lines are cc -o testbin testbin.c -lm (normal unix C) gcc -o testbin testbin.c -lm (GNU C) acc -o testbin testbin.c -lm (Sun's acc) sc link math=ieee output=testbin testbin.c (SAS C) The program reads the binary file "dump" and should print out the land mask. Test 8 Reading the binary file with fortran. Run test 6 to convert the land mask into a binary file. Compile and run the program testbin.f using your fortran 77 compiler. If everything went correctly, you should see the land mask. If it works, good. If it doesn't work, too bad. You are on your own. Suggestions: (1) if all else fails, read the fortran manual (RTFM), (2) change fortran compilers, (3) try reading the data with no headers (-nh option in wgrib), (4) give up and read the text dump instead. This step is very system dependent. Consult your local expert. Support: No support is necessary because the instructions are crystal clear and the code is bug free. If my directions are as clear as Missisippi mud, think how understandable my verbal directions will be! (Yes, I've been known to talk without nouns, adverbs and even adjectives.) Please, do not waste your dime and call me asking how to compile or link wgrib. You have to ask some one who knows YOUR SYSTEM. If tests 1-6 are sucessful then wgrib works. Test 7 is simply a test of your fortran compiler and you have to read the documentation. If you really think that you found a bug in the code, then send me an e-mail (wd51we@sun1.wwb.noaa.gov).