!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
module cubedag_memory
  use cubetools_parameters
  use cubetools_structure
  use cubedag_messaging
  use cubedag_dag_buffer
  !
  public :: memory
  private
  !
  type :: memory_comm_t
    type(option_t), pointer :: comm
  contains
    procedure, public  :: register => cubedag_memory_register
    procedure, private :: parse    => cubedag_memory_parse
    procedure, private :: main     => cubedag_memory_main
  end type memory_comm_t
  type(memory_comm_t) :: memory
  !
  type memory_user_t
  contains
    procedure, private :: toprog => cubedag_memory_user_toprog
  end type memory_user_t
  !
  type memory_prog_t
  contains
    procedure, public :: act => cubedag_memory_act
  end type memory_prog_t
  !
contains
  !
  subroutine cubedag_memory_command(line,error)
    !-------------------------------------------------------------------
    ! Support routine for command MEMORY
    !-------------------------------------------------------------------
    character(len=*), intent(in)    :: line
    logical,          intent(inout) :: error
    !
    type(memory_user_t) :: user
    character(len=*), parameter :: rname='MEMORY>COMMAND'
    !
    call cubedag_message(dagseve%trace,rname,'Welcome')
    !
    call memory%parse(line,user,error)
    if (error) return
    call memory%main(user,error)
    if (error) return
  end subroutine cubedag_memory_command
  !
  subroutine cubedag_memory_register(memory,error)
    !---------------------------------------------------------------------
    !
    !---------------------------------------------------------------------
    class(memory_comm_t), intent(inout) :: memory
    logical,              intent(inout) :: error
    !
    character(len=*), parameter :: rname='MEMORY>REGISTER'
    !
    call cubedag_message(dagseve%trace,rname,'Welcome')
    !
    call cubetools_register_command(&
         'MEMORY','',&
         'Display the current memory and disk footprint',&
         strg_emp,&
         cubedag_memory_command,&
         memory%comm,error)
    if (error) return
  end subroutine cubedag_memory_register
  !
  subroutine cubedag_memory_parse(memory,line,user,error)
    use cubetools_disambiguate
    !-------------------------------------------------------------------
    ! Parsing facility for command MEMORY
    !-------------------------------------------------------------------
    class(memory_comm_t), intent(inout) :: memory
    character(len=*),     intent(in)    :: line
    type(memory_user_t),  intent(out)   :: user
    logical,              intent(inout) :: error
    !
    character(len=*), parameter :: rname='MEMORY>PARSE'
    !
    call cubedag_message(dagseve%trace,rname,'Welcome')
  end subroutine cubedag_memory_parse
  !
  subroutine cubedag_memory_main(memory,user,error)
    !-------------------------------------------------------------------
    !
    !-------------------------------------------------------------------
    class(memory_comm_t), intent(in)    :: memory
    type(memory_user_t),  intent(in)    :: user
    logical,              intent(inout) :: error
    !
    type(memory_prog_t) :: prog
    character(len=*), parameter :: rname='MEMORY>MAIN'
    !
    call cubedag_message(dagseve%trace,rname,'Welcome')
    !
    call user%toprog(prog,error)
    if (error) return
    call prog%act(error)
    if (error) return
  end subroutine cubedag_memory_main
  !
  subroutine cubedag_memory_user_toprog(user,prog,error)
    !-------------------------------------------------------------------
    ! 
    !-------------------------------------------------------------------
    class(memory_user_t), intent(in)    :: user
    type(memory_prog_t),  intent(out)   :: prog
    logical,              intent(inout) :: error
    !
    character(len=*), parameter :: rname='MEMORY>USER2PROG'
    !
    call cubedag_message(dagseve%trace,rname,'Welcome')
  end subroutine cubedag_memory_user_toprog
  !
  subroutine cubedag_memory_act(prog,error)
    use cubetools_format
    !---------------------------------------------------------------------
    !
    !---------------------------------------------------------------------
    class(memory_prog_t), intent(in)    :: prog
    logical,              intent(inout) :: error
    !
    character(len=*), parameter :: rname='MEMORY>COMMAND'
    !
    call cubedag_message(seve%r,rname,  &
      'DAG size in memory is '//cubetools_format_memsize(cubedag_dag_memsize()))
    call cubedag_message(seve%r,rname,  &
      'DAG size on disk   is '//cubetools_format_memsize(cubedag_dag_disksize()))
  end subroutine cubedag_memory_act
end module cubedag_memory
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
