Re: replacing the do loops

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed, 06 Jun 2007 16:30:57 -0600

Debasish Pai Mazumder wrote:
>
> Hi,
>
>
>
> Does anyone have a suggestion how to do this without using a do loop
> and if statement, so it's faster?
>
>
>
> T1=new ((/24, 848, 70,150/), double)
>
> T1 (:,:,:,:) =-9999.
>
> T1@_FillValue = -9999. ; sets _FillValue to -9999
>

[a] T1=new ((/24, 848, 70,150/), double, -9999.)

      replaces the above lines

      Note: Do not use T1 (:,:,:,:) =-9999. Just use T1=-9999.
               Whenever NCL sees something like (:,:,:,:) it uses
               a less efficient method then T1=-9999.

> m= -1
>
> do i=0,15
>
> do j=0,52
>
> m=m+1
>
> do k=0,69
>
> do l=0,149
>
> if(lat(k).ge.lat1(i).and.lat(k).le.lat1(i+1)) then
>
> if(lon(l).ge.lon1(j).and.lon(l).le.lon1(j+1)) then
>
> T1(:,m,k,l)= TLand(:,k,l)
>
> end if
>
> end if
>
> end do
>
> end do
>
> print(m)
>
> end do
>
> end do
>
> printVarSummary(T1)
>
[b] Normally, the "ind" function would be recommended. However,
         this type of loop is not very optimizeable.
         You can improve efficiency by using the "if" better.
          Also, use of (/ ... /) prevent any meta data transfer.

      do k=0,69

          if (lat(k).ge.lat1(i).and.lat(k).le.lat1(i+1)) then

               do l=0,149

                   if(lon(l).ge.lon1(j).and.lon(l).le.lon1(j+1)) then

                      T1(:,m,k,l)= (/ TLand(:,k,l)
/) ; (/ ... /) prevent meta transfer

                  end if

              end do

          end if

       end do

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jun 06 2007 - 16:30:57 MDT

This archive was generated by hypermail 2.2.0 : Fri Jun 15 2007 - 12:34:56 MDT