How to install wgrib2 in OSX
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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 whatgccis, 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 resultingwgribdirectory. -  In the makefile, uncomment the lines
#export cc=gcc #export FC=gfortranAlso search formakefile.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 thewgribdirectory:
tar -xvf libpng-1.2.57.tar.gz cd libpng-1.2.57/scripts/
now edit themakefile.darwinfile, changing
CC=cc
to
CC=gcc
Now, return to thewgribdirectory, and re-tar libpng!
tar -cf libpng-1.2.57.tar libpng-1.2.57 gzip libpng-1.2.57.tar
If it asks you if you want to replace the original tar.gz file, say “yes”. What we’ve done here is editedlibpngto 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 (gcc, 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.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.