Skip Navigation Links 
NOAA logo - Click to go to the NOAA home page National Weather Service   NWS logo - Click to go to the NWS home page
Climate Prediction Center

About Us
   Our Mission
   Who We Are

Contact Us
   CPC Information
   CPC Web Team

HOME > Monitoring_and_Data > Oceanic and Atmospheric Data > Reanalysis: Atmospheric Data > wgrib2-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 -spread and -csv_long with a different output format.


For an analysis that is valid at a specific time, time0 and time1 will have the same value. For a temporal average or accumulation of analyses, time0 will be the start and time1 will be end of the average or accumulation.

For a forecast, time0 will be the start of the forecast (i.e, date of the initial conditions). For a forecast for a specific time, then time1 will be time that the forecast is valid. For a forecast of a temporal average or accumulation, time1 wll be the end of the average or accumulation.

In grib speak, time0 is the reference time and time1 is the verification time. Here are some examples,

1:0:d=2009062900:TMP:surface:anl:     (default inventory)

   This an analysis (anl) of the surface temperature.
   This analysis is valid for 2009062900.
   Time0 = 2009062900    Time1 = 2009062900
   field=TMP             level=surface

29:1155322:d=2009060500:UGRD:925 mb:180 hour fcst:ENS+19     (default inventory)
   This is a 180 hour forecast of the 925 hPa zonal wind.
   The forecast run uses initial conditions at 2009060500
   and verifies 180 hours laster at 2009061212.  
   Time0 = 2009060500    Time1 = 2009060500
   field=UGRD            level = 925 mb

43:1844451:d=2009060500:APCP:surface:174-180 hour acc fcst:ENS=+19     (default inventory)
   This is a forecast of accumulated precipitation from 174 to 180 hours.
   The forecast run uses initial conditions at 2009060500 and 
   accumulates the precip from 2009061206 to 2009061212.  The
   verification time is defined as the end of the accumulation period
   Time0 = 2009060500    Time1 = 2009060500
   field= APCP           level= surface

The -csv option only works on the grids for which wgrib2 can derive latitude and longitudes values. Otherwise no output is generated. The undefined value is 9.999e20.

The size of a CSV file can be overwhelming. One technique is to only generate the CSV for variables that you need. This can be done with the -match option. Even with the -match option, the high-resolution models can stil generate huge files. The next technique is to undefine the grid points that you don't want. For example, you are only interested in Hawaii (its 0C outside as I write this). Then you can use the the -undefine option to set the grid points outside of the Hawaii domain to undefined. Since -csv doesn't print undefined grid points, the CSV files is much smaller.

Extended Variable Names

The default field value (see above) is the grib name such as TMP or HGT. However, the grib name may not be unique. For example, the field could be the HGT from the 19th ensemble member. A better field name may be "HGT.ENS=+19". You enable the extended variable name by adding the option -set_ext_name 1.


-csv output_file_name
   the field is the grib name
   output_file_name cannot be a memory file
-set_ext_name 1 -csv output_file_name
   the field is the extended grib name
   output_file_name cannot be a memory file


$ wgrib2 fcst.grb2 -csv junk 
1:0:d=2007032600:HGT:1000 mb:anl:
2:125535:d=2007032600:HGT:1000 mb:3 hour fcst:
$ 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
"2007-03-26 00:00:00","2007-03-26 03:00:00","HGT","1000 mb",-1.5,90,-91.7
"2007-03-26 00:00:00","2007-03-26 03:00:00","HGT","1000 mb",-1,90,-91.7
"2007-03-26 00:00:00","2007-03-26 03:00:00","HGT","1000 mb",-0.5,90,-91.7

Warning #1

The options -csv, -csv_long, -spread and -text do not support memory files. You can blame sloth or lack of need. I like to think that text files with grid point values are are insanely large and shouldn't be saved in memory.

Warning #2

It may be tempting to take a grib file, convert it into a CSV file and then deal with the CSV file. After all, everybody can read a CSV file. Sure there is a litte overhead of reading a CSV file but who cares. Suppose you want to read some GFS forecasts files (20 forecast times, 5 days every 6 hours) at 0.25 x 0.25 degree global resolution. Your CSV file is going to be about 720 GBs. Suppose that our hard drive can write/read at 70 MB/s. Then we are talking about 3 hours to write the CSV file and 3 hours to read the CSV file not including CPU time which will slow down the process. Converting grib into CSV is a viable strategy if the conversion is limited. You need to restrict the number of fields converted and should consider only converting a regional domain. Note, I wrote "viable" and not optimal.

See also: -spread, -csv_long, -text, -bin, -ieee, -set_ext_name, -undefine

NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5830 University Research Court
College Park, Maryland 20740
Climate Prediction Center Web Team
Page last modified: Nov 19, 2015
Disclaimer Privacy Policy