!
subroutine debug_all(line,error)
  !$ use omp_lib
  use gkernel_interfaces
  use imager_interfaces, except_this => debug_all
  use clean_def
  use clean_arrays
  use clean_types
  use clean_default
  use gbl_message
  !----------------------------------------------------------------------
  ! @  private
  !
  !! IMAGER  -- Support routine for command DEBUG
  !----------------------------------------------------------------------
  character(len=*), intent(inout) :: line  !! Command line
  logical, intent(out) :: error            !! Logical error flag
  !
  ! Constants
  integer, parameter :: mvoc=8
  character(len=8) :: voca(mvoc)
  data voca /'BUFFERS', 'DEBUG',  'MEMORY', 'METHOD', 'OPTIMIZE', &
    & 'SG', 'THREADS ', 'USER    '/
  ! Local ---
  character(len=8) :: name,argum
  integer :: n, nc, ier, mthread
  integer, allocatable :: mic(:)
  !
  ! Code ----
  argum = '?'
  call sic_ke(line,0,1,argum,n,.false.,error)
  if (error) return
  call sic_ambigs ('DUMP',argum,name,n,voca,mvoc,error)
  if (error) return
  !
  select case(name)
  case ('MEMORY')
    call dump_memory(error)
  case ('USER') 
     call mapping_print_debug(user_method)
  case ('METHOD') 
     call mapping_print_debug(the_method)
  case ('BUFFERS') 
    call uv_dump_buffers('DUMP')
  case ('SG') 
    !
    nc = huv_current%gil%nchan
    if (nc.ne.hcct%gil%dim(2)) then
      Print *,'Mismatch number of channels between HUV ',nc,' and CCT ',hcct%gil%dim(2)
    endif
    !
    allocate(mic(nc),stat=ier)
    call uv_clean_sizes(hcct,dcct,mic,1,nc)
    Print *,'SG_DEBUG -- MIC ',mic
    deallocate(mic)
  case ('THREADS') 
    mthread = 0
    !$ mthread = omp_get_max_threads()
    Print *,'Number of Threads ',mthread
  case ('DEBUG') 
    call sub_print_idebug('DEBUG_APPLY','SELFCAL APPLY')
    call sub_print_debug('DEBUG_CCT','CCT_MERGE')
    call sub_print_debug('DEBUG_GAUSS','CLEAN with GAUSS method')
    call sub_print_debug('DEBUG_MULTI','CLEAN with MULTI method')
    call sub_print_debug('DEBUG_CONT','MAP_CONTINUUM')
    call sub_print_debug('DEBUG_MASK','MASK')
    call sub_print_debug('DEBUG_GUETH','UV_MAP in Mosaic mode GUETH')
    call sub_print_idebug('DEBUG_RESTORE','UV_RESTORE')
    call sub_print_idebug('DEBUG_SAULT','UV_MAP Mosaic mode SAULT')
    call sub_print_debug('DEBUG_MOSAIC','UV_MAP in Mosaic mode')
    call sub_print_idebug('DEBUG_UVMAP','UV_MAP')
    call sub_print_debug('DEBUG_SELF','SELFCAL')
    call sub_print_debug('DEBUG_STOKES','STOKES')
    call sub_print_debug('DEBUG_PREVIEW','UV_PREVIEW')
    call sub_print_debug('DEBUG_RESIDUAL','UV_RESIDUAL and/or UV_RESTORE')
    error = .false.
  case ('OPTIMIZE')
    !! call debug_optimize
  end select
  !
end subroutine debug_all
!
subroutine sub_print_debug(var,purpose)
  character(len=*), intent(in) :: var
  character(len=*), intent(in) :: purpose
  logical :: error, debug
  !
  debug = .false.
  call sic_get_logi(var,debug,error)
  if (error) then
    write(*,'(A,T20,A,T40,A)') var,' logical undefined',' (for '//purpose//') '
  else
    write(*,'(A,T20,A,L,T40,A)') var,' is set to ',debug,' (for '//purpose//') '
  endif
end subroutine sub_print_debug
!
subroutine sub_print_idebug(var,purpose)
  character(len=*), intent(in) :: var
  character(len=*), intent(in) :: purpose
  logical :: error
  integer :: idebug
  !
  idebug = 0
  call sic_get_inte(var,idebug,error)
  if (error) then
    write(*,'(A,T20,A,T40,A)') var,' integer undefined',' (for '//purpose//') '
  else
    write(*,'(A,T20,A,I3,T40,A)') var,' is set to ',idebug,' (for '//purpose//') '
  endif
end subroutine sub_print_idebug
!
subroutine print_imaging(comm,name,img)
  use image_def
  use gbl_message
  use imager_interfaces, only : map_message
  ! @ private
  !!    Print a Debug message to track selected channels
  character(len=*),intent(in) :: comm     !! Command name
  character(len=*),intent(in) :: name     !! Buffer name
  type(imaging_mode), intent(in) :: img   !! Imaging structure
  !
  character(len=128) :: chain
  character(len=14) :: img_mode(-1:1)
  data img_mode /'Continuum --', 'No Imaging --', 'Cube -- '/
  !
  write(chain,'(A,A,I0,A,I0,A,F9.3,A,I0)') name//' -- ', &
    & trim(img_mode(img%mode))//" from [", &
    & img%bounds(1),",",img%bounds(2),"]  Reference ",img%chfreq, &
    & "    Weight ",img%weight
  if (comm.ne.' ') then
    call map_message(seve%i,comm,chain,seve%w)
  else
    write(*,'(A)') trim(chain)
  endif
end subroutine print_imaging
