Re: picking off negative values

From: Mary Haley (haley@XXXXXX)
Date: Fri Aug 24 2001 - 11:51:34 MDT


>
> Dear NCL users
>
> If I have an array;
>
> nd=100
> a=new((/nd/),"float",-999.)
>
> that is made up of negative and positive values, how can I isolate
> the only negative values and make them zero ? Here is my current
> procedure for doing this;
>
> do id=0,nd-1
> if(a(id).lt.0.) then
> a(id) = 0.
> end if
> end do
>
> However when I try running this I get the following error message;
>
> fatal:The result of the conditional expression yields a missing value.
> NCL can not determine branch, see ismissing function
> fatal:Execute: Error occurred at or near line 231
>
> I thought since I set a _FillValue of -999. in the new statement that
> missing values are ignored. I am not sure why NCL keeps encountering
> a missing value. Any suggestions would be greatly appreciated.
>
> Thank you,
> Matt

Matt,

First, to answer your question about setting non-negative values
to 0, you can use the ">" operator:

   a = a > 0

For example, if a is equal to (/-3,-2,-1,0,1,2,3/), then the above
expression will yield a = (/0,0,0,0,1,2,3/).

In answer to why you are getting the error message: you cannot have a
missing value as part of an "if" statement. Thus, if at some
particular value for "id", "a(id)" is missing, then you are trying to
compare a missing value with 0., and it will choke.

You can first check if a(id) is missing, and then check if it's less than
zero:

   if(.not.ismissing(a(id)).and.a(id).lt.0.) then

It won't choke here, because it will evaluate the first expression,
see that it's False, and then exit before evaluating the second
expression. You just have to be sure to include the "ismissing" test
first!

This is all kind of a moot point, anyway, if you use the ">" operator.

--Mary



This archive was generated by hypermail 2b29 : Tue Feb 19 2002 - 09:06:06 MST