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

Last change on this file since 248 was 248, checked in by smasson, 17 years ago

minor bugbix

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