I need to write a general routine to read data from files of unknown size. The files consist of an unknown number of records of comma-delimited values. The number of values in a record is not known, but all records are similar. All of the results need to be stored in an array say A(NVALS, NRECS). The number of records may be quite large (thousands), so A needs to be dynamically allocated. How can I do this?
Part 1: How to read the first record and determine the number of values in it, NVALS?
Part 2: How to read the records, each time adding the values to A? I can use the crude method of reading all the records in a loop without storing the values until EOF, just to count NRECS; then rewind, allocate A (assuming NVALS has been determined), and reread. But surely there is a more elegant or faster way?