!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
module cubemain_stitch
  use cubetools_structure
  use cubemain_messaging
  use cubemain_merging
  !
  type :: stitch_comm_t
     type(option_t), pointer :: comm
     type(merging_comm_t)    :: merge
   contains
     procedure, public  :: register => cubemain_stitch_register
     procedure, public  :: parse    => cubemain_stitch_parse
     procedure, public  :: main     => cubemain_stitch_main
  end type stitch_comm_t
  type(stitch_comm_t) :: stitch
  !
contains
  !
  subroutine cubemain_stitch_command(line,error)
    !----------------------------------------------------------------------
    ! 
    !----------------------------------------------------------------------
    character(len=*), intent(in)    :: line
    logical,          intent(inout) :: error
    !
    type(merging_user_t) :: user
    character(len=*), parameter :: rname='STITCH>COMMAND'
    !
    call cubemain_message(mainseve%trace,rname,'Welcome')
    !
    call stitch%parse(line,user,error)
    if (error) return
    !
    call stitch%main(user,error)
    if (error) return
  end subroutine cubemain_stitch_command
  !
  !----------------------------------------------------------------------
  !
  subroutine cubemain_stitch_register(stitch,error)
    use cubedag_allflags
    !----------------------------------------------------------------------
    !
    !----------------------------------------------------------------------
    class(stitch_comm_t), intent(inout) :: stitch
    logical,              intent(inout) :: error
    !
    character(len=*), parameter :: rname='STITCH>REGISTER'
    !
    call cubemain_message(mainseve%trace,rname,'Welcome')
    !
    call cubetools_register_command(&
         'STITCH','',&
         'Stitch cubes from the current index',&
         'STITCH merges cubes from the current index into one stitched&
         & output cube.'//strg_bl//&
         'Behavior:'//strg_cr//&
         '- Input cubes come from the current default index.'//strg_cr//&
         '- Spectral alignment and output-header controls are provided by&
         & /ALIGN and merge options (/LIKE, /LAXIS, /MAXIS, /FAXIS,&
         & /VAXIS, /PTYPE, /PCENTER, /PANGLE, /FREQUENCY).'//strg_cr//&
         '- Without explicit axis/projection options, output axes are&
         & expanded to cover data from all indexed cubes.'//strg_cr//&
         '- Output family defaults to the first cube family in the index.&
         & /FAMILY overrides it.'//strg_bl//&
         'Examples:'//strg_cr//&
         'CUBE> STITCH'//strg_cr//&
         'CUBE> STITCH /ALIGN VELOCITY'//strg_cr//&
         'CUBE> STITCH /LIKE refcube /FAMILY stitched',&
         cubemain_stitch_command,&
         stitch%comm,&
         error)
    if (error) return
    !
    call stitch%merge%register('stitched',flag_stitch,error)
    if (error) return
  end subroutine cubemain_stitch_register
  !
  subroutine cubemain_stitch_parse(stitch,line,user,error)
    !----------------------------------------------------------------------
    ! 
    !----------------------------------------------------------------------
    class(stitch_comm_t),  intent(in)    :: stitch
    character(len=*),      intent(in)    :: line
    class(merging_user_t), intent(out)   :: user
    logical,               intent(inout) :: error
    !
    character(len=*), parameter :: rname='STITCH>PARSE'
    !
    call cubemain_message(mainseve%trace,rname,'Welcome')
    !
    call stitch%merge%parse(line,user,error)
    if (error) return
  end subroutine cubemain_stitch_parse
  !
  subroutine cubemain_stitch_main(stitch,user,error)
    !----------------------------------------------------------------------
    ! 
    !----------------------------------------------------------------------
    class(stitch_comm_t),  intent(in)    :: stitch
    class(merging_user_t), intent(in)    :: user
    logical,               intent(inout) :: error
    !
    type(merging_prog_t) :: prog
    character(len=*), parameter :: rname='STITCH>MAIN'
    !
    call cubemain_message(mainseve%trace,rname,'Welcome')
    !
    call user%toprog(stitch%merge,prog,error)
    if (error) return
    call prog%main(stitch%merge,error)
    if (error) return
  end subroutine cubemain_stitch_main
end module cubemain_stitch
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
