Index: /issm/trunk/src/c/ContourToNodesx/ContourToNodesx.cpp
===================================================================
--- /issm/trunk/src/c/ContourToNodesx/ContourToNodesx.cpp	(revision 1105)
+++ /issm/trunk/src/c/ContourToNodesx/ContourToNodesx.cpp	(revision 1105)
@@ -0,0 +1,45 @@
+/*! \file  ContourToNodesx.c
+ */
+
+#include "./ContourToNodesx.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "ContourToNodesx"
+
+int ContourToNodesx( Vec* pflags,double* x, double* y, int nods, Contour** contours,int numcontours,int edgevalue){
+
+	int i;
+	int m,n;
+
+	/*Contour:*/
+	Contour* contouri=NULL;
+	int      numgrids;
+	double*  xc=NULL;
+	double*  yc=NULL;
+	double   value;
+
+	/*output: */
+	Vec flags=NULL;
+
+	flags=NewVec(nods);
+
+	/*Loop through all contours: */
+	for (i=0;i<numcontours;i++){
+		#ifdef _DEBUG_
+			printf("\nHandling contour %i/%i\n",i,numcontours);
+		#endif
+		contouri=*(contours+i);
+		numgrids=contouri->nods;
+		xc=contouri->x;
+		yc=contouri->y;
+		IsInPoly(flags,xc,yc,numgrids,x,y,nods,edgevalue);
+	}
+
+	/*Assemble vector: */
+	VecAssemblyBegin(flags);
+	VecAssemblyEnd(flags);
+
+	/*Assign output pointers: */
+	*pflags=flags;
+
+}
Index: /issm/trunk/src/c/ContourToNodesx/ContourToNodesx.h
===================================================================
--- /issm/trunk/src/c/ContourToNodesx/ContourToNodesx.h	(revision 1105)
+++ /issm/trunk/src/c/ContourToNodesx/ContourToNodesx.h	(revision 1105)
@@ -0,0 +1,16 @@
+/*
+	ContourToNodesx.h
+*/
+
+
+#ifndef _CONTOURTONODESX_H
+#define _CONTOURTONODESX_H
+
+#include "../shared/shared.h"
+#include "../objects/objects.h"
+
+/* local prototypes: */
+int ContourToNodesx( Vec* pflags,double* x, double* y, int nods, Contour** contours,int numcontours,int edgevalue);
+
+#endif /* _CONTOURTONODESX_H */
+
Index: /issm/trunk/src/c/ElementConnectivityx/ElementConnectivityx.cpp
===================================================================
--- /issm/trunk/src/c/ElementConnectivityx/ElementConnectivityx.cpp	(revision 1105)
+++ /issm/trunk/src/c/ElementConnectivityx/ElementConnectivityx.cpp	(revision 1105)
@@ -0,0 +1,100 @@
+/*!\file ElementConnectivityx
+ * \brief: compute element connectivity table, using node connectivity table and elements.
+ *
+ * For each element, we want to know which neighbouring elements it connects to (fully, via an entire segment, not by a node).
+ * We use the nodeconnectivity to speed up the computation. The nodeconnectivity gives us for each node of the element, 
+ * all the neighbouring elements of this node, which are good candidates to be neighbours of the element itself.
+ * For now, only triangular elements, ie 3 neighbours max per element.
+ */
+
+#include "./ElementConnectivityx.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__ "ElementConnectivityx"
+
+#include "../shared/shared.h"
+#include "../include/macros.h"
+#include "../toolkits/toolkits.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+
+int hascommondedge(double* element1,double* element2);
+
+void	ElementConnectivityx( double** pelementconnectivity, double* elements, int nel, double* nodeconnectivity, int nods, int width){
+
+	int i,j,k,n;
+
+	/*intermediary: */
+	int    maxels;
+	double element;
+	double connectedelement;
+	int    connectedelementindex;
+	int    node;
+	int    index;
+	int    num_elements;
+
+	/*output: */
+	double* elementconnectivity=NULL;
+
+	/*maxels: */
+	maxels=width-1;
+	/*Allocate connectivity: */
+	elementconnectivity=(double*)xcalloc(nel*3,sizeof(double));
+
+	/*Go through all elements, and for each element, go through its nodes, to get the neighbouring elements. 
+	 * Once we get the neighbouring elements, figure out if they share a segment with the current element. If so, 
+	 * plug them in the connectivity, unless they are already there.: */
+	
+	for(n=0;n<nel;n++){
+
+		element=(double)(n+1); //matlab indexing
+
+		for(i=0;i<3;i++){
+		
+			node=(int)*(elements+n*3+i); //already matlab indexed, elements comes directly from the workspace.
+			index=node-1;
+
+			num_elements=(int)*(nodeconnectivity+width*index+maxels); //retrieve number of elements already  plugged into the connectivity of this node.
+
+			for(j=0;j<num_elements;j++){
+
+				/*for each element connected to node, figure out if it has a commond edge with element: */
+				connectedelement=*(nodeconnectivity+width*index+j);
+				connectedelementindex=(int)(connectedelement-1); //go from matlab indexing to c indexing.
+				
+				if(hascommondedge(elements+n*3+0,elements+connectedelementindex*3+0)){
+					/*Ok, this connected element has a commond edge  with element, plug it into elementconnectivity, unless 
+					 *it is already there: */
+
+					for(k=0;k<3;k++){
+						if (*(elementconnectivity+3*n+k)==0){
+							*(elementconnectivity+3*n+k)=connectedelement;
+							break;
+						}
+						else{
+							if(connectedelement==*(elementconnectivity+3*n+k))break;
+						}
+					}
+				}
+			}
+		}
+	}
+
+	/*Assign output pointers: */
+	*pelementconnectivity=elementconnectivity;
+}
+				
+
+int hascommondedge(double* element1,double* element2){
+
+	int i,j;
+	int count;
+
+	count=0;
+	for(i=0;i<3;i++){
+		for(j=0;j<3;j++){
+			if (*(element1+i)==*(element2+j))count++;
+		}
+	}
+	if (count==2)return 1;
+	else return 0;
+}
Index: /issm/trunk/src/c/ElementConnectivityx/ElementConnectivityx.h
===================================================================
--- /issm/trunk/src/c/ElementConnectivityx/ElementConnectivityx.h	(revision 1105)
+++ /issm/trunk/src/c/ElementConnectivityx/ElementConnectivityx.h	(revision 1105)
@@ -0,0 +1,12 @@
+/*!\file:  ElementConnectivityx.h
+ * \brief header file for element connectivity computation
+ */ 
+
+#ifndef _ELEMENTCONNECTIVITYX_H
+#define _ELEMENTCONNECTIVITYX_H
+
+/* local prototypes: */
+void	ElementConnectivityx( double** pelementconnectivity, double* elements, int nel, double* nodeconnectivity, int nods, int width);
+
+#endif  /* _ELEMENTCONNECTIVITYX_H */
+
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 1104)
+++ /issm/trunk/src/c/Makefile.am	(revision 1105)
@@ -247,4 +247,6 @@
 					./ContourToMeshx/ContourToMeshx.cpp\
 					./ContourToMeshx/ContourToMeshx.h\
+					./ContourToNodesx/ContourToNodesx.cpp\
+					./ContourToNodesx/ContourToNodesx.h\
 					./Reducevectorgtosx/Reducevectorgtosx.cpp\
 					./Reducevectorgtosx/Reducevectorgtosx.h\
@@ -256,4 +258,8 @@
 					./NormalizeConstraintsx/NormalizeConstraintsx.cpp\
 					./NormalizeConstraintsx/NormalizeConstraintsx.h\
+					./NodeConnectivityx/NodeConnectivityx.cpp\
+					./NodeConnectivityx/NodeConnectivityx.h\
+					./ElementConnectivityx/ElementConnectivityx.cpp\
+					./ElementConnectivityx/ElementConnectivityx.h\
 					./SystemMatricesx/SystemMatricesx.cpp\
 					./SystemMatricesx/SystemMatricesx.h\
Index: /issm/trunk/src/c/NodeConnectivityx/NodeConnectivityx.cpp
===================================================================
--- /issm/trunk/src/c/NodeConnectivityx/NodeConnectivityx.cpp	(revision 1105)
+++ /issm/trunk/src/c/NodeConnectivityx/NodeConnectivityx.cpp	(revision 1105)
@@ -0,0 +1,83 @@
+/*!\file NodeConnectivityx
+ * \brief: compute node connectivity table, using elements connectivity table.
+ *
+ * For each node, we want to know how many elements are connected to this element, and which they are. 
+ * Given that the 2d meshes we create in ISSM are triangular for now, and they are delaunay conforming, 
+ * each triangle has a minimum angle of 30 degrees, which implies a connectivity <=6. We therefore return 
+ * a nods x 7 connectivity table, with the 7'th column giving us the number of elements connected to each 
+ * row node, and the first 6 columns giving us the elements numbers. 
+ * Amend that: sounds like some triangles get up to 9 connectivity. Take 10 to be on the safe side.
+ * In order to be compatible with matlab output, the connectivity table is given in matlab indexing (starts at 1).
+ */
+
+#include "./NodeConnectivityx.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__ "NodeConnectivityx"
+
+#include "../shared/shared.h"
+#include "../include/macros.h"
+#include "../toolkits/toolkits.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+
+void	NodeConnectivityx( double** pconnectivity, int* pwidth, double* elements, int nel, int nods){
+
+	int i,j,n;
+	const int maxels=9;
+	const int width=maxels+1;
+
+	/*intermediary: */
+	int     node;
+	int     index;
+	int     num_elements;
+	int     already_plugged=0;
+	double  element;
+
+	/*output: */
+	double* connectivity=NULL;
+
+
+
+	/*Allocate connectivity: */
+	connectivity=(double*)xcalloc(nods*width,sizeof(double));
+
+	/*Go through all elements, and for each elements, plug into the connectivity, all the nodes. 
+	 * If nodes are already plugged into the connectivity, skip them.: */
+	for(n=0;n<nel;n++){
+
+		element=(double)(n+1); //matlab indexing
+
+		for(i=0;i<3;i++){
+		
+			node=(int)*(elements+n*3+i); //already matlab indexed, elements comes directly from the workspace.
+			index=node-1;
+
+			num_elements=(int)*(connectivity+width*index+maxels); //retrieve number of elements already  plugged into the connectivity of this node.
+			
+			already_plugged=0;
+			for(j=0;j<num_elements;j++){
+				if (element==*(connectivity+width*index+j)){
+					already_plugged=1;
+					break;
+				}
+			}
+			if(already_plugged)break;
+
+			/*this elements is not yet plugged  into the connectivity for this node, do it, and increase counter: */
+			*(connectivity+width*index+num_elements)=element;
+			*(connectivity+width*index+maxels)=(double)(num_elements+1);
+			
+		}
+	}
+
+	/*Last check: is the number of elements on last column of the connectivity superior to maxels? If so, then error out and 
+	 * warn the user to increase the connectivity width: */
+	for(i=0;i<nods;i++){
+		if (*(connectivity+width*i+maxels)>maxels)throw ErrorException(__FUNCT__,exprintf("%s%g%s"," max connectivity width reached (",
+					*(connectivity+width*i+maxels),")! increase width of connectivity table"));
+	}
+
+	/*Assign output pointers: */
+	*pconnectivity=connectivity;
+	*pwidth=width;
+}
Index: /issm/trunk/src/c/NodeConnectivityx/NodeConnectivityx.h
===================================================================
--- /issm/trunk/src/c/NodeConnectivityx/NodeConnectivityx.h	(revision 1105)
+++ /issm/trunk/src/c/NodeConnectivityx/NodeConnectivityx.h	(revision 1105)
@@ -0,0 +1,12 @@
+/*!\file:  NodeConnectivityx.h
+ * \brief header file for node connectivity computation
+ */ 
+
+#ifndef _NODECONNECTIVITYX_H
+#define _NODECONNECTIVITYX_H
+
+/* local prototypes: */
+void	NodeConnectivityx( double** pconnectivity, int* pwidth,double* elements, int nel, int nods);
+
+#endif  /* _NODECONNECTIVITYX_H */
+
Index: /issm/trunk/src/c/issm.h
===================================================================
--- /issm/trunk/src/c/issm.h	(revision 1104)
+++ /issm/trunk/src/c/issm.h	(revision 1105)
@@ -24,4 +24,5 @@
 #include "./MpcNodesx/MpcNodesx.h"
 #include "./ContourToMeshx/ContourToMeshx.h"
+#include "./ContourToNodesx/ContourToNodesx.h"
 #include "./DataInterpx/DataInterpx.h"
 #include "./HoleFillerx/HoleFillerx.h"
@@ -51,4 +52,6 @@
 #include "./FieldExtrudex/FieldExtrudex.h"
 #include "./Qmux/Qmux.h"
+#include "./NodeConnectivityx/NodeConnectivityx.h"
+#include "./ElementConnectivityx/ElementConnectivityx.h"
 
 
