module CInstallFillupHeadPermission
    use OperationScenariosModule
    implicit none
    
    contains
    
    subroutine Evaluate_InstallFillupHeadPermission()
        use TD_DrillStemComponents
        implicit none
        
        
        
        if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then
#ifdef OST
            print*, 'Evaluate_InstallFillupHeadPermission=TopDrive'
#endif
        endif
        
        
        
        
        
        
        
        
        
        if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then
#ifdef OST
            print*, 'Evaluate_InstallFillupHeadPermission=Kelly'
#endif


            !!OPERATION-CODE=69
            !if (Get_OperationCondition() == OPERATION_DRILL .and.&
            !    Get_NearFloorConnection() >= 3.0 .and. Get_NearFloorConnection() <= 6.0 .and.&
            !    Get_JointConnectionPossible() == .false. .and.&
            !    Get_KellyConnection() /= KELLY_CONNECTION_STRING .and.&
            !    Get_Slips() == SLIPS_SET_END) then
            !    
            !    call Set_InstallFillupHeadPermission(.true.)
            !    return
            !end if
            
            
            
            !OPERATION-CODE=70
            if (Get_OperationCondition() == OPERATION_TRIP .and.&
                data%State%TD_String%TopJointHeight >= 3.0 .and. data%State%TD_String%TopJointHeight <= 9.0 .and.&
                Get_JointConnectionPossible() == .false. .and.&
                !Get_ElevatorConnectionPossible() == .false. .and.&
                !Get_ElevatorConnection() /= ELEVATOR_CONNECTION_STRING .and.&
                Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING) then
            
                call Set_InstallFillupHeadPermission(.true.)
                return
            end if
            
            
            
        
            call Set_InstallFillupHeadPermission(.false.)

        endif
        
        
        
        
        
    end subroutine
    
    subroutine Subscribe_InstallFillupHeadPermission()
        implicit none
        ! imp me...
    end subroutine
    
end module CInstallFillupHeadPermission