Index: /tags/kapa-1-7-0/Ohana/src/kapa/Makefile
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/Makefile	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/Makefile	(revision 10836)
@@ -0,0 +1,72 @@
+default: kapa
+help:
+	@echo "make options: kapa (default)"
+
+include ../../Configure
+HOME 	=	$(ROOT)/src/kapa
+LIB	=	$(HOME)/lib
+BIN	=	$(HOME)/bin
+LIB	=	$(HOME)/lib
+EDIR	=	$(HOME)/event
+GDIR	=	$(HOME)/graph
+SDIR	=	$(HOME)/setup
+INC	=	$(HOME)/include
+include ../../Makefile.Common
+
+LDFLAGS := 	-lkapa -ldvo -lFITS -lohana $(LDFLAGS)
+LDDEPS  = $(DESTLIB)/libkapa.a $(DESTLIB)/libdvo.a $(DESTLIB)/libFITS.a $(DESTLIB)/libohana.a
+INDEPS  = $(DESTINC)/kapa.h $(DESTINC)/dvo.h $(DESTINC)/gfitsio.h $(DESTINC)/ohana.h
+
+kapa: $(BIN)/kapa.$(ARCH)
+install: $(DESTBIN)/kapa
+
+# local source / object files ########################
+EOBJ = \
+$(EDIR)/CheckPipe.$(ARCH).o               $(EDIR)/Stop.$(ARCH).o               \
+$(EDIR)/EventLoop.$(ARCH).o         	  $(EDIR)/Reconfig.$(ARCH).o           \
+$(EDIR)/SetFont.$(ARCH).o           	  $(EDIR)/PositionPicture.$(ARCH).o\
+$(EDIR)/InterpretKeys.$(ARCH).o     	  $(EDIR)/Refresh.$(ARCH).o		\
+$(EDIR)/SetSection.$(ARCH).o		  $(EDIR)/FlushDisplay.$(ARCH).o	\
+$(EDIR)/Resize.$(ARCH).o
+
+GOBJ = \
+$(GDIR)/DrawObjects.$(ARCH).o             $(GDIR)/DrawFrame.$(ARCH).o       	\
+$(GDIR)/DrawText.$(ARCH).o		  $(GDIR)/LoadObject.$(ARCH).o		\
+$(GDIR)/ErasePlot.$(ARCH).o		  $(GDIR)/LoadBox.$(ARCH).o		\
+$(GDIR)/SetLimits.$(ARCH).o               $(GDIR)/PSObjects.$(ARCH).o		\
+$(GDIR)/DrawLabels.$(ARCH).o              $(GDIR)/LoadLabels.$(ARCH).o		\
+$(GDIR)/cursor.$(ARCH).o 		  $(GDIR)/PSFrame.$(ARCH).o		\
+$(GDIR)/LoadPtext.$(ARCH).o		  $(GDIR)/DrawPtext.$(ARCH).o		\
+$(GDIR)/PSLabels.$(ARCH).o		  $(GDIR)/PSPtext.$(ARCH).o		\
+$(GDIR)/PPMit.$(ARCH).o	          \
+
+BDRAW = \
+$(GDIR)/bDrawIt.$(ARCH).o	  	  $(GDIR)/bDrawFrame.$(ARCH).o          \
+$(GDIR)/bDrawLabels.$(ARCH).o             $(GDIR)/bDrawObjects.$(ARCH).o        \
+$(GDIR)/PNGit.$(ARCH).o \
+
+SOBJ = \
+$(SDIR)/CheckColors.$(ARCH).o             $(SDIR)/MakeGC.$(ARCH).o             \
+$(SDIR)/CheckDisplayName.$(ARCH).o  	  $(SDIR)/MapWindow.$(ARCH).o          \
+$(SDIR)/CheckFontName.$(ARCH).o     	  $(SDIR)/NameWindow.$(ARCH).o         \
+$(SDIR)/CheckGeometry.$(ARCH).o     	  $(SDIR)/OpenDisplay.$(ARCH).o        \
+$(SDIR)/CloseDisplay.$(ARCH).o      	  $(SDIR)/QuitX.$(ARCH).o              \
+$(SDIR)/CreateWindow.$(ARCH).o      	  $(SDIR)/SetNormalHints.$(ARCH).o     \
+$(SDIR)/DefineLayout.$(ARCH).o      	  $(SDIR)/SetUpDisplay.$(ARCH).o       \
+$(SDIR)/SetUpWindow.$(ARCH).o        	  $(SDIR)/args.$(ARCH).o               \
+$(SDIR)/GetColor.$(ARCH).o          	  $(SDIR)/SetWMHints.$(ARCH).o         \
+$(SDIR)/LoadFont.$(ARCH).o          	  $(SDIR)/TopWindow.$(ARCH).o          \
+$(SDIR)/Ximage.$(ARCH).o             \
+$(SDIR)/MakeCursor.$(ARCH).o
+
+OBJ  =  $(EOBJ) $(GOBJ) $(SOBJ) $(BDRAW)
+
+# dependancy rules for include files ########################
+$(OBJ): $(INC)/Ximage.h \
+	$(INC)/constants.h \
+	$(INC)/structures.h \
+	$(INC)/prototypes.h
+
+$(OBJ): $(INDEPS) $(LDDEPS)
+
+$(BIN)/kapa.$(ARCH): $(OBJ)
Index: /tags/kapa-1-7-0/Ohana/src/kapa/bin/.cvsignore
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/bin/.cvsignore	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/bin/.cvsignore	(revision 10836)
@@ -0,0 +1,2 @@
+*.linux *.lin64 *.sol *.sun *.sid *.hp *.irix
+*.linrh
Index: /tags/kapa-1-7-0/Ohana/src/kapa/doc/ChangeLog.txt
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/doc/ChangeLog.txt	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/doc/ChangeLog.txt	(revision 10836)
@@ -0,0 +1,31 @@
+
+- kapa 1.6 : 2006.08.23
+  * some PNG fixes
+  * converted to gfits APIs (forces libfits 1.6)
+  * removed items moved to libkapa
+
+- kapa 1.5
+  * fixed residual label text
+  * fixed box -axis,-label,-ticks bug (was ignoring user input) 
+  * dropped unused axis.label (is replaced by label.text)
+  * fixed bug in event loop which missed certain mask types
+  * fixed bDrawLabel error
+  * changed comms to libkapa functions
+
+- kapa 1.4
+  * major work to allow noX operation
+  * added bDraw functions
+  * integrated with libkapa
+
+kapa-1-3: released 2005.10.20
+  changed cursor interaction (returns name for keys)
+  minor changes to use new libohana (v1.5) / libfits (v1.4)
+
+kapa-1-2: released 2005.08.15
+  cleaned up complaints from -Wall -Werror.  mostly defining 
+  prototypes, removing unused variables, pushing Graphcolors
+    into the MakeColormap function 
+
+kapa-1-1:
+  fixed up the event loop to reduce excess cpu spinning.
+  cleaned up the color structure
Index: /tags/kapa-1-7-0/Ohana/src/kapa/doc/VERSIONS
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/doc/VERSIONS	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/doc/VERSIONS	(revision 10836)
@@ -0,0 +1,5 @@
+
+tag names used by kapa:
+
+TAG         : Comment
+kapa-1-0    : first version under CVS
Index: /tags/kapa-1-7-0/Ohana/src/kapa/doc/input
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/doc/input	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/doc/input	(revision 10836)
@@ -0,0 +1,87 @@
+
+macro colortest
+  lim 0 1 0 1; clear; box
+
+  style -x 2 -pt 0 -sz 3.0
+  dot -c black     0.1 0.9
+  dot -c white     0.2 0.9
+  dot -c red       0.3 0.9
+  dot -c pink      0.4 0.9
+  dot -c orange    0.5 0.9
+  dot -c yellow    0.1 0.8
+  dot -c wheat     0.2 0.8
+  dot -c gold      0.3 0.8
+  dot -c green     0.4 0.8
+  dot -c darkgreen 0.5 0.8
+  dot -c blue      0.1 0.7
+  dot -c skyblue   0.2 0.7
+  dot -c indigo    0.3 0.7
+  dot -c violet    0.4 0.7
+  dot -c grey10    0.5 0.7
+  dot -c grey20    0.1 0.6
+  dot -c grey30    0.2 0.6
+  dot -c grey40    0.3 0.6
+  dot -c grey50    0.4 0.6
+  dot -c grey60    0.5 0.6
+  dot -c grey70    0.1 0.5
+  dot -c grey80    0.2 0.5
+  dot -c grey90    0.3 0.5
+end
+
+macro colortest2
+  lim 0 1 0 1; clear; box
+
+  style -x 2 -pt 7 -sz 3.0
+  dot -c black     0.1 0.9
+  dot -c white     0.2 0.9
+  dot -c red       0.3 0.9
+  dot -c pink      0.4 0.9
+  dot -c orange    0.5 0.9
+  dot -c yellow    0.1 0.8
+  dot -c wheat     0.2 0.8
+  dot -c gold      0.3 0.8
+  dot -c green     0.4 0.8
+  dot -c darkgreen 0.5 0.8
+  dot -c blue      0.1 0.7
+  dot -c skyblue   0.2 0.7
+  dot -c indigo    0.3 0.7
+  dot -c violet    0.4 0.7
+  dot -c grey10    0.5 0.7
+  dot -c grey20    0.1 0.6
+  dot -c grey30    0.2 0.6
+  dot -c grey40    0.3 0.6
+  dot -c grey50    0.4 0.6
+  dot -c grey60    0.5 0.6
+  dot -c grey70    0.1 0.5
+  dot -c grey80    0.2 0.5
+  dot -c grey90    0.3 0.5
+end
+
+macro pltest
+  lim 0 1 0 1; clear; box
+
+  style -x 2 -pt 7 -sz 3.0 -lw 2
+  dot -c black     0.1 0.9
+  dot -c white     0.2 0.9
+  dot -c red       0.3 0.9
+  dot -c pink      0.4 0.9
+  dot -c orange    0.5 0.9
+  dot -c yellow    0.1 0.8
+  dot -c wheat     0.2 0.8
+  dot -c gold      0.3 0.8
+  dot -c green     0.4 0.8
+  dot -c darkgreen 0.5 0.8
+  dot -c blue      0.1 0.7
+  dot -c skyblue   0.2 0.7
+  dot -c indigo    0.3 0.7
+  dot -c violet    0.4 0.7
+  dot -c grey10    0.5 0.7
+  dot -c grey20    0.1 0.6
+  dot -c grey30    0.2 0.6
+  dot -c grey40    0.3 0.6
+  dot -c grey50    0.4 0.6
+  dot -c grey60    0.5 0.6
+  dot -c grey70    0.1 0.5
+  dot -c grey80    0.2 0.5
+  dot -c grey90    0.3 0.5
+end
Index: /tags/kapa-1-7-0/Ohana/src/kapa/doc/notes.txt
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/doc/notes.txt	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/doc/notes.txt	(revision 10836)
@@ -0,0 +1,36 @@
+
+2005.11.27
+
+	I am improving the functionality of kapa so that it does not
+	need to have an X server to build PNG / PPM / PS plots.
+	Before, I generated the PNG / PPM plots from the screen image
+	by using an X function to examine the color of each pixel and
+	generate the corresponding PNG/PPM image.  This implied that
+	an X server was required even if the window was not being
+	looked at.  The PS version of the plots were not quite so
+	difficult: the PS code is generated from the plot when the PS
+	output file is constructed.  I decided to implement the
+	equivalent concept for the PNG/PPM images. 
+
+	I have build a set of drawing functions which are used by the
+	PNG function (PPM not yet implemented) to create the PNG image
+	buffer from the graphic objects stored by Kapa.  This
+	subsystem is called bDraw.  Most of the drawing functions
+	correspond to just the primitive point, line, and circle
+	functions.  I have implemented bDrawPoint, bDrawLine,
+	bDrawCircle, and demonstrated the complete concept.  At this
+	point, only a few features are missing:
+
+	- line weight.  the bDraw functions do not respect the value
+          of the line weight (which is available to them).  All lines
+          and circles are drawn as line weight 1.
+
+	- line type.  no line type data is used. (Kapa probably over
+          respects it: it should not apply the line type to the point
+          plotting)
+
+	- rectangles and triangles.  several of the point-types are
+          constructed by calling bDrawRect, bDrawTri, neither of which
+          are implemented at this time.
+
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/CheckPipe.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/CheckPipe.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/CheckPipe.c	(revision 10836)
@@ -0,0 +1,133 @@
+# include "Ximage.h"
+# define STRCONST(A) ((int)(0x1000000*A[0] + 0x10000*A[1] + 0x100*A[2] + 0x1*A[3]))
+
+int CheckPipe () {
+
+  int status;
+  char buffer[32];
+
+  /***** read (4 byte) message word from socket ****/
+  status = read (sock, buffer, 4);
+  buffer[4] = 0;
+  switch (status) {
+  case -1:                          /* no input from pipe: continue */
+    return (TRUE);
+    break;
+
+  case 0:
+    fprintf (stderr, "pipe has died!\n");
+    return (FALSE);
+    break;
+
+  case 4:
+    break;
+
+  default:
+    fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
+    return (TRUE);
+    break;
+  }
+  
+  /***** handle different messages ****/
+  if (!strcmp (buffer, "QUIT")) return (FALSE);
+  
+  if (!strcmp (buffer, "PSIT")) {
+    status = PSit ();
+    write (sock, "DONE", 4);
+    return (status);
+  }
+  
+  if (!strcmp (buffer, "PNGF")) {
+    status = PNGit ();
+    write (sock, "DONE", 4);
+    return (status);
+  }
+  
+  if (!strcmp (buffer, "PPMF")) {
+    status = PPMit ();
+    write (sock, "DONE", 4);
+    return (status);
+  }
+  
+  if (!strcmp (buffer, "RSIZ")) {
+    status = Resize ();
+    return (status);
+  }
+
+  if (!strcmp (buffer, "PLOT")) {
+    status = LoadObject ();
+    return (status);
+  }
+  
+  if (!strcmp (buffer, "LIMS")) {
+    KiiSendMessage (sock, "%8.1f %8.1f ", 
+		    section[TheSection].axis[0].dfx, 
+		    section[TheSection].axis[1].dfy);
+    return (TRUE);
+  }
+  
+  if (!strcmp (buffer, "SLIM")) {
+    status = SetLimits ();
+    return (TRUE);
+  }
+  
+  if (!strcmp (buffer, "LABL")) {
+    status = LoadLabels ();
+    return (TRUE);
+  }
+  
+  if (!strcmp (buffer, "LSEC")) {
+    status = ListSection ();
+    return (TRUE);
+  }
+  
+  if (!strcmp (buffer, "DSEC")) {
+    status = SetSection (FALSE);
+    return (TRUE);
+  }
+  
+  if (!strcmp (buffer, "SSEC")) {
+    status = SetSection (TRUE);
+    return (TRUE);
+  }
+  
+  if (!strcmp (buffer, "PTXT")) {
+    status = LoadPtext ();
+    return (TRUE);
+  }
+  
+  if (!strcmp (buffer, "FONT")) {
+    status = SetFont ();
+    return (TRUE);
+  }
+  
+  if (!strcmp (buffer, "CURS")) {
+    cursor ();
+    return (TRUE);
+  }
+  
+  /* Erase Section */
+  if (!strcmp (buffer, "ERAS")) {
+    status = ErasePlot (TRUE);
+    return (status);
+  }
+  
+  /* Don't Erase Section */
+  if (!strcmp (buffer, "ERSS")) {
+    status = ErasePlot (FALSE);
+    return (status);
+  }
+  
+  if (!strcmp (buffer, "DBOX")) {
+    status = LoadBox ();
+    return (status);
+  }
+  
+  fprintf (stderr, "unknown signal %s\n", buffer);
+
+  return (TRUE);
+
+}
+
+
+    
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/EventLoop.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/EventLoop.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/EventLoop.c	(revision 10836)
@@ -0,0 +1,139 @@
+# include "Ximage.h"
+
+/* # define IgnoreMask (long) (ButtonPressMask | ClientMessage | ButtonReleaseMask | KeyPressMask | PointerMotionMask) */
+
+/* list events being selected below, all other masks are ignored */ 
+# define IgnoreMask (long) (~(StructureNotifyMask | SubstructureNotifyMask | ExposureMask))
+
+int LastEvent (Display *display, int type, XEvent *event) {
+
+  int found;
+
+  found = FALSE;
+  while (XCheckTypedEvent (display, type, event)) {
+    found = TRUE;
+  }
+  return (found);
+}
+
+int EventLoop () {
+  
+  XEvent          event;
+  int             status;
+  Display        *display;
+  
+  if (USE_XWINDOW) Refresh (1);
+
+  status = TRUE;
+  while (status) {
+    
+    if (!CheckPipe ()) return (FALSE);
+    
+    if (!USE_XWINDOW) {
+      usleep (50000);
+      continue;
+    }
+
+    if (XEventsQueued (graphic.display, QueuedAfterFlush) < 1) {
+	/* fprintf (stderr, "."); */
+      usleep (50000);
+      continue;
+    }
+
+    display = graphic.display;
+
+    /* grab the last entry for these events */
+    if (LastEvent (display, ConfigureNotify, &event)) Reconfig (&event);
+    if (LastEvent (display, CirculateNotify, &event)) Reconfig (&event);
+    if (LastEvent (display, Expose,          &event)) Refresh (1);
+
+    if (LastEvent (display, MappingNotify,   &event)) XRefreshKeyboardMapping ((XMappingEvent *) &event);
+
+    /* drop and ignore the following StructureNotifyMask events */
+    LastEvent (display, GravityNotify, &event);
+    LastEvent (display, ReparentNotify, &event);
+    LastEvent (display, MapNotify, &event);
+    LastEvent (display, UnmapNotify, &event);
+
+    /* remove those events we will ignore */
+    while (XCheckMaskEvent (display, IgnoreMask, &event)) continue;
+
+    /* events to remove which have no mask component */
+    while (XCheckTypedEvent (display, MappingNotify, &event)) continue;
+    while (XCheckTypedEvent (display, ClientMessage, &event)) continue;
+    while (XCheckTypedEvent (display, SelectionClear, &event)) continue;
+    while (XCheckTypedEvent (display, SelectionNotify, &event)) continue;
+    while (XCheckTypedEvent (display, SelectionRequest, &event)) continue;
+  }
+  return (status);
+}
+
+# if (0)
+
+/* all masks from X.h for reference: */
+
+#define NoEventMask                     0L
+#define KeyPressMask                    (1L<<0)
+#define KeyReleaseMask                  (1L<<1)
+#define ButtonPressMask                 (1L<<2)
+#define ButtonReleaseMask               (1L<<3)
+#define EnterWindowMask                 (1L<<4)
+#define LeaveWindowMask                 (1L<<5)
+#define PointerMotionMask               (1L<<6)
+#define PointerMotionHintMask           (1L<<7)
+#define Button1MotionMask               (1L<<8)
+#define Button2MotionMask               (1L<<9)
+#define Button3MotionMask               (1L<<10)
+#define Button4MotionMask               (1L<<11)
+#define Button5MotionMask               (1L<<12)
+#define ButtonMotionMask                (1L<<13)
+#define KeymapStateMask                 (1L<<14)
+#define ExposureMask                    (1L<<15)
+#define VisibilityChangeMask            (1L<<16)
+#define StructureNotifyMask             (1L<<17)
+#define ResizeRedirectMask              (1L<<18)
+#define SubstructureNotifyMask          (1L<<19)
+#define SubstructureRedirectMask        (1L<<20)
+#define FocusChangeMask                 (1L<<21)
+#define PropertyChangeMask              (1L<<22)
+#define ColormapChangeMask              (1L<<23)
+#define OwnerGrabButtonMask             (1L<<24)
+
+/* all events from X.h for reference: */
+
+#define KeyPress                2
+#define KeyRelease              3
+#define ButtonPress             4
+#define ButtonRelease           5
+#define MotionNotify            6
+#define EnterNotify             7
+#define LeaveNotify             8
+#define FocusIn                 9
+#define FocusOut                10
+#define KeymapNotify            11
+#define Expose                  12
+#define GraphicsExpose          13
+#define NoExpose                14
+#define VisibilityNotify        15
+#define CreateNotify            16
+#define DestroyNotify           17
+#define UnmapNotify             18
+#define MapNotify               19
+#define MapRequest              20
+#define ReparentNotify          21
+#define ConfigureNotify         22
+#define ConfigureRequest        23
+#define GravityNotify           24
+#define ResizeRequest           25
+#define CirculateNotify         26
+#define CirculateRequest        27
+#define PropertyNotify          28
+#define SelectionClear          29
+#define SelectionRequest        30
+#define SelectionNotify         31
+#define ColormapNotify          32
+#define ClientMessage           33
+#define MappingNotify           34
+#define LASTEvent               35      /* must be bigger than any event # */
+
+# endif
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/FlushDisplay.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/FlushDisplay.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/FlushDisplay.c	(revision 10836)
@@ -0,0 +1,34 @@
+# include "Ximage.h"
+
+static struct timeval reftime; 
+static char reftimeset = FALSE;
+# define DTIME(A,B) ((A.tv_sec - B.tv_sec) + 1e-6*(A.tv_usec - B.tv_usec))
+
+void FlushDisplay () {
+
+  struct timeval now;
+  int flush;
+  double dtime;
+
+  if (!USE_XWINDOW) return;
+
+  flush = FALSE;
+  if (!reftimeset) {
+    flush = TRUE;
+    gettimeofday (&reftime, NULL);
+  } 
+
+  gettimeofday (&now, NULL);
+  dtime = DTIME (now, reftime);
+
+  if (dtime > 0.1) {
+    flush = TRUE;
+  }
+
+  if (flush) {
+    XFlush (graphic.display);
+    reftime = now;
+  }
+
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/InterpretKeys.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/InterpretKeys.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/InterpretKeys.c	(revision 10836)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+
+int InterpretKeys (XEvent *event) {
+
+  int    status;
+  KeySym keysym;
+  char            string[10];
+  XComposeStatus  composestatus;
+
+  XLookupString ((XKeyEvent *)event, string, 9, &keysym, &composestatus);
+
+  switch (keysym) {
+
+  default:
+    status = TRUE;
+  }
+
+  return (status);
+
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/InterpretPresses.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/InterpretPresses.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/InterpretPresses.c	(revision 10836)
@@ -0,0 +1,57 @@
+# include "Ximage.h"
+
+int 
+InterpretPresses (graphic, layout, event)
+Graphic        graphic[];
+Layout         layout[];
+XButtonEvent   event[];
+{
+
+  int             status, done, this_button, x, y, old_cursor;
+  KeySym          keysym;
+  Button         *button;
+
+  status = TRUE;
+  this_button = event[0].button;
+  
+  if ((event[0].type == ButtonPress) && InPicture (event, &layout[0].picture)) {
+    Reorient (graphic, layout, event);
+  }
+
+  if ((event[0].type == ButtonPress) && InPicture (event, &layout[0].cmapbar)) {
+    DragColorbar (graphic, layout, event);
+  }
+
+  /* if on an exisiting button, Invert, wait for release, then go (or not) */
+  if ((button = CheckButtons (event, layout)) != (Button *) NULL) {
+    InvertButton (graphic, button); 
+    done = FALSE;
+    while (!done) { /* wait for release of this button */
+      XNextEvent (graphic[0].display, (XEvent *) event);
+      if ((event[0].type == ButtonRelease) && (event[0].button == this_button)) {
+	done = TRUE;
+      }
+    }
+    DrawButton (graphic, button);
+    if (InButton (event, button)) {
+      switch (event[0].button) {
+      case 1:
+	status = button[0].function_1(graphic, layout);
+	break;
+      case 2:
+	status = button[0].function_2(graphic, layout);
+	break;
+      case 3:
+	status = button[0].function_3(graphic, layout);
+	break;
+      }
+    }
+    else {
+      return (status);
+    }
+  }
+
+  return (status);
+
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/PositionPicture.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/PositionPicture.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/PositionPicture.c	(revision 10836)
@@ -0,0 +1,95 @@
+# include "Ximage.h"
+
+void PositionPicture (Layout *layout) {
+
+  int fontsize, bump, Nc;
+  double PADx, PADy, Dx, Dy;
+  double PXm, PXp, PYm, PYp;
+  double X0, Y0, dX, dY;
+  char string[64], *fontname;
+
+  fontname = GetRotFont (&fontsize);
+
+  /* window has outer bounding box with margins Wx, Wy 
+     section commands subdivide the internal box (Dx,Dy)
+   */
+
+  PADx = MAX (graphic.dx / 20.0, fontsize);
+  PADy = MAX (graphic.dy / 20.0, fontsize);
+  Dx = graphic.dx - 2*PADx;
+  Dy = graphic.dy - 2*PADy;
+
+  /* each graph has a padding PXm, PXp, PYm, PYp */
+  PXm = (layout[0].axis[1].islabel) ? 4*fontsize : 0;
+  PXp = (layout[0].axis[3].islabel) ? 4*fontsize : 0;
+  PYm = (layout[0].axis[0].islabel) ? 4*fontsize : 0;
+  PYp = (layout[0].axis[2].islabel) ? 4*fontsize : 0;
+ 
+  X0 = PADx + PXm + (Dx * layout[0].x);
+  Y0 = PADy + PYm + (Dy * layout[0].y);
+  dX = (Dx * layout[0].dx) - PXp - PXm;
+  dY = (Dy * layout[0].dy) - PYp - PYm;
+
+  /* define locations of coordinate axes */
+  layout[0].axis[0].fx  = X0;
+  layout[0].axis[0].fy  = graphic.dy - Y0;
+  layout[0].axis[0].dfx = dX;
+  layout[0].axis[0].dfy = 0;
+  
+  layout[0].axis[1].fx  = X0;
+  layout[0].axis[1].fy  = graphic.dy - Y0;
+  layout[0].axis[1].dfx = 0;
+  layout[0].axis[1].dfy = -dY;
+
+  layout[0].axis[2].fx  = X0;
+  layout[0].axis[2].fy  = graphic.dy - Y0 - dY;
+  layout[0].axis[2].dfx = dX;
+  layout[0].axis[2].dfy = 0;
+
+  layout[0].axis[3].fx  = X0 + dX;
+  layout[0].axis[3].fy  = graphic.dy - Y0;
+  layout[0].axis[3].dfx = 0;
+  layout[0].axis[3].dfy = -dY;
+
+  PADx = 0.8*fontsize + 2;
+  PADy = 3.0*fontsize + 4;
+
+  /* define locations of axis labels */
+  layout[0].label[LABELX0].x = layout[0].axis[0].fx + 0.5*layout[0].axis[0].dfx;
+  bump = (layout[0].axis[0].islabel) ? PADy : PADx;
+  layout[0].label[LABELX0].y = layout[0].axis[0].fy + bump;
+
+  layout[0].label[LABELX1].x = layout[0].axis[2].fx + 0.5*layout[0].axis[2].dfx;
+  bump = (layout[0].axis[2].islabel) ? PADy : PADx;
+  layout[0].label[LABELX1].y = layout[0].axis[2].fy - bump;
+
+  sprintf (string, "%4g", layout[0].axis[1].min);
+  Nc = strlen (string);
+  sprintf (string, "%4g", layout[0].axis[1].max);
+  Nc = MAX (Nc, strlen (string));
+
+  layout[0].label[LABELY0].y = layout[0].axis[1].fy + 0.5*layout[0].axis[1].dfy;
+  bump = (layout[0].axis[1].islabel) ? (0.8*Nc*fontsize + 1) : PADx;
+  layout[0].label[LABELY0].x = layout[0].axis[1].fx - bump;
+
+  sprintf (string, "%4g", layout[0].axis[1].min);
+  Nc = strlen (string);
+  sprintf (string, "%4g", layout[0].axis[1].max);
+  Nc = MAX (Nc, strlen (string));
+
+  layout[0].label[LABELY1].y = layout[0].axis[3].fy + 0.5*layout[0].axis[3].dfy;
+  bump = (layout[0].axis[3].islabel) ? (0.8*Nc*fontsize + 1) : PADx;
+  layout[0].label[LABELY1].x = layout[0].axis[3].fx + bump;
+  
+  /* these are wrong and have to be adjusted to sit in the corners */
+
+  layout[0].label[LABELUL].x = layout[0].axis[2].fx - PADx;
+  layout[0].label[LABELUL].y = layout[0].axis[2].fy - PADx;
+  layout[0].label[LABELUR].x = layout[0].axis[2].fx + layout[0].axis[2].dfx + PADx;
+  layout[0].label[LABELUR].y = layout[0].axis[2].fy - PADx;
+  layout[0].label[LABELLL].x = layout[0].axis[0].fx - PADx;
+  layout[0].label[LABELLL].y = layout[0].axis[0].fy + PADx;
+  layout[0].label[LABELLR].x = layout[0].axis[0].fx + layout[0].axis[0].dfx + PADx;
+  layout[0].label[LABELLR].y = layout[0].axis[0].fy + PADx;
+
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/Reconfig.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/Reconfig.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/Reconfig.c	(revision 10836)
@@ -0,0 +1,24 @@
+# include "Ximage.h"
+
+int Reconfig (XEvent *event) {
+
+  int i;
+
+  if ((graphic.dx == event[0].xconfigure.width) &&
+      (graphic.dy == event[0].xconfigure.height)) 
+    return (TRUE);
+
+  graphic.dx = MAX(event[0].xconfigure.width,  MIN_WIDTH); 
+  graphic.dy = MAX(event[0].xconfigure.height, MIN_HEIGHT);
+
+  for (i = 0; i < Nsection; i++) {
+    PositionPicture (&section[i]);
+  }
+
+  XClearWindow (graphic.display, graphic.window);
+
+  Refresh (1);
+
+  return (TRUE);
+
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/Refresh.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/Refresh.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/Refresh.c	(revision 10836)
@@ -0,0 +1,25 @@
+# include "Ximage.h"
+
+void Refresh (int mode) {
+
+  int i;
+  
+  if (!USE_XWINDOW) return;
+  if (HAVE_BACKING) return;
+
+  /* XClearWindow   (graphic.display, graphic.window); */
+  XSetForeground (graphic.display, graphic.gc, graphic.back);
+  XFillRectangle (graphic.display, graphic.window, graphic.gc, 0, 0, graphic.dx, graphic.dy);
+  XSetForeground (graphic.display, graphic.gc, graphic.fore);
+  
+  for (i = 0; i < Nsection; i++) {
+    DrawFrame   (&section[i]);
+    DrawObjects (&section[i]);
+    DrawLabels  (&section[i]);
+    DrawPtext   (&section[i]);
+  }
+
+  FlushDisplay ();
+ 
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/Resize.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/Resize.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/Resize.c	(revision 10836)
@@ -0,0 +1,26 @@
+# include "Ximage.h"
+
+int Resize () {
+ 
+  int i;
+  unsigned int NX, NY;
+
+  KiiScanMessage (sock, "%d %d", &NX, &NY);
+
+  if ((graphic.dx == NX) && (graphic.dy == NY)) 
+    return (TRUE);
+
+  graphic.dx = MAX(NX, 50); 
+  graphic.dy = MAX(NY, 50); 
+
+  if (USE_XWINDOW) XResizeWindow (graphic.display, graphic.window, NX, NY);
+
+  for (i = 0; i < Nsection; i++) {
+    PositionPicture (&section[i]);
+  }
+
+  if (USE_XWINDOW) XClearWindow (graphic.display, graphic.window);
+  Refresh (1);
+
+  return (TRUE);
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/SetFont.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/SetFont.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/SetFont.c	(revision 10836)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+int SetFont () {
+  
+  char buffer[256], name[64];
+  int status, size;
+  
+  fcntl (sock, F_SETFL, !O_NONBLOCK);  
+  status = read (sock, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%s", name);
+  
+  status = read (sock, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%d", &size);
+  fcntl (sock, F_SETFL, O_NONBLOCK);  
+  
+  SetRotFont (name, size);
+  
+  return (TRUE);
+  
+}
+
+/*
+  layout[0].X = 0;
+  layout[0].Y = 0;
+  layout[0].expand = 1;
+  */
+
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/SetSection.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/SetSection.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/SetSection.c	(revision 10836)
@@ -0,0 +1,114 @@
+# include "Ximage.h"
+
+int SetSection (int SwitchSection) {
+  
+  int i, NewSection, ThisSection, MoveSection;
+  char name[128];
+  double x, y, dx, dy;
+
+  if (SwitchSection) {
+    KiiScanMessage (sock, "%s", name);
+  } else {
+    KiiScanMessage (sock, "%s %lf %lf %lf %lf", name, &x, &y, &dx, &dy);
+  }    
+
+  NewSection = FALSE;
+  MoveSection = FALSE;
+  ThisSection = -1;
+  for (i = 0; i < Nsection; i++) {
+    if (!strcmp (name, section[i].name)) {
+      ThisSection = i;
+      break;
+    }
+  }
+
+  if (ThisSection == -1) {
+    if (SwitchSection) {
+      fprintf (stderr, "section %s not found\n", name);
+      return (TRUE);
+    }
+    NewSection = TRUE;
+    Nsection ++;
+    REALLOCATE (section, Layout, Nsection);
+    ThisSection = Nsection - 1;
+    strcpy (section[ThisSection].name, name);
+    section[ThisSection].Nobjects = 0;
+    section[ThisSection].Nptext = 0;
+    ALLOCATE (section[ThisSection].objects, Gobjects, 1);  /* allocate so later free will not crash! */
+    section[ThisSection].objects[0].x   = section[ThisSection].objects[0].y   = section[ThisSection].objects[0].z = (float *) NULL;
+    section[ThisSection].objects[0].dxm = section[ThisSection].objects[0].dxp = (float *) NULL;
+    section[ThisSection].objects[0].dym = section[ThisSection].objects[0].dyp = (float *) NULL;
+    ALLOCATE (section[ThisSection].ptext, Label, 1);       /* allocate so later free will not crash! */
+    for (i = 0; i < 4; i++) {
+      section[ThisSection].axis[i].min = 0;
+      section[ThisSection].axis[i].max = 1;
+      section[ThisSection].axis[i].isaxis = FALSE;
+      section[ThisSection].axis[i].areticks = FALSE;
+      section[ThisSection].axis[i].islabel = FALSE;
+    }    
+    for (i = 0; i < 8; i++) {
+      strcpy (section[ThisSection].label[i].text, "");
+    }
+  }
+
+  if (!SwitchSection) {
+    if (!NewSection && (section[ThisSection].x != x)) MoveSection = TRUE;
+    section[ThisSection].x = x;
+    if (!NewSection && (section[ThisSection].y != y)) MoveSection = TRUE;
+    section[ThisSection].y = y;
+    if (!NewSection && (section[ThisSection].dx != dx)) MoveSection = TRUE;
+    section[ThisSection].dx = dx;
+    if (!NewSection && (section[ThisSection].dy != dy)) MoveSection = TRUE;
+    section[ThisSection].dy = dy;
+
+    if (NewSection || MoveSection) {
+      PositionPicture (&section[ThisSection]);
+    }
+
+    if (MoveSection) {
+      XClearWindow (graphic.display, graphic.window);
+      Refresh (1);
+    } 
+    if (NewSection) {
+    }      
+  }
+
+  TheSection = ThisSection;
+
+  return (TRUE);
+  
+}
+
+int ListSection () {
+  
+  int i, ThisSection;
+  char name[128];
+
+  KiiScanMessage (sock, "%s", name);
+
+  if (!strcmp (name, "*")) {
+    for (i = 0; i < Nsection; i++) {
+      fprintf (stderr, "%s: %6.3f %6.3f %6.3f %6.3f\n", 
+	       section[i].name, section[i].x, section[i].y, section[i].dx, section[i].dy);
+    }
+    return (TRUE);
+  }
+
+  ThisSection = -1;
+  for (i = 0; i < Nsection; i++) {
+    if (!strcmp (name, section[i].name)) {
+      ThisSection = i;
+      break;
+    }
+  }
+  if (ThisSection == -1) {
+    fprintf (stderr, "section %s not found\n", name);
+    return (TRUE);
+  }
+
+  fprintf (stderr, "%s: %6.3f %6.3f %6.3f %6.3f\n", 
+	   section[ThisSection].name, 
+	   section[ThisSection].x, section[ThisSection].y, 
+	   section[ThisSection].dx, section[ThisSection].dy);
+  return (TRUE);
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/event/Stop.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/event/Stop.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/event/Stop.c	(revision 10836)
@@ -0,0 +1,8 @@
+# include "Ximage.h"
+
+int Stop () {
+  return (FALSE);
+}
+
+/******  this function looks stupid, but it has to be like this:
+  it is called as a pointer to function **/
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawFrame.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawFrame.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawFrame.c	(revision 10836)
@@ -0,0 +1,161 @@
+# include "Ximage.h"
+# define DrawLine(X,Y,DX,DY) (XDrawLine (graphic.display, graphic.window, graphic.gc, (int)(X), (int)(Y), (int)(X+DX), (int)(Y+DY)))
+  
+void DrawFrame (Layout *layout) {
+  
+  int i, fx, fy, dfx, dfy, P, IsLabel;
+  double range, major, minor, first, next;
+
+  DrawRotTextInit (graphic.display, graphic.window, graphic.gc, graphic.fore, graphic.back);
+
+  /* each axis is drawn independently, but ticks and labels are placed according to
+     perpendicular distance. */
+  for (i = 0; i < 4; i++) {
+    fx = layout[0].axis[i].fx;
+    fy = layout[0].axis[i].fy;
+    dfx = layout[0].axis[i].dfx;
+    dfy = layout[0].axis[i].dfy;
+    P = hypot ((double)layout[0].axis[(i+1)%2].dfx, (double)layout[0].axis[(i+1)%2].dfy);
+
+    if (layout[0].axis[i].isaxis) {
+      DrawLine (fx, fy, dfx, dfy);
+    }
+    
+    if (layout[0].axis[i].areticks) {
+      range = layout[0].axis[i].max - layout[0].axis[i].min;
+      AxisTickScale (&layout[0].axis[i], &major, &minor);
+
+      first = minor*((int)(layout[0].axis[i].min/minor));
+      if ((range > 0) && (first < layout[0].axis[i].min)) {
+	first += minor;
+      }
+      if ((range < 0) && (first > layout[0].axis[i].min)) {
+	first -= minor;
+      }
+      for (next = first; ((range > 0) && (next <= layout[0].axis[i].max)) || ((range < 0) && (next >= layout[0].axis[i].max));) {
+	IsLabel = FALSE;
+	if ((fabs((int)(next/major) - (next/major)) < 0.5*(minor/major)) || 
+	    (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)) ||
+	    (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)))
+	  IsLabel = layout[0].axis[i].islabel;
+	DrawTick (fx, fy, dfx, dfy, P, layout[0].axis[i].min, layout[0].axis[i].max, next, IsLabel, i);
+	if (range > 0) 
+	  next += minor;
+	else 
+	  next -= minor;
+      }
+    }
+  }
+}
+
+void DrawTick (int fx, int fy, int dfx, int dfy, 
+	       int P, double min, double max, 
+	       double value, int mode, int naxis) {
+  
+  int x, y, dx, dy, pos, dir, fontsize;
+  double size, n;
+  char string[64], *fontname;
+
+  if (mode) { 
+    size = MAX (0.02, 7.0 / P); 
+  } else {
+    size = MAX (0.01, 4.0 / P); 
+  }
+  
+  n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
+  x = fx + (value-min)*dfx/(max - min);
+  y = fy + (value-min)*dfy/(max - min);
+
+  dir = +1;
+  if ((naxis == 0) || (naxis == 1)) dir *= -1;
+  dx = dir*size*dfy*n;	
+  dy = dir*size*dfx*n;
+  
+  DrawLine (x, y, dx, dy);
+
+# ifdef IN_AND_OUT_TICKS
+# define GAP 0.03
+# else
+# define GAP 0.01
+# endif
+
+  if (mode == 1) {
+    fontname = GetRotFont (&fontsize);
+    pos = 0;
+    
+    /* temporarily assume rectilinear axes */
+    if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
+    if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
+
+    if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
+    if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
+
+    x = fx + (value-min)*dfx/(max - min) + dx;
+    y = fy + (value-min)*dfy/(max - min) + dy;
+    if (fabs(value/(max-min)) < 0.001) { value = 0.0; }
+    sprintf (string, "%4g", value);
+    DrawRotText (x, y, string, pos, 0.0);
+  }
+  
+}
+
+
+void AxisTickScale (Axis *axis, double *major, double *minor) {
+
+  double range, lrange, factor, mantis, fmantis, power;
+
+  range = axis[0].max - axis[0].min;
+
+  lrange = log10(MAX(fabs(range), 1e-30));
+  mantis = modf (lrange, &factor);
+  if (mantis < 0.0) {
+    mantis += 1.0;
+    factor -= 1.0;
+  }
+  
+  power = pow(10.0, factor);
+  fmantis = pow(10.0, mantis);
+  *major = 0.5 * power;
+  *minor = 0.1 * power;
+  
+  if ((fmantis >= 1.0) && (fmantis <  1.999)) {
+    *major = 0.5 * power;
+    *minor = 0.1 * power;
+    if (axis[0].areticks == 1) {
+      *major = 1.0 * power;
+      *minor = 0.2 * power;
+    }	  
+  }
+  if ((fmantis >= 1.999) && (fmantis <  3.999)) {
+    *major = 1.0 * power;
+    *minor = 0.2 * power;
+    if (axis[0].areticks == 1) {
+      *major = 2.0 * power;
+      *minor = 0.5 * power;
+    }	  
+  }
+  if ((fmantis >= 3.999) && (fmantis <  5.999)) {
+    *major = 1.0 * power;
+    *minor = 0.5 * power;
+    if (axis[0].areticks == 1) {
+      *major = 2.0 * power;
+      *minor = 0.5 * power;
+    }	  
+  }
+  if ((fmantis >= 5.999) && (fmantis <   7.999)) {
+    *major = 2.0 * power;
+    *minor = 0.5 * power;
+    if (axis[0].areticks == 1) {
+      *major = 2.5 * power;
+      *minor = 0.5 * power;
+    }	  
+  }
+  if ((fmantis >= 7.999) && (fmantis <  10.000)) {
+    *major = 2.5 * power;
+    *minor = 0.5 * power;
+    if (axis[0].areticks == 1) {
+      *major = 5.0 * power;
+      *minor = 1.0 * power;
+    }	  
+  }
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawLabels.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawLabels.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawLabels.c	(revision 10836)
@@ -0,0 +1,57 @@
+# include "Ximage.h"
+  
+void DrawLabels (Layout *layout) {
+  
+  int i, pos, x, y, size;
+  double angle;
+  char *fontname;
+
+  pos = 0;
+  fontname = GetRotFont (&size);
+  XSetForeground (graphic.display, graphic.gc, graphic.fore);
+  DrawRotTextInit (graphic.display, graphic.window, graphic.gc, graphic.fore, graphic.back);
+
+  /* each label is drawn independently */
+  for (i = 0; i < 8; i++) {
+    if (strcmp (layout[0].label[i].text, "")) {
+      angle = 0;
+      switch (i) {
+      case 0: pos = 7; break;
+      case 1: pos = 1; angle = -90; break;
+      case 2: pos = 1; break;
+      case 3: pos = 1; angle =  90; break;
+      case 4: pos = 2; break;
+      case 5: pos = 0; break;
+      case 6: pos = 8; break;
+      case 7: pos = 6; break;
+      }	
+      x = layout[0].label[i].x;
+      y = layout[0].label[i].y;
+      SetRotFont (layout[0].label[i].font, layout[0].label[i].size);
+      DrawRotText (x, y, layout[0].label[i].text, pos, angle);
+    }
+  }
+  SetRotFont (fontname, size);
+}
+
+  /*
+            
+ 4____2___5 
+  |       | 
+  |       | 
+ 1|       |3
+  |       |
+  |       |
+  ---------
+  6   0   7
+          
+ 6____7___8 
+  |       | 
+  |       | 
+ 3|   4   |5
+  |       |
+  |       |
+  ---------
+  0   1   2
+
+  */
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawObjects.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawObjects.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawObjects.c	(revision 10836)
@@ -0,0 +1,619 @@
+# include "Ximage.h"
+# define DrawLine(X1,Y1,X2,Y2) (XDrawLine (graphic.display, graphic.window, graphic.gc, (int)(X1+0.5), (int)(Y1+0.5), (int)(X2+0.5), (int)(Y2+0.5)))
+# define DrawRectangle(X1,Y1,X2,Y2) (XDrawRectangle (graphic.display, graphic.window, graphic.gc, (int)(X1+0.5), (int)(Y1+0.5), (int)(X2+0.5), (int)(Y2+0.5)))
+# define FillRectangle(X1,Y1,X2,Y2) (XFillRectangle (graphic.display, graphic.window, graphic.gc, (int)(X1+0.5), (int)(Y1+0.5), (int)(X2+0.5), (int)(Y2+0.5)))
+# define DrawCircle(X,Y,R) (XDrawArc (graphic.display, graphic.window, graphic.gc, (int)(X-R+0.5), (int)(Y-R+0.5), abs(2*R+0.5), abs(2*R+0.5), 0, 23040))
+
+# define CONNECT 0
+# define HISTOGRAM 1
+# define POINTS 2
+
+void ClipLine (double x0, double y0, double x1, double y1, double X0, double Y0, double X1, double Y1);
+
+/* draw all objects for this Layout */
+int DrawObjects (Layout *layout) {
+  
+  int i;
+  
+  for (i = 0; i < layout[0].Nobjects; i++) {
+    if (DEBUG) fprintf (stderr, "object: %d\n", i);
+    if (DEBUG) fprintf (stderr, "Npts: %d\n", layout[0].objects[i].Npts);
+    DrawObjectN (layout, &layout[0].objects[i]);
+  }    
+  return (TRUE);
+}
+
+/* Draw a specific object in the layout */
+int DrawObjectN (Layout *layout, Gobjects *object) {
+  
+  static char dash[2] = {5,10};
+  static char dot[2] = {3,3};
+  int lweight;
+  
+  lweight = MAX (0, MIN (10, object[0].lweight));
+
+  /* set line type */
+  switch (object[0].ltype) {
+  case 0:
+    XSetLineAttributes (graphic.display, graphic.gc, lweight, LineSolid, CapNotLast, JoinMiter);
+    break;
+  case 1:
+    XSetDashes (graphic.display, graphic.gc, 100, dash, 2);
+    XSetLineAttributes (graphic.display, graphic.gc, lweight, LineOnOffDash, CapNotLast, JoinMiter);
+    break;
+  case 2:
+    XSetDashes (graphic.display, graphic.gc, 10, dot, 2);
+    XSetLineAttributes (graphic.display, graphic.gc, lweight, LineOnOffDash, CapNotLast, JoinMiter);
+    break;
+  default:
+    XSetLineAttributes (graphic.display, graphic.gc, lweight, LineSolid, CapNotLast, JoinMiter);
+    break;
+  }
+
+  XSetForeground (graphic.display, graphic.gc, graphic.color[object[0].color]);
+
+  switch (object[0].style) {
+  case CONNECT: 
+    DrawConnect (layout, object);
+    break;
+  case HISTOGRAM:
+    DrawHistogram (layout, object);
+    break;
+  case POINTS:
+    DrawPoints (layout, object);
+    break;
+  }
+    
+  if (object[0].etype & 0x01) {
+    DrawYErrors (layout, object);
+  }
+  if (object[0].etype & 0x02) {
+    DrawXErrors (layout, object);
+  }
+
+  XSetLineAttributes (graphic.display, graphic.gc, 0, LineSolid, CapNotLast, JoinMiter);
+  XSetForeground (graphic.display, graphic.gc, graphic.fore);
+  return (TRUE);
+}
+
+/******/
+void DrawConnect (Layout *layout, Gobjects *object) {
+  
+  int i;
+  float *x, *y;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1;
+  double X0, X1, Y0, Y1;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  X0 = layout[0].axis[0].fx;
+  X1 = layout[0].axis[0].fx + layout[0].axis[0].dfx;
+  Y0 = layout[0].axis[1].fy;
+  Y1 = layout[0].axis[1].fy + layout[0].axis[1].dfy;
+
+  x = object[0].x; y = object[0].y;
+  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
+  if (i >= object[0].Npts) return;
+  sx0 = x[i]*mxi + y[i]*mxj + bx;
+  sy0 = x[i]*myi + y[i]*myj + by;
+
+  for (i++; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]))) continue;
+    sx1 = x[i]*mxi + y[i]*mxj + bx;
+    sy1 = x[i]*myi + y[i]*myj + by;
+    
+    ClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
+    /* DrawLine (sx0, sy0, sx1, sy1); */
+    sx0 = sx1; sy0 = sy1;
+  }
+  
+}
+
+void ClipLine (double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0) {
+
+  /* skip line segement if both points are beyond box */
+  if ((x0 <= X0) && (x1 <= X0)) return;
+  if ((x0 >= X1) && (x1 >= X1)) return;
+  if ((y0 <= Y0) && (y1 <= Y0)) return;
+  if ((y0 >= Y1) && (y1 >= Y1)) return;
+
+  /* replace x0,y0 if outside box */
+  if ((x0 < X0) && (x1 >= X0)) {
+    y0 = y0 + (X0 - x0)*(y1 - y0)/(x1 - x0);
+    x0 = X0;
+  }
+  if ((x0 > X1) && (x1 <= X1)) {
+    y0 = y0 + (X1 - x0)*(y1 - y0)/(x1 - x0);
+    x0 = X1;
+  }
+  if ((y0 < Y0) && (y1 >= Y0)) {
+    x0 = x0 + (Y0 - y0)*(x1 - x0)/(y1 - y0);
+    y0 = Y0;
+  }
+  if ((y0 > Y1) && (y1 <= Y1)) {
+    x0 = x0 + (Y1 - y0)*(x1 - x0)/(y1 - y0);
+    y0 = Y1;
+  }
+
+  /* skip line segement if both points are beyond box */
+  if ((x0 <= X0) && (x1 <= X0)) return;
+  if ((x0 >= X1) && (x1 >= X1)) return;
+  if ((y0 <= Y0) && (y1 <= Y0)) return;
+  if ((y0 >= Y1) && (y1 >= Y1)) return;
+
+  /* replace x1,y1 if outside box */
+  if ((x1 < X0) && (x0 >= X0)) {
+    y1 = y0 + (X0 - x0)*(y1 - y0)/(x1 - x0);
+    x1 = X0;
+  }
+  if ((x1 > X1) && (x0 <= X1)) {
+    y1 = y0 + (X1 - x0)*(y1 - y0)/(x1 - x0);
+    x1 = X1;
+  }
+  if ((y1 < Y0) && (y0 >= Y0)) {
+    x1 = x0 + (Y0 - y0)*(x1 - x0)/(y1 - y0);
+    y1 = Y0;
+  }
+  if ((y1 > Y1) && (y0 <= Y1)) {
+    x1 = x0 + (Y1 - y0)*(x1 - x0)/(y1 - y0);
+    y1 = Y1;
+  }
+  DrawLine (x0, y0, x1, y1);
+}
+  
+
+/******/
+void DrawHistogram (Layout *layout, Gobjects *object) {
+
+  int i;
+  float *x, *y;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sxa;
+  double X0, X1, Y0, Y1;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  X0 = layout[0].axis[0].fx;
+  X1 = layout[0].axis[0].fx + layout[0].axis[0].dfx;
+  Y0 = layout[0].axis[1].fy;
+  Y1 = layout[0].axis[1].fy + layout[0].axis[1].dfy;
+
+  /* find the first valid datapoint */
+  x = object[0].x; y = object[0].y;
+  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
+  if (i >= object[0].Npts) return;
+  sx0 = x[i]*mxi + y[i]*mxj + bx;
+  sy0 = x[i]*myi + y[i]*myj + by;
+  sx0 = MIN (MAX (sx0, X0), X1);
+  sy0 = MAX (MIN (sy0, Y0), Y1);
+  
+  /* continue with rest of points */
+  for (i++; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]))) continue;
+    sx1 = x[i]*mxi + y[i]*mxj + bx;
+    sy1 = x[i]*myi + y[i]*myj + by;
+    sx1 = MIN (MAX (sx1, X0), X1);
+    sy1 = MAX (MIN (sy1, Y0), Y1);
+    sxa = 0.5*(sx0 + sx1);
+    DrawLine (sx0, sy0, sxa, sy0);
+    DrawLine (sxa, sy0, sxa, sy1);
+    DrawLine (sxa, sy1, sx1, sy1);
+    sx0 = sx1; sy0 = sy1;
+  }
+}
+
+/******/
+void DrawPoints (Layout *layout, Gobjects *object) {
+
+  int i;
+  float *x, *y, *z;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx, sy, d, sx1, sy1, sx2, sy2;
+  
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  /**** points are scaled by object.z ***/
+  if (object[0].size < 0) {
+    d = 0.5 * (graphic.dx + graphic.dy) * 0.01;
+    x = object[0].x; y = object[0].y; z = object[0].z;
+    if (object[0].ptype == 0) {	/* filled box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillRectangle (sx - d*z[i], sy - d*z[i], 2*d*z[i], 2*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 1) {	/* open box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawRectangle (sx - d*z[i], sy - d*z[i], 2*d*z[i], 2*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 2) { /* cross */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d*z[i], sy, sx + d*z[i] + 1, sy);
+	    DrawLine (sx, sy - d*z[i], sx, sy + d*z[i] + 1);
+	  }
+      }
+    }
+    if (object[0].ptype == 3) {	/* x */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx + d*z[i] + 1, sy - d*z[i] - 1, sx - d*z[i], sy + d*z[i]);
+	    DrawLine (sx - d*z[i], sy - d*z[i], sx + d*z[i] + 1, sy + d*z[i] + 1);
+	  }
+      }
+    }
+    if (object[0].ptype == 4) {	/* filled triangle */
+      XPoint points[4];
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    points[0].x = sx - d*z[i];  points[0].y = sy + 0.58*d*z[i];  
+	    points[1].x = sx + d*z[i];  points[1].y = sy + 0.58*d*z[i];  
+	    points[2].x = sx;           points[2].y = sy - 1.15*d*z[i];  
+	    points[3].x = sx - d*z[i];  points[3].y = sy + 0.58*d*z[i];  
+	    XFillPolygon (graphic.display, graphic.window, graphic.gc, points, 4, Convex, CoordModeOrigin);
+	  }
+      }
+    }
+    if (object[0].ptype == 5) {	/* open triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d*z[i], sy + 0.58*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx + d*z[i], sy + 0.58*d*z[i], sx,          sy - 1.15*d*z[i]);
+	    DrawLine (sx,          sy - 1.15*d*z[i], sx - d*z[i], sy + 0.58*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 6) {	/* Y */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx, sy, sx - d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx, sy, sx + d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx, sy, sx,          sy - 1.15*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 7) {	/* 0 */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawCircle (sx, sy, d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 100) {	/* connect a pair of points */
+      for (i = 0; i + 1 < object[0].Npts; i+=2) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx1 = x[i]*mxi + y[i]*mxj + bx;
+	sy1 = x[i]*myi + y[i]*myj + by;
+	if (!(finite(x[i+1]) && finite(y[i+1]))) continue;
+	sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
+	sy2 = x[i+1]*myi + y[i+1]*myj + by;
+	DrawLine (sx1, sy1, sx2, sy2);
+      }
+    }
+  } 
+  /**** points are not scaled by object.z ***/
+  else {
+    d = object[0].size * 0.5 * (graphic.dx + graphic.dy) * 0.003;
+    x = object[0].x; y = object[0].y;
+    if (object[0].ptype == 0) {	/* filled box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillRectangle (sx - d, sy - d, 2*d, 2*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 1) {		/* open box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+   	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawRectangle (sx - d, sy - d, 2*d, 2*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 2) { /* cross */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d, sy, sx + d + 1, sy);
+	    DrawLine (sx, sy - d, sx, sy + d + 1);
+	  }
+      }
+    }
+    if (object[0].ptype == 3) {		/* x */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    /* XDrawLine is a little funny, this is needed to fix endpost errors */
+	    DrawLine (sx + d + 1, sy - d - 1, sx - d, sy + d);
+	    DrawLine (sx - d, sy - d, sx + d + 1, sy + d + 1);
+	  }
+      }
+    }
+    if (object[0].ptype == 4) {	/* filled triangle */
+      XPoint points[4];
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    points[0].x = sx - d;  points[0].y = sy + 0.58*d;  
+	    points[1].x = sx + d;  points[1].y = sy + 0.58*d;  
+	    points[2].x = sx;      points[2].y = sy - 1.15*d;  
+	    points[3].x = sx - d;  points[3].y = sy + 0.58*d;  
+	    XFillPolygon (graphic.display, graphic.window, graphic.gc, points, 4, Convex, CoordModeOrigin);
+	  }
+      }
+    }
+    if (object[0].ptype == 5) {	/* open triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d, sy + 0.58*d, sx + d, sy + 0.58*d);
+	    DrawLine (sx + d, sy + 0.58*d, sx,     sy - 1.15*d);
+	    DrawLine (sx,     sy - 1.15*d, sx - d, sy + 0.58*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 6) {	/* Y */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx, sy, sx - d, sy + 0.58*d);
+	    DrawLine (sx, sy, sx + d, sy + 0.58*d);
+	    DrawLine (sx, sy, sx,     sy - 1.15*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 7) {	/* 0 */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawCircle (sx, sy, d);
+	  }
+      }
+    }
+    if (object[0].ptype == 100) {	
+      for (i = 0; i + 1 < object[0].Npts; i+=2) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx1 = x[i]*mxi + y[i]*mxj + bx;
+	sy1 = x[i]*myi + y[i]*myj + by;
+	sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
+	sy2 = x[i+1]*myi + y[i+1]*myj + by;
+	DrawLine (sx1, sy1, sx2, sy2);
+      }
+    }
+  }
+}
+    
+/******/
+void DrawXErrors (Layout *layout, Gobjects *object) {
+  
+  int i, bar;
+  float *x, *y, *dxm, *dxp;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sz, sx10, sx11;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  x = object[0].x; y = object[0].y; dxp = object[0].dxp; dxm = object[0].dxm; 
+  bar = object[0].ebar; sz = object[0].size*layout[0].axis[1].dfy*0.03;
+  
+  for (i = 0; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]) && finite(dxp[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = (x[i] + dxp[i])*mxi + y[i]*mxj + bx;
+    sy1 = (x[i] + dxp[i])*myi + y[i]*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy))) 
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sy1 - sz;
+	  sx11 = sy1 + sz;
+	  DrawLine (sx1, sx10, sx1, sx11);
+	}
+      }
+    if (!(finite(x[i]) && finite(y[i]) && finite(dxm[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = (x[i] - dxm[i])*mxi + y[i]*mxj + bx;
+    sy1 = (x[i] - dxm[i])*myi + y[i]*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sy1 - sz;
+	  sx11 = sy1 + sz;
+	  DrawLine (sx1, sx10, sx1, sx11);
+	}
+      }
+  }
+}
+    
+/******/
+void DrawYErrors (Layout *layout, Gobjects *object) {
+
+  int i, bar;
+  float *x, *y, *dym, *dyp;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sz, sx10, sx11;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  x = object[0].x; y = object[0].y; dyp = object[0].dyp; dym = object[0].dym; 
+  bar = object[0].ebar; sz = object[0].size*layout[0].axis[0].dfx*0.03;
+  
+  for (i = 0; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]) && finite(dyp[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = sx0 + dyp[i]*mxj;
+    sy1 = sy0 + dyp[i]*myj;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sx1 - sz;
+	  sx11 = sx1 + sz;
+	  DrawLine (sx10, sy1, sx11, sy1);
+	}
+      }
+    if (!(finite(x[i]) && finite(y[i]) && finite(dym[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = x[i]*mxi + (y[i] - dym[i])*mxj + bx;
+    sy1 = x[i]*myi + (y[i] - dym[i])*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sx1 - sz;
+	  sx11 = sx1 + sz;
+	  DrawLine (sx10, sy1, sx11, sy1);
+	}
+      }
+  }
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawPtext.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawPtext.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawPtext.c	(revision 10836)
@@ -0,0 +1,36 @@
+# include "Ximage.h"
+  
+void DrawPtext (Layout *layout) {
+  
+  int i, x, y, size;
+  double angle;
+  char *fontname;
+
+  fontname = GetRotFont (&size);
+  XSetForeground (graphic.display, graphic.gc, graphic.fore);
+  DrawRotTextInit (graphic.display, graphic.window, graphic.gc, graphic.fore, graphic.back);
+
+  for (i = 0; i < layout[0].Nptext; i++) {
+    if (strcmp (layout[0].ptext[i].text, "")) {
+      angle = layout[0].ptext[i].angle;
+      x = layout[0].ptext[i].x;
+      y = layout[0].ptext[i].y;
+      SetRotFont (layout[0].ptext[i].font, layout[0].ptext[i].size);
+      DrawRotText (x, y, layout[0].ptext[i].text, 5, angle);
+    }
+  }
+  SetRotFont (fontname, size);
+}
+
+  /* pos values
+            
+ 4____2___5 
+  |       | 
+  |       | 
+ 1|   8   |3
+  |       |
+  |       |
+  ---------
+  6   0   7
+
+  */
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawText.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawText.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/DrawText.c	(revision 10836)
@@ -0,0 +1,39 @@
+# include "Ximage.h"
+  
+/* Draw text centered at x,y */
+
+void DrawText (int x, int y, char *string, int pos) {
+
+  char *c;
+  int dx, dy;
+
+  for (c = string; (*c == ' ') || (*c == '\t'); c++);
+  if (*c == 0) return;
+  
+  dx  = XTextWidth (graphic.font, c, strlen(c));
+  dy  = graphic.font[0].ascent;
+  switch (pos) {
+  case 0: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx,   y + dy,   c, strlen(c)); break;
+  case 1: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx/2, y + dy,   c, strlen(c)); break;
+  case 2: XDrawString (graphic.display, graphic.window, graphic.gc, x,        y + dy,   c, strlen(c)); break;
+  case 3: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx,   y + dy/2, c, strlen(c)); break;
+  case 4: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx/2, y + dy/2, c, strlen(c)); break;
+  case 5: XDrawString (graphic.display, graphic.window, graphic.gc, x,        y + dy/2, c, strlen(c)); break;
+  case 6: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx,   y,        c, strlen(c)); break;
+  case 7: XDrawString (graphic.display, graphic.window, graphic.gc, x - dx/2, y,        c, strlen(c)); break;
+  case 8: XDrawString (graphic.display, graphic.window, graphic.gc, x,        y,        c, strlen(c)); break;
+  }
+}
+
+/*
+            
+ 6____7___8
+  |       | 
+  |       | 
+ 3|   4   |5
+  |       |
+  |       |
+  ---------
+ 0    1   2
+
+*/
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/ErasePlot.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/ErasePlot.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/ErasePlot.c	(revision 10836)
@@ -0,0 +1,60 @@
+# include "Ximage.h"
+# define TESTFREE(a) { if ((a) != (float *) NULL) free (a);}
+
+int ErasePlot (int ClearSection) {
+  
+  int i, j;
+
+  for (j = 0; j < Nsection; j++) {
+
+    /* free data objects, then re-alloc those needed */
+    for (i = 0; i < section[j].Nobjects; i++) {
+      TESTFREE (section[j].objects[i].x);
+      TESTFREE (section[j].objects[i].y);
+      TESTFREE (section[j].objects[i].z);
+      TESTFREE (section[j].objects[i].dxm);
+      TESTFREE (section[j].objects[i].dxp);
+      TESTFREE (section[j].objects[i].dym);
+      TESTFREE (section[j].objects[i].dyp);
+    }
+    
+    /* reset axes and labels */
+    for (i = 0; i < 4; i++) {
+      section[j].axis[i].isaxis = FALSE;
+      section[j].axis[i].islabel = FALSE;
+      section[j].axis[i].areticks = FALSE;
+    }
+    for (i = 0; i < 8; i++) {
+      strcpy (section[j].label[i].text, "");
+    }
+    
+    /* free objects and text entries, or re-zero */
+    if (ClearSection && (j != 0)) {
+      free (section[j].objects);
+      free (section[j].ptext);
+    } else {
+      section[j].Nobjects = 0;
+      REALLOCATE (section[j].objects, Gobjects, 1);
+      section[j].Nptext = 0;
+      REALLOCATE (section[j].ptext, Label, 1);
+    }
+  }
+
+  if (ClearSection) {
+    Nsection = 1;
+    TheSection = 0;
+    REALLOCATE (section, Layout, Nsection);
+  }
+
+  if (USE_XWINDOW) XClearWindow (graphic.display, graphic.window);
+  Refresh (1);
+
+  return (TRUE);
+  
+}
+
+
+/** note that 'section' is the global variable
+    of type 'Layout' which carries data and info 
+    about each graph section 
+**/
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadBox.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadBox.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadBox.c	(revision 10836)
@@ -0,0 +1,79 @@
+# include "Ximage.h"
+
+int LoadBox () {
+  
+  int i, status;
+  char Axis[16], Labels[16], Ticks[16];
+  Layout *layout;
+  
+  layout = &section[TheSection];
+
+  KiiScanMessage (sock, "%lf %lf %lf %lf", 
+		  &layout[0].axis[0].min, &layout[0].axis[0].max, 
+		  &layout[0].axis[1].min, &layout[0].axis[1].max);
+
+  layout[0].axis[3].min = layout[0].axis[1].min;
+  layout[0].axis[3].max = layout[0].axis[1].max;
+  layout[0].axis[2].min = layout[0].axis[0].min;
+  layout[0].axis[2].max = layout[0].axis[0].max;
+  
+  KiiScanMessage (sock, "%s %s %s", Axis, Labels, Ticks);
+
+  for (i = 0; i < 4; i++) {
+    switch (Axis[i]) {
+    case '0':
+      layout[0].axis[i].isaxis = FALSE;
+      break;
+    case '1':
+      layout[0].axis[i].isaxis = TRUE;
+      break;
+    case '2':
+      layout[0].axis[i].isaxis = TRUE;
+      break;
+    }
+    switch (Ticks[i]) {
+    case '0':
+      layout[0].axis[i].areticks = FALSE;
+      break;
+    case '1':
+      layout[0].axis[i].areticks = TRUE;
+      break;
+    case '2':
+      layout[0].axis[i].areticks = 2;
+      break;
+    }
+    switch (Labels[i]) {
+    case '0':
+      layout[0].axis[i].islabel = FALSE;
+      break;
+    case '1':
+      layout[0].axis[i].islabel = TRUE;
+      break;
+    case '2':
+      layout[0].axis[i].islabel = (i < 2);
+      break;
+    }
+  }
+
+  if (USE_XWINDOW) DrawFrame (layout);
+  status = TRUE;
+  if (status) {
+    for (i = 0; i < Nsection; i++) {
+      PositionPicture (&section[i]);
+    }
+    if (USE_XWINDOW) XClearWindow (graphic.display, graphic.window);
+    Refresh (1);
+  } else {
+    FlushDisplay ();
+  } 
+
+  return (TRUE);
+  
+}
+
+/*
+  layout[0].X = 0;
+  layout[0].Y = 0;
+  layout[0].expand = 1;
+*/
+  
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadLabels.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadLabels.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadLabels.c	(revision 10836)
@@ -0,0 +1,41 @@
+# include "Ximage.h"
+
+int LoadLabels () {
+  
+  char *c, *label;
+  int mode, size, Nbytes;
+  Layout *layout;
+  
+  layout = &section[TheSection];
+  
+  fcntl (sock, F_SETFL, !O_NONBLOCK);  
+  
+  KiiScanMessage (sock, "%d", &mode);
+  label = KiiRecvData (sock);
+
+  bzero (layout[0].label[mode].text, LABEL_MAXLEN);
+
+  Nbytes = MIN (strlen(label), LABEL_MAXLEN - 1);
+  strncpy (layout[0].label[mode].text, label, Nbytes);
+  label[Nbytes] = 0;
+
+  fcntl (sock, F_SETFL, O_NONBLOCK);  
+  
+  c = GetRotFont (&size);
+  layout[0].label[mode].size = size;
+  strcpy (layout[0].label[mode].font, c);
+  DrawLabels (layout);
+  
+  FlushDisplay ();
+  
+  return (TRUE);
+  
+}
+
+/*
+  layout[0].X = 0;
+  layout[0].Y = 0;
+  layout[0].expand = 1;
+  */
+
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadObject.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadObject.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadObject.c	(revision 10836)
@@ -0,0 +1,185 @@
+# include "Ximage.h"
+# include <errno.h>
+
+int LoadObject () {
+  
+  int N;
+  Layout *layout;
+
+  layout = &section[TheSection];
+  
+  fcntl (sock, F_SETFL, !O_NONBLOCK);  
+  
+  N = layout[0].Nobjects;
+  layout[0].Nobjects ++;
+  REALLOCATE (layout[0].objects, Gobjects, layout[0].Nobjects);
+  layout[0].objects[N].x = layout[0].objects[N].y = layout[0].objects[N].z = (float *) NULL;
+  layout[0].objects[N].dxm = layout[0].objects[N].dxp = (float *) NULL;
+  layout[0].objects[N].dym = layout[0].objects[N].dyp = (float *) NULL;
+  
+  KiiScanMessage (sock, "%d %d %d %d %d %d %d %lf %lf",
+		  &layout[0].objects[N].Npts, &layout[0].objects[N].style, 
+		  &layout[0].objects[N].ptype, &layout[0].objects[N].ltype, 
+		  &layout[0].objects[N].etype, &layout[0].objects[N].ebar, 
+		  &layout[0].objects[N].color, 
+		  &layout[0].objects[N].lweight, &layout[0].objects[N].size);
+  
+  if (DEBUG) fprintf (stderr, "%d %d %d %d %d %d %d %lf %lf\n",
+		      layout[0].objects[N].Npts, layout[0].objects[N].style, 
+		      layout[0].objects[N].ptype, layout[0].objects[N].ltype, 
+		      layout[0].objects[N].etype, layout[0].objects[N].ebar, 
+		      layout[0].objects[N].color, 
+		      layout[0].objects[N].lweight, layout[0].objects[N].size);
+  
+  /* force valid ranges */
+  if ((layout[0].objects[N].color > KapaColormapSize()) || (layout[0].objects[N].color < 0))
+    layout[0].objects[N].color = 0;
+
+  KiiScanMessage (sock, "%lf %lf %lf %lf",
+		  &layout[0].objects[N].x0, &layout[0].objects[N].x1, 
+		  &layout[0].objects[N].y0, &layout[0].objects[N].y1);
+  
+  fcntl (sock, F_SETFL, O_NONBLOCK);  
+  
+  if (!LoadVectorData (layout, N, "x")) {
+    FreeObjectData (&layout[0].objects[N]);
+    layout[0].Nobjects --;
+    REALLOCATE (layout[0].objects, Gobjects, MAX (1, layout[0].Nobjects));
+  }
+    
+  if (!LoadVectorData (layout, N, "y")) {
+    FreeObjectData (&layout[0].objects[N]);
+    layout[0].Nobjects --;
+    REALLOCATE (layout[0].objects, Gobjects, MAX (1, layout[0].Nobjects));
+  }
+  if (layout[0].objects[N].size < 0.0) {
+    if (!LoadVectorData (layout, N, "z")) {
+      FreeObjectData (&layout[0].objects[N]);
+      layout[0].Nobjects --;
+      REALLOCATE (layout[0].objects, Gobjects, MAX (1, layout[0].Nobjects));
+    }
+  }
+  if (layout[0].objects[N].etype & 0x01) {
+    if (!LoadVectorData (layout, N, "dym")) {
+      FreeObjectData (&layout[0].objects[N]);
+      layout[0].Nobjects --;
+      REALLOCATE (layout[0].objects, Gobjects, MAX (1, layout[0].Nobjects));
+    }
+    if (!LoadVectorData (layout, N, "dyp")) {
+      FreeObjectData (&layout[0].objects[N]);
+      layout[0].Nobjects --;
+      REALLOCATE (layout[0].objects, Gobjects, MAX (1, layout[0].Nobjects));
+    }
+  }
+  if (layout[0].objects[N].etype & 0x02) {
+    if (!LoadVectorData (layout, N, "dxm")) {
+      FreeObjectData (&layout[0].objects[N]);
+      layout[0].Nobjects --;
+      REALLOCATE (layout[0].objects, Gobjects, MAX (1, layout[0].Nobjects));
+    }
+    if (!LoadVectorData (layout, N, "dxp")) {
+      FreeObjectData (&layout[0].objects[N]);
+      layout[0].Nobjects --;
+      REALLOCATE (layout[0].objects, Gobjects, MAX (1, layout[0].Nobjects));
+    }
+  }
+
+  if (DEBUG) fprintf (stderr, "loaded %d objects, using object %d\n", layout[0].objects[N].Npts, N);
+
+  if (USE_XWINDOW) DrawObjectN (layout, &layout[0].objects[layout[0].Nobjects-1]);
+  FlushDisplay ();
+
+  return (TRUE);
+  
+}
+
+/* load data for the named component */
+int LoadVectorData (Layout *layout, int N, char *type) {
+  
+  int Npts, Ninpts, status, Ntry;
+  int bytes_left;
+  char *buff;
+
+  buff = NULL;
+  Npts = layout[0].objects[N].Npts;
+  status = 1;
+  if (!strcmp (type, "x")) {
+    ALLOCATE (layout[0].objects[N].x, float, MAX (1, Npts));
+    buff = (char *) layout[0].objects[N].x;
+  }
+  if (!strcmp (type, "y")) {
+    ALLOCATE (layout[0].objects[N].y, float, MAX (1, Npts));
+    buff = (char *) layout[0].objects[N].y;
+  }
+  if (!strcmp (type, "z")) {
+    ALLOCATE (layout[0].objects[N].z, float, MAX (1, Npts));
+    buff = (char *) layout[0].objects[N].z;
+  }
+  if (!strcmp (type, "dxm")) {
+    ALLOCATE (layout[0].objects[N].dxm, float, MAX (1, Npts));
+    buff = (char *) layout[0].objects[N].dxm;
+  }
+  if (!strcmp (type, "dxp")) {
+    ALLOCATE (layout[0].objects[N].dxp, float, MAX (1, Npts));
+    buff = (char *) layout[0].objects[N].dxp;
+  }
+  if (!strcmp (type, "dym")) {
+    ALLOCATE (layout[0].objects[N].dym, float, MAX (1, Npts));
+    buff = (char *) layout[0].objects[N].dym;
+  }
+  if (!strcmp (type, "dyp")) {
+    ALLOCATE (layout[0].objects[N].dyp, float, MAX (1, Npts));
+    buff = (char *) layout[0].objects[N].dyp;
+  }
+
+  bytes_left = Npts*sizeof (float);
+
+  Ntry = 0;
+  if (DEBUG) fprintf (stderr, "starting vector load\n");
+  Ninpts = 0;
+  while (bytes_left > 0) {
+    status = read (sock, buff, bytes_left);
+    if (DEBUG) fprintf (stderr, "status: %d, %d\n", status, bytes_left);
+    if (status == 0) {  /* No more pipe */
+      fprintf (stderr, "error: pipe closed\n");
+      return (FALSE);
+    }
+    if (status != -1) { /* pipe has data */
+      Ninpts += status;
+      bytes_left -= status;
+      buff = (char *)(buff + status);
+      Ntry = 0;
+      continue;
+    }
+    if (errno == EAGAIN) {
+      Ntry ++;
+      if (Ntry > 100) {
+	fprintf (stderr, "kapa communication error\n");
+	return (FALSE);
+      }
+      usleep (10000);
+      continue;
+    }
+    perror ("kapa load");
+  }
+  if (Ninpts != Npts*sizeof(float)) {  
+    fprintf (stderr, "error: expected %d bytes, but got only %d\n", Ninpts, (unsigned int)(Npts*sizeof(float)));
+    return (FALSE);
+  }
+  if (DEBUG) fprintf (stderr, "done vector load\n");
+  return (TRUE);
+
+}
+
+void FreeObjectData (Gobjects *object) {
+
+  if (object[0].x != (float *) NULL) free (object[0].x);
+  if (object[0].y != (float *) NULL) free (object[0].y);
+  if (object[0].z != (float *) NULL) free (object[0].z);
+
+  if (object[0].dxm != (float *) NULL) free (object[0].dxm);
+  if (object[0].dxp != (float *) NULL) free (object[0].dxp);
+  if (object[0].dym != (float *) NULL) free (object[0].dym);
+  if (object[0].dyp != (float *) NULL) free (object[0].dyp);
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadPtext.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadPtext.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/LoadPtext.c	(revision 10836)
@@ -0,0 +1,47 @@
+# include "Ximage.h"
+
+int LoadPtext () {
+  
+  char *string;
+  int N, size;
+  double tX, tY, tT, L;
+  Layout *layout;
+  
+  layout = &section[TheSection];
+  
+  fcntl (sock, F_SETFL, !O_NONBLOCK);  
+  
+  layout[0].Nptext = MAX (layout[0].Nptext, 0);
+  N = layout[0].Nptext;
+  layout[0].Nptext++;
+  REALLOCATE (layout[0].ptext, Label, layout[0].Nptext);
+
+  KiiScanMessage (sock, "%lf %lf %lf", &tX, &tY, &tT);
+
+  L = layout[0].axis[0].dfx;
+  layout[0].ptext[N].x = L * (tX - layout[0].axis[0].min) / (layout[0].axis[0].max - layout[0].axis[0].min) + layout[0].axis[0].fx;
+
+  L = layout[0].axis[1].dfy;
+  layout[0].ptext[N].y = L * (tY - layout[0].axis[1].min) / (layout[0].axis[1].max - layout[0].axis[1].min) + layout[0].axis[1].fy;
+
+  layout[0].ptext[N].angle = tT;
+
+  bzero (layout[0].ptext[N].text, LABEL_MAXLEN);
+
+  string = KiiRecvData (sock);
+  strcpy (layout[0].ptext[N].text, string);
+  free (string);
+
+  fcntl (sock, F_SETFL, O_NONBLOCK);  
+  
+  string = GetRotFont (&size);
+  layout[0].ptext[N].size = size;
+  strcpy (layout[0].ptext[N].font, string);
+
+  DrawPtext (layout);
+  
+  FlushDisplay ();
+  
+  return (TRUE);
+  
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/PNGit.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/PNGit.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/PNGit.c	(revision 10836)
@@ -0,0 +1,74 @@
+# include "Ximage.h"
+
+int PNGit () {
+
+  FILE *f;
+  png_structp png_ptr;
+  png_infop info_ptr;
+  png_color *palette;
+  int Npalette;
+  char filename[1024];
+  int Nbytes, status;
+
+  bDrawBuffer *buffer;
+
+  /* expect a line telling the number of bytes and a filename */
+  status = read (sock, filename, 16);
+  filename[16] = 0;
+  sscanf (filename, "%*s %d", &Nbytes);
+  status = read (sock, filename, Nbytes);
+  filename[status] = 0; /* make the string easy to parse */
+
+  f = fopen (filename, "w");
+  if (f == (FILE *) NULL) {
+    fprintf (stderr, "can't open output file %s\n", "Xgraph.png");
+    return (TRUE);  /* true because otherwise it quits kapa! */
+  }
+
+  png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, (png_voidp) NULL, (png_voidp) NULL, (png_voidp) NULL);
+  if (!png_ptr) {
+    fprintf (stderr, "can't get png structure\n");
+    fclose (f);
+    return (TRUE);
+  }
+
+  info_ptr = png_create_info_struct (png_ptr);
+  if (!info_ptr) {
+    fprintf (stderr, "can't get png info structure\n");
+    png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
+    fclose (f);
+    return (TRUE);
+  }
+
+  if (setjmp (png_ptr[0].jmpbuf)) {
+    fprintf (stderr, "can't get png return\n");
+    png_destroy_write_struct (&png_ptr, &info_ptr);
+    fclose (f);
+    return (TRUE);
+  }
+
+  png_init_io (png_ptr, f);
+
+  /* see docs for write-row-callback to provide progress info */
+
+  png_set_IHDR (png_ptr, info_ptr, graphic.dx, graphic.dy, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); 
+
+  /* png_set_IHDR (png_ptr, info_ptr, graphic.dx, graphic.dy, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); */
+
+  palette = KapaPNGPalette (&Npalette);
+  png_set_PLTE (png_ptr, info_ptr, palette, Npalette); 
+ 
+  png_write_info (png_ptr, info_ptr);
+
+  buffer = bDrawIt ();
+
+  png_write_image (png_ptr, buffer[0].pixels);
+  png_write_end (png_ptr, info_ptr);
+  png_destroy_write_struct (&png_ptr, &info_ptr);
+  
+  bDrawBufferFree (buffer);
+  free (palette);
+  fclose (f);
+  return (TRUE);
+
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/PPMit.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/PPMit.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/PPMit.c	(revision 10836)
@@ -0,0 +1,52 @@
+# include "Ximage.h"
+
+int PPMit () {
+
+  FILE *f;
+  char *line, filename[1024];
+  int Nbytes, status, dx, dy, i, j, Npalette, color;
+  png_color *palette;
+
+  bDrawBuffer *buffer;
+
+  /* expect a line telling the number of bytes and a filename */
+  status = read (sock, filename, 16);
+  filename[16] = 0;
+  sscanf (filename, "%*s %d", &Nbytes);
+  status = read (sock, filename, Nbytes);
+  filename[status] = 0; /* make the string easy to parse */
+
+  f = fopen (filename, "w");
+  if (f == (FILE *) NULL) {
+    fprintf (stderr, "can't open output file %s\n", filename);
+    return (TRUE);  /* true because otherwise it quits kapa! */
+  }
+  
+  palette = KapaPNGPalette (&Npalette);
+
+  dx = graphic.dx;
+  dy = graphic.dy;
+  
+  fprintf (f, "P6\n");
+  fprintf (f, "%d %d\n", dx, dy);
+  fprintf (f, "255\n");
+
+  buffer = bDrawIt ();
+
+  ALLOCATE (line, char, 3*dx);
+
+  for (i = 0; i < dy; i++) {
+    for (j = 0; j < dx; j++) {
+      color = buffer[0].pixels[i][j];
+      line[3*j + 0] = palette[color].red;
+      line[3*j + 1] = palette[color].green;
+      line[3*j + 2] = palette[color].blue;
+    }
+    fwrite (line, 3, dx, f);
+  }
+  fclose (f);
+  
+  bDrawBufferFree (buffer);
+  return (TRUE);
+
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSFrame.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSFrame.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSFrame.c	(revision 10836)
@@ -0,0 +1,99 @@
+# include "Ximage.h"
+# define DrawLine(X1,Y1,DX,DY) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f L\n", X1, Y1, X1+DX, Y1+DY))
+
+int PSFrame (Layout *layout, FILE *f) {
+  
+  int i, P, IsLabel, fontsize;
+  double fx, fy, dfx, dfy, range, major, minor, first, next;
+  char *fontname;
+
+  /* each axis is drawn independently */
+  fontname = GetRotFont (&fontsize);
+  fprintf (f, "1 setlinewidth\n");
+  for (i = 0; i < 4; i++) {
+    fx = layout[0].axis[i].fx;
+    fy = graphic.dy - layout[0].axis[i].fy;
+    dfx = layout[0].axis[i].dfx;
+    dfy = -layout[0].axis[i].dfy;
+    P = hypot ((double)layout[0].axis[(i+1)%2].dfx, (double)layout[0].axis[(i+1)%2].dfy);
+
+    if (layout[0].axis[i].isaxis) { DrawLine (fx, fy, dfx, dfy); }
+    
+    if (layout[0].axis[i].areticks) {
+      range = layout[0].axis[i].max - layout[0].axis[i].min;
+      AxisTickScale (&layout[0].axis[i], &major, &minor);
+
+      first = minor*((int)(layout[0].axis[i].min/minor));
+      if ((range > 0) && (first < layout[0].axis[i].min)) {
+	first += minor;
+      }
+      if ((range < 0) && (first > layout[0].axis[i].min)) {
+	first -= minor;
+      }
+      for (next = first; ((range > 0) && (next <= layout[0].axis[i].max)) || ((range < 0) && (next >= layout[0].axis[i].max));) {
+	IsLabel = FALSE;
+	if ((fabs((int)(next/major) - (next/major)) < 0.5*(minor/major)) || 
+	    (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)) ||
+	    (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)))
+	  IsLabel = layout[0].axis[i].islabel;
+	PSTick (f, fx, fy, dfx, dfy, P, layout[0].axis[i].min, layout[0].axis[i].max, next, IsLabel, i);
+	if (range > 0) 
+	  next += minor;
+	else 
+	  next -= minor;
+      }
+    }
+  }
+  return (TRUE);
+}
+
+void PSTick (FILE *f, double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int mode, int naxis) {
+  
+  int pos, dir, fontsize;
+  double size, n, x, y, dx, dy;
+  char string[64], *fontname;
+
+  pos = size = 0;
+
+  if (mode == 1) { size = MAX (0.02, 7.0 / P); }
+  if (mode == 0) { size = MAX (0.01, 4.0 / P); }
+  
+  n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
+  x = fx + (value-min)*dfx/(max - min);
+  y = fy + (value-min)*dfy/(max - min);
+
+  dir = -1;
+  if ((naxis == 0) || (naxis == 1)) dir *= -1;
+  dx = dir*size*dfy*n;	
+  dy = dir*size*dfx*n;
+  
+  DrawLine (x, y, dx, dy);
+
+  if (mode == 1) {
+    fontname = GetRotFont (&fontsize);
+
+    /* temporarily assume rectilinear axes */
+    if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
+    if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
+
+    if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
+    if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
+
+    x = fx + (value-min)*dfx/(max - min) + dx;
+    y = fy + (value-min)*dfy/(max - min) + dy;
+    if (fabs(value) < 1e-14) { value = 0.0; }
+    sprintf (string, "%g", value);
+    PSRotText (f, (int)x, (int)y, string, pos, 0.0);
+  }
+}
+
+  /* 
+  dx = size*dfy*n;	
+  dy = size*dfx*n;
+  DrawLine (x, y, dx, dy);
+  
+  dx = -size*dfy*n;	
+  dy = -size*dfx*n;
+  DrawLine (x, y, dx, dy);
+  */
+  
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSLabels.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSLabels.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSLabels.c	(revision 10836)
@@ -0,0 +1,46 @@
+# include "Ximage.h"
+  
+void PSLabels (Layout *layout, FILE *f) {
+  
+  int i, pos, x, y, size;
+  double angle;
+  char *fontname;
+
+  pos = 0;
+  fontname = GetRotFont (&size);
+  for (i = 0; i < 8; i++) {
+    if (strcmp (layout[0].label[i].text, "")) {
+      angle = 0;
+      switch (i) {
+      case 0: pos = 7; break;
+      case 1: pos = 1; angle = -90; break;
+      case 2: pos = 1; break;
+      case 3: pos = 1; angle =  90; break;
+      case 4: pos = 2; break;
+      case 5: pos = 0; break;
+      case 6: pos = 8; break;
+      case 7: pos = 6; break;
+      }	
+      x = layout[0].label[i].x;
+      y = graphic.dy - layout[0].label[i].y;
+      SetRotFont (layout[0].label[i].font, layout[0].label[i].size); 
+      PSRotText (f, x, y, layout[0].label[i].text, pos, angle);
+    }
+  }
+  SetRotFont (fontname, size);
+}
+
+  /*
+            
+ 4____2___5 
+  |       | 
+  |       | 
+ 1|       |3
+  |       |
+  |       |
+  ---------
+  6   0   7
+
+  */
+
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSObjects.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSObjects.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSObjects.c	(revision 10836)
@@ -0,0 +1,686 @@
+# include "Ximage.h"
+# define XOFFSET 60
+# define YOFFSET 60
+
+void ClipLinePS (double, double, double, double, double, double, double, double, FILE *);
+
+static char *name = "$Name: not supported by cvs2svn $";
+
+int PSit () {
+
+  int i, pageMode, scaleMode;
+  double scale;
+  FILE *f;
+  char filename[1024], pagename[1024], *version;
+  int Nbytes, status;
+
+  /* expect a line telling the number of bytes and a filename */
+  KiiScanMessage (sock, "%s %s %d %d", filename, pagename, &scaleMode, &pageMode);
+
+  if (pageMode == KAPA_PS_NEWPAGE) {
+    f = fopen (filename, "a+");
+  } else {
+    f = fopen (filename, "w");
+  }
+  if (f == NULL) {
+    fprintf (stderr, "can't open output file %s\n", filename);
+    return (TRUE);  /* true because otherwise it quits kapa! */
+  }
+
+  /* two scaling options: expand to fit page / keep absolute size */ 
+  if (scaleMode) {
+    scale = MIN (fabs(500.0 / graphic.dx), fabs (700.0 / graphic.dy));
+  } else {
+    scale = 72.0 / 96.0; /* ratio of screen pixels to points */
+  }
+
+  switch (pageMode) {
+    case KAPA_PS_NEWPLOT:
+      fprintf (f, "%%!PS-Adobe-2.0 EPSF-2.0\n");
+      fprintf (f, "%%%%Title: %s\n", filename);
+      version = strip_version (name);
+      fprintf (f, "%%%%Creator: Kapa (%s)\n", version);
+      free (version);
+      fprintf (f, "%%%%BoundingBox: %d %d %.0f %.0f\n", 
+	       XOFFSET, YOFFSET, XOFFSET + scale*graphic.dx, YOFFSET + scale*graphic.dy);
+      fprintf (f, "%%%%Pages: 1\n");
+      fprintf (f, "%%%%DocumentFonts:\n");
+      fprintf (f, "%%%%EndComments\n");
+      fprintf (f, "%%%%EndProlog\n");
+      fprintf (f, "%%%%Page: %s\n\n", pagename);
+      break;
+
+    case KAPA_PS_NEWPAGE:
+      fprintf (f, "%%%%Page: %s\n\n", pagename);
+      break;
+
+    case KAPA_PS_RAWPAGE:
+      break;
+  } 
+  fprintf (f, "gsave %% encloses picture\n");
+  fprintf (f, "%% local abbreviations\n");
+  fprintf (f, "/Times-Roman findfont 14 scalefont setfont\n");
+  fprintf (f, "/T {moveto show stroke} def\n");
+  fprintf (f, "/B { newpath moveto dup 0 exch rlineto exch dup 0 rlineto exch -1 mul\n");
+  fprintf (f, " 0 exch rlineto -1 mul 0 rlineto closepath stroke } def\n");
+  fprintf (f, "/F { newpath moveto dup 0 exch rlineto exch dup 0 rlineto exch -1 mul\n");
+  fprintf (f, " 0 exch rlineto -1 mul 0 rlineto closepath fill stroke } def\n");
+  fprintf (f, "/C {0 360 arc stroke} def\n");
+  fprintf (f, "/L {newpath moveto lineto stroke} def\n\n");
+  fprintf (f, "/TF {newpath moveto lineto lineto fill stroke} def\n\n");
+
+  if (pageMode != KAPA_PS_RAWPAGE) {
+    fprintf (f, " %d %d translate\n", XOFFSET, YOFFSET);
+    fprintf (f, "  %f  %f scale\n", scale, scale);
+  }
+
+  for (i = 0; i < Nsection; i++) {
+    PSFrame (&section[i], f); 
+    PSObjects (&section[i], f);
+    PSLabels (&section[i], f);
+    PSPtext (&section[i], f);
+  }
+  
+  fprintf (f, "grestore %% end of picture\n");
+
+  if (pageMode != KAPA_PS_RAWPAGE) fprintf (f, "showpage\n");
+
+  fclose (f);
+  return (TRUE);
+
+}
+
+# define DrawLine(X1,Y1,X2,Y2) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f L\n", X1, graphic.dy - Y1, X2, graphic.dy - Y2))
+# define DrawCircle(X1,Y1,R) (fprintf (f, " %6.2f %6.2f %6.2f C\n", (X1), (graphic.dy - Y1), (R)))
+# define DrawRectangle(X,Y,dX,dY) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f B\n", (dX), (dY), (X-0.5*dX), (graphic.dy-Y-0.5*dY)))
+# define FillRectangle(X,Y,dX,dY) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f F\n", (dX), (dY), (X-0.5*dX), (graphic.dy-Y-0.5*dY)))
+# define FillTriangle(X1,Y1,X2,Y2, X3, Y3) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f TF\n", (X1), (graphic.dy-Y1), (X2), (graphic.dy-Y2), (X3), (graphic.dy-Y3)))
+# define CONNECT 0
+# define HISTOGRAM 1
+# define POINTS 2
+
+int PSObjects (Layout *layout, FILE *f) {
+  
+  int i;
+  double lweight;
+  static char dash[] = "5";
+  static char dot[] = "3";
+  
+  for (i = 0; i < layout[0].Nobjects; i++) {
+    switch (layout[0].objects[i].ltype) {
+    case 0:
+      break;
+    case 1:
+      fprintf (f, "[%s] 0 setdash\n", dash);
+      break;
+    case 2:
+      fprintf (f, "[%s] 0 setdash\n", dot);
+      break;
+    default:
+      break;
+    }
+    
+    lweight = MAX (0, MIN (10, layout[0].objects[i].lweight));
+    fprintf (f, "%.1f setlinewidth\n", lweight);
+    fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(layout[0].objects[i].color));
+
+    switch (layout[0].objects[i].style) {
+    case CONNECT: 
+      PSConnect (layout, &layout[0].objects[i], f);
+      break;
+    case HISTOGRAM:
+      PSHistogram (layout, &layout[0].objects[i], f);
+      break;
+    case POINTS:
+      PSPoints (layout, &layout[0].objects[i], f);
+      break;
+    }
+
+    if (layout[0].objects[i].etype & 0x01) {
+      PSYErrors (layout, &layout[0].objects[i], f);
+    }
+    if (layout[0].objects[i].etype & 0x02) {
+      PSXErrors (layout, &layout[0].objects[i], f);
+    }
+    fprintf (f, "[] 0 setdash\n");
+    fprintf (f, "0.00 0.00 0.00 setrgbcolor\n");
+  }
+  return (TRUE);
+}
+
+/*******/
+void PSConnect (Layout *layout, Gobjects *object, FILE *f) {
+  
+  int i;
+  float *x, *y;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1;
+  double X0, X1, Y0, Y1;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0); 
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0); 
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  X0 = layout[0].axis[0].fx;
+  X1 = layout[0].axis[0].fx + layout[0].axis[0].dfx;
+  Y0 = layout[0].axis[1].fy;
+  Y1 = layout[0].axis[1].fy + layout[0].axis[1].dfy;
+
+  x = object[0].x; y = object[0].y;
+  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
+  if (i >= object[0].Npts) return;
+  sx0 = x[i]*mxi + y[i]*mxj + bx;
+  sy0 = x[i]*myi + y[i]*myj + by;
+  
+  for (i++; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]))) continue;
+    sx1 = x[i]*mxi + y[i]*mxj + bx;
+    sy1 = x[i]*myi + y[i]*myj + by;
+    ClipLinePS (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1, f);
+    /* DrawLine (sx0, sy0, sx1, sy1); */
+    sx0 = sx1; sy0 = sy1;
+  }
+}
+
+void ClipLinePS (double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0, FILE *f) {
+
+  /* skip line segement if both points are beyond box */
+  if ((x0 <= X0) && (x1 <= X0)) return;
+  if ((x0 >= X1) && (x1 >= X1)) return;
+  if ((y0 <= Y0) && (y1 <= Y0)) return;
+  if ((y0 >= Y1) && (y1 >= Y1)) return;
+
+  /* replace x0,y0 if outside box */
+  if ((x0 < X0) && (x1 >= X0)) {
+    y0 = y0 + (X0 - x0)*(y1 - y0)/(x1 - x0);
+    x0 = X0;
+  }
+  if ((x0 > X1) && (x1 <= X1)) {
+    y0 = y0 + (X1 - x0)*(y1 - y0)/(x1 - x0);
+    x0 = X1;
+  }
+  if ((y0 < Y0) && (y1 >= Y0)) {
+    x0 = x0 + (Y0 - y0)*(x1 - x0)/(y1 - y0);
+    y0 = Y0;
+  }
+  if ((y0 > Y1) && (y1 <= Y1)) {
+    x0 = x0 + (Y1 - y0)*(x1 - x0)/(y1 - y0);
+    y0 = Y1;
+  }
+
+  /* skip line segement if both points are beyond box */
+  if ((x0 <= X0) && (x1 <= X0)) return;
+  if ((x0 >= X1) && (x1 >= X1)) return;
+  if ((y0 <= Y0) && (y1 <= Y0)) return;
+  if ((y0 >= Y1) && (y1 >= Y1)) return;
+
+  /* replace x1,y1 if outside box */
+  if ((x1 < X0) && (x0 >= X0)) {
+    y1 = y0 + (X0 - x0)*(y1 - y0)/(x1 - x0);
+    x1 = X0;
+  }
+  if ((x1 > X1) && (x0 <= X1)) {
+    y1 = y0 + (X1 - x0)*(y1 - y0)/(x1 - x0);
+    x1 = X1;
+  }
+  if ((y1 < Y0) && (y0 >= Y0)) {
+    x1 = x0 + (Y0 - y0)*(x1 - x0)/(y1 - y0);
+    y1 = Y0;
+  }
+  if ((y1 > Y1) && (y0 <= Y1)) {
+    x1 = x0 + (Y1 - y0)*(x1 - x0)/(y1 - y0);
+    y1 = Y1;
+  }
+  DrawLine (x0, y0, x1, y1);
+}
+
+/*******/
+void PSHistogram (Layout *layout, Gobjects *object, FILE *f) {
+
+  int i;
+  float *x, *y;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sxa;
+  double X0, X1, Y0, Y1;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0); 
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0); 
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  X0 = layout[0].axis[0].fx;
+  X1 = layout[0].axis[0].fx + layout[0].axis[0].dfx;
+  Y0 = layout[0].axis[1].fy;
+  Y1 = layout[0].axis[1].fy + layout[0].axis[1].dfy;
+
+  /* find the first valid datapoint */
+  x = object[0].x; y = object[0].y;
+  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
+  if (i >= object[0].Npts) return;
+  sx0 = x[i]*mxi + y[i]*mxj + bx;
+  sy0 = x[i]*myi + y[i]*myj + by;
+  sx0 = MIN (MAX (sx0, X0), X1);
+  sy0 = MAX (MIN (sy0, Y0), Y1);
+  
+  /* continue with rest of points */
+  for (i++; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]))) continue;
+    sx1 = x[i]*mxi + y[i]*mxj + bx;
+    sy1 = x[i]*myi + y[i]*myj + by;
+    sx1 = MIN (MAX (sx1, X0), X1);
+    sy1 = MAX (MIN (sy1, Y0), Y1);
+    sxa = 0.5*(sx0 + sx1);
+    DrawLine (sx0, sy0, sxa, sy0);
+    DrawLine (sxa, sy0, sxa, sy1);
+    DrawLine (sxa, sy1, sx1, sy1);
+    sx0 = sx1; sy0 = sy1;
+  }
+}
+
+/*******/
+void PSPoints (Layout *layout, Gobjects *object, FILE *f) {
+ 
+  int i;
+  float *x, *y, *z;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx, sy, d, sx1, sy1, sx2, sy2;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);  
+ 
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);  
+
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  /* below here, code is identical with DrawObjects */
+  /**** points are scaled by object.z ***/
+  if (object[0].size < 0) {
+    d = 0.5 * (graphic.dx + graphic.dy) * 0.01;
+    x = object[0].x; y = object[0].y; z = object[0].z;
+    if (object[0].ptype == 0) {	/* filled box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillRectangle (sx, sy, 2*d*z[i], 2*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 1) {	/* open box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawRectangle (sx, sy, 2*d*z[i], 2*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 2) { /* cross */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d*z[i], sy, sx + d*z[i], sy);
+	    DrawLine (sx, sy - d*z[i], sx, sy + d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 3) {	/* x */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx + d*z[i], sy - d*z[i], sx - d*z[i], sy + d*z[i]);
+	    DrawLine (sx - d*z[i], sy - d*z[i], sx + d*z[i], sy + d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 4) {	/* filled triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillTriangle (sx - d*z[i], sy - 0.58*d*z[i], sx + d*z[i], sy - 0.58*d*z[i], sx, sy + 1.15*d*z[i]);
+	    /*
+	    DrawLine (sx - d*z[i], sy + 0.58*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx + d*z[i], sy + 0.58*d*z[i], sx,          sy - 1.15*d*z[i]);
+	    DrawLine (sx,          sy - 1.15*d*z[i], sx - d*z[i], sy + 0.58*d*z[i]);
+	    */
+	  }
+      }
+    }
+    if (object[0].ptype == 5) {	/* open triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d*z[i], sy + 0.58*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx + d*z[i], sy + 0.58*d*z[i], sx,          sy - 1.15*d*z[i]);
+	    DrawLine (sx,          sy - 1.15*d*z[i], sx - d*z[i], sy + 0.58*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 6) {	/* Y */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx, sy, sx - d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx, sy, sx + d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx, sy, sx,          sy - 1.15*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 7) {	/* 0 */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawCircle (sx, sy, d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 100) {	/* connect a pair of points */
+      for (i = 0; i + 1 < object[0].Npts; i+=2) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx1 = x[i]*mxi + y[i]*mxj + bx;
+	sy1 = x[i]*myi + y[i]*myj + by;
+	sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
+	sy2 = x[i+1]*myi + y[i+1]*myj + by;
+	DrawLine (sx1, sy1, sx2, sy2);
+      }
+    }
+  } else {
+    d = object[0].size * 0.5 * (graphic.dx + graphic.dy) * 0.003;
+    x = object[0].x; y = object[0].y;
+    if (object[0].ptype == 0) {	/* filled box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillRectangle (sx, sy, 2*d, 2*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 1) {		/* open box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+   	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawRectangle (sx, sy, 2*d, 2*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 2) { /* cross */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d, sy, sx + d, sy);
+	    DrawLine (sx, sy - d, sx, sy + d);
+	  }
+      }
+    }
+    if (object[0].ptype == 3) {		/* x */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx + d, sy - d, sx - d, sy + d);
+	    DrawLine (sx - d, sy - d, sx + d, sy + d);
+	  }
+      }
+    }
+    if (object[0].ptype == 4) {	/* filled triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    /*
+	    DrawLine (sx - d, sy + 0.58*d, sx + d, sy + 0.58*d);
+	    DrawLine (sx + d, sy + 0.58*d, sx,     sy - 1.15*d);
+	    DrawLine (sx,     sy - 1.15*d, sx - d, sy + 0.58*d);
+	    */
+	    FillTriangle (sx - d, sy - 0.58*d, sx + d, sy - 0.58*d, sx, sy + 1.15*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 5) {	/* open triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d, sy - 0.58*d, sx + d, sy - 0.58*d);
+	    DrawLine (sx + d, sy - 0.58*d, sx,     sy + 1.15*d);
+	    DrawLine (sx,     sy + 1.15*d, sx - d, sy - 0.58*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 6) {	/* Y */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx, sy, sx - d, sy - 0.58*d);
+	    DrawLine (sx, sy, sx + d, sy - 0.58*d);
+	    DrawLine (sx, sy, sx,     sy + 1.15*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 7) {	/* 0 */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawCircle (sx, sy, d);
+	  }
+      }
+    }
+    if (object[0].ptype == 100) {	
+      for (i = 0; i + 1 < object[0].Npts; i+=2) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx1 = x[i]*mxi + y[i]*mxj + bx;
+	sy1 = x[i]*myi + y[i]*myj + by;
+	sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
+	sy2 = x[i+1]*myi + y[i+1]*myj + by;
+	DrawLine (sx1, sy1, sx2, sy2);
+      }
+    }
+  }
+}
+    
+/*******/
+void PSXErrors (Layout *layout, Gobjects *object, FILE *f) {
+  
+  int i, bar;
+  float *x, *y, *dxm, *dxp;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sz, sx10, sx11;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  x = object[0].x; y = object[0].y; dxp = object[0].dxp; dxm = object[0].dxm; 
+  bar = object[0].ebar; sz = object[0].size*layout[0].axis[1].dfy*0.03;
+   
+  for (i = 0; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]) && finite(dxp[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = (x[i] + dxp[i])*mxi + y[i]*mxj + bx;
+    sy1 = (x[i] + dxp[i])*myi + y[i]*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sy1 - sz;
+	  sx11 = sy1 + sz;
+	  DrawLine (sx1, sx10, sx1, sx11);
+	}
+      }
+    if (!(finite(x[i]) && finite(y[i]) && finite(dxm[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = (x[i] - dxm[i])*mxi + y[i]*mxj + bx;
+    sy1 = (x[i] - dxm[i])*myi + y[i]*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sy1 - sz;
+	  sx11 = sy1 + sz;
+	  DrawLine (sx1, sx10, sx1, sx11);
+	}
+      }
+  }
+}
+
+    
+/*******/
+void PSYErrors (Layout *layout, Gobjects *object, FILE *f) {
+  
+  int i, bar;
+  float *x, *y, *dym, *dyp;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sz, sx10, sx11;
+  
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  x = object[0].x; y = object[0].y; dyp = object[0].dyp; dym = object[0].dym; 
+  bar = object[0].ebar; sz = object[0].size*layout[0].axis[0].dfx*0.03;
+  
+  for (i = 0; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]) && finite(dyp[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = x[i]*mxi + (y[i] + dyp[i])*mxj + bx;
+    sy1 = x[i]*myi + (y[i] + dyp[i])*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sx1 - sz;
+	  sx11 = sx1 + sz;
+	  DrawLine (sx10, sy1, sx11, sy1);
+	}
+      }
+    if (!(finite(x[i]) && finite(y[i]) && finite(dym[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = x[i]*mxi + (y[i] - dym[i])*mxj + bx;
+    sy1 = x[i]*myi + (y[i] - dym[i])*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sx1 - sz;
+	  sx11 = sx1 + sz;
+	  DrawLine (sx10, sy1, sx11, sy1);
+	}
+      }
+  }
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSPtext.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSPtext.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/PSPtext.c	(revision 10836)
@@ -0,0 +1,33 @@
+# include "Ximage.h"
+  
+void PSPtext (Layout *layout, FILE *f) {
+
+  int i, x, y, size;
+  double angle;
+  char *fontname;
+
+  fontname = GetRotFont (&size);
+  for (i = 0; i < layout[0].Nptext; i++) {
+    if (strcmp (layout[0].ptext[i].text, "")) {
+      angle = layout[0].ptext[i].angle;
+      x = layout[0].ptext[i].x;
+      y = graphic.dy - layout[0].ptext[i].y;
+      SetRotFont (layout[0].ptext[i].font, layout[0].ptext[i].size);
+      PSRotText (f, x, y, layout[0].ptext[i].text, 5, angle);
+    }
+  }
+  SetRotFont (fontname, size);
+}
+
+  /* pos values
+            
+ 4____2___5 
+  |       | 
+  |       | 
+ 1|   8   |3
+  |       |
+  |       |
+  ---------
+  6   0   7
+
+  */
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/SetLimits.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/SetLimits.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/SetLimits.c	(revision 10836)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+int SetLimits () {
+  
+  int i;
+  double xmin, xmax, ymin, ymax;
+  Layout *layout;
+
+  layout = &section[TheSection];
+
+  KiiScanMessage (sock, "%lf %lf %lf %lf", &xmin, &xmax, &ymin, &ymax);
+
+  layout[0].axis[2].min = layout[0].axis[0].min = xmin;
+  layout[0].axis[2].max = layout[0].axis[0].max = xmax;
+  layout[0].axis[3].min = layout[0].axis[1].min = ymin; 
+  layout[0].axis[3].max = layout[0].axis[1].max = ymax;
+  
+  for (i = 0; i < layout[0].Nobjects; i++) {
+    layout[0].objects[i].x0 = xmin;
+    layout[0].objects[i].x1 = xmax;
+    layout[0].objects[i].y0 = ymin;
+    layout[0].objects[i].y1 = ymax;
+  }
+
+  XClearWindow (graphic.display, graphic.window);
+  Refresh (1);
+
+  return (TRUE);
+  
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawFrame.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawFrame.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawFrame.c	(revision 10836)
@@ -0,0 +1,89 @@
+# include "Ximage.h"
+
+int bDrawFrame (Layout *layout) {
+  
+  int i, P, IsLabel, fontsize;
+  double fx, fy, dfx, dfy, range, major, minor, first, next;
+  char *fontname;
+
+  /* each axis is drawn independently */
+  fontname = GetRotFont (&fontsize);
+  for (i = 0; i < 4; i++) {
+    fx  = layout[0].axis[i].fx;
+    fy  = layout[0].axis[i].fy;
+    dfx = layout[0].axis[i].dfx;
+    dfy = layout[0].axis[i].dfy;
+    P = hypot ((double)layout[0].axis[(i+1)%2].dfx, (double)layout[0].axis[(i+1)%2].dfy);
+
+    if (layout[0].axis[i].isaxis) { 
+      bDrawLine (fx, fy, fx+dfx, fy+dfy); 
+    }
+    
+    if (layout[0].axis[i].areticks) {
+      range = layout[0].axis[i].max - layout[0].axis[i].min;
+
+      AxisTickScale (&layout[0].axis[i], &major, &minor);
+
+      first = minor*((int)(layout[0].axis[i].min/minor));
+      if ((range > 0) && (first < layout[0].axis[i].min)) {
+	first += minor;
+      }
+      if ((range < 0) && (first > layout[0].axis[i].min)) {
+	first -= minor;
+      }
+      for (next = first; ((range > 0) && (next <= layout[0].axis[i].max)) || ((range < 0) && (next >= layout[0].axis[i].max));) {
+	IsLabel = FALSE;
+	if ((fabs((int)(next/major) - (next/major)) < 0.5*(minor/major)) || 
+	    (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)) ||
+	    (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)))
+	  IsLabel = layout[0].axis[i].islabel;
+	bDrawTick (fx, fy, dfx, dfy, P, layout[0].axis[i].min, layout[0].axis[i].max, next, IsLabel, i);
+	if (range > 0) 
+	  next += minor;
+	else 
+	  next -= minor;
+      }
+    }
+  }
+  return (TRUE);
+}
+
+void bDrawTick (double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int mode, int naxis) {
+  
+  int pos, dir, fontsize;
+  double size, n, x, y, dx, dy;
+  char string[64], *fontname;
+
+  pos = size = 0;
+
+  if (mode == 1) { size = MAX (0.02, 7.0 / P); }
+  if (mode == 0) { size = MAX (0.01, 4.0 / P); }
+  
+  n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
+  x = fx + (value-min)*dfx/(max - min);
+  y = fy + (value-min)*dfy/(max - min);
+
+  dir = +1;
+  if ((naxis == 0) || (naxis == 1)) dir *= -1;
+  dx = dir*size*dfy*n;	
+  dy = dir*size*dfx*n;
+  
+  bDrawLine (x, y, x+dx, y+dy);
+
+  if (mode == 1) {
+    fontname = GetRotFont (&fontsize);
+
+    /* temporarily assume rectilinear axes */
+    if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
+    if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
+
+    if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
+    if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
+
+    x = fx + (value-min)*dfx/(max - min) + dx;
+    y = fy + (value-min)*dfy/(max - min) + dy;
+    if (fabs(value) < 1e-14) { value = 0.0; }
+    sprintf (string, "%g", value);
+    bDrawRotText ((int)x, (int)y, string, pos, 0.0);
+  }
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawIt.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawIt.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawIt.c	(revision 10836)
@@ -0,0 +1,24 @@
+# include "Ximage.h"
+
+bDrawBuffer *bDrawIt () {
+
+  int i;
+  bDrawBuffer *buffer;
+  bDrawColor black;
+
+  black = KapaColorByName ("black");
+
+  buffer = bDrawBufferCreate (graphic.dx, graphic.dy);
+  bDrawSetBuffer (buffer);
+  bDrawSetStyle (black, 0, 0);
+  
+  for (i = 0; i < Nsection; i++) {
+    bDrawFrame (&section[i]); 
+    bDrawObjects (&section[i]);
+    bDrawLabels (&section[i]);
+    bDrawPtext (&section[i]);
+  }
+  
+  return (buffer);
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawLabels.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawLabels.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawLabels.c	(revision 10836)
@@ -0,0 +1,65 @@
+# include "Ximage.h"
+  
+void bDrawLabels (Layout *layout) {
+  
+  int i, pos, x, y, size;
+  double angle;
+  char *fontname;
+
+  pos = 0;
+  fontname = GetRotFont (&size);
+  for (i = 0; i < 8; i++) {
+    if (strcmp (layout[0].label[i].text, "")) {
+      angle = 0;
+      switch (i) {
+      case 0: pos = 7; break;
+      case 1: pos = 1; angle = -90; break;
+      case 2: pos = 1; break;
+      case 3: pos = 1; angle =  90; break;
+      case 4: pos = 2; break;
+      case 5: pos = 0; break;
+      case 6: pos = 8; break;
+      case 7: pos = 6; break;
+      }	
+      x = layout[0].label[i].x;
+      y = layout[0].label[i].y;
+      SetRotFont (layout[0].label[i].font, layout[0].label[i].size); 
+      bDrawRotText (x, y, layout[0].label[i].text, pos, angle);
+    }
+  }
+  SetRotFont (fontname, size);
+}
+
+void bDrawPtext (Layout *layout) {
+
+  int i, x, y, size;
+  double angle;
+  char *fontname;
+
+  fontname = GetRotFont (&size);
+  for (i = 0; i < layout[0].Nptext; i++) {
+    if (strcmp (layout[0].ptext[i].text, "")) {
+      angle = layout[0].ptext[i].angle;
+      x = layout[0].ptext[i].x;
+      y = layout[0].ptext[i].y;
+      SetRotFont (layout[0].ptext[i].font, layout[0].ptext[i].size);
+      bDrawRotText (x, y, layout[0].ptext[i].text, 5, angle);
+    }
+  }
+  SetRotFont (fontname, size);
+}
+
+/*
+            
+ 4____2___5 
+  |       | 
+  |       | 
+ 1|       |3
+  |       |
+  |       |
+  ---------
+  6   0   7
+
+*/
+
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawObjects.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawObjects.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/bDrawObjects.c	(revision 10836)
@@ -0,0 +1,570 @@
+# include "Ximage.h"
+
+# define DrawLine(X1,Y1,X2,Y2) (bDrawLine ((X1), (Y1), (X2), (Y2)))
+# define DrawCircle(X1,Y1,R) (bDrawCircle ((X1), (Y1), (R)))
+# define DrawRectangle(X,Y,dX,dY) (bDrawRectOpen ((X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
+# define FillRectangle(X,Y,dX,dY) (bDrawRectFill ((X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
+# define FillTriangle(X1,Y1,X2,Y2,X3,Y3) (bDrawTriFill ((X1), (Y1), (X2), (Y2), (X3), (Y3)))
+# define OpenTriangle(X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen ((X1), (Y1), (X2), (Y2), (X3), (Y3)))
+# define CONNECT 0
+# define HISTOGRAM 1
+# define POINTS 2
+
+int bDrawObjects (Layout *layout) {
+  
+  int i;
+  int type;
+  int weight;
+  bDrawColor color;
+  bDrawColor black;
+  
+  black = KapaColorByName ("black");
+  for (i = 0; i < layout[0].Nobjects; i++) {
+
+    weight = MAX (0, MIN (10, layout[0].objects[i].lweight));
+    type = layout[0].objects[i].ltype;    
+    color = layout[0].objects[i].color;
+    bDrawSetStyle (color, weight, type);
+
+    switch (layout[0].objects[i].style) {
+    case CONNECT: 
+      bDrawConnect (layout, &layout[0].objects[i]);
+      break;
+    case HISTOGRAM:
+      bDrawHistogram (layout, &layout[0].objects[i]);
+      break;
+    case POINTS:
+      bDrawPoints (layout, &layout[0].objects[i]);
+      break;
+    }
+
+    if (layout[0].objects[i].etype & 0x01) {
+      bDrawYErrors (layout, &layout[0].objects[i]);
+    }
+    if (layout[0].objects[i].etype & 0x02) {
+      bDrawXErrors (layout, &layout[0].objects[i]);
+    }
+  }
+  bDrawSetStyle (black, 0, 0);
+  return (TRUE);
+}
+
+void bDrawConnect (Layout *layout, Gobjects *object) {
+  
+  int i;
+  float *x, *y;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1;
+  double X0, X1, Y0, Y1;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0); 
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0); 
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  X0 = layout[0].axis[0].fx;
+  X1 = layout[0].axis[0].fx + layout[0].axis[0].dfx;
+  Y0 = layout[0].axis[1].fy;
+  Y1 = layout[0].axis[1].fy + layout[0].axis[1].dfy;
+
+  x = object[0].x; y = object[0].y;
+  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
+  if (i >= object[0].Npts) return;
+  sx0 = x[i]*mxi + y[i]*mxj + bx;
+  sy0 = x[i]*myi + y[i]*myj + by;
+  
+  for (i++; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]))) continue;
+    sx1 = x[i]*mxi + y[i]*mxj + bx;
+    sy1 = x[i]*myi + y[i]*myj + by;
+    bDrawClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
+    sx0 = sx1; sy0 = sy1;
+  }
+}
+
+void bDrawClipLine (double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0) {
+
+  /* skip line segement if both points are beyond box */
+  if ((x0 <= X0) && (x1 <= X0)) return;
+  if ((x0 >= X1) && (x1 >= X1)) return;
+  if ((y0 <= Y0) && (y1 <= Y0)) return;
+  if ((y0 >= Y1) && (y1 >= Y1)) return;
+
+  /* replace x0,y0 if outside box */
+  if ((x0 < X0) && (x1 >= X0)) {
+    y0 = y0 + (X0 - x0)*(y1 - y0)/(x1 - x0);
+    x0 = X0;
+  }
+  if ((x0 > X1) && (x1 <= X1)) {
+    y0 = y0 + (X1 - x0)*(y1 - y0)/(x1 - x0);
+    x0 = X1;
+  }
+  if ((y0 < Y0) && (y1 >= Y0)) {
+    x0 = x0 + (Y0 - y0)*(x1 - x0)/(y1 - y0);
+    y0 = Y0;
+  }
+  if ((y0 > Y1) && (y1 <= Y1)) {
+    x0 = x0 + (Y1 - y0)*(x1 - x0)/(y1 - y0);
+    y0 = Y1;
+  }
+
+  /* skip line segement if both points are beyond box */
+  if ((x0 <= X0) && (x1 <= X0)) return;
+  if ((x0 >= X1) && (x1 >= X1)) return;
+  if ((y0 <= Y0) && (y1 <= Y0)) return;
+  if ((y0 >= Y1) && (y1 >= Y1)) return;
+
+  /* replace x1,y1 if outside box */
+  if ((x1 < X0) && (x0 >= X0)) {
+    y1 = y0 + (X0 - x0)*(y1 - y0)/(x1 - x0);
+    x1 = X0;
+  }
+  if ((x1 > X1) && (x0 <= X1)) {
+    y1 = y0 + (X1 - x0)*(y1 - y0)/(x1 - x0);
+    x1 = X1;
+  }
+  if ((y1 < Y0) && (y0 >= Y0)) {
+    x1 = x0 + (Y0 - y0)*(x1 - x0)/(y1 - y0);
+    y1 = Y0;
+  }
+  if ((y1 > Y1) && (y0 <= Y1)) {
+    x1 = x0 + (Y1 - y0)*(x1 - x0)/(y1 - y0);
+    y1 = Y1;
+  }
+  DrawLine (x0, y0, x1, y1);
+}
+
+/*******/
+void bDrawHistogram (Layout *layout, Gobjects *object) {
+
+  int i;
+  float *x, *y;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sxa;
+  double X0, X1, Y0, Y1;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0); 
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0); 
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  X0 = layout[0].axis[0].fx;
+  X1 = layout[0].axis[0].fx + layout[0].axis[0].dfx;
+  Y0 = layout[0].axis[1].fy;
+  Y1 = layout[0].axis[1].fy + layout[0].axis[1].dfy;
+
+  /* find the first valid datapoint */
+  x = object[0].x; y = object[0].y;
+  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
+  if (i >= object[0].Npts) return;
+  sx0 = x[i]*mxi + y[i]*mxj + bx;
+  sy0 = x[i]*myi + y[i]*myj + by;
+  sx0 = MIN (MAX (sx0, X0), X1);
+  sy0 = MAX (MIN (sy0, Y0), Y1);
+  
+  /* continue with rest of points */
+  for (i++; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]))) continue;
+    sx1 = x[i]*mxi + y[i]*mxj + bx;
+    sy1 = x[i]*myi + y[i]*myj + by;
+    sx1 = MIN (MAX (sx1, X0), X1);
+    sy1 = MAX (MIN (sy1, Y0), Y1);
+    sxa = 0.5*(sx0 + sx1);
+    DrawLine (sx0, sy0, sxa, sy0);
+    DrawLine (sxa, sy0, sxa, sy1);
+    DrawLine (sxa, sy1, sx1, sy1);
+    sx0 = sx1; sy0 = sy1;
+  }
+}
+
+/*******/
+void bDrawPoints (Layout *layout, Gobjects *object) {
+ 
+  int i;
+  float *x, *y, *z;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx, sy, d, sx1, sy1, sx2, sy2;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);  
+ 
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);  
+
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  /* below here, code is identical with DrawObjects */
+  /**** points are scaled by object.z ***/
+  if (object[0].size < 0) {
+    d = 0.5 * (graphic.dx + graphic.dy) * 0.01;
+    x = object[0].x; y = object[0].y; z = object[0].z;
+    if (object[0].ptype == 0) {	/* filled box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillRectangle (sx, sy, 2*d*z[i], 2*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 1) {	/* open box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawRectangle (sx, sy, 2*d*z[i], 2*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 2) { /* cross */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d*z[i], sy, sx + d*z[i], sy);
+	    DrawLine (sx, sy - d*z[i], sx, sy + d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 3) {	/* x */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx + d*z[i], sy - d*z[i], sx - d*z[i], sy + d*z[i]);
+	    DrawLine (sx - d*z[i], sy - d*z[i], sx + d*z[i], sy + d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 4) {	/* filled triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillTriangle (sx - d*z[i], sy - 0.58*d*z[i], sx + d*z[i], sy - 0.58*d*z[i], sx, sy + 1.15*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 5) {	/* open triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    OpenTriangle (sx - d*z[i], sy + 0.58*d*z[i], sx, sy - 1.15*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 6) {	/* Y */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx, sy, sx - d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx, sy, sx + d*z[i], sy + 0.58*d*z[i]);
+	    DrawLine (sx, sy, sx,          sy - 1.15*d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 7) {	/* 0 */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawCircle (sx, sy, d*z[i]);
+	  }
+      }
+    }
+    if (object[0].ptype == 100) {	/* connect a pair of points */
+      for (i = 0; i + 1 < object[0].Npts; i+=2) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx1 = x[i]*mxi + y[i]*mxj + bx;
+	sy1 = x[i]*myi + y[i]*myj + by;
+	sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
+	sy2 = x[i+1]*myi + y[i+1]*myj + by;
+	DrawLine (sx1, sy1, sx2, sy2);
+      }
+    }
+  } else {
+    d = object[0].size * 0.5 * (graphic.dx + graphic.dy) * 0.003;
+    x = object[0].x; y = object[0].y;
+    if (object[0].ptype == 0) {	/* filled box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillRectangle (sx, sy, 2*d, 2*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 1) {		/* open box */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+   	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawRectangle (sx, sy, 2*d, 2*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 2) { /* cross */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx - d, sy, sx + d, sy);
+	    DrawLine (sx, sy - d, sx, sy + d);
+	  }
+      }
+    }
+    if (object[0].ptype == 3) {		/* x */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx + d, sy - d, sx - d, sy + d);
+	    DrawLine (sx - d, sy - d, sx + d, sy + d);
+	  }
+      }
+    }
+    if (object[0].ptype == 4) {	/* filled triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    FillTriangle (sx - d, sy - 0.58*d, sx + d, sy - 0.58*d, sx, sy + 1.15*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 5) {	/* open triangle */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    OpenTriangle (sx - d, sy + 0.58*d, sx + d, sy + 0.58*d, sx, sy - 1.15*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 6) {	/* Y */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawLine (sx, sy, sx - d, sy - 0.58*d);
+	    DrawLine (sx, sy, sx + d, sy - 0.58*d);
+	    DrawLine (sx, sy, sx,     sy + 1.15*d);
+	  }
+      }
+    }
+    if (object[0].ptype == 7) {	/* 0 */
+      for (i = 0; i < object[0].Npts; i++) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx = x[i]*mxi + y[i]*mxj + bx;
+	sy = x[i]*myi + y[i]*myj + by;
+	if ((sx > layout[0].axis[0].fx) && (sx < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	    (sy < layout[0].axis[1].fy) && (sy > layout[0].axis[1].fy + layout[0].axis[1].dfy))
+	  {
+	    DrawCircle (sx, sy, d);
+	  }
+      }
+    }
+    if (object[0].ptype == 100) {	
+      for (i = 0; i + 1 < object[0].Npts; i+=2) {
+	if (!(finite(x[i]) && finite(y[i]))) continue;
+	sx1 = x[i]*mxi + y[i]*mxj + bx;
+	sy1 = x[i]*myi + y[i]*myj + by;
+	sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
+	sy2 = x[i+1]*myi + y[i+1]*myj + by;
+	DrawLine (sx1, sy1, sx2, sy2);
+      }
+    }
+  }
+}
+    
+/*******/
+void bDrawXErrors (Layout *layout, Gobjects *object) {
+  
+  int i, bar;
+  float *x, *y, *dxm, *dxp;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sz, sx10, sx11;
+
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  x = object[0].x; y = object[0].y; dxp = object[0].dxp; dxm = object[0].dxm; 
+  bar = object[0].ebar; sz = object[0].size*layout[0].axis[1].dfy*0.03;
+   
+  for (i = 0; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]) && finite(dxp[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = (x[i] + dxp[i])*mxi + y[i]*mxj + bx;
+    sy1 = (x[i] + dxp[i])*myi + y[i]*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sy1 - sz;
+	  sx11 = sy1 + sz;
+	  DrawLine (sx1, sx10, sx1, sx11);
+	}
+      }
+    if (!(finite(x[i]) && finite(y[i]) && finite(dxm[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = (x[i] - dxm[i])*mxi + y[i]*mxj + bx;
+    sy1 = (x[i] - dxm[i])*myi + y[i]*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sy1 - sz;
+	  sx11 = sy1 + sz;
+	  DrawLine (sx1, sx10, sx1, sx11);
+	}
+      }
+  }
+}
+    
+/*******/
+void bDrawYErrors (Layout *layout, Gobjects *object) {
+  
+  int i, bar;
+  float *x, *y, *dym, *dyp;
+  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
+  double sx0, sy0, sx1, sy1, sz, sx10, sx11;
+  
+  mxi = layout[0].axis[0].dfx / (object[0].x1 - object[0].x0);
+  mxj = layout[0].axis[1].dfx / (object[0].y1 - object[0].y0);
+  myi = layout[0].axis[0].dfy / (object[0].x1 - object[0].x0);
+  myj = layout[0].axis[1].dfy / (object[0].y1 - object[0].y0);
+  
+  bxi  =  layout[0].axis[0].fx - object[0].x0*layout[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  bxj  =  -object[0].y0*layout[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  byi  =  -object[0].x0*layout[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  byj  =  layout[0].axis[1].fy - object[0].y0*layout[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  bx = bxi + bxj;
+  by = byi + byj;
+  
+  x = object[0].x; y = object[0].y; dyp = object[0].dyp; dym = object[0].dym; 
+  bar = object[0].ebar; sz = object[0].size*layout[0].axis[0].dfx*0.03;
+  
+  for (i = 0; i < object[0].Npts; i++) {
+    if (!(finite(x[i]) && finite(y[i]) && finite(dyp[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = x[i]*mxi + (y[i] + dyp[i])*mxj + bx;
+    sy1 = x[i]*myi + (y[i] + dyp[i])*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sx1 - sz;
+	  sx11 = sx1 + sz;
+	  DrawLine (sx10, sy1, sx11, sy1);
+	}
+      }
+    if (!(finite(x[i]) && finite(y[i]) && finite(dym[i]))) continue;
+    sx0 = x[i]*mxi + y[i]*mxj + bx;
+    sy0 = x[i]*myi + y[i]*myj + by;
+    sx1 = x[i]*mxi + (y[i] - dym[i])*mxj + bx;
+    sy1 = x[i]*myi + (y[i] - dym[i])*myj + by;
+    if (((sx0 > layout[0].axis[0].fx) && (sx0 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy0 < layout[0].axis[1].fy) && (sy0 > layout[0].axis[1].fy + layout[0].axis[1].dfy)) ||
+	((sx1 > layout[0].axis[0].fx) && (sx1 < layout[0].axis[0].fx + layout[0].axis[0].dfx) &&
+	 (sy1 < layout[0].axis[1].fy) && (sy1 > layout[0].axis[1].fy + layout[0].axis[1].dfy)))
+      {
+	DrawLine (sx0, sy0, sx1, sy1);
+	if (bar) {
+	  sx10 = sx1 - sz;
+	  sx11 = sx1 + sz;
+	  DrawLine (sx10, sy1, sx11, sy1);
+	}
+      }
+  }
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/graph/cursor.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/graph/cursor.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/graph/cursor.c	(revision 10836)
@@ -0,0 +1,112 @@
+# include "Ximage.h"
+
+/* # define IgnoreMask (long) (ClientMessage | ButtonReleaseMask | PointerMotionMask) */
+# define IgnoreMask (long) (~(StructureNotifyMask | SubstructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask))
+
+int LastEvent (Display *display, int type, XEvent *event);
+
+int cursor () {
+
+  Display        *display;
+  XEvent          event;
+  KeySym          keysym;
+  int             status, value;
+  XComposeStatus  composestatus;
+  char            string[10], line[40], *name;
+  double          x, y;
+  char            buffer[10];
+  Layout         *layout;
+  XButtonEvent   *mouse_event;
+
+  layout = &section[TheSection];
+
+  while (1) {
+    
+    /* check the pipe for messages */
+    status = read (sock, buffer, 4);
+    buffer[4] = 0;
+    
+    if (status == -1) goto events;
+    if (status ==  0) return (FALSE);
+    if (status ==  4) {
+      if (!strcmp (buffer, "NCUR")) return (TRUE);
+      goto events;
+    }
+    fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
+    return (TRUE);
+
+  events:
+    if (XEventsQueued (graphic.display, QueuedAfterFlush) < 1) {
+      usleep (50000);
+      continue;
+    }
+
+    /* check for x events */
+    display = graphic.display;
+
+    /* grab the last entry for these events */
+    if (LastEvent (display, ConfigureNotify, &event)) Reconfig (&event);
+    if (LastEvent (display, CirculateNotify, &event)) Reconfig (&event);
+    if (LastEvent (display, Expose,          &event)) Refresh (1);
+
+    if (LastEvent (display, MappingNotify,   &event)) XRefreshKeyboardMapping ((XMappingEvent *) &event);
+	
+    /* drop and ignore the following StructureNotifyMask events */
+    LastEvent (display, GravityNotify, &event);
+    LastEvent (display, ReparentNotify, &event);
+    LastEvent (display, MapNotify, &event);
+    LastEvent (display, UnmapNotify, &event);
+
+    /* handle button presses */
+    if (LastEvent (display, ButtonPress,     &event)) {
+      mouse_event = (XButtonEvent *) &event;
+      sprintf (string, "Button%d", mouse_event[0].button);
+      x = (mouse_event[0].x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
+      y = (mouse_event[0].y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
+      snprintf (line, 40, "%12s %12.6f %12.6f ", string, x, y);
+      write (sock, line, 40);
+    }
+
+    /* handle key presses */
+    if (LastEvent (display, KeyPress,        &event)) {
+      value = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
+      name = XKeysymToString (keysym);
+
+      // ignore unmapped keys
+      if (name == NULL) continue;
+
+      x = (event.xkey.x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
+      y = (event.xkey.y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
+
+      // skip the following keys: 
+      if (!strcmp (name, "Shift_L")) continue;
+      if (!strcmp (name, "Shift_R")) continue;
+      if (!strcmp (name, "Control_L")) continue;
+      if (!strcmp (name, "Control_R")) continue;
+      if (!strcmp (name, "Alt_L")) continue;
+      if (!strcmp (name, "Alt_R")) continue;
+      if (!strcmp (name, "Super_L")) continue;
+      if (!strcmp (name, "Super_R")) continue;
+      if (!strcmp (name, "Caps_Lock")) continue;
+      if (!strcmp (name, "Pause")) continue;
+      if (!strcmp (name, "Continue")) continue;
+      if (!strcmp (name, "Num_Lock")) continue;
+      if (!strcmp (name, "Scroll_Lock")) continue;
+      if (!strcmp (name, "Print")) continue;
+      if (!strcmp (name, "(null)")) continue;
+
+      snprintf (line, 40, "%12s %12.6f %12.6f ", name, x, y);
+      write (sock, line, 40);
+    }
+
+    /* remove those events we will ignore */
+    while (XCheckMaskEvent (display, IgnoreMask, &event)) continue;
+
+    /* events to remove which have no mask component */
+    while (XCheckTypedEvent (display, ClientMessage, &event)) continue;
+    while (XCheckTypedEvent (display, SelectionClear, &event)) continue;
+    while (XCheckTypedEvent (display, SelectionNotify, &event)) continue;
+    while (XCheckTypedEvent (display, SelectionRequest, &event)) continue;
+  }
+  return (FALSE);
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/Ximage.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/Ximage.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/Ximage.h	(revision 10836)
@@ -0,0 +1,7 @@
+# include <Xohana.h>
+# include <dvo.h>
+# include <kapa.h>
+# include "constants.h"
+# include "structures.h"
+# include "prototypes.h"
+# include "globals.h"
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/alphabet.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/alphabet.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/alphabet.h	(revision 10836)
@@ -0,0 +1,53 @@
+# include "../rotfont/times8.h"
+# include "../rotfont/times12.h"
+# include "../rotfont/times14.h"
+# include "../rotfont/times18.h"
+# include "../rotfont/times24.h"
+
+# include "../rotfont/courier8.h"
+# include "../rotfont/courier12.h"
+# include "../rotfont/courier14.h"
+# include "../rotfont/courier18.h"
+# include "../rotfont/courier24.h"
+
+# include "../rotfont/helvetica8.h"
+# include "../rotfont/helvetica12.h"
+# include "../rotfont/helvetica14.h"
+# include "../rotfont/helvetica18.h"
+# include "../rotfont/helvetica24.h"
+
+# include "../rotfont/symbol8.h"
+# include "../rotfont/symbol12.h"
+# include "../rotfont/symbol14.h"
+# include "../rotfont/symbol18.h"
+# include "../rotfont/symbol24.h"
+
+# define DEFFONT 1
+static FontSet HardwiredFonts[] = {
+  {times8font,  "times", 8},
+  {times12font, "times", 12},
+  {times14font, "times", 14},
+  {times18font, "times", 18},
+  {times24font, "times", 24},
+  
+  {courier8font,  "courier", 8},
+  {courier12font, "courier", 12},
+  {courier14font, "courier", 14},
+  {courier18font, "courier", 18},
+  {courier24font, "courier", 24},
+  
+  {helvetica8font,  "helvetica", 8},
+  {helvetica12font, "helvetica", 12},
+  {helvetica14font, "helvetica", 14},
+  {helvetica18font, "helvetica", 18},
+  {helvetica24font, "helvetica", 24},
+  
+  {symbol8font,  "symbol", 8},
+  {symbol12font, "symbol", 12},
+  {symbol14font, "symbol", 14},
+  {symbol18font, "symbol", 18},
+  {symbol24font, "symbol", 24}
+};
+
+/* put these as static in RotFont.c with accessor functions */
+# define NROT 256
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/buttons.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/buttons.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/buttons.h	(revision 10836)
@@ -0,0 +1,120 @@
+#define PS_width 25
+#define PS_height 25
+static char PS_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x81, 0x3f, 0x00,
+   0x82, 0x67, 0x60, 0x00, 0x02, 0x26, 0x40, 0x00, 0x02, 0x24, 0x40, 0x00,
+   0x02, 0x24, 0x00, 0x00, 0x02, 0x24, 0x00, 0x00, 0x02, 0x24, 0x00, 0x00,
+   0x02, 0x24, 0x00, 0x00, 0x02, 0x64, 0x00, 0x00, 0x02, 0xc6, 0x00, 0x00,
+   0x82, 0x07, 0x07, 0x00, 0xfe, 0x01, 0x0c, 0x00, 0x02, 0x00, 0x18, 0x00,
+   0x02, 0x00, 0x20, 0x00, 0x02, 0x00, 0x60, 0x00, 0x02, 0x00, 0x40, 0x00,
+   0x02, 0x00, 0xc0, 0x00, 0x02, 0x10, 0x80, 0x00, 0x02, 0x10, 0xc0, 0x00,
+   0x02, 0x60, 0x60, 0x00, 0x02, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00}; 
+#define grey_width 25
+#define grey_height 25
+static char grey_bits[] = {
+   0x90, 0x40, 0xf7, 0x01, 0x04, 0xaa, 0xad, 0x01, 0x68, 0xd5, 0xfe, 0x01,
+   0x82, 0x28, 0xdb, 0x01, 0x10, 0xd2, 0x75, 0x01, 0x40, 0xad, 0xee, 0x01,
+   0xac, 0x50, 0xbf, 0x01, 0x00, 0xaa, 0xf9, 0x01, 0x52, 0xd5, 0xd6, 0x01,
+   0x80, 0x28, 0x6f, 0x01, 0x28, 0xd2, 0xfd, 0x01, 0x44, 0xad, 0xba, 0x01,
+   0x90, 0x50, 0xf7, 0x01, 0x02, 0xaa, 0xcd, 0x01, 0x68, 0xd5, 0x7e, 0x01,
+   0x80, 0x28, 0xfb, 0x01, 0x14, 0xd2, 0xb5, 0x01, 0x40, 0xad, 0xee, 0x01,
+   0xaa, 0x50, 0xdf, 0x01, 0x00, 0xaa, 0x79, 0x01, 0x50, 0xd5, 0xf6, 0x01,
+   0x84, 0x28, 0xaf, 0x01, 0x28, 0xd2, 0xfd, 0x01, 0x40, 0xad, 0xda, 0x01,
+   0x90, 0x50, 0x77, 0x01};
+#define rainbow_width 25
+#define rainbow_height 25
+static char rainbow_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0xff, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x0c, 0x7f, 0x00,
+   0x00, 0xe3, 0x80, 0x01, 0xc0, 0x9c, 0xff, 0x00, 0x20, 0x62, 0x00, 0x01,
+   0x90, 0x99, 0xff, 0x00, 0x48, 0x76, 0x00, 0x01, 0x24, 0x09, 0x00, 0x00,
+   0x94, 0x06, 0x00, 0x00, 0x52, 0x01, 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00,
+   0xa5, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
+   0x2a, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00,
+   0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00,
+   0x15, 0x00, 0x00, 0x00};
+#define recenter_width 25
+#define recenter_height 25
+static char recenter_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00,
+   0x80, 0xef, 0x03, 0x00, 0xe0, 0x00, 0x0e, 0x00, 0x30, 0x00, 0x18, 0x00,
+   0x10, 0x00, 0x10, 0x00, 0x18, 0x00, 0x30, 0x00, 0x08, 0x00, 0x20, 0x00,
+   0x0c, 0x00, 0x60, 0x00, 0x0c, 0x38, 0x60, 0x00, 0x0c, 0x7c, 0x60, 0x00,
+   0x04, 0x7c, 0x40, 0x00, 0x0c, 0x7c, 0x60, 0x00, 0x0c, 0x38, 0x60, 0x00,
+   0x0c, 0x00, 0x60, 0x00, 0x08, 0x00, 0x20, 0x00, 0x18, 0x00, 0x30, 0x00,
+   0x10, 0x00, 0x10, 0x00, 0x30, 0x00, 0x18, 0x00, 0xe0, 0x00, 0x0e, 0x00,
+   0x80, 0xef, 0x03, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define puns_width 25
+#define puns_height 25
+static char puns_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xd8, 0x01,
+   0x00, 0x0c, 0x37, 0x00, 0xf8, 0xc9, 0x6f, 0x00, 0x0c, 0xde, 0xf0, 0x00,
+   0x06, 0x5b, 0x1f, 0x00, 0x7b, 0xd9, 0x0c, 0x00, 0xc9, 0x70, 0x06, 0x00,
+   0x81, 0x71, 0x03, 0x00, 0x78, 0xb9, 0x39, 0x00, 0xc8, 0xdb, 0x0f, 0x00,
+   0x84, 0xf7, 0x7f, 0x00, 0x04, 0xff, 0xc3, 0x00, 0xe6, 0xfe, 0x8e, 0x00,
+   0x9a, 0x7d, 0x0b, 0x00, 0x08, 0xbc, 0x01, 0x00, 0x08, 0xfc, 0x3f, 0x00,
+   0x0c, 0xff, 0x78, 0x00, 0x84, 0x39, 0x60, 0x00, 0x40, 0x38, 0x40, 0x00,
+   0x60, 0x38, 0x40, 0x00, 0x20, 0x38, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00,
+   0x00, 0xd6, 0x00, 0x00};
+#define red_width 25
+#define red_height 25
+static char red_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xfc, 0x03, 0x00,
+   0x20, 0x07, 0x06, 0x00, 0xe0, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x08, 0x00,
+   0x20, 0x00, 0x08, 0x00, 0x20, 0x00, 0x08, 0x00, 0x20, 0x00, 0x08, 0x00,
+   0x20, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x06, 0x00, 0x20, 0x80, 0x01, 0x00,
+   0x20, 0xe0, 0x00, 0x00, 0x20, 0x7e, 0x00, 0x00, 0xe0, 0xc3, 0x00, 0x00,
+   0x20, 0xc0, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, 0x20, 0x80, 0x01, 0x00,
+   0x20, 0x00, 0x01, 0x00, 0x20, 0x00, 0x01, 0x00, 0x20, 0x00, 0x03, 0x00,
+   0x20, 0x00, 0x06, 0x00, 0x20, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x18, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define green_width 25
+#define green_height 25
+static char green_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x00,
+   0x00, 0x06, 0x04, 0x00, 0x80, 0x03, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x80, 0x0f, 0x00, 0x40, 0xc0, 0x30, 0x00,
+   0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x80, 0x01, 0x08, 0x00,
+   0x00, 0x03, 0x08, 0x00, 0x00, 0x7e, 0x0e, 0x00, 0x00, 0xc0, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define blue_width 25
+#define blue_height 25
+static char blue_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xfe, 0x00, 0x00,
+   0xc0, 0x83, 0x07, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x04, 0x00, 0x40, 0x00, 0x02, 0x00,
+   0x40, 0x80, 0x07, 0x00, 0x40, 0xe0, 0x0c, 0x00, 0xc0, 0x3f, 0x08, 0x00,
+   0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x06, 0x00, 0x40, 0x00, 0x02, 0x00,
+   0xc0, 0x80, 0x03, 0x00, 0x40, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define yellow_width 25
+#define yellow_height 25
+static char yellow_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x18, 0x00,
+   0x80, 0x01, 0x0c, 0x00, 0x00, 0x03, 0x06, 0x00, 0x00, 0x02, 0x02, 0x00,
+   0x00, 0x84, 0x01, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x20, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define hms_width 25
+#define hms_height 25
+static char hms_bits[] = {
+   0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+   0x02, 0x00, 0x00, 0x00, 0x02, 0x01, 0xf0, 0x00, 0x1e, 0xef, 0x89, 0x00,
+   0x22, 0x11, 0x09, 0x00, 0x22, 0x11, 0x71, 0x00, 0x22, 0x11, 0x81, 0x00,
+   0x22, 0x11, 0x89, 0x00, 0x22, 0x01, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x1e, 0xc7, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x80, 0x00,
+   0x40, 0x80, 0x80, 0x00, 0x40, 0x80, 0x80, 0x00, 0x40, 0x80, 0x80, 0x00,
+   0x40, 0x80, 0x80, 0x00, 0x5c, 0xb8, 0xb8, 0x00, 0x62, 0xc4, 0xc4, 0x00,
+   0x42, 0x84, 0x84, 0x00, 0x42, 0x84, 0x84, 0x00, 0x62, 0xc4, 0xc4, 0x00,
+   0x5c, 0xb9, 0xb8, 0x00};
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/constants.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/constants.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/constants.h	(revision 10836)
@@ -0,0 +1,45 @@
+/* hardwired values for some window parameters */
+
+# define EVENT_MASK (long) \
+(ButtonPressMask \
+ | ClientMessage \
+ | ButtonReleaseMask \
+ | KeyPressMask \
+ | ExposureMask \
+ | StructureNotifyMask \
+ | PointerMotionMask)
+
+# define DEFAULT_CURSOR XC_crosshair
+# define BORDER_WIDTH 2
+# define MIN_WIDTH 250
+# define MIN_HEIGHT 250
+# define LABEL_MAXLEN 128
+
+/* label names */
+# define LABELX0 0
+# define LABELY0 1
+# define LABELX1 2
+# define LABELY1 3
+# define LABELUL 4
+# define LABELUR 5
+# define LABELLL 6
+# define LABELLR 7
+
+/* EVENT_MASK consists of:
+
+ExposureMask        : Expose
+StructureNotifyMask : CirculateNotify | 
+                      ConfigureNotify | 
+                      DestroyNotify   | 
+		      GravityNotify   | 
+		      MapNotify       |
+		      ReparentNotify  |
+		      UnmapNotify
+ButtonPressMask     : ButtonPress
+ButtonReleaseMask   : ButtonRelease
+KeyPressMask        : KeyPress
+PointerMotionMask   : MotionNotify
+(always)            : ClientMessage 
+(always)            : MappingNotify
+
+*/
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/globals.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/globals.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/globals.h	(revision 10836)
@@ -0,0 +1,21 @@
+
+int HAVE_BACKING;
+int DEBUG;
+int USE_XWINDOW;
+int MAP_WINDOW;
+int FOREGROUND;
+char *NAME_WINDOW;
+
+/* file descriptor for socket connection to mana */
+int sock; 
+
+/* each layout / section defines one of the active portions of the graphics window
+   there may be an arbitrary number of sections, and each section may fill an arbitrary
+   rectangle in the X window.  The startup configuration assumes 1 section filling the 
+   entire X window. */
+
+Layout *section;
+int    Nsection, TheSection;
+
+/* graphic defines the basic details of the X window */
+Graphic graphic;
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/arrow.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/arrow.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/arrow.h	(revision 10836)
@@ -0,0 +1,4 @@
+#define arrow_width 6
+#define arrow_height 9
+static char arrow_bits[] = {
+   0x00, 0x02, 0x06, 0x0e, 0x1e, 0x0e, 0x06, 0x02, 0x00};
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/back.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/back.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/back.h	(revision 10836)
@@ -0,0 +1,6 @@
+#define back_width 16
+#define back_height 16
+static char back_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x3c, 0x00, 0x3f, 0xc0, 0x3f,
+   0xf0, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xf0, 0x3f, 0xc0, 0x3f, 0x00, 0x3f,
+   0x00, 0x3c, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00};
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/down.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/down.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/down.h	(revision 10836)
@@ -0,0 +1,4 @@
+#define down_width 9
+#define down_height 6
+static char down_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00};
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/fore.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/fore.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/fore.h	(revision 10836)
@@ -0,0 +1,6 @@
+#define fore_width 16
+#define fore_height 16
+static char fore_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x3c, 0x00, 0xfc, 0x00, 0xfc, 0x03,
+   0xfc, 0x0f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x0f, 0xfc, 0x03, 0xfc, 0x00,
+   0x3c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/icon.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/icon.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/icon.h	(revision 10836)
@@ -0,0 +1,13 @@
+#define icon_width 29
+#define icon_height 29
+static unsigned char icon_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x07,
+   0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04,
+   0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04, 0xfc, 0xff, 0xff, 0x07,
+   0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04,
+   0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04, 0xfc, 0xff, 0xff, 0x07,
+   0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04,
+   0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04, 0xfc, 0xff, 0xff, 0x07,
+   0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04,
+   0x04, 0x41, 0x10, 0x04, 0x04, 0x41, 0x10, 0x04, 0xfc, 0xff, 0xff, 0x07,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/stop.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/stop.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/icons/stop.h	(revision 10836)
@@ -0,0 +1,6 @@
+#define stop_width 16
+#define stop_height 16
+static char stop_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
+   0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
+   0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/prototypes.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/prototypes.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/prototypes.h	(revision 10836)
@@ -0,0 +1,132 @@
+Button       *CheckButtons        PROTO((XButtonEvent *, Layout *));
+void          CheckColors         PROTO((int *, char **));
+void          CheckDisplayName    PROTO((int *, char **, char *));
+void          CheckFontName       PROTO((int *, char **, char *));
+void          CheckGeometry       PROTO((int *, char **));
+int           CheckPipe           PROTO(());
+void          CreateWindow        PROTO((Window, int, long));
+void          DefineLayout        PROTO((int, char **));
+void          DrawConnect         PROTO((Layout *, Gobjects *));
+void          DrawFrame           PROTO((Layout *));
+void          DrawHistogram       PROTO((Layout *, Gobjects *));
+void          DrawLabels          PROTO((Layout *));
+int           DrawObjectN         PROTO((Layout *, Gobjects *));
+int           DrawObjects         PROTO((Layout *));
+void          DrawPoints          PROTO((Layout *, Gobjects *));
+void          DrawXErrors         PROTO((Layout *, Gobjects *));
+void          DrawYErrors         PROTO((Layout *, Gobjects *));
+int           ErasePlot           PROTO(());
+unsigned long GetColor            PROTO((Display *, char *, Colormap, unsigned long));
+int           GetColormapSize     PROTO(());
+char         *GetRGBString        PROTO((int N));
+int           InButton            PROTO((XButtonEvent *, Button *));
+int           InPicture           PROTO((XButtonEvent *, Picture *));
+int           ListSection         PROTO(());
+int           LoadBox             PROTO(());
+void          LoadFont            PROTO((int *, char **, char *));
+int           LoadLabels          PROTO(());
+int           LoadObject          PROTO(());
+int           LoadPtext           PROTO(());
+int           LoadVectorData      PROTO((Layout *, int, char *));
+void          MakeColormap        PROTO((int, char **));
+void          MakeCursor          PROTO((unsigned int));
+void          MapWindow           PROTO(());
+void          NameWindow          PROTO((char *));
+Display      *OpenDisplay         PROTO((char *, int *));
+int           PNGit               PROTO(());
+int           PPMit               PROTO(());
+void          PSConnect           PROTO((Layout *, Gobjects *, FILE *));
+int           PSFrame             PROTO((Layout *, FILE *));
+void          PSHistogram         PROTO((Layout *, Gobjects *, FILE *));
+void          PSLabels            PROTO((Layout *, FILE *));
+int           PSObjects           PROTO((Layout *, FILE *));
+void          PSPoints            PROTO((Layout *, Gobjects *, FILE *));
+void          PSXErrors           PROTO((Layout *, Gobjects *, FILE *));
+void          PSYErrors           PROTO((Layout *, Gobjects *, FILE *));
+int           PSit                PROTO(());
+void          PositionPicture     PROTO((Layout *));
+void          QuitX               PROTO((Display *, char *, char *));
+int           Reconfig            PROTO((XEvent *));
+void          Refresh             PROTO((int));
+void          Remap               PROTO((Layout *, Matrix  *));
+int           Resize              PROTO(());
+int           SetFont             PROTO(());
+int           SetLimits           PROTO(());
+void          SetNormalHints      PROTO(());
+int           SetSection          PROTO((int SwitchSection));
+void          SetUpDisplay        PROTO((int *, char **));
+void          SetUpWindow         PROTO((int *, char **));
+void          SetWMHints          PROTO((Icon *));
+void          TopWindow           PROTO((Icon *));
+int           cursor              PROTO(());
+int           get_argument        PROTO((int, char **, char *));
+void          hh_hms              PROTO((char *, double, double, char));
+int           remove_argument     PROTO((int, int *, char **));
+
+void MakeGC ();
+
+int EventLoop ();
+void CloseDisplay ();
+int args (int *argc, char **argv);
+
+void DrawPtext (Layout *layout);
+void FlushDisplay ();
+void AxisTickScale (Axis *axis, double *major, double *minor);
+void DrawFrame (Layout *layout);
+void DrawTick (int fx, int fy, int dfx, int dfy, int P, double min, double max, double value, int mode, int naxis);
+void FreeObjectData (Gobjects *object);
+void PSPtext (Layout *layout, FILE *f);
+void PSTick (FILE *f, double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int mode, int naxis);
+
+/* kapa bDraw Functions */
+int bDrawObjects (Layout *layout);
+void bDrawConnect (Layout *layout, Gobjects *object);
+void bDrawClipLine (double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0);
+void bDrawHistogram (Layout *layout, Gobjects *object);
+void bDrawPoints (Layout *layout, Gobjects *object);
+void bDrawXErrors (Layout *layout, Gobjects *object);
+void bDrawYErrors (Layout *layout, Gobjects *object);
+
+int bDrawFrame (Layout *layout);
+void bDrawTick (double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int mode, int naxis);
+void bDrawLabels (Layout *layout);
+void bDrawPtext (Layout *layout);
+
+bDrawBuffer *bDrawIt ();
+
+/******************* XGRAPH **
+void          StatusBox           PROTO((Graphic *, Layout *));
+void          ResetColorbar       PROTO((Graphic *, Layout *, double, double));
+void          Reorient            PROTO((Graphic *, Layout *, XButtonEvent *));
+void          PaintOverlay        PROTO((Graphic *, Layout *, int));
+void          MakeGC              PROTO((Graphic *));
+void          InvertButton        PROTO((Graphic *, Button *));
+void          FlashButton         PROTO((Graphic *, Button *));
+void          DrawButton          PROTO((Graphic *, Button *));
+void          DrawBitmap          PROTO((Graphic *, int, int, int, int, char *, int));
+void          DragColorbar        PROTO((Graphic *, Layout *, XButtonEvent *));
+void          CrossHairs          PROTO((Graphic *, Layout *));
+void          CreateZoom          PROTO((Layout *, Graphic *, double, double));
+void          CreatePicture       PROTO((Layout *, Graphic *));
+int           rainbow             PROTO((Graphic *, Layout *));
+int           puns                PROTO((Graphic *, Layout *));
+int           greycolors          PROTO((Graphic *, Layout *));
+int           UpdatePointer       PROTO((Graphic *, Layout *, XMotionEvent *));
+int           ToggleDEG           PROTO((Graphic *, Layout *));
+int           Stop                PROTO((Graphic *, Layout *));
+int           SaveOverlay         PROTO((Graphic *, Layout *));
+int           Rescale             PROTO((Graphic *, Layout *));
+int           RecenterRescale     PROTO((Graphic *, Layout *));
+int           Recenter            PROTO((Graphic *, Layout *));
+int           Overlay3            PROTO((Graphic *, Layout *));
+int           Overlay2            PROTO((Graphic *, Layout *));
+int           Overlay1            PROTO((Graphic *, Layout *));
+int           Overlay0            PROTO((Graphic *, Layout *));
+int           NewPicture          PROTO((Graphic *, Layout *));
+int           LoadOverlay         PROTO((Graphic *, Layout *));
+int           InterpretPresses    PROTO((Graphic *, Layout *, XButtonEvent *));
+int           InterpretKeys       PROTO((Graphic *, Layout *, XEvent *));
+int           EventLoop           PROTO((Graphic *, Layout *));
+int           EraseOverlay        PROTO((Graphic *, Layout *));
+int           CSaveOverlay        PROTO((Graphic *, Layout *));
+*/
Index: /tags/kapa-1-7-0/Ohana/src/kapa/include/structures.h
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/include/structures.h	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/include/structures.h	(revision 10836)
@@ -0,0 +1,120 @@
+
+/**************** Graphic carries X info around ****************/
+typedef struct {
+  Display       *display;
+  int            screen;
+  int            depth;
+  Window         window;
+  GC             gc;
+  XFontStruct   *font;
+  Cursor         cursor;
+  int            x,  y;
+  int            dx, dy;
+  Colormap       colormap;
+  unsigned long  fore;
+  unsigned long  back;
+  unsigned long  *color;
+} Graphic;
+
+/**************** X related "widget" structures ****************/
+typedef struct {
+  int      x, y, dx, dy;      /* position and size */
+  int      text;              /* does this have a picture or text? */
+  int      width, height;
+  char    *bitmap;          /* picture on button */
+  int    (*function_1) ();  /* mouse_button 1 function */
+  int    (*function_2) ();  /* mouse_button 2 function */
+  int    (*function_3) ();  /* mouse_button 3 function */
+} Button;
+
+typedef struct {
+  int      x, y, dx, dy;   /* position and size */
+  char    *label;          /* label on TextLine */
+  char     text[1024];     /* words of TextLine */
+  char     old_text[1024]; /* words of TextLine */
+  int      outline;        /* draw an outline?  */ 
+  int      cursor;         /* location of cursor (if selected) */
+  int    (*function) ();   /* textline function */
+} TextLine;
+
+typedef char STRING[1024];
+
+typedef struct {
+  int      x, y, dx, dy;   /* position and size */
+  STRING  *text;           /* words of TextLine */
+  int      Nlines;
+  int      outline;        /* draw an outline?  */ 
+  int      cursor_line;    /* cursor line */
+  int      cursor_x;       /* location of cursor (if selected) */
+  int      cursor_y;       /* location of cursor (if selected) */
+  int    (*function) ();   /* textline function */
+} TextBox;
+
+/**************** general structures ****************/
+typedef struct {
+  Pixmap pixmap;
+  int    width;
+  int    height;
+  unsigned char *bits;
+} Icon;
+
+typedef struct {
+  int      dx, dy, x, y;
+  XImage  *pix;
+  char    *data;
+} Picture;
+
+typedef struct {
+  char type[10];
+  double x, y;
+  double dx, dy;
+  double angle;
+  char  *text;
+} Object;
+
+typedef struct {
+  int x, y;
+  int dx, dy;
+  double angle;
+  int  size;
+  char font[64]; 
+  char text[LABEL_MAXLEN];
+} Label;
+
+typedef struct {
+  int Nobjects;
+  unsigned long color;
+  Object *objects;
+} Overlay;
+  
+typedef struct {
+  float *x, *y, *z, *dxp, *dxm, *dyp, *dym;
+  int Npts;
+  int style, ptype, ltype, color, etype, ebar;
+  double lweight, size;
+  double x0, x1, y0, y1;  /* limits for this object */
+} Gobjects;
+
+typedef struct {
+  double min, max;
+  char isaxis, areticks, islabel, islog;
+  double fx, dfx, fy, dfy;  /* axis location on graphic */
+} Axis;
+
+/******** Here we define the Layout struct specific to this program  *******/
+typedef struct {
+  Axis      axis[4];    /* coordinate axes */
+  Label     label[8];   /* fixed axis labels */
+
+  Gobjects *objects;    /* graphic objects */    
+  int      Nobjects;    
+
+  Label    *ptext;      /* placed text labels */
+  int      Nptext;      
+
+  double   x, dx;      /* location of plot on window ( 0 - 1, 0 - 1 ) */
+  double   y, dy; 
+
+  char     name[LABEL_MAXLEN];  /* name of the section */
+
+} Layout;
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckColors.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckColors.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckColors.c	(revision 10836)
@@ -0,0 +1,40 @@
+# include "Ximage.h"
+
+/************** CheckColors *************/
+void CheckColors (int *argc, char **argv) {
+
+  char *temp_name;
+  int N;
+
+  graphic.fore = BlackPixel (graphic.display, graphic.screen);
+  temp_name = XGetDefault (graphic.display, argv[0], "Foreground");
+  if ((N = get_argument (*argc, argv, "-fg"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -fg color\n");
+      exit (0);
+    }
+  }
+  if (temp_name != (char *) NULL) 
+    graphic.fore = GetColor (graphic.display, temp_name, graphic.colormap, graphic.fore);
+
+  graphic.back = WhitePixel (graphic.display, graphic.screen);
+  temp_name = XGetDefault (graphic.display, argv[0], "Background");
+  if ((N = get_argument (*argc, argv, "-bg"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -bg color\n");
+      exit (0);
+    }
+  }  
+  if (temp_name != (char *)NULL) 
+    graphic.back = GetColor (graphic.display, temp_name, graphic.colormap, graphic.back);
+ 
+}
+
+  /* here we define the values for foreground and background
+     if -fg, or -bg exist, or if Foreground or Background are set in .Xdefaults, 
+     use those.  foreground defaults to black, background defaults to white. */
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckDisplayName.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckDisplayName.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckDisplayName.c	(revision 10836)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+/************** CheckDisplayName *************/
+void CheckDisplayName (int *argc, char **argv, char *display_name) {
+
+  int N;
+
+  display_name[0] = 0;
+  if ((N = get_argument (*argc, argv, "-d"))) {
+    if (N + 1 < *argc) {
+      strcpy (display_name, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is [-display/-d] DisplayName\n");
+      exit (0);
+    }
+  }
+
+  if ((N = get_argument (*argc, argv, "-display"))) {
+    if (N + 1 < *argc) {
+      strcpy (display_name, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is [-display/-d] DisplayName\n");
+      exit (0);
+    }
+  }
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckFontName.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckFontName.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckFontName.c	(revision 10836)
@@ -0,0 +1,28 @@
+# include "Ximage.h"
+
+/************** CheckFontName *************/
+void CheckFontName (int *argc, char **argv, char *fontname) {
+
+  int N;
+
+  if ((N = get_argument (*argc, argv, "-font"))) {
+    if (N + 1 < *argc) {
+      strcpy (fontname, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is -font fontname\n");
+      exit (0);
+    }
+  }   
+  if ((N = get_argument (*argc, argv, "-fn"))) {
+    if (N + 1 < *argc) {
+      strcpy (fontname, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is -fn fontname\n");
+      exit (0);
+    }
+  }   
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckGeometry.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckGeometry.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/CheckGeometry.c	(revision 10836)
@@ -0,0 +1,44 @@
+# include "Ximage.h"
+
+/************** CheckGeometry *************/
+void CheckGeometry (int *argc, char **argv) {
+
+  int status, x, y, N;
+  unsigned int dx, dy;
+  int X, Y, dX, dY;
+  char *temp_name;
+  
+  temp_name = XGetDefault (graphic.display, argv[0], "geometry");
+  if ((N = get_argument (*argc, argv, "-geom"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -geom DisplayName\n");
+      exit (0);
+    }
+  }
+
+  X = 10;
+  Y = 10;
+  dX = 512;
+  dY = 512;
+  if (temp_name != (char *)NULL) {  
+    status = XParseGeometry (temp_name, &x, &y, &dx, &dy);
+    if (status & XValue) X = x;
+    if (status & YValue) Y = y;
+    if (status & WidthValue) {
+      dX = dx;
+    }
+    if (status & HeightValue) {
+      dY = dy;
+    }
+    if (status & XNegative) X  = DisplayWidth  (graphic.display, graphic.screen) - dX + X;
+    if (status & YNegative) Y  = DisplayHeight (graphic.display, graphic.screen) - dY + Y;
+  }
+
+  graphic.x = X;
+  graphic.y = Y;
+  graphic.dx = dX;
+  graphic.dy = dY; 
+  
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/CloseDisplay.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/CloseDisplay.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/CloseDisplay.c	(revision 10836)
@@ -0,0 +1,12 @@
+# include "Ximage.h"
+
+/************** CloseDisplay *************/
+void CloseDisplay () {
+  XFreeFont (graphic.display, graphic.font); 
+  XFreeGC (graphic.display, graphic.gc);
+  XDestroySubwindows (graphic.display, graphic.window);
+  XDestroyWindow (graphic.display, graphic.window);
+  XFlush (graphic.display);
+  XCloseDisplay (graphic.display);
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/CreateWindow.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/CreateWindow.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/CreateWindow.c	(revision 10836)
@@ -0,0 +1,34 @@
+# include "Ximage.h"
+
+/************** CreateWindow *************/
+void CreateWindow (Window parent, int border, long events) {
+
+  XSetWindowAttributes attributes;
+  unsigned long attribute_mask;
+  Visual *visual = CopyFromParent;
+
+  HAVE_BACKING = (DoesBackingStore (ScreenOfDisplay(graphic.display, graphic.screen)) == Always);
+
+  if (HAVE_BACKING) {
+    attributes.backing_store = Always;
+    attribute_mask = CWBackingStore | CWBackPixel | CWBorderPixel | CWEventMask;
+  } else {
+    attribute_mask = CWBackPixel | CWBorderPixel | CWEventMask;
+  }
+
+  attributes.background_pixel = graphic.back;
+  attributes.border_pixel     = graphic.fore;
+  attributes.event_mask       = events;
+
+  graphic.window = XCreateWindow (graphic.display, parent, 
+				     graphic.x, graphic.y, 
+				     graphic.dx, graphic.dy, 
+				     border, CopyFromParent,
+				     InputOutput, visual, 
+				     attribute_mask, &attributes);
+
+  if (graphic.window == (Window) None)
+    QuitX (graphic.display, "", "error: could not open window");
+
+  XSelectInput (graphic.display, graphic.window, events);
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/DefineLayout.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/DefineLayout.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/DefineLayout.c	(revision 10836)
@@ -0,0 +1,56 @@
+# include "Ximage.h"
+# define PAD 40
+
+/* general initialization for things not specific to X */
+void DefineLayout (int argc, char **argv) {
+
+  int i;
+  
+  /** initiate connection with server **/
+  if (!FOREGROUND) {	
+    if (argc < 2) {
+      fprintf (stderr, "socket path not specified\n");
+      exit (0);
+    }
+    sock = KiiWait (argv[1]);
+  }
+
+  InitRotFonts ();
+
+  /** set up defaults for display region **/
+  /* default startup uses one graphic region, filling the window */
+  
+  Nsection = 1;
+  ALLOCATE (section, Layout, Nsection);
+  TheSection = 0;
+
+  /* set up axis positions */
+  for (i = 0; i < 4; i++) {
+    section[0].axis[i].min = 0.0;
+    section[0].axis[i].max = 1.0;
+    section[0].axis[i].isaxis = FALSE;
+    section[0].axis[i].areticks = FALSE;
+    section[0].axis[i].islabel = FALSE;
+  }    
+  for (i = 0; i < 8; i++) {
+    strcpy (section[0].label[i].text, "");
+  }
+  section[0].x  = 0;
+  section[0].dx = 1; 
+  section[0].y  = 0; 
+  section[0].dy = 1; 
+  strcpy (section[0].name, "default");
+
+  PositionPicture (&section[0]);
+
+  section[0].Nobjects = 0;
+  section[0].Nptext = 0;
+
+  ALLOCATE (section[0].objects, Gobjects, 1);  /* allocate so later free will not crash! */
+  section[0].objects[0].x   = section[0].objects[0].y   = section[0].objects[0].z = (float *) NULL;
+  section[0].objects[0].dxm = section[0].objects[0].dxp = (float *) NULL;
+  section[0].objects[0].dym = section[0].objects[0].dyp = (float *) NULL;
+  
+  ALLOCATE (section[0].ptext, Label, 1);       /* allocate so later free will not crash! */
+
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/GetColor.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/GetColor.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/GetColor.c	(revision 10836)
@@ -0,0 +1,25 @@
+# include "Ximage.h"
+
+/************** GetColor *************/
+unsigned long 
+GetColor (display, name, colormap, default_color)
+Display  *display;
+char      name[];
+Colormap  colormap;
+unsigned long default_color;
+{
+
+  unsigned long color;
+  XColor rgbcolor, hardwarecolor;
+  int status;
+
+  color = default_color;
+  status = XLookupColor (display, colormap, name, &rgbcolor, &hardwarecolor);
+  if (status) {
+    status = XAllocColor (display, colormap, &hardwarecolor);
+    if (status) {
+      color = hardwarecolor.pixel;
+    }
+  }
+  return (color);
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/LoadFont.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/LoadFont.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/LoadFont.c	(revision 10836)
@@ -0,0 +1,31 @@
+# include "Ximage.h"
+
+/************** LoadFont *************/
+void LoadFont (int *argc, char **argv, char *default_name) {
+
+  char name[400];
+  char *temp_name;
+
+  temp_name = XGetDefault (graphic.display, argv[0], "Font");
+  if (temp_name == (char *) NULL) 
+    strcpy (name, default_name);
+  else 
+    strcpy (name, temp_name);
+
+  CheckFontName (argc, argv, name);
+
+  graphic.font = XLoadQueryFont (graphic.display, name);
+  if (graphic.font == (XFontStruct *) NULL) {
+    fprintf (stderr, "Could not load fond %s, using %s\n", name, default_name);
+    graphic.font = XLoadQueryFont (graphic.display, default_name);
+    if (graphic.font == (XFontStruct *) NULL) {
+      graphic.font = XLoadQueryFont (graphic.display, "fixed");
+      fprintf (stderr, "Could not load fond %s, using %s\n", default_name, "fixed");
+    }
+  }
+
+  if (graphic.font != (XFontStruct *) NULL) 
+    XSetFont (graphic.display, graphic.gc, graphic.font[0].fid);
+  else
+    QuitX (graphic.display, "Error: could not load font", name);
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/MakeCursor.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/MakeCursor.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/MakeCursor.c	(revision 10836)
@@ -0,0 +1,9 @@
+# include "Ximage.h"
+
+/************** MakeCursor *************/
+void MakeCursor (unsigned int which_cursor) {
+
+  graphic.cursor = XCreateFontCursor (graphic.display, (unsigned) which_cursor);
+
+  if (graphic.cursor != (Cursor) None) XDefineCursor (graphic.display, graphic.window, graphic.cursor);
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/MakeGC.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/MakeGC.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/MakeGC.c	(revision 10836)
@@ -0,0 +1,14 @@
+# include "Ximage.h"
+
+/************** MakeGC *************/
+void MakeGC () {
+
+  XGCValues gcvalues;
+
+  gcvalues.foreground = graphic.fore;
+  gcvalues.background = graphic.back;
+  graphic.gc = XCreateGC (graphic.display, graphic.window, 
+			     GCForeground | GCBackground, &gcvalues);
+  if (graphic.gc == 0)
+    QuitX (graphic.display, "Error in creating a Graphics Context", "");
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/MapWindow.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/MapWindow.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/MapWindow.c	(revision 10836)
@@ -0,0 +1,10 @@
+# include "Ximage.h"
+
+/************** MapWindow *************/
+void MapWindow () {
+
+  XMapRaised (graphic.display, graphic.window);
+  XMapSubwindows (graphic.display, graphic.window);
+  FlushDisplay ();
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/NameWindow.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/NameWindow.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/NameWindow.c	(revision 10836)
@@ -0,0 +1,31 @@
+# include "Ximage.h"
+
+/************** NameWindow *************/
+void NameWindow (char *Name) {
+
+  char       *name;
+  char       *class_name;
+  char       *class_type;
+  XClassHint *classhints;
+
+  name = strrchr (Name, '/');
+  if (name != NULL) 
+    name ++;
+  else 
+    name = Name;
+
+  class_type = class_name = name;
+  classhints = XAllocClassHint ();
+
+  if (classhints != (XClassHint *) NULL)  {
+    classhints[0].res_name = class_name;
+    classhints[0].res_class = class_type;
+    XSetClassHint (graphic.display, graphic.window, classhints);
+    XFree (classhints);
+  }
+  
+  XStoreName (graphic.display, graphic.window, name);
+  XSetIconName (graphic.display, graphic.window, name);
+
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/OpenDisplay.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/OpenDisplay.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/OpenDisplay.c	(revision 10836)
@@ -0,0 +1,17 @@
+# include "Ximage.h"
+
+/************** OpenDisplay *************/
+Display *OpenDisplay (char *display_name, int *screen) {
+
+  Display *display;
+  
+  display = XOpenDisplay (display_name);
+  if (display != (Display *) NULL) *screen = DefaultScreen (display);
+  if (display == (Display *) NULL) {
+    fprintf (stderr, "Error could not open X display to %s\n", XDisplayName (display_name));
+    exit (0);
+  }
+  
+  return (display);
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/QuitX.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/QuitX.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/QuitX.c	(revision 10836)
@@ -0,0 +1,12 @@
+# include "Ximage.h"
+
+/************** QuitX *************/
+void QuitX (Display *display, char *error_message, char *error_file) {
+
+  fprintf (stderr, "Error: %s%s\n", error_message, error_file);
+  XCloseDisplay (display);
+  exit (0);
+
+}
+
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetNormalHints.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetNormalHints.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetNormalHints.c	(revision 10836)
@@ -0,0 +1,27 @@
+# include "Ximage.h"
+
+/************** SetNormalHints  *************/
+void SetNormalHints () {
+
+  XSizeHints *sizehints;
+
+  sizehints = XAllocSizeHints ();
+
+  if (sizehints != (XSizeHints *) NULL)  {
+    sizehints[0].x = graphic.x;
+    sizehints[0].y = graphic.x;
+    sizehints[0].width = graphic.dx;
+    sizehints[0].height = graphic.dy;
+    sizehints[0].min_width = MIN_WIDTH;
+    sizehints[0].min_height = MIN_HEIGHT;    
+    sizehints[0].flags = USPosition | USSize | PMinSize;
+
+    sizehints[0].base_width = graphic.dx;
+    sizehints[0].base_height = graphic.dy;
+    sizehints[0].flags |= PBaseSize;
+    
+    XSetWMNormalHints (graphic.display, graphic.window, sizehints);
+    XFree (sizehints);
+  }
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetUpDisplay.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetUpDisplay.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetUpDisplay.c	(revision 10836)
@@ -0,0 +1,16 @@
+# include "Ximage.h"
+
+/************** SetUpDisplay *************/
+void SetUpDisplay (int *argc, char **argv) {
+
+  char display_name[120];
+
+  CheckDisplayName (argc, argv, display_name);
+
+  graphic.display  = OpenDisplay     (display_name,   &graphic.screen);
+  graphic.colormap = DefaultColormap (graphic.display, graphic.screen);
+  graphic.depth    = DefaultDepth    (graphic.display, graphic.screen);
+  CheckColors (argc, argv);
+
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetUpWindow.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetUpWindow.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetUpWindow.c	(revision 10836)
@@ -0,0 +1,37 @@
+# include "Ximage.h"
+# include "icons/icon.h"
+
+/************** SetUpWindow *************/
+void SetUpWindow (int *argc, char **argv) {
+
+  Icon icon;
+  char *name;
+  int Ncolors;
+
+  icon.width = icon_width;
+  icon.height = icon_height;
+  icon.bits = icon_bits;
+
+  CheckGeometry (argc, argv);
+  TopWindow (&icon);
+  LoadFont (argc, argv, "fixed"); 
+
+  FlushDisplay ();
+  XSetWindowBackground (graphic.display, graphic.window, graphic.back);
+
+  SetNormalHints ();
+  SetWMHints (&icon);
+
+  if (NAME_WINDOW == NULL) {
+    NameWindow ("Kapa");
+  } else {
+    ALLOCATE (name, char, strlen(NAME_WINDOW) + 10);
+    sprintf (name, "Kapa %s", NAME_WINDOW);
+    NameWindow (name);
+    free (name);
+  }
+
+  graphic.color = KapaX11colors (graphic.display, graphic.colormap, graphic.fore, &Ncolors);
+  if (MAP_WINDOW) MapWindow (graphic);
+  return;
+}
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetWMHints.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetWMHints.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/SetWMHints.c	(revision 10836)
@@ -0,0 +1,25 @@
+# include "Ximage.h"
+
+/************** SetWMHints  *************/
+void SetWMHints (Icon *icon) {
+
+  XWMHints *wmhints;
+
+  wmhints = XAllocWMHints ();
+  if (wmhints != (XWMHints *) NULL) {
+    wmhints[0].initial_state = NormalState;
+    wmhints[0].input = True;
+    if (icon[0].pixmap != (Pixmap) None) {
+      wmhints[0].icon_pixmap = icon[0].pixmap;
+      wmhints[0].icon_mask = icon[0].pixmap;
+      wmhints[0].flags = StateHint | InputHint | IconPixmapHint | IconMaskHint;
+    } else {
+      wmhints[0].flags = StateHint | InputHint;
+    }
+    
+    XSetWMHints (graphic.display, graphic.window, wmhints);
+    XFree (wmhints);
+
+  }
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/TopWindow.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/TopWindow.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/TopWindow.c	(revision 10836)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+
+/************** TopWindow *************/
+void TopWindow (Icon *icon) {
+
+  Window rootwindow;
+
+  rootwindow = RootWindow (graphic.display, graphic.screen);
+
+  CreateWindow (rootwindow, BORDER_WIDTH, EVENT_MASK);
+  MakeGC ();
+
+  icon[0].pixmap = XCreateBitmapFromData (graphic.display, graphic.window, (char *) icon[0].bits, icon[0].width, icon[0].height);
+
+  MakeCursor (DEFAULT_CURSOR);
+  XFreeCursor (graphic.display, graphic.cursor);
+  FlushDisplay ();
+
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/Ximage.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/Ximage.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/Ximage.c	(revision 10836)
@@ -0,0 +1,22 @@
+# include "Ximage.h"
+
+int main (int argc, char **argv) {
+  
+  /* this is a lame place to put this default */
+  graphic.x = 10;
+  graphic.y = 10;
+  graphic.dx = 512;
+  graphic.dy = 512; 
+
+  args (&argc, argv);
+
+  if (USE_XWINDOW) SetUpDisplay (&argc, argv); /* skip if Xless */
+  if (USE_XWINDOW) SetUpWindow (&argc, argv);  /* skip if Xless */
+
+  DefineLayout (argc, argv); 
+  EventLoop ();
+
+  if (USE_XWINDOW) CloseDisplay ();
+  exit (0);
+}
+
Index: /tags/kapa-1-7-0/Ohana/src/kapa/setup/args.c
===================================================================
--- /tags/kapa-1-7-0/Ohana/src/kapa/setup/args.c	(revision 10836)
+++ /tags/kapa-1-7-0/Ohana/src/kapa/setup/args.c	(revision 10836)
@@ -0,0 +1,40 @@
+# include "Ximage.h"
+
+int args (int *argc, char **argv) {
+
+  int N;
+
+  MAP_WINDOW = TRUE;
+  if ((N = get_argument (*argc, argv, "-nomap"))) {
+    remove_argument(N, argc, argv);
+    MAP_WINDOW = FALSE;
+  }
+
+  NAME_WINDOW = NULL;
+  if ((N = get_argument (*argc, argv, "-name"))) {
+    remove_argument(N, argc, argv);
+    NAME_WINDOW = strcreate (argv[N]);
+    remove_argument(N, argc, argv);
+  }
+
+  USE_XWINDOW = TRUE;
+  if ((N = get_argument (*argc, argv, "-noX"))) {
+    remove_argument(N, argc, argv);
+    USE_XWINDOW = FALSE;
+  }
+
+  if ((N = get_argument (*argc, argv, "-debug"))) {
+    remove_argument(N, argc, argv);
+    DEBUG = TRUE;
+  } else {
+    DEBUG = FALSE;
+  }
+
+  FOREGROUND = FALSE;
+  if ((N = get_argument (*argc, argv, "-fg"))) {
+    remove_argument(N, argc, argv);
+    FOREGROUND = TRUE;
+  }
+
+  return (TRUE);
+}
