Dear Andrew,
There is a way to count the number of columns. The algorithm will be to read in the first line of data and then use STRSPLIT and then to count the number of elements created by STRSPLIT. The following example ilustrate this algorithm:
pro counting_columns
file='countingcolumns.dat'
openr, lun, file, /get_lun
nlines=File_Lines(file)
; Read the first line and parse it into column units.
line=""
ReadF, lun, line
ncolumns = N_Elements(STRSPLIT(line, /RegEx, /EXTRACT))
print, ncolumns
data=lonarr(ncolumns,nlines)
;Rewind the data file to its start reading the data into the array 'data'.
Point_Lun, lun, 0
;Read the data.
ReadF, lun, data
plot, data(0,*), data(1,*)
Free_Lun, lun
end
The rewind line in the code is there to assure that you will start to read the file from the beginning when you are ready to put the data into an array. In my case the input file is an example of and ASCII file composed of 3 columns and 5 lines.
I hope this helped.
|