Home > ctdcal > make_fit_cond.m

make_fit_cond

PURPOSE ^

function [newbotco,newctdco]=make_fit_cond(X,sta,cprs,botc,stddev,fit,plottitle,h_color);

SYNOPSIS ^

function [coeff,stats,stats_deep,newbotco,newctdco]=make_fit_cond(X,sta,cprs,botc,stddev,fit,plottitle,h_color,deep_all,fig);

DESCRIPTION ^

function [newbotco,newctdco]=make_fit_cond(X,sta,cprs,botc,stddev,fit,plottitle,h_color);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [coeff,stats,stats_deep,newbotco,newctdco]=make_fit_cond(X,sta,cprs,botc,stddev,fit,plottitle,h_color,deep_all,fig);
0002 %function [newbotco,newctdco]=make_fit_cond(X,sta,cprs,botc,stddev,fit,plottitle,h_color);
0003 tot=length(find(finite(botc)==1));
0004 jj=1;
0005 count=0;
0006 % repeat fit until standard deviation criteria fits
0007 % store rejects indices in rejects
0008      if (deep_all==0)
0009      fid = fopen('rejs.rej','w');
0010      gid = fopen('rejs_deep.rej','w');
0011      else
0012      hid= fopen('deep_srejs0.rej','w');
0013      end
0014  
0015  while length(jj)>0;
0016    
0017    % fit slope adjustment as a linear function of station number, with a uniform BIAS
0018    
0019    count=count+1;
0020    if (deep_all==0)
0021        
0022    ii=find(finite(botc)==1);
0023      c=X(ii,:)\botc(ii);
0024      %c=c';
0025    
0026    % calculate standard deviation and remove outliers from
0027    % the bottle file
0028    
0029      d=(X*c)-botc;
0030      s=std(d(ii));
0031      jj=find(abs(d)>stddev*s);
0032      rejects = [count*ones(length(jj),1) jj sta(jj) cprs(jj)];
0033      fprintf(fid,'%d %d %d %6.4f\n ',rejects');
0034      botc(jj)=NaN*jj;
0035      if (h_color~=0)
0036      deep_idx=find(cprs(ii)>=h_color);
0037      s_deep=std(d(ii(deep_idx)));
0038      jj_deep=find(abs(d)>stddev*s_deep & cprs>=h_color);
0039      
0040      if (isempty(jj_deep)==0)
0041      rejects_deep = [count*ones(length(jj_deep),1) jj_deep sta(jj_deep)  cprs(jj_deep) ];
0042      fprintf(gid,'%d %d %d %6.4f\n',rejects_deep');
0043      botc(jj_deep)=NaN*jj_deep; 
0044      end
0045      end
0046    else
0047      ii=find(finite(botc)==1 & cprs >=h_color);
0048      c=X\botc(ii);
0049      %c=c';
0050    
0051    % calculate standard deviation and remove outliers from
0052    % the bottle file
0053    
0054       d=(X*c)-botc;
0055       s=std(d(ii));
0056      jj=find(abs(d)>stddev*s);
0057      rejects = [count*ones(length(jj),1) jj sta(jj) cprs(jj)];
0058      fprintf(hid,'%d %d %d %6.4f\n',rejects');
0059      botc(jj)=NaN*jj;
0060    end 
0061 end
0062 if (deep_all==0)
0063 fclose(fid);
0064 fclose(gid);
0065 else
0066 fclose(hid);
0067 end
0068 % get station numbers, but only one for each station
0069 
0070 %sta=[round(stamin):round(stamax)];
0071 
0072 
0073 % get new bottle and ctd conds
0074 
0075 newbotco=botc;
0076 newctdco=X*c;
0077 coeff=c';
0078 % display some statistics
0079 [stats,stats_deep]=stats_fit(newbotco,newctdco,cprs,tot,h_color,fit,plottitle);
0080 
0081 %plot the results
0082 plot_fit(sta,cprs,newbotco,newctdco,s,h_color,fit,plottitle,deep_all,fig) 
0083   
0084 return

Generated on Fri 08-Oct-2004 11:57:17 by m2html © 2003