Re: Function to return the current procedure/function [message #67920 is a reply to message #67905] |
Sat, 05 September 2009 09:16   |
maurya
Messages: 16 Registered: February 2009
|
Junior Member |
|
|
On 5 Sep, 19:04, Heinz Stege <public.215....@arcor.de> wrote:
> On Sat, 5 Sep 2009 07:05:31 -0600, David Fanning wrote:
>> maurya writes:
>
>>> Is there any function to return the current procedure/function name
>>> only not all?
>
>>> There is one function "ROUTINE_INFO" which provide information about
>>> all currently-compiled procedures and functions. But, I want to get
>>> the name of the procedure/function using a function (say Routine_Name)
>>> by calling in the same routine. e.g.
>
>>> Pro test_plot
>
>>> plot,findgen(200)
>>> ;
>
>>> print, Routine_Name()
>
>>> end
>
>>> The print function should return 'test_plot'.
>
>> ProgramRootDir does this:
>
>> http://www.dfanning.com/programs/programrootdir.pro
>
>> Cheers,
>
>> David
>
> An alternative approach is the SCOPE_TRACEBACK function, which is part
> of IDL:
>
> IDL> info=scope_traceback(/structure)
> IDL> n=n_elements(info)
> IDL> help,info[n-1],/structure
> ** Structure IDL_TRACEBACK, 8 tags, length=36, data length=36:
> ROUTINE STRING 'DISPLAY'
> FILENAME STRING 'C:\my_routines\display.pro'
> LINE LONG 99
> LEVEL LONG 1
> IS_FUNCTION BYTE 0
> METHOD BYTE 0
> RESTORED BYTE 0
> SYSTEM BYTE 0
> IDL> print,'Routine name is: '+info[n-1].routine
> Routine name is: DISPLAY
>
> Heinz
Thanks Heinz,
I was looking for such function.
The routine suggested by David is good for finding the root directory
name.
I got the answer as follow:
;;;;;;;;;;;;;
Function Routine_Name
Info=scope_traceback(/structure)
n=n_elements(Info)
FullName=Info[n-2].FileName
SP=Strpos(FullName,'\', /Reverse_Search)
Proc=Strmid(FullName,SP+1,Strlen(FullName)-SP)
Return,Proc
End
Pro Test_Plot
Plot,Findgen(200)
Print,Routine_Name()
End
;;;;;;;;;;;;;;;;
IDL> test_plot
Compiled module: ROUTINE_NAME.
test_plot.pro
Ram
|
|
|