Re: add variable to existing netCDF file

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 27 2013 - 13:21:47 MST

Hi David,
The way to do this is to use the "magic" dimension name "ncl_scalar" when you write the variable. It works both with the simple and with the complicated method.
Assuming your scalar variable is named "x":

x!0 = "ncl_scalar"
ncfile->tas_avg = x

You can also use "ncl_scalar" as the dimension name when using filevardef.
What you should not do is try to define "ncl_scalar" as a dimension using filedimdef.
See example 2 under filevardef. Hope this helps.
 -dave

On Nov 27, 2013, at 12:56 PM, "David B. Reusch" <dreusch@ees.nmt.edu> wrote:

> I would like to add a simple scalar value (e.g., an average for an
> existing variable) to an existing netCDF dataset. I've been using the
> super-easy approach of adding the netCDF file with mode "w", then doing
> something like "ncfile->tas_avg = x". The "problem" I'm seeing is that
> even though the new variable x is a scalar in NCL, the variable is
> defined in the netCDF file with a NCL-generated new dimension (e.g.,
> ncl3). I was hoping to find a way to avoid this since I get a new
> dimension with each scalar I'm adding (which gets kind of messy pretty
> quickly). Plus it seems more "elegant" to not have dimensions when the
> data are actually scalar.
>
> In case it helps, here are some captures from ncdump of what I'm seeing
> and what, ideally, I'd like to see:
> 1) what I get
> dimensions:
> lon = 512 ;
> lat = 50 ;
> time = UNLIMITED ; // (1 currently)
> ncl3 = 1 ;
> float tas_avg(ncl3) ;
>
> 2) what I'd like
> float tas_avg ;
> i.e., no dimension is associated with this var
>
> Maybe it just isn't possible with the simple approach and/or I'm using
> the wrong tool, but I figured it wouldn't hurt to check with the experts
> first.
>
> Thanks,
> Dave
>
> --
> Associate Research Professor of Climatology
> Dept of Earth and Environmental Science
> MSEC 304; 801 Leroy Pl
> New Mexico Tech
> Socorro, NM 87801
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Nov 27 13:21:58 2013

This archive was generated by hypermail 2.1.8 : Wed Dec 04 2013 - 20:42:38 MST