PRO rdcols,file,length,rowvec1,rowvec2,rowvec3,rowvec4,rowvec5 ; ; This procedure reads a general ASCII file of (x,y) data points, ; of arbitrary length. If the length of the file is specified at the ; top, everything is easy. If not, the procedure reads the file in ; row by row, checking after each row to see if EOF has been reached. ; The data structure is created by concatenating each (transposed) ; row to the previous (transposed) rows to create an nx2 array. When ; the file has been completely read, the length of the array and the ; two rows in the nx2 array are returned. ; ; Modified 1993/5/12 by DPS to handle data files with more than 2 ; entries per line. If extra entries exist, they are returned in ; rowvec3, 4, and 5, otherwise these vectors are returned full of ; zeroes. ; r=n_lines(file) IF r LE 0 THEN BEGIN MESSAGE,'File contains no data',/INFORMATIONAL length=0 rowvec1=[0] rowvec2=[0] RETURN ENDIF rdfile,file,1,1,s s=s(0) c=nwrds(s) IF c EQ 2 THEN BEGIN p0=FLOAT(getwrd(s,0)) p1=FLOAT(getwrd(s,1)) dimfirst=((p0 EQ r-1) OR (p1 EQ r-1)) ENDIF ELSE dimfirst=0B OPENR,unit,file,/GET_LUN IF dimfirst THEN BEGIN r=r-1 IF r EQ p0 THEN c=p1 ELSE c=p0 READF,unit,s ; skip the line containing the dimensions ENDIF d=FLTARR(c,r) READF,unit,d CLOSE,unit FREE_LUN,unit d=TRANSPOSE(d) rowvec1=d(*,0) & rowvec2=d(*,1) length=r IF c GE 3 THEN rowvec3=d(*,2) IF c GE 4 THEN rowvec4=d(*,3) IF c GE 5 THEN rowvec5=d(*,4) RETURN END