Index: /trunk/Ohana/src/opihi/lib.shell/expand_vectors.c
===================================================================
--- /trunk/Ohana/src/opihi/lib.shell/expand_vectors.c	(revision 41353)
+++ /trunk/Ohana/src/opihi/lib.shell/expand_vectors.c	(revision 41354)
@@ -1,7 +1,12 @@
 # include "opihi.h"
+
+// XXX need to unroll this function so we can more flexibly 
+// convert items in the line
 
 // converts a[], a[4], a[2][3] to their numeric values
 // add a?[] and a?[][] as equivalent to $?a
 // a[][?]
+
+enum {ANS_NONE, ANS_INT, ANS_FLT, ANS_STR};
 
 char *expand_vectors (char *line) {
@@ -11,5 +16,8 @@
   int n, I, J, size, showLength, showXsize, showYsize, checkType, NLINE, Noff, isBuffer, inRange;
   float *ptr;
-  double f1;
+  opihi_flt valueFlt;
+  opihi_int valueInt;
+  char *valueStr;
+  int answerType;
   Vector *vec;
   Buffer *buf;
@@ -41,4 +49,13 @@
     if (p > q) goto dumpline; /* odd state: unmatched pair: ][ */
 
+    // we have a bracket pair, now interpret the context:
+    // a[N] - vector value
+    // a?[] or a?[N] - vector existence
+    // a[]  - vector length
+    // a[N][M] - buffer value
+    // a?[][], a?[N][], a?[][M] - buffer existence
+    // a[][N] - buffer X size
+    // a[N][] - buffer Y size
+
     /* find vector subscript */
     n = (int) (q - p - 1);
@@ -47,4 +64,5 @@
     showXsize  = FALSE;
     showYsize  = FALSE;
+    answerType = ANS_NONE;
 
     if (n == 0) {
@@ -103,4 +121,9 @@
   asVector:
     /* find vector/buffer name */
+    /* 'checkType' really means check for existence.
+       if 'a' is a vector, then 'a?[]' returns TRUE, else FALSE
+       if 'a' is a buffer, then 'a?[][]' returns TRUE, else FALSE
+    */
+
     checkType = FALSE;
     if (*(p-1) == '?') {
@@ -116,5 +139,6 @@
       buf = SelectBuffer (tmpline, OLDBUFFER, !checkType);
       if (checkType) {
-	f1 = (buf != NULL);
+	valueInt = (buf != NULL);
+	answerType = ANS_INT;
 	goto skipBuffer;
       } 
@@ -125,9 +149,11 @@
       if (buf == NULL) goto dumpline;
       if (showXsize) {
-	f1 = buf[0].header.Naxis[0];
+	valueInt = buf[0].header.Naxis[0];
+	answerType = ANS_INT;
 	goto skipBuffer;
       }
       if (showYsize) {
-	f1 = buf[0].header.Naxis[1];
+	valueInt = buf[0].header.Naxis[1];
+	answerType = ANS_INT;
 	goto skipBuffer;
       }
@@ -145,9 +171,11 @@
       if (J < 0) J += buf[0].header.Naxis[1];
       ptr = (float *) buf[0].matrix.buffer;
-      f1 = ptr[I + J*buf[0].header.Naxis[0]];
+      valueFlt = ptr[I + J*buf[0].header.Naxis[0]];
+      answerType = ANS_FLT;
     } else {
       vec = SelectVector (tmpline, OLDVECTOR, !checkType);
       if (checkType) {
-	f1 = (vec != NULL);
+	valueInt = (vec != NULL);
+	answerType = ANS_INT;
       } else {
 	if (vec == NULL) goto dumpline;
@@ -155,5 +183,6 @@
 	/* find vector element */
 	if (showLength) {
-	  f1 = vec[0].Nelements;
+	  valueInt = vec[0].Nelements;
+	  answerType = ANS_INT;
 	} else {
 	  if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) {
@@ -162,5 +191,19 @@
 	  }
 	  if (I < 0) I += vec[0].Nelements;
-	  f1 = (vec[0].type == OPIHI_FLT) ? vec[0].elements.Flt[I] : vec[0].elements.Int[I];
+
+	  switch (vec[0].type) {
+	    case OPIHI_FLT:
+	      valueFlt = vec[0].elements.Flt[I];
+	      answerType = ANS_FLT;
+	      break;
+	    case OPIHI_INT:
+	      valueInt = vec[0].elements.Int[I];
+	      answerType = ANS_INT;
+	      break;
+	    case OPIHI_STR:
+	      valueStr = vec[0].elements.Str[I];
+	      answerType = ANS_STR;
+	      break;
+	  }
 	}
       }
@@ -169,8 +212,18 @@
   skipBuffer:
     free (tmpline);
-    if ((int)f1 == f1) 
-      snprintf (strValue, 128, "%.0f", f1); 
-    else
-      snprintf (strValue, 128, "%.12g", f1);
+
+    switch (answerType) {
+      case ANS_NONE:
+	goto dumpline;
+      case ANS_INT:
+	snprintf (strValue, 128, OPIHI_INT_FMT, valueInt); 
+	break;
+      case ANS_FLT:
+	snprintf (strValue, 128, "%.12g", valueFlt);
+	break;
+      case ANS_STR:
+	snprintf (strValue, 128, "%s", valueStr); 
+	break;
+    }
 
     /* interpolate vector element into newline (being accumulated) */
