function yeartick
% function to tick x-labels as year (properly!)
%
% see also datetick

% D Menemenlis, 9 feb 98, dimitri@ocean.mit.edu

% get right scaling
Position=get(gca,'Position');
PaperPosition=get(gcf,'PaperPosition');
XScale=Position(3)*PaperPosition(3);
YScale=Position(4)*PaperPosition(4);
if XScale>YScale
  YScale=XScale/YScale; XScale=1;
else 
  XScale=YScale/XScale; YScale=1;
end
YScale=YScale/2.5;
% remove existing tick marks
TickLength=get(gca,'TickLength');
set(gca,'TickLength',[0 0])

% redraw yticks
XLim=get(gca,'XLim');
XTickLength=XScale*TickLength(1)*(XLim(2)-XLim(1));
XLim1=[XLim(1) XLim(1)+XTickLength];
XLim2=[XLim(2)-XTickLength XLim(2)];
YTick=get(gca,'YTick');
HoldStatus=ishold;
hold on
for iYTick=1:length(YTick)
  plot(XLim1,YTick(iYTick)*[1 1])
  plot(XLim2,YTick(iYTick)*[1 1])
end  

% draw xticks
YLim=get(gca,'YLim');
YTickLength=YScale*TickLength(2)*(YLim(2)-YLim(1));
YLim1=[YLim(1) YLim(1)+YTickLength];
YLim2=[YLim(2)-YTickLength YLim(2)];
YearTick=datevec(XLim);
YearTick=YearTick(:,1);
YearTick=YearTick(1):YearTick(2);
YearTick(1)=[];
set(gca,'XTick',datenum(YearTick,7,1,0,0,0));
set(gca,'XTickLabel',YearTick);
YearTick=datenum(YearTick,1,1,0,0,0);
for iYearTick=1:length(YearTick)
  plot(YearTick(iYearTick)*[1 1],YLim1)
  plot(YearTick(iYearTick)*[1 1],YLim2)
end  

if ~HoldStatus, hold off, end
