# Re: Coordinate subscripting with mixed types

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Thu Aug 22 2013 - 12:39:41 MDT

Dave B,

Great. By the way, I belatedly found the "totype" function which was
added in 6.1.2 on a previous request of mine. This also goes to
easier generalized type handling. So, a belated thank you to the NCL
team!

--Dave A.

On Thu, Aug 22, 2013 at 12:30 PM, David Brown <dbrown@ucar.edu> wrote:
> Hi Dave,
> This is a very good suggestion. We will create a ticket for it.
> -dave
>
> On Aug 22, 2013, at 12:06 PM, Dave Allured - NOAA Affiliate <dave.allured@noaa.gov> wrote:
>
>> NCL support,
>>
>> This is a request for improved support for mixed types in coordinate
>> subscripting. For example, it is legal to subscript a double
>> coordinate with floats, but going the other way is an error. This
>> shows that type handling in simple NCL relational operators is more
>> liberal than in coordinate subscripting:
>>
>> lats = (/ 0., 10., 20., 30., 40., 50., 60. /)
>> x = (/ 0, 111, 222, 333, 444, 555, 666 /)
>> x!0 = "lat"
>> y = x
>>
>> x&lat = tofloat (lats)
>> y&lat = todouble (lats)
>>
>> f1 = 20. ; floats
>> f2 = 40.
>> d1 = 20d ; doubles
>> d2 = 40d
>>
>> ind1 = ind (y&lat .ge. f1 .and. y&lat .le. f2)
>> print (ind1+"")
>> print ("")
>>
>> ind2 = ind (x&lat .ge. d1 .and. x&lat .le. d2)
>> print (ind2+"")
>> print ("")
>>
>> sub1 = y({f1:f2}) ; float subscripts double
>> print (sub1&lat+" "+typeof(sub1&lat))
>> print ("")
>>
>> sub2 = x({d1:d2}) ; double subscripts float
>> print (sub2&lat+" "+typeof(sub2&lat))
>>
>> Result:
>>
>> NCAR Command Language Version 6.1.2
>> (0) 2
>> (1) 3
>> (2) 4
>> (0)
>> (0) 2
>> (1) 3
>> (2) 4
>> (0)
>> (0) 20 double
>> (1) 30 double
>> (2) 40 double
>> (0)
>> fatal:Coordinate subscript type mismatch. Subscript (0) can not be
>> coerced to type of coordinate variable
>> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 26 in
>> file mixed-mode-coord-subscripts.ncl
>>
>> I think it would be generally helpful if coordinate subscripting could
>> be broadened to support all reasonable cases of mixed types. At a
>> minimum, please support the same combinations as for the relational
>> operators. I know that there are simple workarounds, but this
>> improvement would benefit simpler user code and generalized file
>> support. Thanks for your consideration.
>>
>> --Dave A.
>> NOAA/PSD/CIRES Climate Analysis Branch
>> _______________________________________________
>> 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 Thu Aug 22 12:40:09 2013

This archive was generated by hypermail 2.1.8 : Fri Aug 30 2013 - 14:04:57 MDT