# include "uniphot.h"

int main (int argc, char **argv) {

  off_t Nimage;
  int status, Nzpts;
  FITS_DB db;
  ZptTable *zpts;
  Image *image;

  /* get configuration info, args, lockfile */
  initialize_setphot (argc, argv);

  set_db (&db);
  status = dvo_image_lock (&db, ImageCat, 60.0, (UPDATE ? LCK_XCLD : LCK_SOFT));
  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
  if (db.dbstate == LCK_EMPTY) Shutdown ("ERROR: No images in catalog %s (1)", db.filename);

  zpts = load_zpt_table (argv[1], &Nzpts);

  // load images 
  image  = load_images_setphot (&db, &Nimage);
  if (!UPDATE) dvo_image_unlock (&db); 
  
  match_zpts_to_images (image, Nimage, zpts, Nzpts);

  update_setphot(image, Nimage);

  // write image table
  if (UPDATE) {
    dvo_image_save (&db, VERBOSE);
  }

  exit (0);
}
  

/* setphot : set the zero points for images in the db (perhaps based on external information)
   setphot (zpt_table)

 * load text table of zpts, time (photcode?)
 * load images
 * match images to zpts
 * set zpts
 * load catalogs
 * update detection (& averages?)

 */

