kapo coulibaly
2009-Dec-17 21:30 UTC
[R] Problem reading binaries created with fortran (More infos)
The structure of the file is clear (see below) the first line is made of integers and doubles with the fifth being a text string followed by arrays of double precision number.: int1 int2 double1 double2 text int3 int4 int5 (array of double) here is an example of file: 1 1 1.0 1.0 "HEAD" 160 224 3 23.4 34.5 ...... I tried to read the first line with readBin (results are copied below):> zz <- file("heads.hds", "rb") > readBin(zz,what="integer",n=2)[1] 1 1> readBin(zz,what="double",n=2)[1] 7.812502e-03 6.013470e-154> readBin(zz,what="character",n=1)[1] " HEAD "> readBin(zz,what="integer",n=3)[1] 14680064 65536 0>Thanks On Thu, Dec 17, 2009 at 3:52 PM, Phil Spector <spector@stat.berkeley.edu>wrote:> Kapo - > You'll get a better response if you tell us what you've already tried, > and an even better response if you > can provide a reproducible example. > > - Phil Spector > Statistical Computing Facility > Department of Statistics > UC Berkeley > spector@stat.berkeley.edu > > > > On Thu, 17 Dec 2009, kapo coulibaly wrote: > > Is it possible to read fortran binaries with R? I tried unsucessfully and >> my >> understanding is that fortran write binaries with leading and trailing >> bytes. I get numbers but not the right ones. >> Thanks >> >> ps: the binary I'm interested in reading is a MODFLOW output with a mix of >> character, double and integers. >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >>[[alternative HTML version deleted]]
Duncan Murdoch
2009-Dec-17 22:02 UTC
[R] Problem reading binaries created with fortran (More infos)
On 17/12/2009 4:30 PM, kapo coulibaly wrote:> The structure of the file is clear (see below) the first line is made of > integers and doubles with the fifth being a text string followed by arrays > of double precision number.: > int1 int2 double1 double2 text int3 int4 int5 > (array of double) > > here is an example of file: > 1 1 1.0 1.0 "HEAD" 160 224 3 > 23.4 34.5 ......That's not the file that readBin is reading, that's the output from something that knows how to read it. If you show us the hex dump from hexView, it's likely we can suggest what to do to read it, especially knowing the above output. Duncan Murdoch> > > I tried to read the first line with readBin (results are copied below): > >> zz <- file("heads.hds", "rb") >> readBin(zz,what="integer",n=2) > [1] 1 1 >> readBin(zz,what="double",n=2) > [1] 7.812502e-03 6.013470e-154 >> readBin(zz,what="character",n=1) > [1] " HEAD " >> readBin(zz,what="integer",n=3) > [1] 14680064 65536 0 > > > Thanks > > > > > > On Thu, Dec 17, 2009 at 3:52 PM, Phil Spector <spector at stat.berkeley.edu>wrote: > >> Kapo - >> You'll get a better response if you tell us what you've already tried, >> and an even better response if you >> can provide a reproducible example. >> >> - Phil Spector >> Statistical Computing Facility >> Department of Statistics >> UC Berkeley >> spector at stat.berkeley.edu >> >> >> >> On Thu, 17 Dec 2009, kapo coulibaly wrote: >> >> Is it possible to read fortran binaries with R? I tried unsucessfully and >>> my >>> understanding is that fortran write binaries with leading and trailing >>> bytes. I get numbers but not the right ones. >>> Thanks >>> >>> ps: the binary I'm interested in reading is a MODFLOW output with a mix of >>> character, double and integers. >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.