!-------------------------------------------------
!  SCpack Module
!-------------------------------------------------
module scpack
  use dcl_common
  contains
!-----------------------------------------------------------------------
!正規化変換 
    subroutine DclSet3DViewPort(xmin,xmax, ymin,ymax, zmin,zmax)
      real, intent(in) :: xmin, xmax, ymin, ymax, zmin, zmax
      call scsvpt(xmin,xmax,ymin,ymax,zmin,zmax)
    end subroutine

    subroutine DclSet3DWindow(xmin,xmax,ymin,ymax,zmin,zmax) !ウインドウの設定．
      real, intent(in) :: xmin, xmax, ymin, ymax, zmin, zmax
      call scswnd(xmin,xmax,ymin,ymax,zmin,zmax)
    end subroutine

    subroutine DclSet3DLogAxis(log_x,log_y,log_z) !対数軸の設定．
      logical,  intent(in) :: log_x, log_y, log_z      !直角直線座標の対数軸指定
      call scslog(log_x, log_y, log_z )
    end subroutine

    subroutine DclSet3DOrigin(factor,x,y,z) !スケーリングファクターと原点の設定
      real, intent(in) :: factor   !円筒座標，球座標のスケーリングファクター
      real, intent(in) :: x, y, z  !円筒座標，球座標の原点の位置
      call scsorg(factor, x, y, z)
    end subroutine

    subroutine DclSet3DTransNumber(number) !変換関数番号の設定
      integer,   intent(in) :: number  !変換関数番号
      call scstrn(number)
    end subroutine

    subroutine DclSet3DTransFunction() !変換関数の確定． 
      call scstrf()
    end subroutine
        
!パラメタ参照ルーチン
    subroutine DclGet3DViewPort(xmin,xmax,ymin,ymax,zmin,zmax)
      real, intent(out) :: xmin, xmax, ymin, ymax, zmin, zmax
      call scqvpt(xmin,xmax,ymin,ymax,zmin,zmax)
    end subroutine

    subroutine DclGet3DWindow(xmin,xmax,ymin,ymax,zmin,zmax) 
      real, intent(out) :: xmin, xmax, ymin, ymax, zmin, zmax
      call scqwnd(xmin,xmax,ymin,ymax,zmin,zmax) 
    end subroutine

    subroutine DclGet3DLogAxis(log_x,log_y,log_z) 
      logical, intent(out) :: log_x,log_y,log_z
      call scqlog(log_x,log_y,log_z) 
    end subroutine

    subroutine DclGet3DOrigin(factor, x, y, z) 
      real, intent(out) :: factor   !円筒座標，球座標のスケーリングファクター
      real, intent(out) :: x, y, z  !円筒座標，球座標の原点の位置
      call scqorg(factor, x, y, z)
    end subroutine

    function DclGet3DTransNumber(number) 
      integer :: DclGet3DTransNumber        !変換関数番号
      call scqtrn(DclGet3DTransNumber) 
    end function
!-----------------------------------------------------------------------------
!透視変換
    subroutine DclSet3DEyePoint(x, y, z)  !視点の設定．
      real, intent(in) :: x, y, z
      call scseye(x, y, z)
    end subroutine

    subroutine DclSet3DObjectPoint(x, y, z)  !焦点の設定
      real, intent(in) :: x, y, z
      call scsobj(x, y, z)
    end subroutine

    subroutine DclSet2DPlane(x_dir, y_dir, section)  !2次元平面の割付
      integer, intent(in) :: x_dir, y_dir
      real,    intent(in) :: section
      call scspln(x_dir, y_dir, section)
    end subroutine
 
    subroutine DclSet3DProjection()  !透視変換の確定． 
      call scsprj()
    end subroutine

!パラメタ参照ルーチン
    subroutine DclGet3DEyePoint(x, y, z)
      real, intent(out) :: x, y, z
      call scqeye(x, y, z)
    end subroutine

    subroutine DclGet3DObjectPoint(x, y, z)
      real, intent(out) :: x, y, z
      call scqobj(x, y, z)
    end subroutine

    subroutine DclGet2DPlane(x_dir, y_dir, section)
      integer, intent(out) :: x_dir, y_dir
      real,    intent(out) :: section
      call scqpln(x_dir, y_dir, section)
    end subroutine

!-----------------------------------------------------------------------------
!ポリライン
    subroutine DclDraw3DLine(x,y,z,index)  !u 座標系で折れ線を描く．  
      real,    intent(in), dimension(:) :: x, y, z !折れ線を結ぶ点のU座標
      integer, intent(in), optional     :: index
        
        if(present(index)) then
          index0 = index
        else
          call scqpli(index0)
        end if

        nx = size(x)
        ny = size(y)
        nz = size(z)
        if(nx.ne.ny .or. ny.ne.nz) call msgdmp('M', 'DclDraw3DLine',  &
                                    & 'Length of x, y, z don''t match.')
        n = min(nx, ny, nz)

        call scplzu(n,x,y,z,index0) 
    end subroutine

    subroutine DclDraw3DLineNormalized(x,y,z,index)   !v 座標系で折れ線を描く
      real,    intent(in), dimension(:) :: x, y, z !折れ線を結ぶ点のU座標
      integer, intent(in), optional     :: index
        
        if(present(index)) then
          index0 = index
        else
          call scqpli(index0)
        end if

        nx = size(x)
        ny = size(y)
        nz = size(z)
        if(nx.ne.ny .or. ny.ne.nz) call msgdmp('M', 'DclDraw3DLineNormalized',  &
                                    & 'Length of x, y, z don''t match.')
        n = min(nx, ny, nz)

        call scplzv(n,x,y,z,index0) 
    end subroutine

    subroutine DclSet3DLineIndex(index)  !ラインインデクスの設定．
      integer,   intent(in) :: index  !折れ線のラインインデクス 
      call scspli(index)
    end subroutine
        
    function DclGet3DLineIndex()
      integer  :: DclGet3DLineIndex     !折れ線のラインインデクス 
      call scqpli(DclGet3DLineIndex)
    end function
    
!------------------------------------------------------------------------------
! ポリマーカー
    subroutine DclDraw3DMarker(x,y,z,type,index,height)  !u 座標系でマーカー列を描く
      real,    intent(in), dimension(:) :: x, y, z
      integer, intent(in), optional     :: type, index
      real,    intent(in), optional     :: height

      integer :: type0, index0

        if(present(type)) then
          type0 = type
        else
          call scqpmt(type0)
        end if

        if(present(index)) then
          index0 = index
        else
          call scqpmi(index0)
        end if

        if(present(height)) then
          height0 = height
        else
          call scqpms(height0)
        end if

        nx = size(x)
        ny = size(y)
        nz = size(z)
        if(nx.ne.ny .or. ny.ne.nz) call msgdmp('M', 'DclDraw3DMarker',  &
                                    & 'Length of x, y, z don''t match.')
        n = min(nx, ny, nz)

        call scpmzu(n, x, y, z, type0, index0, height0)
    end subroutine

    subroutine DclDraw3DMarkerNormalized(x,y,z,type,index,height)
      real,    intent(in), dimension(:) :: x, y, z
      integer, intent(in), optional     :: type, index
      real,    intent(in), optional     :: height

      integer :: type0, index0

        if(present(type)) then
          type0 = type
        else
          call scqpmt(type0)
        end if

        if(present(index)) then
          index0 = index
        else
          call scqpmi(index0)
        end if

        if(present(height)) then
          height0 = height
        else
          call scqpms(height0)
        end if

        nx = size(x)
        ny = size(y)
        nz = size(z)
        if(nx.ne.ny .or. ny.ne.nz) call msgdmp('M', 'DclDraw3DMarkerNormalized',  &
                                    & 'Length of x, y, z don''t match.')
        n = min(nx, ny, nz)

        call scpmzv(n, x, y, z, type0, index0, height0)
    end subroutine

    subroutine DclSet3DMarkerType(type)  !マーカータイプの設定．    
      integer,   intent(in) :: type  !マーカータイプ
      call scspmt(type)
    end subroutine

    subroutine DclSet3DMarkerIndex(index)  !マーカーのラインインデクスの設定  
      integer,   intent(in) :: index  !マーカーを描く線のラインインデクス 
      call scspmi(index)
    end subroutine

    subroutine DclSet3DMarkerSize(height)  !マーカーの大きさ設定．      
      real,      intent(in) :: height  !マーカーの大きさ
      call scspms(height)
    end subroutine
                
! パラメタ参照ルーチン
    function DclGet3DMarkerType()
      integer :: DclGet3DMarkerType !マーカータイプ
      call scqpmt(DclGet3DMarkerType)
    end function

    function DclGet3DMarkerIndex()
      integer :: DclGet3DMarkerIndex    !マーカーを描く線のラインインデクス
      call scqpmi(DclGet3DMarkerIndex)
    end function

    function DclGet3DMarkerSize()  
      real :: DclGet3DMarkerSize    !マーカーの大きさをR-座標系における単位で指定
      call scqpms(DclGet3DMarkerSize)  
    end function

!--------------------------------------------------------------------
!トーン
    subroutine DclDraw3DHatch(x,y,z,pattern1,pattern2)
      real,    intent(in), dimension(3) :: x, y, z
      integer, intent(in), optional     :: pattern1, pattern2

        if(present(pattern1)) then
          itpat1 = pattern1
        else
          call scqtnp(itpat1,idummy) 
        end if

        if(present(pattern2)) then
          itpat2 = pattern2
        else
          call scqtnp(idummy, itpat2) 
        end if

        call sctnzu(x,y,z,itpat1,itpat2) 
    end subroutine

    subroutine DclDraw3DHatchNormalized(x,y,z,pattern1,pattern2)
      real,    intent(in), dimension(3) :: x, y, z
      integer, intent(in), optional     :: pattern1, pattern2

        if(present(pattern1)) then
          itpat1 = pattern1
        else
          call scqtnp(itpat1,idummy) 
        end if

        if(present(pattern2)) then
          itpat2 = pattern2
        else
          call scqtnp(idummy, itpat2) 
        end if

        call sctnzv(x,y,z,itpat1,itpat2) 
    end subroutine

    subroutine DclSet3DHatchPattern(pattern1,pattern2)  !トーンパターン番号設定． 
      integer,   intent(in) :: pattern1,pattern2
      call scstnp(pattern1,pattern2) 
    end subroutine

    subroutine DclGet3DHatchPattern(pattern1,pattern2)
      integer,   intent(out) :: pattern1,pattern2
      call scqtnp(pattern1,pattern2) 
    end subroutine

end module

