Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Run time determination of Subroutine or Function name on OPENVMS FORTRAN 77

1 view
Skip to first unread message

Stuart Norris

unread,
Mar 17, 2003, 11:19:44 PM3/17/03
to
Hello Readers.

A run-time question for Open VMS FORTRAN 77 for programs with
optimisation turned off.

Is it possible at runtime to know the name of the module (ie
subroutine or function) that I am currently in. I wish to use this
information to print to a file for debugging. I would prefer to do it
dynamically to avoid the problem of hard coding and making a mistake.

How do I dynamically get a text string that is the subroutine or
function name so I can log this to a file.

subroutine write_data ( xxxx)
....
sub_name = ????????
write (*,*) sub_name
.....
return
end

Thanks

Stuart

Guido Schlupkothen

unread,
Mar 18, 2003, 7:06:59 AM3/18/03
to

"Stuart Norris" <stuie_...@yahoo.com.au> schrieb im Newsbeitrag
news:51262235.03031...@posting.google.com...


Hi Stuart,

when your main program is entering the subroutine you will know where you
are I think :-)
So, why you don´t write out the name of your subroutine WRITE_DATA
hardcoded, like this:

subroutine write_data ( xxxx)
....
sub_name = ????????

write (*,*) 'write_data'
.....
return
end


Best regards
Guido


Steve Lionel

unread,
Mar 18, 2003, 9:48:13 AM3/18/03
to
On 17 Mar 2003 20:19:44 -0800, stuie_...@yahoo.com.au (Stuart
Norris) wrote:

>A run-time question for Open VMS FORTRAN 77 for programs with
>optimisation turned off.
>
>Is it possible at runtime to know the name of the module (ie
>subroutine or function) that I am currently in. I wish to use this
>information to print to a file for debugging. I would prefer to do it
>dynamically to avoid the problem of hard coding and making a mistake.

The information is available in the traceback records. Getting to it
is difficult. But let me suggest an easy alternative.

When you want to display where you are in the code, add this call:

CALL LIB$SIGNAL (%val(0))

You'll get a SYSTEM-W-NOMSG message followed by a traceback.

Please send Visual Fortran support requests to vf-su...@compaq.com

Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

User communities for Intel Fortran and Compaq Visual Fortran:
http://intel.com/IDS/community

Paul van Delst

unread,
Mar 18, 2003, 9:55:27 AM3/18/03
to
Stuart Norris wrote:
>
> Hello Readers.
>
> A run-time question for Open VMS FORTRAN 77 for programs with
> optimisation turned off.
>
> Is it possible at runtime to know the name of the module (ie
> subroutine or function) that I am currently in. I wish to use this
> information to print to a file for debugging. I would prefer to do it
> dynamically to avoid the problem of hard coding and making a mistake.
>
> How do I dynamically get a text string that is the subroutine or
> function name so I can log this to a file.

I do the following type of thing (my bits are in f90 syntax but you can change it):

subroutine write_data ( xxxx)

character(*), parameter :: ROUTINE_NAME = 'Write_Data'
....

if (debug switch on or error occurs) then
write (*,*) ROUTINE_NAME, ...message...
end if
.....
return
end

This is not what you asked for but, if you use a common output format for your error/debug
messages (I use a subroutine), then you can cut and paste code. You can also insert an
optional argument that returns the routine name which can allow you to construct a dynamic
"path" of the execution order or your code-- sometimes that can be handy if you have a lot
of code that does stuff like
if ( condition ) then
call this_routine(...)
else
call that_routine(...)
end if

cheers,

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Ph: (301)763-8000 x7748
Fax:(301)763-8545

Paul Curtis

unread,
Mar 18, 2003, 2:25:46 PM3/18/03
to
As a follow-on to the last post, I sometimes take this one step further and
create a stack of character variables. Each monitored routine starts with a
push operation which loads the stack with that routine's name or other info
(and increments the stack's associated level counter), and ends with a pop
operation which clears the stack entry (and decrements the level counter)
when the routine exits. This allows one to obtain a complete dynamic view
of the call stack at any time, via a utility routine which prints the
current stack
contents. I have found that a stack depth of 20 is generally sufficient
for my
programs.
0 new messages