[R] Reading in FORTRAN data using R

Tyler Hayes thayes at uwo.ca
Tue Feb 7 21:30:40 CET 2006


Hi There:

I was wondering if there is a way to read FORTRAN list data (similar to 
IDL's readf function).  I often use FORTRAN for most of my number 
crunching, and use something like IDL to visualize and perform 
statistical analysis on that data.  Since the each file is rather large 
(>100 Mb), formatting the output into columns or tables is impractical, 
hence the "list" style.  Please note, this is NOT binary data, but text 
output with no FORMAT.  For example:

My FORTRAN code writes out:

      open(unit=30,name=fnout,status='old')
           
      write(30,'(a20)') fnmod
      write(30,'(a20)') fnstr
      write(30,*) nfault,hpl,vplx,vply,taua,tauf,amuu,
     &      tminn,tstepp,itime,TBIS,bulkms,ntm,ncycle,pdcy
      write(30,*) ptrad
      write(30,'(a1)') respfb
      write(30,*) (timi(n), n=1,nfault)
      write(30,*) (taub(n), n=1,nfault)
      write(30,*) (delts(n), n=1,nf)
      write(30,*) (cfr(n), n=1,nfault)
      write(30,*) (dfr(n), n=1,nfault)
      write(30,*) (slpdf(n), n=1,nf2)
      write(30,*) (slpv(n), n=1,nfault)
      write(30,*) (rhofcc(n), n=1,nfault)
      write(30,*) (islip(n), n=1,nfault)

(NOTE: not all variables are the same length!)

I subsequently read in back the data as:

      open(unit=30,name=fnin,status='old')

      read(30,'(a20)') fnmod
      read(30,'(a20)') fnstr
      read(30,*) nfault,hpl,vplx,vply,taua,tauf,amuu,
     &     tminn,tstepp,ntime,TBIS,bulkms,ntm,ncycle,pdcy
      read(30,*) ptrad
      read(30,'(a1)') respfb
      read(30,*) (timi(n), n=1,nfault)
      read(30,*) (taub(n), n=1,nfault)
      read(30,*) (delts(n), n=1,nf)
      read(30,*) (cfr(n), n=1,nfault)
      read(30,*) (dfr(n), n=1,nfault)
      read(30,*) (slpdf(n), n=1,nf2)
      read(30,*) (slpv(n), n=1,nfault)
      read(30,*) (rhofcc(n), n=1,nfault)
      read(30,*) (islip(n), n=1,nfault)


read.fwf is not what I need from what I read and neither is read.fortran.

How would I go about reading in the above unformatted Fortran file within R?

Sorry if the question is somewhat trivial, but I am a complete nube to R 
(installed it 2 weeks ago) and am just getting caught up to speed.

Thanks for any advice you may have.

Cheers,

t.

-- 
Tyler Joseph Hayes
PhD Candidate, Geophysics
The University of Western Ontario
Department of Earth Sciences
B & GS Building - RM 154
London, Ontario N6A 5B7
CANADA 

email: thayes at uwo.ca
TEL  : 519.661.3187 (main office)
FAX  : 519.661.3198
CELL : 416.655.7897




More information about the R-help mailing list