	PROGRAM SQMAP
C
	BYTE FILMAP(50),FILSMP(30),STRING(82),VERSIE(14)
	BYTE DEV(6),NAME(82),EXT(6),TAB3(4),VFCS(4),ERR,CRLF(3)
	DIMENSION ISGPNT(256),RIOBUF(1024),IGLREF(64)
	COMMON /QUIET / IQUIET
	COMMON /ASSVAR/ IRECRD
	COMMON /GLCREF/ ISEG,IGLCNT,IPOINT,IGLREC,ISGPNT,RIOBUF
	DATA VFC,DEV,TAB3,VFCS,CRLF /'0', 6*0, 3*9,0, ' ',3*'0', "15,"12,0/
	DATA JSW,IGTLIN /"44,"10/
C
	CALL SCOPY('SQMAP V1.3',VERSIE,12)
C
	CALL IPOKE(JSW,IGTLIN.OR.IPEEK(JSW))
	CALL GETLIN('Load  map? ',FILMAP,48)
	ICOMMA=INDEX(FILMAP,',')
	IF (ICOMMA.GT.0) GOTO 6 ! THEN
	  CALL GETLIN('Short map? ',FILSMP,28)
	  GOTO 8
C	ELSE
 6	  FILMAP(ICOMMA)=0
	  CALL SCOPY(FILMAP(ICOMMA+1),FILSMP)
C	ENDIF
C
 8	IQUIET=INDEX(FILSMP,'/Q')
	ISIZE=-INDEX(FILSMP,'/H')
	IF (ISIZE.EQ.0) ISIZE=INDEX(FILSMP,'/S')
	JCREF =INDEX(FILSMP,'/C')
	IF (ISIZE.NE.0) JCREF=0
	IPRINT=INDEX(FILSMP,'/P')
	ISLASH=INDEX(FILSMP,'/')
	IF (ISLASH.NE.0) FILSMP(ISLASH)=0
C
	IF (INDEX(FILMAP,'.').EQ.0) CALL CONCAT(FILMAP,'.MAP',FILMAP)
	INAM=INDEX(FILMAP,':')+1
	IF (INAM.GT.1) CALL SCOPY(FILMAP,DEV,INAM-1)
	IEXT=INDEX(FILMAP,'.')
	CALL SUBSTR(FILMAP,NAME,INAM,IEXT-INAM)
C
	IF (INDEX(FILSMP,'.').EQ.0) CALL CONCAT(FILSMP,'.SMP',FILSMP)
	INAM=INDEX(FILSMP,':')+1
	IEXT=INDEX(FILSMP,'.')
	CALL SCOPY(FILSMP(IEXT),EXT)
	FILSMP(IEXT)=0
	IF (IEXT.EQ.INAM) CALL CONCAT(FILSMP,NAME,FILSMP)
	CALL CONCAT(FILSMP,EXT,FILSMP)
	CALL SCOPY(FILSMP,STRING)
	IF (INAM.EQ.1) CALL CONCAT(DEV,STRING,FILSMP)
CC							page 2 of SQMAP
C
	OPEN(UNIT=1,NAME=FILMAP,TYPE='OLD',ERR=101)
	OPEN(UNIT=2,NAME=FILSMP,TYPE='NEW',ERR=102)
	IF (ISIZE.NE.0) GOTO 110
	  OPEN(UNIT=3,NAME='SQMAP0.TMP',TYPE='SCRATCH',
	*      INITIALSIZE=16,ERR=103)
	  OPEN(UNIT=4,NAME='SQMAP1.TMP',TYPE='SCRATCH',
	*      INITIALSIZE=16,ERR=103)
C	ENDIF
 110	OPEN(UNIT=8,NAME='SQMAP2.TMP',TYPE='SCRATCH',
	*    INITIALSIZE=8,ACCESS='DIRECT',RECORDSIZE=1,
	*    ASSOCIATEVARIABLE=IRECRD,ERR=103)
	IF (JCREF.EQ.0) GOTO 112
	  OPEN(UNIT=9,NAME='SQMAP3.TMP',TYPE='SCRATCH',
	*      INITIALSIZE=32,ACCESS='DIRECT',RECORDSIZE=1024,
	*      ASSOCIATEVARIABLE=IGLREC,ERR=103)
	  IGLREC=1
C	ENDIF
C
 112	CALL SCOPY(VERSIE,STRING)
	CALL CONCAT(STRING,9,STRING)
	CALL CONCAT(STRING,'Squeezed Load Map',STRING)
	CALL CONCAT(STRING,9,STRING)
	CALL CONCAT(STRING,9,STRING)
	L=LEN(STRING)+1
	CALL DATE(STRING(L))
	STRING(L+9)=' '
	CALL TIME(STRING(L+10))
	STRING(L+18)=0
	CALL PUTSTR(2,STRING,'+',ERR)
	IF (ERR.LT.0) GOTO 104
	IF (IQUIET.EQ.0) CALL PUTSTR(7,STRING,VFC,ERR)
C
	STRING(1)=9
	CALL SCOPY(9,STRING(2))
	CALL CONCAT(STRING,FILMAP,STRING)
	CALL CONCAT(STRING,' --> ',STRING)
	CALL CONCAT(STRING,FILSMP,STRING)
	IF (ISIZE.GT.0) CALL CONCAT(STRING,'/S',STRING)
	IF (ISIZE.LT.0) CALL CONCAT(STRING,'/H',STRING)
	CALL OUTPUT(STRING,' ',0)
C
	CALL GETSTR(1,STRING,80,ERR)
	STRING(IABS(INDEX(STRING,'Page')-1))=0
	L=INDEX(STRING,'Load')
	STRING(L-1)=0
	CALL OUTPUT(STRING,VFC,0)
	CALL OUTPUT(STRING(L),' ',0)
	CALL GETSTR(1,STRING,80,ERR)
	STRING(IABS(INDEX(STRING,'Ident:')-1))=0
	CALL OUTPUT(STRING,' ',0)
	IF (ISIZE.GE.0) CALL OUTPUT('Root segment',VFC,0)
C
	ISEG=0
	IGLCNT=0
	IPOINT=1
	CALL GLWRIT(STRING(INDEX(STRING,'Title:')+7))
CC							page 3 of SQMAP
C
	NSECT=0
	NAMTOP=0
	IREG=0
	IRECRD=1
 10	CALL GETSTR(1,STRING,80,ERR)
	ICREF=INDEX(STRING,'Cross Reference')
	IF (ERR.LT.0.OR.ICREF.NE.0) GOTO 100
	  IF (ISIZE.NE.0) GOTO 54
	    IF (INDEX(STRING,TAB3).NE.1) GOTO 50
	      J=INDEX(STRING,9)
 20	      IF (J.EQ.0) GOTO 50
	        IF (STRING(J+1).GE.'0'.AND.STRING(J+1).LE.'9') GOTO 40
	          IF (JCREF.NE.0) CALL GLWRIT(STRING(J+1))
	          DO 30, I=1,6
	            NAME(I)=STRING(I+J)
	            IF (NAME(I).NE.' '.AND.NAME(I).LT.'0') GOTO 40
	            IF (NAME(I).GT.'9'.AND.NAME(I).LT.'A') GOTO 40
	            IF (NAME(I).GT.'Z') GOTO 40
 30	          CONTINUE
	          NAME(7)=0
	          CALL PUTSTR(3,NAME,' ',ERR)
	          IF (ERR.LT.0) GOTO 105
	          NAMTOP=NAMTOP+1
C	        ENDIF
 40	        J=INDEX(STRING,9,J+1)
	        GOTO 20
C	      ENDIF
C	    ENDIF
 50	    CONTINUE
C
	    IF (INDEX(STRING,'(').EQ.0) GOTO 54
	      DO 52, I=2,7
	        IF (STRING(I).EQ.' ') GOTO 52
	        IF (STRING(I).GE.'0'.AND.STRING(I).LE.'9') GOTO 52
	        IF (STRING(I).GE.'A'.AND.STRING(I).LE.'Z') GOTO 52
	        GOTO 54
 52	      CONTINUE
	      STRING(8)=0
	      CALL PUTSTR(4,STRING(2),' ',ERR)
	      IF (ERR.LT.0) GOTO 105
	      NSECT=NSECT+1
C	    ENDIF
C	  ENDIF
C
 54	  ITYP=0
	  IF (INDEX(STRING,'Segment size'     ).NE.0) ITYP=1
	  IF (INDEX(STRING,'Overlay region'   ).NE.0) ITYP=2
	  IF (INDEX(STRING,'Transfer address' ).NE.0) ITYP=3
	  IF (INDEX(STRING,'Undefined globals').NE.0) ITYP=4
CC							page 4 of SQMAP
C
	  IF (ITYP.EQ.0) GOTO 90
	    IF (ITYP.NE.1) GOTO 56
	      DO 540, I=1,15
	        STRING(I)=STRING(I+1)
 540	      CONTINUE
	      DECODE(6,541,STRING(17)) ISGSIZ
 541	      FORMAT(O6)
	      WRITE(8'IRECRD,ERR=105) IREG,ISGSIZ
	      IF (JCREF.EQ.0) GOTO 56
	        ISEG=ISEG+1
	        IF (ISEG.GT.256) CALL STOP('Segment buffer overflow')
	        ISGPNT(ISEG)=IGLCNT+1
C	      ENDIF
C	    ENDIF
 56	    IF (ITYP.EQ.2) DECODE(6,541,STRING(16)) IREG
	    IF (ITYP.LT.3.AND.ISIZE.GE.0) CALL OUTPUT(STRING,VFCS(ITYP),0)
	    IF (ITYP.EQ.2.OR.ISIZE.NE.0) GOTO 58
	      IF (NAMTOP.GT.0) CALL OUTPUT('Globals:',' ',0)
	      CALL PRINAM(NAMTOP)
	      IF (NSECT .GT.0) CALL OUTPUT('Psects:' ,' ',0)
	      CALL PRSECT(NSECT)
C	    ENDIF
 58	    IF (ITYP.NE.3) GOTO 580
	      IHIGH=INDEX(STRING,'High limit')
	      DECODE(6,541,STRING(IHIGH+13)) ISGSIZ
	      WRITE(8'IRECRD,ERR=105) -1,ISGSIZ
	      CALL OUTPUT(STRING(IHIGH),VFCS(ITYP),0)
C	    ENDIF
 580	    IF (ITYP.NE.4.OR.ISIZE.NE.0) GOTO 90
	      REWIND 3
	      NAMTOP=0
	      CALL GETSTR(1,NAME,80,ERR)
 60	      IF (INDEX(NAME,'Transfer address').NE.0) GOTO 80
	        IF (LEN(NAME).LT.6) CALL STRPAD(NAME,6)
	        DO 70, I=1,6
	          IF (NAME(I).EQ.'$'.OR.NAME(I).EQ.'.') NAME(1)=0
 70	        CONTINUE
	        IF (LEN(NAME).NE.6) GOTO 78
	          CALL PUTSTR(3,NAME,' ',ERR)
	          IF (ERR.LT.0) GOTO 105
	          NAMTOP=NAMTOP+1
C	        ENDIF
 78	        CALL GETSTR(1,NAME,80,ERR)
	        GOTO 60
C	      ENDIF
 80	      CALL OUTPUT(STRING,VFCS(ITYP),2+NAMTOP/8)
	      CALL PRINAM(NAMTOP)
	      IHIGH=INDEX(NAME,'High limit')
	      DECODE(6,541,NAME(IHIGH+13)) ISGSIZ
	      WRITE(8'IRECRD,ERR=105) -1,ISGSIZ
	      CALL OUTPUT(NAME(IHIGH),'0',0)
C	    ENDIF
C	  ENDIF
 90	  GOTO 10
C	ENDIF
CC							page 5 of SQMAP
C
 100	IF (ISIZE.GE.0) CALL SQPLOT
	IF (JCREF.EQ.0.OR.ICREF.EQ.0.OR.ISIZE.NE.0) GOTO 1000
	  WRITE(9'IGLREC,ERR=105) RIOBUF
	  CALL SCOPY('Globals referenced in segments: ',STRING)
	  CALL CONCAT(STRING,'(# = defined, + = from library)',STRING)
	  CALL OUTPUT(STRING,'1',0)
	  VFC='0'
C
 200	  CALL GETSTR(1,NAME,80,ERR)
	  IF (ERR.LT.0) GOTO 1000
	  IF (INDEX(NAME,'Page').NE.0) GOTO 200
	  IF (NAME(1).EQ. 0 ) GOTO 200
	  IF (NAME(1).EQ.' ') GOTO 200
 202	  CONTINUE
	    DO 210, I=1,6
	      IF (NAME(I).EQ.'$'.OR.NAME(I).EQ.'.') GOTO 200
 210	    CONTINUE
C
	    STRING(1)=' '
	    CALL SCOPY(NAME,STRING(2),6)
	    NREF=0
	    CALL GLREAD(STRING(2),NREF,IGLREF)
	    DO 212, I=1,NREF
	      IGLREF(I)=-IGLREF(I)
 212	    CONTINUE
C
 220	    CONTINUE
	      IF (INDEX(NAME,'#+').NE.0) STRING(1)='+'
	      CALL TRANSL(NAME,NAME,'  ','#+')	
	      CALL STRPAD(NAME,70)
	      DO 230, I=8,70,9
	        CALL GLREAD(NAME(I),NREF,IGLREF)
 230	      CONTINUE
 240	      CALL GETSTR(1,NAME,80,ERR)
	      IF (ERR.LT.0) GOTO 250
	      IF (INDEX(NAME,'Page').NE.0) GOTO 240
	      IF (NAME(1).EQ. 0 ) GOTO 240
	      IF (NAME(1).EQ.' ') GOTO 220
C	    ENDLOOP
 250	    IF (NREF.EQ.0) GOTO 400
	      DO 270, I=1,NREF
	        DO 260, J=I,NREF
	          IF (IABS(IGLREF(J)).GE.IABS(IGLREF(I))) GOTO 260
	            IHULP    =IGLREF(I)
	            IGLREF(I)=IGLREF(J)
	            IGLREF(J)=IHULP
C	          ENDIF
 260	        CONTINUE
 270	      CONTINUE
CC							page 6 of SQMAP
C
	      I=1
 280	      IF (I.GE.NREF) GOTO 310
	        IF (IABS(IGLREF(I)).NE.IABS(IGLREF(I+1))) GOTO 300
	          IHULP=IGLREF(I)
	          NREF=NREF-1
	          DO 290, J=I,NREF
	            IGLREF(J)=IGLREF(J+1)
 290	          CONTINUE
	          IF (IHULP.LT.0) IGLREF(I)=IHULP
	          I=I-1
C	        ENDIF
 300	        I=I+1
	        GOTO 280
C	      ENDIF
 310	      CONTINUE
	      CALL WRIOUT(STRING,NREF,IGLREF,VFC)
	      VFC=' '
C	    ENDIF
 400	    IF (ERR.EQ.0) GOTO 202
C	  ENDLOOP
C	ENDIF
C
 1000	CALL PUTSTR(7,'?SQMAP-I-Ready','0',ERR)
	IF (IPRINT.EQ.0) GOTO 1010
	  CALL CONCAT('.PRINT ',FILSMP,STRING)
	  CALL PUTSTR(7,STRING,'0',ERR)
	  CALL SETCMD(STRING(2))
	  CALL IPOKE("44,IPEEK("44).OR."40)
C	ENDIF
 1010	CALL PUTSTR(7,' ',' ',ERR)
	CALL EXIT
C
 101	CALL STOP('Cannot open input file')
 102	CALL STOP('Cannot open output file')
 103	CALL STOP('Cannot open scratch file(s)')
 104	CALL STOP('Output file write error')
 105	CALL STOP('Scratch file write error')
C
	END ! SQMAP
	SUBROUTINE OUTPUT(S,V,L)
C
	BYTE V,W,E
	COMMON /QUIET/ IQUIET
	DATA LINE /1/
C
	W=V
	IF (LINE.LT.50) GOTO 10
	  IF (INDEX(S,'Overlay').NE.0) W='1'
	  IF (L.GT.5) W='1'
C	ENDIF
C
 10	CALL PUTSTR(2,S,W,E)
	IF (E.LT.0) CALL STOP('Output file write error')
	IF (IQUIET.EQ.0) CALL PUTSTR(7,S,V,E)
C
	IF (W.EQ.'1') LINE=1
	IF (W.EQ.' ') LINE=LINE+1
	IF (W.EQ.'0') LINE=LINE+2
	LINE=MOD(LINE,60)
C
	RETURN
	END ! OUTPUT
	SUBROUTINE PRINAM(NAMTOP)
C
	BYTE NAME(8),GLOBLS(60),ERR
C
	REWIND 3
	GLOBLS(1)=0
	I=0
	JNAM=0
 60	IF (JNAM.GE.NAMTOP) GOTO 70
	  CALL GETSTR(3,NAME,6,ERR)
	  JNAM=JNAM+1
	  CALL CONCAT(GLOBLS,9,GLOBLS)
	  CALL CONCAT(GLOBLS,NAME,GLOBLS)
	  I=MOD(I+1,8)
	  IF (I.NE.0.AND.JNAM.LT.NAMTOP) GOTO 64
	    CALL OUTPUT(GLOBLS,' ',1+(NAMTOP-JNAM)/8)
	    GLOBLS(1)=0
C	  ENDIF
 64	  GOTO 60
C	ENDIF
 70	NAMTOP=0
	REWIND 3
C
	RETURN
	END ! PRINAM
	SUBROUTINE PRSECT(NSECT)
C
	BYTE NAME(8),PSECTS(60),ERR
C
	REWIND 4
	PSECTS(1)=0
	I=0
	JNAM=0
 60	IF (JNAM.GE.NSECT) GOTO 70
	  CALL GETSTR(4,NAME,6,ERR)
	  JNAM=JNAM+1
	  CALL CONCAT(PSECTS,9,PSECTS)
	  CALL CONCAT(PSECTS,NAME,PSECTS)
	  I=MOD(I+1,8)
	  IF (I.NE.0.AND.JNAM.LT.NSECT) GOTO 64
	    CALL OUTPUT(PSECTS,' ',1+(NSECT-JNAM)/8)
	    PSECTS(1)=0
C	  ENDIF
 64	  GOTO 60
C	ENDIF
 70	NSECT=0
	REWIND 4
C
	RETURN
	END ! PRSECT
	SUBROUTINE GETLIN(PR,STR,LMAX)
C
	BYTE PR(1),STR(1),HPR(82),HULP(82)
C
	CALL SCOPY(PR,HPR,80)
	L=LEN(HPR)+1
	HPR(L)="200
	CALL GTLIN(HULP,HPR)
	CALL SCOPY(HULP,STR,LMAX)
C
	RETURN
	END ! GETLIN
	SUBROUTINE STOP(S)
	CALL PUTSTR(7,'?SQMAP-F-','$',ERR)
	CALL PUTSTR(7,S,'+',ERR)
	CALL IPOKEB("53,IPEEKB("53).OR."10) ! indicate severe error
	CALL EXIT
	END
	SUBROUTINE SQPLOT
C
	BYTE PLOT(74,60),CHAR
	DIMENSION ISPR(16),REGSIZ(16),OVRLAY(16,16)
	COMMON /ASSVAR/ IRECRD
	DATA ISPR,REGSIZ,OVRLAY /16*0,16*0.,256*0./
C
C	Local function to convert integer
C	number of bytes to real number of words:
	WORDS(I)=.5*AMOD(FLOAT(I)+65536.,65536.)
C
	IREG=1
	ISEG=0
	IRECRD=1
 10	CONTINUE
	  READ(8'IRECRD) IRGNUM,ISGSIZ
	  IF (IRGNUM.LT.0) HIGH=WORDS(ISGSIZ)
	  IF (IRGNUM.EQ.0) ROOT=WORDS(ISGSIZ)
	  IF (IRGNUM.LE.0) GOTO 30
	    IF (IRGNUM.EQ.IREG) GOTO 20
	      IREG=IREG+1
	      IF (IREG.GT.16) GOTO 900
	      ISEG=0
C	    ENDIF
 20	    ISEG=ISEG+1
	    IF (ISEG.GT.16) GOTO 900
	    OVRLAY(IREG,ISEG)=WORDS(ISGSIZ)
	    ISPR(IREG)=ISEG
C	  ENDIF
 30	  IF (IRGNUM.NE.-1) GOTO 10
C	ENDLOOP
	IF (IRECRD.EQ.2) RETURN
C
	DO 50, I=1,IREG
	  REGSIZ(I)=OVRLAY(I,1)
	  DO 40, J=2,16
	    IF (OVRLAY(I,J).GT.REGSIZ(I)) REGSIZ(I)=OVRLAY(I,J)
 40	  CONTINUE
 50	CONTINUE
C
	DO 60, I=2,59
	  ENCODE(73,51,PLOT(1,I)) 0
 51	  FORMAT('!',70('*'),'!',A1)
 60	CONTINUE
CC							page 2 of SQPLOT
C
	SIZE=HIGH-ROOT
	ADDR2=0.
	LINE2=1
	NSEG=0
	DO 100, I=1,IREG
	  ADDR1=ADDR2
	  ADDR2=ADDR1+REGSIZ(I)
	  LINE1=MIN0(60,LINE2+1)
	  LINE2=MIN0(60,INT(1.5+59.*ADDR2/SIZE))
	  ICOL2=0
	  DO 90, J=1,ISPR(I)
	    NSEG=NSEG+1
	    ICOL1=MIN0(72,ICOL2+2)
	    ICOL2=MIN0(71,INT(.5+71.*FLOAT(J)/FLOAT(ISPR(I))))
	    LINE3=INT(1.5+59.*(ADDR1+OVRLAY(I,J))/SIZE)
	    DO 80, LINE=LINE1,LINE3
	      CHAR=' '
	      IF (LINE.EQ.LINE3) CHAR='-'
	      DO 70, ICOL=ICOL1,ICOL2
	        PLOT(ICOL,LINE)=CHAR
 70	      CONTINUE
	      PLOT(ICOL1-1,LINE)='!'
	      PLOT(ICOL2+1,LINE)='!'
 80	    CONTINUE
	    ENCODE(3,81,PLOT(ICOL1,LINE1)) NSEG
 81	    FORMAT(O3)
	    DO 82, ICOL=ICOL1,ICOL1+1
	      IF (PLOT(ICOL,LINE1).EQ.' ') PLOT(ICOL,LINE1)='0'
 82	    CONTINUE
 90	  CONTINUE	  
	  ENCODE(73,91,PLOT(1,LINE2)) 0
 91	  FORMAT('!',70('-'),'!',A1)
 100	CONTINUE
C
	ENCODE(73,101,PLOT(1, 1)) ROOT,0
	ENCODE(73,103,PLOT(1,60)) HIGH,0
 101	FORMAT('!- Root = ',F6.0,' ',54('-'),'!',A1)
 103	FORMAT('!- High limit = ',F6.0,' ',48('-'),'!',A1)
C
	CHAR='1'
	DO 200, I=60,1,-1
	  CALL OUTPUT(PLOT(1,I),CHAR,0)
	  CHAR=' '
 200	CONTINUE
	RETURN
C
 900	CALL PUTSTR(7,'?SQMAP-W-Plot buffer overflow, no plot made','0',ERR)
	CALL IPOKEB("53,IPEEKB("53).OR."2) ! indicate warning
	RETURN
	END ! SQPLOT
	SUBROUTINE GLWRIT(NAME)
C
	DIMENSION ISGPNT(256),RIOBUF(1024)
	COMMON /GLCREF/ ISEG,IGLCNT,IPOINT,IGLREC,ISGPNT,RIOBUF
C
	RNAME=RAD50(NAME)
	IF (RNAME.EQ.0.) RETURN
	RIOBUF(IPOINT)=RNAME
	IGLCNT=IGLCNT+1
	IPOINT=IPOINT+1
	IF (IPOINT.LE.1024) GOTO 10
	  WRITE(9'IGLREC,ERR=100) RIOBUF
	  IPOINT=1
C	ENDIF
 10	RIOBUF(IPOINT)=0.
	RETURN
C
 100	CALL STOP('Scratch file write error')
	END ! GLWRIT
	SUBROUTINE GLREAD(NAME,NDEF,ISGDEF)
	DIMENSION ISGDEF(64)
C
	DIMENSION ISGPNT(256),RIOBUF(1024)
	COMMON /GLCREF/ ISEG,IGLCNT,IPOINT,IGLREC,ISGPNT,RIOBUF
C
	RNAME=RAD50(NAME)
	NSEG=1
	NGL=1
	IGLREC=1
 10	CONTINUE
	  IF (IGLCNT.GT.1024) READ(9'IGLREC) RIOBUF
	  DO 30, IPOINT=1,1024
	    IF (NGL.GT.IGLCNT) RETURN
	      IF (RIOBUF(IPOINT).NE.RNAME) GOTO 20
	        NDEF=NDEF+1
	        IF (NDEF.GT.64) GOTO 100
	        ISGDEF(NDEF)=NSEG+"777
C	      ENDIF
 20	      NGL=NGL+1
	      IF (NGL.GE.ISGPNT(NSEG)) NSEG=NSEG+1
C	    ENDIF
 30	  CONTINUE
	  IF (NGL.LE.IGLCNT) GOTO 10
C	ENDLOOP
C
	RETURN
C
 100	CALL STOP('Too many segments')
	END ! GLREAD
	SUBROUTINE WRIOUT(NAME,NREF,IGLREF,VFC)
C
	BYTE STRING(82),NAME(7),VFC
	DIMENSION IGLREF(NREF)
C
	CALL SCOPY(NAME,STRING,7)
C
	NDONE=0
 20	IF (NDONE.GE.NREF) GOTO 40
	  NTODO=MIN0(NREF-NDONE,13)
	  MAX=NDONE+NTODO
	  NCHAR=NTODO*5
	  ENCODE(NCHAR,21,STRING(8)) (IABS(IGLREF(I)),I=NDONE+1,MAX)
 21	  FORMAT(13(O4,X))
	  STRING(8+NCHAR)=0
	  CALL STRPAD(STRING,80)
	  DO 30, I=1,NTODO
	    J=5*I+3
	    STRING(J)=' '
	    IF (IGLREF(NDONE+I).LT.0) STRING(J+4)='#'
 30	  CONTINUE
	  CALL TRIM(STRING)
	  IF (LEN(STRING).NE.0) CALL OUTPUT(STRING,VFC,0)
	  IF (NDONE.EQ.0) CALL SCOPY('       ',STRING)
	  NDONE=MAX
	  GOTO 20
C	ENDIF
C
 40	RETURN
	END ! WRIOUT
