enter image description here

I have downloaded "High Resolution Initial Conditions" climate forecast data for one day, it was in extension .tar.gz so I extracted it in my local directory and I get the files like in the attached image.

I think, that the files without extension are GRIB data (because first word in them is "GRIB"). So i want to get data from the big files (GRIB and NetCDF formats containing climate data like temerature & pressure in grid) to my database, but they are binary. Can you recommend me some easy way for getting data from these files? I can't get any information about handling their datasets on their website.

Converting these files to .csv would be nice, but I can't find any working program to convert the GRIB files.

2 Answers 2


you can use wgrib2 to convert your data to csv.

wgrib2: -csv (comma separated values)

The -csv option writes the grid values to a specified file as a comma separated values (text) which can be imported into a spread sheet. This function is similar to -text with a different output.


Time0 is the reference time, that is usually the analysis or start of the forecast time. Time1 is the verification time. For analyses, Time0 and Time1 will be the same.

wgrib2 fcst.grb2 -csv junk 

$ cat junk 
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",0,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",0.5,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",1,-90,164.1
"2007-03-26 00:00:00","2007-03-26 00:00:00","HGT","1000 mb",1.5,-90,164.1

beside this there is a python library which name is pygrib (python module for reading GRIB files). i think you can read your grib files and then convert them to csv file or anything with it.

Python module for reading and writing GRIB (editions 1 and 2) files. GRIB is the World Meterological Organization standard for distributing gridded data. The module is a python interface to the GRIB API C library from the European Centre for Medium-Range Weather Forecasts (ECMWF).

Some Example code:

import pygrib

grbs = pygrib.open('sampledata/flux.grb')  
grb = grbs.select(name='Maximum temperature')[0]


maxt = grb.values # same as grb['values']
maxt.shape, maxt.min(), maxt.max()
#(94, 192) 223.7 319.9

get the latitudes and longitudes of the grid:

lats, lons = grb.latlons()
lats.shape, lats.min(), lats.max(), lons.shape, lons.min(), lons.max()
(94, 192) -88.5419501373 88.5419501373  0.0 358.125

i hope it helps you...

  • Thank You very much, the wgrib2 looks that it works nice, but it told me "grib1 message ignored (use wgrib)", so I downloaded wgrib (1), but it doesn't have the feature for exporting to other formats (like .csv), so what is the best way to convert grib(1) to .csv or to grib2? I can find it, but I think it helps this topic to be fully answered to others with same problem...
    – Salda
    May 29, 2012 at 11:13
  • Sometimes you want to use a feature of wgrib2 on a grib-1 file. Since wgrib2 doesn't do grib-1, you are out of luck unless you convert the file into grib-2. Some files can be converted into grib2 by the cnvgrib utility.
    – urcm
    May 29, 2012 at 11:26
  • True, I have read that and downloaded cvngrib, it needed f95 (fortran) to install, so I installed it, but it was for some old version of GCC, so I gave up...
    – Salda
    May 29, 2012 at 12:44

I created a tiny makefile that might help you

  1. install wgrib2 ;
  2. get data (you need to add code for your specific data-source) ;
  3. convert to csv using @Aragon suggestion ;
  4. extract only data using awk (update to your need).


First, update the gribFile, csvFile, csvFilteredFile variables to your need.

make extract-data

Running the extract-data will run need task to be complete its action. Namely:

# make convert2csv
# make get-data
# make install

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.