first dry run
This commit is contained in:
parent
f81c5675fa
commit
f16d6e6163
4
GravityField/.gitignore
vendored
4
GravityField/.gitignore
vendored
@ -1,2 +1,6 @@
|
||||
|
||||
essai
|
||||
|
||||
foo.pgm
|
||||
bar.pgm
|
||||
|
||||
|
@ -1,8 +1,15 @@
|
||||
#
|
||||
# Fortraneries by tTh - Gravity Field
|
||||
# Fortraneries by tTh - Gravity Field
|
||||
#
|
||||
|
||||
GFOPT = -Wall -Wextra -g -time
|
||||
|
||||
essai: essai.f90 Makefile
|
||||
gfortran $(GFOPT) $< -o $@
|
||||
all: essai
|
||||
|
||||
realfield.o: realfield.f90 Makefile
|
||||
gfortran $(GFOPT) -c $<
|
||||
|
||||
essai: essai.f90 Makefile realfield.o
|
||||
gfortran $(GFOPT) $< realfield.o -o $@
|
||||
|
||||
|
||||
|
@ -1,62 +1,54 @@
|
||||
!
|
||||
! project "gravity field"
|
||||
!
|
||||
program essai
|
||||
use realfield
|
||||
implicit none
|
||||
|
||||
integer :: ix, iy
|
||||
real :: fx, fy
|
||||
real :: foo, bar, maxi, mini
|
||||
type(massbody) :: planet
|
||||
integer :: foo
|
||||
planet%posx = 1337.314
|
||||
planet%posy = 1664.666
|
||||
planet%mass = 1e4
|
||||
|
||||
maxi = 0.0
|
||||
mini = 9e9
|
||||
do foo=1, 10
|
||||
call build_a_field(800, 600, planet)
|
||||
planet%posy = planet%posy + 51.45
|
||||
enddo
|
||||
|
||||
do ix=1, 2000
|
||||
STOP 'YOLO'
|
||||
|
||||
contains !------------------------------------------
|
||||
!
|
||||
subroutine build_a_field(szx, szy, moon)
|
||||
integer, intent(in) :: szx, szy
|
||||
type(massbody), intent(in) :: moon
|
||||
|
||||
integer :: ix, iy
|
||||
real :: fx, fy
|
||||
real :: grav, maxi, mini
|
||||
integer :: errcode
|
||||
real, dimension(:,:), allocatable :: field
|
||||
|
||||
allocate(field(szx, szy), stat=errcode)
|
||||
|
||||
do ix=1, szx
|
||||
fx = real(ix)
|
||||
do iy=1, 2000
|
||||
do iy=1, szy
|
||||
fy = real(iy)
|
||||
|
||||
foo = rdist(fx, fy, 222.22, 765.432)
|
||||
bar = gravity(foo, 1337.0)
|
||||
|
||||
maxi = max(maxi, bar)
|
||||
mini = min(mini, bar)
|
||||
|
||||
grav = compute_gravity(ix, iy, moon) / 2180800.0
|
||||
field(ix,iy) = grav
|
||||
enddo
|
||||
enddo
|
||||
|
||||
print *, "dist : ", mini, maxi
|
||||
maxi = maxval(field)
|
||||
mini = minval(field)
|
||||
print *, "field: ", mini, maxi, maxi-mini
|
||||
|
||||
contains !------------------------------------------
|
||||
deallocate(field)
|
||||
|
||||
function gravity(distance, masse)
|
||||
real, intent(in) :: distance, masse
|
||||
real :: gravity
|
||||
real :: computed
|
||||
end subroutine
|
||||
|
||||
if (distance .LT. 0.010) then
|
||||
computed = 0.0
|
||||
else
|
||||
computed = masse / (distance ** 2)
|
||||
endif
|
||||
|
||||
gravity = computed
|
||||
|
||||
end function
|
||||
|
||||
!------------------------------------------
|
||||
|
||||
function rdist(ax, ay, bx, by)
|
||||
real, intent(in) :: ax, ay, bx, by
|
||||
real :: rdist
|
||||
real :: rx, ry
|
||||
|
||||
rx = real(ax-bx)
|
||||
ry = real(ay-by)
|
||||
|
||||
rdist = sqrt( (rx*rx) + (ry*ry) )
|
||||
|
||||
end function
|
||||
|
||||
|
||||
!------------------------------------------
|
||||
!------------------------------------------
|
||||
|
||||
end program
|
||||
|
42
GravityField/realfield.f90
Normal file
42
GravityField/realfield.f90
Normal file
@ -0,0 +1,42 @@
|
||||
!
|
||||
! project "gravity field"
|
||||
!
|
||||
!-----------------------------------------------------------------------
|
||||
module realfield
|
||||
implicit none
|
||||
|
||||
!-----------------------------------------------------------------------
|
||||
|
||||
type massbody
|
||||
real :: posx, posy
|
||||
real :: mass
|
||||
integer :: serial
|
||||
end type
|
||||
|
||||
!-----------------------------------------------------------------------
|
||||
contains
|
||||
|
||||
function compute_gravity(ix, iy, body)
|
||||
|
||||
integer, intent(in) :: ix, iy
|
||||
type(massbody), intent(in) :: body
|
||||
real :: compute_gravity
|
||||
real :: rx, ry, dist
|
||||
|
||||
rx = real(ix) - body%posx
|
||||
ry = real(iy) - body%posy
|
||||
|
||||
dist = sqrt( (rx*rx) + (ry*ry) )
|
||||
if (dist .LT. 0.15) then
|
||||
write (0, *) "dist too small ", dist
|
||||
compute_gravity = 0e0
|
||||
endif
|
||||
|
||||
compute_gravity = body%mass * (dist ** 2)
|
||||
|
||||
end function
|
||||
|
||||
!-----------------------------------------------------------------------
|
||||
!-----------------------------------------------------------------------
|
||||
|
||||
end module
|
7
GravityField/runme.sh
Executable file
7
GravityField/runme.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e # stop on error
|
||||
|
||||
make essai
|
||||
|
||||
time ./essai
|
Loading…
Reference in New Issue
Block a user