Index: trunk/Ohana/src/opihi/lib.shell/parse.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/parse.c	(revision 15878)
+++ 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;
   }
