pro table1, infil0, strec, year=year, dir=dir, rec1=rec1
;
;
;
;
infil = findfile(infil0)
infil = infil(0)
break_file, infil0, dsk_log, dir0, fil, ext
fil = fil + ext
;
if (not keyword_set(rec1)) then rd_telem, infil, strec, rec1
tim_str = decom(rec1, 'timehead', 1)
timarr  = decom(rec1, 'timehead', 0)	;Telemetry format = DOY,hh,mm,ss
doy2date, timarr(0), year, month, date
dummy = fmt_tim([0,0,0,0,date,month,year], day_str)
tim_str = day_str + '  ' + tim_str
;
fileid = string(year, month,date, format='(3i2.2)') + '.'
fileid = string(year, month,date, format='(3i2.2)') + '.'
for i=1,2 do fileid = fileid + string(timarr(i), '(i2.2)')
;
fileid0 = fileid		;old fileID, which did not have the seconds in the filename
spawn, 'rm -f ' + dir + 'tab' + fileid0		;remove old file
spawn, 'rm -f ' + dir + 'btb' + fileid0
fileid = fileid + string(timarr(3), format='(i2.2)')
;
outfil = dir + 'tab' + fileid
spawn, 'rm -f ' + outfil				;remove it first since it might be owned by someone else and the
							;program would bomb
openw, lun, outfil, /get_lun
print, 'Found a table.  Output file = ', outfil
;
table = bytarr(64*64)
;
for j=0,63 do begin
    minorf = rec1(*,j)
    temp = byte(minorf, 16, 16, 8)
    temp = temp(8:15,*)		;64 values
    temp = byte(temp, 0, 64)	;turn into 1-d array
    insert, table, temp, j*64
end
;
;---- also write out binary file
;
outfil2 = dir + 'btb' + fileid
spawn, 'rm -f ' + outfil2 				;remove it first since it might be owned by someone else and the
                                                        ;program would bomb^P
openw, lun2, outfil2, /get_lun
writeu, lun2, table
free_lun, lun2
;
;--------------------------- Write out text info for sequence table
;
table_header, lun, fil, tim_str, 0
printf, lun, '-------------------------------- Entry Tables --------------------------------'
printf, lun, '  '
off = 0
printf, lun, '       QT/Hi  FWI Seq #', table(off+0)
printf, lun, '       QT/Hi  PFI Seq #', table(off+1)
printf, lun, '       QT/Med FWI Seq #', table(off+2)
printf, lun, '       QT/Med PFI Seq #', table(off+3)
printf, lun, '       Reserved        ', table(off+4)
printf, lun, '       FL/Hi  PFI Seq #', table(off+5)
printf, lun, '       Reserved        ', table(off+6)
printf, lun, '       FL/Med PFI Seq #', table(off+7)

printf, lun, '  '
printf, lun, '-------------------------------- ROIT Tables --------------------------------'
printf, lun, '  '
off = 42*64 + 32
printf, lun, 'ROIT  Shape  Center   Ref_Center
printf, lun, '  #  NS  EW  Row Col Row Col
for itab = 0, 8 do begin
    printf, lun, byte(itab), extract(table, off+8*itab, 8)
end

printf, lun, '  '
printf, lun, '-------------------------------- EXPDT Tables -------------------------------'
printf, lun, '  '
off = 43*64 + 48
barr = extract(table, off, 8)
printf, lun, '     Filter B/A       DPE'
for itab = 0, 5 do begin
    printf, lun, "$(9x, i1,'/X', 11x, i2)", itab, fix(barr(itab))
end

table_header, lun, fil, tim_str, 1
printf, lun, '-------------------------------- Common Tables ------------------------------'
printf, lun, '  '
off = 16
table_com_str, extract(table, off, 64), lun

off = 64+32
for itab = 0, 3 do begin
    if ((itab mod 2) eq 0) then table_header, lun, fil, tim_str, 1
    str = strtrim(itab,2)
    printf, lun, '----------------------------- FWI Table #', str, ' ---------------------------------'
    printf, lun, '  '
    printf, lun, '                  # Loops (2,3,4,5) = ', string(extract(table, off, 4), '(4i3)')
    printf, lun, '  '
    printf, lun, '  '
    printf, lun, '        Flsh Sht Flt A- DPE DIF Res ROI ROI ROI ROI ROI ROI ROI ROI FWI  BLS
    printf, lun, '                    Door            1St 1W  2St 2W  3St 3W  4St 4W  Mode 
    printf, lun, '        ---- --- --- -- --- --- --- --- --- --- --- --- --- --- --- ---- ---
    for j=0,12 do begin
	table_str, 'F', j, extract(table, itab*(24*13+8) + off+8+j*24, 24), str
	printf, lun, str
    end
    printf, lun, ' '
end

off = 22*64
for itab = 0, 3 do begin
    if ((itab mod 2) eq 0) then table_header, lun, fil, tim_str, 1
    str = strtrim(itab,2)
    printf, lun, '----------------------------- PFI Table #', str, ' ---------------------------------'
    printf, lun, '  '
    printf, lun, '                  # Loops (2,3,4,5) = ', string(extract(table, off, 4), '(4i3)')
    printf, lun, '  '
    printf, lun, '  '
    printf, lun, '        Flsh Sht F#0 F#1 F#2 A- DPE DIF Res ROIT Alt Alt AEC AEC AEC AEC AEC
    printf, lun, '                 B/A B/A    Door                     Lev     ULT LLT UAT LAT
    printf, lun, '        ---- --- --- --- --- -- --- --- --- ---- --- --- --- --- --- --- ---
    for j=0,12 do begin
	table_str, 'P', j, extract(table, itab*(24*13+8) + off+8+j*24, 24), str
	printf, lun, str
    end
    printf, lun, ' '
end

spawn, 'chmod g+w ' + outfil		;allow different person to delete the file to run the reformatter
spawn, 'chmod g+w ' + outfil2		;allow different person to delete the file to run the reformatter

free_lun, lun
end

