Fortraneries/GravityField/essai.f90

71 lines
1.9 KiB
Fortran
Raw Normal View History

!-----------------------------------------------------------------------
2022-11-30 03:24:24 +01:00
!-
! test program for the project "gravity field"
!-
!-----------------------------------------------------------------------
2022-11-24 00:52:13 +01:00
program essai
2022-11-28 13:47:44 +01:00
use realfield
use spitpgm ! XXX
2022-11-24 00:52:13 +01:00
implicit none
2022-11-28 13:47:44 +01:00
type(massbody) :: planet
integer :: foo
2022-11-30 03:24:24 +01:00
character(len=100) :: filename
planet%posx = 337.314
planet%posy = 164.666
planet%mass = 1e8
planet%serial = 42
2022-11-24 00:52:13 +01:00
do foo=0, 48
write (filename, "(a, i5.5, a)") 'WS/', foo, '.pgm'
call build_and_write_a_field(800, 600, planet, filename)
planet%posx = planet%posx + 6.99
planet%posy = planet%posy + 2.55
2022-11-28 13:47:44 +01:00
enddo
STOP 'YOLO'
2022-11-24 00:52:13 +01:00
contains
!-----------------------------------------------------------------------
!-
! compute a field with only one body; and write pic file
!-
subroutine build_and_write_a_field(szx, szy, moon, fname)
2022-11-28 13:47:44 +01:00
integer, intent(in) :: szx, szy
type(massbody), intent(in) :: moon
2022-11-30 03:24:24 +01:00
character(len=*), intent(in) :: fname
2022-11-28 13:47:44 +01:00
real :: maxi, mini
2022-11-28 13:47:44 +01:00
integer :: errcode
real, dimension(:,:), allocatable :: field
integer, dimension(:,:), allocatable :: greymap
2022-11-28 13:47:44 +01:00
allocate(field(szx, szy), stat=errcode)
2022-11-24 00:52:13 +01:00
call compute_a_field(field, moon)
2022-11-28 13:47:44 +01:00
maxi = maxval(field)
mini = minval(field)
print *, "field: ", mini, maxi, maxi-mini
2022-11-24 00:52:13 +01:00
allocate(greymap(szx, szy), stat=errcode)
greymap = 65535
! convert from real value to 16 bits int values
where (field < 65530.0)
greymap = int(field)
end where
call spit_as_pgm_16(greymap, trim(fname))
! make valgrind happy
2022-11-28 13:47:44 +01:00
deallocate(field)
deallocate(greymap)
2022-11-24 00:52:13 +01:00
2022-11-28 13:47:44 +01:00
end subroutine
2022-11-24 00:52:13 +01:00
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
2022-11-24 00:52:13 +01:00
end program