calling a function in herself [message #20893] |
Mon, 31 July 2000 00:00  |
J�rg Schliwa
Messages: 12 Registered: April 2000
|
Junior Member |
|
|
Hy to all!
I have a file with the main-procedure and some functions in it. When I'm in
the function e.g h_wahl I want to call the function h_wahl again. Is that
possible? When I compile the file, the expression h_wahl is not known in
h_wahl.
e.g.
;procedure rasterung.pro
Function H_Wahl(a,b,Steig=steig,Abstand=abstand)
If Keyword_Set(abstand) Then .....
If Keyword_Set(steig) Then Begin
...
return, H_Wahl(c,d,/abstand)
Endif
End
pro rasterung...
Any suggestions?
Thanks in advance,
J�rg Schliwa
|
|
|
|
Re: calling a function in herself [message #20975 is a reply to message #20893] |
Mon, 31 July 2000 00:00   |
promashkin
Messages: 169 Registered: December 1999
|
Senior Member |
|
|
Will FORWARD_FUNCTION do the trick? Or, try placing the new "COMPILE_OPT
IDL2" instructuin at the beginning your code. It will enforce strict
array subscripting using only [ ... ], and anything with ( ... ) will be
considered a function.
Cheers,
Pavel
"J�rg Schliwa" wrote:
>
> Hy to all!
>
> I have a file with the main-procedure and some functions in it. When I'm in
> the function e.g h_wahl I want to call the function h_wahl again. Is that
> possible? When I compile the file, the expression h_wahl is not known in
> h_wahl.
>
> e.g.
> ;procedure rasterung.pro
>
> Function H_Wahl(a,b,Steig=steig,Abstand=abstand)
> If Keyword_Set(abstand) Then .....
>
> If Keyword_Set(steig) Then Begin
> ...
> return, H_Wahl(c,d,/abstand)
> Endif
> End
>
> pro rasterung...
>
> Any suggestions?
>
> Thanks in advance,
> J�rg Schliwa
|
|
|
Re: calling a function [message #32877 is a reply to message #20893] |
Fri, 15 November 2002 17:34  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Surendar Jeyadev (jeyadev@wrc.xerox.bounceback.com) writes:
>> No sense adding more confusion to an already confusing
>> situation. The average IDL newcomer is totally perplexed
>> about why a .RUN command doesn't run a damn thing, although
>
> Doesn't is run the main programme, if that is what comes
> after it?
Indeed it does. And I even used a main program
back in 1977 sometime.
>
>> we long-timers take it as a matter of course.
>
> Not completely illogical, is it?
Did I say "illogical"!? I meant "perverse". :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
|
Re: calling a function [message #32895 is a reply to message #20893] |
Fri, 15 November 2002 10:53  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning (david@dfanning.com) writes:
> Please, let's ALL train ourselves to use .COMPILE when we
> want to compile something. That way we won't all look like
> idiots to the new users. :-)
Oh, my gosh! I inadvertently violated Commandment Number
3 of the Internet Posters Guild:
Commandment 3: Don't EVER use the words idiot, jerk,
numskull, etc. in an Internet communication unless
referring specifically to yourself and you alone. Those
words are loaded and will be misinterpreted by nearly
everyone who reads them, no matter how many smiley faces you
use at the end of the sentence.
My apologies to anyone and everyone. I was simply trying
to make the point that some of the things we do in IDL
don't seem to, uh, make a lot of sense to IDL newcomers.
That's all. :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: calling a function [message #32896 is a reply to message #20893] |
Fri, 15 November 2002 10:39  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
James Kuyper (kuyper@saicmodis.com) writes:
> IDL> .run /non-idl/path/name/glactc.pro
No sense adding more confusion to an already confusing
situation. The average IDL newcomer is totally perplexed
about why a .RUN command doesn't run a damn thing, although
we long-timers take it as a matter of course.
Please, let's ALL train ourselves to use .COMPILE when we
want to compile something. That way we won't all look like
idiots to the new users. :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: calling a function [message #32898 is a reply to message #20893] |
Fri, 15 November 2002 10:24  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
Steve wrote:
>
> Dear all, I have a problem!
> I have a program (main.pro) written in IDL. Then, inside the main.pro
> I want to use a function that I found on Goddard library.
> The function is named glactc.pro, and the calling sequence is the
> following:
> GLACTC, ra, dec, year, gl, gb, j
> How can I call glactc.pro inside main.pro?
If it's really a function (starts with the FUNCTION keyword), then you
have to type:
result = GLACTC(my_ra, my_dec, my_year, my_gl, my_bg, my_j)
On the other hand, if it's a procedure (starts with the PROC keyword),
then you have to type:
GLACTC, my_ra, my_dec, my_year, my_gl, my_bg, my_j
You don't need the 'my_' prefixes, I'm just emphasizing that the names
don't need to match; it's also not an error if they do match.
> After that, when I compile the program, do I have to link
> glactc.pro?If yes, how can I do that?
No. All you have to do is make sure that glactc.pro is in a directory
that's in IDL's search path. That can either be in your current
directory, or in one of the directories listed in the IDL_PATH
environment variable.
Alternatively, you can load glactc.pro, even if it's not in the
IDL_PATH, by
typing:
IDL> .run /non-idl/path/name/glactc.pro
You don't need to add the '.pro' at the end; IDL will figure it out if
you leave it out.
Note: if the name of the file is different from the name of the
procedure or function that you need to execute, then you have to use the
'.run' approach. That's why it's generally a good idea to have the
function and the filename match.
> Is it possible to write "makefile" (like C programming) into IDL?
No, but the reason it's not possible is that it's not really needed.
|
|
|
Re: calling a function [message #32901 is a reply to message #20893] |
Fri, 15 November 2002 08:54  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Steve (Steve.Morris@libero.it) writes:
> I have a program (main.pro) written in IDL. Then, inside the main.pro
> I want to use a function that I found on Goddard library.
> The function is named glactc.pro, and the calling sequence is the
> following:
> GLACTC, ra, dec, year, gl, gb, j
> How can I call glactc.pro inside main.pro?
Just exactly as you did right there. That's it! :-)
> After that, when I compile the program, do I have to link
> glactc.pro?If yes, how can I do that?
You don't have to compile it. IDL will find it and compile
it when it needs it. That is, when it gets to the statement
above in your code. Just put it in a file named glactc.pro
and make sure the procedure GLACTC is the *last* program
module in the file. (This will be true for most of the routines
you get from established libraries, but may not be true for most
of the routines you get from your buddies.)
> Is it possible to write "makefile" (like C programming) into IDL?
Forget makefiles. Forget compiling. You are working with IDL now! :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|