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

Last change on this file since 375 was 375, checked in by pinsard, 16 years ago

improvements of headers (paragraphs and alignments)

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