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

Home » Public Forums » archive » Re: Function to return the current procedure/function
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
Re: Function to return the current procedure/function [message #67905] Mon, 07 September 2009 01:02
Maarten[1] is currently offline  Maarten[1]
Messages: 176
Registered: November 2005
Senior Member
On Sep 5, 6:16 pm, maurya <ramaury...@gmail.com> wrote:

> 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

Just a warning that will prevent a serious headache later on: instead
of hard-coding the path delimiter to '\', you may want to use the
function path_sep() instead. After all, there is only one operating
system that uses '\' as a directory separator.

You may also have a look at the functions file_basename() and
file_dirname().

Best,

Maarten
Re: Function to return the current procedure/function [message #67920 is a reply to message #67905] Sat, 05 September 2009 09:16 Go to previous message
maurya is currently offline  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
Re: Function to return the current procedure/function [message #67922 is a reply to message #67920] Sat, 05 September 2009 07:04 Go to previous message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
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
Re: Function to return the current procedure/function [message #67925 is a reply to message #67922] Sat, 05 September 2009 06:05 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
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


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Readu, Writeu Causing Segmentation Fault
Next Topic: Re: Help, no improvement in FFT speed on a multiprocessor system

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

Current Time: Wed Oct 08 15:14:13 PDT 2025

Total time taken to generate the page: 0.00561 seconds