disp('fastpr07.m')

F1_1= 1 - (wu_1(1,1) / 9 + 2 * wv_1(1,1) / 3 + 2 * wu_1(2,2) / 3) / Ubar_1 / Ubar_1;
F1_2= 1 - (wu_2(1,1) / 9 + 2 * wv_2(1,1) / 3 + 2 * wu_2(2,2) / 3) / Ubar_2 / Ubar_2;
F1_3= 1 - (wu_3(1,1) / 9 + 2 * wv_3(1,1) / 3 + 2 * wu_3(2,2) / 3) / Ubar_3 / Ubar_3;
F1_4= 1 - (wu_4(1,1) / 9 + 2 * wv_4(1,1) / 3 + 2 * wu_4(2,2) / 3) / Ubar_4 / Ubar_4;
F1_5= 1 - (wu_5(1,1) / 9 + 2 * wv_5(1,1) / 3 + 2 * wu_5(2,2) / 3) / Ubar_5 / Ubar_5;
F1_6= 1 - (wu_6(1,1) / 9 + 2 * wv_6(1,1) / 3 + 2 * wu_6(2,2) / 3) / Ubar_6 / Ubar_6;

F2_1= 1 - (wu_1(1,1) / 9 + wv_1(1,1) / 12 + wu_1(2,2) / 3) / Ubar_1 / Ubar_1;
F2_2= 1 - (wu_2(1,1) / 9 + wv_2(1,1) / 12 + wu_2(2,2) / 3) / Ubar_2 / Ubar_2;
F2_3= 1 - (wu_3(1,1) / 9 + wv_3(1,1) / 12 + wu_3(2,2) / 3) / Ubar_3 / Ubar_3;
F2_4= 1 - (wu_4(1,1) / 9 + wv_4(1,1) / 12 + wu_4(2,2) / 3) / Ubar_4 / Ubar_4;
F2_5= 1 - (wu_5(1,1) / 9 + wv_5(1,1) / 12 + wu_5(2,2) / 3) / Ubar_5 / Ubar_5;
F2_6= 1 - (wu_6(1,1) / 9 + wv_6(1,1) / 12 + wu_6(2,2) / 3) / Ubar_6 / Ubar_6;

F3_1= 1 - (wu_1(1,1) / 9 + wv_1(1,1) / 3 + 2 * wu_1(2,2) / 3) / Ubar_1 / Ubar_1;
F3_2= 1 - (wu_2(1,1) / 9 + wv_2(1,1) / 3 + 2 * wu_2(2,2) / 3) / Ubar_2 / Ubar_2;
F3_3= 1 - (wu_3(1,1) / 9 + wv_3(1,1) / 3 + 2 * wu_3(2,2) / 3) / Ubar_3 / Ubar_3;
F3_4= 1 - (wu_4(1,1) / 9 + wv_4(1,1) / 3 + 2 * wu_4(2,2) / 3) / Ubar_4 / Ubar_4;
F3_5= 1 - (wu_5(1,1) / 9 + wv_5(1,1) / 3 + 2 * wu_5(2,2) / 3) / Ubar_5 / Ubar_5;
F3_6= 1 - (wu_6(1,1) / 9 + wv_6(1,1) / 3 + 2 * wu_6(2,2) / 3) / Ubar_6 / Ubar_6;

if length(Ustream_1) > 8191,specsize_1=8192;else,specsize_1=256;end;
if length(Ustream_2) > 8191,specsize_2=8192;else,specsize_2=256;end;
if length(Ustream_3) > 8191,specsize_3=8192;else,specsize_3=256;end;
if length(Ustream_4) > 8191,specsize_4=8192;else,specsize_4=256;end;
if length(Ustream_5) > 8191,specsize_5=8192;else,specsize_5=256;end;
if length(Ustream_6) > 8191,specsize_6=8192;else,specsize_6=256;end;

[Su_1,Fson]=psd2(detrend(Ustream_1),specsize_1,20);[Su_1,Fson]=specsmoo(Su_1,20);
[Su_2,Fson]=psd2(detrend(Ustream_2),specsize_2,20);[Su_2,Fson]=specsmoo(Su_2,20);
[Su_3,Fson]=psd2(detrend(Ustream_3),specsize_3,20);[Su_3,Fson]=specsmoo(Su_3,20);
[Su_4,Fson]=psd2(detrend(Ustream_4),specsize_4,20);[Su_4,Fson]=specsmoo(Su_4,20);
[Su_5,Fson]=psd2(detrend(Ustream_5),specsize_5,20);[Su_5,Fson]=specsmoo(Su_5,20);
[Su_6,Fson]=psd2(detrend(Ustream_6),specsize_6,20);[Su_6,Fson]=specsmoo(Su_6,20);

[Sv_1,Fson]=psd2(detrend(Vstream_1),specsize_1,20);[Sv_1,Fson]=specsmoo(Sv_1,20);
[Sv_2,Fson]=psd2(detrend(Vstream_2),specsize_2,20);[Sv_2,Fson]=specsmoo(Sv_2,20);
[Sv_3,Fson]=psd2(detrend(Vstream_3),specsize_3,20);[Sv_3,Fson]=specsmoo(Sv_3,20);
[Sv_4,Fson]=psd2(detrend(Vstream_4),specsize_4,20);[Sv_4,Fson]=specsmoo(Sv_4,20);
[Sv_5,Fson]=psd2(detrend(Vstream_5),specsize_5,20);[Sv_5,Fson]=specsmoo(Sv_5,20);
[Sv_6,Fson]=psd2(detrend(Vstream_6),specsize_6,20);[Sv_6,Fson]=specsmoo(Sv_6,20);

[Sw_1,Fson]=psd2(detrend(Wstream_1),specsize_1,20);[Sw_1,Fson]=specsmoo(Sw_1,20);
[Sw_2,Fson]=psd2(detrend(Wstream_2),specsize_2,20);[Sw_2,Fson]=specsmoo(Sw_2,20);
[Sw_3,Fson]=psd2(detrend(Wstream_3),specsize_3,20);[Sw_3,Fson]=specsmoo(Sw_3,20);
[Sw_4,Fson]=psd2(detrend(Wstream_4),specsize_4,20);[Sw_4,Fson]=specsmoo(Sw_4,20);
[Sw_5,Fson]=psd2(detrend(Wstream_5),specsize_5,20);[Sw_5,Fson]=specsmoo(Sw_5,20);
[Sw_6,Fson]=psd2(detrend(Wstream_6),specsize_6,20);[Sw_6,Fson]=specsmoo(Sw_6,20);

[Suj_1,Fson]=psd2(detrend(Uj_1),specsize_1,20);[Suj_1,Fson]=specsmoo(Suj_1,20);
[Suj_2,Fson]=psd2(detrend(Uj_2),specsize_2,20);[Suj_2,Fson]=specsmoo(Suj_2,20);
[Suj_3,Fson]=psd2(detrend(Uj_3),specsize_3,20);[Suj_3,Fson]=specsmoo(Suj_3,20);
[Suj_4,Fson]=psd2(detrend(Uj_4),specsize_4,20);[Suj_4,Fson]=specsmoo(Suj_4,20);
[Suj_5,Fson]=psd2(detrend(Uj_5),specsize_5,20);[Suj_5,Fson]=specsmoo(Suj_5,20);
[Suj_6,Fson]=psd2(detrend(Uj_6),specsize_6,20);[Suj_6,Fson]=specsmoo(Suj_6,20);

[Svj_1,Fson]=psd2(detrend(Vj_1),specsize_1,20);[Svj_1,Fson]=specsmoo(Svj_1,20);
[Svj_2,Fson]=psd2(detrend(Vj_2),specsize_2,20);[Svj_2,Fson]=specsmoo(Svj_2,20);
[Svj_3,Fson]=psd2(detrend(Vj_3),specsize_3,20);[Svj_3,Fson]=specsmoo(Svj_3,20);
[Svj_4,Fson]=psd2(detrend(Vj_4),specsize_4,20);[Svj_4,Fson]=specsmoo(Svj_4,20);
[Svj_5,Fson]=psd2(detrend(Vj_5),specsize_5,20);[Svj_5,Fson]=specsmoo(Svj_5,20);
[Svj_6,Fson]=psd2(detrend(Vj_6),specsize_6,20);[Svj_6,Fson]=specsmoo(Svj_6,20);

[Swj_1,Fson]=psd2(detrend(Wj_1),specsize_1,20);[Swj_1,Fson]=specsmoo(Swj_1,20);
[Swj_2,Fson]=psd2(detrend(Wj_2),specsize_2,20);[Swj_2,Fson]=specsmoo(Swj_2,20);
[Swj_3,Fson]=psd2(detrend(Wj_3),specsize_3,20);[Swj_3,Fson]=specsmoo(Swj_3,20);
[Swj_4,Fson]=psd2(detrend(Wj_4),specsize_4,20);[Swj_4,Fson]=specsmoo(Swj_4,20);
[Swj_5,Fson]=psd2(detrend(Wj_5),specsize_5,20);[Swj_5,Fson]=specsmoo(Swj_5,20);
[Swj_6,Fson]=psd2(detrend(Wj_6),specsize_6,20);[Swj_6,Fson]=specsmoo(Swj_6,20);

[St_1,Fson]=psd2(detrend(sst(1:firstq)),specsize_1,20);[St_1,Fson_1]=specsmoo(St_1,20);
[St_2,Fson]=psd2(detrend(sst(firstq+1:seconq)),specsize_2,20);[St_2,Fson]=specsmoo(St_2,20);
[St_3,Fson]=psd2(detrend(sst(seconq+1:thirdq)),specsize_3,20);[St_3,Fson]=specsmoo(St_3,20);
[St_4,Fson]=psd2(detrend(sst(thirdq+1:fourtq)),specsize_4,20);[St_4,Fson]=specsmoo(St_4,20);
[St_5,Fson]=psd2(detrend(sst(fourtq+1:fifthq)),specsize_5,20);[St_5,Fson]=specsmoo(St_5,20);
[St_6,Fson]=psd2(detrend(sst(fifthq+1:sixthq)),specsize_6,20);[St_6,Fson]=specsmoo(St_6,20);

[Sq_1,Fson]=psd2(detrend(abshum(1:firstq))/rho_1,specsize_1,20);[Sq_1,Fson]=specsmoo(Sq_1,20);          %g/kg
[Sq_2,Fson]=psd2(detrend(abshum(firstq+1:seconq))/rho_2,specsize_2,20);[Sq_2,Fson]=specsmoo(Sq_2,20);   %g/kg
[Sq_3,Fson]=psd2(detrend(abshum(seconq+1:thirdq))/rho_3,specsize_3,20);[Sq_3,Fson]=specsmoo(Sq_3,20);   %g/kg
[Sq_4,Fson]=psd2(detrend(abshum(thirdq+1:fourtq))/rho_4,specsize_4,20);[Sq_4,Fson]=specsmoo(Sq_4,20);   %g/kg
[Sq_5,Fson]=psd2(detrend(abshum(fourtq+1:fifthq))/rho_5,specsize_5,20);[Sq_5,Fson]=specsmoo(Sq_5,20);   %g/kg
[Sq_6,Fson]=psd2(detrend(abshum(fifthq+1:sixthq))/rho_6,specsize_6,20);[Sq_6,Fson]=specsmoo(Sq_6,20);   %g/kg

[So_1,Fson]=psd2(detrend(H2O(1:firstq))/rho_1,specsize_1,20);[So_1,Fson]=specsmoo(So_1,20);
[So_2,Fson]=psd2(detrend(H2O(firstq+1:seconq))/rho_2,specsize_2,20);[So_2,Fson]=specsmoo(So_2,20);
[So_3,Fson]=psd2(detrend(H2O(seconq+1:thirdq))/rho_3,specsize_3,20);[So_3,Fson]=specsmoo(So_3,20);
[So_4,Fson]=psd2(detrend(H2O(thirdq+1:fourtq))/rho_4,specsize_4,20);[So_4,Fson]=specsmoo(So_4,20);
[So_5,Fson]=psd2(detrend(H2O(fourtq+1:fifthq))/rho_5,specsize_5,20);[So_5,Fson]=specsmoo(So_5,20);
[So_6,Fson]=psd2(detrend(H2O(fifthq+1:sixthq))/rho_6,specsize_6,20);[So_6,Fson]=specsmoo(So_6,20);

[Sc_1,Fson]=psd2(detrend(CO2(1:firstq)),specsize_1,20);[Sc_1,Fson]=specsmoo(Sc_1,20);
[Sc_2,Fson]=psd2(detrend(CO2(firstq+1:seconq)),specsize_2,20);[Sc_2,Fson]=specsmoo(Sc_2,20);
[Sc_3,Fson]=psd2(detrend(CO2(seconq+1:thirdq)),specsize_3,20);[Sc_3,Fson]=specsmoo(Sc_3,20);
[Sc_4,Fson]=psd2(detrend(CO2(thirdq+1:fourtq)),specsize_4,20);[Sc_4,Fson]=specsmoo(Sc_4,20);
[Sc_5,Fson]=psd2(detrend(CO2(fourtq+1:fifthq)),specsize_5,20);[Sc_5,Fson]=specsmoo(Sc_5,20);
[Sc_6,Fson]=psd2(detrend(CO2(fifthq+1:sixthq)),specsize_6,20);[Sc_6,Fson]=specsmoo(Sc_6,20);

[Cuw_1,Fson]=csd2(detrend(Wstream_1),detrend(Ustream_1),specsize_1,20);[Cuw_1,Fson]=specsmoo(Cuw_1,20);
[Cuw_2,Fson]=csd2(detrend(Wstream_2),detrend(Ustream_2),specsize_2,20);[Cuw_2,Fson]=specsmoo(Cuw_2,20);
[Cuw_3,Fson]=csd2(detrend(Wstream_3),detrend(Ustream_3),specsize_3,20);[Cuw_3,Fson]=specsmoo(Cuw_3,20);
[Cuw_4,Fson]=csd2(detrend(Wstream_4),detrend(Ustream_4),specsize_4,20);[Cuw_4,Fson]=specsmoo(Cuw_4,20);
[Cuw_5,Fson]=csd2(detrend(Wstream_5),detrend(Ustream_5),specsize_5,20);[Cuw_5,Fson]=specsmoo(Cuw_5,20);
[Cuw_6,Fson]=csd2(detrend(Wstream_6),detrend(Ustream_6),specsize_6,20);[Cuw_6,Fson]=specsmoo(Cuw_6,20);

%for jjj=2:length(Cuw_1);Scuw_1(jjj)=(Cuw_1(jjj)+Cuw_1(jjj-1))/2.*(Fson(jjj)-Fson(jjj-1));end;
%disp(['SUM=  ',num2str(sum(Scuw_1))])
%clear Scuw_1 jjj
%for jjj=2:length(Cuw_1);Scuw_1(jjj)=(Cuw_1(jjj)+Cuw_1(jjj-1))/2.*(Fson(jjj)-Fson(jjj-1));end;
%disp(['SUMsmoo=  ',num2str(sum(Scuw_1))])

[Cvw_1,Fson]=csd2(detrend(Wstream_1),detrend(Vstream_1),specsize_1,20);[Cvw_1,Fson]=specsmoo(Cvw_1,20);
[Cvw_2,Fson]=csd2(detrend(Wstream_2),detrend(Vstream_2),specsize_2,20);[Cvw_2,Fson]=specsmoo(Cvw_2,20);
[Cvw_3,Fson]=csd2(detrend(Wstream_3),detrend(Vstream_3),specsize_3,20);[Cvw_3,Fson]=specsmoo(Cvw_3,20);
[Cvw_4,Fson]=csd2(detrend(Wstream_4),detrend(Vstream_4),specsize_4,20);[Cvw_4,Fson]=specsmoo(Cvw_4,20);
[Cvw_5,Fson]=csd2(detrend(Wstream_5),detrend(Vstream_5),specsize_5,20);[Cvw_5,Fson]=specsmoo(Cvw_5,20);
[Cvw_6,Fson]=csd2(detrend(Wstream_6),detrend(Vstream_6),specsize_6,20);[Cvw_6,Fson]=specsmoo(Cvw_6,20);

[Ctw_1,Fson]=csd2(detrend(Wstream_1),detrend(sst(1:firstq)),specsize_1,20);[Ctw_1,Fson]=specsmoo(Ctw_1,20);
[Ctw_2,Fson]=csd2(detrend(Wstream_2),detrend(sst(firstq+1:seconq)),specsize_2,20);[Ctw_2,Fson]=specsmoo(Ctw_2,20);
[Ctw_3,Fson]=csd2(detrend(Wstream_3),detrend(sst(seconq+1:thirdq)),specsize_3,20);[Ctw_3,Fson]=specsmoo(Ctw_3,20);
[Ctw_4,Fson]=csd2(detrend(Wstream_4),detrend(sst(thirdq+1:fourtq)),specsize_4,20);[Ctw_4,Fson]=specsmoo(Ctw_4,20);
[Ctw_5,Fson]=csd2(detrend(Wstream_5),detrend(sst(fourtq+1:fifthq)),specsize_5,20);[Ctw_5,Fson]=specsmoo(Ctw_5,20);
[Ctw_6,Fson]=csd2(detrend(Wstream_6),detrend(sst(fifthq+1:sixthq)),specsize_6,20);[Ctw_6,Fson]=specsmoo(Ctw_6,20);

[Cqw_1,Fson]=csd2(detrend(Wstream_1),detrend(abshum(1:firstq))/rho_1,specsize_1,20);[Cqw_1,Fson]=specsmoo(Cqw_1,20);           %g/kg
[Cqw_2,Fson]=csd2(detrend(Wstream_2),detrend(abshum(firstq+1:seconq))./rho_2,specsize_2,20);[Cqw_2,Fson]=specsmoo(Cqw_2,20);   %g/kg
[Cqw_3,Fson]=csd2(detrend(Wstream_3),detrend(abshum(seconq+1:thirdq))./rho_3,specsize_3,20);[Cqw_3,Fson]=specsmoo(Cqw_3,20);   %g/kg
[Cqw_4,Fson]=csd2(detrend(Wstream_4),detrend(abshum(thirdq+1:fourtq))./rho_4,specsize_4,20);[Cqw_4,Fson]=specsmoo(Cqw_4,20);   %g/kg
[Cqw_5,Fson]=csd2(detrend(Wstream_5),detrend(abshum(fourtq+1:fifthq))./rho_5,specsize_5,20);[Cqw_5,Fson]=specsmoo(Cqw_5,20);   %g/kg
[Cqw_6,Fson]=csd2(detrend(Wstream_6),detrend(abshum(fifthq+1:sixthq))./rho_6,specsize_6,20);[Cqw_6,Fson]=specsmoo(Cqw_6,20);   %g/kg

[Cow_1,Fson]=csd2(detrend(Wstream_1),detrend(H2O(1:firstq))/rho_1,specsize_1,20);[Cow_1,Fson]=specsmoo(Cow_1,20);
[Cow_2,Fson]=csd2(detrend(Wstream_2),detrend(H2O(firstq+1:seconq))/rho_2,specsize_2,20);[Cow_2,Fson]=specsmoo(Cow_2,20);
[Cow_3,Fson]=csd2(detrend(Wstream_3),detrend(H2O(seconq+1:thirdq))/rho_3,specsize_3,20);[Cow_3,Fson]=specsmoo(Cow_3,20);
[Cow_4,Fson]=csd2(detrend(Wstream_4),detrend(H2O(thirdq+1:fourtq))/rho_4,specsize_4,20);[Cow_4,Fson]=specsmoo(Cow_4,20);
[Cow_5,Fson]=csd2(detrend(Wstream_5),detrend(H2O(fourtq+1:fifthq))/rho_5,specsize_5,20);[Cow_5,Fson]=specsmoo(Cow_5,20);
[Cow_6,Fson]=csd2(detrend(Wstream_6),detrend(H2O(fifthq+1:sixthq))/rho_6,specsize_6,20);[Cow_6,Fson]=specsmoo(Cow_6,20);

[Ccw_1,Fson]=csd2(detrend(Wstream_1),detrend(CO2(1:firstq))/rho_6,specsize_1,20);[Ccw_1,Fson]=specsmoo(Ccw_1,20);
[Ccw_2,Fson]=csd2(detrend(Wstream_2),detrend(CO2(firstq+1:seconq))/rho_6,specsize_2,20);[Ccw_2,Fson]=specsmoo(Ccw_2,20);
[Ccw_3,Fson]=csd2(detrend(Wstream_3),detrend(CO2(seconq+1:thirdq))/rho_6,specsize_3,20);[Ccw_3,Fson]=specsmoo(Ccw_3,20);
[Ccw_4,Fson]=csd2(detrend(Wstream_4),detrend(CO2(thirdq+1:fourtq))/rho_6,specsize_4,20);[Ccw_4,Fson]=specsmoo(Ccw_4,20);
[Ccw_5,Fson]=csd2(detrend(Wstream_5),detrend(CO2(fourtq+1:fifthq))/rho_6,specsize_5,20);[Ccw_5,Fson]=specsmoo(Ccw_5,20);
[Ccw_6,Fson]=csd2(detrend(Wstream_6),detrend(CO2(fifthq+1:sixthq))/rho_6,specsize_6,20);[Ccw_6,Fson]=specsmoo(Ccw_6,20);

[Cuwj_1,Fson]=csd2(detrend(Wj_1),detrend(Uj_1),specsize_1,20);[Cuwj_1,Fson]=specsmoo(Cuwj_1,20);
[Cuwj_2,Fson]=csd2(detrend(Wj_2),detrend(Uj_2),specsize_2,20);[Cuwj_2,Fson]=specsmoo(Cuwj_2,20);
[Cuwj_3,Fson]=csd2(detrend(Wj_3),detrend(Uj_3),specsize_3,20);[Cuwj_3,Fson]=specsmoo(Cuwj_3,20);
[Cuwj_4,Fson]=csd2(detrend(Wj_4),detrend(Uj_4),specsize_4,20);[Cuwj_4,Fson]=specsmoo(Cuwj_4,20);
[Cuwj_5,Fson]=csd2(detrend(Wj_5),detrend(Uj_5),specsize_5,20);[Cuwj_5,Fson]=specsmoo(Cuwj_5,20);
[Cuwj_6,Fson]=csd2(detrend(Wj_6),detrend(Uj_6),specsize_6,20);[Cuwj_6,Fson]=specsmoo(Cuwj_6,20);

[Cvwj_1,Fson]=csd2(detrend(Wj_1),detrend(Vj_1),specsize_1,20);[Cvwj_1,Fson]=specsmoo(Cvwj_1,20);
[Cvwj_2,Fson]=csd2(detrend(Wj_2),detrend(Vj_2),specsize_2,20);[Cvwj_2,Fson]=specsmoo(Cvwj_2,20);
[Cvwj_3,Fson]=csd2(detrend(Wj_3),detrend(Vj_3),specsize_3,20);[Cvwj_3,Fson]=specsmoo(Cvwj_3,20);
[Cvwj_4,Fson]=csd2(detrend(Wj_4),detrend(Vj_4),specsize_4,20);[Cvwj_4,Fson]=specsmoo(Cvwj_4,20);
[Cvwj_5,Fson]=csd2(detrend(Wj_5),detrend(Vj_5),specsize_5,20);[Cvwj_5,Fson]=specsmoo(Cvwj_5,20);
[Cvwj_6,Fson]=csd2(detrend(Wj_6),detrend(Vj_6),specsize_6,20);[Cvwj_6,Fson]=specsmoo(Cvwj_6,20);

clear CO2 H2O
clear Wstream_1 Vstream_1 Ustream_1 Wstream_2 Vstream_2 Ustream_2 Wstream_3 Vstream_3 Ustream_3 Wstream_4 Vstream_4 Ustream_4 Wstream_5 Vstream_5 Ustream_5 Wstream_6 Vstream_6 Ustream_6
clear sst abshum
clear Uj_1 Vj_1 Wj_1 Uj_2 Vj_2 Wj_2 Uj_3 Vj_3 Wj_3 Uj_4 Vj_4 Wj_4 Uj_5 Vj_5 Wj_5 Uj_6 Vj_6 Wj_6
clear specsize_1 specsize_2 specsize_3 specsize_4 specsize_5 specsize_6

%subtract noise

%if length(Su_1)>5,sev=5;else;sev=1;end;
%Su_1=Su_1-median(Su_1(length(Su_1)-sev:length(Su_1)));
%Su_2=Su_2-median(Su_2(length(Su_2)-sev:length(Su_2)));
%Su_3=Su_3-median(Su_3(length(Su_3)-sev:length(Su_3)));
%Su_4=Su_4-median(Su_4(length(Su_4)-sev:length(Su_4)));
%Su_5=Su_5-median(Su_5(length(Su_5)-sev:length(Su_5)));
%Su_6=Su_6-median(Su_6(length(Su_6)-sev:length(Su_6)));

%if length(Sv_1)>5,sev=5;else;sev=1;end;
%Sv_1=Sv_1-median(Sv_1(length(Sv_1)-sev:length(Sv_1)));
%Sv_2=Sv_2-median(Sv_2(length(Sv_2)-sev:length(Sv_2)));
%Sv_3=Sv_3-median(Sv_3(length(Sv_3)-sev:length(Sv_3)));
%Sv_4=Sv_4-median(Sv_4(length(Sv_4)-sev:length(Sv_4)));
%Sv_5=Sv_5-median(Sv_5(length(Sv_5)-sev:length(Sv_5)));
%Sv_6=Sv_6-median(Sv_6(length(Sv_6)-sev:length(Sv_6)));

%if length(Sw_1)>5,sev=5;else;sev=1;end;
%Sw_1=Sw_1-median(Sw_1(length(Sw_1)-sev:length(Sw_1)));
%Sw_2=Sw_2-median(Sw_2(length(Sw_2)-sev:length(Sw_2)));
%Sw_3=Sw_3-median(Sw_3(length(Sw_3)-sev:length(Sw_3)));
%Sw_4=Sw_4-median(Sw_4(length(Sw_4)-sev:length(Sw_4)));
%Sw_5=Sw_5-median(Sw_5(length(Sw_5)-sev:length(Sw_5)));
%Sw_6=Sw_6-median(Sw_6(length(Sw_6)-sev:length(Sw_6)));

if length(St_1)>5,sev=5;else;sev=1;end;
St_1=St_1-median(St_1(length(St_1)-sev:length(St_1)));
St_2=St_2-median(St_2(length(St_2)-sev:length(St_2)));
St_3=St_3-median(St_3(length(St_3)-sev:length(St_3)));
St_4=St_4-median(St_4(length(St_4)-sev:length(St_4)));
St_5=St_5-median(St_5(length(St_5)-sev:length(St_5)));
St_6=St_6-median(St_6(length(St_6)-sev:length(St_6)));

if length(Sq_1)>5,sev=5;else;sev=1;end;
Sq_1=Sq_1-median(Sq_1(length(Sq_1)-sev:length(Sq_1)));
Sq_2=Sq_2-median(Sq_2(length(Sq_2)-sev:length(Sq_2)));
Sq_3=Sq_3-median(Sq_3(length(Sq_3)-sev:length(Sq_3)));
Sq_4=Sq_4-median(Sq_4(length(Sq_4)-sev:length(Sq_4)));
Sq_5=Sq_5-median(Sq_5(length(Sq_5)-sev:length(Sq_5)));
Sq_6=Sq_6-median(Sq_6(length(Sq_6)-sev:length(Sq_6)));

if length(So_1)>5,sev=5;else;sev=1;end;
So_1=So_1-median(So_1(length(So_1)-sev:length(So_1)));
So_2=So_2-median(So_2(length(So_2)-sev:length(So_2)));
So_3=So_3-median(So_3(length(So_3)-sev:length(So_3)));
So_4=So_4-median(So_4(length(So_4)-sev:length(So_4)));
So_5=So_5-median(So_5(length(So_5)-sev:length(So_5)));
So_6=So_6-median(So_6(length(So_6)-sev:length(So_6)));

if length(Sc_1)>5,sev=5;else;sev=1;end;
Sc_1=Sc_1-median(Sc_1(length(Sc_1)-sev:length(Sc_1)));
Sc_2=Sc_2-median(Sc_2(length(Sc_2)-sev:length(Sc_2)));
Sc_3=Sc_3-median(Sc_3(length(Sc_3)-sev:length(Sc_3)));
Sc_4=Sc_4-median(Sc_4(length(Sc_4)-sev:length(Sc_4)));
Sc_5=Sc_5-median(Sc_5(length(Sc_5)-sev:length(Sc_5)));
Sc_6=Sc_6-median(Sc_6(length(Sc_6)-sev:length(Sc_6)));

fminU=min(find(Fson>.8));
fminU=fminU-2;if fminU<1,fminU=1,end;
fmaxU=fminU+2;if fmaxU>length(Fson),fmaxU=length(Fson);end;

%cS=4*2/20;
cS=4;           %PSD2 and CSD2 should take care of the factor 2/20

Cu2_1_1=median(cS*((2*pi/Ustr_1)^(2/3))*Su_1(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cu2_2_1=median(cS*((2*pi/Ustr_2)^(2/3))*Su_2(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cu2_3_1=median(cS*((2*pi/Ustr_3)^(2/3))*Su_3(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cu2_4_1=median(cS*((2*pi/Ustr_4)^(2/3))*Su_4(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cu2_5_1=median(cS*((2*pi/Ustr_5)^(2/3))*Su_5(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cu2_6_1=median(cS*((2*pi/Ustr_6)^(2/3))*Su_6(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));

Cw2_1_1=median(cS*((2*pi/Ustr_1)^(2/3))*Sw_1(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cw2_2_1=median(cS*((2*pi/Ustr_2)^(2/3))*Sw_2(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cw2_3_1=median(cS*((2*pi/Ustr_3)^(2/3))*Sw_3(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cw2_4_1=median(cS*((2*pi/Ustr_4)^(2/3))*Sw_4(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cw2_5_1=median(cS*((2*pi/Ustr_5)^(2/3))*Sw_5(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cw2_6_1=median(cS*((2*pi/Ustr_6)^(2/3))*Sw_6(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));

fminT=min(find(Fson>.35));
fminT=fminT-2;if fminT<1,fminT=1,end;
fmaxT=fminT+2;if fmaxT>length(Fson),fmaxT=length(Fson);end;

Ct2_1_1=median(cS*((2*pi/Ustr_1)^(2/3))*St_1(fminT:fmaxT).*Fson(fminT:fmaxT).^(5/3));
Ct2_2_1=median(cS*((2*pi/Ustr_2)^(2/3))*St_2(fminT:fmaxT).*Fson(fminT:fmaxT).^(5/3));
Ct2_3_1=median(cS*((2*pi/Ustr_3)^(2/3))*St_3(fminT:fmaxT).*Fson(fminT:fmaxT).^(5/3));
Ct2_4_1=median(cS*((2*pi/Ustr_4)^(2/3))*St_4(fminT:fmaxT).*Fson(fminT:fmaxT).^(5/3));
Ct2_5_1=median(cS*((2*pi/Ustr_5)^(2/3))*St_5(fminT:fmaxT).*Fson(fminT:fmaxT).^(5/3));
Ct2_6_1=median(cS*((2*pi/Ustr_6)^(2/3))*St_6(fminT:fmaxT).*Fson(fminT:fmaxT).^(5/3));

fminO=min(find(Fson>0.7));
fminO=fminO-2;if fminO<1,fminO=1,end;
fmaxO=fminO+2;if fmaxO>length(Fson),fmaxO=length(Fson);end;

%cO=4*2/20;
cO=4;           %PSD2 and CSD2 should take care of the factor 2/20

Cq2_1_1=median(cO*((2*pi/Ustr_1)^(2/3))*Sq_1(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cq2_2_1=median(cO*((2*pi/Ustr_2)^(2/3))*Sq_2(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cq2_3_1=median(cO*((2*pi/Ustr_3)^(2/3))*Sq_3(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cq2_4_1=median(cO*((2*pi/Ustr_4)^(2/3))*Sq_4(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cq2_5_1=median(cO*((2*pi/Ustr_5)^(2/3))*Sq_5(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cq2_6_1=median(cO*((2*pi/Ustr_6)^(2/3))*Sq_6(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));

fminO=min(find(Fson>0.7));
fminO=fminO-2;if fminO<1,fminO=1,end;
fmaxO=fminO+2;if fmaxO>length(Fson),fmaxO=length(Fson);end;

%cO=4*2/20;
cO=4;           %PSD2 and CSD2 should take care of the factor 2/20


Co2_1_1=median(cO*((2*pi/Ustr_1)^(2/3))*So_1(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Co2_2_1=median(cO*((2*pi/Ustr_2)^(2/3))*So_2(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Co2_3_1=median(cO*((2*pi/Ustr_3)^(2/3))*So_3(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Co2_4_1=median(cO*((2*pi/Ustr_4)^(2/3))*So_4(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Co2_5_1=median(cO*((2*pi/Ustr_5)^(2/3))*So_5(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Co2_6_1=median(cO*((2*pi/Ustr_6)^(2/3))*So_6(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));

fminO=min(find(Fson>0.7));
fminO=fminO-2;if fminO<1,fminO=1,end;
fmaxO=fminO+2;if fmaxO>length(Fson),fmaxO=length(Fson);end;

%cO=4*2/20;
cO=4;           %PSD2 and CSD2 should take care of the factor 2/20


Cc2_1_1=median(cO*((2*pi/Ustr_1)^(2/3))*Sc_1(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cc2_2_1=median(cO*((2*pi/Ustr_2)^(2/3))*Sc_2(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cc2_3_1=median(cO*((2*pi/Ustr_3)^(2/3))*Sc_3(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cc2_4_1=median(cO*((2*pi/Ustr_4)^(2/3))*Sc_4(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cc2_5_1=median(cO*((2*pi/Ustr_5)^(2/3))*Sc_5(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));
Cc2_6_1=median(cO*((2*pi/Ustr_6)^(2/3))*Sc_6(fminO:fmaxO).*Fson(fminO:fmaxO).^(5/3));

%figure;loglog(Fson,Fson.*Su_1,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_1_1*((2*pi/Ustr_1).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 1 1');
%figure;loglog(Fson,Fson.*Su_2,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_2_1*((2*pi/Ustr_2).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 2 1');
%figure;loglog(Fson,Fson.*Su_3,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_3_1*((2*pi/Ustr_3).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 3 1');
%figure;loglog(Fson,Fson.*Su_4,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_4_1*((2*pi/Ustr_4).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 4 1');
%figure;loglog(Fson,Fson.*Su_5,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_5_1*((2*pi/Ustr_5).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 5 1');
%figure;loglog(Fson,Fson.*Su_6,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_6_1*((2*pi/Ustr_6).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 6 1');
%figure;loglog(Fson,Fson.*Sw_1,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_1_1*((2*pi/Ustr_1).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 1 1');
%figure;loglog(Fson,Fson.*Sw_2,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_2_1*((2*pi/Ustr_2).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 2 1');
%figure;loglog(Fson,Fson.*Sw_3,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_3_1*((2*pi/Ustr_3).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 3 1');
%figure;loglog(Fson,Fson.*Sw_4,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_4_1*((2*pi/Ustr_4).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 4 1');
%figure;loglog(Fson,Fson.*Sw_5,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_5_1*((2*pi/Ustr_5).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 5 1');
%figure;loglog(Fson,Fson.*Sw_6,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_6_1*((2*pi/Ustr_6).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 6 1');
%figure;loglog(Fson,Fson.*St_1,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Ct2_1_1*((2*pi/Ustr_1).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Ct^2 1 1');
%figure;loglog(Fson,Fson.*St_2,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Ct2_2_1*((2*pi/Ustr_2).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Ct^2 2 1');
%figure;loglog(Fson,Fson.*St_3,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Ct2_3_1*((2*pi/Ustr_3).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Ct^2 3 1');
%figure;loglog(Fson,Fson.*St_4,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Ct2_4_1*((2*pi/Ustr_4).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Ct^2 4 1');
%figure;loglog(Fson,Fson.*St_5,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Ct2_5_1*((2*pi/Ustr_5).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Ct^2 5 1');
%figure;loglog(Fson,Fson.*St_6,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Ct2_6_1*((2*pi/Ustr_6).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Ct^2 6 1');
%figure;loglog(Fson,Fson.*Sq_1,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cq2_1_1*((2*pi/Ustr_1).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cq^2 1 1');
%figure;loglog(Fson,Fson.*Sq_2,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cq2_2_1*((2*pi/Ustr_2).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cq^2 2 1');
%figure;loglog(Fson,Fson.*Sq_3,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cq2_3_1*((2*pi/Ustr_3).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cq^2 3 1');
%figure;loglog(Fson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6_1=ts_ib;qsid_6_1=qs_ib;osid_6_1=os_ib;csid_6_1=cs_ib;Lid_6_1=z_u/zet;

fminU=min(find(Fson>.6));if fminU<1,fminU=1,end;
fmaxU=max(find(Fson<3.5));if fmaxU>length(Fson),fmaxU=length(Fson);end;

%cS=4*2/20;
cS=4;           %PSD2 and CSD2 should take care of the factor 2/20


if fminU>fmaxU,fminU=fmaxU-4;end;

Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_1)^(2/3))*Su_1(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cu2_1_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_1)^(2/3))*Su_1(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_1)^(2/3))*Su_1(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cu2_1_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_2)^(2/3))*Su_2(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cu2_2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_2)^(2/3))*Su_2(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_2)^(2/3))*Su_2(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cu2_2_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_3)^(2/3))*Su_3(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cu2_3_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_3)^(2/3))*Su_3(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_3)^(2/3))*Su_3(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cu2_3_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_4)^(2/3))*Su_4(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cu2_4_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_4)^(2/3))*Su_4(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_4)^(2/3))*Su_4(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cu2_4_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_5)^(2/3))*Su_5(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cu2_5_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_5)^(2/3))*Su_5(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_5)^(2/3))*Su_5(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cu2_5_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_6)^(2/3))*Su_6(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cu2_6_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_6)^(2/3))*Su_6(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_6)^(2/3))*Su_6(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cu2_6_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_1)^(2/3))*Sw_1(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cw2_1_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_1)^(2/3))*Sw_1(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_1)^(2/3))*Sw_1(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cw2_1_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_2)^(2/3))*Sw_2(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cw2_2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_2)^(2/3))*Sw_2(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_2)^(2/3))*Sw_2(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cw2_2_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_3)^(2/3))*Sw_3(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cw2_3_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_3)^(2/3))*Sw_3(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_3)^(2/3))*Sw_3(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cw2_3_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_4)^(2/3))*Sw_4(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cw2_4_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_4)^(2/3))*Sw_4(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_4)^(2/3))*Sw_4(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cw2_4_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_5)^(2/3))*Sw_5(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cw2_5_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_5)^(2/3))*Sw_5(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_5)^(2/3))*Sw_5(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cw2_5_2=exp(Zpoly(5));
end;
Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ustr_6)^(2/3))*Sw_6(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cw2_6_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminU+plus+4==fmaxU,
         if fmaxU<4;fmaxU=4;end;
         Zpoly=polyfit(log(Fson(fmaxU-4:fmaxU)),log(cS*((2*pi/Ustr_6)^(2/3))*Sw_6(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ustr_6)^(2/3))*Sw_6(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cw2_6_2=exp(Zpoly(5));
end;

fminT=min(find(Fson>.35));if fminT<1,fminT=1,end;
fmaxT=max(find(Fson<3));if fmaxT>length(Fson),fmaxT=length(Fson);end;

%cS=4*2/20;
cS=4;           %PSD2 and CSD2 should take care of the factor 2/20

if fminT>fmaxT,fminT=fmaxT-4;end;

Zpoly=polyfit(log(Fson(fminT:fmaxT)),log(cS*((2*pi/Ustr_1)^(2/3))*St_1(fminT:fmaxT).*(Fson(fminT:fmaxT).^(2/3))),4);
if Zpoly(4)<0.25,
   Ct2_1_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminT+plus+4==fmaxT,
         if fmaxT<4;fmaxT=4;end;
         Zpoly=polyfit(log(Fson(fmaxT-4:fmaxT)),log(cS*((2*pi/Ustr_1)^(2/3))*St_1(fmaxT-4:fmaxT).*(Fson(fmaxT-4:fmaxT).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminT+plus:fmaxT)),log(cS*((2*pi/Ustr_1)^(2/3))*St_1(fminT+plus:fmaxT).*(Fson(fminT+plus:fmaxT).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Ct2_1_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminT:fmaxT)),log(cS*((2*pi/Ustr_2)^(2/3))*St_2(fminT:fmaxT).*(Fson(fminT:fmaxT).^(2/3))),4);
if Zpoly(4)<0.25,
   Ct2_2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminT+plus+4==fmaxT,
         if fmaxT<4;fmaxT=4;end;
         Zpoly=polyfit(log(Fson(fmaxT-4:fmaxT)),log(cS*((2*pi/Ustr_2)^(2/3))*St_2(fmaxT-4:fmaxT).*(Fson(fmaxT-4:fmaxT).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminT+plus:fmaxT)),log(cS*((2*pi/Ustr_2)^(2/3))*St_2(fminT+plus:fmaxT).*(Fson(fminT+plus:fmaxT).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Ct2_2_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminT:fmaxT)),log(cS*((2*pi/Ustr_3)^(2/3))*St_3(fminT:fmaxT).*(Fson(fminT:fmaxT).^(2/3))),4);
if Zpoly(4)<0.25,
   Ct2_3_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminT+plus+4==fmaxT,
         if fmaxT<4;fmaxT=4;end;
         Zpoly=polyfit(log(Fson(fmaxT-4:fmaxT)),log(cS*((2*pi/Ustr_3)^(2/3))*St_3(fmaxT-4:fmaxT).*(Fson(fmaxT-4:fmaxT).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminT+plus:fmaxT)),log(cS*((2*pi/Ustr_3)^(2/3))*St_3(fminT+plus:fmaxT).*(Fson(fminT+plus:fmaxT).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Ct2_3_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminT:fmaxT)),log(cS*((2*pi/Ustr_4)^(2/3))*St_4(fminT:fmaxT).*(Fson(fminT:fmaxT).^(2/3))),4);
if Zpoly(4)<0.25,
   Ct2_4_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminT+plus+4==fmaxT,
         if fmaxT<4;fmaxT=4;end;
         Zpoly=polyfit(log(Fson(fmaxT-4:fmaxT)),log(cS*((2*pi/Ustr_4)^(2/3))*St_4(fmaxT-4:fmaxT).*(Fson(fmaxT-4:fmaxT).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminT+plus:fmaxT)),log(cS*((2*pi/Ustr_4)^(2/3))*St_4(fminT+plus:fmaxT).*(Fson(fminT+plus:fmaxT).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Ct2_4_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminT:fmaxT)),log(cS*((2*pi/Ustr_5)^(2/3))*St_5(fminT:fmaxT).*(Fson(fminT:fmaxT).^(2/3))),4);
if Zpoly(4)<0.25,
   Ct2_5_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminT+plus+4==fmaxT,
         if fmaxT<4;fmaxT=4;end;
         Zpoly=polyfit(log(Fson(fmaxT-4:fmaxT)),log(cS*((2*pi/Ustr_5)^(2/3))*St_5(fmaxT-4:fmaxT).*(Fson(fmaxT-4:fmaxT).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminT+plus:fmaxT)),log(cS*((2*pi/Ustr_5)^(2/3))*St_5(fminT+plus:fmaxT).*(Fson(fminT+plus:fmaxT).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Ct2_5_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminT:fmaxT)),log(cS*((2*pi/Ustr_6)^(2/3))*St_6(fminT:fmaxT).*(Fson(fminT:fmaxT).^(2/3))),4);
if Zpoly(4)<0.25,
   Ct2_6_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminT+plus+4==fmaxT,
         if fmaxT<4;fmaxT=4;end;
         Zpoly=polyfit(log(Fson(fmaxT-4:fmaxT)),log(cS*((2*pi/Ustr_6)^(2/3))*St_6(fmaxT-4:fmaxT).*(Fson(fmaxT-4:fmaxT).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminT+plus:fmaxT)),log(cS*((2*pi/Ustr_6)^(2/3))*St_6(fminT+plus:fmaxT).*(Fson(fminT+plus:fmaxT).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Ct2_6_2=exp(Zpoly(5));
end;

fminO=min(find(Fson>0.7));if fminO<1,fminO=1,end;
fmaxO=max(find(Fson<3.6));if fmaxO>length(Fson),fmaxO=length(Fson);end;

%cO=4*2/20;
cO=4;           %PSD2 and CSD2 should take care of the factor 2/20

if fminO>fmaxO,fminO=fmaxO-4;end

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*Sq_1(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cq2_1_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*Sq_1(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*Sq_1(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cq2_1_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*Sq_2(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cq2_2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*Sq_2(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*Sq_2(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cq2_2_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*Sq_3(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cq2_3_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*Sq_3(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*Sq_3(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cq2_3_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*Sq_4(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cq2_4_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*Sq_4(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*Sq_4(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cq2_4_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*Sq_5(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cq2_5_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*Sq_5(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*Sq_5(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cq2_5_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*Sq_6(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cq2_6_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*Sq_6(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*Sq_6(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cq2_6_2=exp(Zpoly(5));
end;

fminO=min(find(Fson>0.7));if fminO<1,fminO=1,end;
fmaxO=max(find(Fson<3.6));if fmaxO>length(Fson),fmaxO=length(Fson);end;

%cO=4*2/20;
cO=4;           %PSD2 and CSD2 should take care of the factor 2/20

if fminO>fmaxO,fminO=fmaxO-4;end

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*So_1(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Co2_1_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*So_1(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*So_1(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Co2_1_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*So_2(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Co2_2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*So_2(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*So_2(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Co2_2_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*So_3(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Co2_3_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*So_3(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*So_3(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Co2_3_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*So_4(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Co2_4_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*So_4(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*So_4(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Co2_4_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*So_5(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Co2_5_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*So_5(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*So_5(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Co2_5_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*So_6(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Co2_6_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*So_6(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*So_6(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Co2_6_2=exp(Zpoly(5));
end;

fminO=min(find(Fson>0.7));if fminO<1,fminO=1,end;
fmaxO=max(find(Fson<3.6));if fmaxO>length(Fson),fmaxO=length(Fson);end;

%cO=4*2/20;
cO=4;           %PSD2 and CSD2 should take care of the factor 2/20

if fminO>fmaxO,fminO=fmaxO-4;end

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*Sc_1(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cc2_1_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*Sc_1(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_1)^(2/3))*Sc_1(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cc2_1_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*Sc_2(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cc2_2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*Sc_2(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_2)^(2/3))*Sc_2(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cc2_2_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*Sc_3(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cc2_3_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*Sc_3(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_3)^(2/3))*Sc_3(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cc2_3_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*Sc_4(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cc2_4_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*Sc_4(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_4)^(2/3))*Sc_4(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cc2_4_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*Sc_5(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cc2_5_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*Sc_5(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_5)^(2/3))*Sc_5(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cc2_5_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminO:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*Sc_6(fminO:fmaxO).*(Fson(fminO:fmaxO).^(2/3))),4);
if Zpoly(4)<0.25,
   Cc2_6_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminO+plus+4==fmaxO,
         if fmaxO<4;fmaxO=4;end;
         Zpoly=polyfit(log(Fson(fmaxO-4:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*Sc_6(fmaxO-4:fmaxO).*(Fson(fmaxO-4:fmaxO).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminO+plus:fmaxO)),log(cO*((2*pi/Ustr_6)^(2/3))*Sc_6(fminO+plus:fmaxO).*(Fson(fminO+plus:fmaxO).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cc2_6_2=exp(Zpoly(5));
end;

%figure;loglog(Fson,Fson.*Su_1,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_1_2*((2*pi/Ustr_1).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 1 2');
%figure;loglog(Fson,Fson.*Su_2,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_2_2*((2*pi/Ustr_2).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 2 2');
%figure;loglog(Fson,Fson.*Su_3,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_3_2*((2*pi/Ustr_3).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 3 2');
%figure;loglog(Fson,Fson.*Su_4,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_4_2*((2*pi/Ustr_4).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 4 2');
%figure;loglog(Fson,Fson.*Su_5,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_5_2*((2*pi/Ustr_5).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 5 2');
%figure;loglog(Fson,Fson.*Su_6,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_6_2*((2*pi/Ustr_6).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2 6 2');
%figure;loglog(Fson,Fson.*Sw_1,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_1_2*((2*pi/Ustr_1).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 1 2');
%figure;loglog(Fson,Fson.*Sw_2,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_2_2*((2*pi/Ustr_2).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 2 2');
%figure;loglog(Fson,Fson.*Sw_3,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_3_2*((2*pi/Ustr_3).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 3 2');
%figure;loglog(Fson,Fson.*Sw_4,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_4_2*((2*pi/Ustr_4).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 4 2');
%figure;loglog(Fson,Fson.*Sw_5,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_5_2*((2*pi/Ustr_5).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 5 2');
%figure;loglog(Fson,Fson.*Sw_6,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_6_2*((2*pi/Ustr_6).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2 6 2');
%figure;loglog(Fson,Fson.*St_1,Fson(fminT:fmaxT),Fson(fminT:fmaxT).*Ct2_1_2*((2*pi/Ustr_1).^(-2/3))./cS.*Fson(fminT:fmaxT).^(-5/3));title('Ct^2 1 2');
%figure;loglog(Fson,Fson.*St_2,Fson(fminT:fmaxT),Fson(fminT:fmaxT).*Ct2_2_2*((2*pi/Ustr_2).^(-2/3))./cS.*Fson(fminT:fmaxT).^(-5/3));title('Ct^2 2 2');
%figure;loglog(Fson,Fson.*St_3,Fson(fminT:fmaxT),Fson(fminT:fmaxT).*Ct2_3_2*((2*pi/Ustr_3).^(-2/3))./cS.*Fson(fminT:fmaxT).^(-5/3));title('Ct^2 3 2');
%figure;loglog(Fson,Fson.*St_4,Fson(fminT:fmaxT),Fson(fminT:fmaxT).*Ct2_4_2*((2*pi/Ustr_4).^(-2/3))./cS.*Fson(fminT:fmaxT).^(-5/3));title('Ct^2 4 2');
%figure;loglog(Fson,Fson.*St_5,Fson(fminT:fmaxT),Fson(fminT:fmaxT).*Ct2_5_2*((2*pi/Ustr_5).^(-2/3))./cS.*Fson(fminT:fmaxT).^(-5/3));title('Ct^2 5 2');
%figure;loglog(Fson,Fson.*St_6,Fson(fminT:fmaxT),Fson(fminT:fmaxT).*Ct2_6_2*((2*pi/Ustr_6).^(-2/3))./cS.*Fson(fminT:fmaxT).^(-5/3));title('Ct^2 6 2');
%figure;loglog(Fson,Fson.*Sq_1,Fson(fminO:fmaxO),Fson(fminO:fmaxO).*Cq2_1_2*((2*pi/Ustr_1).^(-2/3))./cO.*Fson(fminO:fmaxO).^(-5/3));title('Cq^2 1 2');
%figure;loglog(Fson,Fson.*Sq_2,Fson(fminO:fmaxO),Fson(fminO:fmaxO).*Cq2_2_2*((2*pi/Ustr_2).^(-2/3))./cO.*Fson(fminO:fmaxO).^(-5/3));title('Cq^2 2 2');
%figure;loglog(Fson,Fson.*Sq_3,Fson(fminO:fmaxO),Fson(fminO:fmaxO).*Cq2_3_2*((2*pi/Ustr_3).^(-2/3))./cO.*Fson(fminO:fmaxO).^(-5/3));title('Cq^2 3 2');
%figure;loglog(Fson,Fson.*Sq_4,Fson(fminO:fmaxO),Fson(fminO:fmaxO).*Cq2_4_2*((2*pi/Ustr_4).^(-2/3))./cO.*Fson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ar_1 Tbar_1 Tsea_1 Qbar_1 wu_1(1,2) wv_1(1,2) wt_1(1,2) wa_1(1,2) wh_1(1,2) rho_1 stdC_1 stdA_1 medC_1 medA_1 Ss_1 Sc_1 Sp_1 rain_1
%     y_2 Ubar_2 Tbar_2 Tsea_2 Qbar_2 wu_2(1,2) wv_2(1,2) wt_2(1,2) wa_2(1,2) wh_2(1,2) rho_2 stdC_2 stdA_2 medC_2 medA_2 Ss_2 Sc_2 Sp_2 rain_2
%     y_3 Ubar_3 Tbar_3 Tsea_3 Qbar_3 wu_3(1,2) wv_3(1,2) wt_3(1,2) wa_3(1,2) wh_3(1,2) rho_3 stdC_3 stdA_3 medC_3 medA_3 Ss_3 Sc_3 Sp_3 rain_3
%     y_4 Ubar_4 Tbar_4 Tsea_4 Qbar_4 wu_4(1,2) wv_4(1,2) wt_4(1,2) wa_4(1,2) wh_4(1,2) rho_4 stdC_4 stdA_4 medC_4 medA_4 Ss_4 Sc_4 Sp_4 rain_4
%     y_5 Ubar_5 Tbar_5 Tsea_5 Qbar_5 wu_5(1,2) wv_5(1,2) wt_5(1,2) wa_5(1,2) wh_5(1,2) rho_5 stdC_5 stdA_5 medC_5 medA_5 Ss_5 Sc_5 Sp_5 rain_5
%     y_6 Ubar_6 Tbar_6 Tsea_6 Qbar_6 wu_6(1,2) wv_6(1,2) wt_6(1,2) wa_6(1,2) wh_6(1,2) rho_6 stdC_6 stdA_6 medC_6 medA_6 Ss_6 Sc_6 Sp_6 rain_6];

newview=[ddd+hhh/24+00/24/60 xship_1 mean_wind_1 min_wind_1 max_wind_1 std_wind_1 mean_dir_1 min_dir_1 max_dir_1 std_dir_1 Ustr_1 Un_1 Ue_1 Twindir_1 Reldir_1 alpha_1 beta_1 Tseasnake_1 Tbarv_1 RHv_1 RH_1 Qbarv_1 Qbar_1 Qseasnake_1 rho_1 yship_1 ysnake_1 std_Rl_1 std_Rs_1 mean_head_1 std_head_1 min_head_1 max_head_1 mean_sog_1 std_sog_1 min_sog_1 max_sog_1 mean_cog_1 std_cog_1 min_cog_1 max_cog_1 mean_gpscog_1 std_gpscog_1 min_gpscog_1 max_gpscog_1 mean_gpsspeed_1 min_gpsspeed_1 max_gpsspeed_1 mean_gyro_1 std_gyro_1 min_gyro_1 max_gyro_1 wu_1(1,2) wuj_1(1,2) wv_1(1,2) wvj_1(1,2) wt_1(1,2) wtd_1(1,2) wtj_1(1,2) wa_1(1,2) waj_1(1,2) wh_1(1,2) wc_1(1,2) wu_1(1,1) wv_1(1,1) wu_1(2,2) wuj_1(1,1) wvj_1(1,1) wuj_1(2,2) wt_1(2,2) wa_1(2,2) wh_1(2,2) wc_1(2,2) mean_CO2_1 med_CO2_1 std_CO2_1 mean_H2Oa_1 med_H2Oa_1 std_H2Oa_1 mean_H2Op_1 med_H2Op_1 std_H2Op_1 mean_H2Ow_1 med_H2Ow_1 std_H2Ow_1 std_absorb_1 std_clear_1 med_clear_1 med_absorb_1 ...
   Sp1_1 Sp2_1 Sp3_1 Ssin_1 Scos_1 Cu2_1_1 Cu2_1_2 Cw2_1_1 Cw2_1_2 Ct2_1_1 Ct2_1_2 Cq2_1_1 Cq2_1_2 Co2_1_1 Co2_1_2 Cc2_1_1 Cc2_1_2 usid_1_1 usid_1_2 tsid_1_1 tsid_1_2 qsid_1_1 qsid_1_2 osid_1_1 osid_1_2 csid_1_1 csid_1_2 Lid_1_1 Lid_1_2 Lon_1 Lat_1 Ubarj_1
   ddd+hhh/24+10/24/60 xship_2 mean_wind_2 min_wind_2 max_wind_2 std_wind_2 mean_dir_2 min_dir_2 max_dir_2 std_dir_2 Ustr_2 Un_2 Ue_2 Twindir_2 Reldir_2 alpha_2 beta_2 Tseasnake_2 Tbarv_2 RHv_2 RH_2 Qbarv_2 Qbar_2 Qseasnake_2 rho_2 yship_2 ysnake_2 std_Rl_2 std_Rs_2 mean_head_2 std_head_2 min_head_2 max_head_2 mean_sog_2 std_sog_2 min_sog_2 max_sog_2 mean_cog_2 std_cog_2 min_cog_2 max_cog_2 mean_gpscog_2 std_gpscog_2 min_gpscog_2 max_gpscog_2 mean_gpsspeed_2 min_gpsspeed_2 max_gpsspeed_2 mean_gyro_2 std_gyro_2 min_gyro_2 max_gyro_2 wu_2(1,2) wuj_2(1,2) wv_2(1,2) wvj_2(1,2) wt_2(1,2) wtd_2(1,2) wtj_2(1,2) wa_2(1,2) waj_2(1,2) wh_2(1,2) wc_2(1,2) wu_2(1,1) wv_2(1,1) wu_2(2,2) wuj_2(1,1) wvj_2(1,1) wuj_2(2,2) wt_2(2,2) wa_2(2,2) wh_2(2,2) wc_2(2,2) mean_CO2_2 med_CO2_2 std_CO2_2 mean_H2Oa_2 med_H2Oa_2 std_H2Oa_2 mean_H2Op_2 med_H2Op_2 std_H2Op_2 mean_H2Ow_2 med_H2Ow_2 std_H2Ow_2 std_absorb_2 std_clear_2 med_clear_2 med_absorb_2 ...
   Sp1_2 Sp2_2 Sp3_2 Ssin_2 Scos_2 Cu2_2_1 Cu2_2_2 Cw2_2_1 Cw2_2_2 Ct2_2_1 Ct2_2_2 Cq2_2_1 Cq2_2_2 Co2_2_1 Co2_2_2 Cc2_2_1 Cc2_2_2 usid_2_1 usid_2_2 tsid_2_1 tsid_2_2 qsid_2_1 qsid_2_2 osid_2_1 osid_2_2 csid_2_1 csid_2_2 Lid_2_1 Lid_2_2 Lon_2 Lat_2 Ubarj_2
   ddd+hhh/24+20/24/60 xship_3 mean_wind_3 min_wind_3 max_wind_3 std_wind_3 mean_dir_3 min_dir_3 max_dir_3 std_dir_3 Ustr_3 Un_3 Ue_3 Twindir_3 Reldir_3 alpha_3 beta_3 Tseasnake_3 Tbarv_3 RHv_3 RH_3 Qbarv_3 Qbar_3 Qseasnake_3 rho_3 yship_3 ysnake_3 std_Rl_3 std_Rs_3 mean_head_3 std_head_3 min_head_3 max_head_3 mean_sog_3 std_sog_3 min_sog_3 max_sog_3 mean_cog_3 std_cog_3 min_cog_3 max_cog_3 mean_gpscog_3 std_gpscog_3 min_gpscog_3 max_gpscog_3 mean_gpsspeed_3 min_gpsspeed_3 max_gpsspeed_3 mean_gyro_3 std_gyro_3 min_gyro_3 max_gyro_3 wu_3(1,2) wuj_3(1,2) wv_3(1,2) wvj_3(1,2) wt_3(1,2) wtd_3(1,2) wtj_3(1,2) wa_3(1,2) waj_3(1,2) wh_3(1,2) wc_3(1,2) wu_3(1,1) wv_3(1,1) wu_3(2,2) wuj_3(1,1) wvj_3(1,1) wuj_3(2,2) wt_3(2,2) wa_3(2,2) wh_3(2,2) wc_3(2,2) mean_CO2_3 med_CO2_3 std_CO2_3 mean_H2Oa_3 med_H2Oa_3 std_H2Oa_3 mean_H2Op_3 med_H2Op_3 std_H2Op_3 mean_H2Ow_3 med_H2Ow_3 std_H2Ow_3 std_absorb_3 std_clear_3 med_clear_3 med_absorb_3 ...
   Sp1_3 Sp2_3 Sp3_3 Ssin_3 Scos_3 Cu2_3_1 Cu2_3_2 Cw2_3_1 Cw2_3_2 Ct2_3_1 Ct2_3_2 Cq2_3_1 Cq2_3_2 Co2_3_1 Co2_3_2 Cc2_3_1 Cc2_3_2 usid_3_1 usid_3_2 tsid_3_1 tsid_3_2 qsid_3_1 qsid_3_2 osid_3_1 osid_3_2 csid_3_1 csid_3_2 Lid_3_1 Lid_3_2 Lon_3 Lat_3 Ubarj_3
   ddd+hhh/24+30/24/60 xship_4 mean_wind_4 min_wind_4 max_wind_4 std_wind_4 mean_dir_4 min_dir_4 max_dir_4 std_dir_4 Ustr_4 Un_4 Ue_4 Twindir_4 Reldir_4 alpha_4 beta_4 Tseasnake_4 Tbarv_4 RHv_4 RH_4 Qbarv_4 Qbar_4 Qseasnake_4 rho_4 yship_4 ysnake_4 std_Rl_4 std_Rs_4 mean_head_4 std_head_4 min_head_4 max_head_4 mean_sog_4 std_sog_4 min_sog_4 max_sog_4 mean_cog_4 std_cog_4 min_cog_4 max_cog_4 mean_gpscog_4 std_gpscog_4 min_gpscog_4 max_gpscog_4 mean_gpsspeed_4 min_gpsspeed_4 max_gpsspeed_4 mean_gyro_4 std_gyro_4 min_gyro_4 max_gyro_4 wu_4(1,2) wuj_4(1,2) wv_4(1,2) wvj_4(1,2) wt_4(1,2) wtd_4(1,2) wtj_4(1,2) wa_4(1,2) waj_4(1,2) wh_4(1,2) wc_4(1,2) wu_4(1,1) wv_4(1,1) wu_4(2,2) wuj_4(1,1) wvj_4(1,1) wuj_4(2,2) wt_4(2,2) wa_4(2,2) wh_4(2,2) wc_4(2,2) mean_CO2_4 med_CO2_4 std_CO2_4 mean_H2Oa_4 med_H2Oa_4 std_H2Oa_4 mean_H2Op_4 med_H2Op_4 std_H2Op_4 mean_H2Ow_4 med_H2Ow_4 std_H2Ow_4 std_absorb_4 std_clear_4 med_clear_4 med_absorb_4 ...
   Sp1_4 Sp2_4 Sp3_4 Ssin_4 Scos_4 Cu2_4_1 Cu2_4_2 Cw2_4_1 Cw2_4_2 Ct2_4_1 Ct2_4_2 Cq2_4_1 Cq2_4_2 Co2_4_1 Co2_4_2 Cc2_4_1 Cc2_4_2 usid_4_1 usid_4_2 tsid_4_1 tsid_4_2 qsid_4_1 qsid_4_2 osid_4_1 osid_4_2 csid_4_1 csid_4_2 Lid_4_1 Lid_4_2 Lon_4 Lat_4 Ubarj_4
   ddd+hhh/24+40/24/60 xship_5 mean_wind_5 min_wind_5 max_wind_5 std_wind_5 mean_dir_5 min_dir_5 max_dir_5 std_dir_5 Ustr_5 Un_5 Ue_5 Twindir_5 Reldir_5 alpha_5 beta_5 Tseasnake_5 Tbarv_5 RHv_5 RH_5 Qbarv_5 Qbar_5 Qseasnake_5 rho_5 yship_5 ysnake_5 std_Rl_5 std_Rs_5 mean_head_5 std_head_5 min_head_5 max_head_5 mean_sog_5 std_sog_5 min_sog_5 max_sog_5 mean_cog_5 std_cog_5 min_cog_5 max_cog_5 mean_gpscog_5 std_gpscog_5 min_gpscog_5 max_gpscog_5 mean_gpsspeed_5 min_gpsspeed_5 max_gpsspeed_5 mean_gyro_5 std_gyro_5 min_gyro_5 max_gyro_5 wu_5(1,2) wuj_5(1,2) wv_5(1,2) wvj_5(1,2) wt_5(1,2) wtd_5(1,2) wtj_5(1,2) wa_5(1,2) waj_5(1,2) wh_5(1,2) wc_5(1,2) wu_5(1,1) wv_5(1,1) wu_5(2,2) wuj_5(1,1) wvj_5(1,1) wuj_5(2,2) wt_5(2,2) wa_5(2,2) wh_5(2,2) wc_5(2,2) mean_CO2_5 med_CO2_5 std_CO2_5 mean_H2Oa_5 med_H2Oa_5 std_H2Oa_5 mean_H2Op_5 med_H2Op_5 std_H2Op_5 mean_H2Ow_5 med_H2Ow_5 std_H2Ow_5 std_absorb_5 std_clear_5 med_clear_5 med_absorb_5 ...
   Sp1_5 Sp2_5 Sp3_5 Ssin_5 Scos_5 Cu2_5_1 Cu2_5_2 Cw2_5_1 Cw2_5_2 Ct2_5_1 Ct2_5_2 Cq2_5_1 Cq2_5_2 Co2_5_1 Co2_5_2 Cc2_5_1 Cc2_5_2 usid_5_1 usid_5_2 tsid_5_1 tsid_5_2 qsid_5_1 qsid_5_2 osid_5_1 osid_5_2 csid_5_1 csid_5_2 Lid_5_1 Lid_5_2 Lon_5 Lat_5 Ubarj_5
   ddd+hhh/24+50/24/60 xship_6 mean_wind_6 min_wind_6 max_wind_6 std_wind_6 mean_dir_6 min_dir_6 max_dir_6 std_dir_6 Ustr_6 Un_6 Ue_6 Twindir_6 Reldir_6 alpha_6 beta_6 Tseasnake_6 Tbarv_6 RHv_6 RH_6 Qbarv_6 Qbar_6 Qseasnake_6 rho_6 yship_6 ysnake_6 std_Rl_6 std_Rs_6 mean_head_6 std_head_6 min_head_6 max_head_6 mean_sog_6 std_sog_6 min_sog_6 max_sog_6 mean_cog_6 std_cog_6 min_cog_6 max_cog_6 mean_gpscog_6 std_gpscog_6 min_gpscog_6 max_gpscog_6 mean_gpsspeed_6 min_gpsspeed_6 max_gpsspeed_6 mean_gyro_6 std_gyro_6 min_gyro_6 max_gyro_6 wu_6(1,2) wuj_6(1,2) wv_6(1,2) wvj_6(1,2) wt_6(1,2) wtd_6(1,2) wtj_6(1,2) wa_6(1,2) waj_6(1,2) wh_6(1,2) wc_6(1,2) wu_6(1,1) wv_6(1,1) wu_6(2,2) wuj_6(1,1) wvj_6(1,1) wuj_6(2,2) wt_6(2,2) wa_6(2,2) wh_6(2,2) wc_6(2,2) mean_CO2_6 med_CO2_6 std_CO2_6 mean_H2Oa_6 med_H2Oa_6 std_H2Oa_6 mean_H2Op_6 med_H2Op_6 std_H2Op_6 mean_H2Ow_6 med_H2Ow_6 std_H2Ow_6 std_absorb_6 std_clear_6 med_clear_6 med_absorb_6 ...
   Sp1_6 Sp2_6 Sp3_6 Ssin_6 Scos_6 Cu2_6_1 Cu2_6_2 Cw2_6_1 Cw2_6_2 Ct2_6_1 Ct2_6_2 Cq2_6_1 Cq2_6_2 Co2_6_1 Co2_6_2 Cc2_6_1 Cc2_6_2 usid_6_1 usid_6_2 tsid_6_1 tsid_6_2 qsid_6_1 qsid_6_2 osid_6_1 osid_6_2 csid_6_1 csid_6_2 Lid_6_1 Lid_6_2 Lon_6 Lat_6 Ubarj_6];

%disp(['uw=  ',num2str(wu_1(1,2))])
%disp(num2str(length(Fson)))

specview=[ddd+hhh/24+00/24/60 Fson Su_1 Sv_1 Sw_1 St_1 Sq_1 So_1 Sc_1 Suj_1 Svj_1 Swj_1 Cuw_1 Cvw_1 Ctw_1 Cqw_1 Cow_1 Ccw_1 Cuwj_1 Cvwj_1
          ddd+hhh/24+10/24/60 Fson Su_2 Sv_2 Sw_2 St_2 Sq_2 So_2 Sc_2 Suj_2 Svj_2 Swj_2 Cuw_2 Cvw_2 Ctw_2 Cqw_2 Cow_2 Ccw_2 Cuwj_2 Cvwj_2
          ddd+hhh/24+20/24/60 Fson Su_3 Sv_3 Sw_3 St_3 Sq_3 So_3 Sc_3 Suj_3 Svj_3 Swj_3 Cuw_3 Cvw_3 Ctw_3 Cqw_3 Cow_3 Ccw_3 Cuwj_3 Cvwj_3
          ddd+hhh/24+30/24/60 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_4 Qsea_5 Qsea_6
clear RHv Solar1 Solar2 T TT Tairv Tsea Tsea_snake Tv Us alphau c
clear Uid_1 Uid_2 Uid_3 Uid_4 Uid_5 Uid_6 c_coeff cog daytest fmax g
clear head hourtest iii lat long qs0 medA_1 medA_2 medA_3 medA_4 medA_5 medA_6
clear stdA_1 stdA_2 stdA_3 stdA_4 stdA_5 stdA_6 qs_ib rho sog ts0 u_id us0
clear us_ib vkon x zet z zi x_1 x_2 x_3 x_4 x_5 x_6 zq zt zu zzz 
clear Qs Qs_10 RH
clear F1_1 F1_2 F1_3 F1_4 F1_5 F1_6
clear F2_1 F2_2 F2_3 F2_4 F2_5 F2_6
clear F3_1 F3_2 F3_3 F3_4 F3_5 F3_6
