103 lines
3.2 KiB
Matlab
103 lines
3.2 KiB
Matlab
function [s] = read_scal_complete_ucf(file,varargin)
|
|
% [s] = read_scal_complete_ucf(file,varargin)
|
|
% Reads u,v,w,p from all processor chunks and combines them to a single field.
|
|
% Input
|
|
% file file to be read
|
|
% 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
|
|
% s complete scalar fields with dim(nx,ny,nz,nscal)
|
|
|
|
% 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(fname,'read','verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
|
if ~obj.validateType('field')
|
|
error('read error: no field data.');
|
|
end
|
|
nscal = obj.getNumDatasets(istep);
|
|
|
|
% Read raw data
|
|
q = cell(1,nscal);
|
|
for iset=1:nscal
|
|
[data,params] = obj.readSet(istep,iset);
|
|
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);
|
|
q{iset} = reshape(data,nxl+2*ighost,nyl+2*ighost,nzl+2*ighost);
|
|
if ighost
|
|
q{iset} = q{iset}(2:end-1,2:end-1,2:end-1);
|
|
end
|
|
end
|
|
|
|
% Reassign content from loop and create global arrays
|
|
s = zeros(nx,ny,nz,nscal,class(q{1}));
|
|
for iscal=1:nscal
|
|
s(ib:ib+nxl-1,jb:jb+nyl-1,kb:kb+nzl-1,iscal) = q{iset};
|
|
end
|
|
|
|
% 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(fname,'read','verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
|
if ~obj.validateType('field')
|
|
error('read error: no field data.');
|
|
end
|
|
|
|
% Read raw data
|
|
q = cell(1,nscal);
|
|
for iset=1:nscal
|
|
[data,params] = obj.readSet(istep,iset);
|
|
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);
|
|
q{iset} = reshape(data,nxl+2*ighost,nyl+2*ighost,nzl+2*ighost);
|
|
if ighost
|
|
q{iset} = q{iset}(2:end-1,2:end-1,2:end-1);
|
|
end
|
|
end
|
|
|
|
% Reassign content from loop and create global arrays
|
|
for iscal=1:nscal
|
|
s(ib:ib+nxl-1,jb:jb+nyl-1,kb:kb+nzl-1,iscal) = q{iset};
|
|
end
|
|
|
|
% Close file
|
|
obj.close();
|
|
|
|
% Move on to next file
|
|
ifile = ifile+1;
|
|
fname = sprintf('%s/%s.%05d',fdir,fbase,ifile);
|
|
end
|
|
end
|