* This program illustrates the use of PGPLOT
* to make a simple plot of some data points.
*   note that fortran variables are real*4 by default,
*   except for names beginning with i,j,k,l,m,n which are integer*4
* 1996 Oct -- Keith Horne @ St.Andrews
* parmeter defines array dimensions
	parameter ( maxdat = 10000 )
* declare arrays
	real*4 x( maxdat )
	real*4 y( maxdat )
	real*4 sigy( maxdat )
* declare character variables
	character*75 file
	character*75 xlabel
	character*75 ylabel
	character*75 title
	character*10 reply
* generate some data values
	ndat = 10
      do i=1,ndat
	x(i) = i
	y(i) = x(i) ** 2
	sigy(i) = sqrt( y(i) )
	write(*,*) i, x(i), y(i), sigy(i)
      end do
* load data values from a file (not used here)
c	file = 'filename.dat'
c	ndat = maxdat
c	call load1d2( file, ndat, 2, x, y, sigy )
* plot limits
	xmn = 0.
	xmx = x(ndat) + 1.
	ymn = 0.
	ymx = ( y(ndat) + sigy(ndat) ) * 1.05
* plot labels
	xlabel = 'x'
	ylabel = 'y = x\u2\d'
	title = 'A Simple Plot'
* open plot
   10	call pgbegin( 0, '?', 1, 1 )
* set character size
	call pgsch( 1.5 )
* set line width
	call pgslw( 4 )
* frame the plot
	call pgenv( xmn, xmx, ymn, ymx, 0, 0 )
* label the plot
	call pglabel( xlabel, ylabel, title )
* set color to red
	call pgsci(2)
* plot a data as a binned histogram
	call pgbin( ndat, x, y, .true. )
* set colour to blue
	call pgsci( 4 )
* plot a line connecting the data points
	call pgline( ndat, x, y )
* set color to green
	call pgsci(3)
* plot vertical error bars
	call pgerrb( 2, ndat, x, y, sigy, 1.0 ) 
	call pgerrb( 4, ndat, x, y, sigy, 1.0 ) 
* plot error bars one at a time (not used here)
c      do i=1,ndat
c	call pgerry( 1, x(i), y(i)+sigy(i), y(i)-sigy(i), 1.0 )
c      end do
* set color to white
	call pgsci(1)
* plot data points as star symbols (symbol 18)
	call pgpoint( ndat, x, y, 18 )
* close the plot
	call pgend
* plot again ?
	write(*,'(A,$)') ' Plot again ? [N] '
	read(*,'(A)') reply
	if( reply.eq.'Y' .or. reply.eq.'y' ) goto 10
	stop
	end
