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