! gtgraph_generic.f90 - 
! Copyright (C) TOYODA Eizi, 2000.  All rights reserved.

module gtgraph_generic

    implicit none
    interface Inquire
        subroutine GtObjInquire(obj, type)
            use gtgraph_types, only: GT_OBJECT
            type(GT_OBJECT), intent(in):: obj
            character(len = *), intent(out), optional:: type
        end subroutine
    end interface

    interface Open

        ! --- デフォルトコンストラクタ ---

        subroutine GTObjOpen(obj)
            use gtgraph_types, only: GT_OBJECT
            type(GT_OBJECT), intent(out):: obj
        end subroutine

        subroutine GTDevOpen(dev, ws_id, err)
            use gtgraph_types, only: GT_DEVICE
            type(GT_DEVICE), intent(out):: dev
            integer, intent(in), optional:: ws_id
            logical, intent(out), optional:: err
        end subroutine

        subroutine GTFrameOpen(frame)
            use gtgraph_types, only: GT_FRAME
            type(GT_FRAME), intent(out):: frame
        end subroutine

        subroutine GTFigOpen(fig)
            use gtgraph_types, only: GT_FIGURE
            type(GT_FIGURE), intent(out):: fig
        end subroutine

        ! --- GTOOL_VARIABLE を引数に取る Open ---

        subroutine GTContOpen(cont, var)
            use gtgraph_types, only: GT_CONTOURS
            use gtdata_types, only: GT_VARIABLE
            type(GT_CONTOURS), intent(out):: cont
            type(GT_VARIABLE), intent(in):: var
        end subroutine

        subroutine GTVectOpen(vect, var1, var2)
            use gtgraph_types, only: GT_VECTORS
            use gtdata_types, only: GT_VARIABLE
            type(GT_VECTORS), intent(out):: vect
            type(GT_VARIABLE), intent(in):: var1
            type(GT_VARIABLE), intent(in):: var2
        end subroutine

        subroutine GTLineOpen(Line, var)
            use gtgraph_types, only: GT_Line
            use gtdata_types, only: GT_VARIABLE
            type(GT_Line), intent(out):: Line
            type(GT_VARIABLE), intent(in):: var
        end subroutine

        subroutine GTAxisOpen(axis, var, dimno, vertical)
            use gtgraph_types, only: GT_AXIS
            use gtdata_types, only: GT_VARIABLE
            type(GT_AXIS), intent(out):: axis
            type(GT_VARIABLE), intent(in):: var
            integer, intent(in):: dimno
            logical, intent(in), optional:: vertical
        end subroutine

    end interface

    interface Close

        subroutine GTDevClose(dev)
            use gtgraph_types, only: GT_DEVICE
            type(GT_DEVICE), intent(inout):: dev
        end subroutine

        recursive subroutine GTObjClose(obj)
            use gtgraph_types, only: GT_OBJECT
            type(GT_OBJECT), intent(inout):: obj
        end subroutine

        subroutine GTFrameClose(frame)
            use gtgraph_types, only: GT_FRAME
            type(GT_FRAME), intent(inout):: frame
        end subroutine

        subroutine GTFigClose(fig)
            use gtgraph_types, only: GT_FIGURE
            type(GT_FIGURE), intent(inout):: fig
        end subroutine

        subroutine GTContClose(cont)
            use gtgraph_types, only: GT_CONTOURS
            type(GT_CONTOURS), intent(inout):: cont
        end subroutine

        subroutine GTVectClose(vect)
            use gtgraph_types, only: GT_VECTORS
            type(GT_VECTORS), intent(inout):: vect
        end subroutine

        subroutine GTLineClose(Line)
            use gtgraph_types, only: GT_LINE
            type(GT_LINE), intent(inout):: Line
        end subroutine

        subroutine GTAxisClose(axis)
            use gtgraph_types, only: GT_AXIS
            type(GT_AXIS), intent(inout):: axis
        end subroutine

    end interface

        ! 内部的に使用
    interface Clear
        subroutine GTObjClear(obj)
            use gtgraph_types, only: GT_OBJECT
            type(GT_OBJECT), intent(inout):: obj
        end subroutine
    end interface

    interface Option

        subroutine GtObjOption(obj, optname, value, err)
            use gtgraph_types, only: GT_OBJECT
            type(GT_OBJECT), intent(in):: obj
            character(len = *), intent(in):: optname
            character(len = *), intent(in):: value
            logical, intent(out):: err
        end subroutine

        subroutine GtFigOption(fig, optname, value, err)
            use gtgraph_types, only: GT_FIGURE
            type(GT_FIGURE), intent(inout):: fig
            character(len = *), intent(in):: optname
            character(len = *), intent(in):: value
            logical, intent(out):: err
        end subroutine

        subroutine GtContOption(cont, optname, value, err)
            use gtgraph_types, only: GT_CONTOURS
            type(GT_CONTOURS), intent(inout):: cont
            character(len = *), intent(in):: optname
            character(len = *), intent(in):: value
            logical, intent(out):: err
        end subroutine

        subroutine GtVectOption(vect, optname, value, err)
            use gtgraph_types, only: GT_VECTORS
            type(GT_VECTORS), intent(inout):: vect
            character(len = *), intent(in):: optname
            character(len = *), intent(in):: value
            logical, intent(out):: err
        end subroutine

        subroutine GtLineOption(line, optname, value, err)
            use gtgraph_types, only: GT_LINE
            type(GT_LINE), intent(inout):: line
            character(len = *), intent(in):: optname
            character(len = *), intent(in):: value
            logical, intent(out):: err
        end subroutine

    end interface

    interface Bind

        subroutine GTObjBindObj(parent, child)
            use gtgraph_types, only: GT_OBJECT
            type(GT_OBJECT), intent(inout):: parent
            type(GT_OBJECT), intent(in):: child
        end subroutine

        subroutine GTFigBindObject(fig, obj)
            use gtgraph_types, only: GT_OBJECT, GT_FIGURE
            type(GT_FIGURE), intent(inout):: fig
            type(GT_OBJECT), intent(in):: obj
        end subroutine

        subroutine GTFigBindAxis(fig, axis, vertical)
            use gtgraph_types, only: GT_FIGURE, GT_AXIS
            type(GT_FIGURE), intent(inout):: fig
            type(GT_AXIS), pointer:: axis
            logical, intent(in), optional:: vertical
        end subroutine

        subroutine GTFigBindCont(fig, cont)
            use gtgraph_types, only: GT_FIGURE, GT_CONTOURS
            type(GT_FIGURE), intent(inout):: fig
            type(GT_CONTOURS), intent(inout):: cont
        end subroutine

        subroutine GTFigBindVect(fig, vect)
            use gtgraph_types, only: GT_FIGURE, GT_VECTORS
            type(GT_FIGURE), intent(inout):: fig
            type(GT_VECTORS), intent(inout):: vect
        end subroutine

        subroutine GTFigBindLine(fig, line)
            use gtgraph_types, only: GT_FIGURE, GT_LINE
            type(GT_FIGURE), intent(inout):: fig
            type(GT_LINE), intent(in):: line
        end subroutine

        subroutine GTFrameBindFig(frame, fig)
            use gtgraph_types, only: GT_FRAME, GT_FIGURE
            type(GT_FRAME), intent(out):: frame
            type(GT_FIGURE), intent(in):: fig
        end subroutine

    end interface

    !
    ! 普通のユーザは Display() を呼び出す。ここから
    ! 内部的に Draw サブルーチン群を呼び出している。
    ! 
    interface Display
 
        subroutine GTFrameDisplay(dev, frame)
            use gtgraph_types, only: GT_DEVICE, GT_FRAME
            type(GT_DEVICE), intent(inout):: dev
            type(GT_FRAME), intent(inout):: frame
        end subroutine

        subroutine GTFigDisplay(dev, fig)
            use gtgraph_types, only: GT_DEVICE, GT_FIGURE
            type(GT_DEVICE), intent(inout):: dev
            type(GT_FIGURE), intent(inout):: fig
        end subroutine

    end interface

    !
    ! Draw(..., paent) は内部的に Display(dev, ...) が
    ! 用いるためにある。parent 引数は通常無用だがユーザが
    ! ミスタイプで呼び出さないために Put と逆位置に
    ! 付加している。
    !
    interface Draw

        subroutine GTAxesDraw(h_axis, v_axis, parent, set_space)
            use gtgraph_types, only: GT_AXIS, GT_FIGURE
            type(GT_AXIS), intent(inout):: h_axis, v_axis
            type(GT_FIGURE), intent(in):: parent
            logical, intent(in), optional:: set_space
        end subroutine

        subroutine GTContDraw(cont, parent)
            use gtgraph_types, only: GT_CONTOURS, GT_FIGURE
            type(GT_CONTOURS), intent(inout):: cont
            type(GT_FIGURE), intent(in):: parent
        end subroutine

        subroutine GTVectDraw(vect, parent)
            use gtgraph_types, only: GT_VECTORS, GT_FIGURE
            type(GT_VECTORS), intent(inout):: vect
            type(GT_FIGURE), intent(in):: parent
        end subroutine

        subroutine GTLineDraw(line, parent)
            use gtgraph_types, only: GT_LINE, GT_FIGURE
            type(GT_LINE), intent(inout):: line
            type(GT_FIGURE), intent(in):: parent
        end subroutine

        subroutine GTFigDraw(fig, parent)
            use gtgraph_types, only: GT_FRAME, GT_FIGURE
            type(GT_FIGURE), intent(inout):: fig
            type(GT_FRAME), intent(in):: parent
        end subroutine

    end interface

    !
    ! 入出力
    !

    interface Load

        recursive subroutine GTObjLoadC(obj, varname, slice)
            use gtgraph_types, only: GT_OBJECT
            type(GT_OBJECT), intent(out):: obj
            character(len = *), intent(in):: varname
            character(len = *), intent(in):: slice
        end subroutine

        recursive subroutine GTObjLoadC2(obj, vnam1, vnam2, slice)
            use gtgraph_types, only: GT_OBJECT
            type(GT_OBJECT), intent(out):: obj
            character(len = *), intent(in):: vnam1
            character(len = *), intent(in):: vnam2
            character(len = *), intent(in):: slice
        end subroutine

        recursive subroutine GTObjLoadVar2(obj, var1, var2)
            use gtgraph_types, only: GT_OBJECT
            use gtdata_types, only: GT_VARIABLE
            type(GT_OBJECT), intent(out):: obj
            type(GT_VARIABLE), intent(in):: var1
            type(GT_VARIABLE), intent(in):: var2
        end subroutine

        recursive subroutine GTObjLoadVar(obj, var)
            use gtgraph_types, only: GT_OBJECT
            use gtdata_types, only: GT_VARIABLE
            type(GT_OBJECT), intent(out):: obj
            type(GT_VARIABLE), intent(in):: var
        end subroutine

        subroutine GTFrameLoad(frame, var)
            use gtgraph_types, only: GT_FRAME
            use gtdata_types, only: GT_VARIABLE
            type(GT_FRAME), intent(out):: frame
            type(GT_VARIABLE), intent(in):: var
        end subroutine

        subroutine GTFigLoad(Fig, var)
            use gtgraph_types, only: GT_FIGURE
            use gtdata_types, only: GT_VARIABLE
            type(GT_FIGURE), intent(out):: Fig
            type(GT_VARIABLE), intent(in):: var
        end subroutine

        subroutine GTContLoad(Cont, var)
            use gtgraph_types, only: GT_CONTOURS
            use gtdata_types, only: GT_VARIABLE
            type(GT_CONTOURS), intent(out):: Cont
            type(GT_VARIABLE), intent(in):: var
        end subroutine

        subroutine GTVectLoad(Vect, var)
            use gtgraph_types, only: GT_VECTORS
            use gtdata_types, only: GT_VARIABLE
            type(GT_VECTORS), intent(out):: Vect
            type(GT_VARIABLE), intent(in):: var
        end subroutine

        subroutine GTLineLoad(Line, var)
            use gtgraph_types, only: GT_Line
            use gtdata_types, only: GT_VARIABLE
            type(GT_Line), intent(out):: Line
            type(GT_VARIABLE), intent(in):: var
        end subroutine

        subroutine GTAxisLoadByName(Axis, varname)
            use gtgraph_types, only: GT_AXIS
            type(GT_AXIS), intent(out):: axis
            character(*), intent(in):: varname
        end subroutine

        subroutine GTAxisLoad(Axis, var)
            use gtgraph_types, only: GT_Axis
            use gtdata_types, only: GT_VARIABLE
            type(GT_Axis), intent(out):: Axis
            type(GT_VARIABLE), intent(in):: var
        end subroutine

    end interface

    ! --- Save ---
    !
    ! Save は図形変数を格納する。varname を省略すれば
    ! 変数名は自動生成される。

    interface Save

        subroutine GTFrameSave(frame, varname, resultname)
            use gtgraph_types, only: GT_FRAME
            use dc_string, only: VSTRING
            type(GT_FRAME), intent(in):: frame
            type(VSTRING), intent(in), optional:: varname
            type(VSTRING), intent(out), optional:: resultname
        end subroutine

        subroutine GTFigSave(fig, varname, resultname)
            use gtgraph_types, only: GT_FIGURE
            use dc_string, only: VSTRING
            type(GT_FIGURE), intent(in):: fig
            type(VSTRING), intent(in), optional:: varname
            type(VSTRING), intent(out), optional:: resultname
        end subroutine

        subroutine GTLineSave(line, varname, resultname)
            use gtgraph_types, only: GT_LINE
            use dc_string, only: VSTRING
            type(GT_LINE), intent(in):: line
            type(VSTRING), intent(in), optional:: varname
            type(VSTRING), intent(out), optional:: resultname
        end subroutine

        subroutine GTContSave(cont, varname, resultname)
            use gtgraph_types, only: GT_CONTOURS
            use dc_string, only: VSTRING
            type(GT_CONTOURS), intent(in):: cont
            type(VSTRING), intent(in), optional:: varname
            type(VSTRING), intent(out), optional:: resultname
        end subroutine

        subroutine GTVectSave(Vect, varname, resultname)
            use gtgraph_types, only: GT_VECTORS
            use dc_string, only: VSTRING
            type(GT_VECTORS), intent(in):: Vect
            type(VSTRING), intent(in), optional:: varname
            type(VSTRING), intent(out), optional:: resultname
        end subroutine

        subroutine GTAxisSave(axis, varname, resultname)
            use gtgraph_types, only: GT_AXIS
            use dc_string, only: VSTRING
            type(GT_AXIS), intent(in):: axis
            type(VSTRING), intent(in), optional:: varname
            type(VSTRING), intent(out), optional:: resultname
        end subroutine

    end interface

    interface operator(.equivalent.)

        logical function GTAxisEquivalent(axis1, axis2)
            use gtgraph_types, only: gt_axis
            type(gt_axis), intent(in):: axis1
            type(gt_axis), intent(in):: axis2
        end function

    end interface

    ! Save が使う名前

    interface
        subroutine GTGraphSaveName(result)
            character(len = *), intent(out):: result
        end subroutine
    end interface

end module
