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

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

start to modify headers of Calendar and Utilities *.pro files for bet
ter 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: 4.1 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; 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)
34can be used
35;
36; @returns the filename with its path
37;
38; @examples
39;
40;  IDL> print, isafile('/Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro')
41;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
42;  IDL> print, isafile('cm_4mesh.pro', iodir = '/Users/sebastie/SAXO_RD/Commons')
43;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
44;  IDL> print, isafile('cm_4mesh.pro', iodir = !path)
45;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
46;  IDL> print, isafile('cm_4mesh.pro', iodir = '/Users/sebastie/SAXO_RD', /recursive)
47;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
48;  IDL> print, isafile('cm_4mesh.pro', iodir = getenv('HOME'), /recursive)
49;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
50;  IDL> print, isafile('fake_file.pro')
51;
52; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
53;                      11/2/2000
54; June 2005: Sebastien Masson: cleaning, use for file_* functions
55;-
56;------------------------------------------------------------
57;------------------------------------------------------------
58;------------------------------------------------------------
59FUNCTION isafile, filein, FILENAME = filename, IODIRECTORY = iodirectory $
60                  , NEW = new, RECURSIVE = RECURSIVE, ONLYPRO = onlypro $
61                  , ONLYNC = onlync, _extra = ex
62;------------------------------------------------------------
63  CASE 1 OF
64    (size(filein, /type))[0] EQ 7:fileout = filein
65    keyword_set(filename):fileout = filename
66    ELSE:fileout = 'file that is not existing'
67  ENDCASE
68  if size(fileout, /type) NE 7 THEN return, -1
69;
70  CASE 1 OF
71    keyword_set(onlypro): filter = '*.pro'
72    keyword_set(onlync): filter = '*.nc'
73    else: filter = '*'
74  ENDCASE
75;
76  basename = file_basename(fileout)
77  dirname = file_dirname(fileout)
78; should we redefine dirname?
79  if keyword_set(iodirectory) AND dirname EQ '.' then dirname = iodirectory
80;
81  if keyword_set(new) then return, dirname + path_sep() + basename
82;
83  fileout = find(basename, iodirectory = dirname $
84                 , recursive = recursive, /unique, /firstfound, ONLYPRO = onlypro $
85                 , ONLYNC = onlync, _extra = ex)
86  WHILE fileout[0] EQ 'NOT FOUND' DO BEGIN
87    fileout = dialog_pickfile(path = dirname[0], filter = filter, _extra = ex)
88    if fileout EQ '' THEN RETURN, report('check/find file canceled')
89; check again everything...
90    basename = file_basename(fileout)
91    dirname = file_dirname(fileout)
92; check if the name of the dirname is ok
93    dirname = isadirectory(dirname, title = 'choose a directory for the file ' $
94                           + basename)
95; if we cancel the check
96    IF size(dirname, /type) NE 7 THEN return, report('check/find file canceled')
97    fileout = find(basename, iodirectory = dirname $
98                   , recursive = recursive, /unique, /firstfound, ONLYPRO = onlypro $
99                   , ONLYNC = onlync, _extra = ex)
100  ENDWHILE
101;
102  RETURN, fileout
103END
Note: See TracBrowser for help on using the repository browser.