      SUBROUTINE SYMISO(NSURF0,NSURF,X,Y,Z,V,NFIS,NEIS
     &                 ,NFMAX,NRECON,XMED,YMED,IOPT)
C
      INCLUDE 'com_options.f'
      DIMENSION X(4,*),Y(4,*),Z(4,*),V(4,*)
      INTEGER   NFIS(5,*),NEIS(*),INV(4)
      DATA INV / 2,1,4,3 /
C
      NSURF = NSURF0
      NSURF02 = 2*NSURF0
      NSURF03 = 3*NSURF0
C
C symetrie d'ordre 4 dans le plan xy
C
      IF (ISYMR.EQ.0) THEN
        IF ((BMIDX.NE.0..OR.BMIDY.NE.0..OR.BMIDZ.NE.0.)
     &       .AND.IOPT.EQ.0) THEN
          DO I=1,NSURF0
            DO K=1,4
              X(K,I) = X(K,I)-BMIDX
              Y(K,I) = Y(K,I)-BMIDY
              Z(K,I) = Z(K,I)-BMIDZ
            ENDDO
          ENDDO
        ENDIF
        IF (IOPT.EQ.1) THEN
          IF (NRECON.EQ.1) THEN
            DO I=1,NSURF0
              DO K=1,4
                X(K,I) = X(K,I)-XMED
                Y(K,I) = Y(K,I)-YMED
              ENDDO
            ENDDO
          ENDIF
          DO I=1,NSURF0
            IF (NFIS(5,I).LT.0) NFIS(5,I) = NFIS(5,I)+10
          ENDDO
        ENDIF
cc      print*,'ici',iopt,nrecon,idemi
        IF (NRECON.GT.1) THEN
          IF (IOPT.EQ.0.OR.NRECON.EQ.2) THEN
            DO I=1,NSURF0
              DO K=1,4
                Y(K,I) = Y(K,I)+YMED
              ENDDO
            ENDDO
          ENDIF
          IF (NSURF0.LE.NFMAX/2) THEN
            DO I=1,NSURF0
              IF (IDEMI.EQ.2) THEN
                DO K=1,4
                  X(K,I) = X(K,I) + XMED
                  KK = INV(K)
                  X(KK,I+NSURF0) = -X(K,I)
                  Y(KK,I+NSURF0) = Y(K,I)
                  Z(KK,I+NSURF0) = Z(K,I)
                  IF (IFVISO.NE.0) V(KK,I+NSURF0) = V(K,I)
                ENDDO
                IF (NFIS(5,I).NE.0) THEN
                  IF (ABS(X(1,I)).LT.EPSISO
     &           .AND.ABS(X(2,I)).LT.EPSISO
     &           .AND.ABS(X(3,I)).LT.EPSISO
     &           .AND.ABS(X(4,I)).LT.EPSISO) THEN
                    NFIS(5,I+NSURF0) = NFIS(5,I)-10
                  ELSE
                    NFIS(5,I+NSURF0) = NFIS(5,I)
                  ENDIF
                ELSE
                  NFIS(5,I+NSURF0) = 0
                ENDIF
              ELSE
                DO K=1,4
                  KK = INV(K)
                  X(KK,I+NSURF0) = X(K,I)
                  Y(KK,I+NSURF0) = -Y(K,I)
                  Z(KK,I+NSURF0) = Z(K,I)
                  IF (IFVISO.NE.0) V(KK,I+NSURF0) = V(K,I)
                ENDDO
                IF (NFIS(5,I).NE.0) THEN
                  IF (ABS(Y(1,I)).LT.EPSISO
     &           .AND.ABS(Y(2,I)).LT.EPSISO
     &           .AND.ABS(Y(3,I)).LT.EPSISO
     &           .AND.ABS(Y(4,I)).LT.EPSISO) THEN
                    NFIS(5,I+NSURF0) = NFIS(5,I)-10
                  ELSE
                    NFIS(5,I+NSURF0) = NFIS(5,I)
                  ENDIF
                ELSE
                  NFIS(5,I+NSURF0) = 0
                ENDIF
              ENDIF
            ENDDO
            NSURF = NSURF02
          ENDIF
          IF (NRECON.GE.3) THEN
            IF (IOPT.EQ.0.OR.NRECON.EQ.3) THEN
              DO I=1,NSURF
                DO K=1,4
                  X(K,I) = X(K,I)+XMED
                ENDDO
              ENDDO
            ENDIF
            IF (NSURF0.LE.NFMAX/3) THEN
              DO I=1,NSURF0
                DO K=1,4
                  KK = INV(K)
                  X(KK,I+NSURF0) = X(K,I)
                  X(KK,I+NSURF02) = -X(K,I)
                  Y(KK,I+NSURF02) = Y(K,I)
                  Z(KK,I+NSURF02) = Z(K,I)
                  IF (IFVISO.NE.0) V(KK,I+NSURF02) = V(K,I)
                ENDDO
                IF (NFIS(5,I).NE.0) THEN
                  IF (ABS(X(1,I)).LT.EPSISO
     &           .AND.ABS(X(2,I)).LT.EPSISO
     &           .AND.ABS(X(3,I)).LT.EPSISO
     &           .AND.ABS(X(4,I)).LT.EPSISO) THEN
                    NFIS(5,I+NSURF02) = NFIS(5,I)-10
                  ELSE
                    NFIS(5,I+NSURF02) = NFIS(5,I)
                  ENDIF
                ELSE
                  NFIS(5,I+NSURF02) = 0
                ENDIF
              ENDDO
              NSURF = NSURF03
            ENDIF
            IF (NRECON.EQ.4.AND.NSURF0.LE.NFMAX/4) THEN
              DO I=1,NSURF0
                DO K=1,4
                  KK = INV(K)
                  X(KK,I+NSURF03) = X(K,I+NSURF02)
                  Y(KK,I+NSURF03) = Y(K,I+NSURF0)
                  Z(KK,I+NSURF03) = Z(KK,I)
                  IF (IFVISO.NE.0) V(KK,I+NSURF03) = V(KK,I)
                ENDDO
                NFIS(5,I) = MIN(NFIS(5,I+NSURF0),NFIS(5,I+NSURF02))
                NFIS(5,I+NSURF0)  = NFIS(5,I)
                NFIS(5,I+NSURF02) = NFIS(5,I)
                NFIS(5,I+NSURF03) = NFIS(5,I)
              ENDDO
              NSURF = 4*NSURF0
            ENDIF
          ENDIF
        ENDIF
C symetrie de rotation d'ordre 4 dans le plan xy
      ELSE
        IF ((BMIDX.NE.0..OR.BMIDY.NE.0..OR.BMIDZ.NE.0.)
     &       .AND.IOPT.EQ.0) THEN
          DO I=1,NSURF0
            DO K=1,4
              X(K,I) = X(K,I)-BMIDX
              Y(K,I) = Y(K,I)-BMIDY
              Z(K,I) = Z(K,I)-BMIDZ
            ENDDO
          ENDDO
        ENDIF
        IF (IOPT.EQ.1) THEN
          IF (NRECON.EQ.1) THEN
            DO I=1,NSURF0
              DO K=1,4
                X(K,I) = X(K,I)-YMED
                Y(K,I) = Y(K,I)-XMED
              ENDDO
            ENDDO
          ENDIF
          DO I=1,NSURF0
            IF (NFIS(5,I).LT.0) NFIS(5,I) = NFIS(5,I)+10
          ENDDO
        ENDIF
        IF (NRECON.GT.1) THEN
          IF (IOPT.EQ.0.OR.NRECON.EQ.2) THEN
            DO I=1,NSURF0
              DO K=1,4
                Y(K,I) = Y(K,I)+XMED
              ENDDO
            ENDDO
          ENDIF
          IF (NSURF0.LE.NFMAX/2) THEN
            XMED2Y = YMED-2.*XMED
            DO I=1,NSURF0
              DO K=1,4
                X(K,I+NSURF0) = -Y(K,I)
                Y(K,I+NSURF0) = X(K,I)
                Z(K,I+NSURF0) = Z(K,I)
                IF (IFVISO.NE.0) V(KK,I+NSURF0) = V(K,I)
                X(K,I) = X(K,I)+YMED
                Y(K,I) = Y(K,I)+XMED2Y
              ENDDO
              IF (NFIS(5,I).NE.0) THEN
                IF (ABS(X(1,I)).LT.EPSISO
     &         .AND.ABS(X(2,I)).LT.EPSISO
     &         .AND.ABS(X(3,I)).LT.EPSISO
     &         .AND.ABS(X(4,I)).LT.EPSISO) THEN
                  NFIS(5,I+NSURF0) = NFIS(5,I)-10
                ELSE
                  NFIS(5,I+NSURF0) = NFIS(5,I)
                ENDIF
              ELSE
                NFIS(5,I+NSURF0) = 0
              ENDIF
            ENDDO
            NSURF = NSURF02
            IF (NRECON.GE.3) THEN
              IF (IOPT.EQ.0.OR.NRECON.EQ.3) THEN
                DO I=1,NSURF
                  DO K=1,4
                    Y(K,I) = Y(K,I)+XMED
                  ENDDO
                ENDDO
              ENDIF
              IF (NSURF0.LE.NFMAX/3) THEN
                XMED2Y2 = 2.*(YMED-XMED)
                DO I=1,NSURF0
                  DO K=1,4
                    X(K,I+NSURF02) = -X(K,I+NSURF0)+XMED2Y2
                    Y(K,I+NSURF02) = -Y(K,I+NSURF0)
                    Z(K,I+NSURF02) = Z(K,I)
                    IF (IFVISO.NE.0) V(KK,I+NSURF02) = V(K,I)
                  ENDDO
                  IF (NFIS(5,I).NE.0) THEN
                    IF (ABS(Y(1,I)).LT.EPSISO
     &             .AND.ABS(Y(2,I)).LT.EPSISO
     &             .AND.ABS(Y(3,I)).LT.EPSISO
     &             .AND.ABS(Y(4,I)).LT.EPSISO) THEN
                      NFIS(5,I+NSURF02) = NFIS(5,I)-10
                    ELSE
                      NFIS(5,I+NSURF02) = NFIS(5,I)
                    ENDIF
                  ELSE
                    NFIS(5,I+NSURF02) = 0
                  ENDIF
                ENDDO
                NSURF = NSURF03
              ENDIF
              IF (NRECON.EQ.4.AND.NSURF0.LE.NFMAX/4) THEN
                DO I=1,NSURF0
                  DO K=1,4
                    X(K,I+NSURF03) = -X(K,I)+XMED2Y2
                    Y(K,I+NSURF03) = -Y(K,I)
                    Z(K,I+NSURF03) = Z(K,I)
                    IF (IFVISO.NE.0) V(KK,I+NSURF03) = V(KK,I)
                  ENDDO
                  NFIS(5,I) = MIN(NFIS(5,I+NSURF0),NFIS(5,I+NSURF02))
                  NFIS(5,I+NSURF0)  = NFIS(5,I)
                  NFIS(5,I+NSURF02) = NFIS(5,I)
                  NFIS(5,I+NSURF03) = NFIS(5,I)
                ENDDO
                NSURF = 4*NSURF0
                DO I=1,NSURF
                  DO K=1,4
                    X(K,I) = X(K,I)+XMED-YMED
                  ENDDO
                ENDDO
              ENDIF
            ENDIF
          ENDIF
        ENDIF
      ENDIF
C
      IF (NSURF.EQ.NSURF02) THEN
        DO I=1,NSURF0
          IF (NFIS(5,I+NSURF0).LT.0) NFIS(5,I) = NFIS(5,I)-10
        ENDDO
      ELSEIF(NSURF.EQ.NSURF03) THEN
        DO I=1,NSURF0
          IF (NFIS(5,I+NSURF0).LT.0.OR.
     &        NFIS(5,I+NSURF02).LT.0) NFIS(5,I) = NFIS(5,I)-10
        ENDDO
      ENDIF
      IF (NSURF.GT.NSURF0) THEN
        K = 0
        DO I=1,NSURF
          IF (NFIS(5,I).LT.0) K = K+1
        ENDDO
        DO I=NSURF0+1,NSURF
          NEIS(I) = NEIS(MOD(I,NSURF0))
        ENDDO
        IF (ISTDOUT.EQ.0) THEN
          IF (ILANG.EQ.0) THEN
            PRINT*,K,' faces aux interfaces (éliminées)'
          ELSE
            PRINT*,K,' facets at interfaces (eliminated)'
          ENDIF
        ENDIF
      ENDIF
      END
C-----------------------------------------------------------------------
      SUBROUTINE SYMETRISE(NRECON0,IBACKTODEB)
      INCLUDE 'com_coor.f'
      INCLUDE 'com_faces.f'
      INCLUDE 'com_options.f'
C
      IF (NOUTLINE.GT.0) CALL CALCOUTLINE(NFACE,1)
      XMAMA = XMED+BX0
      YMAMA = YMED+BY0
      IF (NFACE.EQ.NF) THEN
        BX = BX0
        BY = BY0
        XMIMI = XMED-BX0
        YMIMI = YMED-BY0
      ELSEIF(NFACE.EQ.2*NF) THEN
        IF (IDEMI.LE.1) THEN
          BY = 2.*BY0
          XMIMI = XMED-BX0
          YMIMI = -YMAMA
        ELSE
          BX = 2.*BX0
          XMIMI = -XMAMA
          YMIMI = YMED-BY0
        ENDIF
      ELSE
        BX = 2.*BX0
        BY = 2.*BY0
        XMIMI = -XMAMA
        YMIMI = -YMAMA
      ENDIF
      CALL ARONDI(XMIMI,XMAMA,XECH,PROPX,NECHX,NBECH)
      CALL ARONDI(YMIMI,YMAMA,YECH,PROPY,NECHY,NBECH)
      BNOR = SQRT(BX**2+BY**2+BZ**2)
      CALL INV3X3(ROTA,ROTLOC,IERR)
      DO I=1,3
        DO J=1,3
          ROTA(J,I) = ROTLOC(J,I)
        ENDDO
      ENDDO
      IF (IBACKTODEB.EQ.0) CALL ROTATE(0)
      CALL MINMAX(NFACE,XMED3,YMED3,ZMED3)
      IF (XMED3.NE.0.) THEN
        DO N=1,NF4
          DO I=1,NDS2
            XF(I,N) = XF(I,N)-XMED3
          ENDDO
        ENDDO
      ENDIF
      IF (YMED3.NE.0.) THEN
        DO N=1,NF4
          DO I=1,NDS2
            YF(I,N) = YF(I,N)-YMED3
          ENDDO
        ENDDO
      ENDIF
Cfj      IF (ZMED3.NE.0.) THEN
Cfj        DO N=1,NF4
Cfj          DO I=1,NDS2
Cfj            ZF(I,N) = ZF(I,N)-ZMED3
Cfj          ENDDO
Cfj        ENDDO
Cfj      ENDIF
      IF (NSURF.GT.0.OR.NOUTLINE.GT.0) THEN
C
C Les isosurf se symetrisent mal si on va directement a 
C une symetrie donnee, mais marchent bien si on suit la sequence
C 1/4 2/4 3/4 4/4 1/4
C C'est bizarre mais au lieu de reflechir, on fait comme ca:
C
        IF (NSURF.GT.0) THEN
          NREC = NRECON0
 101      NREC = NREC+1
          IF (NREC.GT.NRECONMAX) NREC = 1
          CALL SYMISO(NSURF0,NSURF,XIS,YIS,ZIS,VIS,NFIS,NEIS
     &               ,NFMAX,NREC,XMED,YMED,1)
          IF (NREC.NE.NRECON) GOTO 101
        ENDIF
        IF (NOUTLINE.GT.0) CALL CALCOUTLINE(NFACE,0)
      ENDIF
      IF (IBACKTODEB.EQ.0) THEN
        CALL INV3X3(ROTA,ROTLOC,IERR)
        DO I=1,3
          DO J=1,3
            ROTA(J,I) = ROTLOC(J,I)
          ENDDO
        ENDDO
        CALL ROTATE(0)
      ENDIF
C
      END
