package Simulation::Automate::PostProcessors;

sub Visualise {
  if($verylast) {
do "$results_file_name";
my $ndests=$nports;
my $ncolors=$ndests+3;
my $ncols=($nbufs+1)*$nports;

my @colors=qw(
orange
blue
red
mediumblue
green
darkblue
navy
dodgerblue
skyblue
royalblue
cornflowerblue
gray
darkgray
silver
lightgrey
darkseagreen 
lightgreen 	
palegreen 	
forestgreen 	
limegreen 	
darkgreen 	
green
lime
seagreen 	
mediumseagreen 	
mintcream 	
springgreen 	
mediumspringgreen
mediumaquamarine 
aquamarine 	
turquoise 	
);
#"$ncols $nrows $ncolors 1",
my $xpm_header=<<"ENDH";
/* XPM */
static char * visualiser_xpm[] = {
"$nrows $ncols $ncolors 1",
"       c white",
"b      c black",
ENDH
my $xpm_filename = $results_file_name;
 $xpm_filename=~s/res$/xpm/;
open XPM,">$xpm_filename";
print XPM $xpm_header;

foreach my $dest (0..$ndests-1) { #FIXME for larger values(>9: use HEX? 2-byte?)
print XPM "\"$dest      c ",$colors[$dest],"\",\n";
}
print XPM "\"$ndests      c white\",\n";

#for my $row (1..$nrows) {

#  print XPM '"';
#  for my $p (0..$nports-1){
#    for my $b (0..$nbufs) {
#$col=$p*($nbufs+1)+$b;
##  for my $col (0..$ncols-1) {
#if($b==$nbufs){
#(not defined($dest[$row][$col])) && ($dest[$row][$col]='b');
#} else {
#(not defined($dest[$row][$col])) && ($dest[$row][$col]=' ');
#}
#print XPM $dest[$row][$col] ;
##}
#} #nbufs
#} #nports
#print XPM "\",\n";

#} #nrows
##############################################################################



  for my $p (0..$nports-1){
    for my $b (0..$nbufs) {
$col=$p*($nbufs+1)+$b;
  print XPM '"';
for my $row (1..$nrows) {
if($b==$nbufs){
(not defined($dest[$row][$col])) && ($dest[$row][$col]='b');
} else {
(not defined($dest[$row][$col])) && ($dest[$row][$col]=' ');
}
print XPM $dest[$row][$col] ;
} #nrows
print XPM "\",\n";
}#nbufs
}#ncols

print XPM "};\n";
close XPM;
system "eog $xpm_filename&";
}

}
1;
