Hello all,

I would like to read the specific line number row of a direct access file (which is stored as a n_row*n_col matrix of elements kind=p) without reading all the preceding lines (i.e 1,2,..,row-1).

Is there a function in R that can perform this task?

To solve my issue, I tried without to call Fortran from R by doing the following steps:

I) I wrote a subroutine in fortran called read_binary.f90
************************************
Subroutine read_binary (n_col,row,img)

   integer*1    :: im1(n_col)
   integer*1    :: im2(n_col)
   integer*1    :: im2(n_col)

   open(10,file=binary_file,access=direct,action=read,status='old',recl=n_col*p)
   if(p==1) then
     read(10,rec=row) img1
      img=img1
   else if(p==2) then
      read(10,rec=row) img2
      img=img2
   else
     read(10,rec=row) img3
      img=img3
   endif
   close(10)

End subroutine read_binary
************************************

II) R CMD SHLIB read_binary.f90

III) dyn.load("read_libray.so")

IV) Then in R,  I tried many variant of the following function but I wasn't able to store the line number row into the vector img
************************************
img<-c(n_col)
Read_binary<-function(n_samples,line,type) {
   as.integer(n_samples),
   as.intger(line),
   as.integer(typ),
   img=as.single(img)
}
************************************

Could anyone tell me what I'm doing wrong? I'm a beginner in R and my guess is that I'm missing something into the above R function.

Cheers

Armel

	[[alternative HTML version deleted]]

