function read_txt_file,file,nx,ny,nhed ;----------------------------------------------------------------------------------------- ; Generic ascii file reader ; ; Input: ; file.....file name ; nx.......# of columns in the data section ; ny.......# of rows in the data section, ; if ny < 0 then the routine will read an unlimited number of rows ; nhed.....# of header lines to read, before starting on the data, these are ignored ; ; Output: ; data....fltarr(nx,ny) of the file contents ; ; Source: Mark Hervig, GATS ;----------------------------------------------------------------------------------------- ;- open the file, read the header lines openr,lu,file,/get_lun head = ' ' if (nhed gt 0) then for i = 1,nhed do readf,lu,head ;- data is a block of known size (nx,ny) if (ny gt 0) then begin if nx gt 1 then data = fltarr(nx,ny) if nx eq 1 then data = fltarr(ny) ; one big column readf,lu,data endif ;- unlimited # of rows if (ny le 0) then begin dat = fltarr( nx ) i = 0 while (not eof(lu)) do begin readf,lu,dat if (i gt 0) then data = [ [data],[dat] ] if (i eq 0) then data = dat i = i + 1 endwhile endif close,lu & free_lun,lu return,data end