;+ ; ; @file_comments ; write an idl procedure, compile it and execute it. ; ; @param command {in}{required}{type=string array} ; array defining the procedure to be created. ; each element will be a line of the created procedure. ; ; @keyword FILENAMEIN {in} {default=for_createpro.pro} ; name of the procedure to be created. ; ; @keyword KWDLIST {in} {type=vector string} ; to specify a list of keywords that must be included in the procedure ; definition. ; ; Warning: the string must start with a ',' ; for example: KWDLIST=', TOTO = toto' ; ; @keyword KWDUSED ; obsolete, please pass directly your keywords through _EXTRA ; ; @keyword _EXTRA ; Used to pass keywords to the created procedure. ; ; @restrictions ; - is not working with functions, use createfunc instead. ; - arguments can be given only through keywords. ; - ends the procedure name with '.pro' if needed. ; ; @examples ; ; IDL> createpro, ['print,''OK'''], FILENAMEIN='test' ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ ; IDL> , FILENAMEIN='test', KWDLIST =', ok = ok' ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ ; IDL> , FILENAMEIN='test', KWDLIST= ', ok = ok', /ok ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; - cleaning + new keywords: October 2005 ; - Feb. 2006: supress keyword "kwdused" and use call_procedure instead of ; execute ; ; @version ; $Id$ ; ;- PRO createpro, command, FILENAMEIN=filenamein $ , KWDLIST=kwdlist, KWDUSED=kwdused, _EXTRA=ex ; compile_opt idl2, hidden, strictarrsubs ; IF keyword_set(kwdused) THEN BEGIN dummy = report(['keyword KWDUSED has been suppressed,' $ , 'please pass directly your keywords through _EXTRA,' $ , 'see examples in createpro header']) return ENDIF ; define filename if needed if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $ ELSE filename = filenamein ; get the name of the procedure (not the name of the file containing the procedure) shortfilename = file_basename(filename, '.pro') ; check if the directory exists dirname = isadirectory(file_dirname(filename) $ , title = 'Redefine '+shortfilename+'.pro directory') IF size(dirname, /type) NE 7 THEN return ; filename = dirname + shortfilename + '.pro' ; create the file if NOT keyword_set(kwdlist) then kwdlist = '' kwdlist = kwdlist + ', _extra = ex' kwdlist = strtrim(kwdlist, 2) IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' + kwdlist ; for i = 0, n_elements(command)-1 do print, command[i] putfile, filename, ['pro ' + shortfilename + kwdlist $ , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end'] ; is dirname in !path? cd, current = here pathlist = [here, strsplit(!path, path_sep(/search_path),/extract)] inpath = total((file_search(dirname, /fully_qualify_path))[0] EQ pathlist) IF inpath EQ 0 THEN !path = dirname + path_sep(/search_path) + !path ; update the list of .pro and .sav in !PATH path_cache, /rebuild ; do we really use shortfilename? list = find(shortfilename, /onlypro, /firstfound) IF list[0] NE filename THEN BEGIN ; it is ok if filename is the first one dummy = report(['Several files ' + shortfilename + ' are found in the !path and' $ , list[0] + ' we be used instead of', filename, 'We stop...'], /simple) stop ENDIF ; compile it resolve_routine, shortfilename ;help,ex,/structure ;print,' ex = ',ex ; execute it call_procedure, shortfilename, _extra = ex ; return end