distinguish between high-level and low-level routines
This commit is contained in:
parent
c62cf45452
commit
226dbf38ff
|
|
@ -1,134 +0,0 @@
|
|||
function [q] = read_field_complete_ucf(file,field,varargin)
|
||||
% [data] = read_field_complete_ucf(file,field,varargin)
|
||||
% Reads a specific field from all processor chunks.
|
||||
% Input
|
||||
% file file to be read
|
||||
% field field to be read
|
||||
% {'u','v','w','p','s1','s2',...}
|
||||
% or integer with dataset index (not in tar-mode)
|
||||
% ? step index of step to be read (default: 1)
|
||||
% ? verbosity verbose output? (default: 0)
|
||||
% ? debug debug output? (default: 0)
|
||||
% ? tarmode read from tar-file? (default: 0)
|
||||
% Output
|
||||
% data partial field with dim(nxl+2*ighost,nyl+2*ighost,nzl+2*ighost)
|
||||
|
||||
% Parse optional input arguments
|
||||
par = inputParser;
|
||||
addParamValue(par,'timestep',1,@isnumeric);
|
||||
addParamValue(par,'verbosity',0,@isnumeric);
|
||||
addParamValue(par,'debug',0,@isnumeric);
|
||||
addParamValue(par,'tarmode',0,@isnumeric);
|
||||
parse(par,varargin{:});
|
||||
istep = par.Results.timestep;
|
||||
|
||||
% Parse field
|
||||
if ischar(field)
|
||||
switch field(1)
|
||||
case 'u'; ifield=1; fbase='uvwp';
|
||||
case 'v'; ifield=2; fbase='uvwp';
|
||||
case 'w'; ifield=3; fbase='uvwp';
|
||||
case 'p'; ifield=4; fbase='uvwp';
|
||||
case 's'; ifield=str2double(field(2:end)); fbase='scal';
|
||||
end
|
||||
elseif isnumeric(field)
|
||||
if par.Results.tarmode
|
||||
error('field cannot be numeric, if tar-mode is used.');
|
||||
end
|
||||
ifield=field; fbase='';
|
||||
else
|
||||
error('field must either be numeric or string.');
|
||||
end
|
||||
|
||||
% Open first file
|
||||
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
||||
if par.Results.tarmode
|
||||
fname = sprintf('%s.%05d',fbase,0);
|
||||
obj.opentar(file.pointer(fname));
|
||||
else
|
||||
[fdir,fbase,fext] = fileparts(file);
|
||||
fname = sprintf('%s/%s.%05d',fdir,fbase,0);
|
||||
obj.open(fname);
|
||||
end
|
||||
|
||||
if ~obj.validateType('field')
|
||||
error('read error: no field data.');
|
||||
end
|
||||
|
||||
% Read raw data
|
||||
[data,params] = obj.readSet(istep,ifield);
|
||||
params = cast(params,'double');
|
||||
ighost = params(1);
|
||||
ib = params(2);
|
||||
jb = params(3);
|
||||
kb = params(4);
|
||||
nxl = params(5);
|
||||
nyl = params(6);
|
||||
nzl = params(7);
|
||||
nx = params(8);
|
||||
ny = params(9);
|
||||
nz = params(10);
|
||||
data = reshape(data,nxl+2*ighost,nyl+2*ighost,nzl+2*ighost);
|
||||
if ighost
|
||||
data = data(2:end-1,2:end-1,2:end-1);
|
||||
end
|
||||
|
||||
% Create global array and assign chunk
|
||||
q = zeros(nx,ny,nz,class(data));
|
||||
q(ib:ib+nxl-1,jb:jb+nyl-1,kb:kb+nzl-1) = data;
|
||||
|
||||
% Close the first file
|
||||
obj.close();
|
||||
|
||||
% Now loop consecutively through files
|
||||
ifile = 1;
|
||||
if par.Results.tarmode
|
||||
loopCondition = @(x) file.isSubfile(x);
|
||||
fname = sprintf('%s.%05d',fbase,ifile);
|
||||
else
|
||||
loopCondition = @(x) exist(x,'file');
|
||||
fname = sprintf('%s/%s.%05d',fdir,fbase,ifile);
|
||||
end
|
||||
while loopCondition(fname)
|
||||
% Open file
|
||||
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
||||
if par.Results.tarmode
|
||||
obj.opentar(file.pointer(fname));
|
||||
else
|
||||
obj.open(fname);
|
||||
end
|
||||
|
||||
if ~obj.validateType('field')
|
||||
error('read error: no field data.');
|
||||
end
|
||||
|
||||
% Read raw data
|
||||
[data,params] = obj.readSet(istep,ifield);
|
||||
params = cast(params,'double');
|
||||
ighost = params(1);
|
||||
ib = params(2);
|
||||
jb = params(3);
|
||||
kb = params(4);
|
||||
nxl = params(5);
|
||||
nyl = params(6);
|
||||
nzl = params(7);
|
||||
data = reshape(data,nxl+2*ighost,nyl+2*ighost,nzl+2*ighost);
|
||||
if ighost
|
||||
data = data(2:end-1,2:end-1,2:end-1);
|
||||
end
|
||||
|
||||
% Assign chunk
|
||||
q(ib:ib+nxl-1,jb:jb+nyl-1,kb:kb+nzl-1) = data;
|
||||
|
||||
% Close the first file
|
||||
obj.close();
|
||||
|
||||
% Move on to next file
|
||||
ifile = ifile+1;
|
||||
if par.Results.tarmode
|
||||
fname = sprintf('%s.%05d',fbase,ifile);
|
||||
else
|
||||
fname = sprintf('%s/%s.%05d',fdir,fbase,ifile);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
function [q,x,y,z] = read_field_complete_ucfmf(fdir,iseq,field,varargin)
|
||||
% [q,x,y,z] = read_field_complete_ucfmf(file,field,varargin)
|
||||
% Reads a specific field from all processor chunks.(Multi-file tar version)
|
||||
% Input
|
||||
% fdir directory with files
|
||||
% iseq sequence index
|
||||
% field field to be read
|
||||
% {'u','v','w','p','s1','s2',...}
|
||||
% ? step index of step to be read (default: 1)
|
||||
% ? verbosity verbose output? (default: 0)
|
||||
% ? debug debug output? (default: 0)
|
||||
% Output
|
||||
% q complete field
|
||||
% x,y,z corresponding grid
|
||||
|
||||
% 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.timestep;
|
||||
|
||||
% Parse field
|
||||
if ischar(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='p';
|
||||
otherwise; error('Invalid field: %s',field);
|
||||
end
|
||||
|
||||
% Read parameters
|
||||
fparam = sprintf('%s/parameters_%04d.asc',fdir,iseq);
|
||||
params = read_parameters_ucf(fparam,'tarmode',0);
|
||||
|
||||
% Construct an array with final mesh size
|
||||
nx = params.mesh.(sprintf('nx%s',cmesh));
|
||||
ny = params.mesh.(sprintf('ny%s',cmesh));
|
||||
nz = params.mesh.(sprintf('nz%s',cmesh));
|
||||
q = zeros(nx,ny,nz);
|
||||
|
||||
% Read grid
|
||||
fgrid = sprintf('%s/grid_%04d.bin',fdir,iseq);
|
||||
[x.u,y.u,z.u,x.v,y.v,z.v,x.w,y.w,z.w,x.p,y.p,z.p] = read_grid_ucf(fgrid,'tarmode',0);
|
||||
x = x.(cmesh);
|
||||
y = y.(cmesh);
|
||||
z = z.(cmesh);
|
||||
|
||||
% Get number of processors
|
||||
nprocs = params.parallel.nprocs;
|
||||
|
||||
% Now read chunk by chunk
|
||||
for iproc=0:nprocs-1
|
||||
fq = sprintf('%s/%s_%04d.%05d',fpath,iseq,iproc);
|
||||
[data,ib,jb,kb,nxl,nyl,nzl] = read_field_chunk_ucf(fq,ifield,'tarmode',0,'ghost',0,'step',istep);
|
||||
q(ib:ib+nxl-1,jb:jb+nyl-1,kb:kb+nzl-1) = data;
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
function [q,x,y,z] = read_field_complete_ucftar(file,field,varargin)
|
||||
% [q,x,y,z] = read_field_complete_ucftar(file,field,varargin)
|
||||
% Reads a specific field from all processor chunks.(UCF tar version)
|
||||
% Input
|
||||
% file name of tar-file to be read
|
||||
% field field to be read
|
||||
% {'u','v','w','p','s1','s2',...}
|
||||
% ? step index of step to be read (default: 1)
|
||||
% ? verbosity verbose output? (default: 0)
|
||||
% ? debug debug output? (default: 0)
|
||||
% Output
|
||||
% q complete field
|
||||
% x,y,z corresponding grid
|
||||
|
||||
% 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.timestep;
|
||||
|
||||
% Parse field
|
||||
switch field(1)
|
||||
case 'u'; cmesh = 'u';
|
||||
case 'v'; cmesh = 'v';
|
||||
case 'w'; cmesh = 'w';
|
||||
case 'p'; cmesh = 'p';
|
||||
case 's'; cmesh = 'p';
|
||||
otherwise; error('Invalid field: %s',field);
|
||||
end
|
||||
|
||||
% Open tar file
|
||||
htar = ustar();
|
||||
htar.open(file);
|
||||
|
||||
% Read parameters
|
||||
params = read_parameters_ucf(htar,'tarmode',1);
|
||||
|
||||
% Construct an array with final mesh size
|
||||
nx = params.mesh.(sprintf('nx%s',cmesh));
|
||||
ny = params.mesh.(sprintf('ny%s',cmesh));
|
||||
nz = params.mesh.(sprintf('nz%s',cmesh));
|
||||
q = zeros(nx,ny,nz);
|
||||
|
||||
% Read grid
|
||||
[x.u,y.u,z.u,x.v,y.v,z.v,x.w,y.w,z.w,x.p,y.p,z.p] = read_grid_ucf(htar,'tarmode',1);
|
||||
x = x.(cmesh);
|
||||
y = y.(cmesh);
|
||||
z = z.(cmesh);
|
||||
|
||||
% Get number of processors
|
||||
nprocs = params.parallel.nprocs;
|
||||
|
||||
% Now read chunk by chunk
|
||||
for iproc=0:nprocs-1
|
||||
[data,ib,jb,kb,nxl,nyl,nzl] = read_field_chunk_ucf(htar,field,'tarmode',1,'rank',iproc,'ghost',0,'step',istep);
|
||||
q(ib:ib+nxl-1,jb:jb+nyl-1,kb:kb+nzl-1) = data;
|
||||
end
|
||||
|
||||
% Close tar file
|
||||
htar.close();
|
||||
end
|
||||
Loading…
Reference in New Issue