subroutine TD_MainCalculations
    
    Use CCasingLinerChokeVariables
    Use CStringConfigurationVariables
    ! Use CSimulationVariables
    Use TD_DrillStemComponents
    use SimulationVariables !@
    use SimulationVariables !@
    use SimulationVariables !@
    Use TD_StringConnectionData
    USE FricPressDropVarsModule
    USE MudSystemVARIABLES
use SimulationVariables !@@@
    
    
    implicit none
    
    Integer              :: i
    !Integer              :: TD_SolDuration
    !integer,dimension(8) :: TD_StartTime , TD_EndTime
    
    
    
    data%State%TD_General%TimeStep = 0.1d0     ! Unit: [s]
    !Call TD_StartUp
    !Call TD_WellReadData
    !Call TD_WellElementsReadData
    !Call TD_DrillStemReadData
    !Call TD_PipePropertiesReadData
    !!Call TD_WellGeoConfiguration
    !!Call TD_WellElementsConfiguration
    !!Call TD_StringConnectionModes
    !!Call TD_DrillStemConfiguration
    
    
    
    
    !loop1: do
    
        
    
        Call TD_WellGeoConfiguration
        Call TD_WellElementsConfiguration
        Call TD_StringConnectionModes
        Call TD_DrillStemConfiguration
        Call TD_ForceReadData
        
        
!===> Mud properties Read_Data from Fluid Module
        !!TD_StringNoHorizontalMudElements = TDNoHorizontalMudElements
        !!data%State%TD_String%NoStringMudElements     = TDNoStringMudElements
        !!data%State%TD_String%NoCasingMudElements     = TDNoCasingMudElements
        !!
        !!if (allocated(TDDensity_MudElementArray) .and. (TD_StringNoHorizontalMudElements+data%State%TD_String%NoStringMudElements+data%State%TD_String%NoCasingMudElements)/=0) then
        !!    if (Allocated(data%State%TD_String%FluidMudDensity))  Deallocate(data%State%TD_String%FluidMudDensity)
        !!    Allocate(data%State%TD_String%FluidMudDensity(TD_StringNoHorizontalMudElements+data%State%TD_String%NoStringMudElements+data%State%TD_String%NoCasingMudElements))
        !!    data%State%TD_String%FluidMudDensity(:) = TDDensity_MudElementArray(:)
        !!end if
        !!
        !!if (allocated(TDXend_MudElementArray)) then
        !!    if (Allocated(data%State%TD_String%FluidMudEndX))  Deallocate(data%State%TD_String%FluidMudEndX)
        !!    Allocate(data%State%TD_String%FluidMudEndX(TD_StringNoHorizontalMudElements+data%State%TD_String%NoStringMudElements+data%State%TD_String%NoCasingMudElements))
        !!    data%State%TD_String%FluidMudEndX(:) = TDXend_MudElementArray(:)
        !!end if
        !!
        !!if (allocated(TDXstart_MudElementArray)) then
        !!    if (Allocated(data%State%TD_String%FluidMudStartX))  Deallocate(data%State%TD_String%FluidMudStartX)
        !!    Allocate(data%State%TD_String%FluidMudStartX(TD_StringNoHorizontalMudElements+data%State%TD_String%NoStringMudElements+data%State%TD_String%NoCasingMudElements))
        !!    data%State%TD_String%FluidMudStartX(:) = TDXstart_MudElementArray(:)
        !!end if
        
        if (data%State%TD_DrillStem(1)%ComponentType==0) then
            Do i = 2 , data%State%TD_String%DrillStemComponentsNumbs
                Call TD_MudPropertiesReadData(i)
                Call TD_BouyancyFactor(i)
                Call TD_CombinedMotionData(i)
            End Do
            data%State%TD_DrillStems(1)%MudDensityIn  = data%State%TD_DrillStems(2)%MudDensityIn  !(1): bit mud properties
            data%State%TD_DrillStems(1)%MudDensityOut = data%State%TD_DrillStems(2)%MudDensityOut
            data%State%TD_DrillStems(1)%MudWeight     = data%State%TD_DrillStems(2)%MudWeight
            data%State%TD_DrillStems(1)%MudPlasticVis = 5.d0+(5.d0*(data%State%TD_DrillStems(1)%MudWeight-8.3d0))
            data%State%TD_DrillStems(1)%MudViscosity  = 0.2d0                          !data%State%TD_DrillStems(i)%MudPlasticVis
            data%State%TD_DrillStems(1)%MudYieldPoint = 10.d0+(data%State%TD_DrillStems(1)%MudWeight-8.3d0)
            Call TD_BouyancyFactor(1)
            Call TD_CombinedMotionData(1)
        else
            Do i = 1 , data%State%TD_String%DrillStemComponentsNumbs
                Call TD_MudPropertiesReadData(i)
                Call TD_BouyancyFactor(i)
                Call TD_CombinedMotionData(i)
            End Do
        end if
!================================================
      
        
        
        Call TD_BOPDiamCalculation
    
    
        Call TD_StaticHookLoadCalculation
        Call TD_WeightOnBitCalculation
        if (abs(data%State%TD_String%DrillStemAxialVelocity)>3.2808d0) then   !1[m/s]=3.2808[ft/s]
            Call TD_ViscousDragForce
        else
            data%State%TD_DrillStems%Drag    = 0.d0
            data%State%TD_String%DrillStemForceType = 5
        end if
        Call TD_ForceCalculation
        Call TD_HookLoadCalculation
    
    
    
          
        
        data%State%TD_StConn%HookHeightOld = data%State%TD_StConn%HookHeight
    
    
    
    
    
end subroutine TD_MainCalculations