% define desired region
region_name='global_1080_test_7d';
nx=1080;

g = 9.806;
rho = 1027.5;
SEAICE_rhoIce = 910;
SEAICE_rhoSnow = 330;
d = 7;
hamming = ones(1,24*d)./(24*d);
% get and save daily-averaged regional fields
pin='~dmenemen/llc_1080/MITgcm/run_day732_896/';
pout=['/nobackupp8/awinetee/' region_name '/'];
for fnm={'Eta'}
    eval(['mkdir ' pout fnm{1} '_seaIceRemoved_30hLPF_hamming_daily'])

    eval(['cd ' pout fnm{1} '_seaIceRemoved_30hLPF_hamming_daily'])
   
    for ts=700800:(40*24*d):700800+(40*24*5)*30 
        
            
        dy=ts2dte(ts,90,2010,1,1)      
                
        fout=[fnm{1} '_seaIceRemoved_' int2str((nx)) 'x' int2str((nx*13)) '.' dy];

       
        
        fld=0; n=0; fld2 = 0; pwr = 0; fld_mn = 0; fld_mn2 = 0; n2 = 0;
        
        for h=0:24*d-1 %, mydisp(h)
            fin=[pin fnm{1} '.' myint2str(ts+h*40,10) '.data'];
            
            if exist(fin)
                tmp = readbin(fin,[nx nx*13]);
                SIheff = readbin([pin 'SIheff.' myint2str(ts+h*40,10) '.data'],[nx,nx*13]);
                SIhsnow = readbin([pin 'SIhsnow.' myint2str(ts+h*40,10) '.data'],[nx,nx*13]);
            
                iceLoad = SIheff*SEAICE_rhoIce + SIhsnow*SEAICE_rhoSnow;
                
                ssh = tmp + iceLoad/rho;
                if sum(sum(tmp)) == 0
                    warning(['ZEROs FILE ' fin])
                    break
                else
                    fld=fld+ hamming(h+1)*ssh;
                    
                    n=n+1;
                end
            else
                warning(['MISSING FILE ' fin])
                break
            end

        end
        if n==24*d
            try
            writebin([pout fnm{1} '_seaIceRemoved_30hLPF_hamming_daily/' fout],fld);
            catch err
                warning(['file not written ' fout]);
                disp(err.message);
                
            end
            
        end
    end
end
