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.
 
 
 
 
 
 

1326 lines
46 KiB

  1. module CManifolds
  2. ! use CStack
  3. ! use CArrangement
  4. use SimulationVariables
  5. use ManifoldVariables
  6. implicit none
  7. contains
  8. subroutine ManifoldToJson(parent)
  9. type(json_value),pointer :: parent
  10. type(json_value),pointer :: p
  11. type(json_core) :: json
  12. logical :: valve_states(ValveCount)
  13. integer :: i
  14. ! 1. create new node
  15. call json%create_object(p,'Manifold')
  16. ! 2. add member of data type to new node
  17. DO I=1,ValveCount
  18. valve_states(i) = data%state%Manifold%Valve(i)%Status
  19. ENDDO
  20. call json%add(p, "valves", valve_states)
  21. ! 3. add new node to parent
  22. call json%add(parent,p)
  23. end subroutine
  24. subroutine PathFinding_Setup()
  25. implicit none
  26. data%state%manifold%IsTraverse = .false.
  27. call Setup()
  28. !call OnSimulationInitialization%Add(PathFinding_Init)
  29. !call OnSimulationStop%Add(PathFinding_Init)
  30. !!**call OnpPathFindingStep%Add(PathFinding_Step)
  31. !!**call OnpPathFindingOutput%Add(PathFinding_Output)
  32. ! !**call OnpPathFindingMain%Add(PathFindingMainBody)
  33. end subroutine
  34. subroutine PathFinding_Init
  35. implicit none
  36. data%state%manifold%IsTraverse = .false.
  37. call Setup()
  38. end subroutine PathFinding_Init
  39. subroutine PathFinding_Step
  40. if (data%state%manifold%IsPathsDirty) then
  41. data%state%manifold%IsPathsDirty = .false.
  42. call Traverse()
  43. endif
  44. end subroutine PathFinding_Step
  45. ! subroutine PathFinding_Output
  46. ! implicit none
  47. ! end subroutine PathFinding_Output
  48. ! subroutine PathFindingMainBody
  49. ! ! use CSimulationVariables
  50. ! implicit none
  51. ! loop : do
  52. ! if(IsStopped) call Quit()
  53. ! call sleepqq(50)
  54. ! if (Manifold%IsPathsDirty) then
  55. ! Manifold%IsPathsDirty = .false.
  56. ! call Traverse()
  57. ! endif
  58. ! end do loop
  59. ! end subroutine PathFindingMainBody
  60. subroutine Traverse() bind(C,name="Traverse")
  61. use CLog5
  62. implicit none
  63. integer :: i
  64. !**call BeforeTraverse%RunAll()
  65. if(allocated(data%state%manifold%OpenPaths)) deallocate(data%state%manifold%OpenPaths)
  66. do i=MinSource, MaxSource
  67. if(IsValveOpen(i)) then
  68. call data%state%manifold%Fringe%Push(i)
  69. call AddChildren(data%state%manifold%Valve(i))
  70. endif
  71. enddo
  72. call PostProcess(data%state%manifold%OpenPaths)
  73. !**call AfterTraverse%RunAll()
  74. data%state%manifold%IsTraverse = .true.
  75. call DisplayOpenPaths()
  76. end subroutine
  77. subroutine PostProcess(pathArr)
  78. implicit none
  79. type(Path), allocatable, intent(inout) :: pathArr(:)
  80. integer :: i
  81. if(.not.allocated(pathArr)) return
  82. i = 1
  83. do
  84. call pathArr(i)%Purge(MinRelation, MaxRelation)
  85. if(pathArr(i)%Length() <= 2) then
  86. call RemovePath(pathArr, i)
  87. else
  88. i = i + 1
  89. endif
  90. if(i > size(pathArr)) exit
  91. enddo
  92. end subroutine
  93. recursive subroutine AddChildren(node)
  94. implicit none
  95. type(Arrangement), intent(inout) :: node
  96. integer :: i,t
  97. do i=1, data%state%manifold%Valve(node%Number)%Length()
  98. t = data%state%manifold%Valve(node%Number)%Adjacent(i)
  99. if(IsValveOpen(t)) then
  100. if(data%state%manifold%Fringe%DoesHave(t)) cycle
  101. call data%state%manifold%Fringe%Push(t)
  102. if(data%state%manifold%Valve(t)%IsSource()) then
  103. call AddPath(data%state%manifold%OpenPaths, data%state%manifold%Fringe%List)
  104. call data%state%manifold%Fringe%Pop()
  105. cycle
  106. endif
  107. call AddChildren(data%state%manifold%Valve(node%Adjacent(i)))
  108. end if
  109. enddo
  110. call data%state%manifold%Fringe%Pop()
  111. end subroutine
  112. logical function IsValveOpen(no)
  113. implicit none
  114. integer, intent(in) :: no
  115. IsValveOpen = data%state%manifold%Valve(no)%Status
  116. end function
  117. subroutine AddPath(pathArr, p)
  118. implicit none
  119. type(Path), intent(in) :: p
  120. type(Path), allocatable, intent(inout) :: pathArr(:)
  121. type(Path), allocatable :: tempArr(:)
  122. integer :: i, isize
  123. if(p%IsNull()) return
  124. if(p%Length()<=1) return
  125. !**call OnpPathOpen%RunAll(p%Valves)
  126. if(allocated(pathArr)) then
  127. isize = size(pathArr)
  128. ! check to see if already have a path same as p
  129. do i=1,isize
  130. if(pathArr(i)%First()==p%First() .and. pathArr(i)%Last()==p%Last()) then
  131. ! if there is then
  132. ! check to see if both have exacly a same length
  133. if(pathArr(i)%Length()==p%Length())then
  134. ! now they are the same so ignore adding this one
  135. return
  136. else
  137. !if they have different lengths then choose the shorter one
  138. if(pathArr(i)%Length()>p%Length())pathArr(i) = p
  139. return
  140. endif
  141. endif
  142. end do
  143. !TODO: if p last valve is input source then ignore adding it
  144. !TODO: if p start valve is output source then ignore adding it
  145. ! if p is a new entry then add it to the collections of found paths
  146. allocate(tempArr(isize+1))
  147. do i=1,isize
  148. tempArr(i) = pathArr(i)
  149. end do
  150. tempArr(isize+1) = p
  151. deallocate(pathArr)
  152. call move_alloc(tempArr, pathArr)
  153. else
  154. allocate(pathArr(1))
  155. pathArr(1) = p
  156. end if
  157. endsubroutine
  158. subroutine RemovePath(pathArr, index)
  159. implicit none
  160. integer, intent(in) :: index
  161. type(Path), allocatable, intent(inout) :: pathArr(:)
  162. type(Path), allocatable :: tempArr(:)
  163. integer :: i
  164. logical :: found
  165. if(index <= 0 .or. index > size(pathArr)) return
  166. if(.not.allocated(pathArr))return
  167. allocate(tempArr(size(pathArr)-1))
  168. found = .false.
  169. do i=1, size(pathArr)
  170. if(i==index) then
  171. found = .true.
  172. cycle
  173. end if
  174. if(found) then
  175. tempArr(i-1) = pathArr(i)
  176. !!**call OnpPathClose%RunAll(pathArr(i)%Valves)
  177. else
  178. tempArr(i) = pathArr(i)
  179. endif
  180. end do
  181. deallocate(pathArr)
  182. call move_alloc(tempArr, pathArr)
  183. endsubroutine
  184. subroutine Setup()
  185. implicit none
  186. integer :: i
  187. ! initialize all valves
  188. do i = 1, ValveCount
  189. call data%state%manifold%Valve(i)%init(i)
  190. end do
  191. ! open source valves
  192. do i = MinSource , MaxSource
  193. data%state%manifold%Valve(i)%Status = .true.
  194. data%state%manifold%Valve(i)%ValveType = InputOutput
  195. end do
  196. do i = MinRelation , MaxRelation
  197. data%state%manifold%Valve(i)%Status = .true.
  198. data%state%manifold%Valve(i)%ValveType = Relation
  199. end do
  200. ! make adjustments
  201. call data%state%manifold%Valve(1)%AdjacentTo(91)
  202. call data%state%manifold%Valve(2)%AdjacentTo(92)
  203. call data%state%manifold%Valve(2)%AdjacentTo(117)
  204. call data%state%manifold%Valve(3)%AdjacentTo(93)
  205. call data%state%manifold%Valve(3)%AdjacentTo(118)
  206. call data%state%manifold%Valve(4)%AdjacentTo(94)
  207. call data%state%manifold%Valve(5)%AdjacentTo(95)
  208. call data%state%manifold%Valve(6)%AdjacentTo(91)
  209. call data%state%manifold%Valve(6)%AdjacentTo(92)
  210. call data%state%manifold%Valve(7)%AdjacentTo(92)
  211. call data%state%manifold%Valve(7)%AdjacentTo(93)
  212. call data%state%manifold%Valve(8)%AdjacentTo(93)
  213. call data%state%manifold%Valve(8)%AdjacentTo(94)
  214. call data%state%manifold%Valve(9)%AdjacentTo(91)
  215. call data%state%manifold%Valve(9)%AdjacentTo(96)
  216. call data%state%manifold%Valve(10)%AdjacentTo(94)
  217. call data%state%manifold%Valve(10)%AdjacentTo(98)
  218. call data%state%manifold%Valve(11)%AdjacentTo(96)
  219. call data%state%manifold%Valve(11)%AdjacentTo(97)
  220. call data%state%manifold%Valve(12)%AdjacentTo(97)
  221. call data%state%manifold%Valve(12)%AdjacentTo(98)
  222. call data%state%manifold%Valve(13)%AdjacentTo(96)
  223. call data%state%manifold%Valve(13)%AdjacentTo(99)
  224. call data%state%manifold%Valve(14)%AdjacentTo(78)
  225. call data%state%manifold%Valve(14)%AdjacentTo(97)
  226. !call Valve(14)%AdjacentTo(126)
  227. call data%state%manifold%Valve(15)%AdjacentTo(98)
  228. call data%state%manifold%Valve(15)%AdjacentTo(99)
  229. call data%state%manifold%Valve(16)%AdjacentTo(121)
  230. !call Valve(16)%AdjacentTo()
  231. call data%state%manifold%Valve(17)%AdjacentTo(122)
  232. !call Valve(17)%AdjacentTo()
  233. call data%state%manifold%Valve(18)%AdjacentTo(123)
  234. !call Valve(18)%AdjacentTo()
  235. call data%state%manifold%Valve(19)%AdjacentTo(101)
  236. call data%state%manifold%Valve(19)%AdjacentTo(102)
  237. call data%state%manifold%Valve(20)%AdjacentTo(100)
  238. call data%state%manifold%Valve(21)%AdjacentTo(101)
  239. call data%state%manifold%Valve(22)%AdjacentTo(102)
  240. call data%state%manifold%Valve(23)%AdjacentTo(71)
  241. call data%state%manifold%Valve(24)%AdjacentTo(71)
  242. call data%state%manifold%Valve(25)%AdjacentTo(108)
  243. call data%state%manifold%Valve(25)%AdjacentTo(118)
  244. call data%state%manifold%Valve(26)%AdjacentTo(109)
  245. call data%state%manifold%Valve(26)%AdjacentTo(117)
  246. call data%state%manifold%Valve(27)%AdjacentTo(32)
  247. call data%state%manifold%Valve(27)%AdjacentTo(108)
  248. call data%state%manifold%Valve(28)%AdjacentTo(33)
  249. call data%state%manifold%Valve(28)%AdjacentTo(108)
  250. call data%state%manifold%Valve(29)%AdjacentTo(110)
  251. call data%state%manifold%Valve(29)%AdjacentTo(113)
  252. call data%state%manifold%Valve(30)%AdjacentTo(34)
  253. call data%state%manifold%Valve(30)%AdjacentTo(109)
  254. call data%state%manifold%Valve(31)%AdjacentTo(35)
  255. call data%state%manifold%Valve(31)%AdjacentTo(109)
  256. call data%state%manifold%Valve(32)%AdjacentTo(27)
  257. call data%state%manifold%Valve(32)%AdjacentTo(61)
  258. call data%state%manifold%Valve(33)%AdjacentTo(28)
  259. call data%state%manifold%Valve(33)%AdjacentTo(62)
  260. call data%state%manifold%Valve(34)%AdjacentTo(30)
  261. call data%state%manifold%Valve(34)%AdjacentTo(63)
  262. call data%state%manifold%Valve(35)%AdjacentTo(31)
  263. call data%state%manifold%Valve(35)%AdjacentTo(64)
  264. call data%state%manifold%Valve(36)%AdjacentTo(116)
  265. call data%state%manifold%Valve(37)%AdjacentTo(78)
  266. call data%state%manifold%Valve(38)%AdjacentTo(71)
  267. call data%state%manifold%Valve(39)%AdjacentTo(77)
  268. !call Valve(40)%AdjacentTo(105)
  269. call data%state%manifold%Valve(40)%AdjacentTo(80)
  270. call data%state%manifold%Valve(41)%AdjacentTo(77)
  271. call data%state%manifold%Valve(42)%AdjacentTo(71)
  272. call data%state%manifold%Valve(43)%AdjacentTo(106)
  273. call data%state%manifold%Valve(44)%AdjacentTo(77)
  274. call data%state%manifold%Valve(45)%AdjacentTo(71)
  275. call data%state%manifold%Valve(46)%AdjacentTo(104)
  276. call data%state%manifold%Valve(47)%AdjacentTo(104)
  277. call data%state%manifold%Valve(47)%AdjacentTo(117)
  278. call data%state%manifold%Valve(48)%AdjacentTo(69)
  279. call data%state%manifold%Valve(48)%AdjacentTo(79)
  280. call data%state%manifold%Valve(49)%AdjacentTo(104)
  281. call data%state%manifold%Valve(49)%AdjacentTo(79)
  282. !call Valve(50)%AdjacentTo(48)
  283. call data%state%manifold%Valve(50)%AdjacentTo(51)
  284. !call Valve(50)%AdjacentTo(54)
  285. call data%state%manifold%Valve(50)%AdjacentTo(104)
  286. call data%state%manifold%Valve(51)%AdjacentTo(50)
  287. call data%state%manifold%Valve(51)%AdjacentTo(52)
  288. call data%state%manifold%Valve(52)%AdjacentTo(51)
  289. !call Valve(52)%AdjacentTo(127)
  290. call data%state%manifold%Valve(52)%AdjacentTo(80)
  291. !call Valve(53)%AdjacentTo(103)
  292. !call Valve(53)%AdjacentTo(105)
  293. call data%state%manifold%Valve(53)%AdjacentTo(80)
  294. !call Valve(54)%AdjacentTo(69)
  295. !call Valve(54)%AdjacentTo(124)
  296. !call Valve(55)%AdjacentTo(103)
  297. !call Valve(55)%AdjacentTo(124)
  298. call data%state%manifold%Valve(56)%AdjacentTo(128)
  299. call data%state%manifold%Valve(56)%AdjacentTo(127)
  300. !call Valve(57)%AdjacentTo(14)
  301. !call Valve(57)%AdjacentTo(103)
  302. !call Valve(57)%AdjacentTo(126)
  303. call data%state%manifold%Valve(58)%AdjacentTo(78)
  304. call data%state%manifold%Valve(59)%AdjacentTo(78)
  305. call data%state%manifold%Valve(60)%AdjacentTo(78)
  306. call data%state%manifold%Valve(61)%AdjacentTo(32)
  307. call data%state%manifold%Valve(61)%AdjacentTo(115)
  308. call data%state%manifold%Valve(62)%AdjacentTo(33)
  309. call data%state%manifold%Valve(62)%AdjacentTo(114)
  310. call data%state%manifold%Valve(63)%AdjacentTo(112)
  311. call data%state%manifold%Valve(63)%AdjacentTo(34)
  312. call data%state%manifold%Valve(64)%AdjacentTo(35)
  313. call data%state%manifold%Valve(64)%AdjacentTo(111)
  314. call data%state%manifold%Valve(65)%AdjacentTo(120)
  315. call data%state%manifold%Valve(66)%AdjacentTo(120)
  316. call data%state%manifold%Valve(67)%AdjacentTo(73)
  317. call data%state%manifold%Valve(68)%AdjacentTo(125)
  318. call data%state%manifold%Valve(68)%AdjacentTo(126)
  319. call data%state%manifold%Valve(69)%AdjacentTo(48)
  320. call data%state%manifold%Valve(69)%AdjacentTo(124)
  321. !call Valve(70)%AdjacentTo()
  322. !call Valve(70)%AdjacentTo()
  323. call data%state%manifold%Valve(71)%AdjacentTo(20)
  324. call data%state%manifold%Valve(71)%AdjacentTo(44)
  325. call data%state%manifold%Valve(71)%AdjacentTo(59)
  326. call data%state%manifold%Valve(72)%AdjacentTo(21)
  327. call data%state%manifold%Valve(72)%AdjacentTo(23)
  328. call data%state%manifold%Valve(73)%AdjacentTo(22)
  329. call data%state%manifold%Valve(74)%AdjacentTo(24)
  330. !call Valve(75)%AdjacentTo()
  331. !call Valve(76)%AdjacentTo()
  332. call data%state%manifold%Valve(77)%AdjacentTo(43)
  333. call data%state%manifold%Valve(77)%AdjacentTo(58)
  334. !call Valve(78)%AdjacentTo()
  335. call data%state%manifold%Valve(79)%AdjacentTo(48)
  336. call data%state%manifold%Valve(79)%AdjacentTo(49)
  337. call data%state%manifold%Valve(80)%AdjacentTo(52)
  338. call data%state%manifold%Valve(80)%AdjacentTo(107)
  339. call data%state%manifold%Valve(81)%AdjacentTo(53)
  340. call data%state%manifold%Valve(82)%AdjacentTo(16)
  341. call data%state%manifold%Valve(83)%AdjacentTo(17)
  342. call data%state%manifold%Valve(84)%AdjacentTo(18)
  343. !call Valve(85)%AdjacentTo()
  344. !call Valve(86)%AdjacentTo()
  345. !call Valve(87)%AdjacentTo()
  346. !call Valve(88)%AdjacentTo()
  347. !!call Valve(89)%AdjacentTo()
  348. !call Valve(90)%AdjacentTo()
  349. call data%state%manifold%Valve(91)%AdjacentTo(6)
  350. call data%state%manifold%Valve(91)%AdjacentTo(9)
  351. call data%state%manifold%Valve(91)%AdjacentTo(75)
  352. call data%state%manifold%Valve(92)%AdjacentTo(6)
  353. call data%state%manifold%Valve(92)%AdjacentTo(7)
  354. call data%state%manifold%Valve(92)%AdjacentTo(2)
  355. call data%state%manifold%Valve(93)%AdjacentTo(3)
  356. call data%state%manifold%Valve(93)%AdjacentTo(7)
  357. call data%state%manifold%Valve(93)%AdjacentTo(8)
  358. call data%state%manifold%Valve(94)%AdjacentTo(8)
  359. call data%state%manifold%Valve(94)%AdjacentTo(10)
  360. call data%state%manifold%Valve(94)%AdjacentTo(95)
  361. call data%state%manifold%Valve(95)%AdjacentTo(76)
  362. call data%state%manifold%Valve(95)%AdjacentTo(94)
  363. call data%state%manifold%Valve(96)%AdjacentTo(9)
  364. call data%state%manifold%Valve(96)%AdjacentTo(11)
  365. call data%state%manifold%Valve(96)%AdjacentTo(13)
  366. call data%state%manifold%Valve(97)%AdjacentTo(11)
  367. call data%state%manifold%Valve(97)%AdjacentTo(12)
  368. call data%state%manifold%Valve(97)%AdjacentTo(14)
  369. call data%state%manifold%Valve(98)%AdjacentTo(10)
  370. call data%state%manifold%Valve(98)%AdjacentTo(12)
  371. call data%state%manifold%Valve(98)%AdjacentTo(15)
  372. call data%state%manifold%Valve(99)%AdjacentTo(13)
  373. call data%state%manifold%Valve(99)%AdjacentTo(15)
  374. call data%state%manifold%Valve(99)%AdjacentTo(125)
  375. !call Valve(100)%AdjacentTo(16)
  376. call data%state%manifold%Valve(100)%AdjacentTo(82)
  377. call data%state%manifold%Valve(100)%AdjacentTo(101)
  378. !call Valve(101)%AdjacentTo(17)
  379. call data%state%manifold%Valve(101)%AdjacentTo(19)
  380. call data%state%manifold%Valve(101)%AdjacentTo(83)
  381. call data%state%manifold%Valve(101)%AdjacentTo(100)
  382. !call Valve(102)%AdjacentTo(18)
  383. call data%state%manifold%Valve(102)%AdjacentTo(19)
  384. call data%state%manifold%Valve(102)%AdjacentTo(84)
  385. !call Valve(103)%AdjacentTo(53)
  386. !call Valve(103)%AdjacentTo(56)
  387. call data%state%manifold%Valve(103)%AdjacentTo(124)
  388. !call Valve(103)%AdjacentTo(56)
  389. !call Valve(103)%AdjacentTo(78)
  390. call data%state%manifold%Valve(104)%AdjacentTo(46)
  391. call data%state%manifold%Valve(104)%AdjacentTo(47)
  392. call data%state%manifold%Valve(104)%AdjacentTo(49)
  393. call data%state%manifold%Valve(104)%AdjacentTo(50)
  394. !call Valve(105)%AdjacentTo(53)
  395. !call Valve(105)%AdjacentTo(107)
  396. !call Valve(105)%AdjacentTo(127)
  397. call data%state%manifold%Valve(106)%AdjacentTo(40)
  398. call data%state%manifold%Valve(106)%AdjacentTo(45)
  399. call data%state%manifold%Valve(107)%AdjacentTo(41)
  400. !call Valve(107)%AdjacentTo(105)
  401. call data%state%manifold%Valve(107)%AdjacentTo(119)
  402. !call Valve(107)%AdjacentTo(42)
  403. call data%state%manifold%Valve(108)%AdjacentTo(25)
  404. call data%state%manifold%Valve(108)%AdjacentTo(27)
  405. call data%state%manifold%Valve(108)%AdjacentTo(28)
  406. call data%state%manifold%Valve(108)%AdjacentTo(110)
  407. call data%state%manifold%Valve(109)%AdjacentTo(26)
  408. call data%state%manifold%Valve(109)%AdjacentTo(30)
  409. call data%state%manifold%Valve(109)%AdjacentTo(31)
  410. call data%state%manifold%Valve(109)%AdjacentTo(110)
  411. call data%state%manifold%Valve(110)%AdjacentTo(29)
  412. call data%state%manifold%Valve(110)%AdjacentTo(85)
  413. call data%state%manifold%Valve(110)%AdjacentTo(108)
  414. call data%state%manifold%Valve(110)%AdjacentTo(109)
  415. call data%state%manifold%Valve(111)%AdjacentTo(37)
  416. call data%state%manifold%Valve(111)%AdjacentTo(64)
  417. call data%state%manifold%Valve(111)%AdjacentTo(112)
  418. call data%state%manifold%Valve(112)%AdjacentTo(63)
  419. call data%state%manifold%Valve(112)%AdjacentTo(111)
  420. call data%state%manifold%Valve(112)%AdjacentTo(113)
  421. call data%state%manifold%Valve(113)%AdjacentTo(29)
  422. call data%state%manifold%Valve(113)%AdjacentTo(112)
  423. call data%state%manifold%Valve(113)%AdjacentTo(114)
  424. call data%state%manifold%Valve(114)%AdjacentTo(62)
  425. call data%state%manifold%Valve(114)%AdjacentTo(113)
  426. call data%state%manifold%Valve(114)%AdjacentTo(115)
  427. call data%state%manifold%Valve(115)%AdjacentTo(36)
  428. call data%state%manifold%Valve(115)%AdjacentTo(61)
  429. call data%state%manifold%Valve(115)%AdjacentTo(114)
  430. call data%state%manifold%Valve(116)%AdjacentTo(38)
  431. call data%state%manifold%Valve(116)%AdjacentTo(39)
  432. call data%state%manifold%Valve(117)%AdjacentTo(2)
  433. call data%state%manifold%Valve(117)%AdjacentTo(26)
  434. call data%state%manifold%Valve(117)%AdjacentTo(47)
  435. call data%state%manifold%Valve(118)%AdjacentTo(3)
  436. call data%state%manifold%Valve(118)%AdjacentTo(25)
  437. call data%state%manifold%Valve(118)%AdjacentTo(46)
  438. call data%state%manifold%Valve(119)%AdjacentTo(42)
  439. call data%state%manifold%Valve(119)%AdjacentTo(60)
  440. call data%state%manifold%Valve(119)%AdjacentTo(107)
  441. call data%state%manifold%Valve(120)%AdjacentTo(71)
  442. !call Valve(121)%AdjacentTo(16)
  443. call data%state%manifold%Valve(121)%AdjacentTo(1)
  444. call data%state%manifold%Valve(121)%AdjacentTo(65)
  445. !call Valve(122)%AdjacentTo(17)
  446. call data%state%manifold%Valve(122)%AdjacentTo(4)
  447. call data%state%manifold%Valve(122)%AdjacentTo(66)
  448. !call Valve(123)%AdjacentTo(18)
  449. call data%state%manifold%Valve(123)%AdjacentTo(5)
  450. call data%state%manifold%Valve(123)%AdjacentTo(67)
  451. !call Valve(124)%AdjacentTo(54)
  452. !call Valve(124)%AdjacentTo(55)
  453. call data%state%manifold%Valve(124)%AdjacentTo(69)
  454. call data%state%manifold%Valve(124)%AdjacentTo(103)
  455. call data%state%manifold%Valve(125)%AdjacentTo(68)
  456. call data%state%manifold%Valve(125)%AdjacentTo(99)
  457. ! call Valve(125)%AdjacentTo(126)
  458. call data%state%manifold%Valve(126)%AdjacentTo(128)
  459. call data%state%manifold%Valve(126)%AdjacentTo(68)
  460. !call Valve(126)%AdjacentTo(125)
  461. call data%state%manifold%Valve(127)%AdjacentTo(56)
  462. call data%state%manifold%Valve(127)%AdjacentTo(78)
  463. !call Valve(127)%AdjacentTo(105)
  464. call data%state%manifold%Valve(128)%AdjacentTo(56)
  465. call data%state%manifold%Valve(128)%AdjacentTo(126)
  466. ! initialization
  467. call ChangeValve(60, .true.)
  468. call RemoveIBop()
  469. call ToggleFillupHead(.false.)
  470. call ToggleMudBox(.false.)
  471. call RemoveTopDriveIBop()
  472. call InstallSafetyValve_KellyMode()
  473. call KellyDisconnected()
  474. end subroutine
  475. subroutine KellyConnected() !Bind(C,name='KellyConnected')
  476. implicit none
  477. call data%state%manifold%Valve(127)%RemoveAdjacent(78)
  478. call data%state%manifold%Valve(127)%AdjacentTo(103)
  479. call data%state%manifold%Valve(103)%AdjacentTo(127)
  480. if(print_log) print*, 'KellyConnected()'
  481. data%state%manifold%IsPathsDirty = .true.
  482. end subroutine
  483. subroutine KellyDisconnected() !Bind(C,name='KellyDisconnected')
  484. implicit none
  485. call data%state%manifold%Valve(127)%RemoveAdjacent(103)
  486. call data%state%manifold%Valve(103)%RemoveAdjacent(127)
  487. call data%state%manifold%Valve(127)%AdjacentTo(78)
  488. if(print_log) print*, 'KellyDisconnected()'
  489. data%state%manifold%IsPathsDirty = .true.
  490. end subroutine
  491. subroutine InstallSafetyValve_KellyMode()
  492. implicit none
  493. data%state%manifold%IsSafetyValveInstalled_KellyMode = .true.
  494. call RemoveTopDriveIBop()
  495. ! Remove Safey Valve (54)
  496. call data%state%manifold%Valve(124)%RemoveAdjacent(54)
  497. call data%state%manifold%Valve(54)%RemoveAdjacent(124)
  498. call data%state%manifold%Valve(69)%RemoveAdjacent(54)
  499. call data%state%manifold%Valve(54)%RemoveAdjacent(69)
  500. ! Remove 126-103 cnn
  501. call data%state%manifold%Valve(128)%RemoveAdjacent(127)
  502. call data%state%manifold%Valve(127)%RemoveAdjacent(128)
  503. ! now make cnn
  504. call data%state%manifold%Valve(124)%AdjacentTo(69)
  505. call data%state%manifold%Valve(69)%AdjacentTo(124)
  506. call data%state%manifold%Valve(128)%AdjacentTo(56)
  507. call data%state%manifold%Valve(56)%AdjacentTo(128)
  508. call data%state%manifold%Valve(56)%AdjacentTo(127)
  509. call data%state%manifold%Valve(127)%AdjacentTo(56)
  510. #ifdef deb
  511. if(print_log) print*, 'InstallSafetyValve_KellyMode()'
  512. #endif
  513. data%Equipments%DrillingConsole%IRSafetyValveLed = 1
  514. call OpenSafetyValve_KellyMode()
  515. end subroutine
  516. subroutine RemoveSafetyValve_KellyMode()
  517. implicit none
  518. data%state%manifold%IsSafetyValveInstalled_KellyMode = .false.
  519. call data%state%manifold%Valve(128)%RemoveAdjacent(56)
  520. call data%state%manifold%Valve(56)%RemoveAdjacent(128)
  521. call data%state%manifold%Valve(127)%RemoveAdjacent(56)
  522. call data%state%manifold%Valve(56)%RemoveAdjacent(127)
  523. call data%state%manifold%Valve(127)%AdjacentTo(128)
  524. call data%state%manifold%Valve(128)%AdjacentTo(127)
  525. data%Equipments%DrillingConsole%IRSafetyValveLed = 0
  526. call CloseSafetyValve_KellyMode()
  527. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  528. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  529. #ifdef deb
  530. if(print_log) print*, 'RemoveSafetyValve_KellyMode()'
  531. #endif
  532. end subroutine
  533. subroutine OpenSafetyValve_KellyMode()
  534. implicit none
  535. if(.not.data%state%manifold%IsSafetyValveInstalled_KellyMode) return
  536. data%Equipments%DrillingConsole%OpenSafetyValveLed = 1
  537. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  538. data%state%manifold%SafetyValve = .true.
  539. call ChangeValve(56, data%state%manifold%SafetyValve)
  540. #ifdef deb
  541. if(print_log) print*, 'OpenSafetyValve_KellyMode()'
  542. #endif
  543. end subroutine
  544. subroutine CloseSafetyValve_KellyMode()
  545. implicit none
  546. if(.not.data%state%manifold%IsSafetyValveInstalled_KellyMode) return
  547. data%Equipments%DrillingConsole%CloseSafetyValveLed = 1
  548. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  549. data%state%manifold%SafetyValve = .false.
  550. call ChangeValve(56, data%state%manifold%SafetyValve)
  551. #ifdef deb
  552. if(print_log) print*, 'CloseSafetyValve_KellyMode()'
  553. #endif
  554. end subroutine
  555. subroutine InstallSafetyValve_TripMode()
  556. implicit none
  557. data%state%manifold%IsSafetyValveInstalled_TripMode = .true.
  558. call data%state%manifold%Valve(128)%RemoveAdjacent(56)
  559. call data%state%manifold%Valve(56)%RemoveAdjacent(128)
  560. call data%state%manifold%Valve(127)%RemoveAdjacent(56)
  561. call data%state%manifold%Valve(56)%RemoveAdjacent(127)
  562. call data%state%manifold%Valve(69)%RemoveAdjacent(124)
  563. call data%state%manifold%Valve(124)%RemoveAdjacent(69)
  564. call data%state%manifold%Valve(127)%AdjacentTo(128)
  565. call data%state%manifold%Valve(128)%AdjacentTo(127)
  566. call data%state%manifold%Valve(124)%AdjacentTo(54)
  567. call data%state%manifold%Valve(54)%AdjacentTo(124)
  568. call data%state%manifold%Valve(54)%AdjacentTo(69)
  569. call data%state%manifold%Valve(69)%AdjacentTo(54)
  570. data%Equipments%DrillingConsole%IRSafetyValveLed = 1
  571. call OpenSafetyValve_TripMode()
  572. #ifdef deb
  573. if(print_log) print*, 'InstallSafetyValve_TripMode()'
  574. #endif
  575. end subroutine
  576. subroutine RemoveSafetyValve_TripMode()
  577. implicit none
  578. data%state%manifold%IsSafetyValveInstalled_TripMode = .false.
  579. call data%state%manifold%Valve(124)%RemoveAdjacent(54)
  580. call data%state%manifold%Valve(54)%RemoveAdjacent(124)
  581. call data%state%manifold%Valve(54)%RemoveAdjacent(69)
  582. call data%state%manifold%Valve(69)%RemoveAdjacent(54)
  583. call data%state%manifold%Valve(124)%AdjacentTo(69)
  584. call data%state%manifold%Valve(69)%AdjacentTo(124)
  585. data%Equipments%DrillingConsole%IRSafetyValveLed = 0
  586. call CloseSafetyValve_TripMode()
  587. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  588. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  589. if(print_log) print*, 'RemoveSafetyValve_TripMode()'
  590. end subroutine
  591. subroutine OpenSafetyValve_TripMode()
  592. implicit none
  593. if(.not.data%state%manifold%IsSafetyValveInstalled_TripMode) return
  594. data%Equipments%DrillingConsole%OpenSafetyValveLed = 1
  595. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  596. data%state%manifold%SafetyValve = .true.
  597. call ChangeValve(54, data%state%manifold%SafetyValve)
  598. #ifdef deb
  599. if(print_log) print*, 'OpenSafetyValve_TripMode()'
  600. #endif
  601. end subroutine
  602. subroutine CloseSafetyValve_TripMode()
  603. implicit none
  604. if(.not.data%state%manifold%IsSafetyValveInstalled_TripMode) return
  605. data%Equipments%DrillingConsole%CloseSafetyValveLed = 1
  606. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  607. data%state%manifold%SafetyValve = .false.
  608. call ChangeValve(54, data%state%manifold%SafetyValve)
  609. #ifdef deb
  610. if(print_log) print*, 'CloseSafetyValve_TripMode()'
  611. #endif
  612. end subroutine
  613. subroutine InstallSafetyValve_TopDrive()
  614. implicit none
  615. data%state%manifold%IsSafetyValveInstalled_TopDrive = .true.
  616. call data%state%manifold%Valve(128)%RemoveAdjacent(56)
  617. call data%state%manifold%Valve(56)%RemoveAdjacent(128)
  618. call data%state%manifold%Valve(127)%RemoveAdjacent(56)
  619. call data%state%manifold%Valve(56)%RemoveAdjacent(127)
  620. call data%state%manifold%Valve(69)%RemoveAdjacent(124)
  621. call data%state%manifold%Valve(124)%RemoveAdjacent(69)
  622. call data%state%manifold%Valve(124)%AdjacentTo(54)
  623. call data%state%manifold%Valve(54)%AdjacentTo(124)
  624. call data%state%manifold%Valve(54)%AdjacentTo(69)
  625. call data%state%manifold%Valve(69)%AdjacentTo(54)
  626. data%Equipments%DrillingConsole%IRSafetyValveLed = 1
  627. call OpenSafetyValve_TopDrive()
  628. #ifdef deb
  629. if(print_log) print*, 'InstallSafetyValve_TopDrive()'
  630. #endif
  631. end subroutine
  632. subroutine RemoveSafetyValve_TopDrive()
  633. implicit none
  634. data%state%manifold%IsSafetyValveInstalled_TopDrive = .false.
  635. call data%state%manifold%Valve(124)%RemoveAdjacent(54)
  636. call data%state%manifold%Valve(54)%RemoveAdjacent(124)
  637. call data%state%manifold%Valve(54)%RemoveAdjacent(69)
  638. call data%state%manifold%Valve(69)%RemoveAdjacent(54)
  639. call data%state%manifold%Valve(124)%AdjacentTo(69)
  640. call data%state%manifold%Valve(69)%AdjacentTo(124)
  641. data%Equipments%DrillingConsole%IRSafetyValveLed = 0
  642. call CloseSafetyValve_TopDrive()
  643. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  644. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  645. #ifdef deb
  646. if(print_log) print*, 'RemoveSafetyValve_TopDrive()'
  647. #endif
  648. end subroutine
  649. subroutine OpenSafetyValve_TopDrive()
  650. implicit none
  651. if(.not.data%state%manifold%IsSafetyValveInstalled_TopDrive) return
  652. data%Equipments%DrillingConsole%OpenSafetyValveLed = 1
  653. data%Equipments%DrillingConsole%CloseSafetyValveLed = 0
  654. data%state%manifold%SafetyValve = .true.
  655. #ifdef deb
  656. if(print_log) print*, 'OpenSafetyValve_TopDrive()'
  657. #endif
  658. call ChangeValve(54, data%state%manifold%SafetyValve)
  659. end subroutine
  660. subroutine CloseSafetyValve_TopDrive()
  661. implicit none
  662. if(.not.data%state%manifold%IsSafetyValveInstalled_TopDrive) return
  663. data%Equipments%DrillingConsole%CloseSafetyValveLed = 1
  664. data%Equipments%DrillingConsole%OpenSafetyValveLed = 0
  665. data%state%manifold%SafetyValve = .false.
  666. #ifdef deb
  667. if(print_log) print*, 'CloseSafetyValve_TopDrive()'
  668. #endif
  669. call ChangeValve(54, data%state%manifold%SafetyValve)
  670. end subroutine
  671. subroutine InstallIBop()
  672. implicit none
  673. data%state%manifold%IsIBopInstalled = .true.
  674. call data%state%manifold%Valve(103)%RemoveAdjacent(124)
  675. call data%state%manifold%Valve(124)%RemoveAdjacent(103)
  676. call data%state%manifold%Valve(55)%AdjacentTo(103)
  677. call data%state%manifold%Valve(55)%AdjacentTo(124)
  678. call data%state%manifold%Valve(103)%AdjacentTo(55)
  679. call data%state%manifold%Valve(124)%AdjacentTo(55)
  680. #ifdef deb
  681. if(print_log) print*, 'InstallIBop()'
  682. #endif
  683. data%Equipments%DrillingConsole%IRIBopLed = 1
  684. call OpenIBop()
  685. end subroutine
  686. subroutine RemoveIBop()
  687. implicit none
  688. data%state%manifold%IsIBopInstalled = .false.
  689. call data%state%manifold%Valve(55)%RemoveAdjacent(103)
  690. call data%state%manifold%Valve(55)%RemoveAdjacent(124)
  691. call data%state%manifold%Valve(103)%RemoveAdjacent(55)
  692. call data%state%manifold%Valve(124)%RemoveAdjacent(55)
  693. call data%state%manifold%Valve(103)%AdjacentTo(124)
  694. call data%state%manifold%Valve(124)%AdjacentTo(103)
  695. #ifdef deb
  696. if(print_log) print*, 'RemoveIBop()'
  697. #endif
  698. data%Equipments%DrillingConsole%IRIBopLed = 0
  699. data%state%manifold%IBop = .false.
  700. call ChangeValve(55, data%state%manifold%IBop)
  701. end subroutine
  702. subroutine OpenIBop()
  703. implicit none
  704. if(.not.data%state%manifold%IsIBopInstalled) return
  705. data%state%manifold%IBop = .true.
  706. #ifdef deb
  707. if(print_log) print*, 'OpenIBop()'
  708. #endif
  709. call ChangeValve(55, data%state%manifold%IBop)
  710. end subroutine
  711. subroutine CloseIBop()
  712. implicit none
  713. if(.not.data%state%manifold%IsIBopInstalled) return
  714. data%state%manifold%IBop = .false.
  715. #ifdef deb
  716. if(print_log) print*, 'CloseIBop()'
  717. #endif
  718. call ChangeValve(55, data%state%manifold%IBop)
  719. end subroutine
  720. subroutine InstallKellyCock()
  721. implicit none
  722. data%state%manifold%IsKellyCockInstalled = .true.
  723. call data%state%manifold%Valve(125)%RemoveAdjacent(126)
  724. call data%state%manifold%Valve(126)%RemoveAdjacent(125)
  725. call data%state%manifold%Valve(125)%AdjacentTo(68)
  726. call data%state%manifold%Valve(68)%AdjacentTo(125)
  727. call data%state%manifold%Valve(68)%AdjacentTo(126)
  728. call data%state%manifold%Valve(126)%AdjacentTo(68)
  729. #ifdef deb
  730. if(print_log) print*, 'InstallKellyCock()'
  731. #endif
  732. call OpenKellyCock()
  733. end subroutine
  734. subroutine RemoveKellyCock()
  735. implicit none
  736. data%state%manifold%IsKellyCockInstalled = .false.
  737. call data%state%manifold%Valve(125)%RemoveAdjacent(68)
  738. call data%state%manifold%Valve(126)%RemoveAdjacent(68)
  739. call data%state%manifold%Valve(68)%RemoveAdjacent(125)
  740. call data%state%manifold%Valve(68)%RemoveAdjacent(126)
  741. call data%state%manifold%Valve(125)%AdjacentTo(126)
  742. call data%state%manifold%Valve(126)%AdjacentTo(125)
  743. data%state%manifold%KellyCock = .false.
  744. call ChangeValve(68, data%state%manifold%KellyCock)
  745. data%Equipments%DrillingConsole%CloseKellyCockLed = 0
  746. data%Equipments%DrillingConsole%OpenKellyCockLed = 0
  747. #ifdef deb
  748. if(print_log) print*, 'RemoveKellyCock()'
  749. #endif
  750. end subroutine
  751. subroutine OpenKellyCock()
  752. implicit none
  753. if(.not.data%state%manifold%IsKellyCockInstalled) return
  754. data%Equipments%DrillingConsole%OpenKellyCockLed = 1
  755. data%Equipments%DrillingConsole%CloseKellyCockLed = 0
  756. data%state%manifold%KellyCock = .true.
  757. #ifdef deb
  758. if(print_log) print*, 'OpenKellyCock()'
  759. #endif
  760. call ChangeValve(68, data%state%manifold%KellyCock)
  761. end subroutine
  762. subroutine CloseKellyCock()
  763. implicit none
  764. if(.not.data%state%manifold%IsKellyCockInstalled) return
  765. data%Equipments%DrillingConsole%CloseKellyCockLed = 1
  766. data%Equipments%DrillingConsole%OpenKellyCockLed = 0
  767. data%state%manifold%KellyCock = .false.
  768. #ifdef deb
  769. if(print_log) print*, 'CloseKellyCock()'
  770. #endif
  771. call ChangeValve(68, data%state%manifold%KellyCock)
  772. end subroutine
  773. subroutine InstallTopDriveIBop()
  774. implicit none
  775. data%state%manifold%IsTopDriveIBopInstalled = .true.
  776. call data%state%manifold%Valve(126)%RemoveAdjacent(128)
  777. call data%state%manifold%Valve(128)%RemoveAdjacent(126)
  778. call data%state%manifold%Valve(126)%AdjacentTo(70)
  779. call data%state%manifold%Valve(70)%AdjacentTo(126)
  780. call data%state%manifold%Valve(128)%AdjacentTo(70)
  781. call data%state%manifold%Valve(70)%AdjacentTo(128)
  782. #ifdef deb
  783. if(print_log) print*, 'InstallTopDriveIBop()'
  784. #endif
  785. call OpenTopDriveIBop()
  786. end subroutine
  787. subroutine RemoveTopDriveIBop()
  788. implicit none
  789. data%state%manifold%IsTopDriveIBopInstalled = .false.
  790. call data%state%manifold%Valve(126)%RemoveAdjacent(70)
  791. call data%state%manifold%Valve(70)%RemoveAdjacent(126)
  792. call data%state%manifold%Valve(128)%RemoveAdjacent(70)
  793. call data%state%manifold%Valve(70)%RemoveAdjacent(128)
  794. call data%state%manifold%Valve(126)%AdjacentTo(128)
  795. call data%state%manifold%Valve(128)%AdjacentTo(126)
  796. #ifdef deb
  797. if(print_log) print*, 'RemoveTopDriveIBop()'
  798. #endif
  799. data%state%manifold%TopDriveIBop = .false.
  800. call ChangeValve(70, data%state%manifold%TopDriveIBop)
  801. end subroutine
  802. subroutine OpenTopDriveIBop()
  803. implicit none
  804. if(.not.data%state%manifold%IsTopDriveIBopInstalled) return
  805. data%state%manifold%TopDriveIBop = .true.
  806. call ChangeValve(70, data%state%manifold%TopDriveIBop)
  807. #ifdef deb
  808. if(print_log) print*, 'OpenTopDriveIBop()'
  809. #endif
  810. end subroutine
  811. subroutine CloseTopDriveIBop()
  812. implicit none
  813. if(.not.data%state%manifold%IsTopDriveIBopInstalled) return
  814. data%state%manifold%TopDriveIBop = .false.
  815. call ChangeValve(70, data%state%manifold%TopDriveIBop)
  816. #ifdef deb
  817. if(print_log) print*, 'CloseTopDriveIBop()'
  818. #endif
  819. end subroutine
  820. subroutine InstallFloatValve()
  821. implicit none
  822. data%state%manifold%IsFloatValveInstalled = .true.
  823. call data%state%manifold%Valve(69)%RemoveAdjacent(79)
  824. call data%state%manifold%Valve(79)%RemoveAdjacent(69)
  825. call data%state%manifold%Valve(48)%AdjacentTo(69)
  826. call data%state%manifold%Valve(48)%AdjacentTo(79)
  827. call data%state%manifold%Valve(69)%AdjacentTo(48)
  828. call data%state%manifold%Valve(79)%AdjacentTo(48)
  829. #ifdef deb
  830. if(print_log) print*, 'InstallFloatValve()'
  831. #endif
  832. call OpenFloatValve()
  833. end subroutine
  834. subroutine RemoveFloatValve()
  835. implicit none
  836. data%state%manifold%IsFloatValveInstalled = .false.
  837. call data%state%manifold%Valve(48)%RemoveAdjacent(69)
  838. call data%state%manifold%Valve(48)%RemoveAdjacent(79)
  839. call data%state%manifold%Valve(69)%RemoveAdjacent(48)
  840. call data%state%manifold%Valve(79)%RemoveAdjacent(48)
  841. call data%state%manifold%Valve(69)%AdjacentTo(79)
  842. call data%state%manifold%Valve(79)%AdjacentTo(69)
  843. #ifdef deb
  844. if(print_log) print*, 'RemoveFloatValve()'
  845. #endif
  846. data%state%manifold%FloatValve = .false.
  847. call ChangeValve(48, data%state%manifold%FloatValve)
  848. end subroutine
  849. subroutine OpenFloatValve()
  850. implicit none
  851. if(.not.data%state%manifold%IsFloatValveInstalled) return
  852. data%state%manifold%FloatValve = .true.
  853. #ifdef deb
  854. if(print_log) print*, 'OpenFloatValve()'
  855. #endif
  856. call ChangeValve(48, data%state%manifold%FloatValve)
  857. end subroutine
  858. subroutine CloseFloatValve()
  859. implicit none
  860. if(.not.data%state%manifold%IsFloatValveInstalled) return
  861. data%state%manifold%FloatValve = .false.
  862. #ifdef deb
  863. if(print_log) print*, 'CloseFloatValve()'
  864. #endif
  865. call ChangeValve(48, data%state%manifold%FloatValve)
  866. end subroutine
  867. subroutine ToggleFillupHead(v)
  868. implicit none
  869. logical, intent(in) :: v
  870. if(v) then
  871. call data%state%manifold%Valve(14)%RemoveAdjacent(78)
  872. call data%state%manifold%Valve(14)%AdjacentTo(57)
  873. call data%state%manifold%Valve(57)%AdjacentTo(14)
  874. call data%state%manifold%Valve(57)%AdjacentTo(103)
  875. call data%state%manifold%Valve(103)%AdjacentTo(57)
  876. else
  877. call data%state%manifold%Valve(14)%RemoveAdjacent(57)
  878. call data%state%manifold%Valve(57)%RemoveAdjacent(14)
  879. call data%state%manifold%Valve(57)%RemoveAdjacent(103)
  880. call data%state%manifold%Valve(103)%RemoveAdjacent(57)
  881. call data%state%manifold%Valve(14)%AdjacentTo(78)
  882. endif
  883. data%state%manifold%IsPathsDirty = .true.
  884. call ChangeValve(57, .true.)
  885. end subroutine
  886. subroutine ToggleMudBox(v)
  887. implicit none
  888. logical, intent(in) :: v
  889. call ChangeValve(53, v)
  890. end subroutine
  891. subroutine ToggleMiddleRams(v)
  892. implicit none
  893. logical, intent(in) :: v
  894. data%state%manifold%Valve(50)%Status = v
  895. call ChangeValve(69, v)
  896. end subroutine
  897. subroutine ToggleValve(i) bind(C,name="ToggleValve")
  898. integer :: i
  899. logical :: currentStatus
  900. currentStatus = data%State%Manifold%Valve(i)%Status
  901. call ChangeValve(i,.not. currentStatus)
  902. end subroutine
  903. subroutine ChangeValve(i, state)
  904. implicit none
  905. integer, intent(in) :: i
  906. logical, intent(in) :: state
  907. if(data%state%manifold%Valve(i)%Status==state) return
  908. data%state%manifold%Valve(i)%Status = state
  909. if(i == 41 .or. i == 42) then
  910. if(data%state%manifold%Valve(41)%Status == .false. .and. data%state%manifold%Valve(42)%Status == .false.) then
  911. data%state%manifold%Valve(60)%Status = .true.
  912. else
  913. data%state%manifold%Valve(60)%Status = .false.
  914. endif
  915. endif
  916. #ifdef deb
  917. if(print_log) print*, 'Valve(', i, ') = ', state
  918. #endif
  919. !call Traverse()
  920. data%state%manifold%IsPathsDirty = .true.
  921. end subroutine
  922. subroutine DisplayOpenPaths()
  923. implicit none
  924. integer :: i
  925. if(allocated(data%state%manifold%OpenPaths)) then
  926. do i = 1, size(data%state%manifold%OpenPaths)
  927. call data%state%manifold%OpenPaths(i)%Display()
  928. end do
  929. end if
  930. end subroutine
  931. subroutine DisplayOpenPathsWrite()
  932. implicit none
  933. integer :: i
  934. if(allocated(data%state%manifold%OpenPaths)) then
  935. do i = 1, size(data%state%manifold%OpenPaths)
  936. call data%state%manifold%OpenPaths(i)%DisplayWrite()
  937. end do
  938. end if
  939. end subroutine
  940. end module CManifolds