Re: How to accomplish a loop with negative stride?

From: Wen.J.Qu <wen.j.qu_at_nyahnyahspammersnyahnyah>
Date: Mon Oct 22 2012 - 17:28:48 MDT

Thanks, David.

I think I understand now. It seems the the stride should always be positive. But when execute NCL can automatically determine to increase or to decrease the loop indentifier by the stride depending on whether the start index is smaller than the end index or the start index is greater than the end index.

Thanks again and all my best!


Shawn




Wen.J.Qu
2012-10-22



发件人: David Brown
发送时间: 2012-10-22 17:36:28
收件人: Wen.J.Qu@gmail.com
抄送: ncl-talk
主题: Re: [ncl-talk] How to accomplish a loop with negative stride?

See the reference manual at http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml#Loops


Here's what it says about looping backwards:


The following shows how to specify a loop with an explicit stride. The following form is also necessary to loop backwards. With this form, if start is greater than end, then the identifier is decremented by the stride value, which must always be positive. If the start is less than the end, then the identifier is incremented by the stride value.


    do loop_identifier = scalar_start_expr , scalar_end_expr , scalar_stride_expr
         statement list
    end do




On Oct 22, 2012, at 4:15 PM, Wen.J.Qu wrote:


Hi, all

Would you please give some suggestions on how to accomplish a loop with negative stride? Just as below?

Thanks a lot.

Shawn



**************************************************
   do i=lon90,lon180
        n588(year_index,day_index,i)=0.0
             do j=lat80,lat10,-1
                  if((h(year_index,day_index,j,i)/10.0 .le. 588.0) .and. (h(year_index,day_index,j-1,i)/10.0 .le. 588.0))then
                       n588(year_index,day_index,i)=j
                       break
                  end if
             end do
   end do
**************************************************




Wen.J.Qu
2012-10-22
_______________________________________________
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 Mon Oct 22 17:28:54 2012

This archive was generated by hypermail 2.1.8 : Tue Oct 23 2012 - 11:10:04 MDT