ucftools/matlab/write_particles_ucf.m

47 lines
1.8 KiB
Matlab

function [] = write_particles_ucf(file,pp,col,time,varargin)
% [] = write_particles_ucf(file,pp,col,time,varargin)
% Writes particles data into a UCF file.
% Input
% file file to be written (the extension will be replaced by the proc rank)
% pp particle data in 'array' format with dim(ncol,np,nt)
% col particle column map. CAUTION: data is not rearranged according to colmap yet!!!
% time simulation time with dim(nt)
% ? endian endianess of the file as used by fopen (default: 'n')
% ? verbosity verbose output? (default: no)
% ? debug debug output? (default: no)
% Parse variable input
par = inputParser;
addParamValue(par,'endian','n',@ischar);
addParamValue(par,'verbosity',0,@isnumeric);
addParamValue(par,'debug',0,@isnumeric);
parse(par,varargin{:});
ncol = size(pp,1);
np = size(pp,2);
[ncolref,ncol_rank,ncol_hybrid,ncol_dem,ncol_scal] = ncol_from_colmap(col);
nt = size(pp,3);
% Check for consistency
if ncol~=col.Count || ncol~=ncolref
error('Particle data does not match column map.');
end
if nt~=numel(time)
error('Number of time steps must match the number of time values given. %d,%d',nt,numel(time));
end
% Create file
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
obj.create(file,'type','particle','endian',par.Results.endian);
% Add particle data step by step
for it=1:nt
obj.appendStep(time(it));
params = int64([np,ncol,ncol_rank,ncol_hybrid,ncol_dem,ncol_scal]);
data = pp(:,:,it);
obj.appendSet(data,params);
end
% Close file
obj.close();
end