File: /nfs/home/0/users/jenkins/mfix.git/model/exit.f

1           SUBROUTINE MFIX_EXIT(myID)
2     
3     ! File unit for .OUT file
4           USE funits, only : UNIT_OUT
5     ! File unit for .LOG files
6           USE funits, only : UNIT_LOG
7     
8           use compar
9           use mpi_utility
10     
11           implicit none
12     
13     ! Rank ID
14           INTEGER, INTENT(IN) :: myID
15     ! Logical showing that a file unit is open.
16           LOGICAL :: isOpen
17     ! The value passed via the dummy argument or the process ID.
18           INTEGER :: myID_l
19     ! Process ID (myPE) converted to a character string.
20           CHARACTER(len=64) :: myID_c
21     
22     ! Set the ID of the caller.
23           myID_c=''; WRITE(myID_c,*) myID
24     
25     ! Write out that this routine was called.
26           IF(myPE == PE_IO) WRITE(*,1000)
27           IF(DMP_LOG) THEN
28              INQUIRE(UNIT=UNIT_LOG,OPENED=isOpen)
29              IF(isOPEN) WRITE(UNIT_LOG,1001) trim(adjustl(myID_c))
30           ENDIF
31     
32     ! Terminate MPI.
33           CALL exitMPI(myID_l)
34     
35     ! Close any open files.
36           CALL CLOSE_FILE(UNIT_OUT)
37           CALL CLOSE_FILE(UNIT_LOG)
38     
39     ! Last gasp...
40           IF(myPE == PE_IO) WRITE(*,1002)
41     
42     ! Hard Stop.
43           STOP 1
44     
45      1000 FORMAT(2/,1x,70('*'),/' Fatal error reported on one or more',    &
46             ' processes. The .LOG file',/' may contain additional',        &
47             ' information about the failure.',/1x,70('*'))
48     
49      1001 FORMAT(2/,1x,70('*'),/' Fatal error reported on PE ',  &
50              A,'. The .LOG file may contain',/' additional ',     &
51             'information about the failure.',/1x,70('*'))
52     
53      1002 FORMAT(2/,1x,'Program Terminated.',2/)
54     
55           END SUBROUTINE MFIX_EXIT
56     
57     
58     
59     !``````````````````````````````````````````````````````````````````````!
60     ! Subroutine: CLOSE_FILE                                               !
61     !                                                                      !
62     ! Purpose: Close a file if it is open.                                 !
63     !......................................................................!
64           SUBROUTINE CLOSE_FILE(UNIT_l)
65     
66     ! Global Variables.
67     !---------------------------------------------------------------------//
68     ! NONE
69     
70           implicit none
71     
72     ! Dummy Arguments:
73     !---------------------------------------------------------------------//
74           INTEGER, INTENT(IN) :: UNIT_l
75     
76     ! Local Variables.
77     !---------------------------------------------------------------------//
78     ! Retruned status of the specifed file unit
79           INTEGER :: IOS
80     ! Logical indicating if the file is open
81           LOGICAL :: FOPEN
82     
83     ! If the file is open...
84           INQUIRE(UNIT=UNIT_l, OPENED=FOPEN, IOSTAT=IOS )
85     ! Close it.
86           IF(FOPEN) CLOSE(UNIT_l)
87     
88           RETURN
89           END SUBROUTINE CLOSE_FILE
90     
91     
92     
93     
94