cc      SUBROUTINE TABCOL(IOPT,ITABLE)
cc itable dans le common
      SUBROUTINE TABCOL(IOPT,IWAVE)
      SAVE ITABCO,ITSAUV,ITSAUV2
      INCLUDE 'com_options.f'
      INTEGER ITABCO(256),ITSAUV(256),ITSAUV2(256),ITBID(256)
C
      IF (IBATCH.EQ.0.AND.ITERMC.EQ.4.AND.IOPT.NE.3333.AND.IOPT.NE.3434)
     &     CALL CHANGE_CURS(5)
      NBCOL0 = 256
      IF (IOPT.EQ.0) THEN
        CALL METTABLE(ITSAUV,NBCOL0)
      ELSEIF(IOPT.EQ.3333) THEN
        DO I=1,256
          ITSAUV2(I) = ITABCO(I)
        ENDDO
c ici pour changer le nombre tables dans le menu (nbtabs2*2)
c et aussi dans deroule...
        NCTAB = 6
        II = 232
        NBTABS2 = 18
        DO I=NBTABS2,1,-1
          CALL TABLE(ITABCO(II),NCTAB,NNN,I,0)
          II = II-NCTAB
        ENDDO
        CALL METTABLE(ITABCO,NBCOL0)
      ELSEIF(IOPT.EQ.3434) THEN
        DO I=1,256
          ITABCO(I) = ITSAUV2(I)
        ENDDO
        CALL METTABLE(ITABCO,NBCOL0)
      ELSEIF(IOPT.GT.-10) THEN
        CALL LITTABLE(ITSAUV,NBCOL0)
        DO I=1,16
          ITABCO(I) = ITSAUV(I)
        ENDDO
C 
        IF (ITABLE.EQ.51.OR.ITABLE.EQ.52) THEN
          NB  = 1
          NV  = 256
          NR  = 2**16
          NBCOL = IOPT
          DT = 1./REAL(NBCOL)
          DO I=1,NBCOL+1
            IR = NINT(DT*(REAL(IROUGE0*(1+NBCOL-I))
     &                   +REAL(IROUGE1*(I-1))))
            IV = NINT(DT*(REAL(IVERT0*(1+NBCOL-I))+REAL(IVERT1*(I-1))))
            IB = NINT(DT*(REAL(IBLEU0*(1+NBCOL-I))+REAL(IBLEU1*(I-1))))
            ITABCO(17+I) = IR*NR + IV*NV + IB*NB
          ENDDO
        ELSEIF(ITABLE.EQ.53.OR.ITABLE.EQ.54) THEN
          ITABLE0 = ITABLE
          NBCOL = IOPT
          NLIMI = NINT(XLIMTAB*NBCOL)
          NLIMI = MAX(2,MIN(NBCOL-1,NLIMI))
C
          NNNN = NBCOL-NLIMI
          ITABLE = ITABLE2
          IF (MOD(ITABLE,2).EQ.1) THEN
            ITATA = ITABLE
          ELSE
            ITATA = ITABLE-1
          ENDIF
          IOPT2 = ITATA/2 + 1
          CALL TABLE(ITABCO(18+NLIMI),NNNN,NNNN,IOPT2,IWAVE)
          IF (MOD(ITABLE2,2).EQ.0) THEN
            DO I=18+NLIMI,18+NBCOL
              ITBID(I) = ITABCO(I)
            ENDDO
            DO I=1,NBCOL+1-NLIMI
              ITABCO(18+NLIMI+I) = ITBID(19+NBCOL-I)
            ENDDO
          ENDIF
C
          NNNN = NLIMI
          ITABLE = ITABLE1
          IF (MOD(ITABLE,2).EQ.1) THEN
            ITATA = ITABLE
          ELSE
            ITATA = ITABLE-1
          ENDIF
          IOPT2 = ITATA/2 + 1
          CALL TABLE(ITABCO(18),NNNN,NNNN,IOPT2,IWAVE)
          IF (MOD(ITABLE1,2).EQ.0) THEN
            DO I=18,18+NLIMI
              ITBID(I) = ITABCO(I)
            ENDDO
            DO I=1,NLIMI+1
              ITABCO(18+I) = ITBID(19+NLIMI-I)
            ENDDO
          ENDIF
          ITABLE = ITABLE0
        ELSE
ccc          IOPT2 = ITABLE/2 + 1
          IOPT2 = (ITABLE+1)/2
          CALL TABLE(ITABCO(18),IOPT,NBCOL,IOPT2,IWAVE)
        ENDIF
C
        ITABCO(19+NBCOL) = ITABCO(18+NBCOL)
        ITABCO(17) = ITSAUV(3)
        IF (IBATCH.EQ.0.AND.ITERMC.EQ.4) THEN
          CALL METTABLE(ITABCO,NBCOL0)
          CALL COMPLTAB(ITABCO,ITSAUV,NBCOL,ITERMC)
        ELSE
          CALL COMPLTAB(ITABCO,ITSAUV,NBCOL,ITERMC)
          CALL METTABLE(ITABCO,NBCOL0)
        ENDIF
      ELSEIF(IOPT.LT.-20000) THEN
        IF (MOD(ITABLE,2).EQ.1) THEN
          ITATA = ITABLE
        ELSE
          ITATA = ITABLE-1
        ENDIF
        IF (ITATA.EQ.51) THEN
          DT = 1./REAL(NBCOL)
          NB  = 1
          NV  = 256
          NR  = 2**16
          DO I=1,NBCOL+1
            IR = NINT(DT*(REAL(IROUGE0*(1+NBCOL-I))
     &                   +REAL(IROUGE1*(I-1))))
            IV = NINT(DT*(REAL(IVERT0*(1+NBCOL-I))+REAL(IVERT1*(I-1))))
            IB = NINT(DT*(REAL(IBLEU0*(1+NBCOL-I))+REAL(IBLEU1*(I-1))))
            ITABCO(17+I) = IR*NR + IV*NV + IB*NB
          ENDDO
          ITABCO(18+NBCOL) = ITABCO(17+NBCOL)
        ELSEIF(ITATA.EQ.53) THEN
          ITABLE0 = ITABLE
          NLIMI = NINT(XLIMTAB*NBCOL)
          NLIMI = MAX(2,MIN(NBCOL-1,NLIMI))
C
          NNNN = NBCOL-NLIMI
          ITABLE = ITABLE2
          IF (MOD(ITABLE,2).EQ.1) THEN
            ITATA = ITABLE
          ELSE
            ITATA = ITABLE-1
          ENDIF
          IOPT2 = ITATA/2 + 1
          CALL TABLE(ITABCO(18+NLIMI),NNNN,NNNN,IOPT2,IWAVE)
          IF (MOD(ITABLE2,2).EQ.0) THEN
            DO I=18+NLIMI,18+NBCOL
              ITBID(I) = ITABCO(I)
            ENDDO
            DO I=1,NBCOL+1-NLIMI
              ITABCO(18+NLIMI+I) = ITBID(19+NBCOL-I)
            ENDDO
          ENDIF
C
          NNNN = NLIMI
          ITABLE = ITABLE1
          IF (MOD(ITABLE,2).EQ.1) THEN
            ITATA = ITABLE
          ELSE
            ITATA = ITABLE-1
          ENDIF
          IOPT2 = ITATA/2 + 1
          CALL TABLE(ITABCO(18),NNNN,NNNN,IOPT2,IWAVE)
          IF (MOD(ITABLE1,2).EQ.0) THEN
            DO I=18,18+NLIMI
              ITBID(I) = ITABCO(I)
            ENDDO
            DO I=1,NLIMI+1
              ITABCO(18+I) = ITBID(19+NLIMI-I)
            ENDDO
          ENDIF
          ITABLE = ITABLE0
        ELSEIF(ITATA.EQ.55) THEN
          NB  = 1
          NV  = 256
          NR  = 2**16
          IIII = (NBCOL+1)/2
          DT = 1./REAL(IIII)
          DO I=1,NBCOL+1
            IF (I.LE.IIII) THEN
              IR = NINT(DT*REAL(IROUGE0*I))
              IV = NINT(DT*REAL(IVERT0*I))
              IB = NINT(DT*REAL(IBLEU0*I))
            ELSE
              IR = IROUGE0+NINT(DT*REAL(I-IIII)*REAL(255-IROUGE0))
              IV = IVERT0 +NINT(DT*REAL(I-IIII)*REAL(255-IVERT0))
              IB = IBLEU0 +NINT(DT*REAL(I-IIII)*REAL(255-IBLEU0))
            ENDIF
            ITABCO(17+I) = IR*NR + IV*NV + IB*NB
          ENDDO
          ITABCO(18+NBCOL) = ITABCO(17+NBCOL)
        ELSE
          IOPT2 = ITATA/2 + 1
          NNN = -IOPT-100000
          CALL TABLE(ITABCO(18),NNN,NBCOL,IOPT2,IWAVE)
        ENDIF
        IF (MOD(ITABLE,2).EQ.0) THEN
          DO I=18,18+NBCOL
            ITBID(I) = ITABCO(I)
          ENDDO
          DO I=1,NBCOL+1
            ITABCO(18+I) = ITBID(19+NBCOL-I)
          ENDDO
          ITABCO(18) = ITABCO(19)
        ENDIF
        ITABCO(19+NBCOL) = ITABCO(18+NBCOL)
        ITABCO(17) = ITSAUV(3)
        IF (IBATCH.EQ.0.AND.ITERMC.EQ.4) THEN
          CALL METTABLE(ITABCO,NBCOL0)
          CALL COMPLTAB(ITABCO,ITSAUV,NBCOL,ITERMC)
        ELSE
          CALL COMPLTAB(ITABCO,ITSAUV,NBCOL,ITERMC)
          CALL METTABLE(ITABCO,NBCOL0)
        ENDIF
      ELSE
        ICHANG = MOD(-IOPT,1000)
        ITABCO(ICHANG) = ITSAUV(-IOPT/1000)
        ITABCO(17) = ITSAUV(3)
        IF (IBATCH.EQ.0.AND.ITERMC.EQ.4) THEN
          CALL METTABLE(ITABCO,NBCOL0)
          CALL COMPLTAB(ITABCO,ITSAUV,NBCOL,ITERMC)
        ELSE
          CALL COMPLTAB(ITABCO,ITSAUV,NBCOL,ITERMC)
          CALL METTABLE(ITABCO,NBCOL0)
        ENDIF
      ENDIF
C
      END
C-----------------------------------------------------------------------
      SUBROUTINE COMPLTAB(ITABCO,ITSAUV,NBCOL,ITERMC)
      INTEGER ITABCO(*),ITSAUV(*)
      INCLUDE 'com_ombreiso.f'
C
      NB  = 1
      NV  = 256
      NR  = 2**16
      NBC = NBCOL+2
      IF (ITERMC.EQ.4) THEN
        IMUL = 75
        SOMBRE = 0.1
        CALL PARAMSOMBRE(NBC,IMUL,SOMBRE)
      ELSE
        IMUL = (NBMAXGRA()-NBC)/NBC
        IF (IMUL.GE.3) THEN
          SOMBRE = MIN(0.8,MAX(0.3,3./REAL(IMUL)))
          DO I=18,17+NBC
            IR  = ITABCO(I)/NR
            IVB = ITABCO(I)-IR*NR
            IV  = IVB/NV
            IB  = MOD(IVB,NV)
            DO IM=1,IMUL
              S = 1. + (SOMBRE-1.)*REAL(IM)/REAL(IMUL)
              ITABCO(I+NBC*IM) = NINT(REAL(IR)*S)*NR
     &                         + NINT(REAL(IV)*S)*NV
     &                         + NINT(REAL(IB)*S)*NB
            ENDDO
          ENDDO
        ELSE
          IMUL = 0
        ENDIF
        IF ((17+NBC*(1+IMUL)).LT.256) THEN
          DO J=18+NBC*(1+IMUL),256
            ITABCO(J)=ITSAUV(1)
          ENDDO
        ENDIF
      ENDIF
      END
