- Timestamp:
- 05/02/06 11:32:05 (18 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 19 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/ToBeReviewed/STRING/getfile.pro
r16 r18 15 15 ; 2=no lines in file. 16 16 ; /QUIET means give no error message. 17 ; 18 ; /FIND search te file in the all !path directories (use 19 ; find.pro) 20 ; 17 21 ; OUTPUTS: 18 22 ; s = string array. out … … 22 26 ; R. Sterner, 20 Mar, 1990 23 27 ; 24 ; S. Masson (smasson@lodyc.jussieu.fr) 13 Mar, 200028 ; S. Masson (smasson@lodyc.jussieu.fr) 4 Feb 2002 25 29 ; search te file in the all !path directories (use find.pro) 30 ; when using /find keyword. Use spawn, 'cat...' for unix os. 26 31 ; 27 32 ; Copyright (C) 1990, Johns Hopkins University/Applied Physics Laboratory … … 33 38 ;------------------------------------------------------------- 34 39 35 function getfile, filein, error=err, help=hlp, quiet=quiet 36 37 38 39 40 41 42 43 44 45 46 47 40 function getfile, filein, error=err, help=hlp, quiet=quiet, find = find 41 42 if (n_params(0) lt 1) or keyword_set(hlp) then begin 43 print,' Read a text file into a string array.' 44 print,' s = getfile(f)' 45 print,' f = text file name. in' 46 print,' s = string array. out' 47 print,' Keywords:' 48 print,' ERROR=err error flag: 0=ok, 1=file not opened,' 49 print,' 2=no lines in file.' 50 print,' /QUIET means give no error message.' 51 return, -1 52 endif 48 53 ; 49 file = find(filein) 50 file = file[0] 51 if file EQ 'NOT FOUND' then begin 52 print, ' Error in getfile: File '+filein+' not fouond.' 54 if keyword_set(find) then begin 55 file = find(filein) 56 file = file[0] 57 if file EQ 'NOT FOUND' then begin 58 print, ' Error in getfile: File '+filein+' not fouond.' 59 return, -1 60 endif 61 ENDIF ELSE file = filein 62 if !version.os_family EQ 'unix' then begin 63 spawn, 'cat '+file, res 64 if res[0] NE '' then return, res ELSE return, '' 65 endif 66 ; 67 get_lun, lun 68 on_ioerror, err 69 openr, lun, file 70 71 s = [' '] 72 t = '' 73 74 while not eof(lun) do begin 75 readf, lun, t 76 s = [s,t] 77 endwhile 78 79 close, lun 80 free_lun, lun 81 if n_elements(s) eq 1 then begin 82 if not keyword_set(quiet) then print,' No lines in file.' 83 err = 2 84 return,-1 85 endif 86 87 err = 0 88 return, s(1:*) 89 90 err: if !err eq -168 then begin 91 if not keyword_set(quiet) then print,' Non-standard text file format.' 92 free_lun, lun 93 return, s(1:*) 94 endif 95 if not keyword_set(quiet) then print,$ 96 ' Error in getfile: File '+file+' not opened.' 97 free_lun, lun 98 err = 1 53 99 return, -1 54 endif 55 56 ; 57 get_lun, lun 58 on_ioerror, err 59 openr, lun, file 60 61 s = [' '] 62 t = '' 63 64 while not eof(lun) do begin 65 readf, lun, t 66 s = [s,t] 67 endwhile 68 69 close, lun 70 free_lun, lun 71 if n_elements(s) eq 1 then begin 72 if not keyword_set(quiet) then print,' No lines in file.' 73 err = 2 74 return,-1 75 endif 76 77 err = 0 78 return, s(1:*) 79 80 err: if !err eq -168 then begin 81 if not keyword_set(quiet) then print,' Non-standard text file format.' 82 free_lun, lun 83 return, s(1:*) 84 endif 85 if not keyword_set(quiet) then print,$ 86 ' Error in getfile: File '+file+' not opened.' 87 free_lun, lun 88 err = 1 89 return, -1 90 91 end 100 101 end
Note: See TracChangeset
for help on using the changeset viewer.