function [figTS,figSP,figDeln]=salcheckplots(ctddat,botmatch,idx_sta,Btl)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function drawplots
%%%%%%%%%%%%%%%%%%%%
% Used in check_bad_salt_CF1 for plotting the figures.  Seems like a stupid
% function to create.

%col='bgrcmkbgrcmk'; %This is pretty stupid for this function

%figTS=bigplot;

%figSP=bigplot;

%figDeln=bigplot;
botmatch.ctdptmp1=sw_ptmp(botmatch.btlsal,botmatch.ctdtmp1,botmatch.ctdprs,0);
for istn=1:length({ctddat.station}),
	Ibot=find(ctddat(istn).station == botmatch.stnnbr & botmatch.quality1==2);
    % Bottle data
	Sb=botmatch.btlsal(Ibot);
	%Tb=botmatch.ctdtmp1(Ibot);
    Tb=botmatch.ctdptmp1(Ibot);
	Pb=botmatch.ctdprs(Ibot);
    % Sensor data
	S=ctddat(istn).salpri;
    S2=ctddat(istn).salsec;
	T=ctddat(istn).thetapri;
    T2=ctddat(istn).thetasec;
	P=ctddat(istn).pressure;
    
    % T-S plot
  	%figure;
        %wysiwyg;
        figTS = bigplot;
		plot(S,T); 
		hold on;
        plot(S2,T2,'k');
		plot(Sb,Tb,'rx');
        plot(Btl(istn).Sal00,Btl(istn).Potemp090C,'oc')
		title(['TS Plot: Station ' num2str(ctddat(istn).station)]);
		xlabel('Salinity');
		ylabel('Temperature');
        legend('Primary','Secondary','Bottle','location','southeast');
    
    % S-P plot    
	%figure;
        %wysiwyg;
        figSP = bigplot;
    	plot(S,P);
        set(gca,'ydir','reverse');
		hold on;
        plot(S2,P,'k');
		plot(Sb,Pb,'rx');
        plot(Btl(istn).Sal00,Btl(istn).PrDM,'oc')
		title(['Salinity Profile' num2str(ctddat(istn).station)]);
		xlabel('Salinity');
		ylabel('Pressure');
        legend('Primary','Secondary','Bottle','location','southeast');

end;
    aux=find(botmatch.quality1(idx_sta)==2);
	Sc=botmatch.ctdsal1(idx_sta(aux));
	Sb=botmatch.btlsal(idx_sta(aux));
	sta=botmatch.stnnbr(idx_sta(aux));
    d_idx=find(botmatch.ctdprs(idx_sta(aux))>1000);
    Delta=Sb-Sc;
    
    [params,extremes]=boxparams(Delta(~isnan(Delta)));
	ii=find(Delta>=params(5)| Delta<=params(1));
    
    % Sensor-Bottle difference plot
    %figure;
        %wysiwyg;
        figDeln=bigplot;
		nS=Delta;
		I=find(abs(nS)>0.02);
		plot(sta,nS,'+');
        hold on;
        plot(sta(d_idx),nS(d_idx),'r+');
		plot(sta(ii),nS(ii),'ko');
		title('Bottle and CTD difference');
		ylabel('difference (psu)');
        legend('Primary','Secondary','location','northwest')

return;
