% 1 floater 2 pts
close all
figure(1)
scale=1000000
ls;
load obs_float/obs_float_test.dat;
whos;
x=obs_float_test (1:2:40,4)
y=obs_float_test (2:2:40,4)
x=x+1;
y=y+1;
plot(x(1),y(1),'+')
hold on;
plot(x(20),y(20),'>')
hold on;
plot(x(1:20),y(1:20),'+');
hold on;
plot(x(1:20),y(1:20),'-r')
hold on;

load obs_float/rfloat_total.dat
rfloat_total(:,:)
x2=rfloat_total(:,4)
y2=rfloat_total(:,3)
x2=x2+1;
y2=y2+1;
[k,h]=size(x2);
plot(x2(2),y2(2),'+')
hold on;
plot(x2(k-1),y2(k-1),'>')
hold on;
plot(x2(2:k-1),y2(2:k-1),'+')
hold on;
plot(x2(2:k-1),y2(2:k-1),'-g')
hold on;

load obs_float/uv_total.dat;
whos;
X1=uv_total(1:5046,end-3);
Y1=uv_total(1:5046,end-2);

%change si pas de temps change
U1=zeros(5046,1);
V1=zeros(5046,1)
e=1;
for r=1:1:19
    
    for count=1:5046
        Unew(count)=uv_total(e,end-1);
        Vnew(count)=uv_total(e,end);
        e=e+1;
    end
    U1=U1+Unew';
    V1=V1+Vnew';
   
    
end
X1=X1+1;
Y1=Y1+1;
U1=U1/19;
V1=V1/19;
quiver(X1,Y1,U1,V1,2,'r','Autoscale','off');

load obs_float/uzero.dat;


whos;
X2=uzero(:,end-2);
Y2=uzero(:,end-1);
X2=X2;
Y2=Y2;
U2=uzero(:,end);
load obs_float/vzero.dat

V2=vzero(:,end);
quiver(X2,Y2,U2,V2,2,'g','Autoscale','off');

% % load uv_total.dat;
% whos;
% X=uv_total(:,end-3);
% Y=uv_total(:,end-2);
% U=uv_total(:,end-1);
% V=uv_total(:,end);
% quiver(X,Y,U,V,2);
% 
load obs_float/utrue.dat;

utrue=roundn(utrue,-6)
whos;
X3=utrue(:,end-2);
Y3=utrue(:,end-1);
X3=X3;
Y3=Y3;
U3=utrue(:,end);
load obs_float/vtrue.dat
vtrue=roundn(vtrue,-6)
V3=vtrue(:,end);
quiver(X3,Y3,U3,V3,2,'b','Autoscale','off');
figure(2)

load obs_float/vel_bck_all.dat
it=find(vel_bck_all(:,1)==1);
Tu=reshape(vel_bck_all(it,4),58,87);
Tv=reshape(vel_bck_all(it,5),58,87);

load obs_float/vel_true_all.dat
it=find(vel_true_all(:,1)==1);
Bu=reshape(vel_true_all(it,4),58,87);
Bv=reshape(vel_true_all(it,5),58,87);

F=(Bu-Tu).^2+(Bv-Tv).^2
imagesc(F)
 hold on 
 
x=obs_float_test (1:2:40,4)
y=obs_float_test (2:2:40,4)
x=x+1;
y=y+1;
plot(x(1),y(1),'+')
hold on;
plot(x(20),y(20),'>')
hold on;
plot(x(1:20),y(1:20),'+');
hold on;
plot(x(1:20),y(1:20),'-r')
hold on;

figure(3)

load obs_float/uv_total.dat
it=find(uv_total(:,1)==0);
Iu0=reshape(uv_total(it,4),58,87);
Iv0=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==1);
Iu1=reshape(uv_total(it,4),58,87);
Iv1=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==2);
Iu2=reshape(uv_total(it,4),58,87);
Iv2=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==3);
Iu3=reshape(uv_total(it,4),58,87);
Iv3=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==4);
Iu4=reshape(uv_total(it,4),58,87);
Iv4=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==5);
Iu5=reshape(uv_total(it,4),58,87);
Iv5=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==6);
Iu6=reshape(uv_total(it,4),58,87);
Iv6=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==7);
Iu7=reshape(uv_total(it,4),58,87);
Iv7=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==8);
Iu8=reshape(uv_total(it,4),58,87);
Iv8=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==9);
Iu9=reshape(uv_total(it,4),58,87);
Iv9=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==10);
Iu10=reshape(uv_total(it,4),58,87);
Iv10=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==11);
Iu11=reshape(uv_total(it,4),58,87);
Iv11=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==12);
Iu12=reshape(uv_total(it,4),58,87);
Iv12=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==13);
Iu13=reshape(uv_total(it,4),58,87);
Iv13=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==14);
Iu14=reshape(uv_total(it,4),58,87);
Iv14=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==15);
Iu15=reshape(uv_total(it,4),58,87);
Iv15=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==16);
Iu16=reshape(uv_total(it,4),58,87);
Iv16=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==17);
Iu17=reshape(uv_total(it,4),58,87);
Iv17=reshape(uv_total(it,5),58,87);
it=find(uv_total(:,1)==18)
Iu18=reshape(uv_total(it,4),58,87);
Iv18=reshape(uv_total(it,5),58,87);
% it=find(uv_total(:,1)==19)
% Iu19=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==20);
% I20=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==21);
% I21=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==22);
% I22=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==23);
% I23=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==24);
% I24=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==25);
% I25=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==26);
% I26=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==27);
% I27=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==28);
% I28=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==29);
% I29=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==30);
% I30=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==31);
% I31=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==32);
% I32=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==33);
% I33=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==34);
% I34=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==35);
% I35=reshape(uv_total(it,4),58,87);
% it=find(uv_total(:,1)==36);
% I36=reshape(uv_total(it,4),58,87);

Cu=(Iu0+Iu1+Iu2+Iu3+Iu4+Iu5+Iu6+Iu7+Iu8+Iu9+Iu10+Iu11+Iu12+Iu13+Iu14+Iu15+Iu16+Iu17+Iu18)/19;
Cv=(Iv0+Iv1+Iv2+Iv3+Iv4+Iv5+Iv6+Iv7+Iv8+Iv9+Iv10+Iv11+Iv12+Iv13+Iv14+Iv15+Iv16+Iv17+Iv18)/19;

F1=(Tu-Cu).^2+(Tv-Cv).^2;
imagesc(F1)
hold on
x=obs_float_test (1:2:40,4)
y=obs_float_test (2:2:40,4)
x=x+1;
y=y+1;
plot(x(1),y(1),'+')
hold on;
plot(x(20),y(20),'>')
hold on;
plot(x(1:20),y(1:20),'+');
hold on;
plot(x(1:20),y(1:20),'-r')
hold on;
F2=(Bu-Cu).^2+(Bv-Cv).^2;
figure(4)
imagesc(F2)
hold on 
x=obs_float_test (1:2:40,4)
y=obs_float_test (2:2:40,4)
x=x+1;
y=y+1;
plot(x(1),y(1),'+')
hold on;
plot(x(20),y(20),'>')
hold on;
plot(x(1:20),y(1:20),'+');
hold on;
plot(x(1:20),y(1:20),'-r')
hold on;




figure (5)
imagesc(F)
axis([70 77 38 46])
hold on
x=obs_float_test (1:2:40,4)
y=obs_float_test (2:2:40,4)
x=x+1;
y=y+1;
plot(x(1),y(1),'+')
hold on;
plot(x(20),y(20),'>')
hold on;
plot(x(1:20),y(1:20),'+');
hold on;
plot(x(1:20),y(1:20),'-r')
hold on;


figure (6)
imagesc(F1)
axis([70 77 38 46])
hold on
x=obs_float_test (1:2:40,4)
y=obs_float_test (2:2:40,4)
x=x+1;
y=y+1;
plot(x(1),y(1),'+')
hold on;
plot(x(20),y(20),'>')
hold on;
plot(x(1:20),y(1:20),'+');
hold on;
plot(x(1:20),y(1:20),'-r')
hold on;


sum=0;
count=0;
for r=70:77
    for t=39:46
        sum=sum+F(t,r);
        count=count+1;
    end
end
sum=sum/count

sum3=0;
count3=0;
for r=70:77
    for t=39:46
        sum3=sum3+F1(t,r);
        count3=count3+1;
    end
end
sum3=sum3/count3