# include "data.h"

int cumulative (int argc, char **argv) {
  
  int i;
  float *Vi, *Vo;
  Vector *ivec, *ovec;

  if (argc != 3) {
    gprint (GP_ERR, "USAGE: cumulative invec outvec\n");
    return (FALSE);
  }

  if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
  if ((ovec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE);
  ovec[0].Nelements = ivec[0].Nelements;
    
  REALLOCATE (ovec[0].elements, float, ovec[0].Nelements);
  bzero (ovec[0].elements, sizeof(float)*ovec[0].Nelements);

  Vi = ivec[0].elements;
  Vo = ovec[0].elements;
  *Vo = *Vi;
  for (i = 1; i < ivec[0].Nelements; i++, Vi++, Vo++) {
    *Vo = Vo[-1] + *Vi;
  }      
  return (TRUE);
}
