//      PROGRAM PGDEM9
//-----------------------------------------------------------------------
// Test program for PGPLOT: test of imaging routine PGPIXL.
//-----------------------------------------------------------------------
//      INTEGER PGBEG
//      INTEGER N, NCOL, NLEV
      N=64; NCOL=32; NLEV=9
      I=J=CI1=CI2=0
      F=floatarray(N,N)
      CLEV=floatarray(NLEV)
      TR=floatarray(6)
//      REAL F(N,N),FMIN,FMAX,R,G,B,CLEV(NLEV),TR(6)
      IA=longarray(N,N)
//
// Compute a suitable function.
//
      FMIN = F[1,1]
      FMAX = F[1,1]
      for I=1,N {
          for J=1,N {
              F[I,J] = cos(0.6*sqrt(I*2.)-0.4*J/3.)*cos(0.4*I/3)+(I-J)/N
              FMIN = min(F[I,J],FMIN)
              FMAX = max(F[I,J],FMAX)
          }
      }
      for I=1,N {
          for J=1,N {
              IA[I,J] = (F[I,J]-FMIN)/(FMAX-FMIN)*(NCOL-1)+16
          }
      }
//
// Open plot device and set up coordinate system. We will plot the
// image within a unit square.
//
      if (pgbeg(0,plotdevice,1,1) != 1) break
      pgqcol CI1, CI2
      if (CI2 < 15+NCOL) {
          print "This program requires a device with at least " + (15+NCOL) + " colors"
          break
      }
      pgpage
      pgscr 0, 0, 0.3, 0.2
      pgsvp 0.05, 0.95, 0.05, 0.95
      pgwnad 0, 1, 0, 1
//
// Set up a color palette using NCOL indices from 16 to 15+NCOL.
//
      for I=1,NCOL {
          R = (I-1)/(NCOL-1)*0.8 + 0.2
          G = max([0.0, 2.0*(I-1-NCOL/2)/(NCOL-1)])
          B = 0.2 + 0.4*(NCOL-I)/NCOL
          pgscr I+15, R, G, B
      }
//
// Use PGPIXL to plot the image.
//
      pgpixl IA,N,N, 1, N, 1, N, 0.0, 1.0, 0.0, 1.0
//
// Annotation.
//
      pgsci 1
      pgmtxt "t",1.0,0.0,0.0,"Test of PGPIXL"
      pgbox "bcnts",0.0,0,"bcnts",0.0,0
//
// Overlay a contour map.
//
      TR[1] = -1.0/(N-1)
      TR[2] = 1.0/(N-1)
      TR[3] = 0.0
      TR[4] = -1.0/(N-1)
      TR[5] = 0.0
      TR[6] = 1.0/(N-1)
      for I=1,NLEV {
          CLEV[I] = FMIN + (FMAX-FMIN)*I/NLEV
      }
      pgcont F, N, N, 1, N, 1, N, CLEV, NLEV, TR
//
// Done.
//
      pgend
