% extract SPURS1 profile time series
cd ~dmenemen/llc_4320/regions/SPURS1/glider
mkdir subsample
cd subsample
format compact

% dimensions of OKMC region
nx=144;
ny=115;
nz=89;

% integration period to extract
ts=10368:144:1492992;
nt=length(ts);

% get and save values
Pnm='~dmenemen/llc_4320/regions/SPURS1/';
suf1='_17209.9179.1_144.115.89';
suf2=['_' int2str(nz) 'x' int2str(nt)];
tmp=zeros(ny,nz,nt);
for fld={'Salt','Theta'}
    eval(['mkdir ' fld{1}])
    for i=25:120, disp(i)
   %for i=25:44, disp(i)
   %for i=45:63, disp(i)
   %for i=64:82, disp(i)
   %for i=83:101, disp(i)
   %for i=102:120, disp(i)
        for t=1:nt
            fnm=[Pnm fld{1} '/' myint2str(ts(t),10) '_' fld{1} suf1];
            tmp(:,:,t)=reshape(quikread_ik(fnm,i,1:(ny*nz),nx,ny*nz),ny,nz);
        end
        for j=6:115
            fnm=[fld{1} '/i' myint2str(i,3) 'j' myint2str(j,3) suf2];
            tmp2=squeeze(tmp(j,:,:));
            writebin(fnm,tmp2);
        end
    end
end
