# include "data.h"

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

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

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

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

  if (SelectScalar (argv[1], &value)) {
    Nin = ovec[0].Nelements;
    ovec[0].Nelements++;
    REALLOCATE (ovec[0].elements, float, ovec[0].Nelements);
    ovec[0].elements[Nin] = value;
    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);
    
}
