function savePrefix = graphMessages(jobdir)

%%% Fetch data
file = dir(fullfile(jobdir,'*.messages'));
if length(file) ~= 1
    error([ 'There should be exactly one file of the form *.messages in ' jobdir ]);
end
file = fullfile(jobdir, file.name);
[PATHSTR,NAME] = fileparts(file);
savePrefix = fullfile(PATHSTR, NAME);

import = importdata(file,'\t',1);
[rows cols] = size(import.data);

messages={import.colheaders{1,3:cols}};
data = import.data(:,3:cols);

colormap mycolormap;
subplot(2,1,1);
pie( sum(data)+eps, [0 0 1 1 1 1 1 1 1 1], repmat({''},1,10) );
view(-90,-90);
zoom(1.5);
legend(messages,'Location','EastOutside','Interpreter','none');

subplot(2,1,2);
bar(0:rows-1, data, 'stack', 'BarWidth', .5);
xlabel('Processing element (deme)');
xlim([-1 rows]);

saveas(gcf, [savePrefix '.messages' '.eps'], 'psc2' );
saveas(gcf, [savePrefix '.messages' '.fig'] );
saveas(gcf, [savePrefix '.messages' '.png'] );

close
end
