Files
GenPlotting90/genplotting.f90
2026-05-07 22:30:30 +02:00

156 lines
4.8 KiB
Fortran

! THE GENPLOTTING MODULE
!
! new Thu Apr 23 01:13.37 PM UTC 2026
!
module genplotting
implicit none
real :: xmin, xmax, ymin, ymax
private :: xmin, xmax, ymin, ymax
real :: xoffset, yoffset, xscale, yscale
private :: xoffset, yoffset, xscale, yscale
real :: rotation
private :: rotation
integer :: outunit = 6
private :: outunit
contains
! ---------------------------------------------------------
! the first parameter _must_ be 0.
! the second can be
! - the name of a file for recoding plot instructions
! or
! - an empty string for send plot command to stdout
!
subroutine genp_init (foo, fname)
integer, intent(in) :: foo
character (len=*), intent(in) :: fname
IF (FOO .NE. 0) THEN
WRITE(0, '("FOO .NE. 0")')
CALL EXIT(1)
END IF
outunit = 6 ! stdout
if (len(fname) .gt. 0) then
write (0, '("genplot init opening : ", A)') fname
open(newunit=outunit,file=fname)
endif
xmin = 9e9 ; xmax = -9e9
ymin = 9e9 ; ymax = -9e9
xoffset = 0.0 ; yoffset = 0.0
xscale = 0.0 ; yscale = 0.0
rotation = 0.0
end subroutine
! ---------------------------------------------------------
subroutine genp_set_offset(ox, oy)
real, intent(in) :: ox, oy
xoffset = ox ; yoffset = oy
end subroutine
subroutine genp_get_offset(ox, oy)
real, intent(out) :: ox, oy
ox = xoffset ; oy = yoffset
end subroutine
! ---------------------------------------------------------
subroutine genp_move (px, py)
real, intent(in) :: px, py
real :: lx, ly
lx = px + xoffset ; ly = py + yoffset
write (outunit, '(2F12.5, I5)') lx, ly, -1
if (lx .lt. xmin) xmin = lx
if (lx .gt. xmax) xmax = lx
if (ly .lt. ymin) ymin = ly
if (ly .gt. ymax) ymax = ly
end subroutine
! ---------------------------------------------------------
subroutine genp_draw (px, py, color)
real, intent(in) :: px, py
integer, intent(in) :: color
real :: lx, ly
lx = px + xoffset ; ly = py + yoffset
write (outunit, '(2F12.5, I5)') lx, ly, color
if (lx .lt. xmin) xmin = lx
if (lx .gt. xmax) xmax = lx
if (ly .lt. ymin) ymin = ly
if (ly .gt. ymax) ymax = ly
end subroutine
! ---------------------------------------------------------
subroutine genp_line(xa, ya, xb, yb, color)
real, intent(in) :: xa, ya, xb, yb
integer, intent(in) :: color
call genp_move(xa, ya)
call genp_draw(xb, yb, color)
end subroutine
! ---------------------------------------------------------
subroutine plot_axes(amp)
real, intent(in) :: amp
call genp_move(0.0, -amp)
call genp_draw(0.0, amp, 7)
call genp_move(-amp, 0.0)
call genp_draw( amp, 0.0, 7)
end subroutine
! ---------------------------------------------------------
subroutine genp_end (foo)
integer, intent(in) :: foo
write (0, '("--- genp_end ---")')
write (0, '("minmax X ", 2F18.5)') xmin, xmax
write (0, '("minmax Y ", 2F18.5)') ymin, ymax
write (outunit, '(2F18.5, I6)') xmin*1.05, ymin*1.05, -1
write (outunit, '(2F18.5, I6)') xmin*1.05, ymax*1.05, 0
write (outunit, '(2F18.5, I6)') xmax*1.05, ymax*1.05, 0
write (outunit, '(2F18.5, I6)') xmax*1.05, ymin*1.05, 0
write (outunit, '(2F18.5, I6)') xmin*1.05, ymin*1.05, 0
close (outunit)
if (6 .ne. outunit) then
write (0, '("genp_end on ", I6, " is ", I6)') outunit, foo
endif
end subroutine
! ---------------------------------------------------------
! /!\ warning /!\
! this procedure is highly experimental, don't use it
! for any real (or critical) work, but it was fine for
! playing around with the #UselessGraphic concept.
subroutine genp_do_render(srcfile, tgafile, xsize, ysize)
character (len=*), intent(in) :: srcfile, tgafile
integer, intent(in) :: xsize, ysize
character (len=1664) :: cmdline
character (len=20) :: dima, dimb
integer :: i, j, errcode
write(0, '("--- genp do_render ---")')
write(0, '(" srcfile: ", A)') srcfile
write(0, '(" tgafile: ", A)') tgafile
write(0, '(" picsize: ", 2I5)') xsize, ysize
write(dima, '(I5, "x", I5)') xsize, ysize
! write(0, '("dima [",A, "]")') dima
dimb = "" ; j = 1
do i=1, len(dima)
if (dima(i:i) .NE. ' ') then
dimb(j:j) = dima(i:i)
j = j +1
endif
enddo
! write(0, '("[",A, "]")') trim(dimb)
write(cmdline, '("genplot2 -s ", A, " ", A, " ", A)') &
trim(dimb), srcfile, tgafile
write(0, '(A)') trim(cmdline)
call execute_command_line(cmdline, exitstat=errcode)
write(0, '("errcode was :", I6)') errcode
end subroutine
! ---------------------------------------------------------
end module genplotting