Re: reading in array with dash in name

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue May 04 2010 - 08:06:19 MDT

Hi folks,

This question is already in the FAQ, but with the word "hyphen"
instead of "dash". I'll add both to make it easier to find.

http://www.ncl.ucar.edu/FAQ/#file_io_008

BTW, you can use the $$ directly around the variable name without
creating a variable for it first:

      U_WND = aa->$"U-component_of_wind"$

The $$ can be used around attributes and coordinate names as well, for
both regular and file variables:

   n = x@$"long-name"$

--Mary

On May 3, 2010, at 5:37 PM, Gus Correa wrote:

> Hi Joe, Adam, list
>
> Very interesting.
>
> I had the same exact problem some time ago, not with a variable name,
> but with an attribute name that had a dash.
> It would be interpreted as a minus sign, exactly as Joe reported.
>
> If interested, mine is a global attribute called "cam-ready",
> and it is part of the CCSM3/CAM3 aerosol mass file.
> The CCSM3/CAM3 code checks to see if that attribute is there,
> and stops otherwise!
> Moreover, the aerosol mass file cannot be removed from the setup,
> or CAM3 stops.
> So, I had to keep the file and the attribute,
> otherwise my runs would fail.
> I found no way around and ended up skipping the attribute in NCL,
> then adding it back with NCO ncatted, an ugly but functional solution.
>
> Maybe the trick Adam taught us here could go to the FAQ.
> Something like:
>
> "How do I handle those pesky
> variable and attribute names with dash?" :)
>
> Thank you Joe for bringing this up!
> Thank you Adam for pointing out a solution!
>
> Gus Correa
> ---------------------------------------------------------------------
> Gustavo Correa
> Lamont-Doherty Earth Observatory - Columbia University
> Palisades, NY, 10964-8000 - USA
> ---------------------------------------------------------------------
>
> Adam Phillips wrote:
>> Hi Joe,
>> Try this:
>> tt = "U-component_of_wind"
>> U_WND = aa->$tt$
>> The $ $ syntax allows you to pass a string in as an array name. If
>> that
>> doesn't work let us know. Adam
>>
>> On 05/03/2010 04:15 PM, Joe Grim wrote:
>>> Hi,
>>>
>>> I was wondering if someone could tell me how to read into NCL an
>>> array
>>> with a dash in its name (e.g., U-component_of_wind). My line
>>> looks like
>>> this:
>>> U_WND = aa->U-component_of_wind
>>> but NCL thinks this is saying, take the difference of "U" in file
>>> "aa"
>>> and "component_of_wind".
>>>
>>> If there isn't a way of being able to read in this array in NCL,
>>> could
>>> you let me know how to alter the netCDF file to change its name
>>> before
>>> reading it into NCL?
>>>
>>> Thank you very much in advance.
>>>
>>> Joe Grim
>>> _______________________________________________
>>> 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

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue May 4 08:06:26 2010

This archive was generated by hypermail 2.1.8 : Fri May 07 2010 - 10:36:00 MDT