g2grb (GrADS 2 grib2): writing grib2 with GrADS and wgrib2
Writing out gridded data
The GRIB first edition (GRIB1)1 is used operationally worldwide by most. Exchange of regularly spaced data in binary form: FM 92 GRIB. GRIB2 to GRIB1 converter: This C program will convert from GRIB2 format to GRIB1 format. You will also need the GRIB2 decoder, above, and the JasPer and JPEG libraries. How to convert GRIB-1 to GRIB-2? It won't be able to convert GRIB1 directly to GRIB2, but you should be able to convert GRIB1 to CSV or another format.
Writing grib2files is not fun if you have to start writing code in Fortran.g2grb is program that allows you to write grib2files directly from GrADS. If you can plot a map with GrADS you can make a grib file (with some exceptions). Suppose you have a GFS 12 hour forecast that doesn't have the500-1000 mb thickness. With only 4 lines in GrADS, we write a grib2 file of the thickness. Forgot to include the the wind speed at 850 mb, no problem.??/??/2010 First public release
Instructions: Setting the GrADS Environment
To use g2grb.gs, the GrADS environement has to be set upcorrectly. The time and vertical level have to be fixed(not covering a range of values).The latitude and longitude have to be varying. Basicallywhen you display an field, you should see a map. An aninimationor a hovmuller diagram is a no go.The script g2grb can only handle regular lat-lon grids, so bothGaussian and Mercator grids are poorly supported. (g2grb will makea grib2 file but it will be a lat-lon approximation of theGaussian/Mercator grids.) Grids such as Lambert conformal andpolar stereographic are fine because GrADS will internally usea regular lat-lon grid.Note, when opening up a global grid, GrADS usually repeats the date line. You should change the longitude range so that doesn't occur. Some programs may not be able to handle a file with the extremeleft and right latitudes being repeated.
Instructions: writing a grib2 file
To write a grib message (record), you run the command g2grb (short for grads2grib).To write write two grib messages to a file, you run g2grb twice. Theonly difference is that for the second (and following writes), you haveto prefix the file name with a plus sign '+'. The plus sign is way totell g2grb that you want to append to an existing file.Undefined Values
GrADS uses a special number to signify an undefined value.With GrADS 2.0+, g2grb queries GrADS for the special value.For older versions of GrADS, g2grb has to be modified for thevalue as defined by the control file. Change the line following'control file specific value'. Or you can change data/control fileto use 9.999e20 which is the wgrib/wgrib2 undefined value.Installation
- install wgrib2 v0.1.8.4+ on your path or change the location in the script g2grb.gs to point to a new wgrib2
- save g2grb.gs (<-- right click to download) in your to grads script directory, $GASCRP
- save template.grb2 (<-- right click to download) to your grads data directory, $GADDIR
- or use the FTP directory
Compression
The default from g2grb is packed integer (like grib1). The filescan be made smaller by setting the compression in the metadata.
Grib also allows setting the precision of the data. Bydefault, the data are stored as scaled 12 bit integers whenwritten out in grib2 format. The only option that is currentlyavailable is :scaline=DEC:BIN where DEC and BIN are integersrepresenting the decimal and binary scaling.
Customization
g2grb.gs has much of the metadata set to undefined (255) such asthe center and subcenter. If you want the center set to a specificvalue, you have to change the center in the file template.grb2. Youcan either use '-set center NN' or '-set_byte'.
Limitations
Grib2 files have metadata which g2grb leaves as undefined. Productsthat are distributed should have the appropriate metadata set. Themetadata can be set with wgrib2 as well by other programs. g2grb assumes that GrADS internal grid is a regular lat-lon grid.A grad that has a varying x/y will not be handled right. g2grb wilmake a regular lat-lon grid based on the latitude and longitude ofthe starting and ending grid points.
All data are written out using GrADS internal grid. Writinga Lambert-conformal or polar stereographic grid is possible but isuntested and undocumented.
How g2grb.gs works
Station data to grib2
GrADS can display station data as either point data or as a griddedfield. The latter can be done using a Cressman analysis (oacres) or by settng the gridvalue based on the station data in the grid cell (oabin). Internally oacres and oabin can create a gridded field which can be written out using g2grb.gs. An example of converting some temperature observations to a grib2 file usingg2grb.gs is given here. The data for this example is here.
Multiple Grids
GrADS can handle multiple grids and convert between the gridsusing the 'lterp' command. G2grb.gs is not so smart andassumes that the 'Expression' to write is properly discribedby the GrADS 'q dim' command. You may have to use 'set dfile I'to change the dimension environment to match the dimensionof 'Expression'.Other uses
![Grib2 to csv Grib2 to csv](/uploads/1/2/6/5/126503783/961082373.jpg)
Writing the grib2 file can be done on the GrADS script level bycalling the needed utilities. The same technique can be adapted by other programs. For exaple, a model would write binary grid data and a simple text metadata. A script based on g2grb could laterconvert the grid and metadata into grib2.
Comments: [email protected]