function octapage(iview,fnameP,R,nsect)
% function octapage(iview,fnameP,R,nsect)
% b klinger, 4/30/16
% Adjust axes for octaglobe projection on either 1 or 2 pages.
% If 2 pages, prints both pages to file fnameP.

%          MODIFICATIONS
% 5/7/16: passes more parameters and uses them to set axis vals.

%---------------------------------------------------------------------
% get missing variables from user or from defaults
%---------------------------------------------------------------------

if ~exist('iview')
   iview=input('1 for normal view, 2 to print in 2 halves: ');
end
if iview==2 & ~exist('fnameP')
   fnameP=input('What is name of output file? ','s');
end
if ~exist('R')
   R=0;
end
if ~exist('nsect') |  nsect==[0 0]
   nsect=[8 4];
end

%---------------------------------------------------------------------
% calculate coordinates for outer borders of octaglobe
%---------------------------------------------------------------------

[xB,yB]=projocta([.5:8.5]*45,[67.501],R,nsect);
yA=max(max(yB));
[xbnd,ybnd]=projocta([0 360],0,R,nsect);
[xM,yM]=projocta(1,67.499,R,nsect);
yfdge=1.01;

axis equal
axis off

%---------------------------------------------------------------------
if iview==1
%---------------------------------------------------------------------

   axis([xbnd -yA*1.01 yA*1.01])

%---------------------------------------------------------------------
elseif iview==2
%---------------------------------------------------------------------

   ylim=[yA yM; yM yA]*yfdge;
   nN=ceil(nsect(1)/4);
   nS=ceil(nsect(2)/4);
   axis([xbnd(1) xbnd(2)/2 -ylim(nS,1) ylim(nN,1)])
   xcont=input('Any number to continue? ');

   eval(['print -dpdf ' fnameP '2.pdf'])
   axis([xbnd(2)/2 xbnd(2) -ylim(nS,2) ylim(nN,2)])
   eval(['print -dpdf ' fnameP '1.pdf'])

%---------------------------------------------------------------------
end
%---------------------------------------------------------------------
