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

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

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

revision 1.2 by gforget, Thu Apr 15 23:15:11 2010 UTC revision 1.4 by gforget, Wed Nov 3 19:53:13 2010 UTC
# Line 1  Line 1 
1  function [v1]=convert2gcmfaces(v0,varargin);  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');  aa=whos('v0'); doGcm2Faces=strcmp(aa.class,'double');
21    
22  if doGcm2Faces;  if doGcm2Faces;
23    
24    if nargin==1; nFaces=5; else; nFaces=varargin{1}; end;    if nargin==1; nFaces=5; else; nFaces=varargin{1}; end;
25    
26    if nFaces>1;    [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);      nn=size(v0,1);
35      pp=size(v0,2)/nn;      pp=size(v0,2)/nn;
36      mm=(pp+4-nFaces)/4*nn;      mm=(pp+4-nFaces)/4*nn;
37    
     n3=size(v0,3); n4=size(v0,4);  
   
38      v00=reshape(v0,[nn*nn*pp n3*n4]);      v00=reshape(v0,[nn*nn*pp n3*n4]);
39      i0=1; i1=nn*mm; v1{1}=reshape(v00(i0:i1,:),[nn mm n3 n4]);      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]);      i0=i1+1; i1=i1+nn*mm; v1{2}=reshape(v00(i0:i1,:),[nn mm n3 n4]);
# Line 24  if doGcm2Faces; Line 45  if doGcm2Faces;
45         i0=i1+1; i1=i1+nn*nn; v1{6}=reshape(v00(i0:i1,:),[nn nn n3 n4]);         i0=i1+1; i1=i1+nn*nn; v1{6}=reshape(v00(i0:i1,:),[nn nn n3 n4]);
46      end;      end;
47    
   else;  
     v1={v0};  
48    end;    end;
49    
50    if nFaces==1; gridType='ll'; elseif nFaces==5; gridType='llc'; elseif nFaces==6; gridType='cube'; end;    if nFaces==1; gridType='ll'; elseif nFaces==5; gridType='llc'; elseif nFaces==6; gridType='cube'; end;
# Line 35  else; Line 54  else;
54    
55    nFaces=get(v0,'nFaces');    nFaces=get(v0,'nFaces');
56    
57    if nFaces>1;    [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;      v0_faces=v0; clear v0;
67      for iFace=1:nFaces; eval(['v0{iFace}=get(v0_faces,''f' num2str(iFace) ''');']); end;      for iFace=1:nFaces; eval(['v0{iFace}=get(v0_faces,''f' num2str(iFace) ''');']); end;
# Line 59  else; Line 85  else;
85    
86     v1=reshape(v11,[nn nn*pp n3 n4]);     v1=reshape(v11,[nn nn*pp n3 n4]);
87    
   else;  
     v1=v0{1};  
88    end;    end;
89    
90  end;  end;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.22