      subroutine PLOTX(FIXFIL,MCHEMG)
      include 'SIZE.INC'
      include 'UNITS.INC'
      include 'INPAR.INC'
      real Y(NPX+2),YW(NPX),YB(NPX),YLEN,RESULT
      real YMIN,YMAX,RANGE,YPRT
      integer XWIDTH,MINBAR,FIXFIL,MCHEMG,EOF,MAXPRM,I0,IT,KIN
      integer WIDTH,WIDN,N,N1,N2,MAXY,Y1,Y2,XCOOD,XOFF,UP,XLOC
      integer VTXTLN(5),VALSTR(5),VLEN,ISTRT,INC,K,IZON
      integer I,I1,I2,I3,I4,J,NC,IOPT,IDAT,IVAL,IMBED,IERR
      integer NOTE(NPX), NOTE1(NPX), NOTE3(NPX)
      character*1 NOTE2(NPX), NOTE4(NPX), NOTEE(NPX)
      character*1 VALEND(4), VALTXT(62)
      character AREA(21)*61, BLABEL(28)*1
      character*1 CCHAR, CONC(21)
      character*1 POLABL(21,4), PRLABL(21,5)
      character*1 POL1(21), POL2(21), POL3(21), POL4(21)
      character*1 PRL1(21), PRL2(21), PRL3(21), PRL4(21), PRL5(21)
      character*1 UNDER
      equivalence(POLABL(1,1),POL1(1)),(POLABL(1,2),POL2(1))
      equivalence(POLABL(1,3),POL3(1)),(POLABL(1,4),POL4(1))
      equivalence(PRLABL(1,1),PRL1(1)),(PRLABL(1,2),PRL2(1))
      equivalence(PRLABL(1,3),PRL3(1)),(PRLABL(1,4),PRL4(1))
      equivalence(PRLABL(1,5),PRL5(1))
      data POL1/7*' ','A','v','e','r','a','g','e',7*' '/
      data POL2/7*' ','M','a','x','i','m','u','m',7*' '/
      data POL3/7*' ','M','i','n','i','m','u','m',7*' '/
      data POL4/7*' ','M','i','n','m','a','x',8*' '/
      data PRL1/5*' ','T','o','t','a','l',' ','m','g','/','L',6*' '/
      data PRL2/4*' ','D','i','s','s','o','l','v','e','d',' ',
     &  'm','g','/','L',' ',' ',' '/
      data PRL3/' ','P','a','r','t','i','c','u','l','a','t','e','s',
     &' ','m','g','/','k','g',' ',' '/
      data PRL4/6*' ','B','i','o','t','a',' ','u','g','/','g',5*' '/
      data PRL5/6*' ','M','a','s','s',' ','g','m','2',7*' '/
      data UNDER/'_'/, WIDTH/11/, MAXY/21/
      data CONC/4*' ','C','o','n','c','e','n','t','r','a',
     &  't','i','o','n',4*' '/
      data VTXTLN/10,14,18,10,9/
      data VALSTR/1,12,26,44,54/
      data VALEND /'L',' ','K','G'/
      data VALTXT/'T','o','t','a','l',' ','m','g','/','L',' ','D','i',
     &   's','s','o','l','v','e','d',' ','m','g','/','L','P','a',
     &   'r','t','i','c','u','l','a','t','e','s',' ','m','g','/',
     &   'k','g','B','i','o','t','a',' ','u','g','/','g','M','a',
     &   's','s',' ','g','/','m','2'/
      data XWIDTH,MINBAR,YLEN /61,3,4./
      data BLABEL /'W','a','t','e','r',' ','C','o','l','u','m','n'
     &,'B','o','t','t','o','m',' ','S','e','d','i','m','e','n','t','s'/
      do 100 J = 1, MAXY
         AREA(J) = ' '
100   continue
      NC = MCHEMG
      call TYPOPT (IOPT)
      if (IOPT.eq.-1) go to 320
      if (IOPT.eq.4) go to 310
      if (IOPT.eq.5) go to 350
      open (unit=PLTLUN(MACHNO),status='OLD',access='SEQUENTIAL',form=
     &'UNFORMATTED',FILE='SSOUT.PLT',err=360)
      if (.not.(TOPOPN(MACHNO))) rewind PLTLUN(MACHNO)
      call DATOPT (IDAT)
      if (IDAT.eq.-1) go to 320
      if (IDAT.eq.7) go to 310
      if (IOPT.eq.2) go to 190
      call STAOPT (IVAL)
      if (IVAL.eq.-1) go to 320
      if (IVAL.eq.6) go to 310
      if (IVAL.eq.4) then
         write (TTYOUT(MACHNO),5000)
5000     format (/1X,'MINMAX plotting option not implemented.')
         go to 310
      endif
      START = IMBED(INPUT,STOPIT)
      if (START.ne.-999) then
         NC = MCHEMG
         call GETNUM (IERR,RESULT)
         if (IERR.eq.0) then
            NC = int(RESULT)
         else
            write (TTYOUT(MACHNO),5010) IERR
5010        format (//' Error converting chemical number. Error',I4)
         endif
      endif
      call SHOPLO (FIXFIL,1,I1,I2,I3,IERR)
      if (IERR.ne.0) go to (340,320,360), IERR
      N = 2
      WIDTH = 11
      WIDN = WIDTH+1
      XOFF = WIDTH/2
      if (mod(WIDTH,2).eq.0) XOFF = XOFF+1
      if (NC.lt.1.or.NC.gt.I1) go to 370
      do 110 I = 1, NC
         call PRODAT (EOF,YW,YB,N1,N2,NOTE1,NOTE2,NOTE3,NOTE4,IDAT)
         call PONDAT (EOF,NOTE,NOTEE,Y,IVAL,IDAT)
         if (EOF.eq.1) go to 320
110   continue
      N1 = N*WIDN
      do 120 I = 1, N1
         AREA(MAXY)(I:I) = UNDER
120   continue
      call SKALE (Y,YLEN,N,1,NPX+2)
      YMIN = Y(N+1)
      YMAX = YMIN+YLEN*Y(N+2)
      RANGE = YMAX-YMIN
      if (RANGE.le.0.) RANGE = 1.0
      do 150 I = 1, N
         XCOOD = WIDN*(I-1)+2
         Y1 = (Y(I)-YMIN)/RANGE*MAXY+0.5
         call XBAR (XCOOD,Y1,WIDTH,MAXY,AREA,NOTE(I),NOTEE(I))
         VLEN = VTXTLN(IDAT)
         if (IDAT.ne.1) go to 130
         if (I.eq.2) then
            VALTXT(10) = VALEND(3)
            VALTXT(11) = VALEND(4)
            VLEN = 11
         else
            VALTXT(10) = VALEND(1)
            VALTXT(11) = VALEND(2)
            VLEN = 10
         endif
130      continue
         ISTRT = VALSTR(IDAT)
         XLOC = XCOOD+XOFF
         Y2 = MAXY-VLEN-1
         do 140 I4 = 1, VLEN
            AREA(Y2+I4)(XLOC:XLOC) = VALTXT(ISTRT+I4-1)
140      continue
150   continue
      INC = 0
      CCHAR = 'I'
      write (TTYOUT(MACHNO),5020)
5020  format (///)
      do 180 I = 1, MAXY
         if (I.eq.MAXY) CCHAR = '+'
         do 160 K = XWIDTH, 1, -1
            if (AREA(I)(K:K).ne.' ') go to 170
160      continue
         K = 1
170      continue
         UP = K
         if (mod(I,5).eq.1) then
            INC = INC+1
            YPRT = YMAX-(INC-1)*Y(N+2)
            write (TTYOUT(MACHNO),5030) POLABL(I,IVAL),CONC(I),YPRT,
     &         CCHAR,AREA(I)(1:UP)
5030        format (1X,A1,1X,A1,1X,1PE9.2,3X,'-',A1,A)
         else
            write (TTYOUT(MACHNO),5040) POLABL(I,IVAL),CONC(I),CCHAR,
     &         AREA(I)(1:UP)
5040        format (1X,A1,1X,A1,14X,A1,A)
         endif
180   continue
      write (TTYOUT(MACHNO),5050)
5050  format (20X,' Water Col',4X,'Benthic')
      go to 330
190   continue
      call ZONOPT (IZON)
      if (IZON.eq.-1) go to 320
      if (IZON.eq.4) go to 310
      START = IMBED(INPUT,STOPIT)
      if (START.eq.-999) go to 200
      NC = MCHEMG
      call GETNUM (IERR,RESULT)
      if (IERR.eq.0) then
         NC = int(RESULT)
      else
         write (TTYOUT(MACHNO),5010) IERR
      endif
200   continue
      call SHOPLO (FIXFIL,1,I1,I2,I3,IERR)
      if (IERR.eq.0) go to 210
      go to (340,320,360), IERR
210   continue
      if (NC.lt.1.or.NC.gt.I1) go to 370
      do 220 I = 1, NC
         call PRODAT (EOF,YW,YB,N1,N2,NOTE1,NOTE2,NOTE3,NOTE4,IDAT)
         if (EOF.eq.1) go to 330
         if (I.ne.NC) call PONDAT (EOF,NOTE,NOTEE,Y,1,1)
         if (EOF.eq.1) go to 330
220   continue
      if (IZON.eq.1) then
         do 230 I = 1, N1
            Y(I) = YW(I)
            NOTE(I) = NOTE1(I)
            NOTEE(I) = NOTE2(I)
230      continue
      else
         do 240 I = 1, N2
            Y(I) = YB(I)
            NOTE(I) = NOTE3(I)
            NOTEE(I) = NOTE4(I)
240      continue
      endif
      N = N1
      if (IZON.eq.2) N = N2
      if (N.eq.0) then
         write (TTYOUT(MACHNO),5060)
5060     format (//' No data available. Plotting abandoned.'/)
         go to 310
      endif
      MAXPRM = (XWIDTH-1)/(1+MINBAR)
      if (N.gt.MAXPRM) then
         write (TTYOUT(MACHNO),5070) N,MAXPRM
5070  format (//1X,I5,' exceeds the maximum number (',I3,') of parameter
     &s that can be plotted.'/1X,'Only the first ',I5,' parameters will 
     &be plotted.'/)
         N = MAXPRM
      endif
      WIDTH = (XWIDTH-1)/N-1
      if (WIDTH.gt.11) WIDTH = 11
      WIDN = WIDTH+1
      N1 = N*WIDN
      do 250 I = 1, N1
         AREA(MAXY)(I:I) = UNDER
250   continue
      call SKALE (Y,YLEN,N,1,NPX+2)
      YMIN = Y(N+1)
      YMAX = YMIN+YLEN*Y(N+2)
      RANGE = YMAX-YMIN
      if (RANGE.le.0.) RANGE = 1.0
      do 260 I = 1, N
         XCOOD = WIDN*(I-1)+2
         Y1 = (Y(I)-YMIN)/RANGE*MAXY+0.5
         call XBAR (XCOOD,Y1,WIDTH,MAXY,AREA,NOTE(I),NOTEE(I))
260   continue
      INC = 0
      CCHAR = 'I'
      write (TTYOUT(MACHNO),5020)
      if (IZON.eq.2) then
         PRLABL(15,1) = 'K'
         PRLABL(16,1) = 'G'
      else
         PRLABL(15,1) = 'L'
         PRLABL(16,1) = ' '
      endif
      do 290 I = 1, MAXY
         if (I.eq.MAXY) CCHAR = '+'
         do 270 K = XWIDTH, 1, -1
            if (AREA(I)(K:K).ne.' ') go to 280
270      continue
         K = 1
280      continue
         UP = K
         if (mod(I,5).eq.1) then
            INC = INC+1
            YPRT = YMAX-(INC-1)*Y(N+2)
            write (TTYOUT(MACHNO),5030) PRLABL(I,IDAT),CONC(I),YPRT,
     &         CCHAR,AREA(I)(1:UP)
         else
            write (TTYOUT(MACHNO),5040) PRLABL(I,IDAT),CONC(I),CCHAR,
     &         AREA(I)(1:UP)
         endif
290   continue
      if (IZON.eq.1) then
         I0 = 0
         IT = 12
      else
         I0 = 12
         IT = 16
      endif
      AREA(1) = ' '
      VLEN = (1+(1+WIDTH)*N)/2
      VLEN = VLEN-IT/2-1
      if (VLEN.lt.0) VLEN = 0
      do 300 I = 1, IT
         I0 = I0+1
         AREA(1)(VLEN+I:VLEN+I) = BLABEL(I0)
300   continue
      write (TTYOUT(MACHNO),5080) AREA(1)
5080  format (19X,A)
      go to 330
310   continue
      close (unit=PLTLUN(MACHNO))
      return
320   continue
      write (TTYOUT(MACHNO),5090)
5090  format (/1X,'End-Of-File encountered.  PLOT terminated.')
      go to 310
330   continue
      go to 310
340   continue
      write (TTYOUT(MACHNO),5100)
5100  format (/1X,'No results are available for plotting.')
      go to 310
350   continue
      call KINOPT (KIN)
      if (KIN.eq.-1) go to 320
      if (KIN.eq.4) go to 310
      open (unit=PLTLUN(MACHNO),status='OLD',access='SEQUENTIAL',form='U
     &NFORMATTED',FILE='KINOUT.PLT',err=360)
      if (.not.(TOPOPN(MACHNO))) rewind PLTLUN(MACHNO)
      call KINET (KIN,MCHEMG)
      go to 310
360   continue
      write (TTYOUT(MACHNO),5110)
5110  format (/1X,'Error encountered while attempting to access',' the p
     &lot file.'/' Possibly no RUN has been executed.'/)
      go to 310
370   continue
      write (TTYOUT(MACHNO),5120)
5120  format (//1X,'Specified chemical number out-of-range.'/1X,'Please 
     &review the following and respecify.')
      call SHOPLO (FIXFIL,0,I1,I2,I3,IERR)
      go to 310
      end
