% Ekman Power

clear
clc
folderVek = ['~dmenemen/llc_4320/regions/global/Vek_daily/'];
folderUek = ['~dmenemen/llc_4320/regions/global/Uek_daily/'];
folderTx = ['~dmenemen/llc_4320/regions/global/oceTAUX_daily/'];
folderTy = ['~dmenemen/llc_4320/regions/global/oceTAUY_daily/'];
nx = 4320;
siz = [17280 15120 1];
fnamesVek = dir([folderVek '/*V*']);
fnamesUek = dir([folderUek '/*U*']);
fnamesTx = dir([folderTx '/*T*']);
fnamesTy = dir([folderTy '/*T*']);
numFiles = length(fnamesVek);
%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);

p_tot = 0;

for ii = 1 : numFiles
    fnamVek = ['~dmenemen/llc_4320/regions/global/Vek_daily/' fnamesVek(ii).name]
    fnamUek = ['~dmenemen/llc_4320/regions/global/Uek_daily/' fnamesUek(ii).name]
    fnamTx = ['~dmenemen/llc_4320/regions/global/oceTAUX_daily/' fnamesTx(ii).name]
    fnamTy = ['~dmenemen/llc_4320/regions/global/oceTAUY_daily/' fnamesTy(ii).name]
   
    Uek = readbin(fnamUek,siz);
    Vek = readbin(fnamVek,siz);
    [Tx, Ty] = quikreadpcolor_uv_llc(fnamTx,fnamTy,nx);
    
    Uek(isnan(Uek)) = 0;
    Uek(abs(Uek) == inf) = 0;
    Vek(isnan(Vek)) = 0;
    Vek(abs(Vek) == inf) = 0;
    Tx(isnan(Tx)) = 0;
    Ty(isnan(Ty)) = 0;
    aV(isnan(aV)) = 0;
    aU(isnan(aU)) = 0;
    Vek(abs(lats) < 15) = 0;
    Uek(abs(lats) < 15) = 0;
    extraArea = sum(sum(aU(abs(lats)<15)));
    pwrT = Uek.*Tx.*aU + Vek.*Ty.*aV;
    mPPA= mean(mean(Uek.*Tx + Vek.*Ty));
    pwr(ii) = sum(sum(pwrT)) + extraArea*mPPA;
end
    