      SUBROUTINE BORD(NB2,XXX,YYY,ICOUL2,ICOUL,NN)
C
      INCLUDE 'com_coor.f'
      INCLUDE 'com_faces.f'
      INCLUDE 'com_options.f'
C
      DIMENSION XXX(4),YYY(4),NB2(4),ISUC(4)
      DATA ISUC / 2,3,4,1 /
C
      IF (NDS.EQ.3) THEN
        ITOTO = NB2(1)*NB2(2)*NB2(3)
      ELSE
        ITOTO = NB2(1)*NB2(2)*NB2(3)*NB2(4)
      ENDIF
      IF (ITOTO.EQ.0) THEN
        CALL GSLW(IEPBOR2)
        CALL GSQCOL(ICCOUR)
        IF (ICCOUR.NE.ICOUL2) CALL GSCOL(ICOUL2)
        NFR = NF*(NRECON-1)
        DO I=1,NDS
          IF (NB2(I).EQ.0) THEN
            II = ISUC(I)
            IF (II.GT.NDS) II = 1
            NNN  = NFAC(I,NN)
            NNNN = NFAC(II,NN)
            IP   = MIN(IPLAN(NNN),IPLAN(NNNN))
            IF ( NRECON.EQ.1 .OR. IP.EQ.0
     &      .OR.(ISYM.EQ.4.AND.(NRECON.EQ.2
     &      .AND.((ISYMR.EQ.0
     &     .AND.((IDEMI.EQ.2.AND.IP.EQ.3).OR.(IDEMI.NE.2.AND.IP.EQ.2)))
     &           .OR.(ISYMR.NE.0
     &        .AND.((NN.LE.NF.AND.IP.EQ.1).OR.(NN.GT.NF.AND.IP.EQ.2))))
     &      .OR.(NRECON.EQ.3.AND.(IP.EQ.3
     &        .OR.(NN.GT.NF.AND.NN.LE.NF*2.AND.IP.EQ.2)
     &        .OR.(NN.GT.NF*2.AND.IP.EQ.1)))))
     &      .OR.(ISYM.NE.4.AND.(NRECON.LT.ISYM.OR.IP.EQ.3)
     &           .AND.((IP.EQ.1
     &            .AND.(NN.LE.NF
     &    .OR.(MOD(NRECON,2).EQ.0.AND.NN.GT.NFR)))
     &             .OR.(IP.EQ.2.AND.MOD(NRECON,2).EQ.1
     &                         .AND.NN.GT.NFR)
     &           ))) THEN
              IF (IFRONT.GT.0) THEN
                IF (IREF(NNN).EQ.IREF(NNNN)) THEN
                  ICOUL3 = IREF(NNN)
                ELSE
                  IF (IOPREF.EQ.1) THEN
                    IF (NDS.EQ.3) THEN
                      ICOUL3 = IREF(NNN)
                    ELSE
                      IF (IREF(NNN).LE.0.OR.IREF(NNN).GE.16) THEN
                        ICOUL3 = IREF(NNNN)
                      ELSEIF (IREF(NNNN).EQ.0.OR.IREF(NNNN).GE.16) THEN
                        ICOUL3 = IREF(NNN)
                      ELSE
                        III = ISUC(II)
                        IF (III.GT.NDS) III=1
                        NNNNN = NFAC(III,NN)
                        IF (IREF(NNNNN).EQ.IREF(NNNN)) THEN
                          ICOUL3 = IREF(NNN)
                        ELSE
                          ICOUL3 = IREF(NNNN)
                        ENDIF
                      ENDIF
                    ENDIF
                  ELSE
                    ICOUL3 = 0
                  ENDIF
                ENDIF
                CALL GSCOL(ICREF(MOD(ICOUL3,16)))
              ENDIF
              CALL GSMOVE(XXX(I),YYY(I))
              CALL GSLINE(XXX(II),YYY(II))
              IF (IFRONT.GT.0) CALL GSCOL(ICOUL2)
            ENDIF
          ENDIF
        ENDDO
        CALL GSQCOL(ICCOUR2)
        IF (ICCOUR2.NE.ICCOUR) CALL GSCOL(ICCOUR)
ccc        IF (ICOUL2.NE.ICOUL) CALL GSCOL(ICOUL)
        CALL GSLW(0)
      ENDIF
      END
