03-01-2013 05:02 AM
Hello guys,
I'd like to learn how to write a data (which is interleaved array of double file format from up to 8 channels) to binary format.
I have the need to compare it with write to TDMS and write to Spreadsheet implementations I have so far.
Any help would be appreciated!
03-01-2013 08:48 AM
Writing data to a binary file is essentially identical to the way you are doing it for TDMS. Open the file, write the binary in a loop, close the file. These are three file primitives on the file I/O palette.
On a related note, your write to spreadsheet is very inefficient and would be somewhat confusing to read. Let's take these one at a time.
The write to spreadsheet VI opens and closes the file every time it is called. You should use the file open primitive before the loop and the file close primitive after the loop to open and close this file. You can use the array to spreadsheet string primitive (on the string palette) to convert your array to a string. Then write to disk using the file write primitive. For fastest performance, buffer your string using a shift register and only write when your string is about 65,000 characters long.
You are taking a 2D array, which you have already interleaved, and saving as a 1D array. Most spreadsheet programs don't deal with this very well. You really want a 2D array of values with one column for each data channel. You can fairly easily do this with your current data using the reshape array primitive (on the array palette) to change your 1D data to 2D data before using the array to spreadsheet string primitive.
Good luck. Let us know if you have further questions.
03-02-2013 04:35 AM
Hi DFGray!
Thanks for the insightful comments. I really appreciate they way you presented your suggestions - very clear and directive, and easy to follow for a newbie like me 🙂
I am not sitting on the test bench now so I can only reply after the weekend. Meanwhile, I will prepare the code.
Regards
03-02-2013 09:56 AM
I have one more problem though. How would I write the channel information like in TDMS write for the Binary write? I have never used this and would like to see some example already done to get my head around it 🙂
03-03-2013 08:05 PM
TDMS file format is a structured data format. However, binary is unstructored, you have to organize data with channel information all by yourself. As far as I know, there is no existing nodes in LabVIEW that can organize meta data and raw data for binary file.
03-04-2013 07:26 AM
As deppSU said, raw binary is just that. It only has in it what you put in it. However, usage is very easy (Open/Create/Replace File, Write to Binary File, Close File). In your case, you could open the file outside the loop, write in the loop, then close outside the loop. As with the text file, maximum performance will be gained (under Windows) if you buffer your data so you are writing about 65,000 bytes per write. DBLs are 8 bytes per point.
The down side is that there is no information in your file describing it. The biggest issue with this is knowing how to deinterleave it on read (your TDMS implementation has the problem too, but you can solve it there by setting an attribute or two). You can solve it by writing some header information, of your own design, into the start of the file. You may want to read up on the binary structure of TDMS, RIFF, or TIFF to get some ideas.
03-04-2013 07:44 PM
If you write channels of interleaved data using LabVIEW, TDMS Read will do the deinterleaving automatically for you when reading out.