% clear all;
% RR=load('../obs_float/r_float_optim1.dat');
% R1=RR(3:2:end,end);
% R2=RR(4:2:end,end);
% %hold on
% figure;
% plot(R1+1,R2+1,'k-');
% hold on
% plot(R1(1)+1,R2(1)+1,'*r');
% 
% obs=load('../obs_float/obs.dat')
% plot(obs(1,end)+1,obs(2,end)+1,'*g');


%%%%%%%LOAD DATA%%%%%%%%%%%%%%%%%%%%

% fname=sprintf('./DATA_eps%i/FAP/RESULTS_B%i/Reaz_ab_jc%i_omd%i_S5_nobet.mat',epss,nbs,jc,omd);
% 
% eval(sprintf('load %s', fname));

clear all;
close all;
optim=10;

N_f=35;
load UV_0.mat;
load UVnext3d.mat;


 

DD=load('../obs_float/obs_true_t72_4h_f35.dat');
%PP=load('../obs_float/obs_pert3d_t60_f35.dat');
for ii=1:N_f
D1(ii,:)=DD(ii:N_f*2:end,end);
D2(ii,:)=DD(N_f+ii:N_f*2:end,end);
%P1(ii,:)=PP(ii:N_f*2:end,end);
%P2(ii,:)=PP(N_f+ii:N_f*2:end,end);
end;


fname=sprintf('../obs_float/r_float_optim_35_%i.dat',optim);
OP=load(fname);
%OP=load('../obs_float/r_float_optim_35_04.dat');
for ii=1:N_f
OP1(ii,:)=OP(ii:N_f*2:end,end);
OP2(ii,:)=OP(N_f+ii:N_f*2:end,end);
end;

for j=1:3;
     figure;
     plot(D1(j,end),D2(j,end),'*g');
     hold on;
     plot(D1(j,1),D2(j,1),'Ok');
     
     plot(OP1(j,:),OP2(j,:),'*m');
 
 end


%cc1=68;
%cc2=36;

cc1=68; %works best 
cc2=36;
far=3;

fname1=sprintf('../obs_float/uoptim_35_%i.dat',optim);
fname2=sprintf('../obs_float/voptim_35_%i.dat',optim);
you=load(fname1);
vee=load(fname2);
Urec=reshape(you(:,5),58,87);
Vrec=reshape(vee(:,5),58,87);

%load('../obs_float/uoptim_35_04.dat');
%Urec=reshape(uoptim_35_04(:,5),58,87);
%load('../obs_float/voptim_35_04.dat');
%Vrec=reshape(voptim_35_04(:,5),58,87);


%if blur
ebefore=norm(uu_pert-uu)./norm(uu)
eafter=norm(Urec-uu)./norm(uu)
%if week
ebefore_local=norm(uu_pert(cc2-far:cc2+far,cc1-far:cc1+far)-uu(cc2-far:cc2+far,cc1-far:cc1+far))...
./norm(uu(cc2-far:cc2+far,cc1-far:cc1+far))
eafter_local=norm(Urec(cc2-far:cc2+far,cc1-far:cc1+far)-uu(cc2-far:cc2+far,cc1-far:cc1+far))...
    ./norm(uu(cc2-far:cc2+far,cc1-far:cc1+far))



figure
quiver([1:1:87],[1:1:58],uu,vv,'k');
hold on;
quiver([1:1:87],[1:1:58],Urec,Vrec);
plot(cc1,cc2,'*r');
 %imagesc(Urec); 
 axis xy; colorbar;
%  for j=11:35;
%     
%     plot(D1(j,:),D2(j,:),'*g');
%     hold on;
%     plot(D1(j,1),D2(j,1),'Ok');
%     
%     plot(OP1(j,:),OP2(j,:),'*m');
%     plot(P1(j,:),P2(j,:),'*r');
%     
% 
%  end
plot(cc1,cc2,'*k')
 
 figure
quiver([1:1:87],[1:1:58],uu,vv,'k');
hold on;
quiver([1:1:87],[1:1:58],uu_pert,vv_pert);
plot(cc1,cc2,'*r');
 %imagesc(Urec); 
 axis xy; colorbar;
 
 
 


if false
L2L2=0;
L2L2A=0;
L2L2B=0;

for i = 1:size(uu,1)
    for j=1:size(uu,2)
        L2L2A=L2L2A+(Urec(i,j)-uu(i,j))^2+(Vrec(i,j)-vv(i,j))^2;
        L2L2B=L2L2B+(uu_pert(i,j)-uu(i,j))^2+(vv_pert(i,j)-vv(i,j))^2;
        L2L2=L2L2+uu(i,j)^2+vv(i,j)^2;
    end    
end

'perturbed'
sqrt(L2L2B/L2L2)
'corrected'
sqrt(L2L2A/L2L2)

%imagesc(Ut); axis xy; colorbar;
end