procedure PGEX21 {
//-----------------------------------------------------------------------
// Test subroutine for PGPLOT: screen alignment and color palette.
//-----------------------------------------------------------------------
      L1 = L2 = 0
      GTYPE = GVER = ""

// Get PGPLOT information.

      pgqinf "VERSION", GVER, L1
      pgqinf "TYPE", GTYPE, L2
      pgbbuf

// Alignment test: clear the screen, and draw a box and grid using
// three monochrome intensities (color indices 1, 14, and 15).  The
// plot uses the largest available square viewport and and unit window.

      pgpage
      pgsvp 0.0,1.0,0.0,1.0
      pgwnad 0.0,1.0,0.0,1.0
      pgsci 14
      pgbox "g",0.02,1,"g",0.02,1
      pgsci 15
      pgbox "g",0.1,5,"g",0.1,5
      pgsci 1
      pgbox "bc",0.1,5,"bc",0.1,5

// Color palette test.

      for I=0,15 {
          pgsci I
          X1 = 0.31 + (I % 4)*0.1
          Y1 = 0.61 - int(I/4)*0.1
          X2 = X1 + 0.08
          Y2 = Y1 + 0.08
          pgrect X1, X2, Y1, Y2
      }

// Write the device type on the plot.

      pgsci 0
      pgrect 0.31, 1.0-0.31, 0.85, 0.97
      pgsci 1
      pgsfs 2
      pgrect 0.31, 1.0-0.31, 0.85, 0.97
      pgptxt 0.5, 0.91, 0.0, 0.5, "PGPLOT "+GVER
      pgptxt 0.5, 0.87, 0.0, 0.5, "Device "+GTYPE

      pgebuf
}

procedure PGEX22 {
//-----------------------------------------------------------------------
// Demonstration program for the PGPLOT plotting package.
// Plot a table of the standard PGPLOT graph marker symbols. This
// program also illustrates how windows and viewports may be manipulated.
//-----------------------------------------------------------------------
      XPIX1 = XPIX2 = YPIX1 = YPIX2 = 0
      X1 = X2 = Y1 = Y2 = 0

// Determine size of view surface.
// Lower left corner is (X1,Y1), upper right (X2, Y2) [inches].

      pgpage
      pgsvp 0.0, 1.0, 0.0, 1.0
      pgqvp 1, X1, X2, Y1, Y2
      X = X2-X1
      Y = Y2-Y1

// Determine device resolution (pixels/inch), and use it to choose
// line width.

      pgqvp 3, XPIX1, XPIX2, YPIX1, YPIX2
      RES = abs(XPIX2-XPIX1)/abs(X)
      LW = 1
      if (RES > 166.0) LW = 2

// Choose horizontal or vertical arrangement depending on
// device aspect ratio.

      if (X > Y) {
          NX = 8
          NY = 5
      } else {
          NX = 5
          NY = 8
      }
      DX = min(X/NX, 0.95*Y/NY)
      DY = DX
      IX = NX
      JY = 1
      XOFF = X1 + (X-NX*DX)*0.5
      YOFF = Y1 + (0.95*Y-NY*DY)*0.5
      pgbbuf

// Each symbol will be drawn in a standard window; the window is moved
// by manipulating the viewport.

      pgswin -1.,1.,-1.,1.

// Loop through all known symbols (N=0-31 and -1 to -8). 

      for N=0,39 {
          if (N <= 31) LABEL = string(N)
          if (N > 31) LABEL = string(31-N)

// Define window and viewport. The loop allows the plot to extend over
// more than one page if necessary; each page is labelled at the top.

          IX = IX+1
          if (IX > NX) {
            IX = 1
            JY = JY-1
          }
          if (JY < 1) {
            JY = NY
            if (N != 0) pgpage
            pgsch 1.2
            pgvsiz XOFF, XOFF+NX*DX, YOFF, YOFF+NY*DY
            pgslw LW
            pgmtxt "T", 1.0, 0.5, 0.5, "\fiPGPLOT \frMarker Symbols"
          }
          pgvsiz XOFF+(IX-1)*DX, XOFF+IX*DX, YOFF+(JY-1)*DY, YOFF+JY*DY

// Call PGBOX to draw a box and PGMTXT to label it.

          pgslw 1
          pgbox "BC",10.0,0,"BC",10.0,0
          pgsch 0.5
          pgmtxt "T",-1.5,0.05,0.0,LABEL

// Call PGPT1 to draw the symbol.

          pgslw LW
          pgsch 1.5
          if (N <= 31) pgpt1 0.0,0.0,N
          if (N > 31) pgpt1 0.0,0.0,31-N
      }

      pgebuf
}

procedure PGEX23 {
//-----------------------------------------------------------------------
// Demonstration program for the PGPLOT plotting package. 
//-----------------------------------------------------------------------
      N=9
      SAMPLE = stringarray(0)
      SAMPLE += "Normal:  \fnABCDQ efgh 1234 \ga\gb\gg\gd \gL\gH\gD\gW"
      SAMPLE += "Roman:  \frABCDQ efgh 1234 \ga\gb\gg\gd \gL\gH\gD\gW"
      SAMPLE += "Italic:  \fiABCDQ efgh 1234 \ga\gb\gg\gd \gL\gH\gD\gW"
      SAMPLE += "Script:  \fsABCDQ efgh 1234 \ga\gb\gg\gd \gL\gH\gD\gW"
      SAMPLE += "\fif\fr(\fix\fr) = \fix\fr\u2\dcos(2\gp\fix\fr)e\u\fix\fr\u2"
      SAMPLE += "\fiH\d0\u \fr= 75 \(2233) 25 km s\u-1\d Mpc\u-1\d"
      SAMPLE += "\fsL/L\d\(2281)\u\fr = 5\.6 \x 10\u6\d (\gl1216\A)"
      SAMPLE += "Markers: 3=\m3, 8=\m8, 12=\m12, 28=\m28."
      SAMPLE += "Cyrillic: \(2830)\(2912)\(2906)\(2911)\(2919)\(2917)\(2915)."

// Call PGENV to initialize the viewport and window.
// Call PGLAB to label the graph.

      pgenv 0.,20.,N,0.,0,-2
      pglab " ", " ", "\fiPGPLOT \frFonts"

// Use PGTEXT to write the sample character strings.

      pgsch 1.6
      for I=1,N {
         X1 = 0.0
         Y1 = I-0.5
         pgtext X1, Y1, SAMPLE[I]
      }
      pgsch 1.0
}

procedure PGEX24 {
//-----------------------------------------------------------------------
// Demonstration program for the PGPLOT plotting package. This example
// illustrates the different line widths.
//                              T. J. Pearson  1982 Dec 28
//----------------------------------------------------------------------

// Call PGENV to initialize the viewport and window.

      pgbbuf
      pgenv 0.,15.,0.,15.,0,0

// Call PGLAB to label the graph.

      pglab "Line Width"," ","\fiPGPLOT \frLine Widths"

// Draw 14 oblique lines in different thicknesses.

      for IW=1,14 {
          pgslw IW
          pgline 2, [IW, 0], [0, IW]
      }

// Draw another set of lines, dashed instead of solid.

      pgsls 2
      for IW=1,14 {
          pgslw IW
          pgline 2, [IW, 15], [15, IW]
      }

      pgsls 1
      pgslw 1
      pgebuf
}

procedure PGEX25 {
//-----------------------------------------------------------------------
// Demonstration program for the PGPLOT plotting package. This program
// tests polygon clipping on polygons and circles, and tests that
// markers are clipped correctly. Note that markers exactly on the edge
// of the window are supposed to be visible.
//                              T. J. Pearson  1994 Nov 25
//-----------------------------------------------------------------------
      PX = [0.0,2.0,4.0,6.0,8.0,10.0,12.0,14.0,16.4,17.0,17.3,17.8, 18.5, 20.0, 22.0, 24.0, 26.0, 28.0, 29.0,28.8,27.2,25.0,23.0,21.5,21.1,21.5,22.8, 24.1, 25.1,25.2, 24.2, 22.1, 20.0, 18.0, 16.0, 14.0, 12.0,10.0,  8.0,  6.1,  4.2,  3.0,  1.3]
      PY = [8.8, 7.6, 7.1, 7.4, 8.0, 8.9, 9.6, 9.9, 9.4,9.7, 12.0, 14.0, 16.1, 17.0, 17.0, 16.0, 13.9,13.1, 13.2, 12.3, 11.5, 11.5, 11.5, 11.2, 10.5,9.0, 8.0, 7.0, 5.1, 3.6, 1.9, 1.1, 0.9, 0.7,0.8, 1.0, 1.0, 1.2, 1.8, 2.1, 2.9, 4.1, 6.0]
      SX = [10.0, 10.0, 20.0, 30.0, 15.0]
      SY = [0.0, -6.0, -6.0,  5.0, -3.5]
      RX = [26.0, 27.0, 26.0]
      RY = [-4.0, -3.0, -3.0]

      pgpage
      pgvstd
      pgbbuf
      pgsave

// Set window.

      pgwnad 5.0, 25.0, -5.0, 15.0
      pgsci 1
      pgslw 1
      pgbox "BCNST", 0.0, 0, "BCNST", 0.0, 0

// Test clipping of polygons and circles

      pgsfs 1
      pgsci 1
      pgpoly 43, PX, PY
      pgsci 0
      pgsfs 3
      pgshs 30.0, 2.0, 0.0
      pgpoly 43, PX, PY
      pgsci 1
      pgshs 30.0, 4.0, 0.25
      pgpoly 43, PX, PY
      pgsci 1
      pgsfs 2
      pgpoly 43, PX, PY

      pgsfs 1
      pgsci 4
      pgpoly 5, SX, SY
      pgsci 0
      pgsfs 4
      pgshs 0.0, 1.6, 0.0
      pgpoly 5, SX, SY
      pgsci 1
      pgsfs 2
      pgpoly 5, SX, SY
     
//       The next polygon should be invisible.
      pgsfs 1
      pgsci 4
      pgpoly 3, RX, RY
      pgsci 1
      pgsfs 2
      pgpoly 3, RX, RY

      pgsfs 1
      pgsci 3
      pgcirc 8.0, 12.0, 3.5
      pgsfs 2
      pgsci 1
      pgcirc 8.0, 12.0, 3.5

// Test clipping of markers: all should be visible.

      pgsci 1
      pgslw 1
      for (I=0; I <= 30; I +=5) {
         for (J=-5; J <= 25; J += 5) {
            pgpt1 I, J, 9
         }
      }

// Draw box.

      pgbox "BCNST", 0.0, 0, "BCNST", 0.0, 0
      pglab " ", " ", "PGPLOT: clipping polygons and markers"

      pgunsa
      pgebuf
}

procedure PGEX26 {
//-----------------------------------------------------------------------
      DEVICE = GTYPE = GVER = ""
      L = L1 = L2 = 0
      X1 = X2 = Y1 = Y2 = 0.0
      PX = [0.0,2.0,4.0,6.0,8.0,10.0,12.0,14.0,16.4,17.0,17.3,17.8, 18.5, 20.0, 22.0, 24.0, 26.0, 28.0, 29.0,28.8,27.2,25.0,23.0,21.5,21.1,21.5,22.8, 24.1, 25.1,25.2, 24.2, 22.1, 20.0, 18.0, 16.0, 14.0, 12.0,10.0,  8.0,  6.1,  4.2,  3.0,  1.3]
      PY = [8.8, 7.6, 7.1, 7.4, 8.0, 8.9, 9.6, 9.9, 9.4,9.7, 12.0, 14.0, 16.1, 17.0, 17.0, 16.0, 13.9,13.1, 13.2, 12.3, 11.5, 11.5, 11.5, 11.2, 10.5,9.0, 8.0, 7.0, 5.1, 3.6, 1.9, 1.1, 0.9, 0.7,0.8, 1.0, 1.0, 1.2, 1.8, 2.1, 2.9, 4.1, 6.0]

      pgqinf "DEV/TYPE", DEVICE, L
      pgqinf "VERSION", GVER, L1
      pgqinf "TYPE", GTYPE, L2
      pgbbuf

// Clear the screen; set background and foreground colors.

      pgpage
      pgscr 0,0.0,0.0,0.35
      pgscr 1,1.0,1.0,1.0
      pgeras

// Draw a frame at the physical extremities of the plot.
// Dimensions are X by Y (inches).

      pgsvp 0.0, 1.0, 0.0, 1.0
      pgqvp 1, X1, X2, Y1, Y2
      X = X2-X1
      Y = Y2-Y1
      pgswin 0.0, X, 0.0, Y
      pgsfs 2
      pgrect 0.0, X, 0.0, Y
      pgmove 0.5*X, 0.0
      pgdraw 0.5*X, Y
      pgmove 0.0, 0.5*Y
      pgdraw X, 0.5*Y

// Draw a circle of diameter 0.5 x min(x,y)

      R = 0.25*min(X,Y)
      pgcirc X*0.5, Y*0.5, R

// Draw some more circles with different line-styles; this tests
// the dashing algorithm on curved lines.

      pgsls 2
      pgcirc X*0.5, Y*0.5, R*1.1
      pgsls 3
      pgcirc X*0.5, Y*0.5, R*1.2
      pgsls 2
      pgslw 3
      pgcirc X*0.5, Y*0.5, R*1.3
      pgsls 1
      pgslw 1

// Demonstrate different line-styles

      for I=1,5 {
          pgsls I
          pgmove I*(X/20.0),0.0
          pgdraw I*(X/20.0),Y
      }
      pgsls 1

// Demonstrate different line-widths

      for I=1,5 {
          pgslw I
          pgmove 0.0, I*(Y/20.0)
          pgdraw X, I*(Y/20.0)
      }
      pgslw 1

// Demonstrate different line-colors

      pgslw 4
      for I=0,15 {
          pgsci I
          XI = (I+20)*(X/40.0)
          pgmove XI,0.0
          pgdraw XI,Y
      }
      pgsci 1
      pgslw 1

// Draw dots in different thicknesses.

      XP = (14+20)*(X/40.0)
      for I=1,21 {
          YP = I*Y/22.0
          pgslw I
          pgpt1 XP,YP,-1
      }
      pgslw 1

// Demonstrate fill area

      for J=1,43 {
         PX[J] = (PX[J]+50.0)/100.0*X
         PY[J] = (PY[J]+75.0)/100.0*Y
      }
      for I=0,3 {
          pgsci I
          pgsfs 1
          pgpoly 43,PX,PY
          pgsci 1
          pgsfs 2
          pgpoly 43,PX,PY
          for J=1,43 {
             PY[J] = PY[J]-0.25*Y
          }
      }

// Write the device type on the plot.

      pgswin 0.0, 1.0, 0.0, 1.0
      pgsfs 1
      pgsci 0
      pgrect 0.31, 1.0-0.31, 0.85, 0.97
      pgsci 1
      pgsfs 2
      pgrect 0.31, 1.0-0.31, 0.85, 0.97
      pgptxt 0.5, 0.91, 0.0, 0.5, "PGPLOT " + GVER
      pgptxt 0.5, 0.87, 0.0, 0.5, "Device " + GTYPE

      pgebuf
}

/* PROGRAM PGDEM2 */
//-----------------------------------------------------------------------
// Demonstration program for PGPLOT. The main program opens the output
// device and calls a series of subroutines, one for each sample plot.
//-----------------------------------------------------------------------

// Call PGOPEN to initiate PGPLOT and open the output device; PGOPEN
// will prompt the user to supply the device name and type.

      if (pgopen(plotdevice) <= 0) break

// Call the demonstration subroutines.

      PGEX21
      PGEX22
      PGEX23
      PGEX24
      PGEX25
      PGEX26

// Finally, call PGCLOS to terminate things properly.

      pgclos

