[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
[128] | 5 | ; @file_comments |
---|
| 6 | ; write an idl procedure, compile it and execute it. |
---|
[2] | 7 | ; |
---|
[163] | 8 | ; @param command {in}{required}{type=string array} |
---|
[136] | 9 | ; a string array defining the procedure to be created. |
---|
| 10 | ; each element will be a line of the created procedure. |
---|
[2] | 11 | ; |
---|
[121] | 12 | ; @keyword FILENAMEIN {in} {default=for_createpro.pro} |
---|
[136] | 13 | ; name of the procedure to be created. |
---|
[2] | 14 | ; |
---|
[136] | 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' |
---|
[2] | 21 | ; |
---|
[136] | 22 | ; @keyword KWDUSED |
---|
| 23 | ; obsolete, please pass directly your keywords through _EXTRA |
---|
[118] | 24 | ; |
---|
[136] | 25 | ; @keyword _EXTRA |
---|
| 26 | ; used to pass your keywords to the created procedure. |
---|
[2] | 27 | ; |
---|
[118] | 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. |
---|
[11] | 32 | ; |
---|
[118] | 33 | ; @examples |
---|
[128] | 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 |
---|
[2] | 39 | ; |
---|
[93] | 40 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[11] | 41 | ; cleaning + new keywords: October 2005 |
---|
[69] | 42 | ; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute |
---|
[118] | 43 | ; |
---|
| 44 | ; @version $Id$ |
---|
[2] | 45 | ;- |
---|
| 46 | ;------------------------------------------------------------ |
---|
| 47 | ;------------------------------------------------------------ |
---|
| 48 | ;------------------------------------------------------------ |
---|
[11] | 49 | PRO createpro, command, FILENAMEIN = filenamein $ |
---|
[121] | 50 | , KWDLIST = kwdlist, KWDUSED = kwdused, _EXTRA = ex |
---|
[69] | 51 | ; |
---|
| 52 | compile_opt idl2, hidden, strictarrsubs |
---|
| 53 | ; |
---|
| 54 | IF keyword_set(kwdused) THEN BEGIN |
---|
| 55 | dummy = report(['keyword KWDUSED has been suppressed,' $ |
---|
| 56 | , 'please pass directly your keywords through _extra,' $ |
---|
[136] | 57 | , 'see examples in createpro header']) |
---|
[69] | 58 | return |
---|
| 59 | ENDIF |
---|
[11] | 60 | ; define filename if needed |
---|
| 61 | if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $ |
---|
[118] | 62 | ELSE filename = filenamein |
---|
[11] | 63 | ; get the name of the procedure (not the name of the file containing the procedure) |
---|
| 64 | shortfilename = file_basename(filename, '.pro') |
---|
| 65 | ; check if the directory exists |
---|
| 66 | dirname = isadirectory(file_dirname(filename) $ |
---|
| 67 | , title = 'Redefine '+shortfilename+'.pro directory') |
---|
| 68 | IF size(dirname, /type) NE 7 THEN return |
---|
| 69 | ; |
---|
| 70 | filename = dirname + shortfilename + '.pro' |
---|
| 71 | ; create the file |
---|
| 72 | if NOT keyword_set(kwdlist) then kwdlist = '' |
---|
[69] | 73 | kwdlist = kwdlist + ', _extra = ex' |
---|
[74] | 74 | kwdlist = strtrim(kwdlist, 2) |
---|
| 75 | IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' + kwdlist |
---|
[69] | 76 | ; for i = 0, n_elements(command)-1 do print, command[i] |
---|
[11] | 77 | putfile, filename, ['pro ' + shortfilename + kwdlist $ |
---|
[69] | 78 | , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end'] |
---|
[11] | 79 | ; go in dirname directory |
---|
| 80 | cd, dirname, current = old_dir |
---|
| 81 | ; compile it |
---|
[2] | 82 | resolve_routine, shortfilename |
---|
[11] | 83 | cd, old_dir |
---|
| 84 | ; execute it |
---|
[69] | 85 | call_procedure, shortfilename, _extra = ex |
---|
[11] | 86 | ; |
---|
[2] | 87 | return |
---|
| 88 | end |
---|