Re: linking programs/ procedures [message #19779] |
Wed, 26 April 2000 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
J.D. Smith (jdsmith@astro.cornell.edu) writes:
> Just trying to defend poor little "@" from the onslaught.
I must be going soft, and my membership in the Curmudgeon Club
will certainly be put to a vote, but I'll except this as one
possible reason to use the @ sign. :-)
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: linking programs/ procedures [message #19780 is a reply to message #19779] |
Wed, 26 April 2000 00:00  |
John-David T. Smith
Messages: 384 Registered: January 2000
|
Senior Member |
|
|
David Fanning wrote:
>
> Troy Carter (tcarter@princeton.edu) writes:
>
>> You can also use:
>>
>> @/path/to/program.pro
>>
>> At the beginning of your code. This will compile program.pro before
>> running the rest of your code.
>
> Uh, no, not exactly. It will put the program.pro code *into*
> the program file as if you had actually typed it there. It
> doesn't compile anything, and it is completely unnecessary. :-(
Oh David, always making these sweeping statements to entice my refutation...
I suppose you meant that it's unnecessary in the case of running a routine from
"program" elsewhere. For this you are correct. But it does have its uses. My
favorite is with common blocks (whose use should, of course, be limited). As
everyone knows, once a common block is defined, you can simple reference it
with:
common my_common
i.e. without any of the variables listed out. This saves typing, but more
importantly, leaves only one location which needs to be modified when common
block variables are added or removed. But there's a catch... you have to
compile the defining routine *first*... i.e. the point of entry into a suite of
programs which share the common block must be a single file/routine. If you try
to enter elsewhere, it will generate a compiler error, and refuse to run.. you
can't simply "call" a defining routine at the beginning of each routine in the
suite either, since it's a compile time, not a run-time error. So, you resort
to making *all* of the routines a defining routine for the common block, but
including all the variables in each common block statement. But this
unfortunately means modification requires you to change each and every one (over
30 places for one of my common blocks) so you're back where you started. But
enter @ to save the day. In a file, call it my_common.pro, put:
common my_common, var1, var2, var3, thefinalvar
or whatever. Then, in each routine which needs it, simply put:
@my_common
in place of "common my_common", and you get the best of both worlds.... single
point of modification, yet every routine capable of defining the common block.
If you need to perform a standard version lookup or some such in all your
routines, you could also include it in my_common.
Just trying to defend poor little "@" from the onslaught.
JD
--
J.D. Smith |*| WORK: (607) 255-5842
Cornell University Dept. of Astronomy |*| (607) 255-6263
304 Space Sciences Bldg. |*| FAX: (607) 255-5875
Ithaca, NY 14853 |*|
|
|
|
Re: linking programs/ procedures [message #19781 is a reply to message #19779] |
Wed, 26 April 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Troy Carter (tcarter@princeton.edu) writes:
> OK. sorry, it doesn't exactly compile it separately, but I believe it
> does what our friend asking the question wanted :). Sometimes it can be
> necessary: I am part of an experimental group that works out of one unix
> account (as a solution to the problem of who owns the data files, maybe
> not the best solution -- afs permissions might be better). So, we all
> use the same routines, but someone is always doing something stupid like
> copying a routine out of one directory into another. So sometimes
> several versions exist in severl places (all of which are in the idl
> path). So this causes much frustration, and it has become easier to
> target the specific file you are after with the "@" include statement.
> Sure, we should do a better job of keeping often used routines in one
> place with one version (I am trying to use RCS/CVS now to help out with
> that), but just to be sure, the "@" makes a lot of sense.
Oh, well, if your life is a mess ... Then, of course, anything
that works. :-)
Cheers,
David
P.S. Let's just say if you know what you are doing you can
get away with a LOT of things. I'm just not sure our friend is
at that stage yet. :-)
--
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: linking programs/ procedures [message #19783 is a reply to message #19779] |
Wed, 26 April 2000 00:00  |
Troy Carter
Messages: 5 Registered: April 2000
|
Junior Member |
|
|
OK. sorry, it doesn't exactly compile it separately, but I believe it
does what our friend asking the question wanted :). Sometimes it can be
necessary: I am part of an experimental group that works out of one unix
account (as a solution to the problem of who owns the data files, maybe
not the best solution -- afs permissions might be better). So, we all
use the same routines, but someone is always doing something stupid like
copying a routine out of one directory into another. So sometimes
several versions exist in severl places (all of which are in the idl
path). So this causes much frustration, and it has become easier to
target the specific file you are after with the "@" include statement.
Sure, we should do a better job of keeping often used routines in one
place with one version (I am trying to use RCS/CVS now to help out with
that), but just to be sure, the "@" makes a lot of sense.
-Troy
David Fanning wrote:
>
> Troy Carter (tcarter@princeton.edu) writes:
>
>> You can also use:
>>
>> @/path/to/program.pro
>>
>> At the beginning of your code. This will compile program.pro before
>> running the rest of your code.
>
> Uh, no, not exactly. It will put the program.pro code *into*
> the program file as if you had actually typed it there. It
> doesn't compile anything, and it is completely unnecessary. :-(
>
> 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
--
Troy Carter
tcarter@princeton.edu
|
|
|
Re: linking programs/ procedures [message #19785 is a reply to message #19779] |
Wed, 26 April 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Troy Carter (tcarter@princeton.edu) writes:
> You can also use:
>
> @/path/to/program.pro
>
> At the beginning of your code. This will compile program.pro before
> running the rest of your code.
Uh, no, not exactly. It will put the program.pro code *into*
the program file as if you had actually typed it there. It
doesn't compile anything, and it is completely unnecessary. :-(
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: linking programs/ procedures [message #19786 is a reply to message #19779] |
Wed, 26 April 2000 00:00  |
Troy Carter
Messages: 5 Registered: April 2000
|
Junior Member |
|
|
You can also use:
@/path/to/program.pro
At the beginning of your code. This will compile program.pro before
running the rest of your code.
-Troy
Sameer Nigam wrote:
>
> hi!
> how do i link two-three files during compilation?
>
> also if i have a procedure X that is written in a file say X.pro and i
> want to call it as a subroutine in another procedure Y that is in another
> file Y, can i just call that procedure by reference/name and if so how do
> i do it?
>
> any suggestions would be most welcome
--
Troy Carter
tcarter@princeton.edu
|
|
|
Re: linking programs/ procedures [message #19787 is a reply to message #19779] |
Wed, 26 April 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Sameer Nigam (samnigam@CS.Arizona.EDU) writes:
> how do i link two-three files during compilation?
>
> also if i have a procedure X that is written in a file say X.pro and i
> want to call it as a subroutine in another procedure Y that is in another
> file Y, can i just call that procedure by reference/name and if so how do
> i do it?
Any "command" name that you wish to call from the IDL
command line or from another procedure or function should
be in a file of the same name as the command in the IDL "path".
If there are multiple procedures and functions in the file,
then the procedure or function that has the same name as the file
should be the LAST procedure or function in the file.
If a procedure or function is in a file, but it does NOT
have the same name as the file, then you can generally assume
this is a utility routine for the procedure or function that
*does* have the same name as the file. That is to say, no one
plans to use that "command" outside of this file. If it were
found to be more useful than just a utility routine, it would
be yanked out of that file and put in another file that
was named appropriately.
In this way, you NEVER have to worry about things being
compiled when they are needed.
> any suggestions would be most welcome
Have you thought about a good book about IDL? :-)
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: linking programs/ procedures [message #19790 is a reply to message #19779] |
Wed, 26 April 2000 00:00  |
Alex Schuster
Messages: 124 Registered: February 1997
|
Senior Member |
|
|
Sameer Nigam wrote:
> hi!
> how do i link two-three files during compilation?
>
> also if i have a procedure X that is written in a file say X.pro and i
> want to call it as a subroutine in another procedure Y that is in another
> file Y, can i just call that procedure by reference/name
Yes.
> and if so how do i do it?
Wel, just do it. If you call some procedure X in a program, IDL searches
the path for a file x.pro, which it compiles then. Look at $IDL_DIR/lib,
there are many IDL routines, written in IDL.
I your file X contains a procedure Z, then you need to compile the file
x.pro beforehand (.compile x), so IDL can find the routine Z when it
needs it.
Alex
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
|
|
|