/[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.3 - (show annotations) (download)
Sun May 2 20:38:03 2010 UTC (15 years, 2 months ago) by gforget
Branch: MAIN
Changes since 1.2: +29 -8 lines
make convert2gcmfaces.m more versatile: it can now handle the
straight global file format, the cube format, and the compact format.

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

  ViewVC Help
Powered by ViewVC 1.1.22