%close any Lwn graphs(lwnfig Lwn handle)

warning off;
if exist('chlfig','var')
   
   try
      close(chlfig);
   catch
      fprintf('');
   end;
   
   
end;

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

%close any K figures(Kfigure K handle)
if exist('Kfigure','var')
   
   try
      close(Kfigure);
   catch
      fprintf('');
   end;
   
   
end;

%close any Lw figures(lwfigure lw handle)
if exist('lwfigure','var')
   
   try
      close(lwfigure);
   catch
      fprintf('');
   end;
   
   
end;

fig=gcf;
%hide option box
set(fig,'visible','off');

%grab the handles from the option box
boxprod=allchild(fig);
if get(boxprod(4),'value')==0&get(boxprod(5),'value')==0
  set(boxprod(4),'value',1)
end;

   
if get(boxprod(8),'value')==1
lwnfig=figure;
for i=1:5
   subplot(5,1,i)
   
   if get(boxprod(3),'value')==1
   [ax,hyy1,hyy2]=plotyy(Y.t,Y.Lwn(:,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,'Fontsize',8);
   set(hyy2,'LineWidth',2);
   LwnLeg=('Mooring Calc');
	hold on;
   end
   
   if get(boxprod(4),'value')==1&get(boxprod(3),'value')==0
      plot(Y.t,Y.Lwn(:,i),'b-')
      hold on;
      LwnLeg=('Mooring Calc');
   end;
   
   
   if get(boxprod(5),'value')==1
      plot(Y.t,Y.Lwnf(:,i),'r-')
      hold on;
      
      if exist('LwnLeg','var') 
         LwnLeg=strvcat(LwnLeg,'Mooring AvgDepth Calc');
      else
         LwnLeg='Mooring AvgDepth Calc';
      end;
      
   end;
   

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

      plot([deploy_dates(j) deploy_dates(j)],[0 2.25],'k','Linewidth',2);
      
      if j<=(length(deploy_dates)-1)      
         text(deploy_dates(j),(2.25*1.05),num2str(Prr600(j)),'Fontsize',8);
      end;
      
     end;
     
     if get(boxprod(6),'value')==1
     LwnLeg=strvcat(LwnLeg,'SPMR Calc');
	  end;


	set(gca,'YGrid','on','XGrid','on','YTick',([0 0.5 1 1.5 2]),'XTick',dates,'XTickLabel',datestr(dates,2),'Fontsize',8,'YColor','k');
	titl=sprintf('Lwn %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,LwnLeg,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 LwnLeg;
   
end;
set(lwnfig,'Position',([3 29 1022 672]));
end;

if get(boxprod(9),'value')==1
lwfigure=figure;
for i=1:5
   subplot(5,1,i)
   
   if get(boxprod(3),'value')==1
	[ax,hyy1,hyy2]=plotyy(Y.t,Y.Lw(:,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,'Fontsize',8);
   set(hyy2,'LineWidth',2);
   LwLeg=('Mooring Calc');
	hold on;
   end
   
   if get(boxprod(4),'value')==1&get(boxprod(3),'value')==0
      plot(Y.t,Y.Lw(:,i),'b-')
      hold on;
      LwLeg=('Mooring Calc');
   end;
   
   
   if get(boxprod(5),'value')==1
      plot(Y.t,Y.Lwf(:,i),'r-')
      hold on;
      
      if exist('LwLeg','var') 
         LwLeg=strvcat(LwLeg,'Mooring AvgDepth Calc');
      else
         LwLeg='Mooring AvgDepth Calc';
      end;
      
   end;
   

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

      plot([deploy_dates(j) deploy_dates(j)],[0 2.25],'k','Linewidth',2);
      
            
     if j<=(length(deploy_dates)-1)      
         text(deploy_dates(j),(2.25*1.05),num2str(Prr600(j)),'Fontsize',8);
      end;
      
     end;
     
     if get(boxprod(6),'value')==1
     LwLeg=strvcat(LwLeg,'SPMR Calc');
	  end;


	set(gca,'YGrid','on','XGrid','on','YTick',([0 0.5 1 1.5 2]),'XTick',dates,'XTickLabel',datestr(dates,2),'Fontsize',8,'YColor','k');
	titl=sprintf('Lw %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,LwLeg,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 LwLeg;
   clear fullplot;
   clear nearplot;
end;
set(lwfigure,'Position',([3 29 1022 672]));
end;

if get(boxprod(10),'value')==1
   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,2),'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]));
end;

if get(boxprod(7),'value')==1
chlfig=figure;
    
    if ~exist('sea','var')
      ConSeaStr='Show Seawifs';
   end;
   
   if get(boxprod(3),'value')==1
   [ax,hyy1,hyy2]=plotyy(Y.t,Y.Morel,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:5:30],'YDir','reverse','XTickLabel','','XTick',dates);
   set(hyy2,'LineWidth',2);
   ChlLeg=('Mooring Calc');
	hold on;
   end
   
   if get(boxprod(4),'value')==1&get(boxprod(3),'value')==0
      plot(Y.t,Y.Morel,'go','Markersize',4)
      hold on;
      ChlLeg=('Mooring Calc');
   end;
   
   
   if get(boxprod(5),'value')==1
      plot(Y.t,Y.Morelf,'ro','Markersize',4)
      hold on;
      
      if exist('ChlLeg','var') 
         ChlLeg=strvcat(ChlLeg,'Mooring AvgDepth Calc');
      else
         ChlLeg='Mooring AvgDepth Calc';
      end;
      
   end;
   

   
   set(gca,'YLim',([0 1.5]));
   ylabel('mg/m^3','Fontweight','bold','Fontsize',8)
	axis([(min(Y.t)-3) (max(Y.t)+3) 0 1.5])
	for j=1:(length(deploy_dates))
      if get(boxprod(6),'value')==1
         plot(deploy_dates(j),Ctd_Chl(j),'gs','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',8,'LineWidth',1.5)
         
         if j==1
            ChlLeg=strvcat(ChlLeg,'CTD Chlorophyll');
         end;
         
      end;

      plot([deploy_dates(j) deploy_dates(j)],[0 1.5],'k','Linewidth',2);
      
            
     	if j<=(length(deploy_dates)-1)      
         text(deploy_dates(j),(1.5*1.025),num2str(Prr600(j)),'Fontsize',8);
      end;
      
	end;
	 
	set(gca,'YGrid','on','XGrid','on','YTick',([0:0.25:1.5]),'XTick',dates,'XTickLabel',datestr(dates,2));
	titl=sprintf('%s Chl490',upper(p(1:3)));
   title(titl,'Fontweight','bold','Fontsize',8,'position',[mean(X.t) (1.5*1.025) 17.3205]);
   legend(gca,ChlLeg,2);
   
%    if get(boxprod(3),'value')==1
%       ylabel('Depth','Fontweight','bold','Fontsize',8)
%    end;
%    

   
   clear ChlLeg;
   
set(chlfig,'Position',([3 29 1022 702]));
conSeawif=uicontrol(chlfig,'string',ConSeaStr,'Callback','Seawif','Position',([45 675 100 20]));
end;
warning on;
set(fig,'visible','on')






