pro myreaddata, filename, data, skipline=skipline, numline=numline, single=single, compress=compress ;+ ; NAME: ; MYREADDATA ; ; PURPOSE: ; Read tabulated data from FILENAME text file into *one* double ; (by default, or single if SINGLE keyword is set) precision ; DATA array in a straightforward way, suitable e.g. for large ; catalogues. ; ; INPUTS: ; FILENAME - Filename containing tabulated data (STRING) ; ; OUTPUTS: ; DATA - double (by default, or single if SINGLE keyword is set) ; precision floating array containing data ; ; KEYWORDS: ; SKIPLINE - # of leading lines to skip when reading DATA from FILENAME ; NUMLINE - overall # of lines to be read into DATA from FILENAME ; SINGLE - if set, uses single rather than (default) double precision ; COMPRESS - if set, assumes input file is compressed using gzip ; ; RESTRICTIONS: ; NB : FILENAME must contain numerical data only, without any leading ; or trailing lines including data description or comments (apart from ; those skipped by using SKIPLINE) ; ; DEPENDENCIES: ; NB : !!! Works with IDL >= 5.6 only !!! ; ; HISTORY: ; 27 Oct 2004 Written by Mattia Vaccari ; 05 Nov 2004 Debugging (Mattia Vaccari) ; 09 Nov 2004 Debugging (Mattia Vaccari) ; 11 Nov 2004 Debugging (Mattia Vaccari) ; 14 Sep 2005 FREE_LUN,LUN added (Mattia Vaccari) ; 06 Mar 2006 Missing FREE_LUN,LUN added (Mattia Vaccari) ; 15 May 2006 NUMLIME keyword added (Mattia Vaccari) ; 15 Jan 2007 on_error,2 added (Mattia Vaccari) ; 06 Dec 2007 SINGLE keyword added (Mattia Vaccari) ; 31 Oct 2009 COMPRESS keyword added (Mattia Vaccari) ;- on_error,2 if n_params() lt 2 then begin $ print,'Calling Sequence : myreaddata, filename, data, [skipline=skipline, numline=numline]' &$ return &$ endif res=findfile(filename) if strlen(res) eq 0 then begin $ print,'File ',filename,' not found! Returning...' &$ return &$ endif ; if not(keyword_set(delimiter)) then delimiter=' ' else delimiter=strcompress(delimiter) if not(keyword_set(skipline)) then skipline=0 if keyword_set(numline) then rows=numline else rows=long(file_lines(filename))-skipline aux='' openr,lun,filename,/get_lun,compress=compress skip_lun,lun,skipline,/lines readf,lun,aux,format='(a5000)' close,lun & free_lun,lun aux=strtrim(strcompress(aux),2) aux2=strarr(strlen(aux)) for i=0,n_elements(aux2)-1 do begin $ aux2[i]=strmid(aux,i,1) &$ endfor columns=n_elements(where(aux2 eq ' '))+1 if not(keyword_set(single)) then data=dblarr(columns,rows) else data=fltarr(columns,rows) openr,lun,filename,/get_lun,compress=compress skip_lun,lun,skipline,/lines readf,lun,data close,lun & free_lun,lun end