function [newCSf,newSNf]=rotate_CSSNface(oldCSf,oldSNf,YCf,iRot);
%----------------------------------------------
%[newCSf,newSNf]=rotate_CSSNface(oldCSf,oldSNf,YCf);
% function to rotate AngleCS/AngleSN:
% ---- 1 ----
% |         |
% 4    0    2
% |         |
% ---- 3 ----
% need YC to determine orientation of face
% where YCf is the face of YC
% Note: where iRot is commented out, need verification
%----------------------------------------------
%determining orientation to locate North:
[nx,ny]=size(YCf);
if(nx==0&ny==0);
  fprintf('empty face, nothing is calc\n');
  newCSf=[];newSNf=[];
else;
aa=[max(YCf(nx/2,:)),max(YCf(:,ny/2))];
if(abs(diff(aa))<0.001);	%North at center
  iNorth=0;
elseif(aa(1)>aa(2));	%North is in Y-dir
  iHalf=nx/2;jHalf=1:ny;
  [vmax,jmax]=max(YCf(iHalf,jHalf));
  if(jmax==1);iNorth=3;elseif(jmax==ny);iNorth=1;elseif(jmax==ny/2);iNorth=0;end;
else;			%North is in X-dir
  iHalf=1:nx;jHalf=ny/2;
  [vmax,imax]=max(YCf(iHalf,jHalf));
  if(imax==1);iNorth=4;elseif(imax==nx);iNorth=2;elseif(imax==nx/2);iNorth=0;end;
end;
switch iNorth
%----------------------        --------------------------------------------
  case 0;		%face3
    newCSf=oldCSf;
    newSNf=oldSNf;
%----------------------        --------------------------------------------
  case {1};		%North up face 1 & 2
    fprintf('entering case 1, North up\n');

%this face in its original orientation has North upward
    [nx ny]=size(oldCSf);	%[270 810]
    iL=1:nx/2;iR=nx/2+1:nx;
    ind=zeros(size(oldCSf));ind(iR,:)=1;

%rotate 90deg clockwise = -90, sym_g(oldCSf{face},7,0);
%swap SN and CS, flip sign of iL for cosine, of iR for sine
    if(iRot==7);
      newCSf=-sym_g(oldSNf,iRot,0);
      newSNf= sym_g(oldCSf,iRot,0);

%rotate 180deg, sym_g(oldCSf{face},6,0);
    elseif(iRot==6);
      newCSf=-sym_g(oldCSf,iRot,0);
      newSNf=-sym_g(oldSNf,iRot,0);

%rotate 90deg counterclockwise = +90, sym_g(oldCSf{face},5,0)
    elseif(iRot==5);
      newCSf= sym_g(oldSNf,iRot,0);
      newSNf=-sym_g(oldCSf,iRot,0);
    elseif(iRot==0);	%no rotation
      newCSf=oldCSf;newSNf=oldSNf;
    end;

%----------------------        --------------------------------------------
  case {4};	%North on Left, face 4&5 in llc
    fprintf('entering case 4, North on Left\n');
    [nx ny]=size(oldCSf); 	%[810 270]
    jL=1:ny/2;jR=ny/2+1:ny;
    ind=zeros(size(oldCSf));ind(:,jR)=1;

%rotate 90deg clockwise = -90, sym_g(oldCSf{face},7,0);
%newcos(Left)= -oldsin, newsin(Right)=-oldcos
    if(iRot==7);
      newCSf=-sym_g(oldSNf,iRot,0);
      newSNf= sym_g(oldCSf,iRot,0);

%rotate 180deg
    elseif(iRot==6);
      newCSf=-sym_g(oldCSf,iRot,0);
      newSNf=-sym_g(oldSNf,iRot,0);

%rotate 90deg counterclockwise = +90, sym_g(oldCSf{face},5,0);
%newsin(left)=-oldcos, newcos(right)=-oldsin
    elseif(iRot==5);
      newCSf= sym_g(oldSNf,iRot,0);
      newSNf=-sym_g(oldCSf,iRot,0);
    elseif(iRot==0);	%no rotation
      newCSf=oldCSf;newSNf=oldSNf;
    end;
end;
end;
return
