109 lines
3.9 KiB
Matlab
109 lines
3.9 KiB
Matlab
function [q] = read_field_block_ucfmf(fdir,iseq,field,ii,jj,kk,varargin)
|
|
% [q] = read_field_block_ucfmf(fdir,iseq,field,ii,jj,kk,varargin)
|
|
% Reads a specified block of a field from processor chunks which hold the data (multi-file version)
|
|
% Input
|
|
% fdir directory with files
|
|
% iseq sequence index
|
|
% field field to be read
|
|
% {'u','v','w','p','s1','s2',...}
|
|
% ii,jj,kk list of global field indices to be read
|
|
% ? step index of step to be read (default: 1)
|
|
% ? verbosity verbose output? (default: 0)
|
|
% ? debug debug output? (default: 0)
|
|
% Output
|
|
% q partial field
|
|
|
|
% Parse optional input arguments
|
|
par = inputParser;
|
|
addParamValue(par,'step',1,@isnumeric);
|
|
addParamValue(par,'verbosity',0,@isnumeric);
|
|
addParamValue(par,'debug',0,@isnumeric);
|
|
parse(par,varargin{:});
|
|
istep = par.Results.step;
|
|
iverb = par.Results.verbosity;
|
|
idebug= par.Results.debug;
|
|
|
|
% Parse field
|
|
switch field(1)
|
|
case 'u'; ifield=1; fbase='uvwp'; cmesh='u';
|
|
case 'v'; ifield=2; fbase='uvwp'; cmesh='v';
|
|
case 'w'; ifield=3; fbase='uvwp'; cmesh='w';
|
|
case 'p'; ifield=4; fbase='uvwp'; cmesh='p';
|
|
case 's'; ifield=str2double(field(2:end)); fbase='scal'; cmesh='s';
|
|
otherwise; error('Invalid field: %s',field);
|
|
end
|
|
|
|
% Read processor grid
|
|
fproc = sprintf('%s/proc_%04d.bin',fdir,iseq);
|
|
[ibeg.u,iend.u,jbeg.u,jend.u,kbeg.u,kend.u,...
|
|
ibeg.v,iend.v,jbeg.v,jend.v,kbeg.v,kend.v,...
|
|
ibeg.w,iend.w,jbeg.w,jend.w,kbeg.w,kend.w,...
|
|
ibeg.p,iend.p,jbeg.p,jend.p,kbeg.p,kend.p,...
|
|
ibeg.s,iend.s,jbeg.s,jend.s,kbeg.s,kend.s] = ...
|
|
read_procgrid_ucf(fproc,'tarmode',0,'verbosity',iverb,'debug',idebug);
|
|
ibeg = ibeg.(cmesh);
|
|
jbeg = jbeg.(cmesh);
|
|
kbeg = kbeg.(cmesh);
|
|
iend = iend.(cmesh);
|
|
jend = jend.(cmesh);
|
|
kend = kend.(cmesh);
|
|
nxprocs = length(ibeg);
|
|
nyprocs = length(jbeg);
|
|
nzprocs = length(kbeg);
|
|
|
|
% Determine the corresponding chunks
|
|
nxb = numel(ii);
|
|
nyb = numel(jj);
|
|
nzb = numel(kk);
|
|
col = zeros(1,nxb);
|
|
row = zeros(1,nyb);
|
|
pln = zeros(1,nzb);
|
|
for iproc=1:nxprocs
|
|
col(ii>=ibeg(iproc) & ii<=iend(iproc)) = iproc;
|
|
end
|
|
for iproc=1:nyprocs
|
|
row(jj>=jbeg(iproc) & jj<=jend(iproc)) = iproc;
|
|
end
|
|
for iproc=1:nzprocs
|
|
pln(kk>=kbeg(iproc) & kk<=kend(iproc)) = iproc;
|
|
end
|
|
|
|
% Setup fast indexing for blocks
|
|
iib = [1:nxb];
|
|
jjb = [1:nyb];
|
|
kkb = [1:nzb];
|
|
|
|
% Print some info (if verbose)
|
|
if iverb
|
|
nchunk = numel(unique(col))*numel(unique(row))*numel(unique(pln));
|
|
fprintf('Reading [%d x %d x %d] points from %d chunks.\n',nxb,nyb,nzb,nchunk);
|
|
end
|
|
|
|
% Load data
|
|
q = zeros(nxb,nyb,nzb);
|
|
for thiscol=unique(col)
|
|
for thisrow=unique(row)
|
|
for thispln=unique(pln)
|
|
% Load the data
|
|
iproc = (thiscol-1)*nyprocs*nzprocs+(thisrow-1)*nzprocs+(thispln-1);
|
|
fdata = sprintf('%s/%s_%04d.%05d',fdir,fbase,iseq,iproc);
|
|
[data,ib,jb,kb,nxl,nyl,nzl,ighost] = read_field_chunk_ucf(fdata,ifield,'tarmode',0,'ghost',0,'step',istep,'verbosity',iverb,'debug',idebug);
|
|
% Determine the points which are covered here
|
|
iiq = ii(col==thiscol);
|
|
jjq = jj(row==thisrow);
|
|
kkq = kk(pln==thispln);
|
|
% Translate to local indexing of loaded data
|
|
iiql = iiq-ib+1;
|
|
jjql = jjq-jb+1;
|
|
kkql = kkq-kb+1;
|
|
% Translate to local indexing of block
|
|
iiqb = iib(col==thiscol);
|
|
jjqb = jjb(row==thisrow);
|
|
kkqb = kkb(pln==thispln);
|
|
% Add loaded data to block
|
|
q(iiqb,jjqb,kkqb) = data(iiql,jjql,kkql);
|
|
end
|
|
end
|
|
end
|
|
end
|