      SUBROUTINE TABLE(ITABCO,N,NBCOL,IOPT,IWAVE)
      INTEGER ITABCO(*),ITS(256)
      DATA US6,DS6,TS6,QS6
     &/ .16666666667 , .33333333333 , .5 , .66666666667 /

C
      NB  = 1
      NV  = 256
      NR  = 2**16
      NBM = NB*255
      NVM = NV*255
      NRM = NR*255
C
      IF (N.LE.6) THEN
        NBCOL = MAX(N,1)
      ELSE
        NBCOL = MIN(N,NBMAXGRA()-3)
      ENDIF
      IF (IOPT.EQ.1) THEN
        IF (NBCOL.GE.6) THEN
          NBCOLD = NBCOL/10
          NBC1 = 1+NBCOLD
          NBC2 = NBCOL-NBCOLD
          DO I=1,NBC1
            ITABCO(1+I) = NB*(30+NINT(235.*REAL(I)/REAL(NBC1+1)))
            ITABCO(NBCOL+1-NBC1+I) = 255*NR 
     &           + (NV+NB)*NINT(255.*REAL(I)/REAL(NBC1))
          ENDDO
          NBC3 = NBC2 - NBC1 - 1
          DO I=2+NBC1,NBC2
            TOTO = 0.6*REAL(NBC2-I)/REAL(NBC3-1)
            IF (TOTO.LE.0.2) THEN
              RRR = 1.
              VVV = 5.*TOTO
              BBB = 0.
            ELSEIF(TOTO.LE.0.4) THEN
              RRR = 2.-5.*TOTO
              VVV = 1.
              BBB = 5.*TOTO - 1.
            ELSEIF(TOTO.LE.0.6) THEN
              RRR = 0.
              VVV = 3.-5.*TOTO
              BBB = 1.
            ELSEIF(TOTO.LE.0.8) THEN
              RRR = 5.*TOTO - 3.
              VVV = 0.
              BBB = 1.
            ELSE
              RRR = 1.
              VVV = 0.
              BBB = 5.*(1.-TOTO)
            ENDIF
            ITABCO(I) = INT(RRR*255.)*NR
     &                + INT(VVV*255.)*NV
     &                + INT(BBB*255.)*NB
          ENDDO
        ELSE
          ITABCO(2) = NBM
          ITABCO(NBCOL+1) = NBM+NVM+NRM
          IF (NBCOL.GE.3) THEN
            ITABCO(NBCOL) = NRM
            IF (NBCOL.GE.4) THEN
              ITABCO(3) = NVM
              IF (NBCOL.EQ.5) THEN
                ITABCO(NBCOL-1) = NVM+NRM
              ENDIF
            ENDIF
          ENDIF
        ENDIF
      ELSE
        IF (IOPT.EQ.2) THEN
          DO I=2,NBCOL+1
            TOTO = REAL(I-2)/REAL(NBCOL-1)
            IF (TOTO.LE.DS6) THEN
              RRR = 0.
              VVV = TOTO*3.
              BBB = 1.
            ELSEIF(TOTO.LE.QS6) THEN
              RRR = (TOTO-DS6)*3.
              VVV = 1.
              BBB = 1.-RRR
            ELSE
              RRR = 1.
              VVV = 1.-(TOTO-DS6)*3.
              BBB = 0.
            ENDIF
            ITABCO(I) = INT(RRR*255.)*NR
     &                + INT(VVV*255.)*NV
     &                + INT(BBB*255.)*NB
          ENDDO
        ELSEIF(IOPT.EQ.3) THEN
          DO I=2,NBCOL+1
            TOTO = QS6*REAL(I-2)/REAL(NBCOL-1)
            IF (TOTO.LE.US6) THEN
              D = 1./SQRT(1.+36.*TOTO**2)
              RRR = 6.*TOTO*D
              VVV = 0.
              BBB = D
            ELSEIF(TOTO.LE.DS6) THEN
              D = 1./SQRT(1.+(2.-6.*TOTO)**2)
              RRR = D
              VVV = 0.
              BBB = (2.-6.*TOTO)*D
            ELSEIF(TOTO.LE.TS6) THEN
              RRR = 1.
              VVV = 6.*TOTO - 2.
              BBB = 0.
            ELSE
              RRR = 1.
              VVV = 1.
              BBB = 6.*TOTO - 3.
            ENDIF
            ITABCO(I) = INT(RRR*255.)*NR
     &                + INT(VVV*255.)*NV
     &                + INT(BBB*255.)*NB
          ENDDO
C
C Noir -> couleur (iopt<11)
C Noir -> couleur -> blanc (10<iopt<17)
C
        ELSEIF(IOPT.LE.16) THEN
          IF (IOPT.GE.11) THEN
            IOPT2 = IOPT-6
          ELSE
            IOPT2 = IOPT
          ENDIF
          IF (IOPT2.EQ.4) THEN
            NCOUL = NR + NV + NB
          ELSEIF(IOPT2.EQ.5) THEN
            NCOUL  = NR
            NCOUL2 = NV + NB
          ELSEIF(IOPT2.EQ.6) THEN
            NCOUL  = NV
            NCOUL2 = NR + NB
          ELSEIF(IOPT2.EQ.7) THEN
            NCOUL  = NB
            NCOUL2 = NR + NV
          ELSEIF(IOPT2.EQ.8) THEN
            NCOUL  = NR + NV
            NCOUL2 = NB
          ELSEIF(IOPT2.EQ.9) THEN
            NCOUL  = NV + NB
            NCOUL2 = NR
          ELSE
            NCOUL  = NR + NB
            NCOUL2 = NV
          ENDIF
          ITOTO = 30
          IF (IOPT.LE.10) THEN
            TOTO = REAL(255-ITOTO)/REAL(NBCOL-1)
            DO I=2,NBCOL+1
              ITABCO(I) = (ITOTO+NINT(REAL(I-2)*TOTO))*NCOUL
            ENDDO
          ELSE
            NBC = NBCOL/2
            TOTO = REAL(255-ITOTO)/REAL(NBC-1)
            DO I=2,NBC+1
              ITABCO(I) = (ITOTO+NINT(REAL(I-2)*TOTO))*NCOUL
            ENDDO
            TOTO = 255./REAL(NBCOL-NBC-1)
            DO I=NBC+2,NBCOL+1
              ITABCO(I) = 255*NCOUL+NCOUL2*NINT(REAL(I-NBC-2)*TOTO)
            ENDDO
          ENDIF
C
C Bitables (chaude/froide)
C
        ELSE
          NBC = NBCOL/2
          IF (IOPT.EQ.17) THEN
            IROUGE0 = 0
            IVERT0  = 255
            IBLEU0  = 255
C
            IROUGE1 = 0
            IVERT1  = 0
            IBLEU1  = 255
C
            IROUGE2 = 255
            IVERT2  = 0
            IBLEU2  = 0
C
            IROUGE3 = 255
            IVERT3  = 255
            IBLEU3  = 0
          ELSE
            IROUGE0 = 255
            IVERT0  = 0
            IBLEU0  = 255
C
            IROUGE1 = 0
            IVERT1  = 0
            IBLEU1  = 255
C
            IROUGE2 = 0
            IVERT2  = 255
            IBLEU2  = 0
C
            IROUGE3 = 255
            IVERT3  = 255
            IBLEU3  = 0
          ENDIF
          IF (NBC.EQ.1) THEN
            IR = (IROUGE0 + IROUGE1)/2
            IV = (IVERT0  + IVERT1) /2
            IB = (IBLEU0  + IBLEU1) /2
            ITABCO(2) = IR*NR + IV*NV + IB*NB
            IR = (IROUGE2 + IROUGE3)/2
            IV = (IVERT2  + IVERT3) /2
            IB = (IBLEU2  + IBLEU3) /2
            ITABCO(3) = IR*NR + IV*NV + IB*NB
          ELSE
            DT = 1./REAL(NBC-1)
            DO I=2,NBC+1
              IR = NINT(DT*(REAL(IROUGE0*(1+NBC-I))
     &                     +REAL(IROUGE1*(I-2))))
              IV = NINT(DT*(REAL(IVERT0*(1+NBC-I))+REAL(IVERT1*(I-2))))
              IB = NINT(DT*(REAL(IBLEU0*(1+NBC-I))+REAL(IBLEU1*(I-2))))
              ITABCO(I) = IR*NR + IV*NV + IB*NB
            ENDDO
            DO II=NBC+2,NBCOL+1
              I = II-NBC
              IR = NINT(DT*(REAL(IROUGE2*(1+NBC-I))
     &                     +REAL(IROUGE3*(I-2))))
              IV = NINT(DT*(REAL(IVERT2*(1+NBC-I))+REAL(IVERT3*(I-2))))
              IB = NINT(DT*(REAL(IBLEU2*(1+NBC-I))+REAL(IBLEU3*(I-2))))
              ITABCO(II) = IR*NR + IV*NV + IB*NB
            ENDDO
          ENDIF
        ENDIF
      ENDIF
C
      ITABCO(1) = ITABCO(2)
C
      IF (IWAVE.NE.0) THEN
        DO I=1,NBCOL+1
          ITS(I) = ITABCO(I)
        ENDDO
        ALPHA = 2.*3.14159265359*REAL(IWAVE)/REAL(NBCOL)
        PROF = .8*REAL(NBCOL)/REAL(IWAVE)
        DO I=1,NBCOL
          II = NINT(I+PROF*SIN(ALPHA*I))
          II = MIN(NBCOL+1,MAX(1,II))
          ITABCO(I) = ITS(II)
        ENDDO
      ENDIF
C
      END
