Unformatted binary IO

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Unformatted binary IO

David Raymond

I am trying to read and write to/from files or stdout/stdin that have
an ascii header followed by unformatted float32 binary data.  (The
files are created using a C program.)  The ascii header first needs to
be parsed to understand the structure of the floating point data.  I
have solved the parsing problem, but getting the unformatted binary
float data into a series of float (or double) immutable, unboxed
vectors has defeated me so far.  The binary package doesn't help as
far as I can see, as the binary format it reads and writes has some
control information at the beginning that doesn't exist in the format
I am reading.

This is easy in C, but seems to be hard in Haskell unless I am missing
something.

Any suggestions?

--
David J. Raymond
Prof. of Physics
New Mexico Tech
http://www.physics.nmt.edu/~raymond/index.html

Reply | Threaded
Open this post in threaded view
|

Unformatted binary IO

Chaddaï Fouché
This is easy in Haskell too and binary provide everything you need. It's
not like you're _forced_ to use the Vector instance to construct a Vector
from your values, you can simply repeat (with replicateM) the get for the
Float (or Double) instance instead and build a Vector from the resulting
list (if you do it properly it will probably fuse into a tight loop anyway).

I don't understand your problem ?

On Mon, Sep 29, 2014 at 5:52 PM, David Raymond <raymond at kestrel.nmt.edu>
wrote:

>
> I am trying to read and write to/from files or stdout/stdin that have
> an ascii header followed by unformatted float32 binary data.  (The
> files are created using a C program.)  The ascii header first needs to
> be parsed to understand the structure of the floating point data.  I
> have solved the parsing problem, but getting the unformatted binary
> float data into a series of float (or double) immutable, unboxed
> vectors has defeated me so far.  The binary package doesn't help as
> far as I can see, as the binary format it reads and writes has some
> control information at the beginning that doesn't exist in the format
> I am reading.
>
> This is easy in C, but seems to be hard in Haskell unless I am missing
> something.
>
> Any suggestions?
>
> --
> David J. Raymond
> Prof. of Physics
> New Mexico Tech
> http://www.physics.nmt.edu/~raymond/index.html
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140929/b2b15fd1/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Unformatted binary IO

Brent Yorgey
In reply to this post by David Raymond
I am not sure I have quite understood your problem, but perhaps the
data-binary-ieee754 package may be of use?

-Brent


I am trying to read and write to/from files or stdout/stdin that have
an ascii header followed by unformatted float32 binary data.  (The
files are created using a C program.)  The ascii header first needs to
be parsed to understand the structure of the floating point data.  I
have solved the parsing problem, but getting the unformatted binary
float data into a series of float (or double) immutable, unboxed
vectors has defeated me so far.  The binary package doesn't help as
far as I can see, as the binary format it reads and writes has some
control information at the beginning that doesn't exist in the format
I am reading.

This is easy in C, but seems to be hard in Haskell unless I am missing
something.

Any suggestions?

--
David J. Raymond
Prof. of Physics
New Mexico Tech
http://www.physics.nmt.edu/~raymond/index.html
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140929/f9eb54c2/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Unformatted binary IO

David Raymond
Brent Yorgey writes:
 > I am not sure I have quite understood your problem, but perhaps the
 > data-binary-ieee754 package may be of use?
 >
 > -Brent

This package looks interesting.  However, I am a true Haskell beginner
and I am having a hard time figuring out how the various Binary packages
are actually used to read and write files.  Any help or pointers to
tutorials would be greatly appreciated.

Dave

--
David J. Raymond
Prof. of Physics
New Mexico Tech
http://www.physics.nmt.edu/~raymond/index.html