Index: trunk/psLib/src/collections/psVector.c
===================================================================
--- trunk/psLib/src/collections/psVector.c	(revision 3264)
+++ trunk/psLib/src/collections/psVector.c	(revision 3407)
@@ -1,3 +1,2 @@
-
 /** @file  psVector.c
 *
@@ -10,6 +9,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-02-17 19:26:23 $
+*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-03-11 20:38:56 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +17,5 @@
 #include <string.h>                        // for memcpy
 #include <stdlib.h>
+#include <stdio.h>
 #include <math.h>
 
@@ -407,2 +407,91 @@
     return outVector;
 }
+
+char* psVectorToString(psVector* vector, int maxLength)
+{
+
+    if (maxLength < 5) {
+        return NULL;
+    }
+
+    char* str = psAlloc(sizeof(char)*maxLength+1);
+
+    if (vector == NULL) {
+        snprintf(str,maxLength, "NULL");
+        return str;
+    }
+
+    int size = vector->n;
+
+    if (size == 0) {
+        snprintf(str,maxLength, "[]");
+        return str;
+    }
+
+    char* tempStr = psAlloc(sizeof(char)*maxLength+1);
+    *str = '\0';
+    bool full = false;
+
+    #define APPEND_ELEMENTS_CASE(TYPE, NATIVE_TYPE, FORMAT) \
+case PS_TYPE_##TYPE: \
+    for (lcv=0; lcv < size && ! full; lcv++) { \
+        snprintf(tempStr, maxLength, "%s" FORMAT, prefix, (NATIVE_TYPE) (vector->data.TYPE[lcv])); \
+        strncat(str,tempStr,maxLength); \
+        full = (strlen(str) > maxLength-2); \
+        prefix = ","; \
+    } \
+    break;
+
+    #define APPEND_ELEMENTS_CASE_COMPLEX(TYPE,CREAL,CIMAG) \
+case PS_TYPE_##TYPE: \
+    for (lcv=0; lcv < size && ! full; lcv++) { \
+        snprintf(tempStr, maxLength, "%s%g%+gi", prefix, \
+                 CREAL(vector->data.TYPE[lcv]), \
+                 CIMAG(vector->data.TYPE[lcv])); \
+        full = (strlen(str) > maxLength-2); \
+        prefix = ","; \
+    } \
+    break;
+
+    int lcv;
+    char* prefix = "[";
+    switch(vector->type.type) {
+        APPEND_ELEMENTS_CASE(S8,char,"%hd")
+        APPEND_ELEMENTS_CASE(S16,short int,"%hd")
+        APPEND_ELEMENTS_CASE(S32,int,"%d")
+        APPEND_ELEMENTS_CASE(S64,long,"%ld")
+        APPEND_ELEMENTS_CASE(U8,unsigned char,"%hu")
+        APPEND_ELEMENTS_CASE(U16,unsigned short,"%hu")
+        APPEND_ELEMENTS_CASE(U32,unsigned int, "%u")
+        APPEND_ELEMENTS_CASE(U64,unsigned long,"%lu")
+        APPEND_ELEMENTS_CASE(F32,double,"%g")
+        APPEND_ELEMENTS_CASE(F64,double,"%g")
+        APPEND_ELEMENTS_CASE_COMPLEX(C32,crealf,cimagf)
+        APPEND_ELEMENTS_CASE_COMPLEX(C64,creal,cimag)
+    default:
+        snprintf(str,maxLength,"[...]");
+        break;
+    }
+
+    if (full) {
+        // couldn't all fit in given string length
+
+        // remove elements until there is room for ",...]"
+        while (strlen(str) > maxLength - 5) {
+            char* lastComma = strrchr(str,',');
+            if (lastComma == NULL) { // no comma, must be first number
+                str[1] = '\0';
+            } else {
+                *lastComma = '\0';
+            }
+        }
+        strncat(str,",...]",maxLength);
+    } else {
+        strncat(str,"]",maxLength);
+    }
+
+    psFree(tempStr);
+
+    return str;
+}
+
