MFIX  2016-1
exit.f
Go to the documentation of this file.
1 #include "version.inc"
2 MODULE exit
3  CONTAINS
4  SUBROUTINE mfix_exit(myID, normal_termination)
5 
6 ! File unit for .OUT file
7  USE funits, only : unit_out
8 ! File unit for .LOG files
9  USE funits, only : unit_log
10 
11  use compar
12  use mpi_utility
13 
14  implicit none
15 
16 ! Rank ID
17  INTEGER, INTENT(IN) :: myID
18 ! if present, normal termination (won't print error message)
19  LOGICAL, INTENT(IN), OPTIONAL :: normal_termination
20 ! Logical showing that a file unit is open.
21  LOGICAL :: isOpen
22 ! The value passed via the dummy argument or the process ID.
23  INTEGER :: myID_l
24 ! Process ID (myPE) converted to a character string.
25  CHARACTER(len=64) :: myID_c
26 
27 ! Set the ID of the caller.
28  myid_c=''; WRITE(myid_c,*) myid
29 
30 ! Write out that this routine was called.
31  IF (.not. present(normal_termination)) THEN
32  IF(mype == pe_io) WRITE(*,1000)
33  IF(dmp_log) THEN
34  INQUIRE(unit=unit_log,opened=isopen)
35  IF(isopen) WRITE(unit_log,1001) trim(adjustl(myid_c))
36  ENDIF
37  ENDIF
38 
39 ! Terminate MPI.
40  CALL exitmpi(myid_l)
41 
42 ! Close any open files.
43  CALL close_file(unit_out)
44  CALL close_file(unit_log)
45 
46 ! Last gasp...
47  IF(mype == pe_io) WRITE(*,1002)
48 
49 ! Hard Stop.
50  error_stop 1
51 
52  1000 FORMAT(2/,1x,70('*'),/' Fatal error reported on one or more', &
53  ' processes. The .LOG file',/' may contain additional', &
54  ' information about the failure.',/1x,70('*'))
55 
56  1001 FORMAT(2/,1x,70('*'),/' Fatal error reported on PE ', &
57  a,'. The .LOG file may contain',/' additional ', &
58  'information about the failure.',/1x,70('*'))
59 
60  1002 FORMAT(2/,1x,'Program Terminated.',2/)
61 
62  END SUBROUTINE mfix_exit
63 
64 !``````````````````````````````````````````````````````````````````````!
65 ! Subroutine: CLOSE_FILE !
66 ! !
67 ! Purpose: Close a file if it is open. !
68 !......................................................................!
69  SUBROUTINE close_file(UNIT_l)
70 
71 ! Global Variables.
72 !---------------------------------------------------------------------//
73 ! NONE
74 
75  implicit none
76 
77 ! Dummy Arguments:
78 !---------------------------------------------------------------------//
79  INTEGER, INTENT(IN) :: UNIT_l
80 
81 ! Local Variables.
82 !---------------------------------------------------------------------//
83 ! Retruned status of the specifed file unit
84  INTEGER :: IOS
85 ! Logical indicating if the file is open
86  LOGICAL :: FOPEN
87 
88 ! If the file is open...
89  INQUIRE(unit=unit_l, opened=fopen, iostat=ios )
90 ! Close it.
91  IF(fopen) CLOSE(unit_l)
92 
93  RETURN
94  END SUBROUTINE close_file
95 
96 END MODULE exit
integer, parameter unit_out
Definition: funits_mod.f:18
integer pe_io
Definition: compar_mod.f:30
subroutine close_file(UNIT_l)
Definition: exit.f:70
subroutine mfix_exit(myID, normal_termination)
Definition: exit.f:5
Definition: exit.f:2
integer, parameter unit_log
Definition: funits_mod.f:21
integer mype
Definition: compar_mod.f:24
subroutine exitmpi(myid)