RE: Manipulating current read position in a binary file
- To: mathgroup at smc.vnet.net
- Subject: [mg80314] RE: [mg80266] Manipulating current read position in a binary file
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Fri, 17 Aug 2007 01:51:44 -0400 (EDT)
- References: <200708160844.EAA23238@smc.vnet.net>
Hi Greg,
> I'm trying to read in a large data file (several million data
> points); at the beginning of the file is the number of data
> points, but at the end of the file is the number of bins into
> which the data will be grouped. Is there a way to skip to
> the end of the file to read in the number of bins before
> returning to the beginning of the file to read in the actual
> data? I can do the analysis In another CAS, since there are
> functions fseek and ftell, so that once I read in the number
> of data points I can seek to the end, get the grouping count,
> then seek back to the beginning, but I'd like to be able to
> do it in Mathematica.
>
> Any suggestions?
It depends on the file's exact format, but something like
iunit = OpenRead["file"];
Find[iunit, "Here are my bins"];
bins = ReadList[iunit, Number, numberOfBins];
SetStreamPosition[iunit, 0]; (* rewind *)
data = ReadList[iunit, Number, numberOfData];
Close[iunit];
Should get you started.
However, unless there were a compelling reason, it'd be inclined to
1. read the file (idata = Import[])
2. sort out my data (data = Take[idata, {1, 1000000}] or data =
idata[[{1, 10000000}]];)
3. sort out my bins (bins = idata[[2000000, 2000000+20]])
Regards,
Dave.
- References:
- Manipulating current read position in a binary file
- From: Aranthon <a.dwarf@gmail.com>
- Manipulating current read position in a binary file