Index: trunk/Ohana/src/opihi/lib.shell/expand_vectors.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/expand_vectors.c	(revision 16002)
+++ trunk/Ohana/src/opihi/lib.shell/expand_vectors.c	(revision 16003)
@@ -4,8 +4,10 @@
 
   char *newline, *tmpline, strValue[128], *val;
-  char *L, *N, *p, *q, *w;
-  int n, I, size, showLength, NLINE, Noff;
+  char *L, *N, *p, *q, *p2, *w;
+  int n, I, J, size, showLength, NLINE, Noff, isBuffer, inRange;
+  float *ptr;
   double f1;
   Vector *vec;
+  Buffer *buf;
 
   if (line == NULL) return (NULL);
@@ -26,5 +28,5 @@
   N = newline + n;
   while (1) {
-    /* find vector subscript */
+    /* find square-bracket pair [..] */
     p = strchr (L, '[');
     q = strchr (L, ']');
@@ -33,4 +35,6 @@
     if ((p == NULL) && (q == NULL)) goto dumpline;
     if (p > q) goto dumpline; /* odd state: unmatched pair: ][ */
+
+    /* find vector subscript */
     n = (int) (q - p - 1);
     val = NULL;
@@ -50,26 +54,81 @@
     }      
 
-    /* find vector name */
+    /* if a second [..] immediately follows, we are a buffer, not a vector */
+    isBuffer = FALSE;
+    if (*(q + 1) == '[') {
+      p2 = strchr (q + 1, ']');
+      if (p2 != NULL) {
+	if (showLength) {
+	  gprint (GP_ERR, "unsupported : name[][..]\n"); 
+	  goto asVector;
+	}
+
+	isBuffer = TRUE;
+
+	/* find buffer second subscript */
+	n = (int) (p2 - q - 2);
+	val = NULL;
+	if (n == 0) {
+	  gprint (GP_ERR, "unsupported : name[..][]\n"); 
+	  isBuffer = FALSE;
+	  goto asVector;
+	} 
+	tmpline = strncreate (q+2, n);
+	val = dvomath (1, &tmpline, &size, 0);
+	free (tmpline);
+	if (val == NULL) {
+	  isBuffer = FALSE;
+	  goto asVector; /* not a valid vector subscript */
+	}
+	J = 0; 
+	if (val != NULL) {
+	  J = atoi (val);
+	  free (val);
+	}      
+      }
+      q = p2;
+    }
+
+  asVector:
+    /* find vector/buffer name */
     for (w = p - 1; (w >= line) && !OHANA_WHITESPACE(*w) && (isalnum(*w) || (*w == ':') || (*w == '_')); w--);
     w ++;
     n = (int)(p - w);
     tmpline = strncreate (w, n);
-    if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline;
-    free (tmpline);
 
-    /* find vector element */
-    if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) {
-      gprint (GP_ERR, "vector subscript out of range\n"); 
-      goto escape;
-    }
-    if (showLength) {
-      f1 = vec[0].Nelements;
+    if (isBuffer) {
+      if ((buf = SelectBuffer (tmpline, OLDBUFFER, TRUE)) == NULL) goto dumpline;
+
+      /* find buffer element */
+      inRange = TRUE;
+      inRange &= (I <  +1*buf[0].header.Naxis[0]);
+      inRange &= (I >= -1*buf[0].header.Naxis[0]);
+      inRange &= (J <  +1*buf[0].header.Naxis[1]);
+      inRange &= (J >= -1*buf[0].header.Naxis[1]);
+      if (!inRange) {
+	gprint (GP_ERR, "buffer subscript out of range\n"); 
+	goto escape;
+      }
+      if (I < 0) I += buf[0].header.Naxis[0];
+      if (J < 0) J += buf[0].header.Naxis[1];
+      ptr = (float *) buf[0].matrix.buffer;
+      f1 = ptr[I + J*buf[0].header.Naxis[1]];
     } else {
-      if (I < 0) {
-	f1 = vec[0].elements[vec[0].Nelements+I];
+      if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline;
+
+      /* find vector element */
+      if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) {
+	gprint (GP_ERR, "vector subscript out of range\n"); 
+	goto escape;
+      }
+      if (showLength) {
+	f1 = vec[0].Nelements;
       } else {
+	if (I < 0) I += vec[0].Nelements;
 	f1 = vec[0].elements[I];
       }
     }
+
+    free (tmpline);
     if ((int)f1 == f1) 
       snprintf (strValue, 128, "%.0f", f1);
Index: trunk/Ohana/src/opihi/lib.shell/parse.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/parse.c	(revision 16002)
+++ trunk/Ohana/src/opihi/lib.shell/parse.c	(revision 16003)
@@ -4,8 +4,10 @@
 
   double fval;
+  float *fptr;
   char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p;
-  int Nval, Nbytes, status, size, NLINE;
+  int Nx, Ny, Nbytes, status, size, NLINE, isBuffer, inRange;
   FILE *f;
   Vector *vec;
+  Buffer *buf;
 
   val = V0 = NULL;
@@ -101,5 +103,5 @@
   }
 
-  /* case 2: vect[N] = value */
+  /* case 2: vect[N] = value or buff[N][M] = value */
   V0 = thiscomm (line);
   if (strchr(V0, '[') != (char *) NULL) { 
@@ -111,5 +113,4 @@
     L = strchr (V0, ']');
     if (L == (char *) NULL) goto error;
-    if (L != V0 + strlen (V0) - 1) goto error;
 
     *N = 0;
@@ -122,14 +123,25 @@
       goto error;
     }
-    Nval = atoi (val);
+    Nx = atoi (val);
     free (val); val = NULL;
     free (V);
 
-    /* find vector */
-    if ((vec = SelectVector (V0, OLDVECTOR, TRUE)) == NULL) goto error;
-    free (V0); V0 = (char *) NULL;
-    if (Nval >= vec[0].Nelements) {
-      gprint (GP_ERR, "no element %d\n", Nval);
-      goto escape;
+    isBuffer = FALSE;
+    N = L + 1;
+    if (*N == '[') {
+      isBuffer = TRUE;
+      L = strchr (N, ']');
+
+      V = strncreate (N+1, L - N - 1);
+
+      /* expand value in brackets */
+      val = dvomath (1, &V, &size, 0);
+      if (val == NULL) {
+	print_error ();
+	goto error;
+      }
+      Ny = atoi (val);
+      free (val); val = NULL;
+      free (V);
     }
 
@@ -146,5 +158,39 @@
       goto error;
     }
-    vec[0].elements[Nval] = atof (val);
+
+    /* find vector */
+    if (isBuffer) {
+      if ((buf = SelectBuffer (V0, OLDBUFFER, TRUE)) == NULL) goto error;
+      free (V0); V0 = (char *) NULL;
+
+      inRange = TRUE;
+      inRange &= (Nx <  +1*buf[0].header.Naxis[0]);
+      inRange &= (Nx >= -1*buf[0].header.Naxis[0]);
+      inRange &= (Ny <  +1*buf[0].header.Naxis[1]);
+      inRange &= (Ny >= -1*buf[0].header.Naxis[1]);
+      if (!inRange) {
+	gprint (GP_ERR, "no element %d,%d\n", Nx, Ny);
+	goto escape;
+      }
+      if (Nx < 0) Nx += buf[0].header.Naxis[0];
+      if (Ny < 0) Ny += buf[0].header.Naxis[1];
+
+      fptr = (float *) buf[0].matrix.buffer;
+      fptr[Nx + Ny*buf[0].header.Naxis[1]] = atof (val);
+    } else {
+      if ((vec = SelectVector (V0, OLDVECTOR, TRUE)) == NULL) goto error;
+      free (V0); V0 = (char *) NULL;
+
+      inRange = TRUE;
+      inRange &= (Nx <  +1*vec[0].Nelements);
+      inRange &= (Nx >= -1*vec[0].Nelements);
+      if (!inRange) {
+	gprint (GP_ERR, "no element %d\n", Nx);
+	goto escape;
+      }
+      if (Nx < 0) Nx += vec[0].Nelements;
+      vec[0].elements[Nx] = atof (val);
+    }
+
     goto escape;
   }
