pro edit3dbins,dat,bins,lat,lon, $
spectra= spectralim, $
EBINS=ebins, $
SUM_EBINS=sum_ebins, $
tbins=tbins, $
classic=classic,$
log=log
if (size(dat,/type) NE 8) then begin
dprint, 'Invalid data'
return
endif
if(dat.valid eq 0) then begin
dprint, 'Invalid data'
return
endif
str_element,spectralim,'bins',bins
options,spectralim,psym=-4
nb = dat.nbins
n_e= dat.nenergy
phi = total(dat.phi,1)/n_e
theta = total(dat.theta,1)/n_e
if keyword_set(ebins) then ebins=ebins(0) $
else ebins=0
if keyword_set(sum_ebins) then sum_ebins=sum_ebins(0) $
else sum_ebins=dat.nenergy
plot3d_new,dat,lat,lon,ebins=ebins,sum_ebins=sum_ebins,tbins=tbins,log=log
state = ['off','on']
colorcode = [!p.background,!p.color]
if n_elements(bins) ne dat.nbins then bins = bytarr(nb)+1
lab=strcompress(indgen(dat.nbins),/rem)
xyouts,phi,theta,lab,align=.5,COLOR=colorcode(bins)
str_element,spectralim,'bins',bins,/add
if keyword_set(classic) then begin
print, 'ON: Button1; OFF: Button2; QUIT: Button3'
cursor,ph,th
button = !err
while button ne 4 do begin
if th ge 1000. then goto, ctnu
pa = pangle(theta,phi,th,ph)
minpa = min(pa,b)
current = bins(b)
bins(b) = button eq 1
if current ne bins(b) then begin
print,ph,th,b,' ',state(bins(b))
xyouts,phi(b),theta(b),lab(b),align=.5,COLOR=colorcode(bins(b))
if keyword_set(spectralim) then begin
w = !d.window
wi,w+1
spectralim.bins = bins
spec3d,dat,lim=spectralim
wi,w
plot3d_new,dat,lat,lon,ebins=ebins,sum_ebins=sum_ebins,/setlim,tbins=tbins,log=log
endif
endif
ctnu:
cursor,ph,th
button = !err
endwhile
endif else begin
print, 'ON/OFF: Left Click; QUIT: Double Click or Right Click'
cursor,ph,th, /up
button = !mouse.button
mouse_time = 0ul
double_click_lim = 350
while (ulong(!mouse.time)-mouse_time) gt double_click_lim and button ne 4 do begin
mouse_time = ulong(!mouse.time)
if ~(th ge 1000.) then begin
if button eq 1 then begin
pa = pangle(theta,phi,th,ph)
minpa = min(pa,b)
bins(b) = ~(bins(b) eq 1)
print,ph,th,b,' ',state(bins(b))
xyouts,phi(b),theta(b),lab(b),align=.5,COLOR=colorcode(bins(b))
if keyword_set(spectralim) then begin
w = !d.window
wi,w+1
spectralim.bins = bins
spec3d,dat,lim=spectralim
wi,w
plot3d_new,dat,lat,lon,ebins=ebins,sum_ebins=sum_ebins,/setlim,tbins=tbins,log=log
endif
endif
endif
cursor,ph,th, /up
button = !mouse.button
endwhile
if (ulong(!mouse.time)-mouse_time) le double_click_lim then begin
pa = pangle(theta,phi,th,ph)
minpa = min(pa,b)
bins(b) = ~(bins(b) eq 1)
xyouts,phi(b),theta(b),lab(b),align=.5,COLOR=colorcode(bins(b))
end
endelse
return
end