Index: ../trunk-jpl/src/m/mesh/bamg.m
===================================================================
--- ../trunk-jpl/src/m/mesh/bamg.m	(revision 19076)
+++ ../trunk-jpl/src/m/mesh/bamg.m	(revision 19077)
@@ -348,7 +348,25 @@
 
 	%Now, build the connectivity tables for this mesh.
 	md.mesh.vertexonboundary=zeros(md.mesh.numberofvertices,1); md.mesh.vertexonboundary(md.mesh.segments(:,1:2))=1;
-else
+
+elseif getfieldvalue(options,'3dsurface',0),
+	
+	md.mesh=mesh3dsurface();
+	md.mesh.x=bamgmesh_out.Vertices(:,1);
+	md.mesh.y=bamgmesh_out.Vertices(:,2);
+	md.mesh.z=md.mesh.x; md.mesh.z(:)=0;
+	md.mesh.elements=bamgmesh_out.Triangles(:,1:3);
+	md.mesh.edges=bamgmesh_out.IssmEdges;
+	md.mesh.segments=bamgmesh_out.IssmSegments(:,1:3);
+	md.mesh.segmentmarkers=bamgmesh_out.IssmSegments(:,4);
+
+	%Fill in rest of fields:
+	md.mesh.numberofelements=size(md.mesh.elements,1);
+	md.mesh.numberofvertices=length(md.mesh.x);
+	md.mesh.numberofedges=size(md.mesh.edges,1);
+	md.mesh.vertexonboundary=zeros(md.mesh.numberofvertices,1); md.mesh.vertexonboundary(md.mesh.segments(:,1:2))=1;
+
+else 
 	md.mesh=mesh2d();
 	md.mesh.x=bamgmesh_out.Vertices(:,1);
 	md.mesh.y=bamgmesh_out.Vertices(:,2);
