!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
module cubeadm_language
  use cubetools_parameters
  use cubetools_structure
  use cubeadm_messaging
  use cubeadm_checksum
  use cubeadm_directory
  use cubeadm_export
  use cubeadm_flag
  use cubeadm_import
  use cubeadm_touch
  use cubeadm_transpose
  use cubeadm_update
  use cubeadm_verify
  !
  public :: cubeadm_register_language
  private
  !
  integer(kind=lang_k) :: langid
  !
contains
  !
  subroutine cubeadm_register_language(error)
    !----------------------------------------------------------------------
    ! Register the ADM\ language
    !----------------------------------------------------------------------
    logical, intent(inout) :: error
    !
    call cubetools_register_language(&
         'ADM',&
         'J.Pety, S.Bardeau, V.deSouzaMagalhaes',&
         'Commands to manage list of cubes',&
         'ADM manages cube registration and metadata operations in the DAG.'//strg_bl//&
         'Behavior:'//strg_cr//&
         '- DIRECTORY defines raw/reduced/tmp search locations.'//strg_cr//&
         '- IMPORT reads files into the DAG and EXPORT writes DAG cubes to files.'//strg_cr//&
         '- UPDATE, FLAG, and VERIFY maintain or validate cube metadata.'//strg_bl//&
         'Typical workflow:'//strg_cr//&
         'CUBE> ADM\DIRECTORY /RAW ./raw /RED ./red'//strg_cr//&
         'CUBE> ADM\IMPORT'//strg_cr//&
         'CUBE> ADM\UPDATE mycube /FLAGS =science'//strg_cr//&
         'CUBE> ADM\EXPORT mycube /FORMAT FITS',&
         'gag_doc:hlp/cube-help-adm.hlp',&
         cubeadm_execute_command,&
         langid,&
         error)
    if (error) return
    !
    call checksum%register(error)
    if (error) return
    call directory%register(error)
    if (error) return
    call export%register(error)
    if (error) return
    call flag%register(error)
    if (error) return
    call import%register(error)
    if (error) return
    call update%register(error)
    if (error) return
    call verify%register(error)
    if (error) return
    if (cube_dev_mode()) then
      call touch%register(error)
      if (error) return
      call transpose%register(error)
      if (error) return
    endif
    !
    call cubetools_register_dict(error)
    if (error) return
  end subroutine cubeadm_register_language
  !
  subroutine cubeadm_execute_command(line,comm,error)
    use cubeadm_opened
    use cubeadm_timing
    !----------------------------------------------------------------------
    ! Execute a command of the ADM\ language
    !----------------------------------------------------------------------
    character(len=*), intent(in)    :: line
    character(len=*), intent(in)    :: comm
    logical,          intent(inout) :: error
    !
    character(len=*), parameter :: rname='EXECUTE>COMMAND'
    !
    error = .false.
    if (comm.eq.'ADM?') then
       call cubetools_list_language_commands(langid,error)
       if (error) return
    else
       call cubeadm_timing_init()
       call cubetools_execute_command(line,langid,comm,error)
       if (error) continue ! To ensure error recovery in the call to cubeadm_finish_all
       call cubeadm_finish_all(comm,line,error)
       if (error) continue ! To ensure error recovery in timing
       call cubeadm_timing_final(comm)
    endif
  end subroutine cubeadm_execute_command
end module cubeadm_language
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
