Home > timeplt > 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 
0013 jd0_index = find(jd == gmin(jd));
0014 jd0=jd(jd0_index(1));
0015 
0016 jdn_index = find(jd == gmax(jd));
0017 n = length(jdn_index);
0018 jd1=jd(jdn_index(n));
0019 
0020 start=gregorian(jd0);
0021 stop=gregorian(jd1);
0022 
0023 start=[start(1:2) 0 0 0 0];
0024 stop=[stop(1) stop(2)+1 0 0 0 0];
0025 jd0=julian(start);
0026 jd1=julian(stop);
0027 ylim=get(gca,'ylim');  
0028 %xlim=[jd0-15 jd1+15];
0029 %set(gca,'xlim',xlim);
0030 set(gca,'units','pixels'); 
0031 pos=get(gca,'pos');
0032 ymin=pos(2);            % y position of x axis in pixels
0033 fontsize=get(gca,'fontsize');    %fontsize = height in pixels?
0034 set(gca,'units','normalized');
0035 xlim=get(gca,'xlim');  
0036 xfac=(xlim(2)-xlim(1))/pos(3);   %ratio of x user units to pixel units
0037 yfac=(ylim(2)-ylim(1))/pos(4);   %ratio of y user units to pixel units
0038 %
0039 date_diff=stop-start;
0040 nmon=date_diff(1)*12+date_diff(2);
0041 start_mon=start(2);
0042 start_year=start(1);
0043 mon=start_mon+[0:montic:nmon];
0044 year=start_year+floor((mon-0.5)/12);
0045 mon=rem(mon,12);
0046 mon=mon+(mon==0)*12;
0047 n=length(mon);
0048 
0049 greg=[year(:) mon(:) ones(n,1) zeros(n,3)];
0050 jdtic=julian(greg);
0051 
0052 %
0053 % find month labels
0054 %
0055 gap_width_pixels=(jdtic(2)-jdtic(1))/xfac;
0056 if(gap_width_pixels > 3*fontsize),
0057    monstr=monstr1;
0058 else
0059    monstr=monstr2;
0060 end
0061 monticlab=monstr(mon,:);
0062 set(gca,'xtick',jdtic,'Xticklabels',monticlab)
0063 %
0064 % find year labels
0065 %
0066 yeardiff=diff(year)';
0067 year_ind=[1 ; find(yeardiff~=0)+1];
0068 yeartic=jdtic(year_ind)';
0069 
0070 % determine y location of month and year labels by determining
0071 % the font height for the day labels, separating the lines
0072 % by linesep pixels
0073 %
0074 linesep=8;
0075 %
0076 ytop=ymin-(fontsize+linesep);    %y location of top of year labels in pixels
0077 ytopy=ylim(1)-(ymin-ytop)*yfac; % " ", but in user units
0078 %
0079 % label years
0080 %
0081 for i=1:length(year(year_ind));
0082   yearticlab(i,:)=int2str(year(year_ind(i)));
0083   text(yeartic(i),ytopy,yearticlab(i,:),...
0084      'HorizontalAlignment','center',...
0085      'VerticalAlignment','top','fontsize',fontsize);
0086 end

Generated on Wed 30-Nov-2005 15:41:21 by m2html © 2003