swap_os=['vms','ultrix','OSF']                  ; list of swap machines
chk=where(!version.os eq swap_os,nscount)       ; current OS in noswap list?
qswap = nscount ne 0                            ; assign boolean


print, 'Problem files to choose from:
print, '     /md65/log/sci160k/950329_000458_293
print, '     /md65/log/sci160k/950329_235350_225
if (n_elements(infil) eq 0) then infil = '/md65/log/sci160k/950329_000458_293'
input, 'Enter the input file name ', infil, infil
;
list_tfi, infil
openr, lun, infil+'.tfr', /get_lun
a = assoc(lun, bytarr(1113))
siz = file_stat(infil+'.tfr', /size)
nrec = siz/1113

irec = nrec-1
while (irec ne -1) do begin
    print, '-------------------------------------------------------------------'
    input, 'Enter the rec number (0-' + strtrim(nrec-1,2) + '), -1 to stop', irec, irec
    if (irec lt 0) then goto, done
    rec = a(irec)
    print, 'First 128 bytes of the record'
    print,rec(0:127),format='(4x,16z3)'
    ;
                dummy = long (rec, 9)
                if (qswap) then dec2sun, dummy
                ba = dummy and '3fffff'x
                block_addr = dummy and '3fffff'x
                proc_id = (dummy and 'c00000'x) / 2L^22
                ;block_addr = long (tf_blk, 9) and '3fffff'x
                ;print,block_addr, recnum,format='(2i10,$)'
                case proc_id of
                        0: print, 'Block Address = ', block_addr, '  FILL data'
                        1: print, 'Block Address = ', block_addr, '  COMPRESSED data'
                        2: print, 'Block Address = ', block_addr, '  PACKED data'
                        3: print, 'Block Address = ', block_addr, '  RAW data'
                        else: print, '?????? data'
                endcase

    if (proc_id eq 1) or (proc_id eq 2) then begin
	print, 'Decompressing the record.....
	decom_rec = tfr_decom(rec)
    end else begin
	decom_rec = fix(rec, 14, 549)
    end
    ndecom = n_elements(decom_rec)
    print, 'Number of words in decompressed transfer frame == ', ndecom
    ;
    read_mdi, infil, xxx, nimg, /nimages
    input, 'Enter the dataset number to read (0-'+strtrim(nimg-1,2)+'), -1 to stop ', drec, nimg-1
    if (drec lt 0) then goto, done
    read_mdi, infil, drec, img, head, tfr_head=tfr_head, /nodata
    print, 'First 10 words of this dataset CCD header:'
    print, tfr_head(0:9) and 65535, format='(4x,5z9)'
    ;
    masked = tfr_head(2:3) and 65535
    nword_dpc = masked(1)*2L^16 + masked(0)
    addr = (rec(10) and '0F'x)*2L^16 + rec(11)*2L^8 + rec(12)
    print, '# words in uncompressed data product           ', nword_dpc
    print, 'Address of the start of the transfer frame     ', addr
    print, 'Number of words in decompressed transfer frame ', ndecom
    print, '# words left to be telemetered down            ', nword_dpc-addr-ndecom
end
;
done:
free_lun, lun
end