#!/usr/local/bin/perl -w # Aaugment.p reads an alist and writes an augmented alist matrix # corresponding to the same code. # # with radford Thu 5/8/99 $seed=123 ; $verbose = 1 ; $randomorder = 0 ; # if this is 1, then each list of points n addressed by the first # point in each face[r] with r>=2 is randomly ordered for all their checks. eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # first, read the old alist in $_ = <>; ($L,$M) = split ; print STDERR $L , " " , $M , "\n" ; $N = $L ; for ( $n = 1 ; $n <= $N ; $n ++ ) { $nlist[$n] = "" ; $numnlist[$n] = 0 ; } for ( $m = 1 ; $m <= $M ; $m ++ ) { $mlist[$m] = "" ; $nummlist[$m] = 0 ; } $_ = <>; # max numbers $_ = <>; @oldnumnlist = split ; $_ = <>; @oldnummlist = split ; for ( $l = 1 ; $l <= $L ; $l ++ ) { $_ = <>; @y = split ; for ( $u = 0 ; $u <= $#y ; $u ++ ){ $ty = $y[$u] ; if ( $ty > 0 ) { $m = $ty ; $n = $l ; &mnadd($m,$n); } } } # # retain the old N and M values $M0 = $M ; # the final check number will be counted here if ( $randomorder ) { srand ( $seed ) ; } print STDERR "===== Aaugment.p ===== (c) DJCM 1999 =====\n" ; print STDERR "N0 = $N, M0 = $M0\n" ; for ( $n = 1 ; $n <= $N ; $n ++ ) { # go through all columns adding extra checks @nlistn = split ( "\t" , $nlist[$n] ) ; print STDERR @nlistn, "\n" if ($verbose>3) ; foreach $m1 (@nlistn) { if ( ( $m1 > 0) && ( $m1 <= $M0 ) ) { foreach $m2 (@nlistn) { print STDERR "considering n=$n, m1=$m1, m2=$m2\n" if ($verbose>4); if ( ( $m2 > $m1) && ( $m2 <= $M0 ) ) { print STDERR "adding rows $m1 and $m2 .. " if ($verbose>2) ; $M++ ; $mlist[$M] = "" ; $nummlist[$M] = 0 ; @mlist1 = split ( "\t" , $mlist[$m1] ) ; @mlist2 = split ( "\t" , $mlist[$m2] ) ; $added = 0 ; foreach $nn ( @mlist1 , @mlist2 ) { if ( $nn != $n ) { &mnadd($M,$nn) ; $added ++ ; } } print STDERR "added row had $added ones\n" if ($verbose > 2 ) ; } } } } } print STDERR "done N = $N ; Mwritten = $M (was $M0)\n" ; if ( 1 ) { $head = "$N $M\n" ; print STDERR "Writing code.\n" ; # find $t (max) and $tr (max) $t = 0 ; $tr = 0 ; for ( $n = 1 ; $n <= $N ; $n ++ ) { if ( $numnlist[$n] > $t ) { $t = $numnlist[$n] ; } } for ( $m = 1 ; $m <= $M ; $m ++ ) { if ( $nummlist[$m] > $tr ) { $tr = $nummlist[$m] ; } } $head .= "$t $tr\n" ; # append zeros to short lines for ( $n = 1 ; $n <= $N ; $n ++ ) { $thisn = $numnlist[$n] ; $head .= "$thisn " ; while ( $thisn < $t ) { $nlist[$n] .= "0\t" ; $thisn ++ ; } } $head .= "\n" ; for ( $m = 1 ; $m <= $M ; $m ++ ) { $thism = $nummlist[$m] ; $head .= "$thism " ; while ( $thism < $tr ) { $mlist[$m] .= "0\t" ; $thism ++ ; } } $head .= "\n" ; print $head ; # print STDERR $head ; # finish lists for ( $n = 1 ; $n <= $N ; $n ++ ) { $nlist[$n] =~ s/\t$/\n/ ; print $nlist[$n] ; } for ( $m = 1 ; $m <= $M ; $m ++ ) { $mlist[$m] =~ s/\t$/\n/ ; print $mlist[$m] ; } } sub mnadd { local($m,$n)=@_; # put m and n on each others lists $nlist[$n] .= $m."\t" ; $mlist[$m] .= $n."\t" ; $numnlist[$n] ++ ; $nummlist[$m] ++ ; }