# include "data.h"

int uniq (int argc, char **argv) {
  
  int Nnew, i, j, found;
  float *v1, *v2;
  Vector *ivec, *ovec;

  if (argc != 3) {
    gprint (GP_ERR, "USAGE: uniq (in) (out)\n");
    return (FALSE);
  }

  if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
  if ((ovec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE);

  /* allocate the maximum possible needed */
  ALLOCATE (ovec[0].elements, float, ivec[0].Nelements);

  Nnew = 0;
  v1 = ivec[0].elements;
  for (i = 0; i < ivec[0].Nelements; i++, v1++) {
    v2 = ovec[0].elements;
    found = FALSE;
    for (j = 0; !found && (j < Nnew); j++, v2++) {
      if (*v1 == *v2) found = TRUE;
    }
    if (!found) {
      ovec[0].elements[Nnew] = *v1;
      Nnew ++;
    }
  }

  ovec[0].Nelements = Nnew;
  REALLOCATE (ovec[0].elements, float, ovec[0].Nelements);

  return (TRUE);
}

