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

Last change on this file since 277 was 269, checked in by pinsard, 17 years ago

add revision in report message. see 65.

  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1;+
2;
3; @file_comments
4; write an idl procedure, compile it and execute it.
5;
6; @param command {in}{required}{type=string array}
7; array defining the procedure to be created.
8; 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} {type=vector string}
14; to specify a list of keywords that must be included in the procedure
15; definition.
16; Warning: the string must start with a ','
17; for example: KWDLIST = ', TOTO = toto'
18;
19; @keyword KWDUSED
20; obsolete, please pass directly your keywords through _EXTRA
21;
22; @keyword _EXTRA
23; Used to pass keywords to the created procedure.
24;
25; @restrictions
26; - is not working with functions, use <pro>createfunc</pro> instead.
27; - arguments can be given only through keywords.
28; - ends the procedure name with '.pro' if needed.
29;
30; @examples
31; IDL> createpro, ['print,''OK'''], FILENAMEIN='test'
32; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
33; IDL>   , FILENAMEIN='test', KWDLIST =', ok = ok'
34; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
35; IDL>   , FILENAMEIN='test', KWDLIST= ', ok = ok', /ok
36;
37; @history
38; Sebastien Masson (smasson\@lodyc.jussieu.fr)
39; cleaning + new keywords: October 2005
40; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute
41;
42; @version
43; $Id$
44;
45;-
46;
47PRO createpro, command, FILENAMEIN = filenamein $
48               , KWDLIST = kwdlist, KWDUSED = kwdused, _EXTRA = ex
49;
50  compile_opt idl2, hidden, strictarrsubs
51;
52  IF keyword_set(kwdused) THEN BEGIN
53    dummy = report(['keyword KWDUSED has been suppressed,' $
54                    , 'please pass directly your keywords through _EXTRA,' $
55                    , 'see examples in createpro header'])
56    return
57  ENDIF
58; define filename if needed
59  if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $
60  ELSE filename = filenamein
61; get the name of the procedure (not the name of the file containing the procedure)
62   shortfilename =  file_basename(filename, '.pro')
63; check if the directory exists
64   dirname = isadirectory(file_dirname(filename) $
65                          , title = 'Redefine '+shortfilename+'.pro directory')
66   IF size(dirname, /type) NE 7 THEN return
67;
68   filename = dirname + shortfilename + '.pro'
69; create the file
70   if NOT keyword_set(kwdlist) then kwdlist = ''
71   kwdlist = kwdlist + ', _extra = ex'
72   kwdlist = strtrim(kwdlist, 2)
73   IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' +  kwdlist
74;  for i = 0, n_elements(command)-1 do print, command[i]
75   putfile, filename, ['pro ' + shortfilename + kwdlist $
76                       , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end']
77; is dirname in !path?
78   cd, current = here
79   pathlist = [here, strsplit(!path, path_sep(/search_path),/extract)]
80   inpath = total((file_search(dirname, /fully_qualify_path))[0] EQ pathlist)
81   IF inpath EQ 0 THEN !path = dirname + path_sep(/search_path) + !path
82; update the list of .pro and .sav in !PATH
83   path_cache, /rebuild
84; do we really use shortfilename?
85   list = find(shortfilename, /onlypro, /firstfound)
86   IF list[0] NE filename THEN BEGIN ; it is ok if filename is the first one
87     dummy = report(['Several files ' + shortfilename + ' are found in the !path and' $
88                     , list[0] + ' we be used instead of', filename, 'We stop...'], /simple)
89     stop
90   ENDIF
91; compile it
92   resolve_routine, shortfilename
93;help,ex,/structure
94;print,' ex = ',ex
95; execute it
96   call_procedure, shortfilename, _extra = ex
97;
98   return
99end
Note: See TracBrowser for help on using the repository browser.