subroutine destroy_watchgroup(handle,err)
character(len=*),parameter :: ident_destroy_watchgroup='M_stopwatch::destroy_watchgroup(3f): destroys a M_StopWatch watch group'
type (watchgroup), intent(in out) :: handle
integer, optional, intent(out) :: err
integer :: erralloc
if (present(err)) then
err=0
end if
if (associated(handle%head)) then
if (handle%wgsize > 1) then
call free_watch_list(handle%head,err)
end if
if (handle%wgsize > 0) then
deallocate(handle%head,stat=erralloc)
if (erralloc > 0) then
call err_handler_watch(ERR_DEALLOC,"destroy_watchgroup","", "Group destroyed, but there may be a memory leak.",err)
end if
nullify(handle%head)
end if
handle%wgsize = 0
end if
end subroutine destroy_watchgroup