I have been able to generate my own library composed of FORTRAN
subroutines and functions that I incorporate as shared objects into NCL.
This works nicely and really extends the functionality of the software.
I would like to be able to generate NCL "subroutines" and "functions" as
well, and I can't seem to figure out an easy way to do this. I am hoping
that I am missing something here. As an example, let's take the
pop_remap sample given on the NCL web site. This sample is appended.
Nearly all of this code will be exactly same for every remapping. In
fact, the only input required in this example is XIN and
"Src_to_Dst.nc", the only output is XOUT. It would seem logical to
create a new function that is composed of NCL commands with the
following interface:
XOUT = remap(XIN, "Src_to_Dst.nc"),
where the NCL function "remap" does everything in the example.
Can this be done in a straightforward manner. I could write the entire
function in FORTRAN (as a subroutine), but then I lose the nice data
file manipulation tools available in NCL.
This is just an example of a larger issue. Is there an easy way to
package lines of NCL into reusable functions? Examples?
Thanks for the help,
todd.
********
fP = addfile("Src_to_Dst.nc","r") ; SCRIP netCDF file
dim_x = dimsizes( XIN ) ; XIN is the variable to be
remapped
nDx = dimsizes( dim_x ) ; rank [# dimensions]
dim_src = fP->src_grid_dims ; size source grid
; error check
if (dim_x(nDx-2).ne.dim_src(1) .or. dim_x(nDx-1).ne.dim_src(0)) then
print (" Input grid and Remap sizes do not match")
exit
end if
dst_add = fP->dst_address ; destination grid [linear]
src_add = fP->src_address ; source grid [linear]
map_wts = fP->remap_matrix ; wts
dim_dst = fP->dst_grid_dims ; size destination grid
mx = dim_dst(0) ; output # elements in "x"
ny = dim_dst(1) ; output # elements in "y"
xout_1D = new (ny*mx, typeof(XIN)) ; (temporary) return grid [1D]
xin_1D = ndtooned ( XIN ) ; convert to 1D
pop_remap(xout_1D, map_wts, dst_add, src_add, xin_1D)
XOUT = onedtond(xout_1D, (/ny,mx/) ) ; new grid
delete(xout_1D) ; clean up
delete(xin_1D)
delete(dst_add)
delete(src_add)
delete(map_wts)
**********
---- Todd Ringler Department of Atmospheric Science Colorado State University Fort Collins, Colorado 80523-1371
tel 970-491-8432 fax 970-491-8428
email todd AT placer.atmos.colostate.edu http://kiwi.atmos.colostate.edu/group/todd/
This archive was generated by hypermail 2b29 : Tue Feb 19 2002 - 09:06:06 MST