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