% Ageostrophic currents from total-geostrophic
clear;
nx = 2160;
siz = [8640 7560 1];
landV = quikreadpcolor_llc('~dmenemen/llc_2160/grid/hFacS.data',nx);
landU = quikreadpcolor_llc('~dmenemen/llc_2160/grid/hFacW.data',nx);

currFldrVag = ['/nobackupp8/awinetee/global/Vag_30hLPF_hamming_daily'];
eval(['mkdir ' currFldrVag]);
currFldrUag = ['/nobackupp8/awinetee/global/Uag_30hLPF_hamming_daily'];
eval(['mkdir ' currFldrUag]);

for ii = 92160:(80*24):1586400;
                
    dy=ts2dte(ii,45,2011,1,17,30)
      
    fnamU = ['/nobackupp8/awinetee/global/U_30hLPF_hamming_daily/U_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    fnamV = ['/nobackupp8/awinetee/global/V_30hLPF_hamming_daily/V_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
     
    fnamUg = ['/nobackupp8/awinetee/global/Ug_noIce_hamming_daily/Ug' '_noIce_hamming' int2str((8640)) 'x' int2str((7560)) '.' dy];
    fnamVg = ['/nobackupp8/awinetee/global/Vg_noIce_hamming_daily/Vg' '_noIce_hamming' int2str((8640)) 'x' int2str((7560)) '.' dy];
     
    fnamUek = ['/nobackupp8/awinetee/global/Uek_30hLPF_hamming_daily/Uek_30hLPF_hamming_oceTAUX_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    fnamVek = ['/nobackupp8/awinetee/global/Vek_30hLPF_hamming_daily/Vek_30hLPF_hamming_oceTAUY_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
   
    
    if exist(fnamUg) && exist(fnamVg) && exist(fnamU) && exist(fnamV)
       
        
        
        Ug = readbin(fnamUg,siz);
        Vg = readbin(fnamVg,siz);
        [U, V] = quikreadpcolor_uv_llc(fnamU,fnamV,nx);
%         Uek = readbin(fnamUek,siz);
%         Vek = readbin(fnamVek,siz);
        
        U(landU==0) = nan;
        Ug(landU==0) = nan;
        V(landV==0) = nan;
        Vg(landV==0) = nan;
%         
%         Uek(landU==0) = nan;
%         Vek(landV==0) = nan;
        
        Uag = U-Ug;
        Vag = V-Vg;
        
%         close all
%         figure
%         quikpcolor(Ug');
%         colorbar
%         caxis([-.5 .5]);
%         colormap([0 0 0 ; brewermap(256,'RdYlBu')])
        figure
        quikpcolor(Vg');
        caxis([-.5 .5]);
        colormap([0 0 0 ; brewermap(256,'RdYlBu')])
        colorbar
%         figure
%         quikpcolor(U');
%         caxis([-.5 .5]);
%         colormap([0 0 0 ; brewermap(256,'RdYlBu')])
%         colorbar
        figure
        quikpcolor(V');
        caxis([-.5 .5]);
        colormap([0 0 0 ; brewermap(256,'RdYlBu')])
        colorbar
%         figure
%         quikpcolor(Uag');
%         caxis([-.5 .5]);
%         colormap([0 0 0 ; brewermap(256,'RdYlBu')])
%         colorbar
%         figure
%         quikpcolor(Vag');
%         caxis([-.5 .5]);
%         colormap([0 0 0 ; brewermap(256,'RdYlBu')])
%         colorbar
%          figure
%         quikpcolor(Uek');
%      caxis([-.5 .5]); 
%      colormap([0 0 0 ; brewermap(256,'RdYlBu')])
%         colorbar
%         figure
%         quikpcolor(Vek');
%        caxis([-.5 .5]);
%        
%        colormap([0 0 0 ; brewermap(256,'RdYlBu')])
%         colorbar
%          pause
% 

s = size(Vag);
  
    fileName = [currFldrUag '/Uag_30hLPF_hamming_' int2str(s(1)) 'x' int2str(s(2)) '.' dy];
    writebin(fileName,Uag);
    
    fileName = [currFldrVag '/Vag_30hLPF_hamming_' int2str(s(1)) 'x' int2str(s(2)) '.' dy];
    writebin(fileName,Vag);

    end
end

        