Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/cs_grid/tiles.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
22586ff4d2 Alis*0001 function [a] = tile(b,varargin)
83ce4d2aa6 Alis*0002 % a=tile(b,n);
                0003 %
                0004 % Extract single tile from cubed array
                0005 %
                0006 % b can have dimensions (M*6,M,Nr) or (M,M,Nr,6)
                0007 %
                0008 % n can be vector of integers between 1 and 6
f8d374081f Jean*0009 %
                0010 % Written by adcroft@.mit.edu, 2001.
22586ff4d2 Alis*0011 if nargin==1
                0012  n=1:6;
                0013 else
                0014  n=varargin{1};
                0015 end
83ce4d2aa6 Alis*0016 
                0017 if min(n)<1 | max(n)>6
                0018  disp(sprintf('n=',n));
                0019  error('tile: second argument n is out of range');
                0020 end
                0021 
                0022 if size(b,ndims(b))==6
                0023  switch ndims(b)
                0024   case 3,
                0025    a=b(:,:,n);
                0026   case 4,
                0027    a=b(:,:,:,n);
                0028   otherwise
                0029    error('tile: it seems that b has too many dimensions');
                0030  end
                0031 elseif size(b,2)==6
                0032  m=size(b,1);
                0033  k=1;
                0034  for N=n;
                0035  switch ndims(b)
                0036   case 3,
                0037    a(:,:,k)=squeeze(b(:,N,:));
                0038   case 4,
                0039    a(:,:,:,k)=squeeze(b(:,N,:,:));
                0040   otherwise
                0041    error('tile: it seems that b has too many dimensions');
                0042  end
                0043  k=k+1;
                0044  end
                0045 elseif size(b,1)==size(b,2)*6
                0046  m=size(b,2);
                0047  k=1;
                0048  for N=n;
                0049  switch ndims(b)
                0050   case 2,
                0051    a(:,:,k)=b((N-1)*m+1:N*m,:);
                0052   case 3,
                0053    a(:,:,:,k)=b((N-1)*m+1:N*m,:,:);
                0054   otherwise
                0055    error('tile: it seems that b has too many dimensions');
                0056  end
                0057  k=k+1;
                0058  end
                0059 else
                0060  disp(sprintf('Size(b) = %i %i %i %i %i %i',size(b)));
                0061  error('tile: Size of first argument is not consistent with cubed array');
                0062 end