Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
finding out if program exists (newproc.pro)
Hello, there has been some discusion lately (actually since a while) that it is difficult to make sure that when you a name a routine, that the name you picked doesn't already exist. Well, here at SMA, we have a program, newproc.pro, that helps us out with this. It takes one parameter, the name of the routine you would like to create. For example, if you want to create the program plot_drop.pro, do the following: idl>newproc,'plot_drop.pro' if the file exists, a warning such as the following is displayed: Procedure with the same name already exists in /tools/idl/lib/idlmeteo/pro Please choose another name If it doesn't exist, the template.pro program is copied into your current directory with the file name you requested. Then you can started editing, or simple exit, and edit the program at your leisure later. (see Using this,below, for a breif discussion of the template file.) SHORT comings: until now, this routine doesn't check for routine names that come with the IDL system. SO if you typed newproc,'min.pro' the file min.pro will be created (in your current directory) despite the fact that min is a built in IDL function. So, if someone would like to add the functionality of checking for IDL system routine, it would be appreciated. Using this: The following line needs to be changed so that it contains the correct path to some header template, called template.pro, you use. If you currently use no template, I have included our template.pro at the end of this posting. spawn, ['cp',!DIR+'/lib/idlmeteo/pro/template.pro',proc], /NOSHELL So make sure you change the above line. Then put this program in a directory that is in the IDL_PATH, and place the template.pro program at the place you just indicated in the changed line above. Okay, here is the program: newproc.pro \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ cut here \\\\\\\\\\\\\\\\\\\\\\ ; ;+ ; NAME: ; NEWPROC ; ; PURPOSE: ; Creating of new procedure. Checks first if a procedure with the ; same name already exists. If not the template.pro with the default ; header will be loaded into the editor set by the envrionment ; variable IMEDITOR (default is vi, if variable is not set). ; ; CATEGORY: ; Help ; ; ; CALLING SEQUENCE: ; newproc, 'procname' ; ; ; INPUTS: ; procname name of procedure to create ; ; ; OUTPUTS: ; New procedure ; ; RESTRICTIONS: ; ; ; EXAMPLE: ; newproc, 'create_table' ; ; SEE ALSO: ; getpro ; ; MODIFICATION HISTORY: ; Written by: Thomas.Oettli@sma.ch, 21-Dec-1992 ; 16-May-1994, added current directory to ; search path. ; ;- PRO newproc, proc i=0 found = -1 editor = getenv("IMEDITOR") cd, CURRENT=here path = str_sep(!PATH+':'+here,':') if strpos(proc,'.') EQ -1 then proc = proc + ".pro" WHILE i LE n_elements(path)-1 AND found EQ -1 DO BEGIN cd, path(i) OPENR, 99, proc, ERROR = err CLOSE, 99 IF (err EQ 0) THEN BEGIN found=1 ENDIF i=i+1 ENDWHILE if found EQ 1 then begin print, "Procedure with the same name already exists in ", path(i-1) print, "Please choose another name" print, " " endif else begin cd, here spawn, ['cp',!DIR+'/lib/idlmeteo/pro/template.pro',proc], /NOSHELL if strlen(editor) NE 0 then spawn, [editor,proc], /NOSHELL $ else spawn, ['vi',proc], /NOSHELL endelse END \\\\\\\\\\\\\\\\\\\\\\\\\\\CUT this off \\\\\\\\\\\\\\\\\\\\\\\\\\\\ okay, now here is a template.pro, which you will need (or use your own one) \\\\\\\\\\\\\\\\\\\\\\\\start of template.pro \\\\\\\\\\\\\\\\\\\\\\\ ; ;+ ; NAME: ; TEMPLATE ; ; PURPOSE: ; Template header for idlmeteo procedures, follows the standard ; IDL rules ; ; ; CATEGORY: ; Help ; ; ; CALLING SEQUENCE: ; ; ; ; INPUTS: ; ; ; ; OPTIONAL INPUTS: ; ; ; ; KEYWORD PARAMETERS: ; ; ; ; OUTPUTS: ; ; ; OPTIONAL OUTPUTS: ; ; ; ; COMMON BLOCKS: ; ; ; SIDE EFFECTS: ; ; ; RESTRICTIONS: ; ; ; ; PROCEDURE: ; ; ; ; EXAMPLE: ; ; ; SEE ALSO: ; ; ; MODIFICATION HISTORY: ; Written by: Your name here, Date. ; ; ;- -- Stephen C Strebel / SKI TO DIE strebel@sma.ch / and Swiss Meteorological Institute, Zuerich / LIVE TO TELL ABOUT IT 01 256 93 85 / (and pray for snow)