dir = 'dsk3:[sxtimages.japan6]
infil = 'file2.dat
;
close, 1
openr, 1, dir+infil
a = assoc(1, bytarr(144,64))
;
arr = intarr(4000)
;
qopen = 0
irec1 = 0
while not eof(1) do begin
    aa = a(irec1)
    bb = byte(aa(*,0), 16, 16,8)
    ;print, irec1, bb(*,0)
    print, '$(1x,i5,a,21(z2.2,1x))', irec1, ' - ', aa(0:20)
    ;
    arr(irec1) = aa(8)
    ;
    qvalid = 0
    if ((bb(0) eq 250) and (bb(1) eq 243)) then qvalid = 1
    ;
    if ((not qopen) and (qvalid)) then begin
	outfil = string(aa(0) mod 4, '(z1)') + string(aa(1), '(z2.2)') + $
		'_' + string(aa(2:4), '(3z2.2)') + '.tel'
	openw, 2, dir+outfil, 9216
	print, 'Opening File: ', dir+outfil
	b = assoc(2, bytarr(144, 64))
	irec2 = 0
	qopen = 1
    end
    if (qvalid) then begin
	aa = a(irec1)
	b(irec2) = aa
	irec2 = irec2 + 1
    end else begin
	close, 2
	qopen = 0
    end
    ;
    irec1 = irec1 + 1
end
;
end
