Index: /issm/trunk/src/mex/CostFunction/CostFunction.cpp
===================================================================
--- /issm/trunk/src/mex/CostFunction/CostFunction.cpp	(revision 3170)
+++ /issm/trunk/src/mex/CostFunction/CostFunction.cpp	(revision 3170)
@@ -0,0 +1,67 @@
+/*\file CostFunction.c
+ *\brief: compute misfit between modeled velocity and observed velocity
+ */
+
+#include "./CostFunction.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*diverse: */
+	int   noerr=1;
+
+	/*input datasets: */
+	DataSet* elements=NULL;
+	DataSet* nodes=NULL;
+	DataSet* loads=NULL;
+	DataSet* materials=NULL;
+	DataSet* parameters=NULL;
+	ParameterInputs* inputs=NULL;
+	int               analysis_type;
+	int               sub_analysis_type;
+
+	/* output datasets: */
+	double J;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&CostFunctionUsage);
+
+	/*Input datasets: */
+	FetchData(&elements,ELEMENTS);
+	FetchData(&nodes,NODES);
+	FetchData(&loads,LOADS);
+	FetchData(&materials,MATERIALS);
+	FetchParams(&parameters,PARAMETERS);
+	FetchData(&analysis_type,ANALYSIS);
+	FetchData(&sub_analysis_type,SUBANALYSIS);
+
+	/*Fetch inputs: */
+	inputs=new ParameterInputs;
+	inputs->Init(INPUTS);
+
+	/*!Call core code: */
+	CostFunctionx(&J, elements,nodes,loads,materials,parameters,inputs,analysis_type,sub_analysis_type);
+
+	/*write output : */
+	WriteData(MISFIT,J);
+
+	/*Free ressources: */
+	delete elements;
+	delete nodes;
+	delete loads;
+	delete materials;
+	delete parameters;
+	delete inputs;
+
+	/*end module: */
+	MODULEEND();
+}
+
+void CostFunctionUsage(void)
+{
+	_printf_("\n");
+	_printf_("   usage: [J] = %s(elements, nodes,loads, materials, parameters, inputs);\n",__FUNCT__);
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/CostFunction/CostFunction.h
===================================================================
--- /issm/trunk/src/mex/CostFunction/CostFunction.h	(revision 3170)
+++ /issm/trunk/src/mex/CostFunction/CostFunction.h	(revision 3170)
@@ -0,0 +1,41 @@
+
+/*
+	CostFunction.h
+*/
+
+
+#ifndef _COSTFUNCTION_H
+#define _COSTFUNCTION_H
+
+/* local prototypes: */
+void CostFunctionUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "CostFunction"
+
+/* serial input macros: */
+#define ELEMENTS (mxArray*)prhs[0]
+#define NODES (mxArray*)prhs[1]
+#define LOADS (mxArray*)prhs[2]
+#define MATERIALS (mxArray*)prhs[3]
+#define PARAMETERS (mxArray*)prhs[4]
+#define INPUTS (mxArray*)prhs[5]
+#define ANALYSIS (mxArray*)prhs[6]
+#define SUBANALYSIS (mxArray*)prhs[7]
+
+/* serial output macros: */
+#define MISFIT (mxArray**)&plhs[0]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS  8
+
+
+#endif  /* _MISFIT_H */
+
+
+
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 3169)
+++ /issm/trunk/src/mex/Makefile.am	(revision 3170)
@@ -13,4 +13,5 @@
 				ContourToNodes \
 				ControlConstrain \
+				CostFunction \
 				Dof\
 				Du\
@@ -99,5 +100,4 @@
 			  ContourToNodes/ContourToNodes.h
 
-
 ControlOptimization_SOURCES = ControlOptimization/ControlOptimization.cpp\
 			  ControlOptimization/ControlOptimization.h
@@ -106,4 +106,7 @@
 			  ControlConstrain/ControlConstrain.h
 
+CostFunction_SOURCES =  CostFunction/CostFunction.cpp \
+						CostFunction/CostFunction.h
+
 Dof_SOURCES = Dof/Dof.cpp\
 			  Dof/Dof.h
Index: /issm/trunk/src/mex/Misfit/Misfit.cpp
===================================================================
--- /issm/trunk/src/mex/Misfit/Misfit.cpp	(revision 3169)
+++ /issm/trunk/src/mex/Misfit/Misfit.cpp	(revision 3170)
@@ -19,5 +19,4 @@
 	int               analysis_type;
 	int               sub_analysis_type;
-	int               real=0; //we are computing a misfit which can be dampened...
 
 	/* output datasets: */
@@ -44,5 +43,5 @@
 
 	/*!Call core code: */
-	Misfitx(&J, elements,nodes,loads,materials,parameters,inputs,analysis_type,sub_analysis_type,real);
+	Misfitx(&J, elements,nodes,loads,materials,parameters,inputs,analysis_type,sub_analysis_type);
 
 	/*write output : */
