[I meant to send this earlier, but got side-tracked. Some of what I  
say below echoes Dennis' comments.]
Hi Lei,
Do loops in any scripted language can be slow, and especially nested  
do loops.
Since you can do array arithmetic in NCL without having to loop, I  
highly recommend using this feature. Also,, anything inside a do loop  
that doesn't need to be there should be moved outside the loop.
Here's another UNTESTED version of your code, that's a bit shorter.  
This is probably not quite right, but hopefully you get the idea:
alat2d    = conform((/natime,nalat/),alat,1)
rlat2     = (alat2d+1.429)*3.14159265/180.0 ; convert degree to radians
rlat1     = (alat2d-1.429)*3.14159265/180.0
temp      = sin(rlat2)-sin(rlat1)
diff_lon  = 2.8152d*3.14159265d/180.0d
R         = 6371.0d*1000.0d ; unit is meterncd
area      = R*R*diff_lon*temp
area      = where(area.lt.0,0.0,area)
totalfch4 =0.0d
do i =0, natime-1
   do j=0,nalat-1
     kk = ind(.not.ismissing(aFCH4(i,j,:)))
     if(.not.all(ismissing(kk))) then
       totalfch4=sum(aFCH4(i,j,kk)*area)
       afch4(i) = afch4(i)+totalfch4
     end if
     delete(kk)
   end do
end do
On Dec 15, 2009, at 1:34 PM, Lei Meng wrote:
> Hi,
>    I was wondering if there are some faster ways to calculate  
> globally total emissions. I used the following code and it looped  
> over each grid cell to calculate total values. It takes so long to  
> finish the calculation.
> --------------------------
> totalfch4=0.0d
>    do i =0, natime-1
>         do j=0,nalat-1
>          rlat2= (alat(j)+1.429)*3.14159265/180.0 ; convert degree  
> to radians
>          rlat1= (alat(j)-1.429)*3.14159265/180.0
>          temp1 = sin(rlat2)
>          temp2 = sin(rlat1)
>          temp = temp1-temp2
>
>             do k=0,nalon-1
>                  if(.not.ismissing(aFCH4(i,j,k))) then
>                     diff_lon = 2.8152d*3.14159265d/180.0d
>                     R=6371.0d*1000.0d ; unit is meterncd
>                     area=R*R*diff_lon*temp
>                     if(area.lt.0) then
>                        area=0.0
>                     end if
>                     totalfch4=aFCH4(i,j,k)*area             ;  
> convert from kgC/m2/s to kgC/s by multiplying area
>                     afch4(i) = afch4(i)+totalfch4
>                   end if
>             end do
>        end do
>   end do
> ------------------------------------
> Any suggestions would be appreciated. Thanks,
> Lei
> _______________________________________________
> 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 Tue Dec 15 21:01:35 2009
This archive was generated by hypermail 2.1.8 : Thu Dec 17 2009 - 17:15:52 MST