"Fossies" - the Fresh Open Source Software Archive 
Member "statist-1.4.2/src/plot.c" (30 Sep 2006, 19178 Bytes) of package /linux/privat/old/statist-1.4.2.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "plot.c" see the
Fossies "Dox" file reference documentation.
1 /* This file is part of statist
2 **
3 ** It is distributed under the GNU General Public License.
4 ** See the file COPYING for details.
5 **
6 ** (c) 1997 Dirk Melcher
7 ** Doerper Damm 4
8 ** 49134 Wallenhorst
9 ** GERMANY
10 ** Tel. 05407/7636
11 ** email: Dirk.Melcher@usf.Uni-Osnabrueck.DE
12 **
13 ** small Changes by Bernhard Reiter http://www.usf.Uni-Osnabrueck.DE/~breiter
14 ** $Id: plot.c,v 1.20 2006/09/30 21:10:38 jakson Exp $
15 ***************************************************************/
16 /* plot.c for STATIST */
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <math.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #ifndef MSDOS
24 #include <iconv.h>
25 #endif
26
27 #include "statist.h"
28 #include "funcs.h"
29 #include "data.h"
30 #include "plot.h"
31 #include "gettext.h"
32
33 #ifndef NOPIPE
34 #define PLOT_MSG out_d(_("Creating gnuplot-graphic ...\n\n"))
35 #define PLOT_CLOSE fflush(pipef)
36 #else
37 #define PLOT_MSG out_d(_("Creating gnuplot command file '%s'\n\n"), GPL_COM)
38 #define PLOT_CLOSE FCLOSE(pipef)
39 #endif
40
41 char GPL_DAT[300];
42 char GPL_COM[16];
43 char **plothist;
44 int histsize = 30;
45 int lastcmd = -1;
46 BOOLEAN has_graph = FALSE;
47
48 char *gnuplot_charset;
49
50 /* Charset conversion function */
51 #ifndef MSDOS
52 char * g(char *s){
53 if(gnuplot_charset == NULL || is_utf8 == FALSE ||
54 strcmp(gnuplot_charset, "UTF-8") == 0)
55 return s;
56 char *b1, *b2;
57 b1 = s;
58 b2 = s;
59 int error;
60 char *inbuf, *outbuf;
61 size_t t, inbytesleft, outbytesleft;
62 iconv_t cd = iconv_open(gnuplot_charset, "UTF-8");
63 if(cd == (iconv_t)-1){
64 if(errno == EINVAL)
65 out_err(ERR, ERR_FILE, ERR_LINE,
66 _("Invalid encoding specification: \"%s\""), gnuplot_charset);
67 else
68 out_err(ERR, ERR_FILE, ERR_LINE, "iconv_open() error");
69 }
70 inbuf = b1;
71 inbytesleft = strlen(b1);
72 outbytesleft = inbytesleft;
73 outbuf = (char*)m_calloc((outbytesleft + 1), sizeof(char));
74 b2 = outbuf;
75 t = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
76 error = errno;
77 if (iconv_close(cd) != 0) {
78 out_err(ERR, ERR_FILE, ERR_LINE, "iconv_close() error");
79 }
80 if(t == -1){
81 char *errmsg = (char*)m_calloc((strlen(s) + 255), sizeof(char));
82 char where[80];
83 int i = 0, l;
84 l = strlen(b2);
85 switch(error){
86 case EILSEQ :
87 while(i < 77 && i < l){
88 where[i] = ' ';
89 i++;
90 }
91 where[i] = '^';
92 where[i+1] = 0;
93 sprintf(errmsg, "%s\n %s %s", _("An invalid multibyte sequence was "
94 "encountered in the input:"), s, where);
95 out_err(WAR, ERR_FILE, ERR_LINE, errmsg);
96 break;
97 case EINVAL :
98 out_err(WAR, ERR_FILE, ERR_LINE,
99 "An incomplete multibyte sequence was encountered in the "
100 "input, and the input byte sequence terminates after it");
101 break;
102 }
103 b2 = b1;
104 }
105 return b2;
106 }
107 #else
108 char * g(char *s){
109 return(s);
110 }
111 #endif
112
113 char * fixquote(char *s){
114 char * fixedlabel;
115 int i = 0, j = 0;
116 int l = strlen(s);
117 fixedlabel = (char*)m_calloc((2 * l), sizeof(char));
118 while(i < l){
119 if(s[i] == '\"' && (i == 0 || s[i-1] != '\\')){
120 fixedlabel[j] = '\\';
121 fixedlabel[j+1] = '\"';
122 j += 1;
123 } else{
124 fixedlabel[j] = s[i];
125 }
126 i++;
127 j++;
128 }
129 fixedlabel[j] = 0;
130 return g(fixedlabel);
131 }
132
133 void gnuplotcmd(char *fmt, ...){
134 va_list argptr;
135 char s[255];
136 va_start(argptr, fmt);
137 vsprintf(s, fmt, argptr);
138 fprintf(pipef, "%s\n", s);
139 if(histsize > 0){
140 lastcmd++;
141 if(lastcmd == histsize)
142 lastcmd = 0;
143 plothist[lastcmd] = (char*)mycalloc((strlen(s)+1), sizeof(char));
144 strcpy(plothist[lastcmd], s);
145 }
146 va_end(argptr);
147 }
148
149 void clear_history(){
150 int i;
151 for(i = 0; i < histsize; i++)
152 if(plothist[i] != NULL){
153 myfree(plothist[i]);
154 plothist[i] = NULL;
155 }
156 }
157
158 void set_default(){
159 clear_history();
160 gnuplotcmd("unset key");
161 gnuplotcmd("unset parametric");
162 gnuplotcmd("unset log x");
163 gnuplotcmd("unset grid");
164 gnuplotcmd("unset label");
165 gnuplotcmd("unset ylabel");
166 gnuplotcmd("set xtics autofreq");
167 gnuplotcmd("set ytics autofreq");
168 gnuplotcmd("linetype=1");
169 has_graph = TRUE;
170 }
171
172 BOOLEAN init_gnuplot() {
173 int i = 1;
174 if(plothist == NULL)
175 plothist = (char**)mycalloc(histsize, sizeof(char*));
176
177 #ifndef NOPIPE
178 switch (gnupl_open) {
179 case CRASH:
180 return FALSE;
181 break;
182 case TRUE:
183 return TRUE;
184 break;
185 case FALSE:
186 #ifdef MSDOS
187 if ((pipef = popen("pgnuplot --version", "w"))==NULL) {
188 #else
189 if ((pipef = popen("gnuplot --version", "w"))==NULL) {
190 #endif
191 out_err(ERR, ERR_FILE, ERR_LINE, _("gnuplot-initialization failed!"));
192 gnupl_open = CRASH;
193 return FALSE;
194 }
195 else {
196 /* popen() has changed. Now we have to close the pipe to know whether
197 * gnuplot is in the path. Adopting plotdrop solution: */
198 int status = pclose(pipef);
199 pipef = NULL;
200 if(status){
201 out_err(ERR, ERR_FILE, ERR_LINE, _("gnuplot-initialization failed!"));
202 gnupl_open = CRASH;
203 pipef = NULL;
204 return FALSE;
205 } else{
206 #ifdef MSDOS
207 pipef = popen("pgnuplot", "w");
208 #else
209 pipef = popen("gnuplot -geometry 450x300", "w");
210 #endif
211 if(pipef){
212 gnupl_open = TRUE;
213 #ifdef MSDOS
214 sprintf(GPL_DAT, "stat_gpl.dat");
215 #else
216 sprintf(GPL_DAT, "%.256s/stat_gpl.dat", getenv("HOME"));
217 while(myexist(GPL_DAT)){
218 i++;
219 sprintf(GPL_DAT, "%.256s/stat_gpl_%i.dat", getenv("HOME"), i);
220 }
221 if(gplt_default_term)
222 gnuplotcmd("set term %s", gplt_default_term);
223 #endif
224 return TRUE;
225 }
226 return FALSE;
227 }
228 }
229 default:
230 return FALSE;
231 }
232
233 #else
234 strcpy(GPL_COM, "stat_gpl.plt");
235 FOPEN(GPL_COM, "w", pipef);
236 gnupl_open = TRUE;
237 sprintf(GPL_DAT, "stat_gpl.dat");
238 return TRUE;
239 #endif
240 }
241
242 void save_png(){
243 if(gnupl_open != TRUE)
244 return;
245 char fn[MLINE];
246 out_i(_("Please enter a name for the png file: ") );
247 GETRLINE;
248 sscanf(line, "%s", fn);
249
250 /* Add .png filename extension if necessary */
251 int i = strlen(fn);
252 if(!(fn[i-4] == '.' && fn[i-3] == 'p' && fn[i-2] == 'n' && fn[i-1] == 'g'))
253 strncat(fn, ".png", MLINE - i - 5);
254
255 /* I added out_d() lines because I suppose that users expect some feedback,
256 * but I can't guarantee that the picture will be created. */
257 out_d("\n");
258 if(gplt_png){
259 gnuplotcmd("set term png font %s", gplt_png);
260 out_d("gnuplot> set term png font %s\n", gplt_png);
261 } else{
262 gnuplotcmd("set term png");
263 out_d("gnuplot> set term png\n");
264 }
265 gnuplotcmd("set output \"%s\"", fn);
266 out_d("gnuplot> set output \"%s\"\n", fn);
267 gnuplotcmd("replot");
268 out_d("gnuplot> replot\n");
269 out_d("\n");
270 if(gplt_default_term)
271 gnuplotcmd("set term %s", gplt_default_term);
272 else
273 gnuplotcmd("set term x11");
274 has_graph = FALSE;
275 }
276
277 BOOLEAN plot_pair(REAL x[], REAL y[], int n, REAL a0, REAL a1,
278 char *xlab, char *ylab) {
279 FILE *tempf;
280 int i;
281 char aline[160];
282
283 if (!init_gnuplot()) {
284 return FALSE;
285 }
286
287 #ifndef NO_GETTEXT
288 SET_C_LOCALE;
289 #endif
290 FOPEN(GPL_DAT, "wt", tempf);
291 for (i=0; i<n; i++) {
292 fprintf(tempf, "%g %g\n", x[i], y[i]);
293 }
294 FCLOSE(tempf);
295 set_default();
296 sprintf(aline, "f(x)=%g + %g*x", a0, a1);
297 gnuplotcmd("%s", aline);
298 gnuplotcmd("set xlabel \"%s\"", fixquote(xlab));
299 gnuplotcmd("set ylabel \"%s\"", fixquote(ylab));
300 #ifndef NO_GETTEXT
301 RESET_LOCALE;
302 #endif
303 if(gtprefix)
304 sprintf(aline, "%s%s", fixquote(gtprefix), g(_("Linear Regression")));
305 else
306 sprintf(aline, "%s", g(_("Linear Regression")));
307 gnuplotcmd("set title \"%s\"", aline);
308 gnuplotcmd("plot '%s', f(x)", GPL_DAT);
309 PLOT_CLOSE;
310 PLOT_MSG;
311 return TRUE;
312 }
313
314
315 BOOLEAN plot_tripl(REAL x[], REAL y[], REAL z[], int n,
316 REAL a0, REAL a1, REAL a2,
317 char *xlab, char *ylab, char *zlab) {
318 FILE *tempf;
319 int i;
320 char aline[160];
321
322 if (!init_gnuplot()) {
323 return FALSE;
324 }
325
326 #ifndef NO_GETTEXT
327 SET_C_LOCALE;
328 #endif
329 FOPEN(GPL_DAT, "wt", tempf);
330 for (i=0; i<n; i++) {
331 fprintf(tempf, "%g %g %g\n", x[i], y[i], z[i]);
332 }
333 FCLOSE(tempf);
334 sprintf(aline, "f(u,v)=%g + %g*u + %g*v\n", a0, a1, a2);
335 set_default();
336 gnuplotcmd("set parametric");
337 gnuplotcmd("%s", aline);
338 gnuplotcmd("set xlabel \"%s\"", fixquote(xlab));
339 gnuplotcmd("set ylabel \"%s\"", fixquote(ylab));
340 gnuplotcmd("set zlabel \"%s\"", fixquote(zlab));
341 #ifndef NO_GETTEXT
342 RESET_LOCALE;
343 #endif
344 if(gtprefix)
345 sprintf(aline, "%s%s", fixquote(gtprefix), g(_("Multiple Linear Regression")));
346 else
347 sprintf(aline, "%s", g(_("Multiple Linear Regression")));
348 gnuplotcmd("set title \"%s\"", aline);
349 #ifndef NO_GETTEXT
350 SET_C_LOCALE;
351 #endif
352 gnuplotcmd("splot [%g:%g][%g:%g][] '%s', '%s' with impulses, u,v,f(u,v)",
353 get_min(x,n), get_max(x,n),get_min(y,n),get_max(y,n), GPL_DAT, GPL_DAT);
354 PLOT_CLOSE;
355 #ifndef NO_GETTEXT
356 RESET_LOCALE;
357 #endif
358 PLOT_MSG;
359 return TRUE;
360 }
361
362
363 BOOLEAN plot_cdf_ks(REAL z[], int n, REAL z0, REAL fn1, REAL fn2,
364 REAL x[], char *xlab) {
365 const REAL zmin=(-3.0), zmax=3.0;
366 FILE *tempf;
367 REAL cdf;
368 int i;
369 char aline[160];
370
371 if (!init_gnuplot()) {
372 return FALSE;
373 }
374
375 #ifndef NO_GETTEXT
376 SET_C_LOCALE;
377 #endif
378 FOPEN(GPL_DAT, "wt", tempf);
379 fprintf(tempf, "%g %g\n", zmin, 0.0);
380 fprintf(tempf, "%g %g\n", z[0], 0.0);
381 for (i=0; i<(n-1); i++) {
382 cdf = (REAL)(i+1)/(REAL)n;
383 fprintf(tempf, "%g %g\n", z[i], cdf);
384 fprintf(tempf, "%g %g\n", z[i+1], cdf);
385 }
386 fprintf(tempf, "%g %g\n", z[n-1], 1.0);
387 fprintf(tempf, "%g %g\n", zmax, 1.0);
388 /*
389 fprintf(tempf, "\n%g %g\n%g %g\n", zmin, fn1, zmax, fn1);
390 fprintf(tempf, "\n%g %g\n%g %g\n", zmin, fn2, zmax, fn2);
391 */
392 FCLOSE(tempf);
393
394 set_default();
395 gnuplotcmd("set xlabel \"N(%s)\"", fixquote(xlab));
396 gnuplotcmd("set ylabel \"S(%s)\"", fixquote(xlab));
397 #ifndef NO_GETTEXT
398 RESET_LOCALE;
399 #endif
400 if(gtprefix)
401 sprintf(aline, "%s%s", fixquote(gtprefix), g(_("KS-Lilliefors-Test")));
402 else
403 sprintf(aline, "%s", g(_("KS-Lilliefors-Test")));
404 gnuplotcmd("set title \"%s\"", aline);
405 #ifndef NO_GETTEXT
406 SET_C_LOCALE;
407 #endif
408 gnuplotcmd("u(x)=%g", fn1);
409 gnuplotcmd("l(x)=%g", fn2);
410 gnuplotcmd("plot [%g:%g] [0:1.02] '%s' with lines, norm(x), u(x), l(x) with lines 3",
411 zmin, zmax, GPL_DAT);
412 PLOT_CLOSE;
413 #ifndef NO_GETTEXT
414 RESET_LOCALE;
415 #endif
416 PLOT_MSG;
417 return TRUE;
418 }
419
420 BOOLEAN plot_cdf(REAL z[], int n, char *xlab) {
421 const REAL zmin= z[0], zmax = z[n-1];
422 FILE *tempf;
423 REAL cdf;
424 int i;
425 char aline[160];
426
427 if (!init_gnuplot()) {
428 return FALSE;
429 }
430
431 #ifndef NO_GETTEXT
432 SET_C_LOCALE;
433 #endif
434 FOPEN(GPL_DAT, "wt", tempf);
435 /* fprintf(tempf, "%g %g\n", z[0], 0.0); */
436 for (i=0; i<(n-1); i++) {
437 cdf = (REAL)(i+1)/(REAL)n;
438 fprintf(tempf, "%g %g\n", z[i], cdf);
439 fprintf(tempf, "%g %g\n", z[i+1], cdf);
440 }
441 fprintf(tempf, "%g %g\n", zmax, 1.0);
442 FCLOSE(tempf);
443
444 set_default();
445 gnuplotcmd("set xlabel \"%s\"", fixquote(xlab));
446 gnuplotcmd("set ylabel \"%%(%s)\"", fixquote(xlab));
447 #ifndef NO_GETTEXT
448 RESET_LOCALE;
449 #endif
450 if(gtprefix)
451 sprintf(aline, "%s%s", fixquote(gtprefix), g(_("Cumulative distribution")));
452 else
453 sprintf(aline, "%s", g(_("Cumulative distribution")));
454 gnuplotcmd("set title \"%s\"", aline);
455 #ifndef NO_GETTEXT
456 SET_C_LOCALE;
457 #endif
458 gnuplotcmd("plot [%g:%g] [0:1.02] '%s' with lines", zmin, zmax, GPL_DAT);
459 PLOT_CLOSE;
460 #ifndef NO_GETTEXT
461 RESET_LOCALE;
462 #endif
463 PLOT_MSG;
464 return TRUE;
465 }
466
467
468 BOOLEAN plot_histo(REAL x[], int y[], int n, REAL step, REAL data[],
469 char *datalab) {
470 FILE *tempf;
471 unsigned int i, miny, maxy;
472 REAL minx, maxx;
473 char aline[160];
474
475 if (!init_gnuplot()) {
476 return FALSE;
477 }
478
479 #ifndef NO_GETTEXT
480 SET_C_LOCALE;
481 #endif
482 FOPEN(GPL_DAT, "wt", tempf);
483 for (i=0; i<n; i++) {
484 fprintf(tempf, "%g %i\n", x[i], y[i]);
485 }
486 miny = 0;
487 maxy = (int)(get_maxint(y, n)*1.05) + 1;
488 minx = get_min(x, n);
489 maxx = get_max(x, n);
490 FCLOSE(tempf);
491 set_default();
492 #ifndef NO_GETTEXT
493 RESET_LOCALE;
494 #endif
495 if(gtprefix)
496 sprintf(aline, "%s%s", fixquote(gtprefix), g(_("Histogram")));
497 else
498 sprintf(aline, "%s", g(_("Histogram")));
499 gnuplotcmd("set title \"%s\"", aline);
500 gnuplotcmd("set ylabel '%s'", g(_("Frequency")));
501 #ifndef NO_GETTEXT
502 SET_C_LOCALE;
503 #endif
504 gnuplotcmd("set xlabel \"%s\"", fixquote(datalab));
505 if(((maxx+step/2.)-(minx-step/2.)) /step >10)
506 {
507 gnuplotcmd("set xtics autofreq");
508 } else
509 gnuplotcmd("set xtics %g, %g, %g",
510 (minx-step/2.), step, (maxx+step/2.));
511 gnuplotcmd("plot [%g:%g][%i:%i] '%s' with boxes linetype linetype",
512 minx-step/2., maxx+step/2., miny, maxy, GPL_DAT);
513 PLOT_CLOSE;
514 #ifndef NO_GETTEXT
515 RESET_LOCALE;
516 #endif
517 PLOT_MSG;
518 return TRUE;
519 }
520
521
522 BOOLEAN plot_histo_discrete(REAL x[], int y[], int n, REAL step, REAL data[],
523 char *datalab) {
524 FILE *tempf;
525 unsigned int i, miny, maxy;
526 REAL minx, maxx;
527 char aline[160];
528
529 if (!init_gnuplot()) {
530 return FALSE;
531 }
532
533 #ifndef NO_GETTEXT
534 SET_C_LOCALE;
535 #endif
536 FOPEN(GPL_DAT, "wt", tempf);
537 for (i=0; i<n; i++) {
538 fprintf(tempf, "%g %i\n", x[i], y[i]);
539 }
540 miny = 0;
541 maxy = get_maxint(y, n) + 1;
542 minx = get_min(x, n) - (step/2.);
543 maxx = get_max(x, n) + (step/2.);
544 FCLOSE(tempf);
545 set_default();
546 #ifndef NO_GETTEXT
547 RESET_LOCALE;
548 #endif
549 if(gtprefix)
550 sprintf(aline, "%s%s", fixquote(gtprefix), g(_("Histogram")));
551 else
552 sprintf(aline, "%s", g(_("Histogram")));
553 gnuplotcmd("set title \"%s\"", aline);
554 gnuplotcmd("set ylabel '%s'", g(_("Frequency")));
555 gnuplotcmd("set xlabel \"%s\"", fixquote(datalab));
556 #ifndef NO_GETTEXT
557 SET_C_LOCALE;
558 #endif
559 gnuplotcmd("set xtics %g, %g, %g", (minx+step/2.), step, (maxx-step/2.));
560 /* gnuplotcmd("set boxwidth %g\n", step/4. ); */
561 /* gnuplotcmd("plot [%g:%g][%i:%i] '%s' with boxes\n", */
562 gnuplotcmd("plot [%g:%g][%i:%i] '%s' with impulses",
563 minx, maxx, miny, maxy, GPL_DAT);
564 PLOT_CLOSE;
565 #ifndef NO_GETTEXT
566 RESET_LOCALE;
567 #endif
568 PLOT_MSG;
569 return TRUE;
570 }
571
572 BOOLEAN plot_probit(REAL dose[], REAL num[], REAL effect[], int n,
573 REAL a0, REAL a1, REAL dose0, REAL dose1,
574 char *doselab, char *effectlab) {
575 FILE *tempf;
576 int i;
577 char aline[160];
578 #ifndef STATIST_X
579 out_r("plot_probit: doselab=|%s|, effectlab=|%s|\n",
580 doselab, effectlab);
581 #endif
582 if (!init_gnuplot()) {
583 return FALSE;
584 }
585
586 #ifndef NO_GETTEXT
587 SET_C_LOCALE;
588 #endif
589 FOPEN(GPL_DAT, "wt", tempf);
590 for (i=0; i<n; i++) {
591 fprintf(tempf, "%g %g\n", dose[i], (effect[i]/num[i])*100.);
592 }
593 FCLOSE(tempf);
594 set_default();
595 #ifndef NO_GETTEXT
596 RESET_LOCALE;
597 #endif
598 sprintf(aline, g(_("Dose %s")), fixquote(doselab));
599 gnuplotcmd("set xlabel \"%s\"", aline);
600 sprintf(aline, g(_("Effect %s [%%]")), fixquote(effectlab));
601 gnuplotcmd("set ylabel \"%s\"", aline);
602 if(gtprefix)
603 sprintf(aline, "%s%s", fixquote(gtprefix), g(_("Probit analysis")));
604 else
605 sprintf(aline, "%s", g(_("Probit analysis")));
606 gnuplotcmd("set title \"%s\"", aline);
607 #ifndef NO_GETTEXT
608 SET_C_LOCALE;
609 #endif
610 gnuplotcmd("set grid");
611 gnuplotcmd("set log x");
612 gnuplotcmd("a0=%g", a0);
613 gnuplotcmd("a1=%g", a1);
614 gnuplotcmd("f(x)=norm((log10(x)*a1+a0)-5)*100");
615 gnuplotcmd("plot [%g:%g] '%s', f(x)",
616 dose0, dose1, GPL_DAT);
617 PLOT_CLOSE;
618 #ifndef NO_GETTEXT
619 RESET_LOCALE;
620 #endif
621 PLOT_MSG;
622 return TRUE;
623 }
624
625
626
627 BOOLEAN plot_box(REAL x[], int n, REAL median, REAL mean, REAL q_l,
628 REAL q_u, REAL w_l, REAL w_u, REAL no_l,
629 REAL no_u, char *xlab) {
630 FILE *tempf;
631 int i;
632 REAL min, max, off;
633 char aline[160];
634
635 if (!init_gnuplot()) {
636 return FALSE;
637 }
638
639 min = get_min(x, n);
640 max = get_max(x, n);
641 off = (max-min)/20.;
642
643 #ifndef NO_GETTEXT
644 SET_C_LOCALE;
645 #endif
646 FOPEN(GPL_DAT, "wt", tempf);
647 fprintf(tempf, "%g 10\n", q_l);
648 fprintf(tempf, "%g 12\n", q_l);
649 fprintf(tempf, "%g 12\n", q_u);
650 fprintf(tempf, "%g 10\n", q_u);
651 fprintf(tempf, "%g 10\n\n", q_l);
652 fprintf(tempf, "%g 10\n", median);
653 fprintf(tempf, "%g 12\n\n", median);
654 fprintf(tempf, "%g 11\n", w_l);
655 fprintf(tempf, "%g 11\n\n", q_l);
656 fprintf(tempf, "%g 10.7\n", w_l);
657 fprintf(tempf, "%g 11.3\n\n", w_l);
658 fprintf(tempf, "%g 11\n", q_u);
659 fprintf(tempf, "%g 11\n\n", w_u);
660 fprintf(tempf, "%g 10.7\n", w_u);
661 fprintf(tempf, "%g 11.3\n\n", w_u);
662 fprintf(tempf, "%g 11.1\n", no_l+off*0.2);
663 fprintf(tempf, "%g 11.1\n", no_l);
664 fprintf(tempf, "%g 10.9\n", no_l);
665 fprintf(tempf, "%g 10.9\n\n", no_l+off*0.2);
666 fprintf(tempf, "%g 11.1\n", no_u-off*0.2);
667 fprintf(tempf, "%g 11.1\n", no_u);
668 fprintf(tempf, "%g 10.9\n", no_u);
669 fprintf(tempf, "%g 10.9\n\n", no_u-off*0.2);
670 FCLOSE(tempf);
671
672 set_default();
673
674 for (i=0; i<n; i++) {
675 if ((x[i]>w_u) || (x[i]<w_l)) {
676 gnuplotcmd("set label '*' at %g, 11 center", x[i]);
677 }
678 }
679
680 gnuplotcmd("unset ytics");
681 gnuplotcmd("set label");
682 gnuplotcmd("set label 'o' at %g, 11 center", mean);
683 gnuplotcmd("set label 'n=%i' at %g, 12.7 right", n, max);
684 #ifndef NO_GETTEXT
685 RESET_LOCALE;
686 #endif
687 if(gtprefix)
688 sprintf(aline, "%s%s", fixquote(gtprefix), g(_("Box-and-Whisker Plot")));
689 else
690 sprintf(aline, "%s", g(_("Box-and-Whisker Plot")));
691 gnuplotcmd("set title \"%s\"", aline);
692 #ifndef NO_GETTEXT
693 SET_C_LOCALE;
694 #endif
695 gnuplotcmd("set xlabel \"%s\"", fixquote(xlab));
696 gnuplotcmd("plot [%g:%g][9:13] '%s' with lines",
697 min-off, max+off, GPL_DAT);
698 PLOT_CLOSE;
699 #ifndef NO_GETTEXT
700 RESET_LOCALE;
701 #endif
702 PLOT_MSG;
703 return TRUE;
704 }
705
706
707
708
709 BOOLEAN plot_poly(REAL x[], REAL y[], int n, REAL a[], int npoly,
710 char *xlab, char *ylab) {
711 FILE *tempf;
712 int i;
713 char term[255], aline[255], grtitle[255];
714
715 if (!init_gnuplot()) {
716 return FALSE;
717 }
718
719 #ifndef NO_GETTEXT
720 SET_C_LOCALE;
721 #endif
722 FOPEN(GPL_DAT, "wt", tempf);
723 for (i=0; i<n; i++) {
724 fprintf(tempf, "%g %g\n", x[i], y[i]);
725 }
726 FCLOSE(tempf);
727 set_default();
728 strcpy(aline, "f(x) = ");
729 for (i=0; i<=npoly; i++) {
730 gnuplotcmd("a%i=%g", i, a[i]);
731 sprintf(term, "a%i*x**%i+", i, i);
732 strncat(aline, term, 255-strlen(aline));
733 }
734 strcat(aline, "0\n");
735 gnuplotcmd("%s", aline);
736 gnuplotcmd("set xlabel \"%s\"", fixquote(xlab));
737 gnuplotcmd("set ylabel \"%s\"", fixquote(ylab));
738 #ifndef NO_GETTEXT
739 RESET_LOCALE;
740 #endif
741 sprintf(grtitle, g(_("Polynomial Regression of Order %i")), npoly);
742 if(gtprefix)
743 sprintf(aline, "%s%s", fixquote(gtprefix), grtitle);
744 else
745 sprintf(aline, "%s", grtitle);
746 gnuplotcmd("set title \"%s\"", aline);
747 gnuplotcmd("plot '%s', f(x)", GPL_DAT);
748 PLOT_CLOSE;
749 PLOT_MSG;
750 return TRUE;
751 }
752
753
754 #ifndef MSDOS
755 BOOLEAN plot_command() {
756 char aline[80];
757 char *s;
758 int i, j;
759
760 if (!init_gnuplot()) {
761 return FALSE;
762 }
763
764 if(plothist && lastcmd > -1){
765 out_d(_("Last commands sent to gnuplot:\n\n"));
766 j = lastcmd;
767 for(i = 0; i < histsize; i++){
768 j++;
769 if(j == histsize)
770 j = 0;
771 if(plothist[j])
772 out_d(" %s\n", plothist[j]);
773 }
774 out_d("\n");
775 }
776 out_i(_("Terminate gnuplot commands with '.'\n\n") );
777
778 do {
779 out_i("gnuplot> ");
780 fgets(aline, 79, stdin);
781 s = aline;
782 while(s[0] == ' ' || s[0] == '\t')
783 s++;
784 if (s[0] == '.')
785 break;
786 if (s[0] == 'q' || (s[0] == 'e' && s[1] == 'x')){
787 pclose(pipef);
788 gnupl_open = FALSE;
789 has_graph = FALSE;
790 clear_history();
791 if(myexist(GPL_DAT))
792 remove(GPL_DAT);
793 break;
794 }
795 gnuplotcmd(g(s));
796 fflush(pipef);
797 } while (1);
798 return TRUE;
799 }
800 #endif