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

Last change on this file since 97 was 97, checked in by pinsard, 18 years ago

start to modify headers of Obsolete *.pro files for better idldoc output

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