File: main.c

package info (click to toggle)
sch-rnd 1.0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,696 kB
  • sloc: ansic: 119,120; awk: 1,502; makefile: 1,421; sh: 1,404; yacc: 905; lex: 172; xml: 160
file content (103 lines) | stat: -rw-r--r-- 2,304 bytes parent folder | download | duplicates (2)
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
#include <stdlib.h>
#include <plugins/lib_plot/plot_data.h>

#define BUFFLEN 1024

static int fill(plot_trace_t *tr, plot_trdata_t *trdata, plot_which_t which, long from, long len)
{
	double tmp[1024];
	long n;
	plot_pos_t pw;

	if (plot_write_init(&pw, tr, trdata, PLOT_MAIN, 0, 0, tmp, sizeof(tmp)/sizeof(tmp[0])) != 0)
		return -1;

	for(n = 0; n < len; n++)
		plot_write(&pw, n);

	plot_flush(&pw);
	return 0;
}


static void dump(plot_trace_t *tr, plot_trdata_t *td)
{
	double bmain[BUFFLEN], bmin[BUFFLEN], bmax[BUFFLEN], dmain, dmin, dmax;
	long n;
	plot_pos_t pmain, pmin, pmax;

	printf(" trace level %d of %ld pts\n", td->level, td->main.len);

	if (td->level == 0) {
		if (plot_read_init(&pmain, tr, td, PLOT_MAIN, 0, 0, bmain, sizeof(bmain)/sizeof(bmain[0])) != 0) {
			printf("  <error>\n");
			return;
		}
		while(plot_read(&pmain, &dmain) == 0)
			printf("  %.2f\n", dmain);
	}
	else {
		if (plot_read_init(&pmain, tr, td, PLOT_MAIN, 0, 0, bmain, sizeof(bmain)/sizeof(bmain[0])) != 0) {
			printf("  <error main>\n");
			return;
		}
		if (plot_read_init(&pmin, tr, td, PLOT_MIN, 0, 0, bmin, sizeof(bmin)/sizeof(bmin[0])) != 0) {
			printf("  <error min>\n");
			return;
		}
		if (plot_read_init(&pmax, tr, td, PLOT_MAX, 0, 0, bmax, sizeof(bmax)/sizeof(bmax[0])) != 0) {
			printf("  <error max>\n");
			return;
		}
		while((plot_read(&pmain, &dmain) == 0) && (plot_read(&pmin, &dmin) == 0) && (plot_read(&pmax, &dmax) == 0))
			printf("  %.2f [%.2f %.2f]\n", dmain, dmin, dmax);
	}
}

static void verify0(plot_trace_t *tr, plot_trdata_t *td)
{
	double bmain[BUFFLEN], dmain;
	long n;
	plot_pos_t pmain;

	if (plot_read_init(&pmain, tr, td, PLOT_MAIN, 0, 0, bmain, sizeof(bmain)/sizeof(bmain[0])) != 0)
		abort();

	n = 0;
	while(plot_read(&pmain, &dmain) == 0) {
		if (dmain != n)
			abort();
		n++;
	}
}

#define LEN 29

int main()
{
	plot_data_t *pt;
	FILE *fc = fopen("cache", "w+");
	plot_trace_t *tr;
	plot_trdata_t *td;

	pt = plot_data_alloc(1);
	tr = &pt->trace[0];
	plot_trace_init(tr, fc);

	td = plot_trdata_alloc(tr, 0, LEN);
	fill(tr, td, PLOT_MAIN, 0, LEN);

	td = plot_trdata_get(tr, 0, 1);
	dump(tr, td);
/*	verify0(tr, td);*/

	td = plot_trdata_get(tr, 1, 1);
	dump(tr, td);

	td = plot_trdata_get(tr, 2, 1);
	dump(tr, td);

	fclose(fc);
	plot_data_free(pt);
	return 0;
}