/[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.4 - (show annotations) (download)
Wed Nov 3 19:53:13 2010 UTC (14 years, 8 months ago) by gforget
Branch: MAIN
Changes since 1.3: +8 -5 lines
add gcmfaces_verbose switch

1 function [v1]=convert2gcmfaces(v0,varargin);
2
3 global fileFormat;
4 if isempty(fileFormat);
5 global gcmfaces_verbose;
6 if gcmfaces_verbose;
7 fprintf('\nconvert2gcmfaces.m init: there are several supported file conventions. \n');
8 fprintf(' By default gcmfaces assumes MITgcm type binary formats as follows: \n')
9 fprintf(' (1 face) straight global format; (4 or 5 faces) compact global format\n');
10 fprintf(' (6 faces) cube format with one face after the other. \n');
11 fprintf(' If this is inadequate, you can change the format below.\n\n');
12 end;
13 if nargin==1; nFaces=5; else; nFaces=varargin{1}; end;
14 if nFaces==1; fileFormat='straight';
15 elseif nFaces==6; fileFormat='cube';
16 else; fileFormat='compact';
17 end;
18 end;
19
20 aa=whos('v0'); doGcm2Faces=strcmp(aa.class,'double');
21
22 if doGcm2Faces;
23
24 if nargin==1; nFaces=5; else; nFaces=varargin{1}; end;
25
26 [n1,n2,n3,n4]=size(v0);
27
28 if strcmp(fileFormat,'straight');
29 v1={v0};
30 elseif strcmp(fileFormat,'cube');
31 for ii=1:6; v1{ii}=v0(n2*(ii-1)+[1:n2],:,:,:); end;
32 elseif strcmp(fileFormat,'compact');
33
34 nn=size(v0,1);
35 pp=size(v0,2)/nn;
36 mm=(pp+4-nFaces)/4*nn;
37
38 v00=reshape(v0,[nn*nn*pp n3*n4]);
39 i0=1; i1=nn*mm; v1{1}=reshape(v00(i0:i1,:),[nn mm n3 n4]);
40 i0=i1+1; i1=i1+nn*mm; v1{2}=reshape(v00(i0:i1,:),[nn mm n3 n4]);
41 i0=i1+1; i1=i1+nn*nn; v1{3}=reshape(v00(i0:i1,:),[nn nn n3 n4]);
42 i0=i1+1; i1=i1+nn*mm; v1{4}=reshape(v00(i0:i1,:),[mm nn n3 n4]);
43 i0=i1+1; i1=i1+nn*mm; v1{5}=reshape(v00(i0:i1,:),[mm nn n3 n4]);
44 if nFaces==6;
45 i0=i1+1; i1=i1+nn*nn; v1{6}=reshape(v00(i0:i1,:),[nn nn n3 n4]);
46 end;
47
48 end;
49
50 if nFaces==1; gridType='ll'; elseif nFaces==5; gridType='llc'; elseif nFaces==6; gridType='cube'; end;
51 v1=gcmfaces(v1,gridType);
52
53 else;
54
55 nFaces=get(v0,'nFaces');
56
57 [n1,n2,n3,n4]=size(v0{1});
58
59 if strcmp(fileFormat,'straight');
60 v1=v0{1};
61 elseif strcmp(fileFormat,'cube');
62 v1=zeros(n2*6,n2,n3,n4);
63 for ii=1:6; v1([1:n2]+(ii-1)*n2,:,:,:)=v0{ii}; end;
64 elseif strcmp(fileFormat,'compact');
65
66 v0_faces=v0; clear v0;
67 for iFace=1:nFaces; eval(['v0{iFace}=get(v0_faces,''f' num2str(iFace) ''');']); end;
68
69 nn=size(v0{1},1); mm=size(v0{1},2);
70 pp=mm/nn*4+nFaces-4;
71
72 n3=size(v0{1},3); n4=size(v0{1},4);
73 v1=NaN*zeros(nn,nn*pp,n3,n4);
74
75 v11=NaN*zeros(nn*nn*pp,n3*n4);
76
77 i0=1; i1=nn*mm; tmp1=reshape(v0{1},[nn*mm n3*n4]); v11(i0:i1,:)=tmp1(:,:);
78 i0=i1+1; i1=i1+nn*mm; tmp1=reshape(v0{2},[nn*mm n3*n4]); v11(i0:i1,:)=tmp1(:,:);
79 i0=i1+1; i1=i1+nn*nn; tmp1=reshape(v0{3},[nn*nn n3*n4]); v11(i0:i1,:)=tmp1(:,:);
80 i0=i1+1; i1=i1+nn*mm; tmp1=reshape(v0{4},[mm*nn n3*n4]); v11(i0:i1,:)=tmp1(:,:);
81 i0=i1+1; i1=i1+nn*mm; tmp1=reshape(v0{5},[mm*nn n3*n4]); v11(i0:i1,:)=tmp1(:,:);
82 if nFaces==6;
83 i0=i1+1; i1=i1+nn*nn; tmp1=reshape(v0{6},[nn*nn n3*n4]); v11(i0:i1,:)=tmp1(:,:);
84 end;
85
86 v1=reshape(v11,[nn nn*pp n3 n4]);
87
88 end;
89
90 end;
91
92

  ViewVC Help
Powered by ViewVC 1.1.22