Changeset 18 for trunk/ToBeReviewed


Ignore:
Timestamp:
05/02/06 11:32:05 (18 years ago)
Author:
pinsard
Message:

upgrade of STRING according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/ : files

Location:
trunk/ToBeReviewed/STRING
Files:
19 copied

Legend:

Unmodified
Added
Removed
  • trunk/ToBeReviewed/STRING/getfile.pro

    r16 r18  
    1515;           2=no lines in file. 
    1616;         /QUIET means give no error message. 
     17; 
     18;         /FIND search te file in the all !path directories (use 
     19;         find.pro) 
     20; 
    1721; OUTPUTS: 
    1822;       s = string array.        out 
     
    2226;       R. Sterner, 20 Mar, 1990 
    2327; 
    24 ;       S. Masson (smasson@lodyc.jussieu.fr) 13 Mar, 2000 
     28;       S. Masson (smasson@lodyc.jussieu.fr) 4 Feb 2002 
    2529;       search te file in the all !path directories (use find.pro) 
     30;       when using /find keyword. Use spawn, 'cat...' for unix os. 
    2631; 
    2732; Copyright (C) 1990, Johns Hopkins University/Applied Physics Laboratory 
     
    3338;------------------------------------------------------------- 
    3439  
    35         function getfile, filein, error=err, help=hlp, quiet=quiet 
    36   
    37         if (n_params(0) lt 1) or keyword_set(hlp) then begin 
    38           print,' Read a text file into a string array.' 
    39           print,' s = getfile(f)' 
    40           print,'   f = text file name.      in' 
    41           print,'   s = string array.        out' 
    42           print,' Keywords:' 
    43           print,'   ERROR=err  error flag: 0=ok, 1=file not opened,' 
    44           print,'     2=no lines in file.' 
    45           print,'   /QUIET means give no error message.' 
    46           return, -1 
    47         endif 
     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 
    4853; 
    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 
    5399           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.