1 |
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 |
% |
6 |
% With the 'new' method (default): each 2D field becomes a column vector, |
7 |
% while the other dimensions remain the same; convert2gcmfaces is used. |
8 |
% With the 'old' method : 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 |
|
13 |
global mygrid; |
14 |
|
15 |
if isa(b,'gcmfaces'); do_gcmfaces2vector=1; else; do_gcmfaces2vector=0; end; |
16 |
if isempty(whos('method')); method='new'; 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 |
end; |
30 |
|
31 |
if strcmp(method,'old'); |
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 |
end; |
46 |
|
47 |
|
48 |
|