/*----------------------------------------------------------------------------- * gnuplot_x11 - X11 outboard terminal driver for gnuplot 2 * * Requires installation of companion inboard x11 driver in gnuplot/term.c * * Acknowledgements: * Chris Peterson (MIT) - original Xlib gnuplot support (and Xaw examples) * Dana Chee (Bellcore) - mods to original support for gnuplot 2.0 * Arthur Smith (Cornell) - graphical-label-widget idea (xplot) * Hendri Hondorp (University of Twente, The Netherlands) - Motif xgnuplot * * This code is provided as is and with no warranties of any kind. * * Ed Kubaitis - Computing Services Office - University of Illinois, Urbana *---------------------------------------------------------------------------*/ #include #include #include #include #include #if defined(SUNOS4) #include #elif defined(HPUX) && defined(MOTIF) #include #else #include "Label.h" #endif #ifdef MOTIF #include /* use -Idir for location on your system */ #define LabelWC xmLabelWidgetClass #define LabelBPM XmNbackgroundPixmap #else #define LabelWC labelWidgetClass #define LabelBPM XtNbitmap #endif #include "x11_limits.h" #define Color (D>1) #define Ncolors 17 FILE *outfile; unsigned long colors[Ncolors]; char color_keys[Ncolors][30] = { "text", "line0", "line1", "line2", "line3", "line4", "line5", "line6", "line7", "line8", "line9", "line10", "line11", "line12", "line13", "line14", "line15" }; char color_values[Ncolors][30] = { "black", "white", "red", "blue", "green", "yellow", "magenta", "cyan", "LimeGreen", "gold", "orange", "HotPink", "DeepSkyBlue", "MediumSpringGreen", "tomato", "tan", "grey75" } ; char dashes[10][5] = { {0}, {1,6,0}, {0}, {4,2,0}, {1,3,0}, {4,4,0}, {1,5,0}, {4,4,4,1,0}, {4,2,0}, {1,3,0} }; #define Nspect 101 XColor xcol; unsigned long spectrum[Nspect]; Widget w_top, w_label; Window win; Display *dpy; Pixmap pixmap; GC gc = (GC)NULL; Dimension W = 512 , H = 512; int D; Arg args[5]; static void gnuplot(), resize(); int cx=0, cy=0, vchar, nc = 0; double xscale, yscale; #define X(x) (Dimension) (x * xscale) #define Y(y) (Dimension) ((X11_YMAX-1-y) * yscale) enum JUSTIFY { LEFT, CENTRE, RIGHT } jmode; #define Nbuf 1024 char buf[Nbuf]; String *commands = NULL; typedef struct { /* See "X Toolkit Intrinsics Programming Manual" */ XFontStruct *font; /* Nye and O'Reilly, O'Reilly & Associates, pp. 80-85 */ unsigned long fg; unsigned long bg; } RValues, *RVptr; RValues rv; XtResource resources[] = { { XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), XtOffset(RVptr, font), XtRString, "fixed" }, { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), XtOffset(RVptr, fg), XtRString, XtDefaultForeground }, { XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel), XtOffset(RVptr, bg), XtRString, XtDefaultBackground }, }; void RGB_values(); /*----------------------------------------------------------------------------- * main program - fire up application and callbacks *---------------------------------------------------------------------------*/ int main(argc, argv) int argc; char *argv[]; { signal(SIGINT, SIG_IGN); signal(SIGTSTP, SIG_IGN); /* initialize application */ w_top = XtInitialize("gnuplot", "Gnuplot", NULL, 0, &argc, argv); XtSetArg(args[0], XtNwidth, W); XtSetArg(args[1], XtNheight, H); w_label = XtCreateManagedWidget ("", LabelWC, w_top, args, (Cardinal)2); XtRealizeWidget(w_top); /* extract needed information */ dpy = XtDisplay(w_top); win = XtWindow(w_label); D = DisplayPlanes(dpy,DefaultScreen(dpy)); if (Color) { char option[20], *value; XColor used, exact; int n; for(n=0; nascent + rv.font->descent); /* add callbacks on input-from-gnuplot-on-stdin & window-resized */ XtAddInput(0, (XtPointer)XtInputReadMask, gnuplot, NULL); XtAddEventHandler(w_label, StructureNotifyMask, FALSE, resize, NULL); XtMainLoop(); return 0; } static int line_style = LineSolid; /*----------------------------------------------------------------------------- * display - display accumulated commands from inboard driver *---------------------------------------------------------------------------*/ int display() { int n, x, y, sw, sl, lt, width, type; char *buf, *str; /* set scaling factor between internal driver & window geometry */ xscale = (double)W / X11_XMAX; yscale = (double)H / X11_YMAX; /* create new pixmap & GC */ if (gc) { XFreeGC(dpy, gc); XFreePixmap(dpy, pixmap); } pixmap = XCreatePixmap(dpy, RootWindow(dpy,DefaultScreen(dpy)), W, H, D); gc = XCreateGC(dpy, pixmap, 0, NULL); XSetFont(dpy, gc, rv.font->fid); /* erase pixmap */ #ifndef MOTIF if (Color) { /* Athena needs different erase for color and mono */ #endif XSetForeground(dpy, gc, colors[0]); XFillRectangle(dpy, pixmap, gc, 0, 0, W, H); XSetForeground(dpy, gc, rv.fg); XSetBackground(dpy, gc, rv.bg); #ifndef MOTIF } else { XSetFunction(dpy, gc, GXxor); XCopyArea(dpy, pixmap, pixmap, gc, 0, 0, W, H, 0, 0); XSetFunction(dpy, gc, GXcopyInverted); } #endif /* connect new pixmap to label widget */ XtSetArg(args[0], LabelBPM, pixmap); XtSetValues(w_label, args, (Cardinal)1); XSetForeground(dpy, gc, colors[0]); /* loop over accumulated commands from inboard driver */ for (n=0; nSTRING_LENGTH) commands[nc++] = XtNewString(buf); else strcpy_ss(commands[nc++], buf); } } if (feof(stdin) || ferror(stdin)) exit(0); } static void resize(w, cd, e) Widget w; char *cd; XConfigureEvent *e; { if (e->type != ConfigureNotify) return; W = e->width; H = e->height; display(); } /* the following is based on an algorithm from Ken Evans: */ void RGB_values(red, green, blue, hue) unsigned short *red; unsigned short *green; unsigned short *blue; double hue; { long ngroups = 5, nmembers = 45, ntotal; double gh, ih; double high=1, medium=0.375, deltax, hx, r, g, b; ntotal = ngroups*nmembers; deltax = (high-medium)/nmembers; hx = hue*ntotal; if (hx<0) hx = 0; if (hx>ntotal) hx = ntotal; gh = (int)(hx/nmembers); ih = (int)(hx); switch ((int)gh) { case 0: r = medium; g = medium + (ih-gh*nmembers)*deltax; b = high; break; case 1: r = medium; g = high; b = high-(ih-gh*nmembers)*deltax; break; case 2: r = medium + (ih-gh*nmembers)*deltax; g = high; b = medium; break; case 3: r = high; g = high-(ih-gh*nmembers)*deltax; b = medium; break; case 4: r = high; g = medium; b = medium+(ih-gh*nmembers)*deltax; break; default: r = high; g = medium; b = high; break; } *red = r*256*255; *green = g*256*255; *blue = b*256*255; }