# [ncl-talk] Fwd: Sub: Loop help

Adam Phillips asphilli at ucar.edu
Mon Nov 6 09:24:37 MST 2017

```Hi DZ,
It looks to me like you are replacing your entire mas array each time
through the do loop. When you are having issues with a do loop it is best
to manually interpret what the result will be each time through. The fact
that you get the right answer when you set i = 1,1 or 2,2 or 3,3 gives a
hint as to what is wrong.

first time through the loop:
where mas.ge.1.and.lt.2, set to 1, otherwise set to _FillValue
second time through the loop:
where mas ge.2.and.lt.3, set to 1, otherwise set to _FillValue   <-----
This second time through the do loop overwrites what you did the first time
through

I am not totally clear as to what you are trying to accomplish, but the
following may work:

do i=1,4
j=i+1
mas=where(mas.ge.i .and. mas.lt.j,i,mas)
end do

If you have any further questions please respond to the ncl-talk email list.

On Sat, Nov 4, 2017 at 6:38 PM, dale zuri <dalezuri at gmail.com> wrote:

>
> ---------- Forwarded message ---------
> From: dale zuri <dalezuri at gmail.com>
> Date: Fri, Nov 3, 2017 at 2:46 PM
> Subject: Re: [ncl-talk] Sub: Loop help
> To: Kevin Hallock <hallock at ucar.edu>
> CC: <ncl-talk at ucar.edu>
>
>
> Hi ,
>
> begin
> printMinMax(mas,0);;;;;;Print----(0,1,2,-21) each number associated with
> different division ( ex., (0-1)- division 1, (1-2) division 2, oceanic
> region are filled with missing number and land regions are filled with
> number 1.
> do i=1,1 or 2,2 or 3,3 ( I get the right selection of region and
> printMinMax shows 1)
> do i=1,4 ( I get the wrong selection of region and printMinMax shows
> missing number)
> j=i+1
> mas=where(mas.ge.i .and. mas.lt.j,1,mas at _FillValue)
> end do
> printMinMax(mas,0) ...(1,1)
> return
>
> I hope this helps! Please let me know If you have any questions.
>
> Thanks
> DZ
>
>
> On Fri, Nov 3, 2017 at 12:01 PM, Kevin Hallock <hallock at ucar.edu> wrote:
>
>> Hi Dz,
>>
>> Could you please provide more detail about how the numbers are wrong?
>>
>> Also, do you have a complete script you could share? That might help us
>> identify any possible issues.
>>
>> Thanks,
>> Kevin
>>
>> > On Nov 3, 2017, at 1:37 PM, dale zuri <dalezuri at gmail.com> wrote:
>> >
>> > Hi NCL users,
>> >
>> > Could someone help me to fix this bug? This loop gives me wrong
>> > do i=1,11
>> > j=i+1
>> > mas=where(mas.ge.i .and. mas.lt.j,1,mas at _FillValue)
>> > end do
>> > Thanks
>> > Dz
>> > _______________________________________________
>> > ncl-talk mailing list
>> > ncl-talk at ucar.edu
>> > List instructions, subscriber options, unsubscribe:
>> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

--