LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How does flatten to string work with arrays?

Hi all,
I'm currently trying to get my head around how flatten to string works in terms of using it to write a configuration file which is loaded on startup in my VI. Writing and loading the configuration file is no problem and it is working beautifully. However... this is for a data acquisition system and the configuration file stores all the calibration data in the system which is entered through arrays. Anyway, the data recorded by my VI is to be post processed using MATLAB and needs to apply the calibration data stored in the configuration file.

So I've been trying to work out how to get MATLAB to decypher the configuration file, but... I can't make heads or tails as to how the data is written into the file. I made a mock up of the saving file routine as you can see below, and run it a number of times by changing the input array dimensions and the values.



Then opened the saved file to see if I can find a pattern... but I can't! Simply changing the element values changes the number of "\   \'s" Here is what I produced from my trials:

[1x1 0]
Config=\00\00\00\01\00\00\00\00\00\00\00\00      (1x1 array of 0's)
[1x1 1]
Config=\00\00\00\01?ð\00\00\00\00\00\00            (1x1 array of 1's)
[1x1 2]
Config=\00\00\00\01@\00\00\00\00\00\00\00       (1x1 array of 2's)
[1x2 0]
Config=\00\00\00\02\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00      (1x2 array of 0's)
[1x2 1]
Config=\00\00\00\02?ð\00\00\00\00\00\00?ð\00\00\00\00\00\00                  (1x2 array of 1's)
[1x2 2]
Config=\00\00\00\02?ð\00\00\00\00\00\00?ð\00\00\00\00\00\00                  (1x2 array of 2's) etc. etc. etc
[2x2 0]
Config=\00\00\00\02\00\00\00\02\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00     
[2x2 1]
Config=\00\00\00\02\00\00\00\02?ð\00\00\00\00\00\00?ð\00\00\00\00\00\00?ð\00\00\00\00\00\00?ð\00\00\00\00\00\00
[2x2 2]
Config=\00\00\00\02\00\00\00\02@\00\00\00\00\00\00\00@\00\00\00\00\00\00\00@\00\00\00\00\00\00\00@\00\00\00\00\00\00\00

Could someone explain to me how flatten to string flattens the array information? Particularly when the array elements are double precision? I look forward to any help that anyone can offer!
Thanks,
Stirling

Message Edited by stirlsilver on 09-08-2007 08:47 AM

0 Kudos
Message 1 of 6
(4,353 Views)

See this link for more information:

http://zone.ni.com/reference/en-XX/help/371361B-01/lvconcepts/flattened_data/

Everything looks reasonable to me.  Your values are changing (e.g. @\00\00\00\00\00\00\00 represents a double precision value).  For a 1-D array, the first four bytes are the dimension size.  For a 2-D, the first 8 bytes are the two 4-byte dimension sizes, etc.

 

0 Kudos
Message 2 of 6
(4,342 Views)
There are optional inputs to "flatten to string" That you can use to modify the outcome as needed. For example you can do little endian.
 
You can also omit the array size from the flattened data (definitely not recommended for 2D arrays). 😉
 
0 Kudos
Message 3 of 6
(4,334 Views)
I would suggest simply using something like the Write to Spreadsheet File VI to save the numbers as strings. True, this would mean that you can not use the configuration file option and that you would need another file (or that you would have to replace the CRLFs with another character), but you can open these using any program from Notepad to Excel.

___________________
Try to take over the world!
Message 4 of 6
(4,322 Views)
Thanks for your replys,
I had forgotten about the write to spreadsheet file and it makes my life a whole lot easier!! I just implemented it then and it will be very straight forward to read it with the code. Thanks!!
0 Kudos
Message 5 of 6
(4,309 Views)
Make sure you save as many digits as you need in the text file.  You can set this using the format input.  The default is good enough for most work, but is only about 1/3 the resolution of a double.
0 Kudos
Message 6 of 6
(4,259 Views)