[R] .Fortran()
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Wed Oct 10 09:18:44 CEST 2001
On Wed, 10 Oct 2001, Jari Oksanen wrote:
> I have had a related conversation about .Fortran with Brian Ripley
> (undercover), and I have learnt some valuable things, for instance
> about English language. As a non-English speaking person I had hastily
> assumed that `may' in ?.Fortran is more or less synonymous with `can',
> but it seems that it rather is synonymous with `may not'. Now I have
Not really. Both `may' and `can' signify possibility, not certainty.
There is at least one R implementation in which it works, so either would be
appropriate. `may not' would mean that there was one where it did not,
and although that is currently known, it may become unknown at some later
date.
I'll expand the statement.
> two new valuable pieces of information:
>
> ripley at stats.ox.ac.uk said:
> > A properly working version of g77 should work on some platforms
> > (including Linux), but not others (including Windows).
>
> This explains why my plug-in Fortran library worked in Linux (RH7.1,
> with gcc updates), but not when my mate tried that in Windows.
>
> And this is the second piece:
>
> ripley at stats.ox.ac.uk said:
> > BTW, no one said Fortran I/O would work, and it sometimes is a
> > problem.
>
> This means that I have a problem. Does anybody here have a solution?
In general, no. Indeed, in general Fortran formatted files are a
completely separate type of file (although I doubt R runs on any such
platform). The problems are
(a) R is a C program linking in Fortran compiled code and libraries, and
the Fortran I/O may not be initialized, and
(b) C and Fortran I/O may be trying to use the same underlying mechanism
and assuming they have exclusive access to it, thereby corrupting the
other attempt.
These are much less likely with C/Fortran compiler pairs like gcc/g77,
but on some platforms we advocate using higher-performance native Fortran
compilers (e.g. on Solaris where f95 optimizes much better than g77, and
has high-performance libraries).
> My problem is that there are plenty of legacy files in our field which
> are written with so-called Cornell Ecology Programs (CEP) formats.
> These are Fortran formatted files, and the actual format used is
> written in the file (on its second line, or, I should say, `card'). I
> thought that a nice solution was to write a Fortran program[me] to read
> these files and pass the data and row and column names back to R which
> then makes these into a data.frame. It was surprisingly easy and worked
> beautifully in Linux, but crashed R in Windows. I made a small test
> package in Fortran which made nothing but opened a file and read a
> line. This crashed in Windows (I don't have access to Windows, so these
> tests were made in Florida, and I never saw what happened). So it seems
> that this is not portable. Now comes the question (finally, I hope
> somebody got this far): Is there a R pluggable module to interpret
> Fortran format (which may be tricky), so that I could read these lines
> with plain C or plain R? (I once made a similar program[me] using
> Scientific Python module in Python, but that was much more tricky than
> using direct Fortran, and failed in some test files).
>
> Another alternative is to let it be and make a separate stand-alone
> program to change these files into, say, csv and then read them into R.
> However, it was so nice when I suddenly had access to tens of my old
> files within an R session, and I would like other people to share my
> joy (sounds like a cheap thrill). Naturally, this works now in my
> system, so my concern is rather abstract.
I would do it that way, even invoke the external program via system.
It's tempting to use pipe/fifo connections, but they are not very portable.
--
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