Index: /trunk/anuga_core/anuga/fit_interpolate/fitsmooth.c
===================================================================
--- /trunk/anuga_core/anuga/fit_interpolate/fitsmooth.c	(revision 9649)
+++ /trunk/anuga_core/anuga/fit_interpolate/fitsmooth.c	(revision 9650)
@@ -152,5 +152,4 @@
     int k,k6;
     double x0,y0,x1,y1,x2,y2;
-    triangle *T;
 
     // set up quad tree and allocate memory
@@ -168,5 +167,5 @@
         x2 = vertex_coordinates[k6 + 4];
         y2 = vertex_coordinates[k6 + 5];
-        T = new_triangle(k,x0,y0,x1,y1,x2,y2);
+        triangle * T = new_triangle(k,x0,y0,x1,y1,x2,y2);
         quad_tree_insert_triangle(tree,T);
     }
@@ -188,14 +187,11 @@
               {
 
+
+
     int k;
+
+
+
     int i,w;
-    edge_key_t key;
-    double x;
-    double y;
-    triangle * T;
-    double * sigma;
-    int js[3];
-
-
     for(w=0;w<zdims;w++){
         for(i=0;i<N;i++){
@@ -204,4 +200,8 @@
     }
 
+    edge_key_t key;
+
+
+
 
     #pragma omp parallel for private(k,i,key,w)
@@ -209,11 +209,11 @@
 
 
-        x = point_coordinates[2*k];
-        y = point_coordinates[2*k+1];
-        T = search(quadtree,x,y);
+        double x = point_coordinates[2*k];
+        double y = point_coordinates[2*k+1];
+        triangle * T = search(quadtree,x,y);
 
         if(T!=NULL){
-            sigma = calculate_sigma(T,x,y);
-
+            double * sigma = calculate_sigma(T,x,y);
+            int js[3];
             for(i=0;i<3;i++){
                 js[i]=triangles[3*(T->index)+i];
@@ -251,8 +251,8 @@
                              double* Atz2,
                              int n, int zdim){
+
+    add_sparse_dok(dok_AtA1,1,dok_AtA2,1);
+
     int i;
-
-    add_sparse_dok(dok_AtA1,1,dok_AtA2,1);
-
     for(i=0;i<n*zdim;i++){
         Atz1[i]+=Atz2[i];
@@ -369,5 +369,4 @@
     PyArrayObject *vertex_coordinates;
     PyArrayObject *extents;
-    int n;
 
 
@@ -387,5 +386,5 @@
     CHECK_C_CONTIG(extents);
 
-    n = triangles->dimensions[0];
+    int n = triangles->dimensions[0];
 
     #ifdef PYVERSION273
@@ -417,7 +416,5 @@
     PyArrayObject *areas;
     PyArrayObject *vertex_coordinates;
-    sparse_dok * smoothing_mat; // Should be an input argument?
     int err;
-    int n;
 
     // Convert Python arguments to C
@@ -436,6 +433,8 @@
     CHECK_C_CONTIG(vertex_coordinates);
 
-    n = triangles->dimensions[0];
-
+    int n = triangles->dimensions[0];
+
+
+    sparse_dok * smoothing_mat; // Should be an input argument?
     smoothing_mat = make_dok();
 
@@ -478,13 +477,9 @@
     PyArrayObject *point_coordinates;
     PyArrayObject *z;
-    sparse_dok * dok_AtA; // Should be an input argument?
     int N; // Number of triangles
     int err;
     int npts;
     int zdims;
-    int i;
     PyObject *tree;
-    quad_tree *quadtree;
-    double ** Atz;
 
     // Convert Python arguments to C
@@ -507,12 +502,13 @@
 
     #ifdef PYVERSION273
-    quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree");
-    #else
-    quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree);
-    #endif
-
-
+    quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree");
+    #else
+    quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree);
+    #endif
+
+    sparse_dok * dok_AtA; // Should be an input argument?
     dok_AtA = make_dok();
-    Atz = malloc(sizeof(double*)*zdims);
+    double ** Atz = malloc(sizeof(double*)*zdims);
+    int i;
     for(i=0;i<zdims;i++){
         Atz[i] = malloc(sizeof(double)*N);
@@ -566,16 +562,4 @@
     PyObject *tree;
     PyArrayObject *point;
-    quad_tree *quadtree;
-    double xp,yp;
-    int *ipointd;
-    double *pointd;
-    triangle *T;
-    PyObject *sigmalist;
-    long found;
-    long index;
-    double *sigma;
-    double ssigma[3];
-    PyObject *retlist;
-
 
     // Convert Python arguments to C
@@ -590,27 +574,28 @@
 
     #ifdef PYVERSION273
-    quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree");
-    #else
-    quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree);
-    #endif
-
-
+    quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree");
+    #else
+    quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree);
+    #endif
+
+    double xp,yp;
     if(PyArray_TYPE(point)==7){
-        ipointd = (int*)point->data;
-        xp = (double)(ipointd[0]);
-        yp = (double)(ipointd[1]);
+        int *pointd = (int*)point->data;
+        xp = (double)(pointd[0]);
+        yp = (double)(pointd[1]);
     }
     else{
-        pointd = (double*)point->data;
+        double *pointd = (double*)point->data;
         xp = pointd[0];
         yp = pointd[1];
     }
 
-    T = search(quadtree,xp,yp);
-    sigmalist = PyList_New(3);
-
+    triangle * T = search(quadtree,xp,yp);
+    PyObject * sigmalist = PyList_New(3);
+    long found;
+    long index;
     
     if(T!=NULL){
-            sigma = calculate_sigma(T,xp,yp);
+            double * sigma = calculate_sigma(T,xp,yp);
             sigmalist = c_double_array_to_list(sigma,3);
             free(sigma);
@@ -618,11 +603,11 @@
             index = (long)T->index;
     }else{
-
-            ssigma[0]=ssigma[1]=ssigma[2]=-1;
-            sigmalist = c_double_array_to_list(ssigma,3);
+            double sigma[3];
+            sigma[0]=sigma[1]=sigma[2]=-1;
+            sigmalist = c_double_array_to_list(sigma,3);
             index = -10;
             found = 0;
     }
-    retlist = PyList_New(3);
+    PyObject * retlist = PyList_New(3);
     PyList_SET_ITEM(retlist,0,PyInt_FromLong(found));
     PyList_SET_ITEM(retlist,1,sigmalist);
@@ -641,5 +626,4 @@
     // Setting up variables to parse input
     PyObject *tree; // capsule to hold quad_tree pointer
-    quad_tree *quadtree;
 
     // Convert Python arguments to C
@@ -653,7 +637,7 @@
     // Extract quad_tree pointer from capsule
     #ifdef PYVERSION273
-    quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree");
-    #else
-    quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree);
+    quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree");
+    #else
+    quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree);
     #endif
     
@@ -669,5 +653,4 @@
     // Setting up variables to parse input
     PyObject *tree; // capsule to hold quad_tree pointer
-    quad_tree *quadtree;
 
     // Convert Python arguments to C
@@ -681,7 +664,7 @@
     // Extract quad_tree pointer from capsule
     #ifdef PYVERSION273
-    quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree");
-    #else
-    quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree);
+    quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree");
+    #else
+    quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree);
     #endif
     
@@ -707,6 +690,4 @@
     PyArrayObject *Atz1, *Atz2;
     int n,zdim; // number of nodes
-    sparse_dok *dok_AtA1;
-    sparse_dok *dok_AtA2;
 
     // Convert Python arguments to C
@@ -721,9 +702,9 @@
     // Get pointers to sparse_dok objects from capsules
     #ifdef PYVERSION273
-    dok_AtA1 = (sparse_dok*) PyCapsule_GetPointer(AtA_cap1,"sparse dok");
-    dok_AtA2 = (sparse_dok*) PyCapsule_GetPointer(AtA_cap2,"sparse dok");
-    #else
-    dok_AtA1 = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap1);
-    dok_AtA2 = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap2);
+    sparse_dok * dok_AtA1 = (sparse_dok*) PyCapsule_GetPointer(AtA_cap1,"sparse dok");
+    sparse_dok * dok_AtA2 = (sparse_dok*) PyCapsule_GetPointer(AtA_cap2,"sparse dok");
+    #else
+    sparse_dok * dok_AtA1 = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap1);
+    sparse_dok * dok_AtA2 = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap2);
     #endif
 
@@ -750,9 +731,4 @@
     PyObject *D_cap; // capsule object holding sparse_dok pointer
     int n; // number of matrix columns/rows
-    sparse_dok * D_mat;
-    PyObject *ret_D;
-    int i,j;
-    edge_key_t key;
-    edge_t *s;
 
     // Convert Python arguments to C
@@ -766,7 +742,7 @@
     // Get pointer to spars_dok struct
     #ifdef PYVERSION273
-    D_mat = (sparse_dok*) PyCapsule_GetPointer(D_cap,"sparse dok");
-    #else
-    D_mat = (sparse_dok*) PyCObject_AsVoidPtr(D_cap);
+    sparse_dok * D_mat = (sparse_dok*) PyCapsule_GetPointer(D_cap,"sparse dok");
+    #else
+    sparse_dok * D_mat = (sparse_dok*) PyCObject_AsVoidPtr(D_cap);
     #endif
 
@@ -780,6 +756,8 @@
 
     // Build new python list containing the full matrix to return
-    ret_D = PyList_New(n);
-
+    PyObject *ret_D = PyList_New(n);
+    int i,j;
+    edge_key_t key;
+    edge_t *s;
     for(i=0;i<n;i++)
     {
@@ -816,11 +794,4 @@
     PyObject *smoothing_mat_cap; // Capsule storing D pointer (sparse_dok struct)
     PyObject *AtA_cap; // Capsule storing AtA pointer (sparse_dok struct)
-    sparse_dok *smoothing_mat;
-    sparse_dok *dok_AtA;
-    sparse_csr *B;
-    PyObject *data;
-    PyObject *colind;
-    PyObject *row_ptr;
-    PyObject *lst;
 
     // Convert Python arguments to C
@@ -834,9 +805,9 @@
     // Extract pointers to c structs from capsules
     #ifdef PYVERSION273
-    smoothing_mat = (sparse_dok*) PyCapsule_GetPointer(smoothing_mat_cap,"sparse dok");
-    dok_AtA = (sparse_dok*) PyCapsule_GetPointer(AtA_cap,"sparse dok");
-    #else
-    smoothing_mat = (sparse_dok*) PyCObject_AsVoidPtr(smoothing_mat_cap);
-    dok_AtA = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap);
+    sparse_dok * smoothing_mat = (sparse_dok*) PyCapsule_GetPointer(smoothing_mat_cap,"sparse dok");
+    sparse_dok * dok_AtA = (sparse_dok*) PyCapsule_GetPointer(AtA_cap,"sparse dok");
+    #else
+    sparse_dok * smoothing_mat = (sparse_dok*) PyCObject_AsVoidPtr(smoothing_mat_cap);
+    sparse_dok * dok_AtA = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap);
     #endif
 
@@ -845,17 +816,18 @@
     
     // Create sparse_csr matrix and convert result to this format
+    sparse_csr * B;
     B = make_csr();
     convert_to_csr_ptr(B,smoothing_mat);
     
     // Extract the sparse_csr data to be returned as python lists
-    data = c_double_array_to_list(B->data,
+    PyObject *data = c_double_array_to_list(B->data,
                                 B->num_entries);
-    colind = c_int_array_to_list(B->colind,
+    PyObject *colind = c_int_array_to_list(B->colind,
                                 B->num_entries);
-    row_ptr = c_int_array_to_list(B->row_ptr,
+    PyObject *row_ptr = c_int_array_to_list(B->row_ptr,
                                 B->num_rows);
 
     // Build python list for return
-    lst = PyList_New(3);
+    PyObject *lst = PyList_New(3);
     PyList_SET_ITEM(lst, 0, data);
     PyList_SET_ITEM(lst, 1, colind);
