summaryrefslogtreecommitdiff
path: root/utils/hp2ps/Scale.c
blob: a471bde47e143fe11b194d26b4d3ae9b830d2c9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Main.h"
#include <stdio.h>
#include <stdlib.h>
#include "Defines.h"
#include "Dimensions.h"
#include "Error.h"
#include "HpFile.h"
#include "Utilities.h"

/* own stuff */
#include "Scale.h"

/*
 *	Return the maximum combined height that all the sample
 *	curves will reach. This (absolute) figure can then be 
 *	used to scale the samples automatically so that they
 *	fit on the page.
 */

floatish
MaxCombinedHeight(void)
{
    intish i;
    intish j;
    floatish mx;
    int bucket;
    floatish value;
    struct chunk* ch;
    floatish *maxima; 

    maxima = (floatish*) xmalloc(nsamples * sizeof(floatish));
    for (i = 0; i < nsamples; i++) {
        maxima[ i ] = 0.0;
    }   

    for (i = 0; i < nidents; i++) {
        for (ch = identtable[i]->chk; ch; ch = ch->next) {
            for (j = 0; j < ch->nd; j++) {
                bucket = ch->d[j].bucket;
                value  = ch->d[j].value;
		if (bucket >= nsamples)
		    Disaster("bucket out of range");
                maxima[ bucket ] += value;
            }   
        }    
    }    

    for (mx = maxima[ 0 ], i = 0; i < nsamples; i++) {
        if (maxima[ i ] > mx) mx = maxima[ i ];
    } 

    free(maxima);
    return mx;
}



/*
 *	Scale the values from the samples so that they will fit on 
 *	the page.	
 */

extern floatish xrange;
extern floatish yrange;

void
Scale(void)
{
    intish i;
    intish j;
    floatish sf;
    struct chunk* ch;

    if (yrange == 0.0)		/* no samples */
	return;

    sf = graphheight / yrange; 

    for (i = 0; i < nidents; i++) {
        for (ch = identtable[i]->chk; ch; ch = ch->next) {
            for (j = 0; j < ch->nd; j++) {
	        ch->d[j].value = ch->d[j].value * sf;
            }    
        }    
    }
}