componentChronograms.m 1.79 KB
function []=componentChronograms(varargin)
% function []=componentChronograms(varargin)
% 
% This function draws the chronogram of the execution of multiple
% CoolBOT components. 
%
% Input parameters:
%   varargin-> list of component names as strings for which the chronogram
%   will be built. For example: componentChronogram('Component1','Component2')
% Output parameters:
%   none
% 
% Author: Antonio C. Domí­nguez Brito (adominguez@iusiani.ulpgc.es)
% Institution: SIANI-ULPGC (www.iusiani.ulpgc.es)
% Date: April 23th 2008

if nargin>0

	colorPalette={'-m','-b','-g','-r','-k','-y','-c'};
	
	% reading chronograms
	error=0;
	maxTime=0; minTime=dateVectorToSeconds(clock);
	for component=1:size(varargin,2)
	
		fileName=[varargin{component} '.chronofile']; % chrono file name
		dataFile=load(fileName,'-ascii'); % reading chrono file
			
		if size(dataFile,2)~=7
		
			fprintf('ERROR: Chrono file "%s" does not exist, or does not have the right format.\n',fileName);
			error=1;
			
		else
		
			times{component}=dateVectorToSeconds(dataFile(:,1:6));
			levels{component}=dataFile(:,7);
			
			if component>1
				levels{component}=levels{component}+1.1*(component-1);
			end
			
			minTime=min([minTime times{component}(1)]);
			maxTime=max([maxTime times{component}(end)]);
			
		end
		
	end
	
	if error return; end % aborting if any error loading chrono files
	
	hold on;
	
	for component=1:size(varargin,2)
	
		times{component}=times{component}-minTime;

		h(component)=plot( ...
			times{component}, ...
			levels{component}, ...
			colorPalette{ rem(component,size(colorPalette,2))+1 } ...
		);	
	
	end


	legend(h,varargin);
  	axis([0 maxTime-minTime -.1 size(varargin,2)*1.1]);
	title('Component Chronograms');
	xlabel('seconds');
	grid on;

else

	fprintf('WARNING: Doing nothing. Input arguments not provided.\n');

end