[ncl-talk] How to do the following array manipulation without using loop?

Mary Haley haley at ucar.edu
Tue Sep 22 09:53:03 MDT 2015


I'm not sure if anybody responded to this, but given the complexity of the
logic, I'm not sure there's one statement that you can use to handle this
without some kind of looping.

I assume that the index locations index_up and index_low could potentially
be different each time through the loop?

I tried to think of a way that you could actually combine a and b into one
array, for example:

ab = where(a.eq.x.and.b.ne.x,b,a)
ab = where(b.eq.x.and.a.ne.x,a,ab)

and then use this to simplify the logic, but this isn't quite right, and,
in addition, the logic you need to apply with c1 and c2 is too complex for
a single line.

I would suggest writing a small Fortran subroutine that does the looping,
and then wrap this subroutine using WRAPIT so you can call it from NCL.

For some examples, see:

http://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#Examples

--Mary



On Mon, Sep 14, 2015 at 8:22 PM, zuibeidemei <zuibeidemei at 126.com> wrote:

> Dear all:
>
>              I'd like to apply the following array manipulation to a
> multi-dimentional array, but given the volume of the array,
>
>              a loop operation cannot be accepted. How can this be done
> without using a loop? Thanks in advance for any suggestion.
>
>                   x  = 1e20
>                   a  = (/1,2,3,4,5,6,x,x,x,x,x,x,x,x,x/)
>                   b  = (/x,x,x,x,x,x,x,x,x,1,2,3,4,5,6/)
>                   c1 = (/x,1,x,1,x,1,x,1,x,1,x,x,x,x,x/)
>                   c2 = (/x,1,x,1,x,1,1,1,1,1,1,x,x,x,x/)
>
>                   index_up  = max(ind(a.ne.x))
>                   index_low = min(ind(b.ne.x))
>
>                   if(.not.all(c1(index_up:index_low).ne.x))then
>                           c1(index_up:index_low)  = x
>                   end if
>
>                   if(.not.all(c2(index_up:index_low).ne.x))then
>                       c2(index_up:index_low) = x
>                   end if
>
>
> For example, in a 2D case:
>
>                   a   =
> (/(/1,2,3,4,5,6,x,x,x,x,x,x,x,x,x/),(/1,2,3,4,5,6,x,x,x,x,x,x,x,x,x/)/)
>           b   =
> (/(/x,x,x,x,x,x,x,x,x,1,2,3,4,5,6/),(/x,x,x,x,x,x,x,x,x,1,2,3,4,5,6/)/)
>           c1 =
> (/(/x,1,x,1,x,1,x,1,x,1,x,x,x,x,x/),(/x,1,x,1,x,1,x,1,x,1,x,x,x,x,x/)/)
>                   c2 =
> (/(/x,1,x,1,x,1,1,1,1,1,1,x,x,x,x/),(/x,1,x,1,x,1,1,1,1,1,1,x,x,x,x/)/)
>
>                   The above operation should be copied to the other
> dimension, which should yield same results as in the first dimension.
>
> Best
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150922/254e7a96/attachment.html 


More information about the ncl-talk mailing list