function [s,ib,jb,kb,nxl,nyl,nzl,ighost] = read_scal_chunk_ucf(file,varargin) % [s,ib,jb,kb,nxl,nyl,nzl,ighost] = read_scal_chunk_ucf(file,varargin) % Reads scalar fields from one processor chunk. % Input % file file name (if tar-mode: ustar handle) % ? step index of timestep to be read (default: 1) % ? ghost keep ghost cells? (default: 1) % ? verbosity verbose output? (default: 0) % ? debug debug output? (default: 0) % ? tarmode read from tar-file? (default: 0) % ? rank rank of processor, ignored if not in tarmode (default: 0) % Output % s partial fields with dim(nxl+2*ighost,nyl+2*ighost,nzl+2*ighost,nscal) % ib,jb,kb,... global index of first grid point of the partial field w/o ghost cells % nxl,nyl,nzl,... local field size w/o ghost cells % ighost ghost cell flag % Parse optional input arguments par = inputParser; addParamValue(par,'step',1,@isnumeric); addParamValue(par,'ghost',1,@isnumeric); addParamValue(par,'verbosity',0,@isnumeric); addParamValue(par,'debug',0,@isnumeric); addParamValue(par,'tarmode',0,@isnumeric); % deprecated addParamValue(par,'rank',0,@isnumeric); parse(par,varargin{:}); istep = par.Results.step; keepghost = par.Results.ghost; % Open file obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug); switch class(file) case 'char' obj.open(file); case {'ustar','ucfmulti'} subfile = sprintf('scal.%05d',par.Results.rank); obj.opentar(file.pointer(subfile)); otherwise error('Input file type not supported: %s',class(file)); end if ~obj.validateType('field') error('read error: no field data.'); end nscal = obj.getNumDatasets(istep); % Read raw data s = 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); s{iset} = reshape(data,nxl+2*ighost,nyl+2*ighost,nzl+2*ighost); if ighost && ~keepghost s{iset} = s{iset}(2:end-1,2:end-1,2:end-1); ighost = 0; end end % Close UCF file obj.close(); % Convert cell array to 4-D array s = cat(4,s{:}); end