1 | module nf95_abort_m |
---|
2 | |
---|
3 | implicit none |
---|
4 | |
---|
5 | contains |
---|
6 | |
---|
7 | subroutine nf95_abort(message, ncerr, ncid, varid) |
---|
8 | |
---|
9 | use, intrinsic:: iso_fortran_env, ONLY: error_unit |
---|
10 | |
---|
11 | ! Libraries:mod_phys_lmdz_mpi_transfert |
---|
12 | use netcdf, only: nf90_strerror |
---|
13 | |
---|
14 | use nf95_close_m, only: nf95_close |
---|
15 | use nf95_inq_file_ncid_m, only: nf95_inq_file_ncid |
---|
16 | |
---|
17 | character(len=*), intent(in):: message |
---|
18 | ! (should include name of calling procedure) |
---|
19 | |
---|
20 | integer, intent(in):: ncerr |
---|
21 | |
---|
22 | integer, intent(in), optional :: ncid |
---|
23 | ! This can be the file ncid or a group ncid. Provide this argument |
---|
24 | ! if you want nf95_abort to try to close the file. |
---|
25 | |
---|
26 | integer, intent(in), optional :: varid |
---|
27 | |
---|
28 | ! Local: |
---|
29 | integer ncid_local |
---|
30 | |
---|
31 | !------------------- |
---|
32 | |
---|
33 | write(error_unit, fmt = *) message, ":" |
---|
34 | if (present(varid)) write(error_unit, fmt = *) "varid = ", varid |
---|
35 | write(error_unit, fmt = *) trim(nf90_strerror(ncerr)) |
---|
36 | |
---|
37 | if (present(ncid)) then |
---|
38 | ! Try to close, to leave the file in a consistent state: |
---|
39 | call nf95_inq_file_ncid(ncid_local, ncid) |
---|
40 | call nf95_close(ncid_local) |
---|
41 | end if |
---|
42 | |
---|
43 | stop 1 |
---|
44 | |
---|
45 | end subroutine nf95_abort |
---|
46 | |
---|
47 | end module nf95_abort_m |
---|