Kaptue Tchuente, Armel
2013-Apr-19 05:05 UTC
[R] How to read a direct access file by connecting fortran with R ?
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]]
Kaptue Tchuente, Armel
2013-Apr-19 11:44 UTC
[R] How to read a direct access file by connecting fortran with R ?
Dear Suzen, Thank you for your reply. I don't know why but it looks like my previous mail was truncated. Here is the R function (described in the step #4 in my previous mail) that I wrote. It contains .Fortran but like I said earlier, it didn't work. ************************************ 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) } ************************************ Armel -----Original Message----- From: mehmet.suzen at gmail.com [mailto:mehmet.suzen at gmail.com] On Behalf Of Suzen, Mehmet Sent: Friday, April 19, 2013 3:17 AM To: Kaptue Tchuente, Armel Subject: Re: [R] How to read a direct access file by connecting fortran with R ? On 19 April 2013 07:05, Kaptue Tchuente, Armel <armel.kaptue at sdstate.edu> wrote:> 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 imgAt this stage you need to use .Fortran; .Fortran("read_binary", as.integer(n_samples), as.intger(line), img=as.single(img)); See ?.Fortran
Apparently Analagous Threads
- How to determine the pdf of a gamma distribution using the estimated parameters?
- Model selection: On the use of the coefficient determination(R2) versus the frequenstist (AIC) and Bayesian (AIC) approaches
- glmnet
- Borrar cada fila 400
- unable to install rPython