subroutine RTable_INPUTS
    
    use CDrillingConsoleVariables
    use SimulationVariables
    use SimulationVariables
    ! use CSimulationVariables
    use UnitySignalsModule
    ! use CTdsElevatorModesEnumVariables
    use CHoistingVariables
    use SimulationVariables
    use SimulationVariables !@
    use TD_DrillStemComponents
    use CUnityInputs
    use CWarnings
    use UnitySignalVariables
    use UnitySignalsModule
    
    IMPLICIT NONE
    integer :: i
    
    
    
    data%State%RTable%AssignmentSwitch  = data%EquipmentControl%DrillingConsole%AssignmentSwitch
    data%State%RTable%Switch            = data%EquipmentControl%DrillingConsole%RTSwitch
    !data%State%RTable%GearsAbuse        = RotaryGearsAbuse
    data%State%RTable%Throttle          = data%EquipmentControl%DrillingConsole%RTThrottle                         ![RPM]
    data%State%RTable%String_Torque     = data%State%TD_String%StringTorque*12.d0              ![lb.ft]*12 ---> [lb.in]  ?????????
    !data%State%RTable%RpmGaugeMalf      !:dar module haye C meghdardehi mishe
    

    
    
    data%State%RTable%N_new = data%State%RTable%Throttle
    if ( data%State%RTable%MotorFaileMalf==1 ) then
        data%State%RTable%N_new = 0.d0
    end if
    data%State%RTable%String_Torque = 0.112984d0*data%State%RTable%String_Torque       ![N.m]
    
  
    
    !===> String_JCoef Calculation
    if ( data%Configuration%Hoisting%DriveType==0 ) then
        if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then
            data%State%RTable%RotaryMode   = 1
            data%State%RTable%String_JCoef = 0.d0
            Do i = 1,data%State%TD_String%StringConfigurationCount
                data%State%RTable%String_JCoef = data%State%RTable%String_JCoef+( (data%State%TD_DrillStem(i)%TotalWeight*((data%State%TD_DrillStem(i)%Id**2.d0)+(data%State%TD_DrillStem(i)%Od**2.d0)))/8.d0 )   ![lb.ft^2] , Jz=(1/2)*m*(r1^2+r2^2)
            End Do
            data%State%RTable%String_JCoef = data%State%RTable%String_JCoef*0.0421401d0   ![kg.m^2]
        else if ( Get_Slips() /= SLIPS_SET_END ) then
            data%State%RTable%RotaryMode    = 2
            data%State%RTable%String_JCoef  = 0.d0
            data%State%RTable%String_Torque = 0.d0
        else
            data%State%RTable%RotaryMode    = 3
            data%State%RTable%String_JCoef  = 0.d0
            data%State%RTable%String_Torque = 0.d0
        end if
    else if ( data%Configuration%Hoisting%DriveType==1 ) then
        if ( Get_IsKellyBushingSetInTable() .or. Get_Slips() == SLIPS_SET_END ) then        !if rotary connected to string
            data%State%RTable%RotaryMode   = 4
            data%State%RTable%String_JCoef = 0.d0
            Do i = 1,data%State%TD_String%StringConfigurationCount
                data%State%RTable%String_JCoef = data%State%RTable%String_JCoef+( (data%State%TD_DrillStem(i)%TotalWeight*((data%State%TD_DrillStem(i)%Id**2.d0)+(data%State%TD_DrillStem(i)%Od**2.d0)))/8.d0 )   ![lb.ft^2] , Jz=(1/2)*m*(r1^2+r2^2)
            End Do
            data%State%RTable%String_JCoef = data%State%RTable%String_JCoef*0.0421401e0   ![kg.m^2]
        else
            data%State%RTable%RotaryMode    = 5
            data%State%RTable%String_JCoef  = 0.d0
            data%State%RTable%String_Torque = 0.d0  
        end if
    end if
    
    
    !===> Transmission Mode
    data%State%RTable%Conv_Ratio = data%State%RTable%High_Conv_Ratio
    
    
    
end subroutine RTable_INPUTS