# include "uniphot.h"

void update_dvo_catalog (Catalog *catalog, Group *sgroup, int warn) {

  int i, j, m, found;
  int Nsec, Nsecfilt;
  PhotCode *code;

  Nsec = GetPhotcodeNsec (photcode[0].code);
  Nsecfilt = GetPhotcodeNsecfilt ();

  found = 0;    
  for (i = 0; i < catalog[0].Naverage; i++) {
    
    if (catalog[0].secfilt[i*Nsecfilt+Nsec].M != NO_MAG) {
      catalog[0].secfilt[i*Nsecfilt+Nsec].M += sgroup[0].M;
    }

    m = catalog[0].average[i].offset;
    for (j = 0; j < catalog[0].average[i].Nm; j++, m++) {
      code = GetPhotcodebyCode (catalog[0].measure[m].photcode);
      if (code == NULL) continue;
      if (code[0].type != PHOT_DEP) continue;
      if (code[0].equiv != photcode[0].code) continue;
      catalog[0].measure[m].Mcal -= sgroup[0].M;
      found ++;
    }
  }

  if (found) {
    fprintf (stderr, "found %d matches\n", found);
    if (warn) fprintf (stderr, "warning: updated values, perhaps out of range?\n");
  }
}
