# include "data.h"

int create (int argc, char **argv) {
  
  int i, N, INT;
  float start, end, delta;
  Vector *vec;
  
  INT = FALSE;
  if ((N = get_argument (argc, argv, "-int"))) {
    INT = TRUE;
    remove_argument (N, &argc, argv);
  }

  if ((argc != 5) && (argc != 4)) {
    gprint (GP_ERR, "USAGE: create vector start end [delta]\n");
    return (FALSE);
  }

  if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) return (FALSE);

  start = atof (argv[2]);
  end   = atof (argv[3]);
  delta = 1;
  if (argc == 5) delta = atof (argv[4]);
  if ((start == end) || (delta == 0)) {
    gprint (GP_ERR, "error in value: %f to %f, %f\n", start, end, delta);
    return (FALSE);
  }
  delta = fabs (delta);
  if (end - start < 0) {
    delta = -1.0 * delta;
  }

  if (INT && (delta != (int)delta)) {
    gprint (GP_ERR, "integer vector requested but fractional step-size specified\n");
    return (FALSE);
  }

  vec[0].Nelements = (end - start) / delta;

  if (INT) {
    vec[0].type = OPIHI_INT;
    REALLOCATE (vec[0].elements.Int, opihi_int, vec[0].Nelements);
    for (i = 0; i < vec[0].Nelements; i++) {
      vec[0].elements.Int[i] = start + i*delta;
    }
  } else {
    vec[0].type = OPIHI_FLT;
    REALLOCATE (vec[0].elements.Flt, opihi_flt, vec[0].Nelements);
    for (i = 0; i < vec[0].Nelements; i++) {
      vec[0].elements.Flt[i] = start + i*delta;
    }
  }

  return (TRUE);
}
