Index: /issm/trunk/autom4te.cache/traces.0
===================================================================
--- /issm/trunk/autom4te.cache/traces.0	(revision 131)
+++ /issm/trunk/autom4te.cache/traces.0	(revision 132)
@@ -1,3 +1,3 @@
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/amversion.m4:20: -1- AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.10'
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/amversion.m4:20: -1- AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.10'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
@@ -5,14 +5,14 @@
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/amversion.m4:37: -1- AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.10.2])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/amversion.m4:37: -1- AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.10.2])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/auxdir.m4:52: -1- AC_DEFUN([AM_AUX_DIR_EXPAND], [dnl Rely on autoconf to set up CDPATH properly.
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/auxdir.m4:52: -1- AC_DEFUN([AM_AUX_DIR_EXPAND], [dnl Rely on autoconf to set up CDPATH properly.
 AC_PREREQ([2.50])dnl
 # expand $ac_aux_dir to an absolute path
 am_aux_dir=`cd $ac_aux_dir && pwd`
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/cond.m4:34: -1- AC_DEFUN([AM_CONDITIONAL], [AC_PREREQ(2.52)dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/cond.m4:34: -1- AC_DEFUN([AM_CONDITIONAL], [AC_PREREQ(2.52)dnl
  ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
 	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
@@ -33,5 +33,5 @@
 Usually this means the macro was only invoked conditionally.]])
 fi])])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/depend.m4:132: -1- AC_DEFUN([_AM_DEPENDENCIES], [AC_REQUIRE([AM_SET_DEPDIR])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/depend.m4:132: -1- AC_DEFUN([_AM_DEPENDENCIES], [AC_REQUIRE([AM_SET_DEPDIR])dnl
 AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
 AC_REQUIRE([AM_MAKE_INCLUDE])dnl
@@ -137,8 +137,8 @@
   && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/depend.m4:142: -1- AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/depend.m4:142: -1- AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl
 AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/depend.m4:158: -1- AC_DEFUN([AM_DEP_TRACK], [AC_ARG_ENABLE(dependency-tracking,
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/depend.m4:158: -1- AC_DEFUN([AM_DEP_TRACK], [AC_ARG_ENABLE(dependency-tracking,
 [  --disable-dependency-tracking  speeds up one-time build
   --enable-dependency-tracking   do not reject slow dependency extractors])
@@ -151,5 +151,5 @@
 _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/depout.m4:63: -1- AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], [# Autoconf 2.62 quotes --file arguments for eval, but not when files
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/depout.m4:63: -1- AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], [# Autoconf 2.62 quotes --file arguments for eval, but not when files
 # are listed without --file.  Let's play safe and only enable the eval
 # if we detect the quoting.
@@ -200,13 +200,13 @@
 done
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/depout.m4:77: -1- AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles],
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/depout.m4:77: -1- AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles],
      [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
      [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/header.m4:12: -1- AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/header.m4:12: -1- AC_DEFUN([AM_CONFIG_HEADER], [AC_DIAGNOSE([obsolete], [The macro `AM_CONFIG_HEADER' is obsolete.
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/header.m4:12: -1- AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)])
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/header.m4:12: -1- AC_DEFUN([AM_CONFIG_HEADER], [AC_DIAGNOSE([obsolete], [The macro `AM_CONFIG_HEADER' is obsolete.
 You should run autoupdate.])dnl
 AC_CONFIG_HEADERS($@)])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/init.m4:103: -1- AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.60])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/init.m4:103: -1- AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.60])dnl
 dnl Autoconf wants to disallow AM_ names.  We explicitly allow
 dnl the ones we care about.
@@ -285,5 +285,5 @@
 ])
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/init.m4:125: -1- AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], [# Compute $1's index in $config_headers.
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/init.m4:125: -1- AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], [# Compute $1's index in $config_headers.
 _am_arg=$1
 _am_stamp_count=1
@@ -297,8 +297,8 @@
 done
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/install-sh.m4:14: -1- AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/install-sh.m4:14: -1- AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 install_sh=${install_sh-"\$(SHELL) $am_aux_dir/install-sh"}
 AC_SUBST(install_sh)])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/lead-dot.m4:21: -1- AC_DEFUN([AM_SET_LEADING_DOT], [rm -rf .tst 2>/dev/null
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/lead-dot.m4:21: -1- AC_DEFUN([AM_SET_LEADING_DOT], [rm -rf .tst 2>/dev/null
 mkdir .tst 2>/dev/null
 if test -d .tst; then
@@ -309,5 +309,5 @@
 rmdir .tst 2>/dev/null
 AC_SUBST([am__leading_dot])])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/make.m4:51: -1- AC_DEFUN([AM_MAKE_INCLUDE], [am_make=${MAKE-make}
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/make.m4:51: -1- AC_DEFUN([AM_MAKE_INCLUDE], [am_make=${MAKE-make}
 cat > confinc << 'END'
 am__doit:
@@ -346,5 +346,5 @@
 rm -f confinc confmf
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/minuso.m4:35: -1- AC_DEFUN([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC_C_O])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/minuso.m4:35: -1- AC_DEFUN([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC_C_O])dnl
 AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 AC_REQUIRE_AUX_FILE([compile])dnl
@@ -367,8 +367,8 @@
           [m4_fatal([AC_PROG_CC cannot be called after AM_PROG_CC_C_O])])
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/missing.m4:17: -1- AC_DEFUN([AM_MISSING_PROG], [AC_REQUIRE([AM_MISSING_HAS_RUN])
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/missing.m4:17: -1- AC_DEFUN([AM_MISSING_PROG], [AC_REQUIRE([AM_MISSING_HAS_RUN])
 $1=${$1-"${am_missing_run}$2"}
 AC_SUBST($1)])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/missing.m4:35: -1- AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/missing.m4:35: -1- AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 AC_REQUIRE_AUX_FILE([missing])dnl
 test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing"
@@ -381,5 +381,5 @@
 fi
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/mkdirp.m4:26: -1- AC_DEFUN([AM_PROG_MKDIR_P], [AC_PREREQ([2.60])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/mkdirp.m4:26: -1- AC_DEFUN([AM_PROG_MKDIR_P], [AC_PREREQ([2.60])dnl
 AC_REQUIRE([AC_PROG_MKDIR_P])dnl
 dnl Automake 1.8 to 1.9.6 used to define mkdir_p.  We now use MKDIR_P,
@@ -396,14 +396,14 @@
 esac
 ])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/options.m4:14: -1- AC_DEFUN([_AM_MANGLE_OPTION], [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/options.m4:20: -1- AC_DEFUN([_AM_SET_OPTION], [m4_define(_AM_MANGLE_OPTION([$1]), 1)])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/options.m4:26: -1- AC_DEFUN([_AM_SET_OPTIONS], [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/options.m4:32: -1- AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/runlog.m4:17: -1- AC_DEFUN([AM_RUN_LOG], [{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/options.m4:14: -1- AC_DEFUN([_AM_MANGLE_OPTION], [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/options.m4:20: -1- AC_DEFUN([_AM_SET_OPTION], [m4_define(_AM_MANGLE_OPTION([$1]), 1)])
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/options.m4:26: -1- AC_DEFUN([_AM_SET_OPTIONS], [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/options.m4:32: -1- AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/runlog.m4:17: -1- AC_DEFUN([AM_RUN_LOG], [{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD
    ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
    ac_status=$?
    echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
    (exit $ac_status); }])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/sanity.m4:51: -1- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane])
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/sanity.m4:51: -1- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane])
 # Just in case
 sleep 1
@@ -442,5 +442,5 @@
 fi
 AC_MSG_RESULT(yes)])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/strip.m4:28: -1- AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/strip.m4:28: -1- AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
 # Installed binaries are usually stripped using `strip' when the user
 # run `make install-strip'.  However `strip' might not be the right
@@ -453,6 +453,6 @@
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/substnot.m4:12: -1- AC_DEFUN([_AM_SUBST_NOTMAKE])
-m4trace:/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/tar.m4:95: -1- AC_DEFUN([_AM_PROG_TAR], [# Always define AMTAR for backward compatibility.
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/substnot.m4:12: -1- AC_DEFUN([_AM_SUBST_NOTMAKE])
+m4trace:/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/tar.m4:95: -1- AC_DEFUN([_AM_PROG_TAR], [# Always define AMTAR for backward compatibility.
 AM_MISSING_PROG([AMTAR], [tar])
 m4_if([$1], [v7],
@@ -1664,5 +1664,5 @@
 m4trace:configure.ac:2: -1- AM_CONFIG_HEADER([config.h])
 m4trace:configure.ac:2: -1- _m4_warn([obsolete], [The macro `AM_CONFIG_HEADER' is obsolete.
-You should run autoupdate.], [/u/wilkes-r1b/larour/Bin/automake/share/aclocal-1.10/header.m4:12: AM_CONFIG_HEADER is expanded from...
+You should run autoupdate.], [/u/astrid1/larour/issm/trunk/devpackages/automake/install/share/aclocal-1.10/header.m4:12: AM_CONFIG_HEADER is expanded from...
 configure.ac:2: the top level])
 m4trace:configure.ac:3: -1- m4_pattern_allow([^build$])
Index: /issm/trunk/src/c/GriddataMeshToGridx/GriddataMeshToGridx.cpp
===================================================================
--- /issm/trunk/src/c/GriddataMeshToGridx/GriddataMeshToGridx.cpp	(revision 132)
+++ /issm/trunk/src/c/GriddataMeshToGridx/GriddataMeshToGridx.cpp	(revision 132)
@@ -0,0 +1,183 @@
+/*!\file GriddataMeshToGridx
+ * \brief: griddata from a mesh to a regular grid
+ */
+
+#include "./GriddataMeshToGridx.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__ "GriddataMeshToGridx"
+
+#include "../shared/shared.h"
+#include "../include/macros.h"
+#include "../toolkits/toolkits.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+
+
+
+void GriddataMeshToGridx( double** pgriddata,double*  index,int nel,double* x,double* y,int nods, Contour** contours,int numcontours,
+		double* meshdata,double cornereast,double cornernorth,double xposting,double yposting,int nlines,int ncols,
+		int interpolation,int filter,int windowsize){
+
+	int			i,j,k,l;
+	int         ii,jj;
+	int         maxi;
+
+	/*output: */
+	double* griddata=NULL;
+	int*    sparsity=NULL;
+	
+	
+	/*intermediary: */
+	double  cornersouth;
+	int     gridi, gridj;
+	double  xi,yi,value;
+	int     gridi0,gridi1,gridj0,gridj1;
+	double* in_nods=NULL;
+
+	/*Contour:*/
+	Contour* contouri=NULL;
+	int      numgrids;
+	double*  xc=NULL;
+	double*  yc=NULL;
+
+
+	
+
+
+	/*First, allocate griddata: */
+	griddata=(double*)xcalloc(nlines*ncols,sizeof(double));
+	sparsity=(int*)xcalloc(nlines*ncols,sizeof(int));
+	
+	/*Build cornersouth: */
+	cornersouth=cornernorth-nlines*yposting;
+
+	/*Split according to type of interpolation being carried out: */
+	if (interpolation==0){
+		maxi=nods;
+	}
+	else if (interpolation==0){
+		maxi=nel;
+	}
+	else{
+		throw ErrorException(__FUNCT__," interpolation type not supported yet!");
+	}
+	
+	/*Go through grids or elements, and for each grid or element, plug meshdata value into gridded data:*/
+	for(i=0;i<maxi;i++){
+		
+		if (interpolation==0){
+			xi=x[i];
+			yi=y[i];
+		}
+		else{
+			xi=(x[(int)*(index+3*i+0)-1]+ x[(int)*(index+3*i+1)-1]+ x[(int)*(index+3*i+2)-1])/3.0;
+			yi=(y[(int)*(index+3*i+0)-1]+ y[(int)*(index+3*i+1)-1]+ y[(int)*(index+3*i+2)-1])/3.0;
+		}
+
+		value=meshdata[i];
+
+		/*Find grid cell into which we are plugging value: */
+		gridi=(int)floor((yi-cornersouth)/yposting);
+		gridj=(int)floor((xi-cornereast)/xposting);
+
+		if (gridi<0)continue;
+		if (gridj<0)continue;
+		if (gridi>=nlines)continue;
+		if (gridj>=ncols)continue;
+
+	
+		/*printf("yi %g cornersouth %g posting %g yi-cornersouth %g gridi %i\n",yi,cornersouth,posting,yi-cornersouth,gridi);
+		printf("xi %g cornereast %g posting %g xi-cornereast %g gridj %i\n",xi,cornereast,posting,xi-cornereast,gridj);*/
+
+		/*Now, we need a filter box. Ie, build a box around (gridi,gridj): */;
+		gridi0=gridi-windowsize;
+		if(gridi0<0)gridi0=0;
+		gridi1=gridi+windowsize;
+		if(gridi1>=nlines)gridi1=nlines-1;
+
+		gridj0=gridj-windowsize;
+		if(gridj0<0)gridj0=0;
+		gridj1=gridj+windowsize;
+		if(gridj1>=ncols)gridj1=ncols-1;
+
+		/*Using this box, we add value in the box. If filter is average, we add 1 to sparsity for each member of this 
+		 * box, if filter is nearest, we set 1 to sparisty for each member of this box: */
+
+		if(filter==0){
+			/*average: */
+			for(ii=gridi0;ii<=gridi1;ii++){
+				for(jj=gridj0;jj<=gridj1;jj++){
+					*(griddata+ncols*ii+jj) +=value;
+					*(sparsity+ncols*ii+jj) +=1;
+				}
+			}
+		}
+		else if(filter==1){
+			/*nearest: */
+			for(ii=gridi0;ii<=gridi1;ii++){
+				for(jj=gridj0;jj<=gridj1;jj++){
+					*(griddata+ncols*ii+jj)=value;
+					*(sparsity+ncols*ii+jj)=1;
+				}
+			}
+		}
+	} //for(i=0;i<maxi;i++)
+	
+
+	/*Ok, now we have griddata, and sparsity. Divide griddata by sparsity: */
+	for(i=0;i<nlines;i++){
+		for(j=0;j<ncols;j++){
+			if (*(griddata+ncols*i+j)!=0){
+				*(griddata+ncols*i+j)= *(griddata+ncols*i+j) / *(sparsity+ncols*i+j);
+			}
+		}
+	}
+
+	/*Ok, last thing, we need to be sure that our filtering did not introduce values outside our original mesh. 
+	 *Go through the contours (which are the outer boundaries and holes of the mesh), and anything outside must be 0. 
+	 *We need a list of x and y positions for each grid:*/
+	x=(double*)xmalloc(nlines*ncols*sizeof(double));
+	y=(double*)xmalloc(nlines*ncols*sizeof(double));
+	in_nods=(double*)xcalloc(nlines*ncols,sizeof(double));
+	for(i=0;i<nlines;i++){
+		for(j=0;j<ncols;j++){
+			x[i*ncols+j]=cornereast+xposting*j;
+			y[i*ncols+j]=cornersouth+yposting*i;
+		}
+	}
+	for (i=0;i<numcontours;i++){
+		#ifdef _DEBUG_
+			_printf_("Handling contour %i/%i\n",i,numcontours);
+		#endif
+		contouri=*(contours+i);
+		numgrids=contouri->nods;
+		xc=contouri->x;
+		yc=contouri->y;
+
+		IsInPolySerial(in_nods,xc,yc,numgrids,x,y,nlines*ncols,2);
+
+		if (i==0){
+			/*Dealing with domain outline, exclude all grids outside the domain outline : */
+			for(k=0;k<nlines;k++){
+				for(l=0;l<ncols;l++){
+					if (in_nods[k*ncols+l]==0){
+						*(griddata+ncols*k+l)=0;
+					}
+				}
+			}
+		}
+		else{
+			/*Dealing with holes, exclude all grids inside holes: */
+			for(k=0;k<nlines;k++){
+				for(l=0;l<ncols;l++){
+					if (in_nods[k*ncols+l]==1)*(griddata+ncols*k+l)=0;
+				}
+			}
+		}
+
+	}
+
+
+	/*Assign output pointers: */
+	*pgriddata=griddata;
+}
Index: /issm/trunk/src/c/GriddataMeshToGridx/GriddataMeshToGridx.h
===================================================================
--- /issm/trunk/src/c/GriddataMeshToGridx/GriddataMeshToGridx.h	(revision 132)
+++ /issm/trunk/src/c/GriddataMeshToGridx/GriddataMeshToGridx.h	(revision 132)
@@ -0,0 +1,16 @@
+/*!\file:  GriddataMeshToGridx.h
+ * \brief header file for griddata mesh to grid
+ */ 
+
+#ifndef _GRIDDATAMESHTOGRIDX_H
+#define _GRIDDATAMESHTOGRIDX_H
+
+#include "../objects/Contour.h"
+
+/* local prototypes: */
+void GriddataMeshToGridx( double** pgriddata,double*  index,int nel,double* x,double* y,int nods,
+		Contour** contours,int numcontours,double* meshdata,double cornereast,double cornernorth,double xposting,double yposting,int nlines,int ncols,
+		int interpolation,int filter,int windowsize);
+
+#endif  /* _GRIDDATAMESHTOGRIDX_H */
+
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 131)
+++ /issm/trunk/src/c/Makefile.am	(revision 132)
@@ -171,4 +171,6 @@
 					./Dux/Dux.h\
 					./Dux/Dux.cpp\
+					./GriddataMeshToGridx/GriddataMeshToGridx.h\
+					./GriddataMeshToGridx/GriddataMeshToGridx.cpp\
 					./ControlConstrainx/ControlConstrainx.h\
 					./ControlConstrainx/ControlConstrainx.cpp\
@@ -389,4 +391,6 @@
 					./Dux/Dux.h\
 					./Dux/Dux.cpp\
+					./GriddataMeshToGridx/GriddataMeshToGridx.h\
+					./GriddataMeshToGridx/GriddataMeshToGridx.cpp\
 					./ControlConstrainx/ControlConstrainx.h\
 					./ControlConstrainx/ControlConstrainx.cpp\
Index: /issm/trunk/src/c/issm.h
===================================================================
--- /issm/trunk/src/c/issm.h	(revision 131)
+++ /issm/trunk/src/c/issm.h	(revision 132)
@@ -45,4 +45,5 @@
 #include "./ControlConstrainx/ControlConstrainx.h"
 #include "./VelocityExtrudex/VelocityExtrudex.h"
+#include "./GriddataMeshToGridx/GriddataMeshToGridx.h"
 
 
Index: /issm/trunk/src/m/classes/public/ismodelselfconsistent.m
===================================================================
--- /issm/trunk/src/m/classes/public/ismodelselfconsistent.m	(revision 131)
+++ /issm/trunk/src/m/classes/public/ismodelselfconsistent.m	(revision 132)
@@ -331,4 +331,13 @@
 end
 
+%MESH2GRID
+if strcmpi(solutiontype,'mesh2grid'),
+	if ~strcmpi(md.cluster,'none'),
+		disp(['model is not correctly configured: mesh2grid not supported in parallel yet!']);
+		bool=0;return;
+	end
+end
+
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  PACKAGE CHECKS   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
Index: /issm/trunk/src/m/classes/public/solve.m
===================================================================
--- /issm/trunk/src/m/classes/public/solve.m	(revision 131)
+++ /issm/trunk/src/m/classes/public/solve.m	(revision 132)
@@ -50,11 +50,8 @@
 usenamespace(package);
 
-%Check model is self-consistent
-if ~strcmpi(solutiontype,'mesh2grid'),
-	disp(sprintf('\n%s','checking model consistency'));
-	if ~ismodelselfconsistent(md,solutiontype,package),
+if ~ismodelselfconsistent(md,solutiontype,package),
 		error(' '); %previous error messages should explain what is going on.
-	end
 end
+
 disp('launching solution sequence');
 
Index: sm/trunk/src/m/solutions/cielo/cielo/cielomesh2grid.m
===================================================================
--- /issm/trunk/src/m/solutions/cielo/cielo/cielomesh2grid.m	(revision 131)
+++ 	(revision )
@@ -1,37 +1,0 @@
-function md=cielomesh2grid(md)
-%INPUT function md=cielomesh2grid(md)
-%mesh2grid solution
-
-	%timing
-	t1=clock;
-
-	analysis='mesh2grid';
-
-	%configure, and initialise data model and parameter defaults:
-	SetParameterDefaults;
-
-	%Initialize results
-	md.mesh2grid_results=cell(length(md.mesh2grid_parameters),1);
-
-	%Recover domain outline as a contour structure. 
-	writefile('contours.exp',md.domainoutline);
-	contours=expread('contours.exp',0);
-	contours=contours(1); %just keep the outer domain outline.
-	delete('contours.exp');
-   
-	%loop on the number of mesh2grid parameters:
-	for i=1:length(md.mesh2grid_parameters),
-		parameter=eval(['md.' md.mesh2grid_parameters{i}]);
-
-		%call GriddataMeshToGrid module:
-		md.mesh2grid_results{i}=...
-			GriddataMeshToGrid( md.elements,md.x,md.y,contours,parameter,md.mesh2grid_cornereast,md.mesh2grid_cornernorth,...
-					md.mesh2grid_xposting,md.mesh2grid_yposting,md.mesh2grid_nlines,md.mesh2grid_ncolumns,md.mesh2grid_interpolation{i},...
-					md.mesh2grid_filter{i},md.mesh2grid_windowsize);
-		
-	end
-
-
-	%timing
-	t2=clock;
-	disp(sprintf('\n%s\n',['   solution lasted ' num2str(etime(t2,t1)) ' seconds']));
Index: /issm/trunk/src/m/solutions/cielo/mesh2grid.m
===================================================================
--- /issm/trunk/src/m/solutions/cielo/mesh2grid.m	(revision 132)
+++ /issm/trunk/src/m/solutions/cielo/mesh2grid.m	(revision 132)
@@ -0,0 +1,34 @@
+function md=mesh2grid(md)
+%MESH2GRID - mesh2grid solution sequence
+%
+%   Usage:
+%      md=mesh2grid(md)
+
+	%timing
+	t1=clock;
+
+	%Initialize results
+	md.mesh2grid_results=cell(length(md.mesh2grid_parameters),1);
+
+	%Recover domain outline as a contour structure. 
+	writefile('contours.exp',md.domainoutline);
+	contours=expread('contours.exp',0);
+	contours=contours(1); %just keep the outer domain outline.
+	delete('contours.exp');
+   
+	%loop on the number of mesh2grid parameters:
+	for i=1:length(md.mesh2grid_parameters),
+		parameter=eval(['md.' md.mesh2grid_parameters{i}]);
+
+		%call GriddataMeshToGrid module:
+		md.mesh2grid_results{i}=...
+			GriddataMeshToGrid( md.elements,md.x,md.y,contours,parameter,md.mesh2grid_cornereast,md.mesh2grid_cornernorth,...
+					md.mesh2grid_xposting,md.mesh2grid_yposting,md.mesh2grid_nlines,md.mesh2grid_ncolumns,md.mesh2grid_interpolation{i},...
+					md.mesh2grid_filter{i},md.mesh2grid_windowsize);
+		
+	end
+
+
+	%timing
+	t2=clock;
+	disp(sprintf('\n%s\n',['   solution lasted ' num2str(etime(t2,t1)) ' seconds']));
Index: /issm/trunk/src/mex/GriddataMeshToGrid/GriddataMeshToGrid.cpp
===================================================================
--- /issm/trunk/src/mex/GriddataMeshToGrid/GriddataMeshToGrid.cpp	(revision 132)
+++ /issm/trunk/src/mex/GriddataMeshToGrid/GriddataMeshToGrid.cpp	(revision 132)
@@ -0,0 +1,113 @@
+/*\file GriddataMeshToGrid.c
+ *\brief: compute diff between observed and modeled velocity
+ */
+
+#include "./GriddataMeshToGrid.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*diverse: */
+	int i;
+
+	/*input datasets: */
+	double* index=NULL;
+	int     nel;
+	double* x=NULL;
+	int     nods;
+	double* y=NULL;
+	double* meshdata=NULL;
+	double  cornereast;
+	double  cornernorth;
+	double  xposting;
+	double  yposting;
+	int     nlines,ncols;
+	char*   interpolationtype;
+	int     interpolation;
+	char*   filterstring=NULL;
+	int     filter;
+	int     windowsize;
+	
+	//contours
+	int numcontours;
+	Contour** contours=NULL;
+	Contour*  contouri=NULL;
+
+	/* output datasets: */
+	double* griddata=NULL;
+
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&GriddataMeshToGridUsage);
+
+	/*Input datasets: */
+	FetchData((void**)&index,&nel,NULL,INDEX,"Matrix","Mat");
+	FetchData((void**)&x,&nods,NULL,X,"Matrix","Mat");
+	FetchData((void**)&y,NULL,NULL,Y,"Matrix","Mat");
+
+	/*Recover list of contours from the 'contours' structure: */
+	//number of contours;
+	numcontours=mxGetNumberOfElements(CONTOURS);
+	//allocate array:
+	contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+
+	//go through contours, and populate xcontours and ycontours accordingly.
+	for(i=0;i<numcontours;i++){
+		//allocate
+		contouri=(Contour*)xmalloc(sizeof(Contour));
+		//retrieve dimension of this contour.
+		contouri->nods=(int)mxGetScalar(mxGetField(CONTOURS,i,"nods"));
+		//set pointers.
+		contouri->x=mxGetPr(mxGetField(CONTOURS,i,"x"));
+		contouri->y=mxGetPr(mxGetField(CONTOURS,i,"y"));
+		*(contours+i)=contouri;
+	}
+
+	FetchData((void**)&meshdata,NULL,NULL,MESHDATA,"Matrix","Mat");
+	FetchData((void**)&cornereast,NULL,NULL,CORNEREAST,"Scalar",NULL);
+	FetchData((void**)&cornernorth,NULL,NULL,CORNERNORTH,"Scalar",NULL);
+	FetchData((void**)&xposting,NULL,NULL,XPOSTING,"Scalar",NULL);
+	FetchData((void**)&yposting,NULL,NULL,YPOSTING,"Scalar",NULL);
+	FetchData((void**)&nlines,NULL,NULL,NLINES,"Integer",NULL);
+	FetchData((void**)&ncols,NULL,NULL,NCOLS,"Integer",NULL);
+	FetchData((void**)&interpolationtype,NULL,NULL,INTERPOLATIONTYPE,"String",NULL);
+	if (strcmp(interpolationtype,"node")==0){ interpolation=0; } else if (strcmp(interpolationtype,"element")==0){ interpolation=1; } else{ interpolation=-1; }
+	FetchData((void**)&filterstring,NULL,NULL,FILTER,"String",NULL);
+	if (strcmp(filterstring,"average")==0){ filter=0; } else if (strcmp(filterstring,"nearest")==0){ filter=1; } else{ filter=-1; }
+	FetchData((void**)&windowsize,NULL,NULL,WINDOWSIZE,"Integer",NULL);
+
+	/*Call core of computation: */
+	GriddataMeshToGridx( &griddata, index,nel,x,y,nods,contours,numcontours,meshdata,cornereast,cornernorth,xposting,yposting,nlines,ncols,interpolation,filter,windowsize);
+
+
+	/*Write results: */
+	WriteData(GRIDDATA,griddata,nlines,ncols,"Matrix","Mat");
+
+	/*Free ressources: */
+	//let matlab do this.
+	
+	/*end module: */
+	MODULEEND();
+}
+
+
+
+void GriddataMeshToGridUsage(void)
+{
+	_printf_("   usage:\n");
+	_printf_("   [rgrid_data]= GriddataMeshToGrid( index,x,y,contours,meshdata,cornereast,cornernorth,xposting,yposting,nlines,ncols,interpolationtype,filter,windowsize)\n");
+	_printf_("\n");
+	_printf_("   where:\n");
+	_printf_("\n");
+	_printf_("   index,x,y: delaunay triangulation defining the mesh.\n");
+	_printf_("   contours: structure holding sets of vertices making open contours.\n");
+	_printf_("   meshdata: vertex values of data to be interpolated.\n");
+	_printf_("   cornereast,cornernorth,posting,nlines,ncols: parameters that define the grid\n");
+	_printf_("   interpolationtype: either 'node', or 'element'\n");
+	_printf_("   filter: 'average','nearest'. \n");
+	_printf_("   windowsize: size of filter window, in units of grid.\n");
+	_printf_("   rgrid_data: reference pointer to interpolated grid data.\n");
+	_printf_("               data for which no value was available is set to -9999  (not NaN, which is platform dependent) value.\n");
+}
Index: /issm/trunk/src/mex/GriddataMeshToGrid/GriddataMeshToGrid.h
===================================================================
--- /issm/trunk/src/mex/GriddataMeshToGrid/GriddataMeshToGrid.h	(revision 132)
+++ /issm/trunk/src/mex/GriddataMeshToGrid/GriddataMeshToGrid.h	(revision 132)
@@ -0,0 +1,43 @@
+
+/*
+	GriddataMeshToGrid.h
+*/
+
+
+#ifndef _GRIDDATAMESHTOGRID_H
+#define _GRIDDATAMESHTOGRID_H
+
+/* local prototypes: */
+void GriddataMeshToGridUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "GriddataMeshToGrid"
+
+/* serial input macros: */
+#define INDEX (mxArray*)prhs[0]
+#define X (mxArray*)prhs[1]
+#define Y (mxArray*)prhs[2]
+#define CONTOURS (mxArray*)prhs[3]
+#define MESHDATA (mxArray*)prhs[4]
+#define CORNEREAST (mxArray*)prhs[5]
+#define CORNERNORTH (mxArray*)prhs[6]
+#define XPOSTING (mxArray*)prhs[7]
+#define YPOSTING (mxArray*)prhs[8]
+#define NLINES (mxArray*)prhs[9]
+#define NCOLS (mxArray*)prhs[10]
+#define INTERPOLATIONTYPE (mxArray*)prhs[11]
+#define FILTER (mxArray*)prhs[12]
+#define WINDOWSIZE (mxArray*)prhs[13]
+
+/* serial output macros: */
+#define GRIDDATA (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  14
+
+#endif  /* _GRIDDATAMESHTOGRID_H */
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 131)
+++ /issm/trunk/src/mex/Makefile.am	(revision 132)
@@ -15,4 +15,5 @@
 				Echo\
 				Gradj\
+				GriddataMeshToGrid\
 				HoleFiller \
 				Mergesolutionfromftog\
@@ -95,4 +96,7 @@
 			  Gradj/Gradj.h
 
+GriddataMeshToGrid_SOURCES = GriddataMeshToGrid/GriddataMeshToGrid.cpp\
+			  GriddataMeshToGrid/GriddataMeshToGrid.h
+
 Test_SOURCES = Test/Test.cpp\
 			  Test/Test.h
