Index: trunk/packages/vizservers/nanovis/Command.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/Command.cpp	(revision 1193)
+++ trunk/packages/vizservers/nanovis/Command.cpp	(revision 1194)
@@ -675,4 +675,8 @@
         nBytes -= nRead;
     }
+    if (NanoVis::recfile != NULL) {
+    	fwrite(buf.bytes(), sizeof(char), buf.size(), NanoVis::recfile);
+	fflush(NanoVis::recfile);
+    }
     {
         Rappture::Outcome err;
Index: trunk/packages/vizservers/nanovis/NvEventLog.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/NvEventLog.cpp	(revision 1193)
+++ trunk/packages/vizservers/nanovis/NvEventLog.cpp	(revision 1194)
@@ -1,3 +1,2 @@
-#include "NvEventLog.h"
 #include "config.h"
 #include <stdio.h>
@@ -9,5 +8,6 @@
 #include <stdlib.h>
 #include <string.h>
-
+#include "NvEventLog.h"
+#include "nanovis.h"
 
 
@@ -25,5 +25,4 @@
     char* logName = NULL;
     int logNameLen = 0;
-    extern int debug_flag;
 
     if (user == NULL) {
@@ -39,5 +38,5 @@
     }
 
-    if (!debug_flag) {
+    if (!NanoVis::debug_flag) {
 	//open log and map stderr to log file
 	xinetd_log = fopen(logName, "w");
Index: trunk/packages/vizservers/nanovis/nanovis.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/nanovis.cpp	(revision 1193)
+++ trunk/packages/vizservers/nanovis/nanovis.cpp	(revision 1194)
@@ -104,9 +104,6 @@
 int NanoVis::updir = Y_POS;
 NvCamera* NanoVis::cam = NULL;
-bool NanoVis::axis_on = true;
-int NanoVis::win_width = NPIX;                  //size of the render window
-int NanoVis::win_height = NPIX;                 //size of the render window
 int NanoVis::n_volumes = 0;
-unsigned char* NanoVis::screen_buffer = NULL;
+vector<Volume*> NanoVis::volume;
 vector<HeightMap*> NanoVis::heightMap;
 VolumeRenderer* NanoVis::vol_renderer = 0;
@@ -119,4 +116,5 @@
 graphics::RenderContext* NanoVis::renderContext = 0;
 NvLIC* NanoVis::licRenderer = 0;
+R2Fonts* NanoVis::fonts;
 
 FILE *NanoVis::stdin = NULL;
@@ -127,5 +125,7 @@
 bool NanoVis::particle_on = false;
 bool NanoVis::vector_on = false;
+bool NanoVis::axis_on = true;
 bool NanoVis::config_pending = false;
+bool NanoVis::debug_flag = false;
 
 Tcl_Interp *NanoVis::interp;
@@ -136,18 +136,17 @@
 NVISid NanoVis::final_color_tex = 0;
 NVISid NanoVis::final_depth_rb = 0;
-int render_window;              //the handle of the render window;
-
-// pointers to volumes, currently handle up to 10 volumes
-/*FIXME: Is the above comment true? Is there a 10 volume limit */
-vector<Volume*> NanoVis::volume;
-
-//if true nanovis renders volumes in 3D, if not renders 2D plane
+int NanoVis::render_window = 0;       /* GLUT handle for the render window */
+int NanoVis::win_width = NPIX;        /* Width of the render window */
+int NanoVis::win_height = NPIX;       /* Height of the render window */
+
+unsigned char* NanoVis::screen_buffer = NULL;
+
 /* FIXME: This variable is always true. */
 bool volume_mode = true; 
 
+#ifdef notdef
 // color table for built-in transfer function editor
 float color_table[256][4];
-
-int debug_flag = false;
+#endif
 
 // in Command.cpp
@@ -168,5 +167,4 @@
 CGparameter m_passthru_scale_param, m_passthru_bias_param;
 
-R2Fonts* NanoVis::fonts;
 
 // Variables for mouse events
@@ -411,9 +409,9 @@
     start = CVT2SECS(tv);
 
-    if (debug_flag) {
-	fprintf(NanoVis::logfile, "%s\n", Tcl_DStringValue(dsPtr));
+    if (NanoVis::debug_flag) {
+	fprintf(NanoVis::logfile, "(%s)\n", Tcl_DStringValue(dsPtr));
     }
     if (NanoVis::recfile != NULL) {
-	fprintf(NanoVis::recfile, "%s\n", Tcl_DStringValue(dsPtr));
+	fprintf(NanoVis::recfile, "%s", Tcl_DStringValue(dsPtr));
 	fflush(NanoVis::recfile);
     }
@@ -507,9 +505,10 @@
 }
 
+#ifdef notdef
 //Update the transfer function using local GUI in the non-server mode
 void 
 update_tf_texture()
 {
-    glutSetWindow(render_window);
+    glutSetWindow(NanoVis::render_window);
 
     //fprintf(stderr, "tf update\n");
@@ -537,4 +536,5 @@
 #endif
 }
+#endif
 
 int
@@ -1216,7 +1216,10 @@
 
 /*----------------------------------------------------*/
-static void
-idle()
-{
+void
+NanoVis::idle()
+{
+    if (debug_flag) {
+        fprintf(stderr, "in idle()\n");
+    }
     glutSetWindow(render_window);
 
@@ -1228,8 +1231,11 @@
 #endif
 #ifdef XINETD
-    NanoVis::xinetd_listen();
+    xinetd_listen();
 #else
     glutPostRedisplay();
 #endif
+    if (debug_flag) {
+        fprintf(stderr, "leaving idle()\n");
+    }
 }
 
@@ -1237,4 +1243,7 @@
 NanoVis::display_offscreen_buffer()
 {
+    if (debug_flag) {
+        fprintf(stderr, "in display_offscreen_buffer\n");
+    }
     glEnable(GL_TEXTURE_2D);
     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
@@ -1257,4 +1266,7 @@
     }
     glEnd();
+    if (debug_flag) {
+        fprintf(stderr, "leaving display_offscreen_buffer\n");
+    }
 }
 
@@ -1600,4 +1612,7 @@
     double xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;
 
+    if (debug_flag) {
+        fprintf(stderr, "in SetVolumeRanges\n");
+    }
     xMin = yMin = zMin = wMin = DBL_MAX;
     xMax = yMax = zMax = wMax = -DBL_MAX;
@@ -1651,4 +1666,7 @@
     }
     Volume::update_pending = false;
+    if (debug_flag) {
+        fprintf(stderr, "leaving SetVolumeRanges\n");
+    }
 }
 
@@ -1658,4 +1676,7 @@
     double xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;
 
+    if (debug_flag) {
+        fprintf(stderr, "in SetHeightmapRanges\n");
+    }
     xMin = yMin = zMin = wMin = DBL_MAX;
     xMax = yMax = zMax = wMax = -DBL_MAX;
@@ -1715,4 +1736,7 @@
     }
     HeightMap::update_pending = false;
+    if (debug_flag) {
+        fprintf(stderr, "leaving SetHeightmapRanges\n");
+    }
 }
 
@@ -1721,4 +1745,7 @@
 NanoVis::display()
 {
+    if (debug_flag) {
+        fprintf(stderr, "in display\n");
+    }
     //assert(glGetError()==0);
     if (HeightMap::update_pending) {
@@ -1728,8 +1755,14 @@
         SetVolumeRanges();
     }
+    if (debug_flag) {
+        fprintf(stderr, "in display: glClear\n");
+    }
     //start final rendering
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear screen
 
     if (volume_mode) {
+        if (debug_flag) {
+           fprintf(stderr, "in display: volume_mode\n");
+        }
         //3D rendering mode
         glEnable(GL_TEXTURE_2D);
@@ -1796,4 +1829,7 @@
         //perf->disable();
 
+        if (debug_flag) {
+           fprintf(stderr, "in display: render heightmap\n");
+        }
         for (unsigned int i = 0; i < heightMap.size(); ++i) {
             if (heightMap[i]->isVisible()) {
@@ -1814,4 +1850,7 @@
 #endif
     perf->reset();
+    if (debug_flag) {
+        fprintf(stderr, "leaving display\n");
+    }
 
 }
@@ -2008,5 +2047,5 @@
 init_service()
 {
-    if (!debug_flag) {
+    if (!NanoVis::debug_flag) {
 	//open log and map stderr to log file
 	xinetd_log = fopen("/tmp/log.txt", "w");
@@ -2109,4 +2148,7 @@
         fcntl(0, F_SETFL, flags | O_NONBLOCK);
         npass++;
+	if (NanoVis::debug_flag) {
+    	   break;
+	}
     }
     fcntl(0, F_SETFL, flags);
@@ -2195,7 +2237,9 @@
     glutInitWindowSize(NanoVis::win_width, NanoVis::win_height);
     glutInitWindowPosition(10, 10);
+    NanoVis::render_window = glutCreateWindow("nanovis");
     glutDisplayFunc(NanoVis::display);
-    glutIdleFunc(idle);
+    glutIdleFunc(NanoVis::idle);
     glutReshapeFunc(NanoVis::resize_offscreen_buffer);
+
 #ifndef XINETD
     glutMouseFunc(NanoVis::mouse);
@@ -2203,6 +2247,4 @@
     glutKeyboardFunc(NanoVis::keyboard);
 #endif
-
-    render_window = glutCreateWindow("nanovis");
 
 
@@ -2241,9 +2283,8 @@
 	case 3:
 	case 'd':
-	    debug_flag = true;
+	    NanoVis::debug_flag = true;
 	    break;
 	case 0:
 	case 'i':
-	    fprintf(stderr, "opening infile %s\n", optarg);
 	    NanoVis::stdin = fopen(optarg, "r");
 	    if (NanoVis::stdin == NULL) {
@@ -2254,5 +2295,4 @@
 	case 1:
 	case 'l':
-	    fprintf(stderr, "opening logfile %s\n", optarg);
 	    NanoVis::logfile = fopen(optarg, "w");
 	    if (NanoVis::logfile == NULL) {
@@ -2266,5 +2306,4 @@
 	    char buf[200];
 
-	    fprintf(stderr, "Recording commands to %s\n", optarg);
 	    Tcl_DStringInit(&ds);
 	    Tcl_DStringAppend(&ds, optarg, -1);
@@ -2321,5 +2360,4 @@
     NvInitEventLog();
 #endif
-    //event loop
     glutMainLoop();
 
Index: trunk/packages/vizservers/nanovis/nanovis.h
===================================================================
--- trunk/packages/vizservers/nanovis/nanovis.h	(revision 1193)
+++ trunk/packages/vizservers/nanovis/nanovis.h	(revision 1194)
@@ -135,6 +135,7 @@
     static int win_width;	//size of the render window
     static int win_height;	//size of the render window
- 
+    static int render_window; 
 
+    static bool debug_flag;
     static bool lic_on;
     static bool particle_on;
@@ -159,4 +160,5 @@
     static void bmp_write_to_file(int frame_number, const char* directory_name);
     static void display(void);
+    static void idle(void);
     static void update(void);
     static void display_offscreen_buffer();
