function dum=octacircles(R,col30,colfold,fsz,nsect);
% function dum=octacircles(R,col30,colfold,fsz,nsect);
% octacircles.m
% b klinger, 7/17/12
% Create lat circles and tick marks on lon circles for OctaGlobe.
% R=radius of sphere, 
% col30=color of +/-0,30,60 lats (default red), 
% colfold=color of fold lines (default white),
% fsz=fontsize for latitude labels (default=6),
% nsect=sector of [Arct Antarct] octagons (default=[8 4])
% Calls projocta

%          MODIFICATIONS
% 8/25/12 add nsect option

%---------------------------------------------------------------------
% some parameters
%---------------------------------------------------------------------

if ~exist('R') | R==0
   R=1 ./sqrt(sqrt(2)*(sqrt(2)-1));   % choose R to make A=1
end
if ~exist('col30')
   col30='r';
end
if ~exist('colfold')
   colfold=[.99 .99 .99];
end
if ~exist('fsz')
   fsz=6;
end
if ~exist('nsect')
   nsect=[8 4];
end
HA='horizontalalignment';
FS='fontsize';
LW='linewidth';

%---------------------------------------------------------------------
% draw black outlines around sectors
%---------------------------------------------------------------------

for i=0:7
   lonp=45*i+[0 44.999];
   latp=[-1.499 -.5 .5 1.499]*45;
   [xp,yp]=projocta(lonp,latp,R,nsect);
   xpp=[xp(:,1)' xp(:,2)' xp(1,1)];
   ypp=[yp(:,1)' yp([4 3 2 1],2)' yp(1,1)];
   plot(xpp,ypp,'k')
   hold on
end
[xp,yp]=projocta(0:45:360,67.5001,R,nsect);
plot(xp,yp,'k')
[xp,yp]=projocta(0:45:360,-67.5001,R,nsect);
plot(xp,yp,'k')

%---------------------------------------------------------------------
% Draw latitude circles at +/- 60,30,0 deg 
% and (using 5 deg long dashes) at +/- 22.5,
%---------------------------------------------------------------------

[xd30lo,yd30]=projocta(0:10:350,30,R,nsect);
[xd30hi,yd30]=projocta([0:10:350]+4.999,30,R,nsect);
[xd60lo,yd60]=projocta(0:10:350,60,R,nsect);
[xd60hi,yd60]=projocta([0:10:350]+4.999,60,R,nsect);
[xd0lo,yd0]=projocta(0:10:350,0,R,nsect);
[xd0hi,yd0]=projocta([0:10:350]+4.999,0,R,nsect);
for i=1:length(xd30lo)
   plot([xd30lo(i) xd30hi(i)],yd30(i)*[1 1],col30,LW,1);
   plot([xd30lo(i) xd30hi(i)],-yd30(i)*[1 1],col30,LW,1);
   plot([xd60lo(i) xd60hi(i)],yd60(i)*[1 1],col30,LW,1);
   plot([xd60lo(i) xd60hi(i)],-yd60(i)*[1 1],col30,LW,1);
   plot([xd0lo(i) xd0hi(i)],yd0(i)*[1 1],col30,LW,1);
end

[xdFlo,ydF]=projocta(0:10:350,22.5,R,nsect);
[xdFhi,ydF]=projocta([0:10:350]+4.999,22.5,R,nsect);
for i=1:length(xdFlo)
   plot([xdFlo(i) xdFhi(i)],ydF(i)*[1 1],'color',colfold);
   plot([xdFlo(i) xdFhi(i)],-ydF(i)*[1 1],'color',colfold);
end

%---------------------------------------------------------------------
% annotate latitude circles
%---------------------------------------------------------------------

[xlat,ylat]=projocta(337.5,[2 32 -32 62 -62],R,nsect);
xlat=xlat(1);
text(xlat,ylat(1),'\bf EQUATOR','color',col30,FS,fsz,HA,'center')
text(xlat,ylat(2),'\bf 30^oN','color',col30,FS,fsz,HA,'center')
text(xlat,ylat(3),'\bf 30^oS','color',col30,FS,fsz,HA,'center')
text(xlat,ylat(4),'\bf 60^oN','color',col30,FS,fsz,HA,'center')
text(xlat,ylat(5),'\bf 60^oS','color',col30,FS,fsz,HA,'center')
[xlat,ylat]=projocta(157.5,[2 32 -32 62 -62],R,nsect);
xlat=xlat(1);
text(xlat,ylat(1),'\bf EQUATOR','color',col30,FS,fsz,HA,'center')
text(xlat,ylat(2),'\bf 30^oN','color',col30,FS,fsz,HA,'center')
text(xlat,ylat(3),'\bf 30^oS','color',col30,FS,fsz,HA,'center')
text(xlat,ylat(4),'\bf 60^oN','color',col30,FS,fsz,HA,'center')
text(xlat,ylat(5),'\bf 60^oS','color',col30,FS,fsz,HA,'center')

%---------------------------------------------------------------------
% Ticmarks every 5 deg lat at each longitude boundary (every 45 deg),
% first for trop/midlat and then for polar segments
%---------------------------------------------------------------------

for i=0:7
   for rlat=-65:5:65
      [rx,ry]=projocta([0 1]+i*45,rlat,R,nsect);
      plot(rx,ry,col30)
      [rx,ry]=projocta([44 44.99]+i*45,rlat,R,nsect);
      plot(rx,ry,col30)
   end
end

for rlon=0:45:315
   for rlat=[-85:5:-70 70:5:85]
      [rx,ry]=projocta(rlon+[-2.5 0 2.5],rlat,R,nsect);
      plot(rx,ry,col30)
   end
end

