Back to home page

MITgcm

 
 

    


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

view on githubraw file Latest commit 4ec37fd8 on 2023-10-03 22:00:32 UTC
4ec37fd829 Jean*0001 %- this is an example which do conversion between
                0002 % a) old-format (not compact) to compact format
                0003 % b) compact-format to per face format (matlab structure)
                0004 
                0005  rgbDim=[90 270 90];
                0006 %rgbDim=[1 1 1]*32;
                0007 
                0008 %- set all 6 faces dimensions
                0009  nR=rgbDim(1); nG=rgbDim(2); nB=rgbDim(3);
                0010  nf=ones(6,2);
                0011  nf(1,:)=[nR nG]; nf(2,:)=[nB nG]; nf(3,:)=[nB nR];
                0012  nf(4,:)=[nG nR]; nf(5,:)=[nG nB]; nf(6,:)=[nR nB];
                0013  fdim=prod(nf,2); fd2= cumsum(fdim); fd1=fd2-fdim+1;
                0014 
                0015  namf='XC';
                0016  namf=['res_s00/',namf]; oldFormat=1;
                0017 %namf=['res_n00/',namf]; oldFormat=0;
                0018 
                0019 %- read file:
                0020 fprintf(['reading file: ',namf,' ...']);TimeT0=clock;
                0021 v0=rdmds(namf);
                0022 TimeT1=clock; fprintf(' (took %6.4f s)\n',etime(TimeT1,TimeT0));
                0023 dim0=size(v0); ndims=length(dim0);
                0024 
                0025 if oldFormat,
                0026 %- with old format, cannot guess Nb of faces to process --> specify it here:
                0027 %- default = 6 ; polar-cap (with or without missing tiles) = 5
                0028 % NOTE: has changed (2007-03-21) rdmds so that it always return
                0029 %       a full domain array (filling up for missing tiles)
                0030  nFaces=6;
                0031 
                0032  lgx=nR+2*nB+2*nG+nR; lgy=nG;
                0033  if nFaces==5, lgx=lgx-nR; end %- face 6 missing
                0034 
                0035 %- field was read from standard (old) format file (global or tiled):
                0036 %  expected size: lgx * lgy ; transfert v0 -> v1 in compact format
                0037  nPg=fd2(nFaces); ib=0;
                0038  if ndims == 2,
                0039   v1=zeros(nPg,1); dim1=[nPg 1];
                0040   for n=1:nFaces
                0041    vv=v0(ib+1:ib+nf(n,1),1:nf(n,2)); %- extract face n
                0042    v1(fd1(n):fd2(n),1)=reshape(vv,[fdim(n) 1]);
                0043    ib=ib+nf(n,1);
                0044   end
                0045  else
                0046   n3=prod(dim0(3:end));
                0047   v1=zeros(nPg,1,n3);
                0048   for n=1:nFaces
                0049    vv=v0(ib+1:ib+nf(n,1),1:nf(n,2),:); %- extract face n
                0050    v1(fd1(n):fd2(n),1,:)=reshape(vv,[fdim(n) 1 n3]);
                0051    ib=ib+nf(n,1);
                0052   end
                0053   dim1=[nPg 1 dim0(3:end)];
                0054   v1=reshape(v1,dim1);
                0055 end
                0056 
                0057 %-- end olfFormat
                0058 end
                0059 
                0060 if ~oldFormat,
                0061 %- field was read from compact (new) format file (global or tiled):
                0062 %  just copy to v1:
                0063  v1=v0;
                0064  nPg=dim0(1)*dim0(2);
                0065 %-- check that number of points "nPg" matches fd2(nFaces)
                0066  [N]=find(fd2 == nPg);
                0067  if length(N) == 1, nFaces=N; else
                0068    fprintf(' # of points nPg= %i do not match any Nb faces (fd2):\n',nPg);
                0069    fprintf(' fd2='); fprintf(' %i ,',fd2); fprintf('\n');
                0070    error('check size of (compact fmt) input !')
                0071  end
                0072  if ndims == 2, dim1=[nPg 1]; else dim1=[nPg 1 dim0(3:end)]; end
                0073  v1=reshape(v1,dim1);
                0074 end
                0075 
                0076 %- put variable into matlab structure "vF", with 6 faces: vF.f001, vF.f002,  ...
                0077  if ndims == 2, dim1=[dim1 1]; end; n3=prod(dim1(3:end));
                0078  v1=reshape(v1,[nPg n3]);
                0079  clear vF
                0080  for n=1:nFaces,
                0081   v1f=reshape(v1(fd1(n):fd2(n),:),[nf(n,:) dim1(3:end)]);
                0082   nvar=sprintf('vF.f%3.3i=v1f;',n); eval(nvar)
                0083  end
                0084 
                0085 return
                0086 %----------------------------------------------------------------------
                0087 %- make a plot to check
                0088 figure(1);clf; ccB=[0 0];
                0089 xyP=zeros(6,4);
                0090 xyP(1,:)=[0.05  0.05  0.20  0.72];
                0091 xyP(2,:)=[0.29  0.05  0.20  0.72];
                0092 xyP(3,:)=[0.29  0.80  0.20  0.18];
                0093 xyP(4,:)=[0.53  0.05  0.20  0.72];
                0094 xyP(5,:)=[0.77  0.05  0.20  0.72];
                0095 xyP(6,:)=[0.77  0.80  0.20  0.18];
                0096 
                0097 k=1; ccB=[-1 1]*190;
                0098 for n=1:nFaces,
                0099  nvar=sprintf('var=vF.f%3.3i;',n); eval(nvar);
                0100  if ndims > 2, var=var(:,:,k); end
                0101  if n > 3, var=fliplr(var'); end
                0102  AA=axes('position',xyP(n,:));
                0103  imagesc(var'); set(gca,'YDir','normal');
                0104  if ccB(1) < ccB(2), caxis(ccB); end
                0105 end
                0106 H=colorbar('peer',AA,'North');
                0107 set(H,'Position',[xyP(4,1) 0.90 xyP(4,3) 0.020]);