Index: /issm/trunk/src/m/classes/public/plugvelocitiesraw.m
===================================================================
--- /issm/trunk/src/m/classes/public/plugvelocitiesraw.m	(revision 1318)
+++ /issm/trunk/src/m/classes/public/plugvelocitiesraw.m	(revision 1318)
@@ -0,0 +1,98 @@
+function md=plugvelocitiesraw(md,filename,default_value)
+%PLUGVELOCITIESRAW - load raw velocities on a model
+%
+%   load a matlab file (extension .mat) which holds 4 variables
+%   x,y,vx,vy to be plugged onto the model (or similar names)
+%   x and y must be vectors, vx, vy matrices
+%
+%   Usage:
+%      md=plugvelocitiesraw(md,filename,default_value)
+%
+%   Example:
+%      md=plugvelocitiesraw(md,'velocityfile.mat',0);
+%
+%   See also: PLUGVELOCITIES INTERPFROMFILE, GRIDDATA
+
+%some checks
+if nargin~=3 | nargout~=1
+	help plugvelocitiesraw
+	error('plugvelocitiesraw error message: bad usage');
+end
+if ~exist(filename)
+	error(['plugvelocitiesraw error message: file ' filename  ' does not exist']);
+end
+
+%Get variables
+A=whos('-file',filename);
+
+%find x,y,vx and vy
+xenum=NaN; yenum=NaN; vxenum=NaN; vyenum=NaN;
+if length(A)==4,
+	for i=1:4
+		if strcmpi(A(i).name(1),'x');
+			xenum=i;
+		elseif strcmpi(A(i).name(1),'y');
+			yenum=i;
+		else
+			if strcmpi(A(i).name(end),'x');
+				vxenum=i;
+			elseif strcmpi(A(i).name(end),'y');
+				vyenum=i;
+			end
+		end
+	end
+else
+	error(['plugvelocitiesraw error message: file ' filename  ' not supported yet (it should hold 4 variables x,y,vx and vy)']);
+end
+
+%assum that we have found at least vxenum and vyenum
+if ( isnan(vxenum) | isnan(vyenum))
+	error(['plugvelocitiesraw error message: file ' filename  ' not supported yet (it should hold 4 variables x,y,vx and vy)']);
+end
+
+%find x y
+if (isnan(xenum) | isnan(yenum))
+
+	%check the size
+	if A(vxenum).size(1)==A(vxenum).size(2),
+		error(['plugvelocitiesraw error message: file ' filename  ' not supported (velocities is a square matrix, save x and y with another name)']);
+	end
+	if ~(A(vxenum).size(1)==A(vyenum).size(1) & A(vxenum).size(2)==A(vyenum).size(2)),
+		error(['plugvelocitiesraw error message: file ' filename  ' not supported (vx and vy matrices do not have the same size)']);
+	end
+
+	%find xenum and yenum
+	for i=1:4
+		lengthi=max(A(i).size);
+		if ((i~=vxenum) & (lengthi==A(vxenum).size(1) | lengthi==A(vxenum).size(1)+1)),
+			yenum=i;
+		elseif ((i~=vxenum) & (lengthi==A(vxenum).size(2) | lengthi==A(vxenum).size(2)+1)),
+			xenum=i;
+		end
+	end
+
+	%last check
+	if (isnan(xenum) | isnan(yenum))
+		error(['plugdata error message: file ' filename  ' not supported yet']);
+	end
+end
+
+%create names:
+xname=A(xenum).name;
+yname=A(yenum).name;
+vxname=A(vxenum).name;
+vyname=A(vyenum).name;
+
+%load data
+B=load(filename);
+
+%get x y vx and vy
+eval(['x=B.' xname ';'])
+eval(['y=B.' yname ';'])
+eval(['vx=B.' vxname ';'])
+eval(['vy=B.' vyname ';'])
+
+%interpolate
+md.vx_obs_raw=InterpFromGrid(x,y,vx,md.x,md.y,default_value);
+md.vy_obs_raw=InterpFromGrid(x,y,vy,md.x,md.y,default_value);
+md.vel_obs_raw=sqrt(md.vx_obs_raw.^2+md.vy_obs_raw.^2);
