[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / utils / hp2ps / TopTwenty.c
1 #include <stdio.h>
2 #include "Main.h"
3 #include "Defines.h"
4 #include "Error.h"
5 #include "HpFile.h"
6 #include "Utilities.h"
7
8 /* own stuff */
9 #include "TopTwenty.h"
10
11 /*
12  *      We only have room in the key for a maximum of 20 identifiers. 
13  *      We therefore choose to keep the top 20 bands --- these will 
14  *      be the most important ones, since this pass is performed after 
15  *      the threshold and standard deviation passes. If there are more 
16  *      than 20 bands, the excess are gathered together as an "OTHER" ]
17  *      band which appears as band 20.
18  */
19
20 extern void free();
21
22 void
23 TopTwenty()
24 {
25     intish i;
26     intish j;
27     intish compact;
28     intish bucket;
29     floatish value;
30     struct entry* en;
31     struct chunk* ch;
32     floatish *other; 
33
34     i = nidents;
35     if (i <= TWENTY) return;    /* nothing to do! */
36
37     other = (floatish*) xmalloc(nsamples * sizeof(floatish));
38     /* build a list of samples for "OTHER" */ 
39
40     compact = (i - TWENTY) + 1;
41
42     for (i = 0; i < nsamples; i++) {
43         other[ i ] = 0.0;
44     }   
45
46     for (i = 0; i < compact && i < nidents; i++) {
47         for (ch = identtable[i]->chk; ch; ch = ch->next) {
48             for (j = 0; j < ch->nd; j++) {
49                 bucket = ch->d[j].bucket;
50                 value  = ch->d[j].value;
51                 if (bucket >= nsamples)
52                     Disaster("bucket out of range");
53                 other[ bucket ] += value;
54             }   
55         }    
56     }    
57
58     en = MakeEntry("OTHER");
59     en->next = 0;
60
61     for (i = 0; i < nsamples; i++) {
62         StoreSample(en, i, other[i]);
63     }
64
65     /* slide samples down */
66     for (i = compact; i < nidents; i++) {
67         identtable[i-compact+1] = identtable[i];
68     }
69
70     nidents = TWENTY;
71     identtable[0] = en;
72     free(other);
73 }