Re: Global variables and command line [message #11568 is a reply to message #11566] |
Fri, 17 April 1998 00:00   |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
Daniel SAGE wrote:
>
> Hello,
>
> I would like use the variables created in the input command line inside
> the procedures/functions. But in my application where I automatically
> generate IDL code, I can't use the common mechanism or passing by
> parameters.
>
> pro run
> resolve_routine, "test"
> call_procedure, "test"
> end
>
> pro test
> common var
> print, v1
> print, v2
> end
>
> IDL> common var, v1
> IDL> v1=111
> IDL> v2=222
> % Compiled module: RUN.
> % Compiled module: TEST.
> IDL> run
> % Procedure was compiled while active: RUN. Returning.
> % Compiled module: TEST.
> 111
> % PRINT: Variable is undefined: V2.
> % Execution halted at: TEST 10 HD:Desktop Folder:test.pro
>
> % $MAIN$
>
> How is it possible to make V2 visible inside the test procedure when I
> can't pass the parameters with the run procedure ?
>
> Thanks
>
Your problem is that you define your common block only with v1 - and
once it is defined, you can't change it!!
The above example will work if you type common var,v1,v2 on the command
line. However, a better approach would probably be to call EXECUTE (or
CALL_PROCEDURE, CALL_FUNCTION) to "execute" your procedure or function
that you generate automatically. There should always be some way of
parameter passing. Even if you don't know how many variables you will
need in advance neither their name, you could still construct a
structure and pass that into the function/procedure. I have a CHKSTRU
function in my library (html below) which you can use to see if a
certain structure tag is defined.
Hope this helps,
Martin
--
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Earth&Planetary Sciences, Harvard University
186 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA
phone: (617)-496-8318
fax : (617)-495-4551
e-mail: mgs@io.harvard.edu
IDL-homepage: http://www-as.harvard.edu/people/staff/mgs/idl/
------------------------------------------------------------ -------
|
|
|