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 to be read % Optional input (key/value pair) % timestep index of timestep to be read (default: 1) % ghost keep ghost cells? (default: yes) % verbosity verbose output? (default: no) % debug debug output? (default: no) % 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; addOptional(par,'timestep',1,@isnumeric); addOptional(par,'ghost',1,@isnumeric); addOptional(par,'verbosity',0,@isnumeric); addOptional(par,'debug',0,@isnumeric); parse(par,varargin{:}); istep = par.Results.timestep; keepghost = par.Results.ghost; % Open file obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug); obj.open(file); 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