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

Home » Public Forums » archive » Re: regarding scope of variables
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
Re: regarding scope of variables [message #46501] Sun, 27 November 2005 01:09
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
IDLmastertobe wrote:

> Thanks Dr.Fanning. I never used pointers IDL. It looks like the variable
> "yarr" only exists in this one procedure and as soon as the procedure is
> called again, "yarr" is no longer defined if !firsty is not 1. Is there a
> way to declear a global dynamic variable that can preserve value when the
> procedure is called multiple times and the size of the variable can vary
> depending on the array we are copying? such as Vector function in C++ and
> JAVA. Thank you.

Follow Davids advice

cheers
Reimar
Re: regarding scope of variables [message #46508 is a reply to message #46501] Sat, 26 November 2005 06:51 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
IDLmastertobe writes:

> Thanks Dr.Fanning. I never used pointers IDL. It looks like the variable
> "yarr" only exists in this one procedure and as soon as the procedure is
> called again, "yarr" is no longer defined if !firsty is not 1. Is there a
> way to declear a global dynamic variable that can preserve value when the
> procedure is called multiple times and the size of the variable can vary
> depending on the array we are copying? such as Vector function in C++ and
> JAVA.

I think you are looking for a pointer. :-)

You might like to read the pointer tutorial:

http://www.dfanning.com/misc_tips/pointers.html

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: regarding scope of variables [message #46509 is a reply to message #46508] Sat, 26 November 2005 01:19 Go to previous message
IDLmastertobe is currently offline  IDLmastertobe
Messages: 54
Registered: June 2004
Member
Thanks Dr.Fanning. I never used pointers IDL. It looks like the variable
"yarr" only exists in this one procedure and as soon as the procedure is
called again, "yarr" is no longer defined if !firsty is not 1. Is there a
way to declear a global dynamic variable that can preserve value when the
procedure is called multiple times and the size of the variable can vary
depending on the array we are copying? such as Vector function in C++ and
JAVA. Thank you.
Re: regarding scope of variables [message #46510 is a reply to message #46509] Fri, 25 November 2005 20:42 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
IDLmastertobe writes:

> Hi, I have an array of data and I am trying to keep a copy of it so that i
> can restore the origianl data after certain operations. however I found
> everytime it reiterates the function, the variable that keeps the copy
> would go out of scope and my copy is gone. following is part of my code:
>
> if(size(ydata, /n_dimensions) eq 3) then begin
> if(!firsty eq 1) then begin
> yarr = ydata
> !firsty=0
> endif
> ydata = smooth(yarr, [1, !smo, !smo])
> oyimage->SetProperty, data = ydata
> endif
>
> however, the second time when this code is called, the yarr variable
> becomes undefined since it goes out of scope. What it copied in the first
> time is gone. Since I have no information on the size of the array i'm
> copying, i cannot preset an array as system variable to run. Does anyone
> have any idea?

I have a hunch "variable scope" is not your real problem here.
I already see two more system variables in these few lines of
code than I've ever used in an IDL procedure. :-)

Is the real problem that you can't figure out how to pass around
data in a widget program? Have you thought about using pointers?

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: iMap & contouring question
Next Topic: Pointer Type Question

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

Current Time: Wed Oct 08 15:47:27 PDT 2025

Total time taken to generate the page: 0.00435 seconds