SPEIbase: converting between NetCDF4 and NetCDF3 formats

A number of users of our SPEIbase dataset worried because they could not read our netCDF files in their software. Indeed, some commercial softwares such as Matlab, ArcGIS and Idrisi do not have support for NetCDF4 or did not have it until recently. The main reason for us to use netCDF4 for the SPEIbase is because it allows for data compression, resulting in large file size and internet traffic saving. We did not use any of the other fancy options implemented in netCDF4 such as grouping, compound types or multiple unlimited dimensions. This means that our netCDF4 files conform to the classic model, so they can be converted back to the netCDF3 legacy format.

One way of converting to netCDF3 is by using the nccopy program by unidata. For example, to convert a netCDF-4 classic-model format file foo4c.nc to a classic format file foo3.nc:

nccopy -k classic foo4c.nc foo3.nc.

Another way would be to install the netCDF operators (NCO) toolset from unidata, and then use the ncks utility:
ncks -3 foo4c.nc foo3.nc.

In fact, ncks allows for much greater functionality. For example, if one wants to extract the first 100 times from an SPEIbase file:

ncks -d time,0,100 spei_12.nc output_file.nc

would generate a (smaller) netCDF file with only those timesteps. In a similar fashion, it is possible to use ncks to select a specific geographical region.


  • Hola Santiago!

    Te pido desesperadamente tu ayuda. Necesito convertir un archivo con formato netcdf4 a netcdf3 para poder leerlo con el lenguaje IDL instalado en UNIX (Macbook pro) pero no se como hacerlo. Podrías por favor ayudarme. Mi correo es ballinas@gmail.com.

  • sbegueria wrote:

    Hi Romeo, you can do that using nccopy program by unidata. We explain how to do it here.

  • Much helpful for solving my issue. Thank you so much!

  • Santiago, What means “nccopy -k classic foo4c.nc foo3.nc”? it is a script in nccopy program?

  • sbegueria wrote:

    Hi Carlo, nccopy is a console program. nccopy -k classic foo4c.nc foo3.nc is the command line you need to use in order to convert foo4.nc to foo3.nc.

Leave a Reply

Your email is never shared.Required fields are marked *