% Computes 10-min CO2 fluxes for one hour's data from LICORs(7200,7500) for HiWinGS2013
% 8/2014 - BWB Clean up and comment.  Cellular blocks.
% 10/2013 - LB
%   Same as previous code version but 
%   1) attempt better calculation using Tvais+Tsonic and hydrostatic pressure correction (Pvais + heave)
%   2) adjust CO2/H2O mean to qvais and CO2 7200 PSD
%   3) detrend signal in cov flux computation
%   4) spectral decorrelation + PKT

%	These variables must exist in the current workspace
%		hhh: numerical value of current hour (00-23)
%		ddd: numerical value of current day of year (0-365)
%		yyyy: string variable of current year (e.g.'2014')
%		way_raw_data_flux: string path to data folder

%   Assumes following path for UH motion and wind data
%       /Volumes/User/bblomquist/Documents/Cruises/HiWinGS_2013/MotionData/

%   Output are ascii text files of mean 10-min values and spectra/cospectra
%   See comments at end of script for file formats

%% set hour and day-of-year string variables
hr = sprintf('%02i',hhh);
jd = sprintf('%03i',ddd);

%% define digital filter parameters and gas constant
fs = 10;                                % Sonic are output at 20 Hz
fc = 1/30;                              % Cutoff frequency for angle calculation
nfreq = fs/2.0;                         % Nyquist frequency
wp = fc/nfreq;
ws = .7*wp;
[n,wn] = buttord(wp,ws,10,25);          % Filter coefficients
[bhi,ahi] = butter(n,wn,'high');        % High pass Butterworth filter

R = 8.314472;                           % Pa m3 /K /mol

%% setup the hydrostatic correction
% assume 1 min mean met data (matrix A) is loaded as shown below
% before this script is called
% A =importdata('/Volumes/User/bblomquist/Documents/Cruises/HiWinGS_2013/MeanNBulkfluxes/HiWinGS_2013_1minMeans_r1.txt');
% A=A.data;
yday = A(:,1);                                    % decimal DOY
ii = find(yday>=ddd+hhh/24 & yday<ddd+(hhh+1)/24);% find data for this hour
press = A(ii,14)';                                % P (mb) @ 15 m
Rhvais = A(ii,15)';                               % RH(%) @ 15 m
Tvais = A(ii,16)';                                % Air T (C) @ 15 m
Tsea = A(ii,18)';                                 % SST (C) @ 5m depth

% compute q & rho, convert P(mb) to P(Pa) & T(C) to T(K)
[Press,Tseak,Tairk,Qsatsea,Qsatms,Qms,Rhoair] = scalarv(press,Tsea,Tvais,Rhvais);

qair = Qms;                                     % g/Kg
tsonicV = Tairk.*(1+0.51*Qms./1000);            % estimated sonic temperature??
rairV = Qms./(1-Qms./1000);                     % Mixing ratio g/Kg
TvirtV = Tairk.*(1+0.61.*Qms./1000);            % Fluctuating air temperature
rhovV = Rhoair.*rairV;                          % Corrected density
meanP = nanmean1(press)/10;
meanQ = nanmean1(Qms);
meanTv = nanmean1(TvirtV);
h2oV = 29*meanQ/18/8.314/meanTv*meanP*1000;     % Humidity mmol/m^3
clear Press Qsatms Qsatms Qsatsea Tairk Tseak
Rhoair = nanmean1(Rhoair);

% compute gravity from latitude
gpslat = A(ii,2)';
g = grv(nanmedian(gpslat));

% load heave data for pressure correction
motmat = load(['/Volumes/User/bblomquist/Documents/Cruises/HiWinGS_2013/MotionData/HiWinGS2013_UHmotionfile_',jd,hr,'.prn']);
% tmotion=motdata(:,1);
heave = motmat(:,7);
%removes first and last 20s for motcorr filter tapering issues
heave(1:20) = NaN;
heave(end-19:end) = NaN;

heave = heave-nanmean1(heave); 
dp = -nanmean1(Rhoair)*g*heave/100;
dp(isnan(dp)) = nanmedian1(dp);
% 
% S1=length(heave);t1=(1:S1)/S1;
% V1=length(press); tV=(1:V1)./V1;
% Pair=interp1(tV,press,t1);

PairL = (nanmean1(press)+dp)/10; % Pressure to use in 7500 computation (in kPa)
PairL = PairL';
PairL(isnan(PairL)) = nanmean1(PairL);

% pressf=speedup(dp,press)';
% PairL=pressf-filtfilt(bhi,ahi,pressf)+filtfilt(bhi,ahi,dp); %mb here!
% PairL=PairL'/10;
% PairL(isnan(PairL))=nanmean1(PairL);

clear dp pressf
% figure;plot(tref,Licor_Press,tref,dpair/10,'r')

%% get sonic temperature
read_son_HiWinGS_2013;    % get virtual temperature Tsonic = 1x36000 for cross corr correction
hr = sprintf('%02i',hhh); % repeat these in case clearit=1 and read_son kills them
jd = sprintf('%03i',ddd);

% Tvirt=Tsonic-nanmean1(Tsonic)+nanmean1(Tvais);  %Let's keep it simple
% Tair1 = Tvirt./(1+0.51*nanmean1(qair)./1000);   %Fluctuating air temperature

% Or use Tvais for Licor computation
S1 = length(heave); t1=(1:S1)/S1;
V1 = length(press); tV=(1:V1)./V1;
TairL = interp1(tV,Tvais,t1);
TairL(isnan(TairL)) = nanmean1(TairL);
clear S1 t1 V1 tV
% figure;plot(tV*3600,Tvais,'b',t1*3600,TairL,'g--',tref,Licor_Temp,'k')

RHL = speedup(TairL,Rhvais);
tvirt = speedup(TairL,TvirtV);

%% load PSD 7500
dfl = [way_raw_data_flux, yyyy(3:4),jd,'/', 'lic0' yyyy(3:4) jd hr '_raw.txt'];
[agc_0,Licor_CO2,Licor_H2O,Licor_Temp,Licor_Press] = read_7500co2_HiWinGs_2013(dfl);
%       Licor_CO2   = 1x36000, mmol/m^3
%       Licor_H2O   = 1x36000, mmol/m^3
%       Licor_Temp  = 1x36000, degC
%       Licor_Press = 1x36000, kPa

% [licorval7500PSD,h2ommol7500PSD] = licorWebbPTK(Licor_CO2,Licor_H2O,PairL,TairL,RHL,tvirt,10);
% Rc7500PTK_PSD=licorval7500PSD(1,:);       % CO2 Mixing ratio mg/Kg
% Rv7500PTK_PSD=licorval7500PSD(2,:);       % H2O Mixing ratio g/Kg
% Tair7500PTK_PSD=licorval7500PSD(4,:);     % Fluctuating air temperature (degC)
% rhfast7500PTK_PSD=licorval7500PSD(6,:);   % fast rh from Licor and Vaisala(%)

% convert units from mol/m3 to mol/mol
Rgas = 287.1;
Rgas_universal = 8.314472;    % Pa m3 /K /mol
Licor_CO2_a = (Licor_CO2*1e-3).*Rgas_universal.*(TairL+273.15)./(PairL*1e3); % mmol/m3 to mol/mol
% figure;plot(tref,Licor_CO2_a*1e6,tref,Licor_CO2_a2*1e6,'g')
% [SCO2_7500PSD2,Fpic]=psd2(detrend(Licor_CO2_a2*1e6),length(Licor_CO2_a2*1e6),10,hamming(length(Licor_CO2_a2*1e6)));[SCO2_7500PSD2,Fpics]=specsmoo(SCO2_7500PSD2,10);
% [SCO2_7500PSD,Fpic]=psd2(detrend(Licor_CO2_a*1e6),length(Licor_CO2_a*1e6),10,hamming(length(Licor_CO2_a*1e6)));[SCO2_7500PSD,Fpics]=specsmoo(SCO2_7500PSD,10);
% figure;loglog(Fpics,Fpics.*SCO2_7500PSD,Fpics,Fpics.*SCO2_7500PSD2,'g','LineWidth',2);grid
% legend('Using 7500 measurements','using Tvais and Pvais+hydrostatic dp')

% wcell = 8.314/1000*Licor_H2O.*(TairL+273.15)./PairL;  %H2O mass concentration mmol/mol
% M = 29 - 11/1000*wcell;                               %Molecular weight of moist air
% qair2 = 18*wcell./M;                                  %Specific humidity g/Kg
% rair = qair./(1-qair/1000);                           %Mixing ratio g/Kg

% [licortest,h2otest] = licorWebb(Licor_CO2,Licor_H2O,PairL*10,TairL,nanmean1(Rhvais),Tsonic+273.15);

LI7500_CO2mf = Licor_CO2_a*1e6;         %7500 CO2 in ppm
LI7500_H2O = Licor_H2O;                 %7500 CO2 in mmol/m3

LI7500_AGC = reshape(agc_0,6000,6);
LI7500_AGC_10m = nanmean1(LI7500_AGC,1);
LI7500_AGC_10s = nanstd1(LI7500_AGC);

clear Lenlic Licor_CO2_1 Licor_H2O Licor_Press Licor_Temp Licor_diag_0  agc_0 LI7500_AGC Nlenlic Licor_CO2_a Licrate Licor_CO2_a2
clear Tsea t_case1_adjustment t_case2_adjustment t_dome1_adjustment t_dome2_adjustment ta_etl_adjustment ta_im_adjustment tsnake_adjustment

%% load PSD 7200
read_7200_HiWinGS_2013_all;     %reads most of the variables

Zw0 = 0.99553;                  % Licor calibraiton constants
Sw0 = 0.99473;
Zc0 = 0.92308;
Sc0 = 1.01813;
aw = 1.72;
Xwc = 0.0024;
Sco2 = Sc0;
Sw = Sw0;

[alphac,CO2dnew,CO2mfnew,alphaw,H2Odnew,H2Omfnew,Xc,Xw,Pec] = LicorH2OCO2fromequations(LI7200_Press,LI7200_H2Omf/1000,LI7200_Tmean,LI7200_cooler,LI7200_CO2AW,LI7200_CO2AWO,LI7200_H2OAW,LI7200_H2OAWO,Zc0,Zw0,aw,Xwc,Sco2,Sw);
clear alphac CO2dnew alphaw H2Omfnew Xc Xw Pec
%  dry mole fraction computed from raw data using Licor equations
CO2mfnew = (CO2mfnew./(1-1e-6.*H2Odnew.*R.*(LI7200_Tmean+273.15)./LI7200_Press));
clear LI7200_Press LI7200_H2Omf LI7200_Tmean LI7200_cooler LI7200_CO2AW LI7200_CO2AWO LI7200_H2OAW LI7200_H2OAWO Zc0 Zw0 Sc0 Sw0

% adjust array lengthg
if length(LI7200_CO2mf)< 36000
    LI7200_CO2mf = [LI7200_CO2mf (1:36000-length(LI7200_CO2mf)).*0+LI7200_CO2mf(length(LI7200_CO2mf))];
    LI7200_CO2mfd = [LI7200_CO2mfd (1:36000-length(LI7200_CO2mfd)).*0+LI7200_CO2mfd(length(LI7200_CO2mfd))];
    LI7200_H2Od = [LI7200_H2Od (1:36000-length(LI7200_H2Od)).*0+LI7200_H2Od(length(LI7200_H2Od))];
    LI7200_agc = [LI7200_agc (1:36000-length(LI7200_agc)).*0+LI7200_agc(length(LI7200_agc))];
    CO2mfnew = [CO2mfnew (1:36000-length(CO2mfnew)).*0+CO2mfnew(length(CO2mfnew))];
    H2Odnew = [H2Odnew (1:36000-length(H2Odnew)).*0+H2Odnew(length(H2Odnew))];
elseif length(LI7200_CO2mf)> 36000    
    LI7200_CO2mf = LI7200_CO2mf(1:36000);
    LI7200_CO2mfd = LI7200_CO2mfd(1:36000);
    LI7200_H2Od = LI7200_H2Od(1:36000);
    LI7200_agc = LI7200_agc(1:36000);
    CO2mfnew = CO2mfnew(1:36000);
    H2Odnew = H2Odnew(1:36000);
end

LI7200_AGC_PSD = reshape(LI7200_agc,6000,6);
LI7200_AGC_PSD_10m = nanmean1(LI7200_AGC_PSD);
LI7200_AGC_PSD_10s = nanstd1(LI7200_AGC_PSD);

% remove residual effects from the puff spike (removes first 1min to be safe)
LI7200_CO2mf(1:600) = NaN;
LI7200_CO2mfd(1:600) = NaN;

clear LI7200_AGC_PSD Nlenlic 

%% load motion corrected winds 
try
    uvwmat = load(['/Volumes/User/bblomquist/Documents/Cruises/HiWinGS_2013/MotionData/HiWinGS2013_UH_UVWstream_',jd hr,dcname,'.prn']);
    tmotion = uvwmat(:,1)';   % all 1x36000
    uj = uvwmat(:,2)';
    vj = uvwmat(:,3)';
    wj = uvwmat(:,4)';
catch
    uj = LI7200_CO2mf*0+NaN;
    vj = LI7200_CO2mf*0+NaN;
    wj = LI7200_CO2mf*0+NaN;
end;

%% get the acceleration and displacement distances
% read_motion_HiWinGS_2013;
% Plat=[accx
%       accy
%       accz];

% Use UH motion data
% motmat=load(['/Volumes/User/bblomquist/Documents/Cruises/HiWinGS_2013/MotionData/HiWinGS2013_UHmotionfile_',jd hr,'.prn']);
uvwplat = [motmat(:,1) motmat(:,2) motmat(:,3)]'; % 3x36000 rotated platform velocities
xyzplat = [motmat(:,4) motmat(:,5) motmat(:,6)]'; % 3x36000 rotated platform displacement distances
% euler = [motmat(:,7) motmat(:,8) motmat(:,9)]';
Plat = [motmat(:,14) motmat(:,15) motmat(:,16)]'; % 3x36000 raw platform accelerations

%% Apply various corrections, mainly Webb to PSD 7500
%convert from mmol/m3 to g/kg
LI7500_H2O = LI7500_H2O.*18./1000./Rhoair;
% adjust H2O to PSD Vaisala
LI7500_H2O = LI7500_H2O + nanmedian1((nanmedian1(qair)-LI7500_H2O));
% CO2 dilution correction
LI7500_CO2mf = LI7500_CO2mf./(1-LI7500_H2O./18.*1000.*Rhoair.*Rgas_universal.*(TairL+273.15)./1000./PairL./1000);
% adjust 7500 mean CO2 to PSD7200
LI7500_CO2mf = LI7500_CO2mf+nanmedian1(LI7200_CO2mf-LI7500_CO2mf);
% PSD 7200 - convert from mmol/m3 to g/kg
LI7200_H2O = LI7200_H2Od.*18./1000./Rhoair;         
H2Odnew = H2Odnew.*18./1000./Rhoair;

% when Nafion OFF - no drying of 7200.  LI7200 output should = vaisala & 7500
if ddd+hhh/24>=341.25  
    LI7200_H2O = LI7200_H2O + nanmedian1((nanmedian1(qair) - LI7200_H2O));  % adjust output to PSD Vaisala
    H2Odnew = H2Odnew + nanmedian1((nanmedian1(qair) - H2Odnew));           % as computed from raw 7200 variables
end;

%% adjust PSD 7500 H2O for 7200 lag
% use for water vapor crosstalk correction on 7200 when dryer is absent
% not generally useful since 7500 was mostly bad

mr_att = TubingAttenuation(LI7500_H2O,10,0.4);  %brings UC 7200 H2O to PSD 7200
mr_att(1:30) = nanmedian1(mr_att);
mr_att2 = [];
mr_att2(1:57) = mr_att(57+2);
mr_att2(57+1:36000) = mr_att(1:36000-57); %kg/kg  %delays H2O by 5.7s
clear mr_att

%% compute fast rh
Exx = 6.1121*exp(17.502*TairL./(240.97+TairL));
Exx = Exx.*(1.0007+PairL*10*3.46E-6);
Qsat = 0.622*Exx./(PairL*10-.375*Exx)*1000;
rhfast7500_PSD = LI7500_H2O./Qsat;  
rhfast7200_PSD = LI7200_H2O./Qsat;
clear Qsat Exx

rhoair = Rhoair;

% replace NaNs with median
if any(isnan(wj));            wj(isnan(wj)) = nanmedian1(wj); end;
if any(isnan(LI7200_CO2mf));  LI7200_CO2mf(isnan(LI7200_CO2mf )) = nanmedian1(LI7200_CO2mf); end;
if any(isnan(LI7200_CO2mfd)); LI7200_CO2mfd(isnan(LI7200_CO2mfd )) = nanmedian1(LI7200_CO2mfd); end;
if any(isnan(LI7200_H2O));    LI7200_H2O(isnan(LI7200_H2O)) = nanmedian1(LI7200_H2O); end;
if any(isnan(LI7500_CO2mf));  LI7500_CO2mf(isnan(LI7500_CO2mf )) = nanmedian1(LI7500_CO2mf); end;
if any(isnan(LI7500_H2O));    LI7500_H2O(isnan(LI7500_H2O)) = nanmedian1(LI7500_H2O); end;
if any(isnan(CO2mfnew));      CO2mfnew(isnan(CO2mfnew)) = nanmedian1(CO2mfnew); end;
if any(isnan(H2Odnew));       H2Odnew(isnan(H2Odnew)) = nanmedian1(H2Odnew); end;

%% start flux computations

% 7200 lag time determined from analysis of hourly puffs w/respect to UH wind
PSD7200lag = 57;
Nlendata = 6000; % length 10min segment @ 10Hz

% allocate variables for 10 minute flux segments (6 per hour)
rngw = [];
rng7200PSD = [];
wCO2_7200PSD = ones(1,6)+NaN;
wH2O_7200PSD = ones(1,6)+NaN;
wCO2_7500PSD = ones(1,6)+NaN;
wH2O_7500PSD = ones(1,6)+NaN;

wCO2H2O_7500PSD = ones(1,6)+NaN;
wCO2H2O_7200PSD = ones(1,6)+NaN;
wCO2H2O_7200PSD2 = ones(1,6)+NaN;

muco2h2o_7500PSD = ones(1,6)+NaN;
muco2h2o_7200PSD = ones(1,6)+NaN;
slopeCO2_7200PSD = ones(1,6)+NaN; stdCO2_7200PSD = ones(1,6)+NaN;  meanCO2_7200PSD = ones(1,6)+NaN;
slopeH2O_7200PSD = ones(1,6)+NaN; stdH2O_7200PSD = ones(1,6)+NaN;  meanH2O_7200PSD = ones(1,6)+NaN;
slopeCO2_7500PSD = ones(1,6)+NaN; stdCO2_7500PSD = ones(1,6)+NaN;  meanCO2_7500PSD = ones(1,6)+NaN;
slopeH2O_7500PSD = ones(1,6)+NaN; stdH2O_7500PSD = ones(1,6)+NaN;  meanH2O_7500PSD = ones(1,6)+NaN;

Fpic=ones(48,6)+NaN; % frequency bins
SCO2_7200PSD = ones(48,6)+NaN; CwCO2_7200PSD = ones(48,6)+NaN;
SCO2_7500PSD = ones(48,6)+NaN; CwCO2_7500PSD = ones(48,6)+NaN;
SH2O_7200PSD = ones(48,6)+NaN; CwH2O_7200PSD = ones(48,6)+NaN;
SH2O_7500PSD = ones(48,6)+NaN; CwH2O_7500PSD = ones(48,6)+NaN;

wCO2PKT_7500PSD = ones(1,6)+NaN;   rhoc7500PSDPKT = ones(1,6)+NaN;
wCO2PKT_7200PSD = ones(1,6)+NaN;   rhoc7200PSDPKT = ones(1,6)+NaN;
wCO2PKTlb_7500PSD = ones(1,6)+NaN; rhoc7500PSDPKTlb = ones(1,6)+NaN;
wCO2PKTlb_7200PSD = ones(1,6)+NaN; rhoc7200PSDPKTlb = ones(1,6)+NaN;

wCO2JE0_7500PSD = ones(1,6)+NaN; wCO2JE1_7500PSD = ones(1,6)+NaN; gamPSDJE_7500PSD=ones(1,6)+NaN;gamPKTJE_7500PSD = ones(1,6)+NaN;
wCO2JE0_7200PSD = ones(1,6)+NaN; wCO2JE1_7200PSD = ones(1,6)+NaN; gamPSDJE_7200PSD=ones(1,6)+NaN;gamPKTJE_7200PSD = ones(1,6)+NaN;
Cqc7500PSD = ones(48,6)+NaN; Scc7500PSD = ones(48,6)+NaN; muw7500PSD = ones(48,6)+NaN;
Cqc7200PSD = ones(48,6)+NaN; Scc7200PSD = ones(48,6)+NaN; muw7200PSD = ones(48,6)+NaN;
C_H2O7200PSD_H2O7500PSD = ones(48,6)+NaN;
rqc_7200PSD = ones(1,6)+NaN;
rqc_7500PSD = ones(1,6)+NaN;
CCO2H2O_7500PSD = ones(48,6)+NaN;
CCO2H2O_7200PSD = ones(48,6)+NaN;

SCO2d_7200PSD = ones(48,6)+NaN;    CwCO2d_7200PSD = ones(48,6)+NaN;
slopeCO2d_7200PSD = ones(1,6)+NaN; stdCO2d_7200PSD = ones(1,6)+NaN; meanCO2d_7200PSD = ones(1,6)+NaN;
wCO2d_7200PSD = ones(1,6)+NaN;

uCO2d_7200PSD = ones(1,6)+NaN; vCO2d_7200PSD = ones(1,6)+NaN;
uCO2_7500PSD = ones(1,6)+NaN;  vCO2_7500PSD = ones(1,6)+NaN;

CwCO2c7500PSD = ones(48,6)+NaN;   CwCO2c7200PSD = ones(48,6)+NaN;
Srhoc7200PSDPKT = ones(48,6)+NaN; Cwrhoc7200PSDPKT = ones(48,6)+NaN;
Srhoc7500PSDPKT = ones(48,6)+NaN; Cwrhoc7500PSDPKT = ones(48,6)+NaN;
CCO2H2Or_7200PSD = ones(48,6)+NaN;
CwCO2d_7200PSD_ogive = ones(48,6)+NaN;
CwCO2d_7200PSD_cumtrapz = ones(48,6)+NaN;

Cwtson = ones(48,6)+NaN;
Cwt_ogive = ones(48,6)+NaN;
Cwt_cumtrapz = ones(48,6)+NaN;
FwCO2d_7200PSD_ogive = ones(48,6)+NaN; % frequency bins
Fwt_ogive = ones(48,6)+NaN;

slopeCO2_7200PSDrecomp = ones(1,6)+NaN; stdCO2_7200PSDrecomp = ones(1,6)+NaN; meanCO2_7200PSDrecomp = ones(1,6)+NaN;
slopeH2O_7200PSDrecomp = ones(1,6)+NaN; stdH2O_7200PSDrecomp =ones(1,6)+NaN;  meanH2O_7200PSDrecomp = ones(1,6)+NaN;
wCO2_7200PSDrecomp = ones(1,6)+NaN;     wH2O_7200PSDrecomp = ones(1,6)+NaN;
SCO2_7200PSDrecomp = ones(48,6)+NaN;    CwCO2_7200PSDrecomp = ones(48,6)+NaN;
SH2O_7200PSDrecomp = ones(48,6)+NaN;    CwH2O_7200PSDrecomp = ones(48,6)+NaN;

CTH2O_7500PSD = ones(48,6)+NaN;  
CTH2O_7200PSD = ones(48,6)+NaN;
STson_PSD = ones(48,6)+NaN;

newmu7500PSD = ones(48,6)+NaN;
CwCO2_7500PSDdecorr = ones(48,6)+NaN;
RqT7500PSD = ones(48,6)+NaN;

F_chop = ones(50,6)+NaN; % frequency bins
CwCO2d_7200PSDi = ones(50,6)+NaN;  
wCO2d_7200PSDi = ones(1,6)+NaN;  
CwCO2d_7200PSDichop = ones(50,6)+NaN;  
wCO2d_7200PSDichop = ones(1,6)+NaN;  
    
%% loop through 10-minute segments
% input 10Hz variables should all be 1x36000 arrays
for tt=0:5
    %% choose indices, adjusting for lag in 7200
    if tt~=5
        rng7200PSD = Nlendata*tt+1+abs(PSD7200lag):Nlendata*(tt+1)+abs(PSD7200lag); % 6000 point CO2 segment, lagged
        rngw7200PSD = Nlendata*tt+1:Nlendata*(tt+1);                                % 6000 point W segment
    else
        rng7200PSD = Nlendata*tt+1+abs(PSD7200lag):Nlendata*6;      % last CO2 segment is lagged but only 6000-lagPnts long
        rngw7200PSD = Nlendata*tt+1:Nlendata*tt+length(rng7200PSD); % last W segment, same length as above
    end;
    % but get rid of puff spike in first segment - 5400 point segment at top of hour
    if tt==0
        rng7200PSD(1:600) = [];
        rngw7200PSD(1:600) = []; 
    end;
 
    %% decorr CO2 and motion
    % use rng7200PSD for both 7200 CO2 & motion - no lag applied here as motion effects instantaneous on sensor...
    % first w/respect to acceleration
    LI7200_CO2mf(rng7200PSD) = motiondecorr(LI7200_CO2mf(rng7200PSD),Plat(:,rng7200PSD));
    LI7200_CO2mfd(rng7200PSD) = motiondecorr(LI7200_CO2mfd(rng7200PSD),Plat(:,rng7200PSD));
    LI7200_H2O(rng7200PSD) = motiondecorr(LI7200_H2O(rng7200PSD),Plat(:,rng7200PSD));
    LI7500_H2O(rngw7200PSD) = motiondecorr(LI7500_H2O(rngw7200PSD),Plat(:,rngw7200PSD));
    LI7500_CO2mf(rngw7200PSD) = motiondecorr(LI7500_CO2mf(rngw7200PSD),Plat(:,rngw7200PSD));
	% then w/respect to velocity
    LI7200_CO2mf(rng7200PSD) = motiondecorr(LI7200_CO2mf(rng7200PSD),uvwplat(:,rng7200PSD));
    LI7200_CO2mfd(rng7200PSD) = motiondecorr(LI7200_CO2mfd(rng7200PSD),uvwplat(:,rng7200PSD));
    LI7200_H2O(rng7200PSD) = motiondecorr(LI7200_H2O(rng7200PSD),uvwplat(:,rngw7200PSD));
    LI7500_H2O(rngw7200PSD) = motiondecorr(LI7500_H2O(rngw7200PSD),uvwplat(:,rngw7200PSD));
    LI7500_CO2mf(rngw7200PSD) = motiondecorr(LI7500_CO2mf(rngw7200PSD),uvwplat(:,rngw7200PSD));

%     figure;
%     subplot(2,1,1);     
%         plot(tmotion(rng7200UC),CO27200_UC(rng7200UC)-nanmean1(CO27200_UC(rng7200UC)),tmotion(rngw7200UC),wj(rngw7200UC),'g--');grid;xlim([tmotion(Nlendata*tt+1) tmotion(Nlendata*(tt+1))])
%     subplot(2,1,2);     
%         plot(tmotion(rng7200PSD),LI7200_CO2mf(rng7200PSD)-nanmean1(LI7200_CO2mf(rng7200PSD)),tmotion(rngw7200PSD),wj(rngw7200PSD),'g--');grid;xlim([tmotion(Nlendata*tt+1) tmotion(Nlendata*(tt+1))])
% 
%     figure;
%     subplot(2,1,1);     
%         plot(CO27200_UC(rng7200UC)-nanmean1(CO27200_UC(rng7200UC)));hold on;plot(wj(rngw7200UC),'g--');grid;
%     subplot(2,1,2); 
%         plot(LI7200_CO2mf(rng7200PSD)-nanmean1(LI7200_CO2mf(rng7200PSD)));hold on;plot(wj(rngw7200PSD),'g--');grid;

%% compute raw covariances
    % 7200 CO2 mole fraction units
    coj1 = nancov1(detrend(wj(rngw7200PSD)), detrend(LI7200_CO2mf(rng7200PSD)));
    wCO2_7200PSD(tt+1) = coj1(1,2);
    % 7200 CO2 dry-air mole fraction units, from Licor output
    coj1 = nancov1(detrend(wj(rngw7200PSD)), detrend(LI7200_CO2mfd(rng7200PSD)));
    wCO2d_7200PSD(tt+1) = coj1(1,2);
    % 7200 CO2 dry-air mole fraction, recomputed from Licor equations
    coj1 = nancov1(detrend(wj(rngw7200PSD)), detrend(CO2mfnew(rng7200PSD)));
    wCO2_7200PSDrecomp(tt+1) = coj1(1,2);
    % 7200 H2O dry-air g/kg (only meaningful when Nafion dryer is removed)
    coj1 = nancov1(detrend(wj(rngw7200PSD)), detrend(LI7200_H2O(rng7200PSD)));
    wH2O_7200PSD(tt+1) = coj1(1,2);
    % 7200 H2O dry-air g/kg, recomputed from Licor equations (only meaningful when Nafion dryer is removed)
    coj1 = nancov1(detrend(wj(rngw7200PSD)), detrend(H2Odnew(rng7200PSD)));
    wH2O_7200PSDrecomp(tt+1) = coj1(1,2);
    % 7500 CO2 mole fraction units
    coj1 = nancov1(detrend(wj(rngw7200PSD)), detrend(LI7500_CO2mf(rngw7200PSD)));
    wCO2_7500PSD(tt+1) = coj1(1,2);
    % 7500 H2O g/kg units
    coj1 = nancov1(detrend(wj(rngw7200PSD)), detrend(LI7500_H2O(rngw7200PSD)));
    wH2O_7500PSD(tt+1) = coj1(1,2);
    % 7200 horizontal flux components, dry-air mole fraction units
    coj1 = nancov1(detrend(uj(rngw7200PSD)),detrend(LI7200_CO2mfd(rng7200PSD))); uCO2d_7200PSD(tt+1) = coj1(1,2);
    coj1 = nancov1(detrend(vj(rngw7200PSD)),detrend(LI7200_CO2mfd(rng7200PSD))); vCO2d_7200PSD(tt+1) = coj1(1,2);
    % 7500 horizontal flux components, mole fraction units
    coj1 = nancov1(detrend(uj(rngw7200PSD)),detrend(LI7500_CO2mf(rngw7200PSD))); uCO2_7500PSD(tt+1) = coj1(1,2);
    coj1 = nancov1(detrend(vj(rngw7200PSD)),detrend(LI7500_CO2mf(rngw7200PSD))); vCO2_7500PSD(tt+1) = coj1(1,2);

%% CO2 PKT corrections
    % 7500
    [rhoc7500PSD] = PKTcode(LI7500_H2O(rngw7200PSD)/1000,rhfast7500_PSD(rngw7200PSD)*100,LI7500_CO2mf(rngw7200PSD)/1e6,wj(rngw7200PSD),rhoair);
    coj1 = nancov1(detrend(wj(rngw7200PSD)),detrend(rhoc7500PSD));
    wCO2PKT_7500PSD(tt+1) = coj1(1,2);
    rhoc7500PSDPKT(tt+1) = nanmean1(rhoc7500PSD); % ppm
    % 7200
    [rhoc7200PSD] = PKTcode(LI7200_H2O(rngw7200PSD)/1000,rhfast7200_PSD(rngw7200PSD)*100,LI7200_CO2mfd(rngw7200PSD)/1e6,wj(rngw7200PSD),rhoair);
    coj1 = nancov1(detrend(wj(rngw7200PSD)),detrend(rhoc7200PSD));
    wCO2PKT_7200PSD(tt+1) = coj1(1,2);
    rhoc7200PSDPKT(tt+1) = nanmean1(rhoc7200PSD); % ppm
    % 7500, LB code
    [rhoc7500PSDlb] = PKTcode_lb(LI7500_H2O(rngw7200PSD)/1000,rhfast7500_PSD(rngw7200PSD)*100,LI7500_CO2mf(rngw7200PSD)/1e6,wj(rngw7200PSD),rhoair);
    coj1 = nancov1(detrend(wj(rngw7200PSD)),detrend(rhoc7500PSDlb));
    wCO2PKTlb_7500PSD(tt+1) = coj1(1,2);
    rhoc7500PSDPKTlb(tt+1) = nanmean1(rhoc7500PSDlb); % ppm
    % 7200, LB code
    [rhoc7200PSDlb] = PKTcode_lb(LI7200_H2O(rngw7200PSD)/1000,rhfast7200_PSD(rngw7200PSD)*100,LI7200_CO2mfd(rngw7200PSD)/1e6,wj(rngw7200PSD),rhoair);
    coj1 = nancov1(detrend(wj(rngw7200PSD)),detrend(rhoc7200PSDlb));
    wCO2PKTlb_7200PSD(tt+1) = coj1(1,2);
    rhoc7200PSDPKTlb(tt+1) = nanmean1(rhoc7200PSDlb); % ppm
    
%% CO2 correction, cross-correlation approach
    % 7500
    coj1 = nancov1(detrend(LI7500_CO2mf(rngw7200PSD)),detrend(LI7500_H2O(rngw7200PSD)));
    wCO2H2O_7500PSD(tt+1) = coj1(1,2);
    % 7200 - only works when Nafion dryer is removed
    coj1 = nancov1(detrend(LI7200_CO2mfd(rng7200PSD)),detrend(LI7200_H2O(rng7200PSD)));
    wCO2H2O_7200PSD2(tt+1) = coj1(1,2);
    % 7200, using lagged water vapor from 7500 - also only meaningful when Nafion dryer is removed
    coj1 = nancov1(mr_att2(rngw7200PSD),LI7200_CO2mfd(rng7200PSD));
    wCO2H2O_7200PSD(tt+1) = coj1(1,2);
    muco2h2o_7200PSD(tt+1) = coj1(1,2)/coj1(1,1);    
    rqc_7200PSD(tt+1) = coj1(1,2)./(sqrt(coj1(1,1).*coj1(2,2)));  % q-c correlation
    % mu and correlation for 7500
    coj1 = nancov1(detrend(LI7500_CO2mf(rngw7200PSD)),detrend(LI7500_H2O(rngw7200PSD)));
    muco2h2o_7500PSD(tt+1) = coj1(1,2)/coj1(2,2);
    rqc_7500PSD(tt+1) = coj1(1,2)./(sqrt(coj1(1,1).*coj1(2,2)));  % q-c correlation
    
%% compute stationarity criteria related to dCO2/dt
    [slopeCO2_7200PSD(tt+1), stdCO2_7200PSD(tt+1),  meanCO2_7200PSD(tt+1)] = stationcrit (rng7200PSD, LI7200_CO2mf);   
    [slopeCO2d_7200PSD(tt+1), stdCO2d_7200PSD(tt+1),  meanCO2d_7200PSD(tt+1)] = stationcrit (rng7200PSD, LI7200_CO2mfd);  
    [slopeH2O_7200PSD(tt+1), stdH2O_7200PSD(tt+1),  meanH2O_7200PSD(tt+1)] = stationcrit (rng7200PSD, LI7200_H2O);
    [slopeCO2_7500PSD(tt+1), stdCO2_7500PSD(tt+1),  meanCO2_7500PSD(tt+1)] = stationcrit (rngw7200PSD,LI7500_CO2mf);
    [slopeH2O_7500PSD(tt+1), stdH2O_7500PSD(tt+1),  meanH2O_7500PSD(tt+1)] = stationcrit (rngw7200PSD,LI7500_H2O);
    [slopeCO2_7200PSDrecomp(tt+1), stdCO2_7200PSDrecomp(tt+1),  meanCO2_7200PSDrecomp(tt+1)] = stationcrit (rng7200PSD, CO2mfnew);  
    [slopeH2O_7200PSDrecomp(tt+1), stdH2O_7200PSDrecomp(tt+1),  meanH2O_7200PSDrecomp(tt+1)] = stationcrit (rng7200PSD, H2Odnew);

       
%%  compute specta/cospectra
    % 7200 CO2 spectrum, mole fraction wet and dry
    [SCO2_7200PSD_i,Fpic_i] = psd2(detrend(LI7200_CO2mf(rng7200PSD)),length(LI7200_CO2mf(rng7200PSD)),10,hamming(length(LI7200_CO2mf(rng7200PSD))));   
    [P,D] = specsmoo(SCO2_7200PSD_i,10);  % P is number of points in smoothed spectrum (~48)
    [SCO2_7200PSD(1:length(P),tt+1),Fpic_i] = specsmoo(SCO2_7200PSD_i,10);
    [SCO2d_7200PSD_i,Fpic_i] = psd2(detrend(LI7200_CO2mfd(rng7200PSD)),length(LI7200_CO2mfd(rng7200PSD)),10,hamming(length(LI7200_CO2mfd(rng7200PSD))));
    [SCO2d_7200PSD(1:length(P),tt+1),Fpics_i] = specsmoo(SCO2d_7200PSD_i,10);
    
    % 7200 CO2 cospectrum, dry-air mole fraction
    [CwCO2d_7200PSD_i,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(LI7200_CO2mfd(rng7200PSD)),length(LI7200_CO2mfd(rng7200PSD)),10,hamming(length(LI7200_CO2mfd(rng7200PSD))));
    [CwCO2d_7200PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CwCO2d_7200PSD_i,10);   
        % LB - add chopchop to get rid of some weird spikes in spectra
        % coming from sonic w'...vibration? Couldn't get rid of it with decorr
        % or Edson
    [Cc,Fc,dfc] = specsmooludot([CwCO2d_7200PSD_i],10);
    wc0 = real(nansum(Cc.*dfc));
    CwCO2d_7200PSDi(1:length(Cc),tt+1) = Cc;
    wCO2d_7200PSDi(tt+1) = wc0;
    [Y] = chopchop(5e-2,9e-2,Fc,Cc,1);
    wc1 = real(nansum(Y.*dfc));
    CwCO2d_7200PSDichop(1:length(Y),tt+1) = Y;
    wCO2d_7200PSDichop(tt+1) = wc1;
    F_chop(1:length(Y),tt+1) = dfc;
    
    % 7200 CO2 cospectrum, wet mole fraction
    [CwCO2_7200PSD_i,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(LI7200_CO2mf(rng7200PSD)),length(LI7200_CO2mf(rng7200PSD)),10,hamming(length(LI7200_CO2mf(rng7200PSD))));
    [CwCO2_7200PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CwCO2_7200PSD_i,10);
    
    % 7200 H2O spectrum & cospectrum
    [SH2O_7200PSD_i,Fpic_i] = psd2(detrend(LI7200_H2O(rng7200PSD)),length(LI7200_H2O(rng7200PSD)),10,hamming(length(LI7200_H2O(rng7200PSD))));
    [SH2O_7200PSD(1:length(P),tt+1),Fpics_i] = specsmoo(SH2O_7200PSD_i,10);
    [CwH2O_7200PSD_i,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(LI7200_H2O(rng7200PSD)),length(LI7200_H2O(rng7200PSD)),10,hamming(length(LI7200_H2O(rng7200PSD))));
    [CwH2O_7200PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CwH2O_7200PSD_i,10);
    
    % 7500 CO2 spectrum & cospectrum, dry mole fraction (webb corrected)
    [SCO2_7500PSD_i,Fpic_i] = psd2(detrend(LI7500_CO2mf(rngw7200PSD)),length(LI7500_CO2mf(rngw7200PSD)),10,hamming(length(LI7500_CO2mf(rngw7200PSD))));
    [SCO2_7500PSD(1:length(P),tt+1),Fpics_i] = specsmoo(SCO2_7500PSD_i,10);
    [CwCO2_7500PSD_i,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(LI7500_CO2mf(rngw7200PSD)),length(LI7500_CO2mf(rngw7200PSD)),10,hamming(length(LI7500_CO2mf(rngw7200PSD))));
    [CwCO2_7500PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CwCO2_7500PSD_i,10);
    
    % 7500 H2O spectrum & cospectrum
    [SH2O_7500PSD_i,Fpic_i] = psd2(detrend(LI7500_H2O(rngw7200PSD)),length(LI7500_H2O(rngw7200PSD)),10,hamming(length(LI7500_H2O(rngw7200PSD))));
    [SH2O_7500PSD(1:length(P),tt+1),Fpics_i] = specsmoo(SH2O_7500PSD_i,10);
    [CwH2O_7500PSD_i,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(LI7500_H2O(rngw7200PSD)),length(LI7500_H2O(rngw7200PSD)),10,hamming(length(LI7500_H2O(rngw7200PSD))));
    [CwH2O_7500PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CwH2O_7500PSD_i,10);   
    
    % 7200 spectra and cospectra from recomputed CO2 and H2O
    [SCO2_7200PSD_recompi,Fpic_i] = psd2(detrend(CO2mfnew(rng7200PSD)),length(CO2mfnew(rng7200PSD)),10,hamming(length(CO2mfnew(rng7200PSD))));
    [SCO2_7200PSDrecomp(1:length(P),tt+1),Fpics_i] = specsmoo(SCO2_7200PSD_recompi,10);
    [CwCO2_7200PSD_recompi,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(CO2mfnew(rng7200PSD)),length(CO2mfnew(rng7200PSD)),10,hamming(length(CO2mfnew(rng7200PSD))));
    [CwCO2_7200PSDrecomp(1:length(P),tt+1),Fpics_i] = specsmoo(CwCO2_7200PSD_recompi,10);   
    [SH2O_7200PSD_recompi,Fpic_i] = psd2(detrend(H2Odnew(rng7200PSD)),length(H2Odnew(rng7200PSD)),10,hamming(length(H2Odnew(rng7200PSD))));
    [SH2O_7200PSDrecomp(1:length(P),tt+1),Fpics_i] = specsmoo(SH2O_7200PSD_recompi,10);
    [CwH2O_7200PSD_recompi,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(H2Odnew(rng7200PSD)),length(H2Odnew(rng7200PSD)),10,hamming(length(H2Odnew(rng7200PSD))));
    [CwH2O_7200PSDrecomp(1:length(P),tt+1),Fpics_i] = specsmoo(CwH2O_7200PSD_recompi,10);   
    
%% spectra & cospectra for spectral crosstalk correction     
    [CCO2H2O_7500PSD_i,Fpic_i] = csd2(detrend(LI7500_CO2mf(rngw7200PSD)),detrend(LI7500_H2O(rngw7200PSD)),length(LI7500_H2O(rngw7200PSD)),10,hamming(length(LI7500_H2O(rngw7200PSD))));
    [CCO2H2O_7500PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CCO2H2O_7500PSD_i,10);   
    [CCO2H2O_7200PSD_i,Fpic_i] = csd2(detrend(LI7200_CO2mfd(rngw7200PSD)),detrend(LI7200_H2O(rngw7200PSD)),length(LI7200_H2O(rngw7200PSD)),10,hamming(length(LI7200_H2O(rngw7200PSD))));
    [CCO2H2O_7200PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CCO2H2O_7200PSD_i,10);   
    [CTH2O_7500PSD_i,Fpic_i] = csd2(detrend(Tsonic(rngw7200PSD)),detrend(LI7500_H2O(rngw7200PSD)),length(LI7500_H2O(rngw7200PSD)),10,hamming(length(LI7500_H2O(rngw7200PSD))));
    [CTH2O_7500PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CTH2O_7500PSD_i,10);   
    [CTH2O_7200PSD_i,Fpic_i] = csd2(detrend(Tsonic(rngw7200PSD)),detrend(LI7200_H2O(rngw7200PSD)),length(LI7200_H2O(rngw7200PSD)),10,hamming(length(LI7200_H2O(rngw7200PSD))));
    [CTH2O_7200PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CTH2O_7200PSD_i,10);   
    [STson_i,Fpic_i] = psd2(detrend(Tsonic(rngw7200PSD)),length(Tsonic(rngw7200PSD)),10,hamming(length(Tsonic(rngw7200PSD))));
    [STson_PSD(1:length(P),tt+1),Fpics_i] = specsmoo(STson_i,10);
    % to compute mucc in freqeuncy domain
    [CCO2H2Or_7200PSD_i,Fpic_i] = csd2(detrend(LI7200_CO2mfd(rng7200PSD)),detrend(mr_att2(rngw7200PSD)),length(LI7200_CO2mfd(rng7200PSD)),10,hamming(length(LI7200_CO2mfd(rng7200PSD))));  
    [CCO2H2Or_7200PSD(1:length(P),tt+1),Fpics_i] = specsmoo(CCO2H2Or_7200PSD_i,10);
    
    Fpic(1:length(P),tt+1) = Fpics_i;         
    % computes corresponding fluxes from spectral crosstalk approach   
    [wCO2JE0_7500PSD(tt+1),wCO2JE1_7500PSD(tt+1),gamPSDJE_7500PSD(tt+1),gamPKTJE_7500PSD(tt+1),Cqc7500PSD(1:length(P),tt+1),Scc7500PSD(1:length(P),tt+1),muw7500PSD(1:length(P),tt+1),CwCO2c7500PSD(1:length(P),tt+1)] = SpectralCrosstalk(CCO2H2O_7500PSD_i,SH2O_7500PSD_i,CwCO2_7500PSD_i,CwH2O_7500PSD_i,wCO2d_7200PSD(tt+1),wCO2PKT_7500PSD(tt+1),SCO2_7500PSD_i,1.15);    
    [wCO2JE0_7200PSD(tt+1),wCO2JE1_7200PSD(tt+1),gamPSDJE_7200PSD(tt+1),gamPKTJE_7200PSD(tt+1),Cqc7200PSD(1:length(P),tt+1),Scc7200PSD(1:length(P),tt+1),muw7200PSD(1:length(P),tt+1),CwCO2c7200PSD(1:length(P),tt+1)] = SpectralCrosstalk(CCO2H2O_7200PSD_i,SH2O_7200PSD_i,CwCO2d_7200PSD_i,CwH2O_7200PSD_i,wCO2d_7200PSD(tt+1),wCO2PKT_7200PSD(tt+1),SCO2d_7200PSD_i,0.88);    
    % to look at H2O response cospectrum - should use lagged range
    % rng7200PSD for LI7200_H2O here???
    [C_H2O7200PSD_H2O7500PSD_i,Fpic_i] = csd2(detrend(LI7200_H2O(rngw7200PSD)),detrend(LI7500_H2O(rngw7200PSD)),length(LI7200_H2O(rng7200PSD)),10,hamming(length(LI7200_H2O(rng7200PSD))));
    [C_H2O7200PSD_H2O7500PSD(1:length(P),tt+1),Fpics_i] = specsmoo(C_H2O7200PSD_H2O7500PSD_i,10);   

%% spectra & cospectra for PKT correction
    [Srhoc7200PSD_i,Fpic_i] = psd2(detrend(rhoc7200PSD),length(rhoc7200PSD),10,hamming(length(rhoc7200PSD)));
    [Srhoc7200PSDPKT(1:length(P),tt+1),Fpics_i] = specsmoo(Srhoc7200PSD_i,10);
    [Cwrhoc7200PSD_i,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(rhoc7200PSD),length(rhoc7200PSD),10,hamming(length(rhoc7200PSD)));
    [Cwrhoc7200PSDPKT(1:length(P),tt+1),Fpics_i] = specsmoo(Cwrhoc7200PSD_i,10);   
    [Srhoc7500PSD_i,Fpic_i] = psd2(detrend(rhoc7500PSD),length(rhoc7500PSD),10,hamming(length(rhoc7500PSD)));
    [Srhoc7500PSDPKT(1:length(P),tt+1),Fpics_i] = specsmoo(Srhoc7500PSD_i,10);
    [Cwrhoc7500PSD_i,Fpic_i]=csd2(detrend(wj(rngw7200PSD)),detrend(rhoc7500PSD),length(rhoc7500PSD),10,hamming(length(rhoc7500PSD)));
    [Cwrhoc7500PSDPKT(1:length(P),tt+1),Fpics_i] = specsmoo(Cwrhoc7500PSD_i,10);   

%% compute Ogive & cumtrapz for CO2 and T
    [Ct,Fl] = Ogive(CwCO2d_7200PSD_i,fs); % similar to test=cumtrapz(Fpic_i,CwCO2d_7200PSD_i);
    CwCO2d_7200PSD_ogive(1:length(Ct),tt+1) = Ct;
    FwCO2d_7200PSD_ogive(1:length(Ct),tt+1) = Fl;  
    [Ctemp,Ftemp] = specsmoo(cumtrapz(Fpic_i,CwCO2d_7200PSD_i),10);
    CwCO2d_7200PSD_cumtrapz(1:length(P),tt+1) = Ctemp; 
    % Sensible heat
    [Cwti,Fpic_i] = csd2(detrend(wj(rngw7200PSD)),detrend(Tsonic(rngw7200PSD)),length(Tsonic(rngw7200PSD)),10,hamming(length(Tsonic(rngw7200PSD))));
    [Cwtson(1:length(P),tt+1),Fpics_i] = specsmoo(Cwti,10);   
    [Ct,Fl] = Ogive(Cwti,fs);  %similar to test=cumtrapz(Fpic_i,CwCO2d_7200PSD_i);
    Cwt_ogive(1:length(Ct),tt+1) = Ct;
    Fwt_ogive(1:length(Ct),tt+1) = Fl; 
    [Ctemp,Ftemp] = specsmoo(cumtrapz(Fpic_i,Cwti),10);
    Cwt_cumtrapz(1:length(P),tt+1) = Ctemp;
    
%% spectra from Edson 2011
    % compute mu(f) via eq. A8 & A10, Edson 2011, using default RqTf7500PSD
    newmu7500PSD(1:48,tt+1) = (CCO2H2O_7500PSD(:,tt+1)./SH2O_7500PSD(:,tt+1))-sqrt(RqTf7500PSD.*SCO2_7500PSD(:,tt+1)./SH2O_7500PSD(:,tt+1));
    % corrected cospectrum, eq. 20, Edson 2011
    CwCO2_7500PSDdecorr(1:48,tt+1) = CwCO2_7500PSD(:,tt+1)-newmu7500PSD(:,tt+1).*CwH2O_7500PSD(:,tt+1);
    % eq. A9, Edson 2011, but Rqt rather than Rqc
    % updated estimate for default RqT loaded above??
	RqT7500PSD(1:48,tt+1) = (CTH2O_7500PSD(:,tt+1).*CTH2O_7500PSD(:,tt+1))./(STson_PSD(:,tt+1).*SH2O_7500PSD(:,tt+1));
end;

%% save results

% dcnames='_vCO2decorr3';   % with gam fluctuating
% dcnames='_vCO2decorr1';   % with gam fixed
% dcnames='_vCO2decorr_noWebbon7500mast';
dcnames='_UH_vCO2decorr1';  % with gam fixed, UH motion & wind

%------10-minute variable array:
%{
Col Variable Name               Description
1   Decimal_DOY                 Decimal day-of-year
2   wCO2_7200PSD                LI-7200 W'CO2' covariance, wet mole fraction output, ppm m/s
3   wH2O_7200PSD                LI-7200 W'H2O' covariance, g/kg dry air m/s
4   wCO2_7500PSD                LI-7500 W'CO2' covariance, dry mole fraction, ppm m/s, (Webb corrected)
5   wH2O_7500PSD                LI-7500 W'H2O' covariance, g/kg wet air m/s
6   slopeCO2_7200PSD            LI-7200 CO2 d(ppm,wet)/dt
7   stdCO2_7200PSD              LI-7200 CO2 std dev, ppm(wet)
8   meanCO2_7200PSD             LI-7200 CO2 mean, ppm(wet)
9   slopeH2O_7200PSD            LI-7200 H2O d(g/kg dry air)/dt
10  stdH2O_7200PSD              LI-7200 H2O std dev, g/kg dry air
11  meanH2O_7200PSD             LI-7200 H2O mean, g/kg dry air
12  slopeCO2_7500PSD            LI-7500 CO2 d(ppm,dry)/dt, (Webb corrected)
13  stdCO2_7500PSD              LI-7500 CO2 std dev, ppm(dry), (Webb corrected)
14  meanCO2_7500PSD             LI-7500 CO2 mean, ppm(dry), (Webb corrected)
15  slopeH2O_7500PSD            LI-7500 H2O d(g/kg wet air)/dt
16  stdH2O_7500PSD              LI-7500 H2O std dev, g/kg
17  meanH2O_7500PSD             LI-7500 H2O mean, g/kg
18  LI7200_AGC_PSD_10m          LI-7200 AGC, mean
19  LI7200_AGC_PSD_10s          LI-7200 AGC, std dev
20  LI7500_AGC_10m              LI-7500 AGC, mean
21  LI7500_AGC_10s              LI-7500 AGC, std dev
22  NPnts_7500CO2               LI-7500 Data points in 10-min segment
23  NPnts_7200CO2               LI-7200 Data points in 10-min segment
24  wCO2PKT_7500PSD             LI-7500 W'CO2' covariance, dry mole fraction, PKT correction, (Webb corrected)
25  rhoc7500PSDPKT              LI-7500 CO2, dry mole fraction, PKT correction, (Webb corrected)
26  wCO2PKT_7200PSD             LI-7200 W'CO2' covariance, dry mole fraction, PKT correction
27  rhoc7200PSDPKT              LI-7200 CO2, dry mole fraction, PKT correction
28  wCO2JE0_7500PSD             LI-7500 Uncorrected dry mole fraction flux, (Webb corrected)
29  wCO2JE1_7500PSD             LI-7500 Cross-correlation corrected dry mole fraction flux, (Webb corrected)
30  gamPSDJE_7500PSD            LI-7500 Gamma factor, based on dry mf 7200 flux
31  gamPKTJE_7500PSD            LI-7500 Gamma factor, based on PKT-corrected dry mf 7500 flux
32  wCO2JE0_7200PSD             LI-7200 Uncorrected dry mole fraction flux
33  wCO2JE1_7200PSD             LI-7200 Cross-correlation corrected dry mole fraction flux
34  gamPSDJE_7200PSD            LI-7200 Gamma factor, based on dry mf 7200 flux
35  gamPKTJE_7200PSD            LI-7200 Gamma factor, based on PKT-corrected dry mf 7500 flux
36  slopeCO2d_7200PSD           LI-7200 CO2 d(ppm,dry)/dt
37  stdCO2d_7200PSD             LI-7200 CO2 std dev, ppm(dry)
38  meanCO2d_7200PSD            LI-7200 CO2 mean, ppm(dry)
39  wCO2d_7200PSD               LI-7200 W'CO2' covariance, dry mole fraction output
40  wCO2PKTlb_7500PSD           LI-7500 W'CO2' covariance, dry mole fraction, PKT correction, LB code, (Webb corrected)
41  rhoc7500PSDPKTlb            LI-7500 CO2, dry mole fraction, PKT correction, LB code, (Webb corrected)
42  wCO2PKTlb_7200PSD           LI-7200 W'CO2' covariance, dry mole fraction, PKT correction, LB code
43  rhoc7200PSDPKTlb            LI-7200 CO2, dry mole fraction, PKT correction, LB code
44  uCO2d_7200PSD               LI-7200 horiz flux, dry mf, U component
45  vCO2d_7200PSD               LI-7200 horiz flux, dry mf, V component
46  uCO2_7500PSD                LI-7500 horiz flux, dry mf, U component, (Webb corrected)
47  vCO2_7500PSD                LI-7500 horiz flux, dry mf, V component, (Webb corrected)
48  slopeCO2_7200PSDrecomp      LI-7200 CO2 d(ppm,dry)/dt, recomputed mf
49  stdCO2_7200PSDrecomp        LI-7200 CO2 std dev, ppm(dry), recomputed mf
50  meanCO2_7200PSDrecomp       LI-7200 CO2 mean, ppm(dry), recomputed mf
51  slopeH2O_7200PSDrecomp      LI-7200 H2O d(g/kg dry air)/dt, recomputed mf
52  stdH2O_7200PSDrecomp        LI-7200 H2O std dev, g/kg dry air, recomputed mf
53  meanH2O_7200PSDrecomp       LI-7200 H2O mean, g/kg dry air, recomputed mf
54  wCO2_7200PSDrecomp          LI-7200 W'CO2' covariance, dry mole fraction, recomputed mf
55  wH2O_7200PSDrecomp          LI-7200 W'H2O' covariance, g/kg dry air m/s, recomputed qs
56  muco2h2o_7500PSD            LI-7500 mu from cross-correlation correction
57  muco2h2o_7200PSD            LI-7200 mu from cross-correlation correction
58  wCO2H2O_7500PSD             LI-7500 CO2:H2O covariance, cross-correlation correction, uses lagged 7500 H2O
59  wCO2H2O_7200PSD             LI-7200 CO2:H2O covariance, cross-correlation correction
60  rqc_7200PSD                 LI-7200 q-co2 correlation coeff, cross-correlation correction
61  rqc_7500PSD                 LI-7500 q-co2 correlation coeff, cross-correlation correction
62  wCO2H2O_7200PSD2            LI-7500 CO2:H2O covariance, cross-correlation correction, uses 7200 H2O
63  wCO2d_7200PSDi              LI-7200 W'CO2' flux from integration of dry air mf cospectrum
64  wCO2d_7200PSDichop          LI-7200 W'CO2' flux from integration of chopchop adjusted cospectrum
%}

newview =[(ddd+hhh/24+(00:10:50)/24/60)' ...
    wCO2_7200PSD' wH2O_7200PSD' wCO2_7500PSD' wH2O_7500PSD' ...
    slopeCO2_7200PSD'  stdCO2_7200PSD'   meanCO2_7200PSD'  ...
    slopeH2O_7200PSD'  stdH2O_7200PSD'   meanH2O_7200PSD'  ...
    slopeCO2_7500PSD'  stdCO2_7500PSD'   meanCO2_7500PSD'  ...
    slopeH2O_7500PSD'  stdH2O_7500PSD'   meanH2O_7500PSD'  ...
    LI7200_AGC_PSD_10m' LI7200_AGC_PSD_10s' LI7500_AGC_10m' LI7500_AGC_10s'...
    ones(6,1)*length(Licor_CO2) ones(6,1)*length(LI7200_CO2mf) ...
    wCO2PKT_7500PSD' rhoc7500PSDPKT' ...
    wCO2PKT_7200PSD' rhoc7200PSDPKT' ...
    wCO2JE0_7500PSD' wCO2JE1_7500PSD' gamPSDJE_7500PSD' gamPKTJE_7500PSD' ... 
    wCO2JE0_7200PSD' wCO2JE1_7200PSD' gamPSDJE_7200PSD' gamPKTJE_7200PSD' ...
    slopeCO2d_7200PSD'  stdCO2d_7200PSD'   meanCO2d_7200PSD'  wCO2d_7200PSD' ...
    wCO2PKTlb_7500PSD' rhoc7500PSDPKTlb' ...
    wCO2PKTlb_7200PSD' rhoc7200PSDPKTlb' ...
    uCO2d_7200PSD' vCO2d_7200PSD' ...
    uCO2_7500PSD' vCO2_7500PSD' ...
    slopeCO2_7200PSDrecomp' stdCO2_7200PSDrecomp' meanCO2_7200PSDrecomp' ...
    slopeH2O_7200PSDrecomp' stdH2O_7200PSDrecomp' meanH2O_7200PSDrecomp'...
    wCO2_7200PSDrecomp' wH2O_7200PSDrecomp' ...
    muco2h2o_7500PSD'  muco2h2o_7200PSD' ...
    wCO2H2O_7500PSD' wCO2H2O_7200PSD'...
    rqc_7200PSD' rqc_7500PSD' wCO2H2O_7200PSD2'...
    wCO2d_7200PSDi' wCO2d_7200PSDichop'];

sdg=['save ',drive_w1,'CO2flux',jd hr,dcname,dcnames, '.txt newview -ascii'];
disp(sdg);
eval(sdg);

% 10-min spectra/cospectra array: 40 spectra @ 6x48 points, 6 spectra @ 7x50 points
% (ogives & CwCO2d_7200PSDi/CwCO2d_7200PSDichop),and decimal day (6x1).  Final array: 6x2271
%{
columns     Varible Name                Description
1           Decimal_DOY                 Decimal day-of-year
2:49        Fpic                        Frequency array for all except ogives
50:97       SCO2_7200PSD                LI-7200, wet mf, spectrum
98:145      CwCO2_7200PSD               LI-7200, wet mf, W cospectrum
146:193     SCO2_7500PSD                LI-7500, dry mf, spectrum (Webb corrected)
194:241     CwCO2_7500PSD               LI-7500, dry mf, cospectrum (Webb corrected)
242:289     SH2O_7200PSD                LI-7200, g/kg dry air, spectrum
290:337     CwH2O_7200PSD               LI-7200, g/kg dry air, W cospectrum
338:385     SH2O_7500PSD                LI-7500, g/kg wet air, spectrum
386:433     CwH2O_7500PSD               LI-7500, g/kg wet air, W cospectrum
434:481     CCO2H2O_7500PSD             LI-7500, CO2:H2O cospectrum
482:529     CCO2H2O_7200PSD             LI-7200, CO2:H2O cospectrum
530:577     Cqc7500PSD                  LI-7500, cross-correlation corrected qc cospectrum, Cqc=CCO2H2O-muw.*SH2O;
578:625     Scc7500PSD                  LI-7500, cross-correlation corrected c spectrum, Scc=SCO2-muw.*[CCO2H2O+Cqc];
626:673     muw7500PSD                  LI-7500, cross-correlation mu spectrum
674:721     Cqc7200PSD                  LI-7200, cross-correlation corrected qc cospectrum, Cqc=CCO2H2O-muw.*SH2O;
722:769     Scc7200PSD                  LI-7200, cross-correlation corrected c spectrum, Scc=SCO2-muw.*[CCO2H2O+Cqc];
770:817     muw7200PSD                  LI-7200, cross-correlation mu spectrum
818:865     C_H2O7200PSD_H2O7500PSD     LI-7200 : LI7500 water vapor cospectrum - relative response test
866:913     SCO2d_7200PSD               LI-7200, CO2 dry mf output, spectrum
914:961     CwCO2d_7200PSD              LI-7200, CO2 dry mf output, W cospectrum
962:1009    CwCO2c7500PSD               LI-7500, cross-correlation corrected cospectrum
1010:1057   CwCO2c7200PSD               LI-7200, cross-correlation corrected cospectrum
1058:1105   Srhoc7200PSDPKT             LI-7200, PKT corrected CO2 dry mf spectrum
1106:1153   Cwrhoc7200PSDPKT            LI-7200, PKT corrected CO2 dry mf W cospectrum
1154:1201   Srhoc7500PSDPKT             LI-7500, PKT corrected CO2 dry mf spectrum
1202:1249   Cwrhoc7500PSDPKT            LI-7500, PKT corrected CO2 dry mf W cospectrum
1250:1297   CCO2H2Or_7200PSD            LI-7200, cross-correlation mu spectrum
1298:1347   CwCO2d_7200PSD_ogive        LI-7200, dry air W cospectrum ogive
1348:1397   FwCO2d_7200PSD_ogive        LI-7200, frequency array, ogive
1398:1445   CwCO2d_7200PSD_cumtrapz     LI-7200, dry air integrated W cospectrum
1446:1493   Cwtson                      Sonic T W cospectrum
1494:1543   Cwt_ogive                   Sonic T W cospectrum ogive
1544:1593   Fwt_ogive                   Sonic T, frequency array, ogive
1594:1641   Cwt_cumtrapz                Sonic T, integrated W cospectrum
1642:1689   SCO2_7200PSDrecomp          LI-7200, recomputed CO2 dry mf, spectrum
1690:1737   CwCO2_7200PSDrecomp         LI-7200, recomputed CO2 dry mf, W cospectrum
1738:1785   SH2O_7200PSDrecomp          LI-7200, recomputed H2O g/kg dry air, spectrum
1786:1833   CwH2O_7200PSDrecomp         LI-7200, recomputed H2O g/kg dry air, W cospectrum
1834:1881   CTH2O_7500PSD               LI-7500, H2O:Tsonic cospectrum, cross-correlation correction
1882:1929   CTH2O_7200PSD               LI-7200, H2O:Tsonic cospectrum, cross-correlation correction
1930:1977   STson_PSD                   Sonic T spectrum
1978:2025   RqT7500PSD                  LI-7500, Rqt(f), Edson 2011
2026:2073   newmu7500PSD                LI-7500, Mu(f), Edson 2011
2074:2121   CwCO2_7500PSDdecorr         LI-7500, Corrected CO2 cospectrum, Edson 2011
2122:2171   CwCO2d_7200PSDi             LI-7200, Raw uncorrected cospectrum, dry mf output, equiv to CwCO2d_7200PSD above
2172:2221   CwCO2d_7200PSDichop         LI-7200, despiked cospectrum, dry mf output
2222:2271   F_chop                      Frequency array for above two cospetra
%}

specview =[(ddd+hhh/24+(00:10:50)/24/60)',Fpic',...
            SCO2_7200PSD',real(CwCO2_7200PSD)',...
            SCO2_7500PSD',real(CwCO2_7500PSD)',...
            SH2O_7200PSD',real(CwH2O_7200PSD)',...
            SH2O_7500PSD',real(CwH2O_7500PSD)',... 
            real(CCO2H2O_7500PSD)',... 
            real(CCO2H2O_7200PSD)',... 
            real(Cqc7500PSD)',real(Scc7500PSD)',real(muw7500PSD)',... 
            real(Cqc7200PSD)',real(Scc7200PSD)',real(muw7200PSD)',... 
            real(C_H2O7200PSD_H2O7500PSD)',...
            SCO2d_7200PSD',real(CwCO2d_7200PSD)',...
            real(CwCO2c7500PSD)',real(CwCO2c7200PSD)',...
            Srhoc7200PSDPKT',real(Cwrhoc7200PSDPKT)',...
            Srhoc7500PSDPKT',real(Cwrhoc7500PSDPKT)',...
            real(CCO2H2Or_7200PSD)',... %to compute mucc in frequency domain
            real(CwCO2d_7200PSD_ogive)',FwCO2d_7200PSD_ogive',real(CwCO2d_7200PSD_cumtrapz)',...
            real(Cwtson)',real(Cwt_ogive)',Fwt_ogive',real(Cwt_cumtrapz)',...
            SCO2_7200PSDrecomp',real(CwCO2_7200PSDrecomp)',...
            SH2O_7200PSDrecomp',real(CwH2O_7200PSDrecomp)',...
            real(CTH2O_7500PSD)',real(CTH2O_7200PSD)',STson_PSD',...
            real(RqT7500PSD)',real(newmu7500PSD)',real(CwCO2_7500PSDdecorr)',...
            real(CwCO2d_7200PSDi)',real(CwCO2d_7200PSDichop)',F_chop'];

sdg=['save ',drive_w1,'CO2spec',jd hr,dcname,dcnames, '.txt specview -ascii'];
disp(sdg);
eval(sdg);

% cleanup
fclose all;
if clearit
    clear LI7200_AGC_PSD_10s         Srhoc7500PSD_i             meanH2O_7500PSD            stdH2O_7200PSD             
    clear CCO2H2O_7200PSD            LI7200_APress              Sw                         meanP                      stdH2O_7200PSDrecomp       
    clear CCO2H2O_7200PSD_i          LI7200_CO2d                TairL                      meanQ                      stdH2O_7500PSD             
    clear CCO2H2O_7500PSD            LI7200_CO2mf               Tsonic                     meanTv                     su                         
    clear CCO2H2O_7500PSD_i          LI7200_CO2mfd              Tvais                      motmat                     sv                         
    clear CCO2H2Or_7200PSD           LI7200_CO2raw              TvirtV                     mr_att2                    sw                         
    clear CCO2H2Or_7200PSD_i         LI7200_H2O                 U                          mst                        t7200                      
    clear CO2mfnew                   LI7200_H2Od                V                          msu                        tmotion                    
    clear CTH2O_7200PSD              LI7200_H2Omfd              W                          msv                        tref                       
    clear CTH2O_7200PSD_i            LI7200_H2Oraw              Xwc                        msw                        tsonicV                    
    clear CTH2O_7500PSD              LI7200_agc                 Y                          muco2h2o_7200PSD           tsons                      
    clear CTH2O_7500PSD_i            LI7500_AGC_10m             ahi                        muco2h2o_7500PSD           tt                         
    clear C_H2O7200PSD_H2O7500PSD    LI7500_AGC_10s             ans                        muw7200PSD                 tvirt                      
    clear C_H2O7200PSD_H2O7500PSD_i  LI7500_CO2mf               aw                         muw7500PSD                 u                          
    clear Cc                         LI7500_H2O                 b                          n                          uCO2_7500PSD               
    clear Cqc7200PSD                                            bhi                        ncol                       uCO2d_7200PSD              
    clear Cqc7500PSD                                            chk                        newmu7500PSD               uj                         
    clear Ct                         Lenlic                                                newview                    uvwmat                     
    clear Ctemp                      Licor_CO2                  coj1                       nfreq                      uvwplat                    
    clear CwCO2_7200PSD              Licrate                                                                          v                          
    clear CwCO2_7200PSD_i                                                                                             vCO2_7500PSD               
    clear CwCO2_7200PSD_recompi                                                            press                      vCO2d_7200PSD              
    clear CwCO2_7200PSDrecomp        Nlendata                                              qair                       vj                         
    clear CwCO2_7500PSD              P                          dfc                        rairV                      wCO2H2O_7200PSD            
    clear CwCO2_7500PSD_i            PSD7200lag                 dfl                        rhfast7200_PSD             wCO2H2O_7200PSD2           
    clear CwCO2_7500PSDdecorr        PairL                      dfx                        rhfast7500_PSD             wCO2H2O_7500PSD            
    clear CwCO2c7200PSD              Plat                                                  rhoair                     wCO2JE0_7200PSD            
    clear CwCO2c7500PSD              Qms                        fc                         rhoc7200PSD                wCO2JE0_7500PSD            
    clear CwCO2d_7200PSD             R                                                     rhoc7200PSDPKT             wCO2JE1_7200PSD            
    clear CwCO2d_7200PSD_cumtrapz    RHL                        flist                      rhoc7200PSDPKTlb           wCO2JE1_7500PSD            
    clear CwCO2d_7200PSD_i           Rgas                       fs                         rhoc7200PSDlb              wCO2PKT_7200PSD            
    clear CwCO2d_7200PSD_ogive       Rgas_universal                                        rhoc7500PSD                wCO2PKT_7500PSD            
    clear CwCO2d_7200PSDi            Rhoair                     g                          rhoc7500PSDPKT             wCO2PKTlb_7200PSD          
    clear CwCO2d_7200PSDichop        Rhvais                     gamPKTJE_7200PSD           rhoc7500PSDPKTlb           wCO2PKTlb_7500PSD          
    clear CwH2O_7200PSD              RqT7500PSD                 gamPKTJE_7500PSD           rhoc7500PSDlb              wCO2_7200PSD               
    clear CwH2O_7200PSD_i                                       gamPSDJE_7200PSD           rhovV                      wCO2_7200PSDrecomp         
    clear CwH2O_7200PSD_recompi                                 gamPSDJE_7500PSD           rng7200PSD                 wCO2_7500PSD               
    clear CwH2O_7200PSDrecomp        SCO2_7200PSD               gpslat                     rngw                       wCO2d_7200PSD              
    clear CwH2O_7500PSD              SCO2_7200PSD_i             h2oV                       rngw7200PSD                wCO2d_7200PSDi             
    clear CwH2O_7500PSD_i            SCO2_7200PSD_recompi       heave                                                 wCO2d_7200PSDichop         
    clear Cwrhoc7200PSDPKT           SCO2_7200PSDrecomp                                    rqc_7200PSD                wH2O_7200PSD               
    clear Cwrhoc7200PSD_i            SCO2_7500PSD               hr                         rqc_7500PSD                wH2O_7200PSDrecomp         
    clear Cwrhoc7500PSDPKT           SCO2_7500PSD_i             ii                         sdg                        wH2O_7500PSD               
    clear Cwrhoc7500PSD_i            SCO2d_7200PSD
    clear Cwt_cumtrapz               SCO2d_7200PSD_i            jd                         slopeCO2_7200PSD           wc0                        
    clear Cwt_ogive                  SH2O_7200PSD               jd7200                     slopeCO2_7200PSDrecomp     wc1                        
    clear Cwti                       SH2O_7200PSD_i                                        slopeCO2_7500PSD           wj                         
    clear Cwtson                     SH2O_7200PSD_recompi                                  slopeCO2d_7200PSD          wn                         
    clear D                          SH2O_7200PSDrecomp                                    slopeH2O_7200PSD           wp                         
    clear Fc                         SH2O_7500PSD               m                          slopeH2O_7200PSDrecomp     ws                         
    clear Fl                         SH2O_7500PSD_i             mU                         slopeH2O_7500PSD           xyzplat                    
    clear Fpic                       STson_PSD                  mV                                                    yday                       
    clear Fpic_i                     STson_i                    mW                         specview                       
    clear Fpics_i                    Scc7200PSD                 meanCO2_7200PSD            st                     
    clear Ftemp                      Scc7500PSD                 meanCO2_7200PSDrecomp      st1                      
    clear FwCO2d_7200PSD_ogive       Sco2                       meanCO2_7500PSD            stdCO2_7200PSD                       
    clear Fwt_ogive                  Srhoc7200PSDPKT            meanCO2d_7200PSD           stdCO2_7200PSDrecomp       zy                         
    clear H2Odnew                    Srhoc7200PSD_i             meanH2O_7200PSD            stdCO2_7500PSD             zz                         
    clear LI7200_AGC_PSD_10m         Srhoc7500PSDPKT            meanH2O_7200PSDrecomp      stdCO2d_7200PSD     
end;
