module CManifolds use CStack use CArrangement use CPathChangeEvents use CDrillingConsoleVariables, only: IRSafetyValveLed, IRIBopLed, OpenKellyCockLed, CloseKellyCockLed, OpenSafetyValveLed, CloseSafetyValveLed implicit none public integer, parameter :: ValveCount = 128 integer, parameter :: MinSource = 71 integer, parameter :: MaxSource = 90 integer, parameter :: MinRelation = 91 integer, parameter :: MaxRelation = 128 type(Arrangement) :: Valve(ValveCount) type(Path), allocatable :: OpenPaths(:) type(Stack) :: Fringe logical :: IsRepititveOutput logical :: IsSafetyValveInstalled logical :: IsSafetyValveInstalled_KellyMode logical :: IsSafetyValveInstalled_TripMode logical :: IsSafetyValveInstalled_TopDrive logical :: SafetyValve logical :: IsIBopInstalled logical :: IBop logical :: IsKellyCockInstalled logical :: KellyCock logical :: IsTopDriveIBopInstalled logical :: TopDriveIBop logical :: IsFloatValveInstalled logical :: FloatValve logical :: IsPathsDirty = .false. logical :: IsTraverse = .false. contains subroutine PathFinding_Setup() use CSimulationVariables implicit none IsTraverse = .false. call Setup() !call OnSimulationInitialization%Add(PathFinding_Init) !call OnSimulationStop%Add(PathFinding_Init) !call OnPathFindingStep%Add(PathFinding_Step) !call OnPathFindingOutput%Add(PathFinding_Output) call OnPathFindingMain%Add(PathFindingMainBody) end subroutine subroutine PathFinding_Init implicit none IsTraverse = .false. call Setup() end subroutine PathFinding_Init subroutine PathFinding_Step implicit none 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 (IsPathsDirty) then IsPathsDirty = .false. call Traverse() endif end do loop end subroutine PathFindingMainBody subroutine Traverse() use CLog5 implicit none integer :: i, Duration integer, dimension(8) :: StartTime,EndTime !TODO: clean up call DATE_AND_TIME(values=StartTime) !TODO: clean up call BeforeTraverse%RunAll() if(allocated(OpenPaths)) deallocate(OpenPaths) do i=MinSource, MaxSource if(IsValveOpen(i)) then call AddRootNode(i) call AddChildren(Valve(i)) endif enddo call PostProcess(OpenPaths) call AfterTraverse%RunAll() IsTraverse = .true. !TODO: clean up #ifdef Log5 CALL DATE_AND_TIME(values=EndTime) Duration= EndTime(8) - StartTime(8) !print*, 'Duration= ', Duration, 'ms' call Log_5('Duration= ', Duration) call DisplayOpenPaths() call Log_5('==========================================') #endif endsubroutine 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 subroutine AddRootNode(valve) implicit none integer, intent(in) :: valve call Fringe%Push(valve) end subroutine recursive subroutine AddChildren(node) implicit none type(Arrangement), intent(inout) :: node integer :: i,t do i=1, Valve(node%Number)%Length() t = Valve(node%Number)%Adjacent(i) if(IsValveOpen(t)) then if(Fringe%DoesHave(t)) cycle call Fringe%Push(t) if(Valve(t)%IsSource()) then call AddPath(OpenPaths, Fringe%List) call Fringe%Pop() cycle endif call AddChildren(Valve(node%Adjacent(i))) end if enddo call Fringe%Pop() end subroutine logical function IsValveOpen(no) implicit none integer, intent(in) :: no IsValveOpen = 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 OnPathOpen%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 OnPathClose%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 Valve(i)%init(i) end do ! open source valves do i = MinSource , MaxSource Valve(i)%Status = .true. Valve(i)%ValveType = InputOutput end do do i = MinRelation , MaxRelation Valve(i)%Status = .true. Valve(i)%ValveType = Relation end do ! make adjustments call Valve(1)%AdjacentTo(91) call Valve(2)%AdjacentTo(92) call Valve(2)%AdjacentTo(117) call Valve(3)%AdjacentTo(93) call Valve(3)%AdjacentTo(118) call Valve(4)%AdjacentTo(94) call Valve(5)%AdjacentTo(95) call Valve(6)%AdjacentTo(91) call Valve(6)%AdjacentTo(92) call Valve(7)%AdjacentTo(92) call Valve(7)%AdjacentTo(93) call Valve(8)%AdjacentTo(93) call Valve(8)%AdjacentTo(94) call Valve(9)%AdjacentTo(91) call Valve(9)%AdjacentTo(96) call Valve(10)%AdjacentTo(94) call Valve(10)%AdjacentTo(98) call Valve(11)%AdjacentTo(96) call Valve(11)%AdjacentTo(97) call Valve(12)%AdjacentTo(97) call Valve(12)%AdjacentTo(98) call Valve(13)%AdjacentTo(96) call Valve(13)%AdjacentTo(99) call Valve(14)%AdjacentTo(78) call Valve(14)%AdjacentTo(97) !call Valve(14)%AdjacentTo(126) call Valve(15)%AdjacentTo(98) call Valve(15)%AdjacentTo(99) call Valve(16)%AdjacentTo(121) !call Valve(16)%AdjacentTo() call Valve(17)%AdjacentTo(122) !call Valve(17)%AdjacentTo() call Valve(18)%AdjacentTo(123) !call Valve(18)%AdjacentTo() call Valve(19)%AdjacentTo(101) call Valve(19)%AdjacentTo(102) call Valve(20)%AdjacentTo(100) call Valve(21)%AdjacentTo(101) call Valve(22)%AdjacentTo(102) call Valve(23)%AdjacentTo(71) call Valve(24)%AdjacentTo(71) call Valve(25)%AdjacentTo(108) call Valve(25)%AdjacentTo(118) call Valve(26)%AdjacentTo(109) call Valve(26)%AdjacentTo(117) call Valve(27)%AdjacentTo(32) call Valve(27)%AdjacentTo(108) call Valve(28)%AdjacentTo(33) call Valve(28)%AdjacentTo(108) call Valve(29)%AdjacentTo(110) call Valve(29)%AdjacentTo(113) call Valve(30)%AdjacentTo(34) call Valve(30)%AdjacentTo(109) call Valve(31)%AdjacentTo(35) call Valve(31)%AdjacentTo(109) call Valve(32)%AdjacentTo(27) call Valve(32)%AdjacentTo(61) call Valve(33)%AdjacentTo(28) call Valve(33)%AdjacentTo(62) call Valve(34)%AdjacentTo(30) call Valve(34)%AdjacentTo(63) call Valve(35)%AdjacentTo(31) call Valve(35)%AdjacentTo(64) call Valve(36)%AdjacentTo(116) call Valve(37)%AdjacentTo(78) call Valve(38)%AdjacentTo(71) call Valve(39)%AdjacentTo(77) !call Valve(40)%AdjacentTo(105) call Valve(40)%AdjacentTo(80) call Valve(41)%AdjacentTo(77) call Valve(42)%AdjacentTo(71) call Valve(43)%AdjacentTo(106) call Valve(44)%AdjacentTo(77) call Valve(45)%AdjacentTo(71) call Valve(46)%AdjacentTo(104) call Valve(47)%AdjacentTo(104) call Valve(47)%AdjacentTo(117) call Valve(48)%AdjacentTo(69) call Valve(48)%AdjacentTo(79) call Valve(49)%AdjacentTo(104) call Valve(49)%AdjacentTo(79) !call Valve(50)%AdjacentTo(48) call Valve(50)%AdjacentTo(51) !call Valve(50)%AdjacentTo(54) call Valve(50)%AdjacentTo(104) call Valve(51)%AdjacentTo(50) call Valve(51)%AdjacentTo(52) call Valve(52)%AdjacentTo(51) !call Valve(52)%AdjacentTo(127) call Valve(52)%AdjacentTo(80) !call Valve(53)%AdjacentTo(103) !call Valve(53)%AdjacentTo(105) call 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 Valve(56)%AdjacentTo(128) call Valve(56)%AdjacentTo(127) !call Valve(57)%AdjacentTo(14) !call Valve(57)%AdjacentTo(103) !call Valve(57)%AdjacentTo(126) call Valve(58)%AdjacentTo(78) call Valve(59)%AdjacentTo(78) call Valve(60)%AdjacentTo(78) call Valve(61)%AdjacentTo(32) call Valve(61)%AdjacentTo(115) call Valve(62)%AdjacentTo(33) call Valve(62)%AdjacentTo(114) call Valve(63)%AdjacentTo(112) call Valve(63)%AdjacentTo(34) call Valve(64)%AdjacentTo(35) call Valve(64)%AdjacentTo(111) call Valve(65)%AdjacentTo(120) call Valve(66)%AdjacentTo(120) call Valve(67)%AdjacentTo(73) call Valve(68)%AdjacentTo(125) call Valve(68)%AdjacentTo(126) call Valve(69)%AdjacentTo(48) call Valve(69)%AdjacentTo(124) !call Valve(70)%AdjacentTo() !call Valve(70)%AdjacentTo() call Valve(71)%AdjacentTo(20) call Valve(71)%AdjacentTo(44) call Valve(71)%AdjacentTo(59) call Valve(72)%AdjacentTo(21) call Valve(72)%AdjacentTo(23) call Valve(73)%AdjacentTo(22) call Valve(74)%AdjacentTo(24) !call Valve(75)%AdjacentTo() !call Valve(76)%AdjacentTo() call Valve(77)%AdjacentTo(43) call Valve(77)%AdjacentTo(58) !call Valve(78)%AdjacentTo() call Valve(79)%AdjacentTo(48) call Valve(79)%AdjacentTo(49) call Valve(80)%AdjacentTo(52) call Valve(80)%AdjacentTo(107) call Valve(81)%AdjacentTo(53) call Valve(82)%AdjacentTo(16) call Valve(83)%AdjacentTo(17) call 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 Valve(91)%AdjacentTo(6) call Valve(91)%AdjacentTo(9) call Valve(91)%AdjacentTo(75) call Valve(92)%AdjacentTo(6) call Valve(92)%AdjacentTo(7) call Valve(92)%AdjacentTo(2) call Valve(93)%AdjacentTo(3) call Valve(93)%AdjacentTo(7) call Valve(93)%AdjacentTo(8) call Valve(94)%AdjacentTo(8) call Valve(94)%AdjacentTo(10) call Valve(94)%AdjacentTo(95) call Valve(95)%AdjacentTo(76) call Valve(95)%AdjacentTo(94) call Valve(96)%AdjacentTo(9) call Valve(96)%AdjacentTo(11) call Valve(96)%AdjacentTo(13) call Valve(97)%AdjacentTo(11) call Valve(97)%AdjacentTo(12) call Valve(97)%AdjacentTo(14) call Valve(98)%AdjacentTo(10) call Valve(98)%AdjacentTo(12) call Valve(98)%AdjacentTo(15) call Valve(99)%AdjacentTo(13) call Valve(99)%AdjacentTo(15) call Valve(99)%AdjacentTo(125) !call Valve(100)%AdjacentTo(16) call Valve(100)%AdjacentTo(82) call Valve(100)%AdjacentTo(101) !call Valve(101)%AdjacentTo(17) call Valve(101)%AdjacentTo(19) call Valve(101)%AdjacentTo(83) call Valve(101)%AdjacentTo(100) !call Valve(102)%AdjacentTo(18) call Valve(102)%AdjacentTo(19) call Valve(102)%AdjacentTo(84) !call Valve(103)%AdjacentTo(53) !call Valve(103)%AdjacentTo(56) call Valve(103)%AdjacentTo(124) !call Valve(103)%AdjacentTo(56) !call Valve(103)%AdjacentTo(78) call Valve(104)%AdjacentTo(46) call Valve(104)%AdjacentTo(47) call Valve(104)%AdjacentTo(49) call Valve(104)%AdjacentTo(50) !call Valve(105)%AdjacentTo(53) !call Valve(105)%AdjacentTo(107) !call Valve(105)%AdjacentTo(127) call Valve(106)%AdjacentTo(40) call Valve(106)%AdjacentTo(45) call Valve(107)%AdjacentTo(41) !call Valve(107)%AdjacentTo(105) call Valve(107)%AdjacentTo(119) !call Valve(107)%AdjacentTo(42) call Valve(108)%AdjacentTo(25) call Valve(108)%AdjacentTo(27) call Valve(108)%AdjacentTo(28) call Valve(108)%AdjacentTo(110) call Valve(109)%AdjacentTo(26) call Valve(109)%AdjacentTo(30) call Valve(109)%AdjacentTo(31) call Valve(109)%AdjacentTo(110) call Valve(110)%AdjacentTo(29) call Valve(110)%AdjacentTo(85) call Valve(110)%AdjacentTo(108) call Valve(110)%AdjacentTo(109) call Valve(111)%AdjacentTo(37) call Valve(111)%AdjacentTo(64) call Valve(111)%AdjacentTo(112) call Valve(112)%AdjacentTo(63) call Valve(112)%AdjacentTo(111) call Valve(112)%AdjacentTo(113) call Valve(113)%AdjacentTo(29) call Valve(113)%AdjacentTo(112) call Valve(113)%AdjacentTo(114) call Valve(114)%AdjacentTo(62) call Valve(114)%AdjacentTo(113) call Valve(114)%AdjacentTo(115) call Valve(115)%AdjacentTo(36) call Valve(115)%AdjacentTo(61) call Valve(115)%AdjacentTo(114) call Valve(116)%AdjacentTo(38) call Valve(116)%AdjacentTo(39) call Valve(117)%AdjacentTo(2) call Valve(117)%AdjacentTo(26) call Valve(117)%AdjacentTo(47) call Valve(118)%AdjacentTo(3) call Valve(118)%AdjacentTo(25) call Valve(118)%AdjacentTo(46) call Valve(119)%AdjacentTo(42) call Valve(119)%AdjacentTo(60) call Valve(119)%AdjacentTo(107) call Valve(120)%AdjacentTo(71) !call Valve(121)%AdjacentTo(16) call Valve(121)%AdjacentTo(1) call Valve(121)%AdjacentTo(65) !call Valve(122)%AdjacentTo(17) call Valve(122)%AdjacentTo(4) call Valve(122)%AdjacentTo(66) !call Valve(123)%AdjacentTo(18) call Valve(123)%AdjacentTo(5) call Valve(123)%AdjacentTo(67) !call Valve(124)%AdjacentTo(54) !call Valve(124)%AdjacentTo(55) call Valve(124)%AdjacentTo(69) call Valve(124)%AdjacentTo(103) call Valve(125)%AdjacentTo(68) call Valve(125)%AdjacentTo(99) ! call Valve(125)%AdjacentTo(126) call Valve(126)%AdjacentTo(128) call Valve(126)%AdjacentTo(68) !call Valve(126)%AdjacentTo(125) call Valve(127)%AdjacentTo(56) call Valve(127)%AdjacentTo(78) !call Valve(127)%AdjacentTo(105) call Valve(128)%AdjacentTo(56) call 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() !use CLog3 implicit none call Valve(127)%RemoveAdjacent(78) call Valve(127)%AdjacentTo(103) call Valve(103)%AdjacentTo(127) #ifdef deb print*, 'KellyConnected()' !call Log_3( 'KellyConnected()') #endif IsPathsDirty = .true. end subroutine subroutine KellyDisconnected() !use CLog3 implicit none call Valve(127)%RemoveAdjacent(103) call Valve(103)%RemoveAdjacent(127) call Valve(127)%AdjacentTo(78) #ifdef deb print*, 'KellyDisconnected()' !call Log_3( 'KellyDisconnected()') #endif IsPathsDirty = .true. end subroutine subroutine InstallSafetyValve_KellyMode() implicit none IsSafetyValveInstalled_KellyMode = .true. call RemoveTopDriveIBop() ! Remove Safey Valve (54) call Valve(124)%RemoveAdjacent(54) call Valve(54)%RemoveAdjacent(124) call Valve(69)%RemoveAdjacent(54) call Valve(54)%RemoveAdjacent(69) ! Remove 126-103 cnn call Valve(128)%RemoveAdjacent(127) call Valve(127)%RemoveAdjacent(128) ! now make cnn call Valve(124)%AdjacentTo(69) call Valve(69)%AdjacentTo(124) call Valve(128)%AdjacentTo(56) call Valve(56)%AdjacentTo(128) call Valve(56)%AdjacentTo(127) call Valve(127)%AdjacentTo(56) #ifdef deb print*, 'InstallSafetyValve_KellyMode()' #endif IRSafetyValveLed = 1 call OpenSafetyValve_KellyMode() end subroutine subroutine RemoveSafetyValve_KellyMode() implicit none IsSafetyValveInstalled_KellyMode = .false. call Valve(128)%RemoveAdjacent(56) call Valve(56)%RemoveAdjacent(128) call Valve(127)%RemoveAdjacent(56) call Valve(56)%RemoveAdjacent(127) call Valve(127)%AdjacentTo(128) call Valve(128)%AdjacentTo(127) IRSafetyValveLed = 0 call CloseSafetyValve_KellyMode() OpenSafetyValveLed = 0 CloseSafetyValveLed = 0 #ifdef deb print*, 'RemoveSafetyValve_KellyMode()' #endif end subroutine subroutine OpenSafetyValve_KellyMode() implicit none if(.not.IsSafetyValveInstalled_KellyMode) return OpenSafetyValveLed = 1 CloseSafetyValveLed = 0 SafetyValve = .true. call ChangeValve(56, SafetyValve) #ifdef deb print*, 'OpenSafetyValve_KellyMode()' #endif end subroutine subroutine CloseSafetyValve_KellyMode() implicit none if(.not.IsSafetyValveInstalled_KellyMode) return CloseSafetyValveLed = 1 OpenSafetyValveLed = 0 SafetyValve = .false. call ChangeValve(56, SafetyValve) #ifdef deb print*, 'CloseSafetyValve_KellyMode()' #endif end subroutine subroutine InstallSafetyValve_TripMode() implicit none IsSafetyValveInstalled_TripMode = .true. call Valve(128)%RemoveAdjacent(56) call Valve(56)%RemoveAdjacent(128) call Valve(127)%RemoveAdjacent(56) call Valve(56)%RemoveAdjacent(127) call Valve(69)%RemoveAdjacent(124) call Valve(124)%RemoveAdjacent(69) call Valve(127)%AdjacentTo(128) call Valve(128)%AdjacentTo(127) call Valve(124)%AdjacentTo(54) call Valve(54)%AdjacentTo(124) call Valve(54)%AdjacentTo(69) call Valve(69)%AdjacentTo(54) IRSafetyValveLed = 1 call OpenSafetyValve_TripMode() #ifdef deb print*, 'InstallSafetyValve_TripMode()' #endif end subroutine subroutine RemoveSafetyValve_TripMode() implicit none IsSafetyValveInstalled_TripMode = .false. call Valve(124)%RemoveAdjacent(54) call Valve(54)%RemoveAdjacent(124) call Valve(54)%RemoveAdjacent(69) call Valve(69)%RemoveAdjacent(54) call Valve(124)%AdjacentTo(69) call Valve(69)%AdjacentTo(124) IRSafetyValveLed = 0 call CloseSafetyValve_TripMode() OpenSafetyValveLed = 0 CloseSafetyValveLed = 0 #ifdef deb print*, 'RemoveSafetyValve_TripMode()' #endif end subroutine subroutine OpenSafetyValve_TripMode() implicit none if(.not.IsSafetyValveInstalled_TripMode) return OpenSafetyValveLed = 1 CloseSafetyValveLed = 0 SafetyValve = .true. call ChangeValve(54, SafetyValve) #ifdef deb print*, 'OpenSafetyValve_TripMode()' #endif end subroutine subroutine CloseSafetyValve_TripMode() implicit none if(.not.IsSafetyValveInstalled_TripMode) return CloseSafetyValveLed = 1 OpenSafetyValveLed = 0 SafetyValve = .false. call ChangeValve(54, SafetyValve) #ifdef deb print*, 'CloseSafetyValve_TripMode()' #endif end subroutine subroutine InstallSafetyValve_TopDrive() implicit none IsSafetyValveInstalled_TopDrive = .true. call Valve(128)%RemoveAdjacent(56) call Valve(56)%RemoveAdjacent(128) call Valve(127)%RemoveAdjacent(56) call Valve(56)%RemoveAdjacent(127) call Valve(69)%RemoveAdjacent(124) call Valve(124)%RemoveAdjacent(69) call Valve(124)%AdjacentTo(54) call Valve(54)%AdjacentTo(124) call Valve(54)%AdjacentTo(69) call Valve(69)%AdjacentTo(54) IRSafetyValveLed = 1 call OpenSafetyValve_TopDrive() #ifdef deb print*, 'InstallSafetyValve_TopDrive()' #endif end subroutine subroutine RemoveSafetyValve_TopDrive() implicit none IsSafetyValveInstalled_TopDrive = .false. call Valve(124)%RemoveAdjacent(54) call Valve(54)%RemoveAdjacent(124) call Valve(54)%RemoveAdjacent(69) call Valve(69)%RemoveAdjacent(54) call Valve(124)%AdjacentTo(69) call Valve(69)%AdjacentTo(124) IRSafetyValveLed = 0 call CloseSafetyValve_TopDrive() OpenSafetyValveLed = 0 CloseSafetyValveLed = 0 #ifdef deb print*, 'RemoveSafetyValve_TopDrive()' #endif end subroutine subroutine OpenSafetyValve_TopDrive() implicit none if(.not.IsSafetyValveInstalled_TopDrive) return OpenSafetyValveLed = 1 CloseSafetyValveLed = 0 SafetyValve = .true. #ifdef deb print*, 'OpenSafetyValve_TopDrive()' #endif call ChangeValve(54, SafetyValve) end subroutine subroutine CloseSafetyValve_TopDrive() implicit none if(.not.IsSafetyValveInstalled_TopDrive) return CloseSafetyValveLed = 1 OpenSafetyValveLed = 0 SafetyValve = .false. #ifdef deb print*, 'CloseSafetyValve_TopDrive()' #endif call ChangeValve(54, SafetyValve) end subroutine subroutine InstallIBop() implicit none IsIBopInstalled = .true. call Valve(103)%RemoveAdjacent(124) call Valve(124)%RemoveAdjacent(103) call Valve(55)%AdjacentTo(103) call Valve(55)%AdjacentTo(124) call Valve(103)%AdjacentTo(55) call Valve(124)%AdjacentTo(55) #ifdef deb print*, 'InstallIBop()' #endif IRIBopLed = 1 call OpenIBop() end subroutine subroutine RemoveIBop() implicit none IsIBopInstalled = .false. call Valve(55)%RemoveAdjacent(103) call Valve(55)%RemoveAdjacent(124) call Valve(103)%RemoveAdjacent(55) call Valve(124)%RemoveAdjacent(55) call Valve(103)%AdjacentTo(124) call Valve(124)%AdjacentTo(103) #ifdef deb print*, 'RemoveIBop()' #endif IRIBopLed = 0 IBop = .false. call ChangeValve(55, IBop) end subroutine subroutine OpenIBop() implicit none if(.not.IsIBopInstalled) return IBop = .true. #ifdef deb print*, 'OpenIBop()' #endif call ChangeValve(55, IBop) end subroutine subroutine CloseIBop() implicit none if(.not.IsIBopInstalled) return IBop = .false. #ifdef deb print*, 'CloseIBop()' #endif call ChangeValve(55, IBop) end subroutine subroutine InstallKellyCock() implicit none IsKellyCockInstalled = .true. call Valve(125)%RemoveAdjacent(126) call Valve(126)%RemoveAdjacent(125) call Valve(125)%AdjacentTo(68) call Valve(68)%AdjacentTo(125) call Valve(68)%AdjacentTo(126) call Valve(126)%AdjacentTo(68) #ifdef deb print*, 'InstallKellyCock()' #endif call OpenKellyCock() end subroutine subroutine RemoveKellyCock() implicit none IsKellyCockInstalled = .false. call Valve(125)%RemoveAdjacent(68) call Valve(126)%RemoveAdjacent(68) call Valve(68)%RemoveAdjacent(125) call Valve(68)%RemoveAdjacent(126) call Valve(125)%AdjacentTo(126) call Valve(126)%AdjacentTo(125) KellyCock = .false. call ChangeValve(68, KellyCock) CloseKellyCockLed = 0 OpenKellyCockLed = 0 #ifdef deb print*, 'RemoveKellyCock()' #endif end subroutine subroutine OpenKellyCock() implicit none if(.not.IsKellyCockInstalled) return OpenKellyCockLed = 1 CloseKellyCockLed = 0 KellyCock = .true. #ifdef deb print*, 'OpenKellyCock()' #endif call ChangeValve(68, KellyCock) end subroutine subroutine CloseKellyCock() implicit none if(.not.IsKellyCockInstalled) return CloseKellyCockLed = 1 OpenKellyCockLed = 0 KellyCock = .false. #ifdef deb print*, 'CloseKellyCock()' #endif call ChangeValve(68, KellyCock) end subroutine subroutine InstallTopDriveIBop() implicit none IsTopDriveIBopInstalled = .true. call Valve(126)%RemoveAdjacent(128) call Valve(128)%RemoveAdjacent(126) call Valve(126)%AdjacentTo(70) call Valve(70)%AdjacentTo(126) call Valve(128)%AdjacentTo(70) call Valve(70)%AdjacentTo(128) #ifdef deb print*, 'InstallTopDriveIBop()' #endif call OpenTopDriveIBop() end subroutine subroutine RemoveTopDriveIBop() implicit none IsTopDriveIBopInstalled = .false. call Valve(126)%RemoveAdjacent(70) call Valve(70)%RemoveAdjacent(126) call Valve(128)%RemoveAdjacent(70) call Valve(70)%RemoveAdjacent(128) call Valve(126)%AdjacentTo(128) call Valve(128)%AdjacentTo(126) #ifdef deb print*, 'RemoveTopDriveIBop()' #endif TopDriveIBop = .false. call ChangeValve(70, TopDriveIBop) end subroutine subroutine OpenTopDriveIBop() implicit none if(.not.IsTopDriveIBopInstalled) return TopDriveIBop = .true. call ChangeValve(70, TopDriveIBop) #ifdef deb print*, 'OpenTopDriveIBop()' #endif end subroutine subroutine CloseTopDriveIBop() implicit none if(.not.IsTopDriveIBopInstalled) return TopDriveIBop = .false. call ChangeValve(70, TopDriveIBop) #ifdef deb print*, 'CloseTopDriveIBop()' #endif end subroutine subroutine InstallFloatValve() implicit none IsFloatValveInstalled = .true. call Valve(69)%RemoveAdjacent(79) call Valve(79)%RemoveAdjacent(69) call Valve(48)%AdjacentTo(69) call Valve(48)%AdjacentTo(79) call Valve(69)%AdjacentTo(48) call Valve(79)%AdjacentTo(48) #ifdef deb print*, 'InstallFloatValve()' #endif call OpenFloatValve() end subroutine subroutine RemoveFloatValve() implicit none IsFloatValveInstalled = .false. call Valve(48)%RemoveAdjacent(69) call Valve(48)%RemoveAdjacent(79) call Valve(69)%RemoveAdjacent(48) call Valve(79)%RemoveAdjacent(48) call Valve(69)%AdjacentTo(79) call Valve(79)%AdjacentTo(69) #ifdef deb print*, 'RemoveFloatValve()' #endif FloatValve = .false. call ChangeValve(48, FloatValve) end subroutine subroutine OpenFloatValve() implicit none if(.not.IsFloatValveInstalled) return FloatValve = .true. #ifdef deb print*, 'OpenFloatValve()' #endif call ChangeValve(48, FloatValve) end subroutine subroutine CloseFloatValve() implicit none if(.not.IsFloatValveInstalled) return FloatValve = .false. #ifdef deb print*, 'CloseFloatValve()' #endif call ChangeValve(48, FloatValve) end subroutine subroutine ToggleFillupHead(v) implicit none logical, intent(in) :: v if(v) then call Valve(14)%RemoveAdjacent(78) call Valve(14)%AdjacentTo(57) call Valve(57)%AdjacentTo(14) call Valve(57)%AdjacentTo(103) call Valve(103)%AdjacentTo(57) else call Valve(14)%RemoveAdjacent(57) call Valve(57)%RemoveAdjacent(14) call Valve(57)%RemoveAdjacent(103) call Valve(103)%RemoveAdjacent(57) call Valve(14)%AdjacentTo(78) endif 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 Valve(50)%Status = v call ChangeValve(69, v) end subroutine subroutine ChangeValve(i, state) implicit none integer, intent(in) :: i logical, intent(in) :: state if(Valve(i)%Status==state) return Valve(i)%Status = state if(i == 41 .or. i == 42) then if(Valve(41)%Status == .false. .and. Valve(42)%Status == .false.) then Valve(60)%Status = .true. else Valve(60)%Status = .false. endif endif #ifdef deb print*, 'Valve(', i, ') = ', state #endif !call Traverse() IsPathsDirty = .true. end subroutine subroutine DisplayOpenPaths() implicit none integer :: i if(allocated(OpenPaths)) then do i = 1, size(OpenPaths) call OpenPaths(i)%Display() end do end if end subroutine subroutine DisplayOpenPathsWrite() implicit none integer :: i if(allocated(OpenPaths)) then do i = 1, size(OpenPaths) call OpenPaths(i)%DisplayWrite() end do end if end subroutine end module CManifolds