@checkip_subs
@xcheckip_event
pro xcheckip, infil, indir=indir, all=all_out, runall=runall
;+
;NAME:
;	xcheckip
;PURPOSE:
;	To check the IP processing of data products
;SAMPLE CALLING SEQUENCE:
;	xcheckip
;	xcheckip, '/md60/log/sci160k/950118_232658'
;	xcheckip, '950118_232658,950119_010819,950119_013006,950124_002715', indir='/md60/log/sci160k', /runall
;METHOD:
;	1. Telemeter the raw image down in 160K line, manufacture
;	   the new IP data product, compare it to the data product
;	   made and telemetered down in the 160K line.
;	2. Same as above, but the IP data product is telemetered
;	   down in the 5K line.
;HISTORY:
;	Written 10-Apr-95 by M.Morrison
;	11-Apr-95 (MDM) - Modified how to recognize test classes
;			- Many changes/additions
;	 1-May-95 (MDM) - Modified to use GET_XFONT rather than DEF_FONT
;-
;
common xcheckip_blk, all
;
if (n_elements(indir) eq 0) then indir = getenv('MDI_SCI160K_LOG_DIR')
mat=rd_tfile(concat_dir('$MDI_CAL_INFO', 'checkip.table'),nocomment='#',7)
test = mat(0,*)
img_list = mat(6,*)
ndp = fix(mat(5,*))
for i=0,n_elements(test)-1 do test(i) = strmid(test(i), 0, strpos(test(i),'_'))
dpc_list = lonarr(4,n_elements(test))
temp = mat(1:4,*)
reads, temp, dpc_list, format='(z)'
utest = test(uniq(test, sort(test)))
nutest = n_elements(utest)

check_list = ['Cropped Image (CROP)', 'Limb Figure (LIMB)', $
		'Rect Binned (RWBIN)', 'Vector Weighted Bin (VWBIN)']

;-------------------------
;font = def_font()
font = get_xfont(closest=13,/only_one)
if (getenv('MDI_DEF_FONT') ne "") then font = getenv('MDI_DEF_FONT')

widget_control, default_font=font
dummy = !d.window
device, font=font
if (dummy eq -1) then wdelete	;delete the window created when setting the font

base0=widget_base(/column,title='X Check IP', xoff=0, yoff=0)
xmenu, ['QUIT', 'New Dir', 'New File', 'New File(s) by Subset', 'Run All', '** Start Checks **'], $
        base0, $
        buttons=main_buts, /row
xmenu, ['Enable image display', 'Read from 5K'], $
        base0, $
        buttons=main_buts2, /row, /nonexclusive

base2=widget_base(base0, /row, /frame)

;-------------------------

base_col1 = widget_base(base2, /column, /frame)
lab_base_col1 = widget_label(base_col1, value = 'Input Options')

line_base = widget_base(base_col1, /row)
xx       = widget_label(line_base, value = 'SCI160K dir:')
id_indir = widget_text(line_base, /editable, xsize=20, ysize=1)
line_base = widget_base(base_col1, /row)
xx       = widget_label(line_base, value = 'SCI160K File:')
id_infil = widget_text(line_base, /editable, xsize=20, ysize=1)

xmenu, 'Run '+utest, /nonexclusive, base_col1, buttons=test_but, /col, uvalue=intarr(nutest)
;-------------------------

base_col2 = widget_base(base2, /column, /frame)
lab_base_col2 = widget_label(base_col2, value='Diagnostics Options')

xmenu, 'Diagnose '+utest, /exclusive, base_col2, buttons=diag_but, /col, uvalue=intarr(nutest)

;-------------------------

base3=widget_base(base0, /row, /frame)

id_info = widget_text(base3, xsize=60, ysize=4)
widget_control, id_info, /append

;-------------------------

nn = n_elements(mat(0,*))
all = {base:base0, $
	ntest_type: nn, $
	test_type:  mat(0,*), $
	test_dpc:   dpc_list, $
	test_img_list: img_list, $
	test_ndp:   ndp, $
	test_exist: bytarr(nn), $
	nutest:     nutest, $
	utest:      utest, $
	outfil:     ' ', $
	show_plot:  0, $
	use_5k:     0, $
	id_test:    test_but, $
	id_diag:    diag_but, $
        id_infil:   id_infil, 	infil: ' ', $
        id_indir:   id_indir, 	indir: ' ', $
        id_info:    id_info $
}


if (keyword_set(indir)) then begin
    all.indir = indir
    widget_control, all.id_indir, set_value=all.indir
end
if (keyword_set(infil)) then begin
    break_file, str2arr(infil), dsk_log, dir00, filnam
    all.infil = arr2str(strmid(filnam, 0, 13))
    
    if (keyword_set(dir00(0))) then all.indir = dir00(0)
    widget_control, all.id_indir, set_value=all.indir
    widget_control, all.id_infil, set_value=all.infil

    checkip_avail, all, /update_utest
end


widget_control,set_uvalue=all, base0
widget_control,base0,/realize
if (keyword_set(runall)) then for i=0,nutest-1 do widget_control, all.id_test(i), /set_button, set_uvalue=1
xmanager, 'xcheckip', base0

all_out = temporary(all)
return
end


