[R] Graceful exit from fortran. (fwd)

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Oct 7 10:47:12 CEST 2001


On Tue, 2 Oct 2001, Jari Oksanen wrote:

>
> rolf at math.unb.ca said:
> > If I say something like
> >       if(x .gt. 42.d0) stop
> > then indeed everything stops, i.e. R falls over.  I'd ***like*** to be
> > able to print out an informative error message (which I guess could be
> > done -
>
>
> In Fortran:
>
>     subroutine foo(..., ier)
>     integer ier
>     ier=0
>     ...
>     if (x .gt. 42.d0) then
>        ier=1
>        return
>     endif
>     ...
>     return
>     end
>
> In R:
>
> foo <- .Fortran("foo", ..., ier=integer(1))
> if(foo$ier) stop("error: x > 42")

(Rolf wanted it from a deeply nested subroutine.  This is now solved in
R-devel: see its NEWS file.)

> By the way, is the following allowed in Windows with mignw32 g77:
>
> subroutine topen(filename)
> character*255 filename
> open(unit=1, file=filename, status='old')
> return
> end
>
> subroutine tread(line)
> character*255 line
> read(1, *) line
> return
> end
>
> This seems to work magically when linked to R in Linux (RH7.1, gcc
> "2.96" g77), but one friend of mine told it crashes R when linked to
> Windows R. I don't have Windows R with building tools anywhere I know,
> so I am not sure if this is the cause of the failure.

The cause of the failure is that you declared a fixed-length 255 character
string and did not pass one!  You were lucky it worked anywhere. It is
more correct Fortran (and more portable) to declare character*(*) in your
examples.


-- 
Brian D. Ripley,                  ripley at 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

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list