2 ##############################################################################
3 # Time-stamp: <Wed Jul 24 1996 22:19:02 Stardate: [-31]7859.44 hwloidl>
5 # Usage: ps-scale-y [options] <file>
7 # It is assumed that the last line of <file> is of the format:
8 # %% y_scaling: <f> max: <n>
9 # where <f> is a floating point number determining the amount of scaling of
10 # the y-axis of the graph that is necessary. <n> is the real maximal number
11 # of tasks in the program (needed to rebuild y-axis). This script replaces the
12 # definitions of the PostScript functions scale-y and unscale-y in <file> by
13 # new definitions that do the right amount of scaling.
14 # The y-axis is rebuilt (using the above maximal number of tasks and a copy
15 # of the print_y_axis routine from qp2ps).
16 # If the above line doesn't exist, <file> is unchanged.
17 # This script is typically called from gr2ps.
19 ##############################################################################
30 # NB: This must be the same as in qp2ps!!
36 $labelx = $scalex - 45;
37 $markx = $scalex - 30;
48 open (GET_SCALING,"cat $file | tail -1 |") || die "Can't open pipe: $file | tail -1 |\n";
52 while (<GET_SCALING>){
54 if (/^\%\%\s+y_scaling:\s+([0-9\.]+)\s+max:\s+(\d+)/) {
57 $y_translate = 1.0 - $y_scaling;
62 if ( $y_scaling != 1.0 ) {
63 print STDERR "Scaling $file ($y_scaling; $pmax tasks) ...\n" if $opt_v;
64 # print STDERR "SCALING NECESSARY: y_scaling = $y_scaling; y_translate = $y_translate !\n";
66 # No scaling necessary!!
71 open (IN,"<$file") || die "Can't open file $file\n";
72 open (OUT,">$tmpfile") || die "Can't open file $tmpfile\n";
76 $skip = 0 if $skip && /^% End Y-Axis.$/;
79 print OUT "/scale-y { gsave\n" .
80 " 0 50 $y_translate mul translate\n" .
81 " 1 $y_scaling scale } def\n";
83 elsif (/\/unscale\-y/) {
84 print OUT "/unscale-y { grestore } def \n";
97 rename($tmpfile,$file);
101 # ###########################################################################
102 # Same as in qp2ps (but printing to OUT)!
103 # ###########################################################################
107 local ($y, $smax,$majormax, $majorint);
111 print OUT "% " . ("-" x 75) . "\n";
112 print OUT "% Y-Axis (scaled):\n";
113 print OUT "% " . ("-" x 75) . "\n";
115 print OUT ("%scale-y % y-axis outside scaled area if ps-scale-y rebuilds it!\n");
117 print OUT ("gsave\n");
118 print OUT ("HE12 setfont\n");
119 print OUT ("(tasks)\n");
120 print OUT ("dup stringwidth pop\n");
121 print OUT ("$ymax\n");
122 print OUT ("exch sub\n");
123 print OUT ("$labelx exch\n");
124 print OUT ("translate\n");
125 print OUT ("90 rotate\n");
126 print OUT ("0 0 moveto\n");
127 print OUT ("show\n");
128 print OUT ("grestore\n");
132 if ($pmax < $majorticks) {
136 print OUT ("HE12 setfont\n$scalex $ymin moveto\n$scalex $ymax lineto\n");
137 print OUT ("% Max number of tasks: $pmax\n");
138 print OUT ("% Number of ticks: $majorticks\n");
140 print OUT "0.5 setlinewidth\n";
142 $y = $ymax; # (($pmax - $ymin)/$majorticks) * ($majorticks-$i) + $ymin;
143 print OUT ("$scalex $y moveto\n$major $y lineto\n");
144 print OUT ("$markx $y moveto\n($pmax) show\n");
146 $majormax = int($pmax/$majorticks)*$majorticks;
147 $smax = $majormax*(($ymax-$ymin)/$pmax)+$ymin;
148 $majorint = $majormax/$majorticks;
150 for($i=1; $i <= $majorticks; ++$i) {
151 $y = (($smax - $ymin)/$majorticks) * ($majorticks-$i) + $ymin;
152 $majorval = int($majorint * ($majormax/$majorint-$i));
153 print OUT ("$scalex $y moveto\n$major $y lineto\n");
154 print OUT ("$markx $y moveto\n($majorval) show\n");
157 # print OUT ("$xmin $ymax moveto\n10 0 rlineto\n10 0 rmoveto\n($pmax) show\n");
158 print OUT " stroke\n";
159 print OUT "1 setlinewidth\n";
160 print OUT ("%unscale-y\n");
161 print OUT ("% End Y-Axis (scaled).\n");
162 print OUT "% " . ("-" x 75) . "\n";
165 # ----------------------------------------------------------------------------
167 sub process_options {
170 open(ME,$0) || die "Can't open myself ($0): $!\n";
182 print "Usage: $0 [options] <file>\n";
183 print "Use -h option to get details\n";