!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
module cubecompute_complex
  use cubecompute_two2one_template
  use cubecompute_messaging
  !
  public :: cubecompute_complex_register
  private
  !
  type(two2one_comm_t) :: complex
  !
contains
  !
  subroutine cubecompute_complex_register(error)
    use cubedag_allflags
    !----------------------------------------------------------------------
    ! 
    !----------------------------------------------------------------------
    logical, intent(inout) :: error
    !
    character(len=*), parameter :: rname='COMPLEX>REGISTER'
    !
    call cubecompute_message(computeseve%trace,rname,'Welcome')
    !
    call complex%register_syntax(&
         'COMPLEX','real','imaginary',&
         'Build a complex cube from two aligned real cubes',&
         'Build a complex cube from two aligned real&
         & input cubes over the selected region.'//strg_bl//&
         'Behavior:'//strg_cr//&
         '- The first input fills the real part and the second input fills&
         & the imaginary part for each selected pixel.'//strg_cr//&
         '- Both inputs must be real image-set cubes with matching shapes.'&
         //strg_cr//&
         '- The output is a complex visibility cube.'//strg_bl//&
         'Examples:'//strg_cr//&
         '- CUBE> COMPLEX realcube imagcube.'//strg_cr//&
         '- CUBE> COMPLEX realcube imagcube /RANGE -5km/s 5km/s.',&
         code_access_imaset,[flag_complex],cubecompute_complex_command,error)
    if (error) return
    call complex%act%register_imaima2vis(cubecompute_complex_prog_act,error)
    if (error) return
  end subroutine cubecompute_complex_register
  !
  subroutine cubecompute_complex_command(line,error)
    !----------------------------------------------------------------------
    !
    !----------------------------------------------------------------------
    character(len=*), intent(in)    :: line
    logical,          intent(inout) :: error
    !
    type(two2one_user_t) :: user
    character(len=*), parameter :: rname='COMPLEX>COMMAND'
    !
    call cubecompute_message(computeseve%trace,rname,'Welcome')
    !
    call complex%parse(line,user,error)
    if (error) return
    call complex%main(user,error)
    if (error) continue
  end subroutine cubecompute_complex_command
  !
  !----------------------------------------------------------------------
  !
  subroutine cubecompute_complex_prog_act(ie,real,imaginary,complex,error)
    use cubetools_parameters
    use cubeadm_image_types
    use cubeadm_visi_types
    !----------------------------------------------------------------------
    !
    !----------------------------------------------------------------------
    integer(kind=entr_k), intent(in)    :: ie
    type(image_t),        intent(inout) :: real
    type(image_t),        intent(inout) :: imaginary
    type(visi_t ),        intent(inout) :: complex
    logical,              intent(inout) :: error
    !
    integer(kind=pixe_k) :: ix,iy
    character(len=*), parameter :: rname='COMPLEX>PROG>ACT'
    !
    call real%get(ie,error)
    if (error) return
    call imaginary%get(ie,error)
    if (error) return
    do iy=1,complex%ny
       do ix=1,complex%nx
          complex%val(ix,iy) = cmplx(real%val(ix,iy),imaginary%val(ix,iy))
       enddo ! ix
    enddo ! iy
    call complex%put(ie,error)
    if (error) return
  end subroutine cubecompute_complex_prog_act
end module cubecompute_complex
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
