Index: /trunk/Ohana/src/libfits/matrix/F_compress_M.c
===================================================================
--- /trunk/Ohana/src/libfits/matrix/F_compress_M.c	(revision 41738)
+++ /trunk/Ohana/src/libfits/matrix/F_compress_M.c	(revision 41739)
@@ -288,4 +288,6 @@
 }
 
+// copy everything except the fields which get translated:
+// SIMPLE, NAXIS, NAXIS0 - 9, BSCALE, BZERO, BLANK, 
 int gfits_copy_keywords_compress (Header *srchead, Header *tgthead) {
   OHANA_UNUSED_PARAM(tgthead);
@@ -294,11 +296,65 @@
 # if (0)
   int i;
-
+  char endline[82];
+
+  // find the END of the header
+  char *p = gfits_header_field (tgthead, "END", 1);
+  if (p == NULL) return (FALSE); 
+
+  // save the END line
+  memcpy (endline, p, FT_LINE_LENGTH);
+
+  // p tracks the current last (non-END) header line
   for (i = 0; i < srchead->datasize; i += FT_LINE_LENGTH) {
-  }
-# endif
-
+
+    NEED TO FIX THIS ---
+
+    // is there enough space for 2 more lines (keyword + END)?
+    if (tgthead->datasize - (p - (tgthead->buffer)) < 2*FT_LINE_LENGTH) {
+      tgthead->datasize += FT_RECORD_SIZE;
+      REALLOCATE (tgthead->buffer, char, tgthead->datasize);
+      p = gfits_header_field (tgthead, "END", 1);
+      if (p == NULL) return (FALSE); 
+    }
+
+    // copy the line to the target header
+    memcpy (p, &srchead->buffer[i], FT_LINE_LENGTH);
+    
+    // advance p:
+    p += FT_LINE_LENGTH;
+  }
+
+  // is there enough space for 1 more line?
+  if (tgthead->datasize - (p - (tgthead->buffer)) < FT_LINE_LENGTH) {
+    tgthead->datasize += FT_RECORD_SIZE;
+    REALLOCATE (tgthead->buffer, char, tgthead->datasize);
+    p = gfits_header_field (tgthead, "END", 1);
+    if (p == NULL) return (FALSE); 
+  }
+# endif  
   return TRUE;
 }
+
+# if (0)
+int gfits_add_keyword_raw (Header *header) {
+
+    /* new entry, find the END of the header */
+    p = gfits_header_field (header, "END", 1);
+    if (p == NULL) return (FALSE); 
+    
+    /* is there enough space for 1 more line? */
+    if (header[0].datasize - (p - (header[0].buffer)) < 2*FT_LINE_LENGTH) {
+      header[0].datasize += FT_RECORD_SIZE;
+      REALLOCATE (header[0].buffer, char, header[0].datasize);
+      p = gfits_header_field (header, "END", 1);
+      if (p == NULL) return (FALSE); 
+      memset (p + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE);
+    }
+    
+    /* push END line back 1 */
+    memmove ((p + FT_LINE_LENGTH), p, FT_LINE_LENGTH);
+    memset (p, ' ', FT_LINE_LENGTH);
+# endif
+
 
 // raw_pixsize is the bytes / pixel for the input matrix
