make_dll
options
newCommand
argDec
argDec
argDec
…
make_dll_i
options
newCommand
argDec
argDec
argDec
…
make_dll.tcl defines
procedures for automatically producing an interface from NAP to a
DLL (dynamic-link library or shared library)
based on C or Fortran Code.
This process defines a new tcl command which can either be used directly or via another interface
(written in Tcl) defining a NAP function.
make_dll
options
newCommand
argDec
argDec
argDec
…
newCommand is name of new command.
Each argument-declaration argDec is a list with the form
{name dataType intent} where
c8 i8 u8 i16 u16 i32 u32 f32 f64 void
in (default) or inout.
Actual in arguments can be expressions of any type
(including ragged) and will be
converted to the specified type (unless this is void).
options are:
The following example (under Linux) defines a new NAP function
You can do the same thing in fortran 90 using the following source code:
The following log was produced using the Linux Lahey f95 compiler.
(Note that the entry point is
The arguments are similar to
-quiet: Do not echo commands.
-compile command: C compile-command with options
-dll fileName: output filename for
DLL (default: newCommand.dll for windows,
newCommand.so for unix)
-entry
-header fileName: header (*.h) filename (default: none)
-libs fileNames: filenames of extra binary libraries (default: none)
-link command: Link-command with options
-object fileName:
User-routine object-file (default: newCommand.obj
for windows, newCommand.o for unix)
-source fileName:
Output file containing C source code of interface
(default: newCommand_i.c)
-version 1.0)
partialProd
which calculates partial-products.
This is analogous to the standard nap function psum which calculates partial sums.
The new function is based on the following C file pprod.c:
void pprod(int *n, float *x, float *result) {
int i;
float prod = 1;
for (i = 0; i < *n; i++) {
result[i] = prod = prod * x[i];
}
}
% exec cc -c -o pprod.o pprod.c
% make_dll pprod {n i32 in} {x f32} {y f32 inout}
cc -I/home/dav480/tcl/include -c pprod_i.c
ld -shared -o libpprod.so pprod_i.o pprod.o
% load ./libpprod.so
% proc partialProd x {
set result [nap "reshape(0f, shape(x))"]
pprod "nels(x)" x result
return $result
}
% [nap "partialProd({2 1.5 3 0.5})"]
2 3 9 4.5
subroutine pprod(n, x, result)
integer, intent(in) :: n
real, intent(in) :: x(n)
real, intent(out) :: result(n)
integer :: i
real :: prod
prod = 1.0
do i = 1, n
prod = prod * x(i)
result(i) = prod
end do
end subroutine pprod
pprod_)
% exec lf95 -c pprod.f90
Compiling file pprod.f90.
Compiling program unit pprod at line 1:
/home/dav480/tmp/asm03529aaa.s: Assembler messages:
/home/dav480/tmp/asm03529aaa.s:86: Warning: translating to `fstp %st'
/home/dav480/tmp/asm03529aaa.s:90: Warning: translating to `fstp %st'
% make_dll -entry pprod_ pprod {n i32 in} {x f32} {y f32 inout}
cc -I/home/dav480/tcl/include -c pprod_i.c
ld -shared -o libpprod.so pprod_i.o pprod.o
% load ./libpprod.so
% proc partialProd x {
set result [nap "reshape(0f, shape(x))"]
pprod "nels(x)" x result
return $result
}
% [nap "partialProd({2 1.5 3 0.5})"]
2 3 9 4.5
Make NAP C interface to user's C function or Fortran subroutine.
This procedure is normally used via make_dll_i
options
newCommand
argDec
argDec
argDec
…
make_dll, but may be used directly if you prefer to
do your own compiling and linking.
The result of make_dll_i is the C code.
make_dll, except that the only options are:
-entry
-header fileName: header (*.h) filename (default: none)
-version 1.0)