clear
clc
folderVg = ['~dmenemen/llc_4320/regions/global/Vg_daily/'];
folderUg = ['~dmenemen/llc_4320/regions/global/Ug_daily/'];
folderTx = ['~dmenemen/llc_4320/regions/global/oceTAUX_daily/'];
folderTy = ['~dmenemen/llc_4320/regions/global/oceTAUY_daily/'];
nx = 2160;
siz = [8640,7560];
fnamesVg = dir([folderVg '/*E*']);
fnamesUg = dir([folderUg '/*E*']);
fnamesTx = dir([folderTx '/*T*']);
fnamesTy = dir([folderTy '/*T*']);
numFiles = length(fnamesVg);
%dx = quikread_llc('~dmenemen/llc_4320/grid/DXC.data',4320,1,'real*4','~dmenemen/llc_4320/grid/',-90,90,0,360);
%dy = quikread_llc('~dmenemen/llc_4320/grid/DYC.data',4320,1,'real*4','~dmenemen/llc_4320/grid/',-90,90,0,360);
% aU = quikreadpcolor_llc('~dmenemen/llc_4320/grid/RAW.data',nx);
% aV = quikreadpcolor_llc('~dmenemen/llc_4320/grid/RAS.data',nx);
lats = quikreadpcolor_llc('~dmenemen/llc_4320/grid/YC.data',nx);
[aV aU] = quikreadpcolor_RASRAW_llc('~dmenemen/llc_2160/grid/RAS.data','~dmenemen/llc_2160/grid/RAW.data',nx);

p_tot = 0;
n = 1;
strNames = {};
for ii = 92160:(80*24):1586400;
                
    dy=ts2dte(ii,45,2011,1,17,30);
    fnamTy = ['~dmenemen/llc_2160/regions/global/oceTAUY_daily/oceTAUY' '_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    fnamTx = ['~dmenemen/llc_2160/regions/global/oceTAUX_daily/oceTAUX' '_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    
    fnamUg = ['~dmenemen/llc_2160/regions/global/Ug_daily/Ug' '_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
    fnamVg = ['~dmenemen/llc_2160/regions/global/Vg_daily/Vg' '_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
     
    if exist(fnamUg) && exist(fnamVg) && exist(fnamTy) && exist(fnamTx)
        strNames{n} = dy;
        
        Ug = readbin(fnamUg,siz);
        Vg = readbin(fnamVg,siz);
        [Tx, Ty] = quikreadpcolor_uv_llc(fnamTx,fnamTy,nx);
        
        Ug(isnan(Ug)) = 0;
        Ug(abs(Ug) == inf) = 0;
        Vg(isnan(Vg)) = 0;
        Vg(abs(Vg) == inf) = 0;
        Tx(isnan(Tx)) = 0;
        Ty(isnan(Ty)) = 0;
        aV(isnan(aV)) = 0;
        aU(isnan(aU)) = 0;
        Vg(abs(lats) < 15) = 0;
        Ug(abs(lats) < 15) = 0;
        extraArea = sum(sum(aU(abs(lats)<15)));
        pwrT = Ug.*Tx.*aU + Vg.*Ty.*aV;
        mPPA= mean(mean(Ug.*Tx + Vg.*Ty));
        pwr(ii) = sum(sum(pwrT)) + extraArea*mPPA;
    end
end

    