/[MITgcm]/MITgcm_contrib/high_res_cube/matlab-grid-generator/bin/dimsum.m
ViewVC logotype

Contents of /MITgcm_contrib/high_res_cube/matlab-grid-generator/bin/dimsum.m

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


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Tue Nov 11 18:08:08 2003 UTC (23 years ago) by cnh
Branch: MAIN, initial
CVS Tags: baseline, HEAD
Changes since 1.1: +0 -0 lines
Checking in work done with Dimitri on high-resolution cube gridding and parallel 
communications. 
   o code is in a contrib experiment for now so we can continue collaborating
     on it. However most code is general and will be moved into main branch once 
     it is fully hardened.
   o There are README files in the contrib root and in the subdirectories that
     explain the contents

1 function ds = dimsum(A,d,varargin);
2 % Matrix multiply a vector using a multi-dimensional array.
3 % This allows weighted summation in a 3-D/4-D arrays over
4 % a single index.
5 %
6 % >> size(T)
7 % ans =
8 % 128 64 10 23
9 % >> size(dz)
10 % ans =
11 % 10 1
12 % >> vintegral=dimsum(T,dz,3);
13 % >> size(vintegral)
14 % ans =
15 % 128 64 23
16
17 error(nargchk(2,3,nargin))
18
19 if size(d,2) ~= 1, error('Second argument must be a vector'); end
20
21 if nargin==3
22 dim=varargin{1};
23 else
24 if sum( size(A)==size(d,1) )==1
25 dim=find( size(A)==size(d,1));
26 else
27 error('One and only one dimension must match unless you specify the dimension to sum')
28 end
29 end
30
31 if size(A,dim) ~= size(d,1)
32 error('Dimensions of matrix and vector do not match')
33 end
34
35 dims=[size(A) 1];
36 nd=size(d,1);
37 ip=[dim:ndims(A)+1 1:dim-1];
38 A=permute(A,ip);
39 A=A(1:nd,:);
40 ds=A'*d;
41
42 dims(dim)=1;
43 dims=dims(ip);
44 ds=reshape(ds,dims);
45 ds=squeeze(ipermute(ds,ip));

  ViewVC Help
Powered by ViewVC 1.1.22