Index: /inundation/ga/storm_surge/pmesh/load_mesh/loadASCII.py
===================================================================
--- /inundation/ga/storm_surge/pmesh/load_mesh/loadASCII.py	(revision 1400)
+++ /inundation/ga/storm_surge/pmesh/load_mesh/loadASCII.py	(revision 1401)
@@ -1350,5 +1350,5 @@
     for i,vert in enumerate( points):
         
-        attlist = ""
+        attlist = ","
         for att in pointattributes.keys():
             attlist = attlist + str(pointattributes[att][i])+ delimiter
@@ -1356,5 +1356,5 @@
         attlist.strip()
         fd.write( str(vert[0]) + delimiter
-                  + str(vert[1]) + delimiter 
+                  + str(vert[1])
                   + attlist + "\n")
     fd.close()
Index: /inundation/ga/storm_surge/pmesh/mesh.py
===================================================================
--- /inundation/ga/storm_surge/pmesh/mesh.py	(revision 1400)
+++ /inundation/ga/storm_surge/pmesh/mesh.py	(revision 1401)
@@ -545,5 +545,7 @@
         for element in dic_mesh.keys():
             dic[element] = dic_mesh[element]
-        
+        for element in dic.keys():
+            dic[element].sort()
+            
         # A dic for the exported/imported m
         dic_other = other.Mesh2triangList()
@@ -551,4 +553,6 @@
         for element in dic_mesh.keys():
             dic_other[element] = dic_mesh[element]
+        for element in dic.keys():
+            dic_other[element].sort()
 
         #print "dsg************************8"
@@ -569,5 +573,5 @@
         PreCondition: maxArea is a double
         """
-        print "mode ",mode
+        #print "mode ",mode
         if mode == None:
             self.mode = ""
@@ -736,4 +740,7 @@
         Precondition: Each vertex has a dupindex, which is the list
         index.
+
+        Note: this removes vertices that have the same x,y values,
+        not duplicate instances in the Vertices list.
         """
         remove = []
@@ -1312,5 +1319,5 @@
                                  expand_pinch=expand_pinch)
         boundary_segs = self.shape.get_boundary()
-        print "boundary_segs",boundary_segs
+        #print "boundary_segs",boundary_segs
         segs2delete = self.alphaUserSegments
 
@@ -1622,57 +1629,5 @@
             #Most probably, the Tkinter module is not available.
             #"""
-     # FIXME let's not use this function,
-     # use export _mesh_file instead
-    def export_triangulation_file(self,ofile):
-        """
-        export a file, ofile, with the format
-        
-        First line:  <# of vertices> <# of attributes>
-        Following lines:  <vertex #> <x> <y> [attributes]
-        One line:  <vertex attribute titles> 
-        One line:  <# of triangles> 
-        Following lines:  <triangle #> <vertex #>  <vertex #> <vertex #> <neigbouring triangle #> <neigbouring triangle #> <neigbouring triangle #> [attribute of region]
-        One line:  <# of segments> 
-        Following lines:  <segment #> <vertex #>  <vertex #> [boundary tag]
-        """
-        gen_dict = self.Mesh2IODict()
-        if (ofile[-4:] == ".tsh"):
-            fd = open(ofile,'w')
-            load_mesh.loadASCII.write_ASCII_triangulation(fd,gen_dict)
-            self.writeASCIImesh(fd,
-                                self.userVertices,
-                                self.getUserSegments(),
-                                self.holes,
-                                self.regions)    
-            fd.close()
-        elif (ofile[-4:] == ".msh"):
-            #print "mesh gen_dict",gen_dict 
-            load_mesh.loadASCII.write_msh_file(ofile, gen_dict)
             
-# self.writeASCIImesh(fd, does anything use this?
-
-    #FIXME this function has a bug..        
-    def exportASCIIsegmentoutlinefile(self,ofile):
-        """
-        export a file, ofile, with no triangulation and only vertices connected to segments.
-        """
-        fd = open(ofile,'w')
-        meshDict = {}
-        
-        meshDict['vertices'] = []
-        meshDict['vertex_attributes'] = []
-        meshDict['segments'] = []
-        meshDict['segment_tags'] = []
-        meshDict['triangles'] = [] 
-        meshDict['triangle_tags'] = []
-        meshDict['triangle_neighbors'] = []
-        
-        load_mesh.loadASCII.write_ASCII_triangulation(fd,meshDict)
-        self.writeASCIIsegmentoutline(fd,
-                            self.userVertices,
-                            self.getUserSegments(),
-                            self.holes,
-                            self.regions)    
-        fd.close()
 
     def exportASCIIobj(self,ofile):
@@ -1706,28 +1661,18 @@
                      + str(tri.vertices[1].index1) + " " 
                      + str(tri.vertices[2].index1) + "\n")
-
-    #FIXME I think this has a bug...            
-    def writeASCIIsegmentoutline(self,
-                       fd,
-                       userVertices,
-                       userSegments,
-                       holes,
-                       regions):
-        """Write the user mesh info, only with vertices that are connected to segs
-        """
-        verts = []
-        #dupindex = 0
-        for seg in self.userSegments:
-            verts.append(seg.vertices[0])
-            verts.append(seg.vertices[1])
-        print 'verts>',verts
-
-        verts, count = self.removeDuplicatedVertices(verts)
-        print 'verts no dups>',verts
-        self.writeASCIImesh(fd,
-                            verts,
-                            self.getUserSegments(),
-                            self.holes,
-                            self.regions)
+           
+    def exportASCIIsegmentoutlinefile(self,ofile):
+        """Write the boundary user mesh info, eg
+         vertices that are connected to segments,
+         segments
+        """
+        
+        verts = {}
+        for seg in self.getUserSegments():
+            verts[seg.vertices[0]] = seg.vertices[0]
+            verts[seg.vertices[1]] = seg.vertices[1]
+        #print "verts.values()",verts.values() 
+        meshDict = self.Mesh2IOOutlineDict(userVertices=verts.values())
+        load_mesh.loadASCII.export_mesh_file(ofile,meshDict)
         
         # exportASCIImeshfile   - this function is used
@@ -1740,53 +1685,21 @@
         load_mesh.loadASCII.export_mesh_file(ofile,dict)
 
-    # is this function obsolete? 
-    def writeASCIImesh(self,
-                       fd,
-                       userVertices,
-                       userSegments,
-                       holes,
-                       regions):
-        
-        #print "mesh.writeASCIImesh*********"
-        #print "dict",dict 
-        #print "mesh*********"
-        load_mesh.loadASCII.write_ASCII_outline(fd, dict)
-
-                #FIXME the title is wrong, need more comments
-    def exportxyafile(self,ofile):
-        """
-        export a file, ofile, with the format
-        
-        First line:  <# of vertices> <# of attributes>
-        Following lines:  <vertex #> <x> <y> [attributes]
-        """
-        #load_mesh.loadASCII
-        #FIXME, this should be a mesh2io method
-        if self.meshVertices == []:
-            Vertices = self.userVertices
+    def exportPointsFile(self,ofile):
+        """
+        export a points (.xya or .pts)  file, ofile.
+        
+        """
+        
+        mesh_dict = self.Mesh2IODict()
+        point_dict = {}
+        point_dict['attributelist'] = {} #this will need to be expanded..
+                                         # if attributes are brought back in. 
+        point_dict['geo_reference'] = self.geo_reference
+        if mesh_dict['vertices'] == []:
+            point_dict['pointlist'] = mesh_dict['points']
         else:
-            Vertices = self.meshVertices
-            
-        numVert = str(len(Vertices))
-        
-        if Vertices == []:
-            raise RuntimeError
-        numVertAttrib = str(len(Vertices[0].attributes))
-        #title = numVert + " " + numVertAttrib + " # <vertex #> <x> <y> [attributes]"
-
-        #Convert the Vertices to pointlist and pointattributelist
-        xya_dict = {}
-        pointattributes = []
-        points = []
-        
-        for vert in Vertices:
-            points.append([vert.x,vert.y])
-            pointattributes.append(vert.attributes)
-            
-        xya_dict['pointlist'] = points
-        xya_dict['pointattributelist'] = pointattributes
-        xya_dict['geo_reference'] = self.geo_reference
-
-        load_mesh.loadASCII.export_points_file(ofile, xya_dict)
+            point_dict['pointlist'] = mesh_dict['vertices']
+
+        load_mesh.loadASCII.export_points_file(ofile,point_dict)
 
         
@@ -1844,5 +1757,4 @@
         vertices=[]
         vertex_attributes=[]
-
 
         self.maxVertexIndex=0
@@ -1963,5 +1875,4 @@
         #print "*(*("
         return meshDict
-          
 
     def IOTriangulation2Mesh(self, genDict):
@@ -2010,8 +1921,4 @@
                 self.meshTriangles[index].setAttribute("")
             else:
-                # Note, is the first attribute always the region att?
-                # haven't confirmed this
-		#Peter - I think so (from manuel)
- 		#...the first such value is assumed to be a regional attribute...
                 self.meshTriangles[index].setAttribute(att)
             index += 1
Index: /inundation/ga/storm_surge/pmesh/pmesh.py
===================================================================
--- /inundation/ga/storm_surge/pmesh/pmesh.py	(revision 1400)
+++ /inundation/ga/storm_surge/pmesh/pmesh.py	(revision 1401)
@@ -111,14 +111,14 @@
                                  label='Export ASCII obj',
                                  command=self.exportObj)
-        # FIXME, add this function back into pmesh
-        #self.menuBar.addmenuitem('File', 'command',
-         #                        'Export ASCII segment outline',
-          #                       label='Export ASCII segment outline...',
-           #                      command=self.exportASCIIsegmentoutlinefile)
+        
+        self.menuBar.addmenuitem('File', 'command',
+                                 'Export ASCII segment outline',
+                                 label='Export ASCII segment outline...',
+                                 command=self.exportASCIIsegmentoutlinefile)
         
         self.menuBar.addmenuitem('File', 'command',
                                  'Export ASCII xya file',
                                  label='Export ASCII xya file...',
-                                 command=self.exportxyafile)
+                                 command=self.exportPointsFile)
         
         self.menuBar.addmenuitem('File', 'command',
@@ -1244,106 +1244,39 @@
         
     def exportASCIIsegmentoutlinefile(self):
-        fileType = "tsh"
-        fileTypeDesc = "text mesh"
         
         ofile = tkFileDialog.asksaveasfilename(initialdir=self.currentPath,
-                                         filetypes=[(fileTypeDesc, fileType),
-                                                          ("All Files", "*")])
+                                               filetypes=[("mesh", "*.tsh *.msh"),
+                                             ("All Files", "*")])
+           
         if ofile:
-            addOn = "." + fileType
-            jumpback = - len(addOn)
-            if ofile[jumpback:] != addOn:  
-                ofile = ofile + addOn
+            # .tsh is the default file format
+            if (ofile[-4:] == ".tsh" or ofile[-4:] == ".msh"):  
+                self.currentFilePathName = ofile
+            else:
+                self.currentFilePathName = ofile + ".tsh"
+                
             try:
                 self.mesh.exportASCIIsegmentoutlinefile(ofile)
+            except IOError: #FIXME should this function be throwing any errors?
+                showerror('Export ASCII file',
+                                   'Can not write to file.')
+
+    def exportPointsFile(self):
+        ofile = tkFileDialog.asksaveasfilename(initialdir=self.currentPath,
+                                         filetypes=[("point files",
+                                                     "*.xya *.pts"),
+                                                ("All Files", "*")])
+        if ofile:
+            # .xya is the default file format
+            if (ofile[-4:] == ".xya" or ofile[-4:] == ".pts"):  
+                self.currentFilePathName = ofile
+            else:
+                self.currentFilePathName = ofile + ".xya"
+                
+            try:
+                self.mesh.exportPointsFile(ofile)
             except IOError:
                 showerror('Export ASCII file',
                                    'Can not write to file.')
-
-    def exportxyafile(self):
-        fileType = "xya"
-        fileTypeDesc = "text vertices"
-        
-        ofile = tkFileDialog.asksaveasfilename(initialdir=self.currentPath,
-                                         filetypes=[(fileTypeDesc, fileType),
-                                                ("All Files", "*")])
-        if ofile:
-            addOn = "." + fileType
-            jumpback = - len(addOn)
-            if ofile[jumpback:] != addOn:  
-                ofile = ofile + addOn
-            try:
-                self.mesh.exportxyafile(ofile)
-            except IOError:
-                showerror('Export ASCII file',
-                                   'Can not write to file.')
-                                
-    def exportTriangulation(self):
-        """
-        This function is not used?
-        """
-        fileType = "tsh"
-        fileTypeDesc = "text mesh"
-        
-        ofile = tkFileDialog.asksaveasfilename(initialdir=self.currentPath,
-                                         filetypes=[(fileTypeDesc, fileType),
-                                                ("All Files", "*")])
-        if ofile:
-            addOn = "." + fileType
-            jumpback = - len(addOn)
-            if ofile[jumpback:] != addOn:  
-                ofile = ofile + addOn
-            try:
-                # FIXME - check that this is what we want
-                self.mesh.export_triangulation_file(ofile)
-            except IOError:
-                showerror('Export ASCII file',
-                                   'Can not write to file.')
-            except RuntimeError:
-                showerror('Export ASCII file',
-                                   'No triangulation to export.')
-                
-    
-    def export_tsh(self):
-        fileType = "tsh"
-        fileTypeDesc = "text Mesh"
-        
-        ofile = tkFileDialog.asksaveasfilename(initialdir=self.currentPath,
-                                         filetypes=[(fileTypeDesc, fileType),
-                                                ("All Files", "*")])
-        if ofile:
-            addOn = "." + fileType
-            jumpback = - len(addOn)
-            if ofile[jumpback:] != addOn:  
-                ofile = ofile + addOn
-            try:
-                self.mesh.exportASCIImeshfile(ofile)
-            except IOError:
-                showerror('Export ASCII file',
-                                   'Can not write to file.')
-            except RuntimeError:
-                showerror('Export ASCII file',
-                                   'No mesh to export.')
-    
-    def exportMesh(self):
-        fileType = "tsh"
-        fileTypeDesc = "text Mesh"
-        
-        ofile = tkFileDialog.asksaveasfilename(initialdir=self.currentPath,
-                                         filetypes=[(fileTypeDesc, fileType),
-                                                ("All Files", "*")])
-        if ofile:
-            addOn = "." + fileType
-            jumpback = - len(addOn)
-            if ofile[jumpback:] != addOn:  
-                ofile = ofile + addOn
-            try:
-                self.mesh.exportASCIImeshfile(ofile)
-            except IOError:
-                showerror('Export ASCII file',
-                                   'Can not write to file.')
-            except RuntimeError:
-                showerror('Export ASCII file',
-                                   'No mesh to export.')
                     
     def importFile(self):
Index: /inundation/ga/storm_surge/pmesh/test_mesh.py
===================================================================
--- /inundation/ga/storm_surge/pmesh/test_mesh.py	(revision 1400)
+++ /inundation/ga/storm_surge/pmesh/test_mesh.py	(revision 1401)
@@ -237,5 +237,5 @@
                         'Segment should not be new. ')
         
-    def ztestautoSegment(self):
+    def testautoSegment(self):
         p0 = Vertex (0.0, 0.0)
         p1 = Vertex (0.0, 4.0)
@@ -256,5 +256,5 @@
                         'userSegments is wrong!')
      
-    def ztestautoSegmentII(self):
+    def testautoSegmentII(self):
         p1 = Vertex (3.0, 4.0)
         p2 = Vertex (3.0,2.0)
@@ -781,6 +781,6 @@
         self.failUnless(xmin == -100.0 and ymin == -100.0 and xmax == 0.0 and ymax == 100.0,
                         'normalise failed')
-    # Fix me, this function has a bug    
-    def zztest_exportASCIIsegmentoutlinefile(self):
+        
+    def test_exportASCIIsegmentoutlinefile(self):
         a = Vertex (0,0)
         b = Vertex (0,3)
@@ -817,4 +817,43 @@
         m.meshSegments = []
         m.userVertices=[a,b,c]
+        #print "mesh ***************dsg*", m
+        #print "(m.__cmp__(m_returned)", m.__cmp__(m_returned) 
+        self.failUnless(0 == m.__cmp__(m),
+                        'test_exportASCIIsegmentoutlinefile:loading and saving of a mesh failed')
+        self.failUnless(0 == m.__cmp__(m_returned),
+                        'test_exportASCIIsegmentoutlinefile:loading and saving of a mesh failed')
+ 
+    def test_exportASCIIsegmentoutlinefile2(self):
+        a = Vertex (0,0)
+        b = Vertex (0,1)
+        c = Vertex (1,0)
+        d = Vertex (1,1)
+        e = Vertex (0.5,0.5)
+        f  = Vertex (0.6,0.6)
+      
+        s1 = Segment(a,e, tag = "50")
+        s2 = Segment(b,e, tag = "40")
+        s3 = Segment(c,e, tag = "30")
+        s4 = Segment(d,e, tag = "30")
+     
+        r1 = Region(2, 1,tag = "1.3")
+        h1 = Hole(1,4)
+        m = Mesh(userVertices=[a,b,c,d,e],
+                 userSegments=[s1,s2,s3,s4],
+                 regions=[r1],
+                 holes = [h1])      
+        
+        fileName = tempfile.mktemp(".tsh")
+        m.exportASCIIsegmentoutlinefile(fileName)
+        
+        m_returned = importMeshFromFile(fileName)
+        #print "****************** fileName", fileName
+        os.remove(fileName)
+
+        #Trim mesh, so it should like like m_returned
+        m.meshVertices = []
+        m.meshTriangles = []
+        m.meshSegments = []
+        m.userVertices=[a,e,d,b,c]
         #print "mesh ***************dsg*", m
         #print "(m.__cmp__(m_returned)", m.__cmp__(m_returned) 
@@ -874,5 +913,5 @@
         #                'loadxy, test 5 failed')
         
-    def test_exportxyafile(self):
+    def test_exportPointsFile(self):
         a = Vertex (0,0)
         b = Vertex (0,3)
@@ -895,37 +934,50 @@
         
         fileName = tempfile.mktemp(".xya")
-        m.exportxyafile(fileName)
+        m.exportPointsFile(fileName)
         file = open(fileName)
         lFile = file.read().split('\n')
         file.close()
 
-        #print "**********************"
-        #print lFile
-        #print "**********************"
-        
         os.remove(fileName)
-        self.failUnless(lFile[0] == "5 0 # <vertex #> <x> <y> [attributes]" and
-                        lFile[1] == "0 0 " and
-                        lFile[2] == "0 3 " and
-                        lFile[3] == "3 3 " and
-                        lFile[4] == "1 2 " and
-                        lFile[5] == "3 1 " 
+        self.failUnless(lFile[0] == "" and
+                        lFile[1] == "0,0" and
+                        lFile[2] == "0,3" and
+                        lFile[3] == "3,3" and
+                        lFile[4] == "1,2" and
+                        lFile[5] == "3,1" 
                         ,
                         'exported Ascii xya file is wrong')
        
         m.generateMesh("QApz", maxArea = 2.1)
-        fileName = tempfile.mktemp(".txt")
-        m.exportxyafile(fileName)
+        fileName = tempfile.mktemp(".xya")
+        m.exportPointsFile(fileName)
         file = open(fileName)
         lFile = file.read().split('\n')
         file.close()
         os.remove(fileName)
-        self.failUnless(lFile[0] == "6 0 # <vertex #> <x> <y> [attributes]" and
-                        lFile[1] == "0.0 0.0 " and
-                        lFile[2] == "0.0 3.0 " and
-                        lFile[3] == "3.0 3.0 " and
-                        lFile[4] == "1.0 2.0 " and
-                        lFile[5] == "3.0 1.0 " and
-                        lFile[6] == "1.5 1.5 "  
+        self.failUnless(lFile[0] == "" and
+                        lFile[1] == "0.0,0.0" and
+                        lFile[2] == "0.0,3.0" and
+                        lFile[3] == "3.0,3.0" and
+                        lFile[4] == "1.0,2.0" and
+                        lFile[5] == "3.0,1.0" and
+                        lFile[6] == "1.5,1.5"  
+                        ,
+                        'exported Ascii xya file is wrong')
+           
+    def test_exportPointsFilefile2(self):
+        m = Mesh()
+        
+        fileName = tempfile.mktemp(".xya")
+        m.exportPointsFile(fileName)
+        file = open(fileName)
+        lFile = file.read().split('\n')
+        file.close()
+
+        os.remove(fileName)
+        #print "************* test_mesh exportPointsFilefile"
+        #print "lFile",lFile 
+        #print "************* test_mesh exportPointsFilefile"
+        self.failUnless(lFile[0] == "" 
                         ,
                         'exported Ascii xya file is wrong')
@@ -1003,5 +1055,5 @@
         #                    'y duplicate verts not removed')
 
-
+        
     def test_ungenerateFileLoading(self):
         
