/[MITgcm]/MITgcm/utils/cs_grid/split_UV_cub.m
ViewVC logotype

Contents of /MITgcm/utils/cs_grid/split_UV_cub.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download)
Thu Sep 15 16:51:14 2005 UTC (17 years, 8 months ago) by jmc
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
FILE REMOVED
moved from utils/cs_grid to utils/matlab/cs_grid.

1 function [u6t,v6t] = split_UV_cub(u3d,v3d,ksign,kad)
2 % [u6t,v6t] = split_UV_cub(u3d,v3d,[ksign,kad])
3 %---------------------------------------------
4 % split 2d/3d arrays u,v to 3d x 6 faces, and:
5 % (kad=1): add 1 column to U and one row to V
6 % => output is u6t(nc+1,nc,[nr],6) & v6t(nc,nc+1,[nr],6)
7 % (kad=2): add 1 column + 2 rows to U and 2 columns + 1 row to V
8 % => output is u6t(nc+1,nc+2,[nr],6) & v6t(nc+2,nc+1,[nr],6)
9 %----------------------------------------------
10 % $Header: /u/gcmpack/MITgcm/utils/cs_grid/split_UV_cub.m,v 1.2 2005/09/06 17:47:43 jmc Exp $
11 % $Name: $
12
13 if nargin < 3 , ksign = 0; end
14 if nargin < 4 , kad = 1; end
15 % ksign = 0 ==> no sign ; ksign = 1 ==> change the sign where needed
16 % ==> in fact, used only if kad=2
17 plmn = 1 - 2*ksign ;
18
19 dims=size(u3d);
20 if dims(1) ~= 6*dims(2),
21 fprintf(' ERROR in split_UV_cub: 1rst array has the wrong shape !\n');
22 fprintf(' dimensions:'); fprintf(' %i',dims); fprintf(' ; => STOP\n');
23 u6t=0; v6t=0; return;
24 end
25 dims=size(v3d); nDim=length(dims);
26 %fprintf(' nDim= %i , dims:',nDim);fprintf(' %i',dims);fprintf('\n');
27 if dims(1) ~= 6*dims(2),
28 fprintf(' ERROR in split_UV_cub: 2nd array has the wrong shape !\n');
29 fprintf(' dimensions:'); fprintf(' %i',dims); fprintf(' ; => STOP\n');
30 u6t=0; v6t=0; return;
31 end
32 nx=dims(1); nc=dims(2); ncp=nc+1; n2p=nc+2;
33 if nDim == 2, nr=1; else nr=prod(dims(3:end)); end
34 %u3d=reshape(u3d,[nx nc nr]);
35 %v3d=reshape(v3d,[nx nc nr]);
36
37 %=================================================================
38
39 u3d=reshape(u3d,[nc 6 nc nr]);
40 v3d=reshape(v3d,[nc 6 nc nr]);
41 u3d=permute(u3d,[1 3 4 2]);
42 v3d=permute(v3d,[1 3 4 2]);
43
44 if kad == 0,
45 %- split on to 6 faces with no overlap:
46 dims(1)=nc;
47 u6t=u3d;
48 v6t=v3d;
49
50 elseif kad == 1,
51
52 dims(1)=ncp;
53 %- split on to 6 faces with overlap in i+1 for u and j+1 for v :
54 u6t=zeros(ncp,nc,nr,6);
55 v6t=zeros(nc,ncp,nr,6);
56 u6t([1:nc],:,:,:)=u3d(:,:,:,:);
57 v6t(:,[1:nc],:,:)=v3d(:,:,:,:);
58
59 u6t(ncp,[1:nc],:,1)=u3d(1,[1:nc],:,2);
60 u6t(ncp,[1:nc],:,2)=v3d([nc:-1:1],1,:,4);
61 u6t(ncp,[1:nc],:,3)=u3d(1,[1:nc],:,4);
62 u6t(ncp,[1:nc],:,4)=v3d([nc:-1:1],1,:,6);
63 u6t(ncp,[1:nc],:,5)=u3d(1,[1:nc],:,6);
64 u6t(ncp,[1:nc],:,6)=v3d([nc:-1:1],1,:,2);
65
66 v6t([1:nc],ncp,:,1)=u3d(1,[nc:-1:1],:,3);
67 v6t([1:nc],ncp,:,2)=v3d([1:nc],1,:,3);
68 v6t([1:nc],ncp,:,3)=u3d(1,[nc:-1:1],:,5);
69 v6t([1:nc],ncp,:,4)=v3d([1:nc],1,:,5);
70 v6t([1:nc],ncp,:,5)=u3d(1,[nc:-1:1],:,1);
71 v6t([1:nc],ncp,:,6)=v3d([1:nc],1,:,1);
72
73 elseif kad == 2,
74
75 dims(1)=ncp;
76 dims(2)=n2p;
77 %- split on to 6 faces:
78 u6t=zeros(ncp,n2p,nr,6);
79 v6t=zeros(n2p,ncp,nr,6);
80 u6t([1:nc],[2:ncp],:,:)=u3d(:,:,:,:);
81 v6t([2:ncp],[1:nc],:,:)=v3d(:,:,:,:);
82
83 %- add overlap in i=nc+1 for u and j=nc+1 for v :
84 u6t(ncp,[2:ncp],:,1)=u3d(1,[1:nc],:,2);
85 u6t(ncp,[2:ncp],:,2)=v3d([nc:-1:1],1,:,4);
86 u6t(ncp,[2:ncp],:,3)=u3d(1,[1:nc],:,4);
87 u6t(ncp,[2:ncp],:,4)=v3d([nc:-1:1],1,:,6);
88 u6t(ncp,[2:ncp],:,5)=u3d(1,[1:nc],:,6);
89 u6t(ncp,[2:ncp],:,6)=v3d([nc:-1:1],1,:,2);
90
91 v6t([2:ncp],ncp,:,1)=u3d(1,[nc:-1:1],:,3);
92 v6t([2:ncp],ncp,:,2)=v3d([1:nc],1,:,3);
93 v6t([2:ncp],ncp,:,3)=u3d(1,[nc:-1:1],:,5);
94 v6t([2:ncp],ncp,:,4)=v3d([1:nc],1,:,5);
95 v6t([2:ncp],ncp,:,5)=u3d(1,[nc:-1:1],:,1);
96 v6t([2:ncp],ncp,:,6)=v3d([1:nc],1,:,1);
97
98 %- add overlap in j=0,nc+1 for u and i=0,nc+1 for v :
99 u6t([1:ncp], 1 ,:,1)=u6t([1:ncp],ncp,:,6);
100 u6t([1:ncp],n2p,:,1)=v6t( 2 ,[ncp:-1:1],:,3)*plmn;
101 u6t([1:ncp], 1 ,:,3)=u6t([1:ncp],ncp,:,2);
102 u6t([1:ncp],n2p,:,3)=v6t( 2 ,[ncp:-1:1],:,5)*plmn;
103 u6t([1:ncp], 1 ,:,5)=u6t([1:ncp],ncp,:,4);
104 u6t([1:ncp],n2p,:,5)=v6t( 2 ,[ncp:-1:1],:,1)*plmn;
105
106 u6t([1:ncp], 1 ,:,2)=v6t(ncp,[ncp:-1:1],:,6)*plmn;
107 u6t([1:ncp],n2p,:,2)=u6t([1:ncp], 2 ,:,3);
108 u6t([1:ncp], 1 ,:,4)=v6t(ncp,[ncp:-1:1],:,2)*plmn;
109 u6t([1:ncp],n2p,:,4)=u6t([1:ncp], 2 ,:,5);
110 u6t([1:ncp], 1 ,:,6)=v6t(ncp,[ncp:-1:1],:,4)*plmn;
111 u6t([1:ncp],n2p,:,6)=u6t([1:ncp], 2 ,:,1);
112
113 v6t( 1 ,[1:ncp],:,1)=u6t([ncp:-1:1],ncp,:,5)*plmn;
114 v6t(n2p,[1:ncp],:,1)=v6t( 2 ,[1:ncp],:,2);
115 v6t( 1 ,[1:ncp],:,3)=u6t([ncp:-1:1],ncp,:,1)*plmn;
116 v6t(n2p,[1:ncp],:,3)=v6t( 2 ,[1:ncp],:,4);
117 v6t( 1 ,[1:ncp],:,5)=u6t([ncp:-1:1],ncp,:,3)*plmn;
118 v6t(n2p,[1:ncp],:,5)=v6t( 2 ,[1:ncp],:,6);
119
120 v6t( 1 ,[1:ncp],:,2)=v6t(ncp,[1:ncp],:,1);
121 v6t(n2p,[1:ncp],:,2)=u6t([ncp:-1:1], 2 ,:,4)*plmn;
122 v6t( 1 ,[1:ncp],:,4)=v6t(ncp,[1:ncp],:,3);
123 v6t(n2p,[1:ncp],:,4)=u6t([ncp:-1:1], 2 ,:,6)*plmn;
124 v6t( 1 ,[1:ncp],:,6)=v6t(ncp,[1:ncp],:,5);
125 v6t(n2p,[1:ncp],:,6)=u6t([ncp:-1:1], 2 ,:,2)*plmn;
126
127 end
128
129 %- restaure the right shape:
130 if nDim == 2,
131 u6t=squeeze(u6t);
132 v6t=squeeze(v6t);
133 else
134 u6t=reshape(u6t,[dims 6]);
135 v6t=reshape(v6t,[dims(2) dims(1) dims(3:end) 6]);
136 end
137
138 return

  ViewVC Help
Powered by ViewVC 1.1.22