Russ Rew wrote:
Hi,
Some new resources for learning about netCDF are now available.
First is the "NetCDF for Developers Workshop", consisting of online
materials from a recent one-day workshop presented in Boulder:
http://www.unidata.ucar.edu/software/netcdf/docs/workshop/
We have also made a set of complete example programs available that
illustrate equivalent uses of netCDF from C, Fortran 77, Fortran 90,
C++, and Java:
http://www.unidata.ucar.edu/software/netcdf/examples/programs/
(If developers of the Perl, Python, Ruby, MATLAB, IDL, Ada, or other
interfaces contribute equivalent examples for those interfaces, we
will consider also including them.)
Russ and Ed: I'm working on making python versions of all those sample
programs. Attached is a python version of the first one
(simple_xy_wr.py). I'll send you more as they are completed.
HTH,
-Jeff
--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@xxxxxxxx
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
# the Scientific Python netCDF interface
#from Scientific.IO.NetCDF import NetCDFFile as Dataset
# the classic version of the netCDF4 python interface
from netCDF4_classic import Dataset
import numpy
"""
This is a very simple example which writes a 2D array of
sample data. To handle this in netCDF we create two shared
dimensions, "x" and "y", and a netCDF variable, called "data".
This example demonstrates the netCDF Python API.
It will work either with the Scientific Python NetCDF interface
(http://dirac.cnrs-orleans.fr/ScientificPython/)
of the 'classic' version of the netCDF4 interface.
(http://netcdf4-python.googlecode.com/svn/trunk/docs/netCDF4_classic-module.html)
To switch from one to another, just comment/uncomment the appropriate
import statements at the beginning of this file.
Requires the add-on numpy array module
(http://numpy.scipy.org).
"""
# the output array to write will be nx x ny
nx = 6; ny = 12
# open a new netCDF file for writing.
ncfile = Dataset('simple_xy.nc','w')
# create the output array (int32)
data_out = numpy.empty((nx,ny),numpy.int32)
for y in range(ny):
for x in range(nx):
data_out[x,y] = x*ny + y
# create the x and y dimensions.
ncfile.createDimension('x',nx)
ncfile.createDimension('y',ny)
# create the variable (4 byte integer in this case)
# first argument is name of variable, second is datatype, third is
# a tuple with the names of dimensions.
data = ncfile.createVariable('data','i',('x','y'))
# write data to variable.
data[:] = data_out
# close the file.
ncfile.close()
print '*** SUCCESS writing example file simple_xy.py!'