
C THIS SUBROUTINE LOOKS UP THE OLD STATEMENT LABEL AND COMPUTES
C WHAT THE NEW LABEL IS, CONVERTS IT TO ASCII CHARACTERS AND PLACES
C IT IN 'DIGIT'
C IT IS PART OF THE MAIN PROGRAM 'RESEQ.FOR'
C
	SUBROUTINE LOOKUP()
	LOGICAL*1 STRING(81), SPARE(81), DIGIT(6), NUMBER(11), NULL
	LOGICAL*1 SPAREB(81), SPAREA(81)
	INTEGER START, LABEL(500)
	EXTERNAL LEN
	DATA SPAREA/81*' '/
C
C THE COMMON STATEMENTS
C
	COMMON /A/ JJ, J
	COMMON /B/ISTART, START, LNDEX, DIGIT, LABEL, NUMBER, NULL
	COMMON /C/ LL, L, STRING, SPARE
C
C DETERMINE # OF DIGITS IN OLD LABEL AND CONVERT TO INTEGER
C
	ILENG = LEN(STRING)
	DO 100, JA=J,ILENG	!STARTING DIGIT
		IF(STRING(JA) .LE. 'Z' .AND. STRING(JA) .GE. 'A') GOTO 270
		IF(STRING(JA) .EQ. ')' .OR. STRING(JA) .EQ. '*') GOTO 270
		IF(STRING(JA) .LE. '9' .AND. STRING(JA) .GE. '0') GOTO 110
100	CONTINUE
	IF(JA .EQ. ILENG) GOTO 270
110	DO 120, K=JA,ILENG	!ENDING DIGIT
		IF(STRING(K) .LT. '0' .OR. STRING(K) .GT. '9') GOTO 130
120	CONTINUE
130	M = K - JA	!# OF DIGITS IN LABEL
	CALL SUBSTR(STRING,DIGIT,JA,M)
	DIGIT(M+1) = NULL
	DECODE(M,140,DIGIT,ERR=280) N
140	FORMAT( I5)
C
C FIND OLD LABEL
C
	DO 150, I=1,500
		IF(LABEL(I) .EQ. N) GOTO 160
150	CONTINUE
160	N = (I)*LNDEX+ISTART	!CALCULATE NEW LABEL
C
C DETERMINE THE NUMBER OF DIGITS IN THE NEW LABEL
C
	IF(N .GT. 9) GOTO 170
	JJ=1
	DIGIT(1) = NUMBER(N+1)
	GOTO 250
170	IF(N .GT. 99) GOTO 180
	JJ=2
	GOTO 210
180	IF(N .GT. 999) GOTO 190
	JJ=3
	GOTO 210
190	IF(N .GT. 9999) GOTO 200
	JJ=4
	GOTO 210
200	JJ=5
210	II=0
C
C TAKES NEW LABEL AND CONVERTS FROM INTEGER TO ASCII AND PLACES IT
C IN 'DIGIT'
C
	DO 230, I=JJ-1, 1, -1
		II=II+1
		IJ=10**I
		M=N/IJ
		IF(M .NE. 0) GOTO 220
		DIGIT(II) = NUMBER(11)
		GOTO 230
220		DIGIT(II) = NUMBER(M+1)
		N = N-IJ*M
230	CONTINUE
	IF(N .NE. 0) GOTO 240
	DIGIT(JJ) = NUMBER(11)
	GOTO 250
240	DIGIT(JJ) = NUMBER(N+1)
250	DIGIT(JJ+1) = NULL
C ZERO ALL STRING ARRAYS
C
	DO 260, JKL=1,81
		SPAREB(JKL) = NULL
		SPARE(JKL) = NULL
		SPAREA(JKL) = NULL
260	CONTINUE
	CALL TRIM(SPARE)
	CALL TRIM(SPAREA)
	CALL TRIM(SPAREB)
C
C REASSEMBLES 'STRING' WITH NEW ASCII LABEL
C
	CALL SUBSTR(STRING,SPAREB,1,JA-1)
	CALL SUBSTR(STRING,SPARE,K,80)
	CALL CONCAT(SPAREB,DIGIT,STRING,80)
	CALL CONCAT(STRING,SPARE,STRING,80)
270	RETURN
280	STOP 'DECODE ERROR'
	END



