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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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