m_TraceBack.F90 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! Math and Computer Science Division, Argonne National Laboratory !
  3. !-----------------------------------------------------------------------
  4. ! CVS m_TraceBack.F90,v 1.3 2004-04-21 22:54:46 jacob Exp
  5. ! CVS MCT_2_8_0
  6. !BOP -------------------------------------------------------------------
  7. !
  8. ! !MODULE: m_TraceBack - Generation of Traceback Information
  9. !
  10. ! !DESCRIPTION:
  11. ! This module supports the generation of traceback information for
  12. ! a given routine.
  13. !
  14. !
  15. ! !INTERFACE:
  16. module m_TraceBack
  17. ! !USES:
  18. ! No external modules are used in the declaration section of this module.
  19. implicit none
  20. private ! except
  21. ! !PUBLIC TYPES:
  22. ! No public types are declared in this module.
  23. ! !PUBLIC MEMBER FUNCTIONS:
  24. public :: GenTraceBackString
  25. interface GenTraceBackString; module procedure &
  26. GenTraceBackString1, &
  27. GenTraceBackString2
  28. end interface
  29. ! !PUBLIC DATA MEMBERS:
  30. ! No public data member constants are declared in this module.
  31. ! !REVISION HISTORY:
  32. ! 5 Aug02 - J. Larson <larson@mcs.anl.gov> - Initial version.
  33. !EOP ___________________________________________________________________
  34. ! Parameters local to this module:
  35. character(len=*),parameter :: myname='MCT(MPEU)::m_TraceBackString'
  36. character(len=len('|X|')), parameter :: StartChar = '|X|'
  37. character(len=len('->')), parameter :: ArrowChar = '->'
  38. contains
  39. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. ! Math and Computer Science Division, Argonne National Laboratory !
  41. !BOP -------------------------------------------------------------------
  42. !
  43. ! !IROUTINE: GenTraceBackString1 - Start a TraceBack with One Routine Name
  44. !
  45. ! !DESCRIPTION:
  46. ! This routine takes in CHARACTER form the names of the calling routine
  47. ! (the input argument {\tt RoutineName} and returns a {\tt String}
  48. ! (the output argument {\tt TraceBackString}) that portrays this routine
  49. ! as the starting point of a downwards procedural trace. The contents
  50. ! of {\tt TraceBackString} is merely an {\tt '|X|'}, followed immediately
  51. ! by the value of {\tt RoutineName}.
  52. !
  53. ! !INTERFACE:
  54. subroutine GenTraceBackString1(TraceBackString, RoutineName)
  55. !
  56. ! !USES:
  57. !
  58. use m_stdio
  59. use m_die
  60. use m_String, only : String
  61. use m_String, only : String_init => init
  62. implicit none
  63. ! !INPUT PARAMETERS:
  64. !
  65. character(len=*), intent(in) :: RoutineName
  66. ! !OUTPUT PARAMETERS:
  67. !
  68. type(String), intent(out) :: TraceBackString
  69. ! !REVISION HISTORY:
  70. ! 5Aug02 - J. Larson <larson@mcs.anl.gov> - Initial version.
  71. !EOP ___________________________________________________________________
  72. character(len=*),parameter :: myname_=myname//'::GenTraceBackString1'
  73. integer :: i, ierr
  74. integer :: RoutineNameLength, ScratchBufferLength
  75. character, dimension(:), allocatable :: ScratchBuffer
  76. ! Note: The value of ArrowChar is inherited
  77. ! from the declaration section of this module.
  78. ! Determine the lengths of ParentName and ChildName
  79. RoutineNameLength = len(RoutineName)
  80. ! Set up ScratchBuffer:
  81. ScratchBufferLength = len(StartChar) + RoutineNameLength
  82. allocate(ScratchBuffer(ScratchBufferLength), stat=ierr)
  83. if(ierr /= 0) then
  84. write(stderr,'(2a,i8)') myname_, &
  85. ':: Allocate(ScratchBuffer...) failed. ierr = ',ierr
  86. call die(myname_)
  87. endif
  88. ! Load ScratchBuffer:
  89. do i=1,len(StartChar) ! Load the '|X|'...
  90. ScratchBuffer(i) = StartChar(i:i)
  91. end do
  92. do i=1,RoutineNameLength
  93. ScratchBuffer(len(StartChar)+i) = RoutineName(i:i)
  94. end do
  95. ! Create TraceBackString
  96. call String_init(TraceBackString, ScratchBuffer)
  97. ! Clean up:
  98. deallocate(ScratchBuffer, stat=ierr)
  99. if(ierr /= 0) then
  100. write(stderr,'(2a,i8)') myname_, &
  101. ':: Deallocate(ScratchBuffer...) failed. ierr = ',ierr
  102. call die(myname_)
  103. endif
  104. end subroutine GenTraceBackString1
  105. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  106. ! Math and Computer Science Division, Argonne National Laboratory !
  107. !BOP -------------------------------------------------------------------
  108. !
  109. ! !IROUTINE: GenTraceBackString2 - Connect Two Routine Names in a TraceBack
  110. !
  111. ! !DESCRIPTION:
  112. ! This routine takes in CHARACTER form the names of the parent and
  113. ! child routines (the input arguments {\tt ParentName} and
  114. ! {\tt ChildName}, repsectively), and returns a {\tt String} (the output
  115. ! argument {\tt TraceBackString}) that portrays their procedural
  116. ! relationship. The contents of {\tt TraceBackString} is merely
  117. ! {\tt ParentName}, followe by an arrow ({\tt "->"}), followed by
  118. ! {\tt ChildName}.
  119. !
  120. ! !INTERFACE:
  121. subroutine GenTraceBackString2(TraceBackString, ParentName, ChildName)
  122. !
  123. ! !USES:
  124. !
  125. use m_stdio
  126. use m_die
  127. use m_String, only : String
  128. use m_String, only : String_init => init
  129. implicit none
  130. ! !INPUT PARAMETERS:
  131. !
  132. character(len=*), intent(in) :: ParentName
  133. character(len=*), intent(in) :: ChildName
  134. ! !OUTPUT PARAMETERS:
  135. !
  136. type(String), intent(out) :: TraceBackString
  137. ! !REVISION HISTORY:
  138. ! 5Aug02 - J. Larson <larson@mcs.anl.gov> - Initial version.
  139. !EOP ___________________________________________________________________
  140. character(len=*),parameter :: myname_=myname//'::GenTraceBackString2'
  141. integer :: i, ierr
  142. integer :: ParentNameLength, ChildNameLength, ScratchBufferLength
  143. character, dimension(:), allocatable :: ScratchBuffer
  144. ! Note: The value of ArrowChar is inherited
  145. ! from the declaration section of this module.
  146. ! Determine the lengths of ParentName and ChildName
  147. ParentNameLength = len(ParentName)
  148. ChildNameLength = len(ChildName)
  149. ! Set up ScratchBuffer:
  150. ScratchBufferLength = ParentNameLength + ChildNameLength + &
  151. len(ArrowChar)
  152. allocate(ScratchBuffer(ScratchBufferLength), stat=ierr)
  153. if(ierr /= 0) then
  154. write(stderr,'(2a,i8)') myname_, &
  155. ':: Allocate(ScratchBuffer...) failed. ierr = ',ierr
  156. call die(myname_)
  157. endif
  158. ! Load ScratchBuffer:
  159. do i=1,ParentNameLength ! Load the Parent Routine Name...
  160. ScratchBuffer(i) = ParentName(i:i)
  161. end do
  162. do i=1,len(ArrowChar) ! Load the Arrow...
  163. ScratchBuffer(ParentNameLength+i) = ArrowChar(i:i)
  164. end do
  165. do i=1,ChildNameLength
  166. ScratchBuffer(ParentNameLength+len(ArrowChar)+i) = ChildName(i:i)
  167. end do
  168. ! Create TraceBackString
  169. call String_init(TraceBackString, ScratchBuffer)
  170. ! Clean up:
  171. deallocate(ScratchBuffer, stat=ierr)
  172. if(ierr /= 0) then
  173. write(stderr,'(2a,i8)') myname_, &
  174. ':: Deallocate(ScratchBuffer...) failed. ierr = ',ierr
  175. call die(myname_)
  176. endif
  177. end subroutine GenTraceBackString2
  178. end module m_TraceBack