/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_convert/convert2vector.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_convert/convert2vector.m

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


Revision 1.2 - (hide annotations) (download)
Thu Mar 3 17:04:29 2016 UTC (9 years, 4 months ago) by gforget
Branch: MAIN
Changes since 1.1: +25 -6 lines
- gcmfaces_interp_coeffs.m: add sparse matrix output (for interpolation using convert2vector.m).
- example_interp.m: add sparse matrix method exmaple (inactive).
- convert2vector.m: revised method ('new') that uses gcmfaces (old method remains the default).
- gcmfaces_interp_2d.m: remove extra ';'

1 gforget 1.2 function [a]=convert2vector(b,method);
2     %[a]=CONVERT2VECTOR(b,method);
3     % converts gcmfaces object b to vector format a -- and vice versa
4     % when b is instead a vector obtained ealier using convert2vector.
5 gforget 1.1 %
6 gforget 1.2 % With the 'new' method: each 2D field becomes a column vector,
7     % while the other dimensions remain the same; convert2gcmfaces is used.
8     % With the 'old' method (default): convert2array is used and the third+
9     % dimensions of b get conflated in the column vector length.
10     %
11     % The 'old' method will get removed after updating routines that use convert2vector.
12 gforget 1.1
13     global mygrid;
14    
15     if isa(b,'gcmfaces'); do_gcmfaces2vector=1; else; do_gcmfaces2vector=0; end;
16 gforget 1.2 if isempty(whos('method')); method='old'; end;
17    
18     if strcmp(method,'new');
19     if do_gcmfaces2vector;
20     bb=convert2gcmfaces(b);
21     siz=size(bb); if length(siz)==2; siz=[siz 1]; end;
22     a=reshape(bb,[prod(siz(1:2)) siz(3:end)]);
23     else;
24     bb=convert2gcmfaces(mygrid.XC);
25     siz=size(b);
26     bb=reshape(b,[size(bb) siz(2:end)]);
27     a=convert2gcmfaces(bb);
28     end;
29     return;
30     end;
31 gforget 1.1
32     if do_gcmfaces2vector;
33     bb=convert2array(b);
34     a=bb(:);
35     else;
36     bb=convert2array(mygrid.XC);
37     if mod(length(b(:)),length(bb(:)))~=0;
38     error('vector length is inconsistent with gcmfaces objects');
39     else;
40     n3=length(b(:))/length(bb(:));
41     end;
42     b=reshape(b,[size(bb) n3]);
43     a=convert2array(b);
44     end;
45    
46    
47    

  ViewVC Help
Powered by ViewVC 1.1.22