! Copyright (C) GFD Dennou Club, 2000.  All rights reserved.

subroutine GtFigBindObject(fig, obj)
    use gtgraph_types, only: GT_FIGURE, GT_OBJECT
    use gtgraph_generic, only: Bind
    use dc_error, only: StoreError, GT_EFAKE
    use dc_trace, only: beginsub, endsub, debug
    implicit none
    type(GT_FIGURE), intent(inout):: fig
    type(GT_OBJECT), intent(inout):: obj
    call beginsub('gtfigbindobject')

    if (associated(obj%line)) then
        call Bind(fig, obj%line)
    else if (associated(obj%vect)) then
        call Bind(fig, obj%vect)
    else if (associated(obj%cont)) then
        call Bind(fig, obj%cont)
    else if (associated(obj%fig)) then
        ! なんだか変だが...
        if (.not.(associated(obj%fig%contours) &
            & .or. associated(obj%fig%line))) then
            goto 999
        else if (.not.(associated(fig%contours) &
            & .or. associated(fig%line))) then
            fig = obj%fig
        else
            call StoreError(GT_EFAKE, "GTFigBindObject(FIG)")
        endif
    else if (associated(obj%axis)) then
        continue
    else
        call StoreError(GT_EFAKE, "GTFigBindObject(UNKNOWN)")
    endif
999 continue
    call endsub('gtfigbindobject')
end subroutine