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

Last change on this file since 331 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
RevLine 
[2]1;+
[232]2;
[128]3; @file_comments
4; write an idl procedure, compile it and execute it.
[2]5;
[163]6; @param command {in}{required}{type=string array}
[242]7; array defining the procedure to be created.
[136]8; each element will be a line of the created procedure.
[2]9;
[121]10; @keyword FILENAMEIN {in} {default=for_createpro.pro}
[136]11; name of the procedure to be created.
[2]12;
[242]13; @keyword KWDLIST {in} {type=vector string}
[136]14; to specify a list of keywords that must be included in the procedure
15; definition.
16; Warning: the string must start with a ','
[327]17; for example: KWDLIST=', TOTO = toto'
[2]18;
[136]19; @keyword KWDUSED
20; obsolete, please pass directly your keywords through _EXTRA
[118]21;
[136]22; @keyword _EXTRA
[231]23; Used to pass keywords to the created procedure.
[2]24;
[118]25; @restrictions
[242]26; - is not working with functions, use <pro>createfunc</pro> instead.
[118]27; - arguments can be given only through keywords.
28; - ends the procedure name with '.pro' if needed.
[11]29;
[118]30; @examples
[269]31; IDL> createpro, ['print,''OK'''], FILENAMEIN='test'
[128]32; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
[269]33; IDL>   , FILENAMEIN='test', KWDLIST =', ok = ok'
[128]34; IDL> createpro, ['if keyword_set(ok) then print,''OK'' else print, ''No'''] $
[269]35; IDL>   , FILENAMEIN='test', KWDLIST= ', ok = ok', /ok
[2]36;
[224]37; @history
38; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[11]39; cleaning + new keywords: October 2005
[69]40; Feb. 2006: supress keyword "kwdused" and use call_procedure instead of execute
[118]41;
[224]42; @version
43; $Id$
[242]44;
[2]45;-
[327]46PRO createpro, command, FILENAMEIN=filenamein $
47             , KWDLIST=kwdlist, KWDUSED=kwdused, _EXTRA=ex
[69]48;
49  compile_opt idl2, hidden, strictarrsubs
50;
51  IF keyword_set(kwdused) THEN BEGIN
52    dummy = report(['keyword KWDUSED has been suppressed,' $
[269]53                    , 'please pass directly your keywords through _EXTRA,' $
[136]54                    , 'see examples in createpro header'])
[69]55    return
56  ENDIF
[11]57; define filename if needed
58  if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $
[118]59  ELSE filename = filenamein
[11]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 = ''
[69]70   kwdlist = kwdlist + ', _extra = ex'
[74]71   kwdlist = strtrim(kwdlist, 2)
72   IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' +  kwdlist
[69]73;  for i = 0, n_elements(command)-1 do print, command[i]
[11]74   putfile, filename, ['pro ' + shortfilename + kwdlist $
[69]75                       , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end']
[229]76; is dirname in !path?
77   cd, current = here
78   pathlist = [here, strsplit(!path, path_sep(/search_path),/extract)]
[243]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
[227]81; update the list of .pro and .sav in !PATH
82   path_cache, /rebuild
[239]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
[11]90; compile it
[2]91   resolve_routine, shortfilename
[231]92;help,ex,/structure
93;print,' ex = ',ex
[11]94; execute it
[69]95   call_procedure, shortfilename, _extra = ex
[11]96;
[2]97   return
98end
Note: See TracBrowser for help on using the repository browser.