% {{{ Initialize 
nx=960;
ny=1280;
pn1='~dmenemen/llc_4320/regions/CalSWOT/';
pn2='~dmenemen/llc_4320/regions/CalSWOT/run_template1/MITgcm/run/';
cd ~dmenemen/llc_4320/regions/CalSWOT/run_template1
mkdir animations


fnm=dir('/nobackup/dmenemen/forcing/ECMWF_operational/EOG_pres_tide_2012');
lon=0:.140625:359.9;
lat=-89.8924;
lat_inc=[.1394,.14018,.14039,.1404695,.140496,.1405145,.1405275,.1405375, ...
         .1405455,.140552,.1405575,.140562,.1405655,.140568,.1405695, ...
         ones(1,1249)*.14057, ...
         .1405695,.140568,.1405655,.140562,.1405575,.140552,.1405455, ...
         .1405375,.1405275,.1405145,.140496,.1404695,.14039,.14018,.1394];

,
 precip_nlon       = 2560,
 precip_nlat       = 1280,




% }}}

% {{{ compare Eta 
cd ~dmenemen/llc_4320/regions/CalSWOT/run_template1/animations
mkdir frames
cd frames
fn1=dir([pn1 'Eta/Eta*']);
fn2=dir([pn2 'Eta*data']);
frm=0;
cx=[-2 2];
for h=1:min(length(fn1),length(fn2))
    e1=readbin([pn1 'Eta/' fn1(h).name],[nx ny]);
    for t=1:6;
        clf
        subplot(121)
        mypcolor(e1');
        caxis(cx)
        thincolorbar
        title(['1/48, hour ' int2str(h-1)])
        e2=readbin([pn2 fn2((h-1)*6+t).name],[nx ny]);
        subplot(122)
        mypcolor(e2');
        caxis(cx)
        thincolorbar
        title(['regional, hour ' int2str(h-1) ':' myint2str((t-1)*10)])
        eval(['print -djpeg frame' myint2str(frm,4)])
        frm=frm+1;
    end
end
!module load imagemagick; convert -delay 20 *.jpg Eta.gif
!mv *.gif ..
cd ..
!rm -rf frames
% }}}

% {{{ compare U
fn1=dir([pn1 'U/U*']);
fn2=dir([pn2 'U*data']);
cx=[-1 1]/2;
eval(['cd ' pn1])
mkdir frame2
cd frame2
!rm *
frm=0;
for h=1:length(fn1)
    e1=readbin([pn1 'U/' fn1(h).name],[nx ny]);
    for t=1:6;
        clf
        subplot(121)
        mypcolor(e1');
        caxis(cx)
        thincolorbar
        title(['1/48, hour ' int2str(h-1)])
        e2=readbin([pn2 fn2((h-1)*6+t).name],[nx ny]);
        subplot(122)
        mypcolor(e2');
        caxis(cx)
        thincolorbar
        title(['regional, hour ' int2str(h-1) ':' myint2str((t-1)*10)])
        eval(['print -djpeg frame' myint2str(frm,4)])
        frm=frm+1;
    end
end
% cd ~/llc_4320/regions/CalSWOT/frame2
% module load imagemagick
% convert -delay 20 *.jpg U.gif
% mv *.gif ..

% compare V
fn1=dir([pn1 'V/V*']);
fn2=dir([pn2 'V*data']);
cx=[-1 1]/2;
eval(['cd ' pn1])
mkdir frame3
cd frame3
!rm *
frm=0;
for h=1:length(fn1)
    e1=readbin([pn1 'V/' fn1(h).name],[nx ny]);
    for t=1:6;
        clf
        subplot(121)
        mypcolor(e1');
        caxis(cx)
        thincolorbar
        title(['1/48, hour ' int2str(h-1)])
        e2=readbin([pn2 fn2((h-1)*6+t).name],[nx ny]);
        subplot(122)
        mypcolor(e2');
        caxis(cx)
        thincolorbar
        title(['regional, hour ' int2str(h-1) ':' myint2str((t-1)*10)])
        eval(['print -djpeg frame' myint2str(frm,4)])
        frm=frm+1;
    end
end
% cd ~/llc_4320/regions/CalSWOT/frame3
% module load imagemagick
% convert -delay 20 *.jpg V.gif
% mv *.gif ..

% compare Theta
fn1=dir([pn1 'Theta/Theta*']);
fn2=dir([pn2 'T*data']);
cx=[7.5 20.5];
eval(['cd ' pn1])
mkdir frames
cd frames
!rm *
frm=0;
for h=1:length(fn1)
    e1=readbin([pn1 'Theta/' fn1(h).name],[nx ny]);
    clf
    subplot(121)
    mypcolor(e1');
    caxis(cx)
    thincolorbar
    title(['1/48, hour ' int2str(h-1)])
    e2=readbin([pn2 fn2((h-1)*6+1).name],[nx ny]);
    subplot(122)
    mypcolor(e2');
    caxis(cx)
    thincolorbar
    title(['regional, hour ' int2str(h-1)])
    eval(['print -djpeg frame' myint2str(frm,4)])
    frm=frm+1;
end
% cd ~/llc_4320/regions/CalSWOT/frames
% module load imagemagick
% convert -delay 20 *.jpg T.gif
% mv *.gif ..

% compare Salt
fn1=dir([pn1 'Salt/Salt*']);
fn2=dir([pn2 'S*data']);
cx=[32 36];
eval(['cd ' pn1])
mkdir frame4
cd frame4
!rm *
frm=0;
for h=1:length(fn1)
    e1=readbin([pn1 'Salt/' fn1(h).name],[nx ny]);
    clf
    subplot(121)
    mypcolor(e1');
    caxis(cx)
    thincolorbar
    title(['1/48, hour ' int2str(h-1)])
    e2=readbin([pn2 fn2((h-1)*6+1).name],[nx ny]);
    subplot(122)
    mypcolor(e2');
    caxis(cx)
    thincolorbar
    title(['regional, hour ' int2str(h-1)])
    eval(['print -djpeg frame' myint2str(frm,3)])
    frm=frm+1;
end
% cd ~/llc_4320/regions/CalSWOT/frame4
% module load imagemagick
% convert -delay 20 *.jpg S.gif
% mv *.gif ..
