-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvariance.cc
More file actions
126 lines (90 loc) · 3.79 KB
/
variance.cc
File metadata and controls
126 lines (90 loc) · 3.79 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
-------------------------------------------------------------------------
OBJECT NAME: variance.c
FULL NAME: Spectral Variance routines.
ENTRY POINTS: ComputeBandLimitedVariance()
PlotVarianceX()
PlotVariancePS()
STATIC FNS: makeTotalVarLabel()
makeBandLimitedVarLabel()
DESCRIPTION:
REFERENCES: spctrm.c
REFERENCED BY: Callback
COPYRIGHT: University Corporation for Atmospheric Research, 1996-8
-------------------------------------------------------------------------
*/
#include "define.h"
#include "spec.h"
#include "ps.h"
static void makeTotalVarLabel(),
makeBandLimitedVarLabel(size_t, size_t, double, double);
/* -------------------------------------------------------------------- */
void ComputeBandLimitedVariance(Widget w, XtPointer client, XtPointer call)
{
size_t i, startBin, endBin;
psd[0].bandVariance = 0.0;
if ((startBin = (size_t)(startFreq() / psd[0].freqPerBin)) <= 0)
startBin = 1;
if ((endBin = (size_t)(endFreq() / psd[0].freqPerBin)) > psd[0].M)
endBin = psd[0].M;
for (i = startBin; i <= endBin; ++i)
psd[0].bandVariance += psd[0].Pxx[i];
} /* END COMPUTEBANDLIMITEDVARIANCE */
/* -------------------------------------------------------------------- */
void PlotVarianceX(PLOT_INFO *plot, XFontStruct *fontInfo)
{
size_t startBin, endBin;
XSetFont(plot->dpy, plot->gc, fontInfo->fid);
if ((startBin = (size_t)(startFreq() / psd[0].freqPerBin)) <= 0)
startBin = 1;
if ((endBin = (size_t)(endFreq() / psd[0].freqPerBin)) > psd[0].M)
endBin = psd[0].M;
makeTotalVarLabel();
XDrawString(plot->dpy, plot->win, plot->gc, plot->x.LV,
plot->x.windowHeight - 25, buffer, strlen(buffer));
makeBandLimitedVarLabel(startBin, endBin,
psd[0].freqPerBin * startBin, psd[0].freqPerBin * endBin);
XDrawString(plot->dpy, plot->win, plot->gc, plot->x.LV,
plot->x.windowHeight - 15, buffer, strlen(buffer));
snprintf(buffer, BUFFSIZE, "K = %d, M = %d, nPoints = %ld\n",
(int)psd[0].K, (int)psd[0].M, (long)dataSet[0].nPoints);
XDrawString(plot->dpy, plot->win, plot->gc, plot->x.LV,
plot->x.windowHeight - 5, buffer, strlen(buffer));
} /* END PLOTVARIANCEX */
/* -------------------------------------------------------------------- */
void PlotVariancePS(PLOT_INFO *plot, FILE *fp)
{
size_t startBin, endBin;
if ((startBin = (size_t)(startFreq() / psd[0].freqPerBin)) <= 0)
startBin = 1;
if ((endBin = (size_t)(endFreq() / psd[0].freqPerBin)) > psd[0].M)
endBin = psd[0].M;
makeTotalVarLabel();
fprintf(fp, moveto, 0, plot->ps.xLabelOffset - 75);
fprintf(fp, show, buffer);
makeBandLimitedVarLabel(startBin, endBin,
psd[0].freqPerBin * startBin, psd[0].freqPerBin * endBin);
fprintf(fp, moveto, 0, plot->ps.xLabelOffset - 120);
fprintf(fp, show, buffer);
snprintf(buffer, BUFFSIZE, "K = %d, M = %d, nPoints = %ld\n",
(int)psd[0].K, (int)psd[0].M, (long)dataSet[0].nPoints);
fprintf(fp, moveto, 0, plot->ps.xLabelOffset - 165);
fprintf(fp, show, buffer);
} /* END PLOTVARIANCEPS */
/* -------------------------------------------------------------------- */
static void makeTotalVarLabel()
{
snprintf(buffer, BUFFSIZE, "Total %svariance = %g",
psd[0].display == SPECTRA ? "" : "co-", psd[0].totalVariance);
}
/* -------------------------------------------------------------------- */
static void makeBandLimitedVarLabel(size_t startBin, size_t endBin, double sf, double ef)
{
if (startBin == 1 && endBin == psd[0].M)
snprintf(buffer, BUFFSIZE, "%sVariance (w/o DC component) = %g",
psd[0].display == SPECTRA ? "" : "Co-", psd[0].bandVariance);
else
snprintf(buffer, BUFFSIZE, "Band limited %svariance = %g (%gHz - %gHz)",
psd[0].display == SPECTRA ? "" : "co-", psd[0].bandVariance, sf, ef);
}
/* END VARIANCE.C */