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

Last change on this file since 327 was 327, checked in by pinsard, 17 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1;+
2;
3; @file_comments
4; same as <pro>find</pro> except that as long as the file is 'NOT FOUND',
5; <pro>isafile</pro> calls
6; <proidl>DIALOG_PICKFILE</proidl>, to ask the user to select a file.
7;
8; @categories
9; Input/Output
10;
11; @param filein {in}{optional}
12; a proposed name. If neither filein input parameter or filename keyword are
13; defined, we 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, <pro>find</pro> 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 keywords to <pro>find</pro>,
40; <proidl>FILE_SEARCH</proidl> and
41; <proidl>DIALOG_PICKFILE</proidl>
42;
43; @returns
44; the filename with its path
45;
46; @examples
47; IDL> print, isafile('/Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro')
48;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
49; IDL> print, isafile('cm_4mesh.pro', iodir = '/Users/sebastie/SAXO_RD/Commons')
50;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
51; IDL> print, isafile('cm_4mesh.pro', iodir = !path)
52;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
53; IDL> print, isafile('cm_4mesh.pro', iodir = '/Users/sebastie/SAXO_RD', /recursive)
54;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
55; IDL> print, isafile('cm_4mesh.pro', iodir = getenv('HOME'), /recursive)
56;  /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro
57; IDL> print, isafile('fake_file.pro')
58;
59; @history
60; Sebastien Masson (smasson\@lodyc.jussieu.fr)
61;                      11/2/2000
62; June 2005: Sebastien Masson: cleaning, use for file_* functions
63;
64; @version
65; $Id$
66;
67;-
68FUNCTION isafile, filein, FILENAME=filename, IODIRECTORY=iodirectory $
69                , NEW=new, RECURSIVE=RECURSIVE, ONLYPRO=onlypro $
70                , ONLYNC=onlync, _EXTRA=ex
71;
72  compile_opt idl2, strictarrsubs
73;
74  CASE 1 OF
75    (size(filein, /type))[0] EQ 7:fileout = filein
76    keyword_set(filename):fileout = filename[0]
77    ELSE:fileout = 'file that is not existing'
78  ENDCASE
79  if size(fileout, /type) NE 7 THEN return, -1
80;
81  CASE 1 OF
82    keyword_set(onlypro): filter = '*.pro'
83    keyword_set(onlync): filter = '*.nc'
84    else: filter = '*'
85  ENDCASE
86;
87  basename = file_basename(fileout)
88  dirname = file_dirname(fileout)
89; should we redefine dirname?
90  if fileout NE dirname+'/'+basename AND dirname EQ '.' AND NOT keyword_set(iodirectory) then dirname = ''
91  if keyword_set(iodirectory) AND dirname EQ '.' then dirname = iodirectory
92;
93  if keyword_set(new) then return, dirname + path_sep() + basename
94;
95  fileout = find(basename, iodirectory = dirname $
96                 , recursive = recursive, /unique, /firstfound, ONLYPRO = onlypro $
97                 , ONLYNC = onlync, _extra = ex)
98  WHILE fileout[0] EQ 'NOT FOUND' DO BEGIN
99    fileout = dialog_pickfile(path = dirname[0], filter = filter, _extra = ex)
100    if fileout EQ '' THEN RETURN, report('check/find file canceled')
101; check again everything...
102    basename = file_basename(fileout)
103    dirname = file_dirname(fileout)
104; check if the name of the dirname is ok
105    dirname = isadirectory(dirname, title = 'choose a directory for the file ' $
106                           + basename)
107; if we cancel the check
108    IF size(dirname, /type) NE 7 THEN return, report('check/find file canceled')
109    fileout = find(basename, iodirectory = dirname $
110                   , recursive = recursive, /unique, /firstfound, ONLYPRO = onlypro $
111                   , ONLYNC = onlync, _extra = ex)
112  ENDWHILE
113;
114  RETURN, fileout
115END
Note: See TracBrowser for help on using the repository browser.