% define desired region
region_name='global';
nx=4320;

% get and save daily-averaged regional fields
pin='~dmenemen/llc_4320/MITgcm/run/';
pout=['~dmenemen/llc_4320/regions/' region_name '/'];
for fnm={'Eta','U','V','oceTAUX','oceTAUY'}
    eval(['mkdir ' pout fnm{1} '_daily'])
    eval(['cd ' pout fnm{1} '_daily'])
    for ts=10368:(144*24):485568
        dy=ts2dte(ts,25,2011,9,10,29);
        fout=[fnm{1} '_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];
        if mod(ts,144*24*10) 
            disp(fout);
        end
        
            fld=0; n=0;
        for h=0:23 %, mydisp(h)
            fin=[pin fnm{1} '.' myint2str(ts,10) '.data'];
            if exist(fin)
                fld=fld+readbin(fin,[nx nx*13]);
                n=n+1;
            else
                break
            end
        end
        if n==24
            writebin(fout,fld/n);
        else
            break
        end
    end
end
