subroutine TD_WellReadData

   use SimulationVariables !@
   use SimulationVariables !@
   
   implicit none

   Integer ::  i
   
   
   
   data%State%TD_WellGeneral%WellIntervalsCount = data%Configuration%Path%ItemCount + 1   ! +1 is belong to ROP hole
   
   if (Allocated(data%State%TD_WellGeo)) deAllocate (data%State%TD_WellGeo)
   Allocate (data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount))
   
   
   
   
!====================================================
!                Set Well Geometry Data
!====================================================
   
   data%State%TD_WellGeo(1)%HoleType      = data%Configuration%Path%Items(1)%HoleType
   data%State%TD_WellGeo(1)%StartAngle    = 0.d0                                              ![rad]
   data%State%TD_WellGeo(1)%EndAngle      = data%Configuration%Path%Items(1)%FinalAngle*(pi/180.d0)    ![rad]
   data%State%TD_WellGeo(1)%IntervalLength= data%Configuration%Path%Items(1)%TotalLength               ![ft]
   !data%State%TD_WellGeo(1)%VerticalDepth = PathGenerations(1)%TotalVerticalDepth 
   data%State%TD_WellGeo(1)%TopDepth      = 0.d0
   data%State%TD_WellGeo(1)%DownDepth     = data%Configuration%Path%Items(1)%MeasuredDepth
   
   
   
   Do i=2,data%State%TD_WellGeneral%WellIntervalsCount-1
       
       data%State%TD_WellGeo(i)%HoleType      = data%Configuration%Path%Items(i)%HoleType
       data%State%TD_WellGeo(i)%StartAngle    = data%Configuration%Path%Items(i-1)%FinalAngle*(pi/180.d0)
       data%State%TD_WellGeo(i)%EndAngle      = data%Configuration%Path%Items(i)%FinalAngle*(pi/180.d0)
       data%State%TD_WellGeo(i)%IntervalLength= data%Configuration%Path%Items(i)%TotalLength
       !data%State%TD_WellGeo(i)%VerticalDepth = data%Configuration%Path%Items(i)%TotalVerticalDepth
       data%State%TD_WellGeo(i)%TopDepth      = data%Configuration%Path%Items(i-1)%MeasuredDepth
       data%State%TD_WellGeo(i)%DownDepth     = data%Configuration%Path%Items(i)%MeasuredDepth
       
       !=====> Radius Of Curvature Calculation
       if (data%State%TD_WellGeo(i)%HoleType/=0) then
           data%State%TD_WellGeo(i)%RCurvature = ((data%State%TD_WellGeo(i)%IntervalLength)/abs(data%State%TD_WellGeo(i)%EndAngle-data%State%TD_WellGeo(i)%StartAngle))
       end if
       
   End Do
   
   
   
   
   
!=====> Set ROP Hole Data
   data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%HoleType      = 0  !Straight
   data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%StartAngle    = data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount-1)%EndAngle
   data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%EndAngle      = data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%StartAngle
   data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%IntervalLength= 0.d0
   !data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%VerticalDepth = data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount-1)%VerticalDepth
   data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%TopDepth      = data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount-1)%DownDepth
   data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%DownDepth     = data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%TopDepth+data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%IntervalLength
   
   
   
   
   
   
!=====> Vertical Depth Calculation
   if ( data%State%TD_WellGeo(1)%HoleType==0 ) then
       data%State%TD_WellGeo(1)%VerticalDepth = data%State%TD_WellGeo(1)%IntervalLength*cos(data%State%TD_WellGeo(1)%StartAngle)
   else if ( data%State%TD_WellGeo(1)%HoleType==1 ) then
       data%State%TD_WellGeo(1)%VerticalDepth = (data%State%TD_WellGeo(1)%RCurvature*sin(abs(data%State%TD_WellGeo(1)%EndAngle)-abs(data%State%TD_WellGeo(1)%StartAngle))*cos(abs(data%State%TD_WellGeo(1)%StartAngle)))-(data%State%TD_WellGeo(1)%RCurvature*(1.-cos(abs(data%State%TD_WellGeo(1)%EndAngle)-abs(data%State%TD_WellGeo(1)%StartAngle)))*sin(abs(data%State%TD_WellGeo(1)%StartAngle)))
   else if ( data%State%TD_WellGeo(1)%HoleType==2 ) then
       data%State%TD_WellGeo(1)%VerticalDepth = (data%State%TD_WellGeo(1)%RCurvature*sin(abs(abs(data%State%TD_WellGeo(1)%EndAngle)-abs(data%State%TD_WellGeo(1)%StartAngle)))*cos(abs(data%State%TD_WellGeo(1)%StartAngle)))+(data%State%TD_WellGeo(1)%RCurvature*(1.-cos(abs(abs(data%State%TD_WellGeo(1)%EndAngle)-abs(data%State%TD_WellGeo(1)%StartAngle))))*sin(abs(data%State%TD_WellGeo(1)%StartAngle)))
   End if
   Do i= 2,data%State%TD_WellGeneral%WellIntervalsCount
       if ( data%State%TD_WellGeo(i)%HoleType==0 ) then
           data%State%TD_WellGeo(i)%VerticalDepth = data%State%TD_WellGeo(i-1)%VerticalDepth+data%State%TD_WellGeo(i)%IntervalLength*cos(data%State%TD_WellGeo(i)%StartAngle)
       else if ( data%State%TD_WellGeo(i)%HoleType==1 ) then
           data%State%TD_WellGeo(i)%VerticalDepth = data%State%TD_WellGeo(i-1)%VerticalDepth+(data%State%TD_WellGeo(i)%RCurvature*sin(abs(data%State%TD_WellGeo(i)%EndAngle)-abs(data%State%TD_WellGeo(i)%StartAngle))*cos(abs(data%State%TD_WellGeo(i)%StartAngle)))-(data%State%TD_WellGeo(i)%RCurvature*(1.-cos(abs(data%State%TD_WellGeo(i)%EndAngle)-abs(data%State%TD_WellGeo(i)%StartAngle)))*sin(abs(data%State%TD_WellGeo(i)%StartAngle)))
       else if ( data%State%TD_WellGeo(i)%HoleType==2 ) then
           data%State%TD_WellGeo(i)%VerticalDepth = data%State%TD_WellGeo(i-1)%VerticalDepth+(data%State%TD_WellGeo(i)%RCurvature*sin(abs(abs(data%State%TD_WellGeo(i)%EndAngle)-abs(data%State%TD_WellGeo(i)%StartAngle)))*cos(abs(data%State%TD_WellGeo(i)%StartAngle)))+(data%State%TD_WellGeo(i)%RCurvature*(1.-cos(abs(abs(data%State%TD_WellGeo(i)%EndAngle)-abs(data%State%TD_WellGeo(i)%StartAngle))))*sin(abs(data%State%TD_WellGeo(i)%StartAngle)))
       End if
   End Do
   !Do i=1,data%State%TD_WellGeneral%WellIntervalsCount
   !    print*, 'data%State%TD_WellGeo(i)%TopDepth='      , i ,   data%State%TD_WellGeo(i)%TopDepth
   !    print*, 'data%State%TD_WellGeo(i)%DownDepth='     , i ,   data%State%TD_WellGeo(i)%DownDepth
   !    print*, 'data%State%TD_WellGeo(i)%HoleType='      , i ,   data%State%TD_WellGeo(i)%HoleType
   !    print*, 'data%State%TD_WellGeo(i)%RCurvature='    , i ,   data%State%TD_WellGeo(i)%RCurvature
   !    print*, 'data%State%TD_WellGeo(i)%EndAngle='      , i ,   data%State%TD_WellGeo(i)%EndAngle
   !    print*, 'data%State%TD_WellGeo(i)%StartAngle='    , i ,   data%State%TD_WellGeo(i)%StartAngle
   !    print*, 'data%State%TD_WellGeo(i)%VerticalDepth=' , i ,   data%State%TD_WellGeo(i)%VerticalDepth
   !end do
   
   
   
   
   
   
   
!=====> Well Total Length Calculation 
   data%State%TD_WellGeneral%WellTotalLength         = data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%DownDepth
   data%State%TD_WellGeneral%WellTotalVerticalLength = data%State%TD_WellGeo(data%State%TD_WellGeneral%WellIntervalsCount)%VerticalDepth


   
   
   
   
end subroutine 