subroutine TD_TorqueCalculation(i)
    
   use CHoistingVariables
    use SimulationVariables
!    Use TD_DrillStemComponents
!    use ConfigurationVariables !@
!    use ConfigurationVariables !@
!    use ConfigurationVariables !@
!    use ConfigurationVariables !@, only: RTable
!    use ConfigurationVariables, only: TDS
   

   implicit none
   
   Integer :: i
    
   
   
   
   if ( data%Configuration%Hoisting%DriveType==1 .and. data%State%RTable%Speed==0.d0 ) then
       data%State%TD_DrillStems(i)%Torque = 0.d0
   else if ( data%Configuration%Hoisting%DriveType==0 .and. data%State%TDS%Speed==0.d0 .and. data%State%RTable%Speed==0.d0 ) then
       data%State%TD_DrillStems(i)%Torque = 0.d0
   end if
   
   
   
   
    if ( i==1 ) then
        data%State%TD_String%TotalTorque = data%State%TD_DrillStems(i)%Torque
    else
        data%State%TD_String%TotalTorque = data%State%TD_String%TotalTorque + data%State%TD_DrillStems(i)%Torque
    end if
    
     !if (data%State%TD_DrillStems(i)%Torque>500.) then
     !    print* , 'data%State%TD_String%TotalTorque=' , i , data%State%TD_String%TotalTorque , data%State%TD_DrillStems(i)%Torque
     !    !print* , 'properties=' , data%State%TD_DrillStems(i)%Force1 , data%State%TD_DrillStems(i)%MudViscosity , data%State%TD_DrillStems(i)%EndAngle , data%State%TD_DrillStems(i)%StartAngle , data%State%TD_DrillStems(i)%WeightperLength , data%State%TD_DrillStems(i)%MudVisCorrectCoef
     !end if
     
    
    
    
end subroutine