ucftools/matlab/read_grid_ucf.m

68 lines
1.8 KiB
Matlab

function [xu,yu,zu,xv,yv,zv,xw,yw,zw,xp,yp,zp] = read_grid_ucf(file,varargin)
% [xu,yu,zu,xv,yv,zv,xw,yw,zw,xp,yp,zp] = read_grid_ucf(file,varargin)
% Reads staggered grid from ucf file.
% Input
% file file to be read
% Optional input (key/value pair)
% verbosity verbose output? (default: no)
% debug debug output? (default: no)
% Output
% xu,yu,zu velocity grid u
% xv,yv,zv velocity grid v
% xw,yw,zw velocity grid w
% xp,yp,zp pressure grid / scalar grid
% Parse optional input arguments
par = inputParser;
addOptional(par,'verbosity',0,@isnumeric);
addOptional(par,'debug',0,@isnumeric);
parse(par,varargin{:});
% Define sets to be read
sets = {'u','v','w','p'};
nset = numel(sets);
% Open UCF file and read
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
obj.open(file);
% Read raw data
x = cell(1,nset);
y = cell(1,nset);
z = cell(1,nset);
for iset=1:nset
[data,params] = obj.readSet(1,iset);
params = cast(params,'double');
nx = params(1);
ny = params(2);
nz = params(3);
x{iset} = data(1:nx);
y{iset} = data(nx+1:nx+ny);
z{iset} = data(nx+ny+1:nx+ny+nz);
end
% Close UCF file
obj.close();
% Reassign content from loop
iset = find(strcmp(sets,'u'));
xu = x{iset};
yu = y{iset};
zu = z{iset};
iset = find(strcmp(sets,'v'));
xv = x{iset};
yv = y{iset};
zv = z{iset};
iset = find(strcmp(sets,'w'));
xw = x{iset};
yw = y{iset};
zw = z{iset};
iset = find(strcmp(sets,'p'));
xp = x{iset};
yp = y{iset};
zp = z{iset};
end