% PolarCap, extracted to check for corrup files for Georgy (March26, 2022)
% SIuice, SIvice files on Sept 1st, 2012
% extract surface U, V, Salt, oceQnet for complete 20-Jan-2020 to 25-March 2021

% {{{ define desired region
nx=4320;
prec='real*4';
region_name='PolarCap';
mints=dte2ts('01-Sep-2012',25,2011,9,10);
maxts=dte2ts('01-Sep-2012',25,2011,9,10);
% }}}

% {{{ extract indices for desired region
fc=3;
ix=1:nx;
jx=1:nx;
kx=1;
suf1=['_' int2str(length(ix)) 'x' int2str(length(jx))];
% }}}

% {{{ create commands for extracting model output fields
pout=['~dmenemen/llc_4320/regions/' region_name '/'];
extract='/home4/bcnelson/MITgcm/extract/latest/extract4320 -p ';
timesteps=[int2str(mints) '-' int2str(maxts) ' '];
startPoint=[int2str(min(ix)) ',' int2str(min(jx)) ',1 '];

% {{{ get and save 2D fields
extent=[int2str(max(ix)) ',' int2str(max(jx)) ',1'];
for fnm={'SIuice','SIvice'}
    eval(['mkdir ' pout fnm{1}])
    eval(['cd ' pout fnm{1}])
    fieldNames=[fnm{1} ' '];
    system([extract timesteps  fieldNames  startPoint  extent '  > joblist']);
    disp(['cd ' pout fnm{1}])
    disp('parallel --slf $PBS_NODEFILE -j2 -a joblist')
end
% }}}

% }}}
