[R] Reading in FORTRAN data using R

From: Tyler Hayes <thayes_at_uwo.ca>
Date: Wed 08 Feb 2006 - 07:30:40 EST


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@uwo.ca
TEL  : 519.661.3187 (main office)
FAX  : 519.661.3198
CELL : 416.655.7897

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Feb 08 07:36:41 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:24 EST