Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading Binary doubles

3 views
Skip to first unread message

Marco Antoniotti

unread,
Oct 18, 1998, 3:00:00 AM10/18/98
to

spoon <sp...@hilbert.maths.utas.edu.au> writes:

> Hi,
> Forgetting for the moment endian issues, given a binary file
> of doubles, what is the best way to read the file into (common) lisp?
> Is there any way to open a bindary stream of doubles?
>

(READ-SEQUENCE (make-array N :element-type 'double-float
:initial-element 0.0d0)
stream)


--
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - (0)6 - 68 10 03 16, fax. +39 - (0)6 - 68 80 79 26
http://www.parades.rm.cnr.it

Bruno Haible

unread,
Oct 20, 1998, 3:00:00 AM10/20/98
to
Marco Antoniotti <mar...@galvani.parades.rm.cnr.it> wrote:
>
>> given a binary file of doubles, what is the best way to read the file
>> into (common) lisp? Is there any way to open a binary stream of doubles?

>
> (READ-SEQUENCE (make-array N :element-type 'double-float
> :initial-element 0.0d0)
> stream)

This might work in a particular implementation. It is not guaranteed to
be portable according to ANSI CL, however.

The reason is, (upgraded-array-element-type 'double-float) might be t;
thus, `read-sequence' could not even know that you want double-floats.
And I always thought `read-sequence' would fill the sequence with characters
or integers, according to the stream's element type.

Btw, what is `read-sequence' expected to do when the stream's element type
is (or (UNSIGNED-BYTE 8) CHARACTER) ? (Pipe or socket streams can be such
beasts.)

Bruno http://clisp.cons.org/~haible/


Marco Antoniotti

unread,
Oct 21, 1998, 3:00:00 AM10/21/98
to

hai...@clisp.cons.org (Bruno Haible) writes:

> Marco Antoniotti <mar...@galvani.parades.rm.cnr.it> wrote:
> >
> >> given a binary file of doubles, what is the best way to read the file
> >> into (common) lisp? Is there any way to open a binary stream of doubles?
> >
> > (READ-SEQUENCE (make-array N :element-type 'double-float
> > :initial-element 0.0d0)
> > stream)
>
> This might work in a particular implementation. It is not guaranteed to
> be portable according to ANSI CL, however.
>
> The reason is, (upgraded-array-element-type 'double-float) might be t;
> thus, `read-sequence' could not even know that you want double-floats.
> And I always thought `read-sequence' would fill the sequence with characters
> or integers, according to the stream's element type.
>

As a matter of fact you should do careful cross check of the
upgraded-array-element-type and of the stream element-type. In CMUCL

* (upgraded-array-element-type 'double-float)
DOUBLE-FLOAT
*

so you are home safe.


> Btw, what is `read-sequence' expected to do when the stream's element type
> is (or (UNSIGNED-BYTE 8) CHARACTER) ? (Pipe or socket streams can be such
> beasts.)
>

This is more interesting. However, why should you define the stream
type to be of such strange type? I'd define a socket stream element
type to be (UNSIGNED-BYTE 8). I think this is more precise in Common
Lisp terms.

jon....@totient.demon.co.uk

unread,
Oct 21, 1998, 3:00:00 AM10/21/98
to
In article <70j6k5$1...@news.u-bordeaux.fr>,

hai...@clisp.cons.org (Bruno Haible) wrote:
> Marco Antoniotti <mar...@galvani.parades.rm.cnr.it> wrote:
> >
> >> given a binary file of doubles, what is the best way to read the file
> >> into (common) lisp? Is there any way to open a binary stream of doubles?
> >
> > (READ-SEQUENCE (make-array N :element-type 'double-float
> > :initial-element 0.0d0)
> > stream)
>
> This might work in a particular implementation. It is not guaranteed to
> be portable according to ANSI CL, however.
>
> The reason is, (upgraded-array-element-type 'double-float) might be t;
> thus, `read-sequence' could not even know that you want double-floats.
> And I always thought `read-sequence' would fill the sequence with characters
> or integers, according to the stream's element type.
>
> Btw, what is `read-sequence' expected to do when the stream's element type
> is (or (UNSIGNED-BYTE 8) CHARACTER) ? (Pipe or socket streams can be such
> beasts.)
>
> Bruno http://clisp.cons.org/~haible/
>
>


I have tried the read-sequence code above, after producing a file using
write sequence. I have not discovered how you are meant to write out and
read back a binary doubles. The Cl standard seems to suggest this is not
possible, in a portable manner.

Jon

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Marco Antoniotti

unread,
Oct 22, 1998, 3:00:00 AM10/22/98
to

jon....@totient.demon.co.uk writes:

What CL implementation are you using?

In CMUCL it is possible (alas with an experimental version) to do. It
is very important to declare the stream-element-type to
double-float. Of course, you milaege may vary.

jon....@totient.demon.co.uk

unread,
Oct 22, 1998, 3:00:00 AM10/22/98
to

> > I have tried the read-sequence code above, after producing a file using
> > write sequence. I have not discovered how you are meant to write out and
> > read back a binary doubles. The Cl standard seems to suggest this is not
> > possible, in a portable manner.
> >
>
> What CL implementation are you using?
>
> In CMUCL it is possible (alas with an experimental version) to do. It
> is very important to declare the stream-element-type to
> double-float. Of course, you milaege may vary.
>
> --

I have tried this in CMUCL 18b on Solaris and Acl5.0 beta on linux.
Neither seem to allow the stream's element-type to be double-float.

Why is this not allowed.???

0 new messages