Re: IEEE single precision number.
- To: mathgroup at smc.vnet.net
- Subject: [mg51858] Re: [mg51782] IEEE single precision number.
- From: Yasvir Tesiram <tesiramy at omrf.ouhsc.edu>
- Date: Wed, 3 Nov 2004 01:26:32 -0500 (EST)
- References: <200411020705.CAA21601@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
G'day, If your problem is that binary files aren't being read fast enough, then have a look at, http://library.wolfram.com/infocenter/MathSource/354/ for the fast binary files package. The syntax is the same as in the standard Utilities`BinaryFiles` package. Cheers Yas On Tue, 2 Nov 2004, Vangelis Marinakis wrote: > Dear everyone, > > Looking at the internet I found this email: > > ***************************************************************** > > Hi, > > I want to convert a group/stream of Bytes to various internal > Mathematica numerical types, particularly into Real (machine precision > number). The motivation is the fast reading of binary files. > > I don't want to deal with the Std Package > Utilities`BinaryFiles`ReadBinary or Developer'BinaryImport, which do > have the conversion utilities (e.g. into Real32, etc), since they are > SLOW or otherwise clunky. > > When employing the suggested fast reading of binary files: > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > There are numerous means of reading data into Mathematica from binary > files. However, most of them are too slow. Through experience and > some newsgroup research, I've found the fast easy way: > > stream = OpenRead["Cals9", DOSTextFormat -> False]; > (* Note: this DOSTextFormat->False option is key to using > ReadList[] in binary mode; otherwise, it wants to digest text. Readin > Byte chunks, then post-format. Remarkably, the DosTextFormat option > is not mentioned/discussed anywhere in the Mathematica book or Help > Browser *) > > SetStreamPosition[stream, 78*131072]; > (* Position to desired read starting location within file...count > is in Bytes, and is index base = 0 *). > > data = ReadList[stream, Byte, 131072]; > (* Reads 131072 Bytes into linear List "data" *) > > Close[stream]; > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > > you end up with a list of Bytes. Converting it to 16-bit integers is > easy: > > data = Map[(#1[[1]] + 256*#1[[2]] & ), Partition[data, 2]]; > (* takes original Byte List "data" and makes 16-bit "words", writing > over List "data". Result is half-as-long List of words. *) > > > ...but how would one convert it to real numbers (given that every 4 > bytes comprises an IEEE single-precision number)? > > Thanks. > > franki at aerodyne.com > > ***************************************************************** > > Does anyone no the answer, because I have exactly the same problem! > > Thanks. > > Vangelis Marinakis. >
- References:
- IEEE single precision number.
- From: Vangelis Marinakis <V.Marinakis@damtp.cam.ac.uk>
- IEEE single precision number.