      SUBROUTINE EXAGERE(DFACX,DFACY,DFACZ,IOPT)
      INCLUDE 'com_coor.f'
      INCLUDE 'com_faces.f'
      INCLUDE 'com_options.f'
C
      IF (DFACX.EQ.0..AND.DFACY.EQ.0..AND.DFACZ.EQ.0.) RETURN
      CALL INV3X3(ROTA,ROTLOC,IERR)
      DO I=1,3
        DO J=1,3
          ROTA(J,I) = ROTLOC(J,I)
        ENDDO
      ENDDO
      CALL ROTATE(0)
      XMIN = BIG
      XMAX = -BIG
      YMIN = BIG
      YMAX = -BIG
      ZMIN = BIG
      ZMAX = -BIG
c
      IF (IFIX.GT.0) THEN
        TXFIX = X(IFIX) - BMIDX
        TYFIX = Y(IFIX) - BMIDY
        TZFIX = Z(IFIX) - BMIDZ
      ENDIF
      DO N=1,NUMBIS
        X(N) = X(N) + DFACX*DEPX(N)
        Y(N) = Y(N) + DFACY*DEPY(N)
        Z(N) = Z(N) + DFACZ*DEPZ(N)
        XMIN = MIN(XMIN,X(N)+XMED0)
        XMAX = MAX(XMAX,X(N)+XMED0)
        YMIN = MIN(YMIN,Y(N)+YMED0)
        YMAX = MAX(YMAX,Y(N)+YMED0)
        ZMIN = MIN(ZMIN,Z(N)+ZMED0)
        ZMAX = MAX(ZMAX,Z(N)+ZMED0)
      ENDDO
      IF (ICOURB.GT.0) THEN
        IF (IECHFX.EQ.0) CALL ARONDI(XMIN,XMAX,XECH,PROPX,NECHX,NBECH)
        IF (IECHFY.EQ.0) CALL ARONDI(YMIN,YMAX,YECH,PROPY,NECHY,NBECH)
        IF (IECHFZ.EQ.0) CALL ARONDI(ZMIN,ZMAX,ZECH,PROPZ,NECHZ,NBECH)
      ENDIF
      DO N=1,NF
        DO I=1,NDS2
          XF(I,N) = X(NFAC(I,N))
          YF(I,N) = Y(NFAC(I,N))
          ZF(I,N) = Z(NFAC(I,N))
        ENDDO
      ENDDO
      IF (NRECONMAX.GT.1) CALL SYMETR(NF,NRECONMAX,XMED2,YMED2)
      BBN0 = SQRT(BX**2+BY**2+BZ**2)
      BXSAUV = BX
      BYSAUV = BY
      BZSAUV = BZ
      BX = -BIG
      BY = -BIG
      BZ = -BIG
      BIDX = BIG
      BIDY = BIG
      BIDZ = BIG
      DO N=1,NF
        DO I=1,NDS
          BX = MAX(XF(I,N),BX)
          BY = MAX(YF(I,N),BY)
          BZ = MAX(ZF(I,N),BZ)
          BIDX = MIN(XF(I,N),BIDX)
          BIDY = MIN(YF(I,N),BIDY)
          BIDZ = MIN(ZF(I,N),BIDZ)
        ENDDO
      ENDDO
      IF (ICOURXYZ.NE.0) THEN
        BX = BX*1.2
        BY = BY*1.2
        BZ = BZ*1.2
      ENDIF
C
      BIDMIDX = 0.5*(BX+BIDX)
      BIDMIDY = 0.5*(BY+BIDY)
      BIDMIDZ = 0.5*(BZ+BIDZ)
      BX0 = BX - BIDMIDX
      BY0 = BY - BIDMIDY
      BZ0 = BZ - BIDMIDZ
C
      IF (IOPT.EQ.0) THEN
        BMIDX = BIDMIDX
        BMIDY = BIDMIDY
        BMIDZ = BIDMIDZ
      ELSEIF(NFACE.GT.NF) THEN
        IF (NFACE.EQ.2*NF) THEN
          IF (IDEMI.LE.1) THEN
            BMIDX = BIDMIDX
          ELSE
            BMIDY = BIDMIDY
          ENDIF
        ELSE
            BMIDX = BIDMIDX
            BMIDY = BIDMIDY
        ENDIF
      ENDIF
      IF (IECHFX.NE.0) THEN
        BX = BX00
        IF (ICOURB.LT.0) THEN
          BX0 = BX*FACEXAX
          BMIDX = (XBMAX+XBMIN)*0.5*FACEXAX
        ELSE
          BX0 = BX
c          BMIDX = (XBMAX+XBMIN)*0.5
        ENDIF
      ENDIF
      IF (IECHFY.NE.0) THEN
        BY = BY00
        IF (ICOURB.LT.0) THEN
          BY0 = BY*FACEXAY
          BMIDY = (YBMAX+YBMIN)*0.5*FACEXAY
        ELSE
          BY0 = BY
c          BMIDY = (YBMAX+YBMIN)*0.5
        ENDIF
      ENDIF
      IF (IECHFZ.NE.0) THEN
        BZ = BZ00
        IF (ICOURB.LT.0) THEN
          BZ0 = BZ*FACEXAZ
          BMIDZ = (ZBMAX+ZBMIN)*0.5*FACEXAZ
        ELSE
          BZ0 = BZ
c          BMIDZ = (ZBMAX+ZBMIN)*0.5
        ENDIF
      ENDIF
C
      IF (IFIX.GT.0) THEN
        BMIDX = X(IFIX) - TXFIX
        BMIDY = Y(IFIX) - TYFIX
        BMIDZ = Z(IFIX) - TZFIX
      ENDIF
c      print*,'passe',bmidz
      DO N=1,NF4
        DO I=1,NDS2
          XF(I,N) = XF(I,N) - BMIDX
          YF(I,N) = YF(I,N) - BMIDY
          ZF(I,N) = ZF(I,N) - BMIDZ
        ENDDO
      ENDDO
C
      IF (NBCORN.NE.0) THEN
        DO I=1,NUMNP
          X(I) = X(I) + XMED
          Y(I) = Y(I) + YMED
          Z(I) = Z(I) + ZMED
        ENDDO
        CALL RAYTMS(X,Y,Z,ICOR,RAYON0,BIG,NUMNP,NBCORN)
        DO I=1,NUMNP
          X(I) = X(I) - XMED
          Y(I) = Y(I) - YMED
          Z(I) = Z(I) - ZMED
        ENDDO
      ENDIF
C
      XMED = 0.5*XMED2 + BMIDX
      YMED = 0.5*YMED2 + BMIDY
      ZMED = ZMED + BMIDZ
C
      IF (NOUTLINE.GT.0) CALL CALCOUTLINE(NFACE,1)
      BZ = BZ0
      IF (NFACE.EQ.NF) THEN
        BX = BX0
        BY = BY0
      ELSEIF(NFACE.EQ.2*NF) THEN
        IF (IDEMI.LE.1) THEN
          BY = 2.*BY0
        ELSE
          BX = 2.*BX0
        ENDIF
      ELSE
        BX = 2.*BX0
        BY = 2.*BY0
      ENDIF
      BNOR = SQRT(BX**2+BY**2+BZ**2)
      DIST1 = DIST0*SQRT(BX**2+BY**2+BZ**2)/BBN0
      DIST  = DIST*DIST1/DIST0
      DIST0 = DIST1
      XPUP(1) = DIST
      XPUP(2) = DIST
      XPUP(3) = DIST
      CALL INV3X3(ROTA,ROTLOC,IERR)
      DO I=1,3
        DO J=1,3
          ROTA(J,I) = ROTLOC(J,I)
        ENDDO
      ENDDO
      CALL ROTATE(0)
      END
