1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME:isafile |
---|
6 | ; |
---|
7 | ; PURPOSE:find a file and check if it is a real file! |
---|
8 | ; |
---|
9 | ; CATEGORY:for open |
---|
10 | ; |
---|
11 | ; CALLING SEQUENCE:filename = isafile() |
---|
12 | ; |
---|
13 | ; INPUTS:none |
---|
14 | ; |
---|
15 | ; KEYWORD PARAMETERS: |
---|
16 | ; FILENAME: a proposed filename. |
---|
17 | ; IODIRECTORY: a directory where must be the file. |
---|
18 | ; /NEW:to specify that filename is a new file |
---|
19 | ; |
---|
20 | ; OUTPUTS:the filename |
---|
21 | ; |
---|
22 | ; COMMON BLOCKS:none |
---|
23 | ; |
---|
24 | ; SIDE EFFECTS: |
---|
25 | ; |
---|
26 | ; RESTRICTIONS: |
---|
27 | ; |
---|
28 | ; EXAMPLE: |
---|
29 | ; |
---|
30 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
31 | ; 11/2/2000 |
---|
32 | ;- |
---|
33 | ;------------------------------------------------------------ |
---|
34 | ;------------------------------------------------------------ |
---|
35 | ;------------------------------------------------------------ |
---|
36 | FUNCTION isafile, FILENAME = filename, IODIRECTORY = iodirectory, FILTER = filter, NEW = new |
---|
37 | ;------------------------------------------------------------ |
---|
38 | ; we find the filename. |
---|
39 | ;------------------------------------------------------------ |
---|
40 | ; is filename given by the FILENAME keyword a good one? |
---|
41 | ; si iodirectory n''est pas definit on l''initialise au repertoire courant |
---|
42 | if NOT keyword_set(filename) then filename = 'nimportequoi' |
---|
43 | thisOS = strupcase(strmid(!version.os_family, 0, 3)) |
---|
44 | CASE thisOS OF |
---|
45 | 'MAC':sep = ':' |
---|
46 | 'WIN':sep = '\' |
---|
47 | ELSE:sep = '/' |
---|
48 | ENDCASE |
---|
49 | ; we complete filename by iodirectory? |
---|
50 | if strpos(filename, sep) EQ -1 then begin |
---|
51 | if NOT keyword_set(iodirectory) then cd, current = iodirectory |
---|
52 | ; si iodirectory ne finit pas par sep on le rajoute |
---|
53 | if rstrpos(iodirectory, sep) NE strlen(iodirectory)-1 then $ |
---|
54 | iodirectory = iodirectory+sep |
---|
55 | filename = iodirectory+filename |
---|
56 | ENDIF |
---|
57 | if keyword_set(new) then return, filename |
---|
58 | test = findfile(filename) ; le nom cherche correspond bien a un fichier? |
---|
59 | while test[0] EQ '' OR n_elements(test) GT 1 do BEGIN ; on en cherche un tant qu''il ne correspond a rien! |
---|
60 | test = test[0] |
---|
61 | if keyword_set(filter) AND thisOS NE 'MAC' AND thisOS NE 'WIN' then $ |
---|
62 | filename = dialog_pickfile(path = iodirectory, filter = filter) $ |
---|
63 | ELSE filename = dialog_pickfile(path = iodirectory) |
---|
64 | if filename EQ '' then return, report('read_data canceled') |
---|
65 | test = findfile(filename) |
---|
66 | endwhile |
---|
67 | |
---|
68 | return, filename |
---|
69 | end |
---|