      SUBROUTINE CALCOUTLINE(NF,IOPT)
      INCLUDE 'com_faces.f'
      INCLUDE 'com_options.f'
      INTEGER ISUIV(4)
C
      IF (IELIMI.NE.0) THEN
        NOUTLINE = 0
      ELSEIF(IOPT.EQ.0) THEN
        DO I=1,NDS-1
          ISUIV(I) = I+1
        ENDDO
        ISUIV(NDS) = 1
        NOUTLINE = 0
        DO N=1,NF
          DO I=1,NDS
            IF (NBOR(I,N).EQ.0) THEN
              J = ISUIV(I)
              IFLAG = 0
              IF (NOUTLINE.GT.0) THEN
                DO K=1,NOUTLINE
                  NK = IOUTLINE(1,K)
                  IK = IOUTLINE(2,K)
                  JK = IOUTLINE(3,K)
                  IF (NFAC(I,N).EQ.NFAC(JK,NK)) THEN
                    IF (NFAC(J,N).EQ.NFAC(IK,NK)) THEN
                      IFLAG = 1
                      GOTO 10
                    ENDIF
                  ELSEIF(NFAC(I,N).EQ.NFAC(IK,NK)) THEN
                    IF (NFAC(J,N).EQ.NFAC(JK,NK)) THEN
                      IF (XF(I,N).EQ.XF(IK,NK)
     &               .AND.YF(I,N).EQ.YF(IK,NK)
     &               .AND.XF(J,N).EQ.XF(JK,NK)
     &               .AND.YF(J,N).EQ.YF(JK,NK)) THEN
                        IFLAG = 1
                        GOTO 10
                      ENDIF
                    ENDIF
                  ENDIF
                ENDDO
 10             CONTINUE
              ENDIF
              IF (IFLAG.EQ.0) THEN
                NOUTLINE = NOUTLINE+1
                IOUTLINE(1,NOUTLINE) = N
                IOUTLINE(2,NOUTLINE) = I
                IOUTLINE(3,NOUTLINE) = J
                IF (NOUTLINE.EQ.NOMAX) THEN
                  PRINT*,'*** Trop d''outlines'
                  NOUTLINE = 0
                  RETURN
                ENDIF
              ENDIF
            ENDIF
          ENDDO
        ENDDO
        IF (NOUTLINE.GT.1) THEN
          NOUTRANG  = 0
          NNN = 0
          DO WHILE (NNN.LT.NOUTLINE-1)
            NOUTRANG = NOUTRANG+1
            IOUT = 1
            DO I=NNN+1,NOUTLINE-1
              II = NFAC(IOUTLINE(3,I),IOUTLINE(1,I))
              IFLAG = 0
              DO J=I+1,NOUTLINE
                IF (II.EQ.NFAC(IOUTLINE(2,J),IOUTLINE(1,J))) THEN
C
C pour faire gaffe aux symetrisations...
C
                  IF (XF(IOUTLINE(3,I),IOUTLINE(1,I))
     &            .EQ.XF(IOUTLINE(2,J),IOUTLINE(1,J))
     &           .AND.YF(IOUTLINE(3,I),IOUTLINE(1,I))
     &            .EQ.YF(IOUTLINE(2,J),IOUTLINE(1,J))) THEN
                    IOUT = IOUT+1
                    IF (J.NE.I+1) THEN
                      N1 = IOUTLINE(1,J)
                      N2 = IOUTLINE(2,J)
                      N3 = IOUTLINE(3,J)
                      IOUTLINE(1,J) = IOUTLINE(1,I+1)
                      IOUTLINE(2,J) = IOUTLINE(2,I+1)
                      IOUTLINE(3,J) = IOUTLINE(3,I+1)
                      IOUTLINE(1,I+1) = N1
                      IOUTLINE(2,I+1) = N2
                      IOUTLINE(3,I+1) = N3
                    ENDIF
                    IFLAG = 1
                    GOTO 20
                  ENDIF
                ENDIF
              ENDDO
 20           CONTINUE
              IF (IFLAG.EQ.0) GOTO 30
            ENDDO
 30         IOUTRANG(NOUTRANG) = IOUT
            NNN = NNN+IOUT
          ENDDO
        ELSE
          NOUTRANG = 1
          IOUTRANG(NOUTRANG) = NOUTLINE
        ENDIF
        IF (ISTDOUT.EQ.0) THEN
          IF (NOUTRANG.EQ.1) THEN
              PRINT*,NOUTLINE,' segments'
          ELSE
            IF (ILANG.EQ.0) THEN
              PRINT*,NOUTLINE,' segments,',NOUTRANG,' groupes'
            ELSE
              PRINT*,NOUTLINE,' segments,',NOUTRANG,' groups'
            ENDIF
          ENDIF
        ENDIF
      ENDIF
      IF (NOUTLINE.GT.0) THEN
        DO I=1,NOUTLINE
          XOUT(1,I) = XF(IOUTLINE(2,I),IOUTLINE(1,I))
          XOUT(2,I) = XF(IOUTLINE(3,I),IOUTLINE(1,I))
          YOUT(1,I) = YF(IOUTLINE(2,I),IOUTLINE(1,I))
          YOUT(2,I) = YF(IOUTLINE(3,I),IOUTLINE(1,I))
          ZOUT(1,I) = ZF(IOUTLINE(2,I),IOUTLINE(1,I))
          ZOUT(2,I) = ZF(IOUTLINE(3,I),IOUTLINE(1,I))
        ENDDO
cc        print*,'***',NOUTLINE+5*NOUTRANG,NOUTLINEM
        IF ((NOUTLINE+5*NOUTRANG).LE.NOUTLINEM) THEN
          IFOUTLINE = 0
        ELSE
          IFOUTLINE = 1
        ENDIF
      ELSE
          IFOUTLINE = 1
      ENDIF
      END
