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

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

debug + new xxx

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