Index: /inundation/ga/storm_surge/pyvolution/least_squares.py
===================================================================
--- /inundation/ga/storm_surge/pyvolution/least_squares.py	(revision 1002)
+++ /inundation/ga/storm_surge/pyvolution/least_squares.py	(revision 1003)
@@ -31,7 +31,8 @@
 
 from general_mesh import General_mesh
-from mesh import Mesh
-
-from Numeric import zeros, take, array, Float, Int, dot, transpose, concatenate
+from Numeric import zeros, array, Float, Int, dot, transpose, concatenate, ArrayType
+#from mesh import Mesh
+
+from Numeric import zeros, take, array, Float, Int, dot, transpose, concatenate, ArrayType
 from sparse import Sparse, Sparse_CSR
 from cg_solve import conjugate_gradient, VectorShapeError
@@ -81,5 +82,5 @@
     
     from load_mesh.loadASCII import mesh_file_to_mesh_dictionary, \
-                 load_points_file, export_triangulation_file, \
+                 load_points_file, export_mesh_file, \
                  concatinate_attributelist
     
@@ -89,7 +90,14 @@
     vertex_coordinates = mesh_dict['vertices']
     triangles = mesh_dict['triangles']
-    
-    old_point_attributes = mesh_dict['vertex_attributes'] 
-    old_title_list = mesh_dict['vertex_attribute_titles']
+    if type(mesh_dict['vertex_attributes']) == ArrayType: 
+        old_point_attributes = mesh_dict['vertex_attributes'].tolist()
+    else:
+        old_point_attributes = mesh_dict['vertex_attributes'] 
+        
+    if type(mesh_dict['vertex_attribute_titles']) == ArrayType:
+        old_title_list = mesh_dict['vertex_attribute_titles'].tolist()
+    else: 
+        old_title_list = mesh_dict['vertex_attribute_titles']
+        
     if verbose:print "tsh file loaded"
    
@@ -103,6 +111,4 @@
     title_list,point_attributes = concatinate_attributelist(point_dict['attributelist'])  
     if verbose: print "points file loaded"
-
-    
     if verbose:print "fitting to mesh"
     f = fit_to_mesh(vertex_coordinates,
@@ -134,5 +140,5 @@
 
     #FIXME (Ole): Remember to output mesh_origin as well    
-    export_triangulation_file(mesh_output_file, mesh_dict)
+    export_mesh_file(mesh_output_file, mesh_dict)
         
 
Index: /inundation/ga/storm_surge/pyvolution/test_least_squares.py
===================================================================
--- /inundation/ga/storm_surge/pyvolution/test_least_squares.py	(revision 1002)
+++ /inundation/ga/storm_surge/pyvolution/test_least_squares.py	(revision 1003)
@@ -1053,9 +1053,7 @@
 
 
-
-
     def test_fit_to_mesh_file(self):
         from load_mesh.loadASCII import mesh_file_to_mesh_dictionary, \
-             export_triangulation_file    
+             export_mesh_file    
         import tempfile
         import os
@@ -1076,5 +1074,5 @@
                                                   'external']       
         mesh_file = tempfile.mktemp(".tsh")
-        export_triangulation_file(mesh_file,mesh_dic)
+        export_mesh_file(mesh_file,mesh_dic)
         
         # create an .xya file
@@ -1108,5 +1106,5 @@
     def test_fit_to_mesh_fileII(self):
         from load_mesh.loadASCII import mesh_file_to_mesh_dictionary, \
-             export_triangulation_file    
+             export_mesh_file    
         import tempfile
         import os
@@ -1127,5 +1125,5 @@
                                                   'external']       
         mesh_file = tempfile.mktemp(".tsh")
-        export_triangulation_file(mesh_file,mesh_dic)
+        export_mesh_file(mesh_file,mesh_dic)
         
         # create an .xya file
@@ -1157,9 +1155,60 @@
         os.remove(point_file)
         
+    def test_fit_to_msh_netcdf_fileII(self):
+        from load_mesh.loadASCII import mesh_file_to_mesh_dictionary,export_mesh_file    
+        import tempfile
+        import os
+        
+        # create a .tsh file, no user outline
+        mesh_dic = {}
+        mesh_dic['vertices'] = [[0.0, 0.0],
+                                          [0.0, 5.0],
+                                          [5.0, 0.0]]
+        mesh_dic['triangles'] =  [[0, 2, 1]]
+        mesh_dic['segments'] = [[0, 1], [2, 0], [1, 2]]
+        mesh_dic['triangle_tags'] = [['']]
+        mesh_dic['vertex_attributes'] = [[1,2], [1,2], [1,2]]
+        mesh_dic['vertex_attribute_titles'] = ['density', 'temp']
+        mesh_dic['triangle_neighbors'] = [[-1, -1, -1]]
+        mesh_dic['segment_tags'] = ['external',
+                                                  'external',
+                                                  'external']       
+        mesh_file = tempfile.mktemp(".msh")
+        export_mesh_file(mesh_file,mesh_dic)
+        
+        # create an .xya file
+        point_file = tempfile.mktemp(".xya")
+        fd = open(point_file,'w')
+        fd.write("elevation, stage \n 1.0, 1.0,2.,4 \n 1.0, 3.0,4,8 \n 3.0,1.0,4.,8 \n")
+        fd.close()
+        
+        mesh_output_file = "new_triangle.msh"
+        fit_to_mesh_file(mesh_file,
+                         point_file,
+                         mesh_output_file,
+                         alpha = 0.0)  
+        # load in the .tsh file we just wrote
+        mesh_dic = mesh_file_to_mesh_dictionary(mesh_output_file)
+
+        assert allclose(mesh_dic['vertex_attributes'],
+                        [[1.0, 2.0,0.0, 0.0],
+                         [1.0, 2.0,5.0, 10.0],
+                         [1.0, 2.0,5.0,10.0]])
+        
+        self.failUnless(mesh_dic['vertex_attribute_titles']  ==
+                        ['density', 'temp','elevation','stage'],
+                        'test_fit_to_mesh_file failed')
+        
+        #clean up
+        os.remove(mesh_file)
+        os.remove(mesh_output_file)        
+        os.remove(point_file)
+        
 #-------------------------------------------------------------
 if __name__ == "__main__":
     suite = unittest.makeSuite(TestCase,'test')
 
-    #suite = unittest.makeSuite(TestCase,'test_arbitrary_datapoints')
+    #suite = unittest.makeSuite(TestCase,'test_fit_to_msh_netcdf_fileII')
+    #suite = unittest.makeSuite(TestCase,'test_fit_to_mesh_fileII')
     runner = unittest.TextTestRunner(verbosity=1)
     runner.run(suite)
