#!/usr/athena/bin/perl -lw

use strict;
use IO::File;

do "./dexmaster-current";
undef $@;

#print "Loading in datadex...";
loaddex ('datadex', 'main') || die "Cannot open datadex";

my @circ = sort qw( C/P H );
my @reserve = sort qw( P LP VLP SFWA SFWA-P SFWA-VLP );
my @special = sort qw( SR-P SR-H SR-LP );

my @care = sort (@circ, @reserve, @special);

my @counts;

use vars qw( %dex %category );
for my $bk (@{$dex{main}})
  {
    my %hash = codetohash ($$bk{code});
    my %x = map { $_ => 0 } keys %category;
    $x{ basecode($_) } += $hash{$_} for keys %hash;  # handles @P
    $x{"book"} = $bk;
    push @counts, \%x if grep { $x{$_} } @circ;
  }

my %tot = ("C/P" => 0, "H" => 0);
$tot{"C/P"} += $$_{"C/P"} for @counts;
$tot{"H"} += $$_{"H"} for @counts;

my %bin;
for my $pcirc (0..2) {
  for my $hcirc (0..3) {
    for my $res (0, .5, 1) {
      $bin{$pcirc}{$hcirc}{$res} = 0;
    }
  }
}

for my $count (@counts)
  {
    my $res = 0;
    $res = .5 if grep { $$count{$_} } @special;
    $res = 1 if grep { $$count{$_} } @reserve;
    ++$bin{$$count{"C/P"}}{$$count{"H"}}{$res};

    print panther($$count{"book"})
      if $$count{"C/P"} == 2 and $$count{"H"} == 3 and $res == 1;
  }
exit 0;

print scalar(@counts), " distinct titles";
print "$tot{'C/P'} C/P, $tot{H} H (indistinct)";
print "";
for my $pcirc (0..2) {
  for my $hcirc (0..3) {
    for my $res (0, .5, 1) {
      print join "\t", $pcirc, $hcirc, $res, $bin{$pcirc}{$hcirc}{$res};
    }
  }
}
