     	SUBROUTINE LAYOUT_PICK( TEXT )
C
C  PROGRAMMER: R.S. ZHOU		JUNE-1986
C
C	THIS ROUTINE PICKS LAYOUT ENTRIES FOR TRANSFORMS AND
C	THEN HIGHLIGHTS THE SEGMENTS BY MAKING THEM BLINKING.
C
    	INCLUDE 'LAYOUT.CBS'
     	PARAMETER NKS= 18
     	CHARACTER KEY*3, KWD(NKS)*3, TEXT*(*)
     	DIMENSION KP(2), RP(2)

     	DATA KWD / 'ALL',
     +  'WHI', 'RED', 'GRE', 'BLU', 'CYA', 'PUR', 'YEL',
     +  'BAR', 'BOX', 'ARC', 'OBL', 'POL', 'ARR', 'SYM',
     +  'TEX', 'LIN', 'FIL' /

     	NCH = IFMISC_NEXT( TEXT )
     	IF( NCH.EQ.0 ) THEN
     	    WRITE(6,1000)
1000	FORMAT('$Select what? ')
     	    READ(5,1001,END=999) TEXT
1001	FORMAT(A)
     	    IF( TEXT.EQ.' ' ) GOTO 999
     	    NCH = IFMISC_STRIP( TEXT )
     	ENDIF
     	NLGOLD = NLG			!SAVE THE CURRENT "NLG"
C
C  TRY TO DECODE ENTRY RANGE NUMBERS FIRST...
C
    	NCH = IFMISC_DECODE( TEXT, 2, RP, KP )
    	IF( NCH.EQ.0 ) GOTO 222
C
C  PICK ENTRIES BY RANGE POINTERS...
C
     	CALL LAYOUT_PICK_NUMBER( INT(RP(1)), INT(RP(2)) )
     	GOTO 999
C
C  TRY THE KEYWORD ENTRIES NEXT...
C
222	KEY = TEXT(1:3)
     	DO IK = 1, NKS
     	   IF( KEY.EQ.KWD(IK) ) GOTO 333
     	ENDDO
     	CALL LAYOUT_ERROR(2)
     	GOTO 999
C
C  PICK BY KEYWORD...
C
333	IF( IK.EQ.1 ) THEN
     	    CALL LAYOUT_PICK_NUMBER(1,NLC)
     	ELSE IF( IK.GT.1 .AND. IK.LT.9 ) THEN
     	    CALL LAYOUT_PICK_COLOR( IK-1 )
     	ELSE IF( IK.GT.8 .AND. IK.LT.NKS ) THEN
     	    CALL LAYOUT_PICK_ID( IK-8 )
     	ELSE IF( IK.EQ.NKS ) THEN
     	    IF( NFG.EQ.0 ) THEN
     		CALL LAYOUT_ERROR(2)
     	    ELSE
     		IK = 0
     		NCH = IFMISC_NEXT( TEXT )
     		IF( NCH.GT.0 ) THEN
     		    DECODE( NCH, 444, TEXT, ERR=555 ) IK
444		    FORMAT(I)
     		    IF( IK.LT.1 .OR. IK.GT.NFG ) GOTO 555
     		ENDIF
     		CALL LAYOUT_PICK_FILL( IK )
     	    ENDIF
     	ENDIF
999	IF( BLINK.GT.0 .AND. NLG.GT.NLGOLD ) CALL IFINIT_DUMP
     	RETURN
555	CALL LAYOUT_ERROR(2)
     	RETURN
    	END

     	SUBROUTINE LAYOUT_PICK_ID( ID )
C
C	THIS ROUTINE SELECTS LAYOUT ENTRIES FOR TRANSFORM
C	BY ENTRY ID.
C
     	INCLUDE 'LAYOUT.CBS'

     	IT = ID
     	DO 111 I = 1, NLC
     	   IF( NID(I).NE.IT ) GOTO 111
     	   IS = NSN(I)
    	   DO K = 1, NLG
    	      IF( NLS(K).EQ.IS ) GOTO 111
    	   ENDDO
    	   NLG = NLG + 1
    	   NLS(NLG) = IS
     	   IF(BLINK.GT.0) CALL IFSEG_BLINK(IS)
111	CONTINUE

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PICK_COLOR( IC )
C
C	THIS ROUTINE SELECTS LAYOUT ENTRIES FOR TRANSFORM
C	BY ENTRY COLOR/PEN CODE.
C
     	INCLUDE 'LAYOUT.CBS'

     	IPN = IC
     	DO 111 I = 1, NLC
     	   IF( PEN(I).NE.IPN ) GOTO 111
     	   IS = NSN(I)
    	   DO K = 1, NLG
    	      IF( NLS(K).EQ.IS ) GOTO 111
    	   ENDDO
    	   NLG = NLG + 1
    	   NLS(NLG) = IS
     	   IF(BLINK.GT.0) CALL IFSEG_BLINK(IS)
111	CONTINUE

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PICK_NUMBER( I1, I2 )
C
C	THIS ROUTINE SELECTS LAYOUT ENTRIES FOR TRANSFORM
C	BY TWO NUMBERS (I1,I2) IDENTIFYING THE SEQUENCE RANGE.
C
     	INCLUDE 'LAYOUT.CBS'
C
C  CONVERT I1,I2 TO ABSOLUTE RANGE IF NOT SO...
C
     	IT1 = I1
     	IT2 = I2
     	IF( IT1.LE.0 ) IT1 = NLC + IT1
     	IF( IT1.LT.1 ) IT1 = 1
     	IF( IT1.GT.NLC ) IT1 = NLC
     	IT2 = IT1 + IT2
     	IF( IT2.LT.1 ) IT2 = 1
     	IF( IT2.GT.NLC ) IT2 = NLC
     	IF( IT2.LT.IT1 ) THEN
     	    ITT = IT2
     	    IT2 = IT1
     	    IT1 = ITT
     	ENDIF
C
C  START THE PICKING...
C
     	DO 111 I = IT1, IT2
     	   IS = NSN(I)
    	   DO K = 1, NLG
    	      IF( NLS(K).EQ.IS ) GOTO 111
    	   ENDDO
    	   NLG = NLG + 1
    	   NLS(NLG) = IS
     	   IF(BLINK.GT.0) CALL IFSEG_BLINK(IS)
111	CONTINUE

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PICK_FILL( IFG )
C
C	THIS ROUTINE SELECTS LAYOUT ENTRIES FOR TRANSFORM
C	BY A FILL GROUP POINTER "IFG".
C	IF IFG=0, ALL EXISTING FILL GROUPS ARE SELECTED.
C
     	INCLUDE 'LAYOUT.CBS'

     	IT1 = IFG
     	IT2 = IT1
     	IF( IT1.EQ.0 ) THEN
     	    IT1 = 1
     	    IT2 = NFG
     	ENDIF

     	DO  111 I=IT1, IT2
     	    DO  J=1, NLC
     		IF( NFL(J).EQ.I ) THEN
     		    IS = NSN(J)
     		    DO  K=1, NLG
     			IF( NLS(K).EQ.IS ) GOTO 111
     		    ENDDO
     		    NLG = NLG + 1
     		    NLS(NLG) = IS
     		    IF(BLINK.GT.0) CALL IFSEG_BLINK(IS)
     		ENDIF
     	    ENDDO
111	CONTINUE

     	RETURN
     	END

     	SUBROUTINE LAYOUT_PICK_SEG( ISEG )
C
C  PROGRAMMER: R.S. ZHOU		JUNE-1986
C
C	THIS ROUTINE SELECTS A LAYOUT SEGMENT FOR TRANSFORM
C	BY ITS SEGMENT NUMBER "ISEG". IF "ISEG" IS ALREADY
C	PICKED, IT'S RELEASED FROM THE PICKED LIST.
C
    	INCLUDE 'LAYOUT.CBS'

     	IS = ISEG
     	DO K=1, NLG
     	   IF( NLS(K).EQ.IS ) GOTO 111
     	ENDDO
C
C  ADD A NEW ENTRY...
C
     	NLG = NLG + 1
     	NLS(NLG) = IS
     	IF( BLINK.GT.0 ) THEN
     	    CALL IFSEG_BLINK( IS )
     	    CALL IFINIT_DUMP
     	ENDIF
     	GOTO 999
C
C  RELEASE AN ENTRY...
C
111	IF( BLINK.GT.0 ) THEN
     	    CALL IFSEG_BLINK(-IS)
     	    CALL IFINIT_DUMP
     	ENDIF
     	DO I=K, NLG-1
     	   NLS(I) = NLS(I+1)
     	ENDDO
     	NLG = NLG - 1

999	RETURN
     	END

