      SUBROUTINE LEG
C
      INCLUDE 'param.f'
      REAL*4 XXX(6),YYY(6)
C
C Legendes
C
      IF (FRANCAIS) THEN
        CALL COMMENTE_PS('Début des légendes',18)
      ELSE
        CALL COMMENTE_PS('Beginning of legends',20)
      ENDIF
      CALL METSACCENTS(1)
      IF (IPTILEG.EQ.1) THEN
        CALL GSLSS(IFONT3)
      ELSEIF(IPTILEG.EQ.2) THEN
        CALL GSLSS(IFONT1)
      ENDIF
      IOPT2 = ABS(IOPT)
      IF (IOPT2.GT.10) THEN
        IF (IPTILEG.EQ.0) THEN
          FAC = 1.
        ELSEIF(IPTILEG.EQ.1) THEN
          FAC = 0.65
        ELSE
          FAC = 0.45
        ENDIF
        DX1  = 3.5*TY
        DY1  = 3.5*TX
        DX2  = .75*TY
        DY2  = .75*TX
        DDXX = (XMAX-XMIN)*.02*SIZCAR*FAC
        YLEG = (NCOURB*YBOX+2.*TX)*FAC
        XLELE = 0.
        XLEG = 0.
        DO I=1,NCOURB
          IF (ILT(I).GE.0) XLELE = 4.
          XLEG = AMAX1(XLEG,TAILLE_CHAINE(LEGEND(I),NLEG))
        ENDDO
        XLEG = XLEG + (XLELE+3.)*DDXX
        IF (IOPT2.EQ.11) THEN
          X0 = XMIN + DX1
          X1 = X0   + XLEG
          Y1 = YMAX - DY1
          Y0 = Y1   - YLEG
          X2 = X0   + DX2
          X3 = X1   + DX2
          Y2 = Y0   - DY2
          Y3 = Y1   - DY2
        ELSEIF(IOPT2.EQ.12) THEN
          X0 = .5*(XMIN + XMAX - XLEG)
          X1 = X0   + XLEG
          Y1 = YMAX - DY1
          Y0 = Y1   - YLEG
          X2 = X0   + DX2
          X3 = X1   + DX2
          Y2 = Y0   - DY2
          Y3 = Y1   - DY2
        ELSEIF(IOPT2.EQ.13) THEN
          X0 = XMAX - DX1
          X1 = X0   - XLEG
          Y1 = YMAX - DY1
          Y0 = Y1   - YLEG
          X2 = X0   - DX2
          X3 = X1   - DX2
          Y2 = Y0   - DY2
          Y3 = Y1   - DY2
        ELSEIF(IOPT2.EQ.14) THEN
          X0 = XMAX - DX1
          X1 = X0   - XLEG
          Y0 = .5*(YMIN + YMAX - YLEG)
          Y1 = Y0   + YLEG
          X2 = X0   - DX2
          X3 = X1   - DX2
          Y2 = Y0   - DY2
          Y3 = Y1   - DY2
        ELSEIF(IOPT2.EQ.15) THEN
          X0 = XMAX - DX1
          X1 = X0   - XLEG
          Y1 = YMIN + DY1
          Y0 = Y1   + YLEG
          X2 = X0   - DX2
          X3 = X1   - DX2
          Y2 = Y0   + DY2
          Y3 = Y1   + DY2
        ELSEIF(IOPT2.EQ.16) THEN
          X0 = .5*(XMIN + XMAX - XLEG)
          X1 = X0   + XLEG
          Y1 = YMIN + DY1
          Y0 = Y1   + YLEG
          X2 = X0   + DX2
          X3 = X1   + DX2
          Y2 = Y0   + DY2
          Y3 = Y1   + DY2
        ELSEIF(IOPT2.EQ.17) THEN
          X0 = XMIN + DX1
          X1 = X0   + XLEG
          Y1 = YMIN + DY1
          Y0 = Y1   + YLEG
          X2 = X0   + DX2
          X3 = X1   + DX2
          Y2 = Y0   + DY2
          Y3 = Y1   + DY2
        ELSEIF(IOPT2.EQ.18) THEN
          X0 = XMIN + DX1
          X1 = X0   + XLEG
          Y0 = .5*(YMIN + YMAX - YLEG)
          Y1 = Y0   + YLEG
          X2 = X0   + DX2
          X3 = X1   + DX2
          Y2 = Y0   - DY2
          Y3 = Y1   - DY2
        ELSEIF(IOPT2.EQ.19) THEN
          X0 = .5*(XMIN + XMAX - XLEG)
          X1 = X0   + XLEG
          Y0 = .5*(YMIN + YMAX - YLEG)
          Y1 = Y0   + YLEG
          X2 = X0   + DX2
          X3 = X1   + DX2
          Y2 = Y0   - DY2
          Y3 = Y1   - DY2
        ENDIF
C
        CALL GSPATF(0)
        CALL GSPAT(16)
        IF (ICADLEG.EQ.0) THEN
          XXX(1) = X0
          XXX(2) = X0
          XXX(3) = X2
          XXX(4) = X3
          XXX(5) = X3
          XXX(6) = X1
          YYY(1) = Y1
          YYY(2) = Y0
          YYY(3) = Y2
          YYY(4) = Y2
          YYY(5) = Y3
          YYY(6) = Y1
          CALL MY_GSAREA(1,XXX,YYY,6)
C Fignolage...
          XXX(5) = X1
          YYY(5) = Y0
          CALL GSMOVE(XXX(2),YYY(2))
          CALL GSPLNE(2,XXX(5),YYY(5))
          CALL GSMOVE(XXX(5),YYY(5))
          CALL GSLINE(XXX(4),YYY(4))
        ELSE
          XXX(1) = X0
          XXX(2) = X0
          XXX(3) = X1
          XXX(4) = X1
          YYY(1) = Y1
          YYY(2) = Y0
          YYY(3) = Y0
          YYY(4) = Y1
          IF (ICADLEG.EQ.1) THEN
            CALL MY_GSAREA(1,XXX,YYY,4)
          ELSE
            CALL MY_GSAREA(0,XXX,YYY,4)
          ENDIF
        ENDIF
        CALL GSCOL(7)
ccc        CALL GSTA(2,4)
        XX1 = MIN(X0,X1) + DDXX
        XX2 = XX1 + DDXX*XLELE
        XX3 = XX2 + DDXX
        YY0 = MAX(Y0,Y1)
        DO 30 I=1,NCOURB
          YY1  = YY0 - (YBOX*(REAL(I)-.5) + TX)*FAC
          YYY1 = YY1 - YBOX*.25*FAC
          IF (ILT(I).GE.0) THEN
            CALL GSMOVE(XX1,YY1)
            IF (IMONO.EQ.1) THEN
              ICOLOR = ICOL(I)
            ELSE
              ICOLOR = 7
            ENDIF
            CALL GSCOL(ICOLOR)
            CALL GSLW(IGROS+IEPL(I))
            CALL GSLT(ILT(I))
            CALL GSLINE(XX2,YY1)
          ENDIF
          CALL GSLW(IGROS+1)
          CALL GSCOL(7)
          CALL GSCHAR(XX3,YYY1,NLEG,LEGEND(I))
          IF (NMARK(I).GT.0) THEN
            IF (IMONO.EQ.1) THEN
              CALL GSCOL(ICOLM(I))
            ELSE
              CALL GSCOL(7)
            ENDIF
            CALL GSMS(NMARK(I))
            CALL GSMB(TM(I)*XMB,TM(I)*YMB)
            IF (ILT(I).GE.0) THEN
              CALL GSMARK(XX1,YY1)
              CALL GSMARK(XX2,YY1)
            ELSE
              CALL GSMARK(.5*(XX1+XX2),YY1)
            ENDIF
          ENDIF
  30    CONTINUE
      ENDIF
      CALL GSCOL(7)
      CALL GSLW(IGROS+1)
      CALL GSLT(0)
      CALL METSACCENTS(0)
      IF (IPTILEG.NE.0) CALL GSLSS(IFONT2)
      IF (FRANCAIS) THEN
        CALL COMMENTE_PS('Fin des légendes',16)
      ELSE
        CALL COMMENTE_PS('End of legends',14)
      ENDIF
      END
