LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fast read and write of arrays to ascii file

I am trying to write to, and then read back, an array of data to an ASCII file.  I have tried various methods over the past few weeks and I am now frustrated.  I have tried methods including the one I show in the BMP file attached and also by simply using the LV Read and Write to Measurement File.  Both methods work great but are much, much too slow.

 

Using either method takes a few seconds to write the array of values and then read them back in.  I am trying to do this in near real time (the write is much more ciritcal).  There are always the same number of data points in the array(110+points) and if I were to write this file using standard "C" I could accomplish the write in near real time.  I therefore feel that I should be able to do the same in LabView if I used the proper functions.

 

Any suggestions on speeding this up significantly? 

0 Kudos
Message 1 of 3
(6,199 Views)

Here's a basic example. I have not benchmarked it but my guess is that your calling the  Format Into File and Scan From File multiple times is where you have made the biggest mistake.

 

Write Text File.PNG

Message Edited by Dennis Knutson on 08-17-2009 09:56 AM
0 Kudos
Message 2 of 3
(6,187 Views)

Your fundamental (though not only) problem is that you are doing a file I/O operation each time you iterate through the loop. This is expensive, in any programming language. If your arrays are not large enough, then the best way to do this is to read/write out the array all at once. For this you could simply use Read From Spreadsheet File and Write to Spreadsheet File. An even faster method is to simply use binary files. This skips the formatting to string. See the shipping examples on reading/writing binary files.

 

Code comments:

  • I don't understand why you use a while loop to read and a for loop to write. You know the number of values, so a for-loop should be used. Note that for the writing you can simply use auto-indexing.
  • You do not need to use Build Array with a shift register. This is text-based programming. Use auto-indexing to automatically get an array output. 

Note that the above code comments are for the code as-is, and that you'd be better off doing it as I had mentioned in my first paragraph.
0 Kudos
Message 3 of 3
(6,183 Views)