Re: if then else statement

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu May 30 2013 - 14:05:22 MDT

You can't use an "if" statement on an array of values by themselves.

If "wb" is an array, and you want the True part of the "if" statement to be executed if *any* of the "wb" values are greater than 0, then use the "any" function:

  if(any(wb).gt.0) then
     …

If you want the True part of the "if" statement executed only if *all* of the values are > 0, then use "all":

  if(all(wb).gt.0) then

You may also want to look at the "where" function, which allows you to do a calculation on a variable based on certain conditions and then return the new value.

For example, if you want "wb" to have a calculation performed on it for any value over 0, but you want to keep the value for anything <= 0, you can do something like:

   wb = where(wb.gt.0,wb+1,wb) ; Adds 1 to any value > 0

The "wb+1" is just an example. Obviously you'd want to replace this with your own calculation.

--Mary

On May 30, 2013, at 1:58 PM, jbuzan wrote:

> Hello NCL-Talk,
>
> I am having an issue with my statement:
>
> Line 276 if (wb.gt.0.) then
> Line 277 do j = 0, 4
> Line 278-347 calculations…
> Line 348 end do
> Line 349 else
> Line 350 wb = wb
> Line 351 end if
>
> fatal:Conditional statements (if and do while) require SCALAR logical values, see all and any functions
> fatal:Execute: Error occurred at or near line 350
>
> I am not sure what I am doing incorrectly here, any suggestions?
>
> -Jonathan
>
>
> _______________________________________________
> 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 May 30 14:05:30 2013

This archive was generated by hypermail 2.1.8 : Tue Jun 04 2013 - 09:50:17 MDT