function momulper_examine(setup, tag)
% Analyse the results of one tag: Attempt to read the run traces and
% provide graphics for output. Automatically export all plots that are
% possible. The user can decide later, which ones to use.
%
% Here we assume that the setup directories exist and that they
% contain all the necessary files.

%% Read the info files describing the purpose of this run

infofn=fullfile(setup.resdir,tag,'info.txt')

fid = fopen(infofn);
dummy = fgetl(fid);
datafname = fgetl(fid);
fclose(fid);

datafname    = fullfile(setup.datadir,datafname);
initpopname  = fullfile(setup.resdir,tag,'pop0.dat');
finalpopname = fullfile(setup.resdir,tag,'pop_final.dat');
parentsfname = fullfile(setup.resdir,tag,'parents.dat');
tracefname   = fullfile(setup.resdir,tag,'traced.dat');

inipop   = read_mlppop(initpopname);
finpop   = read_mlppop(finalpopname);


parentof = read_parents(parentsfname);
traced   = read_trace(tracefname);

d = dlmread(datafname, ' ');

%% In multiobjective cases, present the final population
if (finpop.nobj > 1)
  figure;
  parcoord(finpop);
  print('-depsc', fullfile(setup.postdir,[tag,'_parcoord.original.eps']));
end

%% In 2D binary classification cases, visualize the dataset:
figure
hold on;
vis_binclass_dataset(d);

if (finpop.nobj == 1) 
  % In single-objective cases, select the best individual:
  [v,ind] = sort(finpop.obj,'ascend');
  indsel = ind(1);
  %indsel = ind(1:min(8,numel(ind)))
else
  % In multi-objective cases, select up to 10 first individuals:
  % TODO: Proper heuristics
  indsel = 1:(min(10,numel(finpop.id)))
end

%% For 2D cases and suitable networks, visualize the MLP action
lstyle={'k-','r-','g-','b-','m-','c-','y-','k:','b:','m:'}
ils=0;
for iind=(indsel(:)')
  ils = ils+1;
  fprintf(1,'Visualizing action of index %d\n',finpop.id(iind));
  visualize_action_2d_internal(finpop.net{iind}, lstyle{ils});
  if numel(indsel)<5
    visualize_hidden_2d_internal(finpop.net{iind}, 'k-');
  end
end
axis([-1 1 -1 1],'square')
print('-depsc', fullfile(setup.postdir,[tag,'_concept.original.eps']));


%% Try out the tracing outputs:
% FIXME: Not at all final!!
figure;
hold on;
for ids=finpop.id(indsel)
  fprintf(1,'plotting trace for index %d\n',ids);
  plot_traced(ids,traced,parentof,[1,2]);
end
print('-depsc', fullfile(setup.postdir,[tag '_trace.original.eps']));
