comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Static Variables in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Static Variables in IDL [message #5924] Wed, 13 March 1996 00:00 Go to next message
santanu is currently offline  santanu
Messages: 8
Registered: March 1996
Junior Member
Hi,
Is there a way to statically allocate variables in IDL ? I would
like to define a static variable in a .pro which is repeatedly called
from an upper level. I am specifically looking for the IDL counterpart
of
static int testint;

I would appreciate any help in this regard,

Thanks
Santanu
santanu@uiuc.edu
Re: Static Variables in IDL [message #5994 is a reply to message #5924] Thu, 14 March 1996 00:00 Go to previous message
peter is currently offline  peter
Messages: 80
Registered: February 1994
Member
Santanu Bhattacharyya (santanu@ux7.cso.uiuc.edu) wrote:
: Hi,
: Is there a way to statically allocate variables in IDL ? I would
: like to define a static variable in a .pro which is repeatedly called
: from an upper level. I am specifically looking for the IDL counterpart
: of
: static int testint;

: I would appreciate any help in this regard,
:
: Thanks
: Santanu
: santanu@uiuc.edu

Place it in a common block. Declare the common block everywhere you
want the variable to be in scope.

Peter


--------------------------------
Peter Webb, HP Labs Medical Dept
E-Mail: peter_webb@hpl.hp.com
Phone: (415) 813-3756
Re: Static Variables in IDL [message #5996 is a reply to message #5924] Thu, 14 March 1996 00:00 Go to previous message
rivers is currently offline  rivers
Messages: 228
Registered: March 1991
Senior Member
In article <4i8geg$5fv@vixen.cso.uiuc.edu>, santanu@eehpx22.cen.uiuc.edu
(S Bhattacharyya) writes:
> rivers@cars3.uchicago.edu (Mark Rivers) writes:
>
> Pardon me if I appear a bit obtuse, but I am still a little confused. I am
> under the impression that the common block declaration is equivalent to
> C's global declaration. What I would like to have is a bit of non re-entrant
> code in a standalone function (.pro). I want an IDL .pro that does the
> following::
>
> main()
> {
> for(;;) non_rEntrant();
> }
> non_rEntrant()
> {
> static int block=1;
>
> if (block == 1){
> puts("This is executed only once");
> block=0;
> }
> puts("And this is done over and over again");
> }
>
> The following does exactly the same thing ----------------
>
> pro test
> common SHARE,block
> block=1
>
> repeat begin
> call_procedure,'non_rEntrant'
> endrep until block eq 1
> end
>
> pro non_rEntrant
> common SHARE,block
> if block eq 1 then begin print,'This is executed only once' & block=0 & endif
> print,'And this is done over and over again'
> end
>
> But the two lower level function/pro's are not the same, the
> C version is standalone, how do I make the IDL pro non_rEntrant behave
> in the same way ?

Change your IDL example to the following:

pro test
while (1) call_procedure,'non_rEntrant'
end

pro non_rEntrant
common SHARE,block
if (n_elements(block) eq 0) then begin
print,'This is executed only once'
block=0
endif
print,'And this is done over and over again'
end

The key is n_elements(). If non_rEntrant has never been called then block is
undefined and n_elements(block)=0.

____________________________________________________________
Mark Rivers (312) 702-2279 (office)
CARS (312) 702-9951 (secretary)
Univ. of Chicago (312) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
Re: Static Variables in IDL [message #5997 is a reply to message #5924] Thu, 14 March 1996 00:00 Go to previous message
santanu is currently offline  santanu
Messages: 8
Registered: March 1996
Junior Member
rivers@cars3.uchicago.edu (Mark Rivers) writes:

> In article <4i7ara$606@vixen.cso.uiuc.edu>, santanu@ux7.cso.uiuc.edu (Santanu Bhattacharyya) writes:
>> Hi,
>> Is there a way to statically allocate variables in IDL ? I would
>> like to define a static variable in a .pro which is repeatedly called
>> from an upper level. I am specifically looking for the IDL counterpart
>> of
>> static int testint;
>>

> Yes, it is easy. Use a common block. Make the name of the common block unique
> enough that you can be sure it won't conflict with common blocks used in other
> procedures.

> common unique_name, testint
> testint = 14


Pardon me if I appear a bit obtuse, but I am still a little confused. I am
under the impression that the common block declaration is equivalent to
C's global declaration. What I would like to have is a bit of non re-entrant
code in a standalone function (.pro). I want an IDL .pro that does the
following::

main()
{
for(;;) non_rEntrant();
}
non_rEntrant()
{
static int block=1;

if (block == 1){
puts("This is executed only once");
block=0;
}
puts("And this is done over and over again");
}

The following does exactly the same thing ----------------

pro test
common SHARE,block
block=1

repeat begin
call_procedure,'non_rEntrant'
endrep until block eq 1
end

pro non_rEntrant
common SHARE,block
if block eq 1 then begin print,'This is executed only once' & block=0 & endif
print,'And this is done over and over again'
end

But the two lower level function/pro's are not the same, the
C version is standalone, how do I make the IDL pro non_rEntrant behave
in the same way ?
I really appreciate the help,
Thanks,
Santanu
santanu@uiuc.edu

> testint will have the value 14 the next time the .pro file is called.

> ____________________________________________________________
> Mark Rivers (312) 702-2279 (office)
> CARS (312) 702-9951 (secretary)
> Univ. of Chicago (312) 702-5454 (FAX)
> 5640 S. Ellis Ave. (708) 922-0499 (home)
> Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: does Precision Visuals have a web site?
Next Topic: Widget Bulider on Mac OS

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 00:43:57 PDT 2025

Total time taken to generate the page: 1.43925 seconds