# include "display.h"

int PlotVectorSingle (int kapa, Vector *vec, char *mode) {

  int i, Npts;
  float *temp;

  Npts = vec->Nelements;
  ALLOCATE (temp, float, Npts);

  if (vec->type == OPIHI_FLT) {
    opihi_flt *value = vec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = vec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, mode);

  free (temp);

  return (TRUE);
}

int PlotVectorPair (int kapa, Vector *xVec, Vector *yVec, Graphdata *graphmode) {

  int i, Npts;
  float *temp;

  if (xVec->Nelements != yVec->Nelements) return (FALSE);
  Npts = xVec->Nelements;

  ALLOCATE (temp, float, Npts);

  KapaPrepPlot (kapa, Npts, graphmode);

  if (xVec->type == OPIHI_FLT) {
    opihi_flt *value = xVec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = xVec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, "x");

  if (yVec->type == OPIHI_FLT) {
    opihi_flt *value = yVec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = yVec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, "y");

  free (temp);

  return (TRUE);
}

int PlotVectorTriplet (int kapa, Vector *xVec, Vector *yVec, Vector *zVec, Graphdata *graphmode) {

  int i, Npts;
  float *temp;

  if (xVec->Nelements != yVec->Nelements) return (FALSE);
  if (xVec->Nelements != zVec->Nelements) return (FALSE);
  Npts = xVec->Nelements;

  ALLOCATE (temp, float, Npts);

  KapaPrepPlot (kapa, Npts, graphmode);

  if (xVec->type == OPIHI_FLT) {
    opihi_flt *value = xVec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = xVec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, "x");

  if (yVec->type == OPIHI_FLT) {
    opihi_flt *value = yVec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = yVec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, "y");

  if (zVec->type == OPIHI_FLT) {
    opihi_flt *value = zVec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = zVec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, "z");

  free (temp);

  return (TRUE);
}

int PlotVectorPairErrors (int kapa, Vector *xVec, Vector *yVec, Vector *dyVec, Graphdata *graphmode) {

  int i, Npts;
  float *temp;

  if (xVec->Nelements != yVec->Nelements) return (FALSE);
  if (xVec->Nelements != dyVec->Nelements) return (FALSE);
  Npts = xVec->Nelements;

  ALLOCATE (temp, float, Npts);

  KapaPrepPlot (kapa, Npts, graphmode);

  if (xVec->type == OPIHI_FLT) {
    opihi_flt *value = xVec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = xVec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, "x");

  if (yVec->type == OPIHI_FLT) {
    opihi_flt *value = yVec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = yVec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, "y");

  if (dyVec->type == OPIHI_FLT) {
    opihi_flt *value = dyVec->elements.Flt;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  } else {
    opihi_int *value = dyVec->elements.Int;
    for (i = 0; i < Npts; i++) {
      temp[i] = value[i];
    }
  }
  KapaPlotVector (kapa, Npts, temp, "dym");
  KapaPlotVector (kapa, Npts, temp, "dyp");

  free (temp);

  return (TRUE);
}

