	SUBROUTINE GVSCAN(LINE,IBGN,LEND,LSTCHR,ID1,ID2,IVALID)
C COPYRIGHT (C) 1983 GLENN EVERHART
C PERMISSION IS GIVEN TO ANYONE TO USE, DISTRIBUTE, OR COPY THIS
C PROGRAM FREELY BUT NOT TO SELL IT COMMERICALLY.
C VARSCN - SCAN COMMAND LINE FOR VARIABLE NAMES.
C
C	SCANS FOR VARIABLE NAMES OF FORM AAANNN WHERE AAA = LETTERS
C BETWEEN A AND Z UP TO NON-ALPHA, CORRESPONDING TO ROW, FOLLOWED BY
C NUMBERS IN THE 0-9 RANGE MAKING A DECIMAL COLUMN NUMBER.
C   THIS VERSION IS FOR USE WITH A GRAPHICS PROGRAM AND WILL NOT DECODE
C   FORMS OF TYPE P## OR D## AS WILL THE ONE IN PORTACALC. ALSO IT WILL
C   NOT MAKE CHECKS ON LIMITS OF VARIABLES SAVE FOR VERY CRUDE CHECKS OF
C   REASONABLENESS.
C
C THE LETTERS ARE FORMED BY
C A-Z ALONE GIVE ROW 1-26, COL 1. % IS ROW 27,COL1
C A1-Z1 GIVE ROW 1-26, COL 2
C AA1-ZZ1 ARE ROW 27-52, COL 2
	IMPLICIT INTEGER*2 (A-Z)
	PARAMETER RRW=1000
	PARAMETER RCL=1000
C RRCL IS USED AS A GUARD TO ENSURE AGAINST OVERFLOWS. VAX COMPLAINS OF
C INTEGER OVERFLOWS (PAIN).
	PARAMETER RRCL=1100
	PARAMETER CUP=1,NEL=14
C NOTE COL 1 IS DUMMY. DISPLAY THE SHEET SIDEWAYS SO WE GET USUAL VISUAL
C ROWS, COLS., AND ACCUMULATORS A-Z,% JUST APPEAR AS A FICTITIOUS ROW 0
C ON DISPLAY, INSTEAD OF REAL COLUMN 1 HERE.
	DIMENSION LINE(LEND)
	LOGICAL*1 LINE
C
	INTEGER*2 RSM,CSM,AFG,ASM,VCF,CH
C ZERO OUR VARIABLES
	LPFG=0 ! FLAG WE GOT A LOGICAL/PHYSICAL # FORM AND TYPE
	AFG=0  ! FLAG WE SAW AN ALPHA
	ASM=0  ! SUM OF ALPHAS HASHCODED (ACCUMULATOR)
	NSM=0  ! ACCUMULATOR FOR NUMERICS
	NFG=0  ! FLAG WE SAW A NUMERIC
	RSM=0  ! AC FOR ROWS IN # FORMS
	CSM=0  ! AC FOR COLS IN # FORMS
	ISPC=0 ! COUNTER FOR NONSPACES SEEN (USED TO STOP ON TRAILING SPACES)
	IF(LINE(IBGN).NE.'%')GOTO 2000
	ID1=27
	ID2=1
	IVALID=1
	LSTCHR=IBGN+1
C SPECIAL CASE FOR % = AC #27
	RETURN
2000	CONTINUE
	DO 1 N=IBGN,LEND
	VCF=0
	LSTCHR=N
	CH=LINE(N)
C IGNORE SPACES AND TABS IF LEADING
	IF(CH.GT.32)ISPC=ISPC+1
	IF(CH.GT.0.AND.CH.LE.32.AND.ISPC.EQ.0)GOTO 1
C GET CHARACTER VALUE IN.
C MUST BE UPPERCASE.
	IF(.NOT.(CH.GE.65.AND.CH.LE.91)) GOTO 100
C CH IS AN ALPHA, RANGE A-Z
	VCF=1 ! VALID CHAR SEEN
	AFG=1 !SAW THE ALPHA
	IF(ASM.LT.RRCL)ASM=(CH-64)+26*ASM
	IF(CH.EQ.80)LPFG=1 ! FLAG WE GOT PHYS. FORM MAYBE
	IF(CH.EQ.68)LPFG=2 ! FLAG WE GOT DISPLAY FORM MAYBE
100	CONTINUE
C NEXT TEST NUMERICS
	IF(.NOT.(CH.GE.48.AND.CH.LE.57))GOTO 101
C CH IS A NUMERIC, RANGE 0-9
	VCF=1 ! VALID CHAR SEEN
	NFG=1 ! FLAG WE SAW NUMERIC
	IF(AFG.NE.0)GOTO 102
103	CONTINUE
C INVALID ... NUMERIC AND NO PRIOR ALPHA. FLAG BAD NAME AND EXIT.
	IVALID=0
	RETURN
102	CONTINUE
	IF(NSM.LT.RRCL)NSM=(CH-48)+10*NSM ! CONVERT CHARS TO BINARY AS SEEN
101	CONTINUE
	IF(VCF.EQ.0)GOTO 2 !END ON ANY INVALID CHARACTER
1	CONTINUE
2	CONTINUE
	IF(AFG.EQ.0)GOTO 103
	ID1=ASM
C HERE WE MAKE ID2 JUST NSM, NOT 1+NSM.
	ID2=NSM
C FLAG PURE ALPHAS NOT VALID FOR PLOTTING HERE. (THEY AREN'T SAVED ANYHOW)
	IF(NSM.LE.0)GOTO 103
	IF(ID1.GT.RRW.OR.ID1.LE.0)GOTO 103
	IF(ID2.GT.RCL.OR.ID2.LE.0)GOTO 103
	IVALID=1
C ALL IS WELL
	RETURN
	END
C GN - GET NUMBER
	SUBROUTINE GN(LAST,LEND,NUM,LINE)
	IMPLICIT INTEGER*2(A-Z)
	PARAMETER CUP=1,NEL=14
	DIMENSION LINE(110)
	LOGICAL*1 LINE
	LOGICAL*1 NCH
	INTEGER*2 CH,SFG
	NUM=0
	JSSF=0
	ISSF=0
	CH=0
	SFG=1
	NCH=0
	DO 1 N=LAST,LEND
	M=N
	NCH=LINE(N)
	CH=NCH
	IF(CH.EQ.0)GOTO 2
	IF(CH.EQ.45)SFG=-1
C SFG=SIGN FLAG
C 43 IS ASCII FOR +; 45 IS ASCII FOR - SIGN.
C IGNORE + SIGNS
	IF(CH.GT.32)ISSF=ISSF+1
	IF(ISSF.EQ.0.AND.CH.EQ.32)GOTO 1
C IGNORE SPACES TOO, PROVIDED THEY ARE LEADING SPACES.
C (OTHERS MAY BE DELIMITERS.)
	IF(CH.EQ.43.OR.CH.EQ.45)JSSF=JSSF+1
	IF(JSSF.GT.1.AND.(CH.EQ.43.OR.CH.EQ.45))GOTO 2
C IF WE HAVEN'T SEEN A +/- PROCESS IT HERE.
	IF(CH.EQ.43)GOTO 1
	IF(CH.EQ.45)GOTO 1
	IF(CH.LT.48.OR.CH.GT.57)GOTO 2
C TERMINATE ON ANY NON NUMERIC. SHOULD ALLOW TERMINATE ON SECOND #.
	IF(NUM.LT.3100)NUM=10*NUM+(CH-48)
1	CONTINUE
C NEXT LINE WAS MAX0...
2	LAST=MIN0(M,LEND)
	NUM=NUM*SFG
C ACCOUNTED FOR SIGN; NOW RETURN
	RETURN
	END
