# include "data.h"

int dimendown (int argc, char **argv) {
  
  int i, Nx, Ny, Npix;
  float *in, *out;
  Vector *vec;
  Buffer *buf;

  if (argc != 3) {
    fprintf (stderr, "USAGE: dimendown <buffer> <vector>\n");
    return (FALSE);
  }

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

  Nx = buf[0].matrix.Naxis[0];
  Ny = buf[0].matrix.Naxis[1];
  Npix = Nx * Ny;

  vec[0].Nelements = Npix;
  REALLOCATE (vec[0].elements, float, Npix);

  in = (float *) buf[0].matrix.buffer;
  out = vec[0].elements;

  for (i = 0; i < Npix; i++, in++, out++) {
    *out = *in;
  }

  return (TRUE);
}

