subroutine TD_DrillStemReadData
    use SimulationVariables
    Use CStringConfigurationVariables
    Use TD_DrillStemComponents
    use SimulationVariables !@
    use SimulationVariables !@
    Use TD_StringConnectionData
    ! use ConfigurationVariables !@, only: Drawworks
   

   implicit none 

   
   
   
   Integer :: i
   Integer :: TD_FirstIndex , TD_LastIndex
  
   
   
   
!====================================================
!         Set Drill Stem Components Data
!====================================================
   data%State%TD_String%StringConfigurationCount = data%Configuration%StringConfiguration%StringConfigurationCount
   data%State%TD_String%DrillStemComponentsNumbs = 0
   
   
   !########## data%State%TD_DrillStem%ComponentType  ::
   !#Bit_ComponentType                     = 0
   !#Stabilizer_ComponentType              = 1
   !#Collar_ComponentType                  = 2
   !#DrillPipe_ComponentType               = 3
   !#Heavyweight_ComponentType             = 4
   !#IBOP                                  = 5
   !#Kelly & SafetyValve (DrillMode)       = 6
   !#SafetyValve (TripMode)                = 7
   
   
   if (Allocated(data%State%TD_DrillStem)) deAllocate (data%State%TD_DrillStem)
   Allocate (data%State%TD_DrillStem(data%State%TD_String%StringConfigurationCount+100))
   
   
   Do i=1, data%State%TD_String%StringConfigurationCount
     data%State%TD_DrillStem(i)%ComponentType   = data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType        
     data%State%TD_DrillStem(i)%Numbs           = data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint
     data%State%TD_DrillStem(i)%Id              = data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId/12.d0   ![ft]
     data%State%TD_DrillStem(i)%Od              = data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd/12.d0   ![ft]
     data%State%TD_DrillStem(i)%Length          = data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint    ![ft]
     data%State%TD_DrillStem(i)%WeightperLength = data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength   ![lb/ft]
     data%State%TD_DrillStem(i)%TotalLength     = data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength
     data%State%TD_DrillStem(i)%TotalWeight     = data%State%TD_DrillStem(i)%TotalLength*data%State%TD_DrillStem(i)%WeightperLength
     
     data%State%TD_String%DrillStemComponentsNumbs     = data%State%TD_String%DrillStemComponentsNumbs+data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint
     
    !!=========> Set Separated Drill Stem Components Data
    !     TD_LastIndex = TD_LastIndex+StringConfigurations(i)%NumberOfJoint
    !     
    !     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%ComponentType  = data%State%TD_DrillStem(i)%ComponentType        
    !     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Id             = data%State%TD_DrillStem(i)%Id
    !     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Od             = data%State%TD_DrillStem(i)%Od      
    !     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Length         = data%State%TD_DrillStem(i)%Length
    !     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Weight         = data%State%TD_DrillStem(i)%Weight
    !    
    !     TD_FirstIndex = TD_LastIndex+1
   End Do
   
   
   
   
   
   
!===> Initial Values of Removed-Volume Variables 
   if (data%State%TD_DrillStem(1)%ComponentType==0) then
       data%State%TD_Vol%PreCount = data%State%TD_String%StringConfigurationCount-1
   else
       data%State%TD_Vol%PreCount = data%State%TD_String%StringConfigurationCount
   end if
   data%State%TD_Vol%PreElementVolume = data%State%TD_DrillStem(data%State%TD_String%StringConfigurationCount)%TotalLength*(((pi*((data%State%TD_DrillStem(data%State%TD_String%StringConfigurationCount)%Id)**2))/4.d0))   ![ft^3]
   data%State%TD_Vol%PreElementLength = data%State%TD_DrillStem(data%State%TD_String%StringConfigurationCount)%TotalLength
   

   
   
   
   
   
!====================================================
!        Set Separated Drill Stem Components Data
!====================================================
   
   TD_FirstIndex = 1
   TD_LastIndex  = 0
   if (Allocated(data%State%TD_DrillStems)) deAllocate (data%State%TD_DrillStems)
   Allocate   (data%State%TD_DrillStems(data%State%TD_String%DrillStemComponentsNumbs+300))   ! +300: because of: Add or Remove DrillStem Components
   Call TD_DrillStemStartUp
   
   
   Do i=1, data%State%TD_String%StringConfigurationCount
     
     TD_LastIndex = TD_LastIndex+data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint
     
     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%ComponentType  = data%State%TD_DrillStem(i)%ComponentType        
     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Id             = data%State%TD_DrillStem(i)%Id
     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Od             = data%State%TD_DrillStem(i)%Od
     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Area           = (pi*((data%State%TD_DrillStem(i)%Od**2)-(data%State%TD_DrillStem(i)%Id**2)))/4.0d0
     
     if (data%State%TD_DrillStem(i)%ComponentType == 3 .or. data%State%TD_DrillStem(i)%ComponentType == 4) then
         data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%RtoolJoint     = data%State%TD_DrillStem(i)%Od*1.30d0/2.0d0
         data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%ToolJointRange = data%State%TD_String%ToolJointRange
     else if (data%State%TD_DrillStem(i)%ComponentType == 1 .or. data%State%TD_DrillStem(i)%ComponentType == 2) then
         data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%RtoolJoint = data%State%TD_DrillStem(i)%Od/2.0d0
         data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%ToolJointRange = data%State%TD_String%ToolJointRange
     else if (data%State%TD_DrillStem(i)%ComponentType == 0) then
         data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%RtoolJoint = data%State%TD_DrillStem(i)%Od
         data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%ToolJointRange = 0.0d0
     end if
     
     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Length         = data%State%TD_DrillStem(i)%Length
     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%LengthIni      = data%State%TD_DrillStem(i)%Length
     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%WeightperLength= data%State%TD_DrillStem(i)%WeightperLength
     data%State%TD_DrillStems(TD_FirstIndex:TD_LastIndex)%Weight         = data%State%TD_DrillStem(i)%WeightperLength*data%State%TD_DrillStem(i)%Length
    
     TD_FirstIndex = TD_LastIndex+1
     
   End Do
   
   
   
   
   
   

!====================================================
!               Set Hook Height Data
!====================================================
   data%State%TD_StConn%HookHeightOld = data%State%Drawworks%Hook_Height_ini
   data%State%TD_StConn%HookHeight    = data%State%TD_StConn%HookHeightOld
   
   
   
   
   
    
end subroutine 