Index: /issm/trunk/src/m/utils/Exp/expcoarsen.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/expcoarsen.m	(revision 1218)
+++ /issm/trunk/src/m/utils/Exp/expcoarsen.m	(revision 1219)
@@ -30,8 +30,9 @@
 
 %Go through the profiles
-for i=1:numprofiles
+count=1;
+while count<=numprofiles,
 
 	%get number of points and initialize j
-	numpoints=length(A(i).x);
+	numpoints=length(A(count).x);
 	j=1;
 
@@ -40,16 +41,16 @@
 
 		%See whether we keep this point or not
-		distance=sqrt((A(i).x(j)-A(i).x(j+1))^2+(A(i).y(j)-A(i).y(j+1))^2);
+		distance=sqrt((A(count).x(j)-A(count).x(j+1))^2+(A(count).y(j)-A(count).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)=[];
+			A(count).x(j+1)=[];
+			A(count).y(j+1)=[];
 			numpoints=numpoints-1;
 		else
 			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)];
+				x=linspace(A(count).x(j),A(count).x(j+1),division)';
+				y=linspace(A(count).y(j),A(count).y(j+1),division)';
+				A(count).x=[A(count).x(1:j);x(2:end-1); A(count).x(j+1:end)];
+				A(count).y=[A(count).y(1:j);y(2:end-1); A(count).y(j+1:end)];
 
 				%update current point
@@ -62,5 +63,10 @@
 		end
 	end
-
+	if length(A(count).x)<=1,
+		A(count)=[];
+		numprofiles=numprofiles-1;
+	else
+		count=count+1;
+	end
 end
 
Index: /issm/trunk/src/m/utils/Exp/expopen.m
===================================================================
--- /issm/trunk/src/m/utils/Exp/expopen.m	(revision 1218)
+++ /issm/trunk/src/m/utils/Exp/expopen.m	(revision 1219)
@@ -8,3 +8,3 @@
 
 a=expread(oldname,0); %0 for opening.
-expwrite(newname,a);
+expwrite(a,newname);
