function []=plot_llc_tracer(xc,yc,field,klev,figN,ccaxis,varname)
%============================================================
% function []=plot_llc_tracer(xc,yc,field,klev,figN,ccaxis,varname)
% XC,YC,field: in compact form
% varname: example 'ddETAN'
% figN: figure number
% ccaxis [ccN,ccS,ccM]
% klev = k level
%============================================================

%--------------- setup grid --------------------
lat_N=55;lat_S=-50;lat_NM=67;lat_SM=-60;

[nx,ny,nz]=size(field);
[LON,XC]=patchface3D(nx,ny,1,xc,2);
[LAT,YC]=patchface3D(nx,ny,1,yc,2);

% face 3
x=XC{3};y=YC{3};
ii=find(x>180);if(length(ii)>0);x(ii)=x(ii)-360;end;

% North [55N, 90N]
iN=find(LAT(1,:)>lat_N);iN=iN(1);
xN=LON(:,iN:3*nx);yN=LAT(:,iN:3*nx);
ii=find(xN>180);if(length(ii)>0);xN(ii)=xN(ii)-360;end;
min_N=min(min(yN));
m_proj('Stereographic','lon',0,'lat',90,'rad',90-min_N);
[x,y]=m_ll2xy(x,y);
[xN,yN]=m_ll2xy(xN,yN);

%South [90S, 55S]
iS=find(LAT(1,:)<lat_S);iS=iS(end);
xS=LON(:,1:iS);yS=LAT(:,1:iS);
ii=find(xS>180);if(length(ii)>0);xS(ii)=xS(ii)-360;end;
max_S=max(max(yS));
m_proj('Stereographic','lon',0,'lat',-90,'rad',90+max_S);
[xS,yS]=m_ll2xy(xS,yS);

%World [-70N,63N]
iM=find(LAT(1,:)>=lat_SM & LAT(1,:)<=lat_NM);
iflip=find(diff(LON(:,iM(1))<0)); iflip=iflip(2); %1308
% need to make lon goes from -180 to 180, not -130 to 180 and -180 to -130
istop=length(iflip+1:size(LON,1)); %852;
xM=zeros(size(LON(:,iM)));xM(1:istop,:)=LON(iflip+1:end,iM);xM(istop+1:end,:)=LON(1:iflip,iM);
yM=zeros(size(LAT(:,iM)));yM(1:istop,:)=LAT(iflip+1:end,iM);yM(istop+1:end,:)=LAT(1:iflip,iM);
ii=find(xM>180);if(length(ii)>0);xM(ii)=xM(ii)-360;end;
ll=[-180,180];%ll=[min(min(xM)),max(max(xM))];
LL=[lat_SM,lat_NM];%LL=[min(min(yM)),max(max(yM))];
m_proj('Miller Cylindrical','lon',ll,'lat',LL);
[xM,yM]=m_ll2xy(xM,yM);

%============================================================
% now look at the field
  if(isempty(ccaxis)==0);ccN=ccaxis(1,:);ccS=ccaxis(2,:);ccM=ccaxis(3,:);end
  k=klev;
  [b,faces]=patchface3D(nx,ny,nz,field,2); face3=faces{3};

    z=face3(:,:,k);  zN=b(:,iN:3*nx,k);  zS=b(:,1:iS,k);
    zM=zeros(size(xM));zM(1:istop,:)=b(iflip+1:end,iM,k);zM(istop+1:end,:)=b(1:iflip,iM,k);

    h=figure(figN);clf;
    hh=subplot(221);set(hh,'position',[.1,.54,.4,.4]);
    m_proj('Stereographic','lon',0,'lat',90,'rad',90-min_N);
    pcolor(x,y,z);shading flat;if(exist('ccN','var'));caxis(ccN);end;thincolorbar('horiz');
    hold on;pcolor(xN,yN,zN);shading flat;hold off;
    m_grid;

    hh=subplot(222);set(hh,'position',[.57,.54,.4,.4]);
    m_proj('Stereographic','lon',0,'lat',-90,'rad',90+max_S);
    pcolor(xS,yS,zS);shading flat;if(exist('ccS','var'));caxis(ccS);end;thincolorbar('horiz');
    m_grid;

    hh=subplot(212);set(hh,'position',[.1,.1,.84,.4]);
    m_proj('Miller Cylindrical','lon',ll,'lat',LL);
    pcolor(xM,yM,zM);shading flat;if(exist('ccM','var'));caxis(ccM);end;thincolorbar('horiz');
    m_grid;
    hh=text(0.5,1.0,[varname,' k=',myint2str(k,2)]);set(hh,'color','k','fontsize',12);

return
