-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmo_finish.f90
137 lines (97 loc) · 4.04 KB
/
mo_finish.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
!> \file mo_finish.f90
!> \brief Finish a program gracefully
!> \details This module supplies a routine that writes out final comments and then stops.
!> \authors Original of Echam5, (C) MPI-MET, Hamburg, Germany.\n
!> Modified Matthias Cuntz
!> \date Jan 2011
MODULE mo_finish
! This module supplies a routine to finish a program gracefully.
! Written Jan 2011, Matthias Cuntz - Adapted from Echam5, (C) MPI-MET, Hamburg, Germany
! Modified May 2016, Matthias Cuntz - copied separator from mo_string_utils
! License
! -------
! This file is part of the JAMS Fortran package, distributed under the MIT License.
!
! Copyright (c) 2011-2016 Matthias Cuntz, MPI-MET Hamburg Germany - mc (at) macu (dot) de
!
! Permission is hereby granted, free of charge, to any person obtaining a copy
! of this software and associated documentation files (the "Software"), to deal
! in the Software without restriction, including without limitation the rights
! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
! copies of the Software, and to permit persons to whom the Software is
! furnished to do so, subject to the following conditions:
!
! The above copyright notice and this permission notice shall be included in all
! copies or substantial portions of the Software.
!
! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
! SOFTWARE.
IMPLICIT NONE
PRIVATE
PUBLIC :: finish ! Write out error message and stop program
! ------------------------------------------------------------------
CHARACTER(len=*), PARAMETER :: separator = repeat('-',70)
! ------------------------------------------------------------------
CONTAINS
! ------------------------------------------------------------------
! NAME
! finish
! PURPOSE
!> \brief Finish a program gracefully
!> \details Stop a program but writing out a message first that is separated
!> from earlier output by -------------- (i.e. the separator)
! CALLING SEQUENCE
! call finish(name, text=text, unit=unit)
! INTENT(IN)
!> \param[in] "character(len=*) :: name" First string separated from otional second by :
! INTENT(INOUT)
! None
! INTENT(OUT)
! None
! INTENT(IN), OPTIONAL
!> \param[in] "character(len=*), optional :: text" Second string separated by :
!> \param[in] "integer, optional :: unit" File unit for write (default: *)
! INTENT(INOUT), OPTIONAL
! None
! INTENT(OUT), OPTIONAL
! None
! RESTRICTIONS
! None
! EXAMPLE
! call finish('main','End gracefully')
! -> see also example in test directory
! LITERATURE
! None
! HISTORY
!> \author Written, Matthias Cuntz - modified from Echam5, (C) MPI-MET, Hamburg, Germany
!> \date Dec 2011
SUBROUTINE finish(name, text, unit)
IMPLICIT NONE
CHARACTER(len=*), INTENT(IN) :: name
CHARACTER(len=*), INTENT(IN), OPTIONAL :: text
INTEGER, INTENT(IN), OPTIONAL :: unit
IF (PRESENT(unit)) THEN
WRITE (unit,'(a)') separator
IF (PRESENT(text)) THEN
WRITE (unit,'(a,a,a)') name, ': ', text
ELSE
WRITE (unit,'(a)') name
END IF
WRITE (unit,'(a)') separator
ELSE
WRITE (*,'(a)') separator
IF (PRESENT(text)) THEN
WRITE (*,'(a,a,a)') name, ': ', text
ELSE
WRITE (*,'(a)') name
END IF
WRITE (*,'(a)') separator
ENDIF
STOP
END SUBROUTINE finish
END MODULE mo_finish