     	SUBROUTINE LAYOUT_PACK_ENTRY( ISG )
C
C	THIS ROUTINE REPACKS LAYOUT ENTRIES AFTER ENTRY DELETE.
C
C	ISG: SEGMENT NUMBER TO BE STRIPPED.
C
     	INCLUDE 'LAYOUT.CBS'
     	LOGICAL LOGLID, LOGLDT, LOGFIL
C
C  PACK MAIN ENTRY LIST FIRST...
C
     	K = 0
     	IT= ISG
     	LOGLDT = .FALSE.
     	LOGLID = .FALSE.
     	LOGFIL = .FALSE.
     	DO  111 I=1, NLC
     	    IF( NSN(I).EQ.IT ) THEN
     		IF( NFL(I).GT.0 .AND. .NOT.LOGFIL ) LOGFIL = .TRUE.
     		GOTO 111
     	    ENDIF
     	    K = K + 1
     	    IF( K.EQ.I ) GOTO 111
     	    PEN(K) = PEN(I)
     	    NSN(K) = NSN(I)
     	    NFL(K) = NFL(I)
     	    RAN(K) = RAN(I)
     	    ZXF(K) = ZXF(I)
     	    ZYF(K) = ZYF(I)
     	    DO  J=1, MNS
     		P00(J,K) = P00(J,I)
     	    ENDDO
     	    JK = NID(K)
     	    JI = NID(I)
     	    NID(K) = NID(I)
     	    IF( JK.EQ.8 ) THEN		!TEXT ENTRY
     		IK = LAYOUT_LDT( K )
     		LDT(IK) = 0
     		LOGLDT = .TRUE.
     	    ENDIF
     	    IF( JK.EQ.9 .AND. P00(3,K).NE.2.0 ) THEN	!LINE ENTRY
     		IK = LAYOUT_LID( K )
     		LID(IK) = 0
     		LOGLID = .TRUE.
     	    ENDIF
     	    IF( JI.EQ.8 ) THEN		!TEXT ENTRY
     		IK = LAYOUT_LDT( I )
     		LDT(IK) = K
     	    ENDIF
     	    IF( JI.EQ.9 .AND. P00(3,I).NE.2.0 ) THEN	!LINE ENTRY
     		IK = LAYOUT_LID( I )
     		LID(IK) = K
     	    ENDIF
111	CONTINUE
     	IF( K.LT.NLC ) THEN
     	    DO  I= K+1, NLC
     		JI = NID(I)
     		IF( JI.EQ.8 ) THEN
     		    IK = LAYOUT_LDT( I )
     		    LDT(IK) = 0
     		    LOGLDT = .TRUE.
     		ENDIF
     		IF( JI.EQ.9 ) THEN
     		    IK = LAYOUT_LID( I )
     		    LID(IK) = 0
     		    LOGLID = .TRUE.
     		ENDIF
     	    ENDDO
     	ENDIF
     	NLC = K				!RESET ENTRY COUNTER
C
C  PACK TEXT/LINE/FILL ENTRY LIST NEXT...
C
     	IF( LOGLDT ) CALL LAYOUT_PACK_LDT
     	IF( LOGLID ) CALL LAYOUT_PACK_LID
     	IF( LOGFIL ) CALL LAYOUT_PACK_NFG

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PACK_LDT

     	INCLUDE 'LAYOUT.CBS'

     	K = 0
     	DO  I=1, NTX
     	    IF( LDT(I).NE.0 ) THEN
     		K = K + 1
     		LDT(K) = LDT(I)
     		TXT(K) = TXT(I)
     	    ENDIF
     	ENDDO
     	NTX = K				!RESET TEXT ENTRY COUNTER

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PACK_LID

     	INCLUDE 'LAYOUT.CBS'

     	K = 0
     	DO  I=1, NCU
     	    IF( LID(I).NE.0 ) THEN
     		K = K + 1
     		LID(K) = LID(I)
     		DO  J=1, MNP
     		    XSC(J,K) = XSC(J,I)
     		    YSC(J,K) = YSC(J,I)
     		ENDDO
     	    ENDIF
     	ENDDO
     	NCU = K				!RESET LINE ENTRY COUNTER

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PACK_NFG
C
C	THIS ROUTINE REPACKS THE FILL GROUPS.
C
     	INCLUDE 'LAYOUT.CBS'
     	LOGICAL SKIP

     	IK = 1
     	DO  I=1, NFG
     	    SKIP = .TRUE.
     	    DO  J=1, NLC
     		IF( NFL(J).EQ.I ) THEN
     		    NFL(J) = IK
     		    SKIP = .FALSE.
     		ENDIF
     	    ENDDO
     	    IF( .NOT. SKIP ) THEN
     		NFP(IK) = NFP(I)
     		IK = IK+1
     	    ENDIF
     	ENDDO
     	NFG = IK-1

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PACK_NLG
C
C	THIS ROUTINE RESORTS PICKED SEGMENT NUMBERS.
C
     	INCLUDE 'LAYOUT.CBS'

     	K = 0
     	DO I=1, NLG
     	   IF( NLS(I).GT.0 ) THEN
     	       K = K + 1
     	       NLS(K) = NLS(I)
     	   ENDIF
     	ENDDO
     	NLG = K

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PACK_SEG
C
C	THIS ROUTINE REPACKS ENTRY SEGMENT NUMBERS
C	TO PREVENT SEGMENT NUMBER FROM GETTING TOO BIG.
C
     	INCLUDE 'LAYOUT.CBS'
     	LOGICAL SKIP

     	CALL IFANSI_VIDEO(30)
     	WRITE(6,1234)
1234	FORMAT('$Repacking layout segment pointers... please wait...')

     	IK = NSG+1
     	DO  I= NSG+1, KSG
     	    SKIP = .TRUE.
     	    DO  J=1, NLC
     		IS = NSN(J)
     		IF( IS.EQ.I ) THEN
     		    IF( IS.GT.IK ) THEN
     			NSN(I) = IK
     			CALL IFSEG_RENAME( IS, IK )
     			DO  K=1, NLG
     			    IF( NLS(K).EQ.IS ) THEN
     				NLS(K) = IK
     				GOTO 111
     			    ENDIF
     			ENDDO
     		    ENDIF
111     	    SKIP = .FALSE.
     	        ENDIF
     	    ENDDO
     	    IF( .NOT. SKIP ) IK = IK + 1
     	ENDDO
     	IF( .NOT. SKIP ) KSG = IK - 1

     	CALL IFANSI_VIDEO(47)
     	RETURN
     	END

