	program seq6
	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,recflag
C
	character*80 fname
	integer*4 f1,m1
	integer iargc
	character*4 xstr,ystr
	character*2 optstr
	character*1 resp
	character*32 evar,lck,rstr,svar
C
	retflag=.false.
	locflag=.false.
	sxsize=1280
	sysize=1024
C
	narg=iargc()
	if (narg.ge.3) then
		call getenv('WF_BUFFER',evar)
		call getenv('WF_SHOOT',svar)
		if (index(evar,'rt').eq.0) evar='rt1'
		lck='/tmp/LCK..'//evar
		rstr='rm '//lck
		open(7,iostat=io,err=10,file=lck,status='old')
  10		continue
		if (io.eq.0) then
			print *,'device busy...try later'
			goto 998
		else
			open(7,file=lck,status='new')
		endif
	endif
	if (narg.lt.1) then
		print *,' '
	print *,'Usage: seq xdim ydim [-s] [-f] [-v] [-x]
     + [-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 *,' -x              record image on abekas'
	print *,' -p xloc yloc    position on screen'
		goto 998
	else
		call getarg(1,xstr)	
		call getarg(2,ystr)	
		call ctoi(xstr,xdim)
		call ctoi(ystr,ydim)
		imax=3
		do 100 i=3,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.'-x') then 
				recflag=.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'
				call system(rstr)
				goto 998
			endif
		else
			call seq8(fname,ioerr)
			if (ioerr.ne.0) then
				print *,'i/o error in image name/size'
				call system(rstr)
				goto 998
			endif
		endif
C
		if (recflag) then
			call system(svar)
		endif
		if (retflag) then
			print *,'Press q to quit'
			read (*,101) resp
 101			format(a1)
			if ((resp.eq.'q').or.(resp.eq.'Q')) then
				call system(rstr)
				goto 998
			endif
		endif
 200	continue
	call system(rstr)
 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*1310720 bb
	integer*4 irec
	integer stat,lun
C
	irec=xdim
	xoff=sxsize/2
	yoff=ydim-(sysize/2)
C
	l=lnblnk(fname)
	stat=1
	call rtinit(stat,lun)
 	call entgra
	call blank(1)
C
	open (13,iostat=io,err=998,file=fname(1:l),status='old',
     +	access='direct',recl=irec)
	do 100 i=0,ydim-1
		i1=(xdim*i)+1
		i2=i1+(xdim-1)
		i3=i+1
		read (13,rec=i3,iostat=io,err=998) bb(i1:i2)
 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
 	call movabs(ix,iy)
 	call pixel8(ydim,xdim,bb)
	call blank(0)
 	call quit
 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*3932160 rb
	integer*4 irec
	character*80 rname,gname,bname
	integer stat,lun
	integer xdim3
C
	xdim3=3*xdim
	irec=xdim3
	xoff=sxsize/2
	yoff=ydim-(sysize/2)
C
	l=lnblnk(fname)
	stat=1
	call rtinit(stat,lun)
 	call entgra
 	call rgbtru(1)
	call blank(1)
C
	open (13,iostat=io,err=998,file=fname(1:l),status='old',
     +	access='direct',recl=irec)
	do 100 i=0,ydim-1
		i1=(xdim3*i)+1
		i2=i1+(xdim3-1)
		i3=i+1
		read (13,rec=i3,iostat=io,err=998) rb(i1:i2)
 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
 	call movabs(ix,iy)
 	call pixels(ydim,xdim,rb)
	call blank(0)
 	call quit
 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
	
