function []=stkmaxis(m1, yr1, m9, yr9, delm, daytic)
%	Plot stackplot x axis using a monthly calendar.
%	Data to be plotted is assumed to be given in jd as # days
%	since 1/1/70!! If not, scale your time variable with jdcvt.
%
%	function []=stkmaxis(m1, yr1, m9, yr9, delm[, daytic])
%	  m1=  starting (left) month on the axis {integer scaler}
%	  yr1= starting year in the format xx {scaler}
%	  m9=  ending (right) month on the axis {integer scaler}
%	  yr9= ending year in the format xx {scaler}
%	  delm= delta month on the axis in integer months {scaler}
%	  daytic= if daytic = 1 then tic mark every day {scaler} (optional)

%	Latest revision by P. Dragos 21-May-91.
%
%	P. Dragos, Battelle Ocean Sciences
%	Duxbury, MA 02332
%	(617) 934-0571
%
%	Copyright (c) 1991 by Paul Dragos.
%	This program is copyrighted.  However, you are encouraged to
%	copy and share it, so long as no charge is imposed.

%				---------------------------------------
%				defaults
if (nargin < 6), daytic = 0; end;

month=['Jan   ';'Feb   ';'Mar   ';'Apr   ';'May   ';'Jun   ';
       'Jul   ';'Aug   ';'Sep   ';'Oct   ';'Nov   ';'Dec   '];
%				---------------------------------------
%				defaults from stkparm.mat
load stkparm.mat
x0= stkx0; y0= stky0; x1= stkx1; y1= stky1;
sep= stksep; c= stkc; dc= stkdc; cht= stkcht; cwt= stkcwt; tht= stktht;
cht2= cht/2; cwt2= cwt/2; stht= stkstht;
%				---------------------------------------
%				Calculate jd of 1st day of each month
itnum= ((yr9-yr1)*12+m9)-m1+1;
mon= [m1:m1+itnum]';
yrnum= floor((mon-1)./12);
yr= yr1 + yrnum;
mon= mon - (yrnum.*12);
jd1stmon= julpd(mon,ones(yr),yr,zeros(yr),'y');
%				---------------------------------------
%			              Calculate starting, ending jd and
%				      delta length
start= jd1stmon(1);
last= jd1stmon(length(jd1stmon));

%				---------------------------------------
%				defaults to stkparm.mat
stkax(:,1)= start*ones(10,1);
stkax(:,2)= last*ones(10,1);
save stkparm.mat stkax stkx0 stky0 stkx1 stky1 stksep ...
                 stkc stkdc stkcht stkcwt stktht stkstht;
%				---------------------------------------
%				Calculate locations of numbers and tics
x= x0;
y= y0;
axl= x1-x0;
ynum= -2.0*cht + y;
ymon= -4*cht + y;
ytic=tht+y;
ydtic=(0.75*tht)+y;

day=[start:last]';
dl = axl / (last-start);
%				---------------------------------------
%				Add year to month string where appropriate
j= [1:delm:length(jd1stmon)-1];
i= j(find(yrnum(j) ~= [-1;yrnum(j(1:length(j)-1))]));
string= month(mon,:);
%				---------------------------------------
%				Plot MONTHS on main axis
xnum= x + (jd1stmon-start)*dl;
text(xnum(j),ynum.*ones(xnum(j)),string(j,:));
for k=[1:length(i)], 
  text(xnum(i(k)),ymon,int2str(1900+yr(i(k))));
end;
%				---------------------------------------
%				Plot main axis line and tics
xtic= x + (jd1stmon-start)*dl;
xt=[xtic xtic];
yt=[y ytic];
plot([x x+axl], [y y], c, xt, yt, c);
if (daytic == 1),
  xdtic= x + (day-start)*dl;
  xt=[xdtic xdtic];
  yt=[y ydtic];
  plot(xt, yt, c);
end;  

%				---------------------------------------
%				Calculate locations of tics on second axis
y= y1;
ytic=-tht+y;
ydtic=-stht+y;
%				---------------------------------------
%				Plot second axis line and tics
xt=[xtic xtic];
yt=[y ytic];
plot([x x+axl], [y y], c, xt, yt, c);
if (daytic == 1),
  xdtic= x + (day-start)*dl;
  xt=[xdtic xdtic];
  yt=[y ydtic];
  plot(xt, yt, c);
end;  

