pro cat_phaser2,fname
;
;    displays 64x64 images on phaser for cataloging
;
;    fname = root name to search for
;            eg:  fname = 'c1' will search for all files whose
;			file names begin with c1: c1*.img
;
if n_params() eq 0 then fn='' else fn=fname
f=findfile(fn+'*.img')
s = size(f)
if s(0) eq 0 then begin print,'No files found' & return & endif
lastdevice=!d.name
nf=s(1)
print,'Number of files to process = ',nf
ni=0	; used for position of image in display
window,0,xsize=512+128,ysize=512,title=fn
xlabel=520
ylabel=500
ynum = 500
deltay = 10
;g=strpos(f,'.hdr')
;for i=0,nf-1 do f(i)=strmid(f(i),0,g(i))
nimg = 0
istart=0
for i=0,nf-1,8 do begin
    xnum = 18
    nfm=7<(nf-1-i)
    for j=0,nfm do begin
        print,'Processing file:  ',f(i+j)
        x=read_image_old(f(i+j),h)
        sz = size(x)
        if (sz(0) lt 2) then goto, cont
        y=congrid(x,64,64)
        tvscl,y,ni
        xyouts,xnum,ynum,string(i+j+1-istart),/device
        xyouts,xlabel,ylabel-(i+j-istart)*deltay,string(i+j+1-istart,f(i+j), $
               format='(i2,2x,a)'),/device
        ni = ni+1
	xnum = xnum+64
        cont:
    endfor
    ni = ni+2
    ynum = ynum-64
    nimg = nimg+1+nfm
    if ((nimg ge 47) or ((i+j) ge (nf-1))) then begin
       stop
       xlabel=520
       ylabel=500
       ynum = 500
       ni = 0
       nimg=0
       istart=i+8
       x=tvrd(0,0,640,512)
       fi = '~/idlplot.ps'
       count = 0
       repeat begin
           count = count+1
           fp=fi+string( format='(I3.3)',count)
           nfp=findfile(fp) 
           sp = size(nfp)
       endrep until sp(0) eq 0
       set_plot,'ps'
       device,/landscape,xsize=9,ysize=7,/inch,yoffset=9.75, $
              xoffset=0.75,filename=fp

;	in landscape mode be careful of the origin and direction
;       of the xoffset and yoffset.  They are measured from the
;       same corner as in portrait mode which is the lower right
;       in landscape mode.  Also xoffset is measured up (in y
;	direction) and yoffset is measured to the left (in -x 
;	direction).  BE CAREFUL

       tv,x
       device,/close
       set_plot,lastdevice
       spawn,'lpr -h -r -s -Plasco-phaser '+fp
       tv,x-x
    endif
endfor
return
end
