[1157] | 1 | ! $Id$ |
---|
| 2 | module handle_err_m |
---|
| 3 | |
---|
| 4 | implicit none |
---|
| 5 | |
---|
| 6 | contains |
---|
| 7 | |
---|
| 8 | subroutine handle_err(message, ncerr, ncid, varid) |
---|
| 9 | |
---|
| 10 | use netcdf, only: nf90_strerror, nf90_noerr, nf90_close |
---|
| 11 | |
---|
| 12 | character(len=*), intent(in):: message |
---|
| 13 | ! (should include name of calling procedure) |
---|
| 14 | |
---|
| 15 | integer, intent(in):: ncerr |
---|
| 16 | |
---|
| 17 | integer, intent(in), optional :: ncid |
---|
| 18 | ! (Provide this argument if you want "handle_err" to try to close |
---|
| 19 | ! the file.) |
---|
| 20 | |
---|
| 21 | integer, intent(in), optional :: varid |
---|
| 22 | |
---|
| 23 | ! Variable local to the procedure: |
---|
| 24 | integer ncerr_close |
---|
| 25 | |
---|
| 26 | !------------------- |
---|
| 27 | |
---|
| 28 | if (ncerr /= nf90_noerr) then |
---|
[3815] | 29 | print *, "NetCDF95 handle_err:" |
---|
[1157] | 30 | print *, message, ":" |
---|
| 31 | if (present(varid)) print *, "varid = ", varid |
---|
| 32 | print *, trim(nf90_strerror(ncerr)) |
---|
| 33 | if (present(ncid)) then |
---|
| 34 | ! Try to close, to leave the file in a consistent state: |
---|
| 35 | ncerr_close = nf90_close(ncid) |
---|
| 36 | ! (do not call "nf95_close", we do not want to recurse) |
---|
| 37 | if (ncerr_close /= nf90_noerr) then |
---|
| 38 | print *, "nf90_close:" |
---|
| 39 | print *, trim(nf90_strerror(ncerr_close)) |
---|
| 40 | end if |
---|
| 41 | end if |
---|
[3815] | 42 | call abort_physic("NetCDF95 handle_err", "see above", 1) |
---|
[1157] | 43 | end if |
---|
| 44 | |
---|
| 45 | end subroutine handle_err |
---|
| 46 | |
---|
| 47 | end module handle_err_m |
---|