! $Id: ncdf_error_handler.f90 6490 2020-09-10 17:36:27Z idculv $ subroutine ncdf_error_handler(status) !****s* Misc/ncdf_error_handler ! ! NAME ! ncdf_error_handler - (Internal) error handler for the ncdf library. ! ! SYNOPSIS ! use ncdf ! ... ! status = ! if (status /= nf90_noerr) call ncdf_error_handler(status) ! ! DESCRIPTION ! This subroutine issues a textual error message from a netCDF error status. ! ! INPUTS ! integer :: status ! ! EXAMPLE ! If you want to check whether you have successfully added a global ! attribute "title" to an existing netCDF data file 'test.nc', try ! ! use ncdf ! ... ! character(len=256) :: title = ! ... ! call ncdf_open('test.nc') ! ... ! status = nf90_put_att(ncdf_ncid, nf90_global, "title", trim(title)) ! if (status /= nf90_noerr) call ncdf_error_handler(status) ! ! AUTHOR ! C. Marquardt, Darmstadt, Germany ! ! COPYRIGHT ! ! Copyright (c) 2005 Christian Marquardt ! ! All rights reserved. ! ! Permission is hereby granted, free of charge, to any person obtaining ! a copy of this software and associated documentation files (the ! "Software"), to deal in the Software without restriction, including ! without limitation the rights to use, copy, modify, merge, publish, ! distribute, sublicense, and/or sell copies of the Software, and to ! permit persons to whom the Software is furnished to do so, subject to ! the following conditions: ! ! The above copyright notice and this permission notice shall be ! included in all copies or substantial portions of the Software as well ! as in supporting documentation. ! ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ! NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ! LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ! OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ! WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ! !**** !------------------------------------------------------------------------------ ! 1. Declarations !------------------------------------------------------------------------------ use messages use ncdf, not_this => ncdf_error_handler implicit none integer, intent(in) :: status integer :: status_on_close integer :: istat character(len = 4096) :: text character(len = 1024) :: ncname character(len = 256) :: routine !------------------------------------------------------------------------------ ! 2. Close the netcdf data file !------------------------------------------------------------------------------ status_on_close = nf90_close(ncdf_ncid) if (status_on_close /= nf90_noerr) then call message_get_routine(routine) call message_set_routine('ncdf_error_handler') call message(msg_error, "Attempt to close file failed") call message_set_routine(routine) endif !------------------------------------------------------------------------------ ! 3. Issue an error (and possibly delete the netcdf data file) !------------------------------------------------------------------------------ if (status /= nf90_noerr) then if (ncdf_delete_on_error) then ncname = ncdf_ncname call file_delete(ncname, istat) text = trim(nf90_strerror(status)) // '\n ' // 'File ' // & trim(ncname) // ' deleted.\n' else text = trim(nf90_strerror(status)) endif call message(msg_fatal, trim(text)) end if end subroutine ncdf_error_handler