Editing / modifying GRIB file.

All other topics about postprocessing model data (GrADS and other software), about other numerical weather prediction software (including WRF-NMM and WRF-ARW discussion unrelated to UEMS/WRF EMS), and general meteorology talk go in this forum.
Post Reply
kszyk
Posts: 1
Joined: Thu Jan 10, 2013 10:41 am

Editing / modifying GRIB file.

Post by kszyk » Thu Jan 10, 2013 11:56 am

Hello guys!

For some time I'm trying to get my head around editing GRIB 2 files. The idea is to:
1) download GFS GRIB 2 file form here http://nomads.ncdc.noaa.gov/data/gfs4/
2) edit some fields in the file e.g. edit values of Surface Temperature
3) use edited files as an input to NEWR EMS.

I tried using wgrib2, cdo ( exporting to netcdf format, editing data with netcdf-java library and then exporting back to GRIB 2) and grib api.
Only thing that worked for me was wgrib2.

Ok, let's say i want to edit Surface Temperature values in gfs_4_20130101_0000_000.grb2 file.

Finding the Surface Temperature message:

Code: Select all

wgrib2 gfs_4_20130101_0000_000.grb2 -match "TMP:surface"
Dumping Surface Temperature to text file:

Code: Select all

gfs_4_20130101_0000_000.grb2 -match "TMP:surface" -text tmpsurface.txt
Dumping all value from all records to text file:

Code: Select all

wgrib2 gfs_4_20130101_0000_000.grb2 -text everything.txt
Now, using tmpsurface.txt file I can find where the Surface Temperature values are located in everything.txt. Then i can modify everything.txt and create new GRIB file containing edited values like this:

Code: Select all

wgrib2 gfs_4_20130101_0000_000.grb2 -import_text everything.txt -grib_out myedited.grb2
This solution is O.K. but everything.txt file size is about 500mb. Editing this kind of file is time consuming so it is not elegant :D
Can you point me to other solution to edit grib files ( not necessarily with wgrib2)? Maybe there is a way to just append tmpsurface.txt to file?

Thanks in advance,
kszyk

Post Reply