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 | ; RECURSIVE: performs recursive searching of directory hierarchies. |
---|
30 | ; In a recursive search, find looks recursively for any and all |
---|
31 | ; subdirectories in the file hierarchy rooted at the IODIRECTORY |
---|
32 | ; argument. |
---|
33 | ; |
---|
34 | ; all find, file_search and dialog_pickfile keywords (like title) |
---|
35 | ; |
---|
36 | ; OUTPUTS:the filename with its path |
---|
37 | ; |
---|
38 | ; COMMON BLOCKS:none |
---|
39 | ; |
---|
40 | ; SIDE EFFECTS: |
---|
41 | ; |
---|
42 | ; RESTRICTIONS: |
---|
43 | ; |
---|
44 | ; EXAMPLE: |
---|
45 | ; |
---|
46 | ; IDL> print, isafile('/Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro') |
---|
47 | ; /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro |
---|
48 | ; IDL> print, isafile('cm_4mesh.pro', iodir = '/Users/sebastie/SAXO_RD/Commons') |
---|
49 | ; /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro |
---|
50 | ; IDL> print, isafile('cm_4mesh.pro', iodir = !path) |
---|
51 | ; /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro |
---|
52 | ; IDL> print, isafile('cm_4mesh.pro', iodir = '/Users/sebastie/SAXO_RD', /recursive) |
---|
53 | ; /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro |
---|
54 | ; IDL> print, isafile('cm_4mesh.pro', iodir = getenv('HOME'), /recursive) |
---|
55 | ; /Users/sebastie/SAXO_RD/Commons/cm_4mesh.pro |
---|
56 | ; IDL> print, isafile('fake_file.pro') |
---|
57 | ; |
---|
58 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
59 | ; 11/2/2000 |
---|
60 | ; June 2005: Sebastien Masson: cleaning, use for file_* functions |
---|
61 | ;- |
---|
62 | ;------------------------------------------------------------ |
---|
63 | ;------------------------------------------------------------ |
---|
64 | ;------------------------------------------------------------ |
---|
65 | FUNCTION isafile, filein, FILENAME = filename, IODIRECTORY = iodirectory $ |
---|
66 | , NEW = new, RECURSIVE = RECURSIVE, _extra = ex |
---|
67 | ;------------------------------------------------------------ |
---|
68 | CASE 1 OF |
---|
69 | (size(filein, /type))[0] EQ 7:fileout = filein |
---|
70 | keyword_set(filename):fileout = filename |
---|
71 | ELSE:fileout = 'file that is not existing' |
---|
72 | ENDCASE |
---|
73 | if size(fileout, /type) NE 7 THEN return, -1 |
---|
74 | ; |
---|
75 | basename = file_basename(fileout) |
---|
76 | dirname = file_dirname(fileout) |
---|
77 | ; should we redefine dirname? |
---|
78 | if keyword_set(iodirectory) AND dirname EQ '.' then dirname = iodirectory |
---|
79 | ; |
---|
80 | if keyword_set(new) then return, dirname + path_sep() + basename |
---|
81 | ; |
---|
82 | fileout = find(basename, iodirectory = dirname $ |
---|
83 | , recursive = recursive, /unique, /firstfound, _extra = ex) |
---|
84 | WHILE fileout[0] EQ 'NOT FOUND' DO BEGIN |
---|
85 | fileout = dialog_pickfile(path = dirname[0], _extra = ex) |
---|
86 | if fileout EQ '' THEN RETURN, report('check/find file canceled') |
---|
87 | ; check again everything... |
---|
88 | basename = file_basename(fileout) |
---|
89 | dirname = file_dirname(fileout) |
---|
90 | ; check if the name of the dirname is ok |
---|
91 | dirname = isadirectory(dirname, title = 'choose a directory for the file ' $ |
---|
92 | + basename) |
---|
93 | ; if we cancel the check |
---|
94 | IF size(dirname, /type) NE 7 THEN return, report('check/find file canceled') |
---|
95 | fileout = find(basename, iodirectory = dirname $ |
---|
96 | , recursive = recursive, /unique, /firstfound, _extra = ex) |
---|
97 | ENDWHILE |
---|
98 | ; |
---|
99 | RETURN, fileout |
---|
100 | END |
---|