🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.stats.s
Article #16112

Re: S and NAG (Fortran, really)

#16112
From: Charles Geyer
Date: Mon, 13 Jan 1992 23:38
85 lines
3467 bytes
In <9201131845.AA02180@astro.ocis.temple.edu> rmh@astro.ocis.temple.edu
(Richard M. Heiberger) writes:

> Mike Denham asks about using S with NAG.  Both NAG and IMSL Fortran routines
> use Fortran I/O.  According to the blue book this explicitly prevents them
> from being used with dyn.load.  I wrote an interface using the unix() command
> that is available from statlib.
> 
> s.f77.c.libs	Simple interface from S to f77 or C programs with Fortran I/O.
> 		No modifications to either S or IMSL are required!
> 		IMSL and some other libraries use Fortran I/O for errors.
> 		Partial replacement for dyn.load() when dyn.load is unavailable.
> 		(rmh@gaia.stat.temple.edu).
> 		[27/Nov/1989] (7775 bytes)

There is a workaround that is much better or much worse depending on your
point of view.  I have installed NAG routines in S, directly with dyn.load.
The catch is that all Fortran I/O must be turned off.  If the routine
needs a constant stream of blather to let you know what's happening, you're
S. O. L.  On the other hand, if the I/O is only for error conditions which
will not arise with your perfect code, who needs it?

Here's a little test routine that does some I/O.

          subroutine bar(i)
          integer i
          if (i .gt. 0) write (0,*) 'Oops'
          end

If we compile it to bar.o and try to load it into S, we get complaints.

   > dyn.load("bar.o")
   ld:
   Undefined:
   s_wsle
   do_lio
   e_wsle
   ld: No such file or directory
   Error in dyn.load("bar.o"): 'ld -A ...' failed
   Dumped

Looks like we need routines s_wsle, do_lio, and e_wsle.  No problem,
we just write replacements (in C).

   /* Dumbed-down Fortran I/O package */

   void static oops()
   {
	   printf("Hey!  No Fortran I/O allowed, Bub.\n");
   }

   e_wsle() { oops(); }
   s_wsle() { oops(); }
   do_lio() { oops(); }

Note that this is *extremely* non-portable.  If you have a machine
different from this one, the Fortran I/O library routine names will
be different.  Even on this machine, if we had tried more elaborate
I/O, there would have been more routines called.  But the principal
is the same: supply dummy routines for whatever is missing.

Now it works.

   > print(dyn.load(c("foo.o","bar.o")))
   [1] "e_wsle" "s_wsle" "do_lio" "bar_"
   > .Fortran("bar", i=as.integer(0))
   $i:
   [1] 0

As long as the Fortran I/O is not called, there are no problems.  Of
course if it is called, the dummy routines don't do a very good job.

   > .Fortran("bar", i=as.integer(1))
   Hey!  No Fortran I/O allowed, Bub.
   Hey!  No Fortran I/O allowed, Bub.
   Hey!  No Fortran I/O allowed, Bub.
   $i:
   [1] 1

----
Charles Geyer
School of Statistics
University of Minnesota
charlie@umnstat.stat.umn.edu
D
Technical Details
Message-ID: <9201132310.AA27099@umnstat.stat.umn.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!spool.mu.edu!munnari.oz.au!uniwa!dmsperth!dmssyd.syd.dms.CSIRO.AU!news

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fa931,cef4df34bf9b8b4,start
X-Google-Attributes: gidfa931,public
X-Google-ArrivalTime: 1992-01-13 16:22:15 PST
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!spool.mu.edu!munnari.oz.au!uniwa!dmsperth!dmssyd.syd.dms.CSIRO.AU!news
From: charlie@umnstat.stat.umn.edu (Charles Geyer)
Newsgroups: aus.stats.s
Subject: Re: S and NAG (Fortran, really)
Message-ID: <9201132310.AA27099@umnstat.stat.umn.edu>
Date: 13 Jan 92 23:38:47 GMT
Article-I.D.: umnstat.9201132310.AA27099
Sender: daemon@syd.dms.CSIRO.AU
Organization: CSIRO Div. Maths & Stats, CSIRO Div. Applied Physics
Lines: 84
X-Gateway: dmssyd.syd.dms.CSIRO.AU