Reply to topic  [ 3 posts ] 
Are there worked examples of writing netcdf data ? 
Author Message

Joined: Thu Aug 16, 2007 12:28 pm
Posts: 9
Post Are there worked examples of writing netcdf data ?
Hi,

Are there worked examples of writing netcdf data ?
I've googled and looked through the code but can't find any.

I need to write a 3D data array out and visualize it in a 3rd party renderer like paraview,
so if there were another useful format I'd be open to that as well.

Thanks,
Ira


PS,
more poking around suggests that HDF5 might be a useful format for my application.
I'll try to get that up as well.


Mon Apr 09, 2012 2:55 am
Profile
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Post Re: Are there worked examples of writing netcdf data ?
Code:
> require,"netcdf.i"
> help,nc_open
/* DOCUMENT f= nc_open(filename, mode)
      opens a netCDF file FILENAME for reading or update as specified
      by MODE, which defaults to "rb".  Attributes and dimension names
      can be found in the three external variables nc_dims (an array of
      type NC_dim), nc_attrs (an array of type NC_attr), and nc_vars
      (an array of type NC_var) after this call.
      MODE should be either "rb" or "r+b"; nothing else makes sense.
      If FILENAME is an array of strings, exactly those files will be
      opened as a family (if possible).  Note that nc_open("myfile00")
      potentially opens myfile01, myfile02, and so on, as for openb,
      but that nc_open(["myfile00"]) opens myfile00 only.
    SEE ALSO: nc_create, nc_enddef, nc_attribute, nc_dimsof
  */
defined at:  LINE: 37  FILE: /usr/lib/yorick/i/netcdf.i
> help,nc_create
/* DOCUMENT ncf= nc_create(filename)
      creates a netCDF file FILENAME.
      After this call, use nc_vardef to declare the netCDF variables.
      Then use nc_enddef to write the netCDF self-descriptive
      information.  Only after this are you free to actually write data.

    SEE ALSO: nc_open, nc_vardef, nc_attrdef, nc_enddef, nc_addrec,
              nc_attribute, nc_dimsof
  */
defined at:  LINE: 241  FILE: /usr/lib/yorick/i/netcdf.i
> help,nc_vardef
/* DOCUMENT nc_vardef, ncf, name, type, dims, record=0/1
        -or- nc_vardef, ncf, name, type, record=0/1
        -or- nc_vardef, ncf, name, template=template, record=0/1
      define a variable in the NCF (returned by nc_create) with name
      NAME, type TYPE (as returned by typeof or structof), and dimensions
      DIMS (as returned by dimsof).  The template= keyword may be used
      instead of type and dims; the type and dims will be those of the
      TEMPLATE.  If dims is not specified, a scalar is assumed.  If the
      record= keyword is present and non-zero, the variable is a record
      variable; otherwise it is a non-record variable.

      You can use the dimnames= keyword to write specific dimension
      names into the netCDF file.  These are not useful to Yorick, but
      other codes may require them.  If two variables share a dimension
      name, the corresponding dimension must have the same length.  For
      example:
        nc_vardef, ncf, "theta", double, [1,nlat], dimnames=["latitude"]
        nc_vardef, ncf, "phi", double, [1,nlong], dimnames=["longitude"]
        nc_vardef, ncf, "elevation", double,
                   dimnames=["latitude","longitude"]
      A dimension name of "" lets Yorick invent a fake dimension name,
      as it does by default.  If dimnames= is present and the lengths
      of the dimensions have previously been defined, then the DIMS
      parameter is unnecessary, as in the "elevation" array in the example.
      You can use the nc_dimdef function to define a named dimension size
      before you define any variables with that dimension.

    SEE ALSO: nc_create, nc_attrdef, nc_enddef, nc_addrec, nc_dimdef
  */
defined at:  LINE: 255  FILE: /usr/lib/yorick/i/netcdf.i
> help,nc_enddef
/* DOCUMENT f= nc_enddef(ncf)
      creates netCDF file NCF (returned by nc_create), and writes the self-
      descriptive information.  Returns the ordinary Yorick file object
      corresponding to the new file.  You are then free to write variables,
      or use the save or nc_addrec functions.

    SEE ALSO: nc_create, nc_addrec, nc_open, nc_attrdef, nc_dimsof
  */
defined at:  LINE: 427  FILE: /usr/lib/yorick/i/netcdf.i
> x=span(0,1,3)+span(0,1,4)(-,)+span(0,1,5)(-,-,)
> info,x
array(double,3,4,5)
> f=nc_create("~/junk.nc")
> nc_vardef,f,"x",structof(x),dimsof(x)
> f=nc_enddef(f)
> save,f,x
> close,f
> f=nc_open("~/junk.nc")
> show,f
1 non-record variables:
     x                                                                         
> info,f.x
array(double,3,4,5)
> anyof(x!=f.x)
0


Tue Apr 10, 2012 7:16 pm
Profile

Joined: Thu Aug 16, 2007 12:28 pm
Posts: 9
Post Re: Are there worked examples of writing netcdf data ?
Hi,
that example worked fine.
Thank you.


Thu Apr 12, 2012 9:24 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.