1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME:createpro |
---|
6 | ; |
---|
7 | ; PURPOSE: write an idl procedure, compile it and execute it. |
---|
8 | ; |
---|
9 | ; CATEGORY: |
---|
10 | ; |
---|
11 | ; CALLING SEQUENCE:createpro, command |
---|
12 | ; |
---|
13 | ; INPUTS: |
---|
14 | ; command: a string array defining the procedure to be created. |
---|
15 | ; each element will be a line of the created procedure. |
---|
16 | ; |
---|
17 | ; KEYWORD PARAMETERS: |
---|
18 | ; |
---|
19 | ; FILENAMEIN: name of the procedure to be created. |
---|
20 | ; 'for_createpro.pro' by default |
---|
21 | ; |
---|
22 | ; KWDLIST: a vector string. to specify a list of keywords that |
---|
23 | ; must be included in the procedure definition. Warning: the string |
---|
24 | ; must start with a ',' for example: KWDLIST = ', TOTO = toto' |
---|
25 | ; |
---|
26 | ; _EXTRA: used to pass your keywords to the created procedure. |
---|
27 | ; |
---|
28 | ; OUTPUTS: none |
---|
29 | ; |
---|
30 | ; COMMON BLOCKS: none |
---|
31 | ; |
---|
32 | ; SIDE EFFECTS: ends teh procedure name with '.pro' if needed |
---|
33 | ; |
---|
34 | ; RESTRICTIONS:de marche pas pour les fonctions |
---|
35 | ; |
---|
36 | ; EXAMPLE: |
---|
37 | ; IDL> createpro, ['print,''OK'''], filename='test' |
---|
38 | ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ |
---|
39 | ; IDL> , filename = 'test', kwdlist =', ok = ok' |
---|
40 | ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ |
---|
41 | ; IDL> , filename = 'test', kwdlist = ', ok = ok', /ok |
---|
42 | ; |
---|
43 | ; |
---|
44 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
45 | ; cleaning + new keywords: October 2005 |
---|
46 | ; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute |
---|
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 exaemples 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 | ; for i = 0, n_elements(command)-1 do print, command[i] |
---|
77 | putfile, filename, ['pro ' + shortfilename + kwdlist $ |
---|
78 | , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end'] |
---|
79 | ; go in dirname directory |
---|
80 | cd, dirname, current = old_dir |
---|
81 | ; compile it |
---|
82 | resolve_routine, shortfilename |
---|
83 | cd, old_dir |
---|
84 | ; execute it |
---|
85 | call_procedure, shortfilename, _extra = ex |
---|
86 | ; |
---|
87 | return |
---|
88 | end |
---|