# include "astro.h"

int cplot (int argc, char **argv) {
  
  int i, Npts, Ngraph;
  float *x, *y, *r, *d, Rmin, Rmax;
  Vector Xvec, Yvec, *xvec, *yvec;
  Graphdata graphmode;

  if (argc != 3) {
    fprintf (stderr, "USAGE: cplot <ra> <dec>\n");
    return (FALSE);
  }
  
  Ngraph = 0;
  if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);

  Rmin = graphmode.coords.crval1 - 182.0;
  Rmax = graphmode.coords.crval1 + 182.0;

  /* find vectors */
  if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
  if ((yvec = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);

  if (xvec[0].Nelements != yvec[0].Nelements) {
    fprintf (stderr, "vectors are not the same length\n");
    return (FALSE);
  }

  ALLOCATE (Xvec.elements, float, xvec[0].Nelements);
  ALLOCATE (Yvec.elements, float, xvec[0].Nelements);
    
  Xvec.Nelements = xvec[0].Nelements;
  Yvec.Nelements = xvec[0].Nelements;
  
  r = xvec[0].elements;
  d = yvec[0].elements;
  x = Xvec.elements;
  y = Yvec.elements;
  
  for (i = 0; i < Xvec.Nelements; i++, r++, d++, x++, y++) {
    while (*r < Rmin) *r += 360.0;
    while (*r > Rmax) *r -= 360.0;
    fRD_to_XY (x, y, *r, *d, &graphmode.coords);
  }
  
  
  Npts = Xvec.Nelements;
  graphmode.etype = 0;
  PrepPlotting (Npts, &graphmode);
  PlotVector (Npts, Xvec.elements);
  PlotVector (Npts, Yvec.elements);
  
  free (Xvec.elements);
  free (Yvec.elements);
    
  return (TRUE);

}

