/[MITgcm]/MITgcm_contrib/gael/matlab_class/@gcmfaces/mk3D.m
ViewVC logotype

Diff of /MITgcm_contrib/gael/matlab_class/@gcmfaces/mk3D.m

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

revision 1.1 by gforget, Wed Feb 10 14:43:47 2010 UTC revision 1.3 by gforget, Sat Apr 24 22:08:10 2010 UTC
# Line 1  Line 1 
1  function a = mk3D(b,c)  function a = mk3D(b,c)
2    %function a = mk3D(b,c)
3    %  => makes a 3D field of the same format as c, based on b, which may be
4    %  either       [A] a 2D field consistent with c(:,:,1)
5    %  or           [B] a 1D vector concistent
6    %  
7    %  in case [A], if b has more that 2D, then the first 2D field is used
8    %  in case [B], if the length of b is n3=size(c.f1,3), then we map b(k) to
9    %  a(:,:,k). Otherwise we map b(1) to a(:,:,k) and issue a warning.
10    
11  a=c;  a=c;
12    n3=size(a.f1,3);
13    
14  if isa(b,'gcmfaces');  if isa(b,'gcmfaces');
15     %go from 2D field to 3D field     %go from 2D field to 3D field
    for kk=1:size(a.f1,3)  
16        for iFace=1:a.nFaces;        for iFace=1:a.nFaces;
17           iF=num2str(iFace);           iF=num2str(iFace);
18           eval(['a.f' iF '(:,:,kk)=b.f' iF '(:,:);']);           eval(['tmp1=b.f' iF ';']); [n1,n2]=size(tmp1); tmp1=tmp1(:);
19             tmp1=tmp1*ones(1,size(a.f1,3)); tmp1=reshape(tmp1,[n1 n2 n3]);
20             eval(['a.f' iF '=tmp1;']);
21        end;        end;
    end;  
22  elseif isa(b,'double');  elseif isa(b,'double');
23     for kk=1:size(a.f1,3)        if length(b)~=1&length(b)~=n3; fprintf('     mk3D warning: b(1) is used \n'); end;
24          if length(b)~=n3; b=b(1)*ones(1,n3); end;
25          if size(b,1)~=1; b=b'; end;
26        for iFace=1:a.nFaces;          for iFace=1:a.nFaces;  
27           iF=num2str(iFace);           iF=num2str(iFace);
28           eval(['a.f' iF '(:,:,kk)=b(kk);']);           eval(['tmp1=c.f' iF ';']); tmp2=size(tmp1); n1=tmp2(1); n2=tmp2(2);
29             tmp1=reshape(ones(n1*n2,1)*b,[n1 n2 n3]);;
30             eval(['a.f' iF '=tmp1;']);
31        end;        end;
    end;  
32  else  else
33     error('indexing not supported by gcmfaces objects')     error('indexing not supported by gcmfaces objects')
34  end  end

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.22