2022-02-12 21:00:57 +01:00
|
|
|
module spitpgm
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
contains
|
|
|
|
|
|
|
|
!-----------------------------------------------------
|
|
|
|
|
|
|
|
subroutine spit_as_pgm(pic, fname)
|
|
|
|
|
|
|
|
integer, intent(in), dimension (:,:) :: pic
|
|
|
|
character (len=*), intent(in) :: fname
|
|
|
|
|
|
|
|
integer :: io, foo
|
|
|
|
integer :: ix, iy
|
|
|
|
real :: fk, fpix
|
|
|
|
|
2022-03-01 20:49:40 +01:00
|
|
|
write(0, '(1X, A)') "> spit_as_pgm to " // trim(fname)
|
2022-02-12 21:00:57 +01:00
|
|
|
|
|
|
|
open(newunit=io, file=fname)
|
|
|
|
write (io, '(a2)') "P2"
|
|
|
|
write (io, '(i0," ",i0)') size(pic, 1), size(pic, 2)
|
|
|
|
write (io, '(i0)') 65535
|
|
|
|
|
|
|
|
foo = MAXVAL(pic)
|
|
|
|
if (foo .EQ. 0) then
|
|
|
|
print *, " IS SOMETHING WRONG GOING TO HAPPEN ?"
|
|
|
|
do ix = 1, size(pic)
|
|
|
|
write (io, "(i0)") 0
|
|
|
|
enddo
|
|
|
|
else
|
|
|
|
fk = float(foo) / 65535.0
|
|
|
|
print *, " max pix value", foo, " fk = ", fk
|
|
|
|
do iy = 1, ubound(pic, 2)
|
|
|
|
do ix = 1, ubound(pic, 1)
|
|
|
|
fpix = float(pic(ix, iy)) / fk
|
|
|
|
write (io, "(i0)") int(fpix)
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
endif
|
2022-02-12 23:27:59 +01:00
|
|
|
close(io)
|
|
|
|
|
|
|
|
end subroutine
|
|
|
|
!-----------------------------------------------------
|
|
|
|
subroutine spit_as_pgm_8(pic, fname)
|
|
|
|
|
|
|
|
integer, intent(in), dimension (:,:) :: pic
|
|
|
|
character (len=*), intent(in) :: fname
|
|
|
|
|
|
|
|
integer :: io, foo
|
|
|
|
integer :: ix, iy
|
|
|
|
|
2022-02-14 14:15:10 +01:00
|
|
|
! XXX print *, "> spit_as_pgm_8 to ", fname
|
2022-02-12 23:27:59 +01:00
|
|
|
foo = MAXVAL(pic)
|
2022-02-14 14:15:10 +01:00
|
|
|
! XXX print *, " max = ", foo
|
2022-02-12 23:27:59 +01:00
|
|
|
open(newunit=io, file=fname)
|
|
|
|
write (io, '(a2)') "P2"
|
|
|
|
write (io, '(i0," ",i0)') size(pic, 1), size(pic, 2)
|
|
|
|
write (io, '(i0)') 255
|
2022-02-12 21:00:57 +01:00
|
|
|
|
2022-02-12 23:27:59 +01:00
|
|
|
do iy=1,ubound(pic, 2)
|
|
|
|
do ix=1, ubound(pic, 1)
|
|
|
|
foo = pic(ix, iy)
|
|
|
|
if (foo .GT. 255) foo = 255
|
|
|
|
write(io, "(i3)") foo
|
|
|
|
enddo
|
|
|
|
enddo
|
2022-02-12 21:00:57 +01:00
|
|
|
close(io)
|
|
|
|
|
|
|
|
end subroutine
|
|
|
|
!-----------------------------------------------------
|
|
|
|
|
|
|
|
end module spitpgm
|