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

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

some improvements and corrections in some .pro file according to
aspell and idldoc log file

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