Index: /issm/trunk/src/c/InterpFromGridx/InterpFromGridx.cpp
===================================================================
--- /issm/trunk/src/c/InterpFromGridx/InterpFromGridx.cpp	(revision 1172)
+++ /issm/trunk/src/c/InterpFromGridx/InterpFromGridx.cpp	(revision 1172)
@@ -0,0 +1,183 @@
+/*!\file:  InterpFromGridx.cpp
+ * \brief  "c" core code for interpolating values from a structured grid.
+ */ 
+
+#include "./InterpFromGridx.h"
+#include "../shared/shared.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__ "InterpFromGridx"
+
+int findindices(int* pm,int* pn,double* x,int x_rows, double* y,int y_rows, double xgrid,double ygrid);
+
+int InterpFromGridx( Vec* pdata_mesh,double* x_in, int x_rows, double* y_in, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods) {
+
+
+	/*output: */
+	Vec data_mesh=NULL;
+	
+	/*Intermediary*/
+	double* x=NULL;
+	double* y=NULL;
+	int i,m,n;
+	int ind;
+	double dis;
+	double x_grid,y_grid;
+	double xi,eta;
+	double G1,G2,G3,G4,data_value;
+	double area_1,area_2,area_3;
+	double area;
+
+	/*Some checks on arguments: */
+	if ((M<=2) || (N<=2) || (nods<=0)){
+		throw ErrorException(__FUNCT__,"nothing to be done according to the dimensions of input matrices and vectors.");
+	}
+
+	/*Allocate output vector: */
+	data_mesh=NewVec(nods);
+
+	/*Find out what kind of coordinates (x_in,y_in) have been given is input*/
+	if(N==(x_rows-1) && M==(y_rows-1)){
+
+		/*The coordinates given in input describe the contour of each pixel. Take the center of each pixel*/
+		x=(double*)xmalloc(N*sizeof(double));
+		y=(double*)xmalloc(M*sizeof(double));
+		for (i=0;i<N;i++) x[i]=(x_in[i]+x_in[i+1])/2;
+		for (i=0;i<M;i++) y[i]=(y_in[i]+y_in[i+1])/2;
+		x_rows=x_rows-1;
+		y_rows=y_rows-1;
+	}
+	else if (M==x_rows && N==x_rows){
+
+		/*The coordinates given in input describe the center each pixel. Keep them*/
+		x=(double*)xmalloc(N*sizeof(double));
+		y=(double*)xmalloc(M*sizeof(double));
+		for (i=0;i<N;i++) x[i]=x_in[i];
+		for (i=0;i<M;i++) y[i]=y_in[i];
+	}
+	else{
+		throw ErrorException(__FUNCT__,"x and y vectors length should be 1 or 0 more than data number of rows.");
+	}
+
+	/*Linear (triangle) interpolation: */
+	for ( i=MPI_Lowerrow(nods); i<MPI_Upperrow(nods); i++) {
+
+		x_grid=*(x_mesh+i);
+		y_grid=*(y_mesh+i);
+
+		/*Find indices m and n into y and x, for which  y(m)<=y_grids<=y(m+1) and x(n)<=x_grid<=x(n+1)*/
+		if(findindices(&n,&m,x,x_rows, y,y_rows, x_grid,y_grid)){
+			
+			/*Get area*/
+			area=(x[n+1]-x[n])*(y[m+1]-y[m]);
+
+			/*is it the upper right triangle?*/
+			/*2'     3'
+			 *+-----+
+			 *1\    |
+			 *| \   |
+			 *|  \  |
+			 *|   \ |
+			 *|    \|
+			 *2----3+1' */
+			if ((x_grid-x[n])/(x[n+1]-x[n])<(y_grid-y[m])/(y[m+1]-y[m])){
+
+				/*Then find values of data at each summit*/
+				G1=*(data+m*N+n);
+				G2=*(data+(m+1)*N+n+1);
+				G3=*(data+(m+1)*N+n);
+
+				/*Get first area coordinate*/
+				area_1=((y[m+1]-y_grid)*(x[n+1]-x[n]))/area;
+				/*Get second area coordinate*/
+				area_2=((x_grid-x[n])*(y[m+1]-y[m]))/area;
+				/*Get third area coordinate = 1-area1-area2*/
+				area_3=1-area_1-area_2;
+
+				/*interpolate*/
+				data_value=area_1*G1+area_2*G2+area_3*G3;
+			}
+			else {
+
+				/*Then find values of data at each summit*/
+				G1=*(data+(m+1)*N+n+1);
+				G2=*(data+m*N+n);
+				G3=*(data+m*N+n+1);
+
+				/*Get first area coordinate*/
+				area_1=((y_grid-y[m])*(x[n+1]-x[n]))/area;
+				/*Get second area coordinate*/
+				area_2=((x[n+1]-x_grid)*(y[m+1]-y[m]))/area;
+				/*Get third area coordinate = 1-area1-area2*/
+				area_3=1-area_1-area_2;
+
+				/*interpolate*/
+				data_value=area_1*G1+area_2*G2+area_3*G3;
+			}
+
+			/*Treat NANs: take the closest non nan value avomg neighbors*/
+			if isnan(data_value){
+				ind=m*N+n;
+				dis=pow(x[n+1]-x[n],2);
+				if ( ((pow(y_grid-y[m],2)+pow(x_grid-x[n+1],2))<dis) && (!isnan(data[m*N+n+1]))){
+					ind=m*N+n+1;
+					dis=pow(y_grid-y[m],2)+pow(x_grid-x[n+1],2);
+				}
+				if ( ((pow(y_grid-y[m+1],2)+pow(x_grid-x[n],2))<dis) && (!isnan(data[(m+1)*N+n]))){
+					ind=(m+1)*N+n;
+					dis=pow(y_grid-y[m+1],2)+pow(x_grid-x[n],2);
+				}
+				if ( ((pow(y_grid-y[m+1],2)+pow(x_grid-x[n+1],2))<dis) && (!isnan(data[(m+1)*N+n+1]))){
+					ind=(m+1)*N+n+1;
+					dis=pow(y_grid-y[m+1],2)+pow(x_grid-x[n+1],2);
+				}
+				data_value=*(data+ind);
+			}
+		}
+		else{
+			data_value=-9999;
+		}
+		VecSetValues(data_mesh,1,&i,&data_value,INSERT_VALUES);
+	}
+
+	/*Assign output pointers:*/
+	*pdata_mesh=data_mesh;
+}
+
+int findindices(int* pm,int* pn,double* x,int x_rows, double* y,int y_rows, double xgrid,double ygrid){
+
+	int foundx=0;
+	int foundy=0;
+	int i;
+	int m=-1;
+	int n=-1;
+
+	for (i=0;i<x_rows-1;i++){
+		if ( (*(x+i)<=xgrid) && (xgrid<*(x+i+1)) ){
+			m=i;
+			foundx= 1;
+			break;
+		}
+	}
+	if(*(x+x_rows-1)==xgrid){
+		m=x_rows-2;
+		foundx=1;
+	}
+	
+	for (i=0;i<y_rows-1;i++){
+		if ( (*(y+i)<=ygrid) && (ygrid<*(y+i+1)) ){
+			n=i;
+			foundy= 1;
+			break;
+		}
+	}
+	if(*(y+y_rows-1)==ygrid){
+		m=y_rows-2;
+		foundy=1;
+	}
+
+	/*Assign output pointers:*/
+	*pm=m;
+	*pn=n;
+	return foundx*foundy;
+}
Index: /issm/trunk/src/c/InterpFromGridx/InterpFromGridx.h
===================================================================
--- /issm/trunk/src/c/InterpFromGridx/InterpFromGridx.h	(revision 1172)
+++ /issm/trunk/src/c/InterpFromGridx/InterpFromGridx.h	(revision 1172)
@@ -0,0 +1,13 @@
+/*!\file InterpFromGridx.h
+ * \brief: header file for Data interpolation routines.
+ */
+
+#ifndef _INTERPFROMGRIDX_H
+#define _INTERPFROMGRIDX_H
+
+#include "../toolkits/toolkits.h"
+
+int InterpFromGridx( Vec* pdata_mesh,double* x, int x_rows, double* y, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods);
+
+#endif /* _INTERPFROMGRIDX_H */
+
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 1171)
+++ /issm/trunk/src/c/Makefile.am	(revision 1172)
@@ -239,6 +239,6 @@
 					./MpcNodesx/MpcNodesx.h\
 					./MpcNodesx/MpcNodesx.cpp\
-					./DataInterpx/DataInterpx.cpp\
-					./DataInterpx/DataInterpx.h\
+					./InterpFromGridx/InterpFromGridx.cpp\
+					./InterpFromGridx/InterpFromGridx.h\
 					./HoleFillerx/HoleFillerx.cpp\
 					./HoleFillerx/HoleFillerx.h\
@@ -519,6 +519,6 @@
 					./MpcNodesx/MpcNodesx.h\
 					./MpcNodesx/MpcNodesx.cpp\
-					./DataInterpx/DataInterpx.cpp\
-					./DataInterpx/DataInterpx.h\
+					./InterpFromGridx/InterpFromGridx.cpp\
+					./InterpFromGridx/InterpFromGridx.h\
 					./HoleFillerx/HoleFillerx.cpp\
 					./HoleFillerx/HoleFillerx.h\
Index: /issm/trunk/src/c/issm.h
===================================================================
--- /issm/trunk/src/c/issm.h	(revision 1171)
+++ /issm/trunk/src/c/issm.h	(revision 1172)
@@ -25,5 +25,5 @@
 #include "./ContourToMeshx/ContourToMeshx.h"
 #include "./ContourToNodesx/ContourToNodesx.h"
-#include "./DataInterpx/DataInterpx.h"
+#include "./InterpFromGridx/InterpFromGridx.h"
 #include "./HoleFillerx/HoleFillerx.h"
 #include "./MeshPartitionx/MeshPartitionx.h"
Index: /issm/trunk/src/m/utils/Mesh/squaremesh.m
===================================================================
--- /issm/trunk/src/m/utils/Mesh/squaremesh.m	(revision 1171)
+++ /issm/trunk/src/m/utils/Mesh/squaremesh.m	(revision 1172)
@@ -10,5 +10,5 @@
 %      [x y index]=squaremesh(Lx,Ly,nx,ny)
 
-%get number og elements and number of nodes
+%get number of elements and number of nodes
 nel=(nx-1)*(ny-1)*2;
 nods=nx*ny;
Index: /issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.cpp
===================================================================
--- /issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.cpp	(revision 1172)
+++ /issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.cpp	(revision 1172)
@@ -0,0 +1,79 @@
+/*!\file InterpFromGrid.c
+ * \brief: data interpolation from a list of (x,y,values) into mesh grids
+ 
+	InterpFromGrid.c
+
+	usage:
+	data_mesh=InterpFromGrid(x,y,data,x_mesh,y_mesh);
+	
+	where:
+
+		input:
+		x,y: coordinates of matrix data
+		data - matrix holding the data to be interpolated onto the mesh.
+		x_mesh,y_mesh: coordinates of the mesh grids onto which we interpolate.
+		
+		output: 
+		data_mesh:  vector of mesh interpolated data.
+
+*/
+	
+#include "./InterpFromGrid.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+	int i,j;
+
+	/*input: */
+	double* x=NULL;
+	int     x_rows;
+	
+	double* y=NULL;
+	int     y_rows;
+
+	double* data=NULL; 
+	int     data_rows,data_cols;
+
+	double* x_mesh=NULL;
+	double* y_mesh=NULL;
+	
+	int     x_mesh_rows;
+	int     y_mesh_rows;
+
+	/* output: */
+	Vec  data_mesh=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromGridUsage);
+
+	/*Input datasets: */
+	FetchData((void**)&x,&x_rows,NULL,XHANDLE,"Matrix","Mat");
+	FetchData((void**)&y,&y_rows,NULL,YHANDLE,"Matrix","Mat");
+	FetchData((void**)&data,&data_rows,&data_cols,DATAHANDLE,"Matrix","Mat");
+	FetchData((void**)&x_mesh,&x_mesh_rows,NULL,XMESHHANDLE,"Matrix","Mat");
+	FetchData((void**)&y_mesh,&y_mesh_rows,NULL,YMESHHANDLE,"Matrix","Mat");
+
+	/* Run core computations: */
+	InterpFromGridx( &data_mesh, x, x_rows,  y, y_rows, data, data_rows,data_cols, x_mesh, y_mesh, x_mesh_rows);
+
+	/*Write data: */
+	WriteData(DATAMESH,data_mesh,0,0,"Vector",NULL);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void InterpFromGridUsage(void)
+{
+	_printf_("   usage:\n");
+	_printf_("   data_mesh=InterpFromGrid(x,y,data,x_mesh,y_mesh);\n\n");
+	_printf_("   where:\n");
+	_printf_("      x,y: coordinates of matrix data\n");
+	_printf_("      data - matrix holding the data to be interpolated onto the mesh.\n");
+	_printf_("      x_mesh,y_mesh: coordinates of the mesh grids onto which we interpolate.\n");
+	_printf_("      data_mesh:  vector of mesh interpolated data.\n");
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.h
===================================================================
--- /issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.h	(revision 1172)
+++ /issm/trunk/src/mex/InterpFromGrid/InterpFromGrid.h	(revision 1172)
@@ -0,0 +1,36 @@
+/*!\file InterpFromGrid.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _InterpFromGrid_H
+#define _InterpFromGrid_H
+
+/* local prototypes: */
+void InterpFromGridUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "InterpFromGrid"
+
+#undef CLEANUP
+#define CLEANUP InterpFromGridLocalCleanup();
+
+
+/* serial input macros: */
+#define XHANDLE prhs[0]
+#define YHANDLE prhs[1]
+#define DATAHANDLE prhs[2]
+#define XMESHHANDLE prhs[3]
+#define YMESHHANDLE prhs[4]
+
+/* serial output macros: */
+#define DATAMESH (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  5
+
+#endif  /* _INTERPFROMGRId_H */
Index: /issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.cpp
===================================================================
--- /issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.cpp	(revision 1172)
+++ /issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.cpp	(revision 1172)
@@ -0,0 +1,179 @@
+/*!\file InterpFromMesh2d.c
+ * \brief: data interpolation from a list of (x,y,values) into mesh grids
+ 
+	InterpFromMesh2d.c
+
+	usage:
+	data_mesh=InterpFromMesh2d(index,x,y,data,x_mesh,y_mesh);
+	
+	where:
+
+		input:
+		x,y: coordinates of matrix data
+		data - matrix holding the data to be interpolated onto the mesh.
+		x_mesh,y_mesh: coordinates of the mesh grids onto which we interpolate.
+		
+		output: 
+		data_mesh:  vector of mesh interpolated data.
+
+*/
+	
+#include "./InterpFromMesh2d.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+	/*input: */
+	double* index_data=NULL;
+	int     index_data_rows;
+
+	double* x_data=NULL;
+	int     x_data_rows;
+	
+	double* y_data=NULL;
+	int     y_data_rows;
+
+	double* data=NULL; 
+	int     data_rows;
+	int     data_cols;
+
+	double* x_prime=NULL;
+	double* y_prime=NULL;
+	
+	int     x_prime_rows;
+	int     y_prime_rows;
+
+	/*Intermediary*/
+	int i,j;
+	int nods_data;
+	int nels_data;
+	int nods_prime;
+	int interpolation_type;
+	double area;
+	double area_1,area_2,area_3;
+	double data_value;
+	double xmin,xmax;
+	double ymin,ymax;
+
+	/* output: */
+	Vec  data_prime=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromMesh2dUsage);
+
+	/*Input datasets: */
+	FetchData((void**)&index_data,&index_data_rows,NULL,INDEXHANDLE,"Matrix","Mat");
+	FetchData((void**)&x_data,&x_data_rows,NULL,XHANDLE,"Matrix","Mat");
+	FetchData((void**)&y_data,&y_data_rows,NULL,YHANDLE,"Matrix","Mat");
+	FetchData((void**)&data,&data_rows,&data_cols,DATAHANDLE,"Matrix","Mat");
+	FetchData((void**)&x_prime,&x_prime_rows,NULL,XPRIMEHANDLE,"Matrix","Mat");
+	FetchData((void**)&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE,"Matrix","Mat");
+
+	/* Run core computations: */
+	//InterpFromMesh2dx( &data_mesh, index , index_rows, x, y, x_rows, data, data_rows, x_mesh, y_mesh, x_mesh_rows);
+
+	/*some checks*/
+	if (x_data_rows!=y_data_rows){
+		throw ErrorException(__FUNCT__,"vectors x and y should have the same length!");
+	}
+	if (x_prime_rows!=y_prime_rows){
+		throw ErrorException(__FUNCT__,"vectors x_prime and y_prime should have the same length!");
+	}
+	
+	/*get number of elements and number of nodes in the data*/
+	nels_data=index_data_rows;
+	nods_data=x_data_rows;
+	nods_prime=x_prime_rows;
+
+	/*figure out what kind of interpolation is needed*/
+	if (data_rows==nods_data){
+		interpolation_type=1;
+	}
+	else if (data_rows==nels_data){
+		interpolation_type=2;
+	}
+	else{
+		throw ErrorException(__FUNCT__,"length of vector data not supported yet. It should be of length (number of nodes) or (number of elements)!");
+	}
+
+	/*Get prime mesh extrema coordinates*/
+	xmin=x_prime[0]; xmax=x_prime[0];ymin=y_prime[0]; ymax=y_prime[0];
+	for (i=1;i<nods_prime;i++){
+		if (x_prime[i]<xmin) xmin=x_prime[i];
+		if (x_prime[i]>xmax) xmax=x_prime[i];
+		if (y_prime[i]<ymin) ymin=y_prime[i];
+		if (y_prime[i]>ymax) ymax=y_prime[i];
+	}
+
+	/*Initialize output*/
+	data_prime=NewVec(nods_prime);
+
+	printf("\n   interpolation progress:   %5.2lf %%",0.0);
+	for (i=0;i<nels_data;i++){
+
+		/*display current iteration*/
+		if (fmod(i,100)==0){
+			printf("\b\b\b\b\b\b\b%5.2lf %%",(double)i/nels_data*100);
+		}
+
+		/*if there is no point inside the domain, go to next iteration*/
+		if ( (x_data[(int)index_data[3*i+0]-1]<xmin) && (x_data[(int)index_data[3*i+1]-1]<xmin) && (x_data[(int)index_data[3*i+2]-1]<xmin)) continue;
+		if ( (x_data[(int)index_data[3*i+0]-1]>xmax) && (x_data[(int)index_data[3*i+1]-1]>xmax) && (x_data[(int)index_data[3*i+2]-1]>xmax)) continue;
+		if ( (y_data[(int)index_data[3*i+0]-1]<ymin) && (y_data[(int)index_data[3*i+1]-1]<ymin) && (y_data[(int)index_data[3*i+2]-1]<ymin)) continue;
+		if ( (y_data[(int)index_data[3*i+0]-1]>ymax) && (y_data[(int)index_data[3*i+1]-1]>ymax) && (y_data[(int)index_data[3*i+2]-1]>ymax)) continue;
+
+		/*get area of the current element (Jacobian = 2 * area)*/
+		//area =x2 * y3 - y2*x3 + x1 * y2 - y1 * x2 + x3 * y1 - y3 * x1;
+		area=x_data[(int)index_data[3*i+1]-1]*y_data[(int)index_data[3*i+2]-1]-y_data[(int)index_data[3*i+1]-1]*x_data[(int)index_data[3*i+2]-1]+ x_data[(int)index_data[3*i+0]-1]*y_data[(int)index_data[3*i+1]-1]-y_data[(int)index_data[3*i+0]-1]*x_data[(int)index_data[3*i+1]-1]+ x_data[(int)index_data[3*i+2]-1]*y_data[(int)index_data[3*i+0]-1]-y_data[(int)index_data[3*i+2]-1]*x_data[(int)index_data[3*i+0]-1];
+
+		/*loop over the prime nodes*/
+		for (j=0;j<nods_prime;j++){
+
+			/*Get first area coordinate = det(x-x3  x2-x3 ; y-y3   y2-y3)/area*/
+			area_1=((x_prime[j]-x_data[(int)index_data[3*i+2]-1])*(y_data[(int)index_data[3*i+1]-1]-y_data[(int)index_data[3*i+2]-1]) -  (y_prime[j]-y_data[(int)index_data[3*i+2]-1])*(x_data[(int)index_data[3*i+1]-1]-x_data[(int)index_data[3*i+2]-1]))/area;
+			/*Get second area coordinate =det(x1-x3  x-x3 ; y1-y3   y-y3)/area*/
+			area_2=((x_data[(int)index_data[3*i+0]-1]-x_data[(int)index_data[3*i+2]-1])*(y_prime[j]-y_data[(int)index_data[3*i+2]-1]) - (y_data[(int)index_data[3*i+0]-1]-y_data[(int)index_data[3*i+2]-1])*(x_prime[j]-x_data[(int)index_data[3*i+2]-1]))/area;
+			/*Get third area coordinate = 1-area1-area2*/
+			area_3=1-area_1-area_2;
+
+			/*is the current point in the current element?*/
+			if ((area_1>0 || area_1==0) && (area_2>0 || area_2==0) && (area_3>0 || area_3==0)){
+
+				/*Yes ! compute the value on the point*/
+				if (interpolation_type==1){
+					/*nodal interpolation*/
+					data_value=area_1*data[(int)index_data[3*i+0]-1]+area_2*data[(int)index_data[3*i+1]-1]+area_3*data[(int)index_data[3*i+2]-1];
+				}
+				else{
+					/*element interpolation*/
+					data_value=data[i];
+				}
+
+				/*insert value and go to the next point*/
+				VecSetValue(data_prime,j,data_value,INSERT_VALUES);
+			}
+		}
+	}
+	printf("\b\b\b\b\b\b\b%5.2lf %%\n",100.0);
+
+	/*Write data: */
+	WriteData(DATAPRIME,data_prime,0,0,"Vector",NULL);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void InterpFromMesh2dUsage(void)
+{
+	_printf_("   usage:\n");
+	_printf_("      data_prime=InterpFromMesh2d(index,x,y,data,x_prime,y_prime);\n\n");
+	_printf_("   where:\n");
+	_printf_("      x,y: coordinates of the nodes where data is defined\n");
+	_printf_("      index: index of the mesh where data is defined\n");
+	_printf_("      data - vector holding the data to be interpolated onto the points.\n");
+	_printf_("      x_prime,y_prime: coordinates of the mesh grids onto which we interpolate.\n");
+	_printf_("      data_prime:  vector of prime interpolated data.\n");
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.h
===================================================================
--- /issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.h	(revision 1172)
+++ /issm/trunk/src/mex/InterpFromMesh2d/InterpFromMesh2d.h	(revision 1172)
@@ -0,0 +1,37 @@
+/*!\file InterpFromMesh2d.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _INTERPFROMMESH2D_H
+#define _INTERPFROMMESH2D_H
+
+/* local prototypes: */
+void InterpFromMesh2dUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "InterpFromMesh2d"
+
+#undef CLEANUP
+#define CLEANUP InterpFromMesh2dLocalCleanup();
+
+
+/* serial input macros: */
+#define INDEXHANDLE prhs[0]
+#define XHANDLE prhs[1]
+#define YHANDLE prhs[2]
+#define DATAHANDLE prhs[3]
+#define XPRIMEHANDLE prhs[4]
+#define YPRIMEHANDLE prhs[5]
+
+/* serial output macros: */
+#define DATAPRIME (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  6
+
+#endif  /* _DATAINTERP2_H */
Index: /issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.cpp
===================================================================
--- /issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.cpp	(revision 1172)
+++ /issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.cpp	(revision 1172)
@@ -0,0 +1,195 @@
+/*!\file InterpFromMesh3d.c
+ * \brief: data interpolation from a list of (x,y,values) into mesh grids
+ 
+	InterpFromMesh3d.c
+
+	usage:
+	data_mesh=InterpFromMesh3d(index,x,y,z,data,x_mesh,y_mesh,z_mesh);
+	
+	where:
+
+		input:
+		x,y,z: coordinates of matrix data
+		data - matrix holding the data to be interpolated onto the mesh.
+		x_mesh,y_mesh,z_mesh: coordinates of the mesh grids onto which we interpolate.
+		
+		output: 
+		data_mesh:  vector of mesh interpolated data.
+
+*/
+	
+#include "./InterpFromMesh3d.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+	/*input: */
+	double* index_data=NULL;
+	int     index_data_rows;
+
+	double* x_data=NULL;
+	double* y_data=NULL;
+	double* z_data=NULL;
+
+	int     x_data_rows;
+	int     y_data_rows;
+	int     z_data_rows;
+
+	double* data=NULL; 
+	int     data_rows;
+	int     data_cols;
+
+	double* x_prime=NULL;
+	double* y_prime=NULL;
+	double* z_prime=NULL;
+	
+	int     x_prime_rows;
+	int     y_prime_rows;
+	int     z_prime_rows;
+
+	/*Intermediary*/
+	int i,j;
+	int nods_data;
+	int nels_data;
+	int nods_prime;
+	int interpolation_type;
+	double area;
+	double area_1,area_2,area_3;
+	double zeta,bed,surface;
+	double data_value;
+	double xmin,xmax;
+	double ymin,ymax;
+
+	/* output: */
+	Vec  data_prime=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromMesh3dUsage);
+
+	/*Input datasets: */
+	FetchData((void**)&index_data,&index_data_rows,NULL,INDEXHANDLE,"Matrix","Mat");
+	FetchData((void**)&x_data,&x_data_rows,NULL,XHANDLE,"Matrix","Mat");
+	FetchData((void**)&y_data,&y_data_rows,NULL,YHANDLE,"Matrix","Mat");
+	FetchData((void**)&z_data,&z_data_rows,NULL,ZHANDLE,"Matrix","Mat");
+	FetchData((void**)&data,&data_rows,&data_cols,DATAHANDLE,"Matrix","Mat");
+	FetchData((void**)&x_prime,&x_prime_rows,NULL,XPRIMEHANDLE,"Matrix","Mat");
+	FetchData((void**)&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE,"Matrix","Mat");
+	FetchData((void**)&z_prime,&z_prime_rows,NULL,ZPRIMEHANDLE,"Matrix","Mat");
+
+	/*some checks*/
+	if (index_data_rows<1 || x_data_rows<6 || y_data_rows<6 || z_data_rows<6){
+		throw ErrorException(__FUNCT__,"nothing to be done according to the mesh given in input");
+	}
+	if (x_data_rows!=y_data_rows || x_data_rows!=z_data_rows){
+		throw ErrorException(__FUNCT__,"vectors x, y and z should have the same length!");
+	}
+	if (x_prime_rows!=y_prime_rows || x_prime_rows!=z_prime_rows){
+		throw ErrorException(__FUNCT__,"vectors x_prime, y_prime and z_prime should have the same length!");
+	}
+	
+	/*get number of elements and number of nodes in the data*/
+	nels_data=index_data_rows;
+	nods_data=x_data_rows;
+	nods_prime=x_prime_rows;
+
+	/*figure out what kind of interpolation is needed*/
+	if (data_rows==nods_data){
+		interpolation_type=1;
+	}
+	else if (data_rows==nels_data){
+		interpolation_type=2;
+	}
+	else{
+		throw ErrorException(__FUNCT__,"length of vector data not supported yet. It should be of length (number of nodes) or (number of elements)!");
+	}
+
+	/*Get prime mesh extrema coordinates*/
+	xmin=x_prime[0]; xmax=x_prime[0]; ymin=y_prime[0]; ymax=y_prime[0];
+
+	for (i=1;i<nods_prime;i++){
+		if (x_prime[i]<xmin) xmin=x_prime[i];
+		if (x_prime[i]>xmax) xmax=x_prime[i];
+		if (y_prime[i]<ymin) ymin=y_prime[i];
+		if (y_prime[i]>ymax) ymax=y_prime[i];
+	}
+
+	/*Initialize output*/
+	data_prime=NewVec(nods_prime);
+
+	printf("\n   interpolation progress:   %5.2lf %%",0.0);
+	for (i=0;i<nels_data;i++){
+
+		/*display current iteration*/
+		if (fmod(i,100)==0){
+			printf("\b\b\b\b\b\b\b%5.2lf %%",(double)i/nels_data*100);
+		}
+
+		/*if there is no point inside the domain, go to next iteration*/
+		if ( (x_data[(int)index_data[6*i+0]-1]<xmin) && (x_data[(int)index_data[6*i+1]-1]<xmin) && (x_data[(int)index_data[6*i+2]-1]<xmin)) continue;
+		if ( (x_data[(int)index_data[6*i+0]-1]>xmax) && (x_data[(int)index_data[6*i+1]-1]>xmax) && (x_data[(int)index_data[6*i+2]-1]>xmax)) continue;
+		if ( (y_data[(int)index_data[6*i+0]-1]<ymin) && (y_data[(int)index_data[6*i+1]-1]<ymin) && (y_data[(int)index_data[6*i+2]-1]<ymin)) continue;
+		if ( (y_data[(int)index_data[6*i+0]-1]>ymax) && (y_data[(int)index_data[6*i+1]-1]>ymax) && (y_data[(int)index_data[6*i+2]-1]>ymax)) continue;
+
+		/*get area of the current element (Jacobian = 2 * area)*/
+		//area =x2 * y3 - y2*x3 + x1 * y2 - y1 * x2 + x3 * y1 - y3 * x1;
+		area=x_data[(int)index_data[6*i+1]-1]*y_data[(int)index_data[6*i+2]-1]-y_data[(int)index_data[6*i+1]-1]*x_data[(int)index_data[6*i+2]-1]+ x_data[(int)index_data[6*i+0]-1]*y_data[(int)index_data[6*i+1]-1]-y_data[(int)index_data[6*i+0]-1]*x_data[(int)index_data[6*i+1]-1]+ x_data[(int)index_data[6*i+2]-1]*y_data[(int)index_data[6*i+0]-1]-y_data[(int)index_data[6*i+2]-1]*x_data[(int)index_data[6*i+0]-1];
+
+		/*loop over the prime nodes*/
+		for (j=0;j<nods_prime;j++){
+
+			/*Get first area coordinate = det(x-x3  x2-x3 ; y-y3   y2-y3)/area*/
+			area_1=((x_prime[j]-x_data[(int)index_data[6*i+2]-1])*(y_data[(int)index_data[6*i+1]-1]-y_data[(int)index_data[6*i+2]-1]) -  (y_prime[j]-y_data[(int)index_data[6*i+2]-1])*(x_data[(int)index_data[6*i+1]-1]-x_data[(int)index_data[6*i+2]-1]))/area;
+			/*Get second area coordinate =det(x1-x3  x-x3 ; y1-y3   y-y3)/area*/
+			area_2=((x_data[(int)index_data[6*i+0]-1]-x_data[(int)index_data[6*i+2]-1])*(y_prime[j]-y_data[(int)index_data[6*i+2]-1]) - (y_data[(int)index_data[6*i+0]-1]-y_data[(int)index_data[6*i+2]-1])*(x_prime[j]-x_data[(int)index_data[6*i+2]-1]))/area;
+			/*Get third area coordinate = 1-area1-area2*/
+			area_3=1-area_1-area_2;
+
+			/*is the current point in the current 2d element?*/
+			if ((area_1>0 || area_1==0) && (area_2>0 || area_2==0) && (area_3>0 || area_3==0)){
+
+				/*compute bottom and top height of the element at this 2d position*/
+				bed    =area_1*z_data[(int)index_data[6*i+0]-1]+area_2*z_data[(int)index_data[6*i+1]-1]+area_3*z_data[(int)index_data[6*i+2]-1];
+				surface=area_1*z_data[(int)index_data[6*i+3]-1]+area_2*z_data[(int)index_data[6*i+4]-1]+area_3*z_data[(int)index_data[6*i+5]-1];
+
+				/*Compute zeta*/
+				zeta=2*(z_prime[j]-bed)/(surface-bed)-1;
+
+				if (zeta >=-1 && zeta<=1){
+					if (interpolation_type==1){
+						/*nodal interpolation*/
+						data_value=(1-zeta)/2*(area_1*data[(int)index_data[6*i+0]-1]+area_2*data[(int)index_data[6*i+1]-1]+area_3*data[(int)index_data[6*i+2]-1]) + (1+zeta)/2*(area_1*data[(int)index_data[6*i+3]-1]+area_2*data[(int)index_data[6*i+4]-1]+area_3*data[(int)index_data[6*i+5]-1]);
+					}
+					else{
+						/*element interpolation*/
+						data_value=data[i];
+					}
+
+					/*insert value and go to the next point*/
+					VecSetValue(data_prime,j,data_value,INSERT_VALUES);
+				}
+			}
+		}
+	}
+	printf("\b\b\b\b\b\b\b%5.2lf %%\n",100.0);
+
+	/*Write data: */
+	WriteData(DATAPRIME,data_prime,0,0,"Vector",NULL);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void InterpFromMesh3dUsage(void)
+{
+	_printf_("   usage:\n");
+	_printf_("      data_prime=InterpFromMesh3d(index,x,y,z,data,x_prime,y_prime,z_prime);\n\n");
+	_printf_("   where:\n");
+	_printf_("      x,y,z: coordinates of the nodes where data is defined\n");
+	_printf_("      index: index of the mesh where data is defined\n");
+	_printf_("      data - vector holding the data to be interpolated onto the points.\n");
+	_printf_("      x_prime,y_prime,z_prime: coordinates of the mesh grids onto which we interpolate.\n");
+	_printf_("      data_prime:  vector of prime interpolated data.\n");
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.h
===================================================================
--- /issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.h	(revision 1172)
+++ /issm/trunk/src/mex/InterpFromMesh3d/InterpFromMesh3d.h	(revision 1172)
@@ -0,0 +1,39 @@
+/*!\file InterpFromMesh3d.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _INTERPFROMMESH3D_H
+#define _INTERPFROMMESH3D_H
+
+/* local prototypes: */
+void InterpFromMesh3dUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "InterpFromMesh3d"
+
+#undef CLEANUP
+#define CLEANUP InterpFromMesh3dLocalCleanup();
+
+
+/* serial input macros: */
+#define INDEXHANDLE prhs[0]
+#define XHANDLE prhs[1]
+#define YHANDLE prhs[2]
+#define ZHANDLE prhs[3]
+#define DATAHANDLE prhs[4]
+#define XPRIMEHANDLE prhs[5]
+#define YPRIMEHANDLE prhs[6]
+#define ZPRIMEHANDLE prhs[7]
+
+/* serial output macros: */
+#define DATAPRIME (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  8
+
+#endif  /* _INTERPFROMMESH3D_H */
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 1171)
+++ /issm/trunk/src/mex/Makefile.am	(revision 1172)
@@ -12,5 +12,4 @@
 				ContourToNodes \
 				ControlConstrain \
-				DataInterp \
 				Dof\
 				Du\
@@ -20,4 +19,7 @@
 				GriddataMeshToGrid\
 				HoleFiller \
+				InterpFromGrid \
+				InterpFromMesh2d \
+				InterpFromMesh3d \
 				Mergesolutionfromftog\
 				MeshPartition\
@@ -96,7 +98,4 @@
 			  ControlConstrain/ControlConstrain.h
 
-DataInterp_SOURCES = DataInterp/DataInterp.cpp\
-			  DataInterp/DataInterp.h
-
 Dof_SOURCES = Dof/Dof.cpp\
 			  Dof/Dof.h
@@ -123,4 +122,13 @@
 			  HoleFiller/HoleFiller.h
 
+InterpFromGrid_SOURCES = InterpFromGrid/InterpFromGrid.cpp\
+			  InterpFromGrid/InterpFromGrid.h
+
+InterpFromMesh2d_SOURCES = InterpFromMesh2d/InterpFromMesh2d.cpp\
+							InterpFromMesh2d/InterpFromMesh2d.h
+
+InterpFromMesh3d_SOURCES = InterpFromMesh3d/InterpFromMesh3d.cpp\
+									InterpFromMesh3d/InterpFromMesh3d.h
+
 Mergesolutionfromftog_SOURCES = Mergesolutionfromftog/Mergesolutionfromftog.cpp\
 			  Mergesolutionfromftog/Mergesolutionfromftog.h
