Skip to content

Commit

Permalink
updated with latest code
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Dec 7, 2023
1 parent 16f5465 commit a66184e
Show file tree
Hide file tree
Showing 566 changed files with 85,262 additions and 5,928 deletions.
45 changes: 27 additions & 18 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wgrib2 revised 7.2016
wgrib2 revised 7.2016, 2.2021

wgrib2 is a program to read/write grib2 files.

Expand Down Expand Up @@ -29,22 +29,25 @@ Default makefile options
USE_REGEX=1
USE_TIGGE=1
USE_MYSQL=0
USE_IPOLATES=0
USE_IPOLATES=3
USE_SPECTRAL=1
USE_UDF=0
USE_OPENMP=1
USE_PROJ4=0
USE_WMO_VALIDATION=0
DISABLE_TIMEZONE=0
MAKE_FTN_API=0
MAKE_SHARED_LIB=0

USE_G2CLIB=0
USE_PNG=1
USE_JASPER=1
USE_OPENJPEG=1
USE_AEC=1

To compile without netcdf, set USE_NETCDF3=0 and USE_NETCDF4=0
To compile without netcdf v3, set USE_NETCDF3=1 and USE_NETCDF4=0
To compile without netcdf v4, set USE_NETCDF3=0 and USE_NETCDF4=1
To compile with netcdf v3, set USE_NETCDF3=1 and USE_NETCDF4=0
To compile with netcdf v4, set USE_NETCDF3=0 and USE_NETCDF4=1

For netcdf4, the netcdf4 and hdf5 libraries are usually not included
in the wgrib2.tgz file to save space. The makefile suggests
Expand All @@ -59,11 +62,12 @@ Support for Mysql is an option. You have to modify the makefile to indicate
the locations of the mysql includes and libraries and set USE_MYSQL=1

The option -new_grid uses the ipolates library to do the interpolation.
The required libraries are written in fortran and a few compilers are
already supported in the makefile. For other compilers, you are on
your own. The source code and makefile will have to be modified to use
the ipolates option. Consult a local expert if you want to install this
optional package. No help is available from NCEP for installing the package.
The default is to USE_IPOLATES=3, and USE_SPECTRAL=1. The interpolation
libraries are written in fortran and work with the supported compilers.
For other compilers, you are on your own. The source code and makefile
will have to be modified to use the ipolates option. Consult a local
expert if you want to install this optional package. No help is available
from NCEP for installing the package.

User Defined Functions (UDF) allow you to run shell commands from
within wgrib2. UDF are not available on windows machines unless
Expand Down Expand Up @@ -95,14 +99,22 @@ or supports time zones in a non-POSIX manner, then you have to set
DISABLE_TIMEZONE to 1.

Wgrib2 is both a stand alone utility and a library that is callable
from both C and Fortran. To enable the making the wgrib2 library, you
have to set
from both C, Fortran and python. To enable the making the wgrib2 library,
you have to set

MAKE_FTN_API=1

For use with python, you have to make a shared library using

MAKE_SHARED_LIB=1

To make a library, you have tocompile by

$ make lib

In older versions of wgrib2, the g2clib was the default decoder of grib files.
In the current version, you can use g2clib as an optional decoder. The main
use of compiling wgrib2 with g2clib is for testing g2clib.
use of compiling wgrib2 with g2clib is for testing g2clib.

USE_G2CLIB=1

Expand All @@ -111,12 +123,9 @@ the following options.

USE_PNG=0
USE_JASPER=0
USE_OPENJPEG=0
USE_AEC=0


You might want to turn off the various compressions because

1) libraries do not compile correctly (icc and pgcc have problems with Jasper)
2) reduce the executable size and compile time
3) problems with cross-compiling
Some of the optional libraries require CMake. Some of the optional libraries will
run a configure script. Both features can make cross compiling difficult.

1 change: 1 addition & 0 deletions README.AOCC
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See _README.clang
85 changes: 85 additions & 0 deletions README.EUMETSAT
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Using wgrib2 to process space-perspective EUMETSAT grib2 fields
revised 9.2017

9/2017: Bugs found in space view perspective code when the satellite
is not at 0N OE. Fixed in wgrib2 2.0.7. Space view perspective
is limited to 0N XX-E- (Original testing only had satellite at 0N OE.)


Some of the EUMETSAT data is on a space view perspective grid.

-sh-3.00$ wgrib2 LMPEF_CLM_110328_0945.grib2 -grid
1:0:grid_template=90:winds(N/S):
Space view perspective or orographic grid (3712 x 3712) units 1e-06
input EW:SN output WE:SN res 0
sub-sat point: lat 0.000000 lon 0.000000 ix=1856.000000 iy=1856.000000
diameter of earth dx=3622 dy=3610 grid cells ori_angle 0.000000
sat. altitude=6.610700 (equatorial radii) grid_origin Xo=0 Yo=0

wgrib2 has support for space view perspective grids with the restriction that
the sub-sat point have a latitude of 0.

The rest of the text assumes that you have a space view perspective file.

0. Getting the value at a specific point

bash-4.1$ wgrib2 LMPEF_CLM_110328_0945.grib2.c0 -S
1:0:D=20110328094500:CLOUDM:no_level:anl:
bash-4.1$ wgrib2 LMPEF_CLM_110328_0945.grib2.c0 -lon 10 20
ALPHA: experimental space_view2ll scan=12
ALPHA: experimental space_view2ij
1:0:lon=9.989726,lat=20.003905,val=1

note: use -S otherwise wgrib2 will use a YYYYMMDDHH date code format
and then may complain that the minutes/seconds are non-zero

1. IIRATE has undefined, not zeros

I have a file of IIRATE (instantaneous rain rate), and the values
are either > 0 or undefined. Maybe the values are undefined because
of algorithm limitations but for display, I wanted to have the undefineds
replaced by zero. This is easily done by the -rpn option

wgrib2 IN.grb -rpn "0:exc:merge" -grib_out OUT.grb


2. PDT 30 is not supported by GrADS

My version of GrADS does not support product definition template 30 (PDT 30),
so you need to convert it to a supported PDT. You can convert the PDT to
zero by.

wgrib2 IN.grb -set_pdt +0 -grib_out OUT.grb


3. No level or forecast time

PDT 0 has metadata for level and forecast time. They can be added by

wgrib2 IN.grb -set_lev surface -set_ftime anl -grib OUT.grb


1-3. Update space view perspective file.

Steps 1-3 can be combined into one by

In this example, the 1st grib message is space view perspective

wgrib2 IN.grb -d 1 -rpn "0:exc:merge" -set_pdt +0 -set_lev surface
-set_ftime anl -grib_out final_svp.grb


4. Convert to a lat-lon grid

GrADS does not understand space view perspecive grid, you need to convert
it to a lat-lon grid.

wgrib2 final_svp.grb -lola 0:3600:.1 -90:1801:.1 latlon.grb grib


5. Make a GrADS control and index file

g2ctl latlon.grb >latlon.ctl
gribmap -i new.ctl


133 changes: 133 additions & 0 deletions README.ICON.DWD
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
Using the DWD's ICON forecast grib files with wgrib2 updated 12/2019, 4/2020



The DWD is making global forecasts using the ICON model. This model uses a triangular
mesh, and the forecast quantities are valid for the center of the triangles. The DWD
opendata server is distributing data in grib format for the forecast values from
the center of the triangles. This note shows how to process the grib data using
wgrib2.


Basics that DWD may change:

https://opendata.dwd.de/weather/nwp/icon/grib/HH

HH = 00, 06, 12 or 18

Step 1. Download the CLAT and CLON file

CLAT=latitude of the center of the triangles
CLON=longitude of the center of the triangles

https://opendata.dwd.de/weather/nwp/icon/grib/00/clat/icon_global_icosahedral_time-invariant_YYYYMMDDHH_CLAT.grib2.bz2
https://opendata.dwd.de/weather/nwp/icon/grib/00/clon/icon_global_icosahedral_time-invariant_YYYYMMDDHH_CLON.grib2.bz2

Step 2: Download some forecast files

Example

https://opendata.dwd.de/weather/nwp/icon/grib/00/t_2m/icon_global_icosahedral_single-level_YYYYMMDDHH_000_T_2M.grib2.bz2
https://opendata.dwd.de/weather/nwp/icon/grib/00/t_2m/icon_global_icosahedral_single-level_YYYYMMDDHH_001_T_2M.grib2.bz2
..
https://opendata.dwd.de/weather/nwp/icon/grib/00/t_2m/icon_global_icosahedral_single-level_YYYYMMDDHH_180_T_2M.grib2.bz2

Step 3: Uncompress the data
bunzip2:

Step 4: Combining the files
Bash:
cat icon_global_icosahedral_time-invariant_YYYYMMDDHH_CLAT.grib2 \
icon_global_icosahedral_time-invariant_YYYYMMDDHH_CLON.grib2 \
icon_global_icosahedral_single-level_YYYYMMDDHH_006_TMAX_2M.grib2 >icon.grb

Windows:
copy /b icon_global_icosahedral_time-invariant_YYYYMMDDHH_CLAT.grib2 +
icon_global_icosahedral_time-invariant_YYYYMMDDHH_CLON.grib2 +
icon_global_icosahedral_single-level_YYYYMMDDHH_006_TMAX_2M.grib2 icon.grb

(all of above on one line)

Contents of icon.grb
$ wgrib2 icon.grb
1:0:d=2019040900:GEOLON:surface:anl:
2:5898409:d=2019040900:GEOLAT:surface:anl:
3:11796818:d=2019040900:TMP:2 m above ground:0-360 min max fcst:

Comment:

Regridding takes a long time for the first field because wgrib2 searches
each grid point to find the nearest neighbor. The rest of the fields
is much faster because wgrib2 retains a list of the nearest neighbors.
So processing is faster if all the fields that need regridding are put
into one file. (The unix cat command works for grib files.) This
slow first field behavior also works for the -lon option. The
nearest neighbor search is faster when using multiple cores and the
OpenMP version of wgrib2.


Example 1: Obtaining values for (10E, 20N) and (10W, 30S)

wgrib2 v2.0.9 (in development)
v2.0.9 adds -else, -elseif and -endif
v2.0.9 updates -grid_def to use GEOLAT and GEOLON

$ wgrib2 icon.grb -if "^(1|2):" -grid_def -else -s -lon 10 20 -lon 15 -30 -endif
1:0
2:5898409
3:11796818:d=2019040900:TMP:2 m above ground:0-6 hour max fcst::lon=9.968750,lat=20.012680,
val=296.588:lon=15.078125,lat=-30.069351,val=290.953



wgrib2 v2.0.6 - v2.0.8 (earlier versions of wgrib2 had a bug in -grid_def)

$ wgrib2 icon.grb \
-if ":GEOLAT:" -set center 7 -set_var NLAT -fi \
-if ":GEOLON:" -set center 7 -set_var ELON -fi \
-grid_def -s \
-not_if "^(1|2):" -lon 10 20 -lon 15 -30 -fi
1:0:d=2019040900:ELON:surface:anl:
2:5898409:d=2019040900:NLAT:surface:anl:
3:11796818:d=2019040900:TMP:2 m above ground:0-360 min max fcst::lon=9.968750,lat=20.012680,val=296.588:
lon=15.078125,lat=-30.069351,val=290.953


Example 2: a 1x1 degree global grid by nearest neighbor interpolation


wgrib2 v2.0.9 (in development)

$ wgrib2 icon.grb -if "^(1|2):" -grid_def -else -s -lola 0:360:1 -90:181:1 1x1.grb grib -endif
1:0
2:5898409
3:11796818:d=2019040900:TMP:2 m above ground:0-6 hour max fcst:

wgrib2 v2.0.6 - v2.0.8 (earlier versions of wgrib2 had a bug in -grid_def)

$ wgrib2 icon.grb \
-if ":GEOLAT:" -set center 7 -set_var NLAT -fi \
-if ":GEOLON:" -set center 7 -set_var ELON -fi \
-grid_def -s \
-not_if "^(1|2):" -lola 0:360:1 -90:181:1 1x1.grb grib
1:0:d=2019040900:ELON:local level type 1 0:anl:
2:5898409:d=2019040900:NLAT:local level type 1 0:anl:
3:11796818:d=2019040900:TMP:local level type 103 2:0-6 hour max fcst:


Example 3: Making a netcdf file

The raw ICON grib files do not have latitude and longitude information. By prepending
the CLON and CLAT files, the file has the longitude and latitude information. However,
the wgrib2 cannot make a netcdf file because the data are not on a lat-lon grid. One
could update the netcdf converter to output the ICON data on a trianglular mesh, but
how many visualization codes could read that netcdf file and make a plot?

The suggested method to make a netcdf file using wgrib2 is by making a lat-lon grib
file. See example 2. Once you have made the lat-lon file, you can make a netcdf
file using the grib2->netcdf utility of your choice.

The conversion from the trianglar mesh to a lat-lon grid is slow because a linear search
is used to find the nearest neighbor. The conversion can be made faster by using more cores
and setting the appropriate number of cores to use (export OMP_NUM_THREADS=n). This is why
you want more cores!
25 changes: 25 additions & 0 deletions README.Mac
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
A user had trouble making a 64 bit version of wgrib2 with the Leopard OS.
Some of the libraries where 32 and other 64 bits. To get everything
to work, he had to get the "-m64" flag to all the compiles. He
did this by setting the following environment variables before
doing the "gmake -f makefile"

export CC=/usr/bin/gcc
export CXX=/usr/bin/c++
export F77=ifort
export CFLAGS="-O2 -m64"
export CXXFLAGS="-O2 -m64"
export FFLAGS="-O2 -m64"

Another user had to the above and change makefile

wCPPFLAGS=-O2

to

wCPPFLAGS=-O2 -m64

-------------------------------------------------

Another user Mac user had 32-bit MySQL libraries and had to
remove the -m64 (2/2010)
Loading

0 comments on commit a66184e

Please sign in to comment.