[2] | 1 | ;+ |
---|
[232] | 2 | ; |
---|
[128] | 3 | ; @file_comments |
---|
| 4 | ; write an idl procedure, compile it and execute it. |
---|
[2] | 5 | ; |
---|
[163] | 6 | ; @param command {in}{required}{type=string array} |
---|
[242] | 7 | ; array defining the procedure to be created. |
---|
[136] | 8 | ; each element will be a line of the created procedure. |
---|
[2] | 9 | ; |
---|
[121] | 10 | ; @keyword FILENAMEIN {in} {default=for_createpro.pro} |
---|
[136] | 11 | ; name of the procedure to be created. |
---|
[2] | 12 | ; |
---|
[242] | 13 | ; @keyword KWDLIST {in} {type=vector string} |
---|
[136] | 14 | ; to specify a list of keywords that must be included in the procedure |
---|
| 15 | ; definition. |
---|
| 16 | ; Warning: the string must start with a ',' |
---|
| 17 | ; for example: KWDLIST = ', TOTO = toto' |
---|
[2] | 18 | ; |
---|
[136] | 19 | ; @keyword KWDUSED |
---|
| 20 | ; obsolete, please pass directly your keywords through _EXTRA |
---|
[118] | 21 | ; |
---|
[136] | 22 | ; @keyword _EXTRA |
---|
[231] | 23 | ; Used to pass keywords to the created procedure. |
---|
[2] | 24 | ; |
---|
[118] | 25 | ; @restrictions |
---|
[242] | 26 | ; - is not working with functions, use <pro>createfunc</pro> instead. |
---|
[118] | 27 | ; - arguments can be given only through keywords. |
---|
| 28 | ; - ends the procedure name with '.pro' if needed. |
---|
[11] | 29 | ; |
---|
[118] | 30 | ; @examples |
---|
[269] | 31 | ; IDL> createpro, ['print,''OK'''], FILENAMEIN='test' |
---|
[128] | 32 | ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ |
---|
[269] | 33 | ; IDL> , FILENAMEIN='test', KWDLIST =', ok = ok' |
---|
[128] | 34 | ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ |
---|
[269] | 35 | ; IDL> , FILENAMEIN='test', KWDLIST= ', ok = ok', /ok |
---|
[2] | 36 | ; |
---|
[224] | 37 | ; @history |
---|
| 38 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[11] | 39 | ; cleaning + new keywords: October 2005 |
---|
[69] | 40 | ; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute |
---|
[118] | 41 | ; |
---|
[224] | 42 | ; @version |
---|
| 43 | ; $Id$ |
---|
[242] | 44 | ; |
---|
[2] | 45 | ;- |
---|
[231] | 46 | ; |
---|
[11] | 47 | PRO createpro, command, FILENAMEIN = filenamein $ |
---|
[121] | 48 | , KWDLIST = kwdlist, KWDUSED = kwdused, _EXTRA = ex |
---|
[69] | 49 | ; |
---|
| 50 | compile_opt idl2, hidden, strictarrsubs |
---|
| 51 | ; |
---|
| 52 | IF keyword_set(kwdused) THEN BEGIN |
---|
| 53 | dummy = report(['keyword KWDUSED has been suppressed,' $ |
---|
[269] | 54 | , 'please pass directly your keywords through _EXTRA,' $ |
---|
[136] | 55 | , 'see examples in createpro header']) |
---|
[69] | 56 | return |
---|
| 57 | ENDIF |
---|
[11] | 58 | ; define filename if needed |
---|
| 59 | if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $ |
---|
[118] | 60 | ELSE filename = filenamein |
---|
[11] | 61 | ; get the name of the procedure (not the name of the file containing the procedure) |
---|
| 62 | shortfilename = file_basename(filename, '.pro') |
---|
| 63 | ; check if the directory exists |
---|
| 64 | dirname = isadirectory(file_dirname(filename) $ |
---|
| 65 | , title = 'Redefine '+shortfilename+'.pro directory') |
---|
| 66 | IF size(dirname, /type) NE 7 THEN return |
---|
| 67 | ; |
---|
| 68 | filename = dirname + shortfilename + '.pro' |
---|
| 69 | ; create the file |
---|
| 70 | if NOT keyword_set(kwdlist) then kwdlist = '' |
---|
[69] | 71 | kwdlist = kwdlist + ', _extra = ex' |
---|
[74] | 72 | kwdlist = strtrim(kwdlist, 2) |
---|
| 73 | IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' + kwdlist |
---|
[69] | 74 | ; for i = 0, n_elements(command)-1 do print, command[i] |
---|
[11] | 75 | putfile, filename, ['pro ' + shortfilename + kwdlist $ |
---|
[69] | 76 | , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end'] |
---|
[229] | 77 | ; is dirname in !path? |
---|
| 78 | cd, current = here |
---|
| 79 | pathlist = [here, strsplit(!path, path_sep(/search_path),/extract)] |
---|
[243] | 80 | inpath = total((file_search(dirname, /fully_qualify_path))[0] EQ pathlist) |
---|
| 81 | IF inpath EQ 0 THEN !path = dirname + path_sep(/search_path) + !path |
---|
[227] | 82 | ; update the list of .pro and .sav in !PATH |
---|
| 83 | path_cache, /rebuild |
---|
[239] | 84 | ; do we really use shortfilename? |
---|
| 85 | list = find(shortfilename, /onlypro, /firstfound) |
---|
| 86 | IF list[0] NE filename THEN BEGIN ; it is ok if filename is the first one |
---|
| 87 | dummy = report(['Several files ' + shortfilename + ' are found in the !path and' $ |
---|
| 88 | , list[0] + ' we be used instead of', filename, 'We stop...'], /simple) |
---|
| 89 | stop |
---|
| 90 | ENDIF |
---|
[11] | 91 | ; compile it |
---|
[2] | 92 | resolve_routine, shortfilename |
---|
[231] | 93 | ;help,ex,/structure |
---|
| 94 | ;print,' ex = ',ex |
---|
[11] | 95 | ; execute it |
---|
[69] | 96 | call_procedure, shortfilename, _extra = ex |
---|
[11] | 97 | ; |
---|
[2] | 98 | return |
---|
| 99 | end |
---|