#!/usr/bin/perl -w
+use strict;
+
use Data::Dumper;
+use POSIX;
$_=<DATA>; chomp or die;
our @names = split /\t/, $_;
foreach my $nspots (qw(1 2 3 4)) {
$_=<DATA>; chomp or die;
my @l = split /\t/, $_;
- foreach my $i (0..$#names) { $count{$names[$i]}{$nspots} = $l[$i] // 0; }
+ foreach my $i (0..$#names) { $count{$names[$i]}{$nspots} = $l[$i] || 0; }
}
$_ = Dumper(\%count);
s{^}{// }mg;
-print or die $!;
+
+our $name;
+our $total_count;
+our $max_nrows=0;
+our $max_rowsz=0;
+
+sub wrtoplevel () {
+ print "module $name(){ ////toplevel\n";
+ my $cs = $count{$name};
+ my $total = 0; $total += $_ foreach values %$cs;
+ my $rowsz = ceil(sqrt($total));
+ my $nrows = ceil($total / $rowsz);
+ $total_count += $total;
+ $max_nrows = $nrows if $nrows > $max_nrows;
+ $max_rowsz = $rowsz if $rowsz > $max_rowsz;
+ my $ix = 0;
+ print "// total=$total, rowsz=$rowsz, nrows=$nrows\n";
+ foreach my $nspots (sort keys %$cs) {
+ my $c = $cs->{$nspots};
+ print <<END;
+ union(){
+ Frame(\$phase, token_pitch * [ $rowsz + 0.5, $nrows ]);
+ \$nspots = $nspots;
+END
+ while ($c--) {
+ my $xy = sprintf "[ %5.1f, %5.1f ]",
+ int($ix / $nrows) - 0.5 * ($rowsz-1),
+ $ix % $nrows - 0.5 * ($nrows-1);
+ print " translate(token_pitch * $xy) Token_L();\n";
+ $ix++;
+ }
+ print <<END;
+ };
+END
+ }
+ print "}\n";
+}
+
+foreach $name (sort keys %count) {
+ wrtoplevel();
+}
+
+print <<END;
+// total_count=$total_count
+// max_rowsz=$max_rowsz max_nrows=$max_nrows
+END
+
+STDOUT->error and die $!;
__DATA__
White Green Blue Red Yellow Purple Black Orange