Re: [netcdfgroup] Reading netCDF3 format and writing netCDF4 format

  • To: Gabriel Mateescu <gabriel@xxxxxxxxxx>
  • Subject: Re: [netcdfgroup] Reading netCDF3 format and writing netCDF4 format
  • From: Russ Rew <russ@xxxxxxxxxxxxxxxx>
  • Date: Tue, 03 Nov 2009 10:18:46 -0700
Hi Gabriel,

> I would like to use the netCDF4 library
> (with which I am not familiar yet) to read
> netCDF3 files and to convert them to "classic"
> netCDF4 format (compatible with the
> netCDF3 API).
> 
> What C++ API call should I make for reading
> netCDF3 files and what call for writing classic
> netCDF4 formatted files? Do I need to do some
> in-memory processing of the data read from
> netCDF3 files before writing it in netCDF4
> format?

You could use the nccopy utility that's available in the current
netCDF snapshot release from 

  ftp://ftp.unidata.ucar.edu/pub/netcdf/snapshot/

if you don't mind building from source.  nccopy lets you specify the
kind of output file desired with an argument, so to convert a netCDF
classic or 64-bit offset file (commonly called "netCDF3 files") named
"in.nc" to a netCDF-4 classic model file named "foo_4c.nc", you
could use:

  nccopy -k 4 in.nc foo_4c.nc

Alternatively, you could accomplish the same thing with the NCO
(netCDF Operators) package, available from http://nco.sourceforge.net/
by using the "ncks" program to convert the format, using:

  ncks --fl_fmt=netcdf4_classic in.nc foo_4c.nc

If you want a generic C program to convert netCDF classic files to
netCDF-4 classic model files, you could use the example nccopy3.c
available here:

  http://www.unidata.ucar.edu/netcdf/examples/programs/nccopy3.c

and in the nc_create call to create the output file, use:

  stat = nc_create(outfile,NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL,&ogrp);

Then link the program with the netCDF-4 library and it should work.

We don't have a version of nccopy in C++ yet, but we intend to
eventually provide one as an example for using a new C++ API for
netCDF-4, contributed by Lynton Appel of UKAEA Fusion, that will be made
available soon.

--Russ



  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: