[ncl-talk] where function

Bassill, Nicholas nbassill at albany.edu
Fri Jun 22 09:34:54 MDT 2018


Hi All,

   This isn't an important question, but it's an issue that's cropped up for me enough to count on two hands now. Basically, I'd love to use the "where" function to return values that are not of the same type as the conditional expression. I'm just wondering if anyone has an elegant way around this that doesn't involve a do loop and if check.


This often gives an error, as the documentation notes ("If neither type can be coerced to the other type, an error is returned").


Here's a standard example of why I'd like to use it this way. Say I'm making a risk table for various weather phenomena contingent on that phenomena's value (like say, wind speed or rainfall).


It'd be really nice/easy to be able to do something like:

----------------

; note: below two arrays have same size

riskvalues = *series of random numbers for a variable, say precipitation in inches*

riskwords = *series of words - begin with all equal to "None"*

riskwords = where(riskvalues.gt.1,"High",riskwords) ; assigns a high risk when precipitation is large

--------------

This will give an error because you're returning a string, which can't be coerced to the number type you're evaluating.


So my question is twofold - (1) is there a way/flag to negate this behavior? and (2) assuming not, does anyone have a more elegant solution than a nested assignment inside an if check inside a do loop? It seems like the point of where is to avoid this situation.


Thanks for any input!

   - lazy coder


Nick Bassill, PhD

Modeler & Meteorologist, Center Of Excellence (Prior: NYS Mesonet)

LC SB-28, 1400 Washington Ave.,

SUNY, University at Albany, NY 12222

(518) 442-6375
NYSM Products: http://operations.nysmesonet.org/~nbassill/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180622/db338677/attachment.html>


More information about the ncl-talk mailing list