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 log was produced using the SunOS 5.8 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)
C Example
The following example (under SunOS 5.8) defines a new NAP function 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/sol/home/dav480/tcl/include -c pprod_i.c
ld -G -o libpprod.so pprod_i.o pprod.o
% load ./libpprod.so
% proc partialProd x {
nap "result = reshape(f32(_), shape(x))"
pprod "nels(x)" x result
nap "result"
}
% [nap "partialProd({2 1.5 3 0.5})"]
2 3 9 4.5
Fortran 90 Example
The following fortran 90 example does the same thing as the above C example.
The f90 source code in the file pprod.f90 is:
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 f95 -c pprod.f90
% make_dll -entry pprod_ pprod {n i32 in} {x f32} {y f32 inout}
cc -I/sol/home/dav480/tcl/include -c pprod_i.c
ld -G -o libpprod.so pprod_i.o pprod.o
% load ./libpprod.so
% proc partialProd x {
nap "result = reshape(f32(_), shape(x))"
pprod "nels(x)" x result
nap "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)