function hand=conocta(funcn,lon,lat,A,ci,conpar,R,nsect)
% function hand=conocta(funcn,lon,lat,A,ci,conpar,R,nsect)
% b klinger, 4/29/16
% Does contour plot (contour,contour2,contour4,contourf,contourfP) 
% for octaglobe.
% Calls projocta.m, contour{2,4,fP}.m
% contour,f:  conpar={col}
% contour2,4: conpar={col,lthick}
% contourfP:  conpar={Fcol,xBrk, Lcol, lthick, xlohi}
% hand = cell: cs and han from each of 3 contour graphs (6 elements).

%---------------------------------------------------------------------
% Get parameters from conpar or set to default values
%---------------------------------------------------------------------
 
if ~exist('conpar')
   if funcn=='fP'
      conpar={'k'};
   else
      conpar={'A'};
   end
end
col=conpar{1};
xBrk=0;
lthick=.5;
Lcol='k';

if funcn=='fP'
   if length(conpar)>=2
      xBrk=conpar{2};
   end
   if length(conpar)>=3
      Lcol=conpar{3};
   end
   if length(conpar)>=4
      lthick=conpar{4};
   end
   if length(conpar)>=5
      xlohi=conpar{5};
   else 
      Ndir=length('Fcol');
      xlohi=[zeros(Ndir,1) ones(Ndir,1)];
   end
else
   if length(conpar)>=2
      lthick=conpar{2};
   end
end

%---------------------------------------------------------------------
% create list of variables to pass to contour routine
%---------------------------------------------------------------------

svar='ci,col);';
if funcn=='2' | funcn=='4'
   svar='ci,col,lthick);';
elseif funcn=='fP'
   svar='ci,col,xBrk,Lcol,lthick,xlohi);';
end

%---------------------------------------------------------------------
% do projection & segregate into non-polar and polar segments
%---------------------------------------------------------------------

if ~exist('R')
   R=0;
end
if ~exist('nsect')
   nsect=[0 0];
end
[x,y]=projocta(lon,lat,R,nsect);
jj=find(abs(lat)<67.5);
jn=find(lat>=67.5);
js=find(lat<=-67.5);

%---------------------------------------------------------------------
% contour each low-latitude sector separately
%---------------------------------------------------------------------

for i=0:7
   ii=find(lon>45*i & lon<=45*i+45);
   xi=x(jj,ii);
   yj=y(jj,ii);
   Aji=A(jj,ii);
   eval(['[csT,hanT]=contour' funcn '(xi,yj,Aji,' svar]);
   hand{i+1,1}=csT;
   hand{i+1,2}=hanT;
   hold on
   clear csT hanT
end

%---------------------------------------------------------------------
% contour polar sectors
%---------------------------------------------------------------------

xn=x(jn,:);
yn=y(jn,:);
xs=x(js,:);
ys=y(js,:);
eval(['[csn,hann]=contour' funcn '(xn,yn,A(jn,:),' svar]);
eval(['[css,hans]=contour' funcn '(xs,ys,A(js,:),' svar]);
hand{9,1}=csn;
hand{9,2}=hann;
hand{10,1}=css;
hand{10,2}=hans;

