Index: /issm/trunk/src/mex/ContourToNodes/ContourToNodes.cpp
===================================================================
--- /issm/trunk/src/mex/ContourToNodes/ContourToNodes.cpp	(revision 1103)
+++ /issm/trunk/src/mex/ContourToNodes/ContourToNodes.cpp	(revision 1103)
@@ -0,0 +1,110 @@
+/*! \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;
+
+	/* output: */
+	Vec  flags=NULL;
+	int  nods;
+
+	//contours
+	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); Cant' use it here, as we have variable  outputs.
+	if((nlhs==0) && (nrhs=0)){
+		ContourToNodesUsage();
+		throw ErrorException(__FUNCT__," usage. See above");
+	}
+
+	/*Fetch inputs: */
+	FetchData((void**)&x,&nods,NULL,XHANDLE,"Matrix","Mat");
+	FetchData((void**)&y,NULL,NULL,YHANDLE,"Matrix","Mat");
+	FetchData((void**)&edgevalue,NULL,NULL,EDGEVALUEHANDLE,"Integer",NULL);
+
+	/*Recover list of contours from the 'contours' structure: */
+	//number of contours;
+	numcontours=mxGetNumberOfElements(CONTOURSHANDLE);
+	//allocate array:
+	contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+
+	//go through contours, and populate xcontours and ycontours accordingly.
+	for(i=0;i<numcontours;i++){
+		//allocate
+		contouri=(Contour*)xmalloc(sizeof(Contour));
+		//retrieve dimension of this contour.
+		contouri->nods=(int)mxGetScalar(mxGetField(CONTOURSHANDLE,i,"nods"));
+		//set pointers.
+		contouri->x=mxGetPr(mxGetField(CONTOURSHANDLE,i,"x"));
+		contouri->y=mxGetPr(mxGetField(CONTOURSHANDLE,i,"y"));
+		*(contours+i)=contouri;
+	}
+
+	#ifdef _DEBUG_
+	for(i=0;i<numcontours;i++){
+		printf("\nContour echo: contour number  %i / %i\n",i+1,numcontours);
+		contouri=*(contours+i);
+		printf("   Number of grids %i\n",contouri->nods);
+		for (j=0;j<contouri->nods;j++){
+			printf("   %lf %lf\n",*(contouri->x+j),*(contouri->y+j));
+		}
+	}
+	#endif
+
+	/*Run interpolation routine: */
+	ContourToNodesx( &flags,x,y,nods,contours,numcontours,edgevalue);
+
+	/* output: */
+	WriteData(FLAGS,flags,0,0,"Vector",NULL);
+
+	/*end module: */
+	MODULEEND();
+	
+}
+
+void ContourToNodesUsage(void)
+{
+	printf("   usage:\n");
+	printf("   [flags]=ContourToNodes(,x,y,contours,edgevalue);\n\n");
+	printf("   where:\n");
+	printf("      x,y: list of nodes.\n");
+	printf("      contours: structure holding sets of vertices making open 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("      flags: vector of flags (0 or 1), of size nods.\n");
+	printf("\n");
+}
Index: /issm/trunk/src/mex/ContourToNodes/ContourToNodes.h
===================================================================
--- /issm/trunk/src/mex/ContourToNodes/ContourToNodes.h	(revision 1103)
+++ /issm/trunk/src/mex/ContourToNodes/ContourToNodes.h	(revision 1103)
@@ -0,0 +1,40 @@
+
+/*
+	ContourToNodes.h
+*/
+
+
+#ifndef _CONTOURTONODES_H
+#define _CONTOURTONODES_H
+
+/* local prototypes: */
+void ContourToNodesUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__
+#define __FUNCT__ "ContourToNodes"
+
+
+#ifndef ALL
+#define ALL 0
+#endif
+
+/* input macros: */
+#define XHANDLE prhs[0]
+#define YHANDLE prhs[1]
+#define CONTOURSHANDLE prhs[2]
+#define EDGEVALUEHANDLE prhs[3]
+
+/* serial output macros: */
+#define FLAGS (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  2
+#undef NRHS
+#define NRHS 4
+
+
+#endif  /* _CONTOURTONODES_H */
+
Index: /issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.cpp
===================================================================
--- /issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.cpp	(revision 1103)
+++ /issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.cpp	(revision 1103)
@@ -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((void**)&elements,&nel,NULL,ELEMENTS,"Matrix","Mat");
+	FetchData((void**)&nodeconnectivity,&nods,&width,NODECONNECTIVITY,"Matrix","Mat");
+
+	/*!Generate internal degree of freedom numbers: */
+	ElementConnectivityx(&elementconnectivity, elements,nel, nodeconnectivity, nods, width);
+
+	/*write output datasets: */
+	WriteData(ELEMENTCONNECTIVITY,elementconnectivity,nel,3,"Matrix","Mat");
+
+	/*Free ressources: */
+	xfree((void**)&elements);
+	xfree((void**)&nodeconnectivity);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void ElementConnectivityUsage(void) {
+	_printf_("\n");
+	_printf_("   usage: elementconnectivity = %s(elements, nodeconnectivity);\n",__FUNCT__);
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.h
===================================================================
--- /issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.h	(revision 1103)
+++ /issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.h	(revision 1103)
@@ -0,0 +1,33 @@
+
+/*
+	ElementConnectivity.h
+*/
+
+
+#ifndef _ELEMENTCONNECTIVITY_H
+#define _ELEMENTCONNECTIVITY_H
+
+/* local prototypes: */
+void ElementConnectivityUsage(void);
+
+#include "../../c/issm.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/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 1102)
+++ /issm/trunk/src/mex/Makefile.am	(revision 1103)
@@ -10,4 +10,5 @@
 				ControlOptimization\
 				ContourToMesh \
+				ContourToNodes \
 				ControlConstrain \
 				DataInterp \
@@ -15,4 +16,5 @@
 				Du\
 				Echo\
+				ElementConnectivity\
 				Gradj\
 				GriddataMeshToGrid\
@@ -23,4 +25,5 @@
 				ModelProcessor \
 				MpcNodes\
+				NodeConnectivity\
 				NormalizeConstraints\
 				Orth\
@@ -83,4 +86,8 @@
 			  ContourToMesh/ContourToMesh.h
 
+ContourToNodes_SOURCES = ContourToNodes/ContourToNodes.cpp\
+			  ContourToNodes/ContourToNodes.h
+
+
 ControlOptimization_SOURCES = ControlOptimization/ControlOptimization.cpp\
 			  ControlOptimization/ControlOptimization.h
@@ -101,4 +108,7 @@
 			  Echo/Echo.h
 
+ElementConnectivity_SOURCES = ElementConnectivity/ElementConnectivity.cpp\
+			  ElementConnectivity/ElementConnectivity.h
+
 Gradj_SOURCES = Gradj/Gradj.cpp\
 			  Gradj/Gradj.h
@@ -131,4 +141,7 @@
 			  NormalizeConstraints/NormalizeConstraints.h
 
+NodeConnectivity_SOURCES = NodeConnectivity/NodeConnectivity.cpp\
+			  NodeConnectivity/NodeConnectivity.h
+
 Orth_SOURCES = Orth/Orth.cpp\
 			  Orth/Orth.h
Index: /issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.cpp
===================================================================
--- /issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.cpp	(revision 1103)
+++ /issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.cpp	(revision 1103)
@@ -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((void**)&elements,&nel,NULL,ELEMENTS,"Matrix","Mat");
+	FetchData((void**)&nods,NULL,NULL,NUMNODES,"Integer",NULL);
+
+	/*!Generate internal degree of freedom numbers: */
+	NodeConnectivityx(&connectivity, &width,elements,nel, nods);
+
+	/*write output datasets: */
+	WriteData(CONNECTIVITY,connectivity,nods,width,"Matrix","Mat");
+
+	/*Free ressources: */
+	xfree((void**)&elements);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void NodeConnectivityUsage(void) {
+	_printf_("\n");
+	_printf_("   usage: connectivity = %s(elements, numnodes);\n",__FUNCT__);
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.h
===================================================================
--- /issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.h	(revision 1103)
+++ /issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.h	(revision 1103)
@@ -0,0 +1,33 @@
+
+/*
+	NodeConnectivity.h
+*/
+
+
+#ifndef _NODECONNECTIVITY_H
+#define _NODECONNECTIVITY_H
+
+/* local prototypes: */
+void NodeConnectivityUsage(void);
+
+#include "../../c/issm.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 */
+
