[R] reading fortran binary file

From: simon chou <sentientc_at_gmail.com>
Date: Sun 24 Apr 2005 - 06:04:15 EST


Hi r-help,
I have some troubles reading fortran binary file(from mm5) in R. Here is what I have done.
1. Use a fortran subroutine to read this file in R. The subroutine is as the following.

      subroutine freadmm5(filenamet,out2d)
      integer iflag,var1,miy,mjx,mkz,mt,z,t
      character*4 crdt,corder
      character*24 chrdate
      character*9 cname,var
      character*25 cunit,uunit,vunit,wunit
      character*80 filename
      real out2d(157,109),out3d(157,109,24)
      OPEN (11,FILE=filename,FORM='UNFORMATTED')
10    READ(11) IFLAG
      IF ( IFLAG .EQ. 0 ) THEN
          READ(11)
      goto 10
      elseif (iflag.eq.1) then
          read(11)
     &      IDIM           ! dimension of the field

& ,IB,JB,KB,LB ! starting indices
& ,IE,JE,KE,LE ! ending indices
& ,XTIME ! the ingegration or forcast time
& ,CRDT,CORDER,CHRDATE
& ,CNAME,CUNIT ! field name and unit description
if(cname.eq.'LATITCRS ')then read(11)out2d else read(11) endif goto 10 elseif(iflag.eq.2)then goto 20 endif 20 close(11) end 2.compile the subroutine as share object file with -byteswapio optin
3."dyn.load" the subroutine in R
4.call the subroutine.
.Fortran("freadmm5", filename = as.character("mmout"), array(as.single(0), c(157,109))
This gives a array which is nearly half empty when the subroutine can read the full array. I though it is because of R use double precision to read single precision data at first. When I passed "as.single" to it, it still came out the same result.
Also, I do not understand what is "DUP" in ".Fortran" function for and how it works. Can "DUP" solve my problem? Thanks in Advance,
simon

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 Sun Apr 24 06:09:37 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:25 EST