wrapping fortran intrinsics

From: Jeff Whitaker (jsw AT XXXXXX)
Date: Thu Apr 04 2002 - 09:19:41 MST


Hi: This is probably old hat to most of you, but I'm new to NCL and I
thought this was so cool that I just wanted to share. I needed access to
the complementary error function (erfc), which is not available as an NCL
function. After reading the docs on WRAPIT, I came up with this solution:

undef("erfc")
external ERFC"erfc.so"
function erfc(x:numeric)
; computes complementary error function using fortran intrinsic.
; requires external shared object erfc.so created by running
; WRAPIT script on this simple fortran subroutine:
;C NCLFORTSTART
; subroutine cerf(x,y,n)
; integer n
; real x(n),y(n)
;C NCLEND
; y = erfc(x)
; return
; end
local x1,y1,dims,len
begin
; find dimensions of input array (dims), total number of elements (len)
 dims = dimsizes(x)
 len = dim_product(dims)
; convert input array to 1-d array of length len (x1)
 x1 = ndtooned(x)
 y1 = x1 ; create 1-d array y1
; call fortran external routine with 1-d array x1 as input
 ERFC::cerf(x1,y1,len) ; returns another 1-d array (y1)
; convert 1-d array y1 to same dimension as input array
 y = onedtond(y1,dims)
 return(y)
end

To have access to erfc in NCL all I needed to do was run WRAPIT on erfc.f
(the simple little program given in the comments at the beginning of the
function), then load erf.ncl into my NCL script. "y = erfc(x)" works on
scalars and arrays of any dimension. Kudos to the NCL team - what a great
tool!

BTW: What's the reason that NCAR doesn't open the NCL source? After all,
the binaries are given away for free. I can think of at least three
reasons to do so,

1) it would allow users to port NCL to unsupported platforms,

2) it would allow users to recompile NCL with their own favorite fortran/c
compilers, with maximum optimization,

3) most importantly, it would allow users to
contribute their own extensions/features to the NCL source.

Seems to me like everyone would benefit. This is a major advantage of
other similar tools - i.e. CDAT (http://cdat.sf.net).

-Jeff

 --
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/CDC R/CDC1 Email : jsw@cdc.noaa.gov
325 Broadway Web : www.cdc.noaa.gov/~jsw
Boulder, CO, USA 80303-3328 Office : Skaggs Research Cntr 1D-124



This archive was generated by hypermail 2b29 : Thu Apr 04 2002 - 10:27:40 MST