Index: /issm/trunk-jpl/src/c/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/c/Makefile.am	(revision 14713)
+++ /issm/trunk-jpl/src/c/Makefile.am	(revision 14714)
@@ -804,4 +804,6 @@
 			./modules/HoleFillerx/HoleFillerx.cpp\
 			./modules/HoleFillerx/HoleFillerx.h\
+			./modules/EdgeDetectionx/EdgeDetectionx.cpp\
+			./modules/EdgeDetectionx/EdgeDetectionx.h\
 			./modules/AverageFilterx/AverageFilterx.cpp\
 			./modules/AverageFilterx/AverageFilterx.h\
Index: /issm/trunk-jpl/src/c/modules/EdgeDetectionx/CMakeLists.txt
===================================================================
--- /issm/trunk-jpl/src/c/modules/EdgeDetectionx/CMakeLists.txt	(revision 14714)
+++ /issm/trunk-jpl/src/c/modules/EdgeDetectionx/CMakeLists.txt	(revision 14714)
@@ -0,0 +1,5 @@
+# Subdirectories {{{
+# }}}
+# Include Directory {{{
+include_directories(AFTER $ENV{ISSM_DIR}/src/c/modules/EdgeDetectionx)
+# }}}
Index: /issm/trunk-jpl/src/c/modules/EdgeDetectionx/EdgeDetectionx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/EdgeDetectionx/EdgeDetectionx.cpp	(revision 14714)
+++ /issm/trunk-jpl/src/c/modules/EdgeDetectionx/EdgeDetectionx.cpp	(revision 14714)
@@ -0,0 +1,36 @@
+/*!\file EdgeDetectionx
+ * \brief: x code for EdgeDetection module
+ */
+
+/*Header files: {{{*/
+#include "./EdgeDetectionx.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../io/io.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+/*}}}*/
+
+void EdgeDetectionx(DataSet* contours, bool* image, int M, int N){
+
+	/*intermediary: */
+	int i;
+	
+	/*output: */
+	Contour<IssmPDouble>* contour=NULL;
+	IssmPDouble* x=NULL;
+	IssmPDouble* y=NULL;
+
+	/*Create bogus contour: */
+	x=xNewZeroInit<IssmPDouble>(10);
+	y=xNewZeroInit<IssmPDouble>(10);
+	for(i=0;i<10;i++){
+		x[i]=(IssmPDouble)i;
+		y[i]=(IssmPDouble)i;
+	}
+	contour= new Contour<IssmPDouble>(1,10,x,y,true);
+
+	/*Add contour to our dataset of contours: */
+	contours->AddObject(contour);
+	
+}
Index: /issm/trunk-jpl/src/c/modules/EdgeDetectionx/EdgeDetectionx.h
===================================================================
--- /issm/trunk-jpl/src/c/modules/EdgeDetectionx/EdgeDetectionx.h	(revision 14714)
+++ /issm/trunk-jpl/src/c/modules/EdgeDetectionx/EdgeDetectionx.h	(revision 14714)
@@ -0,0 +1,15 @@
+/*!\file:  EdgeDetectionx.h
+ * \brief header file for EdgeDetectionx module
+ */ 
+
+#ifndef _EDGEDETECTIONX_H_
+#define _EDGEDETECTIONX_H_
+
+#include <string.h>
+#include "../../Container/Container.h"
+#include "../../classes/objects/objects.h"
+
+/* local prototypes: */
+void EdgeDetectionx(DataSet* contours, bool* image, int M, int N);
+
+#endif  /* _EDGEDETECTIONX_H */
Index: /issm/trunk-jpl/src/c/modules/modules.h
===================================================================
--- /issm/trunk-jpl/src/c/modules/modules.h	(revision 14713)
+++ /issm/trunk-jpl/src/c/modules/modules.h	(revision 14714)
@@ -25,4 +25,5 @@
 #include "./DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.h"
 #include "./ElementConnectivityx/ElementConnectivityx.h"
+#include "./EdgeDetectionx/EdgeDetectionx.h"
 #include "./EnumToStringx/EnumToStringx.h"
 #include "./StringToEnumx/StringToEnumx.h"
Index: /issm/trunk-jpl/src/wrappers/EdgeDetection/EdgeDetection.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/EdgeDetection/EdgeDetection.cpp	(revision 14714)
+++ /issm/trunk-jpl/src/wrappers/EdgeDetection/EdgeDetection.cpp	(revision 14714)
@@ -0,0 +1,48 @@
+/*!\file EdgeDetection.c
+ * \brief: edge detection for a boolean image
+*/
+	
+#include "./EdgeDetection.h"
+
+void EdgeDetectionUsage(void){/*{{{*/
+	_pprintLine_("EDGEDETECTION usage- detect edges of a boolean image");
+	_pprintLine_("");
+	_pprintLine_("   Usage:");
+	_pprintLine_("      contours=EdgeDetection(image);");
+	_pprintLine_("");
+	_pprintLine_("      image: boolean matrix");
+	_pprintLine_("");
+	_pprintLine_("   Example:");
+	_pprintLine_("      load('velocities.mat');");
+	_pprintLine_("      md.inversion.vx_obs=EdgeDetection(x_n,y_m,vx,md.mesh.x,md.mesh.y,0);");
+	_pprintLine_("");
+}/*}}}*/
+WRAPPER(EdgeDetection){
+
+	int i,j;
+
+	/*input: */
+	bool *image = NULL;
+	int   M,N;
+
+	/* output: */
+	DataSet* contours=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments: */
+	CHECKARGUMENTS(NLHS,NRHS,&EdgeDetectionUsage);
+
+	/*Input datasets: */
+	FetchData(&image,&M,&N,IMAGE);
+
+	/* Run core computations: */
+	EdgeDetectionx(contours,image,M,N);
+
+	/*Write data: */
+	WriteData(CONTOURS,contours);
+
+	/*end module: */
+	MODULEEND();
+}
Index: /issm/trunk-jpl/src/wrappers/EdgeDetection/EdgeDetection.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/EdgeDetection/EdgeDetection.h	(revision 14714)
+++ /issm/trunk-jpl/src/wrappers/EdgeDetection/EdgeDetection.h	(revision 14714)
@@ -0,0 +1,48 @@
+/*!\file EdgeDetection.h
+ * \brief: prototype for EdgeDetection module 
+ */
+
+#ifndef _EDGEDETECTION_H_
+#define _EDGEDETECTION_H_
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+	#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+/*For python modules: needs to come before header files inclusion*/
+#ifdef _HAVE_PYTHON_
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#endif
+
+#include "../../c/include/globals.h"
+#include "../../c/modules/modules.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../bindings.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "EdgeDetection"
+
+#ifdef _HAVE_MATLAB_MODULES_
+/* serial input macros: */
+#define IMAGE       prhs[0]
+/* serial output macros: */
+#define CONTOURS (mxArray**)&plhs[0]
+#endif
+
+#ifdef _HAVE_PYTHON_MODULES_
+/* serial input macros: */
+#define IMAGE       PyTuple_GetItem(args,0)
+/* serial output macros: */
+#define CONTOURS output,0
+#endif
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  1
+
+#endif  /* _EDGEDETECTION_H_ */
Index: /issm/trunk-jpl/src/wrappers/matlab/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/Makefile.am	(revision 14713)
+++ /issm/trunk-jpl/src/wrappers/matlab/Makefile.am	(revision 14714)
@@ -46,4 +46,5 @@
 						 ContourToMesh.la\
 						 ContourToNodes.la\
+						 EdgeDetection.la\
 						 ElementConnectivity.la\
 						 EnumToString.la\
@@ -216,4 +217,7 @@
 Ll2xy_la_LIBADD = ${deps} $(MPILIB) $(PETSCLIB)
 
+EdgeDetection_la_SOURCES = ../EdgeDetection/EdgeDetection.cpp\
+							../EdgeDetection/EdgeDetection.h
+
 ExpSimplify_la_SOURCES = ../ExpSimplify/ExpSimplify.cpp\
 							../ExpSimplify/ExpSimplify.h
Index: /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp	(revision 14713)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp	(revision 14714)
@@ -360,7 +360,61 @@
 }
 /*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,DataSet* contours){{{*/
+void WriteData(mxArray** pdataref,DataSet* contours){
+
+	/*Intermediary*/
+
+	int         i;
+	mxArray    *dataref           = NULL;
+	const int   numfields         = 6;
+	const char *fnames[numfields];
+	mwSize      ndim              = 2;
+	mwSize      dimensions[2]     = {1,1};
+	char        id[100];
+
+
+	/*Initialize field names*/
+	i=0;
+	fnames[i++] = "name";
+	fnames[i++] = "nods";
+	fnames[i++] = "density";
+	fnames[i++] = "x";
+	fnames[i++] = "y";
+	fnames[i++] = "closed";
+	_assert_(i==numfields);
+
+	/*Initialize matlab structure of dimension numrifts*/
+	dimensions[0]=contours->Size();
+	dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames);
+
+	/*set each matlab each field*/
+	for(int i=0;i<contours->Size();i++){
+		Contour<IssmPDouble>* contour=(Contour<IssmPDouble>*)contours->GetObjectByOffset(i);
+		
+		/*create a name for this contour from the contour id and set it: */
+		sprintf(id,"%i",contour->id);
+		SetStructureFieldi(dataref,i,"name",id);
+
+		/*number of nods: */
+		SetStructureFieldi(dataref,i,"nods"         ,contour->nods);
+		
+		/*density: */
+		SetStructureFieldi(dataref,i,"density"            ,1);
+		
+		/*x and y: */
+		SetStructureFieldi(dataref,i,"x"             ,contour->nods, 1,contour->x);
+		SetStructureFieldi(dataref,i,"y"             ,contour->nods, 1,contour->y);
+
+		/*closed: */
+		SetStructureFieldi(dataref,i,"closed"         ,(int)contour->closed);
+	}
+
+	/*Assign output*/
+	*pdataref=dataref;
+}
+/*}}}*/
 
 /*Toolkit*/
-/*FUNCTION SetStructureField{{{*/
+/*FUNCTION SetStructureField(mxArray* dataref,const char* fieldname,int M,int N,double* fieldpointer){{{*/
 void SetStructureField(mxArray* dataref,const char* fieldname,int M,int N,double* fieldpointer){
 
@@ -372,4 +426,16 @@
 	/*Assign to structure*/
 	mxSetField(dataref,0,fieldname,field);
+}
+/*}}}*/
+/*FUNCTION SetStructureFieldi(mxArray* dataref,const char* fieldname,char* string) {{{*/
+void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,char* string){
+
+	mxArray* field = NULL;
+
+	/*Convert field*/
+	WriteData(&field,string);
+
+	/*Assign to structure*/
+	mxSetField(dataref,i,fieldname,field);
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h	(revision 14713)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h	(revision 14714)
@@ -69,4 +69,5 @@
 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field);
 void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field);
+void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,char* string);
 int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void ));
 
