Index: sm/trunk/config.h.in
===================================================================
--- /issm/trunk/config.h.in	(revision 2416)
+++ 	(revision )
@@ -1,91 +1,0 @@
-/* config.h.in.  Generated from configure.ac by autoheader.  */
-
-/* Define if you have Matlab. */
-#undef HAVE_MATLAB
-
-/* with Mpi in ISSM src */
-#undef HAVE_MPI
-
-/* Define to the Matlab major version number. */
-#undef MATLAB_MAJOR
-
-/* Define to the Matlab minor version number. */
-#undef MATLAB_MINOR
-
-/* Define to 1 if your C compiler doesn't accept -c and -o together. */
-#undef NO_MINUS_C_MINUS_O
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* Version number of package */
-#undef VERSION
-
-/* Define to 1 if the X Window System is missing or not being used. */
-#undef X_DISPLAY_MISSING
-
-/* with Blacs in ISSM src */
-#undef _HAVE_BLACS_
-
-/* with blas lapack in ISSM src */
-#undef _HAVE_BLASLAPACK_
-
-/* with Dakota in ISSM src */
-#undef _HAVE_DAKOTA_
-
-/* with FORTRAN in ISSM src */
-#undef _HAVE_FORTRAN_
-
-/* with GRAPHICS in ISSM src */
-#undef _HAVE_GRAPHICS_
-
-/* with MATH in ISSM src */
-#undef _HAVE_MATH_
-
-/* with Matlab in ISSM src */
-#undef _HAVE_MATLAB_
-
-/* with Metis in ISSM src */
-#undef _HAVE_METIS_
-
-/* with mkl in ISSM src */
-#undef _HAVE_MKL_
-
-/* with Mpi in ISSM src */
-#undef _HAVE_MPI_
-
-/* with Mumps in ISSM src */
-#undef _HAVE_MUMPS_
-
-/* with Petsc in ISSM src */
-#undef _HAVE_PETSC_
-
-/* with Plapack in ISSM src */
-#undef _HAVE_PLAPACK_
-
-/* with Scalapack in ISSM src */
-#undef _HAVE_SCALAPACK_
-
-/* with Slepc in ISSM src */
-#undef _HAVE_SLEPC_
-
-/* with Triangle in ISSM src */
-#undef _HAVE_TRIANGLE_
-
-/* Macro to enable debugging in ISSM. */
-#undef _ISSM_DEBUG_
Index: /issm/trunk/configs/linux64/linux64.sh
===================================================================
--- /issm/trunk/configs/linux64/linux64.sh	(revision 2416)
+++ /issm/trunk/configs/linux64/linux64.sh	(revision 2417)
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-./configure --prefix=$ISSM_DIR --with-matlab-dir=$MATLAB_DIR --with-triangle-dir=$ISSM_DIR/externalpackages/triangle/install --with-metis-dir=$ISSM_DIR/externalpackages/metis/install --with-petsc-dir=$ISSM_DIR/externalpackages/petsc/install --with-mpi-include=$ISSM_DIR/externalpackages/mpich2/install/include  --with-mpi-lib="-L$ISSM_DIR/externalpackages/mpich2/install/lib/ -lmpich" --with-petsc-arch=$ISSM_ARCH --with-dakota-dir=$ISSM_DIR/externalpackages/dakota/install --with-blas-lapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/fblaslapack/$ISSM_ARCH --with-plapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/PLAPACKR32/$ISSM_ARCH --with-blacs-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/blacs-dev/$ISSM_ARCH --with-scalapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/SCALAPACK/$ISSM_ARCH --with-mumps-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/MUMPS_4.6.3/$ISSM_ARCH --with-fortran-lib="-L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/ -lgfortran" --with-graphics-lib=/usr/lib64/libX11.so --with-cxxoptflags="-march=opteron -O2"
+./configure --prefix=$ISSM_DIR --with-matlab-dir=$MATLAB_DIR --with-triangle-dir=$ISSM_DIR/externalpackages/triangle/install --with-metis-dir=$ISSM_DIR/externalpackages/metis/install --with-petsc-dir=$ISSM_DIR/externalpackages/petsc/install --with-mpi-include=$ISSM_DIR/externalpackages/mpich2/install/include  --with-mpi-lib="-L$ISSM_DIR/externalpackages/mpich2/install/lib/ -lmpich" --with-petsc-arch=$ISSM_ARCH --with-dakota-dir=$ISSM_DIR/externalpackages/dakota/install --with-blas-lapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/fblaslapack/$ISSM_ARCH --with-plapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/PLAPACKR32/$ISSM_ARCH --with-blacs-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/blacs-dev/$ISSM_ARCH --with-scalapack-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/SCALAPACK/$ISSM_ARCH --with-mumps-dir=$ISSM_DIR/externalpackages/petsc/install/externalpackages/MUMPS_4.6.3/$ISSM_ARCH --with-fortran-lib="-L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/ -lgfortran" --with-graphics-lib=/usr/lib64/libX11.so --with-cxxoptflags="-march=opteron -O2" --with-numthreads=16
Index: /issm/trunk/m4/issm_options.m4
===================================================================
--- /issm/trunk/m4/issm_options.m4	(revision 2416)
+++ /issm/trunk/m4/issm_options.m4	(revision 2417)
@@ -656,4 +656,21 @@
 	dnl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%optimization-end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+	dnl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%multithreading-beginning%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+	AC_ARG_WITH([numthreads],
+			  AS_HELP_STRING([--with-numthreads = NUMTHREADS_VALUE],
+							 [numthreads, default is 1. ]),
+			  [NUMTHREADS_VALUE=$withval],[NUMTHREADS_VALUE=1])
+	AC_MSG_CHECKING(for number of threads)
+	dnl defaults
+	MULTITHREADING=no
+	MULTITHREADINLIB=""
+	if test "$NUMTHREADS_VALUE" != "1"; then
+		MULTITHREADINGLIB="-lpthread"
+		AC_DEFINE([_MULTITHREADING_],[1],[with numthreads enabled])
+		AC_DEFINE_UNQUOTED([_NUMTHREADS_],[$NUMTHREADS_VALUE],[number of threads])
+	fi
+	AC_SUBST([MULTITHREADINGLIB])
+	AC_MSG_RESULT($NUMTHREADS_VALUE) 
+	dnl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%numthreads build-end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 ])
Index: /issm/trunk/scripts/historyISSM.m
===================================================================
--- /issm/trunk/scripts/historyISSM.m	(revision 2416)
+++ /issm/trunk/scripts/historyISSM.m	(revision 2417)
@@ -30,5 +30,15 @@
 md=setelementstype(md,'pattyn','all','stokes','all');
 md=setelementstype(md,'macayeal','all');
+md=solve(md,'analysis_type','diagnostic','batch','yes');
+md=solve(md,'analysis_type','thermal');
+md=solve(md,'analysis_type','thermal','batch','yes');
 %  --  plots  --
 plotmodel(md,'data',md.results.diagnostic.vel)
 print -dpng vel.png
+%  --  setup --
+md=model;
+md=parameterize(md,'Antarctica.par');
+md=geography(md,'','');
+md=geography(md,'Iceshelves.exp','Islands.exp');
+md=extrude(md,8,1);
+md=mesh(md,'DomainOutline.exp',5000);
Index: /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp
===================================================================
--- /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 2416)
+++ /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 2417)
@@ -2,4 +2,11 @@
  * \brief  "c" core code for interpolating values from a structured grid.
  */ 
+
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
 
 #include "./InterpFromMeshToMesh2dx.h"
@@ -8,6 +15,5 @@
 #undef __FUNCT__ 
 #define __FUNCT__ "InterpFromMeshToMesh2dx"
-
-int InterpFromMeshToMesh2dx( Vec* pdata_prime,double* index_data, double* x_data, double* y_data, int nods_data,int nels_data, double* data, int data_length, double* x_prime, double* y_prime, int nods_prime,double default_value) {
+int InterpFromMeshToMesh2dx( Vec* pdata_prime,double* index_data, double* x_data, double* y_data, int nods_data,int nels_data, double* data, int data_length, double* x_prime, double* y_prime, int nods_prime,double default_value){
 
 	/*Output*/
@@ -15,14 +21,13 @@
 
 	/*Intermediary*/
-	int i,j;
+	int i;
 	int interpolation_type;
 	bool debug;
-	double area;
-	double area_1,area_2,area_3;
-	double data_value;
 	double x_prime_min,x_prime_max;
 	double y_prime_min,y_prime_max;
-	double x_tria_min,y_tria_min;
-	double x_tria_max,y_tria_max;
+
+	/*threading: */
+	InterpFromMeshToMesh2dxThreadStruct gate;
+	const int num=_NUMTHREADS_;
 
 	/*some checks*/
@@ -58,73 +63,29 @@
 	for (i=0;i<nods_prime;i++) VecSetValue(data_prime,i,default_value,INSERT_VALUES);
 
-	/*Loop over the elements*/
-	if (debug) printf("      interpolation progress:   %5.2lf %%",0.0);
-	for (i=0;i<nels_data;i++){
+	/*initialize thread parameters: */
+	gate.debug=debug;
+	gate.nods_prime=nods_prime;
+	gate.nels_data=nels_data;
+	gate.x_data=x_data;
+	gate.y_data=y_data;
+	gate.index_data=index_data;
+	gate.x_prime=x_prime;
+	gate.y_prime=y_prime;
+	gate.data=data;
+	gate.interpolation_type=interpolation_type;
+	gate.default_value=default_value;
+	gate.data_prime=data_prime;
+	gate.x_prime_min=x_prime_min;
+	gate.x_prime_max=x_prime_max;
+	gate.y_prime_min=y_prime_min;
+	gate.y_prime_max=y_prime_max;
 
-		/*display current iteration*/
-		if (debug && fmod((double)i,(double)100)==0) printf("\b\b\b\b\b\b\b%5.2lf %%",(double)i/nels_data*100);
-
-		/*Get extrema coordinates of current elements*/
-		x_tria_min=x_data[(int)index_data[3*i+0]-1]; x_tria_max=x_tria_min;
-		y_tria_min=y_data[(int)index_data[3*i+0]-1]; y_tria_max=y_tria_min;
-		for (j=1;j<3;j++){
-			if(x_data[(int)index_data[3*i+j]-1]<x_tria_min) x_tria_min=x_data[(int)index_data[3*i+j]-1];
-			if(x_data[(int)index_data[3*i+j]-1]>x_tria_max) x_tria_max=x_data[(int)index_data[3*i+j]-1];
-			if(y_data[(int)index_data[3*i+j]-1]<y_tria_min) y_tria_min=y_data[(int)index_data[3*i+j]-1];
-			if(y_data[(int)index_data[3*i+j]-1]>y_tria_max) y_tria_max=y_data[(int)index_data[3*i+j]-1];
-		}
-
-		/*if there is no point inside the domain, go to next iteration*/
-		if ( x_prime_max < x_tria_min ) continue; 
-		if ( x_prime_min > x_tria_max ) continue; 
-		if ( y_prime_max < y_tria_min ) continue; 
-		if ( y_prime_min > y_tria_max ) 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++){
-
-			/*if the current point is not in the triangle, continue*/
-			if ( x_prime[j] < x_tria_min ) continue; 
-			if ( x_prime[j] > x_tria_max ) continue; 
-			if ( y_prime[j] < y_tria_min ) continue; 
-			if ( y_prime[j] > y_tria_max ) continue; 
-
-			/*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_2>=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];
-				}
-				if (isnan(data_value)) data_value=default_value;
-
-				/*insert value and go to the next point*/
-				VecSetValue(data_prime,j,data_value,INSERT_VALUES);
-			}
-		}
-	}
-	 if (debug) printf("\b\b\b\b\b\b\b%5.2lf %%\n",100.0);
+	/*launch the thread manager with InterpFromMeshToMesh2dxt as a core: */
+	LaunchThread(InterpFromMeshToMesh2dxt,(void*)&gate,num);
 
 	/*Assign output pointers:*/
 	*pdata_prime=data_prime;
 }
+
+
+
Index: /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h
===================================================================
--- /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h	(revision 2416)
+++ /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h	(revision 2417)
@@ -8,5 +8,32 @@
 #include "../toolkits/toolkits.h"
 
+
+
+/*threading: */
+typedef struct{
+
+	int debug;
+	int nels_data;
+	double* x_data;
+	double* y_data;
+	double* index_data;
+	int nods_prime;
+	double* x_prime;
+	double* y_prime;
+	double* data;
+	int     interpolation_type;
+	double  default_value;
+	Vec     data_prime;
+	double  x_prime_min;
+	double  x_prime_max;
+	double  y_prime_min;
+	double  y_prime_max;
+
+} InterpFromMeshToMesh2dxThreadStruct;
+
+
 int InterpFromMeshToMesh2dx( Vec* pdata_prime,double* index_data, double* x_data, double* y_data, int nods_data,int nels_data, double* data, int data_length, double* x_prime, double* y_prime, int nods_prime,double default_value);
+void* InterpFromMeshToMesh2dxt(void* vInterpFromMeshToMesh2dxThreadStruct);
+
 
 #endif /* _INTERPFROMMESHTOMESH2DX_H */
Index: /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dxt.cpp
===================================================================
--- /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dxt.cpp	(revision 2417)
+++ /issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dxt.cpp	(revision 2417)
@@ -0,0 +1,146 @@
+/*!\file:  InterpFromMeshToMesh2dxt.cpp
+ * \brief  "thread" core code for interpolating values from a structured grid.
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./InterpFromMeshToMesh2dx.h"
+#include "../shared/shared.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__ "InterpFromMeshToMesh2dxt"
+void* InterpFromMeshToMesh2dxt(void* vpthread_handle){
+
+	/*gate variables :*/
+	InterpFromMeshToMesh2dxThreadStruct* gate=NULL;
+	pthread_handle* handle=NULL;
+	int     my_thread;
+	int     num_threads;
+	int     i0;
+	int     i1;
+	int     debug;
+	int     nels_data;
+	double* x_data=NULL;
+	double* y_data=NULL;
+	double* index_data=NULL;
+	int     nods_prime;
+	double* x_prime=NULL;
+	double* y_prime=NULL;
+	double* data=NULL;
+	int     interpolation_type;
+	double  default_value;
+	Vec     data_prime;
+	double x_prime_min,x_prime_max;
+	double y_prime_min,y_prime_max;
+
+	/*local variables: */
+	int    i,j;
+	double x_tria_min,x_tria_max;
+	double y_tria_min,y_tria_max;
+	double area;
+	double area_1,area_2,area_3;
+	double data_value;
+	int    step;
+
+	/*recover handle and gate: */
+	handle=(pthread_handle*)vpthread_handle;
+	gate=(InterpFromMeshToMesh2dxThreadStruct*)handle->gate;
+	my_thread=handle->id;
+	num_threads=handle->num;
+
+	/*recover parameters :*/
+	debug=                gate->debug;
+	nels_data=            gate->nels_data;
+	x_data=               gate->x_data;
+	y_data=               gate->y_data;
+	index_data=           gate->index_data;
+	nods_prime=           gate->nods_prime;
+	x_prime=              gate->x_prime;
+	y_prime=              gate->y_prime;
+	data=                 gate->data;
+	interpolation_type=   gate->interpolation_type;
+	default_value=        gate->default_value;
+	data_prime=           gate->data_prime;
+	x_prime_min=          gate->x_prime_min;
+	x_prime_max=          gate->x_prime_max;
+	y_prime_min=          gate->y_prime_min;
+	y_prime_max=          gate->y_prime_max;
+
+	/*distribute elements across threads :*/
+	step=(int)floor((double)nels_data/(double)num_threads);
+	for(i=0;i<(my_thread+1);i++){
+		i0=i*step;
+		if(i==(num_threads-1))i1=nels_data;
+		else i1=i0+step;
+	}
+	
+	for (i=i0;i<i1;i++){
+
+		/*display current iteration*/
+		if (debug && (my_thread==0) && fmod((double)(i-i0),(double)100)==0) printf("\b\b\b\b\b\b\b%5.2lf %%",(double)(i-i0)/(i1-i0)*100);
+
+		/*Get extrema coordinates of current elements*/
+		x_tria_min=x_data[(int)index_data[3*i+0]-1]; x_tria_max=x_tria_min;
+		y_tria_min=y_data[(int)index_data[3*i+0]-1]; y_tria_max=y_tria_min;
+		
+		for (j=1;j<3;j++){
+			if(x_data[(int)index_data[3*i+j]-1]<x_tria_min) x_tria_min=x_data[(int)index_data[3*i+j]-1];
+			if(x_data[(int)index_data[3*i+j]-1]>x_tria_max) x_tria_max=x_data[(int)index_data[3*i+j]-1];
+			if(y_data[(int)index_data[3*i+j]-1]<y_tria_min) y_tria_min=y_data[(int)index_data[3*i+j]-1];
+			if(y_data[(int)index_data[3*i+j]-1]>y_tria_max) y_tria_max=y_data[(int)index_data[3*i+j]-1];
+		}
+
+		/*if there is no point inside the domain, go to next iteration*/
+		if ( x_prime_max < x_tria_min ) continue; 
+		if ( x_prime_min > x_tria_max ) continue; 
+		if ( y_prime_max < y_tria_min ) continue; 
+		if ( y_prime_min > y_tria_max ) 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++){
+
+			/*if the current point is not in the triangle, continue*/
+			if ( x_prime[j] < x_tria_min ) continue; 
+			if ( x_prime[j] > x_tria_max ) continue; 
+			if ( y_prime[j] < y_tria_min ) continue; 
+			if ( y_prime[j] > y_tria_max ) continue; 
+
+			/*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_2>=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];
+				}
+				if (isnan(data_value)) data_value=default_value;
+
+				/*insert value and go to the next point*/
+				VecSetValue(data_prime,j,data_value,INSERT_VALUES);
+			}
+		}
+	}
+}
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 2416)
+++ /issm/trunk/src/c/Makefile.am	(revision 2417)
@@ -87,4 +87,6 @@
 					./shared/Alloc/alloc.h\
 					./shared/Alloc/alloc.cpp\
+					./shared/Threads/issm_threads.h\
+					./shared/Threads/LaunchThread.cpp\
 					./shared/Matlab/matlabshared.h\
 					./shared/Matlab/PrintfFunction.cpp\
@@ -248,4 +250,5 @@
 					./InterpFromGridToMeshx/InterpFromGridToMeshx.h\
 					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\
+					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dxt.cpp\
 					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h\
 					./InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp\
@@ -381,4 +384,6 @@
 					./DataSet/DataSet.h\
 					./shared/shared.h\
+					./shared/Threads/issm_threads.h\
+					./shared/Threads/LaunchThread.cpp\
 					./shared/Alloc/alloc.h\
 					./shared/Alloc/alloc.cpp\
@@ -541,4 +546,5 @@
 					./InterpFromGridToMeshx/InterpFromGridToMeshx.h\
 					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\
+					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dxt.cpp\
 					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h\
 					./InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp\
Index: /issm/trunk/src/c/objects/Tria.cpp
===================================================================
--- /issm/trunk/src/c/objects/Tria.cpp	(revision 2416)
+++ /issm/trunk/src/c/objects/Tria.cpp	(revision 2417)
@@ -3668,5 +3668,5 @@
 
 		/*Calculate scalar parameter*/
-		scalar_ocean=gauss_weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_velocity*t_pmp/(heatcapacity*rho_ice);
+		scalar_ocean=gauss_weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_velocity*(t_pmp)/(heatcapacity*rho_ice);
 		if(dt){
 			scalar_ocean=dt*scalar_ocean;
Index: /issm/trunk/src/c/shared/Threads/LaunchThread.cpp
===================================================================
--- /issm/trunk/src/c/shared/Threads/LaunchThread.cpp	(revision 2417)
+++ /issm/trunk/src/c/shared/Threads/LaunchThread.cpp	(revision 2417)
@@ -0,0 +1,67 @@
+/*!\file:  LaunchThread.cpp
+ * \brief  launch thread in a generic way, covering single and multi-threaded cases
+ * This routine attempts to simplify management of multi-threading. When multi-threadeing 
+ * is not requested (serial run), LaunchThread will just call the function (provided in argument 
+ * list), nothing fancy there.  If multi-threading is requested, LaunchThread will launch the 
+ * function on multiple threads (num_threads of them), and provide these functions with the 
+ * local data they need (folded in the "gate" structure) + the thread id + the number of threads 
+ * All this info is collected in the pthread_handle structure. 
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#ifdef _MULTITHREADING_
+#include <pthread.h>
+#endif
+
+#include "./issm_threads.h"
+#include "../Alloc/alloc.h"
+#include "../Exceptions/exceptions.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__ "LaunchThread"
+
+void LaunchThread(void* function(void*), void* gate,int num_threads){
+
+	#ifdef _MULTITHREADING_
+	int i;
+	int* status=NULL;
+
+	pthread_t* threads=NULL;
+	pthread_handle* handles=NULL;
+	
+	/*dynamically allocate: */
+	threads=(pthread_t*)xmalloc(num_threads*sizeof(pthread_t));
+	handles=(pthread_handle*)xmalloc(num_threads*sizeof(pthread_handle));
+
+	for(i=0;i<num_threads;i++){
+		handles[i].gate=gate;
+		handles[i].id=i;
+		handles[i].num=num_threads;
+	}
+	
+	for(i=0;i<num_threads;i++){
+
+		if(pthread_create(threads+i,NULL,function,(void*)(handles+i))){
+			throw ErrorException(__FUNCT__," pthread_create error");
+		}
+	}
+	for(i=0;i<num_threads;i++){
+		if(pthread_join(threads[i],(void**)&status)){
+			throw ErrorException(__FUNCT__," pthread_join error");
+		}
+	}
+	
+	/*Free ressources:*/
+	xfree((void**)&threads);
+	xfree((void**)&handles);
+
+	#else
+	function(&gate);
+	#endif
+
+}
Index: /issm/trunk/src/c/shared/Threads/issm_threads.h
===================================================================
--- /issm/trunk/src/c/shared/Threads/issm_threads.h	(revision 2417)
+++ /issm/trunk/src/c/shared/Threads/issm_threads.h	(revision 2417)
@@ -0,0 +1,21 @@
+/*!\file: issm_threads.h
+ * \brief prototypes for issm_threads.h
+ */ 
+
+#ifndef _ISSM_THREADS_H_
+#define  _ISSM_THREADS_H_
+
+/*structure that holds the local data for each thread (in the gate), 
+ * + the thread specific information (my id + number of threads) : */
+typedef struct{
+	void* gate;
+	int   id;
+	int   num;
+} pthread_handle;
+
+
+/*routine that launches "function" in a multi-threaded way if requested, 
+ * or just serially if not requested: */
+void LaunchThread(void* function(void*), void* gate,int num_threads);
+
+#endif //ifndef _ISSM_THREADS_H_
Index: /issm/trunk/src/c/shared/shared.h
===================================================================
--- /issm/trunk/src/c/shared/shared.h	(revision 2416)
+++ /issm/trunk/src/c/shared/shared.h	(revision 2417)
@@ -18,4 +18,5 @@
 #include "Dofs/dofs.h"
 #include "String/sharedstring.h" //to avoid confusion with <string.h> standard header file
+#include "Threads/issm_threads.h"
 
 
Index: /issm/trunk/src/m/classes/public/basalstress.m
===================================================================
--- /issm/trunk/src/m/classes/public/basalstress.m	(revision 2416)
+++ /issm/trunk/src/m/classes/public/basalstress.m	(revision 2417)
@@ -1,17 +1,10 @@
-function [bx by b]=basalstress(md,options_structure,width,i,type);
+function [bx by b]=basalstress(md)
 %BASALSTRESS - compute basal stress from basal drag and geometric information. 
 %
 %   Usage:
-%      basalstress(md,options_structure,width,i,type);
+%      [bx by b]=basalstress(md);
 %
 %   See also: plot_basaldrag
 
-%check layer
-if strcmpi(md.type,'3d')
-	if options_structure.layer~=1,
-		disp('plot_basaldrag warning: basal drag is displayed in the lower layer')
-		options_structure.layer=1;
-	end
-end
 
 %compute exponents
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 2416)
+++ /issm/trunk/src/mex/Makefile.am	(revision 2417)
@@ -57,7 +57,5 @@
 
 
-#LDADD =   $(TRIANGLELIB)  $(PETSCLIB)  ../c/libISSM.a  $(METISLIB) $(FLIBS)  $(PLAPACKLIB) $(SCALAPACKLIB) $(BLASLAPACKLIB) $(MUMPSLIB) $(BLACSLIB) $(DAKOTALIB)  $(MPILIB) $(MEXLIB) $(MATHLIB) $(FORTRANLIB)
-
-LDADD =   $(TRIANGLELIB) ../c/libISSM.a $(PETSCLIB)   $(FLIBS)  $(PLAPACKLIB)  $(MUMPSLIB) $(SCALAPACKLIB)  $(BLACSLIB)  $(DAKOTALIB) $(METISLIB) $(BLASLAPACKLIB)  $(MPILIB) $(MATHLIB) $(FORTRANLIB) $(GRAPHICSLIB)
+LDADD =   $(TRIANGLELIB) ../c/libISSM.a $(PETSCLIB)   $(FLIBS)  $(PLAPACKLIB)  $(MUMPSLIB) $(SCALAPACKLIB)  $(BLACSLIB)  $(DAKOTALIB) $(METISLIB) $(BLASLAPACKLIB)  $(MPILIB) $(MATHLIB) $(FORTRANLIB) $(GRAPHICSLIB) $(MULTITHREADINGLIB)
 
 AM_LDFLAGS = $(MEXLINK)
