GRIB2 file carpentry
Nov. 18, 2016
Posted by:
RDA Team
Note: This page was originally sourced from our Blogger page: http://ncarrda.blogspot.com/2016/11/grib2-file-carpentry.html
We've learned from several users that the second WRF method in our post about How to work around operational changes to GFS/GDAS/FNL does not work.Use the first method described.
First, you can work around the problem by removing the new vertical levels in the files after the GFS/GDAS change. Then all of your WPS input will be consistent. You can do this yourself with wgrib2, or our "Get a Subset" tool.Here's the detailed recipe for those of you not familiar with wgrib2 tool for manipulating grib2 files.
We're going to use tip #4 and #4a from Wesley's Tricks for wgrib2 page to extract a range of records from a grib2 file.
Start by making a short inventory to identify the records that you want to keep and to remove.
wgrib2 gdas1.fnl0p25.2016051106.f00.grib2 > gdas1.fnl0p25.2016051106.f00.inv
wgrib2 gdas1.fnl0p25.2016051112.f00.grib2 > gdas1.fnl0p25.2016051112.f00.inv
Note that gdas1.fnl0p25.2016051106.f00.inv has 322 lines and gdas1.fnl0p25.2016051112.f00.inv has 352 lines. The extra 30 lines/records are in records 5-34.
We'll extract fields 1-4 and 35-352 separately and then recombine them with the UNIX command, cat. It would be tedious to type in each and every file I want to convert. To save time, I put all the files I want to convert into one directory and ran this bash script.
#!/bin/bash
for file in gdas1*f00.grib2; do
wgrib2 $file -for 1:4 -grib temp1
wgrib2 $file -for 35:352 -grib temp2
cat temp1 temp2 > $file.27
done