Message-ID: <324B1021.4C8F@mail.amsinc.com>
Date: Thu, 26 Sep 1996 16:22:09 -0700
From: Tom Hawker <tom_hawker@mail.amsinc.com>
Organization: AMS, Incorporated
X-Mailer: Mozilla 2.02 (Win16; I)
MIME-Version: 1.0
Newsgroups: comp.lang.smalltalk
Subject: Re: reading Double values from binary file in VW2.5
References: <324AA938.375A@rt.el.utwente.nl>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: thawker.amsinc.com
Lines: 27
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!news.mathworks.com!uunet!in3.uu.net!dns.amsinc.com!

P.B.T.Weustink wrote:
> 
> Hello,
> 
> Does anybody know how to read a binary file of double values that is
> created in C, each double value is 8 bytes long.
> I would like to create an Array of Double objects in VW2.5

OK, here's the basics.

I am assuming that the machine that created this file is the same (at
least in architecture) as the machine from which you are running VW.
Then, do the following:

	| stream floats |
	floats := (Array new: 100) writeStream.
	(stream := 'yourfile.bin' asFilename readStream) binary.
	Stream incompleteNextCountSignal
		handle: [:ex | ex return]
		do:
			[[[stream atEnd]
				whileFalse:
					[| bytes |
					bytes := stream next: 8.
					bytes changeClassToThatOf: 0.0d.
					floats nextPut: bytes]]
				valueNowOrOnUnwindDo: [stream close]].
	^floats contents

Hope this helps.  I'm pretty sure it will work.

Tom Hawker
