# include "display.h"

static int Xgraph;

int PrepPlotting (int Npts, Graphdata *graphmode) {

  if (!GetGraph (NULL, &Xgraph, NULL)) return (FALSE);
  
  /* tell kapa to look for the incoming image */
  KiiSendCommand (Xgraph, 4, "PLOT"); 
  
  /* send Xgraph the plot details */
  KiiSendMessage (Xgraph, "%8d %8d %d %d %d %d %d %f %f", 
		  Npts, graphmode[0].style, 
		  graphmode[0].ptype, graphmode[0].ltype, 
		  graphmode[0].etype, graphmode[0].ebar, graphmode[0].color, 
		  graphmode[0].lweight, graphmode[0].size);
  KiiSendMessage (Xgraph, "%g %g %g %g", 
		  graphmode[0].xmin, graphmode[0].xmax, 
		  graphmode[0].ymin, graphmode[0].ymax);
  return (TRUE);
}

int PlotVector (int Npts, float *values) {

  int Nbytes;

  Nbytes = Npts * sizeof (float);
  write (Xgraph, values, Nbytes);
  return (TRUE);
}

int PlotVectorPair (int N, float *xValues, float *yValues, Graphdata *graphmode) {

    PrepPlotting (N, graphmode);
    PlotVector (N, xValues);
    PlotVector (N, yValues);

    return (TRUE);
}

int PlotVectorTriplet (int N, float *xValues, float *yValues, float *zValues, Graphdata *graphmode) {

    PrepPlotting (N, graphmode);
    PlotVector (N, xValues);
    PlotVector (N, yValues);
    PlotVector (N, zValues);

    return (TRUE);
}

/* we don't use GetGraph in PlotVector because it flushes the connection */
