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

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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