function [fh]=prelim_oxy_plots(oxy_match)
% Used in oxy_cal_new_equation_jay1
% plots the preliminary oxygen data

%% Define variables
%look at all stations
staa=oxy_match.stnnbr(1);
stab=oxy_match.stnnbr(end);
%Define quality control filter
    ii=find(oxy_match.quality1 == 2 & oxy_match.stnnbr >= staa & ...
            oxy_match.stnnbr <= stab);
    
        stn=oxy_match.stnnbr(ii);
        prs=oxy_match.ctdprs(ii);
        boxy=oxy_match.btloxy(ii);
        tot=length(boxy);
        
        %creat variables for primary oxy_match
        sensor='Primary';        
        oxy_volt1=oxy_match.ctdoxv1(ii);
        oxy_mll1=oxy_match.ctdoxy1(ii);
        temp1=oxy_match.ctdtmp1(ii);
        sal1=oxy_match.ctdsal1(ii);        
        cond1=oxy_match.ctdcon1(ii);
        boxyL1=ox_units(oxy_match.btloxy(ii),oxy_match.ctdsal1(ii),...
        sw_ptmp(oxy_match.ctdtmp1(ii),oxy_match.ctdsal1(ii),oxy_match.ctdprs(ii),0),'mmk2mll');       
    
        %creat variables for secondary oxy_match
        sensor='Secondary';        
        oxy_volt2=oxy_match.ctdoxv2(ii);
        oxy_mll2=oxy_match.ctdoxy2(ii);
        temp2=oxy_match.ctdtmp2(ii);
        sal2=oxy_match.ctdsal2(ii);        
        cond2=oxy_match.ctdcon2(ii);
        boxyL2=ox_units(oxy_match.btloxy(ii),oxy_match.ctdsal2(ii),...
        sw_ptmp(oxy_match.ctdtmp2(ii),oxy_match.ctdsal2(ii),oxy_match.ctdprs(ii),0),'mmk2mll');
        
       
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                   Plotting first look in the data                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %Plot Primary and Secondary Oxygen vs. Station
    fcnt=0;
    fcnt=fcnt+1;
	fh(fcnt)=figure;
    subplot(2,1,1)
    plot(prs,oxy_mll1-boxyL1,'ro');  
    %%% calculate mean and standard deviation
    diff_mean=nanmean(oxy_mll1-boxyL1);
    diff_stddev=nanstd(oxy_mll1-boxyL1);
    grid on;
    xlabel('Pressure [dbar]');
    ylabel('CTD Oxygen  - Bottle Oxygen (mL/L)');
    title(['Primary Sensor (Uncalibrated) - Mean Diff: ',num2str(diff_mean), ...
		' Std Dev: ',num2str(diff_stddev)]);
    disp('Raw data - Primary Sensor');
    disp(['Mean residual: ',num2str(diff_mean)]);
    disp(['Standard Deviation: ',num2str(diff_stddev)]);
    disp('Hit any key to continue');
    
    
    subplot(2,1,2)
    plot(prs,oxy_mll2-boxyL2,'ro');
    %%% CMDR ignore nans they make a mess
    diff_mean2=nanmean(oxy_mll2-boxyL2);
    diff_stddev2=nanstd(oxy_mll2-boxyL2);
    grid on;
    xlabel('Pressure [dbar]');
    %%% CMDR NIST recommended symbol for liter is capital L
    ylabel('CTD Oxygen  - Bottle Oxygen (mL/L)');
    title(['Secondary Sensor (Uncalibrated) - Mean Diff: ',num2str(diff_mean2), ...
		' Std Dev: ',num2str(diff_stddev2)]);
    disp('Raw data - Primary Sensor');
    disp(['Mean residual: ',num2str(diff_mean2)]);
    disp(['Standard Deviation: ',num2str(diff_stddev2)]);
    

    %Plot Primary and Secondary Oxygen vs. Station
   
    fcnt=fcnt+1;
	fh(fcnt)=figure;
    subplot(2,1,1)
    
    plot(stn,oxy_mll1-boxyL1,'r+');  
    grid on;
    hold on;
    for i=staa:1:stab,
    	aux=find(stn==i);
    %%%%%% CMDR use nanmean to prevent any NaNs spoiling the result
    	plot(i,nanmean(oxy_mll1(aux)-boxyL1(aux)),'b^','MarkerFaceColor','b');
    end;
    xlabel('Station number');
    ylabel('CTD Oxygen  - Bottle Oxygen (mL/L)');
    title('Primary Sensor - Uncalibrated Data');
    
    subplot(2,1,2)
    plot(stn,oxy_mll2-boxyL2,'r+');
    grid on;
    hold on;
    for i=staa:1:stab,
    aux=find(stn==i);
    %%% CMDR ignore nans they make a mess
    plot(i,nanmean(oxy_mll2(aux)-boxyL2(aux)),'b^','MarkerFaceColor','b');
    end;
    xlabel('Station number');
    %%% CMDR NIST recommended symbol for liter is capital L
    ylabel('CTD Oxygen  - Bottle Oxygen (mL/L)');
    title('Secondary Sensor -Uncalibrated Data');
    
    
    