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

% get and save daily-averaged regional fields
pn='~dmenemen/llc_2160/MITgcm/';
pout=['~dmenemen/llc_2160/regions/' region_name '/'];
for fnm={'KPPhbl'}
   % eval(['mkdir ' pout fnm{1} '_daily_MAX'])

   % eval(['cd ' pout fnm{1} '_daily_MAX'])
   
    for  ts=92160:(80*24):1586400;
         
         if (ts<1198080)
            pin=[pn 'run_day49_624/'];
         else
            pin=[pn 'run/'];
         end
        
        dy=ts2dte(ts,45,2011,1,17,30);
        disp(['dy = ' dy]);
                  
        fout=[fnm{1} '_' 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:23 %, mydisp(h)
            fin=[pin fnm{1} '.' myint2str(ts+h*80,10) '.data'];
            
            if exist(fin)
                tmp = readbin(fin,[nx nx*13]);
                if sum(sum(tmp)) == 0
                    disp([fin])
                    
                else
                    %fld=max(fld,tmp);
                    
                    n=n+1;
                end
            else
                warning(['MISSING FILE ' fin])
                
            end
            
        end
        if n==24
            
           % writebin([pout fnm{1} '_daily_MAX/' fout],fld);
          
        end
      
        
    end
end
