source: CPL/oasis3-mct_5.0/lib/mct/mpeu/m_dropdead.F90 @ 6328

Last change on this file since 6328 was 6328, checked in by aclsce, 17 months ago

First import of oasis3-mct_5.0 (from oasis git server, branch OASIS3-MCT_5.0)

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