[ncl-talk] question about changing comparisons in code

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Wed Apr 6 10:53:09 MDT 2022


When the "if" statement gets complicated, I like to precompute the test
condition.  I think it makes the code easier to understand.  Also I like to
put parentheses around free-standing boolean expressions to make them
distinct, even though they are not required.

    if (input .eq. 0) then
        test1 = (x1(i) .ge. xvalue)
    else
        test1 = (x1(i) .le. xvalue)
    end if

    if (test1) then
        long if block ...
    end if


On Wed, Apr 6, 2022 at 7:37 AM Cathy Smith via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> NCLers
>
> I have need in NCL to set a comparison type based on a subroutine input.
> That is, if the input is "0", then I want to check if something is .ge. to
> a number. If it is "0", I want to check if it is .le.
>
> My 'if' block is long so I would like to avoid repeating that. Any ideas?
>
>  if(x1(i)*.ge.*xvalue)then
>
>      etc.. many lines
>
> end if
>
> I am looking for runs, by the way. I saw some NCL runs subroutines but
> they don't quite do what I need.
>
> Thanks
>
> Cathy Smith
>
> (long live NCL!)
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220406/31d16eed/attachment.html>


More information about the ncl-talk mailing list