pro rd_obs4, infil, dset, framen, img, h, tit, img2, qsummary=qsummary, hc=hc
;+
;NAME:
;	rd_obs4
;PURPOSE:
;	To read the IP page dump data into arrays
;SAMPLE CALLING SEQUENCE:
;	rd_obs4, '/md82/log/sci160k/960402_172208', 533, 19, img0, h0
;	rd_obs4, '/md82/log/sci160k/960402_172208', 535, 19, img0, h0, /qsummary
;	rd_obs4, '/md82/log/sci160k/960402_172208', 538, 20, img0, h0, tit, img2, /qsummary
;	for i=545,556 do rd_obs4, infil, i, 19+(i ge 550), /qsummary, hc=hc
;DATA:
;	At Frame 19, the following are downlinked
;	        0       - Sa
;	        1       - Sc
;	        2       - Sd
;	        5       - 1024x1024 vel
;	        6       - 1024x1024 linedepth
;	At Frame 20, the following are downlinked
;	        3       - Si
;	        5       - Cropped Vel           and SCI5K data products
;	        6       - SCI5K data products
;	        7       - Cropped continuum     and SCI5K data products
;	        14      - Time Weighted average data buffers
;
;	           File				Frame19		Frame20
;	/md82/log/sci160k/960402_172208		533-537		538-544
;	/md82/log/sci160k/960402_172208		545-549		550-556
;	/md82/log/sci160k/960402_172208		557-561		562-568
;HISTORY:
;	Written 2-Apr-96 by M.Morrison
;	 2-Apr-96 (MDM) - Corrected the label for page 3
;-
;
read_mdi, infil, dset, img, h, tfr=tfr
;
;;framen = ccd_hdr_info(tfr, 'framen')		;can't use - it's always 19
dpc_str = string(ccd_hdr_info(tfr, 'dpc'), format='(z8.8)')
;
off = -1
if (framen eq 19) then case dpc_str of
    '64000000': begin & off = 1300	& nx = 1040	& ny = 1032	& tit = 'Sa'		& end
    '64000001': begin & off = 1300	& nx = 1040	& ny = 1032	& tit = 'Sc'		& end
    '64000002': begin & off = 1300	& nx = 1040	& ny = 1032	& tit = 'Sd'		& end
    ;
    '64000005': begin & off = 0		& nx = 1024	& ny = 1024	& tit = '1024x1024 vel'	& end
    '64000006': begin & off = 0		& nx = 1024	& ny = 1024	& tit = '1024x1024 linedepth' & end
    ;
    else: stop, 'DPC not valid for frame 19'
end

if (framen eq 20) then case dpc_str of
    '42000fc0': 							  tit='Final vel dataproduct'
    '46040fc0': 							  tit='Final continuum dataproduct'
    '64000003': begin & off = 1300	& nx = 1040	& ny = 1032	& tit='Si'		& end
    ;
    '64000005': begin & off = '726'x	& nx = 798020	& ny = 1	& tit='Cropped Vel'	& end
    '64000006':								  tit='SCI5K dataproducts'
    '64000007': begin & off = '726'x	& nx = 798020	& ny = 1	& tit='Cropped continuum' & end
    '6400000e':								  tit='Time weighed averages'
    else: stop, 'DPC not valid for frame 19'
end
print, '>>> Observables IV Image: ' + tit

if (off ne -1) then begin
    n = nx*long(ny)
    img = temporary(img (off:off+n-1) )
    img = reform(img, nx, ny)
end
;
nx = n_elements(img(*,0))
ny = n_elements(img(0,*))
;
if (keyword_set(qsummary)) then begin
    if (nx eq 798020) and (ny eq 1) then begin
	img2 = mk_dpc_image(512, img, '42000fc0'x)
	;img_summary, img2, tit, hc=hc
	dpc_img_summary, img2, h, tit, hc=hc
    end else begin
	;if (ny ne 1) then img_summary, img, tit, hc=hc
	if (ny ne 1) then dpc_img_summary, img, h, tit, hc=hc
    end
end

end