-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathgraph-ccode.scm
More file actions
178 lines (162 loc) · 5.16 KB
/
Copy pathgraph-ccode.scm
File metadata and controls
178 lines (162 loc) · 5.16 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
;; graph c code snippets
(c-declare #<<end-of-c-declare
#include <stdio.h>
#include <string.h>
#include <math.h>
#define TRUE 1
#define FALSE 0
#define DOWN 0
#define UP 1
#define EVEN 2
static char *graph_wc_linecomp(char *line, int Ept){
int count;
if (line[Ept-1] == '.'){ /* ERASE THE DECIMAL POINT */
count=Ept-1;
--Ept;
while (line[count] != '\0'){ /* Shift the string back by one */
line[count]= line[count+1];
++count;
}
}
if (line[Ept+1] == '+'){ /* ERASE the PLUS sign AFTER the E */
count=Ept+1;
--Ept;
while (line[count] != '\0'){ /* Shift the string back by one */
line[count]= line[count+1];
++count;
}
}
while (line[Ept+2] == '0'){ /* ERASE ANY UNNECESSARY ZEROES */
count=Ept+2;
while (line[count] != '\0'){ /* Shift the string back by one */
line[count]= line[count+1];
++count;
}
}
return( line );
}
static float graph_wc_ybottom(int multiplier, float cgymi, float cgldecy){
float bottom;
bottom= cgldecy*((float)multiplier)/10.;
while (bottom < cgymi) bottom *= 10.;
return(bottom);
}
static float graph_wc_xbottom(int multiplier, float cgxmi, float cgldecx){
float bottom;
bottom= cgldecx*((float)multiplier)/10.;
while (bottom < cgxmi) bottom *= 10.;
return(bottom);
}
static float graph_wc_trunc(float fvalue, int updown){
float decade,result;
double dublog;
dublog= log10(fvalue);
dublog= floor(dublog);
decade= pow(10.0, dublog);
result= fvalue/decade;
if (updown == UP)
result = ceil(result);
else if (updown == DOWN)
result = floor(result);
else result= floor(result + 0.5);
result *= decade;
return(result);
}
static int graph_findsigdec(float min, float range, int numsep, float ticks, int cgprecision, int cglinnumoff){
float var;
int expon,count,decpt,sigdec;
char line[30];
sigdec=0;
for (var= cglinnumoff*ticks;var<=range;var += numsep*ticks) {
if((var +min) < pow(10.0,(float)cgprecision))
sprintf(line, "%.*g", cgprecision, var+min);
else sprintf(line, "%.*e", cgprecision, var+min);
expon= FALSE;
count=0;
decpt=0;
while (line[count] != '\0') {
if (line[++count] == 'e' ) { /* search for exponent marker */
expon=TRUE;
}
if (line[count] == '.' ) /* locate decimal point */
decpt=count;
}
if (decpt == 0) decpt = count - 1; /* decpt is end of number */
sigdec=((count-decpt-1)>sigdec)?(count-decpt-1):sigdec;
} /* end for() */
return(sigdec);
}
static char *graph_formaxnum(float value, int sigdec, int cgprecision){
static char line[30];
int expon, count, decpt, ept=0;
sprintf(line, "%#.*g", cgprecision, value);
/* convert number to string form */
expon= FALSE;
count=0;
decpt=0;
while (line[count] != '\0') {
if (line[++count] == 'e' ) {
expon=TRUE;
ept=count;
}
if (line[count] == '.' )
decpt=count;
}
if (expon == TRUE) { // need to clean up gcvt's exp notation
graph_wc_linecomp(line,ept);
count= -1;
while (line[++count] != '\0');
}
if(decpt) {
if (sigdec) {
if (sigdec<=cgprecision||expon) {
line[sigdec+decpt+1]='\0'; // original
} else {
line[cgprecision+decpt+1]='\0';
}
}
else line[decpt]='\0';
}
return line;
}
static char *graph_fix_string(char *text,int fix_minus){
char *sptr, *dptr;
char ch;
static char out[128];
sptr = text;
dptr = out;
while( (ch = *sptr++) != '\0'){
if( ch == '-'){
if(fix_minus){
*dptr++ = '\\'; /* subst with octal 261 */
*dptr++ = '2'; /* "-" --> "\261" */
*dptr++ = '6';
*dptr++ = '1';
}
}
else if( ch == '\\' || ch == '(' || ch == ')' ){
*dptr++ = '\\';
*dptr++ = ch;
}
else /* normal characters */
*dptr++ = ch; /* just copy */
}
*dptr++ = '\0'; /* string terminator */
return(out); /* return ptr to the fixed string */
}
end-of-c-declare
)
(define (graphaux:findsigdec arg1 arg2 arg3 arg4 arg5 arg6)
((c-lambda (float float int float int int) int "graph_findsigdec")
(flo arg1) (flo arg2) (fix arg3) (flo arg4) (fix arg5) (fix arg6)))
(define (graphaux:formaxnum arg1 arg2 arg3)
((c-lambda (float int int) char-string "graph_formaxnum") (flo arg1) (fix arg2) (fix arg3)))
(define (graphaux:fixstring arg1 arg2)
((c-lambda (char-string int) char-string "graph_fix_string") arg1 (fix arg2)))
(define (graphaux:wctrunc arg1 arg2)
((c-lambda (float int) float "graph_wc_trunc") (flo arg1) (fix arg2)))
(define (graphaux:wcxbottom arg1 arg2 arg3)
((c-lambda (int float float) float "graph_wc_xbottom") (fix arg1) (flo arg2) (flo arg3)))
(define (graphaux:wcybottom arg1 arg2 arg3)
((c-lambda (int float float) float "graph_wc_ybottom") (fix arg1) (flo arg2) (flo arg3)))
;; eof