Prompted by both my own struggles with wgrib2 compilation and a plea on the rNOMADS email listserv, I’m going to describe how to compile and install wgrib2 on Mac OS.
First of all, some background: wgrib2 is an excellent utility written by Wesley Ebisuzaki at NOAA. It allows for a number of swift and stable operations on GRIB2 files (a common file format for weather and climate data). It is also a requirement for using grib files in rNOMADS (the function ReadGrib() in particular).
So here’s how to install it on Mac OS.
- Get Command Line Tools for Xcode (search for it on Duckduckgo or your engine of choice) and also make sure
gccis installed. If you don’t know what
gccis, stop now and find someone who does (it will save you a lot of time).
- Download wgrib2 here (note download links are pretty far down the page).
- Untar the tarball somewhere, and roll up your sleeves.
cdinto the resulting
- In the makefile, uncomment the lines
makefile.darwinin the makefile and uncomment the line containing it. You’ll see instructions to this effect in the makefile anyway.
- Now we have to edit the included
libpngpackage, since it is untarred by the makefile and doesn’t inherit our compiler specifications in step 4. Ensuring that we’re in the
tar -xvf libpng-1.2.57.tar.gz
now edit the
Now, return to the
wgribdirectory, and re-tar libpng!
tar -cf libpng-1.2.57.tar libpng-1.2.57
If it asks you if you want to replace the original tar.gz file, say “yes”. What we’ve done here is edited
libpngto make sure it uses the right compiler.
- Finally, type
maketo build wgrib2.
If you are still having problems (for example,
libaec complaining that there is no c compiler), make sure that all the compiler commands (
cc, etc.) all point to something other than
clang (the default compiler that comes with OSX). You may have to edit your
bash_profile file to ensure this.
As always, contact me on the form below if you’re having unresolvable issues.