Index: /issm/trunk-jpl/src/m/classes/mesh3dsurface.m
===================================================================
--- /issm/trunk-jpl/src/m/classes/mesh3dsurface.m	(revision 24893)
+++ /issm/trunk-jpl/src/m/classes/mesh3dsurface.m	(revision 24894)
@@ -232,18 +232,18 @@
 					
 					%increase counter: 
-					counter=counter+3;
+					counter += 3;
 				end
 			elseif strcmpi(geometry,'polygon'),
+				% TODO: Refactor the following to reduce repeated code, or 
+				%		leave as is because it is more readable?
 				if isempty(index),
-					counter=1;
 					for i=1:self.numberofelements,
 						el=self.elements(i,:);
 						contours(i).x=[self.long(el(1)) self.long(el(2)) self.long(el(3)) self.long(el(1))];
 						contours(i).y=[self.lat(el(1)) self.lat(el(2)) self.lat(el(3)) self.lat(el(1))];
+						contours(i).Id = i;
 						contours(i).Geometry = 'Polygon';
-						contours(i).Id = i;
 					end
 				else
-					counter=1;
 					for i=1:length(index),
 						el=self.elements(index(i),:);
@@ -255,5 +255,5 @@
 				end
 			else
-				error(sprintf('mesh3dsurface ''export'' error message: geometry %s not supported yet (should be ''point'' or ''line''',geometry));
+				error(sprintf('mesh3dsurface ''export'' error message: geometry %s not supported yet (should be ''point'' or ''line'' or ''polygon'')',geometry));
 			end
 
Index: /issm/trunk-jpl/src/m/classes/mesh3dsurface.py
===================================================================
--- /issm/trunk-jpl/src/m/classes/mesh3dsurface.py	(revision 24893)
+++ /issm/trunk-jpl/src/m/classes/mesh3dsurface.py	(revision 24894)
@@ -1,7 +1,8 @@
+import numpy as np
+
+from checkfield import checkfield
+from fielddisplay import fielddisplay
 from MatlabFuncs import *
 from model import *
-import numpy as np
-from fielddisplay import fielddisplay
-from checkfield import checkfield
 from WriteData import WriteData
 
@@ -12,5 +13,5 @@
     #   Usage:
     #      mesh3dsurface = mesh3dsurface();
-    def __init__(self, *args):  # {{{
+    def __init__(self, *args): # {{{
         self.x = np.nan
         self.y = np.nan
@@ -51,5 +52,5 @@
     # }}}
 
-    def __repr__(self):  # {{{
+    def __repr__(self): # {{{
         string = '   2D tria Mesh (horizontal):'
 
@@ -83,5 +84,5 @@
     # }}}
 
-    def loadobj(self):  # {{{
+    def loadobj(self): # {{{
         # This def is directly called by matlab when a model() selfect is
         # loaded. Update old properties here
@@ -101,5 +102,5 @@
     # }}}
 
-    def setdefaultparameters(self):  # {{{
+    def setdefaultparameters(self): # {{{
         #the connectivity is the averaged number of nodes linked to a
         #given node through an edge. This connectivity is used to initially
@@ -111,5 +112,5 @@
     # }}}
 
-    def checkconsistency(self, md, solution, analyses):  # {{{
+    def checkconsistency(self, md, solution, analyses): # {{{
         md = checkfield(md, 'fieldname', 'mesh.x', 'NaN', 1, 'Inf', 1, 'size', [md.mesh.numberofvertices])
         md = checkfield(md, 'fieldname', 'mesh.y', 'NaN', 1, 'Inf', 1, 'size', [md.mesh.numberofvertices])
@@ -133,5 +134,5 @@
     # }}}
 
-    def marshall(self, prefix, md, fid):  # {{{
+    def marshall(self, prefix, md, fid): # {{{
         WriteData(fid, prefix, 'name', 'md.mesh.domain_type', 'data', 'Domain' + self.domaintype(), 'format', 'String')
         WriteData(fid, prefix, 'name', 'md.mesh.domain_dimension', 'data', self.dimension(), 'format', 'Integer')
@@ -151,17 +152,17 @@
     # }}}
 
-    def domaintype(self):  # {{{
+    def domaintype(self): # {{{
         return '3Dsurface'
     # }}}
 
-    def dimension(self):  # {{{
+    def dimension(self): # {{{
         return 2
     # }}}
 
-    def elementtype(self):  # {{{
+    def elementtype(self): # {{{
         return 'Tria'
     # }}}
 
-    def processmesh(self, options):  # {{{
+    def processmesh(self, options): # {{{
         isplanet = 1
         is2d = 0
@@ -174,5 +175,5 @@
     # }}}
 
-    def savemodeljs(self, fid, modelname):  # {{{
+    def savemodeljs(self, fid, modelname): # {{{
         fid.write('  #s.mesh = new mesh3dsurface()\n' % modelname)
         writejs1Darray(fid, [modelname, '.mesh.x'], self.x)
@@ -195,4 +196,92 @@
         writejs1Darray(fid, [modelname, '.mesh.extractedvertices'], self.extractedvertices)
         writejs1Darray(fid, [modelname, '.mesh.extractedelements'], self.extractedelements)
-
-    # }}}
+    # }}}
+
+    def export(self, *args): # {{{
+        options = pairoptions(*args)
+
+        filename    = options.getfieldvalue('filename')
+        format      = options.getfieldvalue('format', 'shp')
+        geometry    = options.getfieldvalue('geometry', 'line')
+        index       = options.getfieldvalue('index', [])
+        proj        = options.getfieldvalue('projection', '')
+
+        #prepare contours:
+        contours = []
+        if geometry == 'point':
+            for i in range(len(self.numberofvertices)):
+                contour             = OrderedStruct()
+                contour.x           = self.long[i]
+                contour.y           = self.lat[i]
+                contour.id          = i
+                contour.Geometry    = 'Point'
+                contours[i]         = contour
+        elif geometry == 'line':
+            counter = 0
+            for i in range(len(self.numberofelements)): 
+                el = self.elements[i]
+
+                #first line:
+                contour                 = OrderedStruct()
+                contour.x               = [self.long[el[0]] self.long[el[1]]]
+                contour.y               = [self.lat[el[0]] self.lat[el[1]]]
+                contour.Geometry        = 'Line'
+                contours[counter]       = contour
+
+                #second line:
+                contour                 = OrderedStruct()
+                contour.x               = [self.long[el[1]] self.long[el[2]]]
+                contour.y               = [self.lat[el[1]] self.lat[el[2]]]
+                contour.Geometry        = 'Line'
+                contours[counter + 1]   = contour
+
+                #second line:
+                contour                 = OrderedStruct()
+                contour.x               = [self.long[el[2]] self.long[el[0]]]
+                contour.y               = [self.lat[el[2]] self.lat[el[0]]]
+                contour.Geometry        = 'Line'
+                contours[counter + 2]   = contour
+
+                #increase counter:
+                counter += 3
+        elif geometry == 'polygon':
+            # TODO: Refactor the following to reduce repeated code, or 
+            #       leave as is because it is more readable?
+            if index == []:
+                for i in range(len(self.numberofelements)):
+                    el = self.elements[i]
+
+                    contour             = OrderedStruct()
+                    contour.x           = [self.long[el[0]] self.long[el[1]] self.long[el[2]]]
+                    contour.y           = [self.lat[el[0]] self.lat[el[1]] self.lat[el[2]]]
+                    contour.Id          = i
+                    contour.Geometry    = 'Polygon'
+                    contours[i]         = contour
+            else:
+                for i in range(len(index)):
+                    el = self.elements[index[i]]
+
+                    contour             = OrderedStruct()
+                    contour.x           = [self.long[el[0]] self.long[el[1]] self.long[el[2]]]
+                    contour.y           = [self.lat[el[0]] self.lat[el[1]] self.lat[el[2]]]
+                    contour.Id          = index[i]
+                    contour.Geometry    = 'Polygon'
+                    contours[i]         = contour
+        else:
+            raise RuntimeError("mesh3dsurface 'export' error message: geometry %s not supported yet (should be 'point' or 'line' or 'polygon')" % geometry)
+
+        #write file:
+        if format == 'shp':
+            shpwrite(contours, filename)
+        elif format == 'exp':
+            expwrite(contours, filename)
+        else:
+            raise RuntimeError("mesh3dsurface 'export' error message: file format %s not supported yet" % format)
+
+        #write projection file:
+        if proj != '':
+            proj2shpprj(filename, proj)
+
+        #write style file:
+        applyqgisstyle(filename, 'mesh')
+    # }}}
Index: /issm/trunk-jpl/src/m/qmu/helpers.py
===================================================================
--- /issm/trunk-jpl/src/m/qmu/helpers.py	(revision 24893)
+++ /issm/trunk-jpl/src/m/qmu/helpers.py	(revision 24894)
@@ -17,8 +17,8 @@
     attributes other than the array
 
-List - based and struct - based behaviors work normally, however they are referenced
+List-based and struct-based behaviors work normally, however they are referenced
     as if the other does not exist; len(x) corresponds only to
     the list component of x, len(x.a) corresponds to x.a, x.__dict__
-    corresponds only to the non - x - list attributes
+    corresponds only to the non-x-list attributes
 
 Example uses:
@@ -64,9 +64,9 @@
     '''
 A form of dictionary-like structure that maintains the
-    ordering in which its fields / attributes and their
+    ordering in which its fields/attributes and their
     corresponding values were added.
 
 OrderedDict is a similar device, however this class
-    can be used as an "ordered struct / class" giving
+    can be used as an "ordered struct/class" giving
     it much more flexibility in practice. It is
     also easier to work with fixed valued keys in-code.
@@ -128,5 +128,5 @@
 
         if len(args) % 2 != 0:
-            raise RuntimeError('OrderedStruct input error: OrderedStruct(*args) call must have an even number of inputs, in key / value pairs')
+            raise RuntimeError('OrderedStruct input error: OrderedStruct(*args) call must have an even number of inputs, in key/value pairs')
 
         for a, b in zip(args[0::2], args[1::2]):
@@ -186,5 +186,5 @@
     def __copy__(self):
         # shallow copy, hard copies of trivial attributes,
-        # references to structures like lists / OrderedDicts
+        # references to structures like lists/OrderedDicts
         # unless redefined as an entirely different structure
         newInstance = type(self)()
@@ -234,5 +234,5 @@
             return True
 
-    # if anything in that array / matrix is not empty, the whole thing is not empty
+    # if anything in that array/matrix is not empty, the whole thing is not empty
         try:
             x = np.concatenate(x)
