-
Notifications
You must be signed in to change notification settings - Fork 2
/
nf95_abort.f90
48 lines (31 loc) · 1.21 KB
/
nf95_abort.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
module nf95_abort_m
implicit none
contains
subroutine nf95_abort(message, ncerr, ncid, varid, attnum)
use, intrinsic:: iso_fortran_env
! Libraries:
use netcdf, only: nf90_strerror
use nf95_close_m, only: nf95_close
use nf95_inq_file_ncid_m, only: nf95_inq_file_ncid
character(len=*), intent(in):: message
! (should include name of calling procedure)
integer, intent(in), optional:: ncerr
integer, intent(in), optional :: ncid
! This can be the file ncid or a group ncid. Provide this argument
! if you want nf95_abort to try to close the file.
integer, intent(in), optional :: varid, attnum
! Local:
integer ncid_local
!-------------------
write(error_unit, fmt = *) message, ":"
if (present(varid)) write(error_unit, fmt = *) "varid = ", varid
if (present(attnum)) write(error_unit, fmt = *) "attnum = ", attnum
if (present(ncerr)) write(error_unit, fmt = *) trim(nf90_strerror(ncerr))
if (present(ncid)) then
! Try to close, to leave the file in a consistent state:
call nf95_inq_file_ncid(ncid_local, ncid)
call nf95_close(ncid_local)
end if
stop 1
end subroutine nf95_abort
end module nf95_abort_m