Index: /issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.cpp
===================================================================
--- /issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.cpp	(revision 3900)
+++ /issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.cpp	(revision 3900)
@@ -0,0 +1,42 @@
+/*!\file ComputePressurex
+ * \brief: compute pressure according to each element
+ */
+
+#include "./ComputePressurex.h"
+
+#include "../shared/shared.h"
+#include "../include/include.h"
+#include "../toolkits/toolkits.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+
+void	ComputePressurex( Vec* pp_g,DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads, DataSet* materials,Parameters* parameters,
+			int analysis_type,int sub_analysis_type){
+
+	int numberofnodes;
+
+	/*output: */
+	Vec p_g=NULL;
+
+	/*Recover numberofnodes: */
+	parameters->FindParam(&numberofnodes,NumberOfNodesEnum);
+
+	/*Allocate p_g on numberofnodes (only 1 dof): */
+	p_g=NewVec(numberofnodes);
+
+	/*Get elements configured: */
+	elements->Configure(elements,loads, nodes,vertices, materials,parameters);
+	nodes->Configure(elements,loads, nodes,vertices, materials,parameters);
+	loads->Configure(elements,loads,nodes,vertices,materials,parameters);
+	parameters->Configure(elements,loads,nodes,vertices,materials,parameters);
+
+	/*Call on dataset driver: */
+	elements->ComputePressure(p_g,analysis_type,sub_analysis_type);
+
+	/*Assemble vector: */
+	VecAssemblyBegin(p_g);
+	VecAssemblyEnd(p_g);
+
+	/*Assign output pointers: */
+	*pp_g=p_g;
+	
+}
Index: /issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.h
===================================================================
--- /issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.h	(revision 3900)
+++ /issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.h	(revision 3900)
@@ -0,0 +1,16 @@
+/*!\file:  ComputePressurex.h
+ * \brief header file pressure computation
+ */ 
+
+#ifndef _COMPUTEPRESSUREX_H
+#define _COMPUTEPRESSUREX_H
+
+#include "../DataSet/DataSet.h"
+#include "../objects/objects.h"
+
+/* local prototypes: */
+void	ComputePressurex( Vec* pp_g,DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads, DataSet* materials,  Parameters* parameters,
+			int analysis_type,int sub_analysis_type);
+
+#endif  /* _COMPUTEPRESSUREX_H */
+
Index: /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.cpp
===================================================================
--- /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.cpp	(revision 3900)
+++ /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.cpp	(revision 3900)
@@ -0,0 +1,78 @@
+/*! \file  ContourToMeshx.c
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+
+#include "./ContourToMeshx.h"
+
+int ContourToMeshx( Vec* pin_nod,Vec* pin_elem, double* index, double* x, double* y,Contour** contours,int numcontours,char* interptype,int nel,int nods, int edgevalue) {
+
+	int noerr=1;
+	int i;
+	int m,n;
+
+	/*Contour:*/
+	double*  in_nod_serial;
+	double   value;
+
+	/*threading: */
+	ContourToMeshxThreadStruct gate;
+	int num=1;
+	#ifdef _MULTITHREADING_
+	num=_NUMTHREADS_;
+	#endif
+
+
+	/*output: */
+	Vec in_nod=NULL;
+	Vec in_elem=NULL;
+
+	in_nod=NewVec(nods);
+	in_elem=NewVec(nel);
+
+	/*initialize thread parameters: */
+	gate.numcontours=numcontours;
+	gate.contours=contours;
+	gate.nods=nods;
+	gate.edgevalue=edgevalue;
+	gate.in_nod=in_nod;
+	gate.x=x;
+	gate.y=y;
+
+	/*launch the thread manager with ContourToMeshxt as a core: */
+	LaunchThread(ContourToMeshxt,(void*)&gate,num);
+
+	/*Assemble in_nod: */
+	VecAssemblyBegin(in_nod);
+	VecAssemblyEnd(in_nod);
+
+	/*Get in_nod serialised for next operation: */
+	VecToMPISerial(&in_nod_serial,in_nod);
+
+	/*Take care of the case where an element interpolation has been requested: */
+	if ((strcmp(interptype,"element")==0) || (strcmp(interptype,"element and node")==0)){
+		for (n=0;n<nel;n++){
+			if ( (in_nod_serial[ (int)*(index+3*n+0) -1] == 1) && (in_nod_serial[ (int)*(index+3*n+1) -1] == 1) && (in_nod_serial[ (int)*(index+3*n+2) -1] == 1) ){
+				value=1; VecSetValues(in_elem,1,&n,&value,INSERT_VALUES);
+			}
+		}
+	}
+
+	/*Assemble vectors: */
+	VecAssemblyBegin(in_elem);
+	VecAssemblyEnd(in_elem);
+
+	/*Assign output pointers: */
+	*pin_nod=in_nod;
+	*pin_elem=in_elem;
+
+	/*Free ressources:*/
+	xfree((void**)&in_nod_serial);
+
+	return noerr;
+}
Index: /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h
===================================================================
--- /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h	(revision 3900)
+++ /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h	(revision 3900)
@@ -0,0 +1,33 @@
+/*
+	ContourToMeshx.h
+*/
+
+
+#ifndef _CONTOURTOMESHX_H
+#define _CONTOURTOMESHX_H
+
+#include "../shared/shared.h"
+#include "../objects/objects.h"
+
+/*threading: */
+typedef struct{
+
+	int numcontours;
+	Contour** contours;
+	int nods;
+	int edgevalue;
+	Vec in_nod;
+	double* x;
+	double* y;
+
+} ContourToMeshxThreadStruct;
+
+
+/* local prototypes: */
+int ContourToMeshx( Vec* pin_nods,Vec* pin_elem, double* index, double* x, double* y,Contour** contours,int numcontours,char* interptype,int nel,int nods, int edgevalue);
+
+void* ContourToMeshxt(void* vContourToMeshxThreadStruct);
+
+
+#endif /* _CONTOURTOMESHX_H */
+
Index: /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshxt.cpp
===================================================================
--- /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshxt.cpp	(revision 3900)
+++ /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshxt.cpp	(revision 3900)
@@ -0,0 +1,71 @@
+/*!\file:  ContourToMeshxt.cpp
+ * \brief  "thread" core code for interpolating values from a structured grid.
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./ContourToMeshx.h"
+
+void* ContourToMeshxt(void* vpthread_handle){
+	
+	int noerr=1;
+
+	/*gate variables :*/
+	ContourToMeshxThreadStruct* gate=NULL;
+	pthread_handle* handle=NULL;
+	int     my_thread;
+	int     num_threads;
+	int     i0;
+	int     i1;
+
+	int i;
+
+	/*Contour:*/
+	Contour* contouri=NULL;
+	int      numgrids;
+	double*  xc=NULL;
+	double*  yc=NULL;
+
+
+	/*parameters: */
+	int numcontours;
+	Contour** contours=NULL;
+	int nods;
+	int edgevalue;
+	double* x=NULL;
+	double* y=NULL;
+	Vec in_nod=NULL;
+
+
+	/*recover handle and gate: */
+	handle=(pthread_handle*)vpthread_handle;
+	gate=(ContourToMeshxThreadStruct*)handle->gate;
+	my_thread=handle->id;
+	num_threads=handle->num;
+
+	/*recover parameters :*/
+	numcontours=gate->numcontours;
+	contours=gate->contours;
+	nods=gate->nods;
+	edgevalue=gate->edgevalue;
+	in_nod=gate->in_nod;
+	x=gate->x;
+	y=gate->y;
+
+	/*distribute indices across threads :*/
+	PartitionRange(&i0,&i1,nods,num_threads,my_thread);
+
+	/*Loop through all contours: */
+	for (i=0;i<numcontours;i++){
+		contouri=*(contours+i);
+		numgrids=contouri->nods;
+		xc=contouri->x;
+		yc=contouri->y;
+		IsInPoly(in_nod,xc,yc,numgrids,x,y,i0,i1,edgevalue);
+	}
+
+}
Index: /issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp
===================================================================
--- /issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp	(revision 3900)
+++ /issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp	(revision 3900)
@@ -0,0 +1,45 @@
+/*!\file CostFunctionx
+ * \brief: compute misfit between observations and model
+ */
+
+#include "./CostFunctionx.h"
+
+#include "../shared/shared.h"
+#include "../include/include.h"
+#include "../toolkits/toolkits.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../SurfaceAreax/SurfaceAreax.h"
+
+void CostFunctionx( double* pJ, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials,Parameters* parameters,
+			int analysis_type,int sub_analysis_type){
+
+	/*Intermediary*/
+	double fit;
+	double S;
+
+	/*output: */
+	double J;
+	double J_sum;
+	
+	/*First, get elements and loads configured: */
+	elements->Configure(elements,loads, nodes,vertices, materials,parameters);
+	nodes->Configure(elements,loads, nodes,vertices, materials,parameters);
+	parameters->Configure(elements,loads, nodes,vertices, materials,parameters);
+
+	/*Compute surface area: */
+	SurfaceAreax(&S,elements,nodes,vertices, loads,materials,parameters,analysis_type,sub_analysis_type);
+
+	/*add surface area to elements :*/
+	elements->UpdateInputsFromVector(&S,SurfaceAreaEnum,ConstantEnum);
+	
+	/*Compute gradients: */
+	elements->CostFunction(&J,analysis_type,sub_analysis_type);
+
+	/*Sum all J from all cpus of the cluster:*/
+	MPI_Reduce (&J,&J_sum,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD );
+	MPI_Bcast(&J_sum,1,MPI_DOUBLE,0,MPI_COMM_WORLD); 
+	J=J_sum;
+
+	/*Assign output pointers: */
+	*pJ=J;
+}
Index: /issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.h
===================================================================
--- /issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.h	(revision 3900)
+++ /issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.h	(revision 3900)
@@ -0,0 +1,16 @@
+/*!\file:  CostFunctionx.h
+ * \brief header file for inverse methods misfit computation
+ */ 
+
+#ifndef _COSTFUNCTIONX_H
+#define _COSTFUNCTIONX_H
+
+#include "../DataSet/DataSet.h"
+#include "../objects/objects.h"
+
+/* local prototypes: */
+void CostFunctionx( double* pJ, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters, 
+			int analysis_type,int sub_analysis_type);
+
+#endif  /* _MISFITX_H */
+
Index: /issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.cpp
===================================================================
--- /issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.cpp	(revision 3900)
+++ /issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.cpp	(revision 3900)
@@ -0,0 +1,23 @@
+/*!\file DepthAverageInputx
+ * \brief: average field throfieldh thickness
+ */
+
+#include "./DepthAverageInputx.h"
+
+#include "../shared/shared.h"
+#include "../include/include.h"
+#include "../toolkits/toolkits.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+
+void DepthAverageInputx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,int enum_type){
+	
+	/*First, get elements*/
+	elements->Configure(elements,loads, nodes,vertices, materials,parameters);
+
+	/*First depth-average inputs at base of the glacier*/
+	elements->DepthAverageInputAtBase(enum_type);
+
+	/*Then extrude vertically the new inputs*/
+	elements->InputExtrude(enum_type);
+
+}
Index: /issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.h
===================================================================
--- /issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.h	(revision 3900)
+++ /issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.h	(revision 3900)
@@ -0,0 +1,14 @@
+/*!\file:  DepthAverageInputx.h
+ * \brief header file for averaging a field throfieldh thickness
+ */ 
+
+#ifndef _DEPTHAVERAGEINPUTX_H
+#define _DEPTHAVERAGEINPUTX_H
+
+#include "../DataSet/DataSet.h"
+
+/* local prototypes: */
+void DepthAverageInputx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,int enum_type);
+
+#endif  /* _DEPTHAVERAGEINPUTX_H */
+
