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
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
>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
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