;
;
;
;;st_ir = 475		& st_ndp = 21500	;1000/20 pix = 50/1pix
;;en_ir = 495		& en_ndp = 22500
;
;st_ir = 478		& st_ndp = 21650
st_ir = 475		& st_ndp = 21500
en_ir = 499		& en_ndp = 22700
;r = 7
r = 6.5
step = 0.5
nstep = 8		;number of menu items
;
menu1_step = 4.0			;step*nstep
nmenu1 = (en_ir - st_ir)/menu1_step
st_ir_arr = indgen(nmenu1)*menu1_step + st_ir
en_ir_arr = indgen(nmenu1)*menu1_step + st_ir + menu1_step - step
menu1 = 'Central Radius Values ' + string(st_ir_arr + r/2., format='(f5.1)') + $
		' to ' + string(en_ir_arr + r/2., format='(f5.1)')
menu1 = '"' + menu1 + '"'
;
out = ['# File: set_limb.src', $
	'#', $
	'program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"', $
	'source "/mdisw/cfl/dev/src/set_limb.src"', $
	'descr "SET_LIMB - routine to set the limb radius and DPC"', $
	' ']
dmp = ['# ', $
	'program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"', $
	'source "/mdisw/cfl/dev/src/ld_dmp_limb.src"', $
	'descr "LD_DMP_LIMB - load and dump the limb lists"', $
	' ', $
	'open d', $
	' ']
;
out0 = [menu1 + ' \', '"QUIT"']
out = [out, 'menu !LS0 "Values" \', out0, ' ']
out = [out, ' ', 'if !LS0 = "QUIT" then', '    goto done', 'end if', ' ']
;
out99 = ''
;
for i=0,nmenu1-1 do begin
        out = [out, 'if !LS0 = ' + menu1(i) + ' then']
	ir_arr2 = indgen(nstep)*step + st_ir_arr(i)
	;menu2 = 'Central Radius ' + string(ir_arr2 + r/2., format='(f5.1)')
	menu2 = string(ir_arr2 + r/2., format='(f5.1)')
	menu2 = '"' + menu2 + '"'
	out0 = [menu2 + ' \', '"QUIT"']
	out2 = ['menu !LS1 "Central Radius" \', out0, ' ', $
		'if !LS1 = "QUIT" then', '    goto done', 'end if', ' ']
	out = [out, '    ' + out2]
	;
	for j=0,n_elements(ir_arr2)-1 do begin
	    st_ir0 = ir_arr2(j)
	    str = string(round(st_ir0*8+r*8), round(st_ir0*8), format='(2i5)')
	    str2 = string(round(2*r), round(st_ir0*8), format='("0x", z1,z3.3)') 
	    ;str3 = '1975'
	    str3 = strtrim(  ceil(( (st_ir0-st_ir)/float(en_ir-st_ir)  * (en_ndp-st_ndp) + st_ndp)/12.*1.006), 2)
	    ;^^^ Make the downlink blocks 0.6% bigger to make sure they get all down (truncates otherwise)
	    out2 = ['if !LS1 = ' + menu2(j) + ' then', $
	    		' tcblock mbiptbl 4 0x1000 0x7000 0 ' + str + ' \', $
			'   296 12 0x8000 0x700b 0 0 ' + str3 + ' 0x1685 ' + str2, $
			;;' tcblock mbipmacl 0x0FCA ' + str2, $
			'end if', ' ']
	    dmp2 = [out2(1:2), $
			'wait time 4', $
			'perf man_dump_ipreg', $
			'tcb mbipldin 0x1b2 3576 6 0x6300 ' + str2 + ' 0x1000  0x7000 0x2000 0', $
			'tcb mbipldin 0x152 0x1e38', $
			'wait time 10', $
			' ']
	    out = [out, '     ' + out2]
	    dmp = [dmp, dmp2]
	    out99 = [out99, str2 + '  ' + str3 + string(fix(str3)*12)]
	end
	out = [out, ' ', 'end if']
end
;
out = [out, ' ', 'done:']
dmp = [dmp, 'close d']
;
prstr, out, /nomore
prstr, out, file='/mdisw/cfl/dev/src/set_limb.src'
prstr, dmp, file='/mdisw/cfl/dev/src/ld_dmp_limb.src'
prstr, out99
end
