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

Home » Public Forums » archive » Compile Problem with IDL5.2
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
Compile Problem with IDL5.2 [message #16331] Wed, 21 July 1999 00:00 Go to next message
joerg.mosthaf is currently offline  joerg.mosthaf
Messages: 5
Registered: July 1999
Junior Member
Hi
I got a little problem with compiling programms in IDL5.2. Usually everything
works just fine, but sometimes (about 1 in 5) some procedure or function just
doesn't compile and I get an "undefined variablename"-error with the name of
the procedure as undefined variablename. If I compile the programm again after
the error, it usually runs fine.
All my procedures are in one file and the main procedure is the last one.
Anyone got a similar problem solved or knows anything about why this happens?

Thanks,
Joerg Mosthaf
Neurochirurgie
Kopfklinik Heidelberg
Re: Compile Problem with IDL5.2 [message #16379 is a reply to message #16331] Fri, 23 July 1999 00:00 Go to previous message
Pavel Romashkin is currently offline  Pavel Romashkin
Messages: 166
Registered: April 1999
Senior Member
Joerg Mosthaf wrote:

> Oh, I see. Yeah, that could be a problem, as the Program kinda 'evolved'
> from some test routines which got routines and subroutines added. I just
> assumed, that IDL compiles all modules in a file before executing them.
> Well ok, back to some re-ordering.

Don't waste your time re-ordering. I started out this way but came to the
conclusion that David just gave: place each routine in its own file, name
the file accordingly and everything will be always ready, no matter how you
will develop it in the future. IDL will compile each routine whenever its
needed.
Cheers,
Pavel
Re: Compile Problem with IDL5.2 [message #16389 is a reply to message #16331] Fri, 23 July 1999 00:00 Go to previous message
joerg.mosthaf is currently offline  joerg.mosthaf
Messages: 5
Registered: July 1999
Junior Member
David Fanning <davidf@dfanning.com> wrote:
: Joerg Mosthaf (joerg.mosthaf@urz.uni-heidelberg.de) writes:

<snip>

: function, MYFUNCTION, that isn't compiled until *after* UTILITY is
: compiled. As a result, "myfunction" has been registered with IDL
: as a variable.

: The problem is easily solved (without resorting to FORWARD_FUNCTION) by
: moving the function ahead of the UTILITY procedure in the file:

: **********************************************
: FUNCTION myfunction, number
: RETURN, Randomu(seed, number)
: END

: PRO utility
: value = myfunction(5)
: END

: PRO main
: utility
: print, myfunction(3)
: END
: **********************************************

: Now, when I call it:

: IDL> main
: % Compiled module: MAIN.
: 0.383502 0.653919 0.0668422

: Cheers,

: David

: --
: David Fanning, Ph.D.
: Fanning Software Consulting
: Phone: 970-221-0438 E-Mail: davidf@dfanning.com
: Coyote's Guide to IDL Programming: http://www.dfanning.com/
: Toll-Free IDL Book Orders: 1-888-461-0155

Oh, I see. Yeah, that could be a problem, as the Program kinda 'evolved'
from some test routines which got routines and subroutines added. I just
assumed, that IDL compiles all modules in a file before executing them.
Well ok, back to some re-ordering.

Thanks alot,

Joerg Mosthaf
Re: Compile Problem with IDL5.2 [message #16403 is a reply to message #16331] Thu, 22 July 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Joerg Mosthaf (joerg.mosthaf@urz.uni-heidelberg.de) writes:

> Well, thanks for answering so fast, but this is probably not the cause of the
> problem, as I can see in the status-windows that all routines, including the
> offending one, are compiled. At least I presume that when IDL says
> % Compiled module: PatData
> that it really did that and compiled the function. But still it sometimes
> cannot find said routine when executing.
> I will try the suggestion in the second posting and report back.

Here is an illustration of what is going on for you.

Here is my program file, called "main.pro"

**********************************************
PRO utility
value = myfunction(5)
END

FUNCTION myfunction, number
RETURN, Randomu(seed, number)
END

PRO main
utility
print, myfunction(3)
END
**********************************************

When I run this program, I get this:

IDL> main
% Compiled module: MAIN.
% Variable is undefined: MYFUNCTION.
% Execution halted at: UTILITY 2 C:\RSI\IDL52\DAVID\main.pro
% MAIN 10 C:\RSI\IDL52\DAVID\main.pro
% $MAIN$

This happens even if I compile the program first:

IDL> .compile main
% Compiled module: UTILITY.
% Compiled module: MYFUNCTION.
% Compiled module: MAIN.
IDL> main
% Variable is undefined: MYFUNCTION.
% Execution halted at: UTILITY 2 C:\RSI\IDL52\DAVID\main.pro
% MAIN 10 C:\RSI\IDL52\DAVID\main.pro
% $MAIN$

The problem here is that the first module, UTILITY, is calling the
function, MYFUNCTION, that isn't compiled until *after* UTILITY is
compiled. As a result, "myfunction" has been registered with IDL
as a variable.

The problem is easily solved (without resorting to FORWARD_FUNCTION) by
moving the function ahead of the UTILITY procedure in the file:

**********************************************
FUNCTION myfunction, number
RETURN, Randomu(seed, number)
END

PRO utility
value = myfunction(5)
END

PRO main
utility
print, myfunction(3)
END
**********************************************

Now, when I call it:

IDL> main
% Compiled module: MAIN.
0.383502 0.653919 0.0668422

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Compile Problem with IDL5.2 [message #16404 is a reply to message #16331] Thu, 22 July 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Joerg Mosthaf (joerg.mosthaf@urz.uni-heidelberg.de) writes:

> Well, thanks for answering so fast, but this is probably not the cause of the
> problem, as I can see in the status-windows that all routines, including the
> offending one, are compiled. At least I presume that when IDL says
> % Compiled module: PatData
> that it really did that and compiled the function. But still it sometimes
> cannot find said routine when executing.
> I will try the suggestion in the second posting and report back.

Oh, I'm certain it got compiled. My contention is that
it didn't get compiled *BEFORE* it was called the first
time. :-)

FORWARD_FUNCTION will help you out. But I would rather you
solve the underlying problem rather than relying on
FORWARD_FUNCTION to bail you out.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Compile Problem with IDL5.2 [message #16405 is a reply to message #16331] Thu, 22 July 1999 00:00 Go to previous message
joerg.mosthaf is currently offline  joerg.mosthaf
Messages: 5
Registered: July 1999
Junior Member
David Fanning <davidf@dfanning.com> wrote:
: Joerg Mosthaf (joerg.mosthaf@urz.uni-heidelberg.de) writes:

<snip>

: This is a classic symptom of a function being called
: before it is compiled, so I am dubious about your statement
: that all the procedures and functions are in a single file,
: with the main procedure as the last one.

: I presume you know that any procedure or function in front
: of the last module should be utility routines for the last
: module? That is to say, one way this could be happening
: (the "1 in 5" strongly suggests it) is that you have
: a function in the "main" file that you are calling from
: within some other program. If that function gets called
: before the main program is called, then you will get
: this error.

: If this is the case, then you want to take that
: function module out and put it in its own file. That
: way both programs will be able to use it without
: running into this problem.

: Cheers,

: David
: --
: David Fanning, Ph.D.
: Fanning Software Consulting
: Phone: 970-221-0438 E-Mail: davidf@dfanning.com
: Coyote's Guide to IDL Programming: http://www.dfanning.com/
: Toll-Free IDL Book Orders: 1-888-461-0155

Well, thanks for answering so fast, but this is probably not the cause of the
problem, as I can see in the status-windows that all routines, including the
offending one, are compiled. At least I presume that when IDL says
% Compiled module: PatData
that it really did that and compiled the function. But still it sometimes
cannot find said routine when executing.
I will try the suggestion in the second posting and report back.

Thanks,
Joerg Mosthaf
Re: Compile Problem with IDL5.2 [message #16410 is a reply to message #16331] Thu, 22 July 1999 00:00 Go to previous message
Justin Ashmall is currently offline  Justin Ashmall
Messages: 15
Registered: May 1999
Junior Member
David Fanning <davidf@dfanning.com> wrote in message
news:MPG.11ff7c1240fcc81498983b@news.frii.com...
> Joerg Mosthaf (joerg.mosthaf@urz.uni-heidelberg.de) writes:
>
>> I got a little problem with compiling programms in IDL5.2. Usually
everything
>> works just fine, but sometimes (about 1 in 5) some procedure or function
just
>> doesn't compile and I get an "undefined variablename"-error with the
name of
>> the procedure as undefined variablename. If I compile the programm again
after
>> the error, it usually runs fine.
>> All my procedures are in one file and the main procedure is the last
one.
>
Further to what David has said if, like me, you're keen to keep all your
functions for one task in one file you may be able to get around the problem
by cunning ordering of your fucntions in the file, or declare the
troublesome function as a function (and not a variable) at the top of the
file with:
FORWARD_FUNCTION my_function
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: calling call_external MANY times
Next Topic: Re: How can i get SCR_XSIZE, SCR_YSIZE of WIDGET_BASE

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

Current Time: Wed Oct 08 17:25:58 PDT 2025

Total time taken to generate the page: 0.00551 seconds