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.
 
 
 
 
 
 

139 lines
4.1 KiB

  1. # 1 "/home/admin/SimulationCore2/CSharp/Equipments/MudPathFinding/CArrangement.f90"
  2. module CArrangement
  3. implicit none
  4. public
  5. integer, parameter :: Normal = 0
  6. integer, parameter :: Relation = 1
  7. integer, parameter :: Input = 2
  8. integer, parameter :: Output = 3
  9. integer, parameter :: InputOutput = 4
  10. type, public :: Arrangement
  11. integer, allocatable :: Adjacent(:) !adjacent valves that is connected to this valve
  12. logical :: Status !valve status ... open/close ... true/false
  13. integer :: ValveType ! Normal/Input/Output/InputOutput
  14. integer :: Number
  15. logical :: IsTraversed
  16. contains
  17. procedure :: Init => Init
  18. procedure :: IsConnectedTo => IsConnectedTo
  19. procedure :: IsSource => IsSource
  20. procedure :: Length => Length
  21. procedure :: AdjacentTo => AdjacentTo
  22. procedure :: RemoveAdjacent => RemoveAdjacent
  23. end type Arrangement
  24. contains
  25. subroutine Init(this, value)
  26. implicit none
  27. class(Arrangement), intent(inout) :: this
  28. integer, intent(in) :: value
  29. if(allocated(this%Adjacent)) deallocate(this%Adjacent)
  30. this%Status = .false.
  31. this%IsTraversed = .false.
  32. this%ValveType = Normal
  33. this%Number = value
  34. end subroutine
  35. integer function Length(this)
  36. implicit none
  37. class(Arrangement), intent(in) :: this
  38. if(allocated(this%Adjacent)) then
  39. Length = size(this%Adjacent)
  40. return
  41. end if
  42. Length = 0
  43. end function
  44. subroutine AdjacentTo(this, value)
  45. implicit none
  46. class(Arrangement), intent(inout) :: this
  47. integer, intent(in) :: value
  48. integer, allocatable :: tempArr(:)
  49. integer :: i, isize
  50. if(allocated(this%Adjacent)) then
  51. isize = size(this%Adjacent)
  52. ! check to see if already AdjacentTo that valve#
  53. do i=1,isize
  54. if(this%Adjacent(i)==value) return
  55. end do
  56. ! if value is a new entry then add it to the collection
  57. allocate(tempArr(isize+1))
  58. do i=1,isize
  59. tempArr(i) = this%Adjacent(i)
  60. end do
  61. tempArr(isize+1) = value
  62. deallocate(this%Adjacent)
  63. call move_alloc(tempArr, this%Adjacent)
  64. else
  65. allocate(this%Adjacent(1))
  66. this%Adjacent(1) = value
  67. end if
  68. end subroutine
  69. logical function IsConnectedTo(this, value)
  70. implicit none
  71. class(Arrangement), intent(in) :: this
  72. integer, intent(in) :: value
  73. if(.not.allocated(this%Adjacent)) then
  74. IsConnectedTo = .false.
  75. return
  76. endif
  77. IsConnectedTo = any(this%Adjacent == value)
  78. return
  79. end function
  80. logical function IsSource(this)
  81. implicit none
  82. class(Arrangement), intent(in) :: this
  83. IsSource = this%ValveType > Relation
  84. end function
  85. subroutine RemoveAdjacent(this, value)
  86. implicit none
  87. class(Arrangement), intent(inout) :: this
  88. integer, intent(in) :: value
  89. integer, allocatable :: tempArr(:)
  90. integer :: i, index, isize
  91. logical :: found
  92. if(.not.allocated(this%Adjacent))return
  93. index = -1
  94. do i=1, size(this%Adjacent)
  95. if(this%Adjacent(i)==value) then
  96. index = i
  97. exit
  98. end if
  99. end do
  100. if(index <= 0 .or. index > size(this%Adjacent)) return
  101. allocate(tempArr(size(this%Adjacent)-1))
  102. found = .false.
  103. do i=1, size(this%Adjacent)
  104. if(i==index) then
  105. found = .true.
  106. cycle
  107. end if
  108. if(found) then
  109. tempArr(i-1) = this%Adjacent(i)
  110. else
  111. tempArr(i) = this%Adjacent(i)
  112. endif
  113. end do
  114. deallocate(this%Adjacent)
  115. call move_alloc(tempArr, this%Adjacent)
  116. end subroutine
  117. end module CArrangement