	program seq6
$	include /usr/include/fgl.h
	common sxsize,sysize,xdim,ydim,xoff,yoff,xwhere,ywhere,
     +	retflag,locflag,rgbflag
C
	integer sxsize,sysize
	integer xdim,ydim
	integer xoff,yoff
	integer xwhere,ywhere
	logical retflag,locflag,rgbflag,vebflag
C
	character*80 fname
	integer*4 f1,m1
	integer iargc
	character*4 xstr,ystr
	character*2 optstr
	character*1 resp
C
	retflag=.false.
	locflag=.false.
	sxsize=1024
	sysize=768
C
	narg=iargc()
	if (narg.lt.2) then
		print *,' '
	print *,'Usage: seq xdim ydim [-s] [-f] [-v]
     + [-p xwhere ywhere] file1 file2 . .'
	print *,' -s              step through images'
	print *,' -f              use full color (24 bits/pixel)'
	print *,' -v              verbose - echo displayed images'
	print *,' -p xloc yloc    position on screen'
		goto 998
	else
		call getarg(2,xstr)	
		call getarg(3,ystr)	
		call ctoi(xstr,xdim)
		call ctoi(ystr,ydim)
		imax=4
		do 100 i=4,narg
			call getarg(i,optstr)
			if (optstr.eq.'-s') then
				retflag=.true.
				imax=i+1
			endif
			if (optstr.eq.'-f') then 
				rgbflag=.true.
				imax=i+1
			endif
			if (optstr.eq.'-v') then 
				vebflag=.true.
				imax=i+1
			endif
			if (optstr.eq.'-p') then
				i1=i+1
				i2=i+2
				imax=i2+1
				call getarg(i1,xstr)
				call getarg(i2,ystr)
				call ctoi(xstr,xwhere)
				call ctoi(ystr,ywhere)
				locflag=.true.
			endif
 100		continue
	endif
	do 200 i=imax,narg
		call getarg(i,fname)
		if (vebflag) then
			print *,fname
		endif
		if (rgbflag) then
			call seq24(fname,ioerr)
			if (ioerr.ne.0) then
				print *,'i/o error in image name/size'
				goto 998
			endif
		else
			call seq8(fname,ioerr)
			if (ioerr.ne.0) then
				print *,'i/o error in image name/size'
				goto 998
			endif
		endif
C
		if (retflag) then
 102			continue
			if (.not.getbut(102)) goto 102
C			print *,'Press q to quit'
C			read (*,101) resp
C101			format(a1)
C			if ((resp.eq.'q').or.(resp.eq.'Q')) then
C				goto 998
C			endif
		endif
 200	continue
	call tpon()
	call greset
	call gexit
 998	continue
	end
C
	subroutine seq8(fname,ioerr)
	common sxsize,sysize,xdim,ydim,xoff,yoff,xwhere,ywhere,
     +	retflag,locflag,rgbflag
C
	character*(*) fname
	integer ioerr
C
	integer sxsize,sysize
	integer xdim,ydim
	integer xoff,yoff
	integer xwhere,ywhere
	logical retflag,locflag,rgbflag
C
	character*1280 bb(1:1024)
	integer*2 f(1024)
	integer*4 irec
C
	irec=xdim
	xoff=0
	yoff=0
C
	l=index(fname,' ')-1
	call gbegin
	call onemap
	call single
	call gconfi
	call cursof
	call viewpo(0,1023,0,767)
	call ortho2(0.0,1023.0,0.0,767.0)
	call tpoff()
	call color(0)
	call clear
C
	open (13,iostat=io,err=998,file=fname,status='old',
     +	access='direct',recl=irec)
	do 100 i=1,ydim
		read (13,rec=i,iostat=io,err=998) bb(i)(1:xdim)
 100	continue
	close (13)
C
	if (.not.locflag) then
 		ix=((sxsize-xdim)/2)+xoff
 		iy=((sysize-ydim)/2)+yoff
	else
		ix=xwhere+xoff
		iy=ywhere+yoff
	endif
	iyd=ydim-1
	do 310 i=0,iyd
		i1=(iyd-i)+1
		do 300 j=1,xdim
			f(j)=ichar(bb(i1)(j:j))+10
 300		continue
		call cmov2i(ix,i+iy)
		call writep(xdim,f)
 310	continue
 998	continue
	ioerr=io
	return
	end
C
	subroutine seq24(fname,ioerr)
	common sxsize,sysize,xdim,ydim,xoff,yoff,xwhere,ywhere,
     +	retflag,locflag,rgbflag
C
	character*(*) fname
	integer ioerr
C
	integer sxsize,sysize
	integer xdim,ydim
	integer xoff,yoff
	integer xwhere,ywhere
	logical retflag,locflag,rgbflag
C
 	character*3840 rb(1024)
	character*1280 rr,gg,bb
	integer*4 irec
	character*80 rname,gname,bname
	integer stat,lun
	integer xdim3
C
	xdim3=3*xdim
	irec=xdim3
	xoff=0
	yoff=0
C
	l=index(fname,' ')-1
	call gbegin
	call RGBmod()
	call gconfi
	call cursof
	call viewpo(0,1023,0,767)
	call ortho2(0.0,1023.0,0.0,767.0)
C	call tpoff()
	call color(0)
	call clear
C
 	open (13,iostat=io,err=998,file=fname(1:l),status='old',
     +		access='direct',recl=irec)
 	do 100 i=1,ydim
		read (13,rec=i,iostat=io,err=998) rb(i)(1:xdim3)
  100	continue
 	close(13)
C
	if (.not.locflag) then
		ix=((sxsize-xdim)/2)+xoff
		iy=((sysize-ydim)/2)+yoff
	else
		ix=xwhere+xoff
		iy=ywhere+yoff
	endif
	iyd=ydim-1
	do 310 i=0,iyd
		i1=(iyd-i)+1
		jc=0
		do 300 j=1,xdim3,3
			j1=j+1
			j2=j1+1
			jc=jc+1
			rr(jc:jc)=rb(i1)(j:j)
			gg(jc:jc)=rb(i1)(j1:j1)
			bb(jc:jc)=rb(i1)(j2:j2)
 300		continue
		call cmov2i(ix,i+iy)
		call writeR(xdim,rr(1:xdim),gg(1:xdim),bb(1:xdim))
 310	continue
 998	continue
	ioerr=io
	return
	end
C
	subroutine ctoi(str,n)
	character*(*) str
	integer n
	integer s1,s2,s3,s4,x
C
	read(str,'(i10)') n
C
	return
	end
	
