MathGroup Archive 2004

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

Search the Archive

Re: Reads in only part of file

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

On 10/6/04 at 4:34 AM, stevebg at (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];

>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

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

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

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

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