There is no FILE_COLUMNS probably because there is no worldwide standardized way to represent columns in ASCII data files. For some data files a 'comma' indicates the end of one column and the beginning of the next, For others it might be a single blank-space char. For yet others it might be a tab character, or it might be that the 27th character on the line starts a new column. It is for this reason that IDL implemented the ASCII_TEMPLATE function that gives users a quick way to interactively create a reader for a particular ASCII data column format.
Here is some simple code that could provide FILE_COLUMNS functionality, if you know that your ASCII data files are all data (no header - though you could easily modify my code to implement that), that columns are demarcated by blank space chars or commas (and blank space chars or commas are never part of the data "payload"), and that every line (row) has the same number of column elements:
FUNCTION FILE_COLUMNS, asciiDataFile
openr, lun, asciiDataFile, /GET_LUN
testLine = ''
readf, lun, testLine ; Read the first line of the file
free_lun, lun
; Create the regular expression for finding separators
separatorList = '[ ' + string(9b) + ',]' ; Look for blank space, tab, comma
columnStarts = strsplit(testLine, separatorList, /REGEX)
return, n_elements(columnStarts)
END
James Jones
|