Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

830 lines
45 KiB

  1. subroutine TD_StringConnectionModes
  2. Use CHoistingVariables
  3. Use CDrillingConsoleVariables
  4. use UnitySignalVariables
  5. ! Use CKellyConnectionEnumVariables
  6. ! Use CElevatorConnectionEnumVariables
  7. ! Use CSlipsEnumVariables
  8. ! Use COperationConditionEnumVariables
  9. use SoftwareInputsVariables
  10. ! Use CZeroStringSpeed
  11. ! Use CTdsConnectionModesEnumVariables
  12. ! Use CTdsElevatorModesEnumVariables
  13. Use COperationScenariosVariables
  14. Use TD_DrillStemComponents
  15. Use TD_WellElements
  16. Use TD_WellGeometry
  17. Use TD_GeneralData
  18. Use TD_StringConnectionData
  19. Use Drawworks_VARIABLES!, only: Drawworks
  20. implicit none
  21. integer :: i , kk
  22. Real(8) :: LengthSum
  23. !!=====> Read Data
  24. !kk = 0
  25. !LengthSum = 0.d0
  26. !
  27. !Do i = TD_String%DrillStemComponentsNumbs , 1 , -1
  28. ! if (TD_DrillStems(i)%ComponentType==3) then
  29. ! kk = i
  30. ! exit
  31. ! else if (TD_DrillStems(i)%ComponentType==5 .or. TD_DrillStems(i)%ComponentType==7) then
  32. ! LengthSum = LengthSum+TD_DrillStems(i)%LengthIni
  33. ! end if
  34. !End Do
  35. !####C_Program -----> Hoisting%DriveType =
  36. ! = 0 TopDrive_DriveType
  37. ! = 1 Kelly_DriveType
  38. !####C_Program -----> TD_StConn%KellyDriveTypeMode =
  39. ! = 0 Drill Mode (Kelly)
  40. ! = 1 Trip Mode (Elevator)
  41. ! = 2 TopDrive Mode
  42. if ( Hoisting%DriveType==1 .and. Get_OperationCondition()==OPERATION_DRILL ) then
  43. TD_StConn%KellyDriveTypeMode = 0
  44. else if ( Hoisting%DriveType==1 .and. Get_OperationCondition()==OPERATION_TRIP ) then
  45. TD_StConn%KellyDriveTypeMode = 1
  46. else if ( Hoisting%DriveType==0 ) then
  47. TD_StConn%KellyDriveTypeMode = 2
  48. end if
  49. TD_StConn%HookHeight = Drawworks%TDHookHeight ! unit: [ft]
  50. TD_StConn%ElevatorConst = 17.985d0 ! [ft] Elevator Length(14.84) ????????????????? adad ha daghigh shavand
  51. TD_StConn%ElevatorECG = OperationScenario%ECG ! [ft]
  52. TD_StConn%KellyConst = 63.280d0 ! [ft] Kelly Length(61.74) + Safety Valve Length(1.54)
  53. TD_StConn%KellyElementConst = 41.840d0 ! [ft] Kelly Element Length(40.3) + Safety Valve Length(1.54)
  54. TD_StConn%TDSLength = 24.08d0 !??????????????????? ! [ft]
  55. TD_StConn%TDSToolJointLength = 0.77d0 !??????????????????? ! [ft]
  56. TD_StConn%TDSElevatorLength = 26.837d0 !?????? ! TDS with Elevator Length [ft]
  57. TD_StConn%TDSElevatorToolLength= 0.859d0 !??????????????????? ! [ft]
  58. TD_StConn%TDSElevatorECG = 2.454d0 ! [ft]
  59. TD_Load%NumOfCables = Hoisting%NumberOfLine
  60. TD_Load%WeightTB = Hoisting%TravelingBlockWeight ! [lb]
  61. TD_Load%WeightTD = Hoisting%TopDriveWeight ! [lb]
  62. TD_Load%KellyWeight = Hoisting%KellyWeight ! [lb]
  63. !=====> Velocity Calculation
  64. TD_StConn%HookVelocity = (TD_StConn%HookHeight-TD_StConn%HookHeightOld)/TD_General%TimeStep ! [ft/s]
  65. !====================================================
  66. ! Add or Remove DrillStem Components
  67. !====================================================
  68. Call TD_AddComponents
  69. Call TD_RemoveComponents
  70. !=====> Read Data
  71. kk = 0
  72. LengthSum = 0.d0
  73. Do i = TD_String%DrillStemComponentsNumbs , 1 , -1
  74. if (TD_DrillStems(i)%ComponentType==3) then
  75. kk = i
  76. exit
  77. else if (TD_DrillStems(i)%ComponentType==5 .or. TD_DrillStems(i)%ComponentType==7) then
  78. LengthSum = LengthSum+TD_DrillStems(i)%LengthIni
  79. end if
  80. End Do
  81. !print*, 'kk' , kk
  82. !print*, 'TD_DrillStems(kk)%LengthIni0=' , TD_DrillStems(kk)%LengthIni
  83. !====================================================
  84. ! String Connection Mode Determination
  85. !====================================================
  86. !####TD_StConn%StringConnectionMode =
  87. ! = 0 Slips Set ???????
  88. ! = 1 Kelly Connected to String
  89. ! = 2 Kelly Nothing Connected
  90. ! = 3 Kelly Connected to Single
  91. ! = 4 Elevator Connected to String
  92. ! = 5 Elevator Nothing Connected
  93. ! = 6 Elevator Connected to Stand
  94. ! = 7 Elevator Connected to Single
  95. ! = 8 Elevator Latch String
  96. ! = 18 Elevator Latch Single
  97. ! = 19 Elevator Latch Stand
  98. ! = 9 TDS CONNECTION SPINE
  99. ! = 10 TDS CONNECTION STRING
  100. ! = 11 TDS CONNECTION NOTHING .and. TDS ELEVATOR LATCH STRING
  101. ! = 12 TDS CONNECTION NOTHING .and. TDS ELEVATOR CONNECTION STRING
  102. ! = 13 TDS CONNECTION NOTHING .and. TDS ELEVATOR CONNECTION NOTHING
  103. ! = 14 TDS CONNECTION NOTHING .and. TDS ELEVATOR CONNECTION STAND
  104. ! = 15 TDS CONNECTION NOTHING .and. TDS ELEVATOR CONNECTION SINGLE
  105. ! = 16 TDS CONNECTION NOTHING .and. TDS ELEVATOR LATCH SINGLE
  106. ! = 17 TDS CONNECTION NOTHING .and. TDS ELEVATOR LATCH STAND
  107. !if (TD_String%DlTouch<=0.) then ![ft]
  108. ! if(TD_StConn%HookVelocity<=0.) then
  109. ! TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  110. ! TD_StConn%StringVelocity = 0.0d0
  111. ! return
  112. ! end if
  113. !end if
  114. !=====> Connection Height Determination
  115. if ( TD_StConn%KellyDriveTypeMode==0 ) then
  116. if(Get_KellyConnection() == KELLY_CONNECTION_STRING) then
  117. TD_Count%KellyNewStatus(1) = 1
  118. else
  119. TD_Count%KellyNewStatus(1) = 0
  120. !TD_Count%KellyOldStatus(1) = 0
  121. end if
  122. if(Get_KellyConnection()==KELLY_CONNECTION_NOTHING) then
  123. TD_Count%KellyNewStatus(2) = 1
  124. else
  125. TD_Count%KellyNewStatus(2) = 0
  126. !TD_Count%KellyOldStatus(2) = 0
  127. end if
  128. if(Get_KellyConnection()==KELLY_CONNECTION_SINGLE) then
  129. TD_Count%KellyNewStatus(3) = 1
  130. else
  131. TD_Count%KellyNewStatus(3) = 0
  132. !TD_Count%KellyOldStatus(3) = 0
  133. end if
  134. if ( Get_KellyConnection() == KELLY_CONNECTION_STRING ) then
  135. TD_StConn%StringConnectionMode = 1
  136. !print*, 'TD_StConn%ConnectionHeight10=' , TD_StConn%ConnectionHeight
  137. !print*, 'TD_StConn%KellyElementConst1=' , TD_StConn%KellyElementConst
  138. !print*, 'TD_DrillStems(kk)%LengthIni1=' , TD_DrillStems(kk)%LengthIni
  139. if (TD_Count%KellyOldStatus(2)==1 .and. TD_Count%KellyNewStatus(1)/=TD_Count%KellyOldStatus(1)) then
  140. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+TD_StConn%KellyElementConst
  141. TD_Count%KellyOldStatus(1) = TD_Count%KellyNewStatus(1)
  142. TD_Count%KellyOldStatus(2) = 0
  143. else if (TD_Count%KellyOldStatus(3)==1 .and. TD_Count%KellyNewStatus(1)/=TD_Count%KellyOldStatus(1)) then
  144. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+TD_StConn%KellyElementConst+30.d0 !TD_DrillStems(kk)%LengthIni
  145. TD_Count%KellyOldStatus(1) = TD_Count%KellyNewStatus(1)
  146. TD_Count%KellyOldStatus(3) = 0
  147. end if
  148. !print*, 'TD_StConn%ConnectionHeight1=' , TD_StConn%ConnectionHeight
  149. if ( Get_Slips() == SLIPS_SET_END ) then
  150. !!if ( TD_StConn%HookVelocity>0. ) then
  151. !! Print*, '*** UnSet Slips ***' !?????????
  152. !!end if
  153. TD_StConn%KellyConnectionHeight = TD_StConn%HookHeight-(TD_StConn%KellyConst-TD_StConn%KellyElementConst) !?????????
  154. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  155. TD_StConn%StringVelocity = 0.0d0
  156. else
  157. !if (TD_String%DlTouch<=0. .and. TD_StConn%HookVelocity<=0.) then
  158. ! TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  159. ! TD_StConn%StringVelocity = 0.0d0
  160. !else
  161. TD_StConn%KellyConnectionHeight = TD_StConn%HookHeight-(TD_StConn%KellyConst-TD_StConn%KellyElementConst) !??????????
  162. TD_StConn%ConnectionHeight = TD_StConn%KellyConnectionHeight
  163. TD_StConn%StringVelocity = TD_StConn%HookVelocity
  164. !end if
  165. end if
  166. else if ( Get_KellyConnection() == KELLY_CONNECTION_NOTHING ) then
  167. TD_StConn%StringConnectionMode = 2
  168. !print*, 'TD_StConn%ConnectionHeight20=' , TD_StConn%ConnectionHeight
  169. !print*, 'TD_StConn%KellyElementConst2=' , TD_StConn%KellyElementConst
  170. if (TD_Count%KellyOldStatus(1)==1 .and. TD_Count%KellyNewStatus(2)/=TD_Count%KellyOldStatus(2)) then
  171. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight-TD_StConn%KellyElementConst
  172. TD_Count%KellyOldStatus(2) = TD_Count%KellyNewStatus(2)
  173. TD_Count%KellyOldStatus(1) = 0
  174. else if (TD_Count%KellyOldStatus(3)==1 .and. TD_Count%KellyNewStatus(2)/=TD_Count%KellyOldStatus(2)) then
  175. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  176. TD_Count%KellyOldStatus(2) = TD_Count%KellyNewStatus(2)
  177. TD_Count%KellyOldStatus(3) = 0
  178. else if (TD_Count%KellyOldStatus(5)==1 .and. TD_Count%KellyNewStatus(2)/=TD_Count%KellyOldStatus(2)) then
  179. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  180. TD_Count%KellyOldStatus(2) = TD_Count%KellyNewStatus(2)
  181. TD_Count%KellyOldStatus(5) = 0
  182. end if
  183. !print*, 'TD_StConn%ConnectionHeight2=' , TD_StConn%ConnectionHeight
  184. TD_StConn%KellyConnectionHeight = TD_StConn%HookHeight-TD_StConn%KellyConst
  185. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  186. TD_StConn%StringVelocity = 0.0d0
  187. else if ( Get_KellyConnection() == KELLY_CONNECTION_SINGLE ) then
  188. !print*, 'KELLY_CONNECTION_SINGLE' , TD_StConn%ConnectionHeight
  189. TD_StConn%StringConnectionMode = 3
  190. !print*, 'TD_StConn%ConnectionHeight30=' , TD_StConn%ConnectionHeight
  191. !print*, 'TD_StConn%KellyElementConst3=' , TD_StConn%KellyElementConst
  192. !print*, 'TD_DrillStems(kk)%LengthIni3=' , TD_DrillStems(kk)%LengthIni
  193. if (TD_Count%KellyOldStatus(1)==1 .and. TD_Count%KellyNewStatus(3)/=TD_Count%KellyOldStatus(3)) then
  194. !print*, 'KELLY_CONNECTION_SINGLE1' , TD_StConn%ConnectionHeight
  195. !print*, 'TD_StConn%KellyElementConst=' , TD_StConn%KellyElementConst
  196. !print*, 'TD_DrillStems(kk)%LengthIni=' , TD_DrillStems(kk)%LengthIni
  197. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight-TD_StConn%KellyElementConst-30.d0 !TD_DrillStems(kk)%LengthIni
  198. TD_Count%KellyOldStatus(3) = TD_Count%KellyNewStatus(3)
  199. TD_Count%KellyOldStatus(1) = 0
  200. else if (TD_Count%KellyOldStatus(2)==1 .and. TD_Count%KellyNewStatus(3)/=TD_Count%KellyOldStatus(3)) then
  201. !print*, 'KELLY_CONNECTION_SINGLE2' , TD_StConn%ConnectionHeight
  202. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  203. TD_Count%KellyOldStatus(3) = TD_Count%KellyNewStatus(3)
  204. TD_Count%KellyOldStatus(2) = 0
  205. end if
  206. !print*, 'TD_StConn%ConnectionHeight3=' , TD_StConn%ConnectionHeight
  207. !print*, 'KELLY_CONNECTION_SINGLE3' , TD_StConn%ConnectionHeight
  208. TD_StConn%KellyConnectionHeight = TD_StConn%HookHeight-TD_StConn%KellyConst-TD_DrillStems(kk)%LengthIni
  209. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  210. TD_StConn%StringVelocity = 0.0d0
  211. !print*, 'KELLY_CONNECTION_SINGLE4' , TD_StConn%ConnectionHeight
  212. end if
  213. !print*, 'KELLY_CONNECTION_SINGLE5' , TD_StConn%ConnectionHeight
  214. else if ( TD_StConn%KellyDriveTypeMode==1 ) then
  215. if(Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING) then
  216. TD_Count%KellyNewStatus(4) = 1
  217. else
  218. TD_Count%KellyNewStatus(4) = 0
  219. !TD_Count%KellyOldStatus(4) = 0
  220. end if
  221. if(Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING) then
  222. TD_Count%KellyNewStatus(5) = 1
  223. else
  224. TD_Count%KellyNewStatus(5) = 0
  225. !TD_Count%KellyOldStatus(5) = 0
  226. end if
  227. if(Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND) then
  228. TD_Count%KellyNewStatus(6) = 1
  229. else
  230. TD_Count%KellyNewStatus(6) = 0
  231. !TD_Count%KellyOldStatus(6) = 0
  232. end if
  233. if(Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE) then
  234. TD_Count%KellyNewStatus(7) = 1
  235. else
  236. TD_Count%KellyNewStatus(7) = 0
  237. !TD_Count%KellyOldStatus(7) = 0
  238. end if
  239. if(Get_ElevatorConnection() == ELEVATOR_LATCH_STRING) then
  240. TD_Count%KellyNewStatus(8) = 1
  241. else
  242. TD_Count%KellyNewStatus(8) = 0
  243. !TD_Count%KellyOldStatus(8) = 0
  244. end if
  245. if(Get_ElevatorConnection() == ELEVATOR_LATCH_SINGLE) then
  246. TD_Count%KellyNewStatus(18) = 1
  247. else
  248. TD_Count%KellyNewStatus(18) = 0
  249. !TD_Count%KellyOldStatus(18) = 0
  250. end if
  251. if(Get_ElevatorConnection() == ELEVATOR_LATCH_STAND) then
  252. TD_Count%KellyNewStatus(19) = 1
  253. else
  254. TD_Count%KellyNewStatus(19) = 0
  255. !TD_Count%KellyOldStatus(19) = 0
  256. end if
  257. if ( Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING ) then
  258. TD_StConn%StringConnectionMode = 4
  259. if (TD_Count%KellyOldStatus(5)==1 .and. TD_Count%KellyNewStatus(4)/=TD_Count%KellyOldStatus(4)) then
  260. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  261. TD_Count%KellyOldStatus(4) = TD_Count%KellyNewStatus(4)
  262. TD_Count%KellyOldStatus(5) = 0
  263. else if (TD_Count%KellyOldStatus(6)==1 .and. TD_Count%KellyNewStatus(4)/=TD_Count%KellyOldStatus(4)) then
  264. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+(3.d0*TD_DrillStems(kk)%LengthIni)
  265. TD_Count%KellyOldStatus(4) = TD_Count%KellyNewStatus(4)
  266. TD_Count%KellyOldStatus(6) = 0
  267. else if (TD_Count%KellyOldStatus(7)==1 .and. TD_Count%KellyNewStatus(4)/=TD_Count%KellyOldStatus(4)) then
  268. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+TD_DrillStems(kk)%LengthIni
  269. TD_Count%KellyOldStatus(4) = TD_Count%KellyNewStatus(4)
  270. TD_Count%KellyOldStatus(7) = 0
  271. else if (TD_Count%KellyOldStatus(8)==1 .and. TD_Count%KellyNewStatus(4)/=TD_Count%KellyOldStatus(4)) then
  272. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  273. TD_Count%KellyOldStatus(4) = TD_Count%KellyNewStatus(4)
  274. TD_Count%KellyOldStatus(8) = 0
  275. end if
  276. if ( Get_Slips() == SLIPS_SET_END ) then
  277. !if ( TD_StConn%HookVelocity>0. ) then
  278. ! Print*, '*** UnSet Slips ***' !???????????????????
  279. !end if
  280. TD_StConn%ElevatorHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst !?????????????
  281. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  282. TD_StConn%StringVelocity = 0.0d0
  283. else
  284. TD_StConn%ElevatorHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst
  285. TD_StConn%ConnectionHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst+(LengthSum+TD_StConn%ElevatorECG) !(LengthSum+TD_DrillStems(kk)%ToolJointRange)
  286. TD_StConn%StringVelocity = TD_StConn%HookVelocity
  287. end if
  288. else if ( Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING ) then
  289. TD_StConn%StringConnectionMode = 5
  290. if (TD_Count%KellyOldStatus(4)==1 .and. TD_Count%KellyNewStatus(5)/=TD_Count%KellyOldStatus(5)) then
  291. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  292. TD_Count%KellyOldStatus(5) = TD_Count%KellyNewStatus(5)
  293. TD_Count%KellyOldStatus(4) = 0
  294. else if (TD_Count%KellyOldStatus(6)==1 .and. TD_Count%KellyNewStatus(5)/=TD_Count%KellyOldStatus(5)) then
  295. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  296. TD_Count%KellyOldStatus(5) = TD_Count%KellyNewStatus(5)
  297. TD_Count%KellyOldStatus(6) = 0
  298. else if (TD_Count%KellyOldStatus(7)==1 .and. TD_Count%KellyNewStatus(5)/=TD_Count%KellyOldStatus(5)) then
  299. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  300. TD_Count%KellyOldStatus(5) = TD_Count%KellyNewStatus(5)
  301. TD_Count%KellyOldStatus(7) = 0
  302. else if (TD_Count%KellyOldStatus(8)==1 .and. TD_Count%KellyNewStatus(5)/=TD_Count%KellyOldStatus(5)) then
  303. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  304. TD_Count%KellyOldStatus(5) = TD_Count%KellyNewStatus(5)
  305. TD_Count%KellyOldStatus(8) = 0
  306. else if (TD_Count%KellyOldStatus(2)==1 .and. TD_Count%KellyNewStatus(5)/=TD_Count%KellyOldStatus(5)) then
  307. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  308. TD_Count%KellyOldStatus(5) = TD_Count%KellyNewStatus(5)
  309. TD_Count%KellyOldStatus(2) = 0
  310. end if
  311. TD_StConn%ElevatorHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst
  312. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  313. TD_StConn%StringVelocity = 0.0d0
  314. else if ( Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND ) then
  315. TD_StConn%StringConnectionMode = 6
  316. if (TD_Count%KellyOldStatus(4)==1 .and. TD_Count%KellyNewStatus(6)/=TD_Count%KellyOldStatus(6)) then
  317. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight-(3.*TD_DrillStems(kk)%LengthIni)
  318. TD_Count%KellyOldStatus(6) = TD_Count%KellyNewStatus(6)
  319. TD_Count%KellyOldStatus(4) = 0
  320. else if (TD_Count%KellyOldStatus(5)==1 .and. TD_Count%KellyNewStatus(6)/=TD_Count%KellyOldStatus(6)) then
  321. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  322. TD_Count%KellyOldStatus(6) = TD_Count%KellyNewStatus(6)
  323. TD_Count%KellyOldStatus(5) = 0
  324. else if (TD_Count%KellyOldStatus(7)==1 .and. TD_Count%KellyNewStatus(6)/=TD_Count%KellyOldStatus(6)) then
  325. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  326. TD_Count%KellyOldStatus(6) = TD_Count%KellyNewStatus(6)
  327. TD_Count%KellyOldStatus(7) = 0
  328. else if (TD_Count%KellyOldStatus(8)==1 .and. TD_Count%KellyNewStatus(6)/=TD_Count%KellyOldStatus(6)) then
  329. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  330. TD_Count%KellyOldStatus(6) = TD_Count%KellyNewStatus(6)
  331. TD_Count%KellyOldStatus(8) = 0
  332. end if
  333. TD_StConn%ElevatorHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst-(3.*TD_DrillStems(kk)%LengthIni)
  334. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  335. TD_StConn%StringVelocity = 0.0d0
  336. else if ( Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE ) then
  337. TD_StConn%StringConnectionMode = 7
  338. if (TD_Count%KellyOldStatus(4)==1 .and. TD_Count%KellyNewStatus(7)/=TD_Count%KellyOldStatus(7)) then
  339. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight-TD_DrillStems(kk)%LengthIni
  340. TD_Count%KellyOldStatus(7) = TD_Count%KellyNewStatus(7)
  341. TD_Count%KellyOldStatus(4) = 0
  342. else if (TD_Count%KellyOldStatus(5)==1 .and. TD_Count%KellyNewStatus(7)/=TD_Count%KellyOldStatus(7)) then
  343. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  344. TD_Count%KellyOldStatus(7) = TD_Count%KellyNewStatus(7)
  345. TD_Count%KellyOldStatus(5) = 0
  346. else if (TD_Count%KellyOldStatus(6)==1 .and. TD_Count%KellyNewStatus(7)/=TD_Count%KellyOldStatus(7)) then
  347. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  348. TD_Count%KellyOldStatus(7) = TD_Count%KellyNewStatus(7)
  349. TD_Count%KellyOldStatus(6) = 0
  350. else if (TD_Count%KellyOldStatus(8)==1 .and. TD_Count%KellyNewStatus(7)/=TD_Count%KellyOldStatus(7)) then
  351. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  352. TD_Count%KellyOldStatus(7) = TD_Count%KellyNewStatus(7)
  353. TD_Count%KellyOldStatus(8) = 0
  354. end if
  355. TD_StConn%ElevatorHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst-TD_DrillStems(kk)%LengthIni
  356. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  357. TD_StConn%StringVelocity = 0.0d0
  358. else if ( Get_ElevatorConnection() == ELEVATOR_LATCH_STRING ) then
  359. TD_StConn%StringConnectionMode = 8
  360. if (TD_Count%KellyOldStatus(4)==1 .and. TD_Count%KellyNewStatus(8)/=TD_Count%KellyOldStatus(8)) then
  361. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  362. TD_Count%KellyOldStatus(8) = TD_Count%KellyNewStatus(8)
  363. TD_Count%KellyOldStatus(4) = 0
  364. else if (TD_Count%KellyOldStatus(5)==1 .and. TD_Count%KellyNewStatus(8)/=TD_Count%KellyOldStatus(8)) then
  365. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  366. TD_Count%KellyOldStatus(8) = TD_Count%KellyNewStatus(8)
  367. TD_Count%KellyOldStatus(5) = 0
  368. else if (TD_Count%KellyOldStatus(6)==1 .and. TD_Count%KellyNewStatus(8)/=TD_Count%KellyOldStatus(8)) then
  369. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  370. TD_Count%KellyOldStatus(8) = TD_Count%KellyNewStatus(8)
  371. TD_Count%KellyOldStatus(6) = 0
  372. else if (TD_Count%KellyOldStatus(7)==1 .and. TD_Count%KellyNewStatus(8)/=TD_Count%KellyOldStatus(8)) then
  373. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  374. TD_Count%KellyOldStatus(8) = TD_Count%KellyNewStatus(8)
  375. TD_Count%KellyOldStatus(7) = 0
  376. end if
  377. TD_StConn%ElevatorHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst
  378. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  379. TD_StConn%StringVelocity = 0.0d0
  380. else if ( Get_ElevatorConnection() == ELEVATOR_LATCH_SINGLE ) then
  381. TD_StConn%StringConnectionMode = 18
  382. if (TD_Count%KellyOldStatus(5)==1 .and. TD_Count%KellyNewStatus(18)/=TD_Count%KellyOldStatus(18)) then
  383. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  384. TD_Count%KellyOldStatus(18) = TD_Count%KellyNewStatus(18)
  385. TD_Count%KellyOldStatus(5) = 0
  386. else if (TD_Count%KellyOldStatus(7)==1 .and. TD_Count%KellyNewStatus(18)/=TD_Count%KellyOldStatus(18)) then
  387. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  388. TD_Count%KellyOldStatus(18) = TD_Count%KellyNewStatus(18)
  389. TD_Count%KellyOldStatus(7) = 0
  390. else if (TD_Count%KellyOldStatus(8)==1 .and. TD_Count%KellyNewStatus(18)/=TD_Count%KellyOldStatus(18)) then
  391. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  392. TD_Count%KellyOldStatus(18) = TD_Count%KellyNewStatus(18)
  393. TD_Count%KellyOldStatus(8) = 0
  394. end if
  395. TD_StConn%ElevatorHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst
  396. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  397. TD_StConn%StringVelocity = 0.0d0
  398. else if ( Get_ElevatorConnection() == ELEVATOR_LATCH_STAND ) then
  399. TD_StConn%StringConnectionMode = 19
  400. if (TD_Count%KellyOldStatus(5)==1 .and. TD_Count%KellyNewStatus(19)/=TD_Count%KellyOldStatus(19)) then
  401. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  402. TD_Count%KellyOldStatus(19) = TD_Count%KellyNewStatus(19)
  403. TD_Count%KellyOldStatus(5) = 0
  404. else if (TD_Count%KellyOldStatus(6)==1 .and. TD_Count%KellyNewStatus(19)/=TD_Count%KellyOldStatus(19)) then
  405. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  406. TD_Count%KellyOldStatus(19) = TD_Count%KellyNewStatus(19)
  407. TD_Count%KellyOldStatus(6) = 0
  408. else if (TD_Count%KellyOldStatus(8)==1 .and. TD_Count%KellyNewStatus(19)/=TD_Count%KellyOldStatus(19)) then
  409. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  410. TD_Count%KellyOldStatus(19) = TD_Count%KellyNewStatus(19)
  411. TD_Count%KellyOldStatus(8) = 0
  412. end if
  413. TD_StConn%ElevatorHeight = TD_StConn%HookHeight-TD_StConn%ElevatorConst
  414. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  415. TD_StConn%StringVelocity = 0.0d0
  416. end if
  417. else if ( TD_StConn%KellyDriveTypeMode==2 ) then
  418. if( Get_TdsConnectionModes()==TDS_CONNECTION_SPINE ) then
  419. TD_Count%KellyNewStatus(9) = 1
  420. else
  421. TD_Count%KellyNewStatus(9) = 0
  422. !TD_Count%KellyOldStatus(9) = 0
  423. end if
  424. if( Get_TdsConnectionModes()==TDS_CONNECTION_STRING ) then
  425. TD_Count%KellyNewStatus(10) = 1
  426. else
  427. TD_Count%KellyNewStatus(10) = 0
  428. !TD_Count%KellyOldStatus(10) = 0
  429. end if
  430. if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STRING ) then
  431. TD_Count%KellyNewStatus(11) = 1
  432. else
  433. TD_Count%KellyNewStatus(11) = 0
  434. !TD_Count%KellyOldStatus(11) = 0
  435. end if
  436. if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STRING ) then
  437. TD_Count%KellyNewStatus(12) = 1
  438. else
  439. TD_Count%KellyNewStatus(12) = 0
  440. !TD_Count%KellyOldStatus(12) = 0
  441. end if
  442. if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then
  443. TD_Count%KellyNewStatus(13) = 1
  444. else
  445. TD_Count%KellyNewStatus(13) = 0
  446. !TD_Count%KellyOldStatus(13) = 0
  447. end if
  448. if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STAND ) then
  449. TD_Count%KellyNewStatus(14) = 1
  450. else
  451. TD_Count%KellyNewStatus(14) = 0
  452. !TD_Count%KellyOldStatus(14) = 0
  453. end if
  454. if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_SINGLE ) then
  455. TD_Count%KellyNewStatus(15) = 1
  456. else
  457. TD_Count%KellyNewStatus(15) = 0
  458. !TD_Count%KellyOldStatus(15) = 0
  459. end if
  460. if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_SINGLE ) then
  461. TD_Count%KellyNewStatus(16) = 1
  462. else
  463. TD_Count%KellyNewStatus(16) = 0
  464. !TD_Count%KellyOldStatus(16) = 0
  465. end if
  466. if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STAND ) then
  467. TD_Count%KellyNewStatus(17) = 1
  468. else
  469. TD_Count%KellyNewStatus(17) = 0
  470. !TD_Count%KellyOldStatus(17) = 0
  471. end if
  472. if ( Get_TdsConnectionModes()==TDS_CONNECTION_SPINE ) then
  473. TD_StConn%StringConnectionMode = 9
  474. if (TD_Count%KellyOldStatus(10)==1 .and. TD_Count%KellyNewStatus(9)/=TD_Count%KellyOldStatus(9)) then
  475. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  476. TD_Count%KellyOldStatus(9) = TD_Count%KellyNewStatus(9)
  477. TD_Count%KellyOldStatus(10) = 0
  478. else if (TD_Count%KellyOldStatus(11)==1 .and. TD_Count%KellyNewStatus(9)/=TD_Count%KellyOldStatus(9)) then
  479. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  480. TD_Count%KellyOldStatus(9) = TD_Count%KellyNewStatus(9)
  481. TD_Count%KellyOldStatus(11) = 0
  482. else if (TD_Count%KellyOldStatus(13)==1 .and. TD_Count%KellyNewStatus(9)/=TD_Count%KellyOldStatus(9)) then
  483. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  484. TD_Count%KellyOldStatus(9) = TD_Count%KellyNewStatus(9)
  485. TD_Count%KellyOldStatus(13) = 0
  486. end if
  487. if ( Get_Slips() == SLIPS_SET_END ) then
  488. !if ( TD_StConn%HookVelocity>0. ) then
  489. ! Print*, '*** UnSet Slips ***' !???????????????????
  490. !end if
  491. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength-TD_StConn%TDSToolJointLength !?????????????
  492. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  493. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  494. TD_StConn%StringVelocity = 0.0d0
  495. else
  496. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength-TD_StConn%TDSToolJointLength !?????????????
  497. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  498. TD_StConn%ConnectionHeight = TD_StConn%TDSHeight
  499. TD_StConn%StringVelocity = TD_StConn%HookVelocity
  500. end if
  501. else if ( Get_TdsConnectionModes()==TDS_CONNECTION_STRING ) then
  502. TD_StConn%StringConnectionMode = 10
  503. if (TD_Count%KellyOldStatus(9)==1 .and. TD_Count%KellyNewStatus(10)/=TD_Count%KellyOldStatus(10)) then
  504. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  505. TD_Count%KellyOldStatus(10) = TD_Count%KellyNewStatus(10)
  506. TD_Count%KellyOldStatus(9) = 0
  507. end if
  508. if ( Get_Slips() == SLIPS_SET_END ) then
  509. !if ( TD_StConn%HookVelocity>0. ) then
  510. ! Print*, '*** UnSet Slips ***' !???????????????????
  511. !end if
  512. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength-TD_StConn%TDSToolJointLength !?????????????
  513. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  514. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  515. TD_StConn%StringVelocity = 0.0d0
  516. else
  517. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength-TD_StConn%TDSToolJointLength !?????????????
  518. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  519. TD_StConn%ConnectionHeight = TD_StConn%TDSHeight
  520. TD_StConn%StringVelocity = TD_StConn%HookVelocity
  521. end if
  522. else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STRING ) then
  523. TD_StConn%StringConnectionMode = 11
  524. if (TD_Count%KellyOldStatus(9)==1 .and. TD_Count%KellyNewStatus(11)/=TD_Count%KellyOldStatus(11)) then
  525. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  526. TD_Count%KellyOldStatus(11) = TD_Count%KellyNewStatus(11)
  527. TD_Count%KellyOldStatus(9) = 0
  528. else if (TD_Count%KellyOldStatus(12)==1 .and. TD_Count%KellyNewStatus(11)/=TD_Count%KellyOldStatus(11)) then
  529. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  530. TD_Count%KellyOldStatus(11) = TD_Count%KellyNewStatus(11)
  531. TD_Count%KellyOldStatus(12) = 0
  532. else if (TD_Count%KellyOldStatus(13)==1 .and. TD_Count%KellyNewStatus(11)/=TD_Count%KellyOldStatus(11)) then
  533. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  534. TD_Count%KellyOldStatus(11) = TD_Count%KellyNewStatus(11)
  535. TD_Count%KellyOldStatus(13) = 0
  536. else if (TD_Count%KellyOldStatus(16)==1 .and. TD_Count%KellyNewStatus(11)/=TD_Count%KellyOldStatus(11)) then
  537. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+(TD_DrillStems(kk)%LengthIni)
  538. TD_Count%KellyOldStatus(11) = TD_Count%KellyNewStatus(11)
  539. TD_Count%KellyOldStatus(16) = 0
  540. else if (TD_Count%KellyOldStatus(17)==1 .and. TD_Count%KellyNewStatus(11)/=TD_Count%KellyOldStatus(11)) then
  541. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+(3.d0*TD_DrillStems(kk)%LengthIni)
  542. TD_Count%KellyOldStatus(11) = TD_Count%KellyNewStatus(11)
  543. TD_Count%KellyOldStatus(17) = 0
  544. end if
  545. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength !?????????????
  546. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  547. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  548. TD_StConn%StringVelocity = 0.0d0
  549. else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STRING ) then
  550. TD_StConn%StringConnectionMode = 12
  551. if (TD_Count%KellyOldStatus(11)==1 .and. TD_Count%KellyNewStatus(12)/=TD_Count%KellyOldStatus(12)) then
  552. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  553. TD_Count%KellyOldStatus(12) = TD_Count%KellyNewStatus(12)
  554. TD_Count%KellyOldStatus(11) = 0
  555. else if (TD_Count%KellyOldStatus(14)==1 .and. TD_Count%KellyNewStatus(12)/=TD_Count%KellyOldStatus(12)) then
  556. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+(3.d0*TD_DrillStems(kk)%LengthIni)
  557. TD_Count%KellyOldStatus(12) = TD_Count%KellyNewStatus(12)
  558. TD_Count%KellyOldStatus(14) = 0
  559. else if (TD_Count%KellyOldStatus(15)==1 .and. TD_Count%KellyNewStatus(12)/=TD_Count%KellyOldStatus(12)) then
  560. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+(TD_DrillStems(kk)%LengthIni)
  561. TD_Count%KellyOldStatus(12) = TD_Count%KellyNewStatus(12)
  562. TD_Count%KellyOldStatus(15) = 0
  563. end if
  564. if ( Get_Slips() == SLIPS_SET_END ) then
  565. !if ( TD_StConn%HookVelocity>0. ) then
  566. ! Print*, '*** UnSet Slips ***' !???????????????????
  567. !end if
  568. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength !?????????????
  569. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  570. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  571. TD_StConn%StringVelocity = 0.0d0
  572. else
  573. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength !?????????????
  574. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSLength-TD_StConn%TDSElevatorLength !?????????????
  575. TD_StConn%ConnectionHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength+(LengthSum+TD_StConn%TDSElevatorECG) !?????????????
  576. TD_StConn%StringVelocity = TD_StConn%HookVelocity
  577. end if
  578. else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then
  579. TD_StConn%StringConnectionMode = 13
  580. if (TD_Count%KellyOldStatus(9)==1 .and. TD_Count%KellyNewStatus(13)/=TD_Count%KellyOldStatus(13)) then
  581. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  582. TD_Count%KellyOldStatus(13) = TD_Count%KellyNewStatus(13)
  583. TD_Count%KellyOldStatus(9) = 0
  584. else if (TD_Count%KellyOldStatus(11)==1 .and. TD_Count%KellyNewStatus(13)/=TD_Count%KellyOldStatus(13)) then
  585. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  586. TD_Count%KellyOldStatus(13) = TD_Count%KellyNewStatus(13)
  587. TD_Count%KellyOldStatus(11) = 0
  588. else if (TD_Count%KellyOldStatus(12)==1 .and. TD_Count%KellyNewStatus(13)/=TD_Count%KellyOldStatus(13)) then
  589. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  590. TD_Count%KellyOldStatus(13) = TD_Count%KellyNewStatus(13)
  591. TD_Count%KellyOldStatus(12) = 0
  592. else if (TD_Count%KellyOldStatus(14)==1 .and. TD_Count%KellyNewStatus(13)/=TD_Count%KellyOldStatus(13)) then
  593. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  594. TD_Count%KellyOldStatus(13) = TD_Count%KellyNewStatus(13)
  595. TD_Count%KellyOldStatus(14) = 0
  596. else if (TD_Count%KellyOldStatus(15)==1 .and. TD_Count%KellyNewStatus(13)/=TD_Count%KellyOldStatus(13)) then
  597. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  598. TD_Count%KellyOldStatus(13) = TD_Count%KellyNewStatus(13)
  599. TD_Count%KellyOldStatus(15) = 0
  600. else if (TD_Count%KellyOldStatus(16)==1 .and. TD_Count%KellyNewStatus(13)/=TD_Count%KellyOldStatus(13)) then
  601. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  602. TD_Count%KellyOldStatus(13) = TD_Count%KellyNewStatus(13)
  603. TD_Count%KellyOldStatus(16) = 0
  604. end if
  605. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength !?????????????
  606. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  607. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  608. TD_StConn%StringVelocity = 0.0d0
  609. else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STAND ) then
  610. TD_StConn%StringConnectionMode = 14
  611. if (TD_Count%KellyOldStatus(12)==1 .and. TD_Count%KellyNewStatus(14)/=TD_Count%KellyOldStatus(14)) then
  612. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight-(3.d0*TD_DrillStems(kk)%LengthIni)
  613. TD_Count%KellyOldStatus(14) = TD_Count%KellyNewStatus(14)
  614. TD_Count%KellyOldStatus(12) = 0
  615. else if (TD_Count%KellyOldStatus(13)==1 .and. TD_Count%KellyNewStatus(14)/=TD_Count%KellyOldStatus(14)) then
  616. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  617. TD_Count%KellyOldStatus(14) = TD_Count%KellyNewStatus(14)
  618. TD_Count%KellyOldStatus(13) = 0
  619. else if (TD_Count%KellyOldStatus(17)==1 .and. TD_Count%KellyNewStatus(14)/=TD_Count%KellyOldStatus(14)) then
  620. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  621. TD_Count%KellyOldStatus(14) = TD_Count%KellyNewStatus(14)
  622. TD_Count%KellyOldStatus(17) = 0
  623. end if
  624. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength !?????????????
  625. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  626. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  627. TD_StConn%StringVelocity = 0.0d0
  628. else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_SINGLE ) then
  629. TD_StConn%StringConnectionMode = 15
  630. if (TD_Count%KellyOldStatus(12)==1 .and. TD_Count%KellyNewStatus(15)/=TD_Count%KellyOldStatus(15)) then
  631. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight-(TD_DrillStems(kk)%LengthIni)
  632. TD_Count%KellyOldStatus(15) = TD_Count%KellyNewStatus(15)
  633. TD_Count%KellyOldStatus(12) = 0
  634. else if (TD_Count%KellyOldStatus(13)==1 .and. TD_Count%KellyNewStatus(15)/=TD_Count%KellyOldStatus(15)) then
  635. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  636. TD_Count%KellyOldStatus(15) = TD_Count%KellyNewStatus(15)
  637. TD_Count%KellyOldStatus(13) = 0
  638. else if (TD_Count%KellyOldStatus(16)==1 .and. TD_Count%KellyNewStatus(15)/=TD_Count%KellyOldStatus(15)) then
  639. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  640. TD_Count%KellyOldStatus(15) = TD_Count%KellyNewStatus(15)
  641. TD_Count%KellyOldStatus(16) = 0
  642. end if
  643. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength !?????????????
  644. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  645. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  646. TD_StConn%StringVelocity = 0.0d0
  647. else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_SINGLE ) then
  648. TD_StConn%StringConnectionMode = 16
  649. if (TD_Count%KellyOldStatus(11)==1 .and. TD_Count%KellyNewStatus(16)/=TD_Count%KellyOldStatus(16)) then
  650. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight-(TD_DrillStems(kk)%LengthIni)
  651. TD_Count%KellyOldStatus(16) = TD_Count%KellyNewStatus(16)
  652. TD_Count%KellyOldStatus(11) = 0
  653. else if (TD_Count%KellyOldStatus(13)==1 .and. TD_Count%KellyNewStatus(16)/=TD_Count%KellyOldStatus(16)) then
  654. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  655. TD_Count%KellyOldStatus(16) = TD_Count%KellyNewStatus(16)
  656. TD_Count%KellyOldStatus(13) = 0
  657. else if (TD_Count%KellyOldStatus(15)==1 .and. TD_Count%KellyNewStatus(16)/=TD_Count%KellyOldStatus(16)) then
  658. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  659. TD_Count%KellyOldStatus(16) = TD_Count%KellyNewStatus(16)
  660. TD_Count%KellyOldStatus(15) = 0
  661. end if
  662. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength !?????????????
  663. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  664. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  665. TD_StConn%StringVelocity = 0.0d0
  666. else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STAND ) then
  667. TD_StConn%StringConnectionMode = 17
  668. if (TD_Count%KellyOldStatus(11)==1 .and. TD_Count%KellyNewStatus(17)/=TD_Count%KellyOldStatus(17)) then
  669. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight-(3.d0*TD_DrillStems(kk)%LengthIni)
  670. TD_Count%KellyOldStatus(17) = TD_Count%KellyNewStatus(17)
  671. TD_Count%KellyOldStatus(11) = 0
  672. else if (TD_Count%KellyOldStatus(14)==1 .and. TD_Count%KellyNewStatus(17)/=TD_Count%KellyOldStatus(17)) then
  673. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight+(3.d0*TD_DrillStems(kk)%LengthIni)
  674. TD_Count%KellyOldStatus(17) = TD_Count%KellyNewStatus(17)
  675. TD_Count%KellyOldStatus(14) = 0
  676. end if
  677. TD_StConn%TDSHeight = TD_StConn%HookHeight-TD_StConn%TDSLength !?????????????
  678. TD_StConn%TDSElevatorHeight = TD_StConn%HookHeight-TD_StConn%TDSElevatorLength !?????????????
  679. TD_StConn%ConnectionHeight = TD_StConn%ConnectionHeight
  680. TD_StConn%StringVelocity = 0.0d0
  681. end if
  682. end if
  683. !Print*, 'TD_StConn%StringConnectionMode=' , TD_StConn%StringConnectionMode
  684. !print* , 'TD_StConn%ConnectionHeight=' , TD_StConn%ConnectionHeight
  685. !Print*, 'TD_StConn%StringConnectionMode=' , TD_StConn%StringConnectionMode
  686. !print*, 'TD_String%DrillStemComponentsNumbs=' , TD_String%DrillStemComponentsNumbs
  687. !!Print*, 'TD_Count%KellyNewStatus(1)=' , TD_Count%KellyNewStatus(1)
  688. !Print*, 'TD_Count%KellyOldStatus(1)=' , TD_Count%KellyOldStatus(1)
  689. !Print*, 'TD_Count%KellyNewStatus(2)=' , TD_Count%KellyNewStatus(2)
  690. !Print*, 'TD_Count%KellyOldStatus(2)=' , TD_Count%KellyOldStatus(2)
  691. !Print*, 'TD_Count%KellyNewStatus(3)=' , TD_Count%KellyNewStatus(3)
  692. !Print*, 'TD_Count%KellyOldStatus(3)=' , TD_Count%KellyOldStatus(3)
  693. if ( (any(TD_StConn%StringConnectionMode==(/1,9,10/))) .or. DrillingConsole%CloseSafetyValve==.true. ) then !for fluid module
  694. TD_StConn%FluidStringConnectionMode = 1 !string is connected
  695. !else if ( (any(TD_StConn%StringConnectionMode==(/1,9,10/))) .or. DrillingConsole%CloseSafetyValve==.true. ) then
  696. !
  697. else
  698. TD_StConn%FluidStringConnectionMode = 0 !string is not connected
  699. end if
  700. !====================================================
  701. ! Zero String Speed
  702. !====================================================
  703. if ( abs(TD_StConn%StringVelocity)<=0.05d0 ) then ! [ft/s]
  704. TD_Load%ZeroStringSpeed = 1
  705. Call Set_ZeroStringSpeed(.true.)
  706. else
  707. TD_Load%ZeroStringSpeed = 0
  708. Call Set_ZeroStringSpeed(.false.)
  709. end if
  710. end subroutine