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

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

correction of some *.pro using aspell list; introduction of default idldoc syntax

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