85 lines
2.9 KiB
Matlab
85 lines
2.9 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 to be read
|
|
% Optional input (key/value pair)
|
|
% timestep timestep to be read (default: 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)
|
|
% 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;
|
|
addOptional(par,'timestep',0,@isnumeric);
|
|
addOptional(par,'format','array',@ischar);
|
|
addOptional(par,'verbosity',0,@isnumeric);
|
|
addOptional(par,'debug',0,@isnumeric);
|
|
parse(par,varargin{:});
|
|
istep = par.Results.timestep;
|
|
mlformat = par.Results.format;
|
|
|
|
% Open file
|
|
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
|
obj.open(file);
|
|
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
|