[19142] in s-news-athena

home help back first fref pref prev next nref lref last post

[S] Fortran (g77) and S-PLUS on Windows

daemon@ATHENA.MIT.EDU (Prof Brian Ripley)
Wed Sep 8 11:42:38 1999

Message-Id: <199909081536.QAA09205@toucan.stats.ox.ac.uk>
Date: Wed, 8 Sep 1999 16:36:26 +0100 (BST)
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Reply-To: Prof Brian Ripley <ripley@stats.ox.ac.uk>
To: S-news@wubios.wustl.edu
Mime-Version: 1.0
Content-Type: MULTIPART/mixed; BOUNDARY=Colony_of_Gulls_518_000


--Colony_of_Gulls_518_000
Content-Type: TEXT/plain; charset=us-ascii
Content-MD5: OUvYeZt4DnnRYqJl/T9JJg==

A follow-up to comments a while ago from Andrew Bruce and Steve Buyske
on using Fortran compilers with S-PLUS on Windows. I'll assume 2000 for
definiteness, but it probably all applies to 4.0 and 4.5. A lot
of this was found by disassembly, but I have run fairly extensive tests.

There are two rather special things about the Watcom compiler's linkage, and
calls such as DBLEPR are set up for Watcom.  Thus reading `page 579 of the
Programmer's Guide' will only help you with a Watcom compiler.

(1)  Subroutine name gets symbol name NAME (not u/case, no trailing _).

(2)  Character strings get linked indirectly, in C terms as char **
     not char * like most Unix compilers and g77.

Here is how to build a DLL using g77 (from the mingw32 port of gcc-2.95)
that works around these.

(i) once and for all build an import library. Copy Sqpe.def from
S_HOME\lib, edit it to remove two lines ending in ., copy
Sqpe.dll and run

dlltool --dllname Sqpe.dll --def Sqpe.def --output-lib libSqpe.a

(ii) Compile your subroutines my.f and the enclosed piece of C by

gcc -c glue.c
g77 -c my.f
dlltool --export-all-symbols --output-def my.def my.o
dllwrap -o my.dll --def my.def my.o glue.o -L. -lSqpe

(iii) In S-PLUS use

dlltool("/path/to/my.dll", call="cdecl", symbol="mysym_")
.C("mysym_", ....)

You would need to write similar glue in C for XERROR and XERRWV.


If you want to use character strings as arguments to .Fortran then
(a) don't
(b) if you won't take advice, you will need a C wrapper for g77 to do the 
indirection, and you need to know that the strings in g77 are not
null-terminated, so you do need to use abcd//char(0) or to pass the
length to the wrapper.


We are assured this will be much easier in S-PLUS 1,000,000 (= (2000/4)x2000
or whatever name the MathSoft marketing dept come up with next).
Meanwhile things like this are going into the second Venables & Ripley book
on S programming, due in the Spring (N. Hemisphere).

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

--Colony_of_Gulls_518_000
Content-Type: TEXT/x-sun-c-file; name="glue.c"; charset=us-ascii; x-unix-mode=0644
Content-Description: glue.c
Content-MD5: vQ4GVZBcTwVMHEuJwbw+Xg==

/* interface code to mingw32 version of g77 */

void dblepr_(char *s, long *ns, double *x, long*n)
{
    char *p = s;
    DBLEPR(&s, ns, x, n);
}

void realpr_(char *s, long *ns, float *x, long*n)
{
    char *p = s;
    REALPR(&p, ns, x, n);
}

void intpr_(char *s, long *ns, long *x, long*n)
{
    char *p = s;
    INTPR(&p, ns, x, n); 
}

--Colony_of_Gulls_518_000--
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

home help back first fref pref prev next nref lref last post