Home > timeplt5 > timeplt_draw.m

timeplt_draw

PURPOSE ^

TIMEPLT_DRAW: Takes care of drawing routines.

SYNOPSIS ^

function timeplt_draw()

DESCRIPTION ^

 TIMEPLT_DRAW:  Takes care of drawing routines.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function timeplt_draw()
0002 % TIMEPLT_DRAW:  Takes care of drawing routines.
0003 %
0004 
0005 %disp ( sprintf ( 'here in timeplt_draw' ) );
0006 
0007 global timeplt_obj;
0008 
0009 
0010 N = timeplt_obj_index;
0011 
0012 
0013 eval ( 'delete ( timeplt_obj{N}.plot_axes );', '' );
0014 
0015 
0016 %
0017 % Redo all the axes.
0018 num_axes = max(timeplt_obj{N}.istack(:) );
0019 
0020 for i = 1:num_axes
0021     h(i) = subplot(num_axes,1,i);
0022 
0023     if ( ~isempty(timeplt_obj{N}.ylims) )
0024         set ( h, 'YLim', timeplt_obj{N}.ylims(i,:) );
0025     end
0026 
0027 end
0028 
0029 set ( h,     'NextPlot', 'Add' );
0030 
0031             
0032 h = flipud(h(:));
0033 
0034 
0035 
0036 
0037 
0038 jd = timeplt_obj{N}.jd;
0039 data = timeplt_obj{N}.data;
0040 istack = timeplt_obj{N}.istack;
0041 
0042 
0043 %
0044 % colordef white color scheme line colors
0045 defaultcmap = get ( 0, 'defaultaxescolororder' );
0046 if ( size(istack,1) > size(defaultcmap,1) )
0047     cmap = jet(size(istack,1));
0048 else
0049     cmap = defaultcmap;
0050 end
0051 axis_color_index = zeros(length(istack),1);
0052 
0053 
0054     
0055 
0056 
0057 jd0 = gmin(jd(:));
0058 jd1 = gmax(jd(:));
0059 
0060 %
0061 % Make the time axis always extend 5 percent past the
0062 % data.
0063 timediff = jd1 - jd0;
0064 xlim = [(jd0 - timediff*0.05) (jd1 + timediff*0.05)];
0065 set ( h, 'XLim', xlim );
0066 
0067 
0068 %
0069 % plot the data
0070 for i = 1:length(istack)
0071     axes ( h(istack(i)) );
0072 
0073     %
0074     % set the index into the colormap correctly
0075     % each pane is to be the same as the order for regular matlab plots.
0076     % While I'm at it, I think I will cure world hunger.
0077     axis_color_index(istack(i)) = axis_color_index(istack(i)) + 1;
0078     
0079     if ( isreal ( data(:,i) ) )
0080         graph = plot ( jd, data(:,i) );
0081         if ( ~isempty(timeplt_obj{N}.ylims) )
0082             set ( gca, 'YLim', timeplt_obj{N}.ylims(istack(i),:) );
0083         end
0084     else
0085 
0086         %
0087         % Retrieve the ylims.  If ylims were specified
0088         % in the timplt call, then it has already been
0089         % set in the gca.  Otherwise construct it from the
0090         % data.
0091         if ( isempty(timeplt_obj{N}.ylims) )
0092             y0 = min ( gmin(imag(data(:,i))), 0);
0093             y1 = max ( gmax(imag(data(:,i))), 0);
0094             ylim = [y0 y1];
0095             set ( gca, 'YLim', ylim );
0096         else
0097             ylim = get ( gca, 'ylim' );
0098         end
0099 
0100         %
0101         % Construct the scaling factor to accurately do
0102         % stick plots.
0103         old_units = get ( gca, 'Units' );
0104         set ( gca, 'Units', 'Pixels' );
0105         pos = get ( gca, 'Position' );
0106         set ( gca, 'Units', old_units );
0107 
0108         scale_factor = (diff(xlim)/diff(ylim)) * (pos(4)/pos(3));
0109 
0110         u_data = scale_factor * real(data(:,i));
0111         v_data = imag(data(:,i));
0112 
0113         x=jd;
0114         xp=x;
0115         yp=zeros(size(xp));
0116         xplot=ones(length(xp),2);
0117         yplot=xplot;
0118         xplot(:,1)=x(:);
0119         xplot(:,2)=xp(:)+u_data(:);
0120         xplot(:,3)=x(:);
0121         yplot(:,1)=yp(:);
0122         yplot(:,2)=yp(:)+v_data(:);
0123         yplot(:,3)=yp(:)*nan;
0124         xplot=xplot';
0125         yplot=yplot';
0126         if(~isempty(find(finite(u_data(:)))))
0127             graph(1) = plot( [jd0 jd1],[0 0] );
0128             graph(2) = plot ( xplot(:), yplot(:) );...
0129         end
0130             
0131         
0132     end
0133 
0134 %    index = mod(i-1, length(cmap))+1;
0135 %    set ( graph, 'color', cmap(index,:) );
0136     set ( graph, 'color', cmap(axis_color_index(istack(i)),:) );
0137 
0138 end
0139 
0140 
0141 
0142 %
0143 % We want to do our own labels, thank you very much.
0144 set ( h, 'XTickLabel', [] );
0145 
0146 %
0147 % What's the separation of the ticks?
0148 xt = get(gca,'XTick' );
0149 xt_sep = max(diff(xt(:)));
0150 
0151 
0152 axes ( h(1) );
0153 if (timeplt_obj{N}.year_cut_specified)
0154     timeplt_gregax_year ( timeplt_obj{N}.jd );
0155 elseif (timeplt_obj{N}.month_cut_specified)
0156     timeplt_gregax_month ( timeplt_obj{N}.jd );
0157 elseif (timeplt_obj{N}.day_cut_specified)
0158     timeplt_gregax_day ( timeplt_obj{N}.jd );
0159 elseif (timeplt_obj{N}.hour_cut_specified)
0160     timeplt_gregax_hour( timeplt_obj{N}.jd );
0161 elseif (timeplt_obj{N}.minute_cut_specified)
0162     timeplt_gregax_minute( timeplt_obj{N}.jd );
0163 elseif ( xt_sep > timeplt_obj{N}.year_cut )
0164     timeplt_gregax_year ( timeplt_obj{N}.jd );
0165     timeplt_obj{N}.year_cut_specified = 1;
0166 elseif (xt_sep > timeplt_obj{N}.month_cut) 
0167     timeplt_gregax_month ( timeplt_obj{N}.jd );
0168     timeplt_obj{N}.month_cut_specified = 1;
0169 elseif (xt_sep > timeplt_obj{N}.day_cut)
0170     timeplt_gregax_day ( timeplt_obj{N}.jd );
0171     timeplt_obj{N}.day_cut_specified = 1;
0172 elseif (xt_sep > timeplt_obj{N}.hour_cut)
0173     timeplt_gregax_hour( timeplt_obj{N}.jd );
0174     timeplt_obj{N}.hour_cut_specified = 1;
0175 else
0176     timeplt_gregax_minute ( timeplt_obj{N}.jd );
0177     timeplt_obj{N}.minute_cut_specified = 1;
0178 end
0179 
0180 
0181 %
0182 % Now make sure that all axes have the same tick marks as the first.
0183 set ( h, 'XTick', get(h(1), 'XTick' ) );
0184 
0185     
0186 
0187 
0188     
0189 timeplt_obj{N}.plot_axes = h;
0190 
0191 
0192 %
0193 % The last thing we do is to calculate the printing properties.
0194 % We want the paperposition to come out as close as possible to
0195 % what's on screen.
0196 old_units = get( timeplt_obj{N}.figure, 'Units' );
0197 set ( timeplt_obj{N}.figure, 'Units', 'Points' );
0198 old_paper_units = get ( timeplt_obj{N}.figure, 'PaperUnits' );
0199 set ( timeplt_obj{N}.figure, 'PaperUnits', 'Points' );
0200 set ( timeplt_obj{N}.figure, 'PaperType', 'usletter' );
0201 
0202 
0203 onscreen_position = get ( timeplt_obj{N}.figure, 'Position' );
0204 onpaper_position = get ( timeplt_obj{N}.figure, 'PaperPosition' );
0205 
0206 %
0207 % The maximum width that the plot can be is 612 points.  Anything
0208 % larger must be scaled down.
0209 % The maximum height is 792 points.
0210 if ( onscreen_position(3) > 612 )
0211     hreduction_factor = 612 / onscreen_position(3);
0212 else
0213     hreduction_factor = 1;
0214 end
0215 
0216 onpaper_position(3) = onscreen_position(3) * hreduction_factor;
0217 onpaper_position(4) = onscreen_position(4) * hreduction_factor;
0218 
0219 if ( onscreen_position(4) > 792 )
0220     vreduction_factor = 792 / onscreen_position(4);
0221 else
0222     vreduction_factor = 1;
0223 end
0224 
0225 onpaper_position(3) = onpaper_position(3) * vreduction_factor;
0226 onpaper_position(4) = onpaper_position(4) * vreduction_factor;
0227 
0228 onpaper_position(1) = (612 - onpaper_position(3))/2;
0229 onpaper_position(2) = (792 - onpaper_position(3))/2;
0230 
0231 set ( timeplt_obj{N}.figure, 'PaperPosition', onpaper_position );
0232 set ( timeplt_obj{N}.figure, 'Units', old_units );
0233 set ( timeplt_obj{N}.figure, 'PaperUnits', old_paper_units );
0234 
0235 
0236 return;
0237 
0238 
0239 
0240 
0241 
0242 
0243 function timeplt_gregax_day( jd )
0244 %TIMEPLT_GREGAX_DAY:  Writes gregorian axes tick labels
0245 
0246 %disp ( 'present in timeplt_gregax_day' );
0247 
0248 month_label = [    'Jan'; ...
0249                 'Feb';...
0250                 'Mar';...
0251                 'Apr';...
0252                 'May';...
0253                 'Jun';...
0254                 'Jul';...
0255                 'Aug';...
0256                 'Sep';...
0257                 'Oct';...
0258                 'Nov';...
0259                 'Dec'];
0260 
0261 %
0262 % First figure out the height of the bottom plot in points.
0263 % Then allow for 3 lines to fit here.
0264 old_units = get ( gca, 'Units' );
0265 set ( gca, 'Units', 'Points' );
0266 pos = get(gca, 'Position' );
0267 set ( gca, 'Units', old_units )
0268 height = pos(2);
0269 
0270 %
0271 % Fontsize should be the same as the ylabel.
0272 fsize = get ( get(gca,'YLabel'), 'Fontsize' );
0273 
0274 
0275 %
0276 % Now figure the height of the bottom plot in user coords.
0277 ylim = get ( gca, 'YLim' );
0278 cfactor = diff(ylim) / pos(4);
0279 
0280 
0281 xt = get ( gca, 'XTick' );
0282 greg = gregorian ( xt(:) );
0283 
0284 xlim = get(gca,'xlim');
0285 
0286 
0287 %
0288 % Make sure that the minute ticks start right on the day,
0289 % and not in the middle.
0290 % Stop the ticks somewhere around the end of xlim.  Don't really
0291 % care so much about this.
0292 jd0 = gmin(jd(:)); jd1 = xlim(2);
0293 start = gregorian(jd0);
0294 start = [start(1:3) 0 0 0];
0295 jd0 = julian(start);
0296 stop = gregorian(jd1);
0297 
0298 
0299 %
0300 % We need to know how many labels to write.
0301 % Assume that we want a maximum of 50 pts between labels.
0302 max_width = 40;
0303 point_width = pos(3);  
0304 dx = diff(xlim);
0305 scale_factor = dx/point_width;  % number of days per point
0306 
0307 day_tic = max ( max_width*scale_factor, 1 );
0308 
0309 %
0310 % round this up to the nearest day.
0311 day_tic = ceil(day_tic);
0312 
0313 %
0314 % do some more refinement to get good day splits
0315 if ( (day_tic >= 4) & (day_tic <6) )
0316     day_tic = 5;
0317 elseif ( (day_tic >= 6) & (day_tic <8.5) )
0318     day_tic = 7;
0319 elseif ( (day_tic >= 8.5) & (day_tic <12) )
0320     day_tic = 10;
0321 elseif ( (day_tic >= 12) & (day_tic <16) )
0322     day_tic = 14;
0323 end
0324 
0325 xt = [jd0:day_tic:jd1];
0326 
0327 ifind = find((xt>=xlim(1)) & (xt<=xlim(2)));
0328 xt = xt(ifind);
0329 set ( gca, ...
0330         'XTick', xt, ...
0331         'XTickLabel', [] );
0332 
0333 greg = gregorian(xt);
0334 
0335 
0336 
0337 
0338 
0339 %
0340 % Now label the xticks in days.
0341 gt_string = {     num2str(greg(1,3)); ...
0342                 month_label(greg(1,2),:); ...
0343                 num2str(greg(1,1)) };
0344 
0345 ypoint = ylim(1) - 0.5*fsize*cfactor;
0346 xt_label(1) = text ( xt(1), ypoint, 0, gt_string );
0347 
0348 
0349 %
0350 % Keep track of where to put a label for a new month or year
0351 % by differencing the gregorian dates.  Any entry that is not zero
0352 % means that the entry changed from the previous.
0353 tdiff = diff(greg(:,1:3));
0354 
0355 for i = 2:length(xt)
0356 
0357     if ( tdiff(i-1,1)  )
0358         year_str = num2str(greg(i,1));
0359     else
0360         year_str = '';
0361     end
0362 
0363     if ( tdiff(i-1,2)  )
0364         month_str = month_label(greg(i,2),:);
0365     else
0366         month_str = '';
0367     end
0368 
0369     if ( tdiff(i-1,3) )
0370         day_str = num2str(greg(i,3));
0371     else
0372         day_str = '';
0373     end
0374 
0375     gt_string = { day_str; month_str; year_str };
0376 
0377     xt_label(i) = text ( xt(i), ypoint, 0, gt_string );
0378 
0379         
0380 end
0381 
0382 
0383 set ( xt_label, ...
0384         'Fontsize', fsize, ...
0385         'HorizontalAlignment', 'Center', ...
0386         'VerticalAlignment', 'cap' );
0387 
0388 
0389 
0390 
0391 
0392 return;
0393 
0394 
0395 
0396 
0397 
0398 
0399 
0400 
0401 
0402 
0403 function timeplt_gregax_hour( jd )
0404 %TIMEPLT_GREGAX_HOUR:  Writes gregorian axes tick labels
0405 
0406 month_label = [    'Jan'; ...
0407                 'Feb';...
0408                 'Mar';...
0409                 'Apr';...
0410                 'May';...
0411                 'Jun';...
0412                 'Jul';...
0413                 'Aug';...
0414                 'Sep';...
0415                 'Oct';...
0416                 'Nov';...
0417                 'Dec'];
0418 
0419 %
0420 % First figure out the height of the bottom plot in points.
0421 % Then allow for 3 lines to fit here.
0422 old_units = get ( gca, 'Units' );
0423 set ( gca, 'Units', 'Points' );
0424 pos = get(gca, 'Position' );
0425 set ( gca, 'Units', old_units )
0426 height = pos(2);
0427 
0428 %
0429 % Fontsize should be the same as the ylabel.
0430 fsize = get ( get(gca,'YLabel'), 'Fontsize' );
0431 
0432 %
0433 % Fontsize shouldn't be too large.
0434 %fsize = min ( height / 4, 12 );
0435 
0436 
0437 %
0438 % Now figure the height of the bottom plot in user coords.
0439 ylim = get ( gca, 'YLim' );
0440 cfactor = diff(ylim) / pos(4);
0441 
0442 
0443 xt = get ( gca, 'XTick' );
0444 greg = gregorian ( xt(:) );
0445 
0446 xlim = get(gca,'xlim');
0447 
0448 
0449 %
0450 % Make sure that the hour ticks start right on the hour,
0451 % and not in the middle.
0452 % Stop the ticks somewhere around the end of xlim.  Don't really
0453 % care so much about this.
0454 % Also, the first tick starts where the data starts.
0455 jd0 = gmin(jd(:)); jd1 = xlim(2);
0456 start = gregorian(jd0);
0457 start = [start(1:4) 0 0];
0458 jd0 = julian(start);
0459 stop = gregorian(jd1);
0460 
0461 
0462 %
0463 % We need to know how many labels to write.
0464 % Assume that we want a maximum of 50 pts between labels.
0465 max_width = 40;
0466 point_width = pos(3);  
0467 dx = diff(xlim);
0468 scale_factor = dx/point_width;  % points per number of days
0469 
0470 hour_tic = max_width * scale_factor;
0471 
0472 %
0473 % Now round this up to the nearest minute.
0474 hour_tic = ceil ( hour_tic * 24 ) / 24;
0475 
0476 %hour_tic = ceil(max(diff(xt(:)))*24)/24;
0477 
0478 
0479 xt = [jd0:hour_tic:jd1];
0480 
0481 ifind = find((xt>xlim(1)) & (xt<xlim(2)));
0482 xt = xt(ifind);
0483 set ( gca, ...
0484         'XTick', xt, ...
0485         'XTickLabel', [] );
0486 
0487 greg = gregorian(xt);
0488 
0489 
0490 
0491 %
0492 % Now label the xticks in days.
0493 hour_str = sprintf ( '%02i:00', greg(1,4) );
0494 day_str = sprintf ( '%s %2.0f', month_label(greg(1,2),:), greg(1,3) );
0495 year_str = num2str(greg(1,1));
0496 gt_string = { hour_str; day_str; year_str };
0497 
0498 ypoint = ylim(1) - 0.5*fsize*cfactor;
0499 xt_label(1) = text ( xt(1), ypoint, 0, gt_string );
0500 
0501 
0502 %
0503 % Keep track of where to put a label for a new month or year
0504 % by differencing the gregorian dates.  Any entry that is not zero
0505 % means that the entry changed from the previous.
0506 tdiff = diff(greg(:,1:4));
0507 
0508 for i = 2:length(xt)
0509 
0510     if ( tdiff(i-1,4)  )
0511         hour_str = sprintf ( '%02i:00', greg(i,4) );
0512     else
0513         hour_str = '';
0514     end
0515 
0516     if ( tdiff(i-1,3)  )
0517         day_str = sprintf ( '%s %2.0f', month_label(greg(i,2),:), greg(i,3) );
0518     else
0519         day_str = '';
0520     end
0521 
0522     if ( tdiff(i-1,3) )
0523         year_str = num2str(greg(i,1));
0524     else
0525         year_str = '';
0526     end
0527 
0528     gt_string = { hour_str; day_str; year_str };
0529 
0530     xt_label(i) = text ( xt(i), ypoint, 0, gt_string );
0531 
0532         
0533 end
0534 
0535 
0536 set ( xt_label, ...
0537         'Fontsize', fsize, ...
0538         'HorizontalAlignment', 'Center', ...
0539         'VerticalAlignment', 'cap' );
0540 
0541 
0542 
0543 
0544 
0545 return;
0546 
0547 
0548 
0549 
0550 
0551 
0552 
0553 
0554 
0555 
0556 
0557 function timeplt_gregax_minute( jd )
0558 %TIMEPLT_GREGAX_MINUTE:  Writes gregorian axes tick labels
0559 
0560 month_label = [    'Jan'; ...
0561                 'Feb';...
0562                 'Mar';...
0563                 'Apr';...
0564                 'May';...
0565                 'Jun';...
0566                 'Jul';...
0567                 'Aug';...
0568                 'Sep';...
0569                 'Oct';...
0570                 'Nov';...
0571                 'Dec'];
0572 
0573 %
0574 % First figure out the height of the bottom plot in points.
0575 % Then allow for 3 lines to fit here.
0576 old_units = get ( gca, 'Units' );
0577 set ( gca, 'Units', 'Points' );
0578 pos = get(gca, 'Position' );
0579 set ( gca, 'Units', old_units )
0580 height = pos(2);
0581 
0582 %
0583 % Fontsize shouldn't be too large.
0584 fsize = get ( get(gca,'YLabel'), 'Fontsize' );
0585 %fsize = min ( height / 4, 12 );
0586 
0587 
0588 %
0589 % Now figure the height of the bottom plot in user coords.
0590 ylim = get ( gca, 'YLim' );
0591 cfactor = diff(ylim) / pos(4);
0592 
0593 
0594 xt = get ( gca, 'XTick' );
0595 greg = gregorian ( xt(:) );
0596 
0597 xlim = get(gca,'xlim');
0598 
0599 
0600 %
0601 % Make sure that the minute ticks start right on the minute,
0602 % and not in the middle.
0603 % Stop the ticks somewhere around the end of xlim.  Don't really
0604 % care so much about this.
0605 jd0 = gmin(jd(:)); jd1 = xlim(2);
0606 start = gregorian(jd0);
0607 start = [start(1:5) 0];
0608 jd0 = julian(start);
0609 stop = gregorian(jd1);
0610 
0611 
0612 %
0613 % We need to know how many labels to write.
0614 % Assume that we want a maximum of 50 pts between labels.
0615 max_width = 40;
0616 point_width = pos(3);  
0617 dx = diff(xlim);
0618 scale_factor = dx/point_width;  % points per number of days
0619 
0620 min_tic = max_width * scale_factor;
0621 
0622 %
0623 % Now round this up to the nearest minute.
0624 min_tic = ceil ( min_tic * 24 * 60 ) / 24 / 60;
0625 
0626 %min_tic = ceil(max(diff(xt(:)))*24*60)/(24*60);
0627 
0628 
0629 
0630 
0631 xt = [jd0:min_tic:jd1];
0632 
0633 ifind = find((xt>=xlim(1)) & (xt<=xlim(2)));
0634 xt = xt(ifind);
0635 set ( gca, ...
0636         'XTick', xt, ...
0637         'XTickLabel', [] );
0638 
0639 greg = gregorian(xt);
0640 
0641 
0642 
0643 %
0644 % Now label the xticks in days.
0645 year_str = num2str(greg(1,1));
0646 day_str = sprintf ( '%s %2.0i', month_label(greg(1,2),:), greg(1,3) ); 
0647 min_str = sprintf ( '%.0f:%02i', greg(1,4), greg(1,5) );
0648 gt_string = { min_str; day_str; year_str };
0649 
0650 ypoint = ylim(1) - 0.5*fsize*cfactor;
0651 xt_label(1) = text ( xt(1), ypoint, 0, gt_string );
0652 
0653 
0654 %
0655 % Keep track of where to put a label for a new month or year
0656 % by differencing the gregorian dates.  Any entry that is not zero
0657 % means that the entry changed from the previous.
0658 tdiff = diff(greg(:,1:5));
0659 
0660 for i = 2:length(xt)
0661 
0662     if ( tdiff(i-1,1)  )
0663         year_str = num2str(greg(i,1));
0664     else
0665         year_str = '';
0666     end
0667 
0668     if ( tdiff(i-1,3)  )
0669         day_str = sprintf ( '%s %2.0i', month_label(greg(i,2),:), greg(i,3) ); 
0670     else
0671         day_str = '';
0672     end
0673 
0674     if ( tdiff(i-1,5) )
0675         min_str = sprintf ( '%.0f:%02i', greg(i,4), greg(i,5) );
0676     else
0677         min_str = '';
0678     end
0679 
0680     gt_string = { min_str; day_str; year_str };
0681 
0682     xt_label(i) = text ( xt(i), ypoint, 0, gt_string );
0683 
0684         
0685 end
0686 
0687 
0688 set ( xt_label, ...
0689         'Fontsize', round(fsize), ...
0690         'HorizontalAlignment', 'Center', ...
0691         'VerticalAlignment', 'cap', ...
0692         'Tag', 'xtick labels' );
0693 
0694 
0695 
0696 
0697 return;
0698 
0699 
0700 
0701 
0702 
0703 
0704 
0705 
0706 
0707 
0708 
0709 
0710 function timeplt_gregax_month( jd )
0711 %TIMEPLT_GREGAX_MONTH:  Writes gregorian axes tick labels
0712 
0713 month_label = [    'Jan'; ...
0714                 'Feb';...
0715                 'Mar';...
0716                 'Apr';...
0717                 'May';...
0718                 'Jun';...
0719                 'Jul';...
0720                 'Aug';...
0721                 'Sep';...
0722                 'Oct';...
0723                 'Nov';...
0724                 'Dec'];
0725 
0726 
0727 %
0728 % First figure out the height of the bottom plot in points.
0729 % Then allow for 3 lines to fit here.
0730 old_units = get ( gca, 'Units' );
0731 set ( gca, 'Units', 'Points' );
0732 pos = get(gca, 'Position' );
0733 set ( gca, 'Units', old_units )
0734 height = pos(2);
0735 
0736 %
0737 % Fontsize should be the same as the ylabel.
0738 fsize = get ( get(gca,'YLabel'), 'Fontsize' );
0739 
0740 
0741 
0742 %
0743 % Now figure the height of the bottom plot in user coords.
0744 ylim = get ( gca, 'YLim' );
0745 cfactor = diff(ylim) / pos(4);
0746 
0747 
0748 xt = get ( gca, 'XTick' );
0749 greg = gregorian ( xt(:) );
0750 
0751 xlim = get(gca,'xlim');
0752 
0753 
0754 %
0755 % Make sure that the minute ticks start right on the day,
0756 % and not in the middle.
0757 % Stop the ticks somewhere around the end of xlim.  Don't really
0758 % care so much about this.
0759 jd0 = gmin(jd(:)); jd1 = xlim(2);
0760 start = gregorian(jd0);
0761 start = [start(1:2) 1 0 0 0];
0762 jd0 = julian(start);
0763 stop = gregorian(jd1);
0764 
0765 
0766 %
0767 % We need to know how many labels to write.
0768 % Assume that we want a maximum of 50 pts between labels.
0769 max_width = 40;
0770 point_width = pos(3);  
0771 dx = diff(xlim);
0772 scale_factor = dx/point_width;  % points per number of days
0773 
0774 mon_tic = ceil ( max_width * scale_factor / 31 );
0775 
0776 
0777 %mon_tic = ceil(max(diff(xt(:)/31)));
0778 
0779 gticks = start;
0780 last_gtick = gticks;
0781 
0782 last_jtick = julian(last_gtick);
0783 
0784 while ( last_jtick <= xlim(2) )
0785     this_month = last_gtick(2);
0786     this_year = last_gtick(1);
0787     if ( (this_month - 1 + mon_tic) >= 12 )
0788         this_year = this_year+1;
0789     end
0790         
0791     next_month = mod ( this_month -1 + mon_tic, 12) + 1;
0792 
0793     
0794     last_gtick = [this_year next_month 1 0 0 0];
0795     last_jtick = julian(last_gtick);
0796     gticks = [gticks; last_gtick ];
0797 end
0798 
0799 
0800 
0801 
0802 xt = julian(gticks);
0803 
0804 ifind = find((xt>=xlim(1)) & (xt<=xlim(2)));
0805 xt = xt(ifind);
0806 set ( gca, ...
0807         'XTick', xt, ...
0808         'XTickLabel', [] );
0809 
0810 greg = gregorian(xt);
0811 
0812 
0813 
0814 %
0815 % Now figure the height of the bottom plot in user coords.
0816 ylim = get ( gca, 'YLim' );
0817 cfactor = diff(ylim) / pos(4);
0818 
0819 %
0820 % Now label the xticks in days.
0821 year_str = num2str(greg(1,1));
0822 month_str = month_label(greg(1,2),:);
0823 gt_string = { month_str; year_str };
0824 
0825 ypoint = ylim(1) - 0.5*fsize*cfactor;
0826 xt_label(1) = text ( xt(1), ypoint, 0, gt_string );
0827 
0828 
0829 %
0830 % Keep track of where to put a label for a new month or year
0831 % by differencing the gregorian dates.  Any entry that is not zero
0832 % means that the entry changed from the previous.
0833 tdiff = diff(greg(:,1:2));
0834 
0835 for i = 2:length(xt)
0836 
0837     if ( tdiff(i-1,1)  )
0838         year_str = num2str(greg(i,1));
0839     else
0840         year_str = '';
0841     end
0842 
0843     if ( tdiff(i-1,2)  )
0844         month_str = month_label(greg(i,2),:);
0845     else
0846         month_str = '';
0847     end
0848 
0849     gt_string = { month_str; year_str };
0850 
0851     xt_label(i) = text ( xt(i), ypoint, 0, gt_string );
0852 
0853         
0854 end
0855 
0856 
0857 set ( xt_label, ...
0858         'Fontsize', fsize, ...
0859         'HorizontalAlignment', 'Center', ...
0860         'VerticalAlignment', 'cap' );
0861 
0862 
0863 
0864 
0865 return;
0866 
0867 
0868 
0869 
0870 
0871 
0872 
0873 
0874 
0875 function timeplt_gregax_year( jd )
0876 %TIMEPLT_GREGAX_DAY:  Writes gregorian axes tick labels
0877 
0878 
0879 %
0880 % First figure out the height of the bottom plot in points.
0881 % Then allow for 3 lines to fit here.
0882 old_units = get ( gca, 'Units' );
0883 set ( gca, 'Units', 'Points' );
0884 pos = get(gca, 'Position' );
0885 set ( gca, 'Units', old_units )
0886 height = pos(2);
0887 
0888 %
0889 % Fontsize should be the same as the ylabel.
0890 fsize = get ( get(gca,'YLabel'), 'Fontsize' );
0891 
0892 
0893 
0894 %
0895 % Now figure the height of the bottom plot in user coords.
0896 ylim = get ( gca, 'YLim' );
0897 cfactor = diff(ylim) / pos(4);
0898 
0899 
0900 xt = get ( gca, 'XTick' );
0901 greg = gregorian ( xt(:) );
0902 
0903 xlim = get(gca,'xlim');
0904 
0905 
0906 %
0907 % Make sure that the minute ticks start right on the day,
0908 % and not in the middle.
0909 % Stop the ticks somewhere around the end of xlim.  Don't really
0910 % care so much about this.
0911 jd0 = gmin(jd(:)); jd1 = xlim(2);
0912 start = gregorian(jd0);
0913 start = [start(1) 1  1 0 0 0];
0914 jd0 = julian(start);
0915 stop = gregorian(jd1);
0916 
0917 
0918 %
0919 % We need to know how many labels to write.
0920 % Assume that we want a maximum of 50 pts between labels.
0921 max_width = 40;
0922 point_width = pos(3);  
0923 dx = diff(xlim);
0924 scale_factor = dx/point_width;  % points per number of days
0925 
0926 year_tic = ceil ( max_width * scale_factor / 365.24 );
0927 
0928 %year_tic = ceil(max(diff(xt(:)/365.24)));
0929 
0930 
0931 gyears = start;
0932 last_gyear = start; 
0933 last_jyear = julian(start);
0934 while ( last_jyear <= jd1 )
0935     last_gyear(1) = last_gyear(1) + year_tic;
0936     last_jyear = julian(last_gyear);
0937     gyears = [gyears; last_gyear];
0938 end
0939 
0940 xt = julian(gyears);
0941 
0942 ifind = find((xt>=xlim(1)) & (xt<=xlim(2)));
0943 xt = xt(ifind);
0944 set ( gca, ...
0945         'XTick', xt, ...
0946         'XTickLabel', [] );
0947 
0948 greg = gregorian(xt);
0949 
0950 year_labels = num2str(greg(:,1));
0951 set ( gca, 'XTickLabel', year_labels );
0952 
0953 
0954 
0955 
0956 
0957 return;
0958 
0959 
0960 
0961 
0962 
0963 
0964 
0965 
0966 
0967 
0968 function xnew=gmin(x)
0969 %function xnew=gmin(x)
0970 % just like min, except that it skips over bad points
0971 [imax,jmax]=size(x);
0972 
0973 for j=1:jmax
0974    good=find(finite(x(:,j)));
0975    if length(good)>0
0976        xnew(j)=min(x(good,j));
0977    else
0978        xnew(j)=NaN;
0979    end
0980 end
0981 
0982 
0983 
0984 
0985 
0986 
0987 
0988 
0989 function xnew=gmax(x)
0990 %function xnew=gmax(x)
0991 % just like max, except that it skips over bad points
0992 [imax,jmax]=size(x);
0993 
0994 for j=1:jmax
0995        good=find(finite(x(:,j)));
0996        if length(good)>0
0997           xnew(j)=max(x(good,j));
0998        else
0999           xnew(j)=NaN;
1000        end
1001 end

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