subroutine TD_ViscousDragForce
    
   Use TD_DrillStemComponents
   use SimulationVariables !@
   use SimulationVariables !@
   use SimulationVariables !@
   

   implicit none
   
   Integer :: i
   real(8) :: TDden, TDpreup , TDpredown , TDtem , TDmdup , TDmddown
   Real(8) :: TD_ThetaCoef1 , TD_ThetaCoef2 , TD_NCoef , TD_KCoef
   Real(8) :: TD_DragSum
   
   
   
   
   
   Do i = 1 , data%State%TD_String%DrillStemComponentsNumbs
       
       if ( data%State%TD_DrillStems(i)%MudDensityOut==0.d0 .or. data%State%TD_DrillStems(i)%MudDensityIn==0.d0 ) then
           data%State%TD_DrillStems(i)%Drag = 0.d0
           cycle
       end if
       TDmdup   = data%State%TD_DrillStems(i)%TopDepthIni
       Call AnnulusPropertyCalculator ( INT(TDmdup) , TDden , TDpreup , TDtem )
       TDmddown = data%State%TD_DrillStems(i)%DownDepthIni
       Call AnnulusPropertyCalculator ( INT(TDmddown) , TDden , TDpredown , TDtem )
       data%State%TD_DrillStems(i)%Drag = abs(TDpredown-TDpreup)*(pi*data%State%TD_DrillStems(i)%Length*12.d0*data%State%TD_DrillStems(i)%Od*12.d0)   ![psi]*[inch^2]=[lb]  ?????
       
       data%State%TD_DrillStems(i)%Drag = 0.0d0    !?????????????????????
       
   End Do
   

   
   
   
   
   !Do i = 1 , data%State%TD_String%DrillStemComponentsNumbs
   !    
   !    
   !    if ( data%State%TD_DrillStems(i)%MudDensityOut==0.d0 .or. data%State%TD_DrillStems(i)%MudDensityIn==0.d0 ) then
   !        data%State%TD_DrillStems(i)%Drag = 0.d0
   !        cycle
   !    end if
   !    
   !    !------------------------------------------------------------------------------------
   !    data%State%TD_DrillStems(i)%Od            = data%State%TD_DrillStems(i)%Od*12.d0                      ! [inch]
   !    data%State%TD_DrillStems(i)%HoleDiameter  = data%State%TD_DrillStems(i)%HoleDiameter*12.d0            ! [inch]
   !    data%State%TD_DrillStems(i)%MudDensityOut = data%State%TD_DrillStems(i)%MudDensityOut/7.48051948d0    ! [ppg]
   !    !------------------------------------------------------------------------------------
   !    
   !    
   !    TD_ThetaCoef1 = data%State%TD_DrillStems(i)%MudYieldPoint+data%State%TD_DrillStems(i)%MudPlasticVis
   !    TD_ThetaCoef2 = (2.0d0*data%State%TD_DrillStems(i)%MudPlasticVis)+data%State%TD_DrillStems(i)%MudYieldPoint
   !    TD_NCoef      = 3.32d0*log10(TD_ThetaCoef2/TD_ThetaCoef1)
   !    TD_KCoef      = (TD_ThetaCoef1)/(511.d0*TD_NCoef)
   !    
   !    
   !    
   !    If (data%State%TD_DrillStems(i)%TopDepth>0.d0) then
   !     
   !      data%State%TD_DrillStems(i)%PipeVelocity = abs(data%State%TD_String%DrillStemAxialVelocity)
   !
   !      data%State%TD_DrillStems(i)%DiamRatio = (data%State%TD_DrillStems(i)%Od)/data%State%TD_DrillStems(i)%HoleDiameter
   !      
   !
   !      data%State%TD_DrillStems(i)%MudClingingConst = ((data%State%TD_DrillStems(i)%DiamRatio**2) * (1.0d0 - (2.0d0*log(data%State%TD_DrillStems(i)%DiamRatio))) - 1.0d0) &
   !                                         / (2.0d0*(1.0d0-(data%State%TD_DrillStems(i)%DiamRatio**2))*log(data%State%TD_DrillStems(i)%DiamRatio))
   ! 
   !      data%State%TD_DrillStems(i)%AveEffVelocity = data%State%TD_DrillStems(i)%PipeVelocity * ( ((data%State%TD_DrillStems(i)%DiamRatio**2)/(1.0d0-(data%State%TD_DrillStems(i)%DiamRatio**2))) &
   !                                         + data%State%TD_DrillStems(i)%MudClingingConst)
   ! 
   !      data%State%TD_DrillStems(i)%ReNumber =  (926.4*(data%State%TD_DrillStems(i)%MudDensityOut * data%State%TD_DrillStems(i)%AveEffVelocity * (data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od))) &
   !                                   / data%State%TD_DrillStems(i)%MudPlasticVis     !Bingham-plastic drilling fluid
   !      !data%State%TD_DrillStems(i)%ReNumber =  10.9d4*( data%State%TD_DrillStems(i)%MudDensityOut*(data%State%TD_DrillStems(i)%AveEffVelocity**(2-TD_NCoef))/data%State%TD_DrillStems(i)%MudPlasticVis ) &
   !      !                           *( (((data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od)/48.)*(TD_NCoef/((2.*TD_NCoef)+1.)))**TD_NCoef )   !Power-law fluid
   !
   !      if ( data%State%TD_DrillStems(i)%ReNumber .le. 2.1d3 ) then                       !Bingham-plastic drilling fluid
   !      !if ( data%State%TD_DrillStems(i)%ReNumber .le. (3479.-(1370.*TD_NCoef)) ) then     !Power-law fluid
   ! 
   !           data%State%TD_DrillStems(i)%FricFactor = 1.60d1/data%State%TD_DrillStems(i)%ReNumber
   !           
   !           !data%State%TD_DrillStems(i)%Dp_Dl      = ( TD_KCoef/(14.4d4*(data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od)) )&
   !           !                             *( ((48./(data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od))*(((2.*TD_NCoef)+1.)/TD_NCoef))**TD_NCoef )    !Power-law fluid
   !           data%State%TD_DrillStems(i)%Dp_Dl = (data%State%TD_DrillStems(i)%FricFactor * (data%State%TD_DrillStems(i)%AveEffVelocity**2) * data%State%TD_DrillStems(i)%MudDensityOut) &
   !                                     / (25.78d0*(data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od))   !Bingham-plastic drilling fluid
   ! 
   !      else   !Bingham-plastic drilling fluid
   !      !else if ( data%State%TD_DrillStems(i)%ReNumber .gt. (4270.-(1370.*TD_NCoef)) ) then    !Power-law fluid
   !      
   !           data%State%TD_DrillStems(i)%MudClingingConst = (sqrt(( (data%State%TD_DrillStems(i)%DiamRatio**4) + data%State%TD_DrillStems(i)%DiamRatio ) &
   !                                             /(1.0d0 + data%State%TD_DrillStems(i)%DiamRatio )) - (data%State%TD_DrillStems(i)%DiamRatio**2)) &
   !                                             /(1.0d0- (data%State%TD_DrillStems(i)%DiamRatio**2))
   ! 
   !           data%State%TD_DrillStems(i)%AveEffVelocity = data%State%TD_DrillStems(i)%PipeVelocity * ( ((data%State%TD_DrillStems(i)%DiamRatio**2)/(1.0d0-(data%State%TD_DrillStems(i)%DiamRatio**2))) &
   !                                             + data%State%TD_DrillStems(i)%MudClingingConst)
   ! 
   !           data%State%TD_DrillStems(i)%ReNumber =  (926.4d0*(data%State%TD_DrillStems(i)%MudDensityOut * data%State%TD_DrillStems(i)%AveEffVelocity * (data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od))) &
   !                                       / data%State%TD_DrillStems(i)%MudPlasticVis     !Bingham-plastic drilling fluid
   !           !data%State%TD_DrillStems(i)%ReNumber =  10.9d4*( data%State%TD_DrillStems(i)%MudDensityOut*(data%State%TD_DrillStems(i)%AveEffVelocity**(2-TD_NCoef))/data%State%TD_DrillStems(i)%MudPlasticVis ) &
   !           !                          *( (((data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od)/48.)*(TD_NCoef/((2.*TD_NCoef)+1.)))**TD_NCoef )   !Power-law fluid
   ! 
   !           data%State%TD_DrillStems(i)%FricFactor = 0.0791d0/(data%State%TD_DrillStems(i)%ReNumber**0.25d0)
   !           
   !           data%State%TD_DrillStems(i)%Dp_Dl = (data%State%TD_DrillStems(i)%FricFactor * (data%State%TD_DrillStems(i)%AveEffVelocity**2) * data%State%TD_DrillStems(i)%MudDensityOut) &
   !                                     / (25.78d0*(data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od))   !Bingham-plastic drilling fluid
   !           !data%State%TD_DrillStems(i)%Dp_Dl = (data%State%TD_DrillStems(i)%FricFactor * (data%State%TD_DrillStems(i)%AveEffVelocity**2) * data%State%TD_DrillStems(i)%MudDensityOut) &
   !           !                          / (21.1*(data%State%TD_DrillStems(i)%HoleDiameter - data%State%TD_DrillStems(i)%Od))    !Power-law fluid
   !
   !      end if
   !    
   !
   !      data%State%TD_DrillStems(i)%Drag =  ( (pi/4.0d0)*data%State%TD_DrillStems(i)%Dp_Dl*data%State%TD_DrillStems(i)%Length*(data%State%TD_DrillStems(i)%Od**2)/10.d0 )   ! drag/10 = because of the value of drag force
   !      
   !    Else
   !        data%State%TD_DrillStems(i)%Drag =  0.0d0
   !        
   !    End if
   !    
   !    
   !    !------------------------------------------------------------------------------------
   !    data%State%TD_DrillStems(i)%Od            = data%State%TD_DrillStems(i)%Od/12.d0                     ! [ft]
   !    data%State%TD_DrillStems(i)%HoleDiameter  = data%State%TD_DrillStems(i)%HoleDiameter/12.d0           ! [ft]
   !    data%State%TD_DrillStems(i)%MudDensityOut = data%State%TD_DrillStems(i)%MudDensityOut*7.48051948d0   ! [lb/ft3]
   !    !------------------------------------------------------------------------------------
   !    
   ! 
   !end do
   
   if (data%State%TD_DrillStems(1)%ComponentType==0) then
       data%State%TD_DrillStems(1)%Drag = 50.d0*data%State%TD_DrillStems(1)%Od       !Od[ft]   , Drag[lb]?????
       if ( data%State%TD_DrillStems(1)%MudDensityOut==0.d0 .or. data%State%TD_DrillStems(1)%MudDensityIn==0.d0 ) then
           data%State%TD_DrillStems(1)%Drag = 0.d0
       end if
   end if
   
   !!TD_DragSum = 0.
   !!Do i = 1 , data%State%TD_String%DrillStemComponentsNumbs
   !!    TD_DragSum = TD_DragSum+data%State%TD_DrillStems(i)%Drag
   !!end do
   
        
        ! print*, 'TD_NCoef='   , TD_NCoef
        ! print*, 'TD_KCoef='   , TD_KCoef
        !
        ! print*, 'data%State%TD_DrillStems(1)%DiamRatio='   , data%State%TD_DrillStems(1)%DiamRatio
        ! print*, 'data%State%TD_DrillStems(1)%Od='   , data%State%TD_DrillStems(1)%Od
        ! print*, 'data%State%TD_DrillStems(1)%HoleDiameter='   , data%State%TD_DrillStems(1)%HoleDiameter
        ! !
        ! print*, 'data%State%TD_DrillStems(1)%MudClingingConst='   , data%State%TD_DrillStems(1)%MudClingingConst
        ! !
        ! print*, 'data%State%TD_DrillStems(1)%AveEffVelocity='   , data%State%TD_DrillStems(1)%AveEffVelocity
        ! !
        ! !print*, 'data%State%TD_DrillStems(1)%MudPlasticVis=' ,  data%State%TD_DrillStems(1)%MudPlasticVis
        ! print*, 'data%State%TD_DrillStems(1)%MudDensityOut=' ,  data%State%TD_DrillStems(1)%MudDensityOut
        ! print*, 'data%State%TD_DrillStems(1)%ReNumber='   , data%State%TD_DrillStems(1)%ReNumber
        ! !
        ! print*, 'data%State%TD_DrillStems(1)%FricFactor='   , data%State%TD_DrillStems(1)%FricFactor
        ! print*, 'data%State%TD_DrillStems(1)%Dp_Dl='   , data%State%TD_DrillStems(1)%Dp_Dl
        ! print*, 'data%State%TD_DrillStems(1)%Drag='   , data%State%TD_DrillStems(1)%Drag
        ! print*, 'data%State%TD_DrillStems(2)%Drag='   , data%State%TD_DrillStems(2)%Drag
        ! print*, 'data%State%TD_DrillStems(3)%Drag='   , data%State%TD_DrillStems(3)%Drag
        ! print*, 'TD_DragSum='   , TD_DragSum
        ! print*, 'data%State%TD_DrillStems(330)%Drag='   , data%State%TD_DrillStems(330)%Drag
        ! print*, 'data%State%TD_DrillStems(331)%Drag='   , data%State%TD_DrillStems(331)%Drag
        ! print*, 'data%State%TD_DrillStems(333)%Drag='   , data%State%TD_DrillStems(333)%Drag
   
   
   
   
   
   
end subroutine