[R-sig-Geo] reading select values from a binary file
b.rowlingson at lancaster.ac.uk
Wed Dec 9 19:33:20 CET 2009
On Wed, Dec 9, 2009 at 6:20 PM, rick reeves <reeves at nceas.ucsb.edu> wrote:
> Hello All:
> Faced with a similar challenge, and NOT wanting to resort to writing a C
> language function
> employing fseek(), I just used two readBin calls: One to read (and
> implicitly discard) data up
> to the spot I actually wanted to read, and a second call to read the desired
> here is a code sample:
> fileCon = file(sTsFileName,"rb")
> # Offset has been calculated above: number of NumericByte-sized elements
> # the data of interest.
> if (iOffset > 0)
> TestVec = readBin(fileCon,numeric(),size =
> dTimeSeries = readBin(fileCon,numeric(),size =
> iNumericBytes,n=iNumElements) close(fileCon)
> Crude, but effective. I WIS that we could add a seekBin() function that
> positions the file pointer
> to the desired spot.
The R seek function does this. I hadn't tested it when I posted,
hoping the original poster would work it from my message. So I just
now tested it:
I created a file with ascii a to z in, and then:
> con = file("file.tst","rb")
# jump to 13th letter:
# read it:
 6e # thats ascii 'n'
# jump back:
 14 # returns where we were, we've now moved...
 62 # ascii 'b'. Things start at zero....
Is that what you are trying to do?
More information about the R-sig-Geo