#!/usr/local/bin/perl # U.S. letter paper, half inch margins. $urx = $paperx = 612; $xmarge = 72 / 2; $ury = $papery = 792; $ymarge = 72 / 2; $outpoints=10; $pagepoints=12; $tryfact = 1.1; $bigdir = "."; $litdir = "."; $ismaps{"-cernmap"} = "rect (%s,%s) (%s,%s) %s\n"; $ismaps{"-ncsamap"} = "rect %s %s,%s %s,%s\n"; ($progname = $0) =~ s/.*\///; sub usage { local($mess) = @_; print STDERR <) { if ($incomments) { next if /^%!/; if (/^%%BoundingBox:/) { chop; ($tag, $llx, $lly, $urx, $ury) = split; next; } $title = $1, next if /^%%Title: (.*)$/; $incomments = 0, $inprolog = 1, next if /^$/; $incomments = 0, $inprolog = 1, next if /^%%EndComments/; push(@comments, $_); next; } if ($inprolog) { $inprolog = 0, next if /^%%EndSetup/; $pointsize = $1, next if /^\/pointsize ([0-9\.]+) def/; $psxmin = $1, next if /^\/psxmin ([0-9\.]+) def/; $psymin = $1, next if /^\/psymin ([0-9\.]+) def/; $psxmax = $1, next if /^\/psxmax ([0-9\.]+) def/; $psymax = $1, next if /^\/psymax ([0-9\.]+) def/; next; } next unless /^\/B[0-9]/; #/B434 { 157.858 95.719 20.2525 1.80224 Cw BX } def ($name, $lbrack, $x, $y, $w, $h) = split; $right = $x + $w; $l2r{$x} = $right if $right > $l2r{$x}; } $rightadj = $pointsize / 5; sub byval { $a <=> $b; } foreach $left (sort byval keys %l2r) { push(@lefts, $left); $right = $l2r{$left} + $rightadj; push(@rights, $right); print STDERR "\t$left\t$right\n" if $printlinesflag; } if ($tartiles) { $lastpoints = $pointsize; $outpoints = $pointsize; for(;;) { if ($outpoints > 10) { $outpoints = int($outpoints) + 1; } elsif ($outpoints > 6) {$outpoints = (int($outpoints * 2)+1)/2;} elsif ($outpoints > 4) {$outpoints = (int($outpoints * 4)+1)/4;} else { $outpoints *= $tryfact; } #print STDERR "$outpoints\n"; &initscale; $tottiles = &showtheboxes(-1); if ($tottiles > $tartiles) { $outpoints = $lastpoints; last; } $lastpoints = $outpoints; } } #print STDERR "A $outpoints points, $tottiles tiles\n"; &initscale; $tottiles = &showtheboxes(-1); #print STDERR "B $outpoints points, $tottiles tiles\n"; &printheader(0); &printlines if $printlinesflag; &showtheboxes(0); &catfile; &showtheboxes(0); &showtheboxes(1); close(STDOUT); exit(0); sub initscale { $tilescale = $outpoints / $pointsize; $tilewid = $paperx / $tilescale; #$xstep = ($paperx - ($xmarge * 2)) / $tilescale; $xstep = ($urx - llx) / $tilescale; $tileht = $papery / $tilescale; $ystep = ($papery - ($ymarge * 2)) / $tilescale; $yht = $ury - $lly; $yhtadj = $yht - (($ymarge * 2) / $tilescale); $yhtadj = $yht; $ysperc = $yhtadj / $ystep; $nysperc = int($ysperc); #print STDERR "papery $papery ymarge $ymarge tilescale $tilescale lly $lly ury $ury\n"; #print STDERR "yht $yht yhtadj $yhtadj ystep $ystep ysperc $ysperc nysperc $nysperc\n"; $ystep = ($yhtadj / ($nysperc + 1)); $ystep = ((($yht + (($ymarge * 2) / $tilescale)) - $tileht) / $nysperc); #print STDERR "ystep $ystep\n"; } sub printheader { local($tileno) = @_; &setfile($tileno) if $prefix; print < Image map of $tottiles tiles of $title

[$title] Image map of $tottiles tiles of $title

EOS if ($ismap =~ /ncsa/) { print IS "\n"; } else { print IS "\n"; } print IS <
back to main index EOS close(IS); if (!open(ISMAP, $ismapfile)) { warn "Can't open $ismapfile"; $ismap = ""; return; } print ISMAP "default $urlbase/${prefix}no.html\n"; while ($maptile = pop(@maptiles)) { ($x, $y, $tileno) = split("\t", $maptile); &doismap($x, $y, $tileno); } close(ISMAP); } sub saveismap { local($x, $y, $tileno) = @_; return if !$ismap; push(@maptiles, join("\t", $x, $y, $tileno)); } sub doismap { local($x, $y, $tileno) = @_; return if !$ismap; local($tilefile, $url, $turx, $tury, $formurl); $turx = $x + $tilewid; $tury = $y + $tileht; $y = $papery - $y; $tury = $papery - $tury; $x = int($x); $y = int($y); $turx = int($turx); $tury = int($tury); $tilefile = &tilefilename($tileno, "html"); $url = "$urlbase/$tilefile"; $formurl = $ismaps{$ismap}; printf ISMAP $formurl, $url, $x, $tury, $turx, $y if $ismap =~ /ncsa/; printf ISMAP $formurl, $x, $tury, $turx, $y, $url if $ismap =~ /cern/; } sub showtheboxes { local($which) = @_; local($y, $tileno); if ($which > 0) { $date=`date`; chop($date); print < 0 && $ismap) { &setismap; } return($tileno); } sub showxboxes { local($y, $tileno, $which) = @_; local($x, $xnext, $doright); # , $hue); for($x = $llx; $x < $urx;) { ++$tileno; #print STDERR "tile $tileno\n"; if ($which > 0) { &dofile($x, $y, $tileno); &saveismap($x, $y, $tileno); } elsif ($which == 0) { $hue += 0.777; $hue -= 1 if $hue > 1; printf "%d %.4g %.4g %.4g showthebox\n", $tileno, $x, $y, $hue; } $xnext = $x + $xstep; #print STDERR "$x\t$xnext\t$urx\n"; if ($xnext >= ($urx - ($xmarge/$tilescale))) { return($tileno); } $doright = 0; for $right (@rights) { if (($right > $x) && ($right <= $xnext)){ $doright = $right; } } if ($doright) { $x = $doright; } else { $x = $xnext; } } return($tileno); } sub printlines { if (!$linesprinted++) { printf "/lly %.4g def\n", $lly; printf "/ury %.4g def\n", $ury; print <$tilefile") || die "Can't open >$tilefile"; } sub catfile { if ($prefix) { close(STDOUT); system "cat $filename >>$tilefile"; open(STDOUT, ">>$tilefile") || die "Can't open >>$tilefile"; return; } print "($filename) run\n"; }