/[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.3 by gforget, Sun May 2 20:38:03 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     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');  aa=whos('v0'); doGcm2Faces=strcmp(aa.class,'double');
18    
19  if doGcm2Faces;  if doGcm2Faces;
20    
21    if nargin==1; nFaces=5; else; nFaces=varargin{1}; end;    if nargin==1; nFaces=5; else; nFaces=varargin{1}; end;
22    
23    if nFaces>1;    [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);      nn=size(v0,1);
32      pp=size(v0,2)/nn;      pp=size(v0,2)/nn;
33      mm=(pp+4-nFaces)/4*nn;      mm=(pp+4-nFaces)/4*nn;
34    
     n3=size(v0,3); n4=size(v0,4);  
   
35      v00=reshape(v0,[nn*nn*pp n3*n4]);      v00=reshape(v0,[nn*nn*pp n3*n4]);
36      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]);
37      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 42  if doGcm2Faces;
42         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]);
43      end;      end;
44    
   else;  
     v1={v0};  
45    end;    end;
46    
47    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 51  else;
51    
52    nFaces=get(v0,'nFaces');    nFaces=get(v0,'nFaces');
53    
54    if nFaces>1;    [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;      v0_faces=v0; clear v0;
64      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 82  else;
82    
83     v1=reshape(v11,[nn nn*pp n3 n4]);     v1=reshape(v11,[nn nn*pp n3 n4]);
84    
   else;  
     v1=v0{1};  
85    end;    end;
86    
87  end;  end;

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

  ViewVC Help
Powered by ViewVC 1.1.22