Index: /trunk/psLib/src/fits/psFits.c
===================================================================
--- /trunk/psLib/src/fits/psFits.c	(revision 5098)
+++ /trunk/psLib/src/fits/psFits.c	(revision 5099)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-15 21:22:21 $
+ *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-09-22 23:19:38 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -170,4 +170,7 @@
     case PS_META_F64:
         *fitsType = psStringCopy("1D");
+        break;
+    case PS_META_STR:
+        *fitsType = psStringCopy("1A");
         break;
         // XXX: Handle other types, e.g., Vectors, etc.
@@ -1458,5 +1461,4 @@
 {
     int status = 0;
-    psMetadataItem* item;
 
     if (fits == NULL) {
@@ -1485,4 +1487,5 @@
 
     // find the unique items in the array of metadata 'rows'
+    psMetadataItem* item;
     for (int row=0; row < rows; row++) {
         psMetadata* rowMeta = table->data[row];
@@ -1491,15 +1494,23 @@
                                    PS_LIST_HEAD,true);
             while ( (item=psListGetAndIncrement(iter)) != NULL) {
-                if (PS_META_IS_PRIMITIVE(item->type)) {
+                if (PS_META_IS_PRIMITIVE(item->type) || item->type == PS_META_STR) {
                     bool found = false;
+                    psMetadataItem* fItem = NULL;
                     for (int n=0; n < columns->n && ! found; n++) {
-                        if (strcmp(item->name,
-                                   ((psMetadataItem*)(columns->data[n]))->name) == 0) {
+                        fItem = (psMetadataItem*)(columns->data[n]);
+                        if (strcmp(item->name, fItem->name) == 0) {
                             found = true;
+                            break;
                         }
                     }
                     if (! found) {
                         psArrayAdd(columns, columns->nalloc, item);
+                    } else if (item->type == PS_META_STR &&
+                               strlen(fItem->data.V) > strlen(item->data.V)) {
+                        // got to keep the longest string value as to know what size to create the table column
+                        psMemDecrRefCounter(item->data.V);
+                        item->data.V = psMemIncrRefCounter(fItem->data.V);
                     }
+
                 }
             }
@@ -1524,4 +1535,8 @@
             return false;
         }
+        if (fitsType[strlen(fitsType)-1] == 'A') {
+            // string type -- append length to the type.
+            psStringAppend(&fitsType,"%d",strlen(((psMetadataItem*)columns->data[n])->data.V));
+        }
         columnTypes->data[n] = fitsType;
     }
@@ -1554,4 +1569,5 @@
         if (PS_META_IS_PRIMITIVE(item->type)) {
             psVector* col = NULL;
+            psArray* colArray = NULL;
             switch (item->type) {
             case PS_META_S32:
@@ -1570,4 +1586,5 @@
                                    &status);
                 break;
+
             case PS_META_F32:
                 col = psVectorAlloc(table->n, PS_TYPE_F32);
@@ -1585,4 +1602,5 @@
                                    &status);
                 break;
+
             case PS_META_F64:
                 col = psVectorAlloc(table->n, PS_TYPE_F64);
@@ -1600,4 +1618,5 @@
                                    &status);
                 break;
+
             case PS_META_BOOL:
                 col = psVectorAlloc(table->n, PS_TYPE_BOOL);
@@ -1615,4 +1634,21 @@
                                    &status);
                 break;
+
+            case PS_META_STR:
+                colArray = psArrayAlloc(table->n);
+                for (row = 0; row < table->n; row++) {
+                    colArray->data[row] = psMetadataLookupStr(NULL,
+                                          table->data[row],
+                                          item->name);
+                }
+                fits_write_col_str(fits->fd,
+                                   n+1,
+                                   1,
+                                   1,
+                                   table->n,
+                                   (char**)colArray->data,
+                                   &status);
+                break;
+
             default:
                 // XXX: error message?
