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

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

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:keywords set to Id
File size: 3.5 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;-
46PRO createpro, command, FILENAMEIN=filenamein $
47             , KWDLIST=kwdlist, KWDUSED=kwdused, _EXTRA=ex
48;
49  compile_opt idl2, hidden, strictarrsubs
50;
51  IF keyword_set(kwdused) THEN BEGIN
52    dummy = report(['keyword KWDUSED has been suppressed,' $
53                    , 'please pass directly your keywords through _EXTRA,' $
54                    , 'see examples in createpro header'])
55    return
56  ENDIF
57; define filename if needed
58  if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $
59  ELSE filename = filenamein
60; get the name of the procedure (not the name of the file containing the procedure)
61   shortfilename =  file_basename(filename, '.pro')
62; check if the directory exists
63   dirname = isadirectory(file_dirname(filename) $
64                          , title = 'Redefine '+shortfilename+'.pro directory')
65   IF size(dirname, /type) NE 7 THEN return
66;
67   filename = dirname + shortfilename + '.pro'
68; create the file
69   if NOT keyword_set(kwdlist) then kwdlist = ''
70   kwdlist = kwdlist + ', _extra = ex'
71   kwdlist = strtrim(kwdlist, 2)
72   IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' +  kwdlist
73;  for i = 0, n_elements(command)-1 do print, command[i]
74   putfile, filename, ['pro ' + shortfilename + kwdlist $
75                       , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end']
76; is dirname in !path?
77   cd, current = here
78   pathlist = [here, strsplit(!path, path_sep(/search_path),/extract)]
79   inpath = total((file_search(dirname, /fully_qualify_path))[0] EQ pathlist)
80   IF inpath EQ 0 THEN !path = dirname + path_sep(/search_path) + !path
81; update the list of .pro and .sav in !PATH
82   path_cache, /rebuild
83; do we really use shortfilename?
84   list = find(shortfilename, /onlypro, /firstfound)
85   IF list[0] NE filename THEN BEGIN ; it is ok if filename is the first one
86     dummy = report(['Several files ' + shortfilename + ' are found in the !path and' $
87                     , list[0] + ' we be used instead of', filename, 'We stop...'], /simple)
88     stop
89   ENDIF
90; compile it
91   resolve_routine, shortfilename
92;help,ex,/structure
93;print,' ex = ',ex
94; execute it
95   call_procedure, shortfilename, _extra = ex
96;
97   return
98end
Note: See TracBrowser for help on using the repository browser.