m_flow.F90 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  3. !-----------------------------------------------------------------------
  4. ! CVS m_flow.F90,v 1.3 2004-04-21 22:54:47 jacob Exp
  5. ! CVS MCT_2_8_0
  6. !-----------------------------------------------------------------------
  7. !BOP
  8. !
  9. ! !MODULE: m_flow - tracing the program calling tree
  10. !
  11. ! !DESCRIPTION:
  12. !
  13. ! !INTERFACE:
  14. module m_flow
  15. implicit none
  16. private ! except
  17. public :: flow_ci
  18. public :: flow_co
  19. public :: flow_flush
  20. public :: flow_reset
  21. interface flow_ci; module procedure ci_; end interface
  22. interface flow_co; module procedure co_; end interface
  23. interface flow_flush; module procedure flush_; end interface
  24. interface flow_reset; module procedure reset_; end interface
  25. ! !REVISION HISTORY:
  26. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  27. !EOP
  28. !_______________________________________________________________________
  29. character(len=*),parameter :: myname='MCT(MPEU)::m_flow'
  30. integer,parameter :: MX_TNAME= 64
  31. integer,parameter :: LN_TNAME= 32
  32. integer,save :: mxdep= 0
  33. integer,save :: iname=-1
  34. character(len=LN_TNAME),save,dimension(0:MX_TNAME-1) :: tname
  35. character(len=LN_TNAME),save :: ciname=' '
  36. character(len=LN_TNAME),save :: coname=' '
  37. logical,save :: balanced=.true.
  38. contains
  39. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  41. !-----------------------------------------------------------------------
  42. !BOP
  43. !
  44. ! !IROUTINE: ci_ - checking in a level
  45. !
  46. ! !DESCRIPTION:
  47. !
  48. ! !INTERFACE:
  49. subroutine ci_(name)
  50. implicit none
  51. character(len=*),intent(in) :: name
  52. ! !REVISION HISTORY:
  53. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  54. !EOP
  55. !_______________________________________________________________________
  56. character(len=*),parameter :: myname_=myname//'::ci_'
  57. ! Push in an entry in to a circulated list storage to save
  58. ! only the last MX_TNAME entries.
  59. iname=iname+1
  60. tname(modulo(iname,MX_TNAME)) = name
  61. if(mxdep < iname+1) mxdep=iname+1
  62. end subroutine ci_
  63. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  65. !-----------------------------------------------------------------------
  66. !BOP
  67. !
  68. ! !IROUTINE: co_ - checking out a level
  69. !
  70. ! !DESCRIPTION:
  71. !
  72. ! !INTERFACE:
  73. subroutine co_(name)
  74. use m_chars, only : uppercase
  75. implicit none
  76. character(len=*),intent(in) :: name
  77. ! !REVISION HISTORY:
  78. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  79. !EOP
  80. !_______________________________________________________________________
  81. character(len=*),parameter :: myname_=myname//'::co_'
  82. character(len=LN_TNAME) :: uname
  83. if(balanced) then
  84. uname='?'
  85. balanced=iname >= 0
  86. if(balanced) then
  87. uname=tname(modulo(iname,MX_TNAME))
  88. balanced = uname == ' ' .or. uppercase(uname) == uppercase(name)
  89. endif
  90. if(.not.balanced) then
  91. ciname=uname
  92. coname= name
  93. endif
  94. endif
  95. ! Pop out an entry
  96. tname(modulo(iname,MX_TNAME))=' '
  97. iname=iname-1
  98. end subroutine co_
  99. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  101. !-----------------------------------------------------------------------
  102. !BOP
  103. !
  104. ! !IROUTINE: flush_ - print all remaining entries in the list
  105. !
  106. ! !DESCRIPTION:
  107. !
  108. ! !INTERFACE:
  109. subroutine flush_(lu)
  110. implicit none
  111. integer,intent(in) :: lu
  112. ! !REVISION HISTORY:
  113. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  114. !EOP
  115. !_______________________________________________________________________
  116. character(len=*),parameter :: myname_=myname//'::flush_'
  117. integer :: i
  118. ! Nothing to show
  119. if(mxdep == 0 .and. iname == -1) return
  120. WRITE(lu,'(2a,i4)',advance='no') myname,': depth =',mxdep
  121. if(.not.balanced .or. iname < -1) then
  122. WRITE(lu,'(4a)',advance='no') &
  123. ', ci/co unbalanced at ',trim(ciname),'/',trim(coname)
  124. write(lu,'(a,i4)') ', level =',iname+1
  125. return
  126. endif
  127. if(iname >= 0) then
  128. write(lu,'(a)',advance='no') ', '
  129. do i=0,iname-1
  130. write(lu,'(2a)',advance='no') trim(tname(modulo(i,MX_TNAME))),'>'
  131. end do
  132. write(lu,'(a)',advance='no') trim(tname(modulo(iname,MX_TNAME)))
  133. endif
  134. write(lu,*)
  135. end subroutine flush_
  136. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  138. !-----------------------------------------------------------------------
  139. !BOP
  140. !
  141. ! !IROUTINE: reset_ - set the stack to empty
  142. !
  143. ! !DESCRIPTION:
  144. !
  145. ! !INTERFACE:
  146. subroutine reset_()
  147. implicit none
  148. ! !REVISION HISTORY:
  149. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  150. !EOP
  151. !_______________________________________________________________________
  152. character(len=*),parameter :: myname_=myname//'::reset_'
  153. integer :: i
  154. mxdep=0
  155. iname=-1
  156. tname(0:MX_TNAME-1)=' '
  157. ciname=' '
  158. coname=' '
  159. balanced=.true.
  160. end subroutine reset_
  161. end module m_flow