% test to see if Ty is negative



clear
clc
folderV = ['/nobackupp8/awinetee/global/V_30hLPF_hamming_daily/'];
folderU = ['/nobackupp8/awinetee/global/U_30hLPF_hamming_daily/'];

nx = 2160;
siz = [8640 7560 1];

lats = quikreadpcolor_llc('~dmenemen/llc_2160/grid/YC.data',nx);
[aV aU] = quikreadpcolor_RASRAW_llc('~dmenemen/llc_2160/grid/RAS.data','~dmenemen/llc_2160/grid/RAW.data',nx);
landV = quikreadpcolor_llc('~dmenemen/llc_2160/grid/hFacS.data',nx);
landU = quikreadpcolor_llc('~dmenemen/llc_2160/grid/hFacW.data',nx);

p_tot = 0;
n = 1;
strNames = {};


pn='~dmenemen/llc_2160/MITgcm/'; % for ice read in - assume an hourly reading is good enough


n = 0;
Vdiff = 0;
Udiff = 0;
Vgpt = 0;
Ugpt  = 0;
Upt = 0;
Vpt = 0;
Uekpt = 0;
Vekpt = 0;
for ii = 92160:(80*24):1586400;
                
    dy=ts2dte(ii,45,2011,1,17,30)
    
    fnamVp = ['/nobackupp8/awinetee/global/V_oceTAUY_30hLPF_hamming_daily/V_oceTAUY' '_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    fnamUp = ['/nobackupp8/awinetee/global/U_oceTAUX_30hLPF_hamming_daily/U_oceTAUX' '_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];

    fnamU= [folderU 'U_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    fnamV = [folderV 'V_' 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];
    %fnamUek = ['/nobackupp8/awinetee/global/Uek_30hLPF_hamming_daily/Uek_30hLPF_hamming_oceTAUX_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    fnamTx = ['/nobackupp8/awinetee/global/oceTAUX_30hLPF_hamming_daily/oceTAUX_'  int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    fnamTy = ['/nobackupp8/awinetee/global/oceTAUY_30hLPF_hamming_daily/oceTAUY_'  int2str((nx)) 'x' int2str((nx*13)) '.' dy];
        
    if exist(fnamU) && exist(fnamV) && exist(fnamUp) && exist(fnamVp) && exist(fnamTx) && exist(fnamTy)
        n = n + 1
        strNames{n} = dy;
         
        [Up, Vp] = quikreadpcolor_upvp_llc(fnamUp,fnamVp,nx);
        
        if (ii<1198080)
            pin=[pn 'run_day49_624/'];
        else
            pin=[pn 'run/'];
        end
        
        SIheff = quikreadpcolor_llc([pin 'SIheff.' myint2str(ii,10) '.data'],nx);
        
        
       % Uek = readbin(fnamUek,siz);
       % Vek = readbin(fnamVek,siz);
        [Tx, Ty] = quikreadpcolor_uv_llc(fnamTx,fnamTy,nx);
         [U,V] = quikreadpcolor_uv_llc(fnamU,fnamV,nx);
       
       % Vekp = Vek.*Ty;
        %Uekp = Uek.*Tx;
        
        
        Up_c = U.*Tx;
        Vp_c = V.*Ty;
        
       % Ugp(Ugp == 0 | abs(Ugp) == inf | isnan(Ugp)) = 0;
       % Vgp(Vgp == 0 | abs(Vgp) == inf | isnan(Vgp)) = 0;
        
       % Up(Up == 0 | abs(Up) == inf) = 0;
        %Vp(Vp == 0 | abs(Vp) == inf) = 0;
        
       % Uekp(Uekp == 0 | abs(Uekp) == inf) = 0;
       % Vekp(Vekp == 0 | abs(Vekp) == inf) = 0;
       break;
         
    else
        disp('dne');
        
        
    end
end