Index: /issm/trunk-jpl/src/m/exp/expwrite.py
===================================================================
--- /issm/trunk-jpl/src/m/exp/expwrite.py	(revision 26968)
+++ /issm/trunk-jpl/src/m/exp/expwrite.py	(revision 26969)
@@ -20,26 +20,64 @@
 
     fid = open(filename, 'w')
-    for x, y in zip(contours['x'], contours['y']):
-        if len(x) != len(y):
-            raise RuntimeError('contours x and y coordinates must be of identical size')
-
-        if 'name' in contours:
-            fid.write('{}{}\n'.format('## Name:', contours['name']))
+    #if it is a list we need to loop on several contours
+    if isinstance(contours, list):
+        for contour in contours:
+            #if it si some kind of array it is a contour and we loop on indexes
+            if isinstance(contour['x'], (list, tuple, np.ndarray)):
+                writegeomlist(contour, fid, filename)
+            #else it is an index and we just write it down
+            else:
+                writegeom(contour, fid, filename)
+    #if it is a dict type it means just one contour
+    else:
+        #if it si some kind of array it is a contour and we loop on indexes
+        if isinstance(contours['x'], (list, tuple, np.ndarray)):
+            writegeomlist(contours, fid, filename)
+        #else it is an index and we just write it down
         else:
-            fid.write('{}{}\n'.format('## Name:', filename))
-
-        fid.write('{}\n'.format('## Icon:0'))
-        fid.write('{}\n'.format('# Points Count Value'))
-        if 'density' in contours:
-            if isinstance(contours['density'], int):
-                fid.write('{} {}\n'.format(np.size(x), contours['density']))
-            else:
-                fid.write('{} {}\n'.format(np.size(x), 1.))
-        else:
-            fid.write('{} {}\n'.format(np.size(x), 1.))
-        fid.write('{}\n'.format('# X pos Y pos'))
-        for xi, yi in zip(x, y):
-            fid.write('%10.10f %10.10f\n' % (xi, yi))
-        fid.write('\n')
+            writegeom(contours, fid, filename)
 
     fid.close()
+
+
+def writegeomlist(contour, fid, filename):
+    if len(contour['x']) != len(contour['y']):
+        raise RuntimeError('contours x and y coordinates must be of identical size')
+    if 'name' in contour:
+        fid.write('{}{}\n'.format('## Name:', contour['name']))
+    else:
+        fid.write('{}{}\n'.format('## Name:', filename))
+
+    fid.write('{}\n'.format('## Icon:0'))
+    fid.write('{}\n'.format('# Points Count Value'))
+    if 'density' in contour:
+        if isinstance(contour['density'], int):
+            fid.write('{} {}\n'.format(np.size(contour['x']), contour['density']))
+        else:
+            fid.write('{} {}\n'.format(np.size(contour['x']), 1.))
+    else:
+        fid.write('{} {}\n'.format(np.size(contour['x']), 1.))
+    fid.write('{}\n'.format('# X pos Y pos'))
+    for x, y in zip(contour['x'], contour['y']):
+        fid.write('%10.10f %10.10f\n' % (x, y))
+    fid.write('\n')
+
+
+def writegeom(contour, fid, filename):
+    if 'name' in contour:
+        fid.write('{}{}\n'.format('## Name:', contour['name']))
+    else:
+        fid.write('{}{}\n'.format('## Name:', filename))
+
+    fid.write('{}\n'.format('## Icon:0'))
+    fid.write('{}\n'.format('# Points Count Value'))
+    if 'density' in contour:
+        if isinstance(contour['density'], int):
+            fid.write('{} {}\n'.format(1, contour['density']))
+        else:
+            fid.write('{} {}\n'.format(1, 1.))
+    else:
+        fid.write('{} {}\n'.format(1, 1.))
+    fid.write('{}\n'.format('# X pos Y pos'))
+    fid.write('%10.10f %10.10f\n' % (contour['x'], contour['y']))
+    fid.write('\n')
Index: /issm/trunk-jpl/src/m/shp/shpread.py
===================================================================
--- /issm/trunk-jpl/src/m/shp/shpread.py	(revision 26968)
+++ /issm/trunk-jpl/src/m/shp/shpread.py	(revision 26969)
@@ -1,2 +1,3 @@
+import numpy as np
 from collections import OrderedDict
 from os import path
@@ -12,10 +13,10 @@
     """SHPREAD - read a shapefile and build a list of shapes
 
-    This routine reads a shapefile and builds a list of OrderedDict objects 
-    containing the fields x and y corresponding to the coordinates, one for the 
-    filename of the shp file, for the density, for the nodes, and a field 
-    closed to indicate if the domain is closed. If this initial shapefile is 
-    point only, the fields closed and points are ommitted. The first argument 
-    is the shapefile to be read and the second argument (optional) indicates if 
+    This routine reads a shapefile and builds a list of OrderedDict objects
+    containing the fields x and y corresponding to the coordinates, one for the
+    filename of the shp file, for the density, for the nodes, and a field
+    closed to indicate if the domain is closed. If this initial shapefile is
+    point only, the fields closed and points are ommitted. The first argument
+    is the shapefile to be read and the second argument (optional) indicates if
     the last point shall be read (1 to read it, 0 not to).
 
@@ -26,7 +27,7 @@
 
     Example:
-        From underling PyShp implementation, "The shapefile format is actually 
-        a collection of three files. You specify the base filename of the 
-        shapefile or the complete filename of any of the shapefile component 
+        From underling PyShp implementation, "The shapefile format is actually
+        a collection of three files. You specify the base filename of the
+        shapefile or the complete filename of any of the shapefile component
         files."
 
@@ -37,7 +38,7 @@
         list = shpread('domainoutline')
 
-        "OR any of the other 5+ formats which are potentially part of a 
-        shapefile. The library does not care about file extensions". We do, 
-        however, check that a file with the base filename or base filename with 
+        "OR any of the other 5+ formats which are potentially part of a
+        shapefile. The library does not care about file extensions". We do,
+        however, check that a file with the base filename or base filename with
         .shp extension exists.
 
@@ -46,13 +47,13 @@
 
     NOTE:
-    - OrderedDict objects are used instead of OrderedStruct objects (although 
-    addressing in the latter case is closer to the MATLAB struct type) in order 
+    - OrderedDict objects are used instead of OrderedStruct objects (although
+    addressing in the latter case is closer to the MATLAB struct type) in order
     to remain consistent with the pattern established by src/m/exp/expread.py.
 
     TODO:
-    - Create class that can be used to store and pretty print shape structs 
+    - Create class that can be used to store and pretty print shape structs
     (ala OrderedStruct from src/m/qmu/helpers.py).
-    - Convert returned data structure from list of OrderedDict objects to list 
-    of OrderedStruct objects and remove corresponding note (see also 
+    - Convert returned data structure from list of OrderedDict objects to list
+    of OrderedStruct objects and remove corresponding note (see also
     src/m/exp/expread.py). Also, modify handling of returned data structure in,
         - src/m/classes/basin.py
@@ -76,7 +77,6 @@
     Structs = []
     shapes = sf.shapes()
-    for i in range(len(shapes)):
+    for i, shape in enumerate(shapes):
         Struct = OrderedDict()
-        shape = shapes[i]
         if shape.shapeType == shapefile.POINT:
             Struct['x'] = shape.points[0][0]
@@ -88,6 +88,5 @@
             x = []
             y = []
-            for j in range(num_points):
-                point = shape.points[j]
+            for j, point in enumerate(shape.points):
                 x.append(point[0])
                 y.append(point[1])
@@ -103,6 +102,5 @@
             x = []
             y = []
-            for j in range(num_points):
-                point = shape.points[j]
+            for j, point in enumerate(shape.points):
                 x.append(point[0])
                 y.append(point[1])
@@ -115,8 +113,8 @@
             Struct['Geometry'] = 'Polygon'
         else:
-            # NOTE: We could do this once before looping over shapes as all 
-            #       shapes in the file must be of the same type, but we would 
-            #       need to have a second check anyway in order to know how to 
-            #       parse the points. So, let's just assume the file is not 
+            # NOTE: We could do this once before looping over shapes as all
+            #       shapes in the file must be of the same type, but we would
+            #       need to have a second check anyway in order to know how to
+            #       parse the points. So, let's just assume the file is not
             #       malformed.
             #
@@ -125,11 +123,11 @@
         name = ''
         fields = sf.fields
-        for j in range(1, len(fields)): # skip over first field, which is "DeletionFlag"
+        for j in range(1, len(fields)):  # skip over first field, which is "DeletionFlag"
             fieldname = fields[j][0]
             # 'id' field gets special treatment
-            if fieldname == 'id':
-                name = str(sf.record(i)[j - 1]) # record index is offset by one, again, because of "DeletionFlag"
+            if fieldname in ['id', 'fid']:
+                name = str(sf.record(i)[j - 1])  # record index is offset by one, again, because of "DeletionFlag"
             else:
-                setattr(Struct, str(fieldname), sf.record(i)[j - 1]) # cast to string removes "u" from "u'fieldname'"
+                setattr(Struct, str(fieldname), sf.record(i)[j - 1])  # cast to string removes "u" from "u'fieldname'"
         Struct['name'] = name
         Structs.append(Struct)
Index: /issm/trunk-jpl/src/m/shp/shpwrite.py
===================================================================
--- /issm/trunk-jpl/src/m/shp/shpwrite.py	(revision 26968)
+++ /issm/trunk-jpl/src/m/shp/shpwrite.py	(revision 26969)
@@ -23,5 +23,5 @@
 
     TODO:
-    - Should we check if there is only one element (see how MATLAB's shaperead 
+    - Should we check if there is only one element (see how MATLAB's shaperead
     and shapewrite handle single shapes versus multiple shapes)?
     '''
@@ -43,5 +43,5 @@
 
     for i in range(len(shp)):
-        sf.field('name', 'C') # TODO: Allow shape ids/names to be passed through
+        sf.field('name', 'C')  # TODO: Allow shape ids/names to be passed through
         if shapeType == 1: # POINT
             sf.point(shp[i].x, shp[i].y)
@@ -51,5 +51,5 @@
                 points.append([shp[i].x[j], shp[i].y[j]])
             sf.line(line)
-        elif shapeType == 5: # POLYGON
+        elif shapeType == 5:  # POLYGON
             points = []
             for j in range(len(shp[i].x)):
