76 lines
2.6 KiB
Matlab
76 lines
2.6 KiB
Matlab
function [] = write_scal_complete_ucf(file,s,ibegp,iendp,jbegp,jendp,kbegp,kendp,time,varargin)
|
|
% [] = write_scal_complete_ucf(file,s,ibegp,iendp,jbegp,jendp,kbegp,kendp,time,varargin)
|
|
% Writes a complete scalar field to UCF chunks.
|
|
% Input
|
|
% file file to be written (the extension will be replaced by the proc rank)
|
|
% s full scalar field with dim(nx,ny,nz,nscal)
|
|
% ibegp,jbegp,kbegp arrays with length(n.proc) with processor grid
|
|
% iendp,jendp,kendp """
|
|
% time simulation time
|
|
% Optional input (key/value pair)
|
|
% 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{:});
|
|
|
|
% Parse filename
|
|
[fdir,fbase,fext] = fileparts(file);
|
|
fbasepath = fullfile(fdir,fbase);
|
|
|
|
nxprocs = numel(ibegp);
|
|
nyprocs = numel(jbegp);
|
|
nzprocs = numel(kbegp);
|
|
|
|
nx = size(s,1);
|
|
ny = size(s,2);
|
|
nz = size(s,3);
|
|
nscal = size(s,4);
|
|
|
|
for ixproc=0:nxprocs-1
|
|
for iyproc=0:nyprocs-1
|
|
for izproc=0:nzprocs-1
|
|
[iproc] = locfun_proc_id(ixproc,iyproc,izproc,nxprocs,nyprocs,nzprocs);
|
|
fname = sprintf('%s.%05d',fbasepath,iproc);
|
|
|
|
% Extract local indices
|
|
ighost = 0;
|
|
ib = ibegp(ixproc+1);
|
|
ie = iendp(ixproc+1);
|
|
jb = jbegp(iyproc+1);
|
|
je = jendp(iyproc+1);
|
|
kb = kbegp(izproc+1);
|
|
ke = kendp(izproc+1);
|
|
nxl = ie-ib+1;
|
|
nyl = je-jb+1;
|
|
nzl = ke-kb+1;
|
|
|
|
% Create a new chunk file
|
|
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
|
obj.create(fname,'type','field','rank',[iproc,ixproc,iyproc,izproc],'endian',par.Results.endian);
|
|
obj.appendStep(time);
|
|
|
|
% Write data field by field
|
|
for iscal=1:nscal
|
|
params = int64([ighost,ib,jb,kb,nxl,nyl,nzl,nx,ny,nz]);
|
|
data = s(ib:ie,jb:je,kb:ke,iscal);
|
|
obj.appendSet(data,params);
|
|
end
|
|
|
|
% Close chunk file
|
|
obj.close();
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function [ind] = locfun_proc_id(ii,jj,kk,nx,ny,nz)
|
|
% local version of 'sub2ind_zero_row'
|
|
ind=ii*ny*nz+jj*nz+kk;
|
|
end
|