!----------------------------------------------
!  USpack Module
!----------------------------------------------
module uspack
  use dcl_common
  contains
!----------------------------------------------------
    subroutine DclDrawAxis
      call usdaxs
    end subroutine
!----------------------------------------------------
    subroutine DclFitScalingParm
      call uspfit
    end subroutine
!----------------------------------------------------
    subroutine DclDrawXAxis(side)
      character(len=*), intent(in) :: side
      call usxaxs(side)
    end subroutine
!----------------------------------------------------
    subroutine DclDrawYAxis(side)
      character(len=*), intent(in) :: side
      call usyaxs(side)
    end subroutine
!----------------------------------------------------
    subroutine DclDrawGraph(x, y, type, index)
      real,    intent(in), dimension(:) :: x, y
      integer, intent(in), optional     :: type,  index
      integer                           :: type0, index0

      call glrget('rundef', rundef)

      if(present(type)) then
        type0 = type
      else
        call sgqplt(type0)
      end if
        
      if(present(index)) then
        index0 = index
      else
        call sgqpli(index0)
      end if

      nx = size(x)
      ny = size(y)
      if(nx.ne.ny) call msgdmp('M', 'DclScalingPoint', 'Length of x and y don''t match.')
      n = min(nx, ny)

      call usspnt(n, x, y)
      call uspfit
      call grstrf
      call usdaxs
      call sgplzu(n, x, y, type0, index0)

    end subroutine
!----------------------------------------------------
    subroutine DclScalingPoint(x, y)
      real, dimension(:), intent(in), optional :: x, y

      call glrget('rundef', rundef)

      if(present(x) .and. present(y)) then
        nx = size(x)
        ny = size(y)
        if(nx.ne.ny) call msgdmp('M', 'DclScalingPoint', 'Length of x and y don''t match.')
        n = min(nx, ny)
        call usspnt(n, x, y)
      else if(present(x)) then
        n = size(x)
        call usspnt(n, x, rundef)
      else if(present(y)) then
        n = size(y)
        call usspnt(n, rundef, y)
      end if
      
    end subroutine
!----------------------------------------------------
    subroutine DclSetTitle(xtitle, ytitle, xunit, yunit)
      character(len=*), intent(in)           :: xtitle, ytitle
      character(len=*), intent(in), optional :: xunit, yunit

      character(len=80)                      :: xunit0, yunit0

      if(present(xunit)) then
        xunit0 = xunit
      else
        xunit0 = ' '
      end if

      if(present(yunit)) then
        yunit0 = yunit
      else
        yunit0 = ' '
      end if
    
      call ussttl(xtitle, xunit0, ytitle, yunit0)
    end subroutine
!----------------------------------------------------
end module
