function  correct_autosal_ab0409(outfile)
% nominal value for the conductivity ratio
% (see the label of the standard water)
nominal_std=1.99987;
%
load_out=['load ',outfile,'.asc']
eval(load_out);
aux_out=eval(outfile);
date_cond=datenum(aux_out(:,7),aux_out(:,8),aux_out(:,9),aux_out(:,10),aux_out(:,11),aux_out(:,12));
standard1_idx=find(aux_out(:,2)==1000);
standard2_idx=find(aux_out(:,2)==1001);
figure
subplot(2,1,1) 
plot(date_cond(standard1_idx,1),aux_out(standard1_idx,3),'ok')
hold on
plot(date_cond(standard2_idx,1),aux_out(standard2_idx,3),'ok')
datetick('x','HH:MM')
x1=date_cond(standard1_idx,1)
x2=date_cond(standard2_idx,1)
y1=aux_out(standard1_idx,3);
y2=aux_out(standard2_idx,3);
beta=nominal_std-y1;
alfa=(y2-y1)/(x2-x1);
adjust0=(alfa*(date_cond(standard1_idx,1)-x1))+y1;
adjust=(alfa*(date_cond(standard2_idx,1)-x1))+y1;
subplot(2,1,2)
plot(date_cond(standard1_idx,1),(aux_out(standard1_idx,3)-1.999)*100000,'ok')
hold on
plot(date_cond(standard2_idx,1),(aux_out(standard2_idx,3)-1.999)*100000,'ok')
plot(x1,(y1-1.999)*100000,'*k')
plot(x2,(y2-1.999)*100000,'*k')
plot([x1 x2],[(adjust0-1.999)*100000 (adjust-1.999)*100000],'k--')
datetick('x','HH:MM')
title(['Standard alfa = ',num2str(alfa),  'beta = ',num2str(beta)])
saida(1,1)=alfa;
saida(1,2)=beta;
coeff=saida;
t0=date_cond(standard1_idx,1);
aux_date=date_cond-t0;
figure
for j=1:length(aux_date)
  correction=(coeff(1)*aux_date(j))+coeff(2);
  plot(aux_date(j),correction,'ok')
  datetick('x','HH:MM')
  hold on
  cond_ratio2_correct(j,1)=aux_out(j,3)-correction;
  plot(aux_date(j),cond_ratio2_correct(j,1)-aux_out(j,3),'or')
end
out_idx_cor=find(aux_out(:,2)<1000);
output_correct=[aux_out(out_idx_cor,1), aux_out(out_idx_cor,2), cond_ratio2_correct(out_idx_cor,1),...
        sw_sals(cond_ratio2_correct(out_idx_cor,1)/2,24)]
cor_file=[outfile,'_cor.asc']
fid=fopen(cor_file,'w')
fprintf(fid,'Station\t Bottle\t 2*Cond. Ratio Corrected Salinity\n')
fprintf(fid,'%d\t %d\t %1.5f %2f5\n',output_correct')
fclose(fid)
end
return
