Home > omviz > gregaxm.m

gregaxm

PURPOSE ^

GREGAXM Labels the current x-axis with Gregorian labels in units of months,

SYNOPSIS ^

function []=gregaxm(jd,montic);

DESCRIPTION ^

 GREGAXM Labels the current x-axis with Gregorian labels in units of months,
      GREGAXM(JD,MONTIC) draws Gregorian time labels on the x-axis in
      intervals of MONTIC months.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function []=gregaxm(jd,montic);
0002 % GREGAXM Labels the current x-axis with Gregorian labels in units of months,
0003 %      GREGAXM(JD,MONTIC) draws Gregorian time labels on the x-axis in
0004 %      intervals of MONTIC months.
0005 
0006 monstr1=['Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';...
0007 'Oct';'Nov';'Dec'];
0008 
0009 monstr2=['J';'F';'M';'A';'M';'J';'J';'A';'S';'O';'N';'D'];
0010 %
0011 n=length(jd);
0012 start=gregorian(jd(1));
0013 stop=gregorian(jd(n));
0014 start=[start(1:2) 0 0 0 0];
0015 stop=[stop(1) stop(2)+1 0 0 0 0];
0016 jd0=julian(start);
0017 jd1=julian(stop);
0018 ylim=get(gca,'ylim');  
0019 %xlim=[jd0-15 jd1+15];
0020 %set(gca,'xlim',xlim);
0021 set(gca,'units','pixels'); 
0022 pos=get(gca,'pos');
0023 ymin=pos(2);            % y position of x axis in pixels
0024 fontsize=get(gca,'fontsize');    %fontsize = height in pixels?
0025 set(gca,'units','normalized');
0026 xlim=get(gca,'xlim');  
0027 xfac=(xlim(2)-xlim(1))/pos(3);   %ratio of x user units to pixel units
0028 yfac=(ylim(2)-ylim(1))/pos(4);   %ratio of y user units to pixel units
0029 %
0030 date_diff=stop-start;
0031 nmon=date_diff(1)*12+date_diff(2);
0032 start_mon=start(2);
0033 start_year=start(1);
0034 mon=start_mon+[0:montic:nmon];
0035 year=start_year+floor((mon-0.5)/12);
0036 mon=rem(mon,12);
0037 mon=mon+(mon==0)*12;
0038 n=length(mon);
0039 
0040 greg=[year(:) mon(:) ones(n,1) zeros(n,3)];
0041 jdtic=julian(greg);
0042 
0043 %
0044 % find month labels
0045 %
0046 gap_width_pixels=(jdtic(2)-jdtic(1))/xfac
0047 if(gap_width_pixels > 3*fontsize),
0048    monstr=monstr1;
0049 else
0050    monstr=monstr2;
0051 end
0052 monticlab=monstr(mon,:);
0053 set(gca,'xtick',jdtic,'Xticklabels',monticlab)
0054 %
0055 % find year labels
0056 %
0057 yeardiff=diff(year)';
0058 year_ind=[1 ; find(yeardiff~=0)+1];
0059 yeartic=jdtic(year_ind)';
0060 
0061 % determine y location of month and year labels by determining
0062 % the font height for the day labels, separating the lines
0063 % by linesep pixels
0064 %
0065 linesep=8;
0066 %
0067 ytop=ymin-(fontsize+linesep);    %y location of top of year labels in pixels
0068 ytopy=ylim(1)-(ymin-ytop)*yfac; % " ", but in user units
0069 %
0070 % label years
0071 %
0072 for i=1:length(year(year_ind));
0073   yearticlab(i,:)=int2str(year(year_ind(i)));
0074   text(yeartic(i),ytopy,yearticlab(i,:),...
0075      'HorizontalAlignment','center',...
0076      'VerticalAlignment','top','fontsize',fontsize);
0077 end

Generated on Thu 01-Dec-2005 08:50:35 by m2html © 2003