source: trunk/SRC/Utilities/find.pro @ 238

Last change on this file since 238 was 238, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:keywords set to Id
File size: 6.8 KB
RevLine 
[2]1;+
[232]2;
[128]3; @file_comments
[232]4; based on <proidl>file_search</proidl>, but it is possible to specify
[128]5; a set of possibles names and a different set of
6; possibles directories names.
7; By default look for files included in !path
[2]8;
[128]9; all file_search keywords can be used.
10;
[238]11; @categories
[224]12; find a file
[2]13;
[238]14; @param FILEIN {in}{required}
[136]15; A scalar or array variable of string type, containing
16; file names to match. Input names specifications may contain
17; wildcard characters, enabling them to match multiple files
18; (see file_search for more informations). By default and if
19; necessary, find is looking for filename and also for filename
20; completed with '.pro'
[2]21;
[238]22; @keyword FIRSTFOUND
[136]23; activate this keyword to stop looking for the file as soon as we found one.
[77]24;
[238]25; @keyword IODIRECTORY {default=['.',!path]}
[136]26; A scalar or array variable of string type, containing
27; directories names where we are looking for the file.
28; Different directories can be separated by
29; path_sep(/search_path) (':' on unix type machine) as it is done
30; to define !path.
31; Note that if filename's dirname is different from '.', this
32; keyword is not taken into account.
[2]33;
[238]34; @keyword LOOKALLDIR
[152]35; activate to look for the file (with a recursive search if needed)
36; in . iodir, homedir, !path + the DATA:TestsData directory if it exists.
[2]37;
[238]38; @keyword NOPRO
[136]39; activate to avoid the automatic search of filename completed with '.pro'
[77]40;
[238]41; @keyword ONLYPRO
[136]42; force to look only at file ending with .pro
[77]43;
[238]44; @keyword ONLYNC
[136]45; force to look only at file ending with .nc
[77]46;
[238]47; @keyword RECURSIVE
[136]48; performs recursive searching of directory hierarchies.
49; In a recursive search, find looks recursively for any and all
50; subdirectories in the file hierarchy rooted at the IODIRECTORY argument.
[11]51;
[238]52; @keyword REPERTOIRE
[136]53; obsolete. keep for compatibility, use directory keyword
[11]54;
[238]55; @keyword UNIQUE
[136]56; activate to make sure that each element of the output vector is unique.
[11]57;
[238]58; @keyword TRYFIND
[152]59; if the file was not found and this keyword is activated, find will call
60; itself with the keywords /LOOKALLDIR and /FIRSTFOUND to try to find
61; the file we are looking for. Note that if the file was found at the
[238]62; first try this keyword as no effect (which is not the case with LOOKALLDIR)
[152]63;
[238]64; @keyword _EXTRA
[231]65; Used to pass keywords
[118]66;
[238]67; @returns
[136]68; A scalar or array variable of string type, containing the
69; name (with the full path of the matching files. If no files
70; exist with names matching the input arguments, find returns
71; the scalar string : 'NOT FOUND'
[11]72;
[128]73; @examples
[2]74;
[128]75; IDL> print, find('*loadct')
[11]76;   /usr/local/rsi/idl_6.0/lib/utilities/xloadct.pro
77;   /usr/local/rsi/idl_6.0/lib/loadct.pro
[128]78; IDL> print, find('*loadct', iodir=!dir,/recursive)
[11]79;   /usr/local/rsi/idl_6.0/lib/loadct.pro
80;   /usr/local/rsi/idl_6.0/lib/utilities/xloadct.pro
[128]81; IDL> print, find('*loadct.pro')
[11]82;   /usr/local/rsi/idl_6.0/lib/utilities/xloadct.pro
83;   /usr/local/rsi/idl_6.0/lib/loadct.pro
[128]84; IDL> print, find('*loadct',/nopro)
[11]85;   NOT FOUND
[128]86; IDL> print, find('*loadct', iodir = '/usr/local/rsi/idl_6.0/lib')
[11]87;   /usr/local/rsi/idl_6.0/lib/loadct.pro
[128]88; IDL> print, find('*loadct', iodir = '/usr/local/rsi/idl_6.0/lib', /test_write)
[11]89;   NOT FOUND
[128]90; IDL> print, find('*loadct', iodir = '/usr/local/rsi/idl_6.0/lib', /recursive)
[11]91;   /usr/local/rsi/idl_6.0/lib/loadct.pro
92;   /usr/local/rsi/idl_6.0/lib/utilities/xloadct.pro
[128]93; IDL> print, find('mesh*', iodirectory = [iodir, !path])
[11]94;   /Users/sebastie/DATA/ORCA2/meshmaskORCA2closea.nc
95;   /Users/sebastie/IDL/meshmaskclosesea.pro
96;   /Users/sebastie/IDL/meshmaskclosesea.pro~
97;   /Users/sebastie/SAXO_RD/Obsolete/meshlec.pro
98;   /usr/local/rsi/idl_6.0/lib/mesh_obj.pro
[2]99;
[224]100; @history
101; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]102;                       28/4/1999
[121]103;                       6/7/1999: compatibility mac and windows
[11]104; June 2005: Sebastien Masson: cleaning, use for file_* functions
[118]105;
[224]106; @version
107; $Id$
[2]108;-
[231]109;
[11]110FUNCTION find, filein, IODIRECTORY = iodirectory, RECURSIVE = recursive $
[69]111               , REPERTOIRE = repertoire, NOPRO = nopro, ONLYPRO = onlypro $
112               , ONLYNC = onlync, UNIQUE = unique, FIRSTFOUND = firstfound $
[232]113               , LOOKALLDIR = LOOKALLDIR, TRYFIND = tryfind, _EXTRA = ex
[11]114; define where we look for the file
[114]115;
116  compile_opt idl2, strictarrsubs
117;
[11]118  CASE 1 OF
[128]119    keyword_set(lookalldir):BEGIN
[77]120@cm_general
[152]121      dirnames = ['./', iodir, homedir, !path]
[77]122      tstdtadir= file_dirname(find('find', /onlypro), /mark_directory)
123      tstdtadir = (file_search(tstdtadir+'../../DATA/TestsData'))[0]
124      IF tstdtadir NE '' THEN dirnames = [tstdtadir, dirnames]
125    END
[11]126    keyword_set(iodirectory): dirnames = iodirectory
127    keyword_set(repertoire): dirnames = repertoire
[152]128    ELSE: dirnames = ['./', !path]
[11]129  ENDCASE
130  tmp = dirnames
131  dirnames = 'dummy'
132  FOR i = 0, n_elements(tmp)-1 DO $
133    dirnames = [dirnames, strsplit(tmp[i], path_sep(/search_path), /extract)]
134  dirnames = dirnames[1:*]
135;
136  fileout = 'dummy'
137  FOR i = 0, n_elements(filein)-1 DO BEGIN
138    dir = file_dirname(filein[i])
139    base = file_basename(filein[i])
[69]140; try to complete the file name with .pro or .nc if needed...
141    CASE 1 OF
142      keyword_set(onlypro):BEGIN
143        promiss = strpos(base, '.pro', /reverse_search)
144        promiss = promiss - (strlen(base) - 4)
145        bad = where(promiss NE 0 OR strlen(base) LE 4, cnt)
146        IF cnt NE 0 THEN base[bad] = base[bad] + '.pro'
147      end
148      keyword_set(onlync):BEGIN
149        ncmiss = strpos(base, '.nc', /reverse_search)
150        ncmiss = ncmiss - (strlen(base) - 3)
151        bad = where(ncmiss NE 0 OR strlen(base) LE 3, cnt)
152        IF cnt NE 0 THEN base[bad] = base[bad] + '.nc'
153      END
154      ELSE:if strmid(base, 0, 1, /reverse_offset) NE '*' $
155        AND NOT keyword_set(nopro) THEN base = base + '{.pro,}'
156    ENDCASE
[11]157; use dirnames only if dir eq '.'
[128]158    IF dir EQ  '.' THEN BEGIN
[11]159      if keyword_set(recursive) THEN $
160        found = file_search(dirnames, base, _extra = ex) $
[69]161        ELSE found = file_search(dirnames + '/' + base, _extra = ex)
[11]162    ENDIF ELSE found = file_search(dir + '/' + base, _extra = ex)
[128]163    IF found[0] NE '' THEN BEGIN
164      IF keyword_set(firstfound) THEN BEGIN
[11]165        IF keyword_set(unique) THEN return, found[uniq(found, sort(found))] $
166        ELSE return, found
[2]167      ENDIF
[11]168      fileout = [fileout, found]
169    ENDIF
170  ENDFOR
[152]171
[11]172  IF n_elements(fileout) EQ 1 THEN fileout = 'NOT FOUND' $
173  ELSE fileout = fileout[1:*]
174;
[128]175  IF n_elements(fileout) GT 1 THEN BEGIN
[11]176    IF keyword_set(unique) THEN fileout = fileout[uniq(fileout, sort(fileout))]
177  ENDIF ELSE fileout = fileout[0]
178;
[152]179  IF keyword_set(lookalldir) AND fileout[0] EQ 'NOT FOUND' $
180     AND NOT keyword_set(recursive) THEN $
181        filout = find(file_basename(filein[0]), /lookalldir $
182                      , /recursive, _extra = ex)
183;
184  IF keyword_set(tryfind) AND fileout[0] EQ 'NOT FOUND' THEN BEGIN
185    fileout = find(file_basename(filein[0]), /lookalldir, /firstfound, _extra = ex)
186    fileout = fileout[0]
187  ENDIF
188;
[11]189  RETURN, fileout
190END
Note: See TracBrowser for help on using the repository browser.