source: LMDZ6/trunk/tools/netcdf95/nf95_abort.f90 @ 5233

Last change on this file since 5233 was 5084, checked in by Laurent Fairhead, 4 months ago

Reverting to r4065. Updating fortran standard broke too much stuff. Will do it by smaller chunks
AB, LF

File size: 1.1 KB
Line 
1module nf95_abort_m
2
3  implicit none
4
5contains
6
7  subroutine nf95_abort(message, ncerr, ncid, varid)
8
9    use, intrinsic:: iso_fortran_env
10
11    ! Libraries:
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
47end module nf95_abort_m
Note: See TracBrowser for help on using the repository browser.