warning off;

if ~exist('pw', 'var')
   pw = 1;
   ConPurStr='Remove Pure Water';
elseif pw > 0
   ConPurStr='Show Pure Water';
   pw = 0;
else 
   pw=1;
   ConPurStr='Remove Pure Water';
end;

if exist('Kfigure','var')
   
   try
      close(Kfigure);
   catch
      fprintf('');
   end;
   
   
end;

Kfigure=figure;
   
   if ~exist('pw','var')
      ConPurStr='Show Pure Water'
   end;
   
for i=1:5
   subplot(5,1,i)
   
   if get(boxprod(3),'value')==1
	[ax,hyy1,hyy2]=plotyy(Y.t,Y.K(:,i),Y.t,Y.Depth);
	set(ax(1),'XTickLabel','','XTick',[]);

   set(ax(2),'XTickLabel','');
   set(ax(2),'XLim',([min(Y.t),max(Y.t)]),'YLim',([10 30]),'YTick',[10 20 30],'YDir','reverse','XTickLabel','','XTick',dates);
   set(hyy2,'LineWidth',2);
   KLeg=('Mooring_Calc');
	hold on;
   end
   
   if get(boxprod(4),'value')==1&get(boxprod(3),'value')==0
      plot(Y.t,Y.K(:,i),'b-')
      hold on;
      KLeg=('Mooring Calc');
   end;
   
   
   if get(boxprod(5),'value')==1
      plot(Y.t,Y.Kf(:,i),'r-')
      hold on;
      
      if exist('KLeg','var') 
         KLeg=strvcat(KLeg,'Mooring AvgDepth Calc');
      else
         KLeg='Mooring AvgDepth Calc';
      end;
      
   end;
   
   if exist('pw','var')&pw>0
      plot(Y.t,Y.Kpure(:,i),'g-','Linewidth',3);
      KLeg=strvcat(KLeg,'Kd Pure Water');
   end;
   
   

   
   set(gca,'YLim',([0 0.125]));
   ylabel('1/m','Fontweight','bold','Fontsize',8,'Color','k');
	axis([(min(Y.t)-3) (max(Y.t)+3) 0 0.125])
	for j=1:(length(deploy_dates))
      if get(boxprod(6),'value')==1
         plot(deploy_dates(j),SpmrKd(j),spmcol(i,:),'MarkerEdgeColor','k','MarkerFaceColor',spmcol(i,1),'MarkerSize',8,'LineWidth',1.5);
         
      end;

      plot([deploy_dates(j) deploy_dates(j)],[0 0.125],'k','Linewidth',2);
      
               
      
     	if j<=(length(deploy_dates)-1)      
         text(deploy_dates(j),(0.125*1.05),num2str(Prr600(j)),'Fontsize',8);
      end;
   end;
   if get(boxprod(6),'value')==1
     KLeg=strvcat(KLeg,'SPMR Calc');
  end;
	set(gca,'YGrid','on','XGrid','on','YTick',([0:.025:1.25]),'XTick',dates,'XTickLabel',datestr(dates,12),'Fontsize',8,'YColor','k');
	titl=sprintf('Kd %s',num2str(Y.lambda(i)));
   title(titl,'Fontweight','bold','Fontsize',8,'position',[(min(X.t)-length(X.t)/12.5) max(get(gca,'YLim')) 17.3205]);
   [legh(i),objh]=legend(gca,KLeg,2);
   switch i
   case 1
      set(legh(i),'Position',[0.910362 0.883008 0.0904348 0.0419922]);
   case 2
      set(legh(i),'Position',[0.910362 0.711681 0.0904348 0.0419922]);
   case 3
      set(legh(i),'Position',[0.910362 0.540355 0.0904348 0.0419922]);
   case 4
      set(legh(i),'Position',[0.910362 0.369028 0.0904348 0.0419922]);
   case 5
      set(legh(i),'Position',[0.910362 0.197702 0.0904348 0.0419922]);
   end;
   
% 	if get(boxprod(3),'value')==1
%       ylabel('Depth','Fontweight','bold','Fontsize',8)
%    end;

   clear KLeg;

end;
set(Kfigure,'Position',([3 29 1022 702]));
conpure=uicontrol(Kfigure,'string',ConPurStr,'Callback','PureDisp','Position',([45 675 100 20]));


warning on;   