module handerr

contains

  subroutine handle_err(errcode, var)

    implicit none
    include 'netcdf.inc'
  
    integer,intent(in) :: errcode
    character*20,intent(in),optional :: var
  
    if (present(var)) then
      print *, 'Error: ', nf_strerror(errcode), " var: ", var
    else
      print *, 'Error: ', nf_strerror(errcode)
    endif
    stop 2

  end subroutine handle_err

end module handerr
