first dry run

This commit is contained in:
tTh 2022-11-28 13:47:44 +01:00
parent f81c5675fa
commit f16d6e6163
5 changed files with 101 additions and 49 deletions

View File

@ -1,2 +1,6 @@
essai essai
foo.pgm
bar.pgm

View File

@ -4,5 +4,12 @@
GFOPT = -Wall -Wextra -g -time GFOPT = -Wall -Wextra -g -time
essai: essai.f90 Makefile all: essai
gfortran $(GFOPT) $< -o $@
realfield.o: realfield.f90 Makefile
gfortran $(GFOPT) -c $<
essai: essai.f90 Makefile realfield.o
gfortran $(GFOPT) $< realfield.o -o $@

View File

@ -1,62 +1,54 @@
!
! project "gravity field"
!
program essai program essai
use realfield
implicit none implicit none
type(massbody) :: planet
integer :: foo
planet%posx = 1337.314
planet%posy = 1664.666
planet%mass = 1e4
do foo=1, 10
call build_a_field(800, 600, planet)
planet%posy = planet%posy + 51.45
enddo
STOP 'YOLO'
contains !------------------------------------------
!
subroutine build_a_field(szx, szy, moon)
integer, intent(in) :: szx, szy
type(massbody), intent(in) :: moon
integer :: ix, iy integer :: ix, iy
real :: fx, fy real :: fx, fy
real :: foo, bar, maxi, mini real :: grav, maxi, mini
integer :: errcode
real, dimension(:,:), allocatable :: field
maxi = 0.0 allocate(field(szx, szy), stat=errcode)
mini = 9e9
do ix=1, 2000 do ix=1, szx
fx = real(ix) fx = real(ix)
do iy=1, 2000 do iy=1, szy
fy = real(iy) fy = real(iy)
grav = compute_gravity(ix, iy, moon) / 2180800.0
foo = rdist(fx, fy, 222.22, 765.432) field(ix,iy) = grav
bar = gravity(foo, 1337.0)
maxi = max(maxi, bar)
mini = min(mini, bar)
enddo enddo
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) end subroutine
real, intent(in) :: distance, masse
real :: gravity
real :: computed
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 end program

View 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
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e # stop on error
make essai
time ./essai