tomwalters@0: /**************************************************************************** tomwalters@0: * tomwalters@0: * compilation: cc -o xgram xgram.c -lX11 tomwalters@0: * tomwalters@0: * "profile" is an array with an element for each pixel across the window. tomwalters@0: * tomwalters@0: ****************************************************************************/ tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "x11coord.h" tomwalters@0: tomwalters@0: char DEFNAME[]= "stdin"; /* window name */ tomwalters@0: char *name = DEFNAME; tomwalters@0: tomwalters@0: /**************************************************************************** tomwalters@0: * Defaults for plot tomwalters@0: ****************************************************************************/ tomwalters@0: #define DEFn 128 /* number of data points on a plot line */ tomwalters@0: #define DEFln FULLWIDTH>>1 /* length of plot line in pixels */ tomwalters@0: #define DEFl 1000 /* max number of lines to plot */ tomwalters@0: #define DEFs 0 /* number of plot lines offset from start of file */ tomwalters@0: #define DEFf 0.2 /* scale factor for plot y-values */ tomwalters@0: tomwalters@0: #define DEFdx 2 /* origin increments for successive lines, in pixels */ tomwalters@0: #define DEFdy 2 tomwalters@0: tomwalters@0: /**************************************************************************** tomwalters@0: * Arguments tomwalters@0: ****************************************************************************/ tomwalters@0: int s=DEFs; /* start position in file */ tomwalters@0: short n=DEFn; /* number of data points on a plot line */ tomwalters@0: short l=DEFl; /* max number of lines to plot */ tomwalters@0: short ln=DEFln; /* length of plot line in pixels */ tomwalters@0: short dx=DEFdx,dy=DEFdy; /* increments for successive lines, in pixels */ tomwalters@0: double f=DEFf; /* scale factor for each y-value */ tomwalters@0: tomwalters@0: /**************************************************************************** tomwalters@0: * main tomwalters@0: ****************************************************************************/ tomwalters@0: main(argc, argv) tomwalters@0: int argc ; tomwalters@0: char *argv[] ; tomwalters@0: { tomwalters@0: FILE *fp, *fopen(); tomwalters@0: Window w; tomwalters@0: short p; tomwalters@0: int i; tomwalters@0: tomwalters@0: tomwalters@0: while (--argc > 0 && **++argv == '-') tomwalters@0: switch (*++*argv) { tomwalters@0: case 'n': n = atoi(++*argv); break; tomwalters@0: case 'l': l = atoi(++*argv); break; tomwalters@0: case 's': s = atoi(++*argv); break; tomwalters@0: case 'f': f *= atof(++*argv); break; tomwalters@0: case 'x': dx = atoi(++*argv); break; tomwalters@0: case 'y': dy = atoi(++*argv); break; tomwalters@0: case 'h': tomwalters@0: case 'H': tomwalters@0: default: help(); tomwalters@0: } tomwalters@0: /* Open data file */ tomwalters@0: if (argc) { tomwalters@0: name = *argv; tomwalters@0: if ((fp = fopen(name, "r")) == NULL) { tomwalters@0: fprintf(stderr,"can't open %s\n", *argv); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: } tomwalters@0: else fp = stdin; tomwalters@0: /* Seek start of data in file */ tomwalters@0: if (s > 0) { tomwalters@0: s *= n; /* convert number of lines to number of points */ tomwalters@0: for (i=0 ; i