Re: BinaryIO
- To: mathgroup at smc.vnet.net
- Subject: [mg57827] Re: BinaryIO
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Thu, 9 Jun 2005 05:18:42 -0400 (EDT)
- References: <d86b4j$dgs$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Marko Kastens wrote: > Hi, > > I have just updated to Mathematica 5.1.1.0 and trying the new BinaryIO-Commands to > increase the IO speed. But ... here is something strange: > > > n = 1000000; > TSout = Table[{FromDate[{2000, 1, 1, 0, 0, 0}] + i, Random[]}, {i, n}]; > BinaryWrite["binTS.dat", TSout, {"Real64", "Real64"}]; // Timing > TSin = BinaryReadList["binTS.dat", {"Real64", "Real64"}]; // Timing > TSout == TSin > > > Evaluating these lines with a fresh kernel: everything is ok. Evaluate them a > second time and TSout==TSin produce a _False_. Restarting the kernel: > everything is ok. > Every time I (try to) overwrite the file _binTS.dat_ I got a False. It seems to > me that the routine is not able to overwrite files. > > Hmmm, any suggestions? > > marko > The problem with using BinaryWrite (or indeed Write) with a file name as its first argument is that there is no clear concept of closing the files. Create a stream strout=OpenWrite["binTS.dat",BinaryFormat->True] Then you can use that as the argument to BinaryWrite. After that, use Close to close the stream and re-open the file with OpenRead[binTS.dat",BinaryFormat->True] to read it back. Finally, close it again. This is a little bit more work, but Mathematica knows exactly what you want it to do with the files. David Bailey http://www.dbaileyconsultancy.co.uk