X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=quacks-ingredients-counts;h=a1e5f27e40bbcbd86da57aaa6116b2427b0cf13e;hb=d38a78e3f0d0d5e78f2a5f9af996fde136800f43;hp=0affe2efe4eee8892bd45228c0fbaa23c969cd29;hpb=43b7e9e700151cda673bad9642640eb444517306;p=reprap-play.git diff --git a/quacks-ingredients-counts b/quacks-ingredients-counts index 0affe2e..a1e5f27 100755 --- a/quacks-ingredients-counts +++ b/quacks-ingredients-counts @@ -1,6 +1,9 @@ #!/usr/bin/perl -w +use strict; + use Data::Dumper; +use POSIX; $_=; chomp or die; our @names = split /\t/, $_; @@ -10,12 +13,59 @@ our %count; foreach my $nspots (qw(1 2 3 4)) { $_=; 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 <error and die $!; __DATA__ White Green Blue Red Yellow Purple Black Orange