Index: /trunk/Ohana/src/imregister/base/ConfigCamera.c
===================================================================
--- /trunk/Ohana/src/imregister/base/ConfigCamera.c	(revision 69)
+++ /trunk/Ohana/src/imregister/base/ConfigCamera.c	(revision 70)
@@ -16,4 +16,5 @@
   ScanConfig (config, "NCCD", "%d", 1, &Nccd);
   ALLOCATE (ccds, char *, Nccd);
+  ALLOCATE (ccdn, char *, Nccd);
 
   for (i = 0; i < Nccd; i++) {
@@ -23,7 +24,12 @@
     ccds[i] = strcreate (ID);
   }
+
+  for (i = 0; i < Nccd; i++) {
+    sprintf (ID, "%02d", i);
+    ccdn[i] = strcreate (ID);
+  }
 }
 
-int MatchCCDName (Header *header) {
+int MatchCCDNameHeader (Header *header) {
 
   int i;
@@ -49,2 +55,17 @@
 }
 
+int MatchCCDName (char *ID) {
+
+  int i;
+
+  /* compare as number if ID is a complete number (ie, 00 equiv to 0, but 00b not equiv to 0b */
+  for (i = 0; i < Nccd; i++) {
+    if (strnumcmp (ccds[i], ID)) {
+      return (i);
+    }
+  }
+  
+  fprintf (stderr, "warning: ccd %s not found in camera config file\n", ID);
+  return (-1);
+}
+
Index: /trunk/Ohana/src/imregister/base/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/imregister/base/ConfigInit.c	(revision 69)
+++ /trunk/Ohana/src/imregister/base/ConfigInit.c	(revision 70)
@@ -55,4 +55,7 @@
   WarnConfig (config, "CAMERA-KEYWORD",              "%s", 0, CameraKeyword);
 
+  ScanConfig (config, "CAMERA",                      "%s", 0, Camera);
+  ScanConfig (config, "SEEING_REF_CCD",              "%s", 0, SeeingREFCCD);
+
   /* optional values */
   ScanConfig (config, "RA-DDD-KEYWORD",              "%s", 0, RADecDegKeyword);
Index: /trunk/Ohana/src/imregister/base/sort.c
===================================================================
--- /trunk/Ohana/src/imregister/base/sort.c	(revision 69)
+++ /trunk/Ohana/src/imregister/base/sort.c	(revision 70)
@@ -67,2 +67,84 @@
   }
 }
+
+void sortstr (char **S, int *X, int N) {
+
+  int l,j,ir,i;
+  char *tmpS;
+  int tmpX;
+  
+  if (N < 2) return;
+  l = N >> 1;
+  ir = N - 1;
+  for (;;) {
+    if (l > 0) {
+      l--;
+      tmpS = S[l];
+      tmpX = X[l];
+    } else {
+      tmpS = S[ir];
+      S[ir] = S[0];
+      tmpX = X[ir];
+      X[ir] = X[0];
+      if (--ir == 0) {
+	S[0] = tmpS;
+	X[0] = tmpX;
+	return;
+      }
+    }
+    i = l;
+    j = (l << 1) + 1;
+    while (j <= ir) {
+      if (j < ir && (strcmp(S[j], S[j+1]) < 0)) j++;
+      if (strcmp(tmpS, S[j]) < 0) {
+	S[i] = S[j];
+	X[i] = X[j];
+	j += (i=j) + 1;
+      }
+      else j = ir + 1;
+    }
+    S[i] = tmpS;
+    X[i] = tmpX;
+  }
+}
+
+void sortpair (int *X, int *Y, int N) {
+
+  int l,j,ir,i;
+  int tX, tY;
+  
+  if (N < 2) return;
+  l = N >> 1;
+  ir = N - 1;
+  for (;;) {
+    if (l > 0) {
+      l--;
+      tX = X[l];
+      tY = Y[l];
+    } else {
+      tX = X[ir];
+      X[ir] = X[0];
+      tY = Y[ir];
+      Y[ir] = Y[0];
+      if (--ir == 0) {
+	X[0] = tX;
+	Y[0] = tY;
+	return;
+      }
+    }
+    i = l;
+    j = (l << 1) + 1;
+    while (j <= ir) {
+      if (j < ir && X[j] < X[j+1]) j++;
+      if (tX < X[j]) {
+	X[i] = X[j];
+	Y[i] = Y[j];
+	j += (i=j) + 1;
+      }
+      else j = ir + 1;
+    }
+    X[i] = tX;
+    Y[i] = tY;
+  }
+}
+
Index: /trunk/Ohana/src/imregister/detrend/args.detsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/args.detsearch.c	(revision 69)
+++ /trunk/Ohana/src/imregister/detrend/args.detsearch.c	(revision 70)
@@ -301,8 +301,10 @@
     }
   }
+  /*
   if ((base.Type != T_DARK) && base.ExptimeSelect) {
     fprintf (stderr, "ERROR: exptime invalid with type %s\n", typename[base.Type]);
     exit (1);
   }
+  */
   if (output.Select && !base.TimeSelect) {
     fprintf (stderr, "ERROR: selection missing time\n");
Index: /trunk/Ohana/src/imregister/detrend/output.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/output.c	(revision 69)
+++ /trunk/Ohana/src/imregister/detrend/output.c	(revision 70)
@@ -180,5 +180,5 @@
 int PrintSubset (DetReg *detdata, Match *match, int Nmatch) {
   
-  char *dBPath, *typestr, *filtstr;
+  char *dBPath, *typestr, *filtstr, filename[128];
   char *timestr, *modestr, *ccdstr, ccdinfo[16], ccdformat[16];
   int i, j, Nc;
@@ -218,9 +218,15 @@
 
     /* output mode (Select vs List) */
+    if (output.Chipname && criteria[0].CCDSelect && detdata[i].mode == M_MEF) {
+      snprintf (filename, 128, "%s[%s]", detdata[i].filename, ccds[criteria[0].CCD]);
+    } else {
+      strcpy (filename, detdata[i].filename);
+    }
+
     if (output.Select) {
-      fprintf (stdout, "%s/%s\n", dBPath, detdata[i].filename);
+      fprintf (stdout, "%s/%s\n", dBPath, filename);
     } else {
       fprintf (stdout, "%-40s = %19s %7s %6s %6s %s %2d %2d %6.1f  %20s\n", 
-	       detdata[i].filename, timestr, modestr, typestr, filtstr, ccdstr,
+	       filename, timestr, modestr, typestr, filtstr, ccdstr,
 	       detdata[i].Nentry, detdata[i].Norder, detdata[i].exptime, detdata[i].label);
     }
Index: /trunk/Ohana/src/imregister/detrend/recipe.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/recipe.c	(revision 69)
+++ /trunk/Ohana/src/imregister/detrend/recipe.c	(revision 70)
@@ -39,5 +39,7 @@
       }
       if (!strcasecmp (RecipeType[i], "flat") ||
+	  !strcasecmp (RecipeType[i], "scatter") ||
 	  !strcasecmp (RecipeType[i], "fringe") ||
+	  !strcasecmp (RecipeType[i], "frpts") ||
 	  !strcasecmp (RecipeType[i], "modes")) {
 	crit[Ns].FilterSelect = TRUE;
@@ -46,7 +48,9 @@
 	crit[Ns].CCDSelect = FALSE;
       }
+      /*      
       if (!strcasecmp (RecipeType[i], "dark")) {
-	crit[Ns].ExptimeSelect = TRUE;
-      }
+      crit[Ns].ExptimeSelect = TRUE;
+      } 
+      */
       Ns ++;
     }
Index: /trunk/Ohana/src/imregister/imreg/args.imregister.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/args.imregister.c	(revision 69)
+++ /trunk/Ohana/src/imregister/imreg/args.imregister.c	(revision 70)
@@ -2,5 +2,4 @@
 # include "imreg.h"
 
-/* args is now greatly simplified from the rsh-fork version */
 int args (int argc, char **argv) {
 
@@ -25,4 +24,5 @@
   /* all imregister programs are implicitly modifying the db */
   output.modify = TRUE;
+  IMSORT = FALSE;
 
   if (strstr (argv[0], "imregister") != (char *) NULL) {
@@ -45,9 +45,38 @@
       exit (1);
     }
+    IMSORT = TRUE;
     return (TRUE);
   }
   if (strstr (argv[0], "imstatreg") != (char *) NULL) {
+
+    char *path, *file;
+
+    CLIENT = TRUE;
+
+    /* set up name to lockfile */
+    path = pathname (ImageDB);
+    file = filebasename (ImageDB);
+    ALLOCATE (PIDFILE, char, strlen (path) + strlen (file) + 10);
+    sprintf (PIDFILE, "%s/.%s.pid", path, file);
+
+    /* check for daemon mode */
+    if (N = get_argument (argc, argv, "-daemon")) {
+      remove_argument (N, &argc, argv);
+      CLIENT = FALSE;
+
+      /* special daemon options */
+      if (get_argument (argc, argv, "-kill"))   KillProcess (PIDFILE);
+      if (get_argument (argc, argv, "-status")) StatusProcess (PIDFILE);
+
+      if (argc != 1) {
+	fprintf (stderr, "ERROR: Usage: imstatreg\n");
+	exit (1);
+      }
+      return (TRUE);
+    }
+
     if (argc != 4) {
       fprintf (stderr, "ERROR: Usage: imstatreg (fits) (stats) (sdat) [-split] [-noreg]\n");
+      fprintf (stderr, "       or:    imstatreg -daemon\n");
       exit (1);
     }
Index: /trunk/Ohana/src/imregister/imreg/args.imsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/args.imsearch.c	(revision 69)
+++ /trunk/Ohana/src/imregister/imreg/args.imsearch.c	(revision 70)
@@ -79,8 +79,15 @@
     }
     if (criteria.CCD == -1) {
-      fprintf (stderr, "ERROR: ccd %s choice out not found in camera config\n", argv[N]);
-      exit (1);
-    }
-
+      fprintf (stderr, "ERROR: ccd %s choice not found in camera config\n", argv[N]);
+      exit (1);
+    }
+
+    remove_argument (N, &argc, argv);
+    criteria.CCDSelect = TRUE;
+  }
+  /* select CCD seq number */
+  if (N = get_argument (argc, argv, "-ccdn")) {
+    remove_argument (N, &argc, argv);
+    criteria.CCD = atoi (argv[N]);
     remove_argument (N, &argc, argv);
     criteria.CCDSelect = TRUE;
@@ -172,11 +179,20 @@
 
   /*** command-line options which modify behavior (delete, modify, newpath, mef2split split2mef */
-  output.delete = output.modify = FALSE;
-  output.modify_path = output.modify_dist = FALSE;
-  output.mef2split = output.split2mef = FALSE;
+  output.delete = FALSE;
+  output.modify = FALSE;
+  output.modify_path = FALSE; 
+  output.modify_dist = FALSE;
+  output.mef2split = FALSE; 
+  output.split2mef = FALSE;
+  output.unique = FALSE;
 
   if (N = get_argument (argc, argv, "-delete")) {
     remove_argument (N, &argc, argv);
     output.delete = TRUE;
+  }
+
+  if (N = get_argument (argc, argv, "-unique")) {
+    remove_argument (N, &argc, argv);
+    output.unique = TRUE;
   }
 
Index: /trunk/Ohana/src/imregister/imreg/db.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/db.c	(revision 69)
+++ /trunk/Ohana/src/imregister/imreg/db.c	(revision 70)
@@ -3,5 +3,5 @@
 
 /* variables which describe the db */
-char *dBFile;
+char *dBFile = (char *) NULL;
 FILE *f;
 Header header;
@@ -14,4 +14,11 @@
 int dbstate = LCK_UNLOCK;
 
+int set_db (char *filename) {
+
+  /* be careful: don't change db without closing old db */
+  dBFile = filename;
+  return (TRUE);
+}
+
 RegImage *get_images (int *N) {
   *N = Nimage;
@@ -23,14 +30,19 @@
   int Nbytes;
 
+  /* assign pointers to new data block */
   free (image);
+  Nimage = Nnew;
+  image = new;
 
+  /* update header, table structures */
   fits_modify (table.header, "NAXIS2", "%d", 1, Nnew);
   table.header[0].Naxis[1] = Nnew;
   Nbytes = fits_matrix_size (table.header);
 
-  Nimage = Nnew;
-  image = new;
-  REALLOCATE (image, RegImage, Nbytes);
+  /* add padding space to buffer */
+  REALLOCATE ((char *) image, char, Nbytes);
   table.buffer = (char *) image;
+  table.size = Nbytes;
+
   return (TRUE);
 }
@@ -41,5 +53,9 @@
 
   lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
-  dBFile = ImageDB; /* loaded in ConfigInit */ 
+
+  if (dBFile == (char *) NULL) {
+    fprintf (stderr, "ERROR: db file is not set\n");
+    exit (1);
+  }
 
   /* lock database (soft) */
@@ -166,4 +182,9 @@
 }  
 
+int close_lock_db () {
+  close (f);
+  return (TRUE);
+}  
+
 int escape (int mode, char *message) {
   
Index: /trunk/Ohana/src/imregister/imreg/delete.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/delete.c	(revision 69)
+++ /trunk/Ohana/src/imregister/imreg/delete.c	(revision 70)
@@ -10,6 +10,7 @@
   image = get_images (&Nimage);
 
-  ALLOCATE (keep, int, Nimage);
+  ALLOCATE (keep, int, MAX (Nimage, 1));
   for (i = 0; i < Nimage; i++) keep[i] = TRUE;
+  fprintf (stderr, "total of %d images\n", Nimage);
 
   Nbad = 0;
@@ -20,7 +21,9 @@
     Nbad ++;
   }
+  fprintf (stderr, "delete %d images\n", Nbad);
 
   Nsubset = Nimage - Nbad;
-  ALLOCATE (subset, RegImage, Nsubset);
+  ALLOCATE (subset, RegImage, MAX (1, Nsubset));
+  fprintf (stderr, "keeping %d images\n", Nsubset);
   for (j = i = 0; i < Nimage; i++) {
     if (!keep[i]) continue;
Index: /trunk/Ohana/src/imregister/imreg/iminfo.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/iminfo.c	(revision 69)
+++ /trunk/Ohana/src/imregister/imreg/iminfo.c	(revision 70)
@@ -57,5 +57,5 @@
   if (SingleIsSplit && (image[0].mode == MODE_SINGLE)) {
     image[0].mode = MODE_SPLIT;
-    image[0].ccd  = MatchCCDName (&header);
+    image[0].ccd  = MatchCCDNameHeader (&header);
   }
   /* is there a better way to id a 'split' image? */
Index: /trunk/Ohana/src/imregister/imreg/modify.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/modify.c	(revision 69)
+++ /trunk/Ohana/src/imregister/imreg/modify.c	(revision 70)
@@ -68,4 +68,12 @@
     }
 
+    if (output.modify_filter) {
+      strncpy (image[i].filter, output.filter, 31);
+    }
+
+    if (output.modify_type) {
+      image[i].type = output.type;
+    }
+
   }
 
Index: /trunk/Ohana/src/imregister/imreg/output.c
===================================================================
--- /trunk/Ohana/src/imregister/imreg/output.c	(revision 69)
+++ /trunk/Ohana/src/imregister/imreg/output.c	(revision 70)
@@ -173,76 +173,4 @@
 }
 
-void DumpCADCTable (char *filename, RegImage *image, int *match, int Nmatch) {
-  
-  int i, obsid;
-  char *datestr, *line, hdrname[99];
-  unsigned long tsecond;
-  Header header, theader;
-  Matrix matrix;
-  FTable table;
-  RegImage *subset;
-
-  /* create primary header */
-  fits_init_header (&header);    
-  header.extend = TRUE;
-  fits_create_header (&header);
-  fits_create_matrix (&header, &matrix);
-  fits_print (&header, "NEXTEND", "%d", 1, 1);
-  
-  /* create table header */
-  fits_create_table_header (&theader, "TABLE", "CADC_RAW_IMAGES");
-      
-  /* add current date/time to header */
-  str_to_time ("now", &tsecond);
-  datestr = sec_to_date (tsecond);
-  fits_modify (&header,  "DATE", "%s", 1, datestr);
-  fits_modify (&theader, "DATE", "%s", 1, datestr);
-
-  /* define table layout */
-  fits_define_table_column (&theader, "A99",   "FILENAME",     "filename in db",        "",                              1.0, 0.0);
-  fits_define_table_column (&theader, "A99",   "HDR_FILENAME", "filename in db",        "",                              1.0, 0.0);
-  fits_define_table_column (&theader, "I10",   "OBSID",        "image ID number",        "pixels",                         1.0, 0.0); 
-  fits_define_table_column (&theader, "F5.2",  "OBS_IQ",       "image quality",        "pixels",                         1.0, 0.0); 
-  fits_define_table_column (&theader, "F9.3",  "OBS_BG_VAL",   "background level",     "counts / pixel",                 1.0, 0.0); 
-
-  /* define TNULL, TNVAL values */
-  fits_modify (&theader, "TNULL1",  "%s", 1, "NULL");  /* FILENAME     */
-  fits_modify (&theader, "TNULL2",  "%s", 1, "NULL");  /* HDR_FILENAME */
-  fits_modify (&theader, "TNULL3",  "%s", 1, "0");     /* OBSID        */
-  fits_modify (&theader, "TNULL4",  "%s", 1, "NaN");   /* OBS_IQ       */
-  fits_modify (&theader, "TNULL5",  "%s", 1, "NaN");   /* OBS_BG_VAL   */
-
-  fits_modify (&theader, "TNVAL1",  "%s", 1, "NA");    /* FILENAME     */
-  fits_modify (&theader, "TNVAL2",  "%s", 1, "NA");    /* HDR_FILENAME */
-  fits_modify (&theader, "TNVAL3",  "%s", 1, "-1");    /* OBSID        */
-  fits_modify (&theader, "TNVAL4",  "%s", 1, "Inf");   /* OBS_IQ       */
-  fits_modify (&theader, "TNVAL5",  "%s", 1, "Inf");   /* OBS_BG_VAL   */
-
-  /* create table, add data values */
-  fits_create_table (&theader, &table);
-  
-  /* add data to table */
-  for (i = 0; i < Nmatch; i++) {
-    subset = &image[match[i]];
-
-    /* filename: NNNNNNx.fits or NNNNNNxNN.fits */
-    /* OBSID & HDR_FILENAME are derived from FILENAME */
-    obsid = atoi (subset[0].filename);
-    if (obsid < 400000) fprintf (stderr, "warning: derived obsid < 400000\n");
-    sprintf (hdrname, "%s.hdr", subset[0].filename);
-
-    line = fits_table_print (&table, subset[0].filename, hdrname, obsid, (subset[0].fwhm*ARCSEC_PIXEL), subset[0].sky);
-
-    fits_add_rows (&table, line, 1, strlen(line));
-    free (line);
-  }
-
-  fits_write_header  (filename, &header);
-  fits_write_matrix  (filename, &matrix);
-  fits_write_Theader (filename, &theader);
-  fits_write_table   (filename, &table);
-  exit (0);
-}
-
 /* Select, TimeMode are global */
 int PrintSubset (RegImage *image, int *match, int Nmatch) {
@@ -250,5 +178,5 @@
   char ccdstr[64];  
   int i, j;
-  char *pmode, *ptype, *timestr;
+  char *pmode, *ptype, *timestr, *root, *path;
 
   /* print the selected entries */
@@ -283,6 +211,19 @@
 
     if (PTstyle) {
-      /* this is somewhat poor: I have predefined a subset of value, and I can't guarantee that 'filter' has no spaces */
-      fprintf (stdout, "%s/%s %s %s %s\n", image[i].pathname, image[i].filename, image[i].filename, ccdstr, pmode);
+      root = filerootname (image[i].filename);
+
+      /* do i want ccdstr? add a dot? 654321o.ccd00.ext */
+      if (image[i].mode == MODE_MEF) {
+	fprintf (stdout, "%s/%s %s/%s%02d %s %s\n", image[i].pathname, image[i].filename, root, root, image[i].ccd, ccdstr, pmode);
+      }
+
+      if (image[i].mode == MODE_SPLIT) {
+	path = basename (image[i].pathname);
+	fprintf (stdout, "%s/%s %s/%s %s %s\n", image[i].pathname, image[i].filename, path, root, ccdstr, "SPLIT");
+      }
+
+      if ((image[i].mode == MODE_SINGLE) || (image[i].mode == MODE_CUBE)) {
+	fprintf (stdout, "%s/%s %s 0 %s\n", image[i].pathname, image[i].filename, root, pmode);
+      }
     } else {
       /* this is somewhat poor: I have predefined a subset of value, and I can't guarantee that 'filter' has no spaces */
Index: /trunk/Ohana/src/imregister/src/imregister.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imregister.c	(revision 69)
+++ /trunk/Ohana/src/imregister/src/imregister.c	(revision 70)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imregister $Revision: 3.0 $";
+static char *version = "imregister $Revision: 3.1 $";
 
 int main (int argc, char **argv) {
@@ -42,4 +42,6 @@
   }
 
+  set_db (ImageDB);
+
   if (!NoReg) {
     status = load_db ();
@@ -50,4 +52,5 @@
   }
 
+  if (IMSORT) SubmitImages (image);
   fprintf (stderr, "SUCCESS: registered %s\n", argv[1]);
   exit (0);
Index: /trunk/Ohana/src/imregister/src/imregtable.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imregtable.c	(revision 69)
+++ /trunk/Ohana/src/imregister/src/imregtable.c	(revision 70)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imregtable $Revision: 3.1 $";
+static char *version = "imregtable $Revision: 3.2 $";
 
 int main (int argc, char **argv) {
@@ -38,4 +38,6 @@
   ConvertStruct ((char *) image, sizeof (RegImage), Nimage, "regimage");
 
+  set_db (ImageDB);
+
   status = load_db ();
   if (!status) {
Index: /trunk/Ohana/src/imregister/src/imsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imsearch.c	(revision 69)
+++ /trunk/Ohana/src/imregister/src/imsearch.c	(revision 70)
@@ -1,5 +1,5 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imsearch $Revision: 3.0 $";
+static char *version = "imsearch $Revision: 3.1 $";
 
 int main (int argc, char **argv) {
@@ -11,4 +11,6 @@
   args (argc, argv);
 
+  set_db (ImageDB);
+
   status = load_db ();
   if (!status) {
@@ -19,4 +21,5 @@
   
   match = match_criteria (&Nmatch);
+  match = unique_entries (match, &Nmatch);
 
   if (output.modify) ModifySubset (match, Nmatch);
Index: /trunk/Ohana/src/imregister/src/imstatreg.c
===================================================================
--- /trunk/Ohana/src/imregister/src/imstatreg.c	(revision 69)
+++ /trunk/Ohana/src/imregister/src/imstatreg.c	(revision 70)
@@ -1,84 +1,85 @@
 # include "imregister.h"
 # include "imreg.h"
-static char *version = "imstatreg $Revision: 3.1 $";
+static char *version = "imstatreg $Revision: 3.2 $";
 
 int main (int argc, char **argv) {
  
-  FILE *f;
   RegImage *image;
   float *dtime;
-  int i, Nentry, Nslice, *match, Nmatch, status;
+  int i, *match, Nmatch, status, child;
+  char *TempDB, *LogFile;
 
   get_version (argc, argv, version);
   args (argc, argv);
-  image = iminfo (argv[1]);
 
-  /* if images is MEF or SPLIT/SINGLE, load stats file */
-  /* get stats file (has sky, bias, etc) */
-  switch (image[0].mode) {
-  case MODE_MEF:
-  case MODE_SPLIT:
-    f = fopen (argv[2], "r");
-    if (f == (FILE *) NULL) {
-      fprintf (stderr, "ERROR: can't open file.stats\n");
+  if (CLIENT) imregclient (argv[1], argv[2], argv[3]);
+
+  ALLOCATE (TempDB, char, strlen (ImageDB) + 10);
+  sprintf (TempDB, "%s.bfr", ImageDB);
+
+  SetSignals ();
+
+  if (child = fork ()) {
+    if (child == -1) {
+      fprintf (stderr, "error forking imstatreg -daemon \n");
       exit (1);
     }
-    fscanf (f, "%f %f", &image[0].sky, &image[0].bias);
-    fclose (f);
-    image[0].fwhm = get_fwhm (argv[3]);
-    Nentry = 1;
-    break;
-  case MODE_SINGLE:
-    f = fopen (argv[2], "r");
-    if (f == (FILE *) NULL) {
-      fprintf (stderr, "ERROR: can't open file.stats\n");
-      exit (1);
-    }
-    status = fscanf (f, "%d %f %f", &image[0].ccd, &image[0].sky, &image[0].fwhm);
-    fclose (f);
-    Nentry = 1;
-    break;
-  case MODE_CUBE:
-    f = fopen (argv[2], "r");
-    if (f == (FILE *) NULL) {
-      fprintf (stderr, "ERROR: can't open file.stats\n");
-      exit (1);
-    }
-    status = 3;
-    Nslice = image[0].ccd;
-    Nentry = Nslice + 1;
-    REALLOCATE (image, RegImage, Nentry);
-    dtime = (float *)&image[0].junk[0];
-    for (i = 0; i < Nentry; i++) {
-      image[i] = image[0];
-      status = fscanf (f, "%d %f %f", &image[i].ccd, &image[i].sky, &image[i].fwhm);
-      if (image[i].ccd == Nslice) continue;
-      image[i].obstime += *dtime*image[i].ccd;
-    }
-    fclose (f);
-    Nentry = i;
-    break;
-  }
-  if (NoReg) dump_data (image, Nentry);
-
-  status = load_db ();
-  if (!status) {
-    fprintf (stderr, "ERROR: database does not yet exist\n");
-    close_db ();
-    exit (1);
+    fprintf (stderr, "starting imstatreg, logging to %s\n", LogFile);
+    exit (0);
   }
 
-  match = match_images (image, Nentry, &Nmatch);
-  if (!Nmatch) {
-    close_db ();
-    fprintf (stderr, "ERROR: no matched images found\n");
-    fprintf (stderr, "image: %s %s (%d) %s (%d)\n", image[0].filename, sec_to_date (image[0].obstime), image[0].obstime, ccds[image[0].ccd], image[0].ccd);
-    exit (2);
+  /* child process, check for process */
+  ConfigPID (PIDFILE);
+
+  /* redirect stderr, stdout to logfile */
+  ALLOCATE (LogFile, char, strlen (ImageDB) + 10);
+  sprintf (LogFile, "%s.log", ImageDB);
+  tmpfd = freopen (LogFile, "w", stderr);
+  if (tmpfd == (FILE *) NULL) 
+    fprintf (LogFile, "can't open log file %s, writing to stderr\n", LogFile);
+  else 
+    stderr = tmpfd;
+  tmpfd = freopen (LogFile, "w", stdout);
+  if (tmpfd == (FILE *) NULL) 
+    fprintf (LogFile, "can't open log file %s, writing to stderr\n", LogFile);
+  else 
+    stdout = tmpfd;
+
+    /* start loop */
+  while (1) {
+
+    fflush (stderr);
+    fflush (stdout);
+    set_db (TempDB);
+    status = load_db ();
+    if (!status) {
+      fprintf (stderr, "temporary database is empty\n");
+      close_db (); sleep (60); continue;
+    }
+    image = get_images (&Nentry);
+    close_lock_db (); /* file closed, hardlock on temp db remains */
+      
+    set_db (ImageDB);
+    status = load_db ();
+    if (!status) {
+      fprintf (stderr, "database is empty\n");
+      close_db (); sleep (60); continue;
+    }
+      
+    match = match_images (image, Nentry, &Nmatch);
+    if (!Nmatch) {
+      close_db ();
+      fprintf (stderr, "ERROR: no matched images found\n");
+      fprintf (stderr, "image: %s %s (%d) %s (%d)\n", image[0].filename, sec_to_date (image[0].obstime), image[0].obstime, ccds[image[0].ccd], image[0].ccd);
+      exit (2);
+    }
+    update_db (match, Nmatch);
+      
+    /* clear temp db hardlock */
+    unlink (TempDB);
+    clearlockfile2 (TempDB, -1, LCK_HARD, &status);
+    sleep (60);
   }
-
-  update_db (match, Nmatch);
-
-  fprintf (stdout, "SUCCESS\n");
-  exit (0);
 }
 
+
Index: /trunk/Ohana/src/perl/src/ckimregdb
===================================================================
--- /trunk/Ohana/src/perl/src/ckimregdb	(revision 69)
+++ /trunk/Ohana/src/perl/src/ckimregdb	(revision 70)
@@ -14,4 +14,7 @@
 
 # test for current camera?
+
+system ("gconfig CAMERA");
+exit; 
 
 $start = $ARGV[0];
Index: /trunk/Ohana/src/perl/src/dads.detrend
===================================================================
--- /trunk/Ohana/src/perl/src/dads.detrend	(revision 69)
+++ /trunk/Ohana/src/perl/src/dads.detrend	(revision 70)
@@ -5,6 +5,38 @@
 $DO_DEFRINGE = 0;
 $DO_DEMODE   = 0;
-
-if (@ARGV != 3) { die "USAGE: dads.detrend (input) (outbase) (level)\n" }
+$config = "";
+if ($ENV{'PTOLEMY'}) { $config = "-c $ENV{'PTOLEMY'}"; }
+$tmpenv = `mktemp /tmp/elixir.XXXXXX`; chop ($tmpenv);
+
+@opt = ();
+@tARGV = ();
+for (; @ARGV > 0; ) {
+    if ($ARGV[0] eq "-c") {
+        $config = "-c $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-C") {
+        push @opt, "-C $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-D") {
+        push @opt, "-D $ARGV[1] $ARGV[2]";
+        shift; shift; shift; next;
+    }
+    if ($ARGV[0] eq "-cleanup") {
+	$CLEANUP = 0;
+        shift; next;
+    }
+    @tARGV = (@tARGV, $ARGV[0]);
+    shift;
+}
+@ARGV = @tARGV;
+
+$config = join (" ", $config, @opt);
+$status = system ("gconfig -raw $config > $tmpenv");
+if ($status) { &escape ("error in elixir configuration: gconfig fails"); }
+$ENV{'PTOLEMY'} = "$tmpenv";
+
+if (@ARGV != 3) { &escape ("USAGE: dads.detrend (input) (outbase) (level) [-cleanup] [elixir options]"); }
 
 $input  = $ARGV[0];   # input : /path/path/654321o.fits 
@@ -15,5 +47,5 @@
 $level = "\U$level\E";
 if (($level ne "PERFECT") && ($level ne "BEST") && ($level ne "RAW")) {
-    die "ERROR: invalid entry for (level)\n";
+    &escape ("ERROR: invalid entry for (level)");
 }
 $close = "";
@@ -21,14 +53,14 @@
 
 # check for input file (must be MEF)
-if (! -e $input) { die "ERROR: input file not found\n"; }
+if (! -e $input) { &escape ("ERROR: input file not found"); }
 
 # for raw distribution, simply use fhtool to split the files:
 if ($level eq "RAW") {
     system ("rmdir $outdir");
-    if ($?) { die "ERROR: can't remove target directory for fhtool\n"; }
+    if ($?) { &escape ("ERROR: can't remove target directory for fhtool"); }
     system ("fhtool $input $outdir");
-    if ($?) { die "ERROR: failure in fhtool\n"; }
+    if ($?) { &goodbye ("ERROR: failure in fhtool"); }
     print STDOUT "SUCCESS: finished with dads.detrend\n";
-    exit 0;
+    &goodbye;
 }
 
@@ -36,28 +68,28 @@
 if (! -d $outdir) { 
     system ("mkdir -p $outdir"); 
-    if ($?) { die "ERROR: can't create output directory\n"; }
+    if ($?) { &goodbye ("ERROR: can't create output directory"); }
 }
 
 # load ccd config information
-@ccdn   = split (" ", `cameraconfig -ccdn`); if ($?) { die "ERROR in cameraconfig\n"; }
-@ccds   = split (" ", `cameraconfig -ccds`); if ($?) { die "ERROR in cameraconfig\n"; }
+@ccdn   = split (" ", `cameraconfig -ccdn`); if ($?) { &goodbye ("ERROR in cameraconfig"); }
+@ccds   = split (" ", `cameraconfig -ccds`); if ($?) { &goodbye ("ERROR in cameraconfig"); }
 
 # load abstracted keywords
 ($typekwd, $filtkwd, $exptkwd) = split (" ", `gconfig IMAGETYPE-KEYWORD FILTER-KEYWORD EXPTIME-KEYWORD`);
-if ($?) { die "ERROR: config system missing keyword abstractions\n"; }
+if ($?) { &goodbye ("ERROR: config system missing keyword abstractions"); }
 
 # extract keyword values:
 ($junk, $type, $exptime, $filtvalue) = split (" ", `echo $input | fields $typekwd $exptkwd $filtkwd`);
-if ($?) { die "ERROR: failure reading header keywords (1)\n"; }
+if ($?) { &goodbye ("ERROR: failure reading header keywords (1)"); }
 
 # check for valid imagetype & filter
-if ($type ne "OBJECT") { die "ERROR: $input: wrong image type\n"; }
+if ($type ne "OBJECT") { &goodbye ("ERROR: $input: wrong image type"); }
 $filter = `filtnames $filtvalue`; chop $filter;
-if ($?) { die "ERROR: filter not found\n"; }
+if ($?) { &goodbye ("ERROR: filter not found"); }
 
 # check recipe file for detrend types & cutoff exptime values
 $recipefile = `gconfig DETREND_RECIPES`; chop $recipefile;
 ($detypes, $cutoffs) = split (" ", `gconfig -c $recipefile $filter`);
-if ($?) { die "ERROR: failure to get detrend recipes\n"; }
+if ($?) { &goodbye ("ERROR: failure to get detrend recipes"); }
 @detypes = split (",", $detypes);
 @cutoffs = split (",", $cutoffs);
@@ -81,9 +113,9 @@
 # check the GEOMETRY:
 ($tmp, $bin1, $bin2, $raster) = split (" ", `echo $input | fields CCDBIN1 CCDBIN2 RASTER`);
-if ($?) { die "ERROR: failure reading header keywords (2)\n"; }
-
-if ($bin1 != 1) { die "ERROR: $input: binned image\n"; }
-if ($bin2 != 1) { die "ERROR: $input: binned image\n"; }
-if ($raster ne "FULL") { die "ERROR: $input: sub-rastered image\n"; } 
+if ($?) { &goodbye ("ERROR: failure reading header keywords (2)"); }
+
+if ($bin1 != 1) { &goodbye ("ERROR: $input: binned image"); }
+if ($bin2 != 1) { &goodbye ("ERROR: $input: binned image"); }
+if ($raster ne "FULL") { &goodbye ("ERROR: $input: sub-rastered image"); } 
 
 # print a summary of the processing
@@ -158,4 +190,5 @@
     if ($status) { &escape ("ERROR: problem running flatten on $input, $ccds[$i]"); }
 }
+
 
 # we need files containing detlist, demlist, deflist:
@@ -183,4 +216,5 @@
     }
     close (FILE);
+    if (!$DO_DEMODE) { $demlist = $detlist; }
 }
 
@@ -195,15 +229,7 @@
 }
 
-&cleanup;
-print STDOUT "SUCCESS: finished with dads.detrend\n";
-exit 0;
-
-sub escape {
-    # cleanup temporary files:
-
-    &cleanup;
-    die "$_[0]\n";
-    exit 1;
-}
+&goodbye ("SUCCESS: finished with dads.detrend");
+
+########################################################################
 
 sub cleanup {
@@ -211,4 +237,5 @@
     if (!$CLEANUP) { return; }
 
+    unlink $tmpenv;
     # detlist, demlist, deflist
     foreach $name (@detlist) {
@@ -246,5 +273,12 @@
 
 sub goodbye {
-    die "@_\n";
-}
-
+    &cleanup; 
+    print STDERR "@_\n";
+    exit 0;
+}
+
+sub escape {
+    &cleanup;
+    print STDERR "@_\n";
+    exit 1;
+}
Index: /trunk/Ohana/src/perl/src/defringe
===================================================================
--- /trunk/Ohana/src/perl/src/defringe	(revision 69)
+++ /trunk/Ohana/src/perl/src/defringe	(revision 70)
@@ -14,9 +14,9 @@
 @ARGV = @tARGV;
 
-if (@ARGV != 2) { &escape ("ERROR: USAGE: defringe (inlist) (outlist) [-close]"); }
+if (@ARGV != 2) { &escape ("USAGE: defringe (inlist) (outlist) [-close]"); }
 
 # load config info
 $confdir = `gconfig CONFDIR`; chop $confdir;
-if ($?) { &escape ("ERROR: config failure"); }
+if ($?) { &escape ("config failure"); }
 $script = "$confdir/mana/fringe.pro";
 
@@ -26,8 +26,9 @@
 @ccds   = split (" ", `cameraconfig -ccds`);
 $Nccd   = @ccds;
+$dbmode = `gconfig DETREND-DB-MODE`; chop $dbmode;
 
 # find fringe-point file
 $frpts  = `detsearch -quiet -image $input[0] $ccds[0] split -type frpts`; chop $frpts;
-if ($?) { &escape ("ERROR: can't get fringe points for image"); }
+if ($?) { &escape ("can't get fringe points for image"); }
 
 # temporary files
@@ -46,13 +47,20 @@
     # measure fringe amplitude of input image
     vsystem ("getfringe $input[$i] $ccds[$i]  $frpts 1 >> $imstats");
-    if ($?) { die "ERROR: failure to measure fringe amplitude\n"; }
+    if ($?) { die "failure to measure fringe amplitude\n"; }
 
     # find fringe master frames
-    $fringe[$i] = `detsearch -quiet $close -image $input[$i] $ccds[$i] split -type fringe`; chop $fringe[$i];
-    if ($?) { &escape ("ERROR: can't find fringe master for $input[$i]"); }
+    $file = `detsearch -quiet $close -image $input[$i] $ccds[$i] split -type fringe`; chop $file;
+    if ($?) { &escape ("can't find fringe master for $input[$i]"); }
+    $fringe[$i] = $file;
+    if ($dbmode eq "MEF") { $fringe[$i] = "$file\[$ccds[$i]\]"; }
 
     # get fringe master stats
-    ($name, $C0, $C1, $SKY, $RNG) = split (" ", `echo $fringe[$i] | fields FRNG_C0 FRNG_C1 FRNG_SKY FRNG_RNG`);
+    if ($dbmode eq "MEF") {
+	($name, $C0, $C1, $SKY, $RNG) = split (" ", `echo $file | fields -x $i FRNG_C0 FRNG_C1 FRNG_SKY FRNG_RNG`);
+    } else {
+	($name, $C0, $C1, $SKY, $RNG) = split (" ", `echo $file | fields FRNG_C0 FRNG_C1 FRNG_SKY FRNG_RNG`);
+    }
     print FILE "$C0 $C1 $SKY $RNG\n";
+    print STDERR "$C0 $C1 $SKY $RNG\n";
 
     # check on output directory
@@ -65,5 +73,5 @@
 # convert image stats to optimal image parameters
 vsystem ("fr.frstats -applyfit $imstats $frstats $fitpars");
-if ($?) { &escape ("ERROR: can't assign DISPLAY"); }
+if ($?) { &escape ("failure in fr.frstats"); }
 @fitpars = `cat $fitpars`;
 
@@ -97,12 +105,8 @@
 
     vsystem ("imcombred $parfile");
-    if ($?) { &escape ("ERROR: failure running imcombred"); }
+    if ($?) { &escape ("failure running imcombred"); }
 }
 
-exit 0;
-
-foreach $name (@temp) { unlink ($name); }
-print STDERR "SUCCESS\n";
-exit 0;
+&goodbye;
 
 ########
@@ -119,5 +123,5 @@
     if (! -e $dir) {
 	system ("mkdir -p $dir");
-	if ($?) { die "ERROR: can't create output directory $dir\n"; }
+	if ($?) { die "can't create output directory $dir\n"; }
     }
 }
@@ -155,4 +159,5 @@
 sub escape {
     $message = $_[0];
+    die "$message\n";
     foreach $name (@temp) {
 	unlink ($name);
@@ -161,2 +166,6 @@
 }
 
+sub goodbye {
+    foreach $name (@temp) { unlink ($name); }
+    exit 0;
+}
Index: /trunk/Ohana/src/perl/src/detflips
===================================================================
--- /trunk/Ohana/src/perl/src/detflips	(revision 69)
+++ /trunk/Ohana/src/perl/src/detflips	(revision 70)
@@ -1,3 +1,20 @@
 #!/usr/bin/env perl
+
+# grab the command line options [-C config] [-c configfile]
+$config = "";
+@tARGV = ();
+while (@ARGV) {
+    if ($ARGV[0] eq "-C") {
+	$config = "$config -C $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-c") {
+	$config = "$config -c $ARGV[1]";
+        shift; shift; next;
+    }
+    push @tARGV, $ARGV[0];
+    shift;
+}
+@ARGV = @tARGV;
 
 if (@ARGV != 3) { die "ERROR: USAGE: detflips (inlist) (output) (type)\n" }
@@ -19,8 +36,9 @@
 $temp2 = `mktemp /tmp/\@detflips.XXXXXX`; chop $temp2;
 
-if ($type eq "BIAS")   { $paramkey = "FLIPS_PARAM_DARK";   $detype = "bias";    }
-if ($type eq "DARK")   { $paramkey = "FLIPS_PARAM_DARK";   $detype = "dark";    }
-if ($type eq "FLAT")   { $paramkey = "FLIPS_PARAM_FLAT";   $detype = "skyflat"; }
-if ($type eq "FRINGE") { $paramkey = "FLIPS_PARAM_FRINGE"; $detype = "fringe";  }
+if ($type eq "BIAS")    { $paramkey = "FLIPS_PARAM_DARK";   $detype = "bias";    }
+if ($type eq "DARK")    { $paramkey = "FLIPS_PARAM_DARK";   $detype = "dark";    }
+if ($type eq "FLAT")    { $paramkey = "FLIPS_PARAM_FLAT";   $detype = "skyflat"; }
+if ($type eq "FRINGE")  { $paramkey = "FLIPS_PARAM_FRINGE"; $detype = "fringe";  }
+if ($type eq "STACK")   { $paramkey = "FLIPS_PARAM_STACK";  $detype = "science";  }
 
 if ($paramkey eq "")  { 
@@ -29,10 +47,12 @@
 }
 
-$paramfile = `gconfig $paramkey`; chop $paramfile;
+$paramfile = `gconfig $config $paramkey`; chop $paramfile;
+if ($?) { die "ERROR: missing parameter file $paramkey from config\n"; }
+
 open (FILE, "$paramfile");
 @params = <FILE>;
 close (FILE);
 
-print STDERR "using: $paramfile\n";
+print STDERR "detflips parameter file: $paramfile\n";
 
 foreach $line (@params) {
Index: /trunk/Ohana/src/perl/src/elixir.photreport
===================================================================
--- /trunk/Ohana/src/perl/src/elixir.photreport	(revision 69)
+++ /trunk/Ohana/src/perl/src/elixir.photreport	(revision 70)
@@ -15,8 +15,7 @@
 $ENV{'DISPLAY'} = $xdisp;
 
-@filter = ("B", "V", "R", "I");
-# @filter = ("B");
+# select filters 
+@filter = split (" ", `filtnames list`);
 
-# this should come fron the config system
 $logdir   = `gconfig LOGDIR`;   chop $logdir;
 $confdir  = `gconfig CONFDIR`;  chop $confdir;
Index: /trunk/Ohana/src/perl/src/elixir.postrun
===================================================================
--- /trunk/Ohana/src/perl/src/elixir.postrun	(revision 69)
+++ /trunk/Ohana/src/perl/src/elixir.postrun	(revision 70)
@@ -202,10 +202,15 @@
 
 	$refs = `gconfig REFSDIR`; chop $refs;
-	$stds = "$refs/landolt/new";
+	$stds = "$refs/standards";
     
 	# insert standards in photometry database
 	foreach $filter (@filter) {
-	    vsystem ("addrefs -replace -v $stds/Landolt92$filter.fix $filter\_L92");
-	    vsystem ("addrefs -replace -v $stds/Landolt92$filter.hq  $filter\_L92_HQ");
+#	    vsystem ("addrefs -replace -v $stds/Landolt92$filter.fix $filter\_L92");	    
+#	    vsystem ("addrefs -replace -v $stds/Landolt92$filter.hq  $filter\_L92_HQ");
+
+	    @words = split (" ", `filtnames $filter -cal`);
+	    if ($words[1] == 0) { next; }
+	    $photref = $words[2];
+	    vsystem ("addrefs -replace -v $stds/$photref.dat $photref");
 	}
 
@@ -546,5 +551,5 @@
     # global variables
     # add this from the filter configuration system, eventually
-    @filter = ("B", "V", "R", "I");
+    @filter = split (" ", `filtnames list`);
 
     @def_state = ("camera",    "off",
Index: /trunk/Ohana/src/perl/src/flatten.flips
===================================================================
--- /trunk/Ohana/src/perl/src/flatten.flips	(revision 69)
+++ /trunk/Ohana/src/perl/src/flatten.flips	(revision 70)
@@ -7,6 +7,19 @@
 $quiet = 0;
 $close = "";
+$config = "";
 @tARGV = ();
 for (; @ARGV > 0; ) {
+    if ($ARGV[0] eq "-C") {
+        $config = "-C $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-c") {
+        $config = "-c $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-D") {
+        $config = "-D $ARGV[1] $ARGV[2]";
+        shift; shift; shift; next;
+    }
     if ($ARGV[0] eq "-fast") {
         $fast = 1;
@@ -50,12 +63,12 @@
 
 # find the appropriate detrend images (need to fix output name for MEF - option?)
-$flat=`detsearch -chipname -quiet -image $input $ccd $mode -type flat $close`; chop ($flat);
+$flat=`detsearch $config -chipname -quiet -image $input $ccd $mode -type flat $close`; chop ($flat);
 if ($?) { die "ERROR: can't get flat for image\n"; }
 
 if (!$fast) {
-    $bias=`detsearch -chipname -quiet -image $input $ccd $mode -type bias $close`; chop ($bias);
+    $bias=`detsearch $config -chipname -quiet -image $input $ccd $mode -type bias $close`; chop ($bias);
     if ($?) { die "ERROR: can't get bias for image\n"; }
 
-    $dark=`detsearch -chipname -quiet -image $input $ccd $mode -type dark $close`; chop ($dark);
+    $dark=`detsearch $config -chipname -quiet -image $input $ccd $mode -type dark $close`; chop ($dark);
     if ($?) { die "ERROR: can't get dark for image\n"; }
 }
@@ -64,12 +77,12 @@
 $mask = "none";
 if ($use_mask) {
-    $mask=`detsearch -chipname -quiet -image $input $ccd $mode -type mask $close`; chop ($mask);
+    $mask=`detsearch $config -chipname -quiet -image $input $ccd $mode -type mask $close`; chop ($mask);
     if ($?) { die "ERROR: can't get mask for image\n"; }
 }
 
 # abstracted keywords
-$ccdkeyword  = `gconfig -q CCDNUM-KEYWORD`;    chop ($ccdkeyword);
-$darkword    = `gconfig -q DARKTIME-FUNCTION`; chop ($darkword);
-$exptimeword = `gconfig -q EXPTIME-KEYWORD`;   chop ($exptimeword);
+$ccdkeyword  = `gconfig $config CCDNUM-KEYWORD`;    chop ($ccdkeyword);
+$darkword    = `gconfig $config DARKTIME-FUNCTION`; chop ($darkword);
+$exptimeword = `gconfig $config EXPTIME-KEYWORD`;   chop ($exptimeword);
 
 # find the appropriate fringe frame & coords file
@@ -80,5 +93,5 @@
     die "ERROR: -fringe not yet available in flatten.flips\n";
 
-    $filterword  = `gconfig -q FILTER-KEYWORD`;    chop ($filterword);
+    $filterword  = `gconfig $config FILTER-KEYWORD`;    chop ($filterword);
 
     # check the FILTER and EXPTIME, include fringe correction?:
@@ -87,5 +100,5 @@
 
     # recipe file defines detrend types & cutoff exptime values
-    $recipefile = `gconfig DETREND_RECIPES`; chop $recipefile;
+    $recipefile = `gconfig $config DETREND_RECIPES`; chop $recipefile;
     ($detypes, $cutoffs) = split (" ", `gconfig -c $recipefile $filter`);
     if ($?) { die "ERROR: failure to get detrend recipes\n"; }
@@ -104,8 +117,8 @@
     # grab necessary detrend files
     if ($use_fringe) {
-	$fringe = `detsearch -chipname -quiet -image $input $ccd $mode -type fringe $close`; chop ($fringe);
+	$fringe = `detsearch $config -chipname -quiet -image $input $ccd $mode -type fringe $close`; chop ($fringe);
 	if ($?) { die "ERROR: can't get fringe for image\n"; }
 
-	$frpts  = `detsearch -chipname -quiet -image $input $ccd $mode -type frpts $close`;
+	$frpts  = `detsearch $config -chipname -quiet -image $input $ccd $mode -type frpts $close`;
 	if ($?) { die "ERROR: can't get fringe points for image\n"; }
     }
@@ -118,4 +131,5 @@
     ($junk, $t1) = split (" ", `echo $input    | fields $exptimeword`);
     ($name, $t2) = split (" ", `echo $darkfile | fields $exptimeword`);
+    print STDERR "darktime: $input, $t1; $darkfile, $t2\n";
     $darkfactor = `darktime.$darkword $t1 $t2`; chop ($darkfactor);
     if ($?) { die "ERROR: failure to get darkfactor $t1 $t2\n"; }
@@ -123,6 +137,6 @@
 
 # load FLIPS parameter file, fill in missing words:
-$paramfile = `gconfig FLIPS_IMRED_PARAM`; chop $paramfile;
-if ($?) { die "ERROR: missing FLIPS_IMRED_PARAM in config\n"; }
+$paramfile = `gconfig $config FLIPS_PARAM_IMRED`; chop $paramfile;
+if ($?) { die "ERROR: missing FLIPS_PARAM_IMRED in config\n"; }
 open (FILE, "$paramfile");
 @params = <FILE>;
Index: /trunk/Ohana/src/perl/src/fr.defringe
===================================================================
--- /trunk/Ohana/src/perl/src/fr.defringe	(revision 69)
+++ /trunk/Ohana/src/perl/src/fr.defringe	(revision 70)
@@ -31,4 +31,6 @@
 # load flips parameter file
 $paramfile = `gconfig FLIPS_PARAM_DEFRINGE`; chop $paramfile;
+if ($?) { die "ERROR: missing FLIPS_PARAM_DEFRINGE in config\n"; }
+
 open (FILE, "$paramfile");
 @rawpars = <FILE>;
@@ -66,7 +68,5 @@
 }
 
-foreach $name (@temp) { unlink ($name); }
-print STDERR "SUCCESS\n";
-exit 0;
+&goodbye;
 
 ########################################################
@@ -124,2 +124,10 @@
     die "$message\n";
 }
+
+sub goodbye {
+    foreach $name (@temp) { unlink ($name); }
+    print STDERR "SUCCESS\n";
+    exit 0;
+}
+
+
Index: /trunk/Ohana/src/perl/src/fr.select
===================================================================
--- /trunk/Ohana/src/perl/src/fr.select	(revision 69)
+++ /trunk/Ohana/src/perl/src/fr.select	(revision 70)
@@ -121,9 +121,14 @@
 
 open (LIST, ">$output");
-for ($i = 0; $i < @good; $i++) {
-    print LIST "$good[$i]\n";
-} 
+# write output to Nccd list files 
+# keep a random sample of roughly 40 images:
+$Nselect = @good;
+for ($i = 0; $i < $Nselect; $i++) {
+    if (rand ($Nselect) < 40) {
+	print LIST "$good[$i]\n";
+    }
+}
 close (LIST);
-print STDERR "SUCCESS\n";
+print STDERR "SUCCESS\n\n";
 exit 0;
 
Index: /trunk/Ohana/src/perl/src/fr.smooth
===================================================================
--- /trunk/Ohana/src/perl/src/fr.smooth	(revision 69)
+++ /trunk/Ohana/src/perl/src/fr.smooth	(revision 70)
@@ -22,4 +22,6 @@
 $Nccd   = @ccds;
 
+$CCDKEYWORD = `gconfig CCDNUM-KEYWORD`; chop $CCDKEYWORD;
+$dbmode = `gconfig DETREND-DB-MODE`; chop $dbmode;
 @frstats = `cat $frstats`;
 for ($i = 0; $i < @frstats; $i++) {
@@ -33,8 +35,24 @@
 # unbin and insert header keywords
 open (MANA, "|mana --norc");
+print MANA "list kernel\n";
+print MANA "  0.025\n";
+print MANA "  0.100\n";
+print MANA "  0.025\n";
+print MANA "  0.100\n";
+print MANA "  0.500\n";
+print MANA "  0.100\n";
+print MANA "  0.025\n";
+print MANA "  0.100\n";
+print MANA "  0.025\n";
+print MANA "end\n";
 print MANA "macro go\n";
 print MANA " rd a $infile\n";
 print MANA " rebin a A -$binning\n";
-print MANA " rd mask $mask\n";
+print MANA " \$CCDKEYWORD = $CCDKEYWORD\n";
+if ($dbmode eq "MEF") {
+    print MANA " rd mask $mask -n $ccds[$ccd]\n";
+} else {
+    print MANA " rd mask $mask\n";
+}
 print MANA " keyword A NAXIS1 nx1\n";
 print MANA " keyword A NAXIS2 ny1\n";
@@ -43,4 +61,5 @@
 print MANA " delete a\n";
 print MANA " extract A a 0 0 \$nx1 \$ny1 0 0 \$nx2 \$ny2\n";
+print MANA " kern a kernel \n";
 print MANA " set b = a*mask + $Fs*not(mask)\n";
 
@@ -68,4 +87,7 @@
 print MANA " keyword b COMMENT  -ws \"Elixir:fr.smooth version $version\"\n";
 print MANA " keyword b COMMENT  -ws \"Elixir Fringe Frame\"\n";
+print MANA " keyword b COMMENT  -ws \"Elixir smoothing: 3x3 kernel (1): 0.025, 0.100, 0.025\"\n";
+print MANA " keyword b COMMENT  -ws \"Elixir smoothing: 3x3 kernel (2): 0.100, 0.500, 0.100\"\n";
+print MANA " keyword b COMMENT  -ws \"Elixir smoothing: 3x3 kernel (3): 0.025, 0.100, 0.025\"\n";
 
 print MANA " wd b $outfile\n";
@@ -73,4 +95,5 @@
 
 print MANA "end\n";
+print MANA "macro list go\n";
 print MANA "go\n";
 print MANA "exit 1\n";
Index: /trunk/Ohana/src/perl/src/getfringe
===================================================================
--- /trunk/Ohana/src/perl/src/getfringe	(revision 69)
+++ /trunk/Ohana/src/perl/src/getfringe	(revision 70)
@@ -28,6 +28,6 @@
 
 # find input parameter file
-$paramfile = `gconfig FLIPS_IMSTAT_PARAM`; chop $paramfile;
-if ($?) { &escape ("params not in config system"); }
+$paramfile = `gconfig FLIPS_PARAM_IMSTAT`; chop $paramfile;
+if ($?) { &escape ("paramfile FLIPS_PARAM_IMSTAT not in config system"); }
 
 # fill in missing keywords
@@ -89,9 +89,5 @@
 print STDOUT "$input $sky $fringe $dfringe\n";
 
-# cleanup
-unlink $temp1;
-unlink $temp2;
-unlink $temp3;
-exit 0;
+&goodbye;
 
 ########
@@ -116,2 +112,9 @@
     die "$message\n";
 }
+
+sub goodbye {
+    foreach $name (@temp) { unlink ($name); }
+    exit 0;
+}
+
+
Index: /trunk/Ohana/src/perl/src/imclean.cfht
===================================================================
--- /trunk/Ohana/src/perl/src/imclean.cfht	(revision 69)
+++ /trunk/Ohana/src/perl/src/imclean.cfht	(revision 70)
@@ -1,3 +1,54 @@
 #!/usr/bin/env perl
+
+$config = "";
+@tARGV = ();
+for (; @ARGV > 0; ) {
+    if ($ARGV[0] eq "-C") {
+        $config = "-C $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-c") {
+        $config = "-c $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-D") {
+        $config = "-D $ARGV[1] $ARGV[2]";
+        shift; shift; shift; next;
+    }
+    @tARGV = (@tARGV, $ARGV[0]);
+    shift;
+}
+@ARGV = @tARGV;
+
+if (@ARGV < 3) { 
+    print STDERR "ERROR: USAGE: USAGE: imclean.cfht (fits) (obj) (cmp) [option]\n";
+    print STDERR "  corrects for errors with CD1_1, CRPIX1 on 12k for 51400 < MJD < 51540\n";
+    print STDERR "  also determines and inserts the photcode for the image\n";
+    exit 2;
+}
+
+# input image must already be in SPLIT mode
+
+# determine the photcode of this image:
+$photcode=`photcode $config -quiet $ARGV[0] 0 split`; chop $photcode;
+if ($?) { die "ERROR: cannot find photcode\n"; }
+
+# check if we need to correct the WCS terms (only CFH12K)
+($name, $id, $mjd) = split (" ", `echo $ARGV[0] | fields IMAGEID MJD-OBS`);
+
+$fix="";
+if (($mjd > 51400) && ($mjd < 51540) && (($id == 2) || ($id == 6))) {
+    $line = `echo $ARGV[0] | fields CD1_1 CRPIX1 NAXIS1`;
+    ($name, $cd11, $crpix1, $nx) = split (" ", $line, 4);
+    $crpix1 = $nx - $crpix1;
+    $cd11 = -$cd11;
+    $fix = "-key CD1_1 %f $cd11  -key CRPIX1 %f $crpix1";
+}
+
+vsystem ("imclean $config @ARGV -p $photcode $fix");
+
+exit 0;
+
+############
 
 sub vsystem {
@@ -12,37 +63,2 @@
 }
 
-if (@ARGV < 3) { 
-    print STDERR "ERROR: USAGE: USAGE: imclean.cfht (fits) (obj) (cmp) [option]\n";
-    print STDERR "  corrects for errors with CD1_1, CRPIX1 on 12k for 51400 < MJD < 51540\n";
-    print STDERR "  also determines and inserts the photcode for the image\n";
-    exit 2;
-}
-
-# input image must already be in SPLIT mode
-# determine the photcode of this image:
-$photcode=`photcode -quiet $ARGV[0] 0 split`;
-if ($?) {
-    print STDERR "ERROR: cannot find photcode\n";
-    exit 1;
-}
-chop ($photcode);
-
-# check if we need to correct the WCS terms
-$line = `echo $ARGV[0] | fields IMAGEID MJD-OBS`;
-chop ($line);
-($name, $id, $mjd) = split (" ", $line);
-$fix="";
-
-print STDERR "mjd $mjd, $id $id\n";
-if (($mjd > 51400) && ($mjd < 51540) && (($id == 2) || ($id == 6))) {
-    $line = `echo $ARGV[0] | fields CD1_1 CRPIX1 NAXIS1`;
-    ($name, $cd11, $crpix1, $nx) = split (" ", $line, 4);
-    $crpix1 = $nx - $crpix1;
-    $cd11 = -$cd11;
-    $fix = "-key CD1_1 %f $cd11  -key CRPIX1 %f $crpix1";
-}
-
-vsystem ("imclean @ARGV -p $photcode $fix");
-
-exit 0;
-
Index: /trunk/Ohana/src/perl/src/imstatqso
===================================================================
--- /trunk/Ohana/src/perl/src/imstatqso	(revision 69)
+++ /trunk/Ohana/src/perl/src/imstatqso	(revision 70)
@@ -27,4 +27,10 @@
 $line = `echo $ARGV[0] | fields $ccdkeyword`;
 ($tmp, $ccd) = split (" ", $line);
+
+if ($ccd =~ m|amp|) { 
+    # convert to equivalent ccd
+    ($n) = $ccd =~ m|amp(\d*)|;
+    $ccd = sprintf "ccd%02d", $n/2;
+}
 
 if ($ccd ne $refccd) {
Index: /trunk/Ohana/src/perl/src/mkfringe
===================================================================
--- /trunk/Ohana/src/perl/src/mkfringe	(revision 69)
+++ /trunk/Ohana/src/perl/src/mkfringe	(revision 70)
@@ -955,4 +955,8 @@
     @list = load_config ();
     
+    # create directory for fhtool to work in
+    $links = mkfiles ("links");
+    if (! -e $links) { mkdir ($links); }
+
     # create namelist for those with appropriate status
     foreach $confline (@list) {
@@ -982,4 +986,7 @@
 
 	if ($DBmode eq "MEF") {
+	    # empty link directory:
+	    system ("rm -f $links/*.fits");
+
 	    # make links 
 	    foreach $ccd (@ccds) {
@@ -991,4 +998,6 @@
 	    # mef, register
 	    $mef = mknames ("mef", $confline);
+	    system ("rm -f $mef");
+
 	    vsystem ("fhtool -P $links $mef");
 	    if ($status) { $success = 0; }
@@ -2541,5 +2550,5 @@
 	}
 	
-	if ($value eq "-C") {
+	if ($value eq "-D") {
 	    push @opt, $value;
 	    $value = shift @argv;
@@ -2600,7 +2609,26 @@
     if ($?) { &escape ("error with elixir camera configuration"); }
 
-    # desired types:
-    @type = ('fringe', 'fringe');
-    @filt = ('I',      'Z');
+    # get list of valid filters from lookup table
+    @filters = split (" ", `filtnames list`);
+    if ($?) { &escape ("error with elixir filter configuration"); }
+
+    # recipe file defines detrend types & cutoff exptime values
+    $recipefile = `gconfig DETREND_RECIPES`; chop $recipefile;
+    if ($?) { &escape ("missing DETREND_RECIPES in configuration"); }
+
+    @filt = ();
+    foreach $filter (@filters) {
+	($detypes) = split (" ", `gconfig -c $recipefile $filter`);
+	if ($?) { die "ERROR: missing detrend recipe for $filter\n"; }
+
+	@detypes = split (",", $detypes);
+	for ($i = 0; $i < @detypes; $i++) {
+	    if ($detypes[$i] eq "fringe") {
+		push @filt, $filter;
+		push @type, "fringe";
+		last;
+	    }
+	}
+    }
 
     $CGI = `gconfig CGIBIN`; chop ($CGI);
Index: /trunk/Ohana/src/perl/src/mktrans
===================================================================
--- /trunk/Ohana/src/perl/src/mktrans	(revision 69)
+++ /trunk/Ohana/src/perl/src/mktrans	(revision 70)
@@ -6,5 +6,5 @@
 $stop  = $ARGV[1];
 
-@photcodes = ("B", "V", "R", "I", "Z"); 
+@photcodes = split (" ", `filtnames list`);
 
 foreach $code (@photcodes) {
Index: /trunk/Ohana/src/perl/src/mktreport
===================================================================
--- /trunk/Ohana/src/perl/src/mktreport	(revision 69)
+++ /trunk/Ohana/src/perl/src/mktreport	(revision 70)
@@ -6,5 +6,5 @@
 $stop  = $ARGV[1];
 
-@photcodes = ("B", "V", "R", "I"); 
+@photcodes = split (" ", `filtnames list`);
 
 @list = `transearch -offset`;
Index: /trunk/Ohana/src/perl/src/normalize
===================================================================
--- /trunk/Ohana/src/perl/src/normalize	(revision 69)
+++ /trunk/Ohana/src/perl/src/normalize	(revision 70)
@@ -1,5 +1,5 @@
 #!/usr/bin/env perl
 
-$revline = "\$Revision: 1.3 $?";
+$revline = "\$Revision: 1.4 $?";
 ($version) = $revline =~ m|\$Revision:\s*(\S*)|;
 
@@ -48,4 +48,5 @@
 $ccdword = `gconfig -q CCDNUM-KEYWORD`; chop ($ccdword);
 $typeword = `gconfig -q IMAGETYPE-KEYWORD`; chop ($typeword);
+$dbmode = `gconfig -q DETREND-DB-MODE`; chop ($dbmode);
 
 # choose appropriate type
@@ -151,9 +152,14 @@
     print MANA "echo 'starting normalize'\n";
     print MANA "rd a $input\n";
-    print STDERR "mask: $mask\n";
+    print MANA "\$CCDKEYWORD = $ccdword\n";
+    print MANA "keyword a $ccdword ccd\n";
     if ($mask eq "none") {
 	print MANA "set b = a / $refmode\n";
     } else {
-	print MANA "rd c $mask\n";
+	if ($dbmode eq "MEF") {
+	    print MANA "rd c $mask -n \$ccd\n";
+	} else {
+	    print MANA "rd c $mask\n";
+	}
 	print MANA "set b = (a / $refmode) * c\n";
     }
Index: /trunk/Ohana/src/shell/src/checkdisks
===================================================================
--- /trunk/Ohana/src/shell/src/checkdisks	(revision 69)
+++ /trunk/Ohana/src/shell/src/checkdisks	(revision 70)
@@ -1,5 +1,5 @@
 #!/bin/csh -f
 
-set disks="/data/elixir /data/elixir3 /data/koa /data/milo /data/elixir2 /data/kiawe /data/noni /data/ulu /data/hau /data/naupaka"
+set disks="/data/elixir /data/milo /data/elixir3 /data/koa /data/elixir2 /data/kiawe /data/noni /data/ulu /data/hau /data/naupaka"
 
 df $disks
Index: /trunk/Ohana/src/shell/src/el_plots
===================================================================
--- /trunk/Ohana/src/shell/src/el_plots	(revision 69)
+++ /trunk/Ohana/src/shell/src/el_plots	(revision 70)
@@ -7,6 +7,8 @@
 # check that camera is ok:
 set camera=`gconfig CAMERA.CURRENT`
+set datdir=`gconfig DATDIR`
 if ($camera == "cfh12k") goto valid;
 if ($camera == "cfhtir") goto valid;
+if ($camera == "megacam") goto valid;
 
 if ("$1" == "init") then
@@ -51,5 +53,5 @@
  endif 
 
- cp /data/milo/elixir/plots/seeing_night.png /apps/www/www.cfht.hawaii.edu/Instruments/Elixir/seeing/archive/seeing_$2.png
+ cp $datdir/plot/seeing_night.png /apps/www/www.cfht.hawaii.edu/Instruments/Elixir/seeing/archive/seeing_$2.png
  exit 0;
 
Index: /trunk/Ohana/src/shell/src/elixir.fork
===================================================================
--- /trunk/Ohana/src/shell/src/elixir.fork	(revision 69)
+++ /trunk/Ohana/src/shell/src/elixir.fork	(revision 70)
@@ -27,7 +27,16 @@
 
 # set logdir for various logging
-set logdir=`gconfig LOGDIR`
-if ($status) then 
- echo "error with elixir configurations: missing LOGDIR, using /tmp"
+# set logdir=`gconfig LOGDIR`
+# if ($status) then 
+#  echo "error with elixir configurations: missing LOGDIR, using /tmp" 
+# endif
+
+set logdir = "$HOME/elixir"
+if (! -e $logdir) then 
+  mkdir $logdir
+  if ($status) then 
+    echo "error with elixir configurations: missing LOGDIR, using /tmp" 
+    set logdir = "/tmp"
+  endif
 endif
 
Index: /trunk/Ohana/src/shell/src/elixir.launch
===================================================================
--- /trunk/Ohana/src/shell/src/elixir.launch	(revision 69)
+++ /trunk/Ohana/src/shell/src/elixir.launch	(revision 70)
@@ -8,11 +8,12 @@
 set run    = `gconfig RUNID.CURRENT`;
 set camera = `gconfig CAMERA.CURRENT`;
+set logdir = `gconfig LOGDIR`;
 
 if ($1 == "mkdetrend") then
     switch ($camera)
      case cfh12k:
-#     case megacam:
+     case megacam:
       echo "starting mkdetrend"
-      mkdetrend auto run -run $run -camera $camera >>& /data/milo/elixir/log/mkdetrend.log &
+      mkdetrend auto run -run $run -camera $camera >>& $logdir/mkdetrend.log &
       breaksw;
 
@@ -29,10 +30,10 @@
      case megacam:
       echo "starting elixir imstats"
-      elixir -restart -D mode imstats -D CAMERA $camera -D RUNID $run >>& /data/milo/elixir/log/imstats.log &
+      elixir -restart -D mode imstats -D CAMERA $camera -D RUNID $run >>& $logdir/imstats.log &
       breaksw;
 
      case cfhtir:
       echo "starting elixir irstats"
-      elixir -restart -D mode irstats -D CAMERA $camera -D RUNID $run >>& /data/milo/elixir/log/imstats.log &
+      elixir -restart -D mode irstats -D CAMERA $camera -D RUNID $run >>& $logdir/imstats.log &
       breaksw;
 
@@ -46,11 +47,9 @@
 
 if ($1 == "sextract") then
-    exit 0;
-
     switch ($camera)
      case cfh12k:
-#     case megacam:
+     case megacam:
       echo "starting elixir sextract"
-      elixir -restart -D mode sextract -D CAMERA $camera -D RUNID $run >>& /data/milo/elixir/log/sextract.log &
+      elixir -restart -D mode sextract -D CAMERA $camera -D RUNID $run >>& $logdir/sextract.log &
       breaksw;
 
Index: /trunk/Ohana/src/shell/src/getfocus
===================================================================
--- /trunk/Ohana/src/shell/src/getfocus	(revision 69)
+++ /trunk/Ohana/src/shell/src/getfocus	(revision 70)
@@ -135,7 +135,9 @@
 set i = 1
 while ($i <= $#ccds)
- $ccdnum = $ccdn[$i]
- $ccdnam = $ccns[$i]
+ echo $i $ccds
+ set ccdnum = $ccdn[$i]
+ set ccdnam = $ccds[$i]
  echo "split $fdir/$name.fits $ccdnam $temp.$ccdnum.fits" >> $temp.pro
+ @ i++
 end
 mana --norc --only $script $temp.pro
Index: /trunk/Ohana/src/shell/src/getseeing
===================================================================
--- /trunk/Ohana/src/shell/src/getseeing	(revision 69)
+++ /trunk/Ohana/src/shell/src/getseeing	(revision 70)
@@ -66,6 +66,7 @@
 if ($mef) then
  set Nextend = `echo $file | fields NEXTEND | awk '{print $2}'` 
- if ($Nextend > 50) set ccd = amp26
- echo "subraster.mef   $file $ccd $temp.fits $temp.stats" > $temp.pro
+ set tccd = $ccd
+ if ($Nextend > 50) set tccd = amp26
+ echo "subraster.mef   $file $tccd $temp.fits $temp.stats" > $temp.pro
 else
  echo "subraster.split $file $ccd $temp.fits $temp.stats" > $temp.pro
Index: /trunk/Ohana/src/shell/src/gosexphot
===================================================================
--- /trunk/Ohana/src/shell/src/gosexphot	(revision 69)
+++ /trunk/Ohana/src/shell/src/gosexphot	(revision 70)
@@ -15,4 +15,7 @@
     if ("$3" == "-shallow") then
         set name="gosexshallow.sex"
+    endif
+    if ("$3" == "-deep") then
+        set name="gosexdeep.sex"
     endif
 endif
Index: /trunk/Ohana/src/shell/src/sp_phot
===================================================================
--- /trunk/Ohana/src/shell/src/sp_phot	(revision 69)
+++ /trunk/Ohana/src/shell/src/sp_phot	(revision 70)
@@ -13,6 +13,7 @@
 # run this process on 'druid' instead of 'ohia'?
 
-set PROCNAME=sp_phot
-set MAXTIME=300
+set DBMACHINE = `gconfig DBMACHINE`
+set PROCNAME  = sp_phot
+set MAXTIME   = 300
 
 set args=""
@@ -103,9 +104,8 @@
 
 # use the tycho data only to do astrometry
-rsh -n milo gastro -D CATDIR $TYCHO $SMPDIR/$root.smp
+rsh -n $DBMACHINE gastro -D CATDIR $TYCHO $SMPDIR/$root.smp
 # if ($status) goto cleanup;
 
-rsh -n milo addspphot -cal TYCHO_V TYCHO_B $SMPDIR/$root.smp 
-# rsh -n milo addstar -cal TYCHO_V TYCHO_B $SMPDIR/$root.smp 
+rsh -n $DBMACHINE addspphot -image -cal TYCHO_V TYCHO_B $SMPDIR/$root.smp 
 # if ($status) goto cleanup;
 
Index: /trunk/Ohana/src/shell/src/sp_plots
===================================================================
--- /trunk/Ohana/src/shell/src/sp_plots	(revision 69)
+++ /trunk/Ohana/src/shell/src/sp_plots	(revision 70)
@@ -7,4 +7,5 @@
 # find the appropriate script file
 set confdir=`gconfig CONFDIR`
+set datdir=`gconfig DATDIR`
 set script="$confdir/mana/skyprobe"
 set xhost=`gconfig XHOST`
@@ -46,5 +47,5 @@
  endif 
 
- cp /data/milo/elixir/plots/skyprobe_night.png /apps/www/www.cfht.hawaii.edu/Instruments/Skyprobe/archive/mcal_$2.png
+ cp $datdir/plots/skyprobe_night.png /apps/www/www.cfht.hawaii.edu/Instruments/Skyprobe/archive/mcal_$2.png
  exit 0;
 
