Fwd: add scalar variable to existing netCDF file

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 27 2013 - 14:50:45 MST

Hi David,
Well I updated the subject line and I am copying ncl-talk on this message to let everyone know it has been resolved to your satisfaction.
 -dave

Begin forwarded message:

> From: "David B. Reusch" <dreusch@ees.nmt.edu>
> Subject: Re: add variable to existing netCDF file
> Date: November 27, 2013 2:43:57 PM MST
> To: David Brown <dbrown@ucar.edu>
>
> Absolutely it helped! :-) You do not want to know what kind of convoluted alternatives I was pondering after I sent that email. Just wish I'd said "add scalar" instead of "add variable" in my Subject (so others might find it that much more easily in future).
>
> Not sure if I've done this before in NCL (even in the 12+ years I've been using it...) but it did remind of me some coding I did when creating netCDF directly from Fortran.
>
> Thanks again, especially for the quick response.
> Dave
>
> David Brown said the following on 11/27/2013 1:21 PM:
>> 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
>>
>
> --
> 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
Received on Wed Nov 27 14:50:56 2013

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