One of my users here has tried an example from a textbook to
write a postscript file. Initial values are given to two variables
graphics_unit and scale in the MODULE graph_ps.
These values are 20 and 400. These are printed in the main
program to default output. With Salford ftn95 4.5 the values are
printed as 1137180672 and 0.000000E+00. Sun Fortran prints
them correctly. These is some discussion as to whither module
variables which re not parameters can be given initial values.
What does the standard say?
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
PROGRAM testplot
USE graph_ps
! define 8 pointed star
TYPE (point) :: star(8)
INTEGER :: i , j
REAL :: theta
! open file for output
OPEN(graphics_unit,file = 'plot001.ps')
WRITE(graphics_unit , *) '%!PS'
WRITE(graphics_unit , *) 'gsave'
write(6,*) graphics_unit, scale !added by SP
DO i=1,8 ! define 8 points
theta = (REAL(i)-0.5) * 3.14159 / 4.
star(i)%x = 0.5 + 0.5*cos(theta)
star(i)%y = 0.5 + 0.5*sin(theta)
ENDDO
! draw 8 circles
DO i=1,8
CALL circle(star(i) , .05)
ENDDO
! draw lots of lines
DO i=2,8
DO j=1,i
CALL line(star(i) , star(j))
ENDDO
ENDDO
WRITE(graphics_unit , *) 'showpage grestore'
END PROGRAM testplot
John Blair-Fish
Edinburgh University Computing Service
King's Buildings
Edinburgh EH9 3JZ
Phone: 0131 650 4928 Fax: 0131 650 6552
email:[log in to unmask]
|