12-21-2010 03:48 PM
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
12-21-2010 03:56 PM
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.
12-21-2010 03:57 PM - edited 12-21-2010 03:59 PM
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:
(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.)
12-21-2010 04:19 PM
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?
07-17-2012 09:39 AM
I've spent the afternoon trying to solve the excactly same problem
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.
07-17-2012 10:19 AM
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.