1 |
function [z6t] = split_Z_cub(z3d) |
2 |
% [z6t] = split_Z_cub(z3d) |
3 |
%--------------------------------------------- |
4 |
% split 2d/3d arrays z3d to 2d/3d x 6 faces |
5 |
% and add 1 column + 1 row |
6 |
% => output is z6t(nc+1,nc+1,[nr],6) |
7 |
% either input is z3d(nc*6*nc+2,*): includes the 2 missing corners |
8 |
% or input is z3d(nc*6,nc,*): => use the average value (from the 3 |
9 |
% neighbours) for the 2 missing corners |
10 |
%---------------------------------------------- |
11 |
% $Header: $ |
12 |
% $Name: $ |
13 |
|
14 |
dims=size(z3d); nDim=length(dims); |
15 |
%fprintf(' nDim= %i , dims:',nDim);fprintf(' %i',dims);fprintf('\n'); |
16 |
|
17 |
nc=fix((dims(1)-2)/6); nc=fix(sqrt(abs(nc))); |
18 |
if dims(1) == nc*nc*6+2, |
19 |
nr=dims(2); if nDim > 2, nr=prod(dims(2:end)); end |
20 |
nx=6*nc ; nPg=nx*nc; nPts=nPg+2; dims=[nPts 1 dims(2:end)]; |
21 |
z3d=reshape(z3d,[nPts nr]); |
22 |
zzC=z3d(nPg+1:nPg+2,:); z3d=z3d(1:nPg,:); |
23 |
elseif dims(1) == 6*dims(2), |
24 |
if nDim == 2, nr=1; else nr=prod(dims(3:end)); end |
25 |
nc=dims(2); nx=6*nc ; nPg=nx*nc; nPts=nPg+2; |
26 |
zzC=zeros(2,nr); |
27 |
else |
28 |
fprintf(' Error in split_Z_cub: bad input dimensions :'); |
29 |
fprintf(' %i',dims); fprintf('\n'); |
30 |
z6t=0; return |
31 |
end |
32 |
|
33 |
%================================================================= |
34 |
|
35 |
z3d=reshape(z3d,[nc 6 nc nr]); z3d=permute(z3d,[1 3 4 2]); |
36 |
ncp=nc+1; z6t=zeros(ncp,ncp,nr,6); |
37 |
|
38 |
%-- split on to 6 faces: |
39 |
z6t([1:nc],[1:nc],:,:)=z3d; |
40 |
|
41 |
%-- add overlap in i+1 & j+1 : |
42 |
z6t(ncp,[1:nc], :,1)=z3d(1,[1:nc],:,2); |
43 |
z6t(ncp,[2:ncp],:,2)=z3d([nc:-1:1],1,:,4); |
44 |
z6t(ncp,[1:nc], :,3)=z3d(1,[1:nc],:,4); |
45 |
z6t(ncp,[2:ncp],:,4)=z3d([nc:-1:1],1,:,6); |
46 |
z6t(ncp,[1:nc], :,5)=z3d(1,[1:nc],:,6); |
47 |
z6t(ncp,[2:ncp],:,6)=z3d([nc:-1:1],1,:,2); |
48 |
|
49 |
z6t([2:ncp],ncp,:,1)=z3d(1,[nc:-1:1],:,3); |
50 |
z6t([1:nc], ncp,:,2)=z3d([1:nc],1,:,3); |
51 |
z6t([2:ncp],ncp,:,3)=z3d(1,[nc:-1:1],:,5); |
52 |
z6t([1:nc], ncp,:,4)=z3d([1:nc],1,:,5); |
53 |
z6t([2:ncp],ncp,:,5)=z3d(1,[nc:-1:1],:,1); |
54 |
z6t([1:nc], ncp,:,6)=z3d([1:nc],1,:,1); |
55 |
|
56 |
%---------------------------------------------------- |
57 |
|
58 |
%-- missing corners : |
59 |
if dims(1) ~= nPts, |
60 |
%- use the average value (from the 3 neighbours) |
61 |
zzC(1,:)=z3d(1,nc,:,1)+z3d(1,nc,:,3)+z3d(1,nc,:,5); |
62 |
zzC(2,:)=z3d(nc,1,:,2)+z3d(nc,1,:,4)+z3d(nc,1,:,6); |
63 |
zzC=zzC/3; |
64 |
fprintf('split_Z_cub: fills 2 missing corners with local mean value\n'); |
65 |
end |
66 |
%- 1rst (nPg+1) = N.W corner of face 1 |
67 |
z6t(1,ncp,:,1)=zzC(1,:); |
68 |
z6t(1,ncp,:,3)=zzC(1,:); |
69 |
z6t(1,ncp,:,5)=zzC(1,:); |
70 |
%- 2nd (nPg+2) = S.E corner of face 2 |
71 |
z6t(ncp,1,:,2)=zzC(2,:); |
72 |
z6t(ncp,1,:,4)=zzC(2,:); |
73 |
z6t(ncp,1,:,6)=zzC(2,:); |
74 |
|
75 |
if nDim > 2, |
76 |
z6t=reshape(z6t,[ncp ncp dims(3:end) 6]); |
77 |
else |
78 |
z6t=squeeze(z6t); |
79 |
end |
80 |
|
81 |
return |