source: trunk/SRC/Utilities/createfunc.pro @ 72

Last change on this file since 72 was 69, checked in by smasson, 18 years ago

debug + new xxx

File size: 2.9 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:createpro
6;
7; PURPOSE: write an idl procedure, compile it and execute it.
8;
9; CATEGORY:
10;
11; CALLING SEQUENCE:createpro, command
12;
13; INPUTS:
14;      command: a string array defining the procedure to be created.
15;      each element will be a line of the created procedure.
16;
17; KEYWORD PARAMETERS:
18;
19;      FILENAMEIN: name of the procedure to be created.
20;      'for_createpro.pro' by default
21;
22;      KWDLIST: a vector string. to specify a list of keywords that
23;      must be included in the procedure definition. Warning: the string
24;      must start with a ',' for example: KWDLIST = ', TOTO = toto'
25;
26;      _EXTRA: used to pass your keywords to the created procedure.
27;
28; OUTPUTS: none
29;
30; COMMON BLOCKS: none
31;
32; SIDE EFFECTS: ends teh procedure name with '.pro' if needed
33;
34; RESTRICTIONS:de marche pas pour les fonctions
35;
36; EXAMPLE:
37;      IDL> createpro, ['print,''OK'''], filename='test'
38;      IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
39;      IDL>   , filename = 'test', kwdlist =', ok = ok'
40;      IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
41;      IDL>   , filename = 'test', kwdlist = ', ok = ok', /ok
42;
43;
44; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
45; cleaning + new keywords: October 2005
46; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute
47;-
48;------------------------------------------------------------
49;------------------------------------------------------------
50;------------------------------------------------------------
51FUNCTION createfunc, command, FILENAMEIN = filenamein $
52               , KWDLIST = kwdlist, _extra = ex
53;
54  compile_opt idl2, hidden, strictarrsubs
55;
56; define filename if needed
57  if NOT keyword_set(filenamein) then filename = 'for_createfunc.pro' $
58  ELSE filename = filenamein
59; get the name of the function (not the name of the file containing the function)
60   shortfilename =  file_basename(filename, '.pro')
61; check if the directory exists
62   dirname = isadirectory(file_dirname(filename) $
63                          , title = 'Redefine '+shortfilename+'.pro directory')
64   IF size(dirname, /type) NE 7 THEN return, -1
65;
66   filename = dirname + shortfilename + '.pro'
67; create the file
68   if NOT keyword_set(kwdlist) then kwdlist = ''
69   kwdlist = kwdlist + ', _extra = ex'
70   putfile, filename, ['function ' + shortfilename + kwdlist $
71                       , 'compile_opt idl2, hidden, strictarrsubs' $
72                       , 'res = ' + command $
73                       , 'return, res' $
74                       , 'end']
75; go in dirname directory
76   cd, dirname, current = old_dir
77; compile it
78   resolve_routine, shortfilename, /is_function
79   cd, old_dir
80; execute it
81   res = call_function(shortfilename, _extra = ex)
82;
83   return, res
84end
Note: See TracBrowser for help on using the repository browser.