LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I retrieve binary cluster data from a file without the presense of the cluster size in the data?

Hey guys,  I'm trying to read a binary data file created by a C++ program that didn't append sizes to the structures that were used when writing out the data.  I know the format of the structures and have created a cluster typedef in LabView.  However the unflatten from string function expects to see additional bytes of data identifying the size of the cluster in the file.   This just plain bites!  I need to retrieve this data and have it formatted correctly without doing it manually for each and every single element.  Please Help!


Message Edited by AndyP123 on 06-04-2008 11:42 AM
0 Kudos
Message 1 of 9
(3,801 Views)

I think you can read the data as a string then use the Flattened String to Variant data using the type string input to specify exactly how the data will be read.

Check out the following from LabVIEW help:

  • Type Descriptors
  • Flattened String to Variant

And there is an example at:

  • LabVIEWX.X\examples\general\functions\Cluster & Variant\Flattened String to-from Variant.vi

at least in 8.5.

Edit: Just read the last part of your message, and this would require setting the information for all the elements.. Sorry 😞

 



Message Edited by StevenD on 06-04-2008 12:12 PM
0 Kudos
Message 2 of 9
(3,784 Views)
Small update.  I have fixed size arrays in the clusters of data in the file and I have been using arrays in my typedefs in LabView and just defining x number of indexes in the arrays and setting them as the default value under Data Operations.  LabView may maintain the default values, but it still treats an array as an unknown size data type.  This is what causes LabView to expect the cluster size to be appended to the file contents during an unflatten.  I can circumvent this in the most simplest of cases by using clusters of the same type of data in LabView to represent a fixed size array in the file.  However, I can't go around using clusters of data to represent fixed size arrays BECAUSE I have several multi-dimentional arrays of data in the file.  To represent that as a cluster I would have to add a single value for every element to such a cluster and make sure they are lined up sequentially according to every dimension of the array.  That gets mighty hairy, mighty fast. 


EDIT:  Didn't see that other reply before I went and slapped this in here.  I'll try that trick and let you know how it works.......


Message Edited by AndyP123 on 06-04-2008 12:11 PM
0 Kudos
Message 3 of 9
(3,783 Views)
Ok, it looks like this won't be happening for me.  The suggestion about variant data is ok, so long as you know how to interpret the type descriptors.  However, it still includes length data when you are using arrays and you can't convert the data without said length.  It looks like the hard way for me now..............
0 Kudos
Message 4 of 9
(3,761 Views)
The size of the array has to be determined in some way. I do not know much about C++, but LV dynamically allocates space for arrays which is why the size is stored in the flattened strings. You indicate that the file contains fixed size arrays. Therefore you know the array size. Can you insert into the data read from the file the size bytes before feeding it to the unflatten from string? This should be a simple split string and concatenate string operation.

Lynn
0 Kudos
Message 5 of 9
(3,730 Views)
Lynn, I'd have to know where to put the size information.  I think I figured out that it is a 32bit integer but I don't know if it is signed or unsigned, nor where it occurs in the flattened string.  I also wish to avoid having to figure out/interpret that LabView type identifier stuff so I hope that isn't required.  It just gives me a headache trying to interpret the very incomplete and partially incorrect LabView help files regarding how to create or read type identifiers. 
0 Kudos
Message 6 of 9
(3,714 Views)
Andy,

I think that information is published somewhere.

But there may be an easier way. Create (in LV) an array with the same number of elements and the same datatype as the array in the file. Flatten that and look at the resulting string. Make sure that none of the element values is the same as the length of the array to minimize your confusion. Perhaps try it with a few different values, both as array elements and number of elements to be sure you have interpreted it correctly.

Do you know exactly what values are in your file? Or can you create one from the other program with known values so you can test your decoding?

Lynn
0 Kudos
Message 7 of 9
(3,711 Views)
I got it working!  I did the feeding of a constant array into the flatten to string vi and observed the output string in hex code.  It places a 32bit signed integer in front of the array and multiple such integers in front of a multi-dimensional array.  This will take a little more time than I first thought (I initially wanted to flatten a bunch of typedefs and take the string length of the result to figure out how much to read out of the file).   But, it won't be as long as reading each piece individually.  Thanks Lynn.
0 Kudos
Message 8 of 9
(3,704 Views)
Glad you got it working.

Lynn
0 Kudos
Message 9 of 9
(3,681 Views)