Index: /trunk/Ohana/src/imregister/detrend/args.detsearch.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/args.detsearch.c	(revision 20)
+++ /trunk/Ohana/src/imregister/detrend/args.detsearch.c	(revision 21)
@@ -85,4 +85,20 @@
   }
  
+  /* image mode (mef, splt, etc) */
+  base.ModeSelect = FALSE;
+  base.Mode = M_NONE;
+  if (N = get_argument (argc, argv, "-mode")) {
+    remove_argument (N, &argc, argv);
+    for (i = 0; (i < NMODE) && (base.Mode == M_NONE); i++) {
+      if (!strncasecmp (argv[N], modename[i], strlen(argv[N]))) base.Mode = i;
+    }
+    if (base.Mode == M_NONE) {
+      fprintf (stderr, "ERROR: invalid image mode %s\n", argv[N]);
+      exit (1);
+    }
+    remove_argument (N, &argc, argv);
+    base.ModeSelect = TRUE;
+  }
+ 
   /* define time / ranges */
   tstart = tstop = (unsigned long *) NULL;
@@ -259,4 +275,5 @@
     if (!strcasecmp (output.ModifyEntry, "label")) goto valid_entry;
     if (!strcasecmp (output.ModifyEntry, "order")) goto valid_entry;
+    if (!strcasecmp (output.ModifyEntry, "mode"))  goto valid_entry;
     if (!strcasecmp (output.ModifyEntry, "tstop")) goto valid_entry;
     if (!strcasecmp (output.ModifyEntry, "tstart")) goto valid_entry;
Index: /trunk/Ohana/src/imregister/detrend/criteria.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/criteria.c	(revision 20)
+++ /trunk/Ohana/src/imregister/detrend/criteria.c	(revision 21)
@@ -14,7 +14,14 @@
   for (i = 0; (i < Ncriteria) && (match.state == MATCH_NONE); i++) {
 
-    /***********  fix this *****/
-    if (criteria[i].CCDSelect    && (image[0].ccd             != criteria[i].CCD))    continue;
+    if (criteria[i].CCDSelect) {
+      if (image[0].mode == M_MODES) goto valid_ccd;
+      if (image[0].mode == M_MODES) goto valid_ccd;
+      if (image[0].ccd  == criteria[i].CCD) goto valid_ccd;
+      continue;
+    }
+  valid_ccd:
+
     if (criteria[i].TypeSelect   && (image[0].type            != criteria[i].Type))   continue;
+    if (criteria[i].ModeSelect   && (image[0].mode            != criteria[i].Mode))   continue;
     if (criteria[i].FilterSelect && (image[0].filter          != criteria[i].Filter)) continue;
 
Index: /trunk/Ohana/src/imregister/detrend/define.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/define.c	(revision 20)
+++ /trunk/Ohana/src/imregister/detrend/define.c	(revision 21)
@@ -23,5 +23,6 @@
     fits_define_bintable_column (theader, "J",    "VERSION",    "image version number",      "",                              1.0, 0.0);
     fits_define_bintable_column (theader, "J",    "ORDER",      "selection order",           "",                              1.0, 0.0);
-    fits_define_bintable_column (theader, "60A",  "RESERVED",   "space for additions",       "photcode",                      1.0, 0.0);
+    fits_define_bintable_column (theader, "A",    "MODE",       "image mode",                "",                              1.0, 0.0);
+    fits_define_bintable_column (theader, "59A",  "RESERVED",   "space for additions",       "",                              1.0, 0.0);
     fits_define_bintable_column (theader, "64A",  "LABEL",      "data label",                "",                              1.0, 0.0);
     fits_define_bintable_column (theader, "256A", "PATH",       "filename in db",            "",                              1.0, 0.0);
Index: /trunk/Ohana/src/imregister/detrend/entry.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/entry.c	(revision 20)
+++ /trunk/Ohana/src/imregister/detrend/entry.c	(revision 21)
@@ -18,5 +18,6 @@
   newdata.exptime   = descriptor.Exptime;
   newdata.Norder    = descriptor.order;
-  bzero (newdata.dummy, 60);
+  newdata.mode      = descriptor.mode;
+  bzero (newdata.dummy, 59);
   snprintf (newdata.label, 64, "%s", descriptor.label);
   
Index: /trunk/Ohana/src/imregister/detrend/imdef.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/imdef.c	(revision 20)
+++ /trunk/Ohana/src/imregister/detrend/imdef.c	(revision 21)
@@ -4,5 +4,5 @@
 int DefineImage (char *filename, Descriptor *descriptor) {
 
-  int i;
+  int i, Extend, Nextend;
   char line[512];
   Header header;
@@ -21,5 +21,5 @@
     }
     for (i = 0; i < NTYPE; i++) {
-      if (!strncasecmp (line, typename[i], strlen(typename[i]))) {
+      if (!strcasecmp (line, typename[i])) {
 	descriptor[0].type = i;
       }
@@ -44,27 +44,44 @@
   }
 
+  /* modes: a special case */
+  if (descriptor[0].type == T_MODES) {
+    descriptor[0].mode      = M_MODES;
+    descriptor[0].CCD       = Nccd;
+    descriptor[0].CCDSelect = TRUE;
+  }
+
+  /* identify MODE (MEF / SPLIT)  */
+  descriptor[0].mode = MODE_SPLIT;
+  Extend = FALSE;
+  fits_scan (&header, "EXTEND", "%t", 1, &Extend);
+  if (Extend) {
+    descriptor[0].mode      = M_MEF;
+    descriptor[0].CCD       = Nccd;
+    descriptor[0].CCDSelect = TRUE;
+    fits_scan (&header, "NEXTEND",  "%d", 1, &Nextend);
+    if (Nextend != Nccd) { 
+      fprintf (stderr, "warning: NEXTEND != Nccd (%d, %d)\n", Nextend, Nccd);
+    }      
+  }
+
   /* now identify CCD number */
   if (!descriptor[0].CCDSelect) {
-    if (descriptor[0].type != T_MODES) {
-      char ID[64];
+    char ID[64];
 
-      descriptor[0].CCD = -1;
-      if (!fits_scan (&header, CCDnumKeyword, "%s", 1, ID)) {
-	fprintf (stderr, "ERROR: failure to read %s from header\n", CCDnumKeyword);
-	exit (1);
+    descriptor[0].CCD = -1;
+    if (!fits_scan (&header, CCDnumKeyword, "%s", 1, ID)) {
+      fprintf (stderr, "ERROR: failure to read %s from header\n", CCDnumKeyword);
+      exit (1);
+    }
+    for (i = 0; (i < Nccd) && (descriptor[0].CCD == -1); i++) {
+      if (strnumcmp (ID, ccds[i])) {
+	descriptor[0].CCD = i;
       }
-      for (i = 0; (i < Nccd) && (descriptor[0].CCD == -1); i++) {
-	if (strnumcmp (ID, ccds[i])) {
-	  descriptor[0].CCD = i;
-	}
-      }
-      if (descriptor[0].CCD == -1) {
-	fprintf (stderr, "warning: ccd id not found\n");
-	descriptor[0].CCD = 0;
-      }
-      descriptor[0].CCDSelect = TRUE;
-    } else {
-      descriptor[0].CCD = Nccd;
     }
+    if (descriptor[0].CCD == -1) {
+      fprintf (stderr, "warning: ccd id not found\n");
+      descriptor[0].CCD = 0;
+    }
+    descriptor[0].CCDSelect = TRUE;
   }
 
Index: /trunk/Ohana/src/imregister/detrend/modify.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/modify.c	(revision 20)
+++ /trunk/Ohana/src/imregister/detrend/modify.c	(revision 21)
@@ -4,5 +4,5 @@
 int ModifySubset (Match *match, int Nmatch) {
   
-  int i, j, Nimage;
+  int i, j, Nimage, value;
   int *list;
   DetReg *image;
@@ -10,4 +10,18 @@
   image = get_images (&Nimage);
   ALLOCATE (list, int, Nimage);
+  if (output.ModifyEntry, "mode") {
+    for (i = 0; i < NMODE; i++) {
+      if (!strncasecmp (output.ModifyValue, modename[i], strlen(modename[i]))) {
+	value = i;
+	goto valid_mode;
+      }
+    }
+    fprintf (stderr, "ERROR: invalid image mode %s\n", output.ModifyValue);
+    exit (1);
+  }
+  if (!strcasecmp (output.ModifyEntry, "order")) {
+    value = atoi (output.ModifyValue);
+  }
+ valid_mode:
 
   /* list matched images */
@@ -20,5 +34,8 @@
     }
     if (!strcasecmp (output.ModifyEntry, "order")) {
-      image[i].Norder = atoi (output.ModifyValue);
+      image[i].Norder = value;
+    }
+    if (!strcasecmp (output.ModifyEntry, "mode")) {
+      image[i].mode   = value;
     }
     if (!strcasecmp (output.ModifyEntry, "tstart")) {
@@ -26,5 +43,5 @@
     }
     if (!strcasecmp (output.ModifyEntry, "tstop")) {
-      image[i].tstop = output.TimeValue;
+      image[i].tstop  = output.TimeValue;
     }
   }
Index: /trunk/Ohana/src/imregister/detrend/output.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/output.c	(revision 20)
+++ /trunk/Ohana/src/imregister/detrend/output.c	(revision 21)
@@ -55,6 +55,6 @@
   DetReg *newdata;
   FILE *f;
-  char *startstr, *stopstr, *regstr, *line, key[33];
-  char *filtstr, *typestr, *ccdstr, *datestr, *p;
+  char *startstr, *stopstr, *regstr, *line, key[33], ccdinfo[16];
+  char *filtstr, *typestr, *modestr, *ccdstr, *datestr, *p;
   int i;
   unsigned long tsecond;
@@ -84,5 +84,6 @@
   fits_define_table_column (&theader, "A10",  "IMAGETYP",   "detrend type",              "");
   fits_define_table_column (&theader, "A10",  "FILTER",     "filter name",               "");
-  fits_define_table_column (&theader, "A7",   "CCDID",      "ccd name",                  "");
+  fits_define_table_column (&theader, "A7",   "CCDINFO",    "ccd information",                  "");
+  fits_define_table_column (&theader, "A7",   "MODE",       "data format mode",                  "");
   fits_define_table_column (&theader, "I3",   "VERSION",    "image version number",      "");
   fits_define_table_column (&theader, "I3",   "ORDER",      "selection order",           "");
@@ -98,9 +99,10 @@
   fits_modify (&theader, "TNULL6",  "%s", 1, "NULL");  /* IMAGETYP   */
   fits_modify (&theader, "TNULL7",  "%s", 1, "NULL");  /* FILTER     */
-  fits_modify (&theader, "TNULL8",  "%s", 1, "NULL");  /* CCDID      */
-  fits_modify (&theader, "TNULL9",  "%s", 1, "-1");    /* VERSION    */
-  fits_modify (&theader, "TNULL10", "%s", 1, "-1");    /* ORDER      */
-  fits_modify (&theader, "TNULL11", "%s", 1, "NULL");  /* LABEL      */
-  fits_modify (&theader, "TNULL12", "%s", 1, "NULL");  /* PATH       */
+  fits_modify (&theader, "TNULL8",  "%s", 1, "NULL");  /* CCDINFO    */
+  fits_modify (&theader, "TNULL9",  "%s", 1, "NULL");  /* MODE       */
+  fits_modify (&theader, "TNULL10", "%s", 1, "-1");    /* VERSION    */
+  fits_modify (&theader, "TNULL11", "%s", 1, "-1");    /* ORDER      */
+  fits_modify (&theader, "TNULL12", "%s", 1, "NULL");  /* LABEL      */
+  fits_modify (&theader, "TNULL13", "%s", 1, "NULL");  /* PATH       */
 
   fits_modify (&theader, "TNVAL1",  "%s", 1, "NA");    /* KEY        */
@@ -111,9 +113,10 @@
   fits_modify (&theader, "TNVAL6",  "%s", 1, "NA");    /* IMAGETYP   */
   fits_modify (&theader, "TNVAL7",  "%s", 1, "NA");    /* FILTER     */
-  fits_modify (&theader, "TNVAL8",  "%s", 1, "NA");    /* CCDID      */
-  fits_modify (&theader, "TNVAL9",  "%s", 1, "-2");    /* VERSION    */
-  fits_modify (&theader, "TNVAL10", "%s", 1, "-2");    /* ORDER      */
-  fits_modify (&theader, "TNVAL11", "%s", 1, "NA");    /* LABEL      */
-  fits_modify (&theader, "TNVAL12", "%s", 1, "NA");    /* PATH       */
+  fits_modify (&theader, "TNVAL8",  "%s", 1, "NA");    /* CCDINFO    */
+  fits_modify (&theader, "TNVAL9",  "%s", 1, "NA");    /* MODE       */
+  fits_modify (&theader, "TNVAL10",  "%s", 1, "-2");    /* VERSION    */
+  fits_modify (&theader, "TNVAL11", "%s", 1, "-2");    /* ORDER      */
+  fits_modify (&theader, "TNVAL12", "%s", 1, "NA");    /* LABEL      */
+  fits_modify (&theader, "TNVAL13", "%s", 1, "NA");    /* PATH       */
 
   /* create table, add data values */
@@ -139,9 +142,16 @@
     regstr   = sec_to_date (newdata[0].treg);
     typestr  = typename[newdata[0].type];
+    modestr  = modename[newdata[0].mode];
     filtstr  = filterhash[newdata[0].filter];
-    ccdstr   = ccds[newdata[0].ccd];
+
+    if (newdata[0].mode == M_SPLIT) {
+      ccdstr   = ccds[newdata[0].ccd];
+    } else {
+      sprintf (ccdinfo, "%-3d", newdata[0].ccd);
+      ccdstr   = ccdinfo;
+    }
 
     line = fits_table_print (&table, key, startstr, stopstr, regstr, 
-			     newdata[0].exptime, typestr, filtstr, ccdstr,
+			     newdata[0].exptime, typestr, filtstr, ccdstr, modestr,
 			     newdata[0].Nentry, newdata[0].Norder, 
 			     newdata[0].label, newdata[0].filename);
@@ -171,7 +181,9 @@
   
   char *dBPath, *typestr, *filtstr;
-  char *timestr;
-  int i, j;
-
+  char *timestr, *modestr, *ccdstr, ccdinfo[16], ccdformat[16];
+  int i, j, Nc;
+
+  Nc = strlen (ccds[0]);
+  sprintf (ccdformat, "%%%dd", Nc);
   dBPath = get_dBPath ();
 
@@ -195,5 +207,13 @@
 
     typestr = typename[MIN (MAX (detdata[i].type, 0), NTYPE - 1)];
+    modestr = modename[MIN (MAX (detdata[i].mode, 0), NMODE - 1)];
     filtstr = filterhash[MIN (MAX (detdata[i].filter, 0), NFILTER - 1)];
+
+    if (detdata[i].mode == M_SPLIT) {
+      ccdstr   = ccds[detdata[i].ccd];
+    } else {
+      sprintf (ccdinfo, ccdformat, detdata[i].ccd);
+      ccdstr   = ccdinfo;
+    }
 
     /* output mode (Select vs List) */
@@ -201,6 +221,6 @@
       fprintf (stdout, "%s/%s\n", dBPath, detdata[i].filename);
     } else {
-      fprintf (stdout, "%-40s = %19s %7s %6s %02d %2d %2d %6.1f  %20s\n", 
-	       detdata[i].filename, timestr, typestr, filtstr, detdata[i].ccd, 
+      fprintf (stdout, "%-40s = %19s %7s %6s %6s %s %2d %2d %6.1f  %20s\n", 
+	       detdata[i].filename, timestr, modestr, typestr, filtstr, ccdstr,
 	       detdata[i].Nentry, detdata[i].Norder, detdata[i].exptime, detdata[i].label);
     }
