[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 20020805: Sample C Programs for Reading and Writing a netCDF file? (fwd)
- Subject: Re: 20020805: Sample C Programs for Reading and Writing a netCDF file? (fwd)
- Date: Tue, 06 Aug 2002 10:08:03 -0600
------- Forwarded Message
Date: Tue, 06 Aug 2002 10:07:29 -0600
From: Russ Rew <address@hidden>
To: David Han <address@hidden>
Subject: Re: 20020805: Sample C Programs for Reading and Writing a netCDF file?
>To: address@hidden
>cc: address@hidden
>From: David Han <address@hidden>
>Subject: Sample C Programs for Reading and Writing a netCDF file?
>Organization: UCAR/Unidata
>Keywords: 200208051831.g75IVZK13882
Hi David,
> I just downloaded and installed the binary distribution of the netCDF
> 3.5 library for Mac OS X. I've never used netCDF before and am
> wondering whether you have any sample programs (written in C) that
> reads and writes a netCDF file. If you do, I'd appreciate very much
> for getting a copy from you.
The C User's Guide
http://www.unidata.ucar.edu/packages/netcdf/guidec
has lots of examples in the forms of program fragments, but no
complete examples. The source for the program ncdump.c in
src/ncdump/ncdump.c is a complete example of a netCDF program that
opens and reads an arbitrary netCDF file, but it's too comprehensive
for a simple example, though the function do_ncdump() in that file
might be instructive.
There is another complete example in the netCDF source distribution,
in the file src/cxx/example.c, but it uses the old netCDF-2 interface;
it's there for comparison with the equivalent C++ example in that
directory, in src/cxx/example.cpp. The version 2 C interface is still
supported, but we document and recommend that you use the netCDF-3
interface instead. I've put an equivalent netCDF-3 example in:
http://www.unidata.ucar.edu/packages/netcdf/examples/example1.c
Another way to get a simple example of a C program that creates a
netCDF dataset is to first create a text file describing the structure
of the data, then use the "ncgen" netCDF utility with the "-c" option
to generate a C program that can be compiled to create the
corresponding netCDF file. To see how to do this, consult Chapter 10,
"NetCDF Utilities":
http://www.unidata.ucar.edu/packages/netcdf/guidec/guidec-15.html#HEADING15-0
For other examples, you might check some of the open source software
that uses netCDF and that is listed in
http://www.unidata.ucar.edu/packages/netcdf/software.html
for example the NCO package.
Eventually I hope to get around to making some more complete and
instructive equivalent examples using all of the C, C++, Fortran, and
Java interfaces ...
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu
------- End of Forwarded Message