/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_IO/convert2gcmfaces.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/convert2gcmfaces.m

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


Revision 1.2 - (show annotations) (download)
Thu Apr 15 23:15:11 2010 UTC (15 years, 3 months ago) by gforget
Branch: MAIN
Changes since 1.1: +20 -25 lines
speeding up compact<->faces format conversion

1 function [v1]=convert2gcmfaces(v0,varargin);
2
3 aa=whos('v0'); doGcm2Faces=strcmp(aa.class,'double');
4
5 if doGcm2Faces;
6
7 if nargin==1; nFaces=5; else; nFaces=varargin{1}; end;
8
9 if nFaces>1;
10
11 nn=size(v0,1);
12 pp=size(v0,2)/nn;
13 mm=(pp+4-nFaces)/4*nn;
14
15 n3=size(v0,3); n4=size(v0,4);
16
17 v00=reshape(v0,[nn*nn*pp n3*n4]);
18 i0=1; i1=nn*mm; v1{1}=reshape(v00(i0:i1,:),[nn mm n3 n4]);
19 i0=i1+1; i1=i1+nn*mm; v1{2}=reshape(v00(i0:i1,:),[nn mm n3 n4]);
20 i0=i1+1; i1=i1+nn*nn; v1{3}=reshape(v00(i0:i1,:),[nn nn n3 n4]);
21 i0=i1+1; i1=i1+nn*mm; v1{4}=reshape(v00(i0:i1,:),[mm nn n3 n4]);
22 i0=i1+1; i1=i1+nn*mm; v1{5}=reshape(v00(i0:i1,:),[mm nn n3 n4]);
23 if nFaces==6;
24 i0=i1+1; i1=i1+nn*nn; v1{6}=reshape(v00(i0:i1,:),[nn nn n3 n4]);
25 end;
26
27 else;
28 v1={v0};
29 end;
30
31 if nFaces==1; gridType='ll'; elseif nFaces==5; gridType='llc'; elseif nFaces==6; gridType='cube'; end;
32 v1=gcmfaces(v1,gridType);
33
34 else;
35
36 nFaces=get(v0,'nFaces');
37
38 if nFaces>1;
39
40 v0_faces=v0; clear v0;
41 for iFace=1:nFaces; eval(['v0{iFace}=get(v0_faces,''f' num2str(iFace) ''');']); end;
42
43 nn=size(v0{1},1); mm=size(v0{1},2);
44 pp=mm/nn*4+nFaces-4;
45
46 n3=size(v0{1},3); n4=size(v0{1},4);
47 v1=NaN*zeros(nn,nn*pp,n3,n4);
48
49 v11=NaN*zeros(nn*nn*pp,n3*n4);
50
51 i0=1; i1=nn*mm; tmp1=reshape(v0{1},[nn*mm n3*n4]); v11(i0:i1,:)=tmp1(:,:);
52 i0=i1+1; i1=i1+nn*mm; tmp1=reshape(v0{2},[nn*mm n3*n4]); v11(i0:i1,:)=tmp1(:,:);
53 i0=i1+1; i1=i1+nn*nn; tmp1=reshape(v0{3},[nn*nn n3*n4]); v11(i0:i1,:)=tmp1(:,:);
54 i0=i1+1; i1=i1+nn*mm; tmp1=reshape(v0{4},[mm*nn n3*n4]); v11(i0:i1,:)=tmp1(:,:);
55 i0=i1+1; i1=i1+nn*mm; tmp1=reshape(v0{5},[mm*nn n3*n4]); v11(i0:i1,:)=tmp1(:,:);
56 if nFaces==6;
57 i0=i1+1; i1=i1+nn*nn; tmp1=reshape(v0{6},[nn*nn n3*n4]); v11(i0:i1,:)=tmp1(:,:);
58 end;
59
60 v1=reshape(v11,[nn nn*pp n3 n4]);
61
62 else;
63 v1=v0{1};
64 end;
65
66 end;
67
68

  ViewVC Help
Powered by ViewVC 1.1.22