spoon <·····@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
Marco Antoniotti <·······@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/
······@clisp.cons.org (Bruno Haible) writes:
> Marco Antoniotti <·······@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.
--
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
In article <··········@news.u-bordeaux.fr>,
······@clisp.cons.org (Bruno Haible) wrote:
> Marco Antoniotti <·······@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
········@totient.demon.co.uk writes:
> In article <··········@news.u-bordeaux.fr>,
> ······@clisp.cons.org (Bruno Haible) wrote:
> > Marco Antoniotti <·······@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.
>
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.
--
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
> > 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.???
Jon
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own