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

Last change on this file since 239 was 239, checked in by smasson, 17 years ago

cleaning + minor bugfix related to the path definition

  • 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; a string 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}
14; a vector string.
15; to specify a list of keywords that must be included in the procedure
16; definition.
17; Warning: the string must start with a ','
18; for example: KWDLIST = ', TOTO = toto'
19;
20; @keyword KWDUSED
21; obsolete, please pass directly your keywords through _EXTRA
22;
23; @keyword _EXTRA
24; Used to pass keywords to the created procedure.
25;
26; @restrictions
27; - is not working with functions, use createfunc instead.
28; - arguments can be given only through keywords.
29; - ends the procedure name with '.pro' if needed.
30;
31; @examples
32; IDL> createpro, ['print,''OK'''], filename='test'
33; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
34; IDL>   , filename = 'test', kwdlist =', ok = ok'
35; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
36; IDL>   , filename = 'test', kwdlist = ', ok = ok', /ok
37;
38; @history
39; Sebastien Masson (smasson\@lodyc.jussieu.fr)
40; cleaning + new keywords: October 2005
41; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute
42;
43; @version
44; $Id$
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))[0] EQ pathlist)
81   IF inpath EQ 0 THEN !path = !path + path_sep(/search_path) + inpath
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.