m_dropdead.F90 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  3. !-----------------------------------------------------------------------
  4. ! CVS m_dropdead.F90,v 1.4 2007-01-10 03:04:46 rloy Exp
  5. ! CVS MCT_2_8_0
  6. !-----------------------------------------------------------------------
  7. !BOP
  8. !
  9. ! !MODULE: m_dropdead - An abort() with a style
  10. !
  11. ! !DESCRIPTION:
  12. !
  13. ! !INTERFACE:
  14. module m_dropdead
  15. implicit none
  16. private ! except
  17. public :: die ! terminate a program with a condition
  18. interface die; module procedure &
  19. die_, &
  20. diex_
  21. end interface
  22. ! !REVISION HISTORY:
  23. ! 20Feb97 - Jing Guo <guo@eramus> - defined template
  24. !EOP
  25. !_______________________________________________________________________
  26. contains
  27. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  29. !-----------------------------------------------------------------------
  30. !BOP
  31. ! !IROUTINE: die_ - Clean up and raise an exception to the OS
  32. !
  33. ! !DESCRIPTION:
  34. !
  35. ! A call to die() exits the program with minimum information for
  36. ! both the user and the operating system.
  37. !
  38. ! !INTERFACE:
  39. subroutine die_(where)
  40. use m_stdio, only : stderr
  41. use m_mpif90,only : MP_comm_world
  42. use m_mpif90,only : MP_comm_rank
  43. use m_mpif90,only : MP_abort
  44. use m_mpif90,only : MP_initialized
  45. implicit none
  46. character(len=*),intent(in) :: where ! where it is called
  47. ! !REVISION HISTORY:
  48. ! 20Feb97 - Jing Guo <guo@eramus> - defined template
  49. ! 09Jan07 - R. Loy <rloy@mcs.anl.gov> - check for initialized, add
  50. ! options for abort
  51. !
  52. !EOP
  53. !_______________________________________________________________________
  54. character(len=*),parameter :: myname_='MCT(MPEU)::die.'
  55. integer :: myrank,ier
  56. logical :: initialized
  57. call MP_initialized(initialized,ier)
  58. if (initialized) then
  59. !-------------------------------------------------
  60. ! MPI_ should have been initialized for this call
  61. !-------------------------------------------------
  62. call MP_comm_rank(MP_comm_world,myrank,ier)
  63. ! a message for the users:
  64. write(stderr,'(z3.3,5a)') myrank,'.',myname_, &
  65. ': from ',trim(where),'()'
  66. ! raise a condition to the OS
  67. #ifdef ENABLE_UNIX_ABORT
  68. call abort
  69. #else
  70. call MP_abort(MP_comm_world,2,ier)
  71. #endif
  72. else
  73. write(stderr,'(5a)') 'unknown rank .',myname_, &
  74. ': from ',trim(where),'()'
  75. call abort
  76. endif
  77. end subroutine die_
  78. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  80. !-----------------------------------------------------------------------
  81. !BOP
  82. !
  83. ! !IROUTINE: diex_ - Clean up and raise an exception to the OS
  84. !
  85. ! !DESCRIPTION:
  86. !
  87. ! A call to die() exits the program with minimum information for
  88. ! both the user and the operating system. This implementation,
  89. ! however, may be used in conjunction with with a source preprocessor
  90. ! to produce more detailed location information.
  91. !
  92. ! !INTERFACE:
  93. subroutine diex_(where,fnam,line)
  94. use m_stdio, only : stderr
  95. use m_mpif90,only : MP_comm_world
  96. use m_mpif90,only : MP_comm_rank
  97. use m_mpif90,only : MP_abort
  98. use m_mpif90,only : MP_initialized
  99. implicit none
  100. character(len=*),intent(in) :: where ! where it is called
  101. character(len=*),intent(in) :: fnam
  102. integer,intent(in) :: line
  103. ! !REVISION HISTORY:
  104. ! 20Feb97 - Jing Guo <guo@eramus> - defined template
  105. ! 09Jan07 - R. Loy <rloy@mcs.anl.gov> - check for initialized, add
  106. ! options for abort
  107. !
  108. !EOP
  109. !_______________________________________________________________________
  110. character(len=*),parameter :: myname_='die.'
  111. integer :: myrank,ier
  112. character(len=16) :: lineno
  113. logical :: initialized
  114. write(lineno,'(i16)') line
  115. call MP_initialized(initialized,ier)
  116. if (initialized) then
  117. !-------------------------------------------------
  118. ! MPI_ should have been initialized for this call
  119. !-------------------------------------------------
  120. call MP_comm_rank(MP_comm_world,myrank,ier)
  121. ! a message for the users:
  122. write(stderr,'(z3.3,9a)') myrank,'.',myname_, &
  123. ': from ',trim(where),'()', &
  124. ', line ',trim(adjustl(lineno)), &
  125. ' of file ',fnam
  126. ! raise a condition to the OS
  127. #ifdef ENABLE_UNIX_ABORT
  128. call abort
  129. #else
  130. call MP_abort(MP_comm_world,2,ier)
  131. #endif
  132. else
  133. ! a message for the users:
  134. write(stderr,'(9a)') 'unknown rank .',myname_, &
  135. ': from ',trim(where),'()', &
  136. ', line ',trim(adjustl(lineno)), &
  137. ' of file ',fnam
  138. call abort
  139. endif
  140. end subroutine diex_
  141. !=======================================================================
  142. end module m_dropdead
  143. !.