-- Learn about wgrib2: http://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/ -- Download from here: ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz -- Compiling directions for linux/unix here: http://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/compile_questions.html -- Compiling on OS X: This should be similar to Unix, but my directions are even simpler. They were tested on Aug 26, 2014 and worked. Xcode and gfortran MUST be installed on your system. Install Xcode first. Then gfortran. https://developer.apple.com/xcode/downloads/ https://gcc.gnu.org/wiki/GFortranBinaries -- If you don't have superuser privileges on your computer, ask your sys admin to install both for you. Heck, ask them to install wgrib and wgrib2 for you and you will be done in one simple step. ;-) -- If you act as your own sys admin with root privileges, then > su superUserLoginName > sudo mv someDownloadDir/wgrib2.tgz /usr/local > cd /usr/local > sudo tar -xzvf wgrib2.tgz > cd grib2 This directory has several README files and an INSTALLING guide file that tell you to use gmake and gcc. I didn't follow the directions and used the OS X standard cc and make. Check to make sure gfortran and make are in your path. > which gfortran > which make There is a makefile in this directory and you don't have to be able to make sense of it. Just invoke it: > sudo make By default, it makes all, including the system checks and configuration. It even found gcc and set the environment variable from cc to gcc before compiling. If you are successful, you will see the wgrib2 subdirectory containing the wgrib2* executable, /usr/local/grib2/wgrib2/wgrib* Create a soft link to it in /usr/local/bin along with your other local utility programs: > sudo ln -s /usr/local/grib2/wgrib2/wgrib2 /usr/local/bin If /usr/local/bin is in your path (and it should), then you can wgrib2 away! Check: > which wgrib2 should return: /usr/local/bin/wgrib2 -- If you have Xcode and gfortran but do not have superuser privileges, read the instructions above for superusers because they also apply to you (with minor changes): > mkdir ~/local > mv someDownloadDir/wgrib2.tgz ~/local > cd ~/local > mkdir bin > sudo tar -xzvf wgrib2.tgz > cd grib2 > make > ln -s ~/local/grib2/wgrib2/wgrib2 ~/local/bin -------- Wesley's useful tricks here: http://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/tricks.wgrib2 Subsetting syntax: http://gradsusr.org/pipermail/gradsusr/2012-May/032568.html > BTW The simpler way of making regional grib2 subset is to use wgrib2. > > For lat-lon -> subset lat-lon: use the -small_grib option > > wgrib2 IN.grb2 -set_grib_type j -small_grib 100:170 -55:0 OUT.grb2 > > You can also interpolate to a lat-lon grid by the -new_grid option. Piping to csv: You can set grid point values to "undefined" and then they won't print out. wgrib2 grib_file -undefine out-box -10:10 30:40 -csv out.txt wgrib2 grib_file -undefine out-box lon_min:lon_max lat_min:lat_max -csv out.txt The grid points outside of the box are set to undefined. The -csv options tries to print the entire grid but finds only the values between 30N-40N and 10W-10E are defined. ----------------- GRACE'S USAGE EXAMPLE ------------------------ A suburb of Hiroshima suffered a number of deadly landslides after heavy rain. Was this predictable? Let's take a look at the rain forecast from the GFS global model. (FNL is an analysis model and doesn't provide rain accumulation so we will use GFS for this example.) I downloaded half degree GFS output from NOMADS, http://nomads.ncdc.noaa.gov/data.php#hires_weather_datasets wgrib2 can subset the global grid to an area around Hiroshima: We want latitude = [34-35] and longitude = [132-133]. Write out a subset in GRIB2 format: > wgrib2 gfs_4_20140819_0000_012.grb2 -set_grib_type j -small_grib 132:133 34:35 gfs_4_20140819_0000_012.hiro.grb2 Write it out in csv format: > wgrib2 gfs_4_20140819_0000_012.grb2 -undefine out-box 132:133 34:35 -csv gfs_4_20140819_0000_012.hiro.txt