MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Reads in only part of file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51188] Re: Reads in only part of file
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Thu, 7 Oct 2004 05:26:25 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 10/6/04 at 4:34 AM, stevebg at adelphia.net (Steve Gray) wrote:

>I have a binary file of 945 coordinates, in X,Y pairs, each value
>being 8 bits, for 1890 bytes total. I have examined the file with a
>hex file display and editor (which shows the file as 2 hex
>characters per byte) and confirms that the file contains exactly
>the expected number of bytes. My input process is:

>roswin[nv_]:=  Module[{st1}, 
>nverts = nv; st1="D:\Math\Geometry\Combinatorial
>Geom\Oswin\Otypes\otypes07.b08"; Print["Reading file: ",st1];
>xin=ReadList[st1,{Byte,Byte}];
>]

>The file opens ok but the input list xin contains only 230
>coordinate pairs (byte pairs) instead of 945. The values that do
>read in are correct. The {Byte,Byte} seems to be the only data type
>that works here. Can anyone suggest what I am doing wrong? (Do I
>have to Close st1?) Thank you for any tips.

I suggest either ReadListBinary in the package Utilities`BinaryFiles` or BinaryImport in the Experimental context. With ReadListBinary your code could become

<<Utilities`BinaryFiles`;
roswin[nv_]:=  Module[{st1}, 
         nverts = nv; 
         st1="D:\Math\Geometry\Combinatorial Geom\Oswin\Otypes\otypes07.b08";
         Print["Reading file: ",st1];
         xin=ReadListBinary[st1,{Byte,Byte}];
    ]

However, I would change the code to be as follows:

roswin[st1_]:= Module[{}, 
         Print["Reading file: ",st1];
         ReadListBinary[st1,{Byte,Byte}]
    ]

Passing the filename allows the function to be used for any file unlike hard coding the filename as part of the function. Also, my experience indicates manipulating global variables inside a module or function leads to greater difficulties debugging code or modifying those functions/modules later.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: recover a value in module at the end
  • Next by Date: Re: Thichness of Plot does not change Solved
  • Previous by thread: Re: Reads in only part of file
  • Next by thread: Re: Reads in only part of file