Program Pgdem1
!-----------------------------------------------------------------------
! Demonstration program for PGPLOT. The main program opens the output
! device and calls a series of subroutines, one for each sample plot.
!-----------------------------------------------------------------------
      Integer Pgopen
!
! Call PGBEG to initiate PGPLOT and open the output device; PGBEG
! will prompt the user to supply the device name and type. Always
! check the return code from PGBEG.
!
      If (Pgopen('?') <= 0) Stop
!
! Call the demonstration subroutine
!
      Call Pgex1
      Call Pgex2
      Call Pgex3
      Call Pgend
End Program Pgdem1

Subroutine Pgex1
!-----------------------------------------------------------------------
! This example illustrates the use of PGENV, PGLAB, PGPT, PGLINE.
!-----------------------------------------------------------------------
      INTEGER :: I
      REAL :: XS(5),YS(5), XR(100), YR(100)

      XS = (/ 1.,2.,3.,4.,5. /)
      YS = (/ 1.,4.,9.,16.,25. /)
!
! Call PGENV to specify the range of the axes and to draw a box, and
! PGLAB to label it. The x-axis runs from 0 to 10, and y from 0 to 20.
!
      CALL PGENV(0.,10.,0.,20.,0,1)
      CALL PGLAB('(x)', '(y)', 'PGPLOT Example 1:  y = x**2')
!
! Mark five points (coordinates in arrays XS and YS), using symbol
! number 9.
!
      CALL PGPT(5,XS,YS,9)
!
! Compute the function at 60 points, and use PGLINE to draw it.
!
      DO I = 1, 60
          XR(I) = 0.1*I
          YR(I) = XR(I)**2
      End Do
      CALL PGLINE(60,XR,YR)
!-----------------------------------------------------------------------
End Subroutine Pgex1

   Subroutine Pgex2
!-----------------------------------------------------------------------
! Repeat the process for another graph. This one is a graph of the
! sinc (sin x over x) function.
!-----------------------------------------------------------------------
      INTEGER :: I
      REAL :: XR(100), YR(100)
! note axes are now from -ve to +ve
      Call Pgenv(-2.,10.,-0.4,1.2,0,1)
      Call Pglab('(x)', 'sin(x)/x', 'PGPLOT Example 2:  Sinc Function')
      Do I = 1, 100
          XR(I) = (I-20)/6.
          YR(I) = 1.0
          If (XR(I) /=  0.0) YR(I) = SIN(XR(I))/XR(I)
      End Do
      Call Pgline(100,XR,YR)
!-----------------------------------------------------------------------
   End Subroutine Pgex2
 
      Subroutine Pgex3
!----------------------------------------------------------------------
! This example illustrates the use of PGBOX and attribute routines to
! mix colors and line-styles.
!----------------------------------------------------------------------
      REAL, Parameter :: PI = 3.141592
      INTEGER :: I
      REAL :: XR(360), YR(360)
      REAL :: ARG
!
! Call PGENV to initialize the viewport and window; the
! AXIS argument is -2, so no frame or labels will be drawn.
!
      CALL PGENV(0.,720.,-2.0,2.0,0,-2)
      CALL PGSAVE
!
! Set the color index for the axes and grid (index 5 = cyan).
! Call PGBOX to draw first a grid at low brightness, and then a
! frame and axes at full brightness. Note that as the x-axis is
! to represent an angle in degrees, we request an explicit tick 
! interval of 90 deg with subdivisions at 30 deg, as multiples of
! 3 are a more natural division than the default.
!
      CALL PGSCI(14)
      CALL PGBOX('G',30.0,0,'G',0.2,0)
      CALL PGSCI(5)
      CALL PGBOX('ABCTSN',90.0,3,'ABCTSNV',0.0,0)
!
! Call PGLAB to label the graph in a different color (3=green).
!
      CALL PGSCI(3)
      CALL PGLAB('x (degrees)','f(x)','PGPLOT Example 3')
!
! Compute the function to be plotted: a trig function of an
! angle in degrees, computed every 2 degrees.
!
      DO  I = 1, 360
          XR(I) = 2.0*I
          ARG = XR(I)/180.0*PI
          YR(I) = SIN(ARG) + 0.5*COS(2.0*ARG) +  0.5*SIN(1.5*ARG+PI/3.0)
      End Do
!
! Change the color (6=magenta), line-style (2=dashed), and line
! width (3) and draw the function.
!
      CALL PGSCI(6)
      CALL PGSLS(2)
      CALL PGSLW(3)
      CALL PGLINE(360,XR,YR)
!
! Restore attributes to defaults.
!
      CALL PGUNSA
!-----------------------------------------------------------------------
      End Subroutine PGEX3

