;------------------------------------------------------------- ;+ ; NAME: ; GETFILE ; PURPOSE: ; Read a text file into a string array. ; CATEGORY: ; CALLING SEQUENCE: ; s = getfile(f) ; INPUTS: ; f = text file name. in ; KEYWORD PARAMETERS: ; Keywords: ; ERROR=err error flag: 0=ok, 1=file not opened, ; 2=no lines in file. ; /QUIET means give no error message. ; ; /FIND search te file in the all !path directories (use ; find.pro) ; ; OUTPUTS: ; s = string array. out ; COMMON BLOCKS: ; NOTES: ; MODIFICATION HISTORY: ; R. Sterner, 20 Mar, 1990 ; ; S. Masson (smasson@lodyc.jussieu.fr) 4 Feb 2002 ; search te file in the all !path directories (use find.pro) ; when using /find keyword. Use spawn, 'cat...' for unix os. ; ; Copyright (C) 1990, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- function getfile, filein, error=err, help=hlp, quiet=quiet, find = find if (n_params(0) lt 1) or keyword_set(hlp) then begin print,' Read a text file into a string array.' print,' s = getfile(f)' print,' f = text file name. in' print,' s = string array. out' print,' Keywords:' print,' ERROR=err error flag: 0=ok, 1=file not opened,' print,' 2=no lines in file.' print,' /QUIET means give no error message.' return, -1 endif ; if keyword_set(find) then begin file = find(filein) file = file[0] if file EQ 'NOT FOUND' then begin print, ' Error in getfile: File '+filein+' not fouond.' return, -1 endif ENDIF ELSE file = filein if !version.os_family EQ 'unix' then begin spawn, 'cat '+file, res if res[0] NE '' then return, res ELSE return, '' endif ; get_lun, lun on_ioerror, err openr, lun, file s = [' '] t = '' while not eof(lun) do begin readf, lun, t s = [s,t] endwhile close, lun free_lun, lun if n_elements(s) eq 1 then begin if not keyword_set(quiet) then print,' No lines in file.' err = 2 return,-1 endif err = 0 return, s(1:*) err: if !err eq -168 then begin if not keyword_set(quiet) then print,' Non-standard text file format.' free_lun, lun return, s(1:*) endif if not keyword_set(quiet) then print,$ ' Error in getfile: File '+file+' not opened.' free_lun, lun err = 1 return, -1 end