Index: /anuga_core/source/anuga/mesh_engine/mesh_engine.py
===================================================================
--- /anuga_core/source/anuga/mesh_engine/mesh_engine.py	(revision 4915)
+++ /anuga_core/source/anuga/mesh_engine/mesh_engine.py	(revision 4916)
@@ -58,4 +58,5 @@
     if pointatts is None or pointatts == []:
         pointatts = [[] for x in range(points.shape[0])]
+        
     try:
         # If Int is used, instead of Int32, it fails in Linux
@@ -69,4 +70,5 @@
     if segatts is None or segatts == []:
         segatts = [0 for x in range(segments.shape[0])]
+        
     try:
         holes = ensure_numeric(holes, Float)
@@ -109,5 +111,4 @@
         segment array."""
         raise ANUGAError, msg
-
     
     #print "mode", mode
@@ -128,8 +129,9 @@
     #print "pointatts", pointatts
     #print "segatts", segatts
-    #XSprint "mode", mode
-    #print "yeah" 
+    #print "mode", mode
+    #print "yeah"
+    # .copy()
     trianglelist, pointlist, pointmarkerlist, pointattributelist, triangleattributelist, segmentlist, segmentmarkerlist, neighborlist = triang.genMesh(points,segments,holes,regions,
-                          pointatts,segatts, mode, segments.flat)
+                          pointatts,segatts, mode)
     mesh_dict = {}
     # the values as arrays
@@ -145,5 +147,5 @@
     mesh_dict['qaz'] = 1 #debugging
 
-    mesh_dict['triangleattributelist'] = triangleattributelist
+    #mesh_dict['triangleattributelist'] = triangleattributelist
     #print "mesh eng generatedtrianglelist", trianglelist
     #print "mesh eng mesh_dict['triangleattributelist'] ",mesh_dict['triangleattributelist']
@@ -157,4 +159,8 @@
         if mesh_dict['generatedpointattributelist'].shape[1] == 0:
             mesh_dict['generatedpointattributelist'] = None
+            
+        if mesh_dict['generatedtriangleneighborlist'].shape[1] == 0:
+            mesh_dict['generatedtriangleneighborlist'] = None
+            
         if trianglelist.shape[0] == 0:
             # There are no triangles.
@@ -162,5 +168,6 @@
             raise NoTrianglesError
     #print "mesh eng mesh_dict['generatedtriangleattributelist'] ", mesh_dict['generatedtriangleattributelist']  
-    
+    a = mesh_dict['generatedtriangleattributelist']
+    #print 'mesh_dict', mesh_dict
     # the structure of generatedtriangleattributelist is an list of
     # list of integers.  It is transformed into a list of list of
Index: /anuga_core/source/anuga/mesh_engine/mesh_engine_c_layer.c
===================================================================
--- /anuga_core/source/anuga/mesh_engine/mesh_engine_c_layer.c	(revision 4915)
+++ /anuga_core/source/anuga/mesh_engine/mesh_engine_c_layer.c	(revision 4916)
@@ -62,6 +62,5 @@
 //#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH 
 
-//#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
-
+#define PY_ARRAY_UNIQUE_SYMBOL API_YEAH
 //#define NO_IMPORT_ARRAY
 #include "Numeric/arrayobject.h"
@@ -117,5 +116,5 @@
   char *mod;
     
-  if(!PyArg_ParseTuple(args,(char *)"OOOOOOOO",&pointlist,&seglist,&holelist,&regionlist,&pointattributelist,&segmarkerlist,&mode,&test)){
+  if(!PyArg_ParseTuple(args,(char *)"OOOOOOO",&pointlist,&seglist,&holelist,&regionlist,&pointattributelist,&segmarkerlist,&mode)){
     return NULL;
   }
@@ -128,4 +127,5 @@
   /* Initialize and fill up region list */
   in.numberofregions = regionlist-> dimensions[0]; 
+  
   in.regionlist = (double *) regionlist -> data;
   
@@ -133,6 +133,6 @@
   in.numberofsegments = seglist -> dimensions[0]; 
   in.segmentlist = (int *) seglist -> data;
-  /* in.segmentlist = (int *) test -> data; */
   in.segmentmarkerlist = (int *) segmarkerlist -> data;
+  //in.segmentmarkerlist = (int *) NULL;
   
   /*Initialize triangles */
@@ -141,4 +141,7 @@
   in.numberoftriangleattributes = 0;  
   in.triangleattributelist  = (REAL *)NULL; 
+  in.trianglearealist  = (REAL *)NULL; 
+  in.neighborlist = (int *)NULL;
+  in.numberofcorners = 0;
      
   /*Initialize holes */
@@ -155,9 +158,9 @@
   if (0 == pointattributelist -> dimensions[0]) {
     in.numberofpointattributes = 0;
-    in.pointattributelist =  NULL;
+    in.pointattributelist =  (double *) NULL;
   } else {
     if (0 == pointattributelist -> dimensions[1]) {
     in.numberofpointattributes = 0;
-    in.pointattributelist =  NULL;
+    in.pointattributelist =  (double *) NULL;
     } else {
       in.numberofpointattributes = pointattributelist -> dimensions[1];
@@ -170,16 +173,23 @@
  
   printf ("numberofpoints %i\n", in.numberofpoints);
+  printf ("numberofpointattributes %i\n", in.numberofpointattributes);
   for(i = 0; i < in.numberofpoints; i++) {
     printf("(%f,%f)\n",in.pointlist[i* 2+ 0],in.pointlist[i* 2+ 1]);
+    for(j = 0; j < in.numberofpointattributes; j++) {
+      printf("point att (%f)\n",in.pointattributelist[i* in.numberofpointattributes + j]);
+    }
+    
   }
       
   printf ("numberofregions %i\n", in.numberofregions);
   for(i = 0; i < in.numberofregions; i++) {
-    printf("(%f,%f)\n",in.regionlist[i* 2+ 0],in.regionlist[i* 2+ 1]);
+    printf("(%f,%f)  ",in.regionlist[i* 4+ 0],in.regionlist[i* 4+ 1]);
+    printf("index %f Area %f\n",in.regionlist[i* 4+ 2],in.regionlist[i* 4+ 3]);
   }
    
   printf ("numberofsegments %i\n", in.numberofsegments);
   for(i = 0; i < in.numberofsegments; i++) {
-      printf("(%i,%i)",in.segmentlist[i* 2+ 0],in.segmentlist[i* 2+ 1]);
+      printf("(%i,%i)\n",in.segmentlist[i* 2+ 0],in.segmentlist[i* 2+ 1]);
+      printf("Segment marker (%i)\n",in.segmentmarkerlist[i + 0]);
       }
  
@@ -194,6 +204,6 @@
       printf("(%i,%i,%i)",in.trianglelist[i* 3+ 0],in.trianglelist[i* 3+ 1], in.trianglelist[i* 3+ 2]);
       } 
-  printf(" ***  see ya world\n" );       */
-      
+  printf(" ***  see ya world\n" );       
+      */
   /* set up the switch arguments to the triangulation routine */
   mod = PyString_AS_STRING(mode);
@@ -202,5 +212,5 @@
   out.pointlist = (REAL *)NULL;
   out.pointmarkerlist = (int *)NULL;
-  out.numberofpointattributes = in.numberofpointattributes;
+  //out.numberofpointattributes = in.numberofpointattributes;
   out.pointattributelist = (REAL *)NULL;
   
@@ -220,10 +230,8 @@
     
   
-  /*printf("\n\nTriangulate input args: %s \n\n", mod); */
   triangulate(mod, &in, &out, (struct triangulateio *)NULL );
   
   
- 
-  /* printf(" ***  back from triangulate\n" );    */
+    
   /*
     ------- Pass point numbers,coordinates and neighbors back to Python ------
@@ -250,57 +258,39 @@
   dimensions[0] = out.numberoftriangles;
   dimensions[1] = 3;   
-  gentrianglelist = (PyArrayObject *) PyArray_FromDims(2, 
-  						       dimensions, 
-  						       PyArray_INT);
-  gentrianglelist -> data = out.trianglelist;
-  
-  /*gentrianglelist = PyArray_ContiguousFromObject(out.trianglelist, 
-						 PyArray_DOUBLE, 
-						 0, 
-  */						   
-  
-  /*gentrianglelist = PyArray_FromDimsAndData(2,
+  gentrianglelist = (PyArrayObject *) PyArray_FromDimsAndData(2,
 					    dimensions,
 					    PyArray_INT, 
-  					    (int*) out.trianglelist);    
-  */  
+  					    (char*) out.trianglelist); 
+    
   /* Add pointlist */
   dimensions[0] = out.numberofpoints;
   dimensions[1] = 2;   
-  
-  /*genpointlist = (PyArrayObject *) PyArray_FromDims(2, 
-						    dimensions, 
-						    PyArray_DOUBLE);
-  */
+  genpointlist = (PyArrayObject *) PyArray_FromDimsAndData(2,
+					 dimensions,
+					 PyArray_DOUBLE, 
+					 (char*) out.pointlist);
+					   
   /*						 
   (double*) genpointlist -> data = out.pointlist;		 
   ((double*) genpointlist -> data) = out.pointlist;
   ( genpointlist -> data) = (double*) out.pointlist;
+   genpointlist -> data = (double) out.pointlist;
   
   */
-  //genpointlist -> data = out.pointlist;
-  
-  
-  genpointlist = PyArray_FromDimsAndData(2,
-					 dimensions,
-					 PyArray_DOUBLE, 
-					 (char*) out.pointlist);  
-  
-  
   
   /* Add point marker list */
   dimensions[0] = out.numberofpoints;
-  genpointmarkerlist = (PyArrayObject *) PyArray_FromDims(1, 
-							  dimensions, 
-							  PyArray_INT);
-  genpointmarkerlist -> data = out.pointmarkerlist;
+  genpointmarkerlist = (PyArrayObject *) PyArray_FromDimsAndData(1, 
+				  	 dimensions, 
+				         PyArray_INT,
+				        (char*) out.pointmarkerlist);
   
   /* Add point attribute list */
   dimensions[0] = out.numberofpoints;
   dimensions[1] = out.numberofpointattributes;   
-  genpointattributelist = (PyArrayObject *) PyArray_FromDims(2, 
-						 dimensions, 
-						 PyArray_DOUBLE);
-  genpointattributelist -> data = out.pointattributelist;	
+  genpointattributelist = (PyArrayObject *) PyArray_FromDimsAndData(2, 
+					  dimensions, 
+					  PyArray_DOUBLE,
+					  (char*) out.pointattributelist);
   
   
@@ -309,33 +299,40 @@
   dimensions[0] = out.numberoftriangles;
   dimensions[1] = out.numberoftriangleattributes;   
-  gentriangleattributelist = (PyArrayObject *) PyArray_FromDims(2, 
-						 dimensions, 
-						 PyArray_DOUBLE);
-  gentriangleattributelist -> data = out.triangleattributelist;
+  gentriangleattributelist = (PyArrayObject *) PyArray_FromDimsAndData(2, 
+					   dimensions, 
+					   PyArray_DOUBLE,
+					  (char*)out.triangleattributelist);
   
   /* Add segment list */
   dimensions[0] = out.numberofsegments;
   dimensions[1] = 2;   
-  gensegmentlist = (PyArrayObject *) PyArray_FromDims(2, 
+  gensegmentlist = (PyArrayObject *) PyArray_FromDimsAndData(2, 
 						    dimensions, 
-						    PyArray_INT);
-  gensegmentlist -> data = out.segmentlist;
+						    PyArray_INT,
+						    (char*)out.segmentlist);
   
   
   /* Add segment marker list */
   dimensions[0] = out.numberofsegments;
-  gensegmentmarkerlist = (PyArrayObject *) PyArray_FromDims(1, 
-						    dimensions, 
-						    PyArray_INT);
-  gensegmentmarkerlist -> data = out.segmentmarkerlist;
+  gensegmentmarkerlist = (PyArrayObject *) PyArray_FromDimsAndData(1, 
+					    dimensions, 
+					    PyArray_INT,
+					   (char*)out.segmentmarkerlist);
   
   /* Add triangle neighbor list */
-  dimensions[0] = out.numberoftriangles;
-  dimensions[1] = 3;   
-  genneighborlist = (PyArrayObject *) PyArray_FromDims(2, 
-						    dimensions, 
-						    PyArray_INT);
-  genneighborlist -> data = out.neighborlist;
-  
+  if (out.neighborlist != NULL) {
+    dimensions[0] = out.numberoftriangles;
+    dimensions[1] = 3;   
+    genneighborlist = (PyArrayObject *) PyArray_FromDimsAndData(2, 
+					 	 dimensions, 
+					      	 PyArray_INT,
+					       	 (char*)out.neighborlist);
+  }else{ 
+    dimensions[0] = 0;
+    dimensions[1] = 0;   
+    genneighborlist = (PyArrayObject *) PyArray_FromDims(2, 
+							 dimensions, 
+							 PyArray_INT);
+  }
   
   /* Add triangle neighbor list */
@@ -356,48 +353,4 @@
    */
   
-  
-  /* Free in/out structure memory */
-  
-  /* OUT */
-
-  if(!out.pointlist){
-    free(out.pointlist);  out.pointlist=NULL;
-  }
-  if(!out.pointmarkerlist){    
-    free(out.pointmarkerlist); out.pointmarkerlist=NULL;
-  }
-  if(!out.pointattributelist){    
-    free(out.pointattributelist); out.pointattributelist=NULL;
-  }   
-  if(!out.trianglelist){    
-    free(out.trianglelist); out.trianglelist=NULL;
-  }
-  if(!out.triangleattributelist){    
-    free(out.triangleattributelist); out.triangleattributelist=NULL;
-  }
-  if(!out.trianglearealist){    
-    free(out.trianglearealist); out.trianglearealist=NULL;
-  }
-  if(!out.neighborlist){    
-    free(out.neighborlist); out.neighborlist=NULL;
-  }
-  if(!out.segmentlist){
-    free(out.segmentlist); out.segmentlist =NULL;
-  }
-  if(!out.segmentmarkerlist){
-    free(out.segmentmarkerlist); out.segmentmarkerlist  =NULL;
-  }
-  if(!out.edgelist){
-    free(out.edgelist);  out.edgelist=NULL;
-  }
-  if(!out.edgemarkerlist){
-    free(out.edgemarkerlist);  out.edgemarkerlist=NULL;
-  }
-  if(!out.holelist){
-    free(out.holelist); out.holelist=NULL;
-  }
-  if(!out.regionlist){
-    free(out.regionlist); out.regionlist=NULL;
-  }
   
   /* R = Py_BuildValue((char *)"O", holder); */
@@ -421,4 +374,52 @@
   Py_DECREF(gensegmentmarkerlist);
   Py_DECREF(genneighborlist);
+  
+  
+  /* Free in/out structure memory */
+  /* OUT 
+
+  if(!out.pointlist){
+    free(out.pointlist);  out.pointlist=NULL;
+  }
+  if(!out.pointmarkerlist){    
+    free(out.pointmarkerlist); out.pointmarkerlist=NULL;
+  }
+  if(!out.pointattributelist){    
+    free(out.pointattributelist); out.pointattributelist=NULL;
+  }   
+  if(!in.pointattributelist){    
+    free(out.pointattributelist); out.pointattributelist=NULL;
+  }   
+  if(!out.trianglelist){    
+    free(out.trianglelist); out.trianglelist=NULL;
+  }
+  if(!out.triangleattributelist){    
+    free(out.triangleattributelist); out.triangleattributelist=NULL;
+  }
+  if(!out.trianglearealist){    
+    free(out.trianglearealist); out.trianglearealist=NULL;
+  }
+  if(!out.neighborlist){    
+    free(out.neighborlist); out.neighborlist=NULL;
+  }
+  if(!out.segmentlist){
+    free(out.segmentlist); out.segmentlist =NULL;
+  }
+  if(!out.segmentmarkerlist){
+    free(out.segmentmarkerlist); out.segmentmarkerlist  =NULL;
+  }
+  if(!out.edgelist){
+    free(out.edgelist);  out.edgelist=NULL;
+  }
+  if(!out.edgemarkerlist){
+    free(out.edgemarkerlist);  out.edgemarkerlist=NULL;
+  }
+  if(!out.holelist){
+    free(out.holelist); out.holelist=NULL;
+  }
+  if(!out.regionlist){
+    free(out.regionlist); out.regionlist=NULL;
+  }
+    */
   return R;
 }
Index: /anuga_core/source/anuga/mesh_engine/test_generate_mesh.py
===================================================================
--- /anuga_core/source/anuga/mesh_engine/test_generate_mesh.py	(revision 4915)
+++ /anuga_core/source/anuga/mesh_engine/test_generate_mesh.py	(revision 4916)
@@ -355,5 +355,4 @@
 
     def testrectangle_regionsII(self):
-
         points = []
         seglist = []
@@ -703,6 +702,7 @@
 
     suite = unittest.makeSuite(triangTestCase,'test')
-    #suite = unittest.makeSuite(triangTestCase,'test_lone_verts4')
-    #suite = unittest.makeSuite(triangTestCase,'test_transition_to_arrays')
-    runner = unittest.TextTestRunner() #verbosity=2)
+    #suite = unittest.makeSuite(triangTestCase,'testrectangleIIb')
+    #suite = unittest.makeSuite(triangTestCase,'testsegmarker')
+    #suite = unittest.makeSuite(triangTestCase,'testrectangle_regionsII')
+    runner = unittest.TextTestRunner()  #verbosity=2)
     runner.run(suite)
