[Linux-hls-cvs] hls/scripts filter.c,NONE,1.1
Status: Pre-Alpha
Brought to you by:
lucabe
|
From: <lu...@us...> - 2003-12-05 21:48:44
|
Update of /cvsroot/linux-hls/hls/scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv5866/scripts
Added Files:
filter.c
Log Message:
- Some simulator work
- Unbreak the PS scheduler (share was 0 by default)
- Add a filter to convert the simulator output in a .fig file
--- NEW FILE: filter.c ---
#include <stdio.h>
#include <unistd.h>
/* TODO: Allocate this dynamically!!! */
struct plot_data {
int num;
unsigned long long int s1[10000];
unsigned long long int s2[10000];
} data[10];
char dummy1[100], dummy2[100], dummy4[100];
int steps[] = {5, 10, 25, 50, 100, 200, 250, 500, 0};
#define MINSTEP 225
int maxt = 20000;
#define XBORDER 225
#define YBORDER 225
#define YSIZE 1350
#define YBOX 225
#define XOFF 450
#define YAX 1800
#define XAX XOFF + XBORDER
#define YSPACE 800
int data_read(char *filename, struct plot_data *p, int *n)
{
FILE *f;
int res, task, dummy, max, imax, done;
unsigned long long int start, end;
*n = 0;
f = fopen(filename, "r");
if (f == NULL) {
perror("Error opening input file");
exit(-1);
}
done = 0;
max = 0;
while (!done) {
res = fscanf(f, "%d\t\t%Lu %Lu\t%d", &task, &start, &end, &dummy);
if (res != 4) {
done = 1;
} else {
task -= 1000;
p[task].s1[p[task].num] = start / 10000;
p[task].s2[p[task].num] = end / 10000;
#ifdef __VERBOSE__
fprintf(stderr, "Task %d: %Lu - %Lu\n",
task, start / 10000, end / 10000);
#endif
p[task].num++;
if (p[task].num > max) {
max = p[task].num;
imax = task;
}
if (task > *n) {
*n = task;
}
}
}
return imax;
}
void task_plot(int i, unsigned long long int *s1, unsigned long long int *s2, int scale, int n)
{
int j;
for (j = 0; j < i; j++) {
/* 75% filled */
printf("2 2 0 1 0 7 50 0 15 0.000 0 0 -1 0 0 5\n");
printf("\t%d %d ", XAX + (int)s1[j] * scale, YSPACE * n + YAX);
printf("%d %d ", XAX + (int)s1[j] * scale, YSPACE * n + YAX - YBOX);
printf("%d %d ", XAX + (int)s2[j] * scale, YSPACE * n + YAX - YBOX);
printf("%d %d ", XAX + (int)s2[j] * scale, YSPACE * n + YAX);
printf("%d %d\n", XAX + (int)s1[j] * scale, YSPACE * n + YAX);
}
}
void ax_draw(int i, unsigned long long int *s2, int step, int scale, int n)
{
int max_scale, j;
max_scale = (s2[i - 1] + XBORDER) / step;
/* Draw the X ax... */
printf("2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2\n");
printf("0 0 1.00 60.00 120.00\n");
printf("\t%d %d %d %d\n",
XOFF, YSPACE * n + YAX,
XAX + ((int)s2[i - 1] + XBORDER) * scale, YSPACE * n + YAX);
for (j = 1; j < max_scale; j++) {
printf("2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 0 0 2\n");
printf("\t%d %d %d %d\n",
XAX + (j * step) * scale, YSPACE * n + YAX + YBORDER / 2,
XAX + (j * step) * scale, YSPACE * n + YAX);
printf("4 0 0 50 0 0 12 4.7124 4 135 345 ");
printf("%d %d ", XAX + (j * step) * scale - 60, YSPACE * n + YAX + YBORDER);
printf("%d\\001\n", j * step);
}
}
void values_shift(struct plot_data *data, int n)
{
unsigned long long int min;
int j, k;
min = data[0].s1[0];
for (j = 1; j < n; j++) {
if (data[j].s1[0] < min) {
min = data[j].s1[0];
}
}
for(j = 0; j < n; j++) {
for(k = 0; k < data[j].num; k++) {
data[j].s1[k] -= min;
data[j].s2[k] -= min;
}
}
}
void header_out(int n)
{
printf("#FIG 3.2\nLandscape\nCenter\nMetric\nA4\n100.00\nSingle\n-2\n1200 2\n");
/* Draw the Y ax... */
printf("2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2\n");
printf("0 0 1.00 60.00 120.00\n");
printf("\t%d %d %d %d\n",
XAX, (n - 1) * YSPACE + YAX + YBORDER,
XAX, YAX - YSIZE);
}
int main(int argc, char *argv[])
{
int i, j, n;
int step, scale;
int c, done;
if (argc < 2) {
printf("Usage: %s <file1> <file2> ...\n", argv[0]);
exit(-1);
}
done = 0;
while(!done) {
c = getopt(argc, argv, "hs:");
if (c == -1) {
done = 1;
} else {
switch(c) {
case 'h':
fprintf(stderr, "Usage: %s [-s <scale>]\n", argv[0]);
exit(0);
case 's':
maxt = atoi(optarg);
break;
default:
fprintf(stderr, "Unknown option %c\n", c);
exit(-1);
}
}
}
i = data_read(argv[optind], data, &n);
if (i < 0) {
fprintf(stderr, "Cannot read file\n");
exit(-1);
}
#ifdef __VERBOSE__
fprintf(stderr, "Max: %d\n", n);
#endif
n = n + 1;
values_shift(data, n);
step = steps[0];
j = 1;
scale = maxt / (data[0].s2[i - 1] + XBORDER);
while ((step * scale < MINSTEP) && steps[j] != 0) {
step = steps[j++];
}
header_out(n);
for (j = 0; j < n; j++) {
ax_draw(data[j].num, data[j].s2, step, scale, j);
task_plot(data[j].num, data[j].s1, data[j].s2, scale, j);
}
return 0;
}
|