; NAME: ; xconkern ; ; PURPOSE: ; To construct the kernel used in SpeX's telluric correction ; ; CATEGORY: ; Data reduction ; ; CALLING SEQUENCE: ; xconkern ; ; INPUTS: ; None ; ; OUTUTS: ; None ; ; KEYWORD PARAMETERS: ; None ; ; PROCEDURE: ; Normalize the spectrum and deconvolve around a particular line. ; ; ;****************************************************************************** ; ; ----------------------------Support procedures------------------------------ ; ;****************************************************************************** ; pro xconkern_initcommon,std_wave,std_flux,wvega,fvega,fcvega,fc2vega,$ atmos_wave,atmos_flux,YTITLE=ytitle,XTITLE=xtitle common xconkern_state, state ; Build three structures which will hold important info. ; w - contains info pertaining to widget operations. ; r - contains info pertaining to the reduction process. ; d - contains all of the data. ; p - contains info pertaining to the plots. w = {keyboard:0L,$ lineinfo_base:0L,$ message:0L,$ norminfo_base:0L,$ plotwin1:0,$ plotwin2:0,$ plotwin3:0,$ shift_fld:[0L,0L],$ twf_fld:[0L,0L],$ window_bg:0L,$ xconkern_base:0L} r = {cancel:0,$ linereg:[!values.f_nan,!values.f_nan],$ cursormode:'None',$ norm:0,$ nnormreg:0,$ wline:0.,$ scale:0.,$ vshift:0.,$ twf:10.,$ kernel:ptr_new(fltarr(2)),$ normreg:ptr_new(fltarr(2)),$ residplot:0L,$ normdegree:1} d = {atmos_wave:atmos_wave,$ atmos_flux:atmos_flux,$ coeffs:ptr_new(fltarr(2)),$ flux:std_flux,$ fvega:fvega,$ fcvega:fcvega,$ fc2vega:fcvega,$ nflux:std_flux,$ normgoodbad:intarr(n_elements(std_flux)),$ wave:std_wave,$ wvega:wvega} p = {activewin:1,$ buffer:[0.,0.],$ pixmap1_wid:0L,$ pixmap2_wid:0L,$ plotnormreg:0L,$ plotnormfit:0L,$ plotnormspec:0L,$ plotwin1_wid:0L,$ plotwin2_wid:0L,$ xrange1:[min(std_wave,max=max),max],$ xrange2:[0.,0.],$ modlinereg:0,$ modnormreg:0,$ yrange1:[0,max(std_flux,/NAN)],$ plot1size:[750,260],$ yrange2:[0.,0.],$ plot2size:[750,260],$ pscale1:!p,$ xscale1:!x,$ pscale2:!p,$ xscale2:!x,$ xtitle:'!5Wavelength (microns)',$ yscale1:!y,$ yscale2:!y,$ ytitle:'!5DN/s',$ reg:[[!values.f_nan,!values.f_nan],$ [!values.f_nan,!values.f_nan]]} ; Load the three structures in the state structure. state = {w:w,r:r,d:d,p:p} end ; ;****************************************************************************** ; pro xconkern_conkernel common xconkern_state z = where(finite(state.r.linereg) eq 0,count) if count ne 0 then begin ok = dialog_message('Please select a line region.',/error,$ dialog_parent=state.w.xconkern_base) return endif z = where(state.d.wave gt state.r.linereg[0] and $ state.d.wave lt state.r.linereg[1]) vegacorr,state.d.wave[z],state.d.nflux[z],state.d.wvega,$ state.d.fvega,state.d.fc2vega,vshift,redshift state.d.wvega = state.d.wvega*(1.+redshift) fnvega = state.d.fvega/state.d.fc2vega vegaconv,state.d.wave,state.d.nflux,state.d.wvega,state.d.fcvega,$ fnvega,state.r.linereg[0],state.r.linereg[1],wline,kernel,scale,$ WID=state.p.plotwin2_wid,CANCEL=cancel,TWF=state.r.twf if cancel then return state.r.wline = wline state.r.vshift = vshift *state.r.kernel = kernel state.r.scale = scale end ; ;****************************************************************************** ; pro xconkern_definenormreg common xconkern_state range = reform(state.p.reg[0,sort(state.p.reg[0,*])]) if state.r.nnormreg eq 0 then begin *state.r.normreg = range state.r.nnormreg = 1 endif else begin *state.r.normreg = [[*state.r.normreg],[range]] state.r.nnormreg = state.r.nnormreg + 1 endelse end ; ;****************************************************************************** ; pro xconkern_normspec common xconkern_state ; Construct goodbad array ndat = n_elements(state.d.wave) goodbad = intarr(ndat) z = where(finite(*state.r.normreg) eq 1,count) if count eq 0 then begin print, 'Please select a region' return endif for i = 0, state.r.nnormreg-1 do begin tabinv,state.d.wave,(*state.r.normreg)[*,i],idx goodbad[round(idx[0]):round(idx[1])] = 1 endfor ; Now fit the data z = where(goodbad eq 1,count) if count eq 0 then goto,cont *state.d.coeffs = robustpoly1d(state.d.wave,state.d.flux,$ state.r.normdegree,3,0.01,/GAUSSJ,$ IGOODBAD=goodbad,/SILENT,VAR=var) state.d.nflux = state.d.flux/poly(state.d.wave,*state.d.coeffs) tabinv,state.d.wave,state.p.xrange1,idx state.p.xrange2 = state.p.xrange1 state.p.yrange2 = [min((state.d.nflux)[idx[0]:idx[1]]-1,max=ymax,/NAN),ymax] state.p.plotnormspec = 1 cont: end ; ;****************************************************************************** ; pro xconkern_plotupdate common xconkern_state if state.p.activewin eq 1 then begin wset, state.p.pixmap1_wid erase ; Plot the spectrum z = where( state.d.atmos_wave lt state.p.xrange1[1] and $ state.d.atmos_wave gt state.p.xrange1[0]) plot, state.d.atmos_wave[z],state.d.atmos_flux[z],color=5,$ yrange=[0,1],ystyle=5,xstyle=5,xrange=state.p.xrange1,psym=10 ticks = strtrim(findgen(11)*.1,2) axis,yaxis=1,yticks=10,ytickname=ticks,yminor=1,ytitle='!5Atmos',$ color=5 plot,state.d.wave,state.d.flux,/xsty,ysty=9,$ yrange=state.p.yrange1,xrange=state.p.xrange1,psym=10,$ xtitle=state.p.xtitle,ytitle=state.p.ytitle,/NOERASE ; Now plot the normalization region if state.p.plotnormreg then begin for i = 0, state.r.nnormreg-1 do begin if finite((*state.r.normreg)[0,i]) eq 1 then begin tabinv,state.d.wave,(*state.r.normreg)[0,i],idx plots,[(*state.r.normreg)[0,i],(*state.r.normreg)[0,i]],$ [state.p.yrange1[0],state.d.flux[idx]],color=7,linestyle=2 endif if finite((*state.r.normreg)[1,i]) eq 1 then begin tabinv,state.d.wave,(*state.r.normreg)[1,i],idx plots,[(*state.r.normreg)[1,i],(*state.r.normreg)[1,i]],$ [state.p.yrange1[0],state.d.flux[idx]],color=7,linestyle=2 endif endfor endif ; Now the polynomial fit if state.p.plotnormfit then oplot,state.d.wave,$ poly(state.d.wave,*state.d.coeffs),psym=10,color=3 state.p.xscale1 = !x state.p.yscale1 = !y state.p.pscale1 = !p ; Copy the results to the plot window. wset, state.p.plotwin1_wid erase device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap1_wid] endif else begin wset, state.p.pixmap2_wid erase plot,state.d.wave,state.d.nflux-1,/xsty,ysty=1,$ yrange=state.p.yrange2,xrange=state.p.xrange2,psym=10,$ xtitle=state.p.xtitle,ytitle=state.p.ytitle plots,!x.crange,[0,0],linestyle=1,color=3,thick=2 state.p.xscale2 = !x state.p.yscale2 = !y state.p.pscale2 = !p if finite(state.r.linereg[0]) eq 1 then $ plots,[state.r.linereg[0],state.r.linereg[0]],!y.crange,linestyle=2,$ color=7 if finite(state.r.linereg[1]) eq 1 then $ plots,[state.r.linereg[1],state.r.linereg[1]],!y.crange,linestyle=2,$ color=7 wset, state.p.plotwin1_wid erase device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap2_wid] endelse end ; ;****************************************************************************** ; pro xconkern_whichline common xconkern_state del = state.p.xrange1[1]-state.p.xrange1[0] for i = 0,state.r.nnormreg-1 do begin if state.p.reg[0,0] gt (*state.r.normreg)[0,i]-(del*0.005) and $ state.p.reg[0,0] lt (*state.r.normreg)[0,i]+(del*0.005) then begin (*state.r.normreg)[0,i] = !values.f_nan state.p.modnormreg = 1 xconkern_plotupdate endif if state.p.reg[0,0] gt (*state.r.normreg)[1,i]-(del*0.005) and $ state.p.reg[0,0] lt (*state.r.normreg)[1,i]+(del*0.005) then begin (*state.r.normreg)[1,i] = !values.f_nan state.p.modnormreg = 1 xconkern_plotupdate endif endfor end ; ;****************************************************************************** ; ; ------------------------------Event Handlers-------------------------------- ; ;****************************************************************************** ; pro xconkern_event, event common xconkern_state widget_control, event.id, GET_UVALUE = uvalue widget_control, /HOURGLASS case uvalue of 'Accept': widget_control, event.top, /DESTROY 'Cancel': begin state.r.cancel = 1 widget_control, event.top, /DESTROY end 'Clear Line Region': begin state.r.linereg[*] = !values.f_nan xconkern_plotupdate end 'Clear Normalization': begin *state.r.normreg = !values.f_nan state.r.nnormreg = 0 state.p.modnormreg = 0 state.p.plotnormreg = 0 state.p.plotnormfit = 0 state.p.plotnormspec = 0 state.r.cursormode = 'None' xconkern_plotupdate wset, state.p.pixmap2_wid erase wset, state.p.plotwin2_wid erase end 'Construct Kernel': xconkern_conkernel 'Keyboard': begin case strtrim(event.ch,2) of 'c': begin state.r.cursormode = 'None' state.p.reg[*] = !values.f_nan xconkern_plotupdate end 'm': begin state.p.plotnormfit = 0 state.r.cursormode = 'Modify' state.p.reg[*] = !values.f_nan end 'n': begin state.r.cursormode = 'Norm' state.p.reg[*] = !values.f_nan end 's': begin state.r.cursormode = 'Select Line' state.p.reg[*] = !values.f_nan state.r.linereg[*] = !values.f_nan end 'w': begin if state.p.activewin eq 1 then begin state.p.xrange1 = [min((state.d.wave),max=max),max] state.p.yrange1 = [0,max(state.d.flux,/NAN)] xconkern_plotupdate endif if state.p.activewin eq 2 then begin state.p.xrange2 = [min((state.d.wave),max=max),max] state.p.yrange2 = [0,max(state.d.nflux,/NAN)] xconkern_plotupdate endif end 'x': begin if state.r.cursormode eq 'None' then begin state.r.cursormode = 'XZoom' state.p.reg[*] = !values.f_nan endif end 'y': begin if state.r.cursormode eq 'None' then begin state.r.cursormode = 'YZoom' state.p.reg[*] = !values.f_nan endif end 'z': begin state.r.cursormode = 'Zoom' state.p.reg[*] = !values.f_nan end else: endcase end 'Fit Degree': begin x = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15'] state.r.normdegree = x[event.index] end 'Normalize Spectrum': begin xconkern_normspec state.p.plotnormfit=1 xconkern_plotupdate ; state.p.activewin = 2 ; xconkern_plotupdate ; widget_control, state.w.window_bg, SET_VALUE=1 ; widget_control, state.w.plotwin1,EVENT_PRO='xconkern_plotwinevent2' ; widget_control, state.w.norminfo_base,MAP=0 ; widget_control, state.w.lineinfo_base,MAP=1 state.r.cursormode = 'None' end 'Plot Window': begin widget_control, state.w.norminfo_base,MAP=0 widget_control, state.w.lineinfo_base,MAP=0 if event.value eq 'Norm' then begin state.p.activewin = 1 xconkern_plotupdate ; wset, state.p.plotwin1_wid ; erase ; device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ ; state.p.pixmap1_wid] widget_control, state.w.plotwin1,EVENT_PRO='xconkern_plotwinevent1' widget_control, state.w.norminfo_base,MAP=1 endif else begin state.p.activewin = 2 xconkern_plotupdate ; wset, state.p.plotwin1_wid ; erase ; device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ ; state.p.pixmap2_wid] widget_control, state.w.plotwin1,EVENT_PRO='xconkern_plotwinevent2' widget_control, state.w.lineinfo_base,MAP=1 endelse end 'Retry': begin if state.p.activewin eq 1 then begin xconkern_normspec state.p.plotnormfit=1 state.r.cursormode = 'None' xconkern_plotupdate endif xconkern_conkernel end 'TWF Field': begin val = cfld(state.w.twf_fld,4,/EMPTY,CANCEL=cancel) if cancel then return state.r.twf = val xconkern_conkernel end else: endcase cont: end ; ;****************************************************************************** ; pro xconkern_plotwinevent1, event common xconkern_state widget_control, event.id, GET_UVALUE = uvalue ; Check to see if it is a TRACKING event. if strtrim(tag_names(event,/STRUCTURE_NAME),2) eq 'WIDGET_TRACKING' then begin if event.enter eq 0 then widget_control, state.w.keyboard, SENSITIVE=0 wset, state.p.plotwin1_wid erase device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap1_wid] goto, cont endif ; If not, set the keyboard focus and active window. widget_control, state.w.keyboard, /INPUT_FOCUS, /SENSITIVE state.p.activewin = 1 !p = state.p.pscale1 !x = state.p.xscale1 !y = state.p.yscale1 x = event.x/float(state.p.plot1size[0]) y = event.y/float(state.p.plot1size[1]) xy = convert_coord(x,y,/NORMAL,/TO_DATA) case state.r.cursormode of 'Norm': begin if event.type ne 1 then goto, out z = where(finite(state.p.reg) eq 1,count) if count eq 0 then begin state.p.reg[*,0] = xy[0:1] tabinv,state.d.wave,xy[0],idx wset, state.p.pixmap1_wid plots,[xy[0],xy[0]],[state.p.yrange1[0],state.d.flux[idx]],$ color=6,linestyle=1,thick=2 wset, state.p.plotwin1_wid device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],$ 0,0,state.p.pixmap1_wid] endif if count eq 2 then begin state.p.reg[*,1] = xy[0:1] xconkern_definenormreg state.p.reg[*] = !values.f_nan state.p.plotnormreg = 1 xconkern_plotupdate endif end 'Modify': begin case event.type of 0: begin state.p.reg[*,0] = xy[0:1] xconkern_whichline end 1: begin if not state.p.modnormreg then goto, cont z = where(finite(*state.r.normreg) eq 0) (*state.r.normreg)[z] = xy[0] xconkern_plotupdate state.p.modnormreg = 0 end else: end end 'XZoom': begin if event.type ne 1 then goto, out z = where(finite(state.p.reg) eq 1,count) if count eq 0 then begin state.p.reg[*,0] = xy[0:1] wset, state.p.pixmap1_wid plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,$ /DEVICE,linestyle=1,thick=2 wset, state.p.plotwin1_wid device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap1_wid] endif else begin state.p.reg[*,1] = xy[0:1] state.p.xrange1 = [min(state.p.reg[0,*],max=m),m] state.r.cursormode = 'None' state.p.reg[*] = !values.f_nan xconkern_plotupdate endelse end 'YZoom': begin if event.type ne 1 then goto, out z = where(finite(state.p.reg) eq 1,count) if count eq 0 then begin state.p.reg[*,0] = xy[0:1] wset, state.p.pixmap1_wid plots, [0,state.p.plot1size[0]],[event.y,event.y],color=2,$ /DEVICE,linestyle=1,thick=2 wset, state.p.plotwin1_wid device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap1_wid] endif else begin state.p.reg[*,1] = xy[0:1] state.p.yrange1 = [min(state.p.reg[1,*],max=m),m] state.r.cursormode = 'None' state.p.reg[*] = !values.f_nan xconkern_plotupdate endelse end 'Zoom': begin if event.type ne 1 then goto, out z = where(finite(state.p.reg) eq 1,count) if count eq 0 then state.p.reg[*,0] = xy[0:1] else begin state.p.reg[*,1] = xy[0:1] state.p.xrange1 = [min(state.p.reg[0,*],max=max),max] state.p.yrange1 = [min(state.p.reg[1,*],max=max),max] state.r.cursormode = 'None' state.p.reg[*] = !values.f_nan xconkern_plotupdate endelse end else: endcase out: wset, state.p.plotwin1_wid device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap1_wid] case state.r.cursormode of 'XZoom': plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,/DEVICE 'YZoom': plots, [0,state.p.plot1size[0]],[event.y,event.y],color=2,/DEVICE 'Zoom': begin plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,/DEVICE plots, [0,state.p.plot1size[0]],[event.y,event.y],color=2,/DEVICE xy = convert_coord(event.x,event.y,/DEVICE,/TO_DATA) plots,[state.p.reg[0,0],state.p.reg[0,0]],[state.p.reg[1,0],xy[1]],$ linestyle=2,color=2 plots, [state.p.reg[0,0],xy[0]],[state.p.reg[1,0],state.p.reg[1,0]],$ linestyle=2,color=2 end else: begin plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,/DEVICE plots, [0,state.p.plot1size[0]],[event.y,event.y],color=2,/DEVICE end endcase cont: end ; ;****************************************************************************** ; pro xconkern_plotwinevent2, event common xconkern_state widget_control, event.id, GET_UVALUE = uvalue ; Check to see if it is a TRACKING event. if strtrim(tag_names(event,/STRUCTURE_NAME),2) eq 'WIDGET_TRACKING' then begin if event.enter eq 0 then widget_control, state.w.keyboard, SENSITIVE=0 wset, state.p.plotwin1_wid erase device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap2_wid] goto, cont endif ; If not, set the keyboard focus and active window. widget_control, state.w.keyboard, /INPUT_FOCUS, /SENSITIVE state.p.activewin = 2 !p = state.p.pscale2 !x = state.p.xscale2 !y = state.p.yscale2 x = event.x/float(state.p.plot1size[0]) y = event.y/float(state.p.plot1size[1]) xy = convert_coord(x,y,/NORMAL,/TO_DATA) case state.r.cursormode of 'Modify': begin case event.type of 0: begin ; Make sure the region has been define z = where(finite(state.r.linereg) eq 0,count) if count ne 0 then begin state.r.cursormode = 'None' return endif del = state.p.xrange2[1]-state.p.xrange2[0] if xy[0] gt state.r.linereg[0]-(del*0.005) and $ xy[0] lt state.r.linereg[0]+(del*0.005) then begin state.r.linereg[0] = !values.f_nan state.p.modlinereg = 1 endif if xy[0] gt state.r.linereg[1]-(del*0.005) and $ xy[0] lt state.r.linereg[1]+(del*0.005) then begin state.p.modlinereg = 1 state.r.linereg[1] = !values.f_nan endif xconkern_plotupdate end 1: begin if not state.p.modlinereg then goto, out z = where(finite(state.r.linereg) eq 0,count) state.r.linereg[z] = xy[0] state.r.cursormode = 'None' state.p.modlinereg = 0 xconkern_plotupdate end else: end end 'Select Line': begin if event.type ne 1 then goto, out z = where(finite(state.r.linereg) eq 1,count) if count eq 0 then begin state.r.linereg[0] = xy[0] xconkern_plotupdate endif else begin state.r.linereg[1] = xy[0] state.r.cursormode = 'None' xconkern_plotupdate endelse end 'XZoom': begin if event.type ne 1 then goto, out z = where(finite(state.p.reg) eq 1,count) if count eq 0 then begin state.p.reg[*,0] = xy[0:1] wset, state.p.pixmap2_wid plots, [event.x,event.x],[0,state.p.plot2size[1]],color=2,$ /DEVICE,linestyle=1,thick=2 wset, state.p.plotwin1_wid device, copy=[0,0,state.p.plot2size[0],state.p.plot2size[1],0,0,$ state.p.pixmap2_wid] endif else begin state.p.reg[*,1] = xy[0:1] state.p.xrange2 = [min(state.p.reg[0,*],max=m),m] state.r.cursormode = 'None' state.p.reg[*] = !values.f_nan xconkern_plotupdate endelse end 'YZoom': begin if event.type ne 1 then goto, out z = where(finite(state.p.reg) eq 1,count) if count eq 0 then begin state.p.reg[*,0] = xy[0:1] wset, state.p.pixmap2_wid plots, [0,state.p.plot2size[0]],[event.y,event.y],color=2,$ /DEVICE,linestyle=1,thick=2 wset, state.p.plotwin1_wid device, copy=[0,0,state.p.plot2size[0],state.p.plot2size[1],0,0,$ state.p.pixmap2_wid] endif else begin state.p.reg[*,1] = xy[0:1] state.p.yrange2 = [min(state.p.reg[1,*],max=m),m] state.r.cursormode = 'None' state.p.reg[*] = !values.f_nan xconkern_plotupdate endelse end 'Zoom': begin if event.type ne 1 then goto, out z = where(finite(state.p.reg) eq 1,count) if count eq 0 then state.p.reg[*,0] = xy[0:1] else begin state.p.reg[*,1] = xy[0:1] state.p.xrange2 = [min(state.p.reg[0,*],max=max),max] state.p.yrange2 = [min(state.p.reg[1,*],max=max),max] state.r.cursormode = 'None' state.p.reg[*] = !values.f_nan xconkern_plotupdate endelse end else: endcase out: wset, state.p.plotwin1_wid device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap2_wid] case state.r.cursormode of 'Select Line': plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,$ /DEVICE 'Modify': begin plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,/DEVICE plots, [0,state.p.plot1size[0]],[event.y,event.y],color=2,/DEVICE end 'XZoom': plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,/DEVICE 'YZoom': plots, [0,state.p.plot1size[0]],[event.y,event.y],color=2,/DEVICE 'Zoom': begin plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,/DEVICE plots, [0,state.p.plot1size[0]],[event.y,event.y],color=2,/DEVICE xy = convert_coord(event.x,event.y,/DEVICE,/TO_DATA) plots,[state.p.reg[0,0],state.p.reg[0,0]],[state.p.reg[1,0],xy[1]],$ linestyle=2,color=2 plots, [state.p.reg[0,0],xy[0]],[state.p.reg[1,0],state.p.reg[1,0]],$ linestyle=2,color=2 end else: begin plots, [event.x,event.x],[0,state.p.plot1size[1]],color=2,/DEVICE plots, [0,state.p.plot1size[0]],[event.y,event.y],color=2,/DEVICE end endcase cont: end ; ;****************************************************************************** ; pro xconkern_resize,event common xconkern_state widget_control, state.w.xconkern_base, tlb_get_size = size ; Window 1 state.p.plot1size[0]=size[0]-state.p.buffer[0] state.p.plot1size[1]=(size[1]-state.p.buffer[1])*0.5 widget_control, state.w.plotwin1, draw_xsize=state.p.plot1size[0] widget_control, state.w.plotwin1, draw_ysize=state.p.plot1size[1] wdelete,state.p.pixmap1_wid window, /free, /pixmap,xsize=state.p.plot1size[0],ysize=state.p.plot1size[1] state.p.pixmap1_wid = !d.window wset, state.p.plotwin1_wid device, copy=[0,0,state.p.plot1size[0],state.p.plot1size[1],0,0,$ state.p.pixmap1_wid] ; Window 2 state.p.plot2size[0]=size[0]-state.p.buffer[0] state.p.plot2size[1]=(size[1]-state.p.buffer[1])*0.5 widget_control, state.w.plotwin2, draw_xsize=state.p.plot2size[0] widget_control, state.w.plotwin2, draw_ysize=state.p.plot2size[1] wdelete,state.p.pixmap2_wid window, /free, /pixmap,xsize=state.p.plot2size[0],ysize=state.p.plot2size[1] state.p.pixmap2_wid = !d.window tmp = state.p.activewin state.p.activewin = (state.p.activewin eq 1) ? 2:1 xconkern_plotupdate state.p.activewin = tmp xconkern_plotupdate end ; ;****************************************************************************** ; ; ------------------------------Main Program-------------------------------- ; ;****************************************************************************** ; pro xconkern,std_wave,std_flux,wvega,fvega,fcvega,fc2vega,atmos_wave,$ atmos_flux,wline,kernel,scale,vshift,YTITLE=ytitle,$ XTITLE=xtitle,CANCEL=cancel common xconkern_state if not xregistered('xconkern') then begin xconkern_initcommon,std_wave,std_flux,wvega,fvega,fcvega,fc2vega,$ atmos_wave,atmos_flux,YTITLE=ytitle,XTITLE=xtitle ; Build the widget. buttonfont = '-adobe-helvetica-bold-r-normal--14-140-75-75-p-82-iso8859-1' textfont = '-adobe-helvetica-medium-r-normal--0-0-75-75-p-0-iso8859-1' state.w.xconkern_base = widget_base(title='Xconkern', $ /COLUMN,$ /TLB_SIZE_EVENTS) quit_button = widget_button(state.w.xconkern_base,$ FONT=buttonfont,$ EVENT_PRO='xconkern_event',$ VALUE='Cancel',$ UVALUE='Cancel') state.w.keyboard = widget_text(state.w.xconkern_base, $ /ALL_EVENTS, $ SCR_XSIZE=1, $ SCR_YSIZE=1, $ UVALUE='Keyboard', $ EVENT_PRO='xconkern_event',$ VALUE= '') row_base = widget_base(state.w.xconkern_base,$ /ROW,$ FRAME=1,$ EVENT_PRO='xconkern_event',$ /BASE_ALIGN_CENTER) state.w.window_bg = cw_bgroup(row_base,$ font=buttonfont,$ ['Norm','Line'],$ /ROW,$ /RETURN_NAME,$ /NO_RELEASE,$ /EXCLUSIVE,$ LABEL_LEFT='Window:',$ UVALUE='Plot Window',$ SET_VALUE=0) subrow_base = widget_base(row_base) state.w.norminfo_base = widget_base(subrow_base,$ /BASE_ALIGN_CENTER,$ /ROW) value = ['1','2','3','4','5','6','7','8','9','10','11','12',$ '13','14','15'] fitorder_dl = widget_droplist(state.w.norminfo_base,$ FONT=buttonfont,$ TITLE='Fit Degree:',$ VALUE=value,$ UVALUE='Fit Degree') button = widget_button(state.w.norminfo_base,$ VALUE='Normalize Spectrum',$ FONT=buttonfont,$ UVALUE='Normalize Spectrum') button = widget_button(state.w.norminfo_base,$ VALUE='Clear',$ FONT=buttonfont,$ UVALUE='Clear Normalization') state.w.lineinfo_base = widget_base(subrow_base,$ /BASE_ALIGN_CENTER,$ /ROW,$ MAP=0) button = widget_button(state.w.lineinfo_base,$ VALUE='Clear',$ FONT=buttonfont,$ UVALUE='Clear Line Region') state.w.plotwin1 = widget_draw(state.w.xconkern_base,$ XSIZE=state.p.plot1size[0],$ YSIZE=state.p.plot1size[1],$ /TRACKING_EVENTS,$ /BUTTON_EVENTS,$ /MOTION_EVENTS,$ EVENT_PRO='xconkern_plotwinevent1',$ UVALUE='Plot Window 1') row_base = widget_base(state.w.xconkern_base,$ EVENT_PRO='xconkern_event',$ /ROW,$ FRAME=1,$ /BASE_ALIGN_CENTER) twf_fld = coyote_field2(row_base,$ LABELFONT=buttonfont,$ fieldfont=textfont,$ TITLE='TWF Factor:',$ UVALUE='TWF Field',$ VALUE='10.0',$ EVENT_PRO='xconkern_event',$ XSIZE=10,$ /CR_ONLY,$ TEXTID=textid) state.w.twf_fld = [twf_fld,textid] button = widget_button(row_base,$ FONT=buttonfont,$ VALUE='Construct Kernel',$ UVALUE='Construct Kernel') button = widget_button(row_base,$ FONT=buttonfont,$ VALUE='Retry',$ UVALUE='Retry') state.w.plotwin2 = widget_draw(state.w.xconkern_base,$ XSIZE=state.p.plot2size[0],$ YSIZE=state.p.plot2size[1],$ UVALUE='Plot Window 2') button = widget_button(state.w.xconkern_base,$ FONT=buttonfont,$ EVENT_PRO='xconkern_event',$ VALUE='Accept',$ UVALUE='Accept') ; Get things running. Center the widget using the Fanning routine. mkct centertlb,state.w.xconkern_base widget_control, state.w.xconkern_base, /REALIZE ; Get plotwin ids widget_control, state.w.plotwin1, GET_VALUE=x state.p.plotwin1_wid = x widget_control, state.w.plotwin2, GET_VALUE=x state.p.plotwin2_wid = x window, /free, /pixmap,xsize=state.p.plot1size[0],$ ysize=state.p.plot1size[1] state.p.pixmap1_wid = !d.window window, /free, /pixmap,xsize=state.p.plot2size[0],$ ysize=state.p.plot2size[1] state.p.pixmap2_wid = !d.window ; Get sizes for things. widget_geom = widget_info(state.w.xconkern_base, /geometry) state.p.buffer[0]=widget_geom.xsize-state.p.plot1size[0] state.p.buffer[1]=widget_geom.ysize-state.p.plot1size[1]-$ state.p.plot2size[1] xconkern_plotupdate ; Start the Event Loop. This will be a non-blocking program. XManager, 'xconkern', $ state.w.xconkern_base,$ event_handler='xconkern_resize' kernel = *state.r.kernel wline = state.r.wline scale = state.r.scale cancel = state.r.cancel vshift = state.r.vshift ptr_free, state.r.kernel ptr_free, state.r.normreg ptr_free, state.d.coeffs state = 0B endif end