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.

CPath.i90 6.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # 1 "/home/admin/SimulationCore2/CSharp/Equipments/MudPathFinding/CPath.f90"
  2. module CPath
  3. use CLog5
  4. implicit none
  5. public
  6. type, public :: Path
  7. integer, allocatable :: Valves(:)
  8. logical :: IsClosed
  9. contains
  10. procedure :: Display => Display
  11. procedure :: DisplayWrite => DisplayWrite
  12. procedure :: First => First
  13. procedure :: Last => Last
  14. procedure :: Length => Length
  15. procedure :: Get => Get
  16. procedure :: Add => Add
  17. procedure :: Remove => Remove
  18. procedure :: Purge => Purge
  19. procedure :: Copy => Copy
  20. procedure :: MakeNull => MakeNull
  21. procedure :: IsNull => IsNull
  22. procedure :: Equal => Equal
  23. procedure :: Find => Find
  24. end type Path
  25. contains
  26. subroutine DisplayWrite(this)
  27. implicit none
  28. class(Path), intent(in) :: this
  29. character(len=512) :: temp
  30. integer :: i
  31. if(allocated(this%valves)) then
  32. write(temp, '(a1,i0,a3,i0,a4,9999(g0))') '(', this%First(), '<=>', this%Last(), ') : ', (this%Valves(i), ", ",i=1,size(this%Valves))
  33. write(*,*) temp
  34. end if
  35. end subroutine
  36. subroutine Display(this)
  37. implicit none
  38. class(Path), intent(in) :: this
  39. character(len=512) :: temp
  40. integer :: i
  41. if(allocated(this%valves)) then
  42. write(temp, '(a1,i0,a3,i0,a4,9999(g0))') '(', this%First(), '<=>', this%Last(), ') : ', (this%Valves(i), ", ",i=1,size(this%Valves))
  43. call Log_5(temp)
  44. end if
  45. end subroutine
  46. integer function First(this)
  47. implicit none
  48. class(Path), intent(in) :: this
  49. if(allocated(this%Valves) .and. size(this%Valves) > 0) then
  50. First = this%Valves(1)
  51. return
  52. end if
  53. First = 0
  54. end function
  55. integer function Last(this)
  56. implicit none
  57. class(Path), intent(in) :: this
  58. if(allocated(this%Valves) .and. size(this%Valves) > 0) then
  59. Last = this%Valves(size(this%Valves))
  60. return
  61. end if
  62. Last = 0
  63. end function
  64. integer function Length(this)
  65. implicit none
  66. class(Path), intent(in) :: this
  67. if(allocated(this%Valves)) then
  68. Length = size(this%Valves)
  69. return
  70. end if
  71. Length = 0
  72. end function
  73. integer function Get(this, index)
  74. implicit none
  75. class(Path), intent(in) :: this
  76. integer, intent(in) :: index
  77. if(allocated(this%Valves)) then
  78. if(index < 1 .or. index > size(this%Valves)) then
  79. Get = -1
  80. return
  81. endif
  82. Get = this%Valves(index)
  83. return
  84. end if
  85. get = -1
  86. end function
  87. subroutine Add(this, value)
  88. implicit none
  89. class(Path), intent(inout) :: this
  90. integer, allocatable :: tempArr(:)
  91. integer, intent(in) :: value
  92. integer :: i, isize
  93. if(allocated(this%Valves)) then
  94. isize = size(this%Valves)
  95. allocate(tempArr(isize+1))
  96. do i=1,isize
  97. tempArr(i) = this%Valves(i)
  98. end do
  99. tempArr(isize+1) = value
  100. deallocate(this%Valves)
  101. call move_alloc(tempArr, this%Valves)
  102. else
  103. allocate(this%Valves(1))
  104. this%Valves(1) = value
  105. end if
  106. end subroutine
  107. subroutine Remove(this, index)
  108. implicit none
  109. class(Path), intent(inout) :: this
  110. integer, intent(in) :: index
  111. integer, allocatable :: tempArr(:)
  112. integer :: i
  113. logical :: found
  114. if(index <= 0 .or. index > size(this%Valves)) return
  115. if(.not.allocated(this%Valves))return
  116. allocate(tempArr(size(this%Valves)-1))
  117. found = .false.
  118. do i=1, size(this%Valves)
  119. if(i==index) then
  120. found = .true.
  121. cycle
  122. end if
  123. if(found) then
  124. tempArr(i-1) = this%Valves(i)
  125. else
  126. tempArr(i) = this%Valves(i)
  127. endif
  128. end do
  129. deallocate(this%valves)
  130. call move_alloc(tempArr, this%valves)
  131. end subroutine
  132. subroutine Purge(this, min, max)
  133. implicit none
  134. class(Path), intent(inout) :: this
  135. integer, intent(in) :: min
  136. integer, intent(in) :: max
  137. integer :: i
  138. i = 1
  139. do
  140. !
  141. if(this%Valves(i) >= min .and. this%Valves(i) <= max) then
  142. call this%Remove(i)
  143. else
  144. i = i + 1
  145. endif
  146. if(i > this%Length()) exit
  147. enddo
  148. end subroutine
  149. subroutine Copy(this, from)
  150. implicit none
  151. class(Path), intent(inout) :: this
  152. class(Path), intent(in) :: from
  153. if(allocated(from%Valves)) then
  154. if(allocated(this%Valves)) deallocate(this%Valves)
  155. allocate(this%Valves(size(from%Valves)))
  156. this%Valves(:) = from%Valves(:)
  157. end if
  158. end subroutine
  159. subroutine MakeNull(this)
  160. implicit none
  161. class(Path), intent(inout) :: this
  162. if(allocated(this%Valves)) deallocate(this%Valves)
  163. end subroutine
  164. logical function IsNull(this)
  165. implicit none
  166. class(Path), intent(in) :: this
  167. IsNull = .not.allocated(this%Valves)
  168. return
  169. end function
  170. logical function Equal(this, otherPath)
  171. implicit none
  172. class(Path), intent(inout) :: this
  173. class(Path), intent(in) :: otherPath
  174. integer :: i, sizeThis, sizeOtherPath
  175. sizeThis = size(this%Valves)
  176. sizeOtherPath = size(otherPath%Valves)
  177. if(sizeThis /= sizeOtherPath) then
  178. Equal = .false.
  179. return
  180. end if
  181. do i = 1, sizeThis
  182. if(this%Valves(i) /= otherPath%Valves(i)) then
  183. Equal = .false.
  184. return
  185. end if
  186. end do
  187. Equal = .true.
  188. return
  189. end function
  190. logical function Find(this, value)
  191. implicit none
  192. class(Path), intent(in) :: this
  193. integer, intent(in) :: value
  194. if(allocated(this%Valves)) then
  195. Find = any(this%Valves == value)
  196. return
  197. end if
  198. Find = .false.
  199. end function
  200. end module CPath