function []=stkdaxis(str, end, del, year, daytic)
%	Plot stackplot x axis using a day calendar.
%
%	If year is 0 or blank, then str, end and the data are
%	assumed to be given in jd as # days since 1/1/70 !!
%	If year is given, everything is relative to that year.
%
%	function []=stkdaxis(str, end, del, year [, daytic])
%	  str= starting (left) value on the axis in Julian day{integer scaler}
%	  end= ending (right) value on the axis in Julian day {integer scaler}
%	  del= delta value on the axis in integer days {scaler}
%	  year= in the format xx  or  0  {scaler} (optional, def = 0)
%	  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 from/to 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;
stkax(:,1)= str*ones(10,1);
stkax(:,2)= end*ones(10,1);
save stkparm.mat stkax stkx0 stky0 stkx1 stky1 stksep ...
                 stkc stkdc stkcht stkcwt stktht stkstht;
%				---------------------------------------
%				defaults

if (nargin == 4), 
  if (year == 0), year='y'; daytic = 0; 
  elseif (year == 1), year='y'; daytic=1; 
  else, daytic= 0; end;
end;
if (nargin < 4), year='y'; daytic = 0; end;
  
month=['Jan';'Feb';'Mar';'Apr';'May';'Jun';
       'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'];
%				---------------------------------------
%				Calculate locations of numbers and tics
x= x0;
y= y0;
axl= x1-x0;
%				---------------------------------------
%				Calculate locations of numbers and tics
itnum=((end-str)/del)+1;
it= [0:itnum-1]';
idtnum=(end-str)+1;
itd= [0:idtnum-1]';
sgl= axl/(itnum-1);
sgld= axl/(idtnum-1);
ynum= -2.0*cht;
ynum=ynum+y;
ymon= -4*cht;
ymon=ymon+y;
ytic=tht+y;
ydtic=(0.75*tht)+y;
fpn=[str:del:end];
%				---------------------------------------
%				Calculate the calendar day.
date=[];
for i=fpn,
  [dd]=calday(year,i);
  date= [date;dd];
end;
%				---------------------------------------
%				Plot numbers AND MONTHS on main axis
mon=0;
for ig=1:itnum,
  xnum= x+((ig-1)*sgl);
  nstr= sprintf('%2.0f',date(ig,3));
  text(xnum,ynum,nstr);
  if (date(ig,2) ~= mon),
    mon=date(ig,2);
    mstr=[month(mon,:),' ',int2str(date(ig,1))];
    text(xnum,ymon,mstr);
  end;
end;
%				---------------------------------------
%				Plot main axis line and tics
xt= x + it * sgl;
xt= [xt xt];
yt= [y ytic];
plot([x x+axl], [y y], c, xt, yt, c)
if (daytic == 1),
  xtd= x + itd * sgld;
  xtd= [xtd xtd];
  yt= [y ydtic];
  plot(xtd, yt, c)
end;  
%				---------------------------------------
%				Calculate locations of tics on second axis
y=y1;
ytic=-tht+y;
ydtic=-stht+y;
%				---------------------------------------
%				Plot second axis line and tics
yt= [y ytic];
plot([x x+axl], [y y], c, xt, yt, c);
if (daytic == 1),
  yt= [y ydtic];
  plot(xtd, yt, c)
end;  
return;
