Re: loop optimization

From: Dennis Shea (shea AT cgd.ucar.edu)
Date: Mon Aug 30 2004 - 10:18:31 MDT


>
>sfc = new((/399,399/),float)
>do i=0,ix
> do j=0,iy
> sfc(i,j) = zin(minind(sqrt((lon(i,j)-xin)^2+(lat(i,j)-yin)^2)))
> end do
>end do
>
>xin, yin and zin are large 1d arrays. I have tried working on full 3d
>arrays using conform, but then I run out of memory.
>

---
The above assigns to each grid point, the value of the closest "z". 

I can not think of any simple way to optimize the above. --- [1]

One could try (not sure if it will be faster):

lat1d = ndtooned(lat) ; lat is 2d lon1d = ndtooned(lon) ngpts = dimsizes(lat1d) ; # of grid points sfc1d = new ( ngrd, typeof(z) ) do i=0,ngpts-1 sfc1d(i) = zin(minind(sqrt((lon1d(i)-xin)^2+(lat1d(i)-yin)^2))) end do delete(lat1d) ; no longer needed delete(lon1d) sfc = onedtond(sfc1d, dimsizes(lat)) ; reshape delete (sfc1d) ; no longer needed

--- [2]

I do have a fortran subroutine that does what you want. This is a two-dimensional version of NCL's "triple2grid" function.

It has a few extra options not indicated by your above example.

If you want to try this via a fortran shared object, please let me know. It is simple to use. If it works [ :-) ], I'm sure it could be built-in to NCL ["triple2grid2d"] It will be fast.

--- D

_______________________________________________ ncl-talk mailing list ncl-talk@ucar.edu http://mailman.ucar.edu/mailman/listinfo/ncl-talk



This archive was generated by hypermail 2b29 : Mon Aug 30 2004 - 11:05:22 MDT