Index: /issm/trunk-jpl/src/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/Makefile.am	(revision 12031)
+++ /issm/trunk-jpl/src/Makefile.am	(revision 12032)
@@ -1,2 +1,2 @@
 EXTRA_DIST =  perl  pro
-SUBDIRS = c mex m
+SUBDIRS = c modules m
Index: /issm/trunk-jpl/src/modules/AverageFilter/AverageFilter.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/AverageFilter/AverageFilter.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/AverageFilter/AverageFilter.cpp	(revision 12032)
@@ -0,0 +1,62 @@
+/*!\file:  AverageFilter.cpp
+ * \brief fill holes in matlab velocity array
+	this matlab module is an adaptation of a routine written by Robber 
+	Crippen.  The original routine was designed for the SRTM mission at JPL, 
+	and can be found in the current directory, under the name 
+	AverageFilterCrippen.  It fills void holes in an image, using an interpolation 
+	algorithm, and optionnally a smoothing algorithm. 
+	This matlab module extends the Crippen routine to be used in Matlab, 
+	using double arrays found in the workspace, and loaded directly into memory.
+*/
+
+
+#include "./AverageFilter.h"
+
+void mexFunction( int nlhs, mxArray* plhs[],
+				  int nrhs, const mxArray* prhs[])
+{
+
+	int i,j;
+
+	/* required input: */
+	double* imagein=NULL;
+	int     imagein_rows,imagein_cols;
+	int     smooth;
+
+
+	/* output: */
+	mxArray* pfield=NULL;
+	double* imageout=NULL;
+	int     imageout_rows,imageout_cols;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&AverageFilterUsage);
+
+	/*Fetch data: */
+	FetchData(&imagein,&imagein_rows,&imagein_cols,IMAGEIN);
+	FetchData(&smooth,SMOOTH);
+	
+	/*Run core hole filler routine: */
+	AverageFilterx( &imageout,imagein,imagein_rows,imagein_cols,smooth);
+
+	/* output: */
+	WriteData(IMAGEOUT,imageout,imagein_rows,imagein_cols);
+
+	/*end module: */
+	MODULEEND();
+}
+
+
+void AverageFilterUsage(void)
+{
+	printf("   AverageFilter usage:\n");
+	printf("   [image_out]=AverageFilter(image_in,pixels);\n\n");
+	printf("   where:\n");
+	printf("      image_in in double format\n");
+	printf("      pixels: characteristic size of smoothing\n");
+	printf("      image_out in double format\n");
+	printf("\n");
+}
Index: /issm/trunk-jpl/src/modules/AverageFilter/AverageFilter.h
===================================================================
--- /issm/trunk-jpl/src/modules/AverageFilter/AverageFilter.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/AverageFilter/AverageFilter.h	(revision 12032)
@@ -0,0 +1,36 @@
+
+/*
+	AverageFilter.h
+*/
+
+
+#ifndef _AVERAGEFILTER_H
+#define _AVERAGEFILTER_H
+
+/* local prototypes: */
+void AverageFilterUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "AverageFilter"
+
+
+/* serial input macros: */
+#define IMAGEIN prhs[0]
+#define SMOOTH prhs[1]
+
+/* serial output macros: */
+#define IMAGEOUT &plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  2
+
+#endif  /* _AVERAGEFILTER_H */
Index: /issm/trunk-jpl/src/modules/BamgConvertMesh/BamgConvertMesh.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/BamgConvertMesh/BamgConvertMesh.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/BamgConvertMesh/BamgConvertMesh.cpp	(revision 12032)
@@ -0,0 +1,86 @@
+/*\file BamgConvertMesh.c
+ *\brief: bamg module.
+ */
+#include "./BamgConvertMesh.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*input: */
+	double* index=NULL;
+	int     index_rows;
+	double* x=NULL;
+	int     x_cols;
+	double* y=NULL;
+	int     y_rows;
+	int     y_cols;
+
+	/*Output*/
+	BamgMesh* bamgmesh=NULL;
+	BamgGeom* bamggeom=NULL;
+	mxArray* bamgmesh_mat=NULL;
+	mxArray* bamggeom_mat=NULL;
+
+	/*Intermediary*/
+	int nods;
+	int nels;
+	int verbose=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&BamgConvertMeshUsage);
+
+	/*Initialize Bamg outputs*/
+	bamggeom=new BamgGeom();
+	bamgmesh=new BamgMesh();
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs\n");
+	FetchData(&index,&nels,&index_rows,INDEXHANDLE);
+	FetchData(&x,&nods,&x_cols,XHANDLE);
+	FetchData(&y,&y_rows,&y_cols,YHANDLE);
+
+	/*Check inputs*/
+	if (nels<0){
+		_error_("Number of elements must be positive, check index number of lines");
+	}
+	if (nods<0){
+		_error_("Number of nods must be positive, check x and y sizes");
+	}
+	if (index_rows!=3){
+		_error_("index should have 3 columns");
+	}
+	if (y_rows!=nods){
+		_error_("x and y do not have the same length");
+	}
+	if (x_cols>1 || y_cols>1){
+		_error_("x and y should have only one column");
+	}
+
+	/* Run core computations: */
+	if (verbose) printf("Call core\n");
+	BamgConvertMeshx(bamgmesh,bamggeom,index,x,y,nods,nels);
+
+	/*Generate output Matlab Structures*/
+	bamggeom->SetStructureFields((void*)BAMGGEOMOUT);
+	bamgmesh->SetStructureFields((void*)BAMGMESHOUT);
+
+	/*Clean up*/
+	delete bamggeom;
+	delete bamgmesh;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void BamgConvertMeshUsage(void)
+{
+	_printf_(true,"BAMGCONVERTMESH - convert [x y index] to a bamg geom and mesh geom");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [bamggeom bamgmesh]=BamgConvertMesh(index,x,y);\n");
+	_printf_(true,"      index: index of the mesh\n");
+	_printf_(true,"      x,y: coordinates of the nodes\n");
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/BamgConvertMesh/BamgConvertMesh.h
===================================================================
--- /issm/trunk-jpl/src/modules/BamgConvertMesh/BamgConvertMesh.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/BamgConvertMesh/BamgConvertMesh.h	(revision 12032)
@@ -0,0 +1,36 @@
+/*!\file BamgConvertMesh.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _BAMGCONVERTMESH_H
+#define _BAMGCONVERTMESH_H
+
+/* local prototypes: */
+void BamgConvertMeshUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "BamgConvertMesh"
+
+
+/* serial input macros: */
+#define INDEXHANDLE prhs[0]
+#define XHANDLE prhs[1]
+#define YHANDLE prhs[2]
+
+/* serial output macros: */
+#define BAMGMESHOUT    (mxArray**)&plhs[0]
+#define BAMGGEOMOUT    (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  2
+#undef NRHS
+#define NRHS  3
+
+#endif
Index: /issm/trunk-jpl/src/modules/BamgMesher/BamgMesher.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/BamgMesher/BamgMesher.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/BamgMesher/BamgMesher.cpp	(revision 12032)
@@ -0,0 +1,56 @@
+/*\file BamgMesher.c
+ *\brief: mesher that uses the bamg library
+ */
+#include "./BamgMesher.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*Outputs*/
+	mxArray* bamgmesh_mat=NULL;
+	mxArray* bamggeom_mat=NULL;
+
+	/*diverse: */
+	BamgOpts *bamgopts=NULL;
+	BamgMesh *bamgmesh_in=NULL;
+	BamgGeom *bamggeom_in=NULL;
+	BamgMesh *bamgmesh_out=NULL;
+	BamgGeom *bamggeom_out=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&BamgMesherUsage);
+
+	/*Initialize variables*/
+	bamgopts   = new BamgOpts(BAMGOPTIONS);
+	bamggeom_in= new BamgGeom(BAMGGEOMIN);
+	bamgmesh_in= new BamgMesh(BAMGMESHIN);
+
+	/*Initialize outputs*/
+	bamggeom_out=new BamgGeom();
+	bamgmesh_out=new BamgMesh();
+
+	/*!Generate internal degree of freedom numbers: */
+	Bamgx(bamgmesh_out,bamggeom_out,bamgmesh_in,bamggeom_in,bamgopts);
+
+	/*Generate output Matlab Structures*/
+	bamggeom_out->SetStructureFields((void*)BAMGGEOMOUT);
+	bamgmesh_out->SetStructureFields((void*)BAMGMESHOUT);
+
+	/*Free ressources: */
+	delete bamgopts;
+	delete bamggeom_in;
+	delete bamggeom_out;
+	delete bamgmesh_in;
+	delete bamgmesh_out;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void BamgMesherUsage(void){
+	_printf_(true,"\n");
+	_printf_(true,"   usage: [bamgmesh,bamggeom]=%s(bamgmesh,bamggeom,bamgoptions);\n",__FUNCT__);
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/BamgMesher/BamgMesher.h
===================================================================
--- /issm/trunk-jpl/src/modules/BamgMesher/BamgMesher.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/BamgMesher/BamgMesher.h	(revision 12032)
@@ -0,0 +1,36 @@
+/*
+	BamgMesherUsage.h
+*/
+
+#ifndef _BAMG_MESHER_H_
+#define _BAMG_MESHER_H_
+
+/* local prototypes: */
+void BamgMesherUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "BamgMesher"
+    
+/* serial input macros: */
+#define BAMGMESHIN  (mxArray*)prhs[0]
+#define BAMGGEOMIN  (mxArray*)prhs[1]
+#define BAMGOPTIONS (mxArray*)prhs[2]
+
+/* serial output macros: */
+#define BAMGMESHOUT    (mxArray**)&plhs[0]
+#define BAMGGEOMOUT    (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  2
+#undef NRHS
+#define NRHS  3
+
+#endif  /* _BAMG_MESHER_H_ */
+
Index: /issm/trunk-jpl/src/modules/BamgTriangulate/BamgTriangulate.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/BamgTriangulate/BamgTriangulate.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/BamgTriangulate/BamgTriangulate.cpp	(revision 12032)
@@ -0,0 +1,58 @@
+/*\file BamgTriangulate.c
+ *\brief: bamg module.
+ */
+#include "./BamgTriangulate.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*input: */
+	double* x=NULL;
+	double* y=NULL;
+	int     x_cols;
+	int     y_rows,y_cols;
+	int nods;
+
+	/*Output*/
+	int* index=NULL;
+	int  nels;
+
+	/*Intermediary*/
+	int verbose=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&BamgTriangulateUsage);
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs\n");
+	FetchData(&x,&nods,&x_cols,XHANDLE);
+	FetchData(&y,&y_rows,&y_cols,YHANDLE);
+
+	/*Check inputs*/
+	if(y_rows!=nods)         _error_("x and y do not have the same length");
+	if(x_cols>1 || y_cols>1) _error_("x and y should have only one column");
+	if(nods<3)               _error_("At least 3 points are required");
+
+	/* Run core computations: */
+	if (verbose) printf("Call core\n");
+	BamgTriangulatex(&index,&nels,x,y,nods);
+
+	/*Write output*/
+	WriteData(INDEX,index,nels,3);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void BamgTriangulateUsage(void)
+{
+	_printf_(true,"BAMGTRIANGULATE - Delaunay Triangulation of a list of points");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      index=BamgTriangulate(x,y);\n");
+	_printf_(true,"      index: index of the triangulation\n");
+	_printf_(true,"      x,y: coordinates of the nodes\n");
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/BamgTriangulate/BamgTriangulate.h
===================================================================
--- /issm/trunk-jpl/src/modules/BamgTriangulate/BamgTriangulate.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/BamgTriangulate/BamgTriangulate.h	(revision 12032)
@@ -0,0 +1,34 @@
+/*!\file BamgTriangulate.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _BAMGTRIANGULATE_H
+#define _BAMGTRIANGULATE_H
+
+/* local prototypes: */
+void BamgTriangulateUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "BamgTriangulate"
+
+
+/* serial input macros: */
+#define XHANDLE prhs[0]
+#define YHANDLE prhs[1]
+
+/* serial output macros: */
+#define INDEX (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  2
+
+#endif
Index: /issm/trunk-jpl/src/modules/Chaco/Chaco.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/Chaco/Chaco.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Chaco/Chaco.cpp	(revision 12032)
@@ -0,0 +1,146 @@
+/*\file Chaco.c
+ *\brief:  Chaco partitioner mex module
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+
+#include "./Chaco.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+   
+	int i;
+	int nterms;
+
+	/*Inputs: */
+	int       nvtxs;		/* number of vertices in graph */
+    int      *start;		/* start of edge list for each vertex */
+    int      *adjacency;	/* edge list data */
+    int      *vwgts=NULL;	/* weights for all vertices */
+	int       nedges;
+    float    *ewgts=NULL;	/* weights for all edges */
+    float    *x=NULL;
+    float    *y=NULL;
+    float    *z=NULL;		/* coordinates for inertial method */
+    double    options[10]={1,1,0,0,1,1,50,0,.001,7654321}; /* architecture and partitioning options */
+    double*   in_options=NULL;
+    int      *nparts=NULL;	/* number of parts options */
+	int       npart;
+    double   *goal=NULL;	/* desired set sizes */
+
+	/*intermediary pointers: */
+	mwIndex *mwstart, *mwadjacency;
+	double  *doublepointer;
+
+	/*output: */
+    short    *assignment=NULL;	/* set number of each vtx (length nvtxs+1) */
+	double   *doubleassignment=NULL;	/*holds assignment, in double format, to return to matlab*/
+
+
+	#ifndef _HAVE_CHACO_ //only works if dakota library has been compiled in.
+	_error_(" Chaco not available! Cannot carry out Chaco partitioning!");
+	#endif
+
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ChacoUsage);
+
+
+	/*Fetch adjacency matrix: */
+	nvtxs = mxGetN(A_IN);
+
+	mwstart = mxGetJc(A_IN);
+	start=(int*)xmalloc(nvtxs*sizeof(int));
+	for (i=0; i<nvtxs+1;i++)start[i]=(int)mwstart[i];
+
+	mwadjacency = mxGetIr(A_IN);
+	adjacency = (int*)xmalloc(mxGetNzmax(A_IN)*sizeof(int));
+	for (i=0; i<mxGetNzmax(A_IN); i++) adjacency[i]= (int)mwadjacency[i];
+
+	nedges = start[nvtxs];
+	if(!mxIsEmpty(EWGTS_IN)){
+		ewgts = (float *) xcalloc(nedges, sizeof(float));
+		doublepointer=mxGetPr(A_IN);
+		for (i = 0; i < nedges; i++)ewgts[i] = (float)doublepointer[i];
+	}
+	else ewgts=NULL;
+
+	/*Fetch rest of data: */
+	FetchData(&vwgts,&nterms,VWGTS_IN); 
+
+	FetchData(&x,&nterms,X_IN); 
+	FetchData(&y,&nterms,Y_IN); 
+	FetchData(&z,&nterms,Z_IN); 
+	
+	FetchData(&in_options,&nterms,OPTNS_IN); 
+	for (i=0;i<(nterms<10?nterms:10);i++) options[i]=in_options[i]; //copy in_options into default options
+	
+	FetchData(&npart,NPARTS_IN); 
+	nparts=(int*)xmalloc(sizeof(int)); nparts[0]=npart; //weird Chacox interface ain't it?
+
+	FetchData(&goal,&nterms,GOAL_IN); 
+	
+	/*Some debugging print: {{{*/
+	#ifdef _DEBUG_
+	printf("nvtxs: %i\n",nvtxs);
+	printf("options: [");
+	for(i=0;i<10;i++)printf("%g|",options[i]);
+	printf("]\n");
+	printf("start: \n");
+	for (i=0; i<nvtxs+1;i++)printf("%i ",start[i]);
+	printf("\n");
+	printf("adjacency: \n");
+	for (i=0; i<mxGetNzmax(A_IN);i++)printf("%i ",adjacency[i]);
+	printf("\n");
+	printf("nedges: %i %p\n",nedges,ewgts);
+	if(ewgts) for (i = 0; i < nedges; i++)printf("%g ",ewgts[i]);
+	printf("\n");
+	printf("vwgts:\n");
+	for (i = 0; i < nvtxs; i++)printf("%g ",vwgts[i]);
+	printf("\n");
+	printf("nparts: %i\n",nparts[0]);
+	printf("goal: %p\n",goal);
+	#endif
+	/*}}}*/
+	
+	/*Allocate output: */
+	assignment = (short *) xcalloc(nvtxs, sizeof(short));
+	
+    /*Call core: */
+	Chacox(nvtxs, start, adjacency, vwgts, ewgts, x, y, z, assignment, options, nparts, goal);
+
+    /*Output data: */
+	doubleassignment=(double*)xmalloc(nvtxs*sizeof(double));
+	for (i=0;i<nvtxs;i++) doubleassignment[i]=(double)assignment[i];
+	WriteData(ASSGN_OUT,doubleassignment,nvtxs);
+
+	/*Free ressources:*/
+	xfree((void**)&assignment); 
+	xfree((void**)&goal);
+	xfree((void**)&nparts);
+	xfree((void**)&z);
+	xfree((void**)&y);
+	xfree((void**)&x);
+	xfree((void**)&ewgts);
+	xfree((void**)&vwgts);
+	xfree((void**)&adjacency);
+	xfree((void**)&start);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void ChacoUsage( void )
+{
+	_printf_(true,"\n");
+	_printf_(true,"Usage: [assgn] = Chaco(A,vwgts,ewgts,x,y,z,options,nparts,goal);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/Chaco/Chaco.h
===================================================================
--- /issm/trunk-jpl/src/modules/Chaco/Chaco.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Chaco/Chaco.h	(revision 12032)
@@ -0,0 +1,44 @@
+/*!\file:  Chaco.h
+ * \brief header file for Chaco module.
+ */ 
+
+#ifndef _CHACO_H
+#define _CHACO_H
+
+/* local prototypes: */
+void ChacoUsage(void);
+
+#include <stdio.h>
+#include <string.h>    /*  strcasecmp  */
+#include <time.h>      /*  clock,time,difftime  */
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+    
+/* serial input macros: */
+#define A_IN (mxArray*)prhs[0]
+#define VWGTS_IN (mxArray*)prhs[1]
+#define EWGTS_IN (mxArray*)prhs[2]
+#define X_IN (mxArray*)prhs[3]
+#define Y_IN (mxArray*)prhs[4]
+#define Z_IN (mxArray*)prhs[5]
+#define OPTNS_IN (mxArray*)prhs[6]
+#define NPARTS_IN (mxArray*)prhs[7]
+#define GOAL_IN (mxArray*)prhs[8]
+
+/* serial output macros: */
+#define ASSGN_OUT (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  9
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Chaco"
+
+#endif  /* _CHACO_H */
Index: /issm/trunk-jpl/src/modules/ContourToMesh/ContourToMesh.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/ContourToMesh/ContourToMesh.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/ContourToMesh/ContourToMesh.cpp	(revision 12032)
@@ -0,0 +1,135 @@
+/*! \file  ContourtoMesh
+    \brief: takes an  contour file, and figures out which nodes or elements from the mesh  
+    are inside this contour. 
+	usage:
+	[in_nod,in_elem]=ContourToMesh(index,x,y,contours,interptype,edgevalue);
+	
+	input:
+
+		index,x,y: delaunay triangulation.
+		contours: structure holding sets of vertices making open contours. 
+		interptype: string definining type of interpolation ('element', or 'node', or 'element and node');
+		edgevalue: integer (0, 1 or 2) defining the value associated to the nodes on the edges of the polygons
+
+	output:
+		in_nod: vector of flags (0 or 1), of size nods if interptype is set to 'node' or 'element and node', 
+				or of size 0 otherwise.
+		in_elem: vector of flags (0 or 1), of size nel if interptype is set to 'element' or 'element and node', 
+				or of size 0 otherwise.
+*/
+	
+#include "./ContourToMesh.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+	int i,j;
+
+	/* required input: */
+	double* index=NULL;
+	double* x=NULL;
+	double* y=NULL;
+	int     edgevalue;
+	char*   interptype=NULL;
+
+	/* output: */
+	Vector*  in_nod=NULL;
+	int  nods;
+	Vector*  in_elem=NULL;
+	int  nel;
+
+	//contours
+	mxArray*  matlabstructure=NULL;
+	int numcontours;
+	Contour** contours=NULL;
+	Contour*  contouri=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	//CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ContourToMeshUsage); Cant' use it here, as we have variable  outputs.
+	if((nlhs!=1 && nlhs!=2) || (nrhs!=NRHS)){
+		ContourToMeshUsage();
+		_error_(" usage. See above");
+	}
+
+	/*First, call expread on filename to build a contour array in the matlab workspace: */
+	mexCallMATLAB( 1, &matlabstructure, 1, (mxArray**)&FILENAME, "expread");
+
+	/*Fetch inputs: */
+	FetchData(&index,&nel,NULL,INDEXHANDLE);
+	FetchData(&x,&nods,NULL,XHANDLE);
+	FetchData(&y,NULL,NULL,YHANDLE);
+	FetchData(&edgevalue,EDGEVALUEHANDLE);
+
+	//Fetch contours
+	numcontours=mxGetNumberOfElements(matlabstructure);
+	contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+	for(i=0;i<numcontours;i++){
+		//allocate
+		contouri=(Contour*)xmalloc(sizeof(Contour));
+		//retrieve dimension of this contour.
+		contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
+		//set pointers.
+		contouri->x=mxGetPr(mxGetField(matlabstructure,i,"x"));
+		contouri->y=mxGetPr(mxGetField(matlabstructure,i,"y"));
+		*(contours+i)=contouri;
+	}
+
+	/*Fetch  interptype: */
+	FetchData(&interptype,INTERPTYPEHANDLE);
+
+	/* Debugging of contours :{{{1*/
+	/*for(i=0;i<numcontours;i++){
+		printf("\nContour echo: contour number  %i / %i\n",i+1,numcontours);
+		contouri=*(contours+i);
+		printf("   Number of vertices %i\n",contouri->nods);
+		for (j=0;j<contouri->nods;j++){
+			printf("   %lf %lf\n",*(contouri->x+j),*(contouri->y+j));
+		}
+	}*/
+	/*}}}*/
+
+	/*Run interpolation routine: */
+	ContourToMeshx( &in_nod,&in_elem,index,x,y,contours,numcontours,interptype,nel,nods,edgevalue);
+
+	/* output: */
+	if (strcmp(interptype,"node")==0){
+		WriteData(PLHS0,in_nod);
+	}
+	else if (strcmp(interptype,"element")==0){
+		WriteData(PLHS0,in_elem);
+	}
+	else if (strcmp(interptype,"element and node")==0){
+		WriteData(PLHS0,in_nod);
+		WriteData(PLHS1,in_elem);
+	}
+	else _error_(" wrong interpolation type");
+
+	/*end module: */
+	MODULEEND();
+	
+}
+
+void ContourToMeshUsage(void)
+{
+	printf("CONTOURTOMESH - Flag the elements or nodes inside a contour\n");
+	printf("\n");
+	printf("      Usage: \n");
+	printf("         [in_nod,in_elem]=ContourToMesh(index,x,y,contourname,interptype,edgevalue)\n\n");
+	printf("\n");
+	printf("         index,x,y: mesh triangulation.\n");
+	printf("         contourname: name of .exp file containing the contours.\n");
+	printf("         interptype: string definining type of interpolation ('element', or 'node').\n");
+	printf("         edgevalue: integer (0, 1 or 2) defining the value associated to the nodes on the edges of the polygons.\n");
+	printf("         in_nod: vector of flags (0 or 1), of size nods if interptype is set to 'node' or 'element and node', \n");
+	printf("            or of size 0 otherwise.\n");
+	printf("         in_elem: vector of flags (0 or 1), of size nel if interptype is set to 'element' or 'element and node', \n");
+	printf("            or of size 0 otherwise.\n");
+	printf("\n");
+	printf("      Example: \n");
+	printf("         in_nod=ContourToMesh(md.elements,md.x,md.y,'Contour.exp','node',1)\n");
+	printf("         in_elements=ContourToMesh(md.elements,md.x,md.y,'Contour.exp','element',0)\n");
+	printf("         [in_nodes,in_elements]=ContourToMesh(md.elements,md.x,md.y,'Contour.exp','element and node',0)\n");
+	printf("\n");
+}
Index: /issm/trunk-jpl/src/modules/ContourToMesh/ContourToMesh.h
===================================================================
--- /issm/trunk-jpl/src/modules/ContourToMesh/ContourToMesh.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/ContourToMesh/ContourToMesh.h	(revision 12032)
@@ -0,0 +1,47 @@
+
+/*
+	ContourToMesh.h
+*/
+
+
+#ifndef _CONTOURTOMESH_H
+#define _CONTOURTOMESH_H
+
+/* local prototypes: */
+void ContourToMeshUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__
+#define __FUNCT__ "ContourToMesh"
+
+
+#ifndef ALL
+#define ALL 0
+#endif
+
+/* input macros: */
+#define INDEXHANDLE prhs[0]
+#define XHANDLE prhs[1]
+#define YHANDLE prhs[2]
+#define FILENAME prhs[3]
+#define INTERPTYPEHANDLE prhs[4]
+#define EDGEVALUEHANDLE prhs[5]
+
+/* serial output macros: */
+#define PLHS0 (mxArray**)&plhs[0]
+#define PLHS1 (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  2
+#undef NRHS
+#define NRHS 6
+
+
+#endif  /* _CONTOURTOMESH_H */
+
Index: /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.cpp	(revision 12032)
@@ -0,0 +1,114 @@
+/*! \file  ContourtoNodes
+    \brief: takes a  contour file, and figures out which nodes  (x,y list)
+    are inside this contour. 
+
+	usage:
+	[flags]=ContourToNodes(x,y,contours,interptype,edgevalue);
+	
+	where:
+
+	input:
+
+		x,y: node cooredinates
+		
+		contours: structure holding sets of vertices making open contours. 
+		
+		interptype: string definining type of interpolation ('element', or 'node', or 'element and node');
+
+		edgevalue: integer (0, 1 or 2) defining the value associated to the nodes on the edges of the polygons
+
+	output:
+		flags: vector of flags (0 or 1), of size nods 
+*/
+	
+#include "./ContourToNodes.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+	int i,j;
+
+	/* required input: */
+	double* x=NULL;
+	double* y=NULL;
+	int     edgevalue;
+	char*   interptype=NULL;
+
+	/* output: */
+	Vector*  flags=NULL;
+	int  nods;
+
+	//contours
+	mxArray*  matlabstructure=NULL;
+	int numcontours;
+	Contour** contours=NULL;
+	Contour*  contouri=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ContourToNodesUsage);
+
+	
+	/*Fetch inputs: */
+	FetchData(&x,&nods,NULL,XHANDLE);
+	FetchData(&y,NULL,NULL,YHANDLE);
+	FetchData(&edgevalue,EDGEVALUEHANDLE);
+
+	//Fetch contours
+
+	if(mxIsChar(FILENAME)){
+		/*Call expread on filename to build a contour array in the matlab workspace: */
+		mexCallMATLAB( 1, &matlabstructure, 1, (mxArray**)&FILENAME, "expread");
+	}
+	else{
+		/*FILENAME is actually a structure, coming directly from expread: */
+		matlabstructure=(mxArray*)FILENAME;
+	}
+
+	numcontours=mxGetNumberOfElements(matlabstructure);
+	contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+	for(i=0;i<numcontours;i++){
+		//allocate
+		contouri=(Contour*)xmalloc(sizeof(Contour));
+		//retrieve dimension of this contour.
+		contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
+		//set pointers.
+		contouri->x=mxGetPr(mxGetField(matlabstructure,i,"x"));
+		contouri->y=mxGetPr(mxGetField(matlabstructure,i,"y"));
+		*(contours+i)=contouri;
+	}
+
+	/* Debugging of contours :{{{1*/
+	/*for(i=0;i<numcontours;i++){
+		printf("\nContour echo: contour number  %i / %i\n",i+1,numcontours);
+		contouri=*(contours+i);
+		printf("   Number of nodes %i\n",contouri->nods);
+		for (j=0;j<contouri->nods;j++){
+			printf("   %lf %lf\n",*(contouri->x+j),*(contouri->y+j));
+		}
+	}*/
+	/*}}}*/
+
+	/*Run interpolation routine: */
+	ContourToNodesx(&flags,x,y,nods,contours,numcontours,edgevalue);
+
+	/* output: */
+	WriteData(FLAGS,flags);
+
+	/*end module: */
+	MODULEEND();
+
+}
+
+void ContourToNodesUsage(void){
+	printf("   usage:\n");
+	printf("   [flags]=ContourToNodes(x,y,contourname,edgevalue);\n\n");
+	printf("   where:\n");
+	printf("      x,y: list of nodes.\n");
+	printf("      contourname: name of .exp file containing the contours, or resulting structure from call to expread.\n");
+	printf("      interptype: string definining type of interpolation ('element', or 'node').\n");
+	printf("      edgevalue: integer (0, 1 or 2) defining the value associated to the nodes on the edges of the polygons.\n");
+	printf("      flags: vector of flags (0 or 1), of size nods.\n");
+	printf("\n");
+}
Index: /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.h
===================================================================
--- /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.h	(revision 12032)
@@ -0,0 +1,44 @@
+
+/*
+	ContourToNodes.h
+*/
+
+
+#ifndef _CONTOURTONODES_H
+#define _CONTOURTONODES_H
+
+/* local prototypes: */
+void ContourToNodesUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__
+#define __FUNCT__ "ContourToNodes"
+
+
+#ifndef ALL
+#define ALL 0
+#endif
+
+/* input macros: */
+#define XHANDLE prhs[0]
+#define YHANDLE prhs[1]
+#define FILENAME prhs[2]
+#define EDGEVALUEHANDLE prhs[3]
+
+/* serial output macros: */
+#define FLAGS (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS 1
+#undef NRHS
+#define NRHS 4
+
+
+#endif  /* _CONTOURTONODES_H */
+
Index: /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.cpp	(revision 12032)
@@ -0,0 +1,46 @@
+/*\file ElementConnectivity.c
+ *\brief: build element connectivity using node connectivity and elements. 
+ */
+
+#include "./ElementConnectivity.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*inputs: */
+	double* elements=NULL;
+	double* nodeconnectivity=NULL;
+	int     nel,nods;
+	int     width;
+
+	/*outputs: */
+	double* elementconnectivity=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ElementConnectivityUsage);
+        
+	/*Input datasets: */
+	FetchData(&elements,&nel,NULL,ELEMENTS);
+	FetchData(&nodeconnectivity,&nods,&width,NODECONNECTIVITY);
+
+	/*!Generate internal degree of freedom numbers: */
+	ElementConnectivityx(&elementconnectivity, elements,nel, nodeconnectivity, nods, width);
+
+	/*write output datasets: */
+	WriteData(ELEMENTCONNECTIVITY,elementconnectivity,nel,3);
+
+	/*Free ressources: */
+	xfree((void**)&elements);
+	xfree((void**)&nodeconnectivity);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void ElementConnectivityUsage(void) {
+	_printf_(true,"\n");
+	_printf_(true,"   usage: elementconnectivity = %s(elements, nodeconnectivity);\n",__FUNCT__);
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/ElementConnectivity/ElementConnectivity.h	(revision 12032)
@@ -0,0 +1,33 @@
+/*
+	ElementConnectivity.h
+*/
+
+#ifndef _ELEMENTCONNECTIVITY_H
+#define _ELEMENTCONNECTIVITY_H
+
+/* local prototypes: */
+void ElementConnectivityUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "ElementConnectivity"
+
+/* serial input macros: */
+#define ELEMENTS (mxArray*)prhs[0]
+#define NODECONNECTIVITY (mxArray*)prhs[1]
+
+/* serial output macros: */
+#define ELEMENTCONNECTIVITY (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  2
+
+#endif  /* _ELEMENTCONNECTIVITY_H */
Index: /issm/trunk-jpl/src/modules/EnumToString/EnumToString.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/EnumToString/EnumToString.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/EnumToString/EnumToString.cpp	(revision 12032)
@@ -0,0 +1,32 @@
+/*\file EnumToString.c
+ *\brief:convert enum (int) to string
+ */
+
+#include "./EnumToString.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	char    *name    = NULL;
+	int      enum_in;
+
+	/*checks on arguments on the matlab side: */
+	if(nrhs!=NRHS){
+		EnumToStringUsage(); _error_(" usage. See above");
+	}
+
+	/*Fetch inputs: */
+	FetchData(&enum_in,ENUMIN);
+
+	/*Run core function: */
+	EnumToStringx(&name,enum_in);
+
+	/* output: */
+	WriteData(NAME,name);
+}
+
+void EnumToStringUsage(void)
+{
+	_printf_(true,"\n");
+	_printf_(true,"   usage: %sstring = EnumToString(enum);\n",__FUNCT__);
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/EnumToString/EnumToString.h
===================================================================
--- /issm/trunk-jpl/src/modules/EnumToString/EnumToString.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/EnumToString/EnumToString.h	(revision 12032)
@@ -0,0 +1,32 @@
+/*!\file:  EnumToString.h
+ * \brief header file for EnumToString module.
+ */ 
+
+#ifndef _ENUMTOSTRING_H
+#define _ENUMTOSTRING_H
+
+/* local prototypes: */
+void EnumToStringUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+    
+/* serial input macros: */
+#define ENUMIN (mxArray*)prhs[0]
+
+/* serial output macros: */
+#define NAME (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  1
+
+#undef __FUNCT__ 
+#define __FUNCT__  "EnumToString"
+
+#endif  /* _TEST_H */
Index: /issm/trunk-jpl/src/modules/Exp2Kml/Exp2Kml.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/Exp2Kml/Exp2Kml.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Exp2Kml/Exp2Kml.cpp	(revision 12032)
@@ -0,0 +1,115 @@
+/*\file Exp2Kml.c
+ *\brief: exp to kml file conversion mex module.
+ */
+#include "./Exp2Kml.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	char    *filexp=NULL,*filkml=NULL;
+	int     sgn;
+
+	Options* options=NULL;
+	char     *choles=NULL;
+	bool     holes=false;
+	double   cm=0.,sp=0.;
+
+	/* output: */
+	int     iret=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		Exp2KmlUsage();
+		_error_("Exp2Kml usage error");
+	}
+	if (nrhs < NRHS) {
+		Exp2KmlUsage();
+		_error_("Exp2Kml usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&filexp,EXP_IN);
+	if (verbose) printf("  filexp=\"%s\"\n",filexp);
+	FetchData(&filkml,KML_IN);
+	if (verbose) printf("  filkml=\"%s\"\n",filkml);
+	FetchData(&sgn,SGN_IN);
+	if (verbose) printf("  sgn=%d\n",sgn);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+	options->Get(&choles,"holes","no");
+	if (!strncmp(choles,"y",1) || !strncmp(choles,"on",2))
+		holes=true;
+	/*  defaults are in Xy2lldef, so don't duplicate them here, and only use user values if both have been specified  */
+	if (options->GetOption("central_meridian") || options->GetOption("standard_parallel")) {
+		options->Get(&cm,"central_meridian");
+		if (verbose) printf("  cm=%g\n",cm);
+		options->Get(&sp,"standard_parallel");
+		if (verbose) printf("  sp=%g\n",sp);
+	}
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if (sgn != +1 && sgn != -1) _error_("Hemisphere sgn=%d must be +1 (north) or -1 (south).",sgn);
+	if (fabs(cm)      > 180.) _error_("Central meridian cm=%g must be between -180 (west) and +180 (east) degrees.",cm);
+	if (sp < 0. || sp >  90.) _error_("Standard parallel sp=%g must be between 0 and 90 degrees (in specified hemisphere).",sp);
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
+		iret=Exp2Kmlx(filexp,filkml,
+					  sgn,cm,sp,
+					  holes);
+	else
+		iret=Exp2Kmlx(filexp,filkml,
+					  sgn,
+					  holes);
+	if (verbose) printf("  iret=%d\n",iret);
+
+	/*Write data: */
+	WriteData(RET_OUT,iret);
+
+	/*Clean-up*/
+	xfree((void**)&choles);
+	delete options;
+	xfree((void**)&filkml);
+	xfree((void**)&filexp);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void Exp2KmlUsage(void)
+{
+	_printf_(true,"Exp2Kml - exp to kml file conversion module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module converts a file from exp to kml format.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [ret]=Exp2Kml(filexp,filkml,sgn,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      filexp      file name of exp file to be read (char)\n");
+	_printf_(true,"      filkml      file name of kml file to be written (char)\n");
+	_printf_(true,"      sgn         sign for hemisphere (double, +1 (north) or -1 (south))\n");
+	_printf_(true,"\n");
+	_printf_(true,"      central_meridian     central meridian (double, optional, but must specify with sp)\n");
+	_printf_(true,"      standard_parallel    standard parallel (double, optional, but must specify with cm)\n");
+	_printf_(true,"      holes       flag for treatment of multiple profiles (char, optional, 'yes' for holes))\n");
+	_printf_(true,"\n");
+	_printf_(true,"      ret         return code (non-zero for warning)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Examples:\n");
+	_printf_(true,"      [ret]=Exp2Kml('file.exp','file.kml', 1);\n");
+	_printf_(true,"      [ret]=Exp2Kml('file.exp','file.kml', 1,'central_meridian',45,'standard_parallel',70,'holes','yes');\n");
+	_printf_(true,"      [ret]=Exp2Kml('file.exp','file.kml',-1,'central_meridian', 0,'standard_parallel',71,'holes','yes');\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/Exp2Kml/Exp2Kml.h
===================================================================
--- /issm/trunk-jpl/src/modules/Exp2Kml/Exp2Kml.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Exp2Kml/Exp2Kml.h	(revision 12032)
@@ -0,0 +1,36 @@
+/*!\file Exp2Kml.h
+ * \brief: prototype for exp to kml file conversion mex module.
+ */
+
+#ifndef _EXP2KML_H
+#define _EXP2KML_H
+
+/* local prototypes: */
+void Exp2KmlUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Exp2Kml"
+
+
+/* serial input macros: */
+#define EXP_IN    prhs[0]
+#define KML_IN    prhs[1]
+#define SGN_IN    prhs[2]
+
+/* serial output macros: */
+#define RET_OUT    (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  3
+#undef NLHS
+#define NLHS  1
+
+#endif
+
Index: /issm/trunk-jpl/src/modules/HoleFiller/HoleFiller.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/HoleFiller/HoleFiller.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/HoleFiller/HoleFiller.cpp	(revision 12032)
@@ -0,0 +1,69 @@
+/*!\file:  HoleFiller.cpp
+ * \brief fill holes in matlab velocity array
+	this matlab module is an adaptation of a routine written by Robber 
+	Crippen.  The original routine was designed for the SRTM mission at JPL, 
+	and can be found in the current directory, under the name 
+	HoleFillerCrippen.  It fills void holes in an image, using an interpolation 
+	algorithm, and optionnally a smoothing algorithm. 
+	This matlab module extends the Crippen routine to be used in Matlab, 
+	using double arrays found in the workspace, and loaded directly into memory.
+*/
+
+
+#include "./HoleFiller.h"
+
+void mexFunction( int nlhs, mxArray* plhs[],
+				  int nrhs, const mxArray* prhs[])
+{
+
+	int i,j;
+
+	/* required input: */
+	double* imagein=NULL;
+	int     imagein_rows,imagein_cols;
+	int     smooth_flag;
+	int     smooth;
+
+
+	/* output: */
+	mxArray* pfield=NULL;
+	double* imageout=NULL;
+	int     imageout_rows,imageout_cols;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&HoleFillerUsage);
+
+	/*Fetch data: */
+	FetchData(&imagein,&imagein_rows,&imagein_cols,IMAGEIN);
+	FetchData(&smooth_flag,SMOOTH);
+	
+	/*Get smooth flag setup: */
+	if (smooth_flag==0)
+		smooth=1;
+	else
+		smooth=0;
+
+	/*Run core hole filler routine: */
+	HoleFillerx( &imageout,imagein,imagein_rows,imagein_cols,smooth);
+
+	/* output: */
+	WriteData(IMAGEOUT,imageout,imagein_rows,imagein_cols);
+
+	/*end module: */
+	MODULEEND();
+}
+
+
+void HoleFillerUsage(void)
+{
+	printf("   HoleFiller usage:\n");
+	printf("   [image_out]=HoleFiller(image_in,smooth);\n\n");
+	printf("   where:\n");
+	printf("      image_in in double format\n");
+	printf("      smooth: 1 to smooth with a box filer, 0 to leave data raw\n");
+	printf("      image_out in double format\n");
+	printf("\n");
+}
Index: /issm/trunk-jpl/src/modules/HoleFiller/HoleFiller.h
===================================================================
--- /issm/trunk-jpl/src/modules/HoleFiller/HoleFiller.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/HoleFiller/HoleFiller.h	(revision 12032)
@@ -0,0 +1,36 @@
+
+/*
+	HoleFiller.h
+*/
+
+
+#ifndef _HOLEFILLER_H
+#define _HOLEFILLER_H
+
+/* local prototypes: */
+void HoleFillerUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "HoleFiller"
+
+
+/* serial input macros: */
+#define IMAGEIN prhs[0]
+#define SMOOTH prhs[1]
+
+/* serial output macros: */
+#define IMAGEOUT &plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  2
+
+#endif  /* _HOLEFILLER_H */
Index: /issm/trunk-jpl/src/modules/InternalFront/InternalFront.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/InternalFront/InternalFront.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InternalFront/InternalFront.cpp	(revision 12032)
@@ -0,0 +1,99 @@
+/*\file InternalFront.c
+ *\brief: build pressureload
+ */
+
+#include "./InternalFront.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	bool*   elementonwater=NULL;
+	int*    elements=NULL;
+	int*    connectivity=NULL;
+	int*    elementconnectivity=NULL;
+	int*    front=NULL;
+	double* front2=NULL;
+	bool    found;
+	int     numberofelements,numberofsegments;
+	int     N,M;
+	int     i,j,ii,jj,id;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InternalFrontUsage);
+
+	/*Fetch required fields*/
+	FetchData(&numberofelements,mxGetAssignedField(MODEL,0,"numberofelements"));
+	if(numberofelements<=0) _error_("No elements found in the model");
+	FetchData(&elements,&M,&N,mxGetAssignedField(MODEL,0,"elements"));
+	if(M!=numberofelements || N!=3) _error_("Field 'elements' should be of size [md.numberofelements 3]");
+	FetchData(&elementonwater,&M,&N,mxGetAssignedField(MODEL,0,"elementonwater"));
+	if(M!=numberofelements || N!=1) _error_("Field 'elementonwater' should be of size [md.numberofelements 1]");
+	FetchData(&elementconnectivity,&M,&N,mxGetAssignedField(MODEL,0,"elementconnectivity"));
+	if(M!=numberofelements || N!=3) _error_("Field 'elementconnectivity' should be of size [md.numberofelements 3]");
+
+	/*Allocate and initialize all variables*/
+	numberofsegments=0;
+	front=(int*)xmalloc(3*numberofelements*4*sizeof(int));
+
+	/*Loop over all elements on water*/
+	for(i=0;i<numberofelements;i++){
+
+		/*Skip if on water*/
+		if(!elementonwater[i]) continue;
+
+		/*Loop over all three adjacent elements*/
+		for(j=0;j<3;j++){
+
+			/*Skip if adjacent element does not exist or is on water*/
+			id=elementconnectivity[i*3+j];
+			if(id==0) continue;
+			if(elementonwater[id-1]) continue;
+
+			/*We have an ice front to add here, let's go!*/
+			for(ii=0;ii<3;ii++){
+
+				found=false;
+				for(jj=0;jj<3;jj++){
+					if(elements[(id-1)*3+ii]==elements[i*3+jj]){
+						found=true;
+						break;
+					}
+				}
+
+				/*OK, we just found the node of id, which is not in i. We have the segment*/
+				if(!found){
+					front[numberofsegments*4+0]=elements[(id-1)*3+(ii+1)%3];
+					front[numberofsegments*4+1]=elements[(id-1)*3+(ii+2)%3];
+					front[numberofsegments*4+2]=id;
+					front[numberofsegments*4+3]=IceEnum;
+					numberofsegments+=1;
+					break;
+				}
+			}
+
+			/*In debugging mode, check that the segment has been found*/
+			_assert_(!found);
+		}
+	}
+
+	/*Now that we know how many segments there is we can allocate the final matrix*/
+	if(numberofsegments){
+		front2=(double*)xmalloc(4*numberofsegments*sizeof(double));
+		for(i=0;i<4*numberofsegments;i++) front2[i]=(double)front[i];
+	}
+	xfree((void**)&front);
+
+	/*write output datasets: */
+	WriteData(FRONT,front2,numberofsegments,4);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void InternalFrontUsage(void) {
+	_printf_(true,"\n");
+	_printf_(true,"   usage: icefront = %s(md);\n",__FUNCT__);
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/InternalFront/InternalFront.h
===================================================================
--- /issm/trunk-jpl/src/modules/InternalFront/InternalFront.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InternalFront/InternalFront.h	(revision 12032)
@@ -0,0 +1,33 @@
+
+/*
+	InternalFront.h
+*/
+
+
+#ifndef _INTERNALFRONT_H
+#define _INTERNALFRONT_H
+
+/* local prototypes: */
+void InternalFrontUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+#include "../../c/io/io.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "InternalFront"
+
+/* serial input macros: */
+#define MODEL (mxArray*)prhs[0]
+
+/* serial output macros: */
+#define FRONT (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  1
+
+#endif
Index: /issm/trunk-jpl/src/modules/InterpFromGridToMesh/InterpFromGridToMesh.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromGridToMesh/InterpFromGridToMesh.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromGridToMesh/InterpFromGridToMesh.cpp	(revision 12032)
@@ -0,0 +1,95 @@
+/*!\file InterpFromGridToMesh.c
+ * \brief: data interpolation from a list of (x,y,values) into mesh vertices
+ 
+	InterpFromGridToMesh.c
+
+	usage:
+	data_mesh=InterpFromGridToMesh(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 vertices onto which we interpolate.
+		
+		output: 
+		data_mesh:  vector of mesh interpolated data.
+*/
+	
+#include "./InterpFromGridToMesh.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+	int i,j;
+
+	/*input: */
+	double* x=NULL;
+	double* y=NULL;
+	int     x_rows,y_rows;
+	double* data=NULL; 
+	int     data_rows,data_cols;
+	double* x_mesh=NULL;
+	double* y_mesh=NULL;
+	int     x_mesh_rows,y_mesh_rows;
+	double  default_value;
+	int     interpolationenum;
+
+	/* output: */
+	Vector*  data_mesh=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	//CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromGridToMeshUsage);
+	if((nlhs!=NLHS) || (nrhs!=6 && nrhs!=7)){
+		InterpFromGridToMeshUsage();
+		_error_(" usage. See above");
+	}
+
+	/*Input datasets: */
+	FetchData(&x,&x_rows,NULL,XHANDLE);
+	FetchData(&y,&y_rows,NULL,YHANDLE);
+	FetchData(&data,&data_rows,&data_cols,DATAHANDLE);
+	FetchData(&x_mesh,&x_mesh_rows,NULL,XMESHHANDLE);
+	FetchData(&y_mesh,&y_mesh_rows,NULL,YMESHHANDLE);
+	FetchData(&default_value,DEFAULTHANDLE);
+
+	/* Run core computations: */
+	if(nrhs==7){
+		FetchData(&interpolationenum,INTERPENUM);
+		InterpFromGridToMeshx(&data_mesh, x, x_rows,  y, y_rows, data, data_rows,data_cols, x_mesh, y_mesh, x_mesh_rows,default_value,interpolationenum);
+	}
+	else{
+		InterpFromGridToMeshx(&data_mesh, x, x_rows,  y, y_rows, data, data_rows,data_cols, x_mesh, y_mesh, x_mesh_rows,default_value);
+	}
+
+	/*Write data: */
+	WriteData(DATAMESH,data_mesh);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void InterpFromGridToMeshUsage(void)
+{
+	_printf_(true,"INTERPFROMGRIDTOMESH - interpolation from a grid onto a list of points\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This function is a multi-threaded mex file that interpolates a field\n");
+	_printf_(true,"   defined on a grid onto a list of points\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      data_mesh=InterpFromGridToMesh(x,y,data,x_mesh,y_mesh,default_value);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      data: matrix holding the data to be interpolated onto the mesh.\n");
+	_printf_(true,"      x,y: coordinates of matrix data. (x and y must be in increasing order)\n");
+	_printf_(true,"      x_mesh,y_mesh: coordinates of the points onto which we interpolate.\n");
+	_printf_(true,"      default_value: default value if no data is found (holes).\n");
+	_printf_(true,"      data_mesh: vector of mesh interpolated data.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Example:\n");
+	_printf_(true,"      load('velocities.mat');\n");
+	_printf_(true,"      md.inversion.vx_obs=InterpFromGridToMesh(x_n,y_m,vx,md.mesh.x,md.mesh.y,0);\n");
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/InterpFromGridToMesh/InterpFromGridToMesh.h
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromGridToMesh/InterpFromGridToMesh.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromGridToMesh/InterpFromGridToMesh.h	(revision 12032)
@@ -0,0 +1,42 @@
+/*!\file InterpFromGridToMesh.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _InterpFromGridToMesh_H
+#define _InterpFromGridToMesh_H
+
+/* local prototypes: */
+void InterpFromGridToMeshUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "InterpFromGridToMesh"
+
+#undef CLEANUP
+#define CLEANUP InterpFromGridToMeshLocalCleanup();
+
+
+/* serial input macros: */
+#define XHANDLE prhs[0]
+#define YHANDLE prhs[1]
+#define DATAHANDLE prhs[2]
+#define XMESHHANDLE prhs[3]
+#define YMESHHANDLE prhs[4]
+#define DEFAULTHANDLE prhs[5]
+#define INTERPENUM prhs[6]
+
+/* serial output macros: */
+#define DATAMESH (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  6
+
+#endif  /* _INTERPFROMGRIDTOMESH_H */
Index: /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.cpp	(revision 12032)
@@ -0,0 +1,169 @@
+/*!\file InterpFromMesh2d.c
+ * \brief: data interpolation from a list of (x,y,values) into mesh vertices
+ 
+	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 vertices 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;
+	int     dummy;
+
+	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;
+
+
+	double* default_values=NULL;
+	int     num_default_values=0;
+
+	//contours
+	mxArray*  matlabstructure=NULL;
+	Contour** contours=NULL;
+	int       numcontours;
+	Contour*  contouri=NULL;
+	int       i;
+
+	/*Intermediary*/
+	int nods_data;
+	int nels_data;
+	int nods_prime;
+
+	/* output: */
+	Vector*  data_prime=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if(nlhs!=NLHS){
+		InterpFromMesh2dUsage();
+		_error_("InterpFromMeshToMesh2dUsage usage error");
+	}
+	if((nrhs!=6) && (nrhs!=7) && (nrhs!=8)){
+		InterpFromMesh2dUsage();
+		_error_("InterpFromMeshToMesh2dUsage usage error");
+	}
+
+	/*Input datasets: */
+	FetchData(&index_data,&index_data_rows,&dummy,INDEXHANDLE);
+	FetchData(&x_data,&x_data_rows,NULL,XHANDLE);
+	FetchData(&y_data,&y_data_rows,NULL,YHANDLE);
+	FetchData(&data,&data_rows,&data_cols,DATAHANDLE);
+	FetchData(&x_prime,&x_prime_rows,NULL,XPRIMEHANDLE);
+	FetchData(&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE);
+
+	if(nrhs>=7){
+		/*default values: */
+		FetchData(&default_values,&num_default_values,DEFAULTHANDLE);
+	}
+	else{
+		default_values=NULL;
+		num_default_values=0;
+	}
+
+	if(nrhs>=8){
+		
+		/*Call expread on filename to build a contour array in the matlab workspace: */
+		mexCallMATLAB( 1, &matlabstructure, 1, (mxArray**)&FILENAME, "expread");
+
+		/*contours: */
+		numcontours=mxGetNumberOfElements(matlabstructure);
+		contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+		for(i=0;i<numcontours;i++){
+			//allocate
+			contouri=(Contour*)xmalloc(sizeof(Contour));
+			//retrieve dimension of this contour.
+			contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
+			//set pointers.
+			contouri->x=mxGetPr(mxGetField(matlabstructure,i,"x"));
+			contouri->y=mxGetPr(mxGetField(matlabstructure,i,"y"));
+			*(contours+i)=contouri;
+		}
+
+		/* Debugging of contours :{{{1*/
+		/*for(i=0;i<numcontours;i++){
+		  printf("\nContour echo: contour number  %i / %i\n",i+1,numcontours);
+		  contouri=*(contours+i);
+		  printf("   Number of vertices %i\n",contouri->nods);
+		  for (j=0;j<contouri->nods;j++){
+		  printf("   %lf %lf\n",*(contouri->x+j),*(contouri->y+j));
+		  }
+		  }*/
+		/*}}}*/
+	}
+	else{
+		numcontours=0;
+		contours=NULL;
+	}
+
+
+	/*some checks*/
+	if (x_data_rows!=y_data_rows){
+		_error_("vectors x and y should have the same length!");
+	}
+	if (x_prime_rows!=y_prime_rows){
+		_error_("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;
+
+	/* Run core computations: */
+	InterpFromMesh2dx(&data_prime,index_data,x_data,y_data,nods_data,nels_data,data,data_rows,x_prime,y_prime,nods_prime,default_values,num_default_values,contours,numcontours);
+
+	/*Write data: */
+	WriteData(DATAPRIME,data_prime);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void InterpFromMesh2dUsage(void)
+{
+	_printf_(true,"   usage:\n");
+	_printf_(true,"         data_prime=InterpFromMesh2d(index,x,y,data,x_prime,y_prime);\n\n");
+	_printf_(true,"      or data_prime=InterpFromMesh2d(index,x,y,data,x_prime,y_prime,default_value);\n\n");
+	_printf_(true,"      or data_prime=InterpFromMesh2d(index,x,y,data,x_prime,y_prime,default_value,contourname);\n\n");
+	_printf_(true,"   where:\n");
+	_printf_(true,"      x,y: coordinates of the nodes where data is defined\n");
+	_printf_(true,"      index: index of the mesh where data is defined\n");
+	_printf_(true,"      data - vector holding the data to be interpolated onto the points.\n");
+	_printf_(true,"      x_prime,y_prime: coordinates of the mesh vertices onto which we interpolate.\n");
+	_printf_(true,"      default_value: a scalar or vector of size length(x_prime).\n");
+	_printf_(true,"      contourname: linear interpolation will happen on all x_interp,y_interp inside the contour, default value will be adopted on the rest of the mesh.\n");
+	_printf_(true,"      data_prime:  vector of prime interpolated data.\n");
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.h
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.h	(revision 12032)
@@ -0,0 +1,40 @@
+/*!\file InterpFromMesh2d.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _INTERPFROMMESH2D_H
+#define _INTERPFROMMESH2D_H
+
+/* local prototypes: */
+void InterpFromMesh2dUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.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]
+#define DEFAULTHANDLE prhs[6]
+#define FILENAME prhs[7]
+
+/* serial output macros: */
+#define DATAPRIME (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+
+#endif  /* _INTERPFROMMESH2D_H */
Index: /issm/trunk-jpl/src/modules/InterpFromMeshToGrid/InterpFromMeshToGrid.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMeshToGrid/InterpFromMeshToGrid.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromMeshToGrid/InterpFromMeshToGrid.cpp	(revision 12032)
@@ -0,0 +1,79 @@
+/*\file InterpFromMeshToGrid.c
+ *\brief: compute diff between observed and modeled velocity
+ */
+
+#include "./InterpFromMeshToGrid.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*input datasets: */
+	double* index=NULL;
+	int     nel;
+	double* x=NULL;
+	int     nods;
+	double* y=NULL;
+	double* meshdata=NULL;
+	int     meshdata_length;
+	double  xmin;
+	double  ymax;
+	double  xposting;
+	double  yposting;
+	int     nlines,ncols;
+	double  default_value;
+
+	/* output datasets: */
+	double* griddata=NULL;
+	double* x_m=NULL;
+	double* y_m=NULL;
+
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromMeshToGridUsage);
+
+	/*Input datasets: */
+	FetchData(&index,&nel,NULL,INDEX);
+	FetchData(&x,&nods,NULL,X);
+	FetchData(&y,NULL,NULL,Y);
+	FetchData(&meshdata,&meshdata_length,NULL,MESHDATA);
+	FetchData(&xmin,XMIN);
+	FetchData(&ymax,YMAX);
+	FetchData(&xposting,XPOSTING);
+	FetchData(&yposting,YPOSTING);
+	FetchData(&nlines,NLINES);
+	FetchData(&ncols,NCOLS);
+	FetchData(&default_value,DEFAULTVALUE);
+
+	/*Call core of computation: */
+	InterpFromMeshToGridx(&x_m,&y_m,&griddata,index,x,y,nods,nel,meshdata,meshdata_length,xmin,ymax,xposting,yposting,nlines,ncols,default_value);
+
+	/*Write results: */
+	WriteData(XM,x_m,ncols);
+	WriteData(YM,y_m,nlines);
+	WriteData(GRIDDATA,griddata,nlines,ncols);
+
+	/*Free ressources: */
+	//let matlab do this.
+	
+	/*end module: */
+	MODULEEND();
+}
+
+void InterpFromMeshToGridUsage(void)
+{
+	_printf_(true,"INTERPFROMMESHTOGRID - interpolation of a data defined on a mesh onto a grid\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This function is a multi-threaded mex file that interpolates a field\n");
+	_printf_(true,"   defined on a triangular mesh onto a regular grid\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [x_m,y_m,griddata]=InterpFromMeshToGrid(index,x,y,data,xmin,ymax,xposting,yposting,nlines,ncols,default_value)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      index,x,y: delaunay triangulation defining the mesh.\n");
+	_printf_(true,"      meshdata: vertex values of data to be interpolated.\n");
+	_printf_(true,"      xmin,ymax,posting,nlines,ncols: parameters that define the grid\n");
+	_printf_(true,"      default_value: value of points located out of the mesh.\n");
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/InterpFromMeshToGrid/InterpFromMeshToGrid.h
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMeshToGrid/InterpFromMeshToGrid.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromMeshToGrid/InterpFromMeshToGrid.h	(revision 12032)
@@ -0,0 +1,46 @@
+
+/*
+	InterpFromMeshToGrid.h
+*/
+
+
+#ifndef _INTERPFROMMESHTOGRID_H
+#define _INTERPFROMMESHTOGRID_H
+
+/* local prototypes: */
+void InterpFromMeshToGridUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "InterpFromMeshToGrid"
+
+/* serial input macros: */
+#define INDEX (mxArray*)prhs[0]
+#define X (mxArray*)prhs[1]
+#define Y (mxArray*)prhs[2]
+#define MESHDATA (mxArray*)prhs[3]
+#define XMIN (mxArray*)prhs[4]
+#define YMAX (mxArray*)prhs[5]
+#define XPOSTING (mxArray*)prhs[6]
+#define YPOSTING (mxArray*)prhs[7]
+#define NLINES (mxArray*)prhs[8]
+#define NCOLS (mxArray*)prhs[9]
+#define DEFAULTVALUE (mxArray*)prhs[10]
+
+/* serial output macros: */
+#define XM (mxArray**)&plhs[0]
+#define YM (mxArray**)&plhs[1]
+#define GRIDDATA (mxArray**)&plhs[2]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  3
+#undef NRHS
+#define NRHS  11
+
+#endif  /* _INTERPFROMMESHTOGRID_H*/
Index: /issm/trunk-jpl/src/modules/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp	(revision 12032)
@@ -0,0 +1,162 @@
+/*\file InterpFromMeshToMesh2d.c
+ *\brief: bamg module.
+ */
+#include "./InterpFromMeshToMesh2d.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i;
+
+	/*input: */
+	double* index=NULL;
+	int     index_cols;
+
+	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_interp=NULL;
+	double* y_interp=NULL;
+
+	int     x_interp_rows;
+	int     y_interp_rows;
+
+	double* default_values=NULL;
+	int     num_default_values=0;
+
+	//contours
+	mxArray*  matlabstructure=NULL;
+	Contour** contours=NULL;
+	int       numcontours;
+	Contour*  contouri=NULL;
+
+	/*Intermediary*/
+	int nods_data;
+	int nels_data;
+	int nods_interp;
+	int verbose=0;
+
+	/* output: */
+	double* data_interp=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if(nlhs!=NLHS){
+		InterpFromMeshToMesh2dUsage();
+		_error_("InterpFromMeshToMesh2dUsage usage error");
+	}
+	if((nrhs!=6) & (nrhs!=8)){
+		InterpFromMeshToMesh2dUsage();
+		_error_("InterpFromMeshToMesh2dUsage usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs\n");
+	FetchData(&index,&nels_data,&index_cols,INDEXHANDLE);
+	FetchData(&x_data,&x_data_rows,NULL,XHANDLE);
+	FetchData(&y_data,&y_data_rows,NULL,YHANDLE);
+	FetchData(&data,&data_rows,&data_cols,DATAHANDLE);
+	FetchData(&x_interp,&x_interp_rows,NULL,XINTERPHANDLE);
+	FetchData(&y_interp,&y_interp_rows,NULL,YINTERPHANDLE);
+
+	if(nrhs==8){
+		
+		/*Call expread on filename to build a contour array in the matlab workspace: */
+		mexCallMATLAB( 1, &matlabstructure, 1, (mxArray**)&FILENAME, "expread");
+
+		/*default values: */
+		FetchData(&default_values,&num_default_values,DEFAULTHANDLE);
+
+		/*contours: */
+		numcontours=mxGetNumberOfElements(matlabstructure);
+		contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+		for(i=0;i<numcontours;i++){
+			//allocate
+			contouri=(Contour*)xmalloc(sizeof(Contour));
+			//retrieve dimension of this contour.
+			contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
+			//set pointers.
+			contouri->x=mxGetPr(mxGetField(matlabstructure,i,"x"));
+			contouri->y=mxGetPr(mxGetField(matlabstructure,i,"y"));
+			*(contours+i)=contouri;
+		}
+
+		/* Debugging of contours :{{{1*/
+		/*for(i=0;i<numcontours;i++){
+		  printf("\nContour echo: contour number  %i / %i\n",i+1,numcontours);
+		  contouri=*(contours+i);
+		  printf("   Number of vertices %i\n",contouri->nods);
+		  for (j=0;j<contouri->nods;j++){
+		  printf("   %lf %lf\n",*(contouri->x+j),*(contouri->y+j));
+		  }
+		  }*/
+		/*}}}*/
+	}
+	else{
+		num_default_values=0;
+		default_values=NULL;
+		numcontours=0;
+		contours=NULL;
+	}
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs\n");
+	if (x_data_rows!=y_data_rows){
+		_error_("vectors x and y should have the same length!");
+	}
+	if (x_interp_rows!=y_interp_rows){
+		_error_("vectors x_interp and y_interp should have the same length!");
+	}
+	if (index_cols!=3){
+		_error_("index should have 3 columns (input provided has %i columns)",index_cols);
+	}
+
+	/*get number of elements and number of nodes in the data*/
+	nods_data=x_data_rows;
+	nods_interp=x_interp_rows;
+
+	/* Run core computations: */
+	if (verbose) printf("Call core\n");
+	InterpFromMeshToMesh2dx(&data_interp,index,x_data,y_data,nods_data,nels_data,data,data_rows,data_cols,x_interp,y_interp,nods_interp,default_values,num_default_values,contours,numcontours);
+
+	/*Write data: */
+	WriteData(DATAINTERP,data_interp,nods_interp,data_cols);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void InterpFromMeshToMesh2dUsage(void)
+{
+	_printf_(true,"INTERFROMMESHTOMESH2D - interpolation from a 2d triangular mesh onto a list of point\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This function is a multi-threaded mex file that interpolates a field\n");
+	_printf_(true,"   defined on a triangular mesh onto a list of point\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"         data_interp=InterpFromMeshToMesh2d(index,x,y,data,x_interp,y_interp);\n");
+	_printf_(true,"      or data_interp=InterpFromMeshToMesh2d(index,x,y,data,x_interp,y_interp,default_value,contourname);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      index: index of the mesh where data is defined\n");
+	_printf_(true,"      x,y: coordinates of the nodes where data is defined\n");
+	_printf_(true,"      data: matrix holding the data to be interpolated onto the mesh. (one column per field)\n");
+	_printf_(true,"      x_interp,y_interp: coordinates of the points onto which we interpolate.\n");
+	_printf_(true,"      if default_value and contourname not specified: linear interpolation will happen on all x_interp,y_interp.\n");
+	_printf_(true,"      if (default_value,contourname) specified: linear interpolation will happen on all x_interp,y_interp inside the contour, default value will be adopted on the rest of the mesh.\n");
+	_printf_(true,"      note that default_value is either a scalar, or a vector of size  length(x_interp)\n");
+	_printf_(true,"      data_interp: vector of mesh interpolated data.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Example:\n");
+	_printf_(true,"      load('temperature.mat');\n");
+	_printf_(true,"      md.initialization.temperature=InterpFromMeshToMesh2d(index,x,y,temperature,md.mesh.x,md.mesh.y);\n");
+	_printf_(true,"      md.initialization.temperature=InterpFromMeshToMesh2d(index,x,y,temperature,md.mesh.x,md.mesh.y,253,'Contour.exp');\n");
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h	(revision 12032)
@@ -0,0 +1,38 @@
+/*!\file InterpFromMeshToMesh2d.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _INTERPFROMMESHTOMESH2d_H
+#define _INTERPFROMMESHTOMESH2d_H
+
+/* local prototypes: */
+void InterpFromMeshToMesh2dUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "InterpFromMeshToMesh2d"
+
+
+/* serial input macros: */
+#define INDEXHANDLE prhs[0]
+#define XHANDLE prhs[1]
+#define YHANDLE prhs[2]
+#define DATAHANDLE prhs[3]
+#define XINTERPHANDLE prhs[4]
+#define YINTERPHANDLE prhs[5]
+#define DEFAULTHANDLE prhs[6]
+#define FILENAME prhs[7]
+
+/* serial output macros: */
+#define DATAINTERP (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+
+#endif
Index: /issm/trunk-jpl/src/modules/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.cpp	(revision 12032)
@@ -0,0 +1,119 @@
+/*!\file InterpFromMeshToMesh3d.c
+ * \brief: data interpolation from a list of (x,y,values) into mesh vertices
+ 
+	InterpFromMeshToMesh3d.c
+
+	usage:
+	data_mesh=InterpFromMeshToMesh3d(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 vertices onto which we interpolate.
+		
+		output: 
+		data_mesh:  vector of mesh interpolated data.
+
+*/
+	
+#include "./InterpFromMeshToMesh3d.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;
+
+	double  default_value;
+
+	/*Intermediary*/
+	int nods_data;
+	int nels_data;
+	int nods_prime;
+
+	/* output: */
+	Vector*  data_prime=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&InterpFromMeshToMesh3dUsage);
+
+	/*Input datasets: */
+	FetchData(&index_data,&index_data_rows,NULL,INDEXHANDLE);
+	FetchData(&x_data,&x_data_rows,NULL,XHANDLE);
+	FetchData(&y_data,&y_data_rows,NULL,YHANDLE);
+	FetchData(&z_data,&z_data_rows,NULL,ZHANDLE);
+	FetchData(&data,&data_rows,&data_cols,DATAHANDLE);
+	FetchData(&x_prime,&x_prime_rows,NULL,XPRIMEHANDLE);
+	FetchData(&y_prime,&y_prime_rows,NULL,YPRIMEHANDLE);
+	FetchData(&z_prime,&z_prime_rows,NULL,ZPRIMEHANDLE);
+	FetchData(&default_value,DEFAULTHANDLE);
+
+	/*some checks*/
+	if (x_data_rows!=y_data_rows || x_data_rows!=z_data_rows){
+		_error_("vectors x, y and z should have the same length!");
+	}
+	if (x_prime_rows!=y_prime_rows || x_prime_rows!=z_prime_rows){
+		_error_("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;
+
+	/* Run core computations: */
+	InterpFromMeshToMesh3dx(&data_prime,index_data,x_data,y_data,z_data,nods_data,nels_data,data,data_rows,x_prime,y_prime,z_prime,nods_prime,default_value);
+
+	/*Write data: */
+	WriteData(DATAPRIME,data_prime);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void InterpFromMeshToMesh3dUsage(void)
+{
+	_printf_(true,"INTERPFROMMESHTOMESH3D - interpolation from a 3d hexahedron mesh onto a list of point\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This function is a multi-threaded mex file that interpolates a field\n");
+	_printf_(true,"   defined on a triangular mesh onto a list of point\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      data_prime=InterpFromMeshToMesh3d(index,x,y,z,data,x_prime,y_prime,z_prime,default_value);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      index: index of the mesh where data is defined\n");
+	_printf_(true,"      x,y,z: coordinates of the nodes where data is defined\n");
+	_printf_(true,"      data: matrix holding the data to be interpolated onto the mesh.\n");
+	_printf_(true,"      x_prime,y_prime,z_prime: coordinates of the points onto which we interpolate.\n");
+	_printf_(true,"      default_value: default value if no data is found (holes).\n");
+	_printf_(true,"      data_prime: vector of mesh interpolated data.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Example:\n");
+	_printf_(true,"      load('temperature.mat');\n");
+	_printf_(true,"      md.initialization.temperature=InterpFromMeshToMesh3d(index,x,y,z,temperature,md.mesh.x,md.mesh.y,md.mesh.z,253);\n");
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h	(revision 12032)
@@ -0,0 +1,44 @@
+/*!\file InterpFromMeshToMesh3d.h
+ * \brief: prototype for Data Interpolation mex module.
+ */
+
+#ifndef _INTERPFROMMESH3D_H
+#define _INTERPFROMMESH3D_H
+
+/* local prototypes: */
+void InterpFromMeshToMesh3dUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "InterpFromMeshToMesh3d"
+
+#undef CLEANUP
+#define CLEANUP InterpFromMeshToMesh3dLocalCleanup();
+
+
+/* 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]
+#define DEFAULTHANDLE prhs[8]
+
+/* serial output macros: */
+#define DATAPRIME (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  9
+
+#endif  /* _INTERPFROMMESHTOMESH3D_H */
Index: /issm/trunk-jpl/src/modules/KMLFileRead/KMLFileRead.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/KMLFileRead/KMLFileRead.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/KMLFileRead/KMLFileRead.cpp	(revision 12032)
@@ -0,0 +1,151 @@
+/*\file KMLFileRead.c
+ *\brief: KML file reader module.
+ */
+#include "./KMLFileRead.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,j,nnodes=0,verbose=1;
+	KML_Object* kobj;
+
+	/*input: */
+	char*   name=NULL;
+
+	char*   notes=NULL;
+	const mxArray* notesi;
+	mwIndex        nindex;
+
+	int*    elem=NULL;
+	int     melem=0,nelem=0;
+
+	int*    nodecon=NULL;
+	int     mncon=0,nncon=0;
+
+	double* lat=NULL;
+	int     mlat=0,nlat=0,llat=0;
+
+	double* lng=NULL;
+	int     mlng=0,nlng=0,llng=0;
+
+	int     nparts=0;
+
+	int*    part=NULL;
+	int     mprt=0,nprt=0,lprt=0;
+
+	double* data=NULL;
+	int     mdata=0,ndata=0;
+
+	double* cmap=NULL;
+	int     mcmap=0,ncmap=0;
+
+	char*   filnam=NULL;
+
+	FILE*   fidi=NULL;
+	FILE*   fido=NULL;
+
+	Options* options=NULL;
+	char*    echo    =NULL;
+	char*    deepecho=NULL;
+	char*    write   =NULL;
+
+	/* output: */
+	int     ierror=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		KMLFileReadUsage();
+		_error_("KMLFileRead usage error");
+	}
+	if (nrhs < NRHS) {
+		KMLFileReadUsage();
+		_error_("KMLFileRead usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&filnam,FILENAME);
+	if (verbose) printf("  filnam =\"%s\"\n",filnam);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+	options->Get(&echo    ,"echo"    ,"off");
+	options->Get(&deepecho,"deepecho","off");
+	options->Get(&write   ,"write"   ,"off");
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if (!strlen(filnam))
+		strcpy(filnam,"stdout");
+
+	if (verbose) printf("Opening file \"%s\".\n",filnam);
+	fidi=fopen(filnam,"r");
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	kobj=KMLFileReadx(fidi);
+
+	if (verbose) printf("Closing file \"%s\".\n",filnam);
+	fclose(fidi);
+
+	if (kobj) {
+		if (!strncmp(echo    ,"on",2) || !strncmp(echo    ,"y",1))
+			kobj->Echo();
+		if (!strncmp(deepecho,"on",2) || !strncmp(deepecho,"y",1))
+			kobj->DeepEcho();
+		if (strncmp(write,"off",3) && strncmp(write,"no",2)) {
+			if (!strncmp(write,"on",2) || !strncmp(write,"yes",3) || !strncmp(write,"stdout",6)) {
+				kobj->Write(stdout,"");
+			}
+			else {
+				if (verbose) printf("Opening file \"%s\".\n",write);
+				fido=fopen(write,"w");
+				kobj->Write(fido,"");
+				if (verbose) printf("Closing file \"%s\".\n",write);
+				ierror=fclose(fido);
+			}
+		}
+
+		delete kobj;
+	}
+
+	/*Write data: */
+	WriteData(ERRORFLAG,ierror);
+
+	/*Clean-up*/
+	xfree((void**)&write);
+	xfree((void**)&deepecho);
+	xfree((void**)&echo);
+	delete options;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void KMLFileReadUsage(void)
+{
+	_printf_(true,"KMLFileRead - KML file reader module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module reads a KML file.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [ierror]=KMLFileRead(kmlfile,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      kmlfile      file name of kml file to be read (char)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      echo         echo command (char, optional, 'off'/'on')\n");
+	_printf_(true,"      deepecho     deep echo command (char, optional, 'off'/'on')\n");
+	_printf_(true,"      write        write command (char, optional, 'off'/'stdout'/kmlfile)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      ierror       return code (non-zero for error)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Examples:\n");
+	_printf_(true,"      [ierror]=KMLFileRead('file.kml','deepecho','on');\n");
+	_printf_(true,"      [ierror]=KMLFileRead('filin.kml','echo','on','write','filout.kml');\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/KMLFileRead/KMLFileRead.h
===================================================================
--- /issm/trunk-jpl/src/modules/KMLFileRead/KMLFileRead.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/KMLFileRead/KMLFileRead.h	(revision 12032)
@@ -0,0 +1,33 @@
+/*!\file KMLFileRead.h
+ * \brief: prototype for KML file reader mex module.
+ */
+
+#ifndef _KMLFILEREAD_H
+#define _KMLFILEREAD_H
+
+/* local prototypes: */
+void KMLFileReadUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "KMLFileRead"
+
+
+/* serial input macros: */
+#define FILENAME      prhs[0]
+
+/* serial output macros: */
+#define ERRORFLAG (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  1
+#undef NLHS
+#define NLHS  1
+
+#endif
Index: /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp	(revision 12032)
@@ -0,0 +1,198 @@
+/*\file KMLMeshWrite.c
+ *\brief: KML mesh writer module.
+ */
+#include "./KMLMeshWrite.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,j,nnodes=0,verbose=1;
+
+	/*input: */
+	char*   name=NULL;
+
+	char*   notes=NULL;
+	const mxArray* notesi;
+	mwIndex        nindex;
+
+	int*    elem=NULL;
+	int     melem=0,nelem=0;
+
+	int*    nodecon=NULL;
+	int     mncon=0,nncon=0;
+
+	double* lat=NULL;
+	int     mlat=0,nlat=0,llat=0;
+
+	double* lng=NULL;
+	int     mlng=0,nlng=0,llng=0;
+
+	int     nparts=0;
+
+	int*    part=NULL;
+	int     mprt=0,nprt=0,lprt=0;
+
+	double* data=NULL;
+	int     mdata=0,ndata=0;
+
+	double* cmap=NULL;
+	int     mcmap=0,ncmap=0;
+
+	char*   filnam=NULL;
+
+	FILE*   fid=NULL;
+
+	Options* options=NULL;
+
+	/* output: */
+	int     ierror=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		KMLMeshWriteUsage();
+		_error_("KMLMeshWrite usage error");
+	}
+	if (nrhs < NRHS) {
+		KMLMeshWriteUsage();
+		_error_("KMLMeshWrite usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&name,NAME);
+	if (verbose) printf("  name   =\"%s\"\n",name);
+
+/*  notes is typically a cell array of character strings  */
+	if (mxIsCell(NOTES)) {
+		for (nindex=0; nindex<mxGetNumberOfElements(NOTES); nindex++) {
+			notesi=mxGetCell(NOTES,nindex);
+			if (notesi && mxIsChar(notesi) && mxGetNumberOfElements(notesi)) {
+				if (!notes) {
+					notes=(char *) xmalloc((mxGetNumberOfElements(notesi)+1)*sizeof(char));
+					mxGetString(notesi,notes,mxGetNumberOfElements(notesi)+1);
+				}
+				else {
+/*  note that strlen does not include trailing null  */
+					notes=(char *) xrealloc(notes,(strlen(notes)+1+mxGetNumberOfElements(notesi)+1)*sizeof(char));
+					strcat(notes,"\n");
+					mxGetString(notesi,&notes[strlen(notes)],mxGetNumberOfElements(notesi)+1);
+				}
+			}
+		}
+	}
+	else
+		FetchData(&notes,NOTES);
+	if (verbose) printf("  notes  =\"%s\"\n",notes);
+
+	FetchData(&elem,&melem,&nelem,ELEMHANDLE);
+	if (verbose) printf("  elem   =size [%d x %d]\n",melem,nelem);
+	FetchData(&nodecon,&mncon,&nncon,NODECONHANDLE);
+	if (verbose) printf("  nodecon=size [%d x %d]\n",mncon,nncon);
+	FetchData(&lat,&mlat,&nlat,LATHANDLE);
+	llat=mlat*nlat;
+	if (verbose) printf("  lat    =length [%d]\n",llat);
+	FetchData(&lng,&mlng,&nlng,LNGHANDLE);
+	llng=mlng*nlng;
+	if (verbose) printf("  lng    =length [%d]\n",llng);
+	FetchData(&part,&mprt,&nprt,PARTHANDLE);
+	lprt=mprt*nprt;
+	if (verbose) printf("  part   =length [%d]\n",lprt);
+	FetchData(&data,&mdata,&ndata,DATAHANDLE);
+	if (verbose) printf("  data   =size [%d x %d]\n",mdata,ndata);
+	FetchData(&cmap,&mcmap,&ncmap,CMAPHANDLE);
+	if (verbose) printf("  cmap   =size [%d x %d]\n",mcmap,ncmap);
+	FetchData(&filnam,FILENAME);
+	if (verbose) printf("  filnam =\"%s\"\n",filnam);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+//	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	for (i=0; i<melem*nelem; i++)
+		if (elem[i] > nnodes)
+			nnodes=elem[i];
+	if (verbose) printf("  nnodes =%d\n",nnodes);
+	if (part)
+		for (i=0; i<lprt; i++)
+			if (part[i]+1 > nparts)
+				nparts=part[i]+1;
+	if (verbose) printf("  nparts =%d\n",nparts);
+
+	if      (nodecon && (mncon != nnodes))
+		_error_("Nodal connectivity table, if supplied, must be supplied for all nodes.");
+	else if (!nodecon)
+		mncon=nnodes;
+	if ((llat != nnodes) || (llng != nnodes) || (llat != llng))
+		_error_("Latitude and longitude vectors must be supplied for all nodes.");
+	if (part && (lprt != nnodes))
+		_error_("Partitioning vector, if supplied, must be supplied for all nodes.");
+	if (data && !((mdata == nnodes) || (mdata == melem)))
+		_error_("Data matrix, if supplied, must be supplied for all nodes or all elements.");
+	if (cmap && (ncmap != 3))
+		_error_("Colormap matrix, if supplied, must have three columns for rgb.");
+
+	if (!strlen(filnam))
+		strcpy(filnam,"stdout");
+
+	if (verbose) printf("Opening file \"%s\".\n",filnam);
+	fid=fopen(filnam,"w");
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	KMLMeshWritex(&ierror,
+				  name,
+				  notes,
+				  elem,melem,nelem,
+				  nodecon,mncon,nncon,
+				  lat,lng,
+				  part,
+				  data,mdata,ndata,
+				  cmap,mcmap,ncmap,
+				  fid);
+
+	if (verbose) printf("Closing file \"%s\".\n",filnam);
+	fclose(fid);
+
+	/*Write data: */
+	WriteData(ERRORFLAG,ierror);
+
+	/*Clean-up*/
+	delete options;
+	if (mxIsCell(NOTES) && notes) xfree((void**)&notes);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void KMLMeshWriteUsage(void)
+{
+	_printf_(true,"KMLMeshWrite - KML mesh writer module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module writes the mesh of a model as KML polygons into the specified KML file.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      ierror=KMLMeshWrite(name,notes,elem,nodecon,lat,long,part,data,cmap,kmlfile);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      name       model name (string, may be empty)\n");
+	_printf_(true,"      notes      model notes (string or cell array of strings, may be empty)\n");
+	_printf_(true,"      elem       elements (double array)\n");
+	_printf_(true,"      nodecon    nodal connectivity array (double array, may be empty)\n");
+	_printf_(true,"      lat        nodal latititudes (double vector)\n");
+	_printf_(true,"      long       nodal longitudes (double vector)\n");
+	_printf_(true,"      part       nodal partitions (double vector, may be empty)\n");
+	_printf_(true,"      data       nodal or element data (double vector, may be empty)\n");
+	_printf_(true,"      cmap       color map (double nx3 array, may be empty)\n");
+	_printf_(true,"      kmlfile    KML file name (string)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      ierror     error flag (double, non-zero for error)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Example:\n");
+	_printf_(true,"      KMLMeshWrite(md.name,md.notes,md.elements,md.nodeconnectivity,md.lat,md.long,md.part,md.fm_criterion,options.cmap,filekml);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.h
===================================================================
--- /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.h	(revision 12032)
@@ -0,0 +1,42 @@
+/*!\file KMLMeshWrite.h
+ * \brief: prototype for KML mesh writer mex module.
+ */
+
+#ifndef _KMLMESHWRITE_H
+#define _KMLMESHWRITE_H
+
+/* local prototypes: */
+void KMLMeshWriteUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "KMLMeshWrite"
+
+
+/* serial input macros: */
+#define NAME          prhs[0]
+#define NOTES         prhs[1]
+#define ELEMHANDLE    prhs[2]
+#define NODECONHANDLE prhs[3]
+#define LATHANDLE     prhs[4]
+#define LNGHANDLE     prhs[5]
+#define PARTHANDLE    prhs[6]
+#define DATAHANDLE    prhs[7]
+#define CMAPHANDLE    prhs[8]
+#define FILENAME      prhs[9]
+
+/* serial output macros: */
+#define ERRORFLAG (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS 10
+#undef NLHS
+#define NLHS  1
+
+#endif
Index: /issm/trunk-jpl/src/modules/KMLOverlay/KMLOverlay.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/KMLOverlay/KMLOverlay.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/KMLOverlay/KMLOverlay.cpp	(revision 12032)
@@ -0,0 +1,149 @@
+/*\file KMLOverlay.c
+ *\brief: KML file overlay mex module.
+ */
+#include "./KMLOverlay.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	char*   filkml=NULL;
+	char*   filkmz=NULL;
+
+	FILE*   fid=NULL;
+
+	Options* options=NULL;
+	int      nlat=0,nlong=0;
+	double*  lataxis =NULL;
+	double*  longaxis=NULL;
+	int      nimages=0;
+	char**   pimages=NULL;
+	double   dzip=0;
+	char*    czip=NULL;
+
+	/* output: */
+	int     ierror=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		KMLOverlayUsage();
+		_error_("KMLOverlay usage error");
+	}
+	if (nrhs < NRHS) {
+		KMLOverlayUsage();
+		_error_("KMLOverlay usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&filkml,FILENAME);
+	if (verbose) printf("  filkml=\"%s\"\n",filkml);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+//	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+	options->Get(&lataxis ,&nlat ,"lataxis" );
+	if (verbose && lataxis) for (i=0; i<nlat; i++) printf("  lataxis [%d]=%g\n",i,lataxis[i]);
+	options->Get(&longaxis,&nlong,"longaxis");
+	if (verbose && longaxis) for (i=0; i<nlong; i++) printf("  longaxis[%d]=%g\n",i,longaxis[i]);
+//	((Option*)options->GetOption("images"))->DeepEcho();
+	options->Get(&pimages,&nimages,"images");
+	if (verbose && pimages) for (i=0; i<nimages; i++) printf("  pimages[%d]=\"%s\"\n",i,pimages[i]);
+	options->Get(&dzip,"zip",0.);
+	if (verbose) printf("  dzip=%g\n",dzip);
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if (nlat  != 2) _error_("Latitudinal axes \"lataxis\" require two double values, not %d.",nlat);
+	if (nlong != 2) _error_("Longitudinal axes \"longaxis\" require two double values, not %d.",nlong);
+	if (!nimages) _error_("No image files provided.");
+
+	if ((int)dzip) {
+		filkmz=filkml;
+		filkml=(char *) xmalloc(8*sizeof(char));
+		strcpy(filkml,"doc.kml");
+	}
+
+	if (!strlen(filkml))
+		strcpy(filkml,"stdout");
+
+	if (verbose) printf("Opening kml overlay file \"%s\".\n",filkml);
+	fid=fopen(filkml,"w");
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	KMLOverlayx(&ierror,
+				lataxis,longaxis,
+				nimages,pimages,
+				fid);
+
+	if (verbose) printf("Closing file \"%s\".\n",filkml);
+	fclose(fid);
+
+	/* Create kmz file, if specified: */
+	if ((int)dzip) {
+		czip=(char *) xmalloc((5+strlen(filkmz)+1+strlen(filkml)+1)*sizeof(char));
+		czip[0]='\0';
+		strcat(czip,"!zip ");
+		strcat(czip,filkmz);
+		strcat(czip," ");
+		strcat(czip,filkml);
+		for (i=0; i<nimages; i++)
+			if (strlen(pimages[i]) && strncmp(pimages[i],"http",4)) {
+				czip=(char *) xrealloc(czip,(strlen(czip)+1+strlen(pimages[i])+1)*sizeof(char));
+				strcat(czip," ");
+				strcat(czip,pimages[i]);
+			}
+		if (verbose) printf("Zipping file \"%s\".\n",filkmz);
+		if (verbose) printf("%s\n",czip);
+
+		if (mexEvalString(czip)) _error_("Error zipping file \"%s\".",filkmz);
+		xfree((void**)&czip);
+		xfree((void**)&filkmz);
+	}
+
+	/*Write data: */
+	WriteData(ERRORFLAG,ierror);
+
+	/*Clean-up*/
+	if (pimages) {
+		for (i=nimages; i>0; i--) xfree((void**)&(pimages[i-1]));
+		xfree((void**)&pimages);
+	}
+	xfree((void**)&longaxis);
+	xfree((void**)&lataxis);
+	delete options;
+	xfree((void**)&filkml);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void KMLOverlayUsage(void)
+{
+	_printf_(true,"KMLOverlay - KML file overlay module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module reads a list of image files and writes a KML or KMZ overlay file.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      ierror=KMLOverlay(kmlfile,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      kmlfile     KML or KMZ file name (string)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      lataxis     latitude axis (double vector [south north], required)\n");
+	_printf_(true,"      longaxis    longitude axis (double vector [west east], required)\n");
+	_printf_(true,"      images      relative or http image file names (string or array of strings or cell array of strings, required)\n");
+	_printf_(true,"      zip         flag to zip the doc.kml and image files into kmzfile (double, non-zero for kmz)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      ierror     error flag (double, non-zero for error)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Example:\n");
+	_printf_(true,"      KMLOverlay(kmlfile,'lataxis',[south north],'longaxis',[west east],'images',{'file1.png','http://issm/file2.png'},'zip',1);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/KMLOverlay/KMLOverlay.h
===================================================================
--- /issm/trunk-jpl/src/modules/KMLOverlay/KMLOverlay.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/KMLOverlay/KMLOverlay.h	(revision 12032)
@@ -0,0 +1,33 @@
+/*!\file KMLOverlay.h
+ * \brief: prototype for KML file overlay mex module.
+ */
+
+#ifndef _KMLOVERLAY_H
+#define _KMLOVERLAY_H
+
+/* local prototypes: */
+void KMLOverlayUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "KMLOverlay"
+
+
+/* serial input macros: */
+#define FILENAME      prhs[0]
+
+/* serial output macros: */
+#define ERRORFLAG (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  1
+#undef NLHS
+#define NLHS  1
+
+#endif
Index: /issm/trunk-jpl/src/modules/Kml2Exp/Kml2Exp.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/Kml2Exp/Kml2Exp.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Kml2Exp/Kml2Exp.cpp	(revision 12032)
@@ -0,0 +1,106 @@
+/*\file Kml2Exp.c
+ *\brief: kml to exp file conversion mex module.
+ */
+#include "./Kml2Exp.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	char    *filkml=NULL,*filexp=NULL;
+	int     sgn;
+
+	Options* options=NULL;
+	double   cm=0.,sp=0.;
+
+	/* output: */
+	int     iret=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		Kml2ExpUsage();
+		_error_("Kml2Exp usage error");
+	}
+	if (nrhs < NRHS) {
+		Kml2ExpUsage();
+		_error_("Kml2Exp usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&filkml,KML_IN);
+	if (verbose) printf("  filkml=\"%s\"\n",filkml);
+	FetchData(&filexp,EXP_IN);
+	if (verbose) printf("  filexp=\"%s\"\n",filexp);
+	FetchData(&sgn,SGN_IN);
+	if (verbose) printf("  sgn=%d\n",sgn);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+	/*  defaults are in Ll2xydef, so don't duplicate them here, and only use user values if both have been specified  */
+	if (options->GetOption("central_meridian") || options->GetOption("standard_parallel")) {
+		options->Get(&cm,"central_meridian");
+		if (verbose) printf("  cm=%g\n",cm);
+		options->Get(&sp,"standard_parallel");
+		if (verbose) printf("  sp=%g\n",sp);
+	}
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if (sgn != +1 && sgn != -1) _error_("Hemisphere sgn=%d must be +1 (north) or -1 (south).",sgn);
+	if (fabs(cm)      > 180.) _error_("Central meridian cm=%g must be between -180 (west) and +180 (east) degrees.",cm);
+	if (sp < 0. || sp >  90.) _error_("Standard parallel sp=%g must be between 0 and 90 degrees (in specified hemisphere).",sp);
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
+		iret=Kml2Expx(filkml,filexp,
+					  sgn,cm,sp);
+	else
+		iret=Kml2Expx(filkml,filexp,
+					  sgn);
+	if (verbose) printf("  iret=%d\n",iret);
+
+	/*Write data: */
+	WriteData(RET_OUT,iret);
+
+	/*Clean-up*/
+	delete options;
+	xfree((void**)&filexp);
+	xfree((void**)&filkml);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void Kml2ExpUsage(void)
+{
+	_printf_(true,"Kml2Exp - kml to exp file conversion module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module converts a file from kml to exp format.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [ret]=Kml2Exp(filexp,filkml,sgn,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      filkml      file name of kml file to be read (char)\n");
+	_printf_(true,"      filexp      file name of exp file to be written (char)\n");
+	_printf_(true,"      sgn         sign for hemisphere (double, +1 (north) or -1 (south))\n");
+	_printf_(true,"\n");
+	_printf_(true,"      central_meridian     central meridian (double, optional, but must specify with sp)\n");
+	_printf_(true,"      standard_parallel    standard parallel (double, optional, but must specify with cm)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      ret         return code (non-zero for warning)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Examples:\n");
+	_printf_(true,"      [ret]=Kml2Exp('file.kml','file.exp', 1);\n");
+	_printf_(true,"      [ret]=Kml2Exp('file.kml','file.exp', 1,'central_meridian',45,'standard_parallel',70);\n");
+	_printf_(true,"      [ret]=Kml2Exp('file.kml','file.exp',-1,'central_meridian', 0,'standard_parallel',71);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/Kml2Exp/Kml2Exp.h
===================================================================
--- /issm/trunk-jpl/src/modules/Kml2Exp/Kml2Exp.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Kml2Exp/Kml2Exp.h	(revision 12032)
@@ -0,0 +1,36 @@
+/*!\file Kml2Exp.h
+ * \brief: prototype for kml to exp file conversion mex module.
+ */
+
+#ifndef _KML2EXP_H
+#define _KML2EXP_H
+
+/* local prototypes: */
+void Kml2ExpUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Kml2Exp"
+
+
+/* serial input macros: */
+#define KML_IN    prhs[0]
+#define EXP_IN    prhs[1]
+#define SGN_IN    prhs[2]
+
+/* serial output macros: */
+#define RET_OUT    (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  3
+#undef NLHS
+#define NLHS  1
+
+#endif
+
Index: /issm/trunk-jpl/src/modules/Ll2xy/Ll2xy.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/Ll2xy/Ll2xy.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Ll2xy/Ll2xy.cpp	(revision 12032)
@@ -0,0 +1,121 @@
+/*\file Ll2xy.c
+ *\brief: lat/long to x/y coordinate mex module.
+ */
+#include "./Ll2xy.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	double  *lat=NULL,*lon=NULL;
+	int     nlat,nlon,ncoord;
+	int     sgn;
+
+	Options* options=NULL;
+	double   cm=0.,sp=0.;
+
+	/* output: */
+	double  *x=NULL,*y=NULL;
+	int     iret=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		Ll2xyUsage();
+		_error_("Ll2xy usage error");
+	}
+	if (nrhs < NRHS) {
+		Ll2xyUsage();
+		_error_("Ll2xy usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&lat,&nlat,LAT_IN);
+	if (verbose)
+		if   (nlat == 1) printf("  lat=%g\n",lat[0]);
+		else             printf("  lat=[%d values]\n",nlat);
+//	for (i=0; i<nlat; i++) printf("  lat[%d]=%g\n",i,lat[i]);
+	FetchData(&lon,&nlon,LON_IN);
+	if (verbose)
+		if   (nlon == 1) printf("  lon=%g\n",lon[0]);
+		else             printf("  lon=[%d values]\n",nlon);
+//	for (i=0; i<nlon; i++) printf("  lon[%d]=%g\n",i,lon[i]);
+	FetchData(&sgn,SGN_IN);
+	if (verbose) printf("  sgn=%d\n",sgn);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+	/*  defaults are in Ll2xydef, so don't duplicate them here, and only use user values if both have been specified  */
+	if (options->GetOption("central_meridian") || options->GetOption("standard_parallel")) {
+		options->Get(&cm,"central_meridian");
+		if (verbose) printf("  cm=%g\n",cm);
+		options->Get(&sp,"standard_parallel");
+		if (verbose) printf("  sp=%g\n",sp);
+	}
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if   (nlat != nlon) _error_("Must have same number of lat[%d] and lon[%d] coordinates.",nlat,nlon);
+	else                ncoord=nlat;
+	if (sgn != +1 && sgn != -1) _error_("Hemisphere sgn=%d must be +1 (north) or -1 (south).",sgn);
+	if (fabs(cm)      > 180.) _error_("Central meridian cm=%g must be between -180 (west) and +180 (east) degrees.",cm);
+	if (sp < 0. || sp >  90.) _error_("Standard parallel sp=%g must be between 0 and 90 degrees (in specified hemisphere).",sp);
+
+	x=(double *)xmalloc(ncoord*sizeof(double));
+	y=(double *)xmalloc(ncoord*sizeof(double));
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
+		iret=Ll2xyx(x,y,
+					lat,lon,ncoord,
+					sgn,cm,sp);
+	else
+		iret=Ll2xyx(x,y,
+					lat,lon,ncoord,
+					sgn);
+	if (verbose) printf("  iret=%d\n",iret);
+
+	/*Write data: */
+	WriteData(X_OUT,x,ncoord);
+	WriteData(Y_OUT,y,ncoord);
+
+	/*Clean-up*/
+	delete options;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void Ll2xyUsage(void)
+{
+	_printf_(true,"Ll2xy - lat/long to x/y coordinate transformation module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module transforms lat/long to x/y coordinates.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [x,y]=Ll2xy(lat,lon,sgn,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      lat         latitude coordinates (double vector)\n");
+	_printf_(true,"      lon         longitude coordinates (double vector)\n");
+	_printf_(true,"      sgn         sign for hemisphere (double, +1 (north) or -1 (south))\n");
+	_printf_(true,"\n");
+	_printf_(true,"      central_meridian     central meridian (double, optional, but must specify with sp)\n");
+	_printf_(true,"      standard_parallel    standard parallel (double, optional, but must specify with cm)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      x           x coordinates (double vector)\n");
+	_printf_(true,"      y           y coordinates (double vector)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Examples:\n");
+	_printf_(true,"      [x,y]=Ll2xy(lat,lon, 1);\n");
+	_printf_(true,"      [x,y]=Ll2xy(lat,lon, 1,'central_meridian',45,'standard_parallel',70);\n");
+	_printf_(true,"      [x,y]=Ll2xy(lat,lon,-1,'central_meridian', 0,'standard_parallel',71);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/Ll2xy/Ll2xy.h
===================================================================
--- /issm/trunk-jpl/src/modules/Ll2xy/Ll2xy.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Ll2xy/Ll2xy.h	(revision 12032)
@@ -0,0 +1,37 @@
+/*!\file Ll2xy.h
+ * \brief: prototype for lat/long to x/y coordinate mex module.
+ */
+
+#ifndef _LL2XY_H
+#define _LL2XY_H
+
+/* local prototypes: */
+void Ll2xyUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Ll2xy"
+
+
+/* serial input macros: */
+#define LAT_IN    prhs[0]
+#define LON_IN    prhs[1]
+#define SGN_IN    prhs[2]
+
+/* serial output macros: */
+#define X_OUT    (mxArray**)&plhs[0]
+#define Y_OUT    (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  3
+#undef NLHS
+#define NLHS  2
+
+#endif
+
Index: /issm/trunk-jpl/src/modules/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/modules/Makefile.am	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Makefile.am	(revision 12032)
@@ -0,0 +1,8 @@
+SUBDIRS = 
+if MATLAB
+SUBDIRS += matlab
+endif
+
+if PYTHON
+SUBDIRS += python
+endif
Index: /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.cpp	(revision 12032)
@@ -0,0 +1,104 @@
+/*!\file:  MeshPartition.cpp
+ * \brief: partition mesh according to number of areas, using Metis library.
+
+	usage:
+	[element_partitioning,node_partitioning]=MeshPartition(model,numareas)
+	
+	%Info needed from model are the following: 
+	%mesh info: 
+	numberofelements,numberofvertices,elements,elements_width
+	%Non-extruded 2d mesh info
+	nel2d,nods2d,elements2d,
+	%Extruded 2d mesh info
+	nel2d_ext,nods2d_ext,elements2d_ext,
+	%Diverse
+	numberoflayers,dim)
+
+	output:
+	vector of partitioning area numbers, for every element.
+	vector of partitioning area numbers, for every node.
+*/
+	
+#include "./MeshPartition.h"
+
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+
+	/*Indexing: */
+	int i,j;
+
+	/* required input: */
+	int     dim;
+	int     numberofelements;
+	int     numberofvertices;
+	double *elements         = NULL;
+	int     elements_width;
+
+	int numberofelements2d;
+	int numberofvertices2d;
+	double* elements2d=NULL;
+
+	int numberoflayers;
+	int numareas=1;
+
+	/* output: */
+	int    *int_element_partitioning = NULL;
+	int    *int_node_partitioning    = NULL;
+	double *element_partitioning     = NULL;
+	double *node_partitioning        = NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&MeshPartitionUsage);
+
+	/*Fetch data: */
+	FetchData(&dim,mxGetAssignedField(MODEL,0,"dimension"));
+	FetchData(&numberofelements,mxGetAssignedField(MODEL,0,"numberofelements"));
+	FetchData(&numberofvertices,mxGetAssignedField(MODEL,0,"numberofvertices"));
+	FetchData(&elements,NULL,&elements_width,mxGetAssignedField(MODEL,0,"elements"));
+
+	if (dim==3){
+		FetchData(&numberofelements2d,mxGetAssignedField(MODEL,0,"numberofelements2d"));
+		FetchData(&numberofvertices2d,mxGetAssignedField(MODEL,0,"numberofvertices2d"));
+		FetchData(&elements2d,NULL,NULL,mxGetAssignedField(MODEL,0,"elements2d"));
+	}
+	FetchData(&numberoflayers,mxGetAssignedField(MODEL,0,"numberoflayers"));
+	FetchData(&numareas,NUMAREAS);
+
+	/*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */
+	MeshPartitionx(&int_element_partitioning,&int_node_partitioning,numberofelements,numberofvertices,elements,
+		numberofelements2d,numberofvertices2d,elements2d,numberoflayers,elements_width,dim,numareas);
+
+	/*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
+	element_partitioning=(double*)xmalloc(numberofelements*sizeof(double));
+	for (i=0;i<numberofelements;i++){
+		element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
+	}
+	
+	node_partitioning=(double*)xmalloc(numberofvertices*sizeof(double));
+	for (i=0;i<numberofvertices;i++){
+		node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
+	}
+
+	/*Write data:*/
+	WriteData(ELEMENTPARTITIONING,element_partitioning,numberofelements);
+	WriteData(NODEPARTITIONING,node_partitioning,numberofvertices);
+	
+	/*Free ressources:*/
+	//don't! let matlab do it.
+
+	/*end module: */
+	MODULEEND();
+}
+
+void MeshPartitionUsage(void){
+	printf("   usage:\n");
+	printf("   [element_partitioning,node_partitioning]=MeshPartition(md.mesh,numpartitions)");
+	printf("   where:\n");
+	printf("      element_partitioning is a vector of partitioning area numbers, for every element.\n");
+	printf("      node_partitioning is a vector of partitioning area numbers, for every node.\n");
+	printf("\n");
+}
Index: /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.h
===================================================================
--- /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.h	(revision 12032)
@@ -0,0 +1,41 @@
+
+/*
+	MeshPartition.h
+*/
+
+
+#ifndef _MESHPARTITION_H
+#define _MESHPARTITION_H
+
+/* local prototypes: */
+void MeshPartitionUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef CLEANUP
+#define CLEANUP MeshPartitionLocalCleanup();
+
+#undef __FUNCT__ 
+#define __FUNCT__  "MeshPartition"
+
+/* serial input macros: */
+#define MODEL (mxArray*)prhs[0]
+#define NUMAREAS (mxArray*)prhs[1]
+
+/* serial output macros: */
+#define ELEMENTPARTITIONING (mxArray**)&plhs[0]
+#define NODEPARTITIONING (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  2
+#undef NRHS
+#define NRHS  2
+
+
+#endif  /* _MESHPARTITION_H */
+
Index: /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.cpp	(revision 12032)
@@ -0,0 +1,114 @@
+/*! \file  MeshProfileIntersection.cpp
+    \brief: takes a  .exp file (made of several profiles), and figures out its intersection 
+	with a mesh.
+
+	usage:
+	[segments]=MeshProfileIntersection(index,x,y,filename);
+
+	where:
+	input:
+		index,x,y is a triangulation
+		filename: name of Argus style .exp file containing the segments (can be groups of disconnected segments)
+	output:
+		segments: array made of x1,y1,x2,y2,element_id lines (x1,y1) and (x2,y2) are segment extremitis for a segment 
+		belonging to the elemnt_id element. there are as many lines in segments as there are segments intersecting the 
+		mesh.
+*/
+	
+#include "./MeshProfileIntersection.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+	int i,j;
+
+	/* required input: */
+	//mesh
+	double* double_index=NULL;
+	int*    index=NULL;
+	int     nel;
+	double* x=NULL;
+	double* y=NULL;
+	int     nods;
+	int     dummy;
+	
+	//contours
+	mxArray*  matlabstructure=NULL;
+	Contour** contours=NULL;
+	int       numcontours;
+	Contour*  contouri=NULL;
+
+	/* output: */
+	double* segments=NULL;
+	int     numsegs;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&MeshProfileIntersectionUsage);
+
+	/*First, call expread on filename to build a contour array in the matlab workspace: */
+	mexCallMATLAB( 1, &matlabstructure, 1, (mxArray**)&FILENAME, "expread");
+
+	/*Fetch inputs: */
+	//index
+	FetchData(&double_index,&nel,&dummy,INDEX);
+	if(dummy!=3 && dummy!=6)_error_(" element triangulation should be of 3 or 6 column width!");
+	index=(int*)xmalloc(nel*3*sizeof(int));
+	for(i=0;i<nel;i++){
+		for(j=0;j<3;j++){
+			*(index+3*i+j)=(int)*(double_index+dummy*i+j)-1; //"C" style indexing
+		}
+	}
+	//x and y
+	FetchData(&x,&nods,X);
+	FetchData(&y,&dummy,Y);
+
+	//contours
+	numcontours=mxGetNumberOfElements(matlabstructure);
+	contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+	for(i=0;i<numcontours;i++){
+		//allocate
+		contouri=(Contour*)xmalloc(sizeof(Contour));
+		//retrieve dimension of this contour.
+		contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
+		//set pointers.
+		contouri->x=mxGetPr(mxGetField(matlabstructure,i,"x"));
+		contouri->y=mxGetPr(mxGetField(matlabstructure,i,"y"));
+		*(contours+i)=contouri;
+	}
+
+	/* Debugging of contours :{{{1*/
+	/*for(i=0;i<numcontours;i++){
+		printf("\nContour echo: contour number  %i / %i\n",i+1,numcontours);
+		contouri=*(contours+i);
+		printf("   Number of vertices %i\n",contouri->nods);
+		for (j=0;j<contouri->nods;j++){
+			printf("   %lf %lf\n",*(contouri->x+j),*(contouri->y+j));
+		}
+	}*/
+	/*}}}*/
+
+	/*Run interpolation routine: */
+	MeshProfileIntersectionx(&segments,&numsegs,index,x,y,nel,nods,contours,numcontours);
+
+	/* output: */
+	WriteData(SEGMENTS,segments,numsegs,5);
+
+	/*end module: */
+	MODULEEND();
+
+}
+
+void MeshProfileIntersectionUsage(void){
+	printf("   usage:\n");
+	printf("   [segments]=MeshProfileIntersection(index,x,y,filename);\n");
+	printf("   where:\n");
+	printf("   input:\n");
+	printf("        index,x,y is a triangulation\n");
+	printf("        filename: name of Argus style .exp file containing the segments (can be groups of disconnected segments)\n");
+	printf("   output:\n");
+	printf("        segments: array made of x1,y1,x2,y2,element_id lines (x1,y1) and (x2,y2) are segment extremitis for a segment \n");
+	printf("        belonging to the elemnt_id element. there are as many lines in segments as there are segments intersecting the \n");
+	printf("        mesh.\n");
+}
Index: /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.h
===================================================================
--- /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.h	(revision 12032)
@@ -0,0 +1,38 @@
+
+/*
+	MeshProfileIntersection.h
+*/
+
+
+#ifndef _MESHPROFILEINTERSECTION_H
+#define _MESHPROFILEINTERSECTION_H
+
+/* local prototypes: */
+void MeshProfileIntersectionUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__
+#define __FUNCT__ "MeshProfileIntersection"
+
+/* input macros: */
+#define INDEX prhs[0]
+#define X prhs[1]
+#define Y prhs[2]
+#define FILENAME prhs[3]
+
+/* serial output macros: */
+#define SEGMENTS (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS 1
+#undef NRHS
+#define NRHS 4
+
+#endif  /* _MESHPROFILEINTERSECTION_H */
+
Index: /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.cpp	(revision 12032)
@@ -0,0 +1,44 @@
+/*\file NodeConnectivity.c
+ *\brief: build node connectivity from elements. 
+ */
+
+#include "./NodeConnectivity.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*inputs: */
+	double* elements=NULL;
+	int     nel,nods;
+
+	/*outputs: */
+	double* connectivity=NULL;
+	int     width;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&NodeConnectivityUsage);
+        
+	/*Input datasets: */
+	FetchData(&elements,&nel,NULL,ELEMENTS);
+	FetchData(&nods,NUMNODES);
+
+	/*!Generate internal degree of freedom numbers: */
+	NodeConnectivityx(&connectivity, &width,elements,nel, nods);
+
+	/*write output datasets: */
+	WriteData(CONNECTIVITY,connectivity,nods,width);
+
+	/*Free ressources: */
+	xfree((void**)&elements);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void NodeConnectivityUsage(void) {
+	_printf_(true,"\n");
+	_printf_(true,"   usage: connectivity = %s(elements, numnodes);\n",__FUNCT__);
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/NodeConnectivity/NodeConnectivity.h	(revision 12032)
@@ -0,0 +1,33 @@
+/*
+	NodeConnectivity.h
+*/
+
+#ifndef _NODECONNECTIVITY_H
+#define _NODECONNECTIVITY_H
+
+/* local prototypes: */
+void NodeConnectivityUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "NodeConnectivity"
+
+/* serial input macros: */
+#define ELEMENTS (mxArray*)prhs[0]
+#define NUMNODES (mxArray*)prhs[1]
+
+/* serial output macros: */
+#define CONNECTIVITY (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  2
+
+#endif  /* _NODECONNECTIVITY_H */
Index: /issm/trunk-jpl/src/modules/PointCloudFindNeighbors/PointCloudFindNeighbors.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/PointCloudFindNeighbors/PointCloudFindNeighbors.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/PointCloudFindNeighbors/PointCloudFindNeighbors.cpp	(revision 12032)
@@ -0,0 +1,52 @@
+/*! \file  PointCloudFindNeighbors
+    \brief: flag points that are too near one another, within an array of point coordinates
+*/
+	
+#include "./PointCloudFindNeighbors.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
+
+	int i,j;
+
+	/* required input: */
+	double* x=NULL;
+	double* y=NULL;
+	int     nods;
+	double  mindistance;
+	double  multithread;
+
+	/* output: */
+	Vector*  flags=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&PointCloudFindNeighborsUsage);
+
+	/*Fetch inputs: */
+	FetchData(&x,&nods,NULL,XHANDLE);  
+	FetchData(&y,NULL,NULL,YHANDLE);
+	FetchData(&mindistance,MINDISTANCE);
+	FetchData(&multithread,MULTITHREAD);
+
+	/*Run core routine: */
+	PointCloudFindNeighborsx(&flags,x,y,nods,mindistance,multithread);
+
+	/* output: */
+	WriteData(FLAGS,flags);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void PointCloudFindNeighborsUsage(void){
+	printf("   usage:\n");
+	printf("   [flags]=PointCloudFindNeighbors(x,y,mindistance,multithread);\n\n");
+	printf("   where:\n");
+	printf("      x,y: list of points.\n");
+	printf("      mindistance: minimum distance that should exist between points in the cloud.\n");
+	printf("      multithread: run multithreaded or not. with multithreads, flags can get 1 and 2 values in duplicates.\n");
+	printf("      flags: array of flags (flag==1 means point is within mindistance of another point)\n");
+	printf("\n");
+}
Index: /issm/trunk-jpl/src/modules/PointCloudFindNeighbors/PointCloudFindNeighbors.h
===================================================================
--- /issm/trunk-jpl/src/modules/PointCloudFindNeighbors/PointCloudFindNeighbors.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/PointCloudFindNeighbors/PointCloudFindNeighbors.h	(revision 12032)
@@ -0,0 +1,44 @@
+
+/*
+	PointCloudFindNeighbors.h
+*/
+
+
+#ifndef _POINTCLOUDFINDNEIGHBORS_H
+#define _POINTCLOUDFINDNEIGHBORS_H
+
+/* local prototypes: */
+void PointCloudFindNeighborsUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__
+#define __FUNCT__ "PointCloudFindNeighbors"
+
+
+#ifndef ALL
+#define ALL 0
+#endif
+
+/* input macros: */
+#define XHANDLE prhs[0]
+#define YHANDLE prhs[1]
+#define MINDISTANCE prhs[2]
+#define MULTITHREAD prhs[3]
+
+/* serial output macros: */
+#define FLAGS (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS 1
+#undef NRHS
+#define NRHS 4
+
+
+#endif  /* _POINTCLOUDFINDNEIGHBORS_H */
+
Index: /issm/trunk-jpl/src/modules/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.cpp	(revision 12032)
@@ -0,0 +1,47 @@
+/*\file PropagateFlagsFromConnectivity.c
+ *\brief: propagate flags onto mesh, element by element, using connectivity.
+ */
+
+#include "./PropagateFlagsFromConnectivity.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*input/output datasets: */
+	double* connectivity=NULL;
+	int     nel;
+	double* pool=NULL;
+	double* flags=NULL;
+	int     index;
+	int     dummy;
+	
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&PropagateFlagsFromConnectivityUsage);
+        
+	/*Input datasets: */
+	FetchData(&connectivity,&nel,&dummy,CONNECTIVITY);
+	FetchData(&pool,&dummy,POOL);
+	FetchData(&index,INDEX);
+	FetchData(&flags,&dummy,FLAGS);
+
+	/*!Generate internal degree of freedom numbers: */
+	PropagateFlagsFromConnectivityx(pool,connectivity,index,flags);
+
+	/*write output datasets: */
+	WriteData(POOLOUT,pool,nel);
+
+	/*Free ressources: */
+	xfree((void**)&connectivity);
+	xfree((void**)&flags);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void PropagateFlagsFromConnectivityUsage(void) {
+	printf("\n");
+	printf("   usage: [pool] = %s(connectivity,pool,index,flags);\n",__FUNCT__);
+	printf("\n");
+}
Index: /issm/trunk-jpl/src/modules/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/modules/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h	(revision 12032)
@@ -0,0 +1,40 @@
+
+/*
+	PropagateFlagsFromConnectivity.h
+*/
+
+
+#ifndef _PROPAGATEFLAGSFROMCONNECTIVITY_H
+#define _PROPAGATEFLAGSFROMCONNECTIVITY_H
+
+/* local prototypes: */
+void PropagateFlagsFromConnectivityUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "PropagateFlagsFromConnectivity"
+
+/* serial input macros: */
+#define CONNECTIVITY (mxArray*)prhs[0]
+#define POOL (mxArray*)prhs[1]
+#define INDEX (mxArray*)prhs[2]
+#define FLAGS (mxArray*)prhs[3]
+
+/* serial output macros: */
+#define POOLOUT (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  4
+
+
+#endif  /* _PROPAGATEFLAGSFROMCONNECTIVITY_H */
+
+
Index: /issm/trunk-jpl/src/modules/Scotch/Scotch.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/Scotch/Scotch.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Scotch/Scotch.cpp	(revision 12032)
@@ -0,0 +1,267 @@
+/*\file Scotch.c
+ *\brief:  Scotch partitioner mex module
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+
+#include "./Scotch.h"
+
+/******************************/
+/*                            */
+/* This is the main function. */
+/*                            */
+/******************************/
+
+void mexFunction( int nlhs,
+				  mxArray *plhs[],
+				  int nrhs,
+				  const mxArray *prhs[] )
+{
+
+#ifndef _HAVE_SCOTCH_ //only works if scotch library has been compiled in.
+	_error_(" Scotch not available! Cannot carry out Scotch partitioning!");
+	#else
+
+	int     argcm;
+	char    **argvm=NULL;
+	int     nvert =0,nedge2=0,napar =0;
+	mwIndex *ir=NULL,*jc=NULL;
+	int     *adjir=NULL,*adjjc=NULL;
+	double  *vld=NULL,*vwd=NULL,*ewd=NULL,*apd=NULL;
+	int     *vli=NULL,*vwi=NULL,*ewi=NULL,*api=NULL;
+	char    *archtyp=NULL;
+	int     (*maptabi)[2]=NULL;
+	double* maptabd=NULL;
+	int     i,j,k,imi=0,imo=0,isi=0,ierr;
+
+	/* Check for proper number of arguments */
+   
+	if      (nrhs == 0 && nlhs == 0) {
+		GmapUsage();
+		return;
+	}
+	else if (nrhs <  6 || nlhs >  1) {
+		GmapUsage();
+		mexErrMsgTxt(" ");
+	}
+
+/*  load matlab argument list and convert to integer (note that converting here
+	and in the x-layer is inefficient, but it makes the x-layer more general)  */
+
+	argvm = (char **) calloc(nrhs,sizeof(char *));
+
+	if (!(mxIsNumeric(prhs[imi]) &&
+		  (mxGetM(prhs[imi]) == 1 && mxGetN(prhs[imi]) == 1))) {
+		argvm[isi] = (char *) calloc(4+1,sizeof(char));
+		strcpy(argvm[isi],"gmap");
+		mexPrintf("%s -- Using \"%s\" entry point.\n",
+				  __FUNCT__,argvm[isi]);
+		isi++;
+	}
+	else {
+		argvm[isi] = (char *) calloc(5+1,sizeof(char));
+		strcpy(argvm[isi],"gpart");
+		mexPrintf("%s -- Using \"%s\" entry point.\n",
+				  __FUNCT__,argvm[isi]);
+		isi++;
+
+		argvm[isi] = (char *) calloc(17,sizeof(char));
+		sprintf(argvm[isi],"%d",(int)mxGetScalar(prhs[imi]));
+		mexPrintf("%s -- Number of parts is %s.\n",
+				  __FUNCT__,argvm[isi]);
+		isi++;
+		imi++;
+	}
+
+	if (!mxIsNumeric(prhs[imi]) || (!mxIsEmpty(prhs[imi]) && !mxIsSparse(prhs[imi]))) {
+		mexPrintf("%s -- Adjacency matrix must be numeric and sparse.\n",__FUNCT__);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		nvert =mxGetM(prhs[imi]);
+		nedge2=mxGetNzmax(prhs[imi]);
+		if (mxGetNzmax(prhs[imi])) {
+			ir    =mxGetIr(prhs[imi]);
+			adjir = (int *) malloc(mxGetNzmax(prhs[imi])*sizeof(int));
+			for (i=0; i<mxGetNzmax(prhs[imi]); i++)
+				adjir[i]=(int)ir[i];
+		}
+		if (mxGetN(prhs[imi])) {
+			jc    =mxGetJc(prhs[imi]);
+			adjjc = (int *) malloc((mxGetN(prhs[imi])+1)*sizeof(int));
+			for (i=0; i<(mxGetN(prhs[imi])+1); i++)
+				adjjc[i]=(int)jc[i];
+		}
+		mexPrintf("%s -- Adjacency matrix is of size %d by %d with %d non-zeroes.\n",
+				  __FUNCT__,mxGetM(prhs[imi]),mxGetN(prhs[imi]),mxGetNzmax(prhs[imi]));
+	}
+	imi++;
+
+	if (!mxIsNumeric(prhs[imi])) {
+		mexPrintf("%s -- Vertex label vector must be numeric.\n",__FUNCT__);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		if (mxGetM(prhs[imi])*mxGetN(prhs[imi])) {
+			vld=mxGetPr(prhs[imi]);
+			vli = (int *) malloc(mxGetM(prhs[imi])*mxGetN(prhs[imi])*sizeof(int));
+			for (i=0; i<mxGetM(prhs[imi])*mxGetN(prhs[imi]); i++)
+				vli[i]=(int)vld[i];
+		}
+		mexPrintf("%s -- Vertex label vector is of size %d by %d.\n",
+				  __FUNCT__,mxGetM(prhs[imi]),mxGetN(prhs[imi]));
+	}
+	imi++;
+
+	if (!mxIsNumeric(prhs[imi])) {
+		mexPrintf("%s -- Vertex weight vector must be numeric.\n",__FUNCT__);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		if (mxGetM(prhs[imi])*mxGetN(prhs[imi])) {
+			vwd=mxGetPr(prhs[imi]);
+			vwi = (int *) malloc(mxGetM(prhs[imi])*mxGetN(prhs[imi])*sizeof(int));
+			for (i=0; i<mxGetM(prhs[imi])*mxGetN(prhs[imi]); i++)
+				vwi[i]=(int)vwd[i];
+		}
+		mexPrintf("%s -- Vertex weight vector is of size %d by %d.\n",
+				  __FUNCT__,mxGetM(prhs[imi]),mxGetN(prhs[imi]));
+	}
+	imi++;
+
+	if (!mxIsNumeric(prhs[imi]) || (!mxIsEmpty(prhs[imi]) && !mxIsSparse(prhs[imi]))) {
+		mexPrintf("%s -- Edge weight matrix must be numeric and sparse.\n",__FUNCT__);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		if (mxGetM(prhs[imi])) {
+			ewd=mxGetPr(prhs[imi]);
+			ewi = (int *) malloc(mxGetM(prhs[imi])*sizeof(int));
+			for (i=0; i<mxGetNzmax(prhs[imi]); i++)
+				ewi[i]=(int)ewd[i];
+		}
+		mexPrintf("%s -- Edge weight matrix is of size %d by %d with %d non-zeroes.\n",
+				  __FUNCT__,mxGetM(prhs[imi]),mxGetN(prhs[imi]),mxGetNzmax(prhs[imi]));
+	}
+	imi++;
+
+	if (!((strlen (argvm[0]) >= 5) &&
+		  (strncmp (argvm[0] + strlen (argvm[0]) - 5, "gpart", 5) == 0))) {
+		if (!mxIsChar(prhs[imi])) {
+			mexPrintf("%s -- Architecture type must be character.\n",__FUNCT__);
+			mexErrMsgTxt(" ");
+		}
+		else {
+			if (mxGetM(prhs[imi])*mxGetN(prhs[imi])) {
+				archtyp = (char *) calloc(mxGetM(prhs[imi])*mxGetN(prhs[imi])+1,sizeof(char));
+				mxGetString(prhs[imi],archtyp,mxGetM(prhs[imi])*mxGetN(prhs[imi])+1);
+			}
+			mexPrintf("%s -- Architecture type is \"%s\".\n",
+					  __FUNCT__,archtyp);
+		}
+		imi++;
+
+		if (!mxIsNumeric(prhs[imi])) {
+			mexPrintf("%s -- Architecture parameter vector must be numeric.\n",__FUNCT__);
+			mexErrMsgTxt(" ");
+		}
+		else {
+			napar =mxGetM(prhs[imi])*mxGetN(prhs[imi]);
+			if (mxGetM(prhs[imi])*mxGetN(prhs[imi])) {
+				apd=mxGetPr(prhs[imi]);
+				api = (int *) malloc(mxGetM(prhs[imi])*mxGetN(prhs[imi])*sizeof(int));
+				for (i=0; i<mxGetM(prhs[imi])*mxGetN(prhs[imi]); i++)
+					api[i]=(int)apd[i];
+			}
+			mexPrintf("%s -- Architecture parameter vector is of size %d by %d.\n",
+					  __FUNCT__,mxGetM(prhs[imi]),mxGetN(prhs[imi]));
+		}
+		imi++;
+	}
+
+	while (imi < nrhs) {
+		if (!mxIsChar(prhs[imi])) {
+			mexPrintf("%s -- prhs[%d] must be character.\n",__FUNCT__,imi);
+			mexErrMsgTxt(" ");
+		}
+		else {
+			argvm[isi] = (char *) calloc(mxGetM(prhs[imi])*mxGetN(prhs[imi])+1,sizeof(char));
+			mxGetString(prhs[imi],argvm[isi],mxGetM(prhs[imi])*mxGetN(prhs[imi])+1);
+		}
+		isi++;
+		imi++;
+	}
+	argcm=isi;
+	mexPrintf("argcm=%d\n",argcm);
+	for (i=0; i<argcm; i++)
+		mexPrintf("argvm[%d]=\"%s\"\n",i,argvm[i]);
+
+	/* Do the actual computations in a subroutine */
+
+	mexPrintf("Gmapx:\n");
+	ierr=gmapx(&maptabi,
+			   argcm,
+			   argvm,
+			   nvert,
+			   nedge2,
+			   adjir,
+			   adjjc,
+			   vli,
+			   vwi,
+			   ewi,
+			   archtyp,
+			   napar,
+			   api);
+	mexPrintf("%s -- Error %d from Gmapx.\n",__FUNCT__,ierr);
+
+/*  for (i=0; i<nvert; i++)
+		mexPrintf("maptabi[%d][0]=%d, maptabi[%d][1]=%d\n",
+			 	  i,maptabi[i][0],i,maptabi[i][1]); */
+
+	/* Create matrices for the return arguments */
+
+	if (maptabi) {
+		plhs[imo]=mxCreateDoubleMatrix(nvert, 2, mxREAL);
+		maptabd = mxGetPr(plhs[imo]);
+		k=0;
+		for (j=0; j<2; j++)
+			for (i=0; i<nvert; i++)
+				maptabd[k++]=(double)maptabi[i][j];
+		//free(maptabi);
+	}
+	else {
+		plhs[imo]=mxCreateDoubleMatrix(0, 2, mxREAL);
+	}
+	imo++;
+
+	/*if (argvm)
+		for (i=argcm-1; i>=0; i--)
+			free(argvm[i]);
+	if (api)     free(api);
+	if (archtyp) free(archtyp);
+	if (ewi)     free(ewi);
+	if (vwi)     free(vwi);
+	if (vli)     free(vli);
+	if (adjjc)   free(adjjc);
+	if (adjir)   free(adjir);*/
+
+	return;
+#endif //#ifndef _HAVE_SCOTCH_
+}
+
+void GmapUsage( void )
+{
+
+    mexPrintf("\n");
+    mexPrintf("Usage: [maptab]=Scotch(adjmat,vertlb,vertwt,edgewt,archtyp,archpar,\n");
+    mexPrintf("                         Scotch-specific parameters);\n");
+    mexPrintf("\n");
+
+    return;
+}
+
Index: /issm/trunk-jpl/src/modules/Scotch/Scotch.h
===================================================================
--- /issm/trunk-jpl/src/modules/Scotch/Scotch.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Scotch/Scotch.h	(revision 12032)
@@ -0,0 +1,40 @@
+/*!\file:  Scotch.h
+ * \brief header file for Scotch module.
+ */ 
+
+#ifndef _SCOTCH_H
+#define _SCOTCH_H
+
+/* local prototypes: */
+void GmapUsage(void);
+
+#include <stdio.h>
+#include <string.h>    /*  strcasecmp  */
+#include <time.h>      /*  clock,time,difftime  */
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+    
+#undef __FUNCT__ 
+#define __FUNCT__  "Scotch"
+
+/*  Scotch structures and prototypes  */
+#ifdef MATLAB
+		#include "mat.h"
+		#include "mex.h"
+		#include "matrix.h"
+
+		#define printf mexPrintf
+		#define fprintf(file,...) (file == stdout || file == stderr ? mexPrintf(__VA_ARGS__) : fprintf(file,__VA_ARGS__))
+		#define malloc mxMalloc
+		#define calloc mxCalloc
+		#define realloc mxRealloc
+		#define free mxFree
+		#define exit(status) mexErrMsgTxt("exit=" #status)
+#endif
+
+
+#endif  /* _SCOTCH_H */
Index: /issm/trunk-jpl/src/modules/Shp2Kml/Shp2Kml.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/Shp2Kml/Shp2Kml.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Shp2Kml/Shp2Kml.cpp	(revision 12032)
@@ -0,0 +1,117 @@
+/*\file Shp2Kml.c
+ *\brief: shp to kml file conversion mex module.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./Shp2Kml.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	char    *filshp=NULL,*filkml=NULL;
+	int     sgn;
+
+	Options* options=NULL;
+	double   cm=0.,sp=0.;
+
+	/* output: */
+	int     iret=0;
+
+	#ifndef _HAVE_SHAPELIB_ //only works if shapelib library has been compiled in.
+	_error_(" Shapelib not available! Cannot carry out shp file translation!");
+	#endif
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		Shp2KmlUsage();
+		_error_("Shp2Kml usage error");
+	}
+	if (nrhs < NRHS) {
+		Shp2KmlUsage();
+		_error_("Shp2Kml usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&filshp,SHP_IN);
+	if (verbose) printf("  filshp=\"%s\"\n",filshp);
+	FetchData(&filkml,KML_IN);
+	if (verbose) printf("  filkml=\"%s\"\n",filkml);
+	FetchData(&sgn,SGN_IN);
+	if (verbose) printf("  sgn=%d\n",sgn);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+	/*  defaults are in Xy2lldef, so don't duplicate them here, and only use user values if both have been specified  */
+	if (options->GetOption("central_meridian") || options->GetOption("standard_parallel")) {
+		options->Get(&cm,"central_meridian");
+		if (verbose) printf("  cm=%g\n",cm);
+		options->Get(&sp,"standard_parallel");
+		if (verbose) printf("  sp=%g\n",sp);
+	}
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if (sgn < -1 || sgn > +1) _error_("Hemisphere sgn=%d must be +1 (north), -1 (south), or 0 (no translation).",sgn);
+	if (fabs(cm)      > 180.) _error_("Central meridian cm=%g must be between -180 (west) and +180 (east) degrees.",cm);
+	if (sp < 0. || sp >  90.) _error_("Standard parallel sp=%g must be between 0 and 90 degrees (in specified hemisphere).",sp);
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
+		iret=Shp2Kmlx(filshp,filkml,
+					  sgn,cm,sp);
+	else
+		iret=Shp2Kmlx(filshp,filkml,
+					  sgn);
+	if (verbose) printf("  iret=%d\n",iret);
+
+	/*Write data: */
+	WriteData(RET_OUT,iret);
+
+	/*Clean-up*/
+	delete options;
+	xfree((void**)&filkml);
+	xfree((void**)&filshp);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void Shp2KmlUsage(void)
+{
+	_printf_(true,"Shp2Kml - shp to kml file conversion module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module converts a file from shp to kml format.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [ret]=Shp2Kml(filshp,filkml,sgn,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      filshp      file name of shp file to be read (char, extension optional)\n");
+	_printf_(true,"      filkml      file name of kml file to be written (char)\n");
+	_printf_(true,"      sgn         sign for hemisphere (double, +1 (north); -1 (south); or 0 (no translation))\n");
+	_printf_(true,"\n");
+	_printf_(true,"      central_meridian     central meridian (double, optional, but must specify with sp)\n");
+	_printf_(true,"      standard_parallel    standard parallel (double, optional, but must specify with cm)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      ret         return code (non-zero for warning)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Examples:\n");
+	_printf_(true,"      [ret]=Shp2Kml('file.shp','file.kml', 0);\n");
+	_printf_(true,"      [ret]=Shp2Kml('file.shp','file.kml', 1,'central_meridian',45,'standard_parallel',70);\n");
+	_printf_(true,"      [ret]=Shp2Kml('file.shp','file.kml',-1,'central_meridian', 0,'standard_parallel',71);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/Shp2Kml/Shp2Kml.h
===================================================================
--- /issm/trunk-jpl/src/modules/Shp2Kml/Shp2Kml.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Shp2Kml/Shp2Kml.h	(revision 12032)
@@ -0,0 +1,36 @@
+/*!\file Shp2Kml.h
+ * \brief: prototype for shp to kml file conversion mex module.
+ */
+
+#ifndef _SHP2KML_H
+#define _SHP2KML_H
+
+/* local prototypes: */
+void Shp2KmlUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Shp2Kml"
+
+
+/* serial input macros: */
+#define SHP_IN    prhs[0]
+#define KML_IN    prhs[1]
+#define SGN_IN    prhs[2]
+
+/* serial output macros: */
+#define RET_OUT    (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  3
+#undef NLHS
+#define NLHS  1
+
+#endif
+
Index: /issm/trunk-jpl/src/modules/StringToEnum/StringToEnum.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/StringToEnum/StringToEnum.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/StringToEnum/StringToEnum.cpp	(revision 12032)
@@ -0,0 +1,32 @@
+/*\file StringToEnum.c
+ *\brief:convert enum (int) to string
+ */
+
+#include "./StringToEnum.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	char    *name    = NULL;
+	int      enum_out;
+
+	/*checks on arguments on the matlab side: */
+	if(nrhs!=NRHS){
+		StringToEnumUsage(); _error_(" usage. See above");
+	}
+
+	/*Fetch inputs: */
+	FetchData(&name,NAME);
+
+	/*Run core function: */
+	enum_out=StringToEnumx(name);
+
+	/* output: */
+	WriteData(ENUMOUT,enum_out);
+}
+
+void StringToEnumUsage(void)
+{
+	_printf_(true,"\n");
+	_printf_(true,"   usage: %senum = StringToEnum(string);\n",__FUNCT__);
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/StringToEnum/StringToEnum.h
===================================================================
--- /issm/trunk-jpl/src/modules/StringToEnum/StringToEnum.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/StringToEnum/StringToEnum.h	(revision 12032)
@@ -0,0 +1,32 @@
+/*!\file:  StringToEnum.h
+ * \brief header file for StringToEnum module.
+ */ 
+
+#ifndef _STRINGTOENUM_H
+#define _STRINGTOENUM_H
+
+/* local prototypes: */
+void StringToEnumUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+    
+/* serial input macros: */
+#define NAME (mxArray*)prhs[0]
+
+/* serial output macros: */
+#define ENUMOUT (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  1
+
+#undef __FUNCT__ 
+#define __FUNCT__  "StringToEnum"
+
+#endif  /* _TEST_H */
Index: /issm/trunk-jpl/src/modules/TriMesh/TriMesh.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/TriMesh/TriMesh.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMesh/TriMesh.cpp	(revision 12032)
@@ -0,0 +1,72 @@
+/*
+ * TriMesh: mesh a domain using an .exp file
+ */
+
+#include "./TriMesh.h"
+
+WRAPPER(TriMesh){
+	
+	/* input: */
+	char*  domainname=NULL;
+	double area;
+	bool   order;
+
+	/*intermediary: */
+	DataSet* domain=NULL;
+
+	/* output: */
+	Matrix* index=NULL;
+	Vector* x=NULL;
+	Vector* y=NULL;
+	Matrix* segments=NULL;
+	Vector* segmentmarkerlist=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CHECKARGUMENTS(NLHS,NRHS,&TriMeshUsage);
+	
+	/*Fetch data needed for meshing: */
+	FetchData(&domainname,DOMAINOUTLINE);
+	FetchData(&area,AREA);
+	FetchData(&order,ORDER);
+
+	/*Read domain outline: */
+	domain=DomainOutlineRead(domainname,false);
+
+	/*call x core: */
+	TriMeshx(&index,&x,&y,&segments,&segmentmarkerlist,domain,area,order);
+	
+	/*write outputs: */
+	WriteData(INDEX,index);
+	WriteData(X,x);
+	WriteData(Y,y);
+	WriteData(SEGMENTS,segments);
+	WriteData(SEGMENTMARKERLIST,segmentmarkerlist);
+
+	/*free ressources: */
+	delete domain;
+	xdelete_module(&index);
+	xdelete_module(&x);
+	xdelete_module(&y);
+	xdelete_module(&segments);
+	xdelete_module(&segmentmarkerlist);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void TriMeshUsage(void) //{{{1
+{
+	printf("\n");
+	printf("   usage: [index,x,y,segments,segmentmarkers]=TriMesh(domainoutlinefilename,area,ordered) \n");
+	printf("      where: index,x,y defines a triangulation, segments is an array made \n");
+	printf("      of exterior segments to the mesh domain outline, segmentmarkers is an array flagging each segment, \n");
+	printf("      outlinefilename an Argus domain outline file, \n");
+	printf("      area is the maximum area desired for any element of the resulting mesh, \n");
+	printf("      and ordered is a bool that determines whether segments are output in the \n");
+	printf("      order they are made by Triangle (ie none), or ordered counter clockwise around the domain outline.\n");
+	printf("\n");
+}
+//}}}
Index: /issm/trunk-jpl/src/modules/TriMesh/TriMesh.h
===================================================================
--- /issm/trunk-jpl/src/modules/TriMesh/TriMesh.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMesh/TriMesh.h	(revision 12032)
@@ -0,0 +1,68 @@
+/*
+	TriMesh.h
+*/
+
+#ifndef _TRIMESH_H
+#define _TRIMESH_H
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+/*Very important definition in case we are compiling a python module!: needs to come before header files inclusion*/
+#ifdef _HAVE_PYTHON_
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#endif
+
+/*Header files: */
+#include "../../c/include/globals.h"
+#include "../../c/toolkits/toolkits.h"
+#include "../../c/include/include.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+#include "../../c/io/io.h"
+#include "../../c/EnumDefinitions/EnumDefinitions.h"
+
+#ifdef _HAVE_MATLAB_MODULES_
+/* serial input macros: */
+#define DOMAINOUTLINE  (mxArray *)prhs[0]
+#define AREA           (mxArray *)prhs[1]
+#define ORDER          (mxArray *)prhs[2]
+/* serial output macros: */
+#define INDEX             (mxArray**)&plhs[0]
+#define X                 (mxArray**)&plhs[1]
+#define Y                 (mxArray**)&plhs[2]
+#define SEGMENTS          (mxArray**)&plhs[3]
+#define SEGMENTMARKERLIST (mxArray**)&plhs[4]
+#endif
+
+#ifdef _HAVE_PYTHON_MODULES_
+/* serial input macros: */
+#define DOMAINOUTLINE PyTuple_GetItem(args,0)
+#define AREA          PyTuple_GetItem(args,1)
+#define ORDER         PyTuple_GetItem(args,2)
+/* serial output macros: */
+#define INDEX             output,0
+#define X                 output,1
+#define Y                 output,2
+#define SEGMENTS          output,3
+#define SEGMENTMARKERLIST output,4
+#endif
+
+#undef __FUNCT__ 
+#define __FUNCT__  "TriMesh"
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  5
+#undef NRHS
+#define NRHS  3
+
+/* local prototypes: */
+void TriMeshUsage(void);
+
+#endif  /* _TRIMESH_H */
Index: /issm/trunk-jpl/src/modules/TriMeshNoDensity/TriMeshNoDensity.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshNoDensity/TriMeshNoDensity.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMeshNoDensity/TriMeshNoDensity.cpp	(revision 12032)
@@ -0,0 +1,305 @@
+/*
+ * TriMeshNoDensity: out of a domain outline file ( Argus format ), 
+ * use the Triangle package to create a triangular mesh 
+ *
+ */
+
+#include "./TriMeshNoDensity.h"
+
+
+void mexFunction(	int nlhs, mxArray* plhs[],
+					int nrhs, const mxArray* prhs[] )
+{
+
+
+	/*Matlab arrays: */
+	mxArray* pmxa_array=NULL;
+	int i,j;
+	int counter,counter2,backcounter;
+	int prhs_counter;
+	
+	/* returned quantities: */
+
+	double* index=NULL;
+	double* x=NULL;
+	double* y=NULL;
+	double* segments=NULL;
+	double*    segmentmarkerlist=NULL;
+
+	/* input: */
+	char*  domainname=NULL;
+	char*  riftname=NULL;
+	
+	/*Domain outline variables: */
+	int      nprof;
+	int*     profnvertices=NULL;
+	double** pprofx=NULL;
+	double** pprofy=NULL;
+	double*  xprof=NULL;
+	double*  yprof=NULL;
+	int      numberofpoints;
+
+	/*Rift outline variables: */
+	int      numrifts;
+	int*     riftsnumvertices=NULL;
+	double** riftsverticesx=NULL;
+	double** riftsverticesy=NULL;
+
+	/* Triangle structures: */
+	struct triangulateio in,out;
+	char   options[256];
+
+	/* verify correct usage: */
+	if (nlhs==0 && nrhs==0) {
+		/* special case: */
+		TriMeshNoDensityUsage();
+		return;
+	}
+
+	if (!(  (nlhs==5) ||(nrhs==2) || (nrhs==3)  )){
+		mexPrintf("   %s format error.\n", __FUNCT__);
+		TriMeshNoDensityUsage();
+		printf("   ");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch data needed by Triangle: */
+
+	prhs_counter=0;
+	/*First recover the domain outline file name: */
+	if (!mxIsChar(prhs[prhs_counter])){
+		mexPrintf("%s%s\n",__FUNCT__," error message; first argument should be the domain outline file name!");
+		mexErrMsgTxt(" ");
+	}
+	domainname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char));
+	mxGetString(prhs[prhs_counter],domainname,mxGetN(prhs[prhs_counter])+1);
+
+	/*Look for optional rifts file name: */
+	if (nrhs==2){
+		prhs_counter++;
+		if (mxIsChar(prhs[prhs_counter])){
+			riftname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char));
+			mxGetString(prhs[prhs_counter],riftname,mxGetN(prhs[prhs_counter])+1);
+			prhs_counter++;
+		}
+	}
+	
+	/*Start reading the domain outline file: */
+	if(!DomainOutlineRead(&nprof,&profnvertices,&pprofx,&pprofy,NULL,domainname,false)){
+		printf("%s%s%s\n",__FUNCT__," error message reading domain outline ",domainname);
+		mexErrMsgTxt(" ");
+	}
+
+	/*Read rifts file if present: */
+	if(riftname){
+		if(!DomainOutlineRead(&numrifts,&riftsnumvertices,&riftsverticesx,&riftsverticesy,NULL,riftname,false)){
+			printf("%s%s%s\n",__FUNCT__," error message reading rifts outline ",riftname);
+			mexErrMsgTxt(" ");
+		}
+	}
+
+	/*Create initial triangulation to call triangulate():*/
+	numberofpoints=0;
+	for (i=0;i<nprof;i++){
+		numberofpoints+=profnvertices[i];
+	}
+	if (riftname){
+		for (i=0;i<numrifts;i++){
+			numberofpoints+=riftsnumvertices[i];
+		}
+	}
+	in.numberofpoints=numberofpoints;
+
+	in.numberofpointattributes=1;
+	in.pointlist = (REAL *) mxMalloc(in.numberofpoints * 2 * sizeof(REAL));
+
+	counter=0;
+	for (i=0;i<nprof;i++){
+		xprof=pprofx[i];
+		yprof=pprofy[i];
+		for (j=0;j<profnvertices[i];j++){
+			in.pointlist[2*counter+0]=xprof[j];
+			in.pointlist[2*counter+1]=yprof[j];
+			counter++;
+		}
+	}
+	if(riftname){
+		for (i=0;i<numrifts;i++){
+			xprof=riftsverticesx[i];
+			yprof=riftsverticesy[i];
+			for (j=0;j<riftsnumvertices[i];j++){
+				in.pointlist[2*counter+0]=xprof[j];
+				in.pointlist[2*counter+1]=yprof[j];
+				counter++;
+			}
+		}
+	}
+	
+	in.pointattributelist = (REAL *) mxMalloc(in.numberofpoints *
+										  in.numberofpointattributes *
+										  sizeof(REAL));
+	for (i=0;i<in.numberofpoints;i++){
+		in.pointattributelist[i] = 0.0;
+	}
+	in.pointmarkerlist = (int *) mxMalloc(in.numberofpoints * sizeof(int));
+	for(i=0;i<in.numberofpoints;i++){
+		in.pointmarkerlist[i] = 0;
+	}
+	
+
+	/*Build segments: */
+	/*Figure out number of segments: holes and closed outlines have as many segments as vertices, 
+	 *for rifts, we have one less segment as we have vertices*/
+	in.numberofsegments=0;
+	for (i=0;i<nprof;i++){
+		in.numberofsegments+=profnvertices[i];
+	}
+	if (riftname){
+		for (i=0;i<numrifts;i++){
+			in.numberofsegments+=riftsnumvertices[i]-1;
+		}
+	}
+	
+	in.segmentlist = (int *) mxMalloc(in.numberofsegments * 2 * sizeof(int));
+	in.segmentmarkerlist = (int *) mxCalloc(in.numberofsegments,sizeof(int));
+	counter=0;
+	backcounter=0;
+	for (i=0;i<nprof;i++){
+		for (j=0;j<(profnvertices[i]-1);j++){
+			in.segmentlist[2*counter+0]=counter;
+			in.segmentlist[2*counter+1]=counter+1;
+			in.segmentmarkerlist[counter]=0;
+			counter++;
+		}
+		/*Close this profile: */
+		 in.segmentlist[2*counter+0]=counter;
+		 in.segmentlist[2*counter+1]=backcounter;
+		 in.segmentmarkerlist[counter]=0;
+		 counter++;
+		 backcounter=counter;
+	}
+	counter2=counter;
+	if(riftname){
+		for (i=0;i<numrifts;i++){
+			for (j=0;j<(riftsnumvertices[i]-1);j++){
+				in.segmentlist[2*counter2+0]=counter;
+				in.segmentlist[2*counter2+1]=counter+1;
+				in.segmentmarkerlist[counter2]=2+i;
+				counter2++;
+				counter++;
+			}
+			counter++;
+		}
+	}
+
+	
+	/*Build regions: */
+	in.numberofregions = 0;
+
+	/*Build holes: */
+	in.numberofholes = nprof-1; /*everything is a hole, but for the first profile.*/
+	in.holelist = (REAL *) mxMalloc(in.numberofholes * 2 * sizeof(REAL));
+	for (i=0;i<nprof-1;i++){
+		/*We are looking for a vertex that lies inside the hole: */
+		GridInsideHole(&in.holelist[2*i+0],&in.holelist[2*i+1],profnvertices[i+1],pprofx[i+1],pprofy[i+1]);
+	}
+
+	/* Make necessary initializations so that Triangle can return a */
+	/*   triangulation in `out': */
+
+	out.pointlist = (REAL *) NULL;            
+	out.pointattributelist = (REAL *) NULL;
+	out.pointmarkerlist = (int *) NULL; 
+	out.trianglelist = (int *) NULL;          
+	out.triangleattributelist = (REAL *) NULL;
+	out.neighborlist = (int *) NULL;         
+	out.segmentlist = (int *) NULL;
+	out.segmentmarkerlist = (int *) NULL;
+	out.edgelist = (int *) NULL;             
+	out.edgemarkerlist = (int *) NULL;   
+
+	/* Triangulate the points:.  Switches are chosen to read and write a  */
+	/*   PSLG (p), preserve the convex hull (c), number everything from  */
+	/*   zero (z), assign a regional attribute to each element (A), and  */
+	/*   produce an edge list (e), a Voronoi diagram (v), and a triangle */
+	/*   neighbor list (n).                                              */
+
+	sprintf(options,"%s%lf","pQzDq30i"); /*replace V by Q to quiet down the logging*/
+  
+	triangulate(options, &in, &out, NULL);
+	/*report(&out, 0, 1, 1, 1, 1, 0);*/
+
+	/*Allocate index, x and y: */
+	index=(double*)mxMalloc(3*out.numberoftriangles*sizeof(double));
+	x=(double*)mxMalloc(out.numberofpoints*sizeof(double));
+	y=(double*)mxMalloc(out.numberofpoints*sizeof(double));
+	segments=(double*)mxMalloc(3*out.numberofsegments*sizeof(double));
+	segmentmarkerlist=(double*)mxMalloc(out.numberofsegments*sizeof(double));
+
+	for (i = 0; i < out.numberoftriangles; i++) {
+		for (j = 0; j < out.numberofcorners; j++) {
+			*(index+3*i+j)=(double)out.trianglelist[i * out.numberofcorners + j]+1;
+		}
+	}
+	for (i = 0; i < out.numberofpoints; i++) {
+		x[i]=out.pointlist[i * 2 + 0];
+		y[i]=out.pointlist[i * 2 + 1];
+	}
+	
+	for (i = 0; i < out.numberofsegments; i++) {
+		segments[3*i+0]=(double)out.segmentlist[i*2+0]+1;
+		segments[3*i+1]=(double)out.segmentlist[i*2+1]+1;
+		segmentmarkerlist[i]=(double)out.segmentmarkerlist[i];
+	}
+
+	/*Associate elements with segments: */
+	AssociateSegmentToElement(&segments,out.numberofsegments,index,out.numberoftriangles);
+
+	/*Order segments so that their normals point outside the domain: */
+	OrderSegments(&segments,out.numberofsegments, index,out.numberoftriangles);
+
+	/*Output : */
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,out.numberoftriangles);
+	mxSetPr(pmxa_array,index);
+	mexCallMATLAB( 1, &plhs[0], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofpoints);
+	mxSetPr(pmxa_array,x);
+	mexCallMATLAB( 1, &plhs[1], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofpoints);
+	mxSetPr(pmxa_array,y);
+	mexCallMATLAB( 1, &plhs[2], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,out.numberofsegments);
+	mxSetPr(pmxa_array,segments);
+	mexCallMATLAB( 1, &plhs[3], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofsegments);
+	mxSetPr(pmxa_array,segmentmarkerlist);
+	mexCallMATLAB( 1, &plhs[4], 1, &pmxa_array, "transpose");
+	
+	return;
+}
+
+void TriMeshNoDensityUsage(void)
+{
+	printf("\n");
+	printf("   usage: [index,x,y,segments,segmentmarkers]=TriMeshNoDensity(domainoutlinefilename,riftsoutlinename) \n");
+	printf("      where: index,x,y defines a triangulation, segments is an array made \n");
+	printf("      of exterior segments to the mesh domain outline, segmentmarkers is an array flagging each segment \n");
+	printf("      (if rifts are present, markers >=2 flag them ), outlinefilename an Argus domain outline file.\n");
+	printf("      riftsoutlinename is an Argus domain file, defining rifts (ie: open profiles), \n");
+	printf("      riftsoutlinename is an optional arguments.\n");
+	printf("\n");
+}
Index: /issm/trunk-jpl/src/modules/TriMeshNoDensity/TriMeshNoDensity.h
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshNoDensity/TriMeshNoDensity.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMeshNoDensity/TriMeshNoDensity.h	(revision 12032)
@@ -0,0 +1,23 @@
+/*!\file:  TriMeshNoDensity.h
+ * \brief header prototype
+ */ 
+
+#ifndef _TRIMESH_H_
+#define _TRIMESH_H_
+
+#include "mex.h"
+#include "triangle.h"
+#include "string.h"
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+void TriMeshNoDensityUsage(void);
+
+#undef __FUNCT__ 
+#define __FUNCT__ "TriMeshNoDensity"
+
+#endif
Index: /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp	(revision 12032)
@@ -0,0 +1,328 @@
+/*!\file:  TriMeshProcessRifts.cpp
+ * \brief split a mesh where a rift (or fault) is present
+ */ 
+
+#include "./TriMeshProcessRifts.h"
+
+void mexFunction(	int nlhs, mxArray* plhs[],
+					int nrhs, const mxArray* prhs[] ) {
+
+
+	/*Matlab arrays: */
+	mxArray* pmxa_array=NULL;
+	mxArray* pmxa_array2=NULL;
+	mxArray* pmxa_array3=NULL;
+	int i,j,k,counter;
+	
+	/* returned quantities: */
+	int      out_numrifts;
+	int*     out_riftsnumsegments=NULL;
+	double** out_riftssegments=NULL; 
+	int*     out_riftsnumpairs=NULL;
+	double** out_riftspairs=NULL;
+	double*  out_riftstips=NULL;
+	double** out_riftspenaltypairs=NULL;
+	int*     out_riftsnumpenaltypairs=NULL;
+
+	/*empty rifts structure: */
+	double* pNaN=NULL;
+	const	char*	fnames[10];
+	mwSize     ndim=2;
+	mwSize		dimensions[2] = {1,1};
+	double* pair=NULL;
+
+	
+	/* input: */
+	double* tindex_in=NULL;
+	double* index_in=NULL;
+	int     nel;
+	double* x_inm=NULL; //matlab vector
+	double* x_in=NULL; //copy of matlab vector
+	int     nods;
+	double* y_inm=NULL;//matlab vector
+	double* y_in=NULL;//copy of matlab vector
+	double* tsegments_in=NULL;
+	double* segments_in=NULL;
+	double* tsegmentmarkers_in=NULL;
+	double* segmentmarkers_in=NULL;
+
+	/* state: */
+	double* state=NULL;
+
+	int     num_seg;
+
+	/*rifts: */
+	int     riftflag;
+	int     numrifts;
+
+	/* verify correct usage: */
+	if (nlhs==0 && nrhs==0) {
+		/* special case: */
+		TriMeshProcessRiftsUsage();
+		return;
+	}
+	
+	if (!(  (nlhs==6) || (nrhs==5))){
+		mexPrintf("   %s format error.\n", __FUNCT__);
+		TriMeshProcessRiftsUsage();
+		printf("   ");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch index_in: */
+	if(mxIsDouble(prhs[0])){
+		nel=mxGetM(prhs[0]);
+		tindex_in=mxGetPr(prhs[0]);
+		index_in=(double*)xmalloc(nel*3*sizeof(double));
+		for (i=0;i<nel;i++){
+			for (j=0;j<3;j++){
+				*(index_in+3*i+j)=*(tindex_in+nel*j+i);
+			}
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: first argument should be the element list!");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch x_in: */
+	if(mxIsDouble(prhs[1])){
+		nods=mxGetM(prhs[1]);
+		x_inm=mxGetPr(prhs[1]);
+		x_in=(double*)xmalloc(nods*sizeof(double));
+		for (i=0;i<nods;i++){
+			x_in[i]=x_inm[i];
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: second argument should be the x corrdinate list!");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch y_in: */
+	if(mxIsDouble(prhs[2])){
+		y_inm=mxGetPr(prhs[2]);
+		y_in=(double*)xmalloc(nods*sizeof(double));
+		for (i=0;i<nods;i++){
+			y_in[i]=y_inm[i];
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: third argument should be the y corrdinate list!");
+		mexErrMsgTxt(" ");
+	}	
+
+	/*Fetch segments_in: */
+	if(mxIsDouble(prhs[3])){
+		num_seg=mxGetM(prhs[3]);
+		tsegments_in=mxGetPr(prhs[3]);
+		segments_in=(double*)xmalloc(num_seg*3*sizeof(double));
+		for (i=0;i<num_seg;i++){
+			for (j=0;j<3;j++){
+				*(segments_in+3*i+j)=*(tsegments_in+num_seg*j+i);
+			}
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: fourth argument should be the segments list!");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch segment markers: */
+	if(mxIsDouble(prhs[4])){
+		tsegmentmarkers_in=mxGetPr(prhs[4]);
+		segmentmarkers_in=(double*)xmalloc(num_seg*sizeof(double));
+		for (i=0;i<num_seg;i++){
+			segmentmarkers_in[i]=tsegmentmarkers_in[i];
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: fourth argument should be the segmentmarkers list!");
+		mexErrMsgTxt(" ");
+	}
+
+	/*
+	printf("Index: \n");
+	for (i=0;i<nel;i++){
+		for(j=0;j<3;j++){
+			printf("%lf ",*(index_in+3*i+j));
+		}
+		printf("\n");
+	}
+	printf("x,y: \n");
+	for (i=0;i<nods;i++){
+		printf("%16.16lf %16.16lf\n",x_in[i],y_in[i]);
+	}
+	printf("segments:\n");
+	for (i=0;i<num_seg;i++){
+		for(j=0;j<3;j++){
+			printf("%lf ",*(segments_in+3*i+j));
+		}
+		printf("%lf ",segmentmarkers_in[i]);
+		printf("\n");
+	}
+	*/
+
+	/*First, do some fixing on the existing mesh: we do not want any element belonging entirely to the segment list (ie: 
+	 *all the nodes of this element belong to the segments (tends to happen when there are corners: */
+	RemoveCornersFromRifts(&index_in,&nel,&x_in,&y_in,&nods,segments_in,segmentmarkers_in,num_seg);
+
+	/*Figure out if we have rifts, and how many: */
+	IsRiftPresent(&riftflag,&numrifts,segmentmarkers_in,num_seg);
+	
+	if(riftflag){	
+		SplitMeshForRifts(&nel,&index_in,&nods,&x_in,&y_in,&num_seg,&segments_in,&segmentmarkers_in);
+	}
+
+	/*Order segments so that their normals point outside the domain: */
+	OrderSegments(&segments_in,num_seg, index_in,nel);
+
+	
+	if(riftflag){
+		
+		/*We do not want to output segments mixed with rift segments: wring out the rifts from the segments, using the 
+		 *segmentmarkerlist:*/
+		SplitRiftSegments(&segments_in,&segmentmarkers_in,&num_seg,&out_numrifts,&out_riftsnumsegments,&out_riftssegments,numrifts);
+
+		/*Using rift segments, associate rift faces in pairs, each pair face representing opposite flanks of the rifts facing one another directly: */
+		PairRiftElements(&out_riftsnumpairs,&out_riftspairs,out_numrifts,out_riftsnumsegments,out_riftssegments,x_in,y_in);
+		
+		/*Order rifts so that they start from one tip, go to the other tip, and back: */
+		OrderRifts(&out_riftstips, out_riftssegments,out_riftspairs,numrifts,out_riftsnumsegments,x_in,y_in);
+
+		/*Create penalty pairs, used by Imp: */
+		PenaltyPairs(&out_riftspenaltypairs,&out_riftsnumpenaltypairs,numrifts,out_riftssegments,out_riftsnumsegments,out_riftspairs,out_riftstips,x_in,y_in);
+	}
+
+
+	/*Output : */
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,nel);
+	mxSetPr(pmxa_array,index_in);
+	mexCallMATLAB( 1, &plhs[0], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,nods);
+	mxSetPr(pmxa_array,x_in);
+	mexCallMATLAB( 1, &plhs[1], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,nods);
+	mxSetPr(pmxa_array,y_in);
+	mexCallMATLAB( 1, &plhs[2], 1, &pmxa_array, "transpose");
+
+	
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,num_seg);
+	mxSetPr(pmxa_array,segments_in);
+	mexCallMATLAB( 1, &plhs[3], 1, &pmxa_array, "transpose");
+	
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,num_seg);
+	mxSetPr(pmxa_array,segmentmarkers_in);
+	mexCallMATLAB( 1, &plhs[4], 1, &pmxa_array, "transpose");
+
+	if(riftflag){
+		/*Create a structure rifts where if i is a rift number, we have the following fields rifts(i).segments and rifts(i).numsegs: */
+
+		fnames[0] = "numsegs";
+		fnames[1] = "segments";
+		fnames[2] = "pairs";
+		fnames[3] = "tips";
+		fnames[4] = "penaltypairs";
+		fnames[5] = "fill";
+		fnames[6] = "friction";
+		fnames[7] = "fraction";
+		fnames[8] = "fractionincrement";
+		fnames[9] = "state";
+
+		dimensions[0]=out_numrifts;
+
+		pmxa_array=mxCreateStructArray( ndim,dimensions,10,fnames);
+		
+		for (i=0;i<out_numrifts;i++){
+			/*Segments: */
+			pmxa_array2= mxCreateDoubleMatrix(0,0,mxREAL);
+			mxSetM(pmxa_array2,3);
+			mxSetN(pmxa_array2,out_riftsnumsegments[i]);
+			mxSetPr(pmxa_array2,out_riftssegments[i]);
+			mexCallMATLAB( 1, &pmxa_array3, 1, &pmxa_array2, "transpose");
+			
+			mxSetField(pmxa_array,i,"segments",pmxa_array3);
+			mxSetField(pmxa_array,i,"numsegs",mxCreateDoubleScalar((double)out_riftsnumsegments[i]));
+
+			/*Element pairs: */
+			pmxa_array2= mxCreateDoubleMatrix(0,0,mxREAL);
+			mxSetM(pmxa_array2,2);
+			mxSetN(pmxa_array2,out_riftsnumpairs[i]);
+			mxSetPr(pmxa_array2,out_riftspairs[i]);
+			mexCallMATLAB( 1, &pmxa_array3, 1, &pmxa_array2, "transpose");
+			
+			mxSetField(pmxa_array,i,"pairs",pmxa_array3);
+
+			/*Tips: */
+			pmxa_array2= mxCreateDoubleMatrix(0,0,mxREAL);
+			mxSetM(pmxa_array2,1);
+			pair=(double*)xmalloc(2*sizeof(double));
+			pair[0]=*(out_riftstips+2*i+0);
+			pair[1]=*(out_riftstips+2*i+1);
+			mxSetN(pmxa_array2,2);
+			mxSetPr(pmxa_array2,pair);
+			mxSetField(pmxa_array,i,"tips",pmxa_array2);
+
+			/*Penalty pairs: */
+			pmxa_array2= mxCreateDoubleMatrix(0,0,mxREAL);
+			mxSetM(pmxa_array2,7);
+			mxSetN(pmxa_array2,out_riftsnumpenaltypairs[i]);
+			mxSetPr(pmxa_array2,out_riftspenaltypairs[i]);
+			mexCallMATLAB( 1, &pmxa_array3, 1, &pmxa_array2, "transpose");
+			
+			mxSetField(pmxa_array,i,"penaltypairs",pmxa_array3);
+
+			/*Friction fraction, fractionincrement  and fill: */
+			mxSetField(pmxa_array,i,"friction",mxCreateDoubleScalar(0));
+			mxSetField(pmxa_array,i,"fill",mxCreateDoubleScalar(IceEnum)); //default is ice
+			mxSetField(pmxa_array,i,"fraction",mxCreateDoubleScalar(0)); //default is ice
+			mxSetField(pmxa_array,i,"fractionincrement",mxCreateDoubleScalar(0.1)); 
+
+			/*State: */
+			state=(double*)xmalloc(out_riftsnumpenaltypairs[i]*sizeof(double));
+			for(j=0;j<out_riftsnumpenaltypairs[i];j++)state[j]=FreeEnum;
+			pmxa_array2= mxCreateDoubleMatrix(0,0,mxREAL);
+			mxSetM(pmxa_array2,1);
+			mxSetN(pmxa_array2,out_riftsnumpenaltypairs[i]);
+			mxSetPr(pmxa_array2,state);
+			mexCallMATLAB( 1, &pmxa_array3, 1, &pmxa_array2, "transpose");
+			
+			mxSetField(pmxa_array,i,"state",pmxa_array3);
+		}
+	}
+	else{
+		/*output NaN :*/
+		pNaN=(double*)xmalloc(sizeof(double));
+		*pNaN=NAN;
+		pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+		mxSetM(pmxa_array,1);
+		mxSetN(pmxa_array,1);
+		mxSetPr(pmxa_array,pNaN);
+		
+	}
+	plhs[5]=pmxa_array;
+
+	return;
+}
+
+
+void TriMeshProcessRiftsUsage(void)
+{
+	printf("\n");
+	printf("   usage: [index2,x2,y2,segments2,segmentmarkers2,rifts2]=TriMeshProcessrifts(index1,x1,y1,segments1,segmentmarkers1) \n");
+	printf("      where: (index1,x1,y1,segments1,segmentmarkers1) is an initial triangulation.\n");
+	printf("      index2,x2,y2,segments2,segmentmarkers2,rifts2 is the resulting triangulation where rifts have been processed.\n");
+}
Index: /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.h
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.h	(revision 12032)
@@ -0,0 +1,23 @@
+/*!\file:  TriMeshProcessRifts.h
+ * \brief header prototype
+ */ 
+
+#ifndef _TRIMESH_PROCESSRIFTS_H_
+#define _TRIMESH_PROCESSRIFTS_H_
+
+#include "mex.h"
+#include "triangle.h"
+#include "string.h"
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+#include "../../c/EnumDefinitions/EnumDefinitions.h"
+
+void TriMeshProcessRiftsUsage(void);
+#undef __FUNCT__ 
+#define __FUNCT__ "TriMeshProcessRifts"
+
+#endif
Index: /issm/trunk-jpl/src/modules/TriMeshRefine/TriMeshRefine.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshRefine/TriMeshRefine.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMeshRefine/TriMeshRefine.cpp	(revision 12032)
@@ -0,0 +1,327 @@
+/*!\file:  TriMeshRefine
+ * \brief refine a mesh output by TriMesh:
+ */ 
+
+#include "./TriMeshRefine.h"
+
+
+void mexFunction(	int nlhs, mxArray* plhs[],
+					int nrhs, const mxArray* prhs[] )
+{
+
+
+	/*Matlab arrays: */
+	mxArray* pmxa_array=NULL;
+	mxArray* pmxa_array2=NULL;
+	mxArray* pmxa_array3=NULL;
+	int i,j,k,counter;
+	
+	/* returned quantities: */
+
+	double* index=NULL;
+	double* x=NULL;
+	double* y=NULL;
+	double* segments=NULL;
+	double* segmentmarkerlist=NULL;
+	
+	/* input: */
+	double* area=NULL;
+	double* tindex_in=NULL;
+	double*    index_in=NULL;
+	int     nel;
+	double* x_inm=NULL; //matlab vector
+	double* x_in=NULL; //copy of matlab vector
+	int     nods;
+	double* y_inm=NULL;//matlab vector
+	double* y_in=NULL;//copy of matlab vector
+	double* tsegments_in=NULL;
+	double* segments_in=NULL;
+	double* tsegmentmarkers_in=NULL;
+	double* segmentmarkers_in=NULL;
+
+	int     num_seg;
+	char*   order=NULL;
+
+	/* Triangle structures: */
+	struct triangulateio in,out;
+	char   options[256];
+
+	/* verify correct usage: */
+	if (nlhs==0 && nrhs==0) {
+		/* special case: */
+		TriMeshRefineUsage();
+		return;
+	}
+
+	if (!(  (nlhs==5) || (nrhs==6) || (nrhs==7)  )){
+		mexPrintf("   %s format error.\n", __FUNCT__);
+		TriMeshRefineUsage();
+		printf("   ");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch index_in: */
+	if(mxIsDouble(prhs[0])){
+		nel=mxGetM(prhs[0]);
+		tindex_in=mxGetPr(prhs[0]);
+		index_in=(double*)xmalloc(nel*3*sizeof(double));
+		for (i=0;i<nel;i++){
+			for (j=0;j<3;j++){
+				*(index_in+3*i+j)=*(tindex_in+nel*j+i)-1;
+			}
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: first argument should be the element list!");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch x_in: */
+	if(mxIsDouble(prhs[1])){
+		nods=mxGetM(prhs[1]);
+		x_inm=mxGetPr(prhs[1]);
+		x_in=(double*)xmalloc(nods*sizeof(double));
+		for (i=0;i<nods;i++){
+			x_in[i]=x_inm[i];
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: second argument should be the x corrdinate list!");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch y_in: */
+	if(mxIsDouble(prhs[2])){
+		y_inm=mxGetPr(prhs[2]);
+		y_in=(double*)xmalloc(nods*sizeof(double));
+		for (i=0;i<nods;i++){
+			y_in[i]=y_inm[i];
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: third argument should be the y corrdinate list!");
+		mexErrMsgTxt(" ");
+	}	
+
+	/*Fetch segments_in: */
+	if(mxIsDouble(prhs[3])){
+		num_seg=mxGetM(prhs[3]);
+		tsegments_in=mxGetPr(prhs[3]);
+		segments_in=(double*)xmalloc(num_seg*3*sizeof(double));
+		for (i=0;i<num_seg;i++){
+			for (j=0;j<3;j++){
+				*(segments_in+3*i+j)=*(tsegments_in+num_seg*j+i)-1;
+			}
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: fourth argument should be the segments list!");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch segment markers: */
+	if(mxIsDouble(prhs[4])){
+		tsegmentmarkers_in=mxGetPr(prhs[4]);
+		segmentmarkers_in=(double*)xmalloc(num_seg*sizeof(double));
+		for (i=0;i<num_seg;i++){
+			segmentmarkers_in[i]=tsegmentmarkers_in[i];
+		}
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: fourth argument should be the segmentmarkers list!");
+		mexErrMsgTxt(" ");
+	}
+	
+	/*Fetch area: */
+	if(mxIsDouble(prhs[5])){
+		if (mxGetM(prhs[5])!=nel){
+			printf("%s%s\n",__FUNCT__," error message: area vector should be of the same size as index\n");
+			mexErrMsgTxt(" ");
+		}
+		area=mxGetPr(prhs[5]);
+	}
+	else{
+		printf("%s%s\n",__FUNCT__," error message: fifth argument should be the area list!");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Optionaly, recover desired order: */
+	if(nrhs==7){
+		if (!mxIsChar(prhs[6])){
+			mexPrintf("%s%s\n",__FUNCT__," error message; sixth argument should be a string ('yes' or 'no')!");
+			mexErrMsgTxt(" ");
+		}
+		order = (char *) xmalloc((mxGetN(prhs[6])+1)*sizeof(char));
+		mxGetString(prhs[6],order,mxGetN(prhs[6])+1);
+	}
+
+	/*printf("Index: \n");
+	for (i=0;i<nel;i++){
+		for(j=0;j<3;j++){
+			printf("%lf ",*(index_in+3*i+j));
+		}
+		printf("\n");
+	}*/
+	/*printf("x,y: \n");
+	for (i=0;i<nods;i++){
+		printf("%16.16lf %16.16lf\n",x_in[i],y_in[i]);
+	}*/
+	/*printf("segments:\n");
+	for (i=0;i<num_seg;i++){
+		for(j=0;j<3;j++){
+			printf("%lf ",*(segments_in+3*i+j));
+		}
+		printf("%lf ",segmentmarkers_in[i]);
+		printf("\n");
+	}*/
+	/*printf("area: \n");
+	for (i=0;i<nel;i++){
+		printf("%16.16lf \n",area[i]);
+	}*/
+	//if(nrhs==6)printf("Order: %s\n",order);
+
+	/*Create initial triangulation to call triangulate():*/
+	in.numberoftriangles=nel;
+	in.numberoftriangleattributes=1;
+	in.numberofcorners=3;
+	
+	in.trianglelist = (int *) xmalloc(3*in.numberoftriangles * sizeof(int));
+	for(i=0;i<in.numberoftriangles;i++){
+		for(j=0;j<3;j++){
+			in.trianglelist[3*i+j]=(int)index_in[3*i+j];
+		}
+	}
+	in.triangleattributelist = (REAL *) xmalloc(in.numberoftriangles * in.numberoftriangleattributes * sizeof(REAL));
+	for(i=0;i<in.numberoftriangles;i++){
+		in.triangleattributelist[i]=0.0;
+	}
+	in.trianglearealist = (REAL *) xmalloc(in.numberoftriangles * sizeof(REAL));
+	for(i=0;i<in.numberoftriangles;i++){
+		in.trianglearealist[i]=area[i];
+	}
+
+	in.numberofpoints=nods;
+	in.numberofpointattributes=1;
+	in.pointlist = (REAL *) xmalloc(in.numberofpoints * 2 * sizeof(REAL));
+	for (i=0;i<nods;i++){
+		in.pointlist[2*i+0]=x_in[i];
+		in.pointlist[2*i+1]=y_in[i];
+	}
+	in.pointattributelist = (REAL *) xmalloc(in.numberofpoints * in.numberofpointattributes * sizeof(REAL));
+	for (i=0;i<nods;i++){
+		in.pointattributelist[i] = 0.0;
+	}	
+
+	in.numberofsegments = num_seg;
+	in.segmentlist = (int *) xmalloc(in.numberofsegments * 2 * sizeof(REAL));
+	in.segmentmarkerlist = (int *) mxCalloc(in.numberofsegments,sizeof(int));
+	for (i=0;i<num_seg;i++){
+		in.segmentlist[2*i+0]=(int)segments_in[3*i+0];
+		in.segmentlist[2*i+1]=(int)segments_in[3*i+1];
+		in.segmentmarkerlist[i]=(int)segmentmarkers_in[i];
+	}
+	
+	in.numberofholes = 0;
+
+	/* Make necessary initializations so that Triangle can return a */
+	/*   triangulation in `out'.  */
+
+	out.pointlist = (REAL *) NULL;            
+	out.pointattributelist = (REAL *) NULL;
+	out.pointmarkerlist = (int *) NULL; 
+	out.trianglelist = (int *) NULL;          
+	out.triangleattributelist = (REAL *) NULL;
+	out.neighborlist = (int *) NULL;         
+	out.segmentlist = (int *) NULL;
+	out.segmentmarkerlist = (int *) NULL;
+	out.edgelist = (int *) NULL;             
+	out.edgemarkerlist = (int *) NULL;   
+
+	/* Triangulate the points:.  Switches are chosen to read and write a  */
+	/*   PSLG (p), preserve the convex hull (c), number everything from  */
+	/*   zero (z), assign a regional attribute to each element (A), and  */
+	/*   produce an edge list (e), a Voronoi diagram (v), and a triangle */
+	/*   neighbor list (n).                                              */
+
+	sprintf(options,"%s%lf","QzDq30iarp",area); //replace V by Q to quiet down the logging
+
+
+	triangulate(options, &in, &out, NULL);
+	
+	/*Allocate index, x and y: */
+	index=(double*)xmalloc(3*out.numberoftriangles*sizeof(double));
+	x=(double*)xmalloc(out.numberofpoints*sizeof(double));
+	y=(double*)xmalloc(out.numberofpoints*sizeof(double));
+	segments=(double*)xmalloc(3*out.numberofsegments*sizeof(double));
+	segmentmarkerlist=(double*)xmalloc(out.numberofsegments*sizeof(double));
+
+	for (i = 0; i < out.numberoftriangles; i++) {
+		for (j = 0; j < out.numberofcorners; j++) {
+			*(index+3*i+j)=(double)out.trianglelist[i * out.numberofcorners + j]+1;
+		}
+	}
+	for (i = 0; i < out.numberofpoints; i++) {
+		x[i]=out.pointlist[i * 2 + 0];
+		y[i]=out.pointlist[i * 2 + 1];
+	}
+	
+	for (i = 0; i < out.numberofsegments; i++) {
+		segments[3*i+0]=(double)out.segmentlist[i*2+0]+1;
+		segments[3*i+1]=(double)out.segmentlist[i*2+1]+1;
+		segmentmarkerlist[i]=(double)out.segmentmarkerlist[i];
+	}
+
+	/*Associate elements with segments: */
+	AssociateSegmentToElement(&segments,out.numberofsegments,index,out.numberoftriangles);
+
+	/*Order segments so that their normals point outside the domain: */
+	if(!strcmp(order,"yes")){
+		OrderSegments(&segments,out.numberofsegments, index,out.numberoftriangles);
+	}
+	
+	/*Output : */
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,out.numberoftriangles);
+	mxSetPr(pmxa_array,index);
+	mexCallMATLAB( 1, &plhs[0], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofpoints);
+	mxSetPr(pmxa_array,x);
+	mexCallMATLAB( 1, &plhs[1], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofpoints);
+	mxSetPr(pmxa_array,y);
+	mexCallMATLAB( 1, &plhs[2], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,out.numberofsegments);
+	mxSetPr(pmxa_array,segments);
+	mexCallMATLAB( 1, &plhs[3], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofsegments);
+	mxSetPr(pmxa_array,segmentmarkerlist);
+	mexCallMATLAB( 1, &plhs[4], 1, &pmxa_array, "transpose");
+
+	return;
+}
+
+
+void TriMeshRefineUsage(void)
+{
+	printf("\n");
+	printf("   usage: [index2,x2,y2,segments2,segmentmarkers2]=TriMeshRefine(index1,x1,y1,segments1,segmentmarkers1,area,order) \n");
+	printf("      where: (index1,x1,y1,segments1,segmentmarkers1) is an initial triangulation (segment1 does not need to be ordered).\n");
+	printf("      area is a vector of element areas determining which elements will be refined.\n");
+	printf("      order is an optional argument that determines whether segments are output in the \n");
+	printf("      order they are made by Triangle (ie none), or ordered counter clockwise around the domain outline.\n");
+	printf("      (index2,x2,y2,segments2,segmentmarkers2) is the resulting refined triangulation.\n");
+	printf("   note: order is an optional arguments\n");
+}
Index: /issm/trunk-jpl/src/modules/TriMeshRefine/TriMeshRefine.h
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshRefine/TriMeshRefine.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMeshRefine/TriMeshRefine.h	(revision 12032)
@@ -0,0 +1,22 @@
+/*!\file:  TriMeshRefine.h
+ * \brief header prototype
+ */ 
+
+#ifndef _TRIMESH_REFINE_H_
+#define _TRIMESH_REFINE_H_
+
+#include "mex.h"
+#include "triangle.h"
+#include "string.h"
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+void TriMeshRefineUsage(void);
+#undef __FUNCT__ 
+#define __FUNCT__ "TriMeshRefine"
+
+#endif
Index: /issm/trunk-jpl/src/modules/TriMeshRifts/TriMeshRifts.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshRifts/TriMeshRifts.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMeshRifts/TriMeshRifts.cpp	(revision 12032)
@@ -0,0 +1,322 @@
+/*
+ * TriMeshRifts: out of a domain outline file ( Argus format ), 
+ * use the Triangle package to create a triangular mesh 
+ *
+ */
+
+#include "./TriMeshRifts.h"
+
+void mexFunction(	int nlhs, mxArray* plhs[],
+					int nrhs, const mxArray* prhs[] )
+{
+
+
+	/*Matlab arrays: */
+	mxArray* pmxa_array=NULL;
+	int i,j;
+	int counter,counter2,backcounter;
+	int prhs_counter;
+	
+	/* returned quantities: */
+
+	double* index=NULL;
+	double* x=NULL;
+	double* y=NULL;
+	double* segments=NULL;
+	double*    segmentmarkerlist=NULL;
+
+	/* input: */
+	char*  domainname=NULL;
+	char*  riftname=NULL;
+	double area;
+	char*  order=NULL;
+	
+	/*Domain outline variables: */
+	int      nprof;
+	int*     profnvertices=NULL;
+	double** pprofx=NULL;
+	double** pprofy=NULL;
+	double*  xprof=NULL;
+	double*  yprof=NULL;
+	int      numberofpoints;
+
+	/*Rift outline variables: */
+	int      numrifts;
+	int*     riftsnumvertices=NULL;
+	double** riftsverticesx=NULL;
+	double** riftsverticesy=NULL;
+
+	/* Triangle structures: */
+	struct triangulateio in,out;
+	char   options[256];
+
+	/* verify correct usage: */
+	if (nlhs==0 && nrhs==0) {
+		/* special case: */
+		TriMeshRiftsUsage();
+		return;
+	}
+
+	if (!(  (nlhs==5) ||(nrhs==2) || (nrhs==3)  || (nrhs==4) )){
+		mexPrintf("   %s format error.\n", __FUNCT__);
+		TriMeshRiftsUsage();
+		printf("   ");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch data needed by Triangle: */
+
+	prhs_counter=0;
+	/*First recover the domain outline file name: */
+	if (!mxIsChar(prhs[prhs_counter])){
+		mexPrintf("%s%s\n",__FUNCT__," error message; first argument should be the domain outline file name!");
+		mexErrMsgTxt(" ");
+	}
+	domainname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char));
+	mxGetString(prhs[prhs_counter],domainname,mxGetN(prhs[prhs_counter])+1);
+
+	/*Look for optional rifts file name: */
+	prhs_counter++;
+	if (mxIsChar(prhs[prhs_counter])){
+		riftname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char));
+		mxGetString(prhs[prhs_counter],riftname,mxGetN(prhs[prhs_counter])+1);
+		prhs_counter++;
+	}
+
+	/*Recover the mesh density desired:*/
+	area=mxGetScalar(prhs[prhs_counter]);
+
+	/*Optionaly, recover desired order: */
+	prhs_counter++;
+	if (mxIsChar(prhs[prhs_counter])){
+		order = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char));
+		mxGetString(prhs[prhs_counter],order,mxGetN(prhs[prhs_counter])+1);
+	}
+	
+	/*Start reading the domain outline file: */
+	if(!DomainOutlineRead(&nprof,&profnvertices,&pprofx,&pprofy,NULL,domainname,false)){
+		printf("%s%s%s\n",__FUNCT__," error message reading domain outline ",domainname);
+		mexErrMsgTxt(" ");
+	}
+
+	/*Read rifts file if present: */
+	if(riftname){
+		if(!DomainOutlineRead(&numrifts,&riftsnumvertices,&riftsverticesx,&riftsverticesy,NULL,riftname,false)){
+			printf("%s%s%s\n",__FUNCT__," error message reading rifts outline ",riftname);
+			mexErrMsgTxt(" ");
+		}
+	}
+
+	/*Create initial triangulation to call triangulate():*/
+	numberofpoints=0;
+	for (i=0;i<nprof;i++){
+		numberofpoints+=profnvertices[i];
+	}
+	if (riftname){
+		for (i=0;i<numrifts;i++){
+			numberofpoints+=riftsnumvertices[i];
+		}
+	}
+	in.numberofpoints=numberofpoints;
+
+	in.numberofpointattributes=1;
+	in.pointlist = (REAL *) mxMalloc(in.numberofpoints * 2 * sizeof(REAL));
+
+	counter=0;
+	for (i=0;i<nprof;i++){
+		xprof=pprofx[i];
+		yprof=pprofy[i];
+		for (j=0;j<profnvertices[i];j++){
+			in.pointlist[2*counter+0]=xprof[j];
+			in.pointlist[2*counter+1]=yprof[j];
+			counter++;
+		}
+	}
+	if(riftname){
+		for (i=0;i<numrifts;i++){
+			xprof=riftsverticesx[i];
+			yprof=riftsverticesy[i];
+			for (j=0;j<riftsnumvertices[i];j++){
+				in.pointlist[2*counter+0]=xprof[j];
+				in.pointlist[2*counter+1]=yprof[j];
+				counter++;
+			}
+		}
+	}
+	
+	in.pointattributelist = (REAL *) mxMalloc(in.numberofpoints *
+										  in.numberofpointattributes *
+										  sizeof(REAL));
+	for (i=0;i<in.numberofpoints;i++){
+		in.pointattributelist[i] = 0.0;
+	}
+	in.pointmarkerlist = (int *) mxMalloc(in.numberofpoints * sizeof(int));
+	for(i=0;i<in.numberofpoints;i++){
+		in.pointmarkerlist[i] = 0;
+	}
+
+	/*Build segments: */
+	/*Figure out number of segments: holes and closed outlines have as many segments as vertices, 
+	 *for rifts, we have one less segment as we have vertices*/
+	in.numberofsegments=0;
+	for (i=0;i<nprof;i++){
+		in.numberofsegments+=profnvertices[i];
+	}
+	if (riftname){
+		for (i=0;i<numrifts;i++){
+			in.numberofsegments+=riftsnumvertices[i]-1;
+		}
+	}
+	
+	in.segmentlist = (int *) mxMalloc(in.numberofsegments * 2 * sizeof(int));
+	in.segmentmarkerlist = (int *) mxCalloc(in.numberofsegments,sizeof(int));
+	counter=0;
+	backcounter=0;
+	for (i=0;i<nprof;i++){
+		for (j=0;j<(profnvertices[i]-1);j++){
+			in.segmentlist[2*counter+0]=counter;
+			in.segmentlist[2*counter+1]=counter+1;
+			in.segmentmarkerlist[counter]=0;
+			counter++;
+		}
+		/*Close this profile: */
+		 in.segmentlist[2*counter+0]=counter;
+		 in.segmentlist[2*counter+1]=backcounter;
+		 in.segmentmarkerlist[counter]=0;
+		 counter++;
+		 backcounter=counter;
+	}
+	counter2=counter;
+	if(riftname){
+		for (i=0;i<numrifts;i++){
+			for (j=0;j<(riftsnumvertices[i]-1);j++){
+				in.segmentlist[2*counter2+0]=counter;
+				in.segmentlist[2*counter2+1]=counter+1;
+				in.segmentmarkerlist[counter2]=2+i;
+				counter2++;
+				counter++;
+			}
+			counter++;
+		}
+	}
+
+	
+	/*Build regions: */
+	in.numberofregions = 0;
+
+	/*Build holes: */
+	in.numberofholes = nprof-1; /*everything is a hole, but for the first profile.*/
+	in.holelist = (REAL *) mxMalloc(in.numberofholes * 2 * sizeof(REAL));
+	for (i=0;i<nprof-1;i++){
+		/*We are looking for a vertex that lies inside the hole: */
+		GridInsideHole(&in.holelist[2*i+0],&in.holelist[2*i+1],profnvertices[i+1],pprofx[i+1],pprofy[i+1]);
+	}
+
+	/* Make necessary initializations so that Triangle can return a */
+	/*   triangulation in `out': */
+
+	out.pointlist = (REAL *) NULL;            
+	out.pointattributelist = (REAL *) NULL;
+	out.pointmarkerlist = (int *) NULL; 
+	out.trianglelist = (int *) NULL;          
+	out.triangleattributelist = (REAL *) NULL;
+	out.neighborlist = (int *) NULL;         
+	out.segmentlist = (int *) NULL;
+	out.segmentmarkerlist = (int *) NULL;
+	out.edgelist = (int *) NULL;             
+	out.edgemarkerlist = (int *) NULL;   
+
+	/* Triangulate the points:.  Switches are chosen to read and write a  */
+	/*   PSLG (p), preserve the convex hull (c), number everything from  */
+	/*   zero (z), assign a regional attribute to each element (A), and  */
+	/*   produce an edge list (e), a Voronoi diagram (v), and a triangle */
+	/*   neighbor list (n).                                              */
+
+	sprintf(options,"%s%lf","pQzDq30ia",area); /*replace V by Q to quiet down the logging*/
+  
+	triangulate(options, &in, &out, NULL);
+	/*report(&out, 0, 1, 1, 1, 1, 0);*/
+
+	/*Allocate index, x and y: */
+	index=(double*)mxMalloc(3*out.numberoftriangles*sizeof(double));
+	x=(double*)mxMalloc(out.numberofpoints*sizeof(double));
+	y=(double*)mxMalloc(out.numberofpoints*sizeof(double));
+	segments=(double*)mxMalloc(3*out.numberofsegments*sizeof(double));
+	segmentmarkerlist=(double*)mxMalloc(out.numberofsegments*sizeof(double));
+
+	for (i = 0; i < out.numberoftriangles; i++) {
+		for (j = 0; j < out.numberofcorners; j++) {
+			*(index+3*i+j)=(double)out.trianglelist[i * out.numberofcorners + j]+1;
+		}
+	}
+	for (i = 0; i < out.numberofpoints; i++) {
+		x[i]=out.pointlist[i * 2 + 0];
+		y[i]=out.pointlist[i * 2 + 1];
+	}
+	
+	for (i = 0; i < out.numberofsegments; i++) {
+		segments[3*i+0]=(double)out.segmentlist[i*2+0]+1;
+		segments[3*i+1]=(double)out.segmentlist[i*2+1]+1;
+		segmentmarkerlist[i]=(double)out.segmentmarkerlist[i];
+	}
+
+	/*Associate elements with segments: */
+	AssociateSegmentToElement(&segments,out.numberofsegments,index,out.numberoftriangles);
+
+	/*Order segments so that their normals point outside the domain: */
+	if(!strcmp(order,"yes")){
+		OrderSegments(&segments,out.numberofsegments, index,out.numberoftriangles);
+	}
+
+	/*Output : */
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,out.numberoftriangles);
+	mxSetPr(pmxa_array,index);
+	mexCallMATLAB( 1, &plhs[0], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofpoints);
+	mxSetPr(pmxa_array,x);
+	mexCallMATLAB( 1, &plhs[1], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofpoints);
+	mxSetPr(pmxa_array,y);
+	mexCallMATLAB( 1, &plhs[2], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,out.numberofsegments);
+	mxSetPr(pmxa_array,segments);
+	mexCallMATLAB( 1, &plhs[3], 1, &pmxa_array, "transpose");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofsegments);
+	mxSetPr(pmxa_array,segmentmarkerlist);
+	mexCallMATLAB( 1, &plhs[4], 1, &pmxa_array, "transpose");
+	
+	return;
+}
+
+void TriMeshRiftsUsage(void)
+{
+	printf("\n");
+	printf("   usage: [index,x,y,segments,segmentmarkers]=TriMeshRifts(domainoutlinefilename,riftsoutlinename,area,ordered) \n");
+	printf("      where: index,x,y defines a triangulation, segments is an array made \n");
+	printf("      of exterior segments to the mesh domain outline, segmentmarkers is an array flagging each segment \n");
+	printf("      (if rifts are present, markers >=2 flag them ), outlinefilename an Argus domain outline file.\n");
+	printf("      riftsoutlinename is an Argus domain file, defining rifts (ie: open profiles), \n");
+	printf("      area is the maximum area desired for any element of the resulting mesh. \n");
+	printf("      and ordered is a string ('yes' or 'no') that determines whether segments are output in the \n");
+	printf("      order they are made by Triangle (ie none), or ordered counter clockwise around the domain outline.\n");
+	printf("      riftsoutlinename and ordered are optional arguments.\n");
+	printf("\n");
+}
+
+
+
+
Index: /issm/trunk-jpl/src/modules/TriMeshRifts/TriMeshRifts.h
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshRifts/TriMeshRifts.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriMeshRifts/TriMeshRifts.h	(revision 12032)
@@ -0,0 +1,23 @@
+/*!\file:  TriMeshRifts.h
+ * \brief header prototype
+ */ 
+
+#ifndef _TRIMESHRIFTS_H_
+#define _TRIMESHRIFTS_H_
+
+#include "mex.h"
+#include "triangle.h"
+#include "string.h"
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+void TriMeshRiftsUsage(void);
+
+#undef __FUNCT__ 
+#define __FUNCT__ "TriMeshRifts"
+
+#endif
Index: /issm/trunk-jpl/src/modules/TriaSearch/TriaSearch.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/TriaSearch/TriaSearch.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriaSearch/TriaSearch.cpp	(revision 12032)
@@ -0,0 +1,66 @@
+/*\file TriaSearch.c
+ *\brief: TriaSearch module. See TriaSearchx for more details.
+ */
+#include "./TriaSearch.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i;
+
+	/*input: */
+	double* index=NULL;
+	int     nel;
+	int     dummy;
+
+	double* x=NULL;
+	double* y=NULL;
+	int     nods;
+
+	double* x0=NULL;
+	double* y0=NULL;
+	int     numberofnodes;
+
+	/* output: */
+	double*  tria=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&TriaSearchUsage);
+
+	/*Input datasets: */
+	FetchData(&index,&nel,&dummy,INDEXHANDLE);
+	FetchData(&x,&nods,XHANDLE);
+	FetchData(&y,&nods,YHANDLE);
+	FetchData(&x0,&numberofnodes,X0HANDLE);
+	FetchData(&y0,&numberofnodes,Y0HANDLE);
+
+	/* Echo: {{{1*/
+	//printf("(x0,y0)=(%g,%g)\n",x0,y0);
+	/*}}}*/
+
+	/* Run core computations: */
+	TriaSearchx(&tria,index,nel,x,y,nods,x0,y0,numberofnodes);
+
+	/* c to matlab: */
+	for(i=0;i<numberofnodes;i++)tria[i]++;
+
+	/*Write data: */
+	WriteData(TRIA,tria,numberofnodes);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void TriaSearchUsage(void)
+{
+	_printf_(true,"TriaSearch- find triangle holding a point (x0,y0) in a mesh\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"         tria=TriaSearch(index,x,y,x0,y0);\n");
+	_printf_(true,"      index,x,y: mesh triangulatrion\n");
+	_printf_(true,"      x0,y0: coordinates of the point for which we are trying to find a triangle\n");
+	_printf_(true,"      x0,y0 can be an array of points\n");
+	_printf_(true,"\n");
+}
Index: /issm/trunk-jpl/src/modules/TriaSearch/TriaSearch.h
===================================================================
--- /issm/trunk-jpl/src/modules/TriaSearch/TriaSearch.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/TriaSearch/TriaSearch.h	(revision 12032)
@@ -0,0 +1,37 @@
+/*!\file TriaSearch.h
+ */
+
+#ifndef _TRIASEARCH_H
+#define _TRIASEARCH_H
+
+/* local prototypes: */
+void TriaSearchUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "TriaSearch"
+
+
+/* serial input macros: */
+#define INDEXHANDLE prhs[0]
+#define XHANDLE prhs[1]
+#define YHANDLE prhs[2]
+#define X0HANDLE prhs[3]
+#define Y0HANDLE prhs[4]
+
+/* serial output macros: */
+#define TRIA (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+
+#undef NRHS
+#define NRHS  5
+
+#endif
Index: /issm/trunk-jpl/src/modules/Xy2ll/Xy2ll.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/Xy2ll/Xy2ll.cpp	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Xy2ll/Xy2ll.cpp	(revision 12032)
@@ -0,0 +1,121 @@
+/*\file Xy2ll.c
+ *\brief: x/y to lat/long coordinate mex module.
+ */
+#include "./Xy2ll.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	int i,verbose=1;
+
+	/*input: */
+	double  *x=NULL,*y=NULL;
+	int     nx,ny,ncoord;
+	int     sgn;
+
+	Options* options=NULL;
+	double   cm=0.,sp=0.;
+
+	/* output: */
+	double  *lat=NULL,*lon=NULL;
+	int     iret=0;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	if (nlhs > NLHS) {
+		Xy2llUsage();
+		_error_("Xy2ll usage error");
+	}
+	if (nrhs < NRHS) {
+		Xy2llUsage();
+		_error_("Xy2ll usage error");
+	}
+
+	/*Input datasets: */
+	if (verbose) printf("Fetching inputs:\n");
+	FetchData(&x,&nx,X_IN);
+	if (verbose)
+		if   (nx == 1) printf("  x=%g\n",x[0]);
+		else           printf("  x=[%d values]\n",nx);
+//	for (i=0; i<nx; i++) printf("  x[%d]=%g\n",i,x[i]);
+	FetchData(&y,&ny,Y_IN);
+	if (verbose)
+		if   (ny == 1) printf("  y=%g\n",y[0]);
+		else           printf("  y=[%d values]\n",ny);
+//	for (i=0; i<ny; i++) printf("  y[%d]=%g\n",i,y[i]);
+	FetchData(&sgn,SGN_IN);
+	if (verbose) printf("  sgn=%d\n",sgn);
+
+	if (verbose) printf("Parsing options:\n");
+	options=new Options(NRHS,nrhs,prhs);
+	if (options->Size()) for(i=0;i<options->Size();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho();
+	/*  defaults are in Xy2lldef, so don't duplicate them here, and only use user values if both have been specified  */
+	if (options->GetOption("central_meridian") || options->GetOption("standard_parallel")) {
+		options->Get(&cm,"central_meridian");
+		if (verbose) printf("  cm=%g\n",cm);
+		options->Get(&sp,"standard_parallel");
+		if (verbose) printf("  sp=%g\n",sp);
+	}
+
+	/*some checks*/
+	if (verbose) printf("Checking inputs:\n");
+
+	if   (nx != ny) _error_("Must have same number of x[%d] and y[%d] coordinates.",nx,ny);
+	else            ncoord=nx;
+	if (sgn != +1 && sgn != -1) _error_("Hemisphere sgn=%d must be +1 (north) or -1 (south).",sgn);
+	if (fabs(cm)      > 180.) _error_("Central meridian cm=%g must be between -180 (west) and +180 (east) degrees.",cm);
+	if (sp < 0. || sp >  90.) _error_("Standard parallel sp=%g must be between 0 and 90 degrees (in specified hemisphere).",sp);
+
+	lat=(double *)xmalloc(ncoord*sizeof(double));
+	lon=(double *)xmalloc(ncoord*sizeof(double));
+
+	/* Run core computations: */
+	if (verbose) printf("Calling core:\n");
+	if (options->GetOption("central_meridian") && options->GetOption("standard_parallel"))
+		iret=Xy2llx(lat,lon,
+					x,y,ncoord,
+					sgn,cm,sp);
+	else
+		iret=Xy2llx(lat,lon,
+					x,y,ncoord,
+					sgn);
+	if (verbose) printf("  iret=%d\n",iret);
+
+	/*Write data: */
+	WriteData(LAT_OUT,lat,ncoord);
+	WriteData(LON_OUT,lon,ncoord);
+
+	/*Clean-up*/
+	delete options;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void Xy2llUsage(void)
+{
+	_printf_(true,"Xy2ll - x/y to lat/long coordinate transformation module:\n");
+	_printf_(true,"\n");
+	_printf_(true,"   This module transforms x/y to lat/long coordinates.\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Usage:\n");
+	_printf_(true,"      [lat,lon]=Xy2ll(x,y,sgn,'param name',param,...);\n");
+	_printf_(true,"\n");
+	_printf_(true,"      x           x coordinates (double vector)\n");
+	_printf_(true,"      y           y coordinates (double vector)\n");
+	_printf_(true,"      sgn         sign for hemisphere (double, +1 (north) or -1 (south))\n");
+	_printf_(true,"\n");
+	_printf_(true,"      central_meridian     central meridian (double, optional, but must specify with sp)\n");
+	_printf_(true,"      standard_parallel    standard parallel (double, optional, but must specify with cm)\n");
+	_printf_(true,"\n");
+	_printf_(true,"      lat         latitude coordinates (double vector)\n");
+	_printf_(true,"      lon         longitude coordinates (double vector)\n");
+	_printf_(true,"\n");
+	_printf_(true,"   Examples:\n");
+	_printf_(true,"      [lat,lon]=Xy2ll(x,y, 1);\n");
+	_printf_(true,"      [lat,lon]=Xy2ll(x,y, 1,'central_meridian',45,'standard_parallel',70);\n");
+	_printf_(true,"      [lat,lon]=Xy2ll(x,y,-1,'central_meridian', 0,'standard_parallel',71);\n");
+	_printf_(true,"\n");
+}
+
Index: /issm/trunk-jpl/src/modules/Xy2ll/Xy2ll.h
===================================================================
--- /issm/trunk-jpl/src/modules/Xy2ll/Xy2ll.h	(revision 12032)
+++ /issm/trunk-jpl/src/modules/Xy2ll/Xy2ll.h	(revision 12032)
@@ -0,0 +1,37 @@
+/*!\file Xy2ll.h
+ * \brief: prototype for x/y to lat/long coordinate mex module.
+ */
+
+#ifndef _XY2LL_H
+#define _XY2LL_H
+
+/* local prototypes: */
+void Xy2llUsage(void);
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/issm-binding.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Xy2ll"
+
+
+/* serial input macros: */
+#define X_IN      prhs[0]
+#define Y_IN      prhs[1]
+#define SGN_IN    prhs[2]
+
+/* serial output macros: */
+#define LAT_OUT    (mxArray**)&plhs[0]
+#define LON_OUT    (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NRHS
+#define NRHS  3
+#undef NLHS
+#define NLHS  2
+
+#endif
+
Index: /issm/trunk-jpl/src/modules/matlab/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/modules/matlab/Makefile.am	(revision 12032)
+++ /issm/trunk-jpl/src/modules/matlab/Makefile.am	(revision 12032)
@@ -0,0 +1,171 @@
+INCLUDES = @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@
+EXEEXT=$(MATLABWRAPPEREXT)
+#Bin programs {{{1
+if MODULES
+bin_PROGRAMS =  AverageFilter\
+				BamgMesher\
+				BamgConvertMesh\
+				BamgTriangulate\
+				Chaco\
+				ContourToMesh \
+				ContourToNodes \
+				ElementConnectivity\
+				EnumToString\
+				Exp2Kml \
+				HoleFiller \
+				InternalFront\
+				InterpFromGridToMesh \
+				InterpFromMeshToMesh2d \
+				InterpFromMeshToMesh3d \
+				InterpFromMeshToGrid \
+				InterpFromMesh2d \
+				KMLFileRead \
+				KMLMeshWrite \
+				KMLOverlay \
+				Kml2Exp \
+				Ll2xy \
+				NodeConnectivity \
+				MeshPartition\
+				MeshProfileIntersection\
+				PointCloudFindNeighbors\
+				PropagateFlagsFromConnectivity\
+				Scotch\
+				Shp2Kml\
+				StringToEnum\
+				TriaSearch\
+				TriMesh\
+				TriMeshRifts\
+				TriMeshNoDensity\
+				TriMeshProcessRifts\
+				TriMeshRefine\
+				Xy2ll
+endif 
+#}}}
+#Flags and libraries {{{1
+LDADD = ../../c/libISSMCore.a ../../c/libISSMModules.a $(TRIANGLELIB) $(PETSCLIB) $(FLIBS) $(PLAPACKLIB) $(MUMPSLIB) $(SCALAPACKLIB) $(BLACSLIB) $(HYPRELIB) $(MLLIB) $(DAKOTALIB) $(METISLIB) $(CHACOLIB) $(SCOTCHLIB) $(BLASLAPACKLIB) $(MPILIB) $(MATHLIB) $(FORTRANLIB) $(GRAPHICSLIB) $(MULTITHREADINGLIB) $(SHAPELIBLIB) $(GSLLIB)
+
+#Triangle library
+AM_CXXFLAGS =  -DTRILIBRARY -DANSI_DECLARATORS -DNO_TIMER
+
+#Matlab part
+AM_LDFLAGS   = $(MEXLINK)
+AM_CXXFLAGS +=  -D_HAVE_MATLAB_MODULES_ -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread 
+LDADD       += $(MEXLIB) ../../c/libISSMMatlab.a 
+
+LDADD       += ../../c/libISSMCore.a ../../c/libISSMModules.a 
+
+#Optimization flags:
+AM_CXXFLAGS += $(CXXOPTFLAGS) 
+#}}}
+#Bin sources {{{1
+AverageFilter_SOURCES = ../AverageFilter/AverageFilter.cpp\
+			  ../AverageFilter/AverageFilter.h
+
+BamgMesher_SOURCES = ../BamgMesher/BamgMesher.cpp\
+					../BamgMesher/BamgMesher.h
+
+BamgConvertMesh_SOURCES = ../BamgConvertMesh/BamgConvertMesh.cpp\
+					../BamgConvertMesh/BamgConvertMesh.h
+
+BamgTriangulate_SOURCES = ../BamgTriangulate/BamgTriangulate.cpp\
+								  ../BamgTriangulate/BamgTriangulate.h
+
+Chaco_SOURCES = ../Chaco/Chaco.cpp\
+					../Chaco/Chaco.h
+
+ContourToMesh_SOURCES = ../ContourToMesh/ContourToMesh.cpp\
+			  ../ContourToMesh/ContourToMesh.h
+
+ContourToNodes_SOURCES = ../ContourToNodes/ContourToNodes.cpp\
+			  ../ContourToNodes/ContourToNodes.h
+
+ElementConnectivity_SOURCES = ../ElementConnectivity/ElementConnectivity.cpp\
+			  ../ElementConnectivity/ElementConnectivity.h
+
+EnumToString_SOURCES = ../EnumToString/EnumToString.cpp\
+			  ../EnumToString/EnumToString.h
+
+StringToEnum_SOURCES = ../StringToEnum/StringToEnum.cpp\
+			  ../StringToEnum/StringToEnum.h
+
+HoleFiller_SOURCES = ../HoleFiller/HoleFiller.cpp\
+			  ../HoleFiller/HoleFiller.h
+
+InternalFront_SOURCES = ../InternalFront/InternalFront.cpp\
+										 ../InternalFront/InternalFront.h
+
+InterpFromGridToMesh_SOURCES = ../InterpFromGridToMesh/InterpFromGridToMesh.cpp\
+			  ../InterpFromGridToMesh/InterpFromGridToMesh.h
+
+InterpFromMeshToMesh2d_SOURCES = ../InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp\
+							../InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h
+
+InterpFromMeshToMesh3d_SOURCES = ../InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.cpp\
+									../InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h
+
+InterpFromMeshToGrid_SOURCES = ../InterpFromMeshToGrid/InterpFromMeshToGrid.cpp\
+									../InterpFromMeshToGrid/InterpFromMeshToGrid.h
+
+InterpFromMesh2d_SOURCES = ../InterpFromMesh2d/InterpFromMesh2d.cpp\
+									../InterpFromMesh2d/InterpFromMesh2d.h
+
+KMLFileRead_SOURCES = ../KMLFileRead/KMLFileRead.cpp\
+			  ../KMLFileRead/KMLFileRead.h
+
+KMLMeshWrite_SOURCES = ../KMLMeshWrite/KMLMeshWrite.cpp\
+			  ../KMLMeshWrite/KMLMeshWrite.h
+
+KMLOverlay_SOURCES = ../KMLOverlay/KMLOverlay.cpp\
+			  ../KMLOverlay/KMLOverlay.h
+
+Xy2ll_SOURCES = ../Xy2ll/Xy2ll.cpp\
+			  ../Xy2ll/Xy2ll.h
+
+Ll2xy_SOURCES = ../Ll2xy/Ll2xy.cpp\
+			  ../Ll2xy/Ll2xy.h
+
+Exp2Kml_SOURCES = ../Exp2Kml/Exp2Kml.cpp\
+			  ../Exp2Kml/Exp2Kml.h
+
+Kml2Exp_SOURCES = ../Kml2Exp/Kml2Exp.cpp\
+			  ../Kml2Exp/Kml2Exp.h
+
+MeshPartition_SOURCES = ../MeshPartition/MeshPartition.cpp\
+			  ../MeshPartition/MeshPartition.h
+
+MeshProfileIntersection_SOURCES = ../MeshProfileIntersection/MeshProfileIntersection.cpp\
+			  ../MeshProfileIntersection/MeshProfileIntersection.h
+
+NodeConnectivity_SOURCES = ../NodeConnectivity/NodeConnectivity.cpp\
+										../NodeConnectivity/NodeConnectivity.h
+
+PointCloudFindNeighbors_SOURCES = ../PointCloudFindNeighbors/PointCloudFindNeighbors.cpp\
+			  ../PointCloudFindNeighbors/PointCloudFindNeighbors.h
+
+PropagateFlagsFromConnectivity_SOURCES = ../PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.cpp\
+			  ../PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h
+
+Scotch_SOURCES = ../Scotch/Scotch.cpp\
+			  ../Scotch/Scotch.h
+
+Shp2Kml_SOURCES = ../Shp2Kml/Shp2Kml.cpp\
+			  ../Shp2Kml/Shp2Kml.h
+
+TriaSearch_SOURCES = ../TriaSearch/TriaSearch.cpp\
+			  ../TriaSearch/TriaSearch.h
+
+TriMesh_SOURCES = ../TriMesh/TriMesh.cpp\
+			  ../TriMesh/TriMesh.h
+
+TriMeshRifts_SOURCES = ../TriMeshRifts/TriMeshRifts.cpp\
+			  ../TriMeshRifts/TriMeshRifts.h
+
+TriMeshNoDensity_SOURCES = ../TriMeshNoDensity/TriMeshNoDensity.cpp\
+			  ../TriMeshNoDensity/TriMeshNoDensity.h
+
+TriMeshProcessRifts_SOURCES = ../TriMeshProcessRifts/TriMeshProcessRifts.cpp\
+			  ../TriMeshProcessRifts/TriMeshProcessRifts.h
+
+TriMeshRefine_SOURCES = ../TriMeshRefine/TriMeshRefine.cpp\
+			  ../TriMeshRefine/TriMeshRefine.h
+#}}}
Index: /issm/trunk-jpl/src/modules/python/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/modules/python/Makefile.am	(revision 12032)
+++ /issm/trunk-jpl/src/modules/python/Makefile.am	(revision 12032)
@@ -0,0 +1,27 @@
+INCLUDES = @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@
+EXEEXT=$(PYTHONWRAPPEREXT)
+#Bin programs {{{1
+if MODULES
+bin_PROGRAMS = TriMesh
+endif 
+#}}}
+#Flags and libraries {{{1
+LDADD = ../../c/libISSMCore.a ../../c/libISSMModules.a $(TRIANGLELIB) $(PETSCLIB) $(FLIBS) $(PLAPACKLIB) $(MUMPSLIB) $(SCALAPACKLIB) $(BLACSLIB) $(HYPRELIB) $(MLLIB) $(DAKOTALIB) $(METISLIB) $(CHACOLIB) $(SCOTCHLIB) $(BLASLAPACKLIB) $(MPILIB) $(MATHLIB) $(FORTRANLIB) $(GRAPHICSLIB) $(MULTITHREADINGLIB) $(SHAPELIBLIB) $(GSLLIB)
+
+#Triangle library
+AM_CXXFLAGS =  -DTRILIBRARY -DANSI_DECLARATORS -DNO_TIMER
+
+#Python part
+AM_LDFLAGS   = $(PYTHONLINK)
+AM_CXXFLAGS +=  -D_HAVE_PYTHON_MODULES_ -DNPY_NO_DEPRECATED_API 
+LDADD       += $(BOOSTLIB) $(PYTHONLIB) ../../c/libISSMPython.a
+
+LDADD       += ../../c/libISSMCore.a ../../c/libISSMModules.a 
+
+#Optimization flags:
+AM_CXXFLAGS += $(CXXOPTFLAGS) 
+#}}}
+#Bin sources {{{1
+TriMesh_SOURCES = ../TriMesh/TriMesh.cpp\
+			  ../TriMesh/TriMesh.h
+#}}}
