EPS_BINS

Torsten Linders, torsten@oceansurface.se, January 4, 2012

  1. Puts disspation into matrices representing horizontal bins during one day.
  2. Puts dissipation into matrices of S2 and N2 representing all observations during one leg, day or all three days.

Should work with both matlab and octave.

Contents

Cleaning up

clear

Settings

par='eNSav';                  % eps, eNS, eNSav
saving='matlab';            % matlab, octave, no
if strcmp(par,'eps')
    ip_method='nearest';    % nearest
    dbinx=500;              % distance between bins
elseif strcmp(par,'eNS') || strcmp(par,'eNSav')
    kN2scale=4000;          % scaling of N2 bins
    iS2scale=2000;          % scaling of S2 bins
    kN2max=20;              % number of N2 bins
    iS2max=20;              % number of S2 bins
    S2cut=1;                % cut off value for unrealisticly high S2
    dmin=10;                % minimum depth for eNS
    dmax=40;                % maximum depth for eNS
end
if strcmp(par,'eNS')
    avdays=0;               % no averageing
else
    avdays=1:4;             % averageing over each day and and all days
end

Loading prepared data

load mat/timeposlegs
load mat/fjordsection

if strcmp(par,'eps')
    load mat/epsi5dm epsi
    eps=epsi;
    clear epsi
elseif strcmp(par,'eNS') || strcmp(par,'eNSav')
    load mat/epsal
    load mat/shtal
    load mat/N2al
end

Vertical interpolation

if strcmp(par,'eps')
    mssz=(0.5:0.5:120);
    eps=(interp1(mssz,eps,z,ip_method));
end

Allocating

if strcmp(par,'eps')
    binx=min(x):dbinx:max(x);
    epsab=zeros(kmax,length(binx),4);
    epsib=zeros(kmax,length(binx),4);
elseif strcmp(par,'eNS')
    eNSal=zeros(kN2max,iS2max,23);
    eNSali=zeros(kN2max,iS2max,23);
elseif strcmp(par,'eNSav')
    eNSav=zeros(kN2max,iS2max,4);
    eNSavi=zeros(kN2max,iS2max,4);
end

Legs and data points

Selecting legs

for avday=avdays

if avday==1
    legs=1:3;
elseif avday==2
    legs=4:13;
elseif avday==3
    legs=14:23;
else
    legs=1:23;
end

for leg=legs

Selecting data points

    if strcmp(par,'eps')
        if dirlegs(leg)==1
            li=filmss(leg):lilmss(leg);
        elseif dirlegs(leg)==-1
            li=lilmss(leg):-1:filmss(leg);
        end
        for ibad=imssbad
            li=li(find(li~=ibad));
        end
        distleg=distmss(li);
        bins=round(distleg/dbinx)+1;
    end

Binning

    if strcmp(par,'eps')
        epsab(:,bins,avday)=epsab(:,bins,avday)+10.^eps(:,li);
        epsib(:,bins,avday)=epsib(:,bins,avday)+not(isnan(eps(:,li)));
    elseif strcmp(par,'eNS') || strcmp(par,'eNSav')
        if leg==legs(1) || avday==0
            eNS=zeros(kN2max,iS2max);
            eNSi=zeros(kN2max,iS2max);
        end
        S2=shtal(:,:,leg).^2;
        kdmin=dmin/dz;
        kdmax=dmax/dz;
        for k=kdmin:kdmax
            for i=1:imax
                epsi=10^epsal(k,i,leg);
                kN2=round(N2al(k,i,leg)*kN2scale)+1;
                kN2=min(size(eNS,1),kN2);
                iS2=round(S2(k,i)*iS2scale)+1;
                iS2=min(size(eNS,2),iS2);
                if epsi>0 && kN2>0 && iS2>0 && S2(k,i)<S2cut
                    eNS(kN2,iS2)=eNS(kN2,iS2)+epsi;
                    eNSi(kN2,iS2)=eNSi(kN2,iS2)+1;
                end
            end
        end
        if strcmp(par,'eNS')
            eNSal(:,:,leg)=log10(eNS./eNSi);
            eNSali(:,:,leg)=eNSi;
        end
    end
end

if strcmp(par,'eps')
    epsab(:,:,avday)=log10(epsab(:,:,avday)./epsib(:,:,avday));
elseif strcmp(par,'eNSav')
    eNSav(:,:,avday)=log10(eNS./eNSi);
    eNSavi(:,:,avday)=eNSi;
end

end

Saving

if strcmp(saving,'matlab') || strcmp(saving,'octave')
    if strcmp(saving,'octave')
        default_save_options('-mat')
    end
    if strcmp(par,'eps')
        save epsab epsab epsib binx dbinx
    elseif strcmp(par,'eNS')
        save eNSal eNSal eNSali kN2scale iS2scale kN2max iS2max S2cut dmin dmax
    elseif strcmp(par,'eNSav')
        save eNSav eNSav eNSavi kN2scale iS2scale kN2max iS2max S2cut dmin dmax
    end
end