PDA

View Full Version : Reading Text Files for Graphing



Atomic_Sheep
21st January 2012, 14:46
I'm writing a basic program which will open a text file, read the data and plot it. The text files will have several formats of data i.e. one format will be something like this:

124 | 678 | 7890
4567 | 27487 | 5678

with varying numbers of rows and columns, and another text file will just have spaces separating the values

124 678 7890
4567 27487 5678

Firstly, how do I discern between values in a particular row? There's readLine() which will enable me to go down a list of values as I please but how do I go about specifying separation between values?

Secondly, in some cases, I'll be processing the data before plotting/graphing it. i.e. I might need to do basic mathematical operations on the values prior to spitting out final results, what would be the best method of working with potentially large volumes of data (not massive to the extent of gigabytes but possibly 20 megs or so although that's a guess). I mean, what would be an efficient way of working with it, simply use arrays? The operations will all be between values in the same row, so that simplifies it somewhat i.e. I won't be potentially accessing row 20 column 5 and multiplying it by row 1 column 239. Although I'll probably need to sort selected columns of the text document.

ChrisW67
22nd January 2012, 23:02
Try QString::split() and QRegExp (if required).

How you need to work with large volumes, 20MB of numbers expressed in ASCII is not that big, will depend on exactly what you need to do. If you need random access to cells then you have a different set of problems to those faced if you need to sort the entire file based on a column, column or a derived value.

Atomic_Sheep
25th January 2012, 21:34
Thanks for the response. Just trying to sort the data, then plot the results. The sorting is done for a reason that's long to explain for my intended application but suffice to say the calculations are really basic, although as I write this I'm starting to see some difficulties that I didn't anticipate originally.