[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 | ; |
---|
[224] | 40 | ; @history |
---|
| 41 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[11] | 42 | ; cleaning + new keywords: October 2005 |
---|
[69] | 43 | ; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute |
---|
[118] | 44 | ; |
---|
[224] | 45 | ; @version |
---|
| 46 | ; $Id$ |
---|
[2] | 47 | ;- |
---|
| 48 | ;------------------------------------------------------------ |
---|
| 49 | ;------------------------------------------------------------ |
---|
| 50 | ;------------------------------------------------------------ |
---|
[11] | 51 | PRO createpro, command, FILENAMEIN = filenamein $ |
---|
[121] | 52 | , KWDLIST = kwdlist, KWDUSED = kwdused, _EXTRA = ex |
---|
[69] | 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,' $ |
---|
[136] | 59 | , 'see examples in createpro header']) |
---|
[69] | 60 | return |
---|
| 61 | ENDIF |
---|
[11] | 62 | ; define filename if needed |
---|
| 63 | if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $ |
---|
[118] | 64 | ELSE filename = filenamein |
---|
[11] | 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 = '' |
---|
[69] | 75 | kwdlist = kwdlist + ', _extra = ex' |
---|
[74] | 76 | kwdlist = strtrim(kwdlist, 2) |
---|
| 77 | IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' + kwdlist |
---|
[69] | 78 | ; for i = 0, n_elements(command)-1 do print, command[i] |
---|
[11] | 79 | putfile, filename, ['pro ' + shortfilename + kwdlist $ |
---|
[69] | 80 | , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end'] |
---|
[229] | 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 |
---|
[227] | 86 | ; update the list of .pro and .sav in !PATH |
---|
| 87 | path_cache, /rebuild |
---|
[11] | 88 | ; compile it |
---|
[2] | 89 | resolve_routine, shortfilename |
---|
[11] | 90 | ; execute it |
---|
[69] | 91 | call_procedure, shortfilename, _extra = ex |
---|
[11] | 92 | ; |
---|
[2] | 93 | return |
---|
| 94 | end |
---|