# include "imregister.h"
# include "spreg.h"

void DeleteSubset (int *match, int Nmatch) {

  int i, j;
  int *keep, Nbad, Nspectrum, Nsubset;
  Spectrum *spectrum, *subset;

  spectrum = get_spectra (&Nspectrum);

  ALLOCATE (keep, int, MAX (Nspectrum, 1));
  for (i = 0; i < Nspectrum; i++) keep[i] = TRUE;
  fprintf (stderr, "total of %d spectra\n", Nspectrum);

  Nbad = 0;
  for (i = 0; i < Nmatch; i++) {
    j = match[i];
    if (j == -1) continue;
    keep[j] = FALSE;
    Nbad ++;
  }
  fprintf (stderr, "delete %d spectra\n", Nbad);

  Nsubset = Nspectrum - Nbad;
  ALLOCATE (subset, Spectrum, MAX (1, Nsubset));
  fprintf (stderr, "keeping %d spectra\n", Nsubset);
  for (j = i = 0; i < Nspectrum; i++) {
    if (!keep[i]) continue;
    subset[j] = spectrum[i];
    j++;
  }

  free (keep);
  set_spectra (subset, Nsubset);

  save_db ();
  exit (0);

}
