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

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

replace some print by some report in some .pro (continuation) + improvements/corrections of some *.pro headers

  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1;+
2;
3; @file_comments
4; same as <pro>find</pro> except that as long as the file is 'NOT FOUND',
5; isafile calls dialog_pickfile, to ask the user to select a file.
6;
7; @categories
8; io
9;
10; @param FILEIN {in}{optional}
11; a proposed name. If neither filein input parameter of filename keyword are
12; defined, we ask the user to choose a file.
13;
14; @keyword FILENAME
15; a proposed filename.
16;
17; @keyword IODIRECTORY
18; a directory where we look for the file. this
19; keyword is taken into account only if the dirname
20; of filein or filename is '.'
21;
22; @keyword NEW
23; to specify that filename is a new file and that we should check only its
24; path
25;
26; @keyword ONLYPRO
27; force to look only at file ending with .pro
28;
29; @keyword ONLYNC
30; force to look only at file ending with .nc
31;
32; @keyword RECURSIVE
33; performs recursive searching of directory hierarchies.
34; In a recursive search, find looks recursively for any and all
35; subdirectories in the file hierarchy rooted at the IODIRECTORY argument.
36;
37; @keyword _EXTRA
38; Used to pass keywords to <pro>find</pro>,
39; <proidl>file_search</proidl> and
40; <proidl>dialog_pickfile</proidl>
41;
42; @returns
43; the filename with its path
44;
45; @examples
46;
47; IDL> print, isafile('/Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro')
48;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
49; IDL> print, isafile('cm_4mesh.pro', iodir = '/Users/sebastie/SAXO_RD/Commons')
50;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
51; IDL> print, isafile('cm_4mesh.pro', iodir = !path)
52;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
53; IDL> print, isafile('cm_4mesh.pro', iodir = '/Users/sebastie/SAXO_RD', /recursive)
54;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
55; IDL> print, isafile('cm_4mesh.pro', iodir = getenv('HOME'), /recursive)
56;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
57; IDL> print, isafile('fake_file.pro')
58;
59; @history
60; Sebastien Masson (smasson\@lodyc.jussieu.fr)
61;                      11/2/2000
62; June 2005: Sebastien Masson: cleaning, use for file_* functions
63;
64; @version
65; $Id$
66;
67;-
68;
69FUNCTION isafile, filein, FILENAME = filename, IODIRECTORY = iodirectory $
70                  , NEW = new, RECURSIVE = RECURSIVE, ONLYPRO = onlypro $
71                  , ONLYNC = onlync, _EXTRA = ex
72;
73  compile_opt idl2, strictarrsubs
74;
75  CASE 1 OF
76    (size(filein, /type))[0] EQ 7:fileout = filein
77    keyword_set(filename):fileout = filename[0]
78    ELSE:fileout = 'file that is not existing'
79  ENDCASE
80  if size(fileout, /type) NE 7 THEN return, -1
81;
82  CASE 1 OF
83    keyword_set(onlypro): filter = '*.pro'
84    keyword_set(onlync): filter = '*.nc'
85    else: filter = '*'
86  ENDCASE
87;
88  basename = file_basename(fileout)
89  dirname = file_dirname(fileout)
90; should we redefine dirname?
91  if keyword_set(iodirectory) AND dirname EQ '.' then dirname = iodirectory
92;
93  if keyword_set(new) then return, dirname + path_sep() + basename
94;
95  fileout = find(basename, iodirectory = dirname $
96                 , recursive = recursive, /unique, /firstfound, ONLYPRO = onlypro $
97                 , ONLYNC = onlync, _extra = ex)
98  WHILE fileout[0] EQ 'NOT FOUND' DO BEGIN
99    fileout = dialog_pickfile(path = dirname[0], filter = filter, _extra = ex)
100    if fileout EQ '' THEN RETURN, report('check/find file canceled')
101; check again everything...
102    basename = file_basename(fileout)
103    dirname = file_dirname(fileout)
104; check if the name of the dirname is ok
105    dirname = isadirectory(dirname, title = 'choose a directory for the file ' $
106                           + basename)
107; if we cancel the check
108    IF size(dirname, /type) NE 7 THEN return, report('check/find file canceled')
109    fileout = find(basename, iodirectory = dirname $
110                   , recursive = recursive, /unique, /firstfound, ONLYPRO = onlypro $
111                   , ONLYNC = onlync, _extra = ex)
112  ENDWHILE
113;
114  RETURN, fileout
115END
Note: See TracBrowser for help on using the repository browser.