
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

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
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@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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
participants (3)
-
Brent Yorgey
-
Chaddaï Fouché
-
David Raymond