Fix lld detection if both gold and lld are found
[ghc.git] / utils / hp2ps / Scale.c
1 #include "Main.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "Defines.h"
5 #include "Dimensions.h"
6 #include "Error.h"
7 #include "HpFile.h"
8 #include "Utilities.h"
9
10 /* own stuff */
11 #include "Scale.h"
12
13 /*
14 * Return the maximum combined height that all the sample
15 * curves will reach. This (absolute) figure can then be
16 * used to scale the samples automatically so that they
17 * fit on the page.
18 */
19
20 floatish
21 MaxCombinedHeight(void)
22 {
23 intish i;
24 intish j;
25 floatish mx;
26 int bucket;
27 floatish value;
28 struct chunk* ch;
29 floatish *maxima;
30
31 maxima = (floatish*) xmalloc(nsamples * sizeof(floatish));
32 for (i = 0; i < nsamples; i++) {
33 maxima[ i ] = 0.0;
34 }
35
36 for (i = 0; i < nidents; i++) {
37 for (ch = identtable[i]->chk; ch; ch = ch->next) {
38 for (j = 0; j < ch->nd; j++) {
39 bucket = ch->d[j].bucket;
40 value = ch->d[j].value;
41 if (bucket >= nsamples)
42 Disaster("bucket out of range");
43 maxima[ bucket ] += value;
44 }
45 }
46 }
47
48 for (mx = maxima[ 0 ], i = 0; i < nsamples; i++) {
49 if (maxima[ i ] > mx) mx = maxima[ i ];
50 }
51
52 free(maxima);
53 return mx;
54 }
55
56
57
58 /*
59 * Scale the values from the samples so that they will fit on
60 * the page.
61 */
62
63 extern floatish xrange;
64 extern floatish yrange;
65
66 void
67 Scale(void)
68 {
69 intish i;
70 intish j;
71 floatish sf;
72 struct chunk* ch;
73
74 if (yrange == 0.0) /* no samples */
75 return;
76
77 sf = graphheight / yrange;
78
79 for (i = 0; i < nidents; i++) {
80 for (ch = identtable[i]->chk; ch; ch = ch->next) {
81 for (j = 0; j < ch->nd; j++) {
82 ch->d[j].value = ch->d[j].value * sf;
83 }
84 }
85 }
86 }