      SUBROUTINE ECHEL(IOPT,YLAR)
C
      INCLUDE 'com_coor.f'
      INCLUDE 'com_faces.f'
      INCLUDE 'com_options.f'
      INCLUDE 'com_vieucu.f'
C
      REAL*4    XC(8),YC(8),ZC(8),ROTAINV(3,3)
      INTEGER   IOPO(8),ISUC(4),IPERM(4,6)
      LOGICAL*4 IFBON(6)
      DATA ISUC  / 2,3,4,1 /
      DATA IOPO  / 7,8,5,6,3,4,1,2 /
      DATA IPERM / 5,8,4,1 , 2,3,7,6 , 5,1,2,6 ,
     &             4,8,7,3 , 1,4,3,2 , 8,5,6,7 /
C
C Echelles
C
      IF (IECBOI.GT.0) THEN
        NOGRILLE = MOD((IECBOI+1)/2,2)
      ELSE
        NOGRILLE = 1
      ENDIF
      CALL PROBOI(XC,YC,ZC)
      SENS = REAL(ISENS)
      IF (IPERSP.EQ.1) THEN
        DO I=1,6
          U1 = XC(IPERM(3,I))-XC(IPERM(1,I))
          U2 = YC(IPERM(3,I))-YC(IPERM(1,I))
          U3 = ZC(IPERM(3,I))-ZC(IPERM(1,I))
          V1 = XC(IPERM(4,I))-XC(IPERM(2,I))
          V2 = YC(IPERM(4,I))-YC(IPERM(2,I))
          V3 = ZC(IPERM(4,I))-ZC(IPERM(2,I))
          PMIXT = ( U2*V3+U3*V1+U1*V2 - (U3*V2+U1*V3+U2*V1) )*SENS
          IFBON(I) = PMIXT.GE.0.
        ENDDO
      ELSE
        DO I=1,6
          U1 = XC(IPERM(3,I))-XC(IPERM(1,I))
          U2 = YC(IPERM(3,I))-YC(IPERM(1,I))
          U3 = ZC(IPERM(3,I))-ZC(IPERM(1,I))
          V1 = XC(IPERM(4,I))-XC(IPERM(2,I))
          V2 = YC(IPERM(4,I))-YC(IPERM(2,I))
          V3 = ZC(IPERM(4,I))-ZC(IPERM(2,I))
          OBS1 = XPUP(1)-.25*
     &   (XC(IPERM(1,I))+XC(IPERM(2,I))+XC(IPERM(3,I))+XC(IPERM(4,I)))
          OBS2 = XPUP(2)-.25*
     &   (YC(IPERM(1,I))+YC(IPERM(2,I))+YC(IPERM(3,I))+YC(IPERM(4,I)))
          OBS3 = XPUP(3)-.25*
     &   (ZC(IPERM(1,I))+ZC(IPERM(2,I))+ZC(IPERM(3,I))+ZC(IPERM(4,I)))
          PMIXT = ( (U2*V3-U3*V2)*OBS1
     &          +   (U3*V1-U1*V3)*OBS2
     &          +   (U1*V2-U2*V1)*OBS3 )*SENS
          IFBON(I) = PMIXT.GE.0.
        ENDDO
      ENDIF
C
      IF (IOPT.GE.0.AND.IBOITE.NE.0) THEN
        CALL GSLW(1)
C Projetion de la courbe sur la boite
        IF (ICOURXYZ.NE.0) THEN
          CALL GSCOL(4)
          IMAIL2 = IABS(IMAILL)
          IF (IMAIL2.EQ.2.OR.IMAIL2.EQ.5) THEN
            RBOUL = (YDMAX-YDMIN)/120.
          ELSEIF(IMAIL2.EQ.4.OR.IMAIL2.EQ.7) THEN
            RBOUL = (YDMAX-YDMIN)/60.
          ELSE
            RBOUL = (YDMAX-YDMIN)/250.
          ENDIF
          CALL GSMS(5)
          CALL GSMB(RBOUL,RBOUL)
          CALL INV3X3(ROTA,ROTAINV,IERR)
          DO I=1,6
            IF (.NOT.IFBON(I)) THEN
              CALL PROPRO(I,X(1),Y(1),Z(1),ROTAINV,SENS,X0,Y0)
              CALL GSMOVE(X0,Y0)
              DO N=2,NUMNP
                CALL PROPRO(I,X(N),Y(N),Z(N),ROTAINV,SENS,X1,Y1)
                IF (IMAILL.GT.0) CALL GSLINE(X1,Y1)
                IF (IMAIL2.GE.2) CALL GSMARK(X0,Y0)
                X0 = X1
                Y0 = Y1
              ENDDO
              IF (IMAIL2.GE.2) CALL GSMARK(X1,Y1)
            ENDIF
          ENDDO
        ENDIF
        CALL GSCOL(ICOLAX)
        DO I=1,6
          IF (.NOT.IFBON(I)) THEN
            CALL GSMOVE(XBOITE(IPERM(1,I)),YBOITE(IPERM(1,I)))
            CALL GSLINE(XBOITE(IPERM(2,I)),YBOITE(IPERM(2,I)))
            CALL GSLINE(XBOITE(IPERM(3,I)),YBOITE(IPERM(3,I)))
            CALL GSLINE(XBOITE(IPERM(4,I)),YBOITE(IPERM(4,I)))
            CALL GSLINE(XBOITE(IPERM(1,I)),YBOITE(IPERM(1,I)))
          ENDIF
        ENDDO
cc        IF (IECBOI.GE.3) THEN
        IF (NOGRILLE.EQ.0) THEN
          CALL GSLT(1)
          CALL GSLW(-1)
          DO I=1,6
            IF (.NOT.IFBON(I)) THEN
              IF (I.EQ.1) THEN
                CALL GRILLE(PROPY,NECHY,XC,YC,ZC,8,5,4,1)
                CALL GRILLE(PROPZ,NECHZ,XC,YC,ZC,4,8,1,5)
              ELSEIF(I.EQ.2) THEN
                CALL GRILLE(PROPY,NECHY,XC,YC,ZC,7,6,3,2)
                CALL GRILLE(PROPZ,NECHZ,XC,YC,ZC,3,7,2,6)
              ELSEIF(I.EQ.3) THEN
                CALL GRILLE(PROPZ,NECHZ,XC,YC,ZC,2,6,1,5)
                CALL GRILLE(PROPX,NECHX,XC,YC,ZC,6,5,2,1)
              ELSEIF(I.EQ.4) THEN
                CALL GRILLE(PROPZ,NECHZ,XC,YC,ZC,4,8,3,7)
                CALL GRILLE(PROPX,NECHX,XC,YC,ZC,7,8,3,4)
              ELSEIF(I.EQ.5) THEN
                CALL GRILLE(PROPX,NECHX,XC,YC,ZC,2,1,3,4)
                CALL GRILLE(PROPY,NECHY,XC,YC,ZC,3,2,4,1)
              ELSE
                CALL GRILLE(PROPX,NECHX,XC,YC,ZC,6,5,7,8)
                CALL GRILLE(PROPY,NECHY,XC,YC,ZC,7,6,8,5)
              ENDIF
            ENDIF
          ENDDO
          CALL GSLT(0)
          CALL GSLW(1)
        ENDIF
        IF (IECBOI.GT.0) THEN
          INUM = MOD(IECBOI,2)
          IF (IECBOI.GT.4) INUM = INUM+10
          PRES = -BIG
          IF (IPERSP.EQ.1) THEN
            DO I=1,8
              TOTO = SENS*(XC(I)+YC(I)+ZC(I))
              IF (TOTO.GT.PRES) THEN
                IPRES = I
                PRES = TOTO
              ENDIF
            ENDDO
          ELSE
            DO I=1,8
              TOTO = -SENS*((XC(I)-XPUP(1))**2
     &                     +(YC(I)-XPUP(2))**2
     &                     +(ZC(I)-XPUP(3))**2)
              IF (TOTO.GT.PRES) THEN
                IPRES = I
                PRES = TOTO
              ENDIF
            ENDDO
          ENDIF
          ILOIN = IOPO(IPRES)
          TAILLE = YLAR*.045
          CALL GSLSS(IFONT1)
          DO I=1,4
            J = ISUC(I)
            K = I+4
            L = J+4
            CALL TICS(XC,YC,ZC,I,J,IPRES,ILOIN,TAILLE,INUM)
            CALL TICS(XC,YC,ZC,I,K,IPRES,ILOIN,TAILLE,INUM)
            CALL TICS(XC,YC,ZC,K,L,IPRES,ILOIN,TAILLE,INUM)
          ENDDO
        ENDIF
        CALL GSLW(0)
      ELSEIF(IOPT.EQ.-2) THEN
        CALL GSCOL(ICTFON)
        IF (IFOUTLINE.EQ.0) THEN
          IRESTE = 1
          DO I=1,NOUTRANG
            NN = IOUTRANG(I)
            IF (NN.GE.2) THEN
              CALL GSPLNE_SPEED(NN,XXOUT(IRESTE,1),YYOUT(IRESTE,1))
              IRESTE = IRESTE+NN-1
            ENDIF
            CALL GSSEG_SPEED(XXOUT(IRESTE,1),YYOUT(IRESTE,1)
     &                      ,XXOUT(IRESTE,2),YYOUT(IRESTE,2))
            IRESTE = IRESTE+1
          ENDDO
          IF (IRESTE.LE.NOUTLINE) 
     &      CALL GSSEG_SPEED(XXOUT(IRESTE,1),YYOUT(IRESTE,1)
     &                      ,XXOUT(IRESTE,2),YYOUT(IRESTE,2))
        ENDIF
        DO I=1,NPREC
          CALL GSPLNEC(4,XPREC(1,I),YPREC(1,I))
        ENDDO
        IF (IFOUTLINE.EQ.0) THEN
          CALL GSCOL(ICOLAX)
          NPREC = 0
          DO I=1,6
            IF (IFBON(I)) THEN
              NPREC = NPREC+1
              XPREC(1,NPREC) = XBOITE(IPERM(1,I))
              XPREC(2,NPREC) = XBOITE(IPERM(2,I))
              XPREC(3,NPREC) = XBOITE(IPERM(3,I))
              XPREC(4,NPREC) = XBOITE(IPERM(4,I))
              YPREC(1,NPREC) = YBOITE(IPERM(1,I))
              YPREC(2,NPREC) = YBOITE(IPERM(2,I))
              YPREC(3,NPREC) = YBOITE(IPERM(3,I))
              YPREC(4,NPREC) = YBOITE(IPERM(4,I))
              CALL GSPLNEC(4,XPREC(1,NPREC),YPREC(1,NPREC))
            ENDIF
          ENDDO
          CALL GSCOL(1)
          IRESTE = 1
          DO K=1,NOUTRANG
            NN = IOUTRANG(K)
            II = IRESTE+NN-1
            DO I=IRESTE,II
              CALL ROTATION(XOUT(1,I),YOUT(1,I),ZOUT(1,I),ROTA
     &                     ,XR1,YR1,ZR1)
              CALL PROJEC(XR1,YR1,ZR1,SENS,XXOUT(I,1),YYOUT(I,1),IPERSP
     &                   ,XPUP,DIST)
            ENDDO
            CALL ROTATION(XOUT(2,II),YOUT(2,II),ZOUT(2,II)
     &                   ,ROTA,XR2,YR2,ZR2)
            CALL PROJEC(XR2,YR2,ZR2,SENS,XXOUT(II,2),YYOUT(II,2)
     &                 ,IPERSP,XPUP,DIST)
            IF (NN.GE.2) THEN
              CALL GSPLNE_SPEED(NN,XXOUT(IRESTE,1),YYOUT(IRESTE,1))
              IRESTE = II
            ENDIF
            CALL GSSEG_SPEED(XXOUT(IRESTE,1),YYOUT(IRESTE,1)
     &                      ,XXOUT(IRESTE,2),YYOUT(IRESTE,2))
            IRESTE = IRESTE+1
          ENDDO
          IF (IRESTE.LE.NOUTLINE) THEN
            CALL ROTATION(XOUT(1,IRESTE),YOUT(1,IRESTE),ZOUT(1,IRESTE)
     &                   ,ROTA,XR1,YR1,ZR1)
            CALL ROTATION(XOUT(2,IRESTE),YOUT(2,IRESTE),ZOUT(2,IRESTE)
     &                   ,ROTA,XR2,YR2,ZR2)
            CALL PROJEC(XR1,YR1,ZR1,SENS,XXOUT(IRESTE,1),YYOUT(IRESTE,1)
     &                 ,IPERSP,XPUP,DIST)
            CALL PROJEC(XR2,YR2,ZR2,SENS,XXOUT(IRESTE,2),YYOUT(IRESTE,2)
     &                 ,IPERSP,XPUP,DIST)
            CALL GSSEG_SPEED(XXOUT(IRESTE,1),YYOUT(IRESTE,1)
     &                      ,XXOUT(IRESTE,2),YYOUT(IRESTE,2))
          ENDIF
        ENDIF
        CALL GSCOL(ICOLAXB)
        DO I=1,NCOTE
          CALL GSPLNEC(4,XCOTE(1,I),YCOTE(1,I))
        ENDDO
        CALL GSCOL(ICOLAX)
        IF (IFOUTLINE.EQ.0) THEN
          DO I=1,NPREC
            CALL GSPLNEC(4,XPREC(1,I),YPREC(1,I))
          ENDDO
        ELSE
          NPREC = 0
          DO I=1,6
            IF (IFBON(I)) THEN
              NPREC = NPREC+1
              XPREC(1,NPREC) = XBOITE(IPERM(1,I))
              XPREC(2,NPREC) = XBOITE(IPERM(2,I))
              XPREC(3,NPREC) = XBOITE(IPERM(3,I))
              XPREC(4,NPREC) = XBOITE(IPERM(4,I))
              YPREC(1,NPREC) = YBOITE(IPERM(1,I))
              YPREC(2,NPREC) = YBOITE(IPERM(2,I))
              YPREC(3,NPREC) = YBOITE(IPERM(3,I))
              YPREC(4,NPREC) = YBOITE(IPERM(4,I))
              CALL GSPLNEC(4,XPREC(1,NPREC),YPREC(1,NPREC))
            ENDIF
          ENDDO
        ENDIF
      ELSEIF(IOPT.EQ.-3) THEN
        NCOTE = 0
        DO I=1,6
          IF (IFBON(I)) THEN
            NCOTE = NCOTE+1
            XCOTE(1,NCOTE) = XBOITE(IPERM(1,I))
            XCOTE(2,NCOTE) = XBOITE(IPERM(2,I))
            XCOTE(3,NCOTE) = XBOITE(IPERM(3,I))
            XCOTE(4,NCOTE) = XBOITE(IPERM(4,I))
            YCOTE(1,NCOTE) = YBOITE(IPERM(1,I))
            YCOTE(2,NCOTE) = YBOITE(IPERM(2,I))
            YCOTE(3,NCOTE) = YBOITE(IPERM(3,I))
            YCOTE(4,NCOTE) = YBOITE(IPERM(4,I))
          ENDIF
        ENDDO
        NPREC = NCOTE
        DO I=1,NCOTE
          XPREC(1,I) = XCOTE(1,I)
          XPREC(2,I) = XCOTE(2,I)
          XPREC(3,I) = XCOTE(3,I)
          XPREC(4,I) = XCOTE(4,I)
          YPREC(1,I) = YCOTE(1,I)
          YPREC(2,I) = YCOTE(2,I)
          YPREC(3,I) = YCOTE(3,I)
          YPREC(4,I) = YCOTE(4,I)
        ENDDO
        IF (NOUTLINE.GT.0) THEN
          DO I=1,NOUTLINE
            CALL ROTATION(XOUT(1,I),YOUT(1,I),ZOUT(1,I),ROTA
     &                   ,XR1,YR1,ZR1)
            CALL ROTATION(XOUT(2,I),YOUT(2,I),ZOUT(2,I),ROTA
     &                   ,XR2,YR2,ZR2)
            CALL PROJEC(XR1,YR1,ZR1,SENS,XXOUT(I,1),YYOUT(I,1),IPERSP
     &                 ,XPUP,DIST)
            CALL PROJEC(XR2,YR2,ZR2,SENS,XXOUT(I,2),YYOUT(I,2),IPERSP
     &                 ,XPUP,DIST)
          ENDDO
        ENDIF
        IF (IBOITE.EQ.2) THEN
          CALL GSCOL(ICOLAX)
          DO I=1,NCOTE
            CALL GSPLNEC(4,XCOTE(1,I),YCOTE(1,I))
          ENDDO
cc          IF (IECBOI.GE.3) THEN
          IF (NOGRILLE.EQ.0) THEN
            CALL GSLT(1)
            CALL GSLW(-1)
            DO I=1,6
              IF (IFBON(I)) THEN
                IF (I.EQ.1) THEN
                  CALL GRILLE(PROPY,NECHY,XC,YC,ZC,8,5,4,1)
                  CALL GRILLE(PROPZ,NECHZ,XC,YC,ZC,4,8,1,5)
                ELSEIF(I.EQ.2) THEN
                  CALL GRILLE(PROPY,NECHY,XC,YC,ZC,7,6,3,2)
                  CALL GRILLE(PROPZ,NECHZ,XC,YC,ZC,3,7,2,6)
                ELSEIF(I.EQ.3) THEN
                  CALL GRILLE(PROPZ,NECHZ,XC,YC,ZC,2,6,1,5)
                  CALL GRILLE(PROPX,NECHX,XC,YC,ZC,6,5,2,1)
                ELSEIF(I.EQ.4) THEN
                  CALL GRILLE(PROPZ,NECHZ,XC,YC,ZC,4,8,3,7)
                  CALL GRILLE(PROPX,NECHX,XC,YC,ZC,7,8,3,4)
                ELSEIF(I.EQ.5) THEN
                  CALL GRILLE(PROPX,NECHX,XC,YC,ZC,2,1,3,4)
                  CALL GRILLE(PROPY,NECHY,XC,YC,ZC,3,2,4,1)
                ELSE
                  CALL GRILLE(PROPX,NECHX,XC,YC,ZC,6,5,7,8)
                  CALL GRILLE(PROPY,NECHY,XC,YC,ZC,7,6,8,5)
                ENDIF
              ENDIF
            ENDDO
            CALL GSLT(0)
            CALL GSLW(1)
          ENDIF
        ENDIF
      ENDIF
      END
C-----------------------------------------------------------------------
      SUBROUTINE ECHELTR
C
      INCLUDE 'com_options.f'
      INCLUDE 'com_vieucu.f'
C
      DATA ZERO  / 0. /
C
C Translation
C
      CALL GSCOL(ICTFON)
      DO I=1,NPREC
        CALL GSPLNECT(4,XPREC(1,I),YPREC(1,I),DXTRAN0,DYTRAN0)
      ENDDO
      CALL GSCOL(ICOLAXB)
      DO I=1,NPREC
        CALL GSPLNECT(4,XPREC(1,I),YPREC(1,I),ZERO,ZERO)
      ENDDO
      CALL GSCOL(ICOLAX)
      DO I=1,NPREC
        CALL GSPLNECT(4,XPREC(1,I),YPREC(1,I),DXTRANS,DYTRANS)
      ENDDO
      END
C-----------------------------------------------------------------------
      SUBROUTINE GRILLE(PROP,NECH,X,Y,Z,I1,I2,J1,J2)
      INCLUDE 'com_options.f'
      DIMENSION PROP(*),X(*),Y(*),Z(*)
C
      SENS = REAL(ISENS)
      DO N=1,NECH
        X1 = X(I1) + PROP(N)*(X(I2)-X(I1))
        X2 = X(J1) + PROP(N)*(X(J2)-X(J1))
        Y1 = Y(I1) + PROP(N)*(Y(I2)-Y(I1))
        Y2 = Y(J1) + PROP(N)*(Y(J2)-Y(J1))
        Z1 = Z(I1) + PROP(N)*(Z(I2)-Z(I1))
        Z2 = Z(J1) + PROP(N)*(Z(J2)-Z(J1))
        CALL PROJEC(X1,Y1,Z1,SENS,XX1,YY1,IPERSP,XPUP,DIST)
        CALL PROJEC(X2,Y2,Z2,SENS,XX2,YY2,IPERSP,XPUP,DIST)
        CALL GSMOVE(XX1,YY1)
        CALL GSLINE(XX2,YY2)
      ENDDO
      END
C-----------------------------------------------------------------------
      SUBROUTINE PROPRO(I,XLOC,YLOC,ZLOC,ROTAINV,SENS,XP,YP)
      INCLUDE 'com_faces.f'
      INCLUDE 'com_options.f'
C
      CALL ROTATION(XLOC,YLOC,ZLOC,ROTAINV,XXX,YYY,ZZZ)
      IF (I.EQ.1) THEN
        CALL ROTATION(BX,YYY,ZZZ,ROTA,X,Y,Z)
      ELSEIF(I.EQ.2) THEN
        CALL ROTATION(-BX,YYY,ZZZ,ROTA,X,Y,Z)
      ELSEIF(I.EQ.3) THEN
        CALL ROTATION(XXX,BY,ZZZ,ROTA,X,Y,Z)
      ELSEIF(I.EQ.4) THEN
        CALL ROTATION(XXX,-BY,ZZZ,ROTA,X,Y,Z)
      ELSEIF(I.EQ.5) THEN
        CALL ROTATION(XXX,YYY,-BZ,ROTA,X,Y,Z)
      ELSE
        CALL ROTATION(XXX,YYY,BZ,ROTA,X,Y,Z)
      ENDIF
      CALL PROJEC(X,Y,Z,SENS,XP,YP,IPERSP,XPUP,DIST)
      END

