# include "data.h"

int zplot (int argc, char **argv) {
  
  int i, kapa, Npts;
  float *in, *out;
  double min, range;
  Graphdata graphmode;
  Vector *xvec, *yvec, *zvec, Zvec;

  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);

  if (argc != 6) {
    gprint (GP_ERR, "USAGE: zplot <x> <y> <z> min max\n");
    return (FALSE);
  }

  min = atof(argv[4]);
  range = atof(argv[5]) - min;

  /* find vectors */
  if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
  if ((yvec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
  if ((zvec = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
  if (xvec[0].Nelements != yvec[0].Nelements) {
    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[2]);
    return (FALSE);
  }
  if (xvec[0].Nelements != zvec[0].Nelements) {
    gprint (GP_ERR, "vectors %s and %s not the same length\n", argv[1], argv[3]);
    return (FALSE);
  }
  Zvec.Nelements = zvec[0].Nelements;
  ALLOCATE (Zvec.elements, float, Zvec.Nelements);
 
  in = zvec[0].elements;
  out = Zvec.elements;
  for (i = 0; i < Zvec.Nelements; i++, in++, out++) {
    *out = MIN (1.0, MAX (0.01, (*in - min) / range));
  }

  /* point size determined by Zvec */
  graphmode.style = 2; /* plot points */
  graphmode.size = -1; /* point size determined by Zvec */
  graphmode.etype = 0; /* no errorbars */
  Npts = xvec[0].Nelements;
  PlotVectorTriplet (kapa, Npts, xvec[0].elements, yvec[0].elements, Zvec.elements, &graphmode);

  free (Zvec.elements);

  return (TRUE);

}


