Index: anuga_work/development/anugavis/src/Makefile.am
===================================================================
--- anuga_work/development/anugavis/src/Makefile.am	(revision 5501)
+++ anuga_work/development/anugavis/src/Makefile.am	(revision 5502)
@@ -13,5 +13,5 @@
                         globals.c \
                         globals.h \
-                        height_quantity.c \
+                        height_quantity_c.c \
                         height_quantity.h \
                         init.c \
@@ -25,4 +25,6 @@
 libanugavis_cxx_a_SOURCES = anugavis.cc \
 			    anugavis.hh \
+			    height_quantity.cc \
+			    height_quantity.hh \
 			    output.cc \
 			    output.hh \
Index: anuga_work/development/anugavis/src/height_quantity.c
===================================================================
--- anuga_work/development/anugavis/src/height_quantity.c	(revision 5501)
+++ 	(revision )
@@ -1,177 +1,0 @@
-#ifdef HAVE_CONFIG_H
-#  include "config.h"
-#endif
-
-#ifdef HAVE_STDLIB_H
-#  include <stdlib.h>
-#endif
-#ifdef HAVE_STRING_H
-#  include <string.h>
-#endif
-#ifdef HAVE_GL_GL_H
-#  include <GL/gl.h>
-#elif HAVE_OPENGL_GL_H
-#  include <OpenGL/gl.h>
-#endif
-#include <netcdf.h>
-#include <SDL.h>
-#include "error.h"
-#include "globals.h"
-#include "height_quantity.h"
-#include "netcdf_util.h"
-#include "vector.h"
-#include "xfunctions.h"
-
-static int compileDisplayLists(struct height_quantity_simple *height){
-  int frame;
-  unsigned int vol;
-  unsigned int vertex;
-  int vertIndex;
-  vector vs[3];
-  vector v1;
-  vector v2;
-  vector normal;
-  vector flippedNormal;
-  vector up = {0.0, 0.0, 1.0};
-  float *heights = xmalloc(sizeof(float)
-			   * anugavis.number_of_points
-			   * height->frames, "compileDisplayLists()");
-  if(heights == NULL)
-    return -1;
-  if(nc_get_var_float_by_name(anugavis.netcdfId,
-			      height->name, heights) != NC_NOERR){
-    free(heights);
-    return -1;
-  }
-
-  for(frame = 0 ; frame < height->frames ; frame++){
-    glNewList(height->displayLists + frame, GL_COMPILE);
-    for(vol = 0 ; vol < anugavis.number_of_volumes ; vol++){
-      glBegin(GL_POLYGON);
-      for(vertex = 0 ; vertex < 3 ; vertex++){ /* Calculate normal */
-	vertIndex = anugavis.volumes[vol*anugavis.number_of_vertices + vertex];
-	vs[vertex][0] = anugavis.x[vertIndex];
-	vs[vertex][1] = anugavis.y[vertIndex];
-	vs[vertex][2] = heights[frame*anugavis.number_of_points + vertIndex];
-      }
-      vsub(vs[1], vs[0], v1);
-      vsub(vs[2], vs[0], v2);
-      vcross(v1, v2, normal);
-      if(vdot(normal, up) / vlen(normal) < 0){
-	vscale(normal, -1.0, flippedNormal);
-	glNormal3fv(flippedNormal);
-      }else glNormal3fv(normal);
-      for(vertex = 0 ; vertex < anugavis.number_of_vertices ; vertex++){
-	vertIndex = anugavis.volumes[vol*anugavis.number_of_vertices + vertex];
-	glVertex3f(anugavis.x[vertIndex], anugavis.y[vertIndex],
-		   heights[frame * anugavis.number_of_points + vertIndex]);
-      }
-      glEnd();
-    }
-    glEndList();
-  }
-
-  free(heights);
-  return 0;
-}
-
-static void freeHeightQuantity(struct height_quantity_simple *height){
-  if(height->name != NULL) free(height->name);
-  if(glIsList(height->displayLists) == GL_TRUE)
-    glDeleteLists(height->displayLists, height->frames);
-  free(height);
-}
-
-int AnugaVis_DefineHeightQuantity(const char *name,
-				  double offset, double scale,
-				  GLfloat red, GLfloat green, GLfloat blue){
-  struct height_quantity_simple *height;
-  int ncstatus;
-  int ncvarid;
-  int numdims;
-  GLenum glerror;
-  /* Check that it's actually in the NetCDF file */
-  if((ncstatus = nc_inq_varid(anugavis.netcdfId, name, &ncvarid)) != NC_NOERR){
-    AnugaVis_NetCDFError(ncstatus);
-    return -1;
-  }     
-
-  /* Redefining a quantity? */
-  for(height = anugavis.heights ; height != NULL ; height = height->next)
-    if(!strcmp(name, height->name)) break;
-
-  if(height == NULL){ /* Make a new entry. */
-    if((height = xmalloc(sizeof(struct height_quantity_simple),
-			 "AnugaVis_DefineHeightQuantity()")) == NULL)
-      return -1;
-
-    height->name = NULL;
-    height->displayLists = -1;
-
-    if((height->name = xstrdup(name,
-			       "AnugaVis_DefineHeightQuantity()")) == NULL){
-      freeHeightQuantity(height);
-      return -1;
-    }
-
-    /* If the NetCDF variable is 2-dimensional, then it's dynamic. */
-    if((ncstatus = nc_inq_varndims(anugavis.netcdfId,
-				   ncvarid, &numdims)) != NC_NOERR){
-      AnugaVis_NetCDFError(ncstatus);
-      freeHeightQuantity(height);
-      return -1;
-    }
-
-    height->frames = (numdims == 2) ? anugavis.number_of_timesteps : 1;
-    height->displayLists = glGenLists(height->frames);
-    if((glerror = glGetError()) != GL_NO_ERROR){
-      AnugaVis_OpenGLError(glerror);
-      freeHeightQuantity(height);
-      return -1;
-    }
-
-    if(compileDisplayLists(height) == -1){
-      freeHeightQuantity(height);
-      return -1;
-    }
-
-    height->next = anugavis.heights;
-    anugavis.heights = height;
-  }
-
-  height->offset = offset;
-  height->scale = scale;
-  height->red = red;
-  height->green = green;
-  height->blue = blue;
-  return 0;
-}
-
-void AnugaVis_DrawHeightQuantity(struct height_quantity_simple *height){
-  glPushMatrix();
-  glScalef(1, 1, height->scale);
-  glTranslatef(0, 0, height->offset);
-  glColor3f(height->red, height->green, height->blue);
-  glCallList(height->displayLists + (height->frames == 1 ? 0 :
-				     anugavis.current_frame));
-  glPopMatrix();
-}
-
-void AnugaVis_UndefineHeightQuantity(const char *name){
-  struct height_quantity_simple *height = anugavis.heights;
-  struct height_quantity_simple *nextHeight;
-  if(height == NULL) return;
-  if(!strcmp(name, height->name)){
-    anugavis.heights = height->next;
-    freeHeightQuantity(height);
-    return;
-  }
-  for(; height != NULL ; height = height->next)
-    if(height->next == NULL) return;
-    if(!strcmp(name, height->next->name)){
-      nextHeight = height->next;
-      height->next = height->next->next;
-      freeHeightQuantity(nextHeight);
-      return;
-    }
-}
Index: anuga_work/development/anugavis/src/height_quantity.cc
===================================================================
--- anuga_work/development/anugavis/src/height_quantity.cc	(revision 5502)
+++ anuga_work/development/anugavis/src/height_quantity.cc	(revision 5502)
@@ -0,0 +1,52 @@
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <string>
+#ifdef HAVE_GL_GL_H
+#  include <GL/gl.h>
+#elif HAVE_OPENGL_GL_H
+#  include <OpenGL/gl.h>
+#endif
+#ifdef HAVE_GL_GLU_H
+#  include <GL/glu.h>
+#elif HAVE_OPENGL_GLU_H
+#  include <OpenGL/glu.h>
+#endif
+#include "height_quantity.hh"
+#include "sww_file.hh"
+
+using std::string;
+
+HeightQuantity::HeightQuantity(const SWWFile &sww, const string &name,
+			       GLdouble offset, GLdouble scale,
+			       GLfloat red, GLfloat green, GLfloat blue):
+  offset(offset), scale(scale), red(red), green(green), blue(blue), name(name),
+  frame_number(-1), sww(sww){
+  GLenum glerror;
+  this->dynamic = (sww.nc_inq_varndims_by_name(name) == 2);
+  this->display_list = glGenLists(1);
+  if((glerror = glGetError()) != GL_NO_ERROR) throw gluErrorString(glerror);
+  
+}
+
+HeightQuantity::~HeightQuantity(void){
+  if(glIsList(this->display_list) == GL_TRUE)
+    glDeleteLists(this->display_list, 1);
+}
+
+void HeightQuantity::draw(int frame){
+  if(!this->dynamic) frame = 0;
+  if(this->frame_number != frame) this->compile(frame);
+  this->frame_number = frame;
+  glPushMatrix();
+  glScalef(1, 1, this->scale);
+  glTranslatef(0, 0, this->offset);
+  glColor3f(this->red, this->green, this->blue);
+  glCallList(this->display_list);
+  glPopMatrix();
+}
+
+void HeightQuantity::compile(int frame){
+  
+}
Index: anuga_work/development/anugavis/src/height_quantity.hh
===================================================================
--- anuga_work/development/anugavis/src/height_quantity.hh	(revision 5502)
+++ anuga_work/development/anugavis/src/height_quantity.hh	(revision 5502)
@@ -0,0 +1,43 @@
+#ifndef HEIGHT_QUANTITY_HH
+#define HEIGHT_QUANTITY_HH
+
+/* An individual height quantity to render. */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <string>
+
+#ifdef HAVE_GL_GL_H
+#  include <GL/gl.h>
+#elif HAVE_OPENGL_GL_H
+#  include <OpenGL/gl.h>
+#endif
+#include "sww_file.hh"
+
+using std::string;
+
+class HeightQuantity {
+public:
+  HeightQuantity(const SWWFile &sww, const string &name,
+		 const GLdouble offset, GLdouble scale,
+		 GLfloat red, GLfloat green, GLfloat blue);
+  ~HeightQuantity(void);
+  void draw(int frame);
+  GLdouble offset;
+  GLdouble scale;
+  GLfloat red;
+  GLfloat green;
+  GLfloat blue;
+private:
+  void compile(int frame);
+  string name;
+  int frame_number; /* The most recently drawn frame (i.e., the one
+		       cached in the display list. */
+  bool dynamic;
+  GLuint display_list;
+  const SWWFile &sww;
+};
+
+#endif
Index: anuga_work/development/anugavis/src/height_quantity_c.c
===================================================================
--- anuga_work/development/anugavis/src/height_quantity_c.c	(revision 5502)
+++ anuga_work/development/anugavis/src/height_quantity_c.c	(revision 5502)
@@ -0,0 +1,177 @@
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#  include <string.h>
+#endif
+#ifdef HAVE_GL_GL_H
+#  include <GL/gl.h>
+#elif HAVE_OPENGL_GL_H
+#  include <OpenGL/gl.h>
+#endif
+#include <netcdf.h>
+#include <SDL.h>
+#include "error.h"
+#include "globals.h"
+#include "height_quantity.h"
+#include "netcdf_util.h"
+#include "vector.h"
+#include "xfunctions.h"
+
+static int compileDisplayLists(struct height_quantity_simple *height){
+  int frame;
+  unsigned int vol;
+  unsigned int vertex;
+  int vertIndex;
+  vector vs[3];
+  vector v1;
+  vector v2;
+  vector normal;
+  vector flippedNormal;
+  vector up = {0.0, 0.0, 1.0};
+  float *heights = xmalloc(sizeof(float)
+			   * anugavis.number_of_points
+			   * height->frames, "compileDisplayLists()");
+  if(heights == NULL)
+    return -1;
+  if(nc_get_var_float_by_name(anugavis.netcdfId,
+			      height->name, heights) != NC_NOERR){
+    free(heights);
+    return -1;
+  }
+
+  for(frame = 0 ; frame < height->frames ; frame++){
+    glNewList(height->displayLists + frame, GL_COMPILE);
+    for(vol = 0 ; vol < anugavis.number_of_volumes ; vol++){
+      glBegin(GL_POLYGON);
+      for(vertex = 0 ; vertex < 3 ; vertex++){ /* Calculate normal */
+	vertIndex = anugavis.volumes[vol*anugavis.number_of_vertices + vertex];
+	vs[vertex][0] = anugavis.x[vertIndex];
+	vs[vertex][1] = anugavis.y[vertIndex];
+	vs[vertex][2] = heights[frame*anugavis.number_of_points + vertIndex];
+      }
+      vsub(vs[1], vs[0], v1);
+      vsub(vs[2], vs[0], v2);
+      vcross(v1, v2, normal);
+      if(vdot(normal, up) / vlen(normal) < 0){
+	vscale(normal, -1.0, flippedNormal);
+	glNormal3fv(flippedNormal);
+      }else glNormal3fv(normal);
+      for(vertex = 0 ; vertex < anugavis.number_of_vertices ; vertex++){
+	vertIndex = anugavis.volumes[vol*anugavis.number_of_vertices + vertex];
+	glVertex3f(anugavis.x[vertIndex], anugavis.y[vertIndex],
+		   heights[frame * anugavis.number_of_points + vertIndex]);
+      }
+      glEnd();
+    }
+    glEndList();
+  }
+
+  free(heights);
+  return 0;
+}
+
+static void freeHeightQuantity(struct height_quantity_simple *height){
+  if(height->name != NULL) free(height->name);
+  if(glIsList(height->displayLists) == GL_TRUE)
+    glDeleteLists(height->displayLists, height->frames);
+  free(height);
+}
+
+int AnugaVis_DefineHeightQuantity(const char *name,
+				  double offset, double scale,
+				  GLfloat red, GLfloat green, GLfloat blue){
+  struct height_quantity_simple *height;
+  int ncstatus;
+  int ncvarid;
+  int numdims;
+  GLenum glerror;
+  /* Check that it's actually in the NetCDF file */
+  if((ncstatus = nc_inq_varid(anugavis.netcdfId, name, &ncvarid)) != NC_NOERR){
+    AnugaVis_NetCDFError(ncstatus);
+    return -1;
+  }     
+
+  /* Redefining a quantity? */
+  for(height = anugavis.heights ; height != NULL ; height = height->next)
+    if(!strcmp(name, height->name)) break;
+
+  if(height == NULL){ /* Make a new entry. */
+    if((height = xmalloc(sizeof(struct height_quantity_simple),
+			 "AnugaVis_DefineHeightQuantity()")) == NULL)
+      return -1;
+
+    height->name = NULL;
+    height->displayLists = -1;
+
+    if((height->name = xstrdup(name,
+			       "AnugaVis_DefineHeightQuantity()")) == NULL){
+      freeHeightQuantity(height);
+      return -1;
+    }
+
+    /* If the NetCDF variable is 2-dimensional, then it's dynamic. */
+    if((ncstatus = nc_inq_varndims(anugavis.netcdfId,
+				   ncvarid, &numdims)) != NC_NOERR){
+      AnugaVis_NetCDFError(ncstatus);
+      freeHeightQuantity(height);
+      return -1;
+    }
+
+    height->frames = (numdims == 2) ? anugavis.number_of_timesteps : 1;
+    height->displayLists = glGenLists(height->frames);
+    if((glerror = glGetError()) != GL_NO_ERROR){
+      AnugaVis_OpenGLError(glerror);
+      freeHeightQuantity(height);
+      return -1;
+    }
+
+    if(compileDisplayLists(height) == -1){
+      freeHeightQuantity(height);
+      return -1;
+    }
+
+    height->next = anugavis.heights;
+    anugavis.heights = height;
+  }
+
+  height->offset = offset;
+  height->scale = scale;
+  height->red = red;
+  height->green = green;
+  height->blue = blue;
+  return 0;
+}
+
+void AnugaVis_DrawHeightQuantity(struct height_quantity_simple *height){
+  glPushMatrix();
+  glScalef(1, 1, height->scale);
+  glTranslatef(0, 0, height->offset);
+  glColor3f(height->red, height->green, height->blue);
+  glCallList(height->displayLists + (height->frames == 1 ? 0 :
+				     anugavis.current_frame));
+  glPopMatrix();
+}
+
+void AnugaVis_UndefineHeightQuantity(const char *name){
+  struct height_quantity_simple *height = anugavis.heights;
+  struct height_quantity_simple *nextHeight;
+  if(height == NULL) return;
+  if(!strcmp(name, height->name)){
+    anugavis.heights = height->next;
+    freeHeightQuantity(height);
+    return;
+  }
+  for(; height != NULL ; height = height->next)
+    if(height->next == NULL) return;
+    if(!strcmp(name, height->next->name)){
+      nextHeight = height->next;
+      height->next = height->next->next;
+      freeHeightQuantity(nextHeight);
+      return;
+    }
+}
Index: anuga_work/development/anugavis/src/sww_file.cc
===================================================================
--- anuga_work/development/anugavis/src/sww_file.cc	(revision 5501)
+++ anuga_work/development/anugavis/src/sww_file.cc	(revision 5502)
@@ -38,4 +38,17 @@
 }
 
+
+int SWWFile::nc_inq_varndims_by_name(const string &name) const{
+  int ncstatus;
+  int dimid;
+  int ndims;
+  if(((ncstatus = nc_inq_dimid(this->netcdf_id,
+			       name.c_str(), &dimid)) != NC_NOERR) ||
+     ((ncstatus = nc_inq_varndims(this->netcdf_id,
+				  dimid, &ndims)) != NC_NOERR))
+    throw nc_strerror(ncstatus);
+  return ndims;
+}
+
 void SWWFile::compute_extents(void){
   this->minX = this->x[0];
@@ -51,5 +64,5 @@
 }
 
-void SWWFile::nc_get_var_float_by_name(const string &name, float array[]){
+void SWWFile::nc_get_var_float_by_name(const string &name, float array[]) const{
   int ncstatus;
   int varid;
@@ -61,5 +74,5 @@
 }
 
-void SWWFile::nc_get_var_int_by_name(const string &name, int array[]){
+void SWWFile::nc_get_var_int_by_name(const string &name, int array[]) const{
   int ncstatus;
   int varid;
@@ -71,5 +84,5 @@
 }
 
-size_t SWWFile::nc_inq_dimlen_by_name(const string &name){
+size_t SWWFile::nc_inq_dimlen_by_name(const string &name) const{
   int ncstatus;
   int dimid;
Index: anuga_work/development/anugavis/src/sww_file.hh
===================================================================
--- anuga_work/development/anugavis/src/sww_file.hh	(revision 5501)
+++ anuga_work/development/anugavis/src/sww_file.hh	(revision 5502)
@@ -21,9 +21,10 @@
   SWWFile(const string &file_name);
   ~SWWFile(void);
+  int nc_inq_varndims_by_name(const string &name) const;
 private:
+  void nc_get_var_float_by_name(const string &name, float array[]) const;
+  void nc_get_var_int_by_name(const string &name, int array[]) const;
+  size_t nc_inq_dimlen_by_name(const string &name) const;
   void compute_extents(void);
-  void nc_get_var_float_by_name(const string &name, float array[]);
-  void nc_get_var_int_by_name(const string &name, int array[]);
-  size_t nc_inq_dimlen_by_name(const string &name);
   int netcdf_id;
   int number_of_points;
