Fortraneries/BloubWorld/bloubspace.f90

148 lines
3.8 KiB
Fortran
Raw Normal View History

2022-02-07 09:45:08 +11:00
!
! fonctions de base de gestion des bloubs
!
module bloubspace
implicit none
! ----------------------------------------------------------------
type t_bloubs
character(8) :: nick
logical :: alive
2022-02-19 05:30:10 +11:00
integer :: num ! ???
2022-02-07 09:45:08 +11:00
real :: px, py, pz
real :: vx, vy, vz
real :: radius
2022-02-17 01:59:42 +11:00
integer :: age
2022-02-07 09:45:08 +11:00
end type t_bloubs
contains ! -----------------------------------------
subroutine random_pv (blb)
type(t_bloubs), intent (inout) :: blb
2022-02-19 05:30:10 +11:00
blb%px = 1.35 * (rand() - 0.50)
blb%py = 0.50 + (rand() * 0.50)
blb%pz = 1.90 * (rand() - 0.50)
2022-02-07 09:45:08 +11:00
2022-02-11 05:38:44 +11:00
blb%vx = (rand() - 0.5) / 2.500
2022-02-19 05:30:10 +11:00
blb%vy = (rand() - 0.1) / 4.000
2022-02-11 05:38:44 +11:00
blb%vz = (rand() - 0.5) / 2.500
2022-02-07 09:45:08 +11:00
2022-02-08 12:53:49 +11:00
blb%alive = .TRUE.
2022-02-07 09:45:08 +11:00
end subroutine
2022-02-08 12:53:49 +11:00
! ----------------------------------------------------------------
2022-02-19 05:30:10 +11:00
! Load a blbs file into an array of bloubs
! ----------------------------------------------------------------
! Dump an array of bloubs to a blbs file.
! ----------------------------------------------------------------
! Display a bloub content to stderr
2022-02-08 12:53:49 +11:00
subroutine display_bloub (blb, message)
type(t_bloubs), intent (in) :: blb
character(*), intent (in) :: message
character(5) :: life
2022-02-07 09:45:08 +11:00
2022-02-08 12:53:49 +11:00
if (blb%alive) then
life = "alive"
else
life = "dead"
endif
2022-02-17 01:59:42 +11:00
write (0, '(4X, A)') '+--------------- ' // message // " -------"
write (0, '(4X,A3,A8,2X,I6,4X,A5,4X,I5)') '| ', &
blb%nick, blb%num, life, blb%age
2022-02-09 04:56:51 +11:00
write (0, '(4X,A3,3X,3(F8.3, 4X))') '| P', blb%px, blb%py, blb%pz
write (0, '(4X,A3,3X,3(F8.3, 4X))') '| V', blb%vx, blb%vy, blb%vz
2022-02-08 12:53:49 +11:00
write (0, '()')
end subroutine
2022-02-07 09:45:08 +11:00
! ----------------------------------------------------------------
subroutine move_bloub (blb, coef)
type(t_bloubs), intent (inout) :: blb
real, intent (in) :: coef
2022-02-07 12:08:17 +11:00
! we must check that this bloub is alive ?
2022-02-07 09:45:08 +11:00
blb%px = blb%px + (blb%vx * coef)
blb%py = blb%py + (blb%vy * coef)
blb%pz = blb%pz + (blb%vz * coef)
end subroutine
! ----------------------------------------------------------------
2022-02-08 12:53:49 +11:00
subroutine bound_a_blob (blb)
type(t_bloubs), intent (inout) :: blb
if (5.0 .lt. blb%px) then
blb%vx = -1.0 * blb%vx
blb%px = 5.0
2022-02-17 01:59:42 +11:00
blb%age = blb%age + 1
2022-02-08 12:53:49 +11:00
endif
if (-5.0 .gt. blb%px) then
blb%vx = -1.0 * blb%vx
blb%px = -5.0
2022-02-17 01:59:42 +11:00
blb%age = blb%age + 1
2022-02-08 12:53:49 +11:00
endif
if (0.0 .gt. blb%py) then
blb%vy = -1.0 * blb%vy
blb%py = 0.0
2022-02-17 01:59:42 +11:00
blb%age = blb%age + 1
2022-02-08 12:53:49 +11:00
endif
2022-02-18 00:10:15 +11:00
if (4.99 .lt. blb%py) then !!
2022-02-08 12:53:49 +11:00
blb%vy = -1.0 * blb%vy
2022-02-17 01:59:42 +11:00
blb%age = blb%age + 1
2022-02-18 00:10:15 +11:00
blb%py = 4.99 !!
2022-02-08 12:53:49 +11:00
endif
if (5.0 .lt. blb%pz) then
blb%vz = -1.0 * blb%vz
2022-02-17 01:59:42 +11:00
blb%age = blb%age + 1
2022-02-08 12:53:49 +11:00
blb%pz = 5.0
endif
if (-5.0 .gt. blb%pz) then
blb%vz = -1.0 * blb%vz
2022-02-17 01:59:42 +11:00
blb%age = blb%age + 1
2022-02-08 12:53:49 +11:00
blb%pz = -5.0
endif
end subroutine
! ----------------------------------------------------------------
2022-02-17 01:59:42 +11:00
function distance_of_bloubs(bla, blb)
type(t_bloubs), intent(in) :: bla, blb
real :: distance_of_bloubs
real :: dx, dy, dz
dx = (bla%px-blb%px)**2
dy = (bla%py-blb%py)**2
dz = (bla%pz-blb%pz)**2
distance_of_bloubs = sqrt(dx + dy +dz)
end function
! ----------------------------------------------------------------
! kill a bloub under condition(s)
2022-02-08 12:53:49 +11:00
subroutine green_soylent (blb)
type(t_bloubs), intent (inout) :: blb
2022-02-19 05:30:10 +11:00
if (blb%age .gt. 8) then
2022-02-08 12:53:49 +11:00
blb%alive = .FALSE.
endif
end subroutine
! ----------------------------------------------------------------
2022-02-07 09:45:08 +11:00
end module