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 | ; KWDUSED: a vector string. to specify a list of keywords that |
---|
27 | ; must be used when executing the created procedure. Warning: the string |
---|
28 | ; must start with a ',' for example: KWDLIST = ', TOTO = toto' |
---|
29 | ; |
---|
30 | ; OUTPUTS: none |
---|
31 | ; |
---|
32 | ; COMMON BLOCKS: none |
---|
33 | ; |
---|
34 | ; SIDE EFFECTS: ends teh procedure name with '.pro' if needed |
---|
35 | ; |
---|
36 | ; RESTRICTIONS:de marche pas pour les fonctions |
---|
37 | ; |
---|
38 | ; EXAMPLE: |
---|
39 | ; IDL> createpro, ['print,''OK'''], filename='test' |
---|
40 | ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ |
---|
41 | ; IDL> , filename = 'test', kwdlist =', ok = ok' |
---|
42 | ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ |
---|
43 | ; IDL> , filename = 'test', kwdlist = ', ok = ok', kwdused = ', /ok' |
---|
44 | ; |
---|
45 | ; |
---|
46 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
47 | ; cleaning + new keywords: October 2005 |
---|
48 | ;- |
---|
49 | ;------------------------------------------------------------ |
---|
50 | ;------------------------------------------------------------ |
---|
51 | ;------------------------------------------------------------ |
---|
52 | PRO createpro, command, FILENAMEIN = filenamein $ |
---|
53 | , KWDLIST = kwdlist, KWDUSED = kwdused |
---|
54 | |
---|
55 | ; define filename if needed |
---|
56 | if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $ |
---|
57 | ELSE filename = filenamein |
---|
58 | ; get the name of the procedure (not the name of the file containing the procedure) |
---|
59 | shortfilename = file_basename(filename, '.pro') |
---|
60 | ; check if the directory exists |
---|
61 | dirname = isadirectory(file_dirname(filename) $ |
---|
62 | , title = 'Redefine '+shortfilename+'.pro directory') |
---|
63 | IF size(dirname, /type) NE 7 THEN return |
---|
64 | ; |
---|
65 | filename = dirname + shortfilename + '.pro' |
---|
66 | ; create the file |
---|
67 | if NOT keyword_set(kwdlist) then kwdlist = '' |
---|
68 | putfile, filename, ['pro ' + shortfilename + kwdlist $ |
---|
69 | , command, 'return', 'end'] |
---|
70 | ; go in dirname directory |
---|
71 | cd, dirname, current = old_dir |
---|
72 | ; compile it |
---|
73 | resolve_routine, shortfilename |
---|
74 | cd, old_dir |
---|
75 | ; execute it |
---|
76 | if NOT keyword_set(kwdused) then kwdused = '' |
---|
77 | dummy = execute(shortfilename + kwdused) |
---|
78 | ; |
---|
79 | return |
---|
80 | end |
---|