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
RevLine 
[2]1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
[97]5; @file_comments same as find.pro except that as long as the file is 'NOT FOUND',
[11]6;          isafile calls dialog_pickfile, to ask the user to select a file.
[2]7;
[93]8; @categories io
[2]9;
10;
[93]11; @param filein {in}{optional} a proposed name. If neither filein
[11]12;        input parameter of filename keyword are defined,
13;        the ask the user to choose a file.
[2]14;
[93]15; @keyword FILENAME a proposed filename.
[2]16;
[93]17; @keyword IODIRECTORY a directory where we look for the file. this
[121]18;           keyword is taken into account only if the dirname
[11]19;           of filein or filename is '.'
20;
[121]21; @keyword NEW to specify that filename is a new file and that
[11]22;        we should check only its path
23;
[93]24; @keyword ONLYPRO force to look only at file ending with .pro
[69]25;
[93]26; @keyword ONLYNC force to look only at file ending with .nc
[69]27;
[93]28; @keyword RECURSIVE performs recursive searching of directory hierarchies.
[11]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;
[118]33; @keyword _EXTRA used to pass your keywords
34;
[95]35; @file_comments all find, file_search and dialog_pickfile keywords (like title) can be used
[11]36;
[93]37; @returns the filename with its path
[11]38;
[93]39; @examples
[2]40;
[11]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;
[93]53; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]54;                      11/2/2000
[11]55; June 2005: Sebastien Masson: cleaning, use for file_* functions
[118]56;
57; @version $Id$
[2]58;-
59;------------------------------------------------------------
60;------------------------------------------------------------
61;------------------------------------------------------------
[11]62FUNCTION isafile, filein, FILENAME = filename, IODIRECTORY = iodirectory $
[69]63                  , NEW = new, RECURSIVE = RECURSIVE, ONLYPRO = onlypro $
64                  , ONLYNC = onlync, _extra = ex
[2]65;------------------------------------------------------------
[114]66;
67  compile_opt idl2, strictarrsubs
68;
[11]69  CASE 1 OF
70    (size(filein, /type))[0] EQ 7:fileout = filein
[114]71    keyword_set(filename):fileout = filename[0]
[11]72    ELSE:fileout = 'file that is not existing'
73  ENDCASE
74  if size(fileout, /type) NE 7 THEN return, -1
75;
[69]76  CASE 1 OF
77    keyword_set(onlypro): filter = '*.pro'
78    keyword_set(onlync): filter = '*.nc'
79    else: filter = '*'
80  ENDCASE
81;
[11]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 $
[69]90                 , recursive = recursive, /unique, /firstfound, ONLYPRO = onlypro $
91                 , ONLYNC = onlync, _extra = ex)
[11]92  WHILE fileout[0] EQ 'NOT FOUND' DO BEGIN
[69]93    fileout = dialog_pickfile(path = dirname[0], filter = filter, _extra = ex)
[11]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 $
[69]104                   , recursive = recursive, /unique, /firstfound, ONLYPRO = onlypro $
105                   , ONLYNC = onlync, _extra = ex)
[11]106  ENDWHILE
107;
108  RETURN, fileout
109END
Note: See TracBrowser for help on using the repository browser.