Index: /branches/eam_branches/ipp-20130509/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/addstar/include/addstar.h	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/addstar/include/addstar.h	(revision 35594)
@@ -119,4 +119,6 @@
 int    	ACCEPT_TIME;    // accept time stamp (or 0)
 int    	NO_STARS;       // ignore the stars
+int    	NO_DUPLICATE_IMAGES; // allow / skip duplicate images 
+int    	IMAGE_ID_OVERRIDE; // allow / skip duplicate images 
 int    	TEXTMODE;       // force input file to be loaded as RAW
 int     SUBPIX;         // apply a subpix correction
Index: /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/ImageIndex.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/ImageIndex.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/ImageIndex.c	(revision 35594)
@@ -159,5 +159,5 @@
   if (!index) {
       fprintf (stderr, "image index file is not found, cannot check for image duplicates\n");
-      exit (2);
+      exit (1);
   }
 
Index: /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/UpdateImageIDs.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/UpdateImageIDs.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/UpdateImageIDs.c	(revision 35594)
@@ -35,4 +35,9 @@
   }
 
+  // TEST IMAGE_ID OVER-RIDE:
+  if (IMAGE_ID_OVERRIDE) {
+    imageID = IMAGE_ID_OVERRIDE;
+  }
+
   // XXX should the first image ID be 1, not 0?
   if (imageID == 0) imageID = 1;
@@ -54,5 +59,7 @@
   // set and update the imageID sequence
   // the file holding the index is created above if this is an empty db
-  CheckDuplicateImageIDs (images, Nimages);
+  if (NO_DUPLICATE_IMAGES) {
+    CheckDuplicateImageIDs (images, Nimages);
+  }
 
   imageID += Nimages;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/args.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/addstar/src/args.c	(revision 35594)
@@ -308,4 +308,17 @@
   if ((N = get_argument (argc, argv, "-no-stars"))) {
     NO_STARS = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  /* skip the stars */
+  NO_DUPLICATE_IMAGES = TRUE;
+  if ((N = get_argument (argc, argv, "-dup-images"))) {
+    NO_DUPLICATE_IMAGES = FALSE;
+    remove_argument (N, &argc, argv);
+  }
+  /* skip the stars */
+  IMAGE_ID_OVERRIDE = 0;
+  if ((N = get_argument (argc, argv, "-image-id-override"))) {
+    remove_argument (N, &argc, argv);
+    IMAGE_ID_OVERRIDE = atoi(argv[N]);
     remove_argument (N, &argc, argv);
   }
@@ -438,4 +451,5 @@
   fprintf (stderr, "  -use-name                	  : use the given name instead of the filename as the filename\n");
   fprintf (stderr, "  -no-stars                	  : skip the stars\n");
+  fprintf (stderr, "  -dup-images             	  : skip the test for duplicate image IDs (test only!)\n");
   fprintf (stderr, "  -force                	  : force read of database with inconsistent info\n");
   fprintf (stderr, "  -threads (N)            	  : use N threads for resort option\n");
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/include/dvomerge.h
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/include/dvomerge.h	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/include/dvomerge.h	(revision 35594)
@@ -25,4 +25,6 @@
 
 int    VERBOSE;
+int    VERIFY;
+int    IMAGES_ONLY;
 char   CATDIR[256];
 char   GSCFILE[256];
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/args.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/args.c	(revision 35594)
@@ -12,4 +12,17 @@
     remove_argument (N, argc, argv);
   }
+
+  /* verify merge status of output tables, but do not modify */
+  VERIFY = FALSE;
+  if ((N = get_argument (*argc, argv, "-verify"))) {
+    VERIFY = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  if ((N = get_argument (*argc, argv, "-check-only"))) {
+    VERIFY = TRUE;
+    remove_argument (N, argc, argv);
+  }
+
+  /* use a different photcode file to define mean values */
   if ((N = get_argument (*argc, argv, "-photcode-file"))) {
     remove_argument (N, argc, argv);
@@ -113,4 +126,15 @@
   }
 
+  /* verify merge status of output tables, but do not modify */
+  VERIFY = FALSE;
+  if ((N = get_argument (*argc, argv, "-verify"))) {
+    VERIFY = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  if ((N = get_argument (*argc, argv, "-check-only"))) {
+    VERIFY = TRUE;
+    remove_argument (N, argc, argv);
+  }
+
   /* replace measurement, don't duplicate */
   REPLACE_BY_PHOTCODE = FALSE;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomerge.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomerge.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomerge.c	(revision 35594)
@@ -10,6 +10,14 @@
   if (argc == 6) {
     if (!strcasecmp (argv[2], "and")) {
+      if (VERIFY) {
+	fprintf (stderr, "WARNING / ERROR : dvomerge (input1) and (input2) into (output) : VERIFY mode not implemented\n");
+	exit (3);
+      }
       dvomergeCreate (argc, argv);
     } else {
+      if (VERIFY) {
+	fprintf (stderr, "WARNING / ERROR : dvomerge (input) into (output) from (list) : VERIFY mode not implemented\n");
+	exit (3);
+      }
       dvomergeFromList (argc, argv);
     }
@@ -26,9 +34,13 @@
 }
 
-/* we have two possible modes of operation:
+/* we have two major modes of operation:
 
-   Create   : dvomerge (in1) and (in2) to (out) -- create a new db from two input dbs
-   Update   : dvomerge (in) into (out)          -- merge a new db into an existing db
-   Continue : dvomerge (in) into (out) continue -- merge a new db into an existing db
+   Create    : dvomerge (in1) and (in2) to (out) -- create a new db from two input dbs
+   Update    : dvomerge (in) into (out)          -- merge a new db into an existing db
 
+   we also have varients on Update:
+   Continue  : dvomerge (in) into (out) continue -- merge only unmerged tables into the existing db
+   From List : dvomerge (in) into (out) from (list) -- merge only specified tables into the existing db
+
+   neither of the 2 above modes update the image table
 */
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeFromList.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeFromList.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeFromList.c	(revision 35594)
@@ -108,4 +108,6 @@
     dmhObjectStats *inStats = dmhObjectStatsRead (inputfile);
 
+    // XXX : we are not checking for already-merged entries
+
     LoadCatalog (&incatalog, NULL, inputfile, "r", NsecfiltInput);
 
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 35594)
@@ -23,4 +23,5 @@
     CONTINUE = TRUE;
   }
+  if (VERIFY) CONTINUE = TRUE;
 
   input  = argv[1];
@@ -78,4 +79,5 @@
   } else {
     dvomergeImagesUpdate (&IDmap, input, output);
+    if (IMAGES_ONLY) exit (0);
   }
 
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c	(revision 35594)
@@ -76,8 +76,12 @@
     }
     if (!missed) {
-      if (VERBOSE) fprintf (stderr, "skipping %s, empty or already merged\n", inlist[0].filename[i]);
+      if (VERBOSE || VERIFY) fprintf (stderr, "skipping %s, already merged\n", inlist[0].filename[i]);
       OutputStatusFree (outstat, outlist->Nregions);
       dmhObjectStatsFree (inStats);
       SkyListFree (outlist); 
+      continue;
+    }
+    if (VERIFY) { 
+      fprintf (stderr, "%s NOT merged\n", inlist[0].filename[i]);
       continue;
     }
@@ -193,4 +197,5 @@
     char tmpline[DVO_MAX_PATH];
     if (VERBOSE)             { snprintf (tmpline, DVO_MAX_PATH, "%s -v",       command); strcpy (command, tmpline); }
+    if (VERIFY)              { snprintf (tmpline, DVO_MAX_PATH, "%s -verify",  command); strcpy (command, tmpline); }
     if (REPLACE_BY_PHOTCODE) { snprintf (tmpline, DVO_MAX_PATH, "%s -replace", command); strcpy (command, tmpline); }
 
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c	(revision 35594)
@@ -129,4 +129,7 @@
   output = argv[3];
 
+  fprintf (stderr, "WARNING / ERROR : multi-threaded dvomerge does not handle merge tracking yet\n");
+  exit (2);
+
   if (ALTERNATE_PHOTCODE_FILE) {
     fprintf (stderr, "cannot specify photcodes when merging into an existing catdir\n");
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/help.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/help.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvomerge/src/help.c	(revision 35594)
@@ -59,4 +59,6 @@
   fprintf (stderr, "  optional flags:\n");
   fprintf (stderr, "  -v                    	  : verbose mode\n");
+  fprintf (stderr, "  -verify                  	  : verify merge status of output tables, but do not modify\n");
+  fprintf (stderr, "  -check-only              	  : verify merge status of output tables, but do not modify [same as -verify]\n");
   fprintf (stderr, "  -help                 	  : this list\n");
   fprintf (stderr, "  -h                    	  : this list\n\n");
@@ -81,4 +83,6 @@
   fprintf (stderr, "  optional flags:\n");
   fprintf (stderr, "  -v                    	  : verbose mode\n");
+  fprintf (stderr, "  -verify                  	  : verify merge status of output tables, but do not modify\n");
+  fprintf (stderr, "  -check-only              	  : verify merge status of output tables, but do not modify [same as -verify]\n");
   fprintf (stderr, "  -help                 	  : this list\n");
   fprintf (stderr, "  -h                    	  : this list\n\n");
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/include/dvopsps.h
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/include/dvopsps.h	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/include/dvopsps.h	(revision 35594)
@@ -13,4 +13,5 @@
   uint64_t ippObjID;
   uint64_t objID;
+  int      photcode;
   unsigned int flags;
   float zp;
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/src/DetectionOps.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/src/DetectionOps.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/src/DetectionOps.c	(revision 35594)
@@ -54,4 +54,5 @@
   GET_COLUMN(ippObjID    , "ippObjID",    int64_t);
   GET_COLUMN(objID       , "objID",       int64_t);
+  GET_COLUMN(photcode    , "photcode",    int);
   GET_COLUMN(flags       , "flags",       int);
   GET_COLUMN(zp          , "zp",          float);
@@ -73,4 +74,5 @@
     detections[i].ippObjID     = ippObjID[i];   
     detections[i].objID        = objID[i];      
+    detections[i].photcode     = photcode[i];      
     detections[i].flags        = flags[i];      
     detections[i].zp           = zp[i];         
@@ -90,4 +92,5 @@
   free (ippObjID   );
   free (objID      );
+  free (photcode   );
   free (flags      );
   free (zp         );
@@ -154,4 +157,5 @@
   // gfits_define_bintable_column (&theader, "K", "ippObjID",    NULL, NULL, 1.0, BZERO_INT64);
   // gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, BZERO_INT64);
+  gfits_define_bintable_column (&theader, "J", "photcode",    NULL, NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "J", "flags",       NULL, NULL, 1.0, BZERO_INT32);
   gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
@@ -173,4 +177,5 @@
   uint64_t   *ippObjID    ; ALLOCATE (ippObjID    ,  uint64_t, Ndetections);
   uint64_t   *objID       ; ALLOCATE (objID       ,  uint64_t, Ndetections);
+  int        *photcode    ; ALLOCATE (photcode    ,  int,      Ndetections);
   uint32_t   *flags       ; ALLOCATE (flags       ,  uint32_t, Ndetections);
   float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
@@ -190,4 +195,5 @@
     ippObjID[i]    = detections[i].ippObjID    ;
     objID[i]       = detections[i].objID       ;
+    photcode[i]    = detections[i].photcode    ;
     flags[i]       = detections[i].flags       ;
     zp[i]          = detections[i].zp          ;
@@ -207,4 +213,5 @@
   gfits_set_bintable_column (&theader, &ftable, "ippObjID",    ippObjID    , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "objID",       objID       , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "photcode",    photcode    , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "flags",       flags       , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
@@ -222,4 +229,5 @@
   free (ippObjID    );
   free (objID       );
+  free (photcode    );
   free (flags       );
   free (zp          );
Index: /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 35594)
@@ -49,4 +49,5 @@
       // detections[Ndetections]. ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
       detections[Ndetections].objID	   = average->extID;   // objID
+      detections[Ndetections].photcode	   = measure->photcode;   // photcode
       detections[Ndetections].flags 	   = measure->dbFlags;  // flags
       detections[Ndetections].zp 	   = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;   // zp
@@ -168,5 +169,5 @@
   }
 
-  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
+  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, photcode, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
 
   return TRUE;
@@ -179,25 +180,5 @@
 int insert_detections_mysql_value (IOBuffer *buffer, Average *average, Measure *measure) {
 
-  // XXX I am changing the def of ippObjID if I use the code below
   PhotCode *code = GetPhotcodebyCode(measure->photcode);
-  // PrintIOBuffer (buffer, "    (%d, %u, %lu, %lu, %lu, %u, %f, %f, %f, %f, %lf, %lf, %f, %f),\n",
-  // 		 measure->imageID,    // imageID
-  // 		 measure->detID,   // ippDetectID
-  // 		 measure->extID,   // detectID
-  // 		 ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID, // ippObjID
-  // 		 // NOTE: this is better, but the above is the current ippToPsps value
-  // 		 // ((uint64_t)average->catID << 32) + (uint64_t)average->objID, // ippObjID
-  // 		 average->extID,   // objID
-  // 		 measure->dbFlags,  // flags
-  // 		 code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal,   // zp
-  // 		 measure->dMcal,    // zpErr
-  // 		 measure->airmass,
-  // 		 pow(10.0, 0.4 * measure->dt),    // expTime
-  // 		 average->R - measure->dR / 3600.,    // ra
-  // 		 average->D - measure->dR / 3600.,    // dec
-  // 		 measure->dXccd * 0.01 * fabs(measure->pltscale), // estimate of raErr
-  // 		 measure->dYccd * 0.01 * fabs(measure->pltscale) // estimate of decErr
-  //   ); 
-  
   PrintIOBuffer (buffer, "(%d, ", measure->imageID);	  // imageID
   PrintIOBuffer (buffer, "%u, ", measure->detID); // ippDetectID
@@ -207,4 +188,5 @@
   // ((uint64_t)average->catID << 32) + (uint64_t)average->objID, // ippObjID
   PrintIOBuffer (buffer, "%lu, ", average->extID);	  // objID
+  PrintIOBuffer (buffer, "%d, ", measure->photcode);	  // photcode
   PrintIOBuffer (buffer, "%u, ", measure->dbFlags);	  // flags
 
Index: /branches/eam_branches/ipp-20130509/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/libfits/include/gfitsio.h	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/libfits/include/gfitsio.h	(revision 35594)
@@ -26,4 +26,7 @@
 # define FT_LINE_LENGTH          80  /* FITS header line length */
 # define FT_RECORD_SIZE        2880  /* FITS block size */
+
+# define FT_BZERO_INT16 1.0*0x8000	  
+# define FT_BZERO_INT32 1.0*0x80000000
 
 /* this structure defines the buffer which contains a header
Index: /branches/eam_branches/ipp-20130509/Ohana/src/libfits/table/F_define_column.c
===================================================================
--- /branches/eam_branches/ipp-20130509/Ohana/src/libfits/table/F_define_column.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/Ohana/src/libfits/table/F_define_column.c	(revision 35594)
@@ -1,4 +1,48 @@
 # include <ohana.h>
 # include <gfitsio.h>
+
+# if (0)
+/*** special version of this function to define unsigned int columns (special values for BZERO, BSCALE) ********************/
+int gfits_define_bintable_column_unsigned_int (Header *header, char *format, char *label, char *comment, char *unit, int inttype) {
+
+  assert (label);
+  assert (format);
+
+  off_t Naxis1;
+  int Nfields, Nbytes, Nval;
+  char type[16], field[16];
+  
+  if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
+  
+  Nfields = 0;
+  gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
+  gfits_scan (header, "NAXIS1",  OFF_T_FMT, 1,  &Naxis1);
+  Nfields ++;
+  Naxis1 += Nbytes*Nval;
+
+  sprintf (field, "TTYPE%d", Nfields);
+  gfits_modify (header, field, "%s", 1, label);
+  gfits_modify_alt (header, field, "%C", 1, comment);
+  sprintf (field, "TUNIT%d", Nfields);
+  gfits_modify (header, field, "%s", 1, unit);
+  sprintf (field, "TFORM%d", Nfields);
+  gfits_modify (header, field, "%s", 1, format);
+
+  // add scaling parameters unless they amount to a noop
+  if ((bscale != 1.0) || (bzero != 0.0)) {
+      sprintf (field, "TSCAL%d", Nfields);
+      gfits_modify (header, field, "%lf", 1, bscale);
+      sprintf (field, "TZERO%d", Nfields);
+      gfits_modify (header, field, "%lf", 1, bzero);
+  }
+
+  /* update TFIELDS & NAXIS1 */
+  gfits_modify (header, "TFIELDS", "%d", 1, Nfields);
+  gfits_modify (header, "NAXIS1",  OFF_T_FMT, 1,  Naxis1);
+  header[0].Naxis[0] = Naxis1;
+
+  return (TRUE);
+}
+# endif
 
 /***********************/
Index: /branches/eam_branches/ipp-20130509/ippTools/share/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-20130509/ippTools/share/Makefile.am	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippTools/share/Makefile.am	(revision 35594)
@@ -449,4 +449,5 @@
 	diffphottool_data.sql \
 	laptool_definerun.sql \
+	laptool_definerunbyrelease.sql \
 	laptool_exposures.sql \
 	laptool_inactiveexp.sql \
Index: /branches/eam_branches/ipp-20130509/ippTools/share/chiptool_find_rawexp.sql
===================================================================
--- /branches/eam_branches/ipp-20130509/ippTools/share/chiptool_find_rawexp.sql	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippTools/share/chiptool_find_rawexp.sql	(revision 35594)
@@ -6,5 +6,5 @@
 FROM rawExp
 JOIN newExp using (exp_id)
-LEFT JOIN chipRun USING (exp_id)
+LEFT JOIN chipRun ON chipRun.exp_id = rawExp.exp_id -- JOIN hook %s
 WHERE
     rawExp.fault = 0
Index: /branches/eam_branches/ipp-20130509/ippTools/share/laptool_definerunbyrelease.sql
===================================================================
--- /branches/eam_branches/ipp-20130509/ippTools/share/laptool_definerunbyrelease.sql	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/ippTools/share/laptool_definerunbyrelease.sql	(revision 35594)
@@ -0,0 +1,23 @@
+select
+	rel.exp_id AS exp_id,
+	rel.chip_id AS chip_id,
+	false AS private,
+	false AS active,
+	false AS pairwise
+FROM
+	(select exp_id,chip_id FROM ippRelease
+	 JOIN relExp USING(rel_id)
+	 JOIN rawExp USING(exp_id)
+	 WHERE
+	 @RELWHERE@
+	) AS rel
+LEFT JOIN
+	(select MIN(lap_id) AS lap_id,
+	 exp_id,chip_id FROM lapRun
+	 JOIN lapExp USING(lap_id)
+	 WHERE
+	 @LAPWHERE@
+	 GROUP BY exp_id,chip_id
+	) AS lap
+USING(exp_id)
+WHERE lap_id IS NULL
Index: /branches/eam_branches/ipp-20130509/ippTools/src/chiptool.c
===================================================================
--- /branches/eam_branches/ipp-20130509/ippTools/src/chiptool.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippTools/src/chiptool.c	(revision 35594)
@@ -269,5 +269,5 @@
 
     PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
-    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
+    PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false);
     PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
     PXOPT_LOOKUP_STR(expgroup, config->args, "-set_expgroup", false, false);
@@ -298,9 +298,11 @@
     psFree(where);
 
+    psString labelHook = NULL;
     if (unique) {
-      psStringAppend(&query, "AND chip_id IS NULL");
+      psStringAppend(&labelHook, "\nAND chipRun.label = '%s'", label);
+      psStringAppend(&query, " AND chip_id IS NULL");
     }
     
-    if (!p_psDBRunQuery(config->dbh, query)) {
+    if (!p_psDBRunQueryF(config->dbh, query, labelHook ? labelHook : "")) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         psFree(query);
Index: /branches/eam_branches/ipp-20130509/ippTools/src/chiptoolConfig.c
===================================================================
--- /branches/eam_branches/ipp-20130509/ippTools/src/chiptoolConfig.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippTools/src/chiptoolConfig.c	(revision 35594)
@@ -52,5 +52,5 @@
 
     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_workdir",  0,            "define workdir (required)", NULL);
-    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_label",  0,            "define label", NULL);
+    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_label",  0,            "define label (required)", NULL);
     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_reduction",  0,            "define reduction class", NULL);
     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_expgroup",  0,            "define exposure group", NULL);
Index: /branches/eam_branches/ipp-20130509/ippTools/src/laptool.c
===================================================================
--- /branches/eam_branches/ipp-20130509/ippTools/src/laptool.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippTools/src/laptool.c	(revision 35594)
@@ -22,6 +22,8 @@
 // Run level
 static bool definerunMode(pxConfig *config);
+static bool definerunbyreleaseMode(pxConfig *config);
 static bool pendingrunMode(pxConfig *config);
 static bool updaterunMode(pxConfig *config);
+
 // Exposure level
 static bool pendingexpMode(pxConfig *config);
@@ -64,4 +66,5 @@
     
     MODECASE(LAPTOOL_MODE_DEFINERUN,     definerunMode);
+    MODECASE(LAPTOOL_MODE_DEFINERUNBYRELEASE, definerunbyreleaseMode);
     MODECASE(LAPTOOL_MODE_PENDINGRUN,    pendingrunMode);
     MODECASE(LAPTOOL_MODE_UPDATERUN,     updaterunMode);
@@ -401,4 +404,179 @@
 }
 
+static bool definerunbyreleaseMode(pxConfig *config)
+{
+  PS_ASSERT_PTR_NON_NULL(config, false);
+
+  PXOPT_LOOKUP_S64(seq_id,          config->args, "-seq_id",          true, false);
+  PXOPT_LOOKUP_STR(projection_cell, config->args, "-projection_cell", true, false);
+  PXOPT_LOOKUP_STR(tess_id,         config->args, "-tess_id",         true, false);
+  PXOPT_LOOKUP_STR(filter,          config->args, "-filter",          true, false);
+  PXOPT_LOOKUP_STR(label,           config->args, "-label",           false, false);
+  PXOPT_LOOKUP_STR(dist_group,      config->args, "-dist_group",      false, false);
+  PXOPT_LOOKUP_S64(rel_id,          config->args, "-rel_id",          false, false);
+  PXOPT_LOOKUP_STR(rel_name,        config->args, "-release_name",    false, false);
+  PXOPT_LOOKUP_BOOL(simple,         config->args, "-simple",          false);
+
+  // Validate config
+  if ((!rel_name)&&(!rel_id)) {
+    // Die here.
+  }
+  
+  lapRunRow *run = lapRunRowAlloc(0, // lap_id
+				  seq_id,
+				  tess_id,
+				  projection_cell,
+				  filter,
+				  "registered", // state
+				  label,
+				  dist_group,
+				  NULL, // registered
+				  0,    // fault
+				  INT64_MAX,    // quick_sass_id
+				  INT64_MAX     // final_sass_id
+				  );
+  if (!run) {
+    psError(PS_ERR_UNKNOWN, false, "failed to alloc lapRun object");
+    return(true);
+  }
+
+  if (!psDBTransaction(config->dbh)) {
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    return(false);
+  }
+    
+  if (!lapRunInsertObject(config->dbh, run)) {
+    if (!psDBRollback(config->dbh)) {
+      psError(PS_ERR_UNKNOWN, false, "database error");
+    }
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    psFree(run);
+    return(false);
+  }
+
+  if (!lapRunPrintObject(stdout, run, !simple)) {
+    if (!psDBRollback(config->dbh)) {
+      psError(PS_ERR_UNKNOWN, false, "database error");
+    }
+    psError(PS_ERR_UNKNOWN, false, "failed to print object");
+    psFree(run);
+    return(false);
+  }
+
+  psS64 lap_id = psDBLastInsertID(config->dbh);
+
+  psString query = pxDataGet("laptool_definerunbyrelease.sql");
+  if (!query) {
+    if (!psDBRollback(config->dbh)) {
+      psError(PS_ERR_UNKNOWN, false, "database error");
+    }
+    psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement");
+    return(false);
+  }
+  
+  // Add constraints
+  psMetadata *relWhere = psMetadataAlloc();
+  PXOPT_COPY_STR(config->args, relWhere, "-filter",       "rawExp.filter", "==");
+  PXOPT_COPY_STR(config->args, relWhere, "-release_name", "ippRelease.release_name", "==");
+  PXOPT_COPY_S64(config->args, relWhere, "-rel_id",       "ippRelease.rel_id", "==");
+  PXOPT_COPY_TIME(config->args, relWhere, "-dateobs_begin", "rawExp.dateobs", ">=");
+  PXOPT_COPY_TIME(config->args, relWhere, "-dateobs_end", "rawExp.dateobs", "<=");
+  PXOPT_COPY_RADEC(config->args, relWhere, "-ra_min", "rawExp.ra", ">=");
+  PXOPT_COPY_RADEC(config->args, relWhere, "-ra_max", "rawExp.ra", "<");
+  PXOPT_COPY_RADEC(config->args, relWhere, "-decl_min", "rawExp.decl", ">=");
+  PXOPT_COPY_RADEC(config->args, relWhere, "-decl_max", "rawExp.decl", "<");
+
+  psMetadata *lapWhere = psMetadataAlloc();
+  PXOPT_COPY_S64(config->args, lapWhere, "-seq_id",       "lapRun.seq_id", "==");
+  PXOPT_COPY_STR(config->args, lapWhere, "-filter",       "lapRun.filter", "==");
+
+  psString relWhereClause = psDBGenerateWhereConditionSQL(relWhere,NULL);
+  psString lapWhereClause = psDBGenerateWhereConditionSQL(lapWhere,NULL);
+
+  if (relWhereClause) {
+    psStringSubstitute(&query,relWhereClause,"@RELWHERE@");
+  }
+  if (lapWhereClause) {
+    psStringSubstitute(&query,lapWhereClause,"@LAPWHERE@");
+  }
+  psFree(relWhere);
+  psFree(lapWhere);
+
+  // Fetch exposures
+  if (!p_psDBRunQuery(config->dbh, query)) {
+    if (!psDBRollback(config->dbh)) {
+      psError(PS_ERR_UNKNOWN, false, "database error");
+    }
+
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    psFree(query);
+    return(false);
+  }
+  psFree(query);
+
+  psArray *output = p_psDBFetchResult(config->dbh);
+  if (!output) {
+    if (!psDBRollback(config->dbh)) {
+      psError(PS_ERR_UNKNOWN, false, "database error");
+    }
+
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    return(false);
+  }
+  if (!psArrayLength(output)) {
+    if (!psDBRollback(config->dbh)) {
+      psError(PS_ERR_UNKNOWN, false, "database error");
+    }
+
+    psTrace("laptool", PS_LOG_INFO, "no rows found");
+    psFree(output);
+    return(true);
+  }
+
+  // Insert the exposure data
+  for (long i = 0; i < output->n; i++) {
+    psMetadata *row = output->data[i]; // Row from select
+    // Add default values from this run:
+    psMetadataAddS64(row, PS_LIST_TAIL, "lap_id", 0, "", lap_id);
+    psMetadataAddS64(row, PS_LIST_TAIL, "pair_id", 0, "", INT64_MAX);
+    psMetadataAddStr(row, PS_LIST_TAIL, "data_state", 0, "", "new");
+    lapExpRow *lapExp = lapExpObjectFromMetadata(row);
+    lapExp->lap_id = lap_id;
+
+    if (!lapExpInsertObject(config->dbh,lapExp)) {
+      if (!lapExpPrintObject(stdout, lapExp, !simple)) {
+	if (!psDBRollback(config->dbh)) {
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	}
+	psError(PS_ERR_UNKNOWN, false, "failed to print object");
+	psFree(run);
+	return false;
+      }
+      
+      if (!psDBRollback(config->dbh)) {
+	psError(PS_ERR_UNKNOWN, false, "database error");
+      }
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      psFree(output);
+      psFree(lapExp);
+      return(false);
+    }
+  }
+
+  // point of no return
+  if (!psDBCommit(config->dbh)) {
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    return false;
+  }
+
+  
+  psFree(output);
+  return(true);  
+}
+
+
+  
+  
+		   
 static bool pendingrunMode(pxConfig *config)
 {
Index: /branches/eam_branches/ipp-20130509/ippTools/src/laptool.h
===================================================================
--- /branches/eam_branches/ipp-20130509/ippTools/src/laptool.h	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippTools/src/laptool.h	(revision 35594)
@@ -13,4 +13,5 @@
   LAPTOOL_MODE_LISTSEQUENCE,
   LAPTOOL_MODE_DEFINERUN,
+  LAPTOOL_MODE_DEFINERUNBYRELEASE,
   LAPTOOL_MODE_PENDINGRUN,
   LAPTOOL_MODE_UPDATERUN,
Index: /branches/eam_branches/ipp-20130509/ippTools/src/laptoolConfig.c
===================================================================
--- /branches/eam_branches/ipp-20130509/ippTools/src/laptoolConfig.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippTools/src/laptoolConfig.c	(revision 35594)
@@ -57,9 +57,28 @@
   ADD_OPT(Str, definerunArgs, "-label",                       "define the label used", NULL);
   ADD_OPT(Str, definerunArgs, "-dist_group",                  "define the distribution group for this data", NULL);
-
+  
   psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-obsmode", PS_META_DUPLICATE_OK, "search by obsmode", NULL);
   ADD_OPT(Bool,definerunArgs, "-all_obsmode",                 "use all science obsmodes", false);
   
   ADD_OPT(Bool,definerunArgs, "-simple",                      "use the simple output format", false);
+
+  // -definerunbyrelease
+  psMetadata *definerunbyreleaseArgs = psMetadataAlloc();
+  ADD_OPT(S64, definerunbyreleaseArgs, "-seq_id",             "define the LAP sequence for this run (required)", 0);
+  ADD_OPT(Str, definerunbyreleaseArgs, "-projection_cell",    "define the projection cell for this run (required)", NULL);
+  ADD_OPT(Str, definerunbyreleaseArgs, "-tess_id",            "define the tessellation used (required)", NULL);
+  ADD_OPT(Str, definerunbyreleaseArgs, "-filter",             "define the filter used (required)", NULL);
+  ADD_OPT(Str, definerunbyreleaseArgs, "-label",              "define the label used", NULL);
+  ADD_OPT(Str, definerunbyreleaseArgs, "-dist_group",         "define the distribution group for this data", NULL);
+  ADD_OPT(S64, definerunbyreleaseArgs, "-rel_id",             "define the release to copy", 0);
+  ADD_OPT(Str, definerunbyreleaseArgs, "-release_name",       "define the release to copy", NULL);
+  
+  ADD_OPT(Bool, definerunbyreleaseArgs, "-simple",            "use the simple output format", false);
+  psMetadataAddTime(definerunbyreleaseArgs, PS_LIST_TAIL, "-dateobs_begin",      0, "search for exposures by time (>=)", NULL);
+  psMetadataAddTime(definerunbyreleaseArgs, PS_LIST_TAIL, "-dateobs_end",        0, "search for exposures by time (<=)", NULL);
+  psMetadataAddF64(definerunbyreleaseArgs,  PS_LIST_TAIL, "-ra_min",             0, "search by min RA (degrees) ", NAN);
+  psMetadataAddF64(definerunbyreleaseArgs,  PS_LIST_TAIL, "-ra_max",             0, "search by max RA (degrees) ", NAN);
+  psMetadataAddF64(definerunbyreleaseArgs,  PS_LIST_TAIL, "-decl_min",           0, "search by min DEC (degrees)", NAN);
+  psMetadataAddF64(definerunbyreleaseArgs,  PS_LIST_TAIL, "-decl_max",           0, "search by max DEC (degrees)", NAN);
   
   // -pendingrun
@@ -204,4 +223,5 @@
   PXOPT_ADD_MODE("-listsequence",            "", LAPTOOL_MODE_LISTSEQUENCE,     listsequenceArgs);
   PXOPT_ADD_MODE("-definerun",               "", LAPTOOL_MODE_DEFINERUN,        definerunArgs);
+  PXOPT_ADD_MODE("-definerunbyrelease",      "", LAPTOOL_MODE_DEFINERUNBYRELEASE, definerunbyreleaseArgs);
   PXOPT_ADD_MODE("-pendingrun",              "", LAPTOOL_MODE_PENDINGRUN,       pendingrunArgs);
   PXOPT_ADD_MODE("-listrun",                 "", LAPTOOL_MODE_PENDINGRUN,       listrunArgs);
Index: /branches/eam_branches/ipp-20130509/ippconfig/gpc1/ppStack.config
===================================================================
--- /branches/eam_branches/ipp-20130509/ippconfig/gpc1/ppStack.config	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippconfig/gpc1/ppStack.config	(revision 35594)
@@ -81,8 +81,45 @@
 END
 
-STACK_ALLDEEP    METADATA                  # N>>20 inputs, typically MD fields, no cuts
+
+STACK_MD_REF       METADATA  ## revised config for MD refstacks vs PS1_REFERENCE above after ppStack mods 5/03/13
     OUTPUT.NOCOMP           BOOL  TRUE
     OUTPUT.LOGFLUX          BOOL  FALSE
     OUTPUT.REPLICATE        BOOL  TRUE
+    STACK.TYPE              STR   DEEP_STACK  ## needed?
+    PSF.INPUT.CLIP.SIMPLE   BOOL  True
+    PSF.INPUT.MAX           F32   6.0   # never really want >6 pixels in refstack
+    PSF.INPUT.CLIP.NSIGMA   F32   1.0   # sample typically on rising side of distribution (set even smaller?)
+    PSF.INPUT.THRESH        F32   NAN
+    PSF.INPUT.ASYMMETRY     F32   NAN
+    MATCH.REJ               F32   4.0 # need ot tune?
+    SAFE                    BOOL  FALSE
+END
+
+STACK_MD_DEEP     METADATA   ## revised config for MD deepstack above after ppStack mods 5/03/13
+    OUTPUT.NOCOMP           BOOL  TRUE
+    OUTPUT.LOGFLUX          BOOL  FALSE
+    OUTPUT.REPLICATE        BOOL  TRUE
+    STACK.TYPE              STR   DEEP_STACK 
+    PSF.INPUT.CLIP.SIMPLE   BOOL  True
+    PSF.INPUT.MAX           F32   10.0
+    PSF.INPUT.CLIP.NSIGMA   F32   100.0 
+    PSF.INPUT.THRESH        F32   NAN
+    PSF.INPUT.ASYMMETRY     F32   NAN
+    MATCH.REJ               F32   4.0 # need ot tune?
+    SAFE                    BOOL  FALSE
+END
+
+STACK_ALLDEEP      METADATA     # no cuts, everything in changes after ppStack mods 5/03/13
+    OUTPUT.NOCOMP           BOOL  TRUE
+    OUTPUT.LOGFLUX          BOOL  FALSE
+    OUTPUT.REPLICATE        BOOL  TRUE
+    STACK.TYPE              STR   DEEP_STACK 
+    PSF.INPUT.CLIP.SIMPLE   BOOL  True
+    PSF.INPUT.MAX           F32   100.0
+    PSF.INPUT.CLIP.NSIGMA   F32   100.0
+    PSF.INPUT.THRESH        F32   NAN
+    PSF.INPUT.ASYMMETRY     F32   NAN
+    MATCH.REJ               F32   4.0 # need ot tune?
+    SAFE                    BOOL  FALSE
 END
 
Index: /branches/eam_branches/ipp-20130509/ippconfig/recipes/ppStack.config
===================================================================
--- /branches/eam_branches/ipp-20130509/ippconfig/recipes/ppStack.config	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippconfig/recipes/ppStack.config	(revision 35594)
@@ -164,6 +164,15 @@
 END
 
+STACK_MD_REF    METADATA
+END
+
+STACK_MD_DEEP   METADATA
+END
+
 STACK_ALLDEEP   METADATA
 END
+
+
+
 
 TEST1 METADATA
Index: /branches/eam_branches/ipp-20130509/ippconfig/recipes/ppSub.config
===================================================================
--- /branches/eam_branches/ipp-20130509/ippconfig/recipes/ppSub.config	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippconfig/recipes/ppSub.config	(revision 35594)
@@ -108,4 +108,19 @@
 END
 
+# test setup for nodual case
+DIFF_NODUAL    METADATA   
+        DUAL             BOOL    FALSE    # Dual convolution?
+        INVERSE          BOOL    TRUE    # Generate inverse subtraction?
+        PHOTOMETRY       BOOL    TRUE    # Perform photometry?
+        CONVOLVE.TARGET  STR     SINGLE_AUTO
+
+        @ISIS.WIDTHS    F32     1.5  3.0  6.0   # Gaussian kernel FWHM values
+        @ISIS.ORDERS    S32     6    4    2     # Polynomial orders for ISIS kernels
+
+        SCALE.REF       F32     5.0             # FWHM reference for kernel parameter scaling
+        KERNEL.SIZE     S32     20              # Kernel half-size (pixels)
+        STAMP.FOOTPRINT S32     20              # Size of stamps (pixels)
+END
+
 # Difference of two warps
 WARPWARP	METADATA
Index: /branches/eam_branches/ipp-20130509/ippconfig/recipes/reductionClasses.mdc
===================================================================
--- /branches/eam_branches/ipp-20130509/ippconfig/recipes/reductionClasses.mdc	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/ippconfig/recipes/reductionClasses.mdc	(revision 35594)
@@ -299,4 +299,11 @@
 END
 
+# sweetspot no dual test case
+SWEETSPOT_NODUAL            METADATA
+        DIFF_PPSUB        STR     DIFF_NODUAL
+        DIFF_PSPHOT       STR     SSTF_DIFF
+        JPEG_BIN1         STR     PPIMAGE_J1
+        JPEG_BIN2         STR     PPIMAGE_J2
+END
 
 CONSTANT_WEIGHTPHOT		METADATA
@@ -544,4 +551,21 @@
 END
 
+## MD refstack
+MD_REF_STACK            METADATA
+      STACK_PPSTACK           STR     STACK_MD_REF
+      STACK_PPSUB             STR     STACK
+      STACK_PSPHOT            STR     STACK
+      STACKPHOT_PSPHOT        STR     STACKPHOT
+      STATICSKY_CALIBRATION   STR     STATICSKY_DEEPCAL 
+END
+
+## MD deepstack
+MD_DEEP_STACK            METADATA
+      STACK_PPSTACK           STR     STACK_MD_DEEP
+      STACK_PPSUB             STR     STACK
+      STACK_PSPHOT            STR     STACK
+      STACKPHOT_PSPHOT        STR     STACKPHOT
+      STATICSKY_CALIBRATION   STR     STATICSKY_DEEPCAL 
+END
 
 # quick stacks
Index: /branches/eam_branches/ipp-20130509/psModules/src/detrend/pmDark.c
===================================================================
--- /branches/eam_branches/ipp-20130509/psModules/src/detrend/pmDark.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/psModules/src/detrend/pmDark.c	(revision 35594)
@@ -383,6 +383,7 @@
       }
       values_set->data[i] = values;
-    }
-
+      psFree(orders);
+    }
+      
     // retrieve the norm vector, if supplied
     psVector *norm       = psMetadataLookupPtr(&mdok, output->analysis, "DARK.NORM");
@@ -433,4 +434,8 @@
                 }
                 pmReadout *readout = inputs->data[r]; // Input readout
+		if ((!readout)||(!readout->image)) {
+		  mask->data.PS_TYPE_VECTOR_MASK_DATA[r] = 0xff;
+		  continue;
+		}		  
                 int yIn = i - readout->row0; // y position on input readout
                 int xIn = j - readout->col0; // x position on input readout
@@ -504,4 +509,16 @@
     psFree(mask);
 
+    for (int i = 0; i < max_orders->n; i++) {
+      psFree(poly_set->data[i]);
+      psArray *values = values_set->data[i];
+      for (int j = 0; j < values->n; j++) {
+	psFree(values->data[j]);
+      }
+      psFree(values_set->data[i]);
+    }
+    psFree(values_set);
+    psFree(poly_set);
+    psFree(logL);
+
     return true;
 }
Index: /branches/eam_branches/ipp-20130509/psModules/src/objects/models/pmModel_TRAIL.c
===================================================================
--- /branches/eam_branches/ipp-20130509/psModules/src/objects/models/pmModel_TRAIL.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/psModules/src/objects/models/pmModel_TRAIL.c	(revision 35594)
@@ -169,13 +169,13 @@
         dPAR[PM_PAR_SIGMA]  = 0;	// we don't actually allow this to vary, so we do not need to calculate it
 
-	for (int i = 0; i < 7; i++) {
-	  if (isnan(dPAR[i])) {
-	    fprintf (stderr, "*");
-	  }
-	}
-    }
-    if (isnan(f)) {
-      fprintf (stderr, "!");
-    }
+	//	for (int i = 0; i < 7; i++) {
+	//	  if (isnan(dPAR[i])) {
+	//	    fprintf (stderr, "*");
+	//	  }
+	//	}
+    }
+    //    if (isnan(f)) {
+    //      fprintf (stderr, "!");
+    //    }
     return(f);
 }
Index: /branches/eam_branches/ipp-20130509/pstamp/scripts/pstamp_save_server_status.pl
===================================================================
--- /branches/eam_branches/ipp-20130509/pstamp/scripts/pstamp_save_server_status.pl	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/pstamp/scripts/pstamp_save_server_status.pl	(revision 35594)
@@ -12,16 +12,11 @@
 use Pod::Usage qw( pod2usage );
 
-# XXX: We should get this from site.config, but that would about double
-# the execution time for this script.
-my $rundir = "/data/ippc17.0/pstamp";
-
-my $status_file = "$rundir/web/status.html";
-
 my $updatelink;
 my $verbose;
 my $save_temps;
+my $pstamp_workdir;
 
 GetOptions(
-    'rundir=s'      => \$rundir,
+    'workdir=s'      => \$pstamp_workdir,
     'update-link'    => \$updatelink,
     'verbose'       => \$verbose,
@@ -37,9 +32,20 @@
 }
 
+if (!$pstamp_workdir) {
+    my $ipprc = PS::IPP::Config->new(); # IPP Configuration
+    $pstamp_workdir = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_WORKDIR');
+}
+
+if (!$pstamp_workdir) {
+    warn("Failed to find PSTAMP_WORKDIR in the config\n");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+my $status_file = "$pstamp_workdir/server_status/status.html";
+
 my ($sec, $min, $hour, $mday, $month, $year) = gmtime;
 $year += 1900;
 $month += 1;
 
-my $dir = sprintf "$rundir/work/server_status/%4d/%02d/%02d", $year, $month, $mday;
+my $dir = sprintf "$pstamp_workdir/server_status/%4d/%02d/%02d", $year, $month, $mday;
 
 if (!-e $dir ) {
Index: /branches/eam_branches/ipp-20130509/pstamp/test/maketestreq
===================================================================
--- /branches/eam_branches/ipp-20130509/pstamp/test/maketestreq	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/pstamp/test/maketestreq	(revision 35594)
@@ -30,9 +30,7 @@
 }
 
-# XXX: get these from site.config
-$pstamptool .= " -dbserver ippc19 -dbname ippRequestServer";
-
 
 my ($input, $submit, $listfile, $delete, $simple, $tag_req_name, $req_name, $email);
+my ($dbname, $dbserver);
 my ($save_temps, $verbose);
 
@@ -50,4 +48,7 @@
     'label=s'           => \$label,
     'email=s'           => \$email,
+
+    'dbname=s'           => \$dbname,
+    'dbserver=s'         => \$dbserver,
 
     'listfile|l'        => \$listfile,
@@ -68,4 +69,19 @@
 die ("Input file $input not found\n") unless (-e $input);
 die ("Input file $input not readable\n") unless (-r $input);
+
+if (!$dbname or !$dbserver) {
+    my $ipprc = PS::IPP::Config->new('GPC1');
+
+    if (!$dbserver) {
+        $dbserver =  metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER');
+        die ("couldn't find dbserver in site.config\n") unless $dbserver;
+    }
+    if (!$dbname) {
+        $dbname =  metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBNAME');
+        die ("couldn't find dbname in site.config\n") unless $dbname;
+    }
+}
+$pstamptool .= " -dbserver $dbserver -dbname $dbname";
+
 
 # if request name was not supplied make one
Index: /branches/eam_branches/ipp-20130509/pswarp/src/pswarpUpdateStatistics.c
===================================================================
--- /branches/eam_branches/ipp-20130509/pswarp/src/pswarpUpdateStatistics.c	(revision 35593)
+++ /branches/eam_branches/ipp-20130509/pswarp/src/pswarpUpdateStatistics.c	(revision 35594)
@@ -73,7 +73,7 @@
 	      // skip empty output readouts
                 if (!readout->data_exists) {
-		  Nreadout ++;
 		  continue;
 		}
+		Nreadout ++;
     
 		psString readoutName = NULL;
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/README
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/README	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/README	(revision 35594)
@@ -0,0 +1,12 @@
+big dvodb calibration instructions
+
+Step One: run addstar -resort using addstar.resort script
+
+Step Two: run setphot using run.setphot
+ 
+Step Three: run gene.relastro.part1
+
+Step Four: run gene.relastro.part2
+
+Step Five: run gene.relphot
+
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro	(revision 35594)
@@ -0,0 +1,86 @@
+#!/bin/csh -f
+
+set catdir_3pi = /data/ipp064.0/eugene/3pi.20111229/catdir.20111229
+set REALRUN = 1
+
+alias run.relastro \
+  'echo -n "--- starting relastro $catdir_3pi ---"; date; \
+   echo          relastro $options $region -D CATDIR $catdir_3pi; \
+   if ($REALRUN) relastro $options $region -D CATDIR $catdir_3pi'
+
+## NOTE (2012.09.12, pt 1) : I previously ran relastro including all
+## photcodes.  For reasons I don't yet understand, the SCO data is
+## really messed up (bad dR,dD values), and messed up the mean
+## positions for lots of objects.  I am re-running update-objects with
+## only gpc1 and 2MASS data, and I will figure out how to fix SCO
+## later.
+
+## NOTE (2012.09.12, pt 2) : I used the default statmode previously:
+## this is bad since it results in different rejections and thus
+## inconsistent ChiSq values for ChiSqPos and ChiSqPM.  In this
+## re-run, explicitly used the weighted version
+
+# run update-objects on the whole sky
+if (1) then
+  # for a test, only run -pm
+  set options = "-update-objects -pmpar"
+  # set options = "-update-objects -pm"
+  set options = "$options -D PM_DT_MIN 1.0"
+  set options = "$options -D PAR_FACTOR_MIN 0.25"
+  set options = "$options -statmode WTMEAN"
+  set options = "$options +photcode g,r,i,z,y,J,H,K"
+  set options = "$options -update"
+  set options = "$options -parallel"
+  set options = "$options -reset"
+  set options = "$options -v"
+
+  # set region = "-region 180 190 30 40"
+  set region = "-region 0 360 -60 90"
+  
+  # run relastro -update-objects
+  run.relastro
+endif
+
+# try 2000 meas per deg^2, but if memory if available, go to more
+if (0) then
+  set options = "-update-chips"
+  set options = "$options -D RELASTRO_SRC_MEAS_TOOFEW 1"
+  set options = "$options -D RELASTRO_SIGMA_LIM 0.1"
+  set options = "$options -nloop 6"
+  set options = "$options -basic-image-search"
+  set options = "$options -reset"
+  set options = "$options -update"
+  set options = "$options -parallel"
+  set options = "$options -max-density 2000"
+  set options = "$options -threads 4"
+  set options = "$options -v"
+
+  # run relastro -update-chips
+  set ra_min = 0
+  while ($ra_min < 360) 
+    set ra_max = $ra_min
+    @ ra_max += 35
+  
+    if (($ra_min == 240) || ($ra_min == 270)) then 
+      set region = "-region $ra_min $ra_max -60 0"
+      run.relastro 
+
+      set region = "-region $ra_min $ra_max -5 60"
+      run.relastro
+
+      @ ra_min += 30
+      continue
+    endif
+
+    set region = "-region $ra_min $ra_max -60 60"
+    run.relastro
+
+    @ ra_min += 30
+  end
+
+  # pole region 
+  set region = "-region 0 360 55 90"
+  run.relastro
+endif
+
+echo -n "--- done with relastro ---"; date
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part1
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part1	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part1	(revision 35594)
@@ -0,0 +1,84 @@
+#!/bin/csh -f
+if ($#argv != 1) then 
+  echo "USAGE: run.relastro.part1 (catdir) "
+  exit 2
+endif
+
+set REALRUN = 1
+
+set  catdir_3pi = $argv[1]
+
+
+alias run.relastro \
+  'echo -n "--- starting relastro $catdir_3pi ---"; date; \
+   echo          relastro $options $region -D CATDIR $catdir_3pi; \
+   if ($REALRUN) relastro $options $region -D CATDIR $catdir_3pi'
+
+## NOTE (2012.09.12, pt 1) : I previously ran relastro including all
+## photcodes.  For reasons I don't yet understand, the SCO data is
+## really messed up (bad dR,dD values), and messed up the mean
+## positions for lots of objects.  I am re-running update-objects with
+## only gpc1 and 2MASS data, and I will figure out how to fix SCO
+## later.
+
+## NOTE (2012.09.12, pt 2) : I used the default statmode previously:
+## this is bad since it results in different rejections and thus
+## inconsistent ChiSq values for ChiSqPos and ChiSqPM.  In this
+## re-run, explicitly used the weighted version
+
+# run update-objects on the whole sky
+
+# try 2000 meas per deg^2, but if memory if available, go to more
+if (1) then
+  set options = "-update-chips"
+  set options = "$options -D RELASTRO_SRC_MEAS_TOOFEW 1"
+  set options = "$options -D RELASTRO_SIGMA_LIM 0.1"
+  set options = "$options -nloop 6"
+  set options = "$options -basic-image-search"
+  set options = "$options -reset"
+  set options = "$options -update"
+  set options = "$options -parallel"
+  set options = "$options -max-density 2000"
+  set options = "$options -threads 4"
+  set options = "$options -v"
+
+  # run relastro -update-chips
+  set ra_min = 0
+  while ($ra_min < 360) 
+    set ra_max = $ra_min
+    @ ra_max += 35
+  
+    if (($ra_min == 240) || ($ra_min == 270)) then 
+      set region = "-region $ra_min $ra_max -60 0"
+      run.relastro 
+      if ($status) then
+         echo "ERROR : failure running relastro region $ra_min $ra_max -60 0 "
+	 echo -n "--- done with relastro --- "; date
+      endif
+
+      set region = "-region $ra_min $ra_max -5 90"
+      run.relastro
+      if ($status) then
+	echo "ERROR : failure running relastro region $ra_min $ra_max -5 90"
+	echo -n "--- done with relastro --- "; date
+	
+      endif
+
+      @ ra_min += 30
+      continue
+    endif
+
+    set region = "-region $ra_min $ra_max -60 90"
+    run.relastro
+    if ($status) then
+	echo "ERROR : failure running relastro region $ra_min $ra_max -60 90 "
+	echo -n "--- done with relastro --- "; date
+	
+    endif
+
+    @ ra_min += 30
+  end
+
+endif
+
+echo -n "--- done with relastro ---"; date
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part1.
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part1.	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part1.	(revision 35594)
@@ -0,0 +1,86 @@
+#!/bin/csh -f
+
+set catdir_3pi = /data/ipp064.0/eugene/3pi.20111229/catdir.20111229
+set REALRUN = 1
+
+alias run.relastro \
+  'echo -n "--- starting relastro $catdir_3pi ---"; date; \
+   echo          relastro $options $region -D CATDIR $catdir_3pi; \
+   if ($REALRUN) relastro $options $region -D CATDIR $catdir_3pi'
+
+## NOTE (2012.09.12, pt 1) : I previously ran relastro including all
+## photcodes.  For reasons I don't yet understand, the SCO data is
+## really messed up (bad dR,dD values), and messed up the mean
+## positions for lots of objects.  I am re-running update-objects with
+## only gpc1 and 2MASS data, and I will figure out how to fix SCO
+## later.
+
+## NOTE (2012.09.12, pt 2) : I used the default statmode previously:
+## this is bad since it results in different rejections and thus
+## inconsistent ChiSq values for ChiSqPos and ChiSqPM.  In this
+## re-run, explicitly used the weighted version
+
+# run update-objects on the whole sky
+if (1) then
+  # for a test, only run -pm
+  set options = "-update-objects -pmpar"
+  # set options = "-update-objects -pm"
+  set options = "$options -D PM_DT_MIN 1.0"
+  set options = "$options -D PAR_FACTOR_MIN 0.25"
+  set options = "$options -statmode WTMEAN"
+  set options = "$options +photcode g,r,i,z,y,J,H,K"
+  set options = "$options -update"
+  set options = "$options -parallel"
+  set options = "$options -reset"
+  set options = "$options -v"
+
+  # set region = "-region 180 190 30 40"
+  set region = "-region 0 360 -60 90"
+  
+  # run relastro -update-objects
+  run.relastro
+endif
+
+# try 2000 meas per deg^2, but if memory if available, go to more
+if (0) then
+  set options = "-update-chips"
+  set options = "$options -D RELASTRO_SRC_MEAS_TOOFEW 1"
+  set options = "$options -D RELASTRO_SIGMA_LIM 0.1"
+  set options = "$options -nloop 6"
+  set options = "$options -basic-image-search"
+  set options = "$options -reset"
+  set options = "$options -update"
+  set options = "$options -parallel"
+  set options = "$options -max-density 2000"
+  set options = "$options -threads 4"
+  set options = "$options -v"
+
+  # run relastro -update-chips
+  set ra_min = 0
+  while ($ra_min < 360) 
+    set ra_max = $ra_min
+    @ ra_max += 35
+  
+    if (($ra_min == 240) || ($ra_min == 270)) then 
+      set region = "-region $ra_min $ra_max -60 0"
+      run.relastro 
+
+      set region = "-region $ra_min $ra_max -5 60"
+      run.relastro
+
+      @ ra_min += 30
+      continue
+    endif
+
+    set region = "-region $ra_min $ra_max -60 60"
+    run.relastro
+
+    @ ra_min += 30
+  end
+
+  # pole region 
+  set region = "-region 0 360 55 90"
+  run.relastro
+endif
+
+echo -n "--- done with relastro ---"; date
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part2
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part2	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relastro.part2	(revision 35594)
@@ -0,0 +1,57 @@
+#!/bin/csh -f
+
+if ($#argv != 1) then 
+  echo "USAGE: run.relastro (catdir) "
+  exit 2
+endif
+
+set REALRUN = 1
+
+set catdir_3pi = $argv[1]
+
+alias run.relastro \
+  'echo -n "--- starting relastro $catdir_3pi ---"; date; \
+   echo          relastro $options $region -D CATDIR $catdir_3pi; \
+   if ($REALRUN) relastro $options $region -D CATDIR $catdir_3pi'
+
+## NOTE (2012.09.12, pt 1) : I previously ran relastro including all
+## photcodes.  For reasons I don't yet understand, the SCO data is
+## really messed up (bad dR,dD values), and messed up the mean
+## positions for lots of objects.  I am re-running update-objects with
+## only gpc1 and 2MASS data, and I will figure out how to fix SCO
+## later.
+
+## NOTE (2012.09.12, pt 2) : I used the default statmode previously:
+## this is bad since it results in different rejections and thus
+## inconsistent ChiSq values for ChiSqPos and ChiSqPM.  In this
+## re-run, explicitly used the weighted version
+
+# run update-objects on the whole sky
+if (1) then
+  # for a test, only run -pm
+  set options = "-update-objects -pmpar"
+  # set options = "-update-objects -pm"
+  set options = "$options -D PM_DT_MIN 1.0"
+  set options = "$options -D PAR_FACTOR_MIN 0.25"
+  set options = "$options -statmode WTMEAN"
+  set options = "$options +photcode g,r,i,z,y,J,H,K"
+  set options = "$options -update"
+  set options = "$options -parallel"
+  set options = "$options -reset"
+  set options = "$options -v"
+
+  # set region = "-region 180 190 30 40"
+  set region = "-region 0 360 -60 90"
+  
+  # run relastro -update-objects
+  run.relastro
+  if ($status) then
+	echo "ERROR : failure running relastro"
+	echo -n "--- done with relastro --- "; date
+	exit 1
+  endif
+
+endif
+
+
+echo -n "--- done with relastro ---"; date
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relphot
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relphot	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/gene.run.relphot	(revision 35594)
@@ -0,0 +1,134 @@
+#!/bin/csh -f
+if ($#argv != 1) then 
+  echo "USAGE: run.relphot (catdir)"
+  exit 2
+endif
+
+set REALRUN = 1
+
+set catdir_3pi = $argv[1]
+
+alias run.relphot \
+  'echo -n "--- starting relphot $catdir_3pi ---"; date; \
+   echo          relphot $options $region -D CATDIR $catdir_3pi; \
+   if ($REALRUN) relphot $options $region -D CATDIR $catdir_3pi'
+
+# try 2000 meas per deg^2
+if (0) then
+  set filters = "g,r,i,z,y"
+
+  set options = "-imfreeze -mosaic"
+  set options = "$options -D MAG_LIM 32.0"
+  set options = "$options -D SIGMA_LIM 0.1"
+  set options = "$options -D STAR_TOOFEW 1"
+  set options = "$options -D STAR_CHISQ 20.0"
+  set options = "$options -D IMAGE_OFFSET 2.0"
+  set options = "$options -D CAMERA gpc1"
+  set options = "$options -nloop 25"
+  set options = "$options -basic-image-search"
+  set options = "$options -update"
+  set options = "$options -reset"
+  set options = "$options -threads 4"
+  set options = "$options -parallel"
+  set options = "$options -statmode WT_MEAN"
+  set options = "$options -max-density 2000"
+
+  ## note the boundary tree location is hard-wired
+  set options = "$options -boundary-tree ~ippdvo/RINGS.V3.tree.v2.fits"
+
+  set options = "$options $filters"
+
+  # set options = "$options -update-catformat PS1_V3"
+
+  # loop over RA bins, splitting into south and north sections
+  set ra_min = 0
+  while ($ra_min < 360) 
+    set ra_max = $ra_min
+    @ ra_max += 35
+
+    # splitting the sky for all slices
+    # if (($ra_min == 240) || ($ra_min == 270)) then 
+
+    # south half
+    set region = "-region $ra_min $ra_max -60 0"
+    run.relphot
+    if ($status) then
+    	echo "ERROR : failure running relphot $ra_min $ra_max -60 0"
+    	echo -n "--- done with relphot --- "; date
+    endif
+
+    # north half
+    set region = "-region $ra_min $ra_max -5 90"
+    run.relphot
+    if ($status) then
+    	echo "ERROR : failure running relphot $ra_min $ra_max -5 90"
+    	echo -n "--- done with relphot --- "; date	
+    endif
+
+    @ ra_min += 30
+    continue
+  end
+endif
+
+## this block is used to set the mean mags in the assumption that the images are calibrated
+if (1) then
+  set filters = "g,r,i,z,y"
+
+  set options = "-imfreeze -mosaic"
+  set options = "$options -D MAG_LIM 32.0"
+  set options = "$options -D SIGMA_LIM 0.1"
+  set options = "$options -D STAR_TOOFEW 1"
+  set options = "$options -D STAR_CHISQ 20.0"
+  set options = "$options -D IMAGE_OFFSET 2.0"
+  set options = "$options -D CAMERA gpc1"
+  set options = "$options -basic-image-search"
+  set options = "$options -update"
+  set options = "$options -threads 4"
+  set options = "$options -parallel"
+  set options = "$options -statmode WT_MEAN"
+
+  ## note the boundary tree location is hard-wired
+  set options = "$options -boundary-tree ~ippdvo/RINGS.V3.tree.v2.fits"
+  set options = "$options -nloop 0"
+
+  set options = "$options $filters"
+
+  # loop over RA bins, splitting into south and north sections
+  set ra_min = 0
+  set ra_max = 360
+  set dec_min = -90
+  set dec_max = +90
+
+  set region = "-region $ra_min $ra_max $dec_min $dec_max"
+  run.relphot
+  if ($status) then
+    echo "ERROR : failure running relphot $ra_min $ra_max $dec_min $dec_max"
+    echo -n "--- done with relphot --- "; date
+  endif
+endif
+
+echo -n "--- done with relphot ---"; date
+
+## Note from Eddie re overall zero point
+## I compare to each of JT's 8 absolutely calibrated fields.  I compute
+## for each field the best zero point bringing my and his data into
+## agreement.  I report the mean and standard deviations of those zero
+## points over the eight fields.  The sign of the mean is such that mean
+## = < ubercal - JT >, so that these values should be subtracted from the
+## noref2.fits zero points in order to absolutely calibrate them.
+## 
+## filter g: mean = -0.013, sigma =  0.013
+## filter r: mean =  0.012, sigma =  0.007
+## filter i: mean =  0.001, sigma =  0.006
+## filter z: mean = -0.016, sigma =  0.007
+## filter y: mean = -0.021, sigma =  0.010
+## 
+## I think we're going to be adding a hundredth uncertainty in quadrature
+## with everything else getting this right.  John trusts his MD09 data
+## most; that gives results different from what I've given here by about
+## -0.01 in all of the bands.  The choice of whether to average over the
+## 8 fields or just use MD09 depends on whether you believe it's an
+## absolute calibration or relative calibration problem; I don't know.
+## Since the ~1 hundredth scatter is comparable with what we think the
+## uncertainty in ubercal is, I'm recommending using the values above,
+## averaged over the 8 fields.
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.addstar.resort
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.addstar.resort	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.addstar.resort	(revision 35594)
@@ -0,0 +1,35 @@
+#!/bin/csh -f
+
+if ($#argv != 1) then 
+  echo "USAGE: run.addstar.resort (catdir)"
+  exit 2
+endif
+
+set REALRUN = 1
+
+set  catdir = $argv[1]
+
+
+alias run.addstar \
+  'echo -n "--- starting addstar -resort $catdir --- "; date; \
+   echo          addstar -resort $options -D CATDIR $catdir ; \
+   if ($REALRUN) addstar -resort $options -D CATDIR $catdir'
+
+set options = ""
+set options = "$options -D CAMERA GPC1 "
+
+# activate parallel mode when catdir is parallel
+set options = "$options -parallel"
+
+run.addstar
+if ($status) then
+  echo "failed addstar -resort"
+  echo -n "--- done with addstar -resort ---"; date
+    
+  exit 1
+endif
+echo -n "--- done with addstar -resort ---"; date
+exit 0
+
+
+
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relastro.part1
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relastro.part1	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relastro.part1	(revision 35594)
@@ -0,0 +1,47 @@
+#!/bin/csh -f
+
+if ($#argv != 5) then 
+  echo "USAGE: run.relastro (catdir) (Rmin) (Rmax) (Dmin) (Dmax)"
+  exit 2
+endif
+
+set REALRUN = 1
+
+set  catdir = $argv[1]
+set  ra_min = $argv[2]
+set  ra_max = $argv[3]
+set dec_min = $argv[4]
+set dec_max = $argv[5]
+
+alias run.relastro \
+  'echo -n "--- starting relastro $catdir --- "; date; \
+   echo          relastro $options $region -D CATDIR $catdir; \
+   if ($REALRUN) relastro $options $region -D CATDIR $catdir'
+
+# -update-chips : determine improved astrometry calibrations
+# try 1000 meas per deg^2, but if memory if available, go to more
+if (1) then
+  set options = "-update-chips"
+  set options = "$options -D RELASTRO_SRC_MEAS_TOOFEW 1"
+  set options = "$options -D RELASTRO_SIGMA_LIM 0.1"
+  set options = "$options -nloop 6"
+  set options = "$options -basic-image-search"
+  set options = "$options -reset"
+  set options = "$options -update"
+  set options = "$options -max-density 3000"
+  set options = "$options -threads 4"
+  set options = "$options -v"
+
+  # enable parallel operations for parallel databases
+  set options = "$options -parallel"
+
+  set region = "-region $ra_min $ra_max $dec_min $dec_max"
+  run.relastro
+  if ($status) then
+    echo "ERROR : failure running relastro"
+    echo -n "--- done with relastro --- "; date
+    exit 1
+  endif
+endif
+
+echo -n "--- done with relastro --- "; date
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relastro.part2
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relastro.part2	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relastro.part2	(revision 35594)
@@ -0,0 +1,44 @@
+#!/bin/csh -f
+
+if ($#argv != 5) then 
+  echo "USAGE: run.relastro (catdir) (Rmin) (Rmax) (Dmin) (Dmax)"
+  exit 2
+endif
+
+set REALRUN = 1
+
+set  catdir = $argv[1]
+set  ra_min = $argv[2]
+set  ra_max = $argv[3]
+set dec_min = $argv[4]
+set dec_max = $argv[5]
+
+alias run.relastro \
+  'echo -n "--- starting relastro $catdir --- "; date; \
+   echo          relastro $options $region -D CATDIR $catdir; \
+   if ($REALRUN) relastro $options $region -D CATDIR $catdir'
+
+# -update-chips : determine improved astrometry calibrations
+# try 1000 meas per deg^2, but if memory if available, go to more
+
+# -update-objects : determine improved positions, including parallax and proper motions
+if (1) then
+  set options = "-update-objects -pmpar"
+  set options = "$options -D PM_DT_MIN 1.0"
+  set options = "$options -D PAR_FACTOR_MIN 0.25"
+  set options = "$options -update"
+  set options = "$options -v"
+
+  # enable parallel operations for parallel databases
+  set options = "$options -parallel"
+
+  set region = "-region $ra_min $ra_max $dec_min $dec_max"
+  run.relastro
+  if ($status) then
+    echo "ERROR : failure running relastro"
+    echo -n "--- done with relastro --- "; date
+    exit 1
+  endif
+endif
+
+echo -n "--- done with relastro --- "; date
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relphot
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relphot	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.relphot	(revision 35594)
@@ -0,0 +1,98 @@
+#!/bin/csh -f
+
+if ($#argv != 5) then 
+  echo "USAGE: run.relphot (catdir) (Rmin) (Rmax) (Dmin) (Dmax)"
+  exit 2
+endif
+
+set REALRUN = 1
+
+set  catdir = $argv[1]
+set  ra_min = $argv[2]
+set  ra_max = $argv[3]
+set dec_min = $argv[4]
+set dec_max = $argv[5]
+
+alias run.relphot \
+  'echo -n "--- starting relphot $catdir --- "; date; \
+   echo          relphot $options $region -D CATDIR $catdir; \
+   if ($REALRUN) relphot $options $region -D CATDIR $catdir'
+
+## this block is used to calibrate the images and set the mean mags
+# try 2000 meas per deg^2
+if (0) then
+  set filters = "g,r,i,z,y"
+
+  set options = "$filters -imfreeze -mosaic"
+  set options = "$options -D MAG_LIM 32.0"
+  set options = "$options -D SIGMA_LIM 0.1"
+  set options = "$options -D STAR_TOOFEW 1"
+  set options = "$options -D STAR_CHISQ 20.0"
+  set options = "$options -D IMAGE_OFFSET 2.0"
+
+  set options = "$options -nloop 25"
+
+  set options = "$options -D CAMERA gpc1"
+  set options = "$options -basic-image-search"
+  set options = "$options -update"
+  set options = "$options -threads 4"
+  set options = "$options -statmode WT_MEAN"
+  set options = "$options -max-density 2000"
+
+  ## note the boundary tree location is hard-wired
+  set options = "$options -boundary-tree ~ippdvo/RINGS.V3.tree.v2.fits"
+
+  # activate parallel mode when catdir is parallel
+  set options = "$options -parallel"
+
+  # option to change the schema
+  # set options = "$options -update-catformat PS1_V3"
+
+  set region = "-region $ra_min $ra_max $dec_min $dec_max"
+  run.relphot
+  if ($status) then
+    echo "ERROR : failure running relphot"
+    echo -n "--- done with relphot --- "; date
+    exit 1
+  endif
+endif
+
+## this block is used to set the mean mags in the assumption that the images are calibrated
+if (0) then
+  set filters = "g,r,i,z,y"
+
+  set options = "$filters -imfreeze -mosaic"
+  set options = "$options -D MAG_LIM 32.0"
+  set options = "$options -D SIGMA_LIM 0.1"
+  set options = "$options -D STAR_TOOFEW 1"
+  set options = "$options -D STAR_CHISQ 20.0"
+  set options = "$options -D IMAGE_OFFSET 2.0"
+
+  ## note the boundary tree location is hard-wired
+  set options = "$options -boundary-tree ~ippdvo/RINGS.V3.tree.v2.fits"
+  set options = "$options -nloop 0"
+
+  set options = "$options -D CAMERA gpc1"
+  set options = "$options -basic-image-search"
+  set options = "$options -update"
+  set options = "$options -threads 4"
+  set options = "$options -statmode WT_MEAN"
+  set options = "$options -max-density 2000"
+
+  # activate parallel mode when catdir is parallel
+  set options = "$options -parallel"
+
+  # option to change the schema
+  # set options = "$options -update-catformat PS1_V3"
+
+  set region = "-region $ra_min $ra_max $dec_min $dec_max"
+  run.relphot
+  if ($status) then
+    echo "ERROR : failure running relphot"
+    echo -n "--- done with relphot --- "; date
+    exit 1
+  endif
+endif
+
+echo -n "--- done with relphot --- "; date
+exit 0
Index: /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.setphot
===================================================================
--- /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.setphot	(revision 35594)
+++ /branches/eam_branches/ipp-20130509/tools/dvodb_calib/run.setphot	(revision 35594)
@@ -0,0 +1,41 @@
+#!/bin/csh -f
+
+if ($#argv != 1) then 
+  echo "USAGE: run.setphot (catdir)"
+  exit 2
+endif
+
+set REALRUN = 1
+
+set  catdir = $argv[1]
+set ubercal = ~ipp/ucalqw_noref.fits
+
+alias run.setphot \
+  'echo -n "--- starting setphot $catdir --- "; date; \
+   echo          setphot $options -D CATDIR $catdir $ubercal; \
+   if ($REALRUN) setphot $options -D CATDIR $catdir $ubercal'
+
+set options = ""
+set options = "$options -update"
+set options = "$options -ubercal"
+set options = "$options -no-metadata"
+
+# activate parallel mode when catdir is parallel
+set options = "$options -parallel"
+
+set options = "$options -v"
+# the new ubercal file includes Eddie's offsets relative to JT (so, no need to supply -zpt-offsets)
+run.setphot
+if ($status) then
+  echo "failed setphot"
+  echo -n "--- done with setphot ---"; date
+  exit 1
+endif
+echo -n "--- done with setphot ---"; date
+exit 0
+
+
+# old command lines with zpt offsets
+# setphot -parallel -reset -zpt-offsets g,r,i,z,y -0.013,+0.012,+0.001,-0.016,-0.021 -update -ubercal -no-metadata -D CATDIR $catdir_3pi $ubercal
+# setphot -images-only -parallel -reset -zpt-offsets g,r,i,z,y -0.013,+0.012,+0.001,-0.016,-0.021 -update -ubercal -no-metadata -D CATDIR $catdir_3pi $ubercal
+
