Index: /trunk/Ohana/src/imregister/detrend/output.c
===================================================================
--- /trunk/Ohana/src/imregister/detrend/output.c	(revision 6)
+++ /trunk/Ohana/src/imregister/detrend/output.c	(revision 7)
@@ -22,5 +22,5 @@
 
 /* write out complete binary FITS table in format of db */
-void DumpFitsBintable (char *filename, DetReg *image, Match *match, int Nmatch) {
+int DumpFitsBintable (char *filename, DetReg *image, Match *match, int Nmatch) {
 
   int i, j, Nx;
@@ -49,4 +49,5 @@
 
 int DumpFitsTable (char *filename, DetReg *detdata, Match *match, int Nmatch) {
+# define NL 453
   
   Header header, theader;
@@ -55,6 +56,6 @@
   DetReg *newdata;
   FILE *f;
-  char *startstr, *stopstr, *regstr, line[421];
-  char *filtstr, *typestr, *ccdstr, *datestr;
+  char *startstr, *stopstr, *regstr, line[NL], key[33];
+  char *filtstr, *typestr, *ccdstr, *datestr, *p;
   int i;
   unsigned long tsecond;
@@ -77,4 +78,5 @@
 
   /* define table layout */
+  fits_define_table_column (&theader, "A32",  "KEY",        "unique identifier",         "");
   fits_define_table_column (&theader, "A20",  "START_TIME", "start time of measurement", "yyyy/mm/dd,hh:mm:ss");
   fits_define_table_column (&theader, "A20",  "STOP_TIME",  "stop time of measurement",  "yyyy/mm/dd,hh:mm:ss");
@@ -89,4 +91,31 @@
   fits_define_table_column (&theader, "A256", "PATH",       "filename in db",            "");
   
+  /* define TNULL, TBNA values */
+  fits_modify (&theader, "TNULL1",  "%s", 1, "");
+  fits_modify (&theader, "TNULL2",  "%s", 1, "");
+  fits_modify (&theader, "TNULL3",  "%s", 1, "");
+  fits_modify (&theader, "TNULL4",  "%s", 1, "");
+  fits_modify (&theader, "TNULL5",  "%lf", 1, (float) -1);
+  fits_modify (&theader, "TNULL6",  "%s", 1, "");
+  fits_modify (&theader, "TNULL7",  "%s", 1, "");
+  fits_modify (&theader, "TNULL8",  "%s", 1, "");
+  fits_modify (&theader, "TNULL9",  "%d", 1, -1);
+  fits_modify (&theader, "TNULL10", "%d", 1, -1);
+  fits_modify (&theader, "TNULL11", "%s", 1, "");
+  fits_modify (&theader, "TNULL12", "%s", 1, "");
+
+  fits_modify (&theader, "TBNA1",  "%s", 1, "NA");
+  fits_modify (&theader, "TBNA2",  "%s", 1, "NA");
+  fits_modify (&theader, "TBNA3",  "%s", 1, "NA");
+  fits_modify (&theader, "TBNA4",  "%s", 1, "NA");
+  fits_modify (&theader, "TBNA5",  "%lf", 1, (float) -2);
+  fits_modify (&theader, "TBNA6",  "%s", 1, "NA");
+  fits_modify (&theader, "TBNA7",  "%s", 1, "NA");
+  fits_modify (&theader, "TBNA8",  "%s", 1, "NA");
+  fits_modify (&theader, "TBNA9",  "%d", 1, -2);
+  fits_modify (&theader, "TBNA10", "%d", 1, -2);
+  fits_modify (&theader, "TBNA11", "%s", 1, "NA");
+  fits_modify (&theader, "TBNA12", "%s", 1, "NA");
+
   /* create table, add data values */
   fits_create_table (&theader, &table);
@@ -95,4 +124,16 @@
   for (i = 0; i < Nmatch; i++) {
     newdata = &detdata[match[i].image];
+
+    /* key = 02Bk02.flat.V.00.00 */
+    p = strrchr (newdata[0].filename, '/');
+    if (p == (char *) NULL) {
+      p = newdata[0].filename;
+    } else {
+      p ++;
+    }
+    bzero (key, 33);
+    strncpy (key, p, 32);
+    if ((p = strrchr (key, '.')) != (char *) NULL) *p = 0;
+
     startstr = sec_to_date (newdata[0].tstart);
     stopstr  = sec_to_date (newdata[0].tstop);
@@ -101,6 +142,6 @@
     filtstr  = filterhash[newdata[0].filter];
     ccdstr   = ccds[newdata[0].ccd];
-    snprintf (line, 421, "%20s%20s%20s%7.1f%10s%10s%7s%3d%3d%64s%256s",
-	      startstr, stopstr, regstr, newdata[0].exptime,
+    snprintf (line, NL, "%32s%20s%20s%20s%7.1f%10s%10s%7s%3d%3d%64s%256s",
+	      key, startstr, stopstr, regstr, newdata[0].exptime,
 	      typestr, filtstr, ccdstr,
 	      newdata[0].Nentry, newdata[0].Norder, 
@@ -122,5 +163,5 @@
   fits_fwrite_table   (f, &table);
   fclose (f);
-  return (TRUE);
+  exit (0);
 }
 
