source: trunk/SRC/Utilities/createpro.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:keywords set to Id
File size: 3.6 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}
[495]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}
[495]14; to specify a list of keywords that must be included in the procedure
15; definition.
[375]16;
[495]17; Warning: the string must start with a ','
[327]18; for example: KWDLIST=', TOTO = toto'
[2]19;
[495]20; @keyword KWDUSED
[136]21; obsolete, please pass directly your keywords through _EXTRA
[118]22;
[495]23; @keyword _EXTRA
[231]24; Used to pass keywords to the created procedure.
[2]25;
[118]26; @restrictions
[242]27; - is not working with functions, use <pro>createfunc</pro> instead.
[118]28; - arguments can be given only through keywords.
29; - ends the procedure name with '.pro' if needed.
[11]30;
[118]31; @examples
[2]32;
[371]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;
[224]39; @history
40; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[375]41;  - cleaning + new keywords: October 2005
[495]42;  - Feb. 2006: suppress keyword "kwdused" and use call_procedure instead of
[375]43;    execute
[118]44;
[224]45; @version
46; $Id$
[242]47;
[2]48;-
[327]49PRO createpro, command, FILENAMEIN=filenamein $
50             , KWDLIST=kwdlist, KWDUSED=kwdused, _EXTRA=ex
[69]51;
52  compile_opt idl2, hidden, strictarrsubs
53;
54  IF keyword_set(kwdused) THEN BEGIN
55    dummy = report(['keyword KWDUSED has been suppressed,' $
[269]56                    , 'please pass directly your keywords through _EXTRA,' $
[136]57                    , 'see examples in createpro header'])
[69]58    return
59  ENDIF
[11]60; define filename if needed
61  if NOT keyword_set(filenamein) then filename = 'for_createpro.pro' $
[118]62  ELSE filename = filenamein
[11]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 = ''
[69]73   kwdlist = kwdlist + ', _extra = ex'
[74]74   kwdlist = strtrim(kwdlist, 2)
75   IF strmid(kwdlist, 0, 1) NE ',' THEN kwdlist = ', ' +  kwdlist
[69]76;  for i = 0, n_elements(command)-1 do print, command[i]
[11]77   putfile, filename, ['pro ' + shortfilename + kwdlist $
[69]78                       , 'compile_opt idl2, hidden, strictarrsubs', command, 'return', 'end']
[229]79; is dirname in !path?
80   cd, current = here
81   pathlist = [here, strsplit(!path, path_sep(/search_path),/extract)]
[243]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
[227]84; update the list of .pro and .sav in !PATH
85   path_cache, /rebuild
[239]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
[11]93; compile it
[2]94   resolve_routine, shortfilename
[231]95;help,ex,/structure
96;print,' ex = ',ex
[11]97; execute it
[69]98   call_procedure, shortfilename, _extra = ex
[11]99;
[2]100   return
101end
Note: See TracBrowser for help on using the repository browser.