clear all
close all
f=netcdf('/usr/home/mblod/neuro/nemo/nemo_opa/TRY_STYX/modipsl/config/GYRE/EXP00/mesh_mask.nc','nowrite');
lati=f{'nav_lat'}(2:21,2:31);
longi=f{'nav_lon'}(2:21,2:31);
%load ../test_ta.dat
%nbtp2=4;
load ../tb_sbd100.dat
load /usr/home/mblod/neuro/nemo/nemo_opa/TRY_STYX/modipsl/config/GYRE/EXP00/GYRE_sortie_mohamed_ptb.dat
load ../sb_sbd100.dat
load /usr/home/mblod/neuro/nemo/nemo_opa/TRY_STYX/modipsl/config/GYRE/EXP00/GYRE_sortie_mohamed_psb.dat
load ../ub_sbd100.dat
load /usr/home/mblod/neuro/nemo/nemo_opa/TRY_STYX/modipsl/config/GYRE/EXP00/GYRE_sortie_mohamed_pub.dat
load ../vb_sbd100.dat
load /usr/home/mblod/neuro/nemo/nemo_opa/TRY_STYX/modipsl/config/GYRE/EXP00/GYRE_sortie_mohamed_pvb.dat
load ../sshb_sbd100.dat
load /usr/home/mblod/neuro/nemo/nemo_opa/TRY_STYX/modipsl/config/GYRE/EXP00/GYRE_sortie_mohamed_psshb.dat
nx=32;
ny=22;
itest=1;
if itest==1,
  dY=tb_sbd100;
  dF=GYRE_sortie_mohamed_ptb;
elseif itest==2,
  dY=sb_sbd100;
  dF=GYRE_sortie_mohamed_psb;
elseif itest==3,
  dY=ub_sbd100;
  dF=GYRE_sortie_mohamed_pub;
  dY2=vb_sbd100;
  dF2=GYRE_sortie_mohamed_pvb;
elseif itest==4,
  dY=tb_sbd100;
  dF=GYRE_sortie_mohamed_ptb;
%  dY=sshb_sbd100;
%  dF=GYRE_sortie_mohamed_psshb;
end
m=size(dF,2);
%I1=find((GYRE_sortie_mohamed_pta(:,1)==97) & (GYRE_sortie_mohamed_pta(:,m-1)==1)) ;
if itest~=4,
  I1=find(dF(:,m-1)==1) ;
  dbF=dF(I1,m);
  %dbF=dF(:,m);
else
  dbF=dF(:,m);
end
pF=reshape(dbF,ny,nx);
pF=pF(2:21,2:31);
if itest==3,
  dbF2=dF2(I1,m);
  pF2=reshape(dbF2,ny,nx);
  pF2=pF2(2:21,2:31);
  pF=sqrt( pF.*pF +pF2.*pF2);
end

n=size(dY,2);
if itest~=4,
  %%I2=find((dY(:,1)==nbtp2) & (dY(:,n-1)==1)) ;
  I2=find((dY(:,n-1)==1)) ;
  dbY=dY(I2,n);
  %dbY=dY(:,n);
else
  dbY=dY(:,n);
end
norm(dbY-dbF)
p=reshape(dbY,ny,nx);
p=p(2:21,2:31);
if itest==3,
  dbY2=dY2(I1,n);
  pY2=reshape(dbY2,ny,nx);
  pY2=pY2(2:21,2:31);
  p=sqrt( p.*p +pY2.*pY2);
end


p0=abs(p-pF);

figure(1)
set(gcf,'position',[10 600 700 300])

subplot(1,3,1)
set(gca,'Position',[0.09 0.23 0.26 0.76])
pcolor(longi,lati,pF)
shading flat %interp 
xlabel('longi  Fortran')
ylabel('lati')
%colorbar

subplot(1,3,2)
set(gca,'Position',[0.36 0.23 0.26 0.76])
pcolor(longi,lati,p)
set(gca,'yticklabel',[])
shading flat %interp 
xlabel('Yao')
colorbar

subplot(1,3,3)
set(gca,'Position',[0.68 0.23 0.26 0.76])
pcolor(longi,lati,p0)
set(gca,'yticklabel',[])
shading flat %interp 
colorbar


return


subplot(3,1,1)
set(gca,'Position',[0.13 0.7 0.690675 0.23])
imagesc(pF)%%,[min(db) max(db)])
colormap(jet); set(gca,'fontsize',12)
%ylabel('Depth (m)','fontsize',12)
%title(title1,'fontsize',12)
set(gca,'TickDir','out'); 
set(gca,'xticklabel',[]) 
%ylabel('Depth (m)','fontsize',12)
colorbar

subplot(3,1,2)
set(gca,'Position',[0.13 0.4 0.690675 0.23])
imagesc(p)%%,[min(db) max(db)])
colormap(jet); set(gca,'fontsize',12)
%ylabel('Depth (m)','fontsize',12)
%title(title1,'fontsize',12)
set(gca,'TickDir','out'); 
set(gca,'xticklabel',[]) 
%ylabel('Depth (m)','fontsize',12)
colorbar

p0=abs(p-pF);
subplot(3,1,3)
set(gca,'Position',[0.13 0.1 0.690675 0.23])
imagesc(p0)%%,[min(db) max(db)])
colormap(jet); set(gca,'fontsize',12)
%ylabel('Depth (m)','fontsize',12)
%title(title1,'fontsize',12)
set(gca,'TickDir','out');
%ylabel('Depth (m)','fontsize',12)
colorbar


return
m=size(test_ua,2);
TU=3;j0=TU+1;
for j=j0:100,
    I1=find((test_ua(:,1)==j) & (test_ua(:,m-1)==1)) ;
    I2=find((test_va(:,1)==j) & (test_va(:,m-1)==1)) ;
    ua=test_ua(I1,m);
    va=test_va(I2,m);

    ua=reshape(ua,ny,nx);
    va=reshape(va,ny,nx);

    p=sqrt( ua.*ua +va.*va);

    imagesc(p)%%,[min(db) max(db)])
    colormap(jet); set(gca,'fontsize',12)
    ylabel('Depth (m)','fontsize',12)
    %title(title1,'fontsize',12)
    set(gca,'TickDir','out');
    ylabel('Depth (m)','fontsize',12)
    colorbar
    set(gca,'clim',[0.00 0.31 ])
    F(j) = getframe;
	hold off
end
movie(F(4:100))
movie2avi(F(4:100),'fff.avi','quality',100)      
 