-
Notifications
You must be signed in to change notification settings - Fork 14
/
utils.F90
86 lines (64 loc) · 1.99 KB
/
utils.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
module utils_mod
implicit none
integer, parameter, public :: DEBUG = 0, INFORM = 1, WARN = 2, ERROR_CODE = 3
contains
!> @file
!! @brief Contains utility routines.
!!
!> General error handler.
!!
!! @param[in] string error message
!! @param[in] rc error status code
subroutine error_handler(string, rc)
use mpi
implicit none
character(len=*), intent(in) :: string
integer, intent(in) :: rc
integer :: ierr
print *, "- FATAL ERROR: "
write(*,'(A)') trim(string)
print *, "- IOSTAT IS: ", rc
call mpi_abort(mpi_comm_world, 999, ierr)
end subroutine error_handler
!> Error handler for netcdf
!!
!! @param[in] err error status code
!! @param[in] string error message
subroutine netcdf_err(err, string)
use mpi
use netcdf
implicit none
integer, intent(in) :: err
character(len=*), intent(in) :: string
character(len=256) :: errmsg
integer :: iret
if (err .EQ. NF90_NOERR) return
errmsg = NF90_STRERROR(err)
print *, ''
print *, 'FATAL ERROR: ', trim(string), ': ', trim(errmsg)
print *, 'STOP.'
call mpi_abort(mpi_comm_world, 999, iret)
return
end subroutine netcdf_err
!> Convert string from lower to uppercase.
!! @author Clive Page
!!
!! Adapted from http://www.star.le.ac.uk/~cgp/fortran.html (25 May 2012)
!!
!! @param[in] strIn string to convert
!! @return strOut string in uppercase
function to_upper(strIn) result(strOut)
implicit none
character(len=*), intent(in) :: strIn
character(len=len(strIn)) :: strOut
integer :: i, j
do i = 1, len(strIn)
j = iachar(strIn(i:i))
if (j >= iachar("a") .and. j <= iachar("z")) then
strOut(i:i) = achar(iachar(strIn(i:i)) - 32)
else
strOut(i:i) = strIn(i:i)
end if
end do
end function to_upper
end module utils_mod