Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Name of the calling routine

jackosullivan1
883 Views

Is there a function available that will let me test for the name of the Fortran routine that has called my subroutine?

Thanks and God bless!

Jack

0 Kudos
6 Replies
Steven_L_Intel1
Employee
883 Views

No, there isn't. About the best you can do is call TRACEBACKQQ which will generate a traceback - if the program was built with traceback enabled that will contain the names of routines up the call stack. By default this is written to the console (or a popup window), but can be redirected to a file. Probably more complication than you're looking for.

0 Kudos
jackosullivan1
883 Views

Thanks so much, Steve, for your as-usual prompt and expert response.

You're very discerning about the complication.  On to additional ENTRY points!

Thanks again, and of course ...

God bless!

Jack

0 Kudos
Steven_L_Intel1
Employee
883 Views

Please don't use ENTRY! Maybe pass a code as an additional argument to indicate the caller.

0 Kudos
jackosullivan1
883 Views

Sorry to challenge your digestion or blood pressure by mentioning ENTRY, Steve!  But this is an old dog who knows only old tricks trying to keep an old (45-years-old!) program running that just needs a couple of new options.  A lot easier to just point the calling routine into the specific code it needs than to teach the other callers how to identify themselves.  ;-)

Thanks again so much for all you do with and for the Forum.  You make it so pleasant and understandable for us engineers who have to write code every now and then.

God bless!

Jack

0 Kudos
TimP
Honored Contributor III
883 Views

40 years ago, there were several incompatible versions of ENTRY (none standard).

0 Kudos
jimdempseyatthecove
Honored Contributor III
883 Views

Warning Will Robinson hack approaching...

module mod_FindCaller
  character(256) :: LastFile
  integer :: LastLine
    contains
    function FindCaller(f,l,x)
    real :: FindCaller, x   ! same type, use generic function
    character*(*) :: f
    integer :: l
    LastFile = f
    LastLine = l
    FindCaller = x
    end function FindCaller
end module mod_FindCaller
    
subroutine FOO(A, B)
    use mod_FindCaller
    real :: A,B
    real :: C
    real :: X
    X = A + B
    goto 100
    
    ENTRY FEE(C)
    X = C
100 continue
    print *,X
    print *,LastFile,LastLine
end subroutine FOO

program Test
  use mod_FindCaller
  implicit none
! The #defines must not be in the module
! They may be in an FPP #include file
! But not in a Fortran INCLUDE file
#define FOO(a,b) foo(FindCaller(__FILE__, __LINE__, a), b)
#define FEE(a) fee(FindCaller(__FILE__, __LINE__, a))

  CALL FOO(1.0,2.0)
  CALL FEE(5.0)
end program Test

Jim Dempsey

0 Kudos
Reply