102 lines
3.6 KiB
Matlab
102 lines
3.6 KiB
Matlab
function [pp,col,stime] = read_particles_ucf(file,varargin)
|
|
% [pp,col] = read_particles_ucf(file,varargin)
|
|
% Reads particle data from UCF file
|
|
% Input
|
|
% file file name (if tar-mode: ustar handle)
|
|
% ? step timestep to be read (default: 0 [all])
|
|
% ? format MATLAB format (default: 'array')
|
|
% 'array' plain array with dim(ncol.np,nt)
|
|
% 'struct' structure array with short fieldnames
|
|
% 'paraview' structure array with H5Part fieldnames
|
|
% 'cell' cell array with dim(1,nt) and plain arrays with dim(ncol,np) inside
|
|
% ? verbosity verbose output? (default: no)
|
|
% ? debug debug output? (default: no)
|
|
% ? tarmode read from tar-file? (default: 0)
|
|
% ? append read an append file? Only matters for tar archives (default: 0)
|
|
% Output
|
|
% pp particle data in specified format
|
|
% col container map 'char'->'double' which maps quantity names to column index
|
|
% stime simulation time with dim(1,nt)
|
|
|
|
% Parse optional input arguments
|
|
par = inputParser;
|
|
addParamValue(par,'step',0,@isnumeric);
|
|
addParamValue(par,'format','array',@ischar);
|
|
addParamValue(par,'verbosity',0,@isnumeric);
|
|
addParamValue(par,'debug',0,@isnumeric);
|
|
addParamValue(par,'tarmode',0,@isnumeric); % deprecated (automatically checked now)
|
|
addParamValue(par,'append',0,@isnumeric);
|
|
parse(par,varargin{:});
|
|
istep = par.Results.step;
|
|
mlformat = par.Results.format;
|
|
isappend = par.Results.append;
|
|
|
|
% Open file
|
|
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
|
switch class(file)
|
|
case 'char'
|
|
obj.open(file);
|
|
case {'ustar','ucfmulti'}
|
|
if isappend
|
|
ptr = file.pointer('append_particles.bin');
|
|
else
|
|
ptr = file.pointer('particles.bin');
|
|
end
|
|
obj.opentar(ptr);
|
|
otherwise
|
|
error('Input file type not supported: %s',class(file));
|
|
end
|
|
|
|
if ~obj.validateType('particle')
|
|
error('read error: no particle data.');
|
|
end
|
|
|
|
% Get range of steps to be read
|
|
if istep==0
|
|
steps = uint32(1:obj.getNumTimesteps());
|
|
else
|
|
steps = uint32(istep);
|
|
end
|
|
nstepout = numel(steps);
|
|
|
|
% Get simulation time
|
|
stime = obj.getSimulationTime();
|
|
stime = stime(steps);
|
|
|
|
% Read raw data
|
|
for istep=nstepout:-1:1
|
|
[data,params] = obj.readSet(steps(istep),1);
|
|
params = cast(params,'double');
|
|
np = params(1);
|
|
ncol = params(2);
|
|
ncol_rank = params(3);
|
|
ncol_hybrid = params(4);
|
|
ncol_dem = params(5);
|
|
ncol_scalar = params(6);
|
|
data = reshape(data,ncol,np);
|
|
nscal = ncol_scalar/2;
|
|
col = colmap_from_flags(ncol_rank,ncol_hybrid,ncol_dem,nscal);
|
|
|
|
% Parse data to specified format
|
|
switch mlformat
|
|
case 'struct'
|
|
pp(istep) = convert_particles_array2struct(data,col);
|
|
case 'paraview'
|
|
col = convert_colmap_matlab2paraview(col);
|
|
pp(istep) = convert_particles_array2struct(data,col);
|
|
case {'cell','array'}
|
|
pp{istep} = data;
|
|
otherwise
|
|
error('Unknown format: %s',mlformat);
|
|
end
|
|
end
|
|
|
|
% Convert cell array to 3-dim array, if mlformat=='array'
|
|
if strcmp(mlformat,'array')
|
|
pp = cat(3,pp{:});
|
|
end
|
|
|
|
% Close file
|
|
obj.close();
|
|
end
|