97 lines
3.0 KiB
Matlab
97 lines
3.0 KiB
Matlab
function [q] = read_field_complete_ucf(file,ifield,varargin)
|
|
% [data] = read_field_complete_ucf(file,ifield,varargin)
|
|
% Reads a specific field from all processor chunks.
|
|
% Input
|
|
% file file to be read
|
|
% ifield field to be read
|
|
% 'uvwp': 1:u, 2:v, 3:w, 4:p
|
|
% 'scal': 1:s1, 2:s2, ...
|
|
% Optional input (key/value pair)
|
|
% timestep index of timestep to be read (default: 1)
|
|
% verbosity verbose output? (default: no)
|
|
% debug debug output? (default: no)
|
|
% Output
|
|
% data partial field with dim(nxl+2*ighost,nyl+2*ighost,nzl+2*ighost)
|
|
|
|
% Parse optional input arguments
|
|
par = inputParser;
|
|
addOptional(par,'timestep',1,@isnumeric);
|
|
addOptional(par,'verbosity',0,@isnumeric);
|
|
addOptional(par,'debug',0,@isnumeric);
|
|
parse(par,varargin{:});
|
|
istep = par.Results.timestep;
|
|
|
|
% Parse filename
|
|
[fdir,fbase,fext] = fileparts(file);
|
|
fname = sprintf('%s/%s.%05d',fdir,fbase,0);
|
|
|
|
% Open first file
|
|
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
|
obj.open(fname);
|
|
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;
|
|
fname = sprintf('%s/%s.%05d',fdir,fbase,ifile);
|
|
while exist(fname,'file')
|
|
% Open file
|
|
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
|
obj.open(fname);
|
|
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;
|
|
fname = sprintf('%s/%s.%05d',fdir,fbase,ifile);
|
|
end
|
|
end
|