PAR_LEGS

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

Puts parameters into matrices (or vectors) representing legs.

Contents

Cleaning up

clear

Parameters to process

The following parameter can be choosen. Some choises will trigger calculations of several parameters.

Turbulence parameters

Density parameters

Pressure paramers

Velocity parameters

Time and position parameters

Settings

par='eps';                  % eps, dens, N2, U, intU, ...
platform='timos';           % mss, ship, timos
saving='matlab';            % matlab, octave, no
ip_method='linear';         % nearest, linear
avday=0;                    % 0, 1, 2, 3, 4

Loading prepared data

load mat/timeposlegs
load mat/fjordsection

Data from MSS and the ship:

if strcmp(platform,'mss')
    load mat/epsi5dm N2 dens epsi
    eps=epsi;
    clear epsi
end
if strcmp(platform,'ship')
    load mat/gf09_LTA ADCP
end

Data from TIMOS:

if strcmp(platform,'timos')
    for cast=timoscasts
        file=['../TIMOS_GUFI09_ADCP_data/TIMOS_GUFI09_ADCP_' num2str(cast) '.mat'];
        load(file)
        u(:,castfirst(cast):castlast(cast))=uECbin;
        v(:,castfirst(cast):castlast(cast))=vECbin;
    end
    [dummy,dummy,phitrack]=distdepthangle_gf0906(lontimos);
    Uabs=sqrt(u.^2+v.^2);
    phiU=acos(u./Uabs).*sign(v);
    phiUtrack=phiU-repmat(phitrack,501,1);
    Ut=Uabs.*cos(phiUtrack);
    Vt=Uabs.*sin(phiUtrack);
end

Averaged parameters

if avday
    if strcmp(par,'pdev')
        load mat/pdeval1
    elseif strcmp(par,'zdev')
        load mat/zdeval1
    elseif strcmp(par,'densdev')
        load mat/densdeval1
    elseif strcmp(par,'Epot')
        load mat/Epotal1
    end
end

Vertical interpolation

MSS:

if strcmp(platform,'mss')
    mssz=(0.5:0.5:120);
    eps=(interp1(mssz,eps,z,ip_method));
    N2=(interp1(mssz,N2,z,ip_method));
    dens=(interp1(mssz,dens,z,ip_method));
end

The ship:

if strcmp(platform,'ship')
    Us=ADCP.up';
    Us=(interp1(-ADCP.z,Us,z,ip_method));
    ADCPdz=ADCP.z(1)-ADCP.z(2);
    for k=45:60
        if ((z(k)>-ADCP.z(1)-ADCPdz/2) && (z(k)<-ADCP.z(1)))
            Us(k,:)=ADCP.up(:,1);
        end
    end
end

New turbulence parameters

Turbulent kinetic energy

if strcmp(par,'tke')
    cb=0.35;
    cm0=0.556;
    tke=10.^eps.*cb./cm0^3./sqrt(N2);
    tkelog=log10(tke);
    ust=sqrt(2*tke);
    l=cm0^1.5*tke.^(1.5)./10.^eps;
    nu=1.2e-6;
    eta=(nu^3./eps).^(0.25);
end

New density parameters

Horizontal density gradient

if strcmp(par,'dens_h')
    dens_h=zeros(kmax,size(dens,2)-1);
    for k=1:kmax
        dens_h(k,:)=diff(dens(k,:))./diff(distmss)';
    end
end

New pressure parameters

Pressure, z-deviation and potential energy

if strcmp(par,'p0') || strcmp(par,'pdev') || strcmp(par,'zdev') || ...
        strcmp(par,'densdev') || strcmp(par,'Epot')
    p0=dens*NaN;
    p0(19:end,:)=cumsum(dens(19:end,:))*dz*9.81;
    if avday==0
        load mat/pavc
        load mat/densav
    elseif avday==1
        load mat/pavc1
        load mat/densav1
    elseif avday==2
        load mat/pavc2
        load mat/densav2
    elseif avday==3
        load mat/pavc3
        load mat/densav3
    end
    zdev=dens*NaN;
    densdev=dens*NaN;
    Epot=dens*NaN;
    ks=find(densavc>0);
    for i=1:size(dens,2)
        pdev(:,i)=p0(:,i)-pavc;
        zdev(ks,i)=interp1(densavc(ks),z(ks),dens(ks,i))-z(ks)';
        densdev(ks,i)=interp1(z(ks),densavc(ks),z(ks)'+zdev(ks,i))-densavc(ks);
        Epot(ks,i)=zdev(ks,i).*densdev(ks,i)*9.81/1025;
    end
end

New velocity parameters

Vertical shear

if strcmp(par,'shear')
    kmax=kmax-1;
    if strcmp(platform,'ship')
        shs=(Us(1:end-1,:)-Us(2:end,:))/dz;
    end
    if strcmp(platform,'timos')
        span=10;
        window=ones(span,1)/span;
        u=convn(u,window,'same');
        v=convn(v,window,'same');
        sht=sqrt((diff(u,1,1)/dz).^2+(diff(v,1,1)/dz).^2);
        zsh=z(2:end)-dz/2;
    end
end

Horizontal shear

if strcmp(par,'shear_h')
    if strcmp(platform,'ship')
    end
    if strcmp(platform,'timos')
        sht_h=zeros(kmax,size(Ut,2)-1);
        for k=1:kmax
            sht_h(k,:)=diff(Ut(k,:))./diff(disttimos);
        end
        span=5;
        window=ones(span,1)/span;
        sht_h=convn(sht_h,window,'same');
    end
end

Vertical integration of velocity

if strcmp(par,'intU')
    if strcmp(platform,'ship')
        intUs=zeros(1,size(Us,2));
        for i=1:size(Us,2);
            ks=find(not(isnan(Us(:,i))));
            intUs(i)=sum(Us(ks,i))*dz;
        end
    end
    if strcmp(platform,'timos')
        intUt=zeros(1,size(Ut,2));
        for i=1:size(Ut,2);
            ks=find(not(isnan(Ut(:,i))));
            intUt(i)=sum(Ut(ks,i))*dz;
        end
    end
end

Legs and data points

Selecting legs

if avday==0
    if strcmp(platform,'timos')
        legs=2:23;
    else
        legs=1:23;
    end
elseif avday==1
    if strcmp(platform,'timos')
        legs=2:3;
    else
        legs=1:3;
    end
elseif avday==2
    legs=4:13;
elseif avday==3
    legs=14:23;
end

for leg=legs

Selecting data points

    if strcmp(platform,'mss')
        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);
    elseif strcmp(platform,'ship')
        if dirlegs(leg)==1
            li=filship(leg):lilship(leg);
        elseif dirlegs(leg)==-1
            li=lilship(leg):-1:filship(leg);
        end
        distleg=distship(li);
    elseif strcmp(platform,'timos')
        if dirlegs(leg)==1
            li=filtimos(leg):liltimos(leg);
        elseif dirlegs(leg)==-1
            li=liltimos(leg):-1:filtimos(leg);
        end
        distleg=disttimos(li);
    end

Horizontal interpolation

Turbulence parameters

    if strcmp(par,'eps')
        epsal(:,:,leg)=(interp1(distleg,eps(:,li)',x,ip_method))';
    elseif strcmp(par,'tke')
        tkeal(:,:,leg)=(interp1(distleg,tke(:,li)',x,ip_method))';
        tkelogal(:,:,leg)=(interp1(distleg,tkelog(:,li)',x,ip_method))';
        ustal(:,:,leg)=(interp1(distleg,ust(:,li)',x,ip_method))';
        lal(:,:,leg)=(interp1(distleg,l(:,li)',x,ip_method))';
        etaal(:,:,leg)=(interp1(distleg,eta(:,li)',x,ip_method))';

Density parameters

    elseif strcmp(par,'dens')
        densal(:,:,leg)=(interp1(distleg,dens(:,li)',x,ip_method))';
    elseif strcmp(par,'N2')
        N2al(:,:,leg)=(interp1(distleg,N2(:,li)',x,ip_method))';
    elseif strcmp(par,'densdev')
        densdeval(:,:,leg)=(interp1(distleg,densdev(:,li)',x,ip_method))';
    elseif strcmp(par,'zdev')
        zdeval(:,:,leg)=(interp1(distleg,zdev(:,li)',x,ip_method))';
    elseif strcmp(par,'Epot')
        Epotal(:,:,leg)=(interp1(distleg,Epot(:,li)',x,ip_method))';
    elseif strcmp(par,'dens_h')
        distleg=distleg(1:end-1)+diff(distleg);
        li=li(1:end-1);
        dens_hal(:,:,leg)=(interp1(distleg,dens_h(:,li)',x,ip_method))';

Pressure parameters

    elseif strcmp(par,'p0')
        p0al(:,:,leg)=(interp1(distleg,p0(:,li)',x,ip_method))';
    elseif strcmp(par,'pdev')
        pdeval(:,:,leg)=(interp1(distleg,pdev(:,li)',x,ip_method))';

Velocity parameters

    elseif strcmp(par,'U')
        if strcmp(platform,'ship')
            Usal(:,:,leg)=(interp1(distleg,Us(:,li)',x,ip_method))';
        elseif strcmp(platform,'timos')
            Utal(:,:,leg)=(interp1(distleg,Ut(:,li)',x,ip_method))';
        end
    elseif strcmp(par,'V')
        Vtal(:,:,leg)=(interp1(distleg,Vt(:,li)',x,ip_method))';
    elseif strcmp(par,'intU')
        if strcmp(platform,'ship')
            intUsal(:,:,leg)=(interp1(distleg,intUs(:,li)',x,ip_method))';
        elseif strcmp(platform,'timos')
            intUtal(:,:,leg)=(interp1(distleg,intUs(:,li)',x,ip_method))';
        end
    elseif strcmp(par,'shear')
        if strcmp(platform,'ship')
            shsal(:,:,leg)=(interp1(distleg,shs(:,li)',x,ip_method))';
        elseif strcmp(platform,'timos')
            shtal(:,:,leg)=(interp1(distleg,sht(:,li)',x,ip_method))';
        end
    elseif strcmp(par,'shear_h')
        if strcmp(platform,'timos')
            distleg=distleg(1:end-1)+diff(distleg);
            li=li(1:end-1);
            sht_hal(:,:,leg)=(interp1(distleg,sht_h(:,li)',x,ip_method))';
        end

Time parameters

    elseif strcmp(par,'time')
        if strcmp(platform,'mss')
            tmal(:,:,leg)=(interp1(distleg,tmss(:,li)',x,ip_method))';
        elseif strcmp(platform,'ship')
            tsal(:,:,leg)=(interp1(distleg,tship(:,li),x,ip_method))';
        elseif strcmp(platform,'timos')
            ttal(:,:,leg)=(interp1(distleg,ttimos(:,li)',x,ip_method))';
        end
    end
end

Saving

if strcmp(saving,'matlab') || strcmp(saving,'octave')
    if strcmp(saving,'octave')
        default_save_options('-mat')
    end

Turbulence parameters

    if strcmp(par,'eps')
         save epsal.mat epsal
    elseif strcmp(par,'tke')
         save tkeal.mat tkeal tkelogal ustal lal etaal

Density parameters

    elseif strcmp(par,'dens')
         save densal.mat densal
    elseif strcmp(par,'N2')
         save N2al.mat N2al
    elseif strcmp(par,'densdev')
        if avday
            save densdeval1.mat densdeval
        else
            save densdeval.mat densdeval
        end
    elseif strcmp(par,'zdev')
        if avday
            save zdeval1.mat zdeval
        else
            save zdeval.mat zdeval
        end
    elseif strcmp(par,'Epot')
        if avday
            save Epotal1.mat Epotal
        else
            save Epotal.mat Epotal
        end
    elseif strcmp(par,'dens_h')
        save dens_hal.mat dens_hal

Pressure parameters

    elseif strcmp(par,'p0')
         save p0al.mat p0al
    elseif strcmp(par,'pdev')
        if avday
            save pdeval1.mat pdeval
        else
            save pdeval.mat pdeval
        end

Velocity parameters

    elseif strcmp(par,'U')
        if strcmp(platform,'ship')
             save Usal.mat Usal
        elseif strcmp(platform,'timos')
             save Utal.mat Utal
        end
    elseif strcmp(par,'V')
         save Vtal.mat Vtal
    elseif strcmp(par,'intU')
        if strcmp(platform,'ship')
             save intUsal.mat intUsal
        elseif strcmp(platform,'timos')
             save intUtal.mat intUtal
        end
    elseif strcmp(par,'shear')
        if strcmp(platform,'ship')
             save shsal.mat shsal
        elseif strcmp(platform,'timos')
             save shtal.mat shtal
        end
    elseif strcmp(par,'shear_h')
        if strcmp(platform,'ship')
             save shs_hal.mat shs_hal
        elseif strcmp(platform,'timos')
             save sht_hal.mat sht_hal
        end

Time parameters

    elseif strcmp(par,'time')
        if  strcmp(platform,'mss')
            save tmal.mat tmal
        elseif strcmp(platform,'ship')
            save tsal.mat tsal
        elseif strcmp(platform,'timos')
            save ttal.mat ttal
        end
    end
end