Index: /anuga_work/development/anugavis/src/Makefile.am
===================================================================
--- /anuga_work/development/anugavis/src/Makefile.am	(revision 5262)
+++ /anuga_work/development/anugavis/src/Makefile.am	(revision 5263)
@@ -13,4 +13,6 @@
                         init.c \
                         init.h \
+                        netcdf_util.c \
+                        netcdf_util.h \
                         xmalloc.c \
                         xmalloc.h
Index: /anuga_work/development/anugavis/src/anugavis_simple.c
===================================================================
--- /anuga_work/development/anugavis/src/anugavis_simple.c	(revision 5262)
+++ /anuga_work/development/anugavis/src/anugavis_simple.c	(revision 5263)
@@ -3,4 +3,6 @@
 #include "height_quantity.h"
 #include "init.h"
+#include "globals.h"
+#include <stdio.h>
 int main(int argc, char *argv[]){
   if(argc != 2){
@@ -12,4 +14,9 @@
     return 1;
   }
+
+  printf("points: %d\nvertices: %d\nvolumes: %d\n",
+	 anugavis.number_of_points,
+	 anugavis.number_of_vertices,
+	 anugavis.number_of_volumes);
 
   if(AnugaVis_DefineHeightQuantity("elevation", 0, 1, 128, 128, 128) == -1){
Index: /anuga_work/development/anugavis/src/globals.h
===================================================================
--- /anuga_work/development/anugavis/src/globals.h	(revision 5262)
+++ /anuga_work/development/anugavis/src/globals.h	(revision 5263)
@@ -9,4 +9,6 @@
   int netcdfId;
   size_t number_of_points;
+  size_t number_of_vertices;
+  size_t number_of_volumes;
   float *x;
   float *y;
Index: /anuga_work/development/anugavis/src/init.c
===================================================================
--- /anuga_work/development/anugavis/src/init.c	(revision 5262)
+++ /anuga_work/development/anugavis/src/init.c	(revision 5263)
@@ -20,4 +20,5 @@
 #include "error.h"
 #include "globals.h"
+#include "netcdf_util.h"
 #include "xmalloc.h"
 
@@ -51,39 +52,30 @@
 
   if((ncstatus = nc_open(swwFilePath, NC_SHARE,
-			 &anugavis.netcdfId)) != NC_NOERR) goto nc_err;
-  if((ncstatus = nc_inq_dimid(anugavis.netcdfId, "number_of_points",
-			      &ncdimid)) != NC_NOERR) goto nc_err1;
-  if((ncstatus = nc_inq_dimlen(anugavis.netcdfId, ncdimid,
-			       &anugavis.number_of_points)) != NC_NOERR)
-    goto nc_err1;
+			 &anugavis.netcdfId)) != NC_NOERR){
+    SDL_Quit();
+    return -1;
+  }
 
-  /* Get the number of vertices to keep space for. */
-  if((anugavis.x = xmalloc(sizeof(float) * anugavis.number_of_points,
-			   "AnugaVis_Init()")) == NULL)
-    goto bad_malloc;
-  if((anugavis.y = xmalloc(sizeof(float) * anugavis.number_of_points,
-			   "AnugaVis_Init()")) == NULL)
-    goto bad_malloc;
-
-  /* Load the list of x and y points from the NetCDF file. */
-  if((ncstatus = nc_inq_varid(anugavis.netcdfId, "x",
-			      &ncvarid)) != NC_NOERR) goto nc_err1;
-  if((ncstatus = nc_get_var_float(anugavis.netcdfId, ncvarid,
-				  anugavis.x)) != NC_NOERR) goto nc_err1;
-  if((ncstatus = nc_inq_varid(anugavis.netcdfId, "y",
-			      &ncvarid)) != NC_NOERR) goto nc_err1;
-  if((ncstatus = nc_get_var_float(anugavis.netcdfId, ncvarid,
-				  anugavis.y)) != NC_NOERR) goto nc_err1;
-
+  if((nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_points",
+			    &anugavis.number_of_points) != NC_NOERR) ||
+     (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_vertices",
+			    &anugavis.number_of_vertices) != NC_NOERR) ||
+     (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_volumes",
+			    &anugavis.number_of_volumes) != NC_NOERR) ||
+     ((anugavis.x = xmalloc(sizeof(float) * anugavis.number_of_points,
+			    "AnugaVis_Init()")) == NULL) ||
+     ((anugavis.y = xmalloc(sizeof(float) * anugavis.number_of_points,
+			    "AnugaVis_Init()")) == NULL) ||
+     (nc_get_var_float_by_name(anugavis.netcdfId, "x",
+			       anugavis.x) != NC_NOERR) ||
+     (nc_get_var_float_by_name(anugavis.netcdfId, "y",
+			       anugavis.y) != NC_NOERR)){
+    nc_close(anugavis.netcdfId);
+    if(anugavis.x != NULL) free(anugavis.x);
+    if(anugavis.y != NULL) free(anugavis.y);
+    SDL_Quit();
+    return -1;
+  }
   return 0;
- nc_err1:
-  nc_close(anugavis.netcdfId);
- nc_err:
-  AnugaVis_NetCDFError(ncstatus);
- bad_malloc:
-  if(anugavis.x != NULL) free(anugavis.x);
-  if(anugavis.y != NULL) free(anugavis.y);
-  SDL_Quit();
-  return -1;
 }
 
Index: /anuga_work/development/anugavis/src/netcdf_util.c
===================================================================
--- /anuga_work/development/anugavis/src/netcdf_util.c	(revision 5263)
+++ /anuga_work/development/anugavis/src/netcdf_util.c	(revision 5263)
@@ -0,0 +1,20 @@
+#include <netcdf.h>
+#include "error.h"
+
+int nc_inq_dimlen_by_name(int ncid, const char *name, size_t *size){
+  int status;
+  int dimid;
+  if(((status = nc_inq_dimid(ncid, name, &dimid)) != NC_NOERR) ||
+     ((status = nc_inq_dimlen(ncid, dimid, size)) != NC_NOERR))
+    AnugaVis_NetCDFError(status);
+  return status;
+}
+
+int nc_get_var_float_by_name(int ncid, const char *name, float *fp){
+  int status;
+  int varid;
+  if(((status = nc_inq_varid(ncid, name, &varid)) != NC_NOERR) ||
+     ((status = nc_get_var_float(ncid, varid, fp)) != NC_NOERR))
+    AnugaVis_NetCDFError(status);
+  return status;
+}
Index: /anuga_work/development/anugavis/src/netcdf_util.h
===================================================================
--- /anuga_work/development/anugavis/src/netcdf_util.h	(revision 5263)
+++ /anuga_work/development/anugavis/src/netcdf_util.h	(revision 5263)
@@ -0,0 +1,8 @@
+#ifndef NETCDF_UTIL_H
+#define NETCDF_UTIL_H
+
+/* These functions call AnugaVis_NetCDFError() if things go wrong. */
+extern int nc_inq_dimlen_by_name(int ncid, const char *name, size_t *size);
+extern int nc_get_var_float_by_name(int ncid, const char *name, float *fp);
+
+#endif
