subroutine RTable_MainSolver
    
    
    use SimulationVariables !@
    
	IMPLICIT NONE
    
    
    Call RTable_Inputs
    
    if (data%State%RTable%Throttle<=0.d0) then
        data%State%RTable%K_throttle = 1
    end if
    
    
    if ( (any(data%State%RTable%AssignmentSwitch==(/1,2,3,4,5,8,9,10,11/))) .and. (data%State%RTable%Switch==-1) ) then 
        
        data%State%RTable%SoundBlower = .true.
        data%State%RTable%BLWR        = 1
        !======================= Rotary Table Rate_limit =======================
        if (((data%State%RTable%N_new-data%State%RTable%N_old)/data%State%RTable%time_step)>data%State%RTable%RateChange) then
            data%State%RTable%N_ref = (data%State%RTable%RateChange*data%State%RTable%time_step)+data%State%RTable%N_old
        else if (((data%State%RTable%N_old-data%State%RTable%N_new)/data%State%RTable%time_step)>data%State%RTable%RateChange) then
            data%State%RTable%N_ref = (-data%State%RTable%RateChange*data%State%RTable%time_step)+data%State%RTable%N_old
        else
            data%State%RTable%N_ref = data%State%RTable%N_new
        end if
        !=======================================================================
        CALL RTable_OnModeSolver
        
    else if ( (any(data%State%RTable%AssignmentSwitch==(/1,2,3,4,5,8,9,10,11/))) .and. (data%State%RTable%Switch==1) .and. (data%State%RTable%K_throttle==1) ) then
        
        data%State%RTable%SoundBlower = .true.
        data%State%RTable%BLWR        = 1
        !======================= Rotary Table Rate_limit =======================
        if (((data%State%RTable%N_new-data%State%RTable%N_old)/data%State%RTable%time_step)>data%State%RTable%RateChange) then
            data%State%RTable%N_ref = (data%State%RTable%RateChange*data%State%RTable%time_step)+data%State%RTable%N_old
        else if (((data%State%RTable%N_old-data%State%RTable%N_new)/data%State%RTable%time_step)>data%State%RTable%RateChange) then
            data%State%RTable%N_ref = (-data%State%RTable%RateChange*data%State%RTable%time_step)+data%State%RTable%N_old
        else
            data%State%RTable%N_ref = data%State%RTable%N_new
        end if
        !=======================================================================
        CALL RTable_OnModeSolver
        
    else
        
        if((any(data%State%RTable%AssignmentSwitch==(/1,2,3,4,5,8,9,10,11/))) .and. (data%State%RTable%Switch/=0)) then
            data%State%RTable%SoundBlower = .true.
            data%State%RTable%BLWR        = 1
        else
            data%State%RTable%SoundBlower = .false.
            data%State%RTable%BLWR        = 0
        end if            
        Call RTable_OffMode
        data%State%RTable%K_throttle = 0
        
    end if

    
    Call RTable_Outputs
    
    data%State%RTable%N_old = data%State%RTable%N_ref

    
    
end subroutine RTable_MainSolver