
!!  Barlow and Barnett, Computing for Scientists 1998
!!  page 111                  C++ and Fortran 90

! program that creates a simple postscript file

!! Compile the module first
!  To compile this module, do something like:
!    gfortran -c graph_ps.f90

MODULE  graph_ps
                   ! type definition
  TYPE point
     REAL :: x , y
  END TYPE point
                   ! global data
  REAL    :: scale = 400.0
  INTEGER :: graphics_unit = 20

CONTAINS

  SUBROUTINE circle(p,r)
    TYPE(point) :: p
    REAL :: r
    CHARACTER(7)::form = "(3I8,A)"
    WRITE(graphics_unit ,  form) &
         NINT(p%x * scale) ,  &
         NINT(p%y * scale) ,  &
         NINT(scale * r) , ' 0 360 arc stroke'
    RETURN
  END SUBROUTINE circle

  SUBROUTINE line(from , to)
    TYPE(point) :: from , to
    CHARACTER(7):: form = "(2I8,A)"
    WRITE(graphics_unit ,  form) &
         NINT(scale * from%x),  &
         NINT(scale * from%y),' moveto'
    WRITE(graphics_unit , form) &
         NINT(scale * to%x) ,  &
         NINT(scale * to%y),' lineto stroke'
    RETURN
  END SUBROUTINE line
  
END MODULE  graph_ps




