m_die.F90 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  3. !-----------------------------------------------------------------------
  4. ! CVS m_die.F90,v 1.4 2004-04-21 22:54:47 jacob Exp
  5. ! CVS MCT_2_8_0
  6. !-----------------------------------------------------------------------
  7. !BOP
  8. !
  9. ! !MODULE: m_die - die with mpout flushed
  10. !
  11. ! !DESCRIPTION:
  12. !
  13. ! !INTERFACE:
  14. module m_die
  15. use m_mpif90, only : MP_perr
  16. implicit none
  17. private ! except
  18. public :: die ! signal an exception
  19. public :: diex ! a special die() supporting macros
  20. public :: perr,warn ! message(s) to stderr
  21. public :: perr_die ! to be phased out
  22. public :: MP_die ! a special die() for MPI errors
  23. public :: MP_perr ! perr for MPI errors, from m_mpif90
  24. public :: MP_perr_die ! a special die() for MPI errors
  25. public :: assert_ ! used by ASSERT() macro of assert.H
  26. interface die; module procedure &
  27. die0_, & ! die(where)
  28. die1_, & ! die(where,message)
  29. die2_, & ! die(where,proc,ier)
  30. die4_ ! die(where,mesg1,ival1,mesg2,ival2)
  31. end interface
  32. interface diex; module procedure &
  33. diex_ ! diex(where,filename,lineno)
  34. end interface
  35. interface perr; module procedure &
  36. perr1_, & ! perr(where,message)
  37. perr2_, & ! perr(where,proc,ier)
  38. perr4_ ! perr(where,mesg1,ival1,mesg2,ival2)
  39. end interface
  40. interface warn; module procedure &
  41. perr1_, & ! perr(where,message)
  42. perr2_, & ! perr(where,proc,ier)
  43. perr4_ ! perr(where,mesg1,ival1,mesg2,ival2)
  44. end interface
  45. interface perr_die; module procedure &
  46. die2_ ! perr_die(where,proc,ier)
  47. end interface
  48. interface MP_die; module procedure &
  49. MPdie2_ ! MP_die(where,proc,ier)
  50. end interface
  51. interface MP_perr_die; module procedure &
  52. MPdie2_ ! MP_die(where,proc,ier)
  53. end interface
  54. ! !REVISION HISTORY:
  55. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  56. !EOP
  57. !_______________________________________________________________________
  58. character(len=*),parameter :: myname='MCT(MPEU)::m_die'
  59. contains
  60. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  62. !-----------------------------------------------------------------------
  63. !BOP
  64. !
  65. ! !IROUTINE: die0_ - flush(mpout) before die()
  66. !
  67. ! !DESCRIPTION:
  68. !
  69. ! !INTERFACE:
  70. subroutine die0_(where)
  71. use m_mpout, only : mpout,mpout_flush,mpout_close,mpout_ison
  72. use m_flow, only : flow_flush
  73. use m_dropdead, only : ddie => die
  74. implicit none
  75. character(len=*),intent(in) :: where
  76. ! !REVISION HISTORY:
  77. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  78. !EOP
  79. !_______________________________________________________________________
  80. character(len=*),parameter :: myname_=myname//'::die0_'
  81. call mpout_flush()
  82. if(mpout_ison()) call flow_flush(mpout)
  83. call mpout_close()
  84. call ddie(where)
  85. end subroutine die0_
  86. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  88. !-----------------------------------------------------------------------
  89. !BOP
  90. !
  91. ! !IROUTINE: die1_ - flush(mpout) before die()
  92. !
  93. ! !DESCRIPTION:
  94. !
  95. ! !INTERFACE:
  96. subroutine die1_(where,message)
  97. use m_mpout, only : mpout,mpout_flush,mpout_close,mpout_ison
  98. use m_flow, only : flow_flush
  99. use m_dropdead, only : ddie => die
  100. implicit none
  101. character(len=*),intent(in) :: where
  102. character(len=*),intent(in) :: message
  103. ! !REVISION HISTORY:
  104. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  105. !EOP
  106. !_______________________________________________________________________
  107. character(len=*),parameter :: myname_=myname//'::die1_'
  108. call mpout_flush()
  109. if(mpout_ison()) call flow_flush(mpout)
  110. call mpout_close()
  111. call perr1_(where,message)
  112. call ddie(where)
  113. end subroutine die1_
  114. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  115. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  116. !-----------------------------------------------------------------------
  117. !BOP
  118. !
  119. ! !IROUTINE: die2_ - flush(mpout) before die()
  120. !
  121. ! !DESCRIPTION:
  122. !
  123. ! !INTERFACE:
  124. subroutine die2_(where,proc,ier)
  125. use m_mpout, only : mpout,mpout_flush,mpout_close,mpout_ison
  126. use m_flow, only : flow_flush
  127. use m_dropdead, only : ddie => die
  128. implicit none
  129. character(len=*),intent(in) :: where
  130. character(len=*),intent(in) :: proc
  131. integer,intent(in) :: ier
  132. ! !REVISION HISTORY:
  133. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  134. !EOP
  135. !_______________________________________________________________________
  136. character(len=*),parameter :: myname_=myname//'::die2_'
  137. call mpout_flush()
  138. if(mpout_ison()) call flow_flush(mpout)
  139. call mpout_close()
  140. call perr2_(where,proc,ier)
  141. call ddie(where)
  142. end subroutine die2_
  143. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  145. !-----------------------------------------------------------------------
  146. !BOP
  147. !
  148. ! !IROUTINE: die4_ - flush(mpout) before die()
  149. !
  150. ! !DESCRIPTION:
  151. !
  152. ! !INTERFACE:
  153. subroutine die4_(where,mesg1,ival1,mesg2,ival2)
  154. use m_mpout, only : mpout,mpout_flush,mpout_close,mpout_ison
  155. use m_flow, only : flow_flush
  156. use m_dropdead, only : ddie => die
  157. implicit none
  158. character(len=*),intent(in) :: where
  159. character(len=*),intent(in) :: mesg1
  160. integer,intent(in) :: ival1
  161. character(len=*),intent(in) :: mesg2
  162. integer,intent(in) :: ival2
  163. ! !REVISION HISTORY:
  164. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  165. !EOP
  166. !_______________________________________________________________________
  167. character(len=*),parameter :: myname_=myname//'::die4_'
  168. call mpout_flush()
  169. if(mpout_ison()) call flow_flush(mpout)
  170. call mpout_close()
  171. call perr4_(where,mesg1,ival1,mesg2,ival2)
  172. call ddie(where)
  173. end subroutine die4_
  174. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  176. !-----------------------------------------------------------------------
  177. !BOP
  178. !
  179. ! !IROUTINE: diex_ - flush(mpout) before die()
  180. !
  181. ! !DESCRIPTION:
  182. !
  183. ! !INTERFACE:
  184. subroutine diex_(where,filename,line)
  185. use m_mpout, only : mpout,mpout_flush,mpout_close,mpout_ison
  186. use m_flow, only : flow_flush
  187. use m_dropdead, only : ddie => die
  188. implicit none
  189. character(len=*),intent(in) :: where
  190. character(len=*),intent(in) :: filename
  191. integer,intent(in) :: line
  192. ! !REVISION HISTORY:
  193. ! 26Feb98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  194. !EOP
  195. !_______________________________________________________________________
  196. character(len=*),parameter :: myname_=myname//'::diex_'
  197. call mpout_flush()
  198. if(mpout_ison()) call flow_flush(mpout)
  199. call mpout_close()
  200. call ddie(where,filename,line)
  201. end subroutine diex_
  202. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  203. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  204. !BOP -------------------------------------------------------------------
  205. !
  206. ! !IROUTINE: perr1_ - send a simple error message to _stderr_
  207. !
  208. ! !DESCRIPTION:
  209. !
  210. ! !INTERFACE:
  211. subroutine perr1_(where,message)
  212. use m_stdio,only : stderr
  213. implicit none
  214. character(len=*),intent(in) :: where
  215. character(len=*),intent(in) :: message
  216. ! !REVISION HISTORY:
  217. ! 27Apr98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  218. !EOP ___________________________________________________________________
  219. character(len=*),parameter :: myname_=myname//'::perr1_'
  220. write(stderr,'(3a)') where,': ',message
  221. end subroutine perr1_
  222. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  223. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  224. !BOP -------------------------------------------------------------------
  225. !
  226. ! !IROUTINE: perr2_ - send a simple error message to _stderr_
  227. !
  228. ! !DESCRIPTION:
  229. !
  230. ! !INTERFACE:
  231. subroutine perr2_(where,proc,ier)
  232. use m_stdio,only : stderr
  233. implicit none
  234. character(len=*),intent(in) :: where
  235. character(len=*),intent(in) :: proc
  236. integer,intent(in) :: ier
  237. ! !REVISION HISTORY:
  238. ! 27Apr98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  239. !EOP ___________________________________________________________________
  240. character(len=*),parameter :: myname_=myname//'::perr2_'
  241. character(len=16) :: cer
  242. integer :: ios
  243. cer='*******'
  244. write(cer,'(i16)',iostat=ios) ier
  245. write(stderr,'(5a)') where,': ', &
  246. proc,' error, stat =',trim(adjustl(cer))
  247. end subroutine perr2_
  248. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  249. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  250. !BOP -------------------------------------------------------------------
  251. !
  252. ! !IROUTINE: perr4_ - send a simple error message to _stderr_
  253. !
  254. ! !DESCRIPTION:
  255. !
  256. ! !INTERFACE:
  257. subroutine perr4_(where,mesg1,ival1,mesg2,ival2)
  258. use m_stdio,only : stderr
  259. implicit none
  260. character(len=*),intent(in) :: where
  261. character(len=*),intent(in) :: mesg1
  262. integer,intent(in) :: ival1
  263. character(len=*),intent(in) :: mesg2
  264. integer,intent(in) :: ival2
  265. ! !REVISION HISTORY:
  266. ! 27Apr98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  267. !EOP ___________________________________________________________________
  268. character(len=*),parameter :: myname_=myname//'::perr4_'
  269. character(len=16) :: cval1,cval2
  270. integer :: ios
  271. cval1='*******'
  272. cval2='*******'
  273. write(cval1,'(i16)',iostat=ios) ival1
  274. write(cval2,'(i16)',iostat=ios) ival2
  275. write(stderr,'(10a)') where,': error, ', &
  276. mesg1,'=',trim(adjustl(cval1)),', ', &
  277. mesg2,'=',trim(adjustl(cval2)),'.'
  278. end subroutine perr4_
  279. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  280. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  281. !BOP -------------------------------------------------------------------
  282. !
  283. ! !IROUTINE: MPdie2_ - invoke MP_perr before die_
  284. !
  285. ! !DESCRIPTION:
  286. !
  287. ! !INTERFACE:
  288. subroutine MPdie2_(where,proc,ier)
  289. use m_mpif90, only : MP_perr
  290. implicit none
  291. character(len=*),intent(in) :: where
  292. character(len=*),intent(in) :: proc
  293. integer,intent(in) :: ier
  294. ! !REVISION HISTORY:
  295. ! 27Apr98 - Jing Guo <guo@thunder> - initial prototype/prolog/code
  296. !EOP ___________________________________________________________________
  297. character(len=*),parameter :: myname_=myname//'::MPdie2_'
  298. call MP_perr(where,proc,ier)
  299. call die0_(where)
  300. end subroutine MPdie2_
  301. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  302. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  303. !BOP -------------------------------------------------------------------
  304. !
  305. ! !IROUTINE: assert_ - an utility called by ASSERT() macro only
  306. !
  307. ! !DESCRIPTION:
  308. !
  309. ! !INTERFACE:
  310. subroutine assert_(str, file, line)
  311. use m_mpout,only : mpout,mpout_flush,mpout_close,mpout_ison
  312. use m_flow,only : flow_flush
  313. use m_dropdead,only : ddie => die
  314. implicit none
  315. Character(Len=*), Intent(In) :: str ! a message
  316. Character(Len=*), Intent(In) :: file ! a filename
  317. Integer, Intent(In) :: line ! a line number
  318. ! !REVISION HISTORY:
  319. ! 25Aug00 - Jing Guo <guo@dao.gsfc.nasa.gov>
  320. ! - modified
  321. ! - included into m_die for easier module management
  322. ! before - Tom Clune
  323. ! - Created for MPI PSAS implementation as a separate
  324. ! module
  325. ! 19Jan01 - J. Larson <larson@mcs.anl.gov> - removed nested
  326. ! single/double/single quotes in the second argument
  327. ! to the call to perr1_(). This was done for the pgf90
  328. ! port.
  329. !EOP ___________________________________________________________________
  330. character(len=*),parameter :: myname_='ASSERT_'
  331. call mpout_flush()
  332. if(mpout_ison()) call flow_flush(mpout)
  333. call mpout_close()
  334. call perr1_(myname_,'failed: "//str//")')
  335. call ddie(myname_,file,line)
  336. End subroutine assert_
  337. end module m_die