ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/gcalc.c
Revision: 1.1
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2     static const char RCSid[] = "$Id$";
3     #endif
4     /*
5     * gcalc.c - routines to do calculations on graph files.
6     *
7     * 7/7/86
8     * Greg Ward Larson
9     */
10    
11     #include <stdio.h>
12    
13     #include "mgvars.h"
14    
15     #ifndef BSD
16     #define index strchr
17     #endif
18    
19     extern char *index();
20    
21     static double xsum, xxsum, ysum, yysum, xysum;
22     static double xmin, xmax, ymin, ymax;
23     static double lastx, lasty, rsum;
24     static int npts;
25    
26    
27     gcalc(types) /* do a calculation */
28     char *types;
29     {
30     int i, calcpoint();
31    
32     if (index(types, 'h') == NULL)
33     gcheader(types);
34    
35     xmin = gparam[XMIN].flags & DEFINED ?
36     varvalue(gparam[XMIN].name) :
37     -1e10;
38     xmax = gparam[XMAX].flags & DEFINED ?
39     varvalue(gparam[XMAX].name) :
40     1e10;
41    
42     for (i = 0; i < MAXCUR; i++) {
43     xsum = xxsum = ysum = yysum = xysum = 0.0;
44     rsum = 0.0;
45     npts = 0;
46     mgcurve(i, calcpoint);
47     gcvalue(i, types);
48     }
49     }
50    
51    
52     gcheader(types) /* print header */
53     register char *types;
54     {
55     printf("__");
56     while (*types)
57     switch (*types++) {
58     case 'n':
59     printf("|_Label___________");
60     break;
61     case 'a':
62     printf("|____Mean______S.D._");
63     break;
64     case 'm':
65     printf("|_____Min_______Max_");
66     break;
67     case 'i':
68     printf("|___Integ_");
69     break;
70     case 'l':
71     printf("|___Slope_____Intcp______Corr_");
72     break;
73     default:
74     break;
75     }
76     printf("\n");
77     }
78    
79    
80     gcvalue(c, types) /* print the values for the curve */
81     int c;
82     register char *types;
83     {
84     double d1, d2, d3, sqrt();
85    
86     if (npts < 1)
87     return;
88    
89     printf("%c:", c+'A');
90     while (*types)
91     switch (*types++) {
92     case 'n':
93     printf(" %-16s", cparam[c][CLABEL].flags & DEFINED ?
94     cparam[c][CLABEL].v.s : "");
95     break;
96     case 'a':
97     d1 = sqrt((yysum - ysum*ysum/npts)/(npts-1));
98     printf(" %9.2f %9.3f", ysum/npts, d1);
99     break;
100     case 'm':
101     printf(" %9.2f %9.2f", ymin, ymax);
102     break;
103     case 'i':
104     printf(" %9.2f", rsum);
105     break;
106     case 'l':
107     d3 = xxsum - xsum*xsum/npts;
108     d1 = (xysum - xsum*ysum/npts)/d3;
109     d2 = (ysum - d1*xsum)/npts;
110     d3 = d1*sqrt(d3/(yysum - ysum*ysum/npts));
111     printf(" %9.5f %9.2f %9.5f", d1, d2, d3);
112     break;
113     default:
114     break;
115     }
116     printf("\n");
117     }
118    
119    
120     calcpoint(c, x, y) /* add a point to our calculation */
121     int c;
122     double x, y;
123     {
124     if (x < xmin || x > xmax)
125     return;
126    
127     xsum += x;
128     xxsum += x*x;
129     ysum += y;
130     yysum += y*y;
131     xysum += x*y;
132    
133     if (npts) {
134     if (y < ymin)
135     ymin = y;
136     else if (y > ymax)
137     ymax = y;
138     } else
139     ymin = ymax = y;
140    
141     if (npts)
142     rsum += ( y + lasty )*( x - lastx )/2.0;
143     lastx = x;
144     lasty = y;
145    
146     npts++;
147     }