;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME:createpro ; ; PURPOSE: write an idl procedure, compile it and execute it. ; ; CATEGORY: ; ; CALLING SEQUENCE:createpro, command ; ; INPUTS: ; command: a string array defining the procedure to be created. ; each element will be a line of the created procedure. ; ; KEYWORD PARAMETERS: ; ; FILENAMEIN: name of the procedure to be created. ; 'for_createpro.pro' by default ; ; KWDLIST: a 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' ; ; KWDUSED: a vector string. to specify a list of keywords that ; must be used when executing the created procedure. Warning: the string ; must start with a ',' for example: KWDLIST = ', TOTO = toto' ; ; OUTPUTS: none ; ; COMMON BLOCKS: none ; ; SIDE EFFECTS: ends teh procedure name with '.pro' if needed ; ; RESTRICTIONS:de marche pas pour les fonctions ; ; EXAMPLE: ; IDL> createpro, ['print,''OK'''], filename='test' ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ ; IDL> , filename = 'test', kwdlist =', ok = ok' ; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $ ; IDL> , filename = 'test', kwdlist = ', ok = ok', kwdused = ', /ok' ; ; ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) ; cleaning + new keywords: October 2005 ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ PRO createpro, command, FILENAMEIN = filenamein $ , KWDLIST = kwdlist, KWDUSED = kwdused ; 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 = '' putfile, filename, ['pro ' + shortfilename + kwdlist $ , command, 'return', 'end'] ; go in dirname directory cd, dirname, current = old_dir ; compile it resolve_routine, shortfilename cd, old_dir ; execute it if NOT keyword_set(kwdused) then kwdused = '' dummy = execute(shortfilename + kwdused) ; return end