% {{{ Intitialize 
% {{{ Define 2-km region 
nx=960;
ny=1280;
nz=87;
pid='/nobackupp2/dmenemen/llc_4320/regions/CalSWOT/run_template1/data/';
pir='/nobackupp2/dmenemen/llc_4320/regions/CalSWOT/run_template1/MITgcm/run/';
ts=13824:24:24168; % day 4 to day ~7
% }}}
% {{{ Define 250-m region 
Nx=7680;
Ny=10240;
Nz=261;
Pid='/nobackupp2/dmenemen/llc_4320/regions/CalSWOT/run_template3b/data/';
Pir='/nobackupp2/dmenemen/llc_4320/regions/CalSWOT/run_template3b/MITgcm/run/';
Ts=57600:100:100700; % day 4 to day ~7
% }}}
% {{{ Define 30-m region 
NX=12800;
NY=9600;
NZ=259;
PID='/nobackupp2/dmenemen/llc_4320/regions/CalSWOT/run_template4/data/';
PIR='/nobackupp2/dmenemen/llc_4320/regions/CalSWOT/run_template4/MITgcm/run/';
TS=0:300:23100; % day 4 to day ~4.5
% }}}
% {{{ Extract indices for comparison near SWOT Xover 
lon=-124.4;
lat=35.2;
lonc=readbin([pid 'LONC.bin'],[nx ny]);
lonc=lonc(:,1);
latc=readbin([pid 'LATC.bin'],[nx ny]);
latc=latc(1,:);
Lonc=readbin([Pid 'LONC.bin'],[Nx Ny]);
Lonc=Lonc(:,1);
Latc=readbin([Pid 'LATC.bin'],[Nx Ny]);
Latc=Latc(1,:);
LONC=readbin([PID 'LONC.bin'],[NX NY]);
LONC=LONC(:,1);
LATC=readbin([PID 'LATC.bin'],[NX NY]);
LATC=LATC(1,:);
dx=.025;
ix=find(lonc>(lon-7*dx/5)&lonc<(lon+7*dx/5));
iy=find(latc>(lat-dx)&latc<(lat+dx));
Ix=find(Lonc>(lon-7*dx/5)&Lonc<(lon+7*dx/5));
Iy=find(Latc>(lat-dx)&Latc<(lat+dx));
IX=find(LONC>(lon-7*dx/5)&LONC<(lon+7*dx/5));
IY=find(LATC>(lat-dx)&LATC<(lat+dx));
% }}}
% {{{ Directory + colormap 
cd ~dmenemen/llc_4320/regions/CalSWOT/run_template4
mkdir animations
colormap(jet)
% }}}
% }}}

% {{{ compare UV 
% {{{ Extract indices for comparison near SWOT Xover 
lon=-124.4;
lat=35.2;
dx=.05;
ix=find(lonc>(lon-dx)&lonc<(lon+dx));
iy=find(latc>(lat-dx)&latc<(lat+dx));
IX=find(LONC>(lon-dx)&LONC<(lon+dx));
IY=find(LATC>(lat-dx)&LATC<(lat+dx));
% }}}
cd ~dmenemen/llc_4320/regions/CalSWOT/run_template4/animations
cx=[-1 1]/2.5;
t=length(TS);
h=(t-1)/6;
hr=[myint2str(floor(h)) ':' myint2str((h-floor(h))*60)];
flu=readbin([pir 'U.' myint2str(ts(t),10) '.data'],[nx ny]);
Flu=readbin([Pir 'U.' myint2str(Ts(t),10) '.data'],[Nx Ny]);
FLU=readbin([PIR 'U.' myint2str(TS(t),10) '.data'],[NX NY]);
flv=readbin([pir 'V.' myint2str(ts(t),10) '.data'],[nx ny]);
Flv=readbin([Pir 'V.' myint2str(Ts(t),10) '.data'],[Nx Ny]);
FLV=readbin([PIR 'V.' myint2str(TS(t),10) '.data'],[NX NY]);

clf
subplot(321)
mypcolor(flu(ix,iy)');
caxis(cx)
colorbar
title(['U, 2-km sim, hour ' hr])
subplot(322)
mypcolor(flv(ix,iy)');
caxis(cx)
colorbar
title(['V, 2-km sim, hour ' hr])

subplot(323)
mypcolor(Flu(Ix,Iy)');
caxis(cx)
colorbar
title(['U, 250-m sim, hour ' hr])
subplot(324)
mypcolor(Flv(Ix,Iy)');
caxis(cx)
colorbar
title(['V, 250-m sim, hour ' hr])

subplot(325)
mypcolor(FLU(IX,IY)');
caxis(cx)
colorbar
title(['U, 30-m sim, hour ' hr])
subplot(326)
mypcolor(FLV(IX,IY)');
caxis(cx)
colorbar
title(['V, 30-m sim, hour ' hr])
print -djpeg UV_k1
% }}}

% {{{ compare TS 
% {{{ Extract indices for comparison near SWOT Xover 
lon=-124.4;
lat=35.2;
dx=.05;
ix=find(lonc>(lon-dx)&lonc<(lon+dx));
iy=find(latc>(lat-dx)&latc<(lat+dx));
IX=find(LONC>(lon-dx)&LONC<(lon+dx));
IY=find(LATC>(lat-dx)&LATC<(lat+dx));
% }}}
cd ~dmenemen/llc_4320/regions/CalSWOT/run_template4/animations
cs=[33.05 33.22];
ct=[13.2 13.7];
t=length(TS);
h=(t-1)/6;
hr=[myint2str(floor(h)) ':' myint2str((h-floor(h))*60)];
fls=readbin([pir 'Salt.' myint2str(ts(t),10) '.data'],[nx ny]);
Fls=readbin([Pir 'Salt.' myint2str(Ts(t),10) '.data'],[Nx Ny]);
FLS=readbin([PIR 'Salt.' myint2str(TS(t),10) '.data'],[NX NY]);
flt=readbin([pir 'Theta.' myint2str(ts(t),10) '.data'],[nx ny]);
Flt=readbin([Pir 'Theta.' myint2str(Ts(t),10) '.data'],[Nx Ny]);
FLT=readbin([PIR 'Theta.' myint2str(TS(t),10) '.data'],[NX NY]);

clf
subplot(321)
mypcolor(fls(ix,iy)');
caxis(cs)
colorbar
title(['S, 2-km sim, hour ' hr])
subplot(322)
mypcolor(flt(ix,iy)');
caxis(ct)
colorbar
title(['T, 2-km sim, hour ' hr])

subplot(323)
mypcolor(Fls(Ix,Iy)');
caxis(cs)
colorbar
title(['S, 250-m sim, hour ' hr])
subplot(324)
mypcolor(Flt(Ix,Iy)');
caxis(ct)
colorbar
title(['T, 250-m sim, hour ' hr])

subplot(325)
mypcolor(FLS(IX,IY)');
caxis(cs)
colorbar
title(['S, 30-m sim, hour ' hr])
subplot(326)
mypcolor(FLT(IX,IY)');
caxis(ct)
colorbar
title(['T, 30-m sim, hour ' hr])
print -djpeg ST_k1
% }}}

% {{{ compare W 
% {{{ Extract indices for comparison near SWOT Xover 
lon=-124.4;
lat=35.2;
dx=.05;
ix=find(lonc>(lon-dx)&lonc<(lon+dx));
iy=find(latc>(lat-dx)&latc<(lat+dx));
IX=find(LONC>(lon-dx)&LONC<(lon+dx));
IY=find(LATC>(lat-dx)&LATC<(lat+dx));
% }}}
cd ~dmenemen/llc_4320/regions/CalSWOT/run_template4/animations
cs=[-1 1]*.02;
ct=[-1 1]*.01;
t=length(TS);
h=(t-1)/6;
hr=[myint2str(floor(h)) ':' myint2str((h-floor(h))*60)];
fls=readbin([pir 'W.' myint2str(ts(t),10) '.data'],[nx ny],1,'single',10);
Fls=readbin([Pir 'W.' myint2str(Ts(t),10) '.data'],[Nx Ny],1,'single',29);
FLS=readbin([PIR 'W.' myint2str(TS(t),10) '.data'],[NX NY],1,'single',29);
flt=readbin([pir 'W.' myint2str(ts(t),10) '.data'],[nx ny],1,'single',30);
Flt=readbin([Pir 'W.' myint2str(Ts(t),10) '.data'],[Nx Ny],1,'single',89);
FLT=readbin([PIR 'W.' myint2str(TS(t),10) '.data'],[NX NY],1,'single',89);

clf
subplot(321)
mypcolor(fls(ix,iy)');
caxis(cs)
colorbar
title(['W(18m), 2-km sim, hr ' hr])
subplot(322)
mypcolor(flt(ix,iy)');
caxis(ct)
colorbar
title(['W(230m), 2-km sim, hr ' hr])

subplot(323)
mypcolor(Fls(Ix,Iy)');
caxis(cs)
colorbar
title(['W(18m), 250-m sim, hr ' hr])
subplot(324)
mypcolor(Flt(Ix,Iy)');
caxis(ct)
colorbar
title(['W(230m), 250-m sim, hr ' hr])

subplot(325)
mypcolor(FLS(IX,IY)');
caxis(cs)
colorbar
title(['W(18m), 30-m sim, hr ' hr])
subplot(326)
mypcolor(FLT(IX,IY)');
caxis(ct)
colorbar
title(['W(230m), 30-m sim, hr ' hr])
print -djpeg W_k29_89
% }}}
