# 1 "/home/admin/SimulationCore2/CSharp/Equipments/MudPathFinding/CManifolds.f90" module CManifolds ! use CStack ! use CArrangement use SimulationVariables use ManifoldVariables implicit none contains subroutine ManifoldToJson(parent) type(json_value),pointer :: parent type(json_value),pointer :: p type(json_core) :: json logical :: valve_states(ValveCount) integer :: i ! 1. create new node call json%create_object(p,'Manifold') ! 2. add member of data type to new node DO I=1,ValveCount valve_states(i) = data%state%Manifold%Valve(i)%Status ENDDO call json%add(p, "valves", valve_states) ! 3. add new node to parent call json%add(parent,p) end subroutine subroutine PathFinding_Setup() implicit none data%state%manifold%IsTraverse = .false. call Setup() !call OnSimulationInitialization%Add(PathFinding_Init) !call OnSimulationStop%Add(PathFinding_Init) !!**call OnpPathFindingStep%Add(PathFinding_Step) !!**call OnpPathFindingOutput%Add(PathFinding_Output) ! !**call OnpPathFindingMain%Add(PathFindingMainBody) end subroutine subroutine PathFinding_Init implicit none data%state%manifold%IsTraverse = .false. call Setup() end subroutine PathFinding_Init subroutine PathFinding_Step if (data%state%manifold%IsPathsDirty) then data%state%manifold%IsPathsDirty = .false. call Traverse() endif end subroutine PathFinding_Step ! subroutine PathFinding_Output ! implicit none ! end subroutine PathFinding_Output ! subroutine PathFindingMainBody ! ! use CSimulationVariables ! implicit none ! loop : do ! if(IsStopped) call Quit() ! call sleepqq(50) ! if (Manifold%IsPathsDirty) then ! Manifold%IsPathsDirty = .false. ! call Traverse() ! endif ! end do loop ! end subroutine PathFindingMainBody subroutine Traverse() bind(C,name="Traverse") use CLog5 implicit none integer :: i !**call BeforeTraverse%RunAll() if(allocated(data%state%manifold%OpenPaths)) deallocate(data%state%manifold%OpenPaths) do i=MinSource, MaxSource if(IsValveOpen(i)) then call data%state%manifold%Fringe%Push(i) call AddChildren(data%state%manifold%Valve(i)) endif enddo call PostProcess(data%state%manifold%OpenPaths) !**call AfterTraverse%RunAll() data%state%manifold%IsTraverse = .true. call DisplayOpenPaths() end subroutine subroutine PostProcess(pathArr) implicit none type(Path), allocatable, intent(inout) :: pathArr(:) integer :: i if(.not.allocated(pathArr)) return i = 1 do call pathArr(i)%Purge(MinRelation, MaxRelation) if(pathArr(i)%Length() <= 2) then call RemovePath(pathArr, i) else i = i + 1 endif if(i > size(pathArr)) exit enddo end subroutine recursive subroutine AddChildren(node) implicit none type(Arrangement), intent(inout) :: node integer :: i,t do i=1, data%state%manifold%Valve(node%Number)%Length() t = data%state%manifold%Valve(node%Number)%Adjacent(i) if(IsValveOpen(t)) then if(data%state%manifold%Fringe%DoesHave(t)) cycle call data%state%manifold%Fringe%Push(t) if(data%state%manifold%Valve(t)%IsSource()) then call AddPath(data%state%manifold%OpenPaths, data%state%manifold%Fringe%List) call data%state%manifold%Fringe%Pop() cycle endif call AddChildren(data%state%manifold%Valve(node%Adjacent(i))) end if enddo call data%state%manifold%Fringe%Pop() end subroutine logical function IsValveOpen(no) implicit none integer, intent(in) :: no IsValveOpen = data%state%manifold%Valve(no)%Status end function subroutine AddPath(pathArr, p) implicit none type(Path), intent(in) :: p type(Path), allocatable, intent(inout) :: pathArr(:) type(Path), allocatable :: tempArr(:) integer :: i, isize if(p%IsNull()) return if(p%Length()<=1) return !**call OnpPathOpen%RunAll(p%Valves) if(allocated(pathArr)) then isize = size(pathArr) ! check to see if already have a path same as p do i=1,isize if(pathArr(i)%First()==p%First() .and. pathArr(i)%Last()==p%Last()) then ! if there is then ! check to see if both have exacly a same length if(pathArr(i)%Length()==p%Length())then ! now they are the same so ignore adding this one return else !if they have different lengths then choose the shorter one if(pathArr(i)%Length()>p%Length())pathArr(i) = p return endif endif end do !TODO: if p last valve is input source then ignore adding it !TODO: if p start valve is output source then ignore adding it ! if p is a new entry then add it to the collections of found paths allocate(tempArr(isize+1)) do i=1,isize tempArr(i) = pathArr(i) end do tempArr(isize+1) = p deallocate(pathArr) call move_alloc(tempArr, pathArr) else allocate(pathArr(1)) pathArr(1) = p end if endsubroutine subroutine RemovePath(pathArr, index) implicit none integer, intent(in) :: index type(Path), allocatable, intent(inout) :: pathArr(:) type(Path), allocatable :: tempArr(:) integer :: i logical :: found if(index <= 0 .or. index > size(pathArr)) return if(.not.allocated(pathArr))return allocate(tempArr(size(pathArr)-1)) found = .false. do i=1, size(pathArr) if(i==index) then found = .true. cycle end if if(found) then tempArr(i-1) = pathArr(i) !!**call OnpPathClose%RunAll(pathArr(i)%Valves) else tempArr(i) = pathArr(i) endif end do deallocate(pathArr) call move_alloc(tempArr, pathArr) endsubroutine subroutine Setup() implicit none integer :: i ! initialize all valves do i = 1, ValveCount call data%state%manifold%Valve(i)%init(i) end do ! open source valves do i = MinSource , MaxSource data%state%manifold%Valve(i)%Status = .true. data%state%manifold%Valve(i)%ValveType = InputOutput end do do i = MinRelation , MaxRelation data%state%manifold%Valve(i)%Status = .true. data%state%manifold%Valve(i)%ValveType = Relation end do ! make adjustments call data%state%manifold%Valve(1)%AdjacentTo(91) call data%state%manifold%Valve(2)%AdjacentTo(92) call data%state%manifold%Valve(2)%AdjacentTo(117) call data%state%manifold%Valve(3)%AdjacentTo(93) call data%state%manifold%Valve(3)%AdjacentTo(118) call data%state%manifold%Valve(4)%AdjacentTo(94) call data%state%manifold%Valve(5)%AdjacentTo(95) call data%state%manifold%Valve(6)%AdjacentTo(91) call data%state%manifold%Valve(6)%AdjacentTo(92) call data%state%manifold%Valve(7)%AdjacentTo(92) call data%state%manifold%Valve(7)%AdjacentTo(93) call data%state%manifold%Valve(8)%AdjacentTo(93) call data%state%manifold%Valve(8)%AdjacentTo(94) call data%state%manifold%Valve(9)%AdjacentTo(91) call data%state%manifold%Valve(9)%AdjacentTo(96) call data%state%manifold%Valve(10)%AdjacentTo(94) call data%state%manifold%Valve(10)%AdjacentTo(98) call data%state%manifold%Valve(11)%AdjacentTo(96) call data%state%manifold%Valve(11)%AdjacentTo(97) call data%state%manifold%Valve(12)%AdjacentTo(97) call data%state%manifold%Valve(12)%AdjacentTo(98) call data%state%manifold%Valve(13)%AdjacentTo(96) call data%state%manifold%Valve(13)%AdjacentTo(99) call data%state%manifold%Valve(14)%AdjacentTo(78) call data%state%manifold%Valve(14)%AdjacentTo(97) !call Valve(14)%AdjacentTo(126) call data%state%manifold%Valve(15)%AdjacentTo(98) call data%state%manifold%Valve(15)%AdjacentTo(99) call data%state%manifold%Valve(16)%AdjacentTo(121) !call Valve(16)%AdjacentTo() call data%state%manifold%Valve(17)%AdjacentTo(122) !call Valve(17)%AdjacentTo() call data%state%manifold%Valve(18)%AdjacentTo(123) !call Valve(18)%AdjacentTo() call data%state%manifold%Valve(19)%AdjacentTo(101) call data%state%manifold%Valve(19)%AdjacentTo(102) call data%state%manifold%Valve(20)%AdjacentTo(100) call data%state%manifold%Valve(21)%AdjacentTo(101) call data%state%manifold%Valve(22)%AdjacentTo(102) call data%state%manifold%Valve(23)%AdjacentTo(71) call data%state%manifold%Valve(24)%AdjacentTo(71) call data%state%manifold%Valve(25)%AdjacentTo(108) call data%state%manifold%Valve(25)%AdjacentTo(118) call data%state%manifold%Valve(26)%AdjacentTo(109) call data%state%manifold%Valve(26)%AdjacentTo(117) call data%state%manifold%Valve(27)%AdjacentTo(32) call data%state%manifold%Valve(27)%AdjacentTo(108) call data%state%manifold%Valve(28)%AdjacentTo(33) call data%state%manifold%Valve(28)%AdjacentTo(108) call data%state%manifold%Valve(29)%AdjacentTo(110) call data%state%manifold%Valve(29)%AdjacentTo(113) call data%state%manifold%Valve(30)%AdjacentTo(34) call data%state%manifold%Valve(30)%AdjacentTo(109) call data%state%manifold%Valve(31)%AdjacentTo(35) call data%state%manifold%Valve(31)%AdjacentTo(109) call data%state%manifold%Valve(32)%AdjacentTo(27) call data%state%manifold%Valve(32)%AdjacentTo(61) call data%state%manifold%Valve(33)%AdjacentTo(28) call data%state%manifold%Valve(33)%AdjacentTo(62) call data%state%manifold%Valve(34)%AdjacentTo(30) call data%state%manifold%Valve(34)%AdjacentTo(63) call data%state%manifold%Valve(35)%AdjacentTo(31) call data%state%manifold%Valve(35)%AdjacentTo(64) call data%state%manifold%Valve(36)%AdjacentTo(116) call data%state%manifold%Valve(37)%AdjacentTo(78) call data%state%manifold%Valve(38)%AdjacentTo(71) call data%state%manifold%Valve(39)%AdjacentTo(77) !call Valve(40)%AdjacentTo(105) call data%state%manifold%Valve(40)%AdjacentTo(80) call data%state%manifold%Valve(41)%AdjacentTo(77) call data%state%manifold%Valve(42)%AdjacentTo(71) call data%state%manifold%Valve(43)%AdjacentTo(106) call data%state%manifold%Valve(44)%AdjacentTo(77) call data%state%manifold%Valve(45)%AdjacentTo(71) call data%state%manifold%Valve(46)%AdjacentTo(104) call data%state%manifold%Valve(47)%AdjacentTo(104) call data%state%manifold%Valve(47)%AdjacentTo(117) call data%state%manifold%Valve(48)%AdjacentTo(69) call data%state%manifold%Valve(48)%AdjacentTo(79) call data%state%manifold%Valve(49)%AdjacentTo(104) call data%state%manifold%Valve(49)%AdjacentTo(79) !call Valve(50)%AdjacentTo(48) call data%state%manifold%Valve(50)%AdjacentTo(51) !call Valve(50)%AdjacentTo(54) call data%state%manifold%Valve(50)%AdjacentTo(104) call data%state%manifold%Valve(51)%AdjacentTo(50) call data%state%manifold%Valve(51)%AdjacentTo(52) call data%state%manifold%Valve(52)%AdjacentTo(51) !call Valve(52)%AdjacentTo(127) call data%state%manifold%Valve(52)%AdjacentTo(80) !call Valve(53)%AdjacentTo(103) !call Valve(53)%AdjacentTo(105) call data%state%manifold%Valve(53)%AdjacentTo(80) !call Valve(54)%AdjacentTo(69) !call Valve(54)%AdjacentTo(124) !call Valve(55)%AdjacentTo(103) !call Valve(55)%AdjacentTo(124) call data%state%manifold%Valve(56)%AdjacentTo(128) call data%state%manifold%Valve(56)%AdjacentTo(127) !call Valve(57)%AdjacentTo(14) !call Valve(57)%AdjacentTo(103) !call Valve(57)%AdjacentTo(126) call data%state%manifold%Valve(58)%AdjacentTo(78) call data%state%manifold%Valve(59)%AdjacentTo(78) call data%state%manifold%Valve(60)%AdjacentTo(78) call data%state%manifold%Valve(61)%AdjacentTo(32) call data%state%manifold%Valve(61)%AdjacentTo(115) call data%state%manifold%Valve(62)%AdjacentTo(33) call data%state%manifold%Valve(62)%AdjacentTo(114) call data%state%manifold%Valve(63)%AdjacentTo(112) call data%state%manifold%Valve(63)%AdjacentTo(34) call data%state%manifold%Valve(64)%AdjacentTo(35) call data%state%manifold%Valve(64)%AdjacentTo(111) call data%state%manifold%Valve(65)%AdjacentTo(120) call data%state%manifold%Valve(66)%AdjacentTo(120) call data%state%manifold%Valve(67)%AdjacentTo(73) call data%state%manifold%Valve(68)%AdjacentTo(125) call data%state%manifold%Valve(68)%AdjacentTo(126) call data%state%manifold%Valve(69)%AdjacentTo(48) call data%state%manifold%Valve(69)%AdjacentTo(124) !call Valve(70)%AdjacentTo() !call Valve(70)%AdjacentTo() call data%state%manifold%Valve(71)%AdjacentTo(20) call data%state%manifold%Valve(71)%AdjacentTo(44) call data%state%manifold%Valve(71)%AdjacentTo(59) call data%state%manifold%Valve(72)%AdjacentTo(21) call data%state%manifold%Valve(72)%AdjacentTo(23) call data%state%manifold%Valve(73)%AdjacentTo(22) call data%state%manifold%Valve(74)%AdjacentTo(24) !call Valve(75)%AdjacentTo() !call Valve(76)%AdjacentTo() call data%state%manifold%Valve(77)%AdjacentTo(43) call data%state%manifold%Valve(77)%AdjacentTo(58) !call Valve(78)%AdjacentTo() call data%state%manifold%Valve(79)%AdjacentTo(48) call data%state%manifold%Valve(79)%AdjacentTo(49) call data%state%manifold%Valve(80)%AdjacentTo(52) call data%state%manifold%Valve(80)%AdjacentTo(107) call data%state%manifold%Valve(81)%AdjacentTo(53) call data%state%manifold%Valve(82)%AdjacentTo(16) call data%state%manifold%Valve(83)%AdjacentTo(17) call data%state%manifold%Valve(84)%AdjacentTo(18) !call Valve(85)%AdjacentTo() !call Valve(86)%AdjacentTo() !call Valve(87)%AdjacentTo() !call Valve(88)%AdjacentTo() !!call Valve(89)%AdjacentTo() !call Valve(90)%AdjacentTo() call data%state%manifold%Valve(91)%AdjacentTo(6) call data%state%manifold%Valve(91)%AdjacentTo(9) call data%state%manifold%Valve(91)%AdjacentTo(75) call data%state%manifold%Valve(92)%AdjacentTo(6) call data%state%manifold%Valve(92)%AdjacentTo(7) call data%state%manifold%Valve(92)%AdjacentTo(2) call data%state%manifold%Valve(93)%AdjacentTo(3) call data%state%manifold%Valve(93)%AdjacentTo(7) call data%state%manifold%Valve(93)%AdjacentTo(8) call data%state%manifold%Valve(94)%AdjacentTo(8) call data%state%manifold%Valve(94)%AdjacentTo(10) call data%state%manifold%Valve(94)%AdjacentTo(95) call data%state%manifold%Valve(95)%AdjacentTo(76) call data%state%manifold%Valve(95)%AdjacentTo(94) call data%state%manifold%Valve(96)%AdjacentTo(9) call data%state%manifold%Valve(96)%AdjacentTo(11) call data%state%manifold%Valve(96)%AdjacentTo(13) call data%state%manifold%Valve(97)%AdjacentTo(11) call data%state%manifold%Valve(97)%AdjacentTo(12) call data%state%manifold%Valve(97)%AdjacentTo(14) call data%state%manifold%Valve(98)%AdjacentTo(10) call data%state%manifold%Valve(98)%AdjacentTo(12) call data%state%manifold%Valve(98)%AdjacentTo(15) call data%state%manifold%Valve(99)%AdjacentTo(13) call data%state%manifold%Valve(99)%AdjacentTo(15) call data%state%manifold%Valve(99)%AdjacentTo(125) !call Valve(100)%AdjacentTo(16) call data%state%manifold%Valve(100)%AdjacentTo(82) call data%state%manifold%Valve(100)%AdjacentTo(101) !call Valve(101)%AdjacentTo(17) call data%state%manifold%Valve(101)%AdjacentTo(19) call data%state%manifold%Valve(101)%AdjacentTo(83) call data%state%manifold%Valve(101)%AdjacentTo(100) !call Valve(102)%AdjacentTo(18) call data%state%manifold%Valve(102)%AdjacentTo(19) call data%state%manifold%Valve(102)%AdjacentTo(84) !call Valve(103)%AdjacentTo(53) !call Valve(103)%AdjacentTo(56) call data%state%manifold%Valve(103)%AdjacentTo(124) !call Valve(103)%AdjacentTo(56) !call Valve(103)%AdjacentTo(78) call data%state%manifold%Valve(104)%AdjacentTo(46) call data%state%manifold%Valve(104)%AdjacentTo(47) call data%state%manifold%Valve(104)%AdjacentTo(49) call data%state%manifold%Valve(104)%AdjacentTo(50) !call Valve(105)%AdjacentTo(53) !call Valve(105)%AdjacentTo(107) !call Valve(105)%AdjacentTo(127) call data%state%manifold%Valve(106)%AdjacentTo(40) call data%state%manifold%Valve(106)%AdjacentTo(45) call data%state%manifold%Valve(107)%AdjacentTo(41) !call Valve(107)%AdjacentTo(105) call data%state%manifold%Valve(107)%AdjacentTo(119) !call Valve(107)%AdjacentTo(42) call data%state%manifold%Valve(108)%AdjacentTo(25) call data%state%manifold%Valve(108)%AdjacentTo(27) call data%state%manifold%Valve(108)%AdjacentTo(28) call data%state%manifold%Valve(108)%AdjacentTo(110) call data%state%manifold%Valve(109)%AdjacentTo(26) call data%state%manifold%Valve(109)%AdjacentTo(30) call data%state%manifold%Valve(109)%AdjacentTo(31) call data%state%manifold%Valve(109)%AdjacentTo(110) call data%state%manifold%Valve(110)%AdjacentTo(29) call data%state%manifold%Valve(110)%AdjacentTo(85) call data%state%manifold%Valve(110)%AdjacentTo(108) call data%state%manifold%Valve(110)%AdjacentTo(109) call data%state%manifold%Valve(111)%AdjacentTo(37) call data%state%manifold%Valve(111)%AdjacentTo(64) call data%state%manifold%Valve(111)%AdjacentTo(112) call data%state%manifold%Valve(112)%AdjacentTo(63) call data%state%manifold%Valve(112)%AdjacentTo(111) call data%state%manifold%Valve(112)%AdjacentTo(113) call data%state%manifold%Valve(113)%AdjacentTo(29) call data%state%manifold%Valve(113)%AdjacentTo(112) call data%state%manifold%Valve(113)%AdjacentTo(114) call data%state%manifold%Valve(114)%AdjacentTo(62) call data%state%manifold%Valve(114)%AdjacentTo(113) call data%state%manifold%Valve(114)%AdjacentTo(115) call data%state%manifold%Valve(115)%AdjacentTo(36) call data%state%manifold%Valve(115)%AdjacentTo(61) call data%state%manifold%Valve(115)%AdjacentTo(114) call data%state%manifold%Valve(116)%AdjacentTo(38) call data%state%manifold%Valve(116)%AdjacentTo(39) call data%state%manifold%Valve(117)%AdjacentTo(2) call data%state%manifold%Valve(117)%AdjacentTo(26) call data%state%manifold%Valve(117)%AdjacentTo(47) call data%state%manifold%Valve(118)%AdjacentTo(3) call data%state%manifold%Valve(118)%AdjacentTo(25) call data%state%manifold%Valve(118)%AdjacentTo(46) call data%state%manifold%Valve(119)%AdjacentTo(42) call data%state%manifold%Valve(119)%AdjacentTo(60) call data%state%manifold%Valve(119)%AdjacentTo(107) call data%state%manifold%Valve(120)%AdjacentTo(71) !call Valve(121)%AdjacentTo(16) call data%state%manifold%Valve(121)%AdjacentTo(1) call data%state%manifold%Valve(121)%AdjacentTo(65) !call Valve(122)%AdjacentTo(17) call data%state%manifold%Valve(122)%AdjacentTo(4) call data%state%manifold%Valve(122)%AdjacentTo(66) !call Valve(123)%AdjacentTo(18) call data%state%manifold%Valve(123)%AdjacentTo(5) call data%state%manifold%Valve(123)%AdjacentTo(67) !call Valve(124)%AdjacentTo(54) !call Valve(124)%AdjacentTo(55) call data%state%manifold%Valve(124)%AdjacentTo(69) call data%state%manifold%Valve(124)%AdjacentTo(103) call data%state%manifold%Valve(125)%AdjacentTo(68) call data%state%manifold%Valve(125)%AdjacentTo(99) ! call Valve(125)%AdjacentTo(126) call data%state%manifold%Valve(126)%AdjacentTo(128) call data%state%manifold%Valve(126)%AdjacentTo(68) !call Valve(126)%AdjacentTo(125) call data%state%manifold%Valve(127)%AdjacentTo(56) call data%state%manifold%Valve(127)%AdjacentTo(78) !call Valve(127)%AdjacentTo(105) call data%state%manifold%Valve(128)%AdjacentTo(56) call data%state%manifold%Valve(128)%AdjacentTo(126) ! initialization call ChangeValve(60, .true.) call RemoveIBop() call ToggleFillupHead(.false.) call ToggleMudBox(.false.) call RemoveTopDriveIBop() call InstallSafetyValve_KellyMode() call KellyDisconnected() end subroutine subroutine KellyConnected() !Bind(C,name='KellyConnected') implicit none call data%state%manifold%Valve(127)%RemoveAdjacent(78) call data%state%manifold%Valve(127)%AdjacentTo(103) call data%state%manifold%Valve(103)%AdjacentTo(127) if(print_log) print*, 'KellyConnected()' data%state%manifold%IsPathsDirty = .true. end subroutine subroutine KellyDisconnected() !Bind(C,name='KellyDisconnected') implicit none call data%state%manifold%Valve(127)%RemoveAdjacent(103) call data%state%manifold%Valve(103)%RemoveAdjacent(127) call data%state%manifold%Valve(127)%AdjacentTo(78) if(print_log) print*, 'KellyDisconnected()' data%state%manifold%IsPathsDirty = .true. end subroutine subroutine InstallSafetyValve_KellyMode() implicit none data%state%manifold%IsSafetyValveInstalled_KellyMode = .true. call RemoveTopDriveIBop() ! Remove Safey Valve (54) call data%state%manifold%Valve(124)%RemoveAdjacent(54) call data%state%manifold%Valve(54)%RemoveAdjacent(124) call data%state%manifold%Valve(69)%RemoveAdjacent(54) call data%state%manifold%Valve(54)%RemoveAdjacent(69) ! Remove 126-103 cnn call data%state%manifold%Valve(128)%RemoveAdjacent(127) call data%state%manifold%Valve(127)%RemoveAdjacent(128) ! now make cnn call data%state%manifold%Valve(124)%AdjacentTo(69) call data%state%manifold%Valve(69)%AdjacentTo(124) call data%state%manifold%Valve(128)%AdjacentTo(56) call data%state%manifold%Valve(56)%AdjacentTo(128) call data%state%manifold%Valve(56)%AdjacentTo(127) call data%state%manifold%Valve(127)%AdjacentTo(56) # 713 data%Equipments%DrillingConsole%IRSafetyValveLed = 1 call OpenSafetyValve_KellyMode() end subroutine subroutine RemoveSafetyValve_KellyMode() implicit none data%state%manifold%IsSafetyValveInstalled_KellyMode = .false. call data%state%manifold%Valve(128)%RemoveAdjacent(56) call data%state%manifold%Valve(56)%RemoveAdjacent(128) call data%state%manifold%Valve(127)%RemoveAdjacent(56) call data%state%manifold%Valve(56)%RemoveAdjacent(127) call data%state%manifold%Valve(127)%AdjacentTo(128) call data%state%manifold%Valve(128)%AdjacentTo(127) data%Equipments%DrillingConsole%IRSafetyValveLed = 0 call CloseSafetyValve_KellyMode() data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 # 739 end subroutine subroutine OpenSafetyValve_KellyMode() implicit none if(.not.data%state%manifold%IsSafetyValveInstalled_KellyMode) return data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 data%state%manifold%SafetyValve = .true. call ChangeValve(56, data%state%manifold%SafetyValve) # 753 end subroutine subroutine CloseSafetyValve_KellyMode() implicit none if(.not.data%state%manifold%IsSafetyValveInstalled_KellyMode) return data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 data%state%manifold%SafetyValve = .false. call ChangeValve(56, data%state%manifold%SafetyValve) # 767 end subroutine subroutine InstallSafetyValve_TripMode() implicit none data%state%manifold%IsSafetyValveInstalled_TripMode = .true. call data%state%manifold%Valve(128)%RemoveAdjacent(56) call data%state%manifold%Valve(56)%RemoveAdjacent(128) call data%state%manifold%Valve(127)%RemoveAdjacent(56) call data%state%manifold%Valve(56)%RemoveAdjacent(127) call data%state%manifold%Valve(69)%RemoveAdjacent(124) call data%state%manifold%Valve(124)%RemoveAdjacent(69) call data%state%manifold%Valve(127)%AdjacentTo(128) call data%state%manifold%Valve(128)%AdjacentTo(127) call data%state%manifold%Valve(124)%AdjacentTo(54) call data%state%manifold%Valve(54)%AdjacentTo(124) call data%state%manifold%Valve(54)%AdjacentTo(69) call data%state%manifold%Valve(69)%AdjacentTo(54) data%Equipments%DrillingConsole%IRSafetyValveLed = 1 call OpenSafetyValve_TripMode() # 808 end subroutine subroutine RemoveSafetyValve_TripMode() implicit none data%state%manifold%IsSafetyValveInstalled_TripMode = .false. call data%state%manifold%Valve(124)%RemoveAdjacent(54) call data%state%manifold%Valve(54)%RemoveAdjacent(124) call data%state%manifold%Valve(54)%RemoveAdjacent(69) call data%state%manifold%Valve(69)%RemoveAdjacent(54) call data%state%manifold%Valve(124)%AdjacentTo(69) call data%state%manifold%Valve(69)%AdjacentTo(124) data%Equipments%DrillingConsole%IRSafetyValveLed = 0 call CloseSafetyValve_TripMode() data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 if(print_log) print*, 'RemoveSafetyValve_TripMode()' end subroutine subroutine OpenSafetyValve_TripMode() implicit none if(.not.data%state%manifold%IsSafetyValveInstalled_TripMode) return data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 data%state%manifold%SafetyValve = .true. call ChangeValve(54, data%state%manifold%SafetyValve) # 842 end subroutine subroutine CloseSafetyValve_TripMode() implicit none if(.not.data%state%manifold%IsSafetyValveInstalled_TripMode) return data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 data%state%manifold%SafetyValve = .false. call ChangeValve(54, data%state%manifold%SafetyValve) # 856 end subroutine subroutine InstallSafetyValve_TopDrive() implicit none data%state%manifold%IsSafetyValveInstalled_TopDrive = .true. call data%state%manifold%Valve(128)%RemoveAdjacent(56) call data%state%manifold%Valve(56)%RemoveAdjacent(128) call data%state%manifold%Valve(127)%RemoveAdjacent(56) call data%state%manifold%Valve(56)%RemoveAdjacent(127) call data%state%manifold%Valve(69)%RemoveAdjacent(124) call data%state%manifold%Valve(124)%RemoveAdjacent(69) call data%state%manifold%Valve(124)%AdjacentTo(54) call data%state%manifold%Valve(54)%AdjacentTo(124) call data%state%manifold%Valve(54)%AdjacentTo(69) call data%state%manifold%Valve(69)%AdjacentTo(54) data%Equipments%DrillingConsole%IRSafetyValveLed = 1 call OpenSafetyValve_TopDrive() # 891 end subroutine subroutine RemoveSafetyValve_TopDrive() implicit none data%state%manifold%IsSafetyValveInstalled_TopDrive = .false. call data%state%manifold%Valve(124)%RemoveAdjacent(54) call data%state%manifold%Valve(54)%RemoveAdjacent(124) call data%state%manifold%Valve(54)%RemoveAdjacent(69) call data%state%manifold%Valve(69)%RemoveAdjacent(54) call data%state%manifold%Valve(124)%AdjacentTo(69) call data%state%manifold%Valve(69)%AdjacentTo(124) data%Equipments%DrillingConsole%IRSafetyValveLed = 0 call CloseSafetyValve_TopDrive() data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 # 915 end subroutine subroutine OpenSafetyValve_TopDrive() implicit none if(.not.data%state%manifold%IsSafetyValveInstalled_TopDrive) return data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 data%state%manifold%SafetyValve = .true. # 928 call ChangeValve(54, data%state%manifold%SafetyValve) end subroutine subroutine CloseSafetyValve_TopDrive() implicit none if(.not.data%state%manifold%IsSafetyValveInstalled_TopDrive) return data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 data%state%manifold%SafetyValve = .false. # 942 call ChangeValve(54, data%state%manifold%SafetyValve) end subroutine subroutine InstallIBop() implicit none data%state%manifold%IsIBopInstalled = .true. call data%state%manifold%Valve(103)%RemoveAdjacent(124) call data%state%manifold%Valve(124)%RemoveAdjacent(103) call data%state%manifold%Valve(55)%AdjacentTo(103) call data%state%manifold%Valve(55)%AdjacentTo(124) call data%state%manifold%Valve(103)%AdjacentTo(55) call data%state%manifold%Valve(124)%AdjacentTo(55) # 970 data%Equipments%DrillingConsole%IRIBopLed = 1 call OpenIBop() end subroutine subroutine RemoveIBop() implicit none data%state%manifold%IsIBopInstalled = .false. call data%state%manifold%Valve(55)%RemoveAdjacent(103) call data%state%manifold%Valve(55)%RemoveAdjacent(124) call data%state%manifold%Valve(103)%RemoveAdjacent(55) call data%state%manifold%Valve(124)%RemoveAdjacent(55) call data%state%manifold%Valve(103)%AdjacentTo(124) call data%state%manifold%Valve(124)%AdjacentTo(103) # 991 data%Equipments%DrillingConsole%IRIBopLed = 0 data%state%manifold%IBop = .false. call ChangeValve(55, data%state%manifold%IBop) end subroutine subroutine OpenIBop() implicit none if(.not.data%state%manifold%IsIBopInstalled) return data%state%manifold%IBop = .true. # 1005 call ChangeValve(55, data%state%manifold%IBop) end subroutine subroutine CloseIBop() implicit none if(.not.data%state%manifold%IsIBopInstalled) return data%state%manifold%IBop = .false. # 1017 call ChangeValve(55, data%state%manifold%IBop) end subroutine subroutine InstallKellyCock() implicit none data%state%manifold%IsKellyCockInstalled = .true. call data%state%manifold%Valve(125)%RemoveAdjacent(126) call data%state%manifold%Valve(126)%RemoveAdjacent(125) call data%state%manifold%Valve(125)%AdjacentTo(68) call data%state%manifold%Valve(68)%AdjacentTo(125) call data%state%manifold%Valve(68)%AdjacentTo(126) call data%state%manifold%Valve(126)%AdjacentTo(68) # 1043 call OpenKellyCock() end subroutine subroutine RemoveKellyCock() implicit none data%state%manifold%IsKellyCockInstalled = .false. call data%state%manifold%Valve(125)%RemoveAdjacent(68) call data%state%manifold%Valve(126)%RemoveAdjacent(68) call data%state%manifold%Valve(68)%RemoveAdjacent(125) call data%state%manifold%Valve(68)%RemoveAdjacent(126) call data%state%manifold%Valve(125)%AdjacentTo(126) call data%state%manifold%Valve(126)%AdjacentTo(125) data%state%manifold%KellyCock = .false. call ChangeValve(68, data%state%manifold%KellyCock) data%Equipments%DrillingConsole%CloseKellyCockLed = 0 data%Equipments%DrillingConsole%OpenKellyCockLed = 0 # 1068 end subroutine subroutine OpenKellyCock() implicit none if(.not.data%state%manifold%IsKellyCockInstalled) return data%Equipments%DrillingConsole%OpenKellyCockLed = 1 data%Equipments%DrillingConsole%CloseKellyCockLed = 0 data%state%manifold%KellyCock = .true. # 1081 call ChangeValve(68, data%state%manifold%KellyCock) end subroutine subroutine CloseKellyCock() implicit none if(.not.data%state%manifold%IsKellyCockInstalled) return data%Equipments%DrillingConsole%CloseKellyCockLed = 1 data%Equipments%DrillingConsole%OpenKellyCockLed = 0 data%state%manifold%KellyCock = .false. # 1095 call ChangeValve(68, data%state%manifold%KellyCock) end subroutine subroutine InstallTopDriveIBop() implicit none data%state%manifold%IsTopDriveIBopInstalled = .true. call data%state%manifold%Valve(126)%RemoveAdjacent(128) call data%state%manifold%Valve(128)%RemoveAdjacent(126) call data%state%manifold%Valve(126)%AdjacentTo(70) call data%state%manifold%Valve(70)%AdjacentTo(126) call data%state%manifold%Valve(128)%AdjacentTo(70) call data%state%manifold%Valve(70)%AdjacentTo(128) # 1123 call OpenTopDriveIBop() end subroutine subroutine RemoveTopDriveIBop() implicit none data%state%manifold%IsTopDriveIBopInstalled = .false. call data%state%manifold%Valve(126)%RemoveAdjacent(70) call data%state%manifold%Valve(70)%RemoveAdjacent(126) call data%state%manifold%Valve(128)%RemoveAdjacent(70) call data%state%manifold%Valve(70)%RemoveAdjacent(128) call data%state%manifold%Valve(126)%AdjacentTo(128) call data%state%manifold%Valve(128)%AdjacentTo(126) # 1142 data%state%manifold%TopDriveIBop = .false. call ChangeValve(70, data%state%manifold%TopDriveIBop) end subroutine subroutine OpenTopDriveIBop() implicit none if(.not.data%state%manifold%IsTopDriveIBopInstalled) return data%state%manifold%TopDriveIBop = .true. call ChangeValve(70, data%state%manifold%TopDriveIBop) # 1154 end subroutine subroutine CloseTopDriveIBop() implicit none if(.not.data%state%manifold%IsTopDriveIBopInstalled) return data%state%manifold%TopDriveIBop = .false. call ChangeValve(70, data%state%manifold%TopDriveIBop) # 1164 end subroutine subroutine InstallFloatValve() implicit none data%state%manifold%IsFloatValveInstalled = .true. call data%state%manifold%Valve(69)%RemoveAdjacent(79) call data%state%manifold%Valve(79)%RemoveAdjacent(69) call data%state%manifold%Valve(48)%AdjacentTo(69) call data%state%manifold%Valve(48)%AdjacentTo(79) call data%state%manifold%Valve(69)%AdjacentTo(48) call data%state%manifold%Valve(79)%AdjacentTo(48) # 1189 call OpenFloatValve() end subroutine subroutine RemoveFloatValve() implicit none data%state%manifold%IsFloatValveInstalled = .false. call data%state%manifold%Valve(48)%RemoveAdjacent(69) call data%state%manifold%Valve(48)%RemoveAdjacent(79) call data%state%manifold%Valve(69)%RemoveAdjacent(48) call data%state%manifold%Valve(79)%RemoveAdjacent(48) call data%state%manifold%Valve(69)%AdjacentTo(79) call data%state%manifold%Valve(79)%AdjacentTo(69) # 1207 data%state%manifold%FloatValve = .false. call ChangeValve(48, data%state%manifold%FloatValve) end subroutine subroutine OpenFloatValve() implicit none if(.not.data%state%manifold%IsFloatValveInstalled) return data%state%manifold%FloatValve = .true. # 1218 call ChangeValve(48, data%state%manifold%FloatValve) end subroutine subroutine CloseFloatValve() implicit none if(.not.data%state%manifold%IsFloatValveInstalled) return data%state%manifold%FloatValve = .false. # 1228 call ChangeValve(48, data%state%manifold%FloatValve) end subroutine subroutine ToggleFillupHead(v) implicit none logical, intent(in) :: v if(v) then call data%state%manifold%Valve(14)%RemoveAdjacent(78) call data%state%manifold%Valve(14)%AdjacentTo(57) call data%state%manifold%Valve(57)%AdjacentTo(14) call data%state%manifold%Valve(57)%AdjacentTo(103) call data%state%manifold%Valve(103)%AdjacentTo(57) else call data%state%manifold%Valve(14)%RemoveAdjacent(57) call data%state%manifold%Valve(57)%RemoveAdjacent(14) call data%state%manifold%Valve(57)%RemoveAdjacent(103) call data%state%manifold%Valve(103)%RemoveAdjacent(57) call data%state%manifold%Valve(14)%AdjacentTo(78) endif data%state%manifold%IsPathsDirty = .true. call ChangeValve(57, .true.) end subroutine subroutine ToggleMudBox(v) implicit none logical, intent(in) :: v call ChangeValve(53, v) end subroutine subroutine ToggleMiddleRams(v) implicit none logical, intent(in) :: v data%state%manifold%Valve(50)%Status = v call ChangeValve(69, v) end subroutine subroutine ToggleValve(i) bind(C,name="ToggleValve") integer :: i logical :: currentStatus currentStatus = data%State%Manifold%Valve(i)%Status call ChangeValve(i,.not. currentStatus) end subroutine subroutine ChangeValve(i, state) implicit none integer, intent(in) :: i logical, intent(in) :: state if(data%state%manifold%Valve(i)%Status==state) return data%state%manifold%Valve(i)%Status = state if(i == 41 .or. i == 42) then if(data%state%manifold%Valve(41)%Status == .false. .and. data%state%manifold%Valve(42)%Status == .false.) then data%state%manifold%Valve(60)%Status = .true. else data%state%manifold%Valve(60)%Status = .false. endif endif # 1297 !call Traverse() data%state%manifold%IsPathsDirty = .true. end subroutine subroutine DisplayOpenPaths() implicit none integer :: i if(allocated(data%state%manifold%OpenPaths)) then do i = 1, size(data%state%manifold%OpenPaths) call data%state%manifold%OpenPaths(i)%Display() end do end if end subroutine subroutine DisplayOpenPathsWrite() implicit none integer :: i if(allocated(data%state%manifold%OpenPaths)) then do i = 1, size(data%state%manifold%OpenPaths) call data%state%manifold%OpenPaths(i)%DisplayWrite() end do end if end subroutine end module CManifolds