Index: /issm/trunk/src/m/utils/Exp/expcoarsen.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/expcoarsen.m	(revision 1130)
+++ /issm/trunk/src/m/utils/Exp/expcoarsen.m	(revision 1131)
@@ -37,14 +37,27 @@
 
 	%stop if we have reached end of profile (always keep the last point)
-	while j<numpoints-1,,
+	while j<numpoints,
 
 		%See whether we keep this point or not
-		if sqrt((A(i).x(j)-A(i).x(j+1))^2+(A(i).y(j)-A(i).y(j+1))^2)<resolution
+		distance=sqrt((A(i).x(j)-A(i).x(j+1))^2+(A(i).y(j)-A(i).y(j+1))^2);
+		if distance<resolution & j<numpoints-1  %do not remove last point
 			A(i).x(j+1)=[];
 			A(i).y(j+1)=[];
 			numpoints=numpoints-1;
 		else
-			%update current point
-			j=j+1;
+			division=floor(distance/resolution)+2;
+			if division>2,
+				x=linspace(A(i).x(j),A(i).x(j+1),division)';
+				y=linspace(A(i).y(j),A(i).y(j+1),division)';
+				A(i).x=[A(i).x(1:j);x(2:end-1); A(i).x(j+1:end)];
+				A(i).y=[A(i).y(1:j);y(2:end-1); A(i).y(j+1:end)];
+
+				%update current point
+				j=j+1+division-2;
+				numpoints=numpoints+division-2;
+			else
+				%update current point
+				j=j+1;
+			end
 		end
 	end
