function ss_pos, out, ipos
;
;
;
case ipos of
    0: begin & x0 = 31.4	& y0 = 31.4 & end
    1: begin & x0 = 52.0	& y0 = 31.0 & end
    2: begin & x0 = 31.1	& y0 = 11.2 & end
    3: begin & x0 = 10.9	& y0 = 31.8 & end
    4: begin & x0 = 31.3	& y0 = 51.6 & end
endcase

del = sqrt( (out.lasx-x0)^2 + (out.lasy-y0)^2 )
ss = where(del lt 2)
return, ss
end
;------------------------------------------------------------------------------
pro cfig_mich_ang, infil, tit, code
;
;
;
f = 1.0
if (!d.name eq 'X') then f = 6.0 / font_size(1)
;
;txt = rd_tfile('/mdisw/dbase/cal/files/mich2_angle.coeff',4,12,head=head2)
;head = txt(0:7)
;mat = float(str2cols(strtrim(txt(12:*),2)))

mat = rd_tfile(infil, 4, 12, /conv, head=head0)
head = head0(0:7)
arr = str2arr(strcompress(head(2)), delim=' ')	& coeff0 = arr(2)
arr = str2arr(strcompress(head(3)), delim=' ')	& coeff1 = arr(2)
str = '!c ' + arr2str(head, delim='!c    ')
;
xx = findgen(100)/99 *2 -1
yy = xx*coeff1 + coeff0
;
plot, mat(2,*), mat(3,*), tit=tit, psym=1, xtit='Y Relative Position on CCD (-1 to 1)', $
				ytit = 'Central Wave - Position 0 Central Wave (mA)'
oplot, xx, yy
case code of
    0: xyouts, !x.crange(0), !y.crange(1), str, siz=0.8*f
    1: xyouts, !x.crange(0),          -10, str, siz=0.8*f
end
;
end
;------------------------------------------------------------------------------
pro cal_fig_mich, code, hc=hc
;+
;NAME:
;	cal_fig_mich
;PURPOSE:
;	To display the spatial map for the Michelson calibration results
;SAMPLE CALLING SEQUENCE:
;	cal_fig_mich
;	cal_fig_mich, 1
;OPTIONAL INPUT:
;	code	- the pages to display (setting bits)
;HISTORY:
;	Written 29-Jun-94 by M.Morrison
;	30-Aug-94 (MDM) - Added temperature plot to OVEN plot
;V2.1	12-Sep-94 (MDM) - Added plotting of spatial non-uniformity fit figures
;-
;
progver = 'CAL_FIG_MICH  Ver 2.1'
;
if (n_elements(code) eq 0) then code = 255
bits, code, barr
save_dev = !d.name
if (n_elements(hc) eq 0) then hc=0
if (hc) then set_plot, 'ps
;
levels = findgen(30)*10-50
xcontour = (findgen(128)-64)/31.
ycontour = (findgen(128)-64)/31.
;
;---------------------------------------- Page 1 - Michelson One and Two
;
if (barr(0)) then begin
    img1 = rfits('/mdisw/dbase/cal/files/mich1_lspatial.fits', h=h1)
    img2 = rfits('/mdisw/dbase/cal/files/mich2_lspatial.fits', h=h2)
    comments = [sxpar(h2, 'progver'), $
	sxpar(h2, 'prog_run'), $
	'Datasets: ' + string(sxpar(h2, 'dataset'))]
    ;
    fig_summary, 'Michelson Central Wavelength Map', ['I', 'I', 'C', 'C'], subtit='(for Laser data)', $
	img1, 'Michelson #1', $
	img2, 'Michelson #2', $
	img1, 'Michelson #1', $
	img2, 'Michelson #2', $
	levels=levels, xcontour=xcontour, ycontour=ycontour, $
	comments=comments, fmt='(f6.1)', hc=hc, progver=progver
    if (not hc) then pause
end
;
;---------------------------------------- Page 2 - Michelson One (laser and solar)
;
;
if (barr(1)) then begin
    img1 = rfits('/mdisw/dbase/cal/files/mich1_lspatial.fits', h=h1)
    img2 = rfits('/mdisw/dbase/cal/files/mich1_lspatial_sol.fits', h=h2)
    nn = n_elements(img2(*,0))
    ss  = circle_mask(img2, nn/2, nn/2, ' LT ', nn/2-1)
    ss2 = circle_mask(img2, nn/2, nn/2, ' GE ', nn/2-1)
    iavg = total(img2(ss)) / n_elements(ss)
    img2 = img2 - iavg
    img2(ss2) = min(img2(ss))
    dset2 = sxpar(h2, 'FILENAM')
    p = strpos(dset2, '_m')
    dset2 = strmid(dset2, p-3, 3)
    comments = [sxpar(h1, 'progver'), $
	sxpar(h1, 'prog_run'), $
	'Laser Dataset: ' + strtrim(sxpar(h1, 'dataset'),2), $
	'Solar Dataset: ' + dset2]
    ;
    fig_summary, 'Michelson #1 Central Wavelength Maps', ['I', 'I', 'C', 'C'], subtit='(for Laser and Solar data)', $
	img1, 'Michelson #1 (Laser)', $
	img2, 'Michelson #1 (Solar)', $
	img1, 'Michelson #1 (Laser)', $
	img2, 'Michelson #1 (Solar)', $
	con3range=[2,2], con4range=[1,1], $
	levels=levels, $
	comments=comments, fmt='(f6.1)', hc=hc, progver=progver
    if (not hc) then pause
end
;
;---------------------------------------- Page 3 - Michelson Two (laser and solar)
;
;
if (barr(2)) then begin
    img1 = rfits('/mdisw/dbase/cal/files/mich2_lspatial.fits', h=h1)
    img2 = rfits('/mdisw/dbase/cal/files/mich2_lspatial_sol.fits', h=h2)
    nn = n_elements(img2(*,0))
    ss  = circle_mask(img2, nn/2, nn/2, ' LT ', nn/2-1)
    ss2 = circle_mask(img2, nn/2, nn/2, ' GE ', nn/2-1)
    iavg = total(img2(ss)) / n_elements(ss)
    img2 = img2 - iavg
    img2(ss2) = min(img2(ss))
    dset2 = sxpar(h2, 'FILENAM')
    p = strpos(dset2, '_m')
    dset2 = strmid(dset2, p-3, 3)
    comments = [sxpar(h1, 'progver'), $
	sxpar(h1, 'prog_run'), $
	'Laser Dataset: ' + strtrim(sxpar(h1, 'dataset'),2), $
	'Solar Dataset: ' + dset2]
    ;
    fig_summary, 'Michelson #2 Central Wavelength Maps', ['I', 'I', 'C', 'C'], subtit='(for Laser and Solar data)', $
	img1, 'Michelson #2 (Laser)', $
	img2, 'Michelson #2 (Solar)', $
	img1, 'Michelson #2 (Laser)', $
	img2, 'Michelson #2 (Solar)', $
	con3range=[2,2], con4range=[1,1], $
	levels=levels, $
	comments=comments, fmt='(f6.1)', hc=hc, progver=progver
    if (not hc) then pause
end
;
;
;---------------------------------------- Page 4 - Michelson Angular Dependence
;
if (barr(3)) then begin
    tv2, 600, 800, /init, /already, win=1
    !p.multi = [0,1,2]
    cfig_mich_ang, '/mdisw/dbase/cal/files/mich1_angle.coeff', 'Michelson 1', 0
    cfig_mich_ang, '/mdisw/dbase/cal/files/mich2_angle.coeff', 'Michelson 2', 1
    pprint
    clearplot
end
;
;---------------------------------------- Page 5 - Michelson Oven Temperature Dependence
;
if (barr(4)) then begin
    tv2, 600, 800, /init, /already, win=1

    infil = '/mdisw/dbase/cal/files/mich_oven'
    tit = 'Change in Michelsons During Oven Transient'
    out=rd_mmap_sum(infil)
    ;
    iref = 4
    ytit = 'Avg Wavelength change (mA) from Initial State'
    y1 = out.m1.avg				& for i=0,4 do begin & ss = ss_pos(out,i)  & y1(ss) = y1(ss) - y1(ss(iref)) & end
    y2 = out.m2.avg				& for i=0,4 do begin & ss = ss_pos(out,i)  & y2(ss) = y2(ss) - y2(ss(iref)) & end
    ;utplot, out, y2, ytit=ytit, tit=tit	;for i=0,4 do begin & ss = ss_pos(out,i)  & outplot, out(ss), y2(ss), psym=i+1 & end
    ;outplot, out, y1			;for i=0,4 do begin & ss = ss_pos(out,i)  & outplot, out(ss), y1(ss), psym=i+1 & end
    ;
    ss = [ss_pos(out,0), ss_pos(out,1), ss_pos(out,4)]
    ss = ss(sort(ss))
    timerange = ['16-mar-94 7:00', '16-mar-94 20:00']
    !p.position = [0.15, 0.45, 0.95, .95]
    utplot, out(ss), y2(ss), ytit=ytit, tit=tit, timerange=timerange, /xstyle
    outplot, out(ss), y1(ss), linestyle=1
    ;
    xx = !x.crange(0) + .5*deriv_arr(!x.crange)
    xyouts, xx, -35, 'Michelson 1'
    xyouts, xx, -85, 'Michelson 2'
    ;
    xyouts, xx, 120, 'Oven Temperature:', siz=1.5
    xyouts, xx, 100, '   Initial:  36 C', siz=1.5
    xyouts, xx,  80, '   Final:    42 C', siz=1.5

    ;-------------------------- Temperature Portion
    sttim = timerange(0)		;'16-mar-94  3:00'
    entim = timerange(1)		;'16-mar-94 22:00'
    ;
    mnem = ['mtopts5', 'mtopts4']
    temps1 = get_hk_info([sttim, entim], /range, mnem, timarr=timarr1)
    mnem = 'qtopts3n'
    temps2 = get_hk_info([sttim, entim], /range, mnem, timarr=timarr2)
    ;
    ;yrange = [min([min(temps1),min(temps2)]), max([max(temps1),max(temps2)]) ]
    yrange = [30, 45]
    !p.position = [0.15, 0.1, 0.95, .32]
    utplot, timarr1, temps1(*,0), /ynozer, ytit='Oven Temperature (C)', yrange=yrange, /noerase, timerange=timerange, tit=' ', /xstyle
    outplot, timarr1, temps1(*,1), linestyle=1
    outplot, timarr2, temps2, linestyle=2
    ;
    xx = !x.crange(0) + .4*deriv_arr(!x.crange)
    xyouts, xx, 43, 'S/C Sensor "qtopts3n"'
    xyouts, xx, 37, 'MDI Sensors "mtopts4" and "mtopts5"'
    ;
    pprint
end

;
xcontour = (findgen(128)-64)/31.
ycontour = (findgen(128)-64)/31.
levels=findgen(30)*10-50
;---------------------------------------- Page 6 - Michelson One (fit)
;
;
if (barr(5)) then begin
    img1 = rfits('/mdisw/dbase/cal/files/mich1_lspatial.fits', h=h1)
    xfitarr = (findgen(128)-64) / 64. *2
    cal_coeff, '/mdisw/dbase/cal/files/mich1_lspatial.coeff', fit, vals, coeff, text, n=128, xfitarr=xfitarr
    sss = where(img1 eq min(img1))
    fit2 = fit
    fit2(sss) = min(img1)

    comments = [text]
    comments = [text(0:1), 'Coeff=' + arr2str(coeff(0:4), delim = ',  ', /trim), $
                        'Coeff=' + arr2str(coeff(5:*), delim = ',  ', /trim)]

    ;
    fig_summary, 'Michelson #1 Central Wavelength Fits', ['I', 'I', 'I', 'C'], subtit='(3rd order 2-d fit)', $
	img1, 'Michelson #1 Raw (Laser)', $
	fit2, 'Michelson #1 Fit (masked)', $
	fit,  'Michelson #1 Fit', $
	fit,  'Michelson #1 Fit', $
	scl_min = [min(img1), min(img1), min(fit)], scl_max = [max(img1), max(img1), max(fit)], $
	levels=levels, xcontour=xcontour, ycontour=ycontour, $
	comments=comments, fmt='(f6.1)', hc=hc, progver=progver
    if (not hc) then pause
end
;
;---------------------------------------- Page 7 - Michelson Two (fit)
;
;
if (barr(6)) then begin
    img1 = rfits('/mdisw/dbase/cal/files/mich2_lspatial.fits', h=h1)
    xfitarr = (findgen(128)-64) / 64. *2
    cal_coeff, '/mdisw/dbase/cal/files/mich2_lspatial.coeff', fit, vals, coeff, text, n=128, xfitarr=xfitarr
    sss = where(img1 eq min(img1))
    fit2 = fit
    fit2(sss) = min(img1)

    comments = [text]
    comments = [text(0:1), 'Coeff=' + arr2str(coeff(0:4), delim = ',  ', /trim), $
                        'Coeff=' + arr2str(coeff(5:*), delim = ',  ', /trim)]

    ;
    fig_summary, 'Michelson #2 Central Wavelength Fits', ['I', 'I', 'I', 'C'], subtit='(3rd order 2-d fit)', $
	img1, 'Michelson #2 Raw (Laser)', $
	fit2, 'Michelson #2 Fit (masked)', $
	fit,  'Michelson #2 Fit', $
	fit,  'Michelson #2 Fit', $
	scl_min = [min(img1), min(img1), min(fit)], scl_max = [max(img1), max(img1), max(fit)], $
	levels=levels, xcontour=xcontour, ycontour=ycontour, $
	comments=comments, fmt='(f6.1)', hc=hc, progver=progver
    if (not hc) then pause
end
;
set_plot, save_dev
end
