source: trunk/SRC/Utilities/createpro.pro @ 134

Last change on this file since 134 was 128, checked in by pinsard, 18 years ago

improvements of Utilities/*.pro header

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; @file_comments
6; write an idl procedure, compile it and execute it.
7;
8; @param command {in}{required} a string array defining the procedure to be created. each element will be a line of the created procedure.
9;
10; @keyword FILENAMEIN {in} {default=for_createpro.pro}
11;  name of the procedure to be created.
12;
13; @keyword KWDLIST {in} a vector string. to specify a list of keywords that
14;      must be included in the procedure definition. Warning: the string
15;      must start with a ',' for example: KWDLIST = ', TOTO = toto'
16;
17; @keyword KWDUSED obsolote, please pass directly your keywords through _EXTRA
18;
19; @keyword _EXTRA used to pass your keywords to the created procedure.
20;
21; @restrictions
22; - is not working with functions, use createfunc instead.
23; - arguments can be given only through keywords.
24; - ends the procedure name with '.pro' if needed.
25;
26; @examples
27; IDL> createpro, ['print,''OK'''], filename='test'
28; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
29; IDL>   , filename = 'test', kwdlist =', ok = ok'
30; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
31; IDL>   , filename = 'test', kwdlist = ', ok = ok', /ok
32;
33; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
34; cleaning + new keywords: October 2005
35; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute
36;
37; @version $Id$
38;-
39;------------------------------------------------------------
40;------------------------------------------------------------
41;------------------------------------------------------------
42PRO createpro, command, FILENAMEIN = filenamein $
43               , KWDLIST = kwdlist, KWDUSED = kwdused, _EXTRA = ex
44;
45  compile_opt idl2, hidden, strictarrsubs
46;
47  IF keyword_set(kwdused) THEN BEGIN
48    dummy = report(['keyword KWDUSED has been suppressed,' $
49                    , 'please pass directly your keywords through _extra,' $
50                    , 'see exaemples in createpro header'])
51    return
52  ENDIF
53; define filename if needed
54  if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $
55  ELSE filename = filenamein
56; get the name of the procedure (not the name of the file containing the procedure)
57   shortfilename =  file_basename(filename, '.pro')
58; check if the directory exists
59   dirname = isadirectory(file_dirname(filename) $
60                          , title = 'Redefine '+shortfilename+'.pro directory')
61   IF size(dirname, /type) NE 7 THEN return
62;
63   filename = dirname + shortfilename + '.pro'
64; create the file
65   if NOT keyword_set(kwdlist) then kwdlist = ''
66   kwdlist = kwdlist + ', _extra = ex'
67   kwdlist = strtrim(kwdlist, 2)
68   IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' +  kwdlist
69;  for i = 0, n_elements(command)-1 do print, command[i]
70   putfile, filename, ['pro ' + shortfilename + kwdlist $
71                       , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end']
72; go in dirname directory
73   cd, dirname, current = old_dir
74; compile it
75   resolve_routine, shortfilename
76   cd, old_dir
77; execute it
78   call_procedure, shortfilename, _extra = ex
79;
80   return
81end
Note: See TracBrowser for help on using the repository browser.