disp('son_spc')

S=sqrt(u.*u+v.*v+w.*w);
uu=sonraw_dep(2,:);
vv=sonraw_dep(3,:);
ww=sonraw_dep(4,:);
tt=sonraw_dep(5,:);%-273.15;
UU=uu;
VV=vv;
%dir1=atan2(-V,U)*180/pi+180;		%jeff coordinates, +boward, +portward, 180 means wind from
%dir1=mod(dir+720,360);

%clear w vul v uul u tzilch tzero sul st3 speedson prtit prt_it plotit nr1 npz np nl1 jl jk jj jhold jd jazx jaxx jax jam jadson jade j_st j_en j hul hr hll flist
%clear f e dmp2 dmp dir backchk ans V U Tul Tsonic Tll S Rtul Rtll Rsul Rsll Rlul Rlll

if 1   %hhh==0 | hhh==01 | hhh==12 || hhh==13 | hhh==15 | hhh==18 | hhh==22,
    disp(['Calculating spectra for ',num2str(jam)])
    SS=sqrt(UU.^2+VV.^2);
    %speed spectra
    [Su,F]=psd2(detrend(SS),length(SS),20.);
    [Sus,Fsu]=specsmoo(Su,20.);
    % w spectra
    [Sw,F]=psd2(detrend(ww),length(ww),20.);
    [Sws,Fsw]=specsmoo(Sw,20.);
    % u spectra
    [Su,F]=psd2(detrend(uu),length(uu),20.);
    [Sus,Fsu]=specsmoo(Su,20.);
    % v spectra
    [Sv,F]=psd2(detrend(vv),length(vv),20.);
    [Svs,Fsv]=specsmoo(Sv,20.);

npts = num2str(ss(2));
    figure;
    % 5/3 line
    loglog(Fsu(length(Fsu)-31:length(Fsu)),((Fsu(length(Fsu)-31:length(Fsu))).^(-2/3))./(Fsu(length(Fsu)-18).^(-2/3)).*Sus(length(Fsu)-18).*Fsu(length(Fsu)-18),'r');
    hold
    %speed
    %loglog(Fsu,Sus.*Fsu,'b');
    %w
    loglog(Fsw,Sws.*Fsw,'g');
     %u
    loglog(Fsu,Sus.*Fsu,'k');
     %v
     ss = 'c:\data\icealot\data\sonic\Raw_Images\';
    loglog(Fsv,Svs.*Fsv,'b');
    title(['Sonic Anemometer Spectra:   Day ',num2str(jd),'   Hour ',num2str(jam),'  Npts ',npts,]);
    legend('5/3','W','U','V','Location','Best' );
    xlabel('Frequency in Hz');
    ylabel('Spectrum * Frequency');
    print_buffer = [ss ,jd  '_' hr , '_spc.png'];
    print('-dpng ', print_buffer);
    if 0 hhh==12,  % Print out spectra file for hr 12
        specfile=[way_spec_data, '\w_sp',jdr,num2str(jam),'.txt'];
        fspec=fopen(specfile,'w');
        specs=[Fsu
            Sus
            Fsw
            Sws];
        fprintf(fspec,'%11.5f %11.5f %11.5f %11.5f \r\n',specs);
        fclose(fspec);
        clear fspec specs specfile
    end;%end hhh=12
    clear SS UU VV Su F Sus Fsu Sw F Sws Fsw
end;%end hhh=0 or 12 or 18

