Index: trunk/packages/vizservers/nanovis/Command.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/Command.cpp	(revision 1380)
+++ trunk/packages/vizservers/nanovis/Command.cpp	(revision 1381)
@@ -92,15 +92,13 @@
 extern Texture2D* plane[10];
 
-bool load_volume_stream(Rappture::Outcome &status, int index, 
+extern bool load_volume_stream(Rappture::Outcome &status, int index, 
 			std::iostream& fin);
-bool load_volume_stream_odx(Rappture::Outcome &status, int index, 
+extern bool load_volume_stream_odx(Rappture::Outcome &status, int index, 
 	const char *buf, int nBytes);
 extern bool load_volume_stream2(Rappture::Outcome &status, int index, 
 	std::iostream& fin);
-extern void load_volume(int index, int width, int height, int depth,
-            int n_component, float* data, double vmin, double vmax,
-            double nzero_min);
+
 extern bool load_vector_stream(Rappture::Outcome &result, int index, 
-	std::istream& fin);
+	size_t length, char *bytes);
 extern bool load_vector_stream2(Rappture::Outcome &result, int index, 
 	size_t length, char *bytes);
@@ -108,4 +106,7 @@
 	Rappture::Unirect3d &data);
 
+extern void load_volume(int index, int width, int height, int depth,
+            int n_component, float* data, double vmin, double vmax,
+            double nzero_min);
 // Tcl interpreter for incoming messages
 
@@ -691,4 +692,7 @@
 	unsigned int flags;
 
+	if (buf.size() <= 0) {
+	    fprintf(stderr, "encoded DX buffer is empty\n");
+	}
 	flags = RPENC_Z|RPENC_B64|RPENC_HDR;
         if (!Rappture::encoding::decode(err, buf, flags)) {
@@ -698,4 +702,7 @@
             return TCL_ERROR;
         }
+	if (buf.size() <= 0) {
+	    fprintf(stderr, "decoded DX buffer is empty\n");
+	}
     }
     return TCL_OK;
Index: trunk/packages/vizservers/nanovis/Unirect.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/Unirect.cpp	(revision 1380)
+++ trunk/packages/vizservers/nanovis/Unirect.cpp	(revision 1381)
@@ -115,5 +115,5 @@
 	    }
         } else if ((c == 'u') && (strcmp(string, "units") == 0)) {
-            _vUnits = strdup(Tcl_GetString(objv[i+1]));
+            vUnits_ = strdup(Tcl_GetString(objv[i+1]));
         } else if ((c == 'o') && (strcmp(string, "order") == 0)) {
 	    Tcl_Obj **axes;
@@ -180,29 +180,29 @@
     }
 
-    _values = values;
-    _nValues = nValues;
-    _extents = extents;
+    values_ = values;
+    nValues_ = nValues;
+    extents_ = extents;
     if (units[3] != NULL) {
-	_vUnits = strdup(units[3]);
-    }
-    _xMin = min[axis3];
-    _xMax = max[axis3];
-    _xNum = num[axis3];
+	vUnits_ = strdup(units[3]);
+    }
+    xMin_ = min[axis3];
+    xMax_ = max[axis3];
+    xNum_ = num[axis3];
     if (units[axis3] != NULL) {
-	_xUnits = strdup(units[axis3]);
-    }
-    _yMin = min[axis2];
-    _yMax = max[axis2];
-    _yNum = num[axis2];
+	xUnits_ = strdup(units[axis3]);
+    }
+    yMin_ = min[axis2];
+    yMax_ = max[axis2];
+    yNum_ = num[axis2];
     if (units[axis2] != NULL) {
-	_yUnits = strdup(units[axis2]);
-    }
-    _zMin = min[axis1];
-    _zMax = max[axis1];
-    _zNum = num[axis1];
+	yUnits_ = strdup(units[axis2]);
+    }
+    zMin_ = min[axis1];
+    zMax_ = max[axis1];
+    zNum_ = num[axis1];
     if (units[axis1] != NULL) {
-	_zUnits = strdup(units[axis1]);
-    }
-    _initialized = true;
+	zUnits_ = strdup(units[axis1]);
+    }
+    initialized_ = true;
     return TCL_OK;
 }
@@ -225,21 +225,21 @@
     axis[1] = 0;			/* Y-axis */
 
-    _extents = 1;
-    _xNum = _yNum = _nValues = 0;
-    _xMin = _yMin = _xMax = _yMax = 0.0f;
-    if (_xUnits != NULL) {
-	free(_xUnits);
-    }
-    if (_yUnits != NULL) {
-	free(_yUnits);
-    }
-    if (_vUnits != NULL) {
-	free(_vUnits);
-    }
-    _xUnits = _yUnits = _vUnits = NULL;
-    if (_values != NULL) {
-	delete [] _values;
-    }
-    _values = NULL;
+    extents_ = 1;
+    xNum_ = yNum_ = nValues_ = 0;
+    xMin_ = yMin_ = xMax_ = yMax_ = 0.0f;
+    if (xUnits_ != NULL) {
+	free(xUnits_);
+    }
+    if (yUnits_ != NULL) {
+	free(yUnits_);
+    }
+    if (vUnits_ != NULL) {
+	free(vUnits_);
+    }
+    xUnits_ = yUnits_ = vUnits_ = NULL;
+    if (values_ != NULL) {
+	delete [] values_;
+    }
+    values_ = NULL;
 
     int i;
@@ -251,9 +251,9 @@
         c = string[0];
         if ((c == 'x') && (strcmp(string, "xmin") == 0)) {
-            if (GetFloatFromObj(interp, objv[i+1], &_xMin) != TCL_OK) {
+            if (GetFloatFromObj(interp, objv[i+1], &xMin_) != TCL_OK) {
                 return TCL_ERROR;
             }
         } else if ((c == 'x') && (strcmp(string, "xmax") == 0)) {
-            if (GetFloatFromObj(interp, objv[i+1], &_xMax) != TCL_OK) {
+            if (GetFloatFromObj(interp, objv[i+1], &xMax_) != TCL_OK) {
                 return TCL_ERROR;
             }
@@ -268,13 +268,13 @@
                 return TCL_ERROR;
             }
-	    _xNum = n;
+	    xNum_ = n;
         } else if ((c == 'x') && (strcmp(string, "xunits") == 0)) {
-            _xUnits = strdup(Tcl_GetString(objv[i+1]));
+            xUnits_ = strdup(Tcl_GetString(objv[i+1]));
         } else if ((c == 'y') && (strcmp(string, "ymin") == 0)) {
-            if (GetFloatFromObj(interp, objv[i+1], &_yMin) != TCL_OK) {
+            if (GetFloatFromObj(interp, objv[i+1], &yMin_) != TCL_OK) {
                 return TCL_ERROR;
             }
         } else if ((c == 'y') && (strcmp(string, "ymax") == 0)) {
-            if (GetFloatFromObj(interp, objv[i+1], &_yMax) != TCL_OK) {
+            if (GetFloatFromObj(interp, objv[i+1], &yMax_) != TCL_OK) {
                 return TCL_ERROR;
             }
@@ -289,7 +289,7 @@
                 return TCL_ERROR;
             }
-	    _yNum = n;
+	    yNum_ = n;
         } else if ((c == 'y') && (strcmp(string, "yunits") == 0)) {
-            _yUnits = strdup(Tcl_GetString(objv[i+1]));
+            yUnits_ = strdup(Tcl_GetString(objv[i+1]));
         } else if ((c == 'v') && (strcmp(string, "values") == 0)) {
             Tcl_Obj **vobj;
@@ -304,14 +304,14 @@
                 return TCL_ERROR;
 	    }
-	    _nValues = n;
-            _values = new float[_nValues];
+	    nValues_ = n;
+            values_ = new float[nValues_];
             size_t j;
-            for (j = 0; j < _nValues; j++) {
-                if (GetFloatFromObj(interp, vobj[j], _values + j)!=TCL_OK) {
+            for (j = 0; j < nValues_; j++) {
+                if (GetFloatFromObj(interp, vobj[j], values_ + j)!=TCL_OK) {
                     return TCL_ERROR;
 		}
 	    }
         } else if ((c == 'u') && (strcmp(string, "units") == 0)) {
-            _vUnits = strdup(Tcl_GetString(objv[i+1]));
+            vUnits_ = strdup(Tcl_GetString(objv[i+1]));
         } else if ((c == 'e') && (strcmp(string, "extents") == 0)) {
 	    int n;
@@ -325,5 +325,5 @@
                 return TCL_ERROR;
             }
-	    _extents = n;
+	    extents_ = n;
         } else if ((c == 'a') && (strcmp(string, "axisorder") == 0)) {
 	    Tcl_Obj **order;
@@ -350,9 +350,9 @@
         }
     }
-    if (_values == NULL) {
+    if (values_ == NULL) {
         Tcl_AppendResult(interp, "missing \"values\" key", (char *)NULL);
         return TCL_ERROR;
     }
-    if (_nValues != (_xNum * _yNum * _extents)) {
+    if (nValues_ != (xNum_ * yNum_ * extents_)) {
         Tcl_AppendResult(interp, 
 		"wrong number of values: must be xnum*ynum*extents", 
@@ -362,5 +362,5 @@
     
     fprintf(stderr, "generating %dx%dx%d = %d points\n", 
-	    _xNum, _yNum, _extents, _xNum * _yNum * _extents);
+	    xNum_, yNum_, extents_, xNum_ * yNum_ * extents_);
 
 #ifndef notdef
@@ -371,24 +371,24 @@
 	float *data, *dp;
 
-	dp = data = new float[_nValues];
-	for (y = 0; y < _yNum; y++) {
+	dp = data = new float[nValues_];
+	for (y = 0; y < yNum_; y++) {
 	    size_t x;
 
-	    for (x = 0; x < _xNum; x++) {
+	    for (x = 0; x < xNum_; x++) {
 		size_t i, v;
 		    
 		/* Compute the index from the data's described ordering. */
-		i = (y + (_yNum * x)) * _extents;
-		for(v = 0; v < _extents; v++) {
-		    dp[v] = _values[i+v];
+		i = (y + (yNum_ * x)) * extents_;
+		for(v = 0; v < extents_; v++) {
+		    dp[v] = values_[i+v];
 		}
-		dp += _extents;
+		dp += extents_;
 	    }
 	}
-	delete [] _values;
-	_values = data;
+	delete [] values_;
+	values_ = data;
     }
 #endif
-    _initialized = true;
+    initialized_ = true;
     return TCL_OK;
 }
Index: trunk/packages/vizservers/nanovis/Unirect.h
===================================================================
--- trunk/packages/vizservers/nanovis/Unirect.h	(revision 1380)
+++ trunk/packages/vizservers/nanovis/Unirect.h	(revision 1381)
@@ -7,197 +7,215 @@
 
 class Unirect3d {
-    size_t _xNum, _yNum, _zNum;
-    size_t _nValues;
-    int _extents;
-
-    float _xMin, _xMax;
-    float _yMin, _yMax;
-    float _zMin, _zMax;
-    float _vMin, _vMax;
-
-    char *_xUnits;
-    char *_yUnits;
-    char *_zUnits;
-    char *_vUnits;
-
-    float *_values;
-    bool _initialized;
+    size_t xNum_, yNum_, zNum_;
+    size_t nValues_;
+    int extents_;
+
+    float xMin_, xMax_;
+    float yMin_, yMax_;
+    float zMin_, zMax_;
+    float vMin_, vMax_;
+
+    char *xUnits_;
+    char *yUnits_;
+    char *zUnits_;
+    char *vUnits_;
+
+    float *values_;
+    bool initialized_;
 
 public:
+    Unirect3d(float xMin, float xMax, size_t xNum, 
+	      float yMin, float yMax, size_t yNum, 
+	      float zMin, float zMax, size_t zNum, 
+	      size_t nValues, float *values) {
+	xMax_ = xMax;
+	xMin_ = xMin;
+	xNum_ = xNum;
+	yMax_ = yMax;
+	yMin_ = yMin;
+	yNum_ = yNum;
+	zMax_ = zMax;
+	zMin_ = zMin;
+	zNum_ = zNum;
+	nValues_ = nValues;
+	values_ = values;
+	initialized_ = true;
+    }
+
     Unirect3d(void) {
-	_values = NULL;
-	_initialized = false;
-	_xNum = _yNum = _zNum = 0;
-	_nValues = 0;
-	_xUnits = _yUnits = _zUnits = _vUnits = NULL;
+	values_ = NULL;
+	initialized_ = false;
+	xNum_ = yNum_ = zNum_ = 0;
+	nValues_ = 0;
+	xUnits_ = yUnits_ = zUnits_ = vUnits_ = NULL;
     }
     ~Unirect3d(void) {
-	if (_values != NULL) {
-	    delete [] _values;
-	}
-	if (_xUnits != NULL) {
-	    free(_xUnits);
-	}
-	if (_yUnits != NULL) {
-	    free(_yUnits);
-	}
-	if (_zUnits != NULL) {
-	    free(_zUnits);
-	}
-	if (_vUnits != NULL) {
-	    free(_vUnits);
+	if (values_ != NULL) {
+	    delete [] values_;
+	}
+	if (xUnits_ != NULL) {
+	    free(xUnits_);
+	}
+	if (yUnits_ != NULL) {
+	    free(yUnits_);
+	}
+	if (zUnits_ != NULL) {
+	    free(zUnits_);
+	}
+	if (vUnits_ != NULL) {
+	    free(vUnits_);
 	}
     }
     size_t xNum(void) {
-	return _xNum;
+	return xNum_;
     }
     size_t yNum(void) {
-	return _yNum;
+	return yNum_;
     }
     size_t zNum(void) {
-	return _zNum;
+	return zNum_;
     }
     float xMin(void) {
-	return _xMin;
+	return xMin_;
     }
     float yMin(void) {
-	return _yMin;
+	return yMin_;
     }
     float zMin(void) {
-	return _zMin;
+	return zMin_;
     }
     float xMax(void) {
-	return _xMax;
+	return xMax_;
     }
     float yMax(void) {
-	return _yMax;
+	return yMax_;
     }
     float zMax(void) {
-	return _zMax;
+	return zMax_;
     }
     const char *xUnits(void) {
-	return _xUnits;
+	return xUnits_;
     }
     const char *yUnits(void) {
-	return _yUnits;
+	return yUnits_;
     }
     const char *zUnits(void) {
-	return _zUnits;
+	return zUnits_;
     }
     const char *vUnits(void) {
-	return _vUnits;
+	return vUnits_;
     }
     float *values(void) {
-	return _values;
+	return values_;
     }
     float *SaveValues(void) {
 	float *values;
-	values = _values;
-	_values = NULL;
-	_nValues = 0;
+	values = values_;
+	values_ = NULL;
+	nValues_ = 0;
 	return values;
     }
     size_t nValues(void) {
-	return _nValues;
+	return nValues_;
     }
     size_t extents(void) {
-	return _extents;
+	return extents_;
     }
     void extents(size_t extents) {
-	_extents = extents;
+	extents_ = extents;
     }
     int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
     bool isInitialized(void) {
-	return _initialized;
+	return initialized_;
     }
 };
 
 class Unirect2d {
-    size_t _xNum, _yNum;
-    size_t _nValues;
-    size_t _extents;
-
-    float _xMin, _xMax;
-    float _yMin, _yMax;
-    float _vMin, _vMax;
-
-    char *_xUnits;
-    char *_yUnits;
-    char *_vUnits;
-
-    float *_values;
-    bool _initialized;
+    size_t xNum_, yNum_;
+    size_t nValues_;
+    size_t extents_;
+
+    float xMin_, xMax_;
+    float yMin_, yMax_;
+    float vMin_, vMax_;
+
+    char *xUnits_;
+    char *yUnits_;
+    char *vUnits_;
+
+    float *values_;
+    bool initialized_;
 
 public:
     Unirect2d(void) {
-	_values = NULL;
-	_initialized = false;
-	_xNum = _yNum = 0;
-	_nValues = 0;
-	_xUnits = _yUnits = _vUnits = NULL;
+	values_ = NULL;
+	initialized_ = false;
+	xNum_ = yNum_ = 0;
+	nValues_ = 0;
+	xUnits_ = yUnits_ = vUnits_ = NULL;
     }
     ~Unirect2d(void) {
-	if (_values != NULL) {
-	    delete [] _values;
-	}
-	if (_xUnits != NULL) {
-	    free(_xUnits);
-	}
-	if (_yUnits != NULL) {
-	    free(_yUnits);
-	}
-	if (_vUnits != NULL) {
-	    free(_vUnits);
+	if (values_ != NULL) {
+	    delete [] values_;
+	}
+	if (xUnits_ != NULL) {
+	    free(xUnits_);
+	}
+	if (yUnits_ != NULL) {
+	    free(yUnits_);
+	}
+	if (vUnits_ != NULL) {
+	    free(vUnits_);
 	}
     }
     size_t xNum(void) {
-	return _xNum;
+	return xNum_;
     }
     size_t yNum(void) {
-	return _yNum;
+	return yNum_;
     }
     float xMin(void) {
-	return _xMin;
+	return xMin_;
     }
     float yMin(void) {
-	return _yMin;
+	return yMin_;
     }
     float xMax(void) {
-	return _xMax;
+	return xMax_;
     }
     float yMax(void) {
-	return _yMax;
+	return yMax_;
     }
     const char *xUnits(void) {
-	return _xUnits;
+	return xUnits_;
     }
     const char *yUnits(void) {
-	return _yUnits;
+	return yUnits_;
     }
     const char *vUnits(void) {
-	return _vUnits;
+	return vUnits_;
     }
     float *values(void) {
-	return _values;
+	return values_;
     }
     float *acceptValues(void) {
 	float *values;
-	values = _values;
-	_values = NULL;
-	_nValues = 0;
+	values = values_;
+	values_ = NULL;
+	nValues_ = 0;
 	return values;
     }
     size_t nValues(void) {
-	return _nValues;
+	return nValues_;
     }
     size_t extents(void) {
-	return _extents;
+	return extents_;
     }
     void extents(size_t extents) {
-	_extents = extents;
+	extents_ = extents;
     }
     int LoadData(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv);
     bool isInitialized(void) {
-	return _initialized;
+	return initialized_;
     }
 };
Index: trunk/packages/vizservers/nanovis/dxReader.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/dxReader.cpp	(revision 1380)
+++ trunk/packages/vizservers/nanovis/dxReader.cpp	(revision 1381)
@@ -37,4 +37,5 @@
 #include "RpFieldRect3D.h"
 #include "RpFieldPrism3D.h"
+#include <Unirect.h>
 
 //transfer function headers
@@ -70,14 +71,11 @@
 }
 
-/*
- * Load a 3D vector field from a dx-format file
- */
-bool
-load_vector_stream2(Rappture::Outcome &result, int ivol, size_t length,
-		    char *string)
+Rappture::Unirect3d *
+ReadDxVectorFieldData(Rappture::Outcome &result, size_t length, char *string) 
 {
     int nx, ny, nz, npts;
     double x0, y0, z0, dx, dy, dz, ddx, ddy, ddz;
     char *p, *endPtr;
+
 
     dx = dy = dz = 0.0;         // Suppress compiler warning.
@@ -114,5 +112,5 @@
 		result.addError("inconsistent data: expected %d points"
 				" but found %d points", nx*ny*nz, npts);
-		return false;
+		return NULL;
 	    }
 	    break;
@@ -122,35 +120,21 @@
 		result.addError("inconsistent data: expected %d points"
 				" but found %d points", nx*ny*nz, npts);
-		return false;
+		return NULL;
 	    }
 	    break;
 	}
     }
-    Vector3 physicalMin;
-    Vector3 physicalMax;
-
-    physicalMin.set(x0, y0, z0);
-    physicalMax.set(x0 + dx * nx, y0 + dy * ny, z0 + dz * nz);
-
-    // read data points
-    float* srcdata = new float[nx * ny * nz * 3];
-    if (p >= endPtr) {
-        std::cerr << "WARNING: data not found in stream" << std::endl;
-	return true;
-    }
-#ifdef notdef
-    double max_x = -1e21, min_x = 1e21;
-    double max_y = -1e21, min_y = 1e21;
-    double max_z = -1e21, min_z = 1e21;
-#endif
-    double max_mag = -1e21, min_mag = 1e21;
-    int nread = 0;
+    if (npts != nx*ny*nz) {
+	result.addError("inconsistent data: expected %d points"
+			" but found %d points", nx*ny*nz, npts);
+	return NULL;
+    }
+    float *values = new float[npts];
+    int nValues = 0;
     for (int ix=0; ix < nx; ix++) {
 	for (int iy=0; iy < ny; iy++) {
 	    for (int iz=0; iz < nz; iz++) {
 		char *line;
-		double vx, vy, vz, vm;
-
-		if ((p == endPtr) || nread > npts) {
+		if ((p == endPtr) || (nValues > npts)) {
 		    break;
 		}
@@ -159,58 +143,82 @@
 		    continue;	// Skip blank or comment lines.
 		}
+		double vx, vy, vz;
 		if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) {
 		    int nindex = (iz*nx*ny + iy*nx + ix) * 3;
-		    srcdata[nindex] = vx;
-		    //if (srcdata[nindex] > max_x) max_x = srcdata[nindex];
-		    //if (srcdata[nindex] < min_x) min_x = srcdata[nindex];
-		    ++nindex;
-		    
-		    srcdata[nindex] = vy;
-		    //if (srcdata[nindex] > max_y) max_y = srcdata[nindex];
-		    //if (srcdata[nindex] < min_y) min_y = srcdata[nindex];
-		    ++nindex;
-		    
-		    srcdata[nindex] = vz;
-		    //if (srcdata[nindex] > max_z) max_z = srcdata[nindex];
-		    //if (srcdata[nindex] < min_z) min_z = srcdata[nindex];
-		    
-		    vm = sqrt(vx*vx + vy*vy + vz*vz);
-		    if (vm > max_mag) {
-			max_mag = vm;
-		    }
-		    if (vm < min_mag) {
-			min_mag = vm;
-		    }
-		    ++nread;
+		    values[nindex] = vx;
+		    values[nindex+1] = vy;
+		    values[nindex+2] = vz;
+		    nValues++;
 		}
 	    }
 	}
     }
+    // make sure that we read all of the expected points
+    if (nValues != npts) {
+	result.addError("inconsistent data: expected %d points"
+			" but found %d points", npts, nValues);
+	delete values;
+	return NULL;
+    }
+    return new Rappture::Unirect3d(x0, x0 + dx * nx, nx, y0, y0 + dy * ny, ny,
+				   z0, z0 + dz * nz, nz, nValues, values);
+}
+
+
+/*
+ * Load a 3D vector field from a dx-format file
+ */
+bool
+load_vector_stream2(Rappture::Outcome &result, int ivol, size_t length,
+		    char *string)
+{
+    Rappture::Unirect3d *dataPtr;
+    dataPtr = ReadDxVectorFieldData(result, length, string);
+    if (dataPtr == NULL) {
+	return false;
+    }
+    Vector3 physicalMin;
+    Vector3 physicalMax;
+
+    physicalMin.set(dataPtr->xMin(), dataPtr->yMin(), dataPtr->zMin());
+    physicalMax.set(dataPtr->xMax(), dataPtr->yMax(), dataPtr->zMax());
+
+    double max_mag = -DBL_MAX, min_mag = DBL_MAX;
+    float *values = dataPtr->values();
+    for (size_t ix=0; ix < dataPtr->xNum(); ix++) {
+	for (size_t iy=0; iy < dataPtr->yNum(); iy++) {
+	    for (size_t iz=0; iz < dataPtr->zNum(); iz++) {
+		double vx, vy, vz, vm;
+		vx = values[0];
+		vy = values[1];
+		vz = values[2];
+		vm = sqrt(vx*vx + vy*vy + vz*vz);
+		if (vm > max_mag) {
+		    max_mag = vm;
+		}
+		if (vm < min_mag) {
+		    min_mag = vm;
+		}
+		values += 3;
+	    }
+	}
+    }
     
-    // make sure that we read all of the expected points
-    if (nread != nx*ny*nz) {
-	result.addError("inconsistent data: expected %d points"
-			" but found %d points", nx*ny*nz, npts);
-	return false;
-    }
-    
-    float *data = new float[4*nx*ny*nz];
-    memset(data, 0, sizeof(float) * 4 * nx * ny * nz);
-    fprintf(stderr, "generating %dx%dx%d = %d points\n", nx, ny, nz, nx*ny*nz);
-
-    // generate the uniformly sampled data that we need for a volume
+    float *data = new float[4*dataPtr->nValues()];
+    memset(data, 0, sizeof(float) * 4 * dataPtr->nValues());
+    fprintf(stderr, "generating %dx%dx%d = %d points\n", 
+	    dataPtr->xNum(), dataPtr->yNum(), dataPtr->zNum(), 
+	    dataPtr->nValues());
+
     float *destPtr = data;
-    float *srcPtr = srcdata;
-    for (int iz=0; iz < nz; iz++) {
-	for (int iy=0; iy < ny; iy++) {
-	    for (int ix=0; ix < nx; ix++) {
+    float *srcPtr = dataPtr->values();
+    for (size_t iz=0; iz < dataPtr->zNum(); iz++) {
+	for (size_t iy=0; iy < dataPtr->yNum(); iy++) {
+	    for (size_t ix=0; ix < dataPtr->xNum(); ix++) {
 		double vx, vy, vz, vm;
-
-		vx = srcPtr[0];
-		vy = srcPtr[1];
-		vz = srcPtr[2];
-		
+		vx = values[0];
+		vy = values[1];
+		vz = values[2];
 		vm = sqrt(vx*vx + vy*vy + vz*vz);
-		
 		destPtr[0] = vm / max_mag; 
 		destPtr[1] = vx /(2.0*max_mag) + 0.5; 
@@ -224,187 +232,133 @@
     
     Volume *volPtr;
-    volPtr = NanoVis::load_volume(ivol, nx, ny, nz, 4, data, min_mag, max_mag, 
-	0);
-    
-    volPtr->xAxis.SetRange(x0, x0 + nx);
-    volPtr->yAxis.SetRange(y0, y0 + ny);
-    volPtr->zAxis.SetRange(z0, z0 + nz);
+    volPtr = NanoVis::load_volume(ivol, dataPtr->xNum(), dataPtr->yNum(), 
+		dataPtr->zNum(), 4, data, min_mag, max_mag, 0);
+    volPtr->xAxis.SetRange(dataPtr->xMin(), dataPtr->xMax());
+    volPtr->yAxis.SetRange(dataPtr->yMin(), dataPtr->yMax());
+    volPtr->zAxis.SetRange(dataPtr->zMin(), dataPtr->zMax());
     volPtr->wAxis.SetRange(min_mag, max_mag);
     volPtr->update_pending = true;
     volPtr->setPhysicalBBox(physicalMin, physicalMax);
-    delete [] data;
+    delete dataPtr;
+    delete data;
     return true;
 }
 
 bool
-load_vector_stream(Rappture::Outcome result, int index, std::istream& fin)
+load_vector_stream(Rappture::Outcome result, int index, size_t length,
+		    char *string)
 {
-    int dummy, nx, ny, nz, npts;
-    double x0, y0, z0, dx, dy, dz, ddx, ddy, ddz;
-    char line[128], type[128], *start;
-
-    dx = dy = dz = 0.0;         // Suppress compiler warning.
-    x0 = y0 = z0 = 0.0;		// May not have an origin line.
-    while (!fin.eof()) {
-        fin.getline(line, sizeof(line) - 1);
-        if (fin.fail()) {
-            result.addError("error in data stream");
-            return false;
-        }
-        for (start=&line[0]; *start == ' ' || *start == '\t'; start++)
-            ;  // skip leading blanks
-
-        if (*start != '#') {  // skip comment lines
-            if (sscanf(start, "object %d class gridpositions counts %d %d %d", &dummy, &nx, &ny, &nz) == 4) {
-		printf("w:%d h:%d d:%d\n", nx, ny, nz);
-                // found grid size
-            } else if (sscanf(start, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) {
-                // found origin
-            } else if (sscanf(start, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) {
-                // found one of the delta lines
-                if (ddx != 0.0) {
-                    dx = ddx;
-                } else if (ddy != 0.0) {
-                    dy = ddy;
-                } else if (ddz != 0.0) {
-                    dz = ddz;
-                }
-            } else if (sscanf(start, "object %d class array type %s shape 3 rank 1 items %d data follows", &dummy, type, &npts) == 3) {
-		printf("point %d\n", npts);
-                if (npts != nx*ny*nz) {
-                    result.addError("inconsistent data: expected %d points"
-				    " but found %d points", nx*ny*nz, npts);
-                    return false;
-                }
-                break;
-            } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) {
-                if (npts != nx*ny*nz) {
-                    result.addError("inconsistent data: expected %d points"
-				    " but found %d points", nx*ny*nz, npts);
-                    return false;
-                }
-                break;
-            }
-        }
-    }
-
-    // read data points
-    if (!fin.eof()) {
-        Rappture::Mesh1D xgrid(x0, x0+nx*dx, nx);
-        Rappture::Mesh1D ygrid(y0, y0+ny*dy, ny);
-        Rappture::Mesh1D zgrid(z0, z0+nz*dz, nz);
-        Rappture::FieldRect3D xfield(xgrid, ygrid, zgrid);
-        Rappture::FieldRect3D yfield(xgrid, ygrid, zgrid);
-        Rappture::FieldRect3D zfield(xgrid, ygrid, zgrid);
-
-        double vx, vy, vz;
-        int nread = 0;
-        for (int ix=0; ix < nx; ix++) {
-            for (int iy=0; iy < ny; iy++) {
-                for (int iz=0; iz < nz; iz++) {
-                    if (fin.eof() || nread > npts) {
-                        break;
-                    }
-                    fin.getline(line,sizeof(line)-1);
-                    if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) {
-                        int nindex = iz*nx*ny + iy*nx + ix;
-                        xfield.define(nindex, vx);
-                        yfield.define(nindex, vy);
-                        zfield.define(nindex, vz);
-                        nread++;
-                    }
-                }
-            }
-        }
-
-        // make sure that we read all of the expected points
-        if (nread != nx*ny*nz) {
-	    result.addError("inconsistent data: expected %d points"
-			    " but found %d points", nx*ny*nz, npts);
-            return false;
-        }
-
-        // figure out a good mesh spacing
-        int nsample = 30;
-        dx = xfield.rangeMax(Rappture::xaxis) - xfield.rangeMin(Rappture::xaxis);
-        dy = xfield.rangeMax(Rappture::yaxis) - xfield.rangeMin(Rappture::yaxis);
-        dz = xfield.rangeMax(Rappture::zaxis) - xfield.rangeMin(Rappture::zaxis);
-        double dmin = pow((dx*dy*dz)/(nsample*nsample*nsample), 0.333);
-
-	printf("dx:%lf dy:%lf dz:%lf dmin:%lf\n", dx, dy, dz, dmin);
-
-        nx = (int)ceil(dx/dmin);
-        ny = (int)ceil(dy/dmin);
-        nz = (int)ceil(dz/dmin);
-
+    Rappture::Unirect3d *dataPtr;
+    dataPtr = ReadDxVectorFieldData(result, length, string);
+    if (dataPtr == NULL) {
+	return false;
+    }
+    Vector3 physicalMin;
+    Vector3 physicalMax;
+
+    physicalMin.set(dataPtr->xMin(), dataPtr->yMin(), dataPtr->zMin());
+    physicalMax.set(dataPtr->xMax(), dataPtr->yMax(), dataPtr->zMax());
+
+    Rappture::Mesh1D xgrid(dataPtr->xMin(), dataPtr->yMin(), dataPtr->xNum());
+    Rappture::Mesh1D ygrid(dataPtr->yMin(), dataPtr->yMax(), dataPtr->yNum());
+    Rappture::Mesh1D zgrid(dataPtr->zMin(), dataPtr->zMax(), dataPtr->zNum());
+    Rappture::FieldRect3D xfield(xgrid, ygrid, zgrid);
+    Rappture::FieldRect3D yfield(xgrid, ygrid, zgrid);
+    Rappture::FieldRect3D zfield(xgrid, ygrid, zgrid);
+    
+    float *values = dataPtr->values();
+    size_t npts = 0;
+    for (size_t ix=0; ix < dataPtr->xNum(); ix++) {
+	for (size_t iy=0; iy < dataPtr->yNum(); iy++) {
+	    for (size_t iz=0; iz < dataPtr->zNum(); iz++) {
+		xfield.define(npts, values[0]);
+		yfield.define(npts, values[1]);
+		zfield.define(npts, values[2]);
+		npts++;
+		values += 3;
+	    }
+	}
+    }
+
+    double dx, dy, dz;
+    // figure out a good mesh spacing
+    int nsample = 30;
+    dx = xfield.rangeMax(Rappture::xaxis) - xfield.rangeMin(Rappture::xaxis);
+    dy = xfield.rangeMax(Rappture::yaxis) - xfield.rangeMin(Rappture::yaxis);
+    dz = xfield.rangeMax(Rappture::zaxis) - xfield.rangeMin(Rappture::zaxis);
+    double dmin = pow((dx*dy*dz)/(nsample*nsample*nsample), 0.333);
+
+    printf("dx:%lf dy:%lf dz:%lf dmin:%lf\n", dx, dy, dz, dmin);
+
+    size_t nx, ny, nz;
+    nx = (int)ceil(dx/dmin);
+    ny = (int)ceil(dy/dmin);
+    nz = (int)ceil(dz/dmin);
+    
 #ifndef NV40
-        // must be an even power of 2 for older cards
-        nx = (int)pow(2.0, ceil(log10((double)nx)/log10(2.0)));
-        ny = (int)pow(2.0, ceil(log10((double)ny)/log10(2.0)));
-        nz = (int)pow(2.0, ceil(log10((double)nz)/log10(2.0)));
+    // must be an even power of 2 for older cards
+    nx = (int)pow(2.0, ceil(log10((double)nx)/log10(2.0)));
+    ny = (int)pow(2.0, ceil(log10((double)ny)/log10(2.0)));
+    nz = (int)pow(2.0, ceil(log10((double)nz)/log10(2.0)));
 #endif
-
-        float *data = new float[4*nx*ny*nz];
-        memset(data, 0, sizeof(float) * 4 * nx * ny * nz);
-
-        std::cout << "generating " << nx << "x" << ny << "x" << nz << " = " << nx*ny*nz << " points" << std::endl;
-
-        // generate the uniformly sampled data that we need for a volume
-        double vmin = 1e21;
-        double vmax = -1e21;
-        double nzero_min = 0.0;
-        int ngen = 0;
-        for (int iz=0; iz < nz; iz++) {
-            double zval = z0 + iz*dmin;
-            for (int iy=0; iy < ny; iy++) {
-                double yval = y0 + iy*dmin;
-                for (int ix=0; ix < nx; ix++) {
-                    double xval = x0 + ix*dmin;
-
-                    vx = xfield.value(xval,yval,zval);
-                    vy = yfield.value(xval,yval,zval);
-                    vz = zfield.value(xval,yval,zval);
-
-                    double vm;
-                    vm = sqrt(vx*vx + vy*vy + vz*vz);
-                    if (vm < vmin) {
-                        vmin = vm;
-                    } else if (vm > vmax) {
-                        vmax = vm;
-                    }
-                    if ((vm != 0.0f) && (vm < nzero_min)) {
-                        nzero_min = vm;
-                    }
-                    data[ngen++] = vm;
-                    data[ngen++] = vx;
-                    data[ngen++] = vy;
-                    data[ngen++] = vz;
-                }
-            }
-        }
-
-        ngen = 0;
-
-        // scale should be accounted.
-        for (ngen=0; ngen < npts; ) {
-	    data[ngen] = data[ngen] / vmax; ++ngen;
-            data[ngen] = (data[ngen]/(2.0*vmax) + 0.5); ++ngen;
-            data[ngen] = (data[ngen]/(2.0*vmax) + 0.5); ++ngen;
-            data[ngen] = (data[ngen]/(2.0*vmax) + 0.5); ++ngen;
-        }
-        Volume *volPtr;
-        volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, vmin, vmax,
-                    nzero_min);
-
-        volPtr->xAxis.SetRange(x0, x0 + (nx * dx));
-        volPtr->yAxis.SetRange(y0, y0 + (ny * dy));
-        volPtr->zAxis.SetRange(z0, z0 + (nz * dz));
-        volPtr->wAxis.SetRange(vmin, vmax);
-        volPtr->update_pending = true;
-        delete [] data;
-    } else {
-        result.addError("WARNING: data not found in stream");
-	return false;
-    }
+    
+    float *data = new float[4*nx*ny*nz];
+    memset(data, 0, sizeof(float) * 4 * nx * ny * nz);
+    
+    std::cout << "generating " << nx << "x" << ny << "x" << nz << " = " << nx*ny*nz << " points" << std::endl;
+    
+    // generate the uniformly sampled data that we need for a volume
+    double vmin = 1e21;
+    double vmax = -1e21;
+    double nzero_min = 0.0;
+    size_t ngen = 0;
+    for (size_t iz=0; iz < nz; iz++) {
+	double zval = dataPtr->zMin() + iz*dmin;
+	for (size_t iy=0; iy < ny; iy++) {
+	    double yval = dataPtr->yMin() + iy*dmin;
+	    for (size_t ix=0; ix < nx; ix++) {
+		double xval = dataPtr->xMin() + ix*dmin;
+		double vx, vy, vz;
+
+		vx = xfield.value(xval,yval,zval);
+		vy = yfield.value(xval,yval,zval);
+		vz = zfield.value(xval,yval,zval);
+		
+		double vm;
+		vm = sqrt(vx*vx + vy*vy + vz*vz);
+		if (vm < vmin) {
+		    vmin = vm;
+		} else if (vm > vmax) {
+		    vmax = vm;
+		}
+		if ((vm != 0.0f) && (vm < nzero_min)) {
+		    nzero_min = vm;
+		}
+		data[ngen++] = vm;
+		data[ngen++] = vx;
+		data[ngen++] = vy;
+		data[ngen++] = vz;
+	    }
+	}
+    }
+    
+    ngen = 0;
+    // scale should be accounted.
+    for (ngen=0; ngen < npts; /*empty*/) {
+	data[ngen] = data[ngen] / vmax; ++ngen;
+	data[ngen] = (data[ngen]/(2.0*vmax) + 0.5); ++ngen;
+	data[ngen] = (data[ngen]/(2.0*vmax) + 0.5); ++ngen;
+	data[ngen] = (data[ngen]/(2.0*vmax) + 0.5); ++ngen;
+    }
+    Volume *volPtr;
+    volPtr = NanoVis::load_volume(index, nx, ny, nz, 4, data, vmin, vmax,
+				  nzero_min);
+    
+    volPtr->xAxis.SetRange(dataPtr->xMin(), dataPtr->xMin() + (nx * dx));
+    volPtr->yAxis.SetRange(dataPtr->yMin(), dataPtr->yMin() + (ny * dy));
+    volPtr->zAxis.SetRange(dataPtr->zMin(), dataPtr->zMin() + (nz * dz));
+    volPtr->wAxis.SetRange(vmin, vmax);
+    volPtr->update_pending = true;
+    delete [] data;
     return true;
 }
@@ -775,9 +729,8 @@
 }
 
-Rappture::Outcome
-load_volume_stream(int index, std::iostream& fin)
+bool
+load_volume_stream(Rappture::Outcome &result, int index, std::iostream& fin)
 {
     printf("load_volume_stream\n");
-    Rappture::Outcome result;
 
     Rappture::MeshTri2D xymesh;
@@ -793,5 +746,6 @@
         fin.getline(line, sizeof(line) - 1);
         if (fin.fail()) {
-            return result.error("error in data stream");
+            result.error("error in data stream");
+	    return false;
         }
         for (start=line; *start == ' ' || *start == '\t'; start++)
@@ -851,5 +805,6 @@
                     ftri.close();
                 } else {
-                    return result.error("triangularization failed");
+                    result.error("triangularization failed");
+		    return false;
                 }
 		unlink(fpts);
@@ -902,5 +857,6 @@
                 fin.getline(line,sizeof(line)-1);
                 if (fin.fail()) {
-                    return result.error("error reading data points");
+                    result.addError("error reading data points");
+		    return false;
                 }
                 int n = sscanf(line, "%lg %lg %lg %lg %lg %lg", &dval[0], &dval[1], &dval[2], &dval[3], &dval[4], &dval[5]);
@@ -1052,8 +1008,7 @@
                 fin >> dval;
                 if (fin.fail()) {
-                    char mesg[256];
-                    sprintf(mesg,"after %d of %d points: can't read number", 
+                    result.addError("after %d of %d points: can't read number", 
                             nread, npts);
-                    return result.error(mesg);
+		    return false;
                 } else {
                     int nid = nxy*iz + ixy;
@@ -1191,5 +1146,6 @@
         }
     } else {
-        return result.error("data not found in stream");
+        result.error("data not found in stream");
+	return false;
     }
 
@@ -1201,13 +1157,14 @@
     float dz0 = -0.5*dz/dx;
     NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));
-    return result;
+    return true;
 }
 
-Rappture::Outcome
-load_volume_stream_insoo(int index, std::iostream& fin)
+
+bool
+load_volume_stream_insoo(Rappture::Outcome &result, int index, 
+			 std::iostream& fin)
 {
     printf("load_volume_stream\n");
-    Rappture::Outcome result;
-
+ 
     Rappture::MeshTri2D xymesh;
     int dummy, nx, ny, nz, nxy, npts;
@@ -1222,5 +1179,6 @@
         fin.getline(line, sizeof(line) - 1);
         if (fin.fail()) {
-            return result.error("error in data stream");
+	    result.error("error in data stream");
+            return false;
         }
         for (start=line; *start == ' ' || *start == '\t'; start++)
@@ -1280,5 +1238,6 @@
                     ftri.close();
                 } else {
-                    return result.error("triangularization failed");
+		    result.error("triangularization failed");
+		    return false;
                 }
 		unlink(fpts), unlink(fcells);
@@ -1330,5 +1289,6 @@
                 fin.getline(line,sizeof(line)-1);
                 if (fin.fail()) {
-                    return result.error("error reading data points");
+		    result.error("error reading data points");
+                    return false;
                 }
                 int n = sscanf(line, "%lg %lg %lg %lg %lg %lg", &dval[0], &dval[1], &dval[2], &dval[3], &dval[4], &dval[5]);
@@ -1524,5 +1484,6 @@
                     sprintf(mesg,"after %d of %d points: can't read number", 
                             nread, npts);
-                    return result.error(mesg);
+		    result.error(mesg);
+                    return false;
                 } else {
                     int nid = nxy*iz + ixy;
@@ -1660,5 +1621,6 @@
         }
     } else {
-        return result.error("data not found in stream");
+	result.error("data not found in stream");
+        return false;
     }
 
@@ -1670,4 +1632,4 @@
     float dz0 = -0.5*dz/dx;
     NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));
-    return result;
+    return true;
 }
Index: trunk/packages/vizservers/nanovis/dxReader2.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/dxReader2.cpp	(revision 1380)
+++ trunk/packages/vizservers/nanovis/dxReader2.cpp	(revision 1381)
@@ -17,5 +17,5 @@
  */
 bool
-load_volume_stream_odx(Rappture::Outcome &outcome, int index, const char *buf,
+load_volume_stream_odx(Rappture::Outcome &context, int index, const char *buf,
 		       int nBytes)
 {
@@ -23,5 +23,5 @@
 
     if (nBytes == 0) {
-	outcome.error("data not found in stream");
+	context.error("data not found in stream");
         return false;
     }
@@ -40,13 +40,14 @@
     fclose(f);
     if (nWritten != nBytes) {
-        outcome.addError("Can't read %d bytes from file \"%s\"\n", 
+        context.addError("Can't read %d bytes from file \"%s\"\n", 
 			 nBytes, dxfilename);
 	return false;
     }
 
-    Rappture::DX dxObj(outcome, dxfilename);
+    Rappture::DX dxObj(context, dxfilename);
 
     if (unlink(dxfilename) != 0) {
-        outcome.addError("Error deleting dx file: %s\n", dxfilename);
+        context.addError("Error deleting dx file: %s\n", dxfilename);
+	return false;
     }
 
Index: trunk/packages/vizservers/nanovis/nanovis.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/nanovis.cpp	(revision 1380)
+++ trunk/packages/vizservers/nanovis/nanovis.cpp	(revision 1381)
@@ -73,5 +73,5 @@
 extern void NvInitCG(); // in Shader.cpp
 extern bool load_vector_stream2(Rappture::Outcome &result, int index, 
-	std::istream& fin);
+	size_t length, char *string);
 
 // Indicates "up" axis:  x=1, y=2, z=3, -x=-1, -y=-2, -z=-3
@@ -154,7 +154,4 @@
 // in Command.cpp
 extern Tcl_Interp *initTcl();
-
-// in dxReader.cpp
-extern void load_vector_stream(int index, std::istream& fin);
 
 float vert[NMESH*NMESH*3];              //particle positions in main memory
@@ -1810,10 +1807,9 @@
 {
     Rappture::Outcome result;
-    std::ifstream fdata;
-    fdata.open(filename, std::ios::in);
-    
+    Rappture::Buffer buf;
+
+    buf.load(filename);
     int n = NanoVis::n_volumes;
-    //fdata.write(buf.bytes(),buf.size());
-    if (load_vector_stream2(result, n, fdata)) {
+    if (load_vector_stream2(result, n, buf.size(), buf.bytes())) {
 	Volume *volPtr = NanoVis::volume[n];
 	if (volPtr != NULL) {
