disp('gaspr01.m')

F1= 1 - (wu(1,1) / 9 + 2 * wv(1,1) / 3 + 2 * wu(2,2) / 3) / Ubarcorr / Ubarcorr;
F2= 1 - (wu(1,1) / 9 + wv(1,1) / 12 + wu(2,2) / 3) / Ubarcorr / Ubarcorr;
F3= 1 - (wu(1,1) / 9 + wv(1,1) / 3 + 2 * wu(2,2) / 3) / Ubarcorr / Ubarcorr;

if length(U) > 255,
   specsize=round(length(U)/10);
else,
   specsize=128;
end;

[Su,Fson]=psd2(detrend(U),specsize,20);[Su,Fson]=specsmoo(Su,20);
[Sv,Fson]=psd2(detrend(V),specsize,20);[Sv,Fson]=specsmoo(Sv,20);
[Sw,Fson]=psd2(detrend(W),specsize,20);[Sw,Fson]=specsmoo(Sw,20);
[St,Fson]=psd2(detrend(Tsonic),specsize,20);[St,Fson]=specsmoo(St,20);
[Sq,Fson]=psd2(detrend(qophir)./1000./rho,specsize,20);[Sq,Fson]=specsmoo(Sq,20);          %g/kg
[Soh,Fson]=psd2(detrend(oakH2O)./rho,specsize,20);[Soh,Fson]=specsmoo(Soh,20);
[Soc,Fson]=psd2(detrend(rc)./rho,specsize,20);[Soc,Fson]=specsmoo(Soc,20);
[Scc,Fson]=psd2(detrend(oakCO2)./rho,specsize,20);[Scc,Fson]=specsmoo(Scc,20);
[Slh,Fson]=psd2(detrend(LicorH2O)./rho,specsize,20);[Slh,Fson]=specsmoo(Slh,20);
[Slc,Fson]=psd2(detrend(LicorCO2)./rho,specsize,20);[Slc,Fson]=specsmoo(Slc,20);
[Ssc,Fson_ls]=psd2(detrend(LicorseaCO2)./rho,256,20);[Ssc,Fson_ls]=specsmoo(Ssc,20);
[Cuw,Fson]=csd2(detrend(W),detrend(U),specsize,20);[Cuw,Fson]=specsmoo(Cuw,20);
[Cvw,Fson]=csd2(detrend(W),detrend(V),specsize,20);[Cvw,Fson]=specsmoo(Cvw,20);
[Ctw,Fson]=csd2(detrend(W),detrend(Tsonic),specsize,20);[Ctw,Fson]=specsmoo(Ctw,20);
[Cqw,Fson]=csd2(detrend(W),detrend(qophir)./1000./rho,specsize,20);[Cqw,Fson]=specsmoo(Cqw,20);           %g/kg
[Cohw,Fson]=csd2(detrend(W),detrend(oakH2O)./rho,specsize,20);[Cohw,Fson]=specsmoo(Cohw,20);
[Cocw,Fson]=csd2(detrend(W),detrend(rc)./rho,specsize,20);[Cocw,Fson]=specsmoo(Cocw,20);
[Clhw,Fson]=csd2(detrend(W),detrend(LicorH2O)./rho,specsize,20);[Clhw,Fson]=specsmoo(Clhw,20);
[Clcw,Fson]=csd2(detrend(W),detrend(LicorCO2)./rho,specsize,20);[Clcw,Fson]=specsmoo(Clcw,20);

%subtract noise

%if length(Su)>5,sev=5;else;sev=1;end;
%Su=Su-median(Su(length(Su)-sev:length(Su)));
%if length(Sv)>5,sev=5;else;sev=1;end;
%Sv=Sv-median(Sv(length(Sv)-sev:length(Sv)));
%if length(Sw)>5,sev=5;else;sev=1;end;
%Sw=Sw-median(Sw(length(Sw)-sev:length(Sw)));
%if length(St)>5,sev=5;else;sev=1;end;
%St=St-median(St(length(St)-sev:length(St)));
if length(Sq)>5,sev=5;else;sev=1;end;
Sq=abs(Sq-median(Sq(length(Sq)-sev:length(Sq))));
if length(Soh)>5,sev=5;else;sev=1;end;
Soh=abs(Soh-median(Soh(length(Soh)-sev:length(Soh))));
if length(Soc)>5,sev=5;else;sev=1;end;
Soc=abs(Soc-median(Soc(length(Soc)-sev:length(Soc))));
if length(Slh)>5,sev=5;else;sev=1;end;
Slh=abs(Slh-median(Slh(length(Slh)-sev:length(Slh))));
if length(Slc)>5,sev=5;else;sev=1;end;
Slc=abs(Slc-median(Slc(length(Slc)-sev:length(Slc))));
if length(Ssc)>5,sev=5;else;sev=1;end;
Ssc=abs(Ssc-median(Ssc(length(Ssc)-sev:length(Ssc))));

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

%sonic U
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;

Cu2_1=median(cS*((2*pi/Ubarstr)^(2/3))*Su(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));
Cw2_1=median(cS*((2*pi/Ubarstr)^(2/3))*Sw(fminU:fmaxU).*Fson(fminU:fmaxU).^(5/3));

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

Ct2_1=median(cS*((2*pi/Ubarstr)^(2/3))*St(fminT:fmaxT).*Fson(fminT:fmaxT).^(5/3));

%ophir Q
fminQ=min(find(Fson>0.6));
fminQ=fminQ-2;if fminQ<1,fminQ=1,end;
fmaxQ=fminQ+2;if fmaxQ>length(Fson),fmaxQ=length(Fson);end;

Cq2_1=median(cS*((2*pi/Ubarstr)^(2/3))*Sq(fminQ:fmaxQ).*Fson(fminQ:fmaxQ).^(5/3));

%oakridge H
fminH=min(find(Fson>0.6));
fminH=fminH-2;if fminH<1,fminH=1,end;
fmaxH=fminH+2;if fmaxH>length(Fson),fmaxH=length(Fson);end;

Coh2_1=median(cS*((2*pi/Ubarstr)^(2/3))*Soh(fminH:fmaxH).*Fson(fminH:fmaxH).^(5/3));

%oakridge C
fminC=min(find(Fson>0.6));
fminC=fminC-2;if fminC<1,fminC=1,end;
fmaxC=fminC+2;if fmaxC>length(Fson),fmaxC=length(Fson);end;

Coc2_1=median(cS*((2*pi/Ubarstr)^(2/3))*Soc(fminC:fmaxC).*Fson(fminC:fmaxC).^(5/3));

%Apply Wyngaard and Clifford Correction to the Structure Function Parameters

Cu2_1=Cu2_1/F1;
Cw2_1=Cw2_1/F1;
Ct2_1=Ct2_1/F2;
Cq2_1=Cq2_1/F2;
Coc2_1=Coc2_1/F2;
Coh2_1=Coh2_1/F2;

%figure;loglog(Fson,Fson.*Su,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_1*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2_1');
%figure;loglog(Fson,Fson.*Sw,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_1*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2_1');
%figure;loglog(Fson,Fson.*St,Fson(fminT:fmaxT),Fson(fminT:fmaxT).*Ct2_1*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminT:fmaxT).^(-5/3));title('Ct^2_1');
%figure;loglog(Fson,Fson.*Sq,Fson(fminQ:fmaxQ),Fson(fminQ:fmaxQ).*Cq2_1*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminQ:fmaxQ).^(-5/3));title('Cq^2_1');
%figure;loglog(Fson,Fson.*Soh,Fson(fminH:fmaxH),Fson(fminH:fmaxH).*Coh2_1*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminH:fmaxH).^(-5/3));title('Coh^2_1');
%figure;loglog(Fson,Fson.*Soc,Fson(fminC:fmaxC),Fson(fminC:fmaxC).*Coc2_1*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminC:fmaxC).^(-5/3));title('Coc^2_1');
%figure;loglog(Fson,Fson.*Sq,Fson,Fson.*Soh,Fson,Fson.*Slh,Fson(20:length(Fson)),(Fson(20:length(Fson)).^(-2/3))./(mean(Fson(26:31)).^(-2/3)).*(mean(Soh(26:31)).*mean(Fson(26:31))));title([filename(10:16),'  Sq,  Soh,  Slh']);
%figure;loglog(Fson,Fson.*Soc,Fson,Fson.*Scc,Fson,Fson.*Slc,Fson(20:length(Fson)),(Fson(20:length(Fson)).^(-2/3))./(mean(Fson(26:31)).^(-2/3)).*(mean(Soc(26:31)).*mean(Fson(26:31))));title([filename(10:16),'   Soc,  Scc,  Slc']);

y=yship;x=xship;Cu2=Cu2_1;Ct2=Ct2_1;Cq2=Cq2_1;Coh2=Coh2_1;Coc2=Coc2_1;Q=Qbar;gasidiss;usid_1=us0;tsid_1=ts_ib;qsid_1=qs_ib;ocsid_1=ocs_ib;ohsid_1=ohs_ib;Lid_1=z_u/zet;

%sonic U
fminU=min(find(Fson>.6));
fmaxU=max(find(Fson<3.5));
if fminU<1,fminU=1,end;
if fmaxU>length(Fson),fmaxU=length(Fson);end;
if fminU>fmaxU,fminU=fmaxU-4;end;
if size(fminU:fmaxU)<6,fminU=fminU-1;fmaxU=fmaxU+1;end;

Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ubarstr)^(2/3))*Su(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cu2_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/Ubarstr)^(2/3))*Su(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ubarstr)^(2/3))*Su(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cu2_2=exp(Zpoly(5));
end;

Zpoly=polyfit(log(Fson(fminU:fmaxU)),log(cS*((2*pi/Ubarstr)^(2/3))*Sw(fminU:fmaxU).*(Fson(fminU:fmaxU).^(2/3))),4);
if Zpoly(4)<0.25,
   Cw2_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/Ubarstr)^(2/3))*Sw(fmaxU-4:fmaxU).*(Fson(fmaxU-4:fmaxU).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminU+plus:fmaxU)),log(cS*((2*pi/Ubarstr)^(2/3))*Sw(fminU+plus:fmaxU).*(Fson(fminU+plus:fmaxU).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cw2_2=exp(Zpoly(5));
end;

%temperature T
fminT=min(find(Fson>.3));
fmaxT=max(find(Fson<1.4));
if fminT<1,fminT=1,end;
if fmaxT>length(Fson),fmaxT=length(Fson);end;
if fminT>fmaxT,fminT=fmaxT-4;end;
if size(fminT:fmaxT)<6,fminT=fminT-1;fmaxT=fmaxT+1;end;

Zpoly=polyfit(log(Fson(fminT:fmaxT)),log(cS*((2*pi/Ubarstr)^(2/3))*St(fminT:fmaxT).*(Fson(fminT:fmaxT).^(2/3))),4);
if Zpoly(4)<0.25,
   Ct2_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/Ubarstr)^(2/3))*St(fmaxT-4:fmaxT).*(Fson(fmaxT-4:fmaxT).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminT+plus:fmaxT)),log(cS*((2*pi/Ubarstr)^(2/3))*St(fminT+plus:fmaxT).*(Fson(fminT+plus:fmaxT).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Ct2_2=exp(Zpoly(5));
end;

%ophir Q
fminQ=min(find(Fson>0.4));
fmaxQ=max(find(Fson<1.4));
if fminQ<1,fminQ=1,end;
if fmaxQ>length(Fson),fmaxQ=length(Fson);end;
if fminQ>fmaxQ,fminQ=fmaxQ-4;end
if size(fminQ:fmaxQ)<6,fminQ=fminQ-1;fmaxQ=fmaxQ+1;end;

Zpoly=polyfit(log(Fson(fminQ:fmaxQ)),log(cS*((2*pi/Ubarstr)^(2/3))*Sq(fminQ:fmaxQ).*(Fson(fminQ:fmaxQ).^(2/3))),4);
if Zpoly(4)<0.25,
   Cq2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminQ+plus+4==fmaxQ,
         if fmaxQ<4;fmaxQ=4;end;
         Zpoly=polyfit(log(Fson(fmaxQ-4:fmaxQ)),log(cS*((2*pi/Ubarstr)^(2/3))*Sq(fmaxQ-4:fmaxQ).*(Fson(fmaxQ-4:fmaxQ).^(2/3))),4);
         break;
      end;
      Zpoly=polyfit(log(Fson(fminQ+plus:fmaxQ)),log(cS*((2*pi/Ubarstr)^(2/3))*Sq(fminQ+plus:fmaxQ).*(Fson(fminQ+plus:fmaxQ).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Cq2_2=exp(Zpoly(5));
end;

%oakridge H
fminH=min(find(Fson>0.4));
fmaxH=max(find(Fson<1.4));
if fminH<1,fminH=1,end;
if fmaxH>length(Fson),fmaxH=length(Fson);end;
if fminH>fmaxH,fminH=fmaxH-4;end
if size(fminH:fmaxH)<6,fminH=fminH-1;fmaxH=fmaxH+1;end;

Zpoly=polyfit(log(Fson(fminH:fmaxH)),log(cS*((2*pi/Ubarstr)^(2/3))*Soh(fminH:fmaxH).*(Fson(fminH:fmaxH).^(2/3))),4);
if Zpoly(4)<0.25,
   Coh2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminH+plus+4==fmaxH,
         if fmaxH<4;fmaxH=4;end;
         Zpoly=polyfit(log(Fson(fmaxH-4:fmaxH)),log(cS*((2*pi/Ubarstr)^(2/3))*Soh(fmaxH-4:fmaxH).*(Fson(fmaxH-4:fmaxH).^(2/3))),4);
         break;
      end;            
      Zpoly=polyfit(log(Fson(fminH+plus:fmaxH)),log(cS*((2*pi/Ubarstr)^(2/3))*Soh(fminH+plus:fmaxH).*(Fson(fminH+plus:fmaxH).^(2/3))),4);
      if Zpoly(4)>zold,break,end
   end;
   Coh2_2=exp(Zpoly(5));
end;

%oakridge C
fminC=min(find(Fson>0.5));
fmaxC=max(find(Fson<1.0));
if fminC<1,fminC=1,end;
if fmaxC>length(Fson),fmaxC=length(Fson);end;
if fminC>fmaxC,fminC=fmaxC-4;end
if size(fminC:fmaxC)<6,fminC=fminC-1;fmaxC=fmaxC+1;end;

Zpoly=polyfit(log(Fson(fminC:fmaxC)),log(cS*((2*pi/Ubarstr)^(2/3))*Soc(fminC:fmaxC).*(Fson(fminC:fmaxC).^(2/3))),4);
if Zpoly(4)<0.25,
   Coc2_2=exp(Zpoly(5));
else,
   plus=0;
   while 1
      zold=Zpoly(4);
      plus=plus+1;
      if fminC+plus+4>=fmaxC,
         if fmaxC<4;fmaxC=4;end;
         Zpoly=polyfit(log(Fson(fmaxC-4:fmaxC)),log(cS*((2*pi/Ubarstr)^(2/3))*Soc(fmaxC-4:fmaxC).*(Fson(fmaxC-4:fmaxC).^(2/3))),4);
         break;
      end;
      Zpoly=polyfit(log(Fson(fminC+plus:fmaxC)),log(cS*((2*pi/Ubarstr)^(2/3))*Soc(fminC+plus:fmaxC).*(Fson(fminC+plus:fmaxC).^(2/3))),4);
      if Zpoly(4)>zold,break,end;
   end;
   Coc2_2=exp(Zpoly(5));
end;

%   Apply Wyngaard and Clifford Correction to the Structure Function Parameters
Cu2_2=Cu2_2/F1;
Cw2_2=Cw2_2/F1;
Ct2_2=Ct2_2/F2;
Cq2_2=Cq2_2/F2;
Coc2_2=Coc2_2/F2;
Coh2_2=Coh2_2/F2;

%figure;loglog(Fson,Fson.*Su,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cu2_2*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cu^2_2');
%figure;loglog(Fson,Fson.*Sw,Fson(fminU:fmaxU),Fson(fminU:fmaxU).*Cw2_2*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminU:fmaxU).^(-5/3));title('Cw^2_2');
%figure;loglog(Fson,Fson.*St,Fson(fminT:fmaxT),Fson(fminT:fmaxT).*Ct2_2*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminT:fmaxT).^(-5/3));title('Ct^2_2');
%figure;loglog(Fson,Fson.*Sq,Fson(fminQ:fmaxQ),Fson(fminQ:fmaxQ).*Cq2_2*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminQ:fmaxQ).^(-5/3));title('Cq^2_2');
%figure;loglog(Fson,Fson.*Soh,Fson(fminH:fmaxH),Fson(fminH:fmaxH).*Coh2_2*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminH:fmaxH).^(-5/3));title('Coh^2_2');
%figure;loglog(Fson,Fson.*Soc,Fson(fminC:fmaxC),Fson(fminC:fmaxC).*Coc2_2*((2*pi/Ubarstr).^(-2/3))./cS.*Fson(fminC:fmaxC).^(-5/3));title('Coc^2_2');
%figure;loglog(Fson,Fson.*Sq,Fson,Fson.*Soh,Fson,Fson.*Slh,Fson(20:length(Fson)),(Fson(20:length(Fson)).^(-2/3))./(mean(Fson(26:31)).^(-2/3)).*(mean(Soh(26:31)).*mean(Fson(26:31))));title([filename(10:16),'  Sq,  Soh,  Slh']);
%figure;loglog(Fson,Fson.*Soc,Fson,Fson.*Scc,Fson,Fson.*Slc,Fson(20:length(Fson)),(Fson(20:length(Fson)).^(-2/3))./(mean(Fson(26:31)).^(-2/3)).*(mean(Soc(26:31)).*mean(Fson(26:31))));title([filename(10:16),'   Soc,  Scc,  Slc']);

y=yship;x=xship;Cu2=Cu2_2;Ct2=Ct2_2;Cq2=Cq2_2;Coc2=Coc2_2;Coh2=Coh2_2;Q=Qbar;gasidiss;usid_2=us0;tsid_2=ts_ib;qsid_2=qs_ib;ocsid_2=ocs_ib;ohsid_2=ohs_ib;Lid_2=z_u/zet;

%y_y=[y wspd Tbar Tsea Qbar wu(1,2) wv(1,2) wt(1,2) wa(1,2) wh(1,2) rho stdC stdA medC medA Ss Sc Sp rain

newview=[ddd+hhh/24+mmm/24/60 mpair Tetl Twhoi Timet RHetl RHwhoi RHimet Qbar rho Tseaship ...
      Tseaysi Tseasnake Esat Qsea mean_oakCO2 med_oakCO2 std_oakCO2 min_oakCO2 max_oakCO2 ...
      mean_oakH2O med_oakH2O std_oakH2O min_oakH2O max_oakH2O mean_LicorCO2 med_LicorCO2 ...
      std_LicorCO2 min_LicorCO2 max_LicorCO2 mean_rc med_rc std_rc min_rc max_rc ...
      mean_LicorH2O med_LicorH2O std_LicorH2O min_LicorH2O max_LicorH2O mean_LicorseaCO2 ...
      med_LicorseaCO2 std_LicorseaCO2 min_LicorseaCO2 max_LicorseaCO2 mean_OphirH2O ...
      med_OphirH2O std_OphirH2O min_OphirH2O max_OphirH2O mean_absorb med_absorb ...
      std_absorb min_absorb max_absorb mean_clear med_clear std_clear min_clear max_clear ...
      mean_Tsonic med_Tsonic std_Tsonic min_Tsonic max_Tsonic north east mean_sog std_sog ...
      max_sog min_sog mean_cog std_cog min_cog max_cog Rs std_Rs min_Rs max_Rs Rs1 std_Rs1 ...
      min_Rs1 max_Rs1 Rs2 std_Rs2 min_Rs2 max_Rs2 med_Rss std_Rss min_Rss max_Rss Rl ...
      std_Rl min_Rl max_Rl Rl1 std_Rl1 min_Rl1 max_Rl1 Rl2 std_Rl2 min_Rl2 max_Rl2 ...
      mean_wave med_wave std_wave max_wave min_wave wdir Ubarstr Ustr Ubarcorr unorth ...
      uwest reldir relwind wspd alpha beta wu(1,1) wu(1,2) wu(2,2) wv(1,1) wv(1,2) wv(2,2) ...
      wt(1,1) wt(1,2) wt(2,2) wq(1,1) wq(1,2) wq(2,2) wlh(1,1) wlh(1,2) wlh(2,2) wlc(1,1) ...
      wlc(1,2) wlc(2,2) woh(1,1) woh(1,2) woh(2,2) woc(1,1) woc(1,2) woc(2,2) mean_head ...
      std_head min_head max_head Sp1 Sp2 Sp3 rain Lat Lon Us zi zu zq zt xship yship Cu2_1 ...
      Cu2_2 Ct2_1 Ct2_2 Cq2_1 Cq2_2 Coc2_1 Coc2_2 Coh2_1 Coh2_2 usid_1 usid_2 tsid_1 ...
      tsid_2 qsid_1 qsid_2 ocsid_1 ocsid_2 ohsid_1 ohsid_2 Lid_1 Lid_2];

specview=[ddd+hhh/24+mmm/24/60 Su Sv Sw St Sq Soh Soc Slh Slc Ssc Cuw Cvw Ctw Cqw Cohw Cocw Clhw Clcw];

sfl=[num2str(ddd),num2str(hhh),num2str(mmm)];

if filename(9:10)=='98',
   filename=[filename(1:8),filename(11:length(filename))];
end;

sdg=['save d:\temp\d',filename(10:16),'.prn newview -ascii'];
disp(sdg)
eval(sdg)

sdg=['save d:\temp\s',filename(10:16),'.prn specview -ascii'];
disp(sdg)
eval(sdg)
disp('pause'),pause
clear Ch Chs Cq2 Ct2 Cu2 F Fo Ct Cts Cu Cus Cv Cvs Cw Cws Esat Q L LongIR1 LongIR2 P Q Qsea 
clear RHv Solar1 Solar2 T TT Tairv Tsea Tsea_snake Tv Us alphau c Uid Uid_2 Uid_3 Uid_4 
clear Uid_5 Uid_6 c_coeff cog daytest fmax g head hourtest iii lat long qs0 medA medA_2 
clear medA_3 medA_4 medA_5 medA_6 stdA stdA_2 stdA_3 stdA_4 stdA_5 stdA_6 qs_ib rho sog 
clear ts0 u_id us0 us_ib vkon x zet z zi x x_2 x_3 x_4 x_5 x_6 zq zt zu zzz Qs Qs0 RH