[R] Can't read a binary file

Waichler, Scott R Scott.Waichler at pnnl.gov
Fri Apr 13 22:45:04 CEST 2012


Hi, I've read up on readBin() and chapter 6 in the R Data Import/Export manual, but I still can't read a binary file.  Here is how the creator of the file described the code that would be needed in Fortran:

"Every record has a return in fortran.  The length of each record is nx*ny*4.  To read you would use the following:

nlayx = nx*ny*4
do iz=1,nz,4
 read(binary file) var(1:nlayx)
enddo
nrest=mod(nx*ny*nz,nlayx)
read(binary file) var(1:nrest)"

The first value in the file should be 0.05, and all of the data values are real.  Here is what I get (with similar answers using double):

> v<-readBin("plotb.251", numeric(), size=4, n=1)
> v
[1] 1.614296e-39

> v<-readBin("plotb.251", numeric(), size=4, n=1, endian="swap")
> v
[1] 1.359775e-38

Platform is Intel Linux.  How can I read the file described above?

Thanks,
Scott Waichler, PhD
Hydrology Group, Energy & Environment Directorate
Pacific Northwest National Laboratory
scott.waichler at pnnl.gov



More information about the R-help mailing list