Warning, /utils/matlab/cs_grid/latloncap/plot_faces.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
d755cc892a Jean*0001 function plot_faces(nfg,vF,k,ccB,rgbDim);
0002 % plot_faces(nfg,vF,k [,ccB,rgbDim]);
0003 %
0004 % make 1 figure (fig. number = nfg) composed of Nface parts
0005 % with color range ccB(1),ccB(2) (default = ccB=[0 0] = no call to caxis)
4ec37fd829 Jean*0006 % corresponding to level k (enter k=0 if 2D field)
d755cc892a Jean*0007 % a) of the structured array "vF": vF.f001 = face 1, vF.f002 = face 2 ...
0008 % or
0009 % b) of simple array "vF" in compact format (with cs-grid dimensions =
4ec37fd829 Jean*0010 % rgbDim = [nR nG nB] )
d755cc892a Jean*0011
0012 if nargin < 4, ccB=[0 0]; end
0013
0014 %- extract list of faces:
0015 if isstruct(vF),
0016 compact=0;
0017 % convention: faces identificator is "f{n}" (face number n written with 3 digits)
0018 listV=fieldnames(vF); listF=[];
0019 for i=1:size(listV,1)
0020 cvar=char(listV(i));
0021 if length(cvar) == 4 & strncmpi('f00',cvar,3),
0022 if isempty(listF), listF=cvar; else listF=char(listF,cvar); end
4ec37fd829 Jean*0023 %- get facet dimensions:
0024 var=vF.(cvar);
0025 if i == 1, nR=size(var,1); nG=size(var,2);
0026 elseif i==2, nB=size(var,1); end
d755cc892a Jean*0027 end
0028 end
0029 listF=cellstr(listF);
4ec37fd829 Jean*0030 nFaces=size(listF,1); compact=0;
d755cc892a Jean*0031 else
0032 %- compact format:
4ec37fd829 Jean*0033 compact=1;
d755cc892a Jean*0034 dim0=size(vF); ndims=length(dim0);
0035 if ndims == 2, nz=1; else nz=dim0(3); end
4ec37fd829 Jean*0036 nPg=dim0(1)*dim0(2);
0037 vv=reshape(vF,[nPg nz]);
0038 if nargin < 5,
0039 % set default for nR,nG,nB (only used for compact fmt):
0040 % rgbDim=[90 270 90];
d755cc892a Jean*0041 n1=dim0(1); n2=dim0(2);
054bdac3e5 Jean*0042 n2=n2-n1; if rem(n2,4*n1) ~= 0, n2=n2-n1; end
d755cc892a Jean*0043 if rem(n2,4) ~= 0,
0044 error('compact fmt input => Need grid 3 dims (rgbDim, 5th Arg)')
0045 end
4ec37fd829 Jean*0046 rgbDim=[n1 n2/4 n1];
d755cc892a Jean*0047 end
4ec37fd829 Jean*0048 nR=rgbDim(1); nG=rgbDim(2); nB=rgbDim(3);
d755cc892a Jean*0049 %- set all 6 faces dimensions
0050 nf=ones(6,2);
4ec37fd829 Jean*0051 nf(1,:)=[nR nG]; nf(2,:)=[nB nG]; nf(3,:)=[nB nR];
0052 nf(4,:)=[nG nR]; nf(5,:)=[nG nB]; nf(6,:)=[nR nB];
d755cc892a Jean*0053 fdim=prod(nf,2); fd2= cumsum(fdim); fd1=fd2-fdim+1;
4ec37fd829 Jean*0054 %-- check that "number of point "nPg" matches fd2(nFaces)
0055 [N]=find(fd2 == nPg);
0056 if length(N) == 1, nFaces=N; else
0057 fprintf(' # of points nPg= %i do not match any Nb faces (fd2):\n',nPg);
0058 fprintf(' fd2='); fprintf(' %i ,',fd2); fprintf('\n');
0059 error('check size of (compact fmt) input !')
0060 end
d755cc892a Jean*0061 end
0062
4ec37fd829 Jean*0063 fprintf(' plot_faces: nFaces= %i, nR= %i, nG= %i, nB= %i\n',nFaces,nR,nG,nB);
0064 if nFaces > 6,
0065 error([' Nb of faces =',int2str(nFaces),' > 6 !'])
d755cc892a Jean*0066 end
0067
4ec37fd829 Jean*0068 xyP=zeros(6,4); ySep=0.025; dyP1=nG/(nR+nG)*0.9; dyP2=nR/(nR+nG)*0.9;
0069 xyP(1,:)=[0.05 0.05 0.21 dyP1]; yOr2=xyP(1,2)+ySep+dyP1;
0070 xyP(2,:)=[0.29 0.05 0.21 dyP1];
0071 xyP(3,:)=[0.29 yOr2 0.21 dyP2];
0072 xyP(4,:)=[0.53 0.05 0.21 dyP1];
0073 xyP(5,:)=[0.77 0.05 0.21 dyP1];
0074 xyP(6,:)=[0.77 yOr2 0.21 dyP2];
0075
0076 %- move face 3 in top-left corner:
0077 xyP(3,:)=[0.05 yOr2 0.21 dyP2];
0078 %fprintf(' dyP1, yOr2, dyP2= %5.3f %5.3f %5.3f\n',dyP1,yOr2,dyP2);
d755cc892a Jean*0079
0080 figure(nfg);clf;
4ec37fd829 Jean*0081 for n=1:nFaces,
d755cc892a Jean*0082 if compact == 1,
0083 var=reshape(vv(fd1(n):fd2(n),:),[nf(n,:) nz]);
0084 else
0085 cvar=char(listF(n)); var=vF.(cvar);
0086 end
0087 if k ~= 0, var=var(:,:,k); end
0088 if n > 3, var=fliplr(var'); end %- rotate face 4,5,6
0089 if n == 3, var=flipud(var'); end %- rotate to put face 3 in top-left corner
0090 AA=axes('position',xyP(n,:));
0091 imagesc(var'); set(gca,'YDir','normal');
0092 if ccB(1) < ccB(2), caxis(ccB); end
0093 end
0094 H=colorbar('peer',AA,'North');
0095 set(H,'Position',[xyP(4,1) 0.90 xyP(4,3) 0.020]);
0096
0097 return