TIMEPOSLEGS

Torsten Linders, torsten@oceansurface.se, September 13, 2011

Identifies and plots the time and the positions from MSS, the ship and TIMOS. Defines the legs for each platform.

Contents

Cleaning up

clear
close all
fclose('all');

Reading MSS data from tob-files

dir='../epsi_5dm_torsten/';
last_file=1236;
lat_=zeros(last_file,1);
lon_=zeros(last_file,1);
dist_=zeros(last_file,1);
depth_=zeros(last_file,3);
i_=[3:29 31:100 102:106 155:161 163:257 259:413 418:last_file];
for i=i_
    if i<10
        filename=[dir 'epsi000' num2str(i) '.tob'];
    elseif i<100
        filename=[dir 'epsi00' num2str(i) '.tob'];
    elseif i<1000
        filename=[dir 'epsi0' num2str(i) '.tob'];
    else
        filename=[dir 'epsi' num2str(i) '.tob'];
    end
    fid=fopen(filename);
    row1_9=textscan(fid,'%640c',1);
    row10=textscan(fid,'%50c',1);
    fclose(fid);
    row10=cell2mat(row10);
    if i<352
        hour=textscan(row10(7:end),'%f');
        hour=cell2mat(hour);
        if hour<10
            mi=textscan(row10(9:end),'%f');
            sec=textscan(row10(12:end),'%f');
            halfday=textscan(row10(15),'%c');
            lat=textscan(row10(18:end),'%f');
            lon=textscan(row10(30:end),'%f');
        else
            mi=textscan(row10(10:end),'%f');
            sec=textscan(row10(13:end),'%f');
            halfday=textscan(row10(16),'%c');
            lat=textscan(row10(18:end),'%f');
            lon=textscan(row10(30:end),'%f');
        end
        halfday=cell2mat(halfday);
        if halfday=='P' && hour<12
            hour=hour+12;
        elseif halfday=='A' && hour==12
            hour=0;
        end
        lat=cell2mat(lat);
        lon=cell2mat(lon);
    else
        hour=textscan(row10(18:end),'%f');
        hour=cell2mat(hour);
        mi=textscan(row10(21:end),'%f');
        sec=textscan(row10(24:25),'%f');
        if hour<10
            lat=textscan(row10(28:end),'%f');
            lon=textscan(row10(39:end),'%f');
        else
            lat=textscan(row10(28:end),'%f');
            lon=textscan(row10(39:end),'%f');
        end
        lat=cell2mat(lat);
        lon=cell2mat(lon);

        lat_int=floor(lat);
        lat_deg=floor(lat_int/100);
        lat_dec1=(lat_int/100-lat_deg);
        lat_dec2=lat-lat_int;
        lat=lat_deg+lat_dec1*10/6+lat_dec2/100*10/6;

        lon_int=floor(lon);
        lon_deg=floor(lon_int/100);
        lon_dec1=(lon_int/100-lon_deg);
        lon_dec2=lon-lon_int;
        lon=lon_deg+lon_dec1*10/6+lon_dec2/100*10/6;
    end
    mi=cell2mat(mi);
    sec=cell2mat(sec);
    time=(hour*3600+mi*60+sec)/86400;
    if i<188
        june_day=10;
    elseif i<340
        june_day=11;
    elseif i<418
        june_day=12;
    elseif i<643
        june_day=13;
    elseif i<819
        june_day=14;
    elseif i<1062
        june_day=15;
    else
        june_day=16;
    end
    lastofmay=31+28+31+30+31;
    julian=lastofmay+june_day+time;
    julian_(i)=julian;
    lat_(i)=lat;
    lon_(i)=lon;
end

Filling missing MSS data

The missing data are added by the following help scrpts: fill_julianTOB.m and fill_posTOB.m

fill_julianTOB
fill_posTOB
j_=[101 107:154 162 418];
for i=j_
    hour=time_man(i,1)-2;
    mi=time_man(i,2);
    sec=0;
    time=(hour*3600+mi*60+sec)/86400;
    if i<188
        june_day=10;
    elseif i<340
        june_day=11;
    elseif i<418
        june_day=12;
    elseif i<643
        june_day=13;
    elseif i<819
        june_day=14;
    elseif i<1062
        june_day=15;
    else
        june_day=16;
    end
    julian=lastofmay+june_day+time;
    julian_(i)=julian;
    if i<418
        lat_(i)=pos_man(i,1);
        lon_(i)=pos_man(i,2);
    end
end

Loading ship data from mat-file

load mat/gf09_LTA ADCP

Loading TIMOS data from mat-file

Length of data

Data from all timoscasts should be merged into new variables. Here we define the indices in new variables for the first (castfirst) and the last (castlast) data from respective cast. The total length of the data (ldata) is also defined.

timoscasts=1:7;
castfirst=zeros(1,length(timoscasts));
castlast=zeros(1,length(timoscasts));
ldata=0;
for cast=timoscasts
    castfirst(cast)=ldata+1;
    file=['../TIMOS_GUFI09_ADCP_data/TIMOS_GUFI09_ADCP_' num2str(cast) '.mat'];
    load(file)
    ldata=ldata+length(t);
    castlast(cast)=ldata;
end

Merging data

Here we merge data from different mat-files, representing different casts with TIMOS, into single variables.

tchristian=zeros(1,ldata);
dayofjune=zeros(1,ldata);
time=zeros(3,ldata);
for cast=timoscasts
    file=['../TIMOS_GUFI09_ADCP_data/TIMOS_GUFI09_ADCP_' num2str(cast) '.mat'];
    load(file)

    tchristian(castfirst(cast):castlast(cast))=t;

    file=['../TIMOS_GUFI09_ADCP_data/ADCP_600kHz_cast0' num2str(cast+2) '.mat'];
    load(file)

    dayofjune(castfirst(cast):castlast(cast))=SerDay;
    if SerDay>13
        SerHour=SerHour-2;
    end
    time(1,castfirst(cast):castlast(cast))=SerHour;
    time(2,castfirst(cast):castlast(cast))=SerMin;
    time(3,castfirst(cast):castlast(cast))=SerSec;

    lat(castfirst(cast):castlast(cast))=AnFLatDeg;
    lon(castfirst(cast):castlast(cast))=AnFLonDeg;
end

Time

tmss=julian_;
tship=ADCP.tUTC'+1+30/86400;
lastofmay=31+28+31+30+31;
ttimos=lastofmay+dayofjune+time(1,:)/24+time(2,:)/1440+time(3,:)/86400;
lastofdec=floor(tchristian(1))-floor(ttimos(1));
tchristian=tchristian-lastofdec;
ttioms=tchristian;

Positions

latmss=lat_;
lonmss=lon_;
lattimos=lat;
lontimos=lon;
latship=ADCP.Lat;
lonship=ADCP.Lon;
for i=6621:6989
    lonship(i)=interp1_alt(ttimos,lontimos,tship(i));
    latship(i)=interp1_alt(ttimos,lattimos,tship(i));
end

lattrack = [58.2626;58.2641;58.2643;58.2638;58.2607;58.2598;58.2599;58.2608;...
    58.2617;58.2624;58.2674;58.2695;58.2708;58.2731;58.3003];
lontrack = [11.3976;11.4099;11.4139;11.4172;11.4281;11.4329;11.4360;11.4470;...
    11.4555;11.4589;11.4742;11.4799;11.4827;11.4863;11.5251];

[distmss,depthmss]=distdepth_gf0906(lonmss);
[distship,depthship]=distdepth_gf0906(lonship);
[disttimos,depthtimos]=distdepth_gf0906(lontimos);

dirship=(sign(diff(distship)));
dirtimos=(sign(diff(disttimos)));

Legs

This section defines the legs. A leg is an along fjord transection defined by lattrack and lontrack. The first time index of each leg is defined for the three platforms (MSS, the ship and TIMOS). These indices are put in the three arrays filmss, filship and filtimos. The last time index of each leg, for each platform, is put in the three arrays filmss, filship and filtimos.

MSS

The legs of the MSS data, which have the least number of data points (casts), are defined manually. The criteria are that the ship should be in a constant direction and that the speed between the casts should not be approximately constant. For many legs the last cast is identical to the first cast in the next leg. The array dirlegs contains values indicating which direction the leg has, +1 for into the fjord and -1 for out of the fjord.

filmss=[340 352 381 418 451 483 511 542 575 606 ...
    637 665 698 819 860 902 942 978 1020 1059 ...
    1093 1138 1172];
lilmss=[351 381 413 451 483 511 541 575 606 636 ...
    665 698 734 860 902 942 978 1020 1059 1093 ...
    1138 1172 1217 ];
imssbad=[496 626];
imssnl=735:818;
nlegs=length(filmss);
dirlegs=[1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1  1 -1 1 -1 1];

The Ship

The criteria for the legs of the ship data are that they should cover the same time as the MSS legs and that ship should have the same direction as the MSS leg.

for leg=1:nlegs
    i=1;
    while tship(i)<tmss(filmss(leg)) || isnan(tship(i))
        i=i+1;
    end
    while dirship(i)~=dirlegs(leg)
        i=i+1;
    end
    filship(leg)=i-1;
    while tship(i)<tmss(lilmss(leg))
        i=i+1;
    end
    while dirship(i+1)~=dirlegs(leg)
        i=i-1;
    end
    lilship(leg)=i;
end

TIMOS

The criteria for the legs of the TIMOS are the same as the criteria for the legs of the ship. There are no TIMOS data during the first leg.

filtimos=nan;
liltimos=nan;
for leg=2:nlegs
    i=1;
    while ttimos(i)<tmss(filmss(leg)) || isnan(ttimos(i))
        i=i+1;
    end
    while dirtimos(i)~=dirlegs(leg)
        i=i+1;
    end
    filtimos(leg)=i-1;
    while ttimos(i)<tmss(lilmss(leg))
        i=i+1;
    end
    while dirtimos(i+1)~=dirlegs(leg)
        i=i-1;
    end
    liltimos(leg)=i;
end

Saving

save timeposlegs tmss tship ttimos lonmss lonship lontimos ...
    distmss distship disttimos depthmss depthship depthtimos dirlegs nlegs ...
    filmss lilmss imssbad imssnl filship lilship filtimos liltimos ...
    timoscasts castfirst castlast

Plotting

Time

fig=figure(100);
set(fig,'Position',[1 1 900 900]);

plot(tship,distship/1000,'r.')
hold on
plot(ttimos,disttimos/1000,'g.')
plot(tmss,distmss/1000,'bo')
hold off
for june=10:16
    text(lastofmay+june+0.3,9.5,['June ' num2str(june)])
end
xlabel('Julian Days')
ylabel('Distance (km)')
xlim([161 168])
grid on
legend('The ship','TIMOS','MSS',3)

Legs

fig=figure(102);
set(fig,'Position',[1 1 1200 1000]);

for leg=1:nlegs
    subplot(4,6,leg)
    imss=filmss(leg):lilmss(leg);
    for ibad=imssbad
        imss=imss(find(imss~=ibad));
    end
    iship=filship(leg):lilship(leg);
    if leg>1
        itimos=filtimos(leg):liltimos(leg);
    end
    plot(distship(iship)/1000,tship(iship),'-r.')
    hold on
    if leg>1
        plot(disttimos(itimos)/1000,ttimos(itimos),'-g.')
    end
    plot(distmss(imss)/1000,tmss(imss),'-bo')
    hold off
    if leg>1
        y0=min([tmss(imss) tship(iship) ttimos(itimos)]);
        y1=max([tmss(imss) tship(iship) ttimos(itimos)]);
    else
        y0=min([tmss(imss) tship(iship)]);
        y1=max([tmss(imss) tship(iship)]);
    end
    ylim([y0 y1])
    xlim([0 10])
    title(['Leg: ' num2str(leg)])
    grid on

end

subplot(4,6,24)
plot(3:5,'-r.')
hold on
plot(2:4,'-g.')
plot(1:3,'-bo')
hold off
ylim([1 8])
set(gca,'XTick',[],'YTick',[])
legend('The ship','TIMOS','MSS')

Positions

fig=figure(101);
set(fig,'Position',[1 1 900 900]);

plot(lonship,latship,'r.')
hold on
plot(lontimos,lattimos,'g.')
plot(lonmss,latmss,'bo')
plot(lontrack,lattrack,'-m*')
hold off
xlim([11.39 11.58])
ylim([58.245 58.355])
xlabel('Longitude (^oE)')
ylabel('Latitude (^oN)')
grid on
legend('The ship','TIMOS','MSS','Track points',2)