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.

TD_StringConnectionModes.f90 55 KiB

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