function [alphac,CO2dnew,CO2mfnew,alphaw,H2Odnew,H2Omfnew,Xc,Xw,Pec] = LicorH2OCO2fromequations(P,mw,T,Vd,Ac,Ac0,Aw,Aw0,Zc0,Zw0,aw,Xwc,Sco2,Sw)
%05182011- LB
%
%PURPOSE: Recomputes H2O and CO2 from Equations according to equation 3-13, 3-14, 3-17 and 3-18 in the manual
%
%IMPUTS:
%   P=LI7200_Press;    %Total pressure, kPa
%   mw=LI7200_H2Omf;   %mole fraction of WV , mol/mol
%   T=LI7200_Tmean;    %Cell temperature, degC
%   Vd=LI7200_cooler;  %%Detector cooler, Volts
%   Ac=LI7200_CO2AW;   %CO2 source
%   Ac0=LI7200_CO2AWO; %CO2 reference
%   Aw=LI7200_H2OAW;   %H2O source
%   Aw0=LI7200_H2OAWO; %H2O reference
%
%OUTPUTS:
%   alphac:            %CO2 absorptance
%   CO2dnew            %CO2 density, mmol m-3
%   CO2mfnew           %CO2 mol fraction, umol/mol
%   alphaw             %H2O absorptance
%   H2Odnew            %H2O density, mmol m-3
%   H2Omfnew           %H2O mol fraction, mmol/mol

%***************************************************************
%  From the Calibration Certificates
%***************************************************************
%CO2
% Xwc=0.0024; %cross sensitivity factro for H2O on CO2
% Zc0=0.9209; %zero factor determined when setting the zero
Zc=3.120e-5; %zero drift coefficient
% Sco2=1.0025;  %span factor determined when setting the span
pc=[1.29510e12 -1.01573e10 3.56716e7 8.44610e3 1.38494e2 0];    %CO2 Calibration values
%H2O
Xcw=-0.0029; %cross sensitivity factor for H2O on CO2
% Zw0=0.9940; %zero factor determined when setting the zero
Zw=9.360e-5; %zero drift coefficient
% Sw=1.0047;  %span factor determined when setting the span
pw=[2.19323e8 3.10223e6 4.93061e3 0];    %H2O Calibration values

%******************************************************************
%  Now compute the absorptance and number density 
%******************************************************************
% aw=1.15;
% mw(mw<0)=0;
R=8.314472; % Pa m3 /K /mol

%CO2
alphac=1-(Ac./Ac0 + Xwc*(1-Aw./Aw0)).*(Zc0+Zc*Vd);
Pec=P.*(1+(aw-1).*mw);  %equivalent pressure of CO2
Xc=alphac*Sco2./Pec;
CO2dnew=Pec.*polyval(pc,Xc);  %CO2 molar density (mmol/m3)
CO2mfnew=CO2dnew*R.*(T+273.15)./P;  %CO2 mole fraction (umol/mol)

%H2O
alphaw=1-(Aw./Aw0 + Xcw*(1-Ac./Ac0)).*(Zw0+Zw*Vd);
Pew=P;  %equivalent pressure of H2O
Xw=alphaw*Sw./Pew;
H2Odnew=Pew.*polyval(pw,Xw);  %H2O molar density (mmol/m3)
H2Omfnew=H2Odnew*R.*(T+273.15)./(1000*P);  %H2O mole fraction (umol/mol)

