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

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

improvements/corrections of some *.pro headers

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1;+
2; @file_comments
3; write an idl procedure, compile it and execute it.
4;
5; @param command {in}{required}{type=string array}
6; a string array defining the procedure to be created.
7; each element will be a line of the created procedure.
8;
9; @keyword FILENAMEIN {in} {default=for_createpro.pro}
10; name of the procedure to be created.
11;
12; @keyword KWDLIST {in}
13; a 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 createfunc 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'''], filename='test'
32; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
33; IDL>   , filename = 'test', kwdlist =', ok = ok'
34; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
35; IDL>   , filename = '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))[0] EQ pathlist)
80   IF inpath EQ 0 THEN !path = !path + path_sep(/search_path) + inpath
81; update the list of .pro and .sav in !PATH
82   path_cache, /rebuild
83; compile it
84   resolve_routine, shortfilename
85;help,ex,/structure
86;print,' ex = ',ex
87; execute it
88   call_procedure, shortfilename, _extra = ex
89;
90   return
91end
Note: See TracBrowser for help on using the repository browser.