Re: passing string parameter [message #7211 is a reply to message #7207] |
Fri, 18 October 1996 00:00   |
Peter Mason
Messages: 145 Registered: June 1996
|
Senior Member |
|
|
On Wed, 16 Oct 1996, daytime visitor ssg login wrote:
> Hello, I want to write a small help procedure to display breif summaries
> of home made commands.
>
> IDL> helpme, command_name_string
>
> Is there a way to pass command_name_string to the procedure helpme
> without quotes?
If the people using your programs only use IDL to run applications - i.e.,
don't use IDL's command-line functionality, then you might consider
running a little "shell" program to catch certain errors.
I've included an example "shell" program at the end of this posting. It
reads a string from the console, calls EXECUTE() to execute it, and traps
& fixes "undefined variable" errors by turning "variables" into string
constants.
Because it uses EXECUTE(), it doesn't have all of the functionality of the
(proper) IDL command line. e.g., You can't run executive commands
(like ".run") or bring up online help from it. You're also not supposed
to be able to define new variables ( e.g., a=100 ) in it, but this seems
to work (at least, with full IDL on DEC OSF).
I'm sure that any IDL command-line jockey will consider it to be a truly
disgusting hack, but here it is anyway.
Peter Mason
pro shell
; This will stop execute() reporting errors, and will
; also catch ^D etc
catch,e &if (e ne 0) then goto,here
go=1 &s=''
while(go) do begin
here:
try=0
read,s,prom='IDL 2> '
t=strupcase(strtrim(s,2))
if (t eq 'EXIT') or (t eq 'QUIT') then go=0 $
else if (t eq '?') then begin
print,'Sorry, you can''t activate online help from here' &goto,here
endif else begin
there:
if (execute(s) ne 1) then begin ;some error in execute()
if (!error eq -128) then begin ;undefined var - handle it!
try=try+1 &if (try gt 0) then goto,here ;only try to fix once
j=rstrpos(s,',') ;just before problem varname in user's command
if (j le 0) then goto,here ;? - just back to prompt
t=strmid(s,j+1,strlen(s)-j-1) ;the problem varname
s=strmid(s,0,j+1)+"'"+strtrim(t,2)+"'" ;stringify the "varname"
goto,there ;NOW try the execute
endif else begin ;some other error - just report & back to prompt
print,!err_string &print,!syserr_string &goto,here
endelse
endif
endelse
endwhile
return ;you might want EXIT here instead
end
|
|
|