Calviewplot.m
Jump to navigation
Jump to search
% NOTES:
% Enters new times, temp into qcaled window
%
function out=calviewplot(action)
switch action
case 0
%initialize figure
fig=figure;
out=fig;
zoom on % leave here, erases buttondownfcn if moved afterward
set(findall(0,'Tag','calviewBut'),'Userdata',fig);
%put the pointer into the go button
set(findall(0,'Tag','goBut'),'Userdata',...
findall(0,'Tag','calviewBut'));
set(0,'CurrentFig',fig);
set(fig,'pos',[130 30 600 520]);
set(fig,'Tag','calviewFig');
%initialize the plots
subplot(221); %calplot
set(gca,'Tag','calplot');
set(gca,'ButtonDownFcn','calviewplot(3)')
subplot(425); %tempplot
set(gca,'Tag','tempplot');
subplot(414); %specplot
set(gca,'Tag','specplot');
h=subplot(222); %dummy for table
get(gca,'Pos');
wavepos=[ans(1:2) ans(3)/3 ans(4)];
meanpos=[wavepos(1)+wavepos(3) wavepos(2) wavepos(3:4)];
stdpos=[meanpos(1)+wavepos(3) wavepos(2) wavepos(3:4)];
table(fig,wavepos,meanpos,stdpos);
delete(h);
%
rbutpos=[meanpos(1) wavepos(2) wavepos(3) wavepos(4)/10];
rbut(fig,rbutpos)
subplot(426); %stdplot
set(gca,'Tag','stdplot');
signature('calview.m');
%if this window gets closed, calviewBut should be cleared
%set(fig,'Close','disp(''Use Go for next file, or Quit to close all'')');
case 1
[ax_han,fig]=get_ax;
axes(ax_han(1));
udata=get(fig,'Userdata'); %global for all files
prop='a';
if udata.par.prop,
prop='c';
end
ylabel([prop '-' prop '_w (m^{-1})']);
xlabel('time (min)');
axes(ax_han(2));
ylabel('instr. temp. (C)');
axes(ax_han(3));
ylabel([prop '-' prop '_w (m^{-1})']);
xlabel('\lambda (nm)');
axes(ax_han(5));
ylabel('Std. Dev.');
xlabel('\lambda (nm)');
case 2
ax_han=get_ax;
udata=get(ax_han(1),'Userdata');
%initialize calplot
calviewplot1(udata);
axis auto
t_lim=udata.t_lim;
calviewmask(t_lim)
zoom reset
calviewplot2(udata);
%calculate the stats
calviewplot(6)
case 3
%calplot callback
ax_han=get_ax;
udata=get(ax_han(1),'Userdata');
newdata=get(ax_han(3),'Userdata');
%calculate the stats
calviewstats(udata,newdata);
%plot new spectra
newdata=get(ax_han(3),'Userdata');
calviewplot3(udata,newdata);
%update the stats table
newdata=get(ax_han(3),'Userdata');
calviewplot4(udata,newdata);
%update stdplot
calviewplot5(udata,newdata);
case 4
%AllChan callback
ax_han=get_ax;
axes(ax_han(1));
udata=get(gca,'Userdata');
t_lim=get(gca,'Xlim');
zoom out
calviewplot1(udata);
calviewmask(t_lim);
case 5
%AllTime callback
%calviewplot1;
calviewmask([0 0]);
calviewplot(3)
case 6
[ax_han,fig]=get_ax;
%ResetStats callback
l_han=findobj(ax_han(5),'Type','line')
delete(l_han)
set(ax_han(5),'userdata',[])
l_han=findobj(ax_han(3),'Type','line')
delete(l_han)
set(ax_han(3),'userdata',[])
calviewplot(3)
case 7
%ResetTime callback
ax_han=get_ax;
udata=get(ax_han(1),'Userdata');
t_lim=udata.t_lim;
calviewmask(t_lim)
calviewplot(3)
case 8
[ax_han,fig]=get_ax()
axes(ax_han(1));
ax=axis
minmin=ax(1);
maxmin=ax(2);
t1=sprintf('%5.2f',minmin)
t2=sprintf('%5.2f',maxmin)
set(findobj('Tag','t1Box'),'String',t1);
set(findobj('Tag','t2Box'),'String',t2);
mtemp=sprintf('%6.1f',get(ax_han(2),'Userdata'))
set(findobj('Tag','InttempBox'),'String',mtemp);
qcaled_cb('update');
return
end
return
function [ax_han,fig]=get_ax()
fig=get(findall(0,'Tag','calviewBut'),'Userdata');
ax_han(1)=findobj(fig,'Tag','calplot');
ax_han(2)=findobj(fig,'Tag','tempplot');
ax_han(3)=findobj(fig,'Tag','specplot');
ax_han(5)=findobj(fig,'Tag','stdplot');
return
function calviewstats(udata,newdata)
ax_han=get_ax;
axes(ax_han(1));
ax=axis
minmin=ax(1);
maxmin=ax(2);
%new values from calplot axes
t1=sprintf('%5.2f',minmin)
t2=sprintf('%5.2f',maxmin)
mtemp=sprintf('%6.1f',get(ax_han(2),'Userdata'))
%pass array to qcaled_cb to update text fields
isishandle = ishandle(findobj('Tag','QcaledFig1'))
if ishandle(findobj('Tag','QcaledFig1')),
%file text boxes with current file parameters
qcaled_cb('gettextfields');
%update with new values from calplot axes
findobj('Tag','t1Box')
set(findobj('Tag','t1Box'),'String',t1);
set(findobj('Tag','t2Box'),'String',t2);
set(findobj('Tag','InttempBox'),'String',mtemp);
qcaled_cb('update');
else
display('qcal.txt file has not been updated, it is up to you');
end
% $$$ udata=get(ax_han(1),'Userdata');
par=udata.par;
time2=udata.time2;
chan2=udata.chan2;
itemp2=udata.itemp2;
I=udata.I;
ichannels=udata.ichannels;
range=find(time2>minmin & time2<maxmin);
% $$$ newdata=get(ax_han(3),'Userdata');
newdata.avespec=mean(chan2(range,I(ichannels)));
newdata.npts=length(range)*ones(1,9);
newdata.stdspec=std(chan2(range,I(ichannels)));
set(ax_han(3),'Userdata',newdata);
return
function calviewmask(t_lim)
ax_han=get_ax;
axes(ax_han(1));
h=findobj(gca,'Type','line');
%check for t_lim and adjust
if exist('t_lim') & ~isempty(t_lim),
minmin=t_lim(1);
maxmin=t_lim(2);
if maxmin==0,
t_data=get(h(1),'xdata');
maxmin=ceil(t_data(end));
end
set(ax_han(1),'XLim',[minmin maxmin])
end
return
function [ax]=calviewplot1(udata)
%this makes the initial plot of the data using times from file
ax_han=get_ax;
axes(ax_han(1));
h_old=findobj(gca,'Type','line');
if ~isempty(h_old),
delete(h_old)
end
% $$$ udata=get(gca,'Userdata');
title(strrep(udata.file,'_','\_'));
%change plot to line to avoid reinitializing
h=line(udata.time2,udata.chan2(:,udata.I(udata.ichannels)));
mylines(h,'c');
% $$$ %check for t_lim and adjust
% $$$ if exist('t_lim') & ~isempty(t_lim),
% $$$ minmin=t_lim(1);
% $$$ maxmin=t_lim(2);
% $$$ if maxmin==0,
% $$$ t_data=get(h(1),'xdata');
% $$$ maxmin=ceil(t_data(end));
% $$$ end
% $$$ set(ax_han(1),'XLim',[minmin maxmin])
% $$$ end
%zoom reset
l_han=legend(udata.channels(udata.ichannels,:),-1);
l_pos=get(l_han,'pos');
a_pos=get(ax_han(1),'pos');
set(l_han,'pos',[l_pos(1) a_pos(2)+a_pos(4)-l_pos(4) l_pos(3: ...
4)]);
return
function calviewplot2(udata)
%returns max. int. temp, only called once per file
%change plot to line to avoid reinitializing
ax_han=get_ax;
% $$$ udata=get(ax_han(1),'Userdata');
axes(ax_han(2));
%remove previous lines first
h=get(gca,'chil');
delete(h);
line(udata.time2,udata.itemp2);
mtemp=max(get(findobj(gca,'Type','line'),'ydata'));
%store mtemp in axis rather than returning it
set(gca,'Userdata',mtemp);
return
function calviewplot3(udata,newdata)
%plot/replot spec data and store in axis
ax_han=get_ax
% $$$ udata=get(ax_han(1),'Userdata')
axes(ax_han(3));
% $$$ newdata=get(ax_han(3),'Userdata');
l_han=errorbar(udata.par.wave,newdata.avespec,newdata.stdspec);
hold on
if isfield(newdata,'specdata'),
plot(udata.par.wave,newdata.specdata,'k')
else
newdata.specdata=[];
end
hold off
newdata.specdata=[newdata.specdata; newdata.avespec];
set(gca,'Tag','specplot');
set(gca,'Userdata',newdata);
return
function calviewplot4(udata,newdata)
ax_han=get_ax;
% $$$ udata=get(ax_han(1),'Userdata');
% $$$ newdata=get(ax_han(3),'Userdata');
strvcat(sprintf('%3.0f\n',udata.par.wave));
set(findobj('Tag','WaveBox'),'String',ans);
sprintf('%7.4f\n',newdata.avespec);
set(findobj('Tag','MeanBox'),'String',ans);
sprintf('%7.4f\n',newdata.stdspec);
set(findobj('Tag','StdBox'),'String',ans);
return
function calviewplot5(udata,newdata)
%plot/replot std of calplot spectra
ax_han=get_ax;
% $$$ udata=get(ax_han(1),'Userdata');
axes(ax_han(5));
%stddata=get(gca,'Userdata');
% $$$ newdata=get(ax_han(3),'Userdata');
hold on
plot(udata.par.wave,newdata.stdspec);
if isfield(newdata,'stddata'),
plot(udata.par.wave,newdata.stddata,'k')
else
%first time through, initialize these fields
newdata.stddata=[];
newdata.ndata=[];
%problem is that if the plot rescales, the markers don't move
%with the line always, huh?
for ip=1:9,
h(ip)=line(udata.par.wave(ip),newdata.stdspec(ip));
end
mylines(h,'mc');
end
hold off
newdata.stddata=[newdata.stddata; newdata.stdspec];
newdata.ndata=[newdata.ndata; newdata.npts];
title(['npts = ' num2str(mean(newdata.npts))]);
set(ax_han(5),'Tag','stdplot');
set(ax_han(3),'Userdata',newdata);
return
function []=rbut(fig,rbutpos)
uicontrol('Parent',fig, ...
'Callback','calviewplot(2)',...
'Units','norm', ...
'BackgroundColor',[.8 .8 .8], ...
'Position',rbutpos, ...
'String','Reset time', ...
'Style','Push', ...
'Tag','ResetTimeBut');
uicontrol('Parent',fig, ...
'Callback','calviewplot(4)', ...
'Units','norm', ...
'BackgroundColor',[.8 .8 .8], ...
'Position',rbutpos, ...
'String','All chan', ...
'Style','Push', ...
'Tag','AllChanBut');
uicontrol('Parent',fig, ...
'Callback','calviewplot(5)',...
'Units','norm', ...
'BackgroundColor',[.8 .8 .8], ...
'Position',[rbutpos(1) rbutpos(2)+1.1*rbutpos(4) rbutpos(3:4)], ...
'String','All time', ...
'Style','Push', ...
'Tag','AllTimeBut');
uicontrol('Parent',fig, ...
'Callback','calviewplot(6)', ...
'Units','norm', ...
'BackgroundColor',[.8 .8 .8], ...
'Position',[rbutpos(1)+1.1*rbutpos(3) rbutpos(2) rbutpos(3:4)], ...
'String','Reset stats', ...
'Style','Push', ...
'Tag','ResetStatsBut');
uicontrol('Parent',fig, ...
'Callback','calviewplot(7)', ...
'Units','norm', ...
'BackgroundColor',[.8 .8 .8], ...
'Position',[rbutpos(1)+1.1*rbutpos(3) rbutpos(2)+1.1*rbutpos(4)...
rbutpos(3:4)], ...
'String','Reset time', ...
'Style','Push', ...
'Tag','ResetTimeBut');
return
function []=table(fig,wavepos,meanpos,stdpos)
uicontrol('Parent',fig, ...
'Units','norm', ...
'BackgroundColor',[.8 .8 .8], ...
'Position',wavepos, ...
'hor','right', ...
'String','', ...
'Style','text', ...
'Tag','WaveBox');
uicontrol('Parent',fig, ...
'Units','norm', ...
'BackgroundColor',[.8 .8 .8], ...
'Position',meanpos, ...
'hor','right', ...
'String','', ...
'Style','text', ...
'Tag','MeanBox');
uicontrol('Parent',fig, ...
'Units','norm', ...
'BackgroundColor',[.8 .8 .8], ...
'Position',stdpos, ...
'hor','right', ...
'String','', ...
'Style','text', ...
'Tag','StdBox');
return
% TODO
% Add colored symbols to std and ts plots to match the colors on calplot
% Make buttondown on legend names plot that/those channels for all
% time with the greatest resolution.
% Unclick names to get all the lines back
%should newdata be saved in the figure udata rather than the
%axes. Make the figure udata the place to pass data to other figures