% clear

imax=length(julian_);
iADCP=zeros(1,imax);
i=1;
iA=1;
iAmax=length(ADCP.tUTC);
julianA=ADCP.tUTC(iA)+1;
for i=1:imax
     while julian_(i)>julianA && julian_(i)>160 && iA<iAmax
         if not(isnan(ADCP.tUTC(iA)))
             julianA=ADCP.tUTC(iA)+1;
         end
         iA=iA+1;
     end
     iADCP(i)=iA;
end


fclose('all');
dir='C:\Users\torsten\Gf0906\MSS\Epsilon\';
dir='C:\Users\torsten\Gf0906\MSS\epsi_1m_torsten\';
dir='C:\Users\torsten\Gf0906\MSS\epsi_5dm_torsten\';
jan_may=31+28+31+30+31;
last_file=1236;
julian_=160*ones(last_file,1);
i_=[3:29 31:100 102:106 155:161 163:257 259:413 418:last_file];
j_=[101 107:154 162 418];
for i=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
            min=textscan(row10(9:end),'%f');
            sec=textscan(row10(12:end),'%f');
            halfday=textscan(row10(15),'%c');
        else
            min=textscan(row10(10:end),'%f');
            sec=textscan(row10(13:end),'%f');
            halfday=textscan(row10(16),'%c');
        end
        halfday=cell2mat(halfday);
        if halfday=='P' && hour<12
            hour=hour+12;
        elseif halfday=='A' && hour==12
            hour=0;
        end
    else
        hour=textscan(row10(18:end),'%f');
        hour=cell2mat(hour);
        min=textscan(row10(21:end),'%f');
        sec=textscan(row10(24:25),'%f');
    end
    min=cell2mat(min);
    sec=cell2mat(sec);
    time=(hour*3600+min*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=jan_may+june_day+time;
    julian_(i)=julian;
end
fill_julianTOB
for i=j_
    hour=time_man(i,1);
    if hour<22
        hour=hour-2;
    else
        hour=hour-2;
    end
    min=time_man(i,2);
    sec=0;
    time=(hour*3600+min*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=jan_may+june_day+time;
    julian_(i)=julian;    
end
clear min
figure(3000)
plot(i_,julian_(i_),'.b',...
    j_,julian_(j_),'.r')
hold on
plot(i_,ADCP.tUTC(iADCP(i_))+1,'.y',...
    j_,ADCP.tUTC(iADCP(j_))+1,'.g')
hold off
grid on
