20 #define DEFPOINTCHARS "oxabcdefhgijklmnpqrstuvwyz" 139 gr->
pname =
"(unknown)";
155 fprintf(
cp_err,
"Can't open viewport for graphics.\n");
173 char *text =
"Enter p for hardcopy, return to continue";
174 char *text1 =
"Hit p for hardcopy, any other key to continue";
186 &&
prefix(
"/dev/tty", buf)) {
187 fprintf(
cp_err,
"%s", text);
199 request.
fp = (FILE*)0;
220 int i, blsize, nblks, size, len;
229 if (!xs || xs->v_numdims <= 1) {
237 blsize = xs->v_dims[xs->v_numdims-1];
239 for (i = 0; i < v->v_numdims - 1; i++)
240 nblks *= v->v_dims[i];
242 sdata = (
isreal(xs) ? (
char*)xs->v_realdata : (
char*)xs->v_compdata);
243 vdata = (
isreal(v) ? (
char*)v->v_realdata : (
char*)v->v_compdata);
245 xs->v_length = blsize;
246 v->v_length = blsize;
249 for (i = 0; i < nblks; i++) {
253 blsize = len - (size - blsize);
254 xs->v_length = blsize;
255 v->v_length = blsize;
262 xs->v_realdata += blsize;
264 xs->v_compdata += blsize;
266 v->v_realdata += blsize;
268 v->v_compdata += blsize;
272 xs->v_realdata = (
double*) sdata;
274 xs->v_compdata = (
complex*) sdata;
277 v->v_realdata = (
double*) vdata;
279 v->v_compdata = (
complex*) vdata;
292 int degree, gridsize, length;
294 double *scratch, *result, *gridbuf, *mm;
295 double *xdata, *ydata;
296 bool rot, increasing;
297 double dx, dy, lx = 0, ly = 0;
304 if (degree > v->v_length)
305 degree = v->v_length;
307 fprintf(
cp_err,
"Error: polydegree is %d, can't plot...\n",
314 if ((gridsize < 0) || (gridsize > 10000)) {
315 fprintf(
cp_err,
"Error: bad grid size %d\n", gridsize);
318 if (gridsize && xs) {
320 increasing = (xs->v_realdata[0] < xs->v_realdata[1]);
321 for (i = 0; i < xs->v_length - 1; i++)
322 if (increasing != (xs->v_realdata[i] <
323 xs->v_realdata[i + 1])) {
325 "Warning: scale not monotonic, gridsize not relevant.\n");
331 increasing = (
realpart (&xs->v_compdata[0]) <
333 for (i = 0; i < xs->v_length - 1; i++)
334 if (increasing != (
realpart( &xs->v_compdata[i]) <
335 realpart( &xs->v_compdata[i + 1]))) {
337 "Warning: scale not monotonic, gridsize not relevant.\n");
347 for (i = 0; i < v->v_length; i++) {
352 if (v->v_length == 1) {
365 0.0, (j==i ? 1 : i));
371 imagpart(&v->v_compdata[j]), (j==i ? 1 : i));
383 if ((degree == 1) && (gridsize == 0)) {
384 for (i = 0, j = v->v_length; i < j; i++) {
385 dx =
isreal(xs) ? xs->v_realdata[i] :
387 dy =
isreal(v) ? v->v_realdata[i] :
393 if (v->v_length == 1)
399 if (gridsize < degree + 1)
404 gridbuf = (
double *)
tmalloc(gridsize *
sizeof (
double));
405 result = (
double *)
tmalloc(gridsize *
sizeof (
double));
407 ydata = v->v_realdata;
409 ydata = (
double *)
tmalloc(v->v_length *
411 for (i = 0; i < v->v_length; i++)
412 ydata[i] =
realpart(&v->v_compdata[i]);
415 xdata = xs->v_realdata;
417 xdata = (
double *)
tmalloc(xs->v_length *
419 for (i = 0; i < xs->v_length; i++)
420 xdata[i] =
realpart(&xs->v_compdata[i]);
424 dx = (mm[1] - mm[0]) / gridsize;
426 for (i = 0, dy = mm[0]; i < gridsize; i++, dy += dx)
429 for (i = 0, dy = mm[1]; i < gridsize; i++, dy -= dx)
433 fprintf(
cp_err,
"Error: can't put %s on gridsize %d\n",
434 v->v_name, gridsize);
441 for (i = 0; i < gridsize; i++)
442 gr_point(v, gridbuf[i], result[i], gridbuf[i ? (i - 1)
443 : i], result[i ? (i - 1) : i], -1);
457 scratch = (
double *)
tmalloc((degree + 1) * (degree + 2) *
459 result = (
double *)
tmalloc((degree + 1) *
sizeof (double));
460 xdata = (
double *)
tmalloc((degree + 1) *
sizeof (double));
461 ydata = (
double *)
tmalloc((degree + 1) *
sizeof (double));
466 DCOPY(v->v_realdata, ydata, degree + 1);
469 for (i = 0; i <= degree; i++)
470 ydata[i] =
realpart(&v->v_compdata[i]);
472 DCOPY(xs->v_realdata, xdata, degree + 1);
475 for (i = 0; i <= degree; i++)
476 xdata[i] =
realpart(&xs->v_compdata[i]);
479 while (!
ft_polyfit(xdata, ydata, result, degree, scratch)) {
484 if (
ft_polyfit(ydata, xdata, result, degree, scratch)) {
489 fprintf(
cp_err,
"plotcurve: Internal Error: ack...\n");
495 for (i = 0; i < degree; i++)
506 length = v->v_length;
507 for (
l = degree + 1;
l < length;
l++) {
510 for (i = 0; i < degree; i++) {
511 xdata[i] = xdata[i + 1];
512 ydata[i] = ydata[i + 1];
515 ydata[i] = v->v_realdata[
l];
519 xdata[i] = xs->v_realdata[
l];
524 while (!
ft_polyfit(xdata, ydata, result, degree, scratch)) {
525 if (
ft_polyfit(ydata, xdata, result, degree, scratch)) {
531 "plotcurve: Internal Error: ack...\n");
537 result, degree,
true);
540 result, degree,
false);
551 #define GRANULARITY 10 562 double incr, dx, dy, lx, ly;
580 incr = (hi - lo) / (
double) (steps + 1);
584 for (i = 0; i <=
steps; i++, dx += incr) {
605 double newx, newy, oldx, oldy;
612 int fromx, fromy, tox, toy;
617 if (dv->v_plottype ==
PLOT_LIN && !np)
return;
623 oldtox = tox; oldtoy = toy;
625 if (
clip_line(&fromx, &fromy, &tox, &toy,
645 if (tox != oldtox || toy != oldtoy)
652 DevLine(fromx, fromy, tox, toy);
671 pointc[0] = dv->v_linestyle;
698 dl = (
struct dvlist*)linkp;
702 for ( ; dl; dl = dl->
dl_next) {
710 new->v_scale =
vec_copy(new->v_scale);
730 for (dl = (
struct dvlist*)linkp; dl; dl = dn) {
766 struct dvlist *dl, *dl0 = (
struct dvlist *)graph->plotdata;;
777 curcolor = (graph->grid.gridtype ==
GRID_SMITH) ? 3 : 1;
781 for (dl = dl0; dl; dl = dl->
dl_next) {
792 else if (
eq(s,
"zero")) {
807 curcolor = ((graph->grid.gridtype ==
GRID_SMITH &&
862 double oldxratio, oldyratio;
863 double scalex, scaley;
867 oldyratio = graph->aspectratioy;
868 graph->viewportxoff = graph->fontwidth * 8;
869 graph->viewportyoff = graph->fontheight * 4;
871 graph->viewport.width = graph->absolute.width -
872 2 * graph->viewportxoff;
873 graph->viewport.height = graph->absolute.height -
874 2 * graph->viewportyoff;
880 scalex = 1
e-3*(graph->datawindow.xmax - graph->datawindow.xmin);
881 graph->datawindow.xmin += scalex;
882 graph->datawindow.xmax -= scalex;
887 scaley = 1
e-3*(graph->datawindow.ymax - graph->datawindow.ymin);
888 graph->datawindow.ymin += scaley;
889 graph->datawindow.ymax -= scaley;
892 gr_fixgrid(graph, graph->grid.xdelta, graph->grid.ydelta,
893 graph->grid.xdatatype, graph->grid.ydatatype);
897 graph->datawindow.width = graph->datawindow.xmax -
898 graph->datawindow.xmin;
899 graph->datawindow.height = graph->datawindow.ymax -
900 graph->datawindow.ymin;
903 graph->aspectratiox = graph->datawindow.width / graph->viewport.width;
904 graph->aspectratioy = graph->datawindow.height / graph->viewport.height;
907 scalex = oldxratio / graph->aspectratiox;
908 scaley = oldyratio / graph->aspectratioy;
909 for (k = graph->keyed; k; k = k->next) {
910 k->x = (k->x - graph->viewportxoff) * scalex + graph->viewportxoff;
911 k->y = (k->y - graph->viewportyoff) * scaley + graph->viewportyoff;
935 for (link = (
struct dvlist*)graph->plotdata, plotno = 0; link;
936 link = link->
dl_next, plotno++) {
944 graph->onevalue ? (
struct dvec *)
NULL :
963 for (k = graph->keyed; k; k = k->next) {
static char buf[MAXPROMPT]
static void plotinterval()
static void restoretext()
bool cp_getvar(char *n, int t, char *r)
struct graph::@2 absolute
internalerror(char *message)
union graph::@4::@7 yaxis
struct graph::@3 datawindow
static void do_plot_trace()
union response::@11 reply
void gr_point(struct dvec *dv, double newx, double newy, double oldx, double oldy, int np)
static GRDATA copydveclist()
static void freedveclist()
GRAPH * gr_init(struct dvlist *dl0, char *grp)
union graph::@4::@7 xaxis
static char pointchars[128]
struct graph::@1 viewport