LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading binary file of same data type

  I am writing 2D array of numeric data(DBL) in binary file and reading the same binary file but i am geeting an error message like unflatten or byte stream read operation failed due to corrupt, Unexpected or truncated data. Can any pls clarify about this .
0 Kudos
Message 1 of 9
(3,817 Views)
Could you post the vis and also a datafile?
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 9
(3,809 Views)
If you just write an array (of whatever dimension) of numerics to a binary file, it loses the information of array dimension. The file then consists of a stream of individual numeric values. Either you store the dimension sizes separately, read the data stream as a 1D- array and reshape  the array to the appropriate dimension sizes or you flatten the array to string, save the string to binary file and unflatten the string after reading the file. Then the dimension sizes will be recovered automaticaly.
Hope this helps,
greets, Dave
Greets, Dave
0 Kudos
Message 3 of 9
(3,805 Views)
 OK ..so it looses the information of array dimensions but i didnt get how to store the array dimensions seperatetly while writing the datas into binary format .i am attaching my Binary Write VI along with this.
0 Kudos
Message 4 of 9
(3,797 Views)
When using the "Read from Binary File"-function - did you wire the datatype?
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 5 of 9
(3,794 Views)
    Yes, I have connected the datatype also even though i am getting the error and i willl attach the read VI also.
0 Kudos
Message 6 of 9
(3,790 Views)
In the Binary read.vi you open the file to write.
 
Have a look at the picture.
 

Message Edited by becktho on 07-04-2007 02:21 PM

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 7 of 9
(3,788 Views)
As you can see, the size information of the stored array is also saved in the file, this is because you wired the "prepend array size" input with a TRUE. In the attached example VI "Write  Binary data (2D DBL).vi" you can create a file, where a little 2D array is stored (once or twice). Then you can read it with "Binary Read-1.vi" back, that the size information is restored.


This is the BD of the Write- VI



In the HEX- dump of the binary file you can see that the first for bytes hold the Y-size of the first array written, then comes the X-size, then the dbl-values. After the first array comes the size information of the second array, then the values itself.
greets, Dave

Message Edited by daveTW on 07-04-2007 02:50 PM

Greets, Dave
0 Kudos
Message 8 of 9
(3,783 Views)
I am using the function Writebinaryfile without prepending array size in a whileloop structure for multitime writing, and using for reshaping the function Decimate1Darray to recovered the original numric data. I found it pretty much flexible.
0 Kudos
Message 9 of 9
(3,777 Views)