get_lun,u
spawn,'/usr/people/rogerc/dev/sccs/t3',unit=u,/noshell
e = bytarr(2584)	; Buffer for engr header block read
a = intarr(1064960)	; Buffer for displayable image
e1 = intarr(549)		; Buffer for non-header block reads
e2 = intarr(549)		; Buffer for non-header block reads
e3 = intarr(194)		; Buffer for non-header block reads
b = intarr(549)		; Buffer for non-header block reads
b2 = intarr(355)		; Buffer for non-header block reads
avail = { block_addr : 0L, n_words : 0L }
done = 0
got_header = 0
word_ct = 0L
block_addr = 0L
stop_addr = 0L
idx = 0L
temp = 0
first_words = 355L
last_words = 449

repeat begin
  readu,u,avail
  print,"Available Block addr read is ",avail.block_addr
  print,"Available n_words read is ",avail.n_words
  case avail.block_addr of
    0: begin	;	Read the First Engineering Block
         if got_header eq 0 then begin
           writeu,u,avail.block_addr	; Tell 'em that we want the block
           readu,u,e1			; Read into the block buffer
	 end else begin			; If already have the header
           done = 1
         endelse
       end
    1: begin	;	Read the Second Engineering Block
         writeu,u,avail.block_addr	; Tell 'em that we want the block
         readu,u,e2			; Read into the block buffer
       end
    2: begin	;	Read the Third Engineering Block (Partial)
         writeu,u,avail.block_addr	; Tell 'em that we want the block
         readu,u,e3			; Read into the block buffer
         readu,u,b2			; Read into the block buffer
         e(0) = b2
         block_addr = first_words
         word_ct = word_ct + first_words
       end
    else: begin
            writeu,u,avail.block_addr; Tell 'em that we want the block
 print,"storing at block_addr ",block_addr
            if avail.block_addr lt 1065060 then begin	; full block
              readu,u,b		; Read into the block buffer
              a(block_addr) = b
              block_addr = block_addr + avail.n_words
              word_ct = word_ct + avail.n_words
            end else begin	; last full block
	      stop_addr = block_addr + last_words - 1
	      for idx=block_addr,stop_addr do begin
                readu,u,temp		; Read into the block buffer
                a(idx) = temp
	      endfor
              done = 1
              block_addr = block_addr + last_words
              word_ct = word_ct + last_words
            endelse
          end
  endcase
print,"word #: ",word_ct
endrep until done eq 1
print,"DONE, block_addr ",block_addr
print,"final read #: ",word_ct

img = reform(a,1040,1024,/overwrite)
free_lun,u
loadct,1
window,xsize=1024,ysize=1024
tvscl,img(0:1023,*)
end
