Index: /issm/trunk/src/m/classes/public/plugvelocities.m
===================================================================
--- /issm/trunk/src/m/classes/public/plugvelocities.m	(revision 2565)
+++ /issm/trunk/src/m/classes/public/plugvelocities.m	(revision 2566)
@@ -27,6 +27,7 @@
 
 %find x,y,vx and vy
-xenum=NaN; yenum=NaN; vxenum=NaN; vyenum=NaN;
+xenum=NaN; yenum=NaN; vxenum=NaN; vyenum=NaN; indexenum=NaN;
 if length(A)==4,
+	isgrid=1;
 	for i=1:4
 		if strcmpi(A(i).name(1),'x');
@@ -42,11 +43,41 @@
 		end
 	end
+elseif length(A)==5,
+	isgrid=0;
+	for i=1:5
+		if strcmpi(A(i).name(1),'x');
+			xenum=i;
+		elseif strcmpi(A(i).name(1),'y');
+			yenum=i;
+		elseif (strcmpi(A(i).name(1),'index') | strcmpi(A(i).name(1),'elements'));
+			indexenum=i;
+		else
+			if (strcmpi(A(i).name(end),'x') | strncmpi(A(i).name,'vx',2));
+				vxenum=i;
+			elseif (strcmpi(A(i).name(end),'y') | strncmpi(A(i).name,'vy',2));
+				vyenum=i;
+			end
+		end
+	end
 else
-	error(['plugvelocities error message: file ' filename  ' not supported yet (it should hold 4 variables x,y,vx and vy)']);
+	error(['plugvelocities error message: file ' filename  ' not supported yet (it should hold 4 variables x,y,vx and vy (for grids) OR 5 variables  x,y,index,vx and vy (for mesh))']);
 end
 
 %assum that we have found at least vxenum and vyenum
 if ( isnan(vxenum) | isnan(vyenum))
-	error(['plugvelocities error message: file ' filename  ' not supported yet (it should hold 4 variables x,y,vx and vy)']);
+	error(['plugvelocities error message: file ' filename  ' not supported yet (the velocities should be named vx and vy)']);
+end
+
+%find index
+if (~isgrid & insnan(indexenum)),
+	for i=1:5
+		lengthi=min(A(i).size);
+		if (lengthi==3),
+			indexenum=i;
+		end
+	end
+	if isnan(indexenum),
+		error(['plugvelocities error message: file ' filename  ' not supported yet (index not found)']);
+	end
 end
 
@@ -83,4 +114,5 @@
 vxname=A(vxenum).name;
 vyname=A(vyenum).name;
+if ~isgrid, indexname=A(indexenum).name; end
 
 %load data
@@ -88,12 +120,18 @@
 
 %get x y vx and vy
-eval(['x=B.' xname ';'])
-eval(['y=B.' yname ';'])
-eval(['vx=B.' vxname ';'])
-eval(['vy=B.' vyname ';'])
+eval(['x=B.' xname ';']);
+eval(['y=B.' yname ';']);
+eval(['vx=B.' vxname ';']);
+eval(['vy=B.' vyname ';']);
+if ~isgrid, eval(['index=B.' indexname ';']); end
 
 %interpolate
-md.vx_obs=InterpFromGridToMesh(x,y,vx,md.x,md.y,default_value);
-md.vy_obs=InterpFromGridToMesh(x,y,vy,md.x,md.y,default_value);
+if isgrid,
+	md.vx_obs=InterpFromGridToMesh(x,y,vx,md.x,md.y,default_value);
+	md.vy_obs=InterpFromGridToMesh(x,y,vy,md.x,md.y,default_value);
+else
+	md.vx_obs=InterpFromMeshToMesh2d(index,x,y,vx,md.x,md.y,default_value);
+	md.vy_obs=InterpFromMeshToMesh2d(index,x,y,vy,md.x,md.y,default_value);
+end
 md.vx=md.vx_obs;
 md.vy=md.vy_obs;
