pro genread,fname,numcol,xcol,ycol,a,b, count=count, info=info,numLines=numLines, $ double=double ;generic ascii file reader. ;usage ;genread, filename, numberOfColumnsTotal, columnNumberOfVariableA, columnNumberOfVariableB, A,B ; ;set the double keyword to read everything in double. ;set info keyword to print out number of lines. ;pass in numLines keyword to the number of lines in a file to skip the part where this counts lines (saves time) ;count keyword is the number of lines read. if file_test(fname) ne 1 then return if not keyword_set(numLines) then begin numLines = 0L line = '' openr,lun,/get,fname while not eof(lun) do begin readf,lun,line numLines++ endwhile free_lun,lun endif if keyword_set(double) then begin temp = dblarr(numcol) xvar=dblarr(numLines) yvar=dblarr(numLines) endif else begin temp = fltarr(numcol) xvar=fltarr(numLines) yvar=fltarr(numLines) endelse count = 0L on_ioerror, jump1 if file_test(fname) eq 0 then begin message,'file not found' return endif openr,lun,fname,/get_lun jump1: while (not eof(lun)) do begin readf,lun,temp xvar[count] = temp[xcol-1] yvar[count] = temp[ycol-1] count = count + 1 endwhile free_lun,lun if keyword_set(info) then print, 'number of data values : ',count a = temporary(xvar[0:count-1]) b = temporary(yvar[0:count-1]) return END