% extract daily maximum for an llc4320 field
cd ~dmenemen/llc_4320/regions/global
nx=4320;
fieldName='KPPhbl';
pout=[fieldName '_daily_MAX/'];
fout=[fieldName '_max_' int2str((nx)) 'x' int2str((nx*13)) '.'];
uncompress='/home4/bcnelson/MITgcm/extract/v1.08/uncompress4320 ';
for dte=[datenum('01-Feb-2012'):datenum('30-Apr-2012') ...
         datenum('01-Aug-2012'):datenum('31-Oct-2012')];
    mints=dte2ts(datestr(dte),25,2011,9,10);
    maxts=mints+3312;
    timesteps=[int2str(mints) '-' int2str(maxts) ' '];
    [s w]=system([uncompress timesteps  fieldName]);
    fld=zeros(nx,nx*13);
    for ts=mints:144:maxts
        fin=[myint2str(ts,10) '_' fieldName '.data'];
        fld=max(fld,readbin(fin,[nx nx*13]));
        eval(['delete ' fin])
    end
    dy=ts2dte(mints,25,2011,9,10,29);       
    writebin([pout fout dy],fld);
    disp(dy)
end

% look at KPPhbl
k1=quikread_llc('KPPhbl_daily_MAX/KPPhbl_max_4320x56160.2012-03-15',nx);
k2=quikread_llc('KPPhbl_daily_MAX/KPPhbl_max_4320x56160.2012-09-15',nx);
figure(1), clf
colormap(cmap)
quikplot_llc(log10(k1))
caxis([0.5 3])
colorbar('horiz')
title('March 15 log10(KPPhbl)')
print -djpeg figures/Mar15KPPhbl
figure(2), clf
colormap(cmap)
quikplot_llc(log10(k2))
caxis([0.5 3])
colorbar('horiz')
title('September 15 log10(KPPhbl)')
print -djpeg figures/Sep15KPPhbl
