Index: branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/args.c
===================================================================
--- branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/args.c	(revision 34681)
+++ branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/args.c	(revision 34682)
@@ -55,4 +55,11 @@
     remove_argument (N, argc, argv);
   }
+  if ((N = get_argument (*argc, argv, "-photcodes"))) {
+    if (MODE != MODE_IMAGEFILE) usage();
+    MODE = MODE_PHOTCODES;
+    remove_argument (N, argc, argv);
+    PHOTCODE_LIST = strcreate(argv[N]);
+    remove_argument (N, argc, argv);
+  }
   if ((N = get_argument (*argc, argv, "-time"))) {
     if (MODE != MODE_IMAGEFILE) usage();
@@ -86,4 +93,5 @@
     usage ();
   }
+
 goodtime:
 
Index: branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delete_photcodes.c
===================================================================
--- branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delete_photcodes.c	(revision 34682)
+++ branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delete_photcodes.c	(revision 34682)
@@ -0,0 +1,147 @@
+# include "delstar.h"
+
+void delete_times (FITS_DB *db) {
+
+  int found, code;
+  off_t i, j, k, n;
+  off_t Nimage, Nimlist;
+  off_t Nregions, NREGIONS;
+  off_t *imlist;
+  SkyList *skylist, *skyset;
+  SkyTable *sky;
+  Image *image;
+  Catalog catalog;
+
+  photcodesDrop = ParsePhotcodeList (PHOTCODE_LIST, &NphotcodesDrop, FALSE);
+
+  /* load sky from correct table */
+  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+
+  // determine the populated SkyRegions overlapping the requested area (default depth)
+  skylist = SkyListByPatch (sky, -1, &UserPatch);
+
+  // delete images with these photcodes
+  delete_photcodes_images (db, photcodesDrop, NphotcodesDrop);
+
+  // delete images with these photcodes
+  delete_photcodes_catalogs (db, photcodesDrop, NphotcodesDrop);
+
+}
+
+void delete_photcodes_catalogs (skylist, photcodesDrop, NphotcodesDrop) {
+
+  // XXX need to decide how to determine PARALLEL mode...
+  if (PARALLEL && !hostID) {
+    delete_photcodes_parallel (skylist, photcodesDrop, NphotcodesDrop);
+    return TRUE;
+  }
+
+  // delete detections from region
+  for (i = 0; i < skylist[0].Nregions; i++) {
+
+    // does this host ID match the desired location for the table?
+    if (!HostTableTestHost(skylist[0].regions[i], hostID)) continue;
+
+    // set up the basic catalog info
+    // set up the basic catalog info
+    char hostfile[1024];
+    snprintf (hostfile, 1024, "%s/%s.cpt", hostpath, skylist[0].regions[i]->name);
+    catalog.filename  = hostID ? hostfile : skylist[0].filename[i];
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+
+    if (VERBOSE) fprintf (stderr, "deleting from %s\n", catalog.filename);
+
+    // an error exit status here is a significant error
+    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "a")) {
+      fprintf (stderr, "ERROR: failure to open catalog file %s\n", catalog.filename);
+      exit (2);
+    }
+    if (!catalog.Naves_disk) {
+      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
+      continue;
+    }
+
+    find_matches (&catalog, code, START, END);
+    dvo_catalog_save (&catalog, VERBOSE);
+    dvo_catalog_unlock (&catalog);
+    dvo_catalog_free (&catalog);
+  }
+  return TRUE;
+}
+
+// CATDIR is supplied globally
+# define DEBUG 1
+int delete_photcodes__parallel (SkyList *sky) {
+
+  // launch the delstar_client jobs to the parallel hosts
+
+  // load the list of hosts
+  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
+  if (!table) {
+    fprintf (stderr, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
+    exit (1);
+  }    
+
+  int i;
+  for (i = 0; i < table->Nhosts; i++) {
+
+    // ensure that the paths are absolute path names
+    char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
+    free (table->hosts[i].pathname);
+    table->hosts[i].pathname = tmppath;
+
+    // options / arguments that can affect relphot_client -update-objects:
+    // VERBOSE, VERBOSE2
+    // KEEP_UBERCAL
+    // RESET (-reset)
+    // TimeSelect -time
+    // DophotSelect
+    // (note that psfQF is applied rigidly at 0.85, as is the galaxy test)
+    // MAG_LIM
+    // SIGMA_LIM
+    // ImagSelect, ImagMin, ImagMax
+    // MaxDensityUse, MaxDensityValue
+
+    char command[1024];
+    snprintf (command, 1024, "delstar_client -hostID %d -D CATDIR %s -hostdir %s -region %f %f %f %f -photcodes %s", 
+	      table->hosts[i].hostID, CATDIR, table->hosts[i].pathname, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, PHOTCODE_LIST);
+
+    char tmpline[1024];
+    if (VERBOSE)       { snprintf (tmpline, 1024, "%s -v",              command);                    strcpy (command, tmpline); }
+
+    fprintf (stderr, "command: %s\n", command);
+
+    if (PARALLEL_MANUAL) continue;
+
+    if (PARALLEL_SERIAL) {
+      int status = system (command);
+      if (status) {
+	fprintf (stderr, "ERROR running relphot_client\n");
+	exit (2);
+      }
+    } else {
+      // launch the job on the remote machine (no handshake)
+      int errorInfo = 0;
+      int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
+      if (!pid) {
+	if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
+	exit (1);
+      }
+      table->hosts[i].pid = pid; // save for future reference
+    }
+  }
+
+  if (PARALLEL_MANUAL) {
+    fprintf (stderr, "run the delstar_client commands above.  when these are done, hit return\n");
+    getchar();
+  }
+  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
+    HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
+  }
+
+  return TRUE;
+}      
Index: branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delstar.c
===================================================================
--- branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delstar.c	(revision 34681)
+++ branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delstar.c	(revision 34682)
@@ -28,4 +28,7 @@
       delete_times (&db);
       break;
+    case MODE_PHOTCODES:
+      delete_photcoes (&db);
+      break;
     case MODE_ORPHAN:
       fprintf (stderr, "delete orphans not available\n");
Index: branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delstar_client.c
===================================================================
--- branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delstar_client.c	(revision 34682)
+++ branches/eam_branches/ipp-20120905/Ohana/src/delstar/src/delstar_client.c	(revision 34682)
@@ -0,0 +1,45 @@
+# include "delstar.h"
+
+int main (int argc, char **argv) {
+
+  FITS_DB db;
+
+  int status;
+  SetSignals ();
+  ConfigInit (&argc, argv);
+  args (&argc, argv);
+
+  set_db (&db);
+  status = dvo_image_lock (&db, ImageCat, 60.0, LCK_XCLD); /* XCLD */
+  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);
+
+  status = dvo_image_load (&db, VERBOSE, FALSE);
+  if (!status) Shutdown ("can't read image catalog %s", db.filename);
+
+  switch (MODE) {
+    case MODE_IMAGEFILE:
+      delete_imagefile (&db, argv[1]);
+      break;
+    case MODE_IMAGENAME:
+      delete_imagename (&db, argv[1]);
+      break;
+    case MODE_TIME:
+      delete_times (&db);
+      break;
+    case MODE_PHOTCODES:
+      delete_photcoes (&db);
+      break;
+    case MODE_ORPHAN:
+      fprintf (stderr, "delete orphans not available\n");
+      // delete_orphans (argv[1]);
+      break;
+    case MODE_MISSED:
+      fprintf (stderr, "delete missed not available\n");
+      // delete_missed (argv[1]);
+      break;
+    default:
+      usage ();
+  }
+  exit (1);
+}
