Re: current directory [message #34275] |
Mon, 03 March 2003 09:16  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Dear Timm,
good idea in combination whith file_path_name_ext we can save one line.
But if we like to use it in a function then where did the name 'test'
comes from?
regards
Reimar
Timm Weitkamp wrote:
> Dear Ulf and the others,
>
> Maybe I'm missing something, but if the problem is finding the file path
> of a given compiled routine, why not use ROUTINE_INFO with the /SOURCE
> keyword (and, if appropriate, /FUNCTION)? Like this:
>
> IDL> .run test
> IDL> help, /structure, routine_info('test',/source)
> ** Structure <82329dc>, 2 tags, length=16, refs=1:
> NAME STRING 'TEST'
> PATH STRING '/users/weitkamp/idl/test.pro'
>
> Avoids parsing HELP's output (which may even change in future versions of
> IDL). But maybe that takes away all the fun?
>
> And then, admittedly, although ROUTINE_INFO can do a lot of things, one
> thing I think it doesn't do is find out the name of the current routine
> (as HELP, /CALLS does).
>
> Cheers,
> Timm
>
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|
Re: current directory [message #34277 is a reply to message #34275] |
Mon, 03 March 2003 09:05   |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Sat, 01 Mar 2003 07:06:25 -0700, Ulf-Dietrich Braumann wrote:
> Hi,
>
> I wonder if there is some elegant way in IDL to i) determine the
> directory where the current running *.pro file
> is stored in order to
> ii) directly access some other stuff (i.e. images) just placed
> in the same directory as the "calling" *.pro
>
> Thanks and greetings
>
> Ulf-Dietrich
If you're trying to do what I think you're trying to do, here's the recipe
I always use:
source=(routine_info('my_routine',/SOURCE)).PATH
dir=strmid(source,0,strpos(source,path_sep(),/REVERSE_SEARCH ))
It should even be platform independent. You can use the callstack
stuff to find out the calling routine's name programmatically, to
replace "my_routine".
That said, I'm not sure how good of an idea it is to use the code
directories for data storage. You don't want people poking around in
there too much. I use this technique for reading in static data
bundled with the code, but never for writing.
JD
|
|
|
Re: current directory [message #34278 is a reply to message #34277] |
Mon, 03 March 2003 09:00   |
Timm Weitkamp
Messages: 66 Registered: August 2002
|
Member |
|
|
Dear Ulf and the others,
Maybe I'm missing something, but if the problem is finding the file path
of a given compiled routine, why not use ROUTINE_INFO with the /SOURCE
keyword (and, if appropriate, /FUNCTION)? Like this:
IDL> .run test
IDL> help, /structure, routine_info('test',/source)
** Structure <82329dc>, 2 tags, length=16, refs=1:
NAME STRING 'TEST'
PATH STRING '/users/weitkamp/idl/test.pro'
Avoids parsing HELP's output (which may even change in future versions of
IDL). But maybe that takes away all the fun?
And then, admittedly, although ROUTINE_INFO can do a lot of things, one
thing I think it doesn't do is find out the name of the current routine
(as HELP, /CALLS does).
Cheers,
Timm
--
Timm Weitkamp <http://people.web.psi.ch/weitkamp>
|
|
|
Re: current directory [message #34283 is a reply to message #34278] |
Sun, 02 March 2003 07:39   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Reimar Bauer (R.Bauer@fz-juelich.de) writes:
> Here is an other version to make it more readable.
>
> PRO Tester
> Help, Calls=callStack
> r=within_brackets(callStack[0],brackets=['<','('])
> fpe=file_path_name_ext(r)
> print,fpe.path
> END
Oh, my, yes. Even I can figure out what is going on
there. :-)
Well done, Reimar!
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: current directory [message #34284 is a reply to message #34283] |
Sun, 02 March 2003 06:48   |
Ulf-Dietrich Braumann
Messages: 3 Registered: March 2003
|
Junior Member |
|
|
On Sat, 1 Mar 2003, David Fanning wrote:
> Ulf-Dietrich Braumann (braumann@izbi.uni-leipzig.de) writes:
>
>> Ok, the very scaring solution (which in fact also runs under IDL5.0)
>> comes here (just before I go home now ...):
>
> Wow. That could be useful. :-)
>
...
> Remember (those of you who faithfully update your
> IDL version), this requires the obsolete STR_SEP
> function. :-)
Well, due to a sudden ambition I just made a version
without STR_SEP, so here comes another unreadable, but
fairly compatible version :-)
PRO Tester
Help, Calls=callStack
thisRoutine = StrMid(callstack[0],0,StrPos(callstack[0]," "))
callingRoutine = StrMid(callstack[1],0,StrPos(callstack[1]," "))
Print, 'In ' + thisRoutine + ', which is called by ' + $
callingRoutine + '.'
thisRoutine = StrLowCase(thisRoutine) + '.pro'
thePath=StrMid(StrMid(callStack[0], 0, $
StrPos(callStack[0],thisRoutine)), $
StrPos(StrMid(callStack[0], 0, $
StrPos(callStack[0],thisRoutine)),'<')+1, $
StrLen(StrMid(callStack[0], 0, $
StrPos(callStack[0],thisRoutine))) - $
StrPos(StrMid(callStack[0], 0, $
StrPos(callStack[0],thisRoutine)),'<'))
Print, 'The file "' + thisRoutine + '" is in this directory: ' + thePath
END
which e.g. in my test prints out:
IDL> tester
In TESTER, which is called by $MAIN$.
The default path to tester.pro is: G:\
Greetings
Ulf-Dietrich Braumann, PhD
Interdisciplinary Centre for Bioinformatics
University of Leipzig
Kreuzstraße 7b
D-04103 Leipzig
Fed. Rep. of Germany
+49-341-1495114
|
|
|
Re: current directory [message #34285 is a reply to message #34284] |
Sun, 02 March 2003 00:27   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
David Fanning wrote:
> Ulf-Dietrich Braumann (braumann@izbi.uni-leipzig.de) writes:
>
>> Ok, the very scaring solution (which in fact also runs under IDL5.0)
>> comes here (just before I go home now ...):
>
> Wow. That could be useful. :-)
>
> Here is the program stripped of some control characters
> that got embedded somehow when you sent it:
Here is an other version to make it more readable.
I like using functions to get code more readable.
within brackets is a routine which could solve a lot of extraction problems.
one other is within_delimiter which you find in the library too
file_path_name_ext is used to extract from a given file location it's path
it's name and it's extension.
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/within_backets.tar.gz
or as idl binary
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/within_brackets.sav
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/file_path_name_ext.tar.gz
or as idl binary
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/download/file_path_name_ext.sav
PRO Tester
Help, Calls=callStack
r=within_brackets(callStack[0],brackets=['<','('])
fpe=file_path_name_ext(r)
print,fpe.path
END
best regards
Reimar
>
> PRO Tester
> Help, Calls=callStack
> thisRoutine = (Str_Sep(StrCompress(callStack[0])," "))[0]
> callingRoutine = (Str_Sep(StrCompress(callStack[1])," "))[0]
> Print, 'In ' + thisRoutine + ', which is called by ' + $
> callingRoutine + '.'
> thisRoutine = StrLowCase(thisRoutine) + '.pro'
> thePath=strmid(StrMid(callStack[0], 0, $
> StrPos(callStack[0],thisRoutine)), $
> StrPos(StrMid(callStack[0], 0, $
> StrPos(callStack[0],thisRoutine)),'<')+1, $
> StrLen(StrMid(callStack[0], 0, $
> StrPos(callStack[0],thisRoutine))) - $
> StrPos(StrMid(callStack[0], 0, $
> StrPos(callStack[0],thisRoutine)),'<'))
> Print, 'The file "' + thisRoutine + '" is in this directory: ' + thePath
> END
>
> Remember (those of you who faithfully update your
> IDL version), this requires the obsolete STR_SEP
> function. :-)
>
> Cheers,
>
> David
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|
Re: current directory [message #34286 is a reply to message #34285] |
Sat, 01 March 2003 16:03   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Ulf-Dietrich Braumann (braumann@izbi.uni-leipzig.de) writes:
> Ok, the very scaring solution (which in fact also runs under IDL5.0)
> comes here (just before I go home now ...):
Wow. That could be useful. :-)
Here is the program stripped of some control characters
that got embedded somehow when you sent it:
PRO Tester
Help, Calls=callStack
thisRoutine = (Str_Sep(StrCompress(callStack[0])," "))[0]
callingRoutine = (Str_Sep(StrCompress(callStack[1])," "))[0]
Print, 'In ' + thisRoutine + ', which is called by ' + $
callingRoutine + '.'
thisRoutine = StrLowCase(thisRoutine) + '.pro'
thePath=strmid(StrMid(callStack[0], 0, $
StrPos(callStack[0],thisRoutine)), $
StrPos(StrMid(callStack[0], 0, $
StrPos(callStack[0],thisRoutine)),'<')+1, $
StrLen(StrMid(callStack[0], 0, $
StrPos(callStack[0],thisRoutine))) - $
StrPos(StrMid(callStack[0], 0, $
StrPos(callStack[0],thisRoutine)),'<'))
Print, 'The file "' + thisRoutine + '" is in this directory: ' + thePath
END
Remember (those of you who faithfully update your
IDL version), this requires the obsolete STR_SEP
function. :-)
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: current directory [message #34287 is a reply to message #34286] |
Sat, 01 March 2003 14:44   |
Ulf-Dietrich Braumann
Messages: 3 Registered: March 2003
|
Junior Member |
|
|
Thanks a lot, you two guys David and Reimar,
both of you had just the solution to my problem!
> Well, I guess because I'm trying to advertise myself as
> a programmer who writes code you can understand after I
> go home. :-)
Ok, the very scaring solution (which in fact also runs under IDL5.0)
comes here (just before I go home now ...):
PRO Tester
Help, Calls=callStack
thisRoutine = (Str_Sep(StrCompress(callStack[0])," "))[0]
callingRoutine = (Str_Sep(StrCompress(callStack[1])," "))[0]
Print, 'In ' + thisRoutine + ', which is called by ' + $
callingRoutine + '.'
thisRoutine = StrLowCase(thisRoutine) + '.pro'
thePath=strmid(StrMid(callStack[0], 0, StrPos(callStack[0],thisRoutine)),$
StrPos(StrMid(callStack[0], 0, StrPos(callStack[0],thisRoutine)),'<')+1,$
StrLen(StrMid(callStack[0], 0, StrPos(callStack[0],thisRoutine))) - $
StrPos(StrMid(callStack[0], 0, StrPos(callStack[0],thisRoutine)),'<'))
Print, 'The default path to ' + thisRoutine + ' is: ' + thePath
END
Greetings
Ulf-Dietrich
Ulf-Dietrich Braumann, PhD
Interdiscpilinary Centre for Bioinformatics
University of Leipzig
Kreuzstraße 7b
D-04103 Leipzig
+49-341-1495114
|
|
|
Re: current directory [message #34289 is a reply to message #34287] |
Sat, 01 March 2003 11:35   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Reimar Bauer (R.Bauer@fz-juelich.de) writes:
> Dear David why not exchange the file_which by
>
> ;thePath = File_Which(thisRoutine, /Include_Current)
>
> exchanged to
>
> thePath = (strsplit(StrMid(callStack[0], 0, StrPos(callStack[0],$
> thisRoutine)),'<',/extr))[1]
>
> All is known already
Well, I guess because I'm trying to advertise myself as
a programmer who writes code you can understand after I
go home. :-)
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: current directory [message #34292 is a reply to message #34289] |
Sat, 01 March 2003 10:10   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
David Fanning wrote:
> David Fanning (david@dfanning.com) writes:
>
>> But here is some code that gets you as far as you
>> can get to:
>
> Whoops! I see I used the archaic STR_SEP routine in
> that program. That is an obsolete IDL routine that I
> still have on my path for historical reasons. Better
> to use the modern STRSPLIT function:
Dear David why not exchange the file_which by
;thePath = File_Which(thisRoutine, /Include_Current)
exchanged to
thePath = (strsplit(StrMid(callStack[0], 0, StrPos(callStack[0],$
thisRoutine)),'<',/extr))[1]
All is known already
cheers
Reimar
>
> ;----------------------------------------------------------- -------
> PRO Tester
> Help, Calls=callStack
> thisRoutine = (StrSplit(StrCompress(callStack[0])," ", /Extract))[0]
> callingRoutine = (StrSplit(StrCompress(callStack[1])," ", /Extract))[0]
> Print, 'In ' + thisRoutine + ' which is called by ' + callingRoutine +
> '.'
> thisRoutine = StrLowCase(thisRoutine) + '.pro'
> thePath = File_Which(thisRoutine, /Include_Current)
> thePath = StrMid(thePath, 0, StrPos(thepath, thisRoutine))
> Print, 'The default path to ' + thisRoutine + ' is: ' + thePath
> END
> ;----------------------------------------------------------- -------
>
> Cheers,
>
> David
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|
|
Re: current directory [message #34297 is a reply to message #34293] |
Sat, 01 March 2003 07:01   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning (david@dfanning.com) writes:
> But here is some code that gets you as far as you
> can get to:
Whoops! I see I used the archaic STR_SEP routine in
that program. That is an obsolete IDL routine that I
still have on my path for historical reasons. Better
to use the modern STRSPLIT function:
;----------------------------------------------------------- -------
PRO Tester
Help, Calls=callStack
thisRoutine = (StrSplit(StrCompress(callStack[0])," ", /Extract))[0]
callingRoutine = (StrSplit(StrCompress(callStack[1])," ", /Extract))[0]
Print, 'In ' + thisRoutine + ' which is called by ' + callingRoutine +
'.'
thisRoutine = StrLowCase(thisRoutine) + '.pro'
thePath = File_Which(thisRoutine, /Include_Current)
thePath = StrMid(thePath, 0, StrPos(thepath, thisRoutine))
Print, 'The default path to ' + thisRoutine + ' is: ' + thePath
END
;----------------------------------------------------------- -------
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: current directory [message #34298 is a reply to message #34297] |
Sat, 01 March 2003 06:51   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Ulf-Dietrich Braumann (braumann@izbi.uni-leipzig.de) writes:
> I wonder if there is some elegant way in IDL to
> i) determine the directory where the current running *.pro file
> is stored in order to
> ii) directly access some other stuff (i.e. images) just placed
> in the same directory as the "calling" *.pro
I'm not exactly sure what you are asking for. You
can certainly determine the name of the program
module that you are currently in, and the name
of the program module that called you.
And you can find the "default" location of the
current module you are in by using File_Which.
But I don't think IDL keeps track of which of the
10 files you have named "junk.pro" is currently the
compiled one. In other words, you can find out
which of those 10 junk.pro files would be called
if you opened up an IDL session and typed "junk",
but you can't determine which of the 10 is actually
being used in that IDL session.
I suppose this can be good news or bad news depending
upon what you are trying to do here. :-)
But here is some code that gets you as far as you
can get to:
;****************************************************
PRO Tester
Help, Calls=callStack
thisRoutine = (Str_Sep(StrCompress(callStack[0])," "))[0]
callingRoutine = (Str_Sep(StrCompress(callStack[1])," "))[0]
Print, 'In ' + thisRoutine + ', which is called by ' +
callingRoutine + '.'
thisRoutine = StrLowCase(thisRoutine) + '.pro'
thePath = File_Which(thisRoutine, /Include_Current)
thePath = StrMid(thePath, 0, StrPos(thepath, thisRoutine))
Print, 'The default path to ' + thisRoutine + ' is: ' + thePath
END
;****************************************************
Called like this:
IDL> tester
It produces this output:
In TESTER, which is called by $MAIN$.
The default path to tester.pro is: C:\IDL\DAVID\
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: current directory [message #34353 is a reply to message #34275] |
Tue, 04 March 2003 02:13  |
Timm Weitkamp
Messages: 66 Registered: August 2002
|
Member |
|
|
On 03.03.03 at 18:16 +0100, Reimar Bauer wrote:
> Dear Timm,
>
> good idea in combination whith file_path_name_ext we can save one line.
> But if we like to use it in a function then where did the name 'test'
> comes from?
That's what I meant when I said that ROUTINE_INFO does not give you the
name of the current routine or of any of its callers, whereas HELP, /CALLS
does. I feel there should be a better way than HELP to do that sort of
query from inside a routine, and I'd be interested to learn if there
actually is one.
Timm
--
Timm Weitkamp <http://people.web.psi.ch/weitkamp>
|
|
|