#!/usr/bin//perl

# Usage: sep-sizes <size-of-largest-clone>
#   The files OUTPUT.5+.filtered and num-nodes-STATS.5+.filtered must be present.
#
#
# Output: for each i in the range [5 .. size-of-largest-clone], the file
#   OUTPUT.filtered.i, which contains clone pairs in OUTPUT.5+.filtered whose clones
#   are of size i.

$largestSize = $ARGV[0];

open (NUM_NODES, "num-nodes-STATS.5+.filtered") 
    or die "Unable to open num-nodes-STATS.5+.filtered!";
open (INPUT, "OUTPUT.5+.filtered") 
    or die "Unable to open OUTPUT.5+.filtered!";

for($i = 5; $i <= $largestSize; $i++) {
    seek(NUM_NODES, 0, 0);
    seek(INPUT, 0, 0);
    open (OUTPUT, "> OUTPUT.filtered." . $i);
    while(defined($numNodes = <NUM_NODES>) && 
	  defined($inputLine = <INPUT>)) {
	print OUTPUT $inputLine 
	    if ($numNodes == $i);
    }
    close OUTPUT;
    print "done ".$i."\n";
}
