# include "data.h"

int concat (int argc, char **argv) {

  int  i, j, Nin;
  char *end;
  double value;
  Vector *ivec, *ovec;

  /** check basic syntax **/
  if (argc != 3) {
    fprintf (stderr, "SYNTAX: concat (vector/value) vector\n");
    fprintf (stderr, "  concatanate (vector/value) to vector\n");
    return (FALSE);
  }

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

  /* if argv[1] is a number, use just that */
  value = strtod (argv[1], &end);
  if (end == argv[1] + strlen(argv[1])) {
    Nin = ovec[0].Nelements;
    ovec[0].Nelements++;
    REALLOCATE (ovec[0].elements, float, ovec[0].Nelements);
    ovec[0].elements[Nin] = atof (argv[1]);
    return (TRUE);
  } 
  
  if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
  
  REALLOCATE (ovec[0].elements, float, ovec[0].Nelements + ivec[0].Nelements);
  for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
    ovec[0].elements[j] = ivec[0].elements[i];
  }
  ovec[0].Nelements += ivec[0].Nelements;
  
  return (TRUE);
    
}
