1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; @file_comments |
---|
6 | ; write an idl procedure, compile it and execute it. |
---|
7 | ; |
---|
8 | ; @param command {in}{required}{type=string array} |
---|
9 | ; a string array defining the procedure to be created. |
---|
10 | ; each element will be a line of the created procedure. |
---|
11 | ; |
---|
12 | ; @keyword FILENAMEIN {in} {default=for_createpro.pro} |
---|
13 | ; name of the procedure to be created. |
---|
14 | ; |
---|
15 | ; @keyword KWDLIST {in} |
---|
16 | ; a vector string. |
---|
17 | ; to specify a list of keywords that must be included in the procedure |
---|
18 | ; definition. |
---|
19 | ; Warning: the string must start with a ',' |
---|
20 | ; for example: KWDLIST = ', TOTO = toto' |
---|
21 | ; |
---|
22 | ; @keyword KWDUSED |
---|
23 | ; obsolete, please pass directly your keywords through _EXTRA |
---|
24 | ; |
---|
25 | ; @keyword _EXTRA |
---|
26 | ; used to pass your keywords to the created procedure. |
---|
27 | ; |
---|
28 | ; @restrictions |
---|
29 | ; - is not working with functions, use createfunc instead. |
---|
30 | ; - arguments can be given only through keywords. |
---|
31 | ; - ends the procedure name with '.pro' if needed. |
---|
32 | ; |
---|
33 | ; @examples |
---|
34 | ; IDL> createpro, ['print,''OK'''], filename='test' |
---|
35 | ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ |
---|
36 | ; IDL> , filename = 'test', kwdlist =', ok = ok' |
---|
37 | ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ |
---|
38 | ; IDL> , filename = 'test', kwdlist = ', ok = ok', /ok |
---|
39 | ; |
---|
40 | ; @history |
---|
41 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
42 | ; cleaning + new keywords: October 2005 |
---|
43 | ; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute |
---|
44 | ; |
---|
45 | ; @version |
---|
46 | ; $Id$ |
---|
47 | ;- |
---|
48 | ;------------------------------------------------------------ |
---|
49 | ;------------------------------------------------------------ |
---|
50 | ;------------------------------------------------------------ |
---|
51 | PRO createpro, command, FILENAMEIN = filenamein $ |
---|
52 | , KWDLIST = kwdlist, KWDUSED = kwdused, _EXTRA = ex |
---|
53 | ; |
---|
54 | compile_opt idl2, hidden, strictarrsubs |
---|
55 | ; |
---|
56 | IF keyword_set(kwdused) THEN BEGIN |
---|
57 | dummy = report(['keyword KWDUSED has been suppressed,' $ |
---|
58 | , 'please pass directly your keywords through _extra,' $ |
---|
59 | , 'see examples in createpro header']) |
---|
60 | return |
---|
61 | ENDIF |
---|
62 | ; define filename if needed |
---|
63 | if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $ |
---|
64 | ELSE filename = filenamein |
---|
65 | ; get the name of the procedure (not the name of the file containing the procedure) |
---|
66 | shortfilename = file_basename(filename, '.pro') |
---|
67 | ; check if the directory exists |
---|
68 | dirname = isadirectory(file_dirname(filename) $ |
---|
69 | , title = 'Redefine '+shortfilename+'.pro directory') |
---|
70 | IF size(dirname, /type) NE 7 THEN return |
---|
71 | ; |
---|
72 | filename = dirname + shortfilename + '.pro' |
---|
73 | ; create the file |
---|
74 | if NOT keyword_set(kwdlist) then kwdlist = '' |
---|
75 | kwdlist = kwdlist + ', _extra = ex' |
---|
76 | kwdlist = strtrim(kwdlist, 2) |
---|
77 | IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' + kwdlist |
---|
78 | ; for i = 0, n_elements(command)-1 do print, command[i] |
---|
79 | putfile, filename, ['pro ' + shortfilename + kwdlist $ |
---|
80 | , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end'] |
---|
81 | ; is dirname in !path? |
---|
82 | cd, current = here |
---|
83 | pathlist = [here, strsplit(!path, path_sep(/search_path),/extract)] |
---|
84 | inpath = total((file_search(dirname))[0] EQ pathlist) |
---|
85 | IF inpath EQ 0 THEN !path = !path + path_sep(/search_path) + inpath |
---|
86 | ; update the list of .pro and .sav in !PATH |
---|
87 | path_cache, /rebuild |
---|
88 | ; compile it |
---|
89 | resolve_routine, shortfilename |
---|
90 | help,ex,/structure |
---|
91 | print,' ex = ',ex |
---|
92 | ; execute it |
---|
93 | call_procedure, shortfilename, _extra = ex |
---|
94 | ; |
---|
95 | return |
---|
96 | end |
---|