#!/usr/local/bin/perl -w # GHdraw.p # Reads GH spec file and writes a postscript representation of the # matrix. # jan 2000: added ability to indicate state variables by a rule across a column # see code/GH/drawall # cd ~/code/GH/ # drawall # # GHdraw.p o=gh.ps < spec # GHdraw.p o=ps/3.ps spec3 # GHdraw.p o=ps/3G.ps PincludeC=0 spec3G # GHdraw.p o=ps/93.ps spec93 # GHdraw.p o=ps/93b.ps spec93b # GHdraw.p o=ps/93xb.ps spec93xb # GHdraw.p o=ps/93y.ps spec93y # GHdraw.p o=ps/93i.ps poisson=1 ispec/93 # # GHdraw.p o=ps/stair3.ps specstair3 # GHdraw.p o=ps/stair3d.ps specstair3d # GHdraw.p o=ps/sourlas.ps specsourlas # GHdraw.p o=ps/saad.ps specsaad # GHdraw.p o=ps/saadnot.ps specsaadnot # GHdraw.p o=ps/r4p.ps specr4p # GHdraw.p o=ps/r3s.ps specr3s # GHdraw.p o=ps/r3sa.ps specr3sa # convoltional codes: # GHdraw.p o=ps/con.ps speccon # GHdraw.p M=288 o=ps/con.ps speccon # GHdraw.p boxI=1 M=576 o=ps/turbo.ps specturbo $puncfractional = 0 ; $puncoffset = 0.1 ; # fractional size of hte offset for puncutation indicator $apuncoffset = 6 ; # absolute offset $PincludeC = 1 ; # whether to include a circle around permutation matrix integers $cshrink = 1.25 ; # factor by which circles are shrunk inside boxes $arrowsize = 4 ; # size of arrow on circle $Kdeltax=0; # spacing of adidas stripes $Kdeltay=2; # set one of these two to zero $poisson = 0 ; # if poisson, then it reads an MCD spec file instead. $numdashes = 5 ; $fudgex = 5 ; $fudgey = 5 ; $boxI = 0 ; # whether to put a box round identity matrices $boxK = 1 ; # whether to put a box round convolutional codes $boxC = 1 ; # whether to put a box round circles $verbose = 0 ; $background=1; # colour of surrounding box #$neg = 0.0 ; # colour of negatives #$pos = 1.0 ; # colour of positive areas ( 1.0 is white ) $o="gh.ps"; $ytop=600; # set nonzero to cause y to be measured from the top instead of # the bottom $rotate=0; $M=144; # how big M is # bl corner $x0=40; $y0=300; $stroke = "stroke"; # change this to "stroke" to get lines round all boxes. eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $numbers = 0 ; # number of places where a number needs to be drawn $punctured = 0 ; # counts number of puncturings print STDERR "===== GHdraw.p ===== (c) DJCM june 1998 =====\n" ; # # read the spec file # $status = 0 ; $n = 0 ; $m = 0 ; $lambda = 0 ; $c = 0 ; # command number $dlist = ":" ; $dprod = 1 ; if ( $poisson == 0 ) { # read GH.p spec file while(<>) { s/^\s*// ; if (/^#/) { # print STDERR ; next ; } s/\#.*// ; # if (/lambda/) { print STDERR " lambda = " ; ($n,$m) = /lambda\s+(.*)\/(.*)/ ; print STDERR "$n / $m \n" ; if ( $m <= 0 ) { $status -- ; } else { $lambda = ( 1.0 * $n ) / ( 1.0 * $m ) ; } &denoms_add ( $m ) ; } elsif (/refresh/) { $c ++ ; $type[$c] = "refresh" ; print STDERR "refresh\n" ; } elsif (/forbidI/) { $c ++ ; $type[$c] = "forbidI" ; ($sizen[$c],$sized[$c]) = /forbidI\s+(.*)\/(.*)/ ; print STDERR "forbid permutations like I $sizen[$c]/$sized[$c]\n" ; &denoms_add ( $sized[$c] ) ; } elsif ( /[p].*at/ ) { # puncture $c ++ ; ($cols[$c],$type[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c]) = /(.*)\s+([p])\s+(.*)\/(.*)\s+at\s+(.*)\/(.*)/ ; print STDERR " $cols[$c] $type[$c] size $sizen[$c]/$sized[$c] at $xn[$c]/$xd[$c]\n" ; &denoms_add ( $sized[$c] ) ; &denoms_add ( $xd[$c] ) ; $punctured ++ ; } elsif ( /[IPCSKL].*at/ ) { $c ++ ; ($cols[$c],$rows[$c],$type[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) = /(.*)x(.*)\s+([IPSCKL])\s+(.*)\/(.*)\s+at\s+(.*)\/(.*),(.*)\/(.*)/ ; print STDERR " $cols[$c] x $rows[$c] $type[$c] size $sizen[$c]/$sized[$c] at $xn[$c]/$xd[$c],$yn[$c]/$yd[$c]\n" ; &denoms_add ( $sized[$c] ) ; &denoms_add ( $xd[$c] ) ; &denoms_add ( $yd[$c] ) ; } elsif ( /[O].*at/ ) { $c ++ ; ($cols[$c],$rows[$c],$type[$c],$sizen[$c],$sized[$c],$hsizen[$c],$hsized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) = /(.*)x(.*)\s+([O])\s+(.*)\/(.*)x(.*)\/(.*)\s+at\s+(.*)\/(.*),(.*)\/(.*)/ ; print STDERR " $cols[$c] x $rows[$c] $type[$c] size $sizen[$c]/$sized[$c] x $hsizen[$c]/$hsized[$c] at $xn[$c]/$xd[$c],$yn[$c]/$yd[$c]\n" ; &denoms_add ( $sized[$c] ) ; &denoms_add ( $hsized[$c] ) ; &denoms_add ( $xd[$c] ) ; &denoms_add ( $yd[$c] ) ; } } $C = $c ; # print STDERR "# Read $C commands\n" ; # print STDERR "# Make M divisible by $dprod\n" ; } else { # poisson=1 # mcd style spec file, eg ispec/93 --- READ IN PROFILE $_ = <> ; ($NNN,$MMM,$num_n_weights,$num_m_weights) = split ; print STDERR "$NNN $MMM $num_n_weights $num_m_weights\n" ; $lambda = 1.0 * $NNN / $MMM ; $N = $M * $lambda ; $nn = 0 ; $mm = 0 ; $totm = 0.0 ; $totn = 0.0 ; while (<>) { s/^\s*// ; if (/^#/) { next ; } ($weight,$fraction) = split ; if ( $nn < $num_n_weights ) { $nn ++ ; $colweight[$nn] = $weight ; $colfraction[$nn] = $fraction ; $totn += $fraction ; $colcum[$nn] = $totn ; } else { $mm ++ ; $rowweight[$mm] = $weight ; $rowfraction[$mm] = $fraction ; $totm += $fraction ; $rowcum[$mm] = $totm ; } } if ( $mm != $num_m_weights || $nn != $num_n_weights ) { print STDERR "WARNING $mm != $num_m_weights || $nn != $num_n_weights \n" ; } print STDERR "column fractions total $totn, row, $totn (should be 1)\n" ; } sub denoms_add { # should really check for divisibility here! local ($d) = @_ ; if (!($dlist =~ /:$d:/) ) { $dlist = $dlist."$d:" ; $dprod = $dprod * $d ; } } $height = $M ; $bbheight=$height ; $bbheight2=0; if ($punctured) { if ($puncfractional) { $bbheight *= (1+$puncoffset) ; } else { $bbheight += $apuncoffset ; } $bbheight2 = $bbheight - $height ; } $width = $lambda * $M ; open ( OUT , ">$o" ) ; print OUT "%!\n" ; print OUT "%%Title: none\n" ; print OUT "%%Creator: GHdraw.p (DJCM 9806)\n" ; print OUT "%%Pages: 1\n" ; print OUT "%%BoundingBox:" ; # print STDERR "ytop = $ytop, bbheight2 = $bbheight2\n" ; if ( $ytop ) { # yes if( $rotate == 1 ) { # this is not right printf OUT " %d %d %d %d\n" , $y0, $x0 , $y0 + $bbheight , $x0 + $width ; } else { # special handling of puncturing here # yes printf OUT " %d %d %d %d\n" , $x0 ,$ytop-$y0-$height , $x0 + $width ,$ytop-$y0+$bbheight2 ; } } else { if( $rotate == 1 ) { printf OUT " %d %d %d %d\n" , $y0, $x0 , $y0 + $bbheight , $x0 + $width ; } else { printf OUT " %d %d %d %d\n" , $x0 ,$y0 , $x0 + $width ,$y0 + $bbheight ; } } print OUT "%%EndComments\n" ; print OUT "/\$F2psDict 32 dict def \n" ; print OUT "\$F2psDict begin\n" ; print OUT " \$F2psDict /mtrx matrix put\n" ; print OUT "\n" ; print OUT " end\n" ; print OUT " /\$F2psBegin {\$F2psDict begin /\$F2psEnteredState save def} def\n" ; print OUT " /\$F2psEnd {\$F2psEnteredState restore end} def\n" ; print OUT " %%EndProlog\n" ; print OUT "\n" ; print OUT "\$F2psBegin\n" ; print OUT "1 setlinecap 1 setlinejoin\n" ; print OUT "0.10 setlinewidth\n" ; print OUT '%%% ellipse stuff %% Blue Book Program 3, on page 137 %%Creator: Adobe Systems Incorporated %%CreationDate: Thu Dec 28 13:17:45 PST 1989 %%EndComments /ellipsedict 8 dict def ellipsedict /mtrx matrix put /ellipse { ellipsedict begin /endangle exch def /startangle exch def /yrad exch def /xrad exch def /y exch def /x exch def /savematrix mtrx currentmatrix def x y translate xrad yrad scale 0 0 1 startangle endangle arc savematrix setmatrix end } def %% %% ' ; print OUT "% background boxes\n" ; $x = $x0 ; $y = $y0 ; &box ( $x , $y , $width , $height , $background , "stroke") ; if ( $poisson == 0 ) { # do the I and Ps for ( $c = 1 ; $c <= $C ; $c ++ ) { if ( $type[$c] eq "refresh" ) { # do nothing } elsif ( $type[$c] eq "I" ) { &do_I($cols[$c],$rows[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) ; } elsif ( $type[$c] eq "C" ) { &do_C($cols[$c],$rows[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) ; } elsif ( $type[$c] eq "O" ) { # oval, h<->height &do_O($cols[$c],$rows[$c],$sizen[$c],$sized[$c],$hsizen[$c],$hsized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) ; } elsif ( $type[$c] eq "K" ) { &do_K($cols[$c],$rows[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) ; } elsif ( $type[$c] eq "S" ) { &do_S($cols[$c],$rows[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) ; } elsif ( $type[$c] eq "L" ) { &do_L($cols[$c],$rows[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) ; } elsif ( $type[$c] eq "forbidI" ) { # do nothing } elsif ( $type[$c] eq "P" ) { &do_P($cols[$c],$rows[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c],$yn[$c],$yd[$c]) ; } elsif ( $type[$c] eq "p" ) { # puncture &do_p($cols[$c],$sizen[$c],$sized[$c], $xn[$c],$xd[$c]) ; } else { print STDERR "oops, unknown type $type[$c]\n" ; } } } sub do_P { local($Co,$Ro,$sn,$sd,$xn,$xd,$yn,$yd) = @_ ; local($n0) = $M * $xn / $xd ; local($m0) = $M * $yn / $yd ; local($w) = $M * $sn / $sd ; for ( $co = 1 ; $co <= $Co ; $co ++ ) { local($m) = $m0 ; for ( $ro = 1 ; $ro <= $Ro ; $ro ++ ) { local($n) = $n0 ; # if this is the first visit to this perm box, # draw a box. $thestring="$n.$m.$w" ; if (! $visited{$thestring} ) { &box($x0+ $n , $y0+$m , $w ,$w , $background , $stroke ) ; $h=$w ; # hack djcm 99, to fix error messages &circle_n_arrow($x0,$n,$y0,$m,$w,$h) if $PincludeC ; $numbers ++ ; $visited{$thestring} = 1 ; # # $label{$thestring} = $numbers ; $xlist[$numbers] = $x0+$n+$w/2 ; $ylist[$numbers] = $y0+$m+$w/2 ; $stringlist[$numbers] = $thestring ; $width[$numbers] = $w ; } else { $visited{$thestring} ++ ; } $m += $w ; } $n0 += $w; } } # # when we are done we will visit all visited places and mark them sub putlabels { for ($n = 1 ; $n <= $numbers ; $n ++ ) { printf STDERR "at %f %f write %d\n" , $xlist[$n] , $ylist[$n] , $visited{$stringlist[$n]} if ($verbose>=2) ; # &showstring( $xlist[$n] , $ylist[$n] , $visited{$stringlist[$n]} , $width[$n]*0.5 ) ; # } } sub do_p { # puncture local($Co,$sn,$sd,$xn,$xd) = @_ ; local($n0) = $M * $xn / $xd ; if ( $puncfractional ) { local($m0) = - $puncoffset * $M ; } else { local($m0) = - $apuncoffset ; } local($w) = $M * $sn / $sd ; for ( $co = 1 ; $co <= $Co ; $co ++ ) { local($m) = $m0 ; local($n) = $n0 ; &line($x0+ $n , $y0+$m ,$x0+ $w+$n , $y0+$m ) ; $n0 += $w; } # } sub do_I { local($Co,$Ro,$sn,$sd,$xn,$xd,$yn,$yd) = @_ ; local($n0) = $M * $xn / $xd ; local($m0) = $M * $yn / $yd ; local($w) = $M * $sn / $sd ; for ( $co = 1 ; $co <= $Co ; $co ++ ) { local($m) = $m0 ; for ( $ro = 1 ; $ro <= $Ro ; $ro ++ ) { local($n) = $n0 ; &box($x0+$n , $y0+$m , $w ,$w , $background , $stroke ) if ($boxI); &line($x0+ $n , $y0+$m ,$x0+ $w+$n , $y0+$m+$w ) ; $m += $w ; } $n0 += $w; } # } # make two stripes to represent staircase sub do_S { local($Co,$Ro,$sn,$sd,$xn,$xd,$yn,$yd) = @_ ; local($n0) = $M * $xn / $xd ; local($m0) = $M * $yn / $yd ; local($w) = $M * $sn / $sd ; for ( $co = 1 ; $co <= $Co ; $co ++ ) { local($m) = $m0 ; for ( $ro = 1 ; $ro <= $Ro ; $ro ++ ) { local($n) = $n0 ; &box($x0+$n , $y0+$m , $w ,$w , $background , $stroke ) if ($boxK); &line($x0+ $n , $y0+$m ,$x0+ $w+$n , $y0+$m+$w ) ; &line($x0+ $n+2*$Kdeltax , $y0+$m+2*$Kdeltay ,$x0+ $w+$n-2*$Kdeltay , $y0+$m+$w-2*$Kdeltax ) ; # show the little top corner bit also &line($x0+$n+$w-2*$Kdeltay , $y0+$m , $x0+ $w+$n , $y0+$m+2*$Kdeltay ) ; $m += $w ; } $n0 += $w; } # } # make an adidas pattern like a convolutional code # for turbo, the systematic one goes through 2, and the parity through 5 # in order to get parity zero sub do_K { local($Co,$Ro,$sn,$sd,$xn,$xd,$yn,$yd) = @_ ; local($n0) = $M * $xn / $xd ; local($m0) = $M * $yn / $yd ; local($w) = $M * $sn / $sd ; for ( $co = 1 ; $co <= $Co ; $co ++ ) { local($m) = $m0 ; for ( $ro = 1 ; $ro <= $Ro ; $ro ++ ) { local($n) = $n0 ; &box($x0+$n , $y0+$m , $w ,$w , $background , $stroke ) if ($boxK); &line($x0+ $n , $y0+$m ,$x0+ $w+$n , $y0+$m+$w ) ; # &line($x0+ $n+2*$Kdeltax , $y0+$m+2*$Kdeltay ,$x0+ $w+$n-2*$Kdeltay , $y0+$m+$w-2*$Kdeltax ) ; # &line($x0+ $n+6*$Kdeltax , $y0+$m+6*$Kdeltay ,$x0+ $w+$n-6*$Kdeltay , $y0+$m+$w-6*$Kdeltax ) ; &line($x0+ $n+8*$Kdeltax , $y0+$m+8*$Kdeltay ,$x0+ $w+$n-8*$Kdeltay , $y0+$m+$w-8*$Kdeltax ) ; $m += $w ; } $n0 += $w; } # } sub do_L { local($Co,$Ro,$sn,$sd,$xn,$xd,$yn,$yd) = @_ ; local($n0) = $M * $xn / $xd ; local($m0) = $M * $yn / $yd ; local($w) = $M * $sn / $sd ; for ( $co = 1 ; $co <= $Co ; $co ++ ) { local($m) = $m0 ; for ( $ro = 1 ; $ro <= $Ro ; $ro ++ ) { local($n) = $n0 ; &box($x0+$n , $y0+$m , $w ,$w , $background , $stroke ) if ($boxK); &line($x0+ $n , $y0+$m ,$x0+ $w+$n , $y0+$m+$w ) ; &line($x0+ $n+2*$Kdeltax , $y0+$m+2*$Kdeltay ,$x0+ $w+$n-2*$Kdeltay , $y0+$m+$w-2*$Kdeltax ) ; &line($x0+ $n+4*$Kdeltax , $y0+$m+4*$Kdeltay ,$x0+ $w+$n-4*$Kdeltay , $y0+$m+$w-4*$Kdeltax ) ; &line($x0+ $n+6*$Kdeltax , $y0+$m+6*$Kdeltay ,$x0+ $w+$n-6*$Kdeltay , $y0+$m+$w-6*$Kdeltax ) ; &line($x0+ $n+8*$Kdeltax , $y0+$m+8*$Kdeltay ,$x0+ $w+$n-8*$Kdeltay , $y0+$m+$w-8*$Kdeltax ) ; $m += $w ; } $n0 += $w; } # } # do circle to indicate permuting of columns. One of these days I will # want an oval option too, with width not equal to height. (Done: "O") sub do_C { local($Co,$Ro,$sn,$sd,$xn,$xd,$yn,$yd) = @_ ; local($n0) = $M * $xn / $xd ; local($m0) = $M * $yn / $yd ; local($w) = $M * $sn / $sd ; local ($h) = $w ; for ( $co = 1 ; $co <= $Co ; $co ++ ) { local($m) = $m0 ; for ( $ro = 1 ; $ro <= $Ro ; $ro ++ ) { local($n) = $n0 ; &box($x0+$n , $y0+$m , $w ,$h , $background , $stroke ) if ($boxC); # circle plus arrow &circle_n_arrow($x0,$n,$y0,$m,$w,$h) ; $m += $h ; } $n0 += $w; } # } # do oval to indicate permuting of columns or rows. sub do_O { local($Co,$Ro,$sn,$sd,$hsn,$hsd,$xn,$xd,$yn,$yd) = @_ ; local($n0) = $M * $xn / $xd ; local($m0) = $M * $yn / $yd ; local($w) = $M * $sn / $sd ; local($h) = $M * $hsn / $hsd ; for ( $co = 1 ; $co <= $Co ; $co ++ ) { local($m) = $m0 ; for ( $ro = 1 ; $ro <= $Ro ; $ro ++ ) { local($n) = $n0 ; &box($x0+$n , $y0+$m , $w ,$h , $background , $stroke ) if ($boxC); # circle plus arrow &circle_n_arrow($x0,$n,$y0,$m,$w,$h) ; $m += $h ; } $n0 += $w; } # } # circle plus arrow sub circle_n_arrow { local($x0,$n,$y0,$m,$w,$h) = @_ ; # print "x", $x0+$w/2+$n , "\n" ; # print "y", $y0+$h/2+$m , "\n" ; # print "c", $cshrink , "\n" ; # print "w", $w , "\n" ; # print "h", $h , "\n" ; &circle($x0+$w/2+$n , $y0+$h/2+$m , $w/$cshrink ,$h/$cshrink ) ; # add a tiny arrow thing too $newox = $x0+$w/2+$n; $newoy = $y0+$h/2+$m - 0.5* $h/$cshrink ; &line($newox - $arrowsize , $newoy - $arrowsize , $newox , $newoy ) ; &line($newox - $arrowsize , $newoy + $arrowsize , $newox , $newoy ) ; } if ( $poisson == 0 ) { # $l=0; $thiscol=0; $currentrow = 1 ; # uninitialized variable? $h $h = 0 ; # what was this meant to be? # $x = $orig_startx = $startx = $x0 + $m + $h / 2 ; $y = $starty = $y0 + $m + $h / 2 ; $x = $x0 + $m + $h / 2 ; $y = $y0 + $m + $h / 2 ; &putlabels() ; } else { # $colcum[0] = 0.0 ; $rowcum[0] = 0.0 ; # run through cols putting vertical lines for ( $nn = 1 ; $nn <= $num_n_weights ; $nn ++ ) { $n = $colcum[$nn] * $N ; if ( $nn < $num_n_weights ) { &line($x0+ $n , $y0 ,$x0+ $n , $y0+$M ) ; } $n -= $colfraction[$nn] * 0.5 * $N ; $m = $M * 0.5 ; printf STDERR "at %f %f write %d\n" , $n , $m , $colweight[$nn] ; # if ( $colfraction[$nn] * $lambda > 1.0 ) { $stringwidth = $colfraction[$nn]*0.35*$N ; } else { $stringwidth = $colfraction[$nn]*0.85*$N ; } &showstring($x0+ $n ,$y0+ $m , $colweight[$nn], $stringwidth ) ; } # run through rows for ( $mm = 1 ; $mm <= $num_m_weights ; $mm ++ ) { # print STDERR "m = $mm , cum = $rowcum[$mm]\n" ; $m = $rowcum[$mm] * $M ; if ( $mm < $num_m_weights ) { &line($x0 , $y0+$m ,$x0+ $N , $y0+$m ) ; } # centred location: $m -= $rowfraction[$mm] * 0.5 * $M ; $n = $N * 0.5 ; printf STDERR "at %f %f write %d\n" , $n , $m , $rowweight[$mm] ; # # I am trying putting this along the bottom of the rectangle $m = $rowcum[$mm] * $M ; $n = 0 ; $thestring = "<" . "- "x$numdashes . $rowweight[$mm] . " -"x$numdashes . ">"; &show_bl_string($x0+ $n + $fudgex ,$y0+ $m - $fudgey , $thestring , $rowfraction[$mm]*0.25*$M ) ; } } print OUT "\$F2psEnd\nshowpage\n" ; exit(0); sub showstring { # this is specialized for showing single digits local($y,$x,$str,$w) = @_ ; if($rotate==0) { $tmpo = $x ; $x = $y ; $y = $tmpo ; } if($ytop) { $y = $ytop - $y ; } printf OUT "/Helvetica findfont %d scalefont setfont\n" , $w ; printf OUT "%6.4f %6.4f moveto\n" , $x-$w/4, $y-$w/3 ; printf OUT "(%s) show\n", $str ; } sub show3string { # this is specialized for showing 3 digits local($y,$x,$str,$w) = @_ ; if($rotate==0) { $tmpo = $x ; $x = $y ; $y = $tmpo ; } if($ytop) { $y = $ytop - $y ; } printf OUT "/Helvetica findfont %d scalefont setfont\n" , $w ; printf OUT "%6.4f %6.4f moveto\n" , $x-3*$w/4, $y-$w/3 ; printf OUT "(%s) show\n", $str ; } sub show_bl_string { # puts it bottom left aligned local($y,$x,$str,$w) = @_ ; if($rotate==0) { $tmpo = $x ; $x = $y ; $y = $tmpo ; } if($ytop) { $y = $ytop - $y ; } printf OUT "/Helvetica findfont %d scalefont setfont\n" , $w ; printf OUT "%6.4f %6.4f moveto\n" , $x, $y ; printf OUT "(%s) show\n", $str ; } sub box { # draws a box from x,y with width specified. # to get a box with an edge, set $stroke=stroke ; #usage ( $x , $y , $xsize , $ysize, $gray ) local( $y , $x , $ysize, $xsize, $gray , $stroke ) = @_ ; if($rotate==0) { $tmpo = $x ; $x = $y ; $y = $tmpo ; $tmpo = $xsize ; $xsize = $ysize ; $ysize = $tmpo ; } if($ytop) { $y = $ytop - $y ; $ysize = -$ysize ; } printf OUT "%s box %6.4f %6.4f %6.4f %6.4f\n" , '%' , $x, $y, $xsize, $ysize; printf OUT "newpath %6.4f %6.4f moveto %6.4f %6.4f lineto %6.4f %6.4f lineto %6.4f %6.4f lineto closepath %s\n" , $x+$xsize, $y+$ysize, $x+$xsize, $y, $x, $y, $x, $y+$ysize, $stroke ; } sub circle { # draws a circle centred on x,y with diameter w specified. #usage ( $x , $y , $xsize , $ysize ) local( $y , $x , $ysize, $xsize ) = @_ ; local ( $stroke ) = "stroke" ; if($rotate==0) { $tmpo = $x ; $x = $y ; $y = $tmpo ; $tmpo = $xsize ; $xsize = $ysize ; $ysize = $tmpo ; } if($ytop) { $y = $ytop - $y ; $ysize = -$ysize ; } printf OUT "%s circle/ellipse %6.4f %6.4f %6.4f %6.4f\n" , '%' , $x, $y, $xsize, $ysize; # newpath # 144 400 72 144 0 360 ellipse # stroke printf OUT "newpath %6.4f %6.4f %6.4f %6.4f %6.4f %6.4f ellipse %s\n" , $x, $y, $xsize*0.5, $ysize*0.5, 0,360, $stroke ; } sub cbox { # draws a box centred on x,y with half width specified. # to get a box with an edge, set $stroke=stroke ; #usage ( $x , $y , $xsize , $ysize, $gray ) local( $y , $x , $ysize, $xsize, $gray , $stroke ) = @_ ; if($rotate==0) { $tmpo = $x ; $x = $y ; $y = $tmpo ; $tmpo = $xsize ; $xsize = $ysize ; $ysize = $tmpo ; } printf OUT "newpath %6.4f %6.4f moveto %6.4f %6.4f lineto %6.4f %6.4f lineto %6.4f %6.4f lineto closepath gsave %6.4f setgray fill grestore %s\n" , $x+$xsize, $y+$ysize, $x+$xsize, $y-$ysize, $x-$xsize, $y-$ysize, $x-$xsize, $y+$ysize, $gray , $stroke ; } sub line { # draws a line #usage ( $x , $y , $x2 , $y2 ) ; local( $y , $x , $y2, $x2 ) = @_ ; if($rotate==0) { $tmpo = $x ; $x = $y ; $y = $tmpo ; $tmpo = $x2 ; $x2 = $y2 ; $y2 = $tmpo ; } if($ytop) { # invert verttically $y = $ytop - $y ; $y2 = $ytop - $y2 ; } printf OUT "newpath %6.4f %6.4f moveto %6.4f %6.4f lineto stroke\n" , $x,$y, $x2,$y2 ; }