#!/usr/local/bin/perl -w # MCY.p # reads in a difference set and a design and writes out # a multi-matrix cyclic code. # MCY.p M=157 DSfile=string/DS10.157 Dfile=string/D10.4.2 > A # based on binarize.p and G2H.p # writes Alist matrix to stdout $M=0; $DSfile = "string/157.10" ; # difference set $Dfile = "string/D10.4.2" ; # design $skipthese = 0 ; # whether to omit some elements of the construction $v = 0 ; eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; if($M eq "0" ) { print STDERR "usage:\n "; print STDERR " MCY.p M=157 DSfile=string/DS10.157 Dfile=string/D10.4.2 > A\n" ; } # read the design open ( D , "< $Dfile" ) ; $matrices = 0 ; while ( ) { next if ( /^\s*\#/ ) ; $matrices ++ ; @a = split ; $i = 0 ; $I = $#a ; for ( $i = 0 ; $i < $I ; $i ++ ) { $f = $a[$i] ; $A{$matrices,$i} = $f ; print "$f\t" if($v) ; } print "\n orientation: " if($v) ; if ( $a[$I] eq "A" ) { $orientation[$matrices] = 1 ; } elsif ( $a[$I] eq "B" ) { $orientation[$matrices] = -1 ; } else { print STDERR "problem with $a[$I-1] \n" ; exit(0) ; } print $orientation[$matrices]."\n" if($v) ; } open ( H , "< $DSfile" ) ; $i = 0 ; $k = 0 ; $_ = ; @r = split ; # @r contains the difference set. close(H) ; for ( $k = 1 ; $k <= $M ; $k ++ ) { $offset = 0 ; for ( $m = 1 ; $m <= $matrices ; $m ++ ) { # set up the current difference set. for ( $i = 0 ; $i < $I ; $i ++ ) { $thisA = $A{$m,$i} ; $thisr = $r[$thisA] ; if ( ($skipthese) && ($thisA >= $skipthese) ) { # omit this diagonal entirely } else { $difference = $M + $orientation[$m] * $thisr ; $nnn = $difference + $k ; # add the row number ; while ( $nnn > $M ) { $nnn -= $M ; } $nnn += $offset ; mnadd( $k , $nnn ) ; } } $offset += $M ; } print STDERR "." ; } $N = $offset ; print STDERR "done N = $N ; M = $M\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 ; # 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] ++ ; }