module CHoistingProblemsVariables
    use CProblemDifinition
	implicit none    
	public 
    
    ! Input vars
    type :: HoistingProblemsType
        type(CProblem) :: MotorFail
        type(CProblem) :: ClutchEngage
        type(CProblem) :: ClutchDisengage
    end type HoistingProblemsType
    type(HoistingProblemsType):: HoistingProblems
    ! procedure (ActionInteger), pointer :: MotorFailPtr
    ! procedure (ActionInteger), pointer :: ClutchEngagePtr
    ! procedure (ActionInteger), pointer :: ClutchDisengagePtr

    
    contains   
    
    subroutine ProcessHoistingProblemsDueTime(time)
        implicit none
        integer :: time
        if(HoistingProblems%MotorFail%ProblemType == Time_ProblemType) call ProcessDueTime(HoistingProblems%MotorFail, ChangeMotorFail, time)
        if(HoistingProblems%ClutchEngage%ProblemType == Time_ProblemType) call ProcessDueTime(HoistingProblems%ClutchEngage, ChangeClutchEngage, time)
        if(HoistingProblems%ClutchDisengage%ProblemType == Time_ProblemType) call ProcessDueTime(HoistingProblems%ClutchDisengage, ChangeClutchDisengage, time)
    end subroutine
	
	subroutine ProcessHoistingProblemsDuePumpStrokes(strokes)
        implicit none
        integer :: strokes
        if(HoistingProblems%MotorFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(HoistingProblems%MotorFail, ChangeMotorFail, strokes)
        if(HoistingProblems%ClutchEngage%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(HoistingProblems%ClutchEngage, ChangeClutchEngage, strokes)
        if(HoistingProblems%ClutchDisengage%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(HoistingProblems%ClutchDisengage, ChangeClutchDisengage, strokes)
    end subroutine
	
	subroutine ProcessHoistingProblemsDueVolumePumped(volume)
        implicit none
        real(8) :: volume
        if(HoistingProblems%MotorFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(HoistingProblems%MotorFail, ChangeMotorFail, volume)
        if(HoistingProblems%ClutchEngage%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(HoistingProblems%ClutchEngage, ChangeClutchEngage, volume)
        if(HoistingProblems%ClutchDisengage%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(HoistingProblems%ClutchDisengage, ChangeClutchDisengage, volume)
    end subroutine
	
	subroutine ProcessHoistingProblemsDueDistanceDrilled(distance)
        implicit none
        real(8) :: distance
        if(HoistingProblems%MotorFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(HoistingProblems%MotorFail, ChangeMotorFail, distance)
        if(HoistingProblems%ClutchEngage%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(HoistingProblems%ClutchEngage, ChangeClutchEngage, distance)
        if(HoistingProblems%ClutchDisengage%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(HoistingProblems%ClutchDisengage, ChangeClutchDisengage, distance)
    end subroutine
	
	
	
	
	
    
    subroutine ChangeMotorFail(status)
        use Drawworks_VARIABLES
        implicit none
        integer, intent (in) :: status
        ! if(associated(MotorFailPtr)) call MotorFailPtr(status)
        if(status == Clear_StatusType)     Drawworks%MotorFaileMalf=0
        if(status == Executed_StatusType)  Drawworks%MotorFaileMalf=1
    endsubroutine
    
    subroutine ChangeClutchEngage(status)
        use Drawworks_VARIABLES
        implicit none
        integer, intent (in) :: status
        ! if(associated(ClutchEngagePtr)) call ClutchEngagePtr(status)
        if(status == Clear_StatusType)     Drawworks%ClutchEngageMalf=0
        if(status == Executed_StatusType)  Drawworks%ClutchEngageMalf=1
    endsubroutine
    
    subroutine ChangeClutchDisengage(status)
        use Drawworks_VARIABLES
        implicit none
        integer, intent (in) :: status
        ! if(associated(ClutchDisengagePtr)) call ClutchDisengagePtr(status)
        if(status == Clear_StatusType)     Drawworks%ClutchDisengageMalf=0
        if(status == Executed_StatusType)  Drawworks%ClutchDisengageMalf=1
    endsubroutine
    
    
    
    
    
    
    
    
    
    
    ! subroutine SubscribeMotorFail(v)
    ! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeMotorFail
    ! !DEC$ ATTRIBUTES ALIAS: 'SubscribeMotorFail' :: SubscribeMotorFail
	!     implicit none
	!     procedure (ActionInteger) :: v
	!     MotorFailPtr => v
    ! end subroutine

    ! subroutine SubscribeClutchEngage(v)
    ! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeClutchEngage
    ! !DEC$ ATTRIBUTES ALIAS: 'SubscribeClutchEngage' :: SubscribeClutchEngage
	!     implicit none
	!     procedure (ActionInteger) :: v
	!     ClutchEngagePtr => v
    ! end subroutine

    ! subroutine SubscribeClutchDisengage(v)
    ! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeClutchDisengage
    ! !DEC$ ATTRIBUTES ALIAS: 'SubscribeClutchDisengage' :: SubscribeClutchDisengage
	!     implicit none
	!     procedure (ActionInteger) :: v
	!     ClutchDisengagePtr => v
    ! end subroutine
    
    
end module CHoistingProblemsVariables