; ccd_temps
pro ccd_temps
task = getenv("MDI_TASK_DIR") + '/mdi_sci'
spawn,[task,'-s 1','-x','-p'],$
unit=u,/noshell
ccd_hdr = intarr(549)	; Buffer for CCD header block read
b = intarr(549)		; Buffer for data block read
avail = { block_addr : 0L, n_words : 0L }
string1='RT  MDI  160K  Image'
xwp = [16,824,430,16,824]
ywp = [704,704,384,16,16]
loadct,3
loops=0
!order = 1	; display from top down
ip_sync = 'DBE128BD'XL
 
window,6,title="Temperatures",xsize=350,ysize=110,retain=1
wshow,6,0
prevdp=0
newdp=1

while ( 1 eq 1) do begin
done = 0
block_ct = 0L
word_ct = 0L
block_addr = 0L
stop_addr = 0L
idx = 0L
temp = 0
dsos_mode = 0
block_size = 549L
data_product_code = 0L
n_full_blocks = 0L
image_words = 0L
part_block_words = 0L
img_size = 0
ip_sync_test = 0L
ip_exec_ct = 0
ip_src_page = 0L
ip_cksum = 0L
cam_temp = lonarr(10)
temp = fltarr(10)

ba = 999
skip = 0
while (ba ne 0) do begin
  if ((skip gt 0) and (skip lt 2)) then print,"Skipping blocks"
  readu,u,avail
  ba = avail.block_addr
  if (ba ne 0) then begin
    skip = skip + 1
    writeu,u,avail.block_addr
    skbuf = intarr(avail.n_words)
    readu,u,skbuf
  endif
endwhile
if (skip gt 0)  then print,skip,format='("Skipped ",i6," blocks")'
;print,"*********************************************************************"
print,"Assembling an image"
print,avail.block_addr,format ='("Available Block addr read is ",z10)'
;print,"Available n_words read is ",avail.n_words
writeu,u,avail.block_addr		;Tell 'em that we want the header block
print,"Reading Header..."
readu,u,ccd_hdr

ip_sync_test = long(ccd_hdr,502)
print,"ip_sync_test ",ip_sync_test
if ip_sync ne ip_sync_test then dsos_mode = 1
print,"dsos_mode ",dsos_mode

for i = 0,9 do begin
    cam_temp(i) = fix(ccd_hdr,514+i*4)
endfor
c_temp = ((cam_temp - 108.0)/4.0) - 150.0
c_temp = c_temp - c_temp(1)


  wset, 6
  erase
  wshow, 6
  t0_str = string (c_temp(0), "(' Ref = ', f7.2)")
  t1_str = string (c_temp(1), "('  T0 = ', f7.2)")
  t2_str = string (c_temp(2), "(' ADC = ', f7.2)")
  t3_str = string (c_temp(3), "('SCBd = ', f7.2)")
  t4_str = string (c_temp(4), "('VReg = ', f7.2)")
  t5_str = string (c_temp(5), "('Drvr = ', f7.2)")
  t6_str = string (c_temp(6), "('PROM = ', f7.2)")
  t7_str = string (c_temp(7), "('CCDA = ', f7.2)")
  t8_str = string (c_temp(8), "('CCDB = ', f7.2)")
  t9_str = string (c_temp(9), "('Case = ', f7.2)")
  !fancy = 0
  xyouts,   0, 90, t0_str, /device
  xyouts, 180, 90, t1_str, /device
  xyouts,   0, 70, t2_str, /device
  xyouts, 180, 70, t3_str, /device
  xyouts,   0, 50, t4_str, /device
  xyouts, 180, 50, t5_str, /device
  xyouts,   0, 30, t6_str, /device
  xyouts, 180, 30, t9_str, /device
  xyouts,   0, 10, t7_str, /device
  xyouts, 180, 10, t8_str, /device
image_done:

end
return
end
