94 lines
2.5 KiB
Matlab
94 lines
2.5 KiB
Matlab
function [xu,yu,zu,xv,yv,zv,xw,yw,zw,xp,yp,zp,xs,ys,zs] = read_grid_ucf(file,varargin)
|
|
% [xu,yu,zu,xv,yv,zv,xw,yw,zw,xp,yp,zp,xs,ys,zs] = read_grid_ucf(file,varargin)
|
|
% Reads staggered grid from ucf file.
|
|
% Input
|
|
% file file to be read
|
|
% ? verbosity verbose output? (default: 0)
|
|
% ? debug debug output? (default: 0)
|
|
% ? tarmode read from tar-file? (default: 0)
|
|
% Output
|
|
% xu,yu,zu velocity grid u
|
|
% xv,yv,zv velocity grid v
|
|
% xw,yw,zw velocity grid w
|
|
% xp,yp,zp pressure grid
|
|
% xs,ys,zs scalar grid
|
|
|
|
% Parse optional input arguments
|
|
par = inputParser;
|
|
addParamValue(par,'verbosity',0,@isnumeric);
|
|
addParamValue(par,'debug',0,@isnumeric);
|
|
addParamValue(par,'tarmode',0,@isnumeric); % deprecated
|
|
parse(par,varargin{:});
|
|
|
|
% Open UCF file and read
|
|
obj = ucf('verbosity',par.Results.verbosity,'debug',par.Results.debug);
|
|
switch class(file)
|
|
case 'char'
|
|
obj.open(file);
|
|
case {'ustar','ucfmulti'}
|
|
ptr = file.pointer('grid.bin');
|
|
obj.opentar(ptr);
|
|
otherwise
|
|
error('Input file type not supported: %s',class(file));
|
|
end
|
|
|
|
% Define sets to be read
|
|
isDualMesh=(obj.UCFVersion>=2);
|
|
if isDualMesh
|
|
sets = {'u','v','w','p','s'};
|
|
else
|
|
sets = {'u','v','w','p'};
|
|
end
|
|
nset = numel(sets);
|
|
|
|
% 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{iset} = params(1);
|
|
ny{iset} = params(2);
|
|
nz{iset} = params(3);
|
|
x{iset} = data(1:nx{iset});
|
|
y{iset} = data(nx{iset}+1:nx{iset}+ny{iset});
|
|
z{iset} = data(nx{iset}+ny{iset}+1:nx{iset}+ny{iset}+nz{iset});
|
|
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};
|
|
|
|
if isDualMesh
|
|
iset = find(strcmp(sets,'s'));
|
|
xs = x{iset};
|
|
ys = y{iset};
|
|
zs = z{iset};
|
|
else
|
|
xs = xp;
|
|
ys = yp;
|
|
zs = zp;
|
|
end
|
|
end
|