I sent a reply yesterday but I am not sure if it went through. However,
today I am running into a similar problem. When you get a stack overflow
in the dll Splus simply exits. This happens because you may be creating
a temporary large data structure in the Fortran and Splus allows very
limited stack space for the dll. The way to solve it is to pass the
large data structures from Splus to the fortran in the fortran call. For
example
suppose you use Work(dimrow,dimcol) in your dll.
Create this matrix in Splus (eg Workmat<-rep(0,dimrow*dimcol))
add it to your Fortran call.
.Fortran(v1,v2,....Workmat)
This allows Splus to allocate the memory for the variable instead of
the Fortran DLL. I suspect things (or limits) work differently in Unix
and the dummy function you tested probably uses a smaller data set.
Hope this helps,
Michael Conklin
****************************************
Michael Conklin
Sr. VP Analytic Services
GfK Custom Research Inc.
8401 Golden Valley Rd
Minneapolis, MN 55427
mconklin@customresearch.com
763-542-0821 (Voice)
763-542-0864 (Fax)
>>> <Kevin_Brand@hc-sc.gc.ca> 11/15/01 03:56PM >>>
Dear S-Plus users,
I am having trouble using a fortran-compiled DLL in Splus.
Briefly, a function call to the fortran-compiled DLL causes an exit
from S-PLUS!
After reading several posts related to linking fortan to Splus via
DLLs'
(posted on the S-user archives), I am still having problems.
I have spent several days trying to narrow in on the problem. I am
nearing my
wits end.
Platform Details: I'm working on Windows 95, using Splus-2000 (Release
1) and
using Fortran Powerstation 4.0.
My most direct question is how can i get Splus to give me some clues
about the
type
of error that is causing it to exit. I describe the specifics of my
problem in
more detail below.
I have the following code in my Fortran program which as I understand
acts as a
substitute for a formal .DEF file.
!MS$ATTRIBUTES DLLEXPORT :: MYFUN
(it occurs as one of the first statements in my main fortran
subroutine)
I up-load the DLL file in Splus using the following code
if(!is.dll.loaded("myfun.dll")) {
dll.load("C:\\MSDEV\\Projects\\myfun\\Debug\\myfun.dll",
symbols =
list(myfun =
"_MYFUN@56"))
}
I have used Windows-explorer (Quick-view) to examine my DLL, confirming
that it
does indeed declare a symbol for my fortran Subroutine. That symbol's
definition,
_MYFUN@56
is compatible with the command I've used in the call to dll.load.
(BTW, I'm told the 56 makes sense. I understand from previous posts
that it
represents
the number of arguments times 4 ... I have 14 arguments to myfun)
Finally, I have an splus calling function which calls the Fortran
symbol. The
relevant
code is as follows.
storage.mode(x1) <- "integer"
storage.mode(x2) <- "integer"
storage.mode(x3) <- "single"
: : : :
storage.mode(x14) <- "single"
res <- .Fortran("myfun",
x1,
x2,
x3 = X3,
:: ::,
x14)
The argument order and type are consistent between the Splus and
Fortran code.
Note also that exact same code worked on a unix platform
(albeit with dyn.load replacing the role of dll.load), which seems to
confirm
to me that the arguments must be compatable!
When I run my Splus program, the dll loads successfully
however the first call the the fortran subroutine causes an exit from
Splus
(leaving me
no explicit clues regarding the problem).
I think I can ruel out the following.
1. A simple mismatch in argument type or order.
- A dummy version of my DLL consisting of only the subroutine
definition
including all arguments and a few rudimentary expressions works
succesfully
(i.e., as a. Fortran call in splus).
- The exact same code worked on Unix platform using dyn.load()
2. An obvious problem with the fortran code
- I have set-up a main program in fortran and called the very same
Fortran
subroutine
constituting the DLL. It works. This suggests to me that the
problem lies
in the
interface between Splus and the compiler.
I have tried all the sensible permutations for call.convention and MS
attributes in
the fortran code. None of them work.
I would be greatly appreciative of any suggestions about what to
be on the look out for. Are Unix compilers known to be more forgiving
about
certain details than Windows compilers ?
Some added detail is shown below for those who are interested.
My suspicions
1. My fortran program calls several other subroutines (but they were
compiled as
part
of the DLL making process). Could this be causing problems?
2. I pass several arrays from Splus to the fortran subroutine and then
from
there
to several other subroutines. My approach here has been to pass the
dimensions
along as separate arguments in the subroutines, and dimension
accordingly.
Perhaps
the Splus interface imposes tougher restrictions?
3. Perhaps I require an explicit DEF file rather than the DLLEXPORT
option (does
anyone have an example DEF file for me to draw from). This may allow
me to be
explicit about which arguments require pointer-references rather than
value-references
(i.e., the arrays).
---------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
******************************************************************
IMPORTANT CONFIDENTIALITY NOTICE: The documents and accompanying
email communication contain confidential information belonging to
the sender, Custom Research Inc. and/or GfK Database Solutions,
and are legally protected. If you are not the intended recipient,
you are hereby notified that any disclosure, copying, distribution
or the taking of any action in reliance on the contents of the
communicated information is strictly prohibited.
******************************************************************
|