Skip Navigation Links www.nws.noaa.gov 
NOAA logo - Click to go to the NOAA home page National Weather Service   NWS logo - Click to go to the NWS home page
Climate Prediction Center
 
 

 
About Us
   Our Mission
   Who We Are

Contact Us
   CPC Information
   CPC Web Team

 
HOME > Monitoring_and_Data > Oceanic and Atmospheric Data > Reanalysis: Atmospheric Data > wgrib2 questions
 

Compiling wgrib2 v2.0.6+

Compiling wgrib2 is easy on a linux system with gcc/gfortran or Windows with the cygwin compilers
1) Download ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz
2) untar wgrib2.tgz:  tar -xzvf wgrib2.tgz   (use gnu tar)
3) cd to main directory:  cd grib2
4) define the C and fortran compilers and make
   Bash:
     export CC=gcc
     export FC=gfortran
     make
     make lib                        only if you want the ftn_api
   Csh
     setenv CC gcc
     setenv FC gfortran
     make
     make lib                        only if you want the ftn_api
5) See if wgrib2 was compiled
     wgrib2/wgrib2 -config

note: you may have to install gcc and gfortran
Compiling with the intel compilers on a linux system is supported with v2.0.6. However, some code still needs to be compiled with gcc, so the icc and gcc need to called from the same makefile. I wouldn't be surprised that some systems are configured so that you can use GNU or Intel compilers but both at the same time. (This would break the makefile.)
1) Download ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz
2) untar wgrib2.tgz:  tar -xzvf wgrib2.tgz   (use gnu tar)
3) cd to main directory:  cd grib2
4) define the C and fortran compilers and make
   Bash:
     export CC=icc
     export FC=ifort
     export COMP_SYS=intel_linux
     make
     make lib                        only if you want the ftn_api
   Csh
     setenv CC icc
     setenv FC ifort
     setenv COMP_SYS intel_linux
     make
     make lib                        only if you want the ftn_api
5) See if wgrib2 was compiled
     wgrib2/wgrib2 -config
Compiling with Clang
1) download ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz
2) untar wgrib2.tgz:  tar -xzvf wgrib2.tgz   (use gnu tar)
3) cd to main directory:  cd grib2
4) If your version of Clang does not support OpenMP, edit the makefile 
   old: USE_OPENMP=1
   new: USE_OPENMP=0
5) define the C and fortran compilers and make
   Bash:
     export CC=clang
     export FC=gfortran -fplugin=dragonegg
     make
     make lib                        only if you want the ftn_api
   Csh
     setenv CC clang
     setenv FC "gfortran -fplugin=dragonegg"
     make
     make lib                        only if you want the ftn_api
6) See if wgrib2 was compiled
     wgrib2/wgrib2 -config

Wgrib2 also supports gcc/g95, opencc/openf95, xlc/xlf.

If there is no supported fortran compiler, wgrib2 can be compile with only a C compiler.

1) download ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz
2) untar wgrib2.tgz:  tar -xzvf wgrib2.tgz   (use gnu tar)
3) cd to main directory:  cd grib2
4) define the C  and make
   Bash:
     export CC=(your C compiler)
     make
   Csh
     setenv CC (your C compiler)
     make
5) See if wgrib2 was compiled
     wgrib2/wgrib2 -config
  This error occurred on a NOAA super computer.  To compile with the gnu 
compilers, you had to use "module load PrgEnv-gnu" in order to use the GNU 
compilers. However, when you are using another programming environment, the gfortran
library is unavailable. To fix the problem, you have to link in the static 
gfortran library.  You have to edit the makefile.

   old: wLDFLAGS+=-lgfortran
   new: wLDFLAGS+=/opt/gcc/4.7.0/snos/lib64/libgfortran.a

Of course, the above location of libgfortran.a is not standard.  You have to adjust
the above line with the location of libfortran.a in YOUR computer.

Compiling wgrib2 on OS X. See Grace Peng's blog.

Comments:

  1. For Cygwin, use the linux instructions
  2. Using the included g2clib is strongly recommended (wgrib2 v0.1.9.7a or earlier)
  3. If you use the official g2clib, USE_G2CLIB=0 is recommended for wgrib2 v0.1.9.8+)
  4. Using IPOLATES with UNIX is not difficult for a person with the right skills.
  5. Intel and the Portland compilers are not compatible with the Jasper library and are disabled in the makefile

wgrib2 compile questions

Question: Why do you build japser with the following flags?

     --disable-libjpeg --disable-opengl

Answer:

Libjpeg is not needed by wgrib2.  The makefile should work when
the system doesn't have libjpeg installed.

Opengl is not needed by wgrib2. Makefile should still work when the 
system doesn't have opengl installed.

The wgrib2 makefile compiles the libraries in a manner optimized for wgrib2.
The libraries are not meant for general use.  For example, the netcdf library
doesn't have a fortran interface because I want the makefile to
work if a user lacks a fortran compiler. 

Question: why do you include zlib and libpng?

Answer:  Not all linux distributions include libpng or they give it a different name.
Some linux distributions may have different versions of zlib installed.

Question: Why don't you make netcdf4 the default netcdf package?

Answer:

The Netcdf4/hdf5 libraries are very big and the end result is a long
download time and a large executable.  Netcdf3 files can be read by
a netcdf4 client.  However, many people routinely compile with netcdf4.

Question: I get the error messagee: /bin/sh: ./configure: Permission denied

Answer:

It is possible to configure a filesystem so that the execute bit is
set to zero. Programs and scripts will not execute when they reside
on that filesystem.  Try compiling on another filesystem.  If that doesn't
work, you are probably not allowed to download programs.  The solution
is to ask that your sys admin to compile the program for you.  But if
your sys admin will compile code for you, why are you reading this page?
Let him read this page.

Question: Why the options to turn off aec, jpeg2000 and png compression

Answer:

Some HPC machines use one type of cpu and/or OS to compile and
another type of cpu and/or OS to run (cross-compile).  Using configure
scripts can be a challenge when cross-compiling.  I wanted a reasonable
wgrib2-subset that can be cross-compiled.  Consequently all libraries that
that require a configure script are optional.

Question: Why does compiling wgrib2 with the Netcdf option fail?

Answer:

This frequently happens with 32-bit machines.  This problem goes away
on a 64-bit platform or if netcdf-4 is used instead of netcdf-3. This
problem is not being addressed because of a lack of 32-bit machines.

Question: Why the option to turn off g2clib?

Answer: g2clib is not needed but it can be installed for testing.

Question: Why gctpc and proj4? Why not proj4 without gctpc?

Answer: Gctpc and proj4 are both projection libraries and only one is
really needed.  Proj4 has more functionality, is modern and has an
active support group.  Gctpc is old and is more-or-less unsupported.
On the other hand, gctpc is simpler, works and supports OpenMP like the
rest of wgrib2.  Gctpc supports a different threading model.  As
grids get larger, you want the speed of gctpc. Both libraries are being 
supported in order to help debugging and in the case that a future
grid requires Proj4 support.

Question: Why so many compile options?

Answer:  
  Some systems do not support certain POSIX features
  Some functionality is not needed by most systems.
  not all systems have fortran, MySQL, supported NetCDF/HDF
  The code that calls IPOLATES is not using a standard interface
  Some systems do not handle cross-compiling easily
 Problem: I compiled wgrib2 and when I run it, it complains about 
      missing libraries.

Answer:
  I have the same problem with our Cray.  If you compile with the Intel 
  compilers, you have to load the Intel environment.  If you compile with 
  the GNU compilers, you have to load the GNU environment.  Since the 
  system commands do not need an environment, you can compile wgrib2 with 
  the same compiler used for the system commands. (An old version of 
  gcc/gfortran.)

NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5830 University Research Court
College Park, Maryland 20740
Climate Prediction Center Web Team
Page last modified: Aug 18, 2016
Disclaimer Privacy Policy