LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write arrays into a text file in different columns at different times

Hi,

 

          I have a problem write data into a text file. I want to write 4 1D arrays into a text file. The problem is that I need to write it at different time and in different column (in other word, not only append the arrays).

 

Do you have an idea to solve my problem?

 

Thank you

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

Nope! Unless you pad the space in the file for future columns.

You can write to a file a line at a time, but not a column at a time.

 

If you are writing Col 1 then Col 2 then Col 3 and so on. Transpose the array and make your columns rows and the rows columns.

 

 

 

Omar
0 Kudos
Message 2 of 6
(4,932 Views)

A file is long a linear string of data (text). In order ro insert columns, you need to rewrite the entire file, because colums are interlaced over the entire lenght of the file.

 

So:

 

  1. read file into 2D array
  2. insert columns using array operations
  3. write resulting 2D array to file again.

 

 

 

(Only if your colums are guaranteed to be fixed width AND you know the final number of colums, you could write the missing columns as spaces and then overwrite later. Still, it will be painful and inefficient, because column data are not adjacent in the file.)

Message 3 of 6
(4,931 Views)

Solution: wait until you have all the data then write it all at once.

 

If they are very large data sets that you don't want floating around in memory then there are some things you can do. How big are the arrays?

Message 4 of 6
(4,914 Views)

I've spent the afternoon trying to solve the excactly same problem Cat Mad

 

My 2d array could get to a maximum of 3000 x 2048 dbls.

In common only one of these monsters, but i would also have the option to take up to eight measurements at the same time.

0 Kudos
Message 5 of 6
(4,600 Views)

Maybe you could write into 4 separate files per each 1D array, then merge them into one file at the end. This way you can reduce the memory usage during data acquistion. You still need to rewrite the entire file when you are inserting a data though. Just a thought.

0 Kudos
Message 6 of 6
(4,589 Views)