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

Last change on this file since 119 was 118, checked in by pinsard, 18 years ago

add $ in Calendar, Grid, Interpolation, Obsolete and Postscript *.pro files, add svn:keywords Id to all these files, some improvements in header

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; @file_comments write an idl procedure, compile it and execute it.
6;
7; @param command {in}{required} a string array defining the procedure to be created. each element will be a line of the created procedure.
8;
9; @keyword FILENAMEIN {in} name of the procedure to be created.
10;      'for_createpro.pro' by default
11;
12; @keyword KWDLIST {in} a vector string. to specify a list of keywords that
13;      must be included in the procedure definition. Warning: the string
14;      must start with a ',' for example: KWDLIST = ', TOTO = toto'
15;
16; @keyword KWDUSED obsolote, please pass directly your keywords through _extra
17;
18; @keyword _EXTRA used to pass your keywords to the created procedure.
19;
20; @restrictions
21; - is not working with functions, use createfunc instead.
22; - arguments can be given only through keywords.
23; - ends the procedure name with '.pro' if needed.
24;
25; @examples
26;      IDL> createpro, ['print,''OK'''], filename='test'
27;      IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
28;      IDL>   , filename = 'test', kwdlist =', ok = ok'
29;      IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
30;      IDL>   , filename = 'test', kwdlist = ', ok = ok', /ok
31;
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.