subroutine TD_HookLoadCalculation
    
   Use TD_DrillStemComponents
   use SimulationVariables !@
   use SimulationVariables !@
   use SimulationVariables !@
   Use TD_StringConnectionData
   use SimulationVariables !@, only: Drawworks
   use CDataDisplayConsole
    use SimulationVariables
   use CHoistingVariables
    use SimulationVariables
!    Use CSlipsEnumVariables
   use UnitySignalVariables
    use UnitySignalsModule
   Use CBopStackVariables
   use SimulationVariables
   Use CUnityInputs
   
   
   implicit none
   
   Integer :: i , kk
   Real(8) :: TD_eConst=0.98d0 , TD_SumWeight
   
   
   
   
!====================================================
!             Torque & Hook Load Calculation
!====================================================

!=========> HookLoad
  data%State%TD_String%HookLoad = data%State%TD_DrillStems(data%State%TD_String%DrillStemComponentsNumbs)%Force2     ! [lb]
  !print* , 'data%State%TD_String%HookLoad1=' , data%State%TD_String%HookLoad
  
  if ( data%State%Drawworks%motion==1 ) then
      if ( data%State%PipeRam1%Situation_forTD==1 ) then  !Upper Ram
          data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+data%Configuration%BopStack%RamStringDrag
      end if
      if ( data%State%PipeRam2%Situation_forTD==1 ) then  !Lower Ram
          data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+data%Configuration%BopStack%RamStringDrag
      end if
      if ( data%State%RamLine%ShearBop_Situation_forTD==1 ) then  !Blind Ram
          data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+data%Configuration%BopStack%RamStringDrag   !????????????????????
      end if
      if ( data%State%Annular%Annular_Situation_forTD==1 ) then   !Annular Preventer
          data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+(data%State%AnnularComputational%p_annular*data%Configuration%BopStack%AnnularStringDrag)
      end if
  else if ( data%State%Drawworks%motion==-1 ) then
      if ( data%State%PipeRam1%Situation_forTD==1 ) then  !Upper Ram
          data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-data%Configuration%BopStack%RamStringDrag
      end if
      if ( data%State%PipeRam2%Situation_forTD==1 ) then  !Lower Ram
          data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-data%Configuration%BopStack%RamStringDrag
      end if
      if ( data%State%RamLine%ShearBop_Situation_forTD==1 ) then  !Blind Ram
          data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-data%Configuration%BopStack%RamStringDrag    !????????????????????
      end if
      if ( data%State%Annular%Annular_Situation_forTD==1 ) then   !Annular Preventer
          data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-(data%State%AnnularComputational%p_annular*data%Configuration%BopStack%AnnularStringDrag)
      end if
  end if
  
  !print* , 'data%State%TD_String%HookLoad2=' , data%State%TD_String%HookLoad
  
  
  
  
  
  !if ( UpperRamClose_withPossibility==1 ) then
  !    if ( data%State%Drawworks%motion==1 ) then
  !        data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+RamStringDrag
  !    else if ( data%State%Drawworks%motion==-1 ) then
  !        data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-RamStringDrag
  !    end if
  !end if
  !if ( LowerRamClose_withPossibility==1 ) then
  !    if ( data%State%Drawworks%motion==1 ) then
  !        data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+RamStringDrag
  !    else if ( data%State%Drawworks%motion==-1 ) then
  !        data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-RamStringDrag
  !    end if
  !end if
  !if ( BlindRamClose_withPossibility==1 ) then
  !    if ( data%State%Drawworks%motion==1 ) then
  !        data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+RamStringDrag
  !    else if ( data%State%Drawworks%motion==-1 ) then
  !        data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-RamStringDrag
  !    end if
  !end if
  !if ( AnnularPreventerClose_withPossibility==1 ) then
  !    if ( data%State%Drawworks%motion==1 ) then
  !        data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+AnnularStringDrag
  !    else if ( data%State%Drawworks%motion==-1 ) then
  !        data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-AnnularStringDrag
  !    end if
  !end if
  
  
  
  
  
  
  
  
!=========> Torque
  data%State%TD_String%StringTorque = data%State%TD_String%TotalTorque             ![lb.ft]     ??????????
  !print* , 'data%State%TD_String%StringTorque=' , data%State%TD_String%StringTorque
  
  
  
  
  
!====================================================
!             Weight Indicator Calculation
!====================================================
   
   kk = 0
   Do i = data%State%TD_String%DrillStemComponentsNumbs , 1 , -1
           if (data%State%TD_DrillStems(i)%ComponentType==3) then
               kk = i
               exit
           end if
   End Do
  
   
   
   
   
   if ( data%State%TD_StConn%KellyDriveTypeMode==0 ) then
       
       if ( data%State%TD_StConn%StringConnectionMode  == 1 ) then
           if ( Get_Slips() == SLIPS_SET_END ) then
               TD_SumWeight = data%State%TD_Load%WeightTB+data%State%TD_Load%KellyWeight
           else
               TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTB+data%State%TD_Load%KellyWeight    ! data%State%TD_String%HookLoad = String Weight
           end if
       
       else if ( data%State%TD_StConn%StringConnectionMode  == 2 ) then
           if ( Get_JointConnectionPossible() ) then
               TD_SumWeight = data%State%TD_Load%WeightTB
           else
               TD_SumWeight = data%State%TD_Load%WeightTB+data%State%TD_Load%KellyWeight
           end if
       
       else if ( data%State%TD_StConn%StringConnectionMode  == 3 ) then
           if ( Get_JointConnectionPossible() ) then
               TD_SumWeight = data%State%TD_Load%WeightTB
           else
               TD_SumWeight = data%State%TD_Load%WeightTB+data%State%TD_Load%KellyWeight+data%State%TD_DrillStems(kk)%Weight
           end if
           
       end if
       
   else if ( data%State%TD_StConn%KellyDriveTypeMode==1 ) then
       
        if ( data%State%TD_StConn%StringConnectionMode  == 4 ) then
           if ( Get_Slips() == SLIPS_SET_END ) then
               TD_SumWeight = data%State%TD_Load%WeightTB
           else
               TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTB
           end if
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 5 ) then
           TD_SumWeight = data%State%TD_Load%WeightTB
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 6 ) then
           if ( Get_JointConnectionPossible() ) then
               TD_SumWeight = data%State%TD_Load%WeightTB
           else
               TD_SumWeight = data%State%TD_Load%WeightTB+(3.d0*data%State%TD_DrillStems(kk)%Weight)
           end if
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 7 ) then
           if ( Get_JointConnectionPossible() ) then
               TD_SumWeight = data%State%TD_Load%WeightTB
           else
               TD_SumWeight = data%State%TD_Load%WeightTB+data%State%TD_DrillStems(kk)%Weight
           end if
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 8 ) then
           TD_SumWeight = data%State%TD_Load%WeightTB
           
        else if ( data%State%TD_StConn%StringConnectionMode  == 18 ) then
           TD_SumWeight = data%State%TD_Load%WeightTB
           
        else if ( data%State%TD_StConn%StringConnectionMode  == 19 ) then
           TD_SumWeight = data%State%TD_Load%WeightTB
           
        end if
        
   else if ( data%State%TD_StConn%KellyDriveTypeMode==2 ) then
       
        if ( data%State%TD_StConn%StringConnectionMode  == 9 ) then
           if ( Get_Slips() == SLIPS_SET_END ) then
               TD_SumWeight = data%State%TD_Load%WeightTD
           else
               TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTD
           end if
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 10 ) then
           if ( Get_Slips() == SLIPS_SET_END ) then
               TD_SumWeight = data%State%TD_Load%WeightTD
           else
               TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTD
           end if
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 11 ) then
           TD_SumWeight = data%State%TD_Load%WeightTD
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 12 ) then
           if ( Get_Slips() == SLIPS_SET_END ) then
               TD_SumWeight = data%State%TD_Load%WeightTD
           else
               TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTD
           end if
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 13 ) then
           TD_SumWeight = data%State%TD_Load%WeightTD
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 14 ) then
           TD_SumWeight = data%State%TD_Load%WeightTD+(3.d0*data%State%TD_DrillStems(kk)%Weight)
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 15 ) then
           TD_SumWeight = data%State%TD_Load%WeightTD+(data%State%TD_DrillStems(kk)%Weight)
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 16 ) then
           TD_SumWeight = data%State%TD_Load%WeightTD
       
        else if ( data%State%TD_StConn%StringConnectionMode  == 17 ) then
           TD_SumWeight = data%State%TD_Load%WeightTD
           
        end if
    
    end if
    
    
    
    !print* , 'data%State%TD_String%HookLoad3=' , data%State%TD_String%HookLoad
    
    
    
    
  !if ( data%Configuration%Hoisting%DriveType==1 ) then          !==> Kelly_DriveType
  !    
  !    if ( data%State%TD_String%DrillStemForceType==1 .or. data%State%TD_String%DrillStemForceType==2 ) then
  !        data%State%TD_Load%WeightIndicator = ( sngl(data%State%TD_Load%NumOfCables)*(TD_eConst-1.d0)*(TD_SumWeight) )&
  !                              /( TD_eConst*(1.d0-(1.d0/(TD_eConst**data%State%TD_Load%NumOfCables))) )
  !    else if ( data%State%TD_String%DrillStemForceType==3 .or. data%State%TD_String%DrillStemForceType==4 ) then
  !        data%State%TD_Load%WeightIndicator = ( sngl(data%State%TD_Load%NumOfCables)*(1.d0-TD_eConst)*(TD_SumWeight) )&
  !                              /( 1.d0-(TD_eConst**data%State%TD_Load%NumOfCables) )
  !    else if ( data%State%TD_String%DrillStemForceType==5 ) then
          data%State%TD_Load%WeightIndicator = TD_SumWeight
  !    end if
  !    
  !    
  !else if ( data%Configuration%Hoisting%DriveType==0 ) then     !==> TopDrive_DriveType   ??????????????
  !    
  !    if ( data%State%TD_String%DrillStemForceType==1 .or. data%State%TD_String%DrillStemForceType==2 ) then
  !        data%State%TD_Load%WeightIndicator = ( sngl(data%State%TD_Load%NumOfCables)*(TD_eConst-1.d0)*(TD_SumWeight) )&
  !                              /( TD_eConst*(1.d0-(1.d0/(TD_eConst**data%State%TD_Load%NumOfCables))) )
  !    else if ( data%State%TD_String%DrillStemForceType==3 .or. data%State%TD_String%DrillStemForceType==4 ) then
  !        data%State%TD_Load%WeightIndicator = ( sngl(data%State%TD_Load%NumOfCables)*(1.d0-TD_eConst)*(TD_SumWeight) )&
  !                              /( 1.d0-(TD_eConst**data%State%TD_Load%NumOfCables) )
  !    else if ( data%State%TD_String%DrillStemForceType==5 ) then
  !        data%State%TD_Load%WeightIndicator = TD_SumWeight
  !    end if
  !    
  !!else
  !!data%State%TD_Load%WeightIndicator = 0.  !?????????????????
  !
  !end if
  

  
  
  
 data%State%TD_Load%DrawworksLoadInput = data%State%TD_Load%WeightIndicator/(sngl(data%State%TD_Load%NumOfCables))                 ! [lb]
  !print* , 'data%State%TD_String%HookLoad4=' , data%State%TD_String%HookLoad
 !HookLoadPointer = data%State%TD_Load%WeightIndicator/1.0d3                                       ! [klb]
 call Set_HookLoad ((1-data%State%TD_General%WeightIndicatorMalf)*AINT(data%State%TD_Load%WeightIndicator/1.0d3))     ! [klb]
  
  
 
 
 
  
end subroutine