function [final_stats]=eval_fit(sta,ccon,cprs,dcdp,bcon,coeff_cal,index)
% EVAL_FIT - evaluates the fit for a particular cruise?
% 
% VERSION: 
%	$Revision: 1.4 $
%	$Date: 2008/01/19 19:56:30 $
%	$Id: eval_fit.m,v 1.4 2008/01/19 19:56:30 duncombe Exp duncombe $
%
% CHANGELOG: 
%

coeff=coeff_cal;
stat=sta(index);
cond=ccon(index);
pres=cprs(index);
botco=bcon(index);
dcdp=dcdp(index);

fits=1:28;
final_stats(:,1)=fits';
%CalcoS
newctdco(:,1)=coeff(1,2)*cond+coeff(1,1);
newctdco(:,2)=coeff(2,2)*cond+coeff(2,3)*cond.*stat+coeff(2,1);
newctdco(:,3)=coeff(3,2)*cond+coeff(3,3)*cond.*stat+coeff(3,4)*cond.*stat.^2+coeff(3,1);
newctdco(:,4)=coeff(4,2)*cond+coeff(4,3)*cond.*stat+coeff(4,4)*cond.*stat.^2+coeff(4,5)*cond.*stat.^3+coeff(4,1);
newctdco(:,5)=coeff(5,2)*cond+coeff(5,3)*cond.*stat+coeff(5,4)*cond.*stat.^2+coeff(5,5)*cond.*stat.^3+coeff(5,6)*cond.*stat.^4+coeff(5,1);
newctdco(:,6)=coeff(6,2)*cond+coeff(6,3)*cond.*stat+coeff(6,4)*cond.*stat.^2+coeff(6,5)*cond.*stat.^3+coeff(6,6)*cond.*stat.^4+coeff(6,7)*cond.*stat.^5+coeff(6,1);
newctdco(:,7)=coeff(7,2)*cond+coeff(7,3)*cond.*stat+coeff(7,4)*cond.*stat.^2+coeff(7,5)*cond.*stat.^3+coeff(7,6)*cond.*stat.^4+coeff(7,7)*cond.*stat.^5+coeff(7,8)*cond.*stat.^6+coeff(7,1);
%Calcop
newctdco(:,8)=coeff(8,2)*cond+coeff(8,1)+coeff(8,3)*pres;
newctdco(:,9)=coeff(9,2)*cond+coeff(9,3)*cond.*stat+coeff(9,1)+coeff(9,4)*pres;
newctdco(:,10)=coeff(10,2)*cond+coeff(10,3)*cond.*stat+coeff(10,4)*cond.*stat.^2+coeff(10,1)+coeff(10,5)*pres;
newctdco(:,11)=coeff(11,2)*cond+coeff(11,3)*cond.*stat+coeff(11,4)*cond.*stat.^2+coeff(11,5)*cond.*stat.^3+coeff(11,1)+coeff(10,6)*pres;
newctdco(:,12)=coeff(12,2)*cond+coeff(12,3)*cond.*stat+coeff(12,4)*cond.*stat.^2+coeff(12,5)*cond.*stat.^3+coeff(12,6)*cond.*stat.^4+coeff(12,1)+coeff(12,7)*pres;
newctdco(:,13)=coeff(13,2)*cond+coeff(13,3)*cond.*stat+coeff(13,4)*cond.*stat.^2+coeff(13,5)*cond.*stat.^3+coeff(13,6)*cond.*stat.^4+coeff(13,7)*cond.*stat.^5+coeff(13,1)+coeff(13,8)*pres;
newctdco(:,14)=coeff(14,2)*cond+coeff(14,3)*cond.*stat+coeff(14,4)*cond.*stat.^2+coeff(14,5)*cond.*stat.^3+coeff(14,6)*cond.*stat.^4+coeff(14,7)*cond.*stat.^5+coeff(14,8)*cond.*stat.^6+coeff(14,1)+coeff(14,9)*pres;
%Calcodcdp
newctdco(:,15)=coeff(15,2)*cond+coeff(15,1)+coeff(15,3)*dcdp;
newctdco(:,16)=coeff(16,2)*cond+coeff(16,3)*cond.*stat+coeff(16,1)+coeff(16,4)*dcdp;
newctdco(:,17)=coeff(17,2)*cond+coeff(17,3)*cond.*stat+coeff(17,4)*cond.*stat.^2+coeff(17,1)+coeff(17,5)*dcdp;
newctdco(:,18)=coeff(18,2)*cond+coeff(18,3)*cond.*stat+coeff(18,4)*cond.*stat.^2+coeff(18,5)*cond.*stat.^3+coeff(18,1)+coeff(18,6)*dcdp;
newctdco(:,19)=coeff(19,2)*cond+coeff(19,3)*cond.*stat+coeff(19,4)*cond.*stat.^2+coeff(19,5)*cond.*stat.^3+coeff(19,6)*cond.*stat.^4+coeff(19,1)+coeff(19,7)*dcdp;
newctdco(:,20)=coeff(20,2)*cond+coeff(20,3)*cond.*stat+coeff(20,4)*cond.*stat.^2+coeff(20,5)*cond.*stat.^3+coeff(20,6)*cond.*stat.^4+coeff(20,7)*cond.*stat.^5+coeff(20,1)+coeff(20,8)*dcdp;
newctdco(:,21)=coeff(21,2)*cond+coeff(21,3)*cond.*stat+coeff(21,4)*cond.*stat.^2+coeff(21,5)*cond.*stat.^3+coeff(21,6)*cond.*stat.^4+coeff(21,7)*cond.*stat.^5+coeff(21,8)*cond.*stat.^6+coeff(21,1)+coeff(21,9)*dcdp;
%Calcopdcdp
newctdco(:,22)=coeff(22,2)*cond+coeff(22,1)+coeff(22,3)*pres+coeff(22,4)*dcdp;
newctdco(:,23)=coeff(23,2)*cond+coeff(23,3)*cond.*stat+coeff(23,1)+coeff(23,4)*pres+coeff(23,5)*dcdp;
newctdco(:,24)=coeff(24,2)*cond+coeff(24,3)*cond.*stat+coeff(24,4)*cond.*stat.^2+coeff(24,1)+coeff(24,5)*pres+coeff(24,6)*dcdp;
newctdco(:,25)=coeff(25,2)*cond+coeff(25,3)*cond.*stat+coeff(25,4)*cond.*stat.^2+coeff(25,5)*cond.*stat.^3+coeff(25,1)+coeff(25,6)*pres+coeff(25,7)*dcdp;
newctdco(:,26)=coeff(26,2)*cond+coeff(26,3)*cond.*stat+coeff(26,4)*cond.*stat.^2+coeff(26,5)*cond.*stat.^3+coeff(26,6)*cond.*stat.^4+coeff(26,1)+coeff(26,7)*pres+coeff(26,8)*dcdp;
newctdco(:,27)=coeff(27,2)*cond+coeff(27,3)*cond.*stat+coeff(27,4)*cond.*stat.^2+coeff(27,5)*cond.*stat.^3+coeff(27,6)*cond.*stat.^4+coeff(27,7)*cond.*stat.^5+coeff(27,1)+coeff(27,8)*pres+coeff(27,9)*dcdp;
newctdco(:,28)=coeff(28,2)*cond+coeff(28,3)*cond.*stat+coeff(28,4)*cond.*stat.^2+coeff(28,5)*cond.*stat.^3+coeff(28,6)*cond.*stat.^4+coeff(28,7)*cond.*stat.^5+coeff(28,8)*cond.*stat.^6+coeff(28,1)+coeff(28,9)*pres+coeff(28,10)*dcdp;
residuals=newctdco-repmat(botco,1,28);
final_stats(:,2)=std(residuals)';
final_stats(:,3)=mean(residuals)';

