Index: /issm/trunk/src/c/Container/Constraints.cpp
===================================================================
--- /issm/trunk/src/c/Container/Constraints.cpp	(revision 12329)
+++ /issm/trunk/src/c/Container/Constraints.cpp	(revision 12330)
@@ -48,10 +48,11 @@
 
 	/*figure out total number of constraints combining all the cpus (no clones here)*/
-	#ifdef _PARALLEL_
-	MPI_Reduce(&localconstraints,&numberofconstraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
-	MPI_Bcast(&numberofconstraints,1,MPI_INT,0,MPI_COMM_WORLD);
+	#ifdef _HAVE_MPI_
+		MPI_Reduce(&localconstraints,&numberofconstraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
+		MPI_Bcast(&numberofconstraints,1,MPI_INT,0,MPI_COMM_WORLD);
 	#else
-	numberofconstraints=localconstraints;
+		numberofconstraints=localconstraints;
 	#endif
+	
 
 	return numberofconstraints;
Index: /issm/trunk/src/c/Container/DataSet.cpp
===================================================================
--- /issm/trunk/src/c/Container/DataSet.cpp	(revision 12329)
+++ /issm/trunk/src/c/Container/DataSet.cpp	(revision 12330)
@@ -11,4 +11,5 @@
 #endif
 
+#include <cstring>
 #include <vector>
 #include <functional>
@@ -84,329 +85,4 @@
 /*}}}*/
 
-/*I/O*/
-#ifdef _SERIAL_
-/*FUNCTION DataSet::Marshall{{{1*/
-char* DataSet::Marshall(){
-
-	vector<Object*>::iterator object;
-	int                       object_size;
-	int                       marshalled_dataset_size=0;
-	char*                     marshalled_dataset=NULL;
-	char*                     old_marshalled_dataset=NULL;
-
-	/*First get size of marshalled dataset: */
-	object_size=(int)objects.size();
-
-	marshalled_dataset_size=MarshallSize();
-	
-	/*Allocate marshalled dataset: */
-	marshalled_dataset=(char*)xmalloc(marshalled_dataset_size*sizeof(char)); 
-
-	/*Keep track of old_marshalled_dataset: */
-	old_marshalled_dataset=marshalled_dataset;
-
-	/*Store internals of dataset first: */
-	memcpy(marshalled_dataset,&object_size,sizeof(int)); marshalled_dataset+=sizeof(int);
-	memcpy(marshalled_dataset,&sorted,sizeof(int)); marshalled_dataset+=sizeof(int);
-	if(sorted){
-		if(object_size)memcpy(marshalled_dataset,sorted_ids,object_size*sizeof(int)); marshalled_dataset+=object_size*sizeof(int);
-		if(object_size)memcpy(marshalled_dataset,id_offsets,object_size*sizeof(int)); marshalled_dataset+=object_size*sizeof(int);
-	}
-
-	for ( object=objects.begin() ; object < objects.end(); object++ ){
-		(*object)->Marshall(&marshalled_dataset);
-	}
-
-	/* Ok, marshalled_dataset now points to the end of the original marshalled_dataset pointer 
-	 * before  we started the loop on objects. Get object to point right again: */
-	marshalled_dataset-=marshalled_dataset_size;
-
-	/*We should be back to old_marshalled_dataset: check and abort if that's not the case, 
-	 * because this is a nasty error: */
-	if (marshalled_dataset!=old_marshalled_dataset){
-		_error_("final marshalled dataset \"%s\" is different from initial one!",EnumToStringx(enum_type)); 
-		abort();
-	}
-
-	/*Return: */
-	return marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DataSet::MarshallSize{{{1*/
-int DataSet::MarshallSize(){
-
-	vector<Object*>::iterator object;
-	int                      marshalled_dataset_size=0;
-
-
-	for ( object=objects.begin() ; object < objects.end(); object++ ){
-		marshalled_dataset_size+= (*object)->MarshallSize();
-	}
-
-	marshalled_dataset_size+=sizeof(int); //objects size
-	marshalled_dataset_size+=sizeof(int); //sorted size
-	if(sorted){
-		marshalled_dataset_size+=(int)objects.size()*sizeof(int); //sorted ids
-		marshalled_dataset_size+=(int)objects.size()*sizeof(int); //id offsets
-	}
-
-	return marshalled_dataset_size;
-}
-/*}}}*/
-/*FUNCTION DataSet::Demarshall{{{1*/
-DataSet* DataSetDemarshall(char* marshalled_dataset){
-
-	return DataSetDemarshallRaw(&marshalled_dataset);
-
-}
-/*}}}*/
-/*FUNCTION DataSet::DemarshallRaw{{{1*/
-DataSet* DataSetDemarshallRaw(char** pmarshalled_dataset){
-
-	int i;
-
-	DataSet* dataset=NULL;
-	int      numobjects=0;
-	int      enum_type;
-	Object*  object=NULL;
-	int      sorted;
-	int*     sorted_ids=NULL;
-	int*     id_offsets=NULL;
-	char*    marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset pointer: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*initialize dataset: */
-	dataset=new DataSet();
-
-	/*Get internals first: */
-	memcpy(&numobjects,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-	memcpy(&sorted,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-	if(sorted){
-		if(numobjects){
-			sorted_ids=(int*)xmalloc(numobjects*sizeof(int));
-			id_offsets=(int*)xmalloc(numobjects*sizeof(int));
-			memcpy(sorted_ids,marshalled_dataset,numobjects*sizeof(int)); marshalled_dataset+=numobjects*sizeof(int);
-			memcpy(id_offsets,marshalled_dataset,numobjects*sizeof(int)); marshalled_dataset+=numobjects*sizeof(int);
-		}
-		dataset->SetSorting(sorted_ids,id_offsets);
-	}
-
-	for(i=0;i<numobjects;i++){
-
-		/*get enum type of object: */
-		memcpy(&enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-
-		switch(enum_type){
-			case NodeEnum:{
-				Node* node=NULL;
-				node=new Node();
-				node->Demarshall(&marshalled_dataset);
-				dataset->AddObject(node);}
-				break;
-			case VertexEnum:{
-				Vertex* vertex=NULL;
-				vertex=new Vertex();
-				vertex->Demarshall(&marshalled_dataset);
-				dataset->AddObject(vertex);}
-				break;
-			case DoubleParamEnum:{
-				DoubleParam* doubleparam=NULL;
-				doubleparam=new DoubleParam();
-				doubleparam->Demarshall(&marshalled_dataset);
-				dataset->AddObject(doubleparam);}
-				break;
-			case TriaEnum:{
-				Tria* tria=NULL;
-				tria=new Tria();
-				tria->Demarshall(&marshalled_dataset);
-				dataset->AddObject(tria);}
-				break;
-			case TriaP1InputEnum:{
-				TriaP1Input* triavertexinput=NULL;
-				triavertexinput=new TriaP1Input();
-				triavertexinput->Demarshall(&marshalled_dataset);
-				dataset->AddObject(triavertexinput);}
-				break;
-			#ifdef _HAVE_3D_
-			case PentaP1InputEnum:{
-				PentaP1Input* pentavertexinput=NULL;
-				pentavertexinput=new PentaP1Input();
-				pentavertexinput->Demarshall(&marshalled_dataset);
-				dataset->AddObject(pentavertexinput);}
-				break;
-			#endif
-			case TransientInputEnum:{
-				TransientInput* transientinput=NULL;
-				transientinput=new TransientInput();
-				transientinput->Demarshall(&marshalled_dataset);
-				dataset->AddObject(transientinput);}
-				break;
-			#ifdef _HAVE_CONTROL_
-			case ControlInputEnum:{
-			   ControlInput* controlinputinput=NULL;
-				controlinputinput=new ControlInput();
-				controlinputinput->Demarshall(&marshalled_dataset);
-				dataset->AddObject(controlinputinput);}
-				break;
-			#endif
-			case DatasetInputEnum:{
-				DatasetInput* datasetinputinput=NULL;
-				datasetinputinput=new DatasetInput();
-				datasetinputinput->Demarshall(&marshalled_dataset);
-				dataset->AddObject(datasetinputinput);}
-				break;
-			case TriaP1ElementResultEnum:{
-				TriaP1ElementResult* triavertexelementresult=NULL;
-				triavertexelementresult=new TriaP1ElementResult();
-				triavertexelementresult->Demarshall(&marshalled_dataset);
-				dataset->AddObject(triavertexelementresult);}
-				break;
-			 #ifdef _HAVE_3D_
-			case PentaP1ElementResultEnum:{
-				PentaP1ElementResult* pentavertexelementresult=NULL;
-				pentavertexelementresult=new PentaP1ElementResult();
-				pentavertexelementresult->Demarshall(&marshalled_dataset);
-				dataset->AddObject(pentavertexelementresult);}
-				break;
-			case PentaEnum:{
-				Penta* penta=NULL;
-				penta=new Penta();
-				penta->Demarshall(&marshalled_dataset);
-				dataset->AddObject(penta);}
-				break;
-			#endif
-			case MaticeEnum:{
-				Matice* matice=NULL;
-				matice=new Matice();
-				matice->Demarshall(&marshalled_dataset);
-				dataset->AddObject(matice);}
-				break;
-			case MatparEnum:{
-				Matpar* matpar=NULL;
-				matpar=new Matpar();
-				matpar->Demarshall(&marshalled_dataset);
-				dataset->AddObject(matpar);}
-				break;
-			case SpcStaticEnum:{
-				SpcStatic* spcstatic=NULL;
-				spcstatic=new SpcStatic();
-				spcstatic->Demarshall(&marshalled_dataset);
-				dataset->AddObject(spcstatic);}
-				break;
-			case SpcDynamicEnum:{
-				SpcDynamic* spcdynamic=NULL;
-				spcdynamic=new SpcDynamic();
-				spcdynamic->Demarshall(&marshalled_dataset);
-				dataset->AddObject(spcdynamic);}
-				break;
-			case SpcTransientEnum:{
-				SpcTransient* spctransient=NULL;
-				spctransient=new SpcTransient();
-				spctransient->Demarshall(&marshalled_dataset);
-				dataset->AddObject(spctransient);}
-				break;
-			case PengridEnum:{
-				Pengrid* pengrid=NULL;
-				pengrid=new Pengrid();
-				pengrid->Demarshall(&marshalled_dataset);
-				dataset->AddObject(pengrid);}
-				break;
-			case PenpairEnum:{
-				Penpair* penpair=NULL;
-				penpair=new Penpair();
-				penpair->Demarshall(&marshalled_dataset);
-				dataset->AddObject(penpair);}
-				break;
-			case IcefrontEnum:{
-				Icefront* icefront=NULL;
-				icefront=new Icefront();
-				icefront->Demarshall(&marshalled_dataset);
-				dataset->AddObject(icefront);}
-				break;
-			case NumericalfluxEnum:{
-				Numericalflux* numericalflux=NULL;
-				numericalflux=new Numericalflux();
-				numericalflux->Demarshall(&marshalled_dataset);
-				dataset->AddObject(numericalflux);}
-				break;
-			#ifdef _HAVE_RIFTS_
-			case RiftfrontEnum:{
-				Riftfront* riftfront=NULL;
-				riftfront=new Riftfront();
-				riftfront->Demarshall(&marshalled_dataset);
-				dataset->AddObject(riftfront);}
-				break;
-			#endif
-			case DoubleInputEnum:{
-				DoubleInput* doubleinput=NULL;
-				doubleinput=new DoubleInput();
-				doubleinput->Demarshall(&marshalled_dataset);
-				dataset->AddObject(doubleinput);}
-				break;
-			case IntInputEnum:{
-				IntInput* intinput=NULL;
-				intinput=new IntInput();
-				intinput->Demarshall(&marshalled_dataset);
-				dataset->AddObject(intinput);}
-				break;
-			case BoolInputEnum:{
-				BoolInput* boolinput=NULL;
-				boolinput=new BoolInput();
-				boolinput->Demarshall(&marshalled_dataset);
-				dataset->AddObject(boolinput);}
-				break;
-			case IntParamEnum:{
-				IntParam* intparam=NULL;
-				intparam=new IntParam();
-				intparam->Demarshall(&marshalled_dataset);
-				dataset->AddObject(intparam);}
-				break;
-			case BoolParamEnum:{
-				BoolParam* boolparam=NULL;
-				boolparam=new BoolParam();
-				boolparam->Demarshall(&marshalled_dataset);
-				dataset->AddObject(boolparam);}
-				break;
-			case StringParamEnum:{
-				StringParam* stringparam=NULL;
-				stringparam=new StringParam();
-				stringparam->Demarshall(&marshalled_dataset);
-				dataset->AddObject(stringparam);}
-				break;
-			case DoubleVecExternalResultEnum:{
-				DoubleVecExternalResult* doublevecexternalresult=NULL;
-				doublevecexternalresult=new DoubleVecExternalResult();
-				doublevecexternalresult->Demarshall(&marshalled_dataset);
-				dataset->AddObject(doublevecexternalresult);}
-				break;
-			case DoubleExternalResultEnum:{
-				DoubleExternalResult* doubleexternalresult=NULL;
-				doubleexternalresult=new DoubleExternalResult();
-				doubleexternalresult->Demarshall(&marshalled_dataset);
-				dataset->AddObject(doubleexternalresult);}
-				break;
-			#ifdef _HAVE_GROUNDINGLINE_
-			case BoolElementResultEnum:{
-				BoolElementResult* boolelementresult=NULL;
-				boolelementresult=new BoolElementResult();
-				boolelementresult->Demarshall(&marshalled_dataset);
-				dataset->AddObject(boolelementresult);}
-				break;
-			#endif
-			default:
-				_error_("could not recognize enum type: %s",EnumToStringx(enum_type));
-		}
-	}
-
-	/*Assign output pointers:*/
-	*pmarshalled_dataset=marshalled_dataset;
-	
-	return dataset;
-}
-/*}}}*/
-#endif
-
 /*Specific methods*/
 /*FUNCTION DataSet::AddObject{{{1*/
Index: /issm/trunk/src/c/Container/DataSet.h
===================================================================
--- /issm/trunk/src/c/Container/DataSet.h	(revision 12329)
+++ /issm/trunk/src/c/Container/DataSet.h	(revision 12330)
@@ -49,8 +49,4 @@
 		void  Echo();
 		void  DeepEcho();
-		#ifdef _SERIAL_
-		char* Marshall();
-		int   MarshallSize();
-		#endif
 		int   AddObject(Object* object);
 		int   DeleteObject(int id);
@@ -69,11 +65,3 @@
 };
 
-/*This routine cannot be object oriented, but need for demarshalling: */
-#ifdef _SERIAL_
-DataSet* DataSetDemarshall(char* marshalled_dataset);
-DataSet* DataSetDemarshallRaw(char** pmarshalled_dataset);
 #endif
-	
-
-
-#endif
Index: /issm/trunk/src/c/Container/Elements.cpp
===================================================================
--- /issm/trunk/src/c/Container/Elements.cpp	(revision 12329)
+++ /issm/trunk/src/c/Container/Elements.cpp	(revision 12330)
@@ -124,6 +124,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Synchronize across cluster, so as to not end up with different sizes for each patch on each cpu: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&numvertices,&max_numvertices,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&max_numvertices,1,MPI_INT,0,MPI_COMM_WORLD);
@@ -193,7 +193,11 @@
 
 		/*Get rank of first cpu that has results*/
+		#ifdef _HAVE_MPI_
 		if(this->Size()) rank=my_rank;
 		else rank=num_procs;
 		MPI_Allreduce (&rank,&minrank,1,MPI_INT,MPI_MIN,MPI_COMM_WORLD);
+		#else
+		minrank=my_rank;
+		#endif
 
 		/*see what the first element of this partition has in stock (this is common to all partitions)*/
@@ -203,8 +207,11 @@
 			element->ListResultsInfo(&resultsenums,&resultssizes,&resultstimes,&resultssteps,&numberofresults);
 		}
+		#ifdef _HAVE_MPI_
 		MPI_Bcast(&numberofresults,1,MPI_DOUBLE,minrank,MPI_COMM_WORLD);
+		#endif
 
 		/*Get out if there is no results. Otherwise broadcast info*/
 		if(!numberofresults) return;
+		#ifdef _HAVE_MPI_
 		if(my_rank!=minrank){
 			resultsenums=(int*)xmalloc(numberofresults*sizeof(int));
@@ -217,4 +224,5 @@
 		MPI_Bcast(resultstimes,numberofresults,MPI_DOUBLE,minrank,MPI_COMM_WORLD);
 		MPI_Bcast(resultssteps,numberofresults,MPI_INT,minrank,MPI_COMM_WORLD);
+		#endif
 
 		/*Loop over all results and get nodal vector*/
@@ -250,7 +258,5 @@
 
 		/*Gather onto master cpu 0, if needed: */
-#ifdef _PARALLEL_
 		if(io_gather)patch->Gather();
-#endif
 
 		/*create result object and add to results dataset:*/
@@ -276,9 +282,9 @@
 	int numberofelements;
 
-	#ifdef _PARALLEL_
 	local_nelem=this->Size();
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( (void*)&local_nelem,(void*)&numberofelements,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
 	#else
-	numberofelements=this->Size();
+	numberofelements=local_nelem;
 	#endif
 
Index: /issm/trunk/src/c/Container/Loads.cpp
===================================================================
--- /issm/trunk/src/c/Container/Loads.cpp	(revision 12329)
+++ /issm/trunk/src/c/Container/Loads.cpp	(revision 12330)
@@ -63,5 +63,5 @@
 
 	/*figure out total number of loads combining all the cpus (no clones here)*/
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce(&localloads,&numberofloads,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&numberofloads,1,MPI_INT,0,MPI_COMM_WORLD);
@@ -69,4 +69,5 @@
 	numberofloads=localloads;
 	#endif
+
 
 	return numberofloads;
Index: /issm/trunk/src/c/Container/Nodes.cpp
===================================================================
--- /issm/trunk/src/c/Container/Nodes.cpp	(revision 12329)
+++ /issm/trunk/src/c/Container/Nodes.cpp	(revision 12330)
@@ -83,8 +83,12 @@
 	 * 0. This means the dofs between all the cpus are not unique. We now offset the dofs of eache
 	 * cpus by the total last dofs of the previus cpu, starting from 0.
-	 * First: bet number of dofs for each cpu*/
+	 * First: get number of dofs for each cpu*/
 	alldofcount=(int*)xmalloc(num_procs*sizeof(int));
+	#ifdef _HAVE_MPI_
 	MPI_Gather(&dofcount,1,MPI_INT,alldofcount,1,MPI_INT,0,MPI_COMM_WORLD);
 	MPI_Bcast(alldofcount,num_procs,MPI_INT,0,MPI_COMM_WORLD);
+	#else
+	alldofcount[0]=dofcount;
+	#endif
 
 	/* Every cpu should start its own dof count at the end of the dofcount from cpu-1*/
@@ -119,5 +123,10 @@
 		}
 	}
-	MPI_Allreduce ( (void*)truedofs,(void*)alltruedofs,numnodes*maxdofspernode,MPI_INT,MPI_MAX,MPI_COMM_WORLD);
+
+	#ifdef _HAVE_MPI_
+	MPI_Allreduce((void*)truedofs,(void*)alltruedofs,numnodes*maxdofspernode,MPI_INT,MPI_MAX,MPI_COMM_WORLD);
+	#else
+	for(i=0;i<numnodes*maxdofspernode;i++)alltruedofs[i]=truedofs[i];
+	#endif
 
 	/* Now every cpu knows the true dofs of everyone else that is not a clone*/
@@ -145,5 +154,4 @@
 	int  numnodes;
 
-
 	/*Figure out number of nodes for this analysis: */
 	numnodes=this->NumberOfNodes(analysis_type);
@@ -162,5 +170,9 @@
 	 * dealt with by another cpu. We take the minimum because we are going to manage dof assignment in increasing 
 	 * order of cpu rank. This is also why we initialized this array to num_procs.*/
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( (void*)ranks,(void*)minranks,numnodes,MPI_INT,MPI_MIN,MPI_COMM_WORLD);
+	#else
+	for(i=0;i<numnodes;i++)minranks[i]=ranks[i];
+	#endif
 
 	/*Now go through all objects, and use minranks to flag which objects are cloned: */
@@ -204,9 +216,9 @@
 	}
 
-#ifdef _PARALLEL_
 	/*Grab max of all cpus: */
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( (void*)&max,(void*)&allmax,1,MPI_INT,MPI_MAX,MPI_COMM_WORLD);
 	max=allmax;
-#endif
+	#endif
 
 	return max;
@@ -239,5 +251,9 @@
 
 	/*Gather from all cpus: */
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( (void*)&numdofs,(void*)&allnumdofs,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
+	#else
+	allnumdofs=numdofs;
+	#endif
 	return allnumdofs;
 }
@@ -262,5 +278,9 @@
 
 	/*Gather from all cpus: */
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( (void*)&numnodes,(void*)&allnumnodes,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
+	#else
+	allnumnodes=numnodes;
+	#endif
 
 	return allnumnodes;
@@ -288,9 +308,9 @@
 	}
 
-	#ifdef _PARALLEL_
-		MPI_Reduce (&max_sid,&node_max_sid,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
-		MPI_Bcast(&node_max_sid,1,MPI_INT,0,MPI_COMM_WORLD);
-		max_sid=node_max_sid;
-	#endif 
+	#ifdef _HAVE_MPI_
+	MPI_Reduce (&max_sid,&node_max_sid,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
+	MPI_Bcast(&node_max_sid,1,MPI_INT,0,MPI_COMM_WORLD);
+	max_sid=node_max_sid;
+	#endif
 
 	if(max_sid==1){
Index: /issm/trunk/src/c/Container/Observations.cpp
===================================================================
--- /issm/trunk/src/c/Container/Observations.cpp	(revision 12330)
+++ /issm/trunk/src/c/Container/Observations.cpp	(revision 12330)
@@ -0,0 +1,248 @@
+/*
+ * \file Observations.c
+ * \brief: implementation of the Observations class, derived from DataSet class
+ */
+
+/*Headers: {{{*/
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <vector>
+#include <functional>
+#include <algorithm>
+#include <iostream>
+
+#include "./DataSet.h"
+#include "./Observations.h"
+#include "../shared/shared.h"
+#include "../include/include.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+
+using namespace std;
+/*}}}*/
+
+/*Object constructors and destructor*/
+/*FUNCTION Observations::Observations(){{{*/
+Observations::Observations(){
+	this->quadtree = NULL;
+	return;
+}
+/*}}}*/
+/*FUNCTION Observations::Observations(double* observations_list,double* x,double* y,int n,Options* options){{{*/
+Observations::Observations(double* observations_list,double* x,double* y,int n,Options* options){
+
+	/*Intermediaries*/
+	int          i,j,maxdepth,level,counter,index;
+	int          xi,yi;
+	double       xmin,xmax,ymin,ymax;
+	double       offset,minlength,minspacing,mintrimming,maxtrimming;
+	int         *indices     = NULL;
+	Observation *observation = NULL;
+
+	/*Get extrema*/
+	xmin=x[0]; ymin=y[0];
+	xmax=x[0]; ymax=y[0];
+	for(i=1;i<n;i++){
+		xmin=min(xmin,x[i]); ymin=min(ymin,y[i]);
+		xmax=max(xmax,x[i]); ymax=max(ymax,y[i]);
+	}
+	offset=0.05*(xmax-xmin); xmin-=offset; xmax+=offset;
+	offset=0.05*(ymax-ymin); ymin-=offset; ymax+=offset;
+
+	/*Get trimming limits*/
+	options->Get(&mintrimming,"mintrimming",-1.e+21);
+	options->Get(&maxtrimming,"maxtrimming",+1.e+21);
+	options->Get(&minspacing,"minspacing",0.01);
+	if(minspacing<=0) _error_("minspacing must > 0");
+
+	/*Get Minimum box size*/
+	if(options->GetOption("boxlength")){
+		options->Get(&minlength,"boxlength");
+		if(minlength<=0)_error_("boxlength should be a positive number");
+		maxdepth=int(log(max(xmax-xmin,ymax-ymin)/minlength +1)/log(2.0));
+	}
+	else{
+		maxdepth = 30;
+		minlength=max(xmax-xmin,ymax-ymin)/double((1L<<maxdepth)-1);
+	}
+
+	/*Initialize Quadtree*/
+	printf("Generating quadtree with a maximum box size %g (depth=%i)... ",minlength,maxdepth);
+	this->quadtree = new Quadtree(xmin,xmax,ymin,ymax,maxdepth);
+
+	/*Add observations one by one*/
+	counter = 0;
+	for(i=0;i<n;i++){
+
+		/*First check limits*/
+		if(observations_list[i]>maxtrimming) continue;
+		if(observations_list[i]<mintrimming) continue;
+
+		/*First check that this observation is not too close from another one*/
+		this->quadtree->ClosestObs(&index,x[i],y[i]);
+		if(index>=0){
+			observation=(Observation*)this->GetObjectByOffset(index);
+			if(pow(observation->x-x[i],2)+pow(observation->y-y[i],2) < minspacing) continue;
+		}
+
+		this->quadtree->IntergerCoordinates(&xi,&yi,x[i],y[i]);
+		this->quadtree->QuadtreeDepth2(&level,xi,yi);
+		if((int)level <= maxdepth){
+			observation = new Observation(x[i],y[i],xi,yi,counter++,observations_list[i]);
+			this->quadtree->Add(observation);
+			this->AddObject(observation);
+		}
+		else{
+			/*We need to average with the current observations*/
+			this->quadtree->AddAndAverage(x[i],y[i],observations_list[i]);
+		}
+	}
+	printf("done\n");
+	printf("Initial number of observations: %i\n",n);
+	printf("  Final number of observations: %i\n",this->quadtree->NbObs);
+}
+/*}}}*/
+/*FUNCTION Observations::~Observations(){{{*/
+Observations::~Observations(){
+	delete quadtree;
+	return;
+}
+/*}}}*/
+
+/*Methods*/
+/*FUNCTION Observations::ObservationList{{{*/
+void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double radius,int maxdata){
+
+	/*Output and Intermediaries*/
+	bool         stop;
+	int          nobs,tempnobs,i,j,k,n,counter;
+	double       h2,radius2;
+	int         *indices      = NULL;
+	int         *tempindices  = NULL;
+	double      *dists        = NULL;
+	double      *x            = NULL;
+	double      *y            = NULL;
+	double      *obs          = NULL;
+	Observation *observation  = NULL;
+
+	/*Compute radius square*/
+	if(radius==0) radius=this->quadtree->root->length;
+	radius2 = radius*radius;
+
+	/*Find all observations that are in radius*/
+	this->quadtree->RangeSearch(&tempindices,&tempnobs,x_interp,y_interp,radius);
+	if(tempnobs){
+		indices = (int*)xmalloc(tempnobs*sizeof(int));
+		dists   = (double*)xmalloc(tempnobs*sizeof(double));
+	}
+	nobs = 0;
+	for (i=0;i<tempnobs;i++){
+		observation=(Observation*)this->GetObjectByOffset(tempindices[i]);
+		h2 = (observation->x-x_interp)*(observation->x-x_interp) + (observation->y-y_interp)*(observation->y-y_interp);
+
+		if(nobs==maxdata && h2>radius2) continue;
+		if(nobs<=maxdata){
+			indices[nobs]   = tempindices[i];
+			dists[nobs]     = h2;
+			nobs++;
+		}
+		if(nobs==1) continue;
+
+		/*Sort all dists up to now*/
+		n=nobs-1;
+		stop = false;
+		for(k=0;k<n-1;k++){
+			if(h2<dists[k]){
+				counter=1;
+				for(int jj=k;jj<n;jj++){
+					j  = n-counter;
+					dists[j+1]   = dists[j];
+					indices[j+1] = indices[j];
+					counter++;
+				}
+				dists[k]   = h2;
+				indices[k] = tempindices[i];
+				stop = true;
+				break;
+			}
+			if(stop) break;
+		}
+	}  
+	xfree((void**)&dists);
+	xfree((void**)&tempindices);
+
+	if(nobs){
+		/*Allocate vectors*/
+		x   = (double*)xmalloc(nobs*sizeof(double));
+		y   = (double*)xmalloc(nobs*sizeof(double));
+		obs = (double*)xmalloc(nobs*sizeof(double));
+
+		/*Loop over all observations and fill in x, y and obs*/
+		for (i=0;i<nobs;i++){
+			observation=(Observation*)this->GetObjectByOffset(indices[i]);
+			observation->WriteXYObs(&x[i],&y[i],&obs[i]);
+		}
+	}
+
+	/*Assign output pointer*/
+	xfree((void**)&indices);
+	*px=x;
+	*py=y;
+	*pobs=obs;
+	*pnobs=nobs;
+}/*}}}*/
+/*FUNCTION Observations::QuadtreeColoring{{{*/
+void Observations::QuadtreeColoring(double* A,double *x,double *y,int n){
+
+	int xi,yi,level;
+
+	for(int i=0;i<n;i++){
+		this->quadtree->IntergerCoordinates(&xi,&yi,x[i],y[i]);
+		this->quadtree->QuadtreeDepth(&level,xi,yi);
+		A[i]=(double)level;
+	}
+
+}/*}}}*/
+/*FUNCTION Observations::Variomap{{{*/
+void Observations::Variomap(double* gamma,double *x,int n){
+
+	/*Output and Intermediaries*/
+	int          i,j,k;
+	double       distance;
+	Observation *observation1 = NULL;
+	Observation *observation2 = NULL;
+
+	int *counter= (int*)xmalloc(n*sizeof(int));
+	for(j=0;j<n;j++) counter[j] = 0;
+	for(j=0;j<n;j++) gamma[j]   = 0.0;
+
+	for(i=0;i<this->Size();i++){
+		observation1=(Observation*)this->GetObjectByOffset(i);
+
+		for(j=i+1;j<this->Size();j++){
+			observation2=(Observation*)this->GetObjectByOffset(j);
+
+			distance=sqrt(pow(observation1->x - observation2->x,2.) + pow(observation1->y - observation2->y,2.));
+			if(distance>x[n-1]) continue;
+
+			int index = int(distance/(x[1]-x[0]));
+			if(index>n-1) index = n-1;
+			if(index<0)   index = 0;
+
+			gamma[index]   += 1./2.*pow(observation1->value - observation2->value,2.);
+			counter[index] += 1;
+		}
+	}
+
+	/*Normalize semivariogram*/
+	gamma[0]=0;
+	for(k=0;k<n;k++){
+		if(counter[k]) gamma[k] = gamma[k]/double(counter[k]);
+	}
+
+	/*Assign output pointer*/
+	xfree((void**)&counter);
+}/*}}}*/
Index: /issm/trunk/src/c/Container/Observations.h
===================================================================
--- /issm/trunk/src/c/Container/Observations.h	(revision 12330)
+++ /issm/trunk/src/c/Container/Observations.h	(revision 12330)
@@ -0,0 +1,31 @@
+/*!\file: Observations.h
+ * \brief prototypes for Observations.h
+ */ 
+
+#ifndef _CONTAINER_OBSERVATIONS_H_
+#define  _CONTAINER_OBSERVATIONS_H_
+
+class Obsevration;
+class Quadtree;
+class Options;
+
+class Observations: public DataSet{
+
+	private:
+		Quadtree* quadtree;
+
+	public:
+
+		/*constructors, destructors*/
+		Observations();
+		Observations(double* observations_list,double* x,double* y,int n,Options* options);
+		~Observations();
+
+		/*Methods*/
+		void ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double radius,int maxdata);
+		void QuadtreeColoring(double* A,double *x,double *y,int n);
+		void Variomap(double* gamma,double *x,int n);
+
+};
+#endif //ifndef _OBSERVATIONS_H_
+
Index: /issm/trunk/src/c/Container/Options.cpp
===================================================================
--- /issm/trunk/src/c/Container/Options.cpp	(revision 12329)
+++ /issm/trunk/src/c/Container/Options.cpp	(revision 12330)
@@ -13,4 +13,5 @@
 #include <vector>
 #include <algorithm>
+#include <cstring>
 
 #include "./DataSet.h"
@@ -20,7 +21,5 @@
 #include "../shared/shared.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
-#if _SERIAL_
 #include "../io/io.h"
-#endif
 /*}}}*/
 
@@ -31,30 +30,4 @@
 }
 /*}}}*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-/*FUNCTION Options::Options(int istart, int nrhs, const mxArray* prhs[]){{{1*/
-Options::Options(int istart, int nrhs, const mxArray* prhs[]){
-
-	int            i;
-	char          *name    = NULL;
-	Option *option = NULL;
-
-	/*loop over each name and value*/
-	for (i=istart; i<nrhs; i=i+2){
-		if (!mxIsClass(prhs[i],"char")) _error_("Argument %d must be name of option.",i+1);
-
-		FetchData(&name,prhs[i]);
-		if (i+1 == nrhs) _error_("Argument %d must exist and be value of option \"%s\".",i+2,name);
-
-		//_printf_(true,"  Processing option \"%s\" of class \"%s\".\n",name,mxGetClassName(prhs[i+1]));
-		option=(Option*)OptionParse(name,&prhs[i+1]);
-		this->AddOption(option);
-		option=NULL;
-	}
-
-	/*echo the dataset  */
-	//if (this->Size()) for(i=0;i<this->Size();i++) ((Option*)this->GetObjectByOffset(i))->Echo();
-}
-/*}}}*/
-#endif
 /*FUNCTION Options::~Options(){{{1*/
 Options::~Options(){
@@ -93,4 +66,42 @@
 
 	return 1;
+}
+/*}}}*/
+/*FUNCTION Options::Get(int* pvalue, char* name){{{1*/
+void Options::Get(int* pvalue,const char* name){
+
+	vector<Object*>::iterator object;
+	Option* option=NULL;
+
+	/*Get option*/
+	option=GetOption(name);
+
+	/*If the pointer is not NULL, the option has been found*/
+	if(option){
+		option->Get(pvalue);
+	}
+	/*Else, the Option does not exist, no default provided*/
+	else{
+		_error_("option of name \"%s\" not found, and no default value has been provided",name);
+	}
+}
+/*}}}*/
+/*FUNCTION Options::Get(int* pvalue, char* name,int default_value){{{1*/
+void Options::Get(int* pvalue,const char* name,int default_value){
+
+	vector<Object*>::iterator object;
+	Option* option=NULL;
+
+	/*Get option*/
+	option=GetOption(name);
+
+	/*If the pointer is not NULL, the option has been found*/
+	if(option){
+		option->Get(pvalue);
+	}
+	/*Else, the Option does not exist, a default is provided here*/
+	else{
+		*pvalue=default_value;
+	}
 }
 /*}}}*/
Index: /issm/trunk/src/c/Container/Options.h
===================================================================
--- /issm/trunk/src/c/Container/Options.h	(revision 12329)
+++ /issm/trunk/src/c/Container/Options.h	(revision 12330)
@@ -15,7 +15,4 @@
 		/*constructors, destructors*/
 		Options();
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		Options(int istart, int nrhs, const mxArray* prhs[]);
-		#endif
 		~Options();
 
@@ -25,4 +22,6 @@
 		void Get(double*  pvalue,const char* name);
 		void Get(double*  pvalue,const char* name,double default_value);
+		void Get(int*  pvalue,const char* name);
+		void Get(int*  pvalue,const char* name,int default_value);
 		void Get(bool*    pvalue,const char* name);
 		void Get(bool*    pvalue,const char* name,bool default_value);
Index: /issm/trunk/src/c/Container/Parameters.h
===================================================================
--- /issm/trunk/src/c/Container/Parameters.h	(revision 12329)
+++ /issm/trunk/src/c/Container/Parameters.h	(revision 12330)
@@ -5,4 +5,5 @@
 #ifndef _CONTAINER_PARAMETERS_H_
 #define  _CONTAINER_PARAMETERS_H_
+#include <stdio.h>
 
 /*forward declarations */
Index: /issm/trunk/src/c/Container/Results.cpp
===================================================================
--- /issm/trunk/src/c/Container/Results.cpp	(revision 12329)
+++ /issm/trunk/src/c/Container/Results.cpp	(revision 12330)
@@ -65,88 +65,4 @@
 /*}}}*/
 /*FUNCTION Results::Write{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void Results::Write(mxArray** pdataref){
-
-	int i,j;
-	int count;
-
-	/*output: */
-	mxArray* dataref=NULL;
-	mxArray* processeddataref=NULL;
-	mwSize nfields;
-	mwSize maxfields;
-	mwSize nsteps;
-	mwSize step;
-	const char **fnames      = NULL;
-	int         *enums       = NULL;
-	int          baseenum;
-	mwSize       onebyone[2] = {1,1};
-	mwSize       ndim        = 2;
-
-	/*How many time steps do we have? : */
-	nsteps=0;
-	for(i=0;i<this->Size();i++){
-		ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
-		step=result->GetStep();
-		if(step>nsteps)nsteps=step;
-	}
-	onebyone[0]=nsteps;
-
-	/*How many field names do we have. First, figure out how many result types we have: */
-	maxfields=(mwSize)this->Size();
-	enums=(int*)xmalloc(maxfields*sizeof(int));
-	for(i=0;i<maxfields;i++){
-		ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
-		enums[i]=result->InstanceEnum();
-	}
-	/*Now, make result types unique: */
-	for(i=0;i<maxfields;i++){
-		if(enums[i]>=0){//if <0, it means this enum was found to replicate another one previously
-			baseenum=enums[i]; 		
-			/*is the baseenum repeated later on?:*/
-			for(j=i+1;j<maxfields;j++){
-				if (enums[j]==baseenum)enums[j]=-1;
-			}
-		}
-		else continue;
-	}
-
-	/*Now, go through enums, and whatever is not null is a non repeated field name: */
-	nfields=0;
-	for(i=0;i<maxfields;i++)if(enums[i]>0)nfields++;
-
-	/*Add 2 fields for time and step: */
-	nfields=nfields+2;
-	
-	/*Fill the names of the structure field: */
-	fnames=(const char**)xmalloc(nfields*sizeof(char*));
-	count=0;
-	for(i=0;i<maxfields;i++){
-		if (enums[i]>0){
-			fnames[count]=EnumToStringx(enums[i]);
-			count++;
-		}
-	}
-	/*don't forget the extra fields "time" and "step":*/
-	fnames[nfields-2]="time";
-	fnames[nfields-1]="step";
-
-	/*Initialize structure: */
-	dataref=mxCreateStructArray( ndim,onebyone,nfields,fnames);
-
-	/*Fill each field: */
-	for(i=0;i<this->Size();i++){ //do not include the last one used for time
-		ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
-		result->SetMatlabField(dataref);
-	}
-
-	/*Now, process the patch in the dataref structure, by calling MatlabProcessPatch.m 
-	 *on the current dataref structure: */
-	mexCallMATLAB(1,&processeddataref,1,&dataref, "MatlabProcessPatch");
-
-	/*Assign output pointers:*/
-	*pdataref=processeddataref;
-}
-#else 
 void Results::Write(Parameters* parameters){
 	
@@ -167,4 +83,3 @@
 
 }
-#endif
 /*}}}*/
Index: /issm/trunk/src/c/Container/Results.h
===================================================================
--- /issm/trunk/src/c/Container/Results.h	(revision 12329)
+++ /issm/trunk/src/c/Container/Results.h	(revision 12330)
@@ -26,9 +26,5 @@
 		/*numerics: {{{1*/
 		Results* SpawnTriaResults(int* indices);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void Write(mxArray** pdataref);
-		#else 
 		void Write(Parameters* parameters);
-		#endif
 		/*}}}*/
 };
Index: /issm/trunk/src/c/Container/Vertices.cpp
===================================================================
--- /issm/trunk/src/c/Container/Vertices.cpp	(revision 12329)
+++ /issm/trunk/src/c/Container/Vertices.cpp	(revision 12330)
@@ -61,6 +61,10 @@
 	 * First: bet number of dofs for each cpu*/
 	alldofcount=(int*)xmalloc(num_procs*sizeof(int));
+	#ifdef _HAVE_MPI_
 	MPI_Gather(&dofcount,1,MPI_INT,alldofcount,1,MPI_INT,0,MPI_COMM_WORLD);
 	MPI_Bcast(alldofcount,num_procs,MPI_INT,0,MPI_COMM_WORLD);
+	#else
+	alldofcount[0]=dofcount;
+	#endif
 
 	/* Every cpu should start its own dof count at the end of the dofcount from cpu-1*/
@@ -85,5 +89,9 @@
 		vertex->ShowTrueDofs(truedofs);
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce((void*)truedofs,(void*)alltruedofs,numberofobjects*numberofdofsperobject,MPI_INT,MPI_MAX,MPI_COMM_WORLD);
+	#else
+	for(i=0;i<numberofobjects*numberofdofsperobject;i++)alltruedofs[i]=truedofs[i];
+	#endif
 
 	/* Now every cpu knows the true dofs of everyone else that is not a clone*/
@@ -121,5 +129,9 @@
 	 * dealt with by another cpu. We take the minimum because we are going to manage dof assignment in increasing 
 	 * order of cpu rank. This is also why we initialized this array to num_procs.*/
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( (void*)ranks,(void*)minranks,numberofobjects,MPI_INT,MPI_MIN,MPI_COMM_WORLD);
+	#else
+	for(i=0;i<numberofobjects;i++)minranks[i]=ranks[i];
+	#endif
 
 	/*Now go through all objects, and use minranks to flag which objects are cloned: */
@@ -149,5 +161,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&max_sid,&vertex_max_sid,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&vertex_max_sid,1,MPI_INT,0,MPI_COMM_WORLD);
Index: /issm/trunk/src/c/Container/Vertices.h
===================================================================
--- /issm/trunk/src/c/Container/Vertices.h	(revision 12329)
+++ /issm/trunk/src/c/Container/Vertices.h	(revision 12330)
@@ -32,6 +32,3 @@
 };
 
-
-
 #endif //ifndef _VERTICES_H_
-
Index: /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.h
===================================================================
--- /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.h	(revision 12329)
+++ /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.h	(revision 12330)
@@ -153,4 +153,5 @@
 	PetscProfilingCurrentFlopsEnum,
 	PetscProfilingSolutionTimeEnum,
+	MaxIterationConvergenceFlagEnum,
 	SteadystateMaxiterEnum,
 	SteadystateNumRequestedOutputsEnum,
Index: /issm/trunk/src/c/EnumDefinitions/Synchronize.sh
===================================================================
--- /issm/trunk/src/c/EnumDefinitions/Synchronize.sh	(revision 12329)
+++ /issm/trunk/src/c/EnumDefinitions/Synchronize.sh	(revision 12330)
@@ -2,18 +2,18 @@
 #Synchronize EnumToStringx.cpp and StringToEnumx.cpp and matlab Enums
 
-#Get all lines of EnumDefinitions2.h which hold Enum | remove all comas | add line number in the first column > put everything in file temp
-cat EnumDefinitions.h | grep -e "[0-9]Enum," -e "[a-zA-Z]Enum," | grep -v include | sed -e "s/,//g" | awk '{ printf "%s %s\n", NR, $0 }' > temp
+#Get all lines of EnumDefinitions2.h which hold Enum | remove all comas > put everything in file temp
+cat EnumDefinitions.h | grep -e "[0-9]Enum," -e "[a-zA-Z]Enum," | grep -v include | sed -e "s/,/ /g" | awk '{print $1}' > temp
 
 #Removed existing files
-rm $ISSM_TIER/src/m/enum/*.m
-rm $ISSM_TIER/src/c/modules/EnumToStringx/EnumToStringx.cpp
-rm $ISSM_TIER/src/c/modules/StringToEnumx/StringToEnumx.cpp
+rm $ISSM_DIR/src/m/enum/*.m
+rm $ISSM_DIR/src/c/modules/EnumToStringx/EnumToStringx.cpp
+rm $ISSM_DIR/src/c/modules/StringToEnumx/StringToEnumx.cpp
 
 #Get number of enums
 NUMENUMS=$(wc -l temp | awk '{printf("%s",$1);}');
 
-#Build EnumToStringx.cpp {{{1
+#Build EnumToStringx.cpp {{{
 #Header
-cat <<END >  $ISSM_TIER/src/c/modules/EnumToStringx/EnumToStringx.cpp
+cat <<END >  $ISSM_DIR/src/c/modules/EnumToStringx/EnumToStringx.cpp
 /*
 * \file EnumToStringx.cpp:
@@ -35,7 +35,7 @@
 END
 #core
-cat temp |  awk '{print "\t\t" "case " $2" : return \"" substr($2,1,length($2)-4) "\";"}' >> $ISSM_TIER/src/c/modules/EnumToStringx/EnumToStringx.cpp
+cat temp |  awk '{print "\t\t" "case " $1" : return \"" substr($1,1,length($1)-4) "\";"}' >> $ISSM_DIR/src/c/modules/EnumToStringx/EnumToStringx.cpp
 #Footer
-cat <<END >> $ISSM_TIER/src/c/modules/EnumToStringx/EnumToStringx.cpp
+cat <<END >> $ISSM_DIR/src/c/modules/EnumToStringx/EnumToStringx.cpp
 		default : return "unknown";
 
@@ -57,5 +57,5 @@
 #Build StringToEnumx.cpp {{{1
 #Header
-cat <<END > $ISSM_TIER/src/c/modules/StringToEnumx/StringToEnumx.cpp
+cat <<END > $ISSM_DIR/src/c/modules/StringToEnumx/StringToEnumx.cpp
 /*
 * \file StringToEnumx.cpp:
@@ -81,9 +81,9 @@
 i2=120;
 for (( i=1 ; i<=100 ; i++ )); do
-	echo "   if(stage==$i){" >> $ISSM_TIER//src/c/modules/StringToEnumx/StringToEnumx.cpp
+	echo "   if(stage==$i){" >> $ISSM_DIR//src/c/modules/StringToEnumx/StringToEnumx.cpp
 	awk -v i1=$i1 -v i2=$i2 '{if(NR>=i1 && NR<=i2) print $0 }' temp |
-	awk '{print "\t" ((NR==1)?"      if":"      else if") " (strcmp(name,\"" substr($2,1,length($2)-4) "\")==0) return " $2 ";"}' >> $ISSM_TIER//src/c/modules/StringToEnumx/StringToEnumx.cpp
-	echo "         else stage=$(($i+1));" >> $ISSM_TIER//src/c/modules/StringToEnumx/StringToEnumx.cpp
-	echo "   }" >> $ISSM_TIER//src/c/modules/StringToEnumx/StringToEnumx.cpp
+	awk '{print "\t" ((NR==1)?"      if":"      else if") " (strcmp(name,\"" substr($1,1,length($1)-4) "\")==0) return " $1 ";"}' >> $ISSM_DIR//src/c/modules/StringToEnumx/StringToEnumx.cpp
+	echo "         else stage=$(($i+1));" >> $ISSM_DIR//src/c/modules/StringToEnumx/StringToEnumx.cpp
+	echo "   }" >> $ISSM_DIR//src/c/modules/StringToEnumx/StringToEnumx.cpp
 	
 	if [ $i2 -ge $NUMENUMS ]; then break; fi
@@ -93,5 +93,5 @@
 
 #footer
-cat <<END >> $ISSM_TIER/src/c/modules/StringToEnumx/StringToEnumx.cpp
+cat <<END >> $ISSM_DIR/src/c/modules/StringToEnumx/StringToEnumx.cpp
 	/*If we reach this point, the string provided has not been found*/
    _error_("Enum %s not found",name);
@@ -101,31 +101,30 @@
 
 # go through the lines of temp
-for (( i=1 ; i<=$NUMENUMS ; i++ )); do
+ENUM=0;
+for NAMEENUM in $(cat temp); do
 
 	#Get name and enum of the line i
-	NAMEENUM=$(cat temp | grep "^[ ]*$i " | awk '{printf("%s",$2);}');
 	NAME=$(echo $NAMEENUM | sed -e "s/Enum//g")
-	ENUM=$i;
 	#offset Enum by one (Enum begins with 0 and not 1!)
-	let ENUM=$ENUM-1
+	let ENUM=$ENUM+1
 
 	#print info {{{
-	if [ $i -lt 10 ]
+	if [ $ENUM -lt 10 ]
 	then
 		printf "\r                                                                      "
-		printf "\r  $i/$NUMENUMS Adding "$NAME"..."
+		printf "\r  $ENUM/$NUMENUMS Adding "$NAME"..."
 	else
-		if [ $i -lt 100 ]
+		if [ $ENUM -lt 100 ]
 		then
 			printf "\r                                                                      "
-			printf "\r $i/$NUMENUMS Adding "$NAME"..."
+			printf "\r $ENUM/$NUMENUMS Adding "$NAME"..."
 		else
 			printf "\r                                                                      "
-			printf "\r$i/$NUMENUMS Adding "$NAME"..."
+			printf "\r$ENUM/$NUMENUMS Adding "$NAME"..."
 		fi
 	fi
 	#}}}
 	#Add case to matlabenum file{{{
-	cat <<END > $ISSM_TIER"/src/m/enum/"$(echo $NAMEENUM".m")
+	cat <<END > $ISSM_DIR"/src/m/enum/"$(echo $NAMEENUM".m")
 function macro=$(echo $NAMEENUM)()
 %$(echo $NAMEENUM | awk {'print toupper($1)'}) - Enum of $(echo $NAME)
@@ -143,4 +142,21 @@
 
 done
+#MaximumNumberOfEnums{{{
+cat <<END > $ISSM_DIR/src/m/enum/MaximumNumberOfEnums.m
+function macro=MaximumNumberOfEnums()
+%$(echo "MaximumNumberOfEnums" | awk {'print toupper($1)'}) - Enum of MaximumNumberOfEnums
+%
+%   WARNING: DO NOT MODIFY THIS FILE
+%            this file has been automatically generated by src/c/EnumDefinitions/Synchronize.sh
+%            Please read src/c/EnumDefinitions/README for more information
+%
+%   Usage:
+%      macro=MaximumNumberOfEnums()
+
+macro=$(cat EnumDefinitions.h | grep -e "[0-9]Enum" -e "[a-zA-Z]Enum" | grep -v include \
+		| awk '{ printf "%s %s\n", NR-1, $0 }' \
+		| grep "MaximumNumberOfEnums" | awk '{print $1}');
+END
+#}}}
 
 #clean up{{{
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 12329)
+++ /issm/trunk/src/c/Makefile.am	(revision 12330)
@@ -4,17 +4,13 @@
 
 #Library declaration {{{1
-#Compile serial library, and then try and compile parallel library
-if NOSERIAL
-if NOPARALLEL
-lib_LIBRARIES = 
-else
-lib_LIBRARIES = libpISSM.a libOverload.a
-endif
-else
-if NOPARALLEL
-lib_LIBRARIES = libISSM.a libOverload.a
-else
-lib_LIBRARIES = libISSM.a libpISSM.a libOverload.a
-endif
+lib_LIBRARIES = libISSMCore.a libISSMOverload.a
+if PYTHON
+lib_LIBRARIES += libISSMPython.a 
+endif
+if MATLAB
+lib_LIBRARIES += libISSMMatlab.a 
+endif
+if MODULES
+lib_LIBRARIES += libISSMModules.a 
 endif
 #}}}
@@ -22,5 +18,7 @@
 #sources
 #Core sources{{{1
-core_sources = ./include/macros.h\
+core_sources = ./issm.h\
+					./issm-binding.h\
+					./include/macros.h\
 					./include/typedefs.h\
 					./include/types.h\
@@ -211,10 +209,4 @@
 					./shared/Wrapper/ModuleBoot.cpp\
 					./shared/Wrapper/ModuleEnd.cpp\
-					./toolkits/mpi/mpiincludes.h\
-					./toolkits/mpi/patches/mpipatches.h\
-					./toolkits/mpi/patches/DetermineLocalSize.cpp\
-					./toolkits/mpi/patches/MPI_Upperrow.cpp\
-					./toolkits/mpi/patches/MPI_Lowerrow.cpp\
-					./toolkits/mpi/patches/MPI_Boundariesfromrange.cpp\
 					./toolkits/metis/metisincludes.h\
 					./toolkits/issm/issmtoolkit.h\
@@ -223,6 +215,4 @@
 					./toolkits/issm/SeqMat.h\
 					./toolkits/issm/SeqMat.cpp\
-					./toolkits/metis/patches/metispatches.h\
-					./toolkits/metis/patches/METIS_PartMeshNodalPatch.cpp\
 					./toolkits/triangle/triangleincludes.h\
 					./toolkitsenums.h\
@@ -362,14 +352,14 @@
 					  ./modules/AverageOntoPartitionx/AverageOntoPartitionx.cpp\
 					  ./modules/ModelProcessorx/Dakota/CreateParametersDakota.cpp\
-					  ./modules/AverageOntoPartitionx/AverageOntoPartitionx.h
-dakota_psources= ./modules/Dakotax/SpawnCoreParallel.cpp
+					  ./modules/AverageOntoPartitionx/AverageOntoPartitionx.h\
+					  ./modules/Dakotax/SpawnCoreParallel.cpp
 #}}}
 #Transient sources  {{{1
-transient_sources  = ./modules/ModelProcessorx/Transient/UpdateElementsTransient.cpp
-transient_psources = ./solutions/transient_core.cpp
+transient_sources  = ./modules/ModelProcessorx/Transient/UpdateElementsTransient.cpp \
+					 ./solutions/transient_core.cpp
 #}}}
 #Steadystate sources  {{{1
-steadystate_psources = ./solutions/steadystate_core.cpp\
-					        ./solutions/steadystateconvergence.cpp
+steadystate_sources = ./solutions/steadystate_core.cpp\
+					  ./solutions/steadystateconvergence.cpp
 #}}}
 #Prognostic sources  {{{1
@@ -377,6 +367,6 @@
 					      ./modules/ModelProcessorx/Prognostic/CreateNodesPrognostic.cpp\
 					      ./modules/ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp\
-					      ./modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp
-prognostic_psources = ./solutions/prognostic_core.cpp
+					      ./modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp\
+						  ./solutions/prognostic_core.cpp
 #}}}
 #Thermal sources  {{{1
@@ -395,9 +385,8 @@
 					   ./modules/ConstraintsStatex/ThermalConstraintsState.cpp\
 					   ./modules/ConstraintsStatex/ThermalIsPresent.cpp\
-					   ./modules/ResetConstraintsx/ThermalConstraintsReset.cpp
-
-thermal_psources = ./solutions/thermal_core.cpp\
-					    ./solutions/enthalpy_core.cpp\
-					    ./solvers/solver_thermal_nonlinear.cpp
+					   ./modules/ResetConstraintsx/ThermalConstraintsReset.cpp \
+					   ./solutions/thermal_core.cpp\
+					   ./solutions/enthalpy_core.cpp\
+					   ./solvers/solver_thermal_nonlinear.cpp
 #}}}
 #Control sources  {{{1
@@ -443,8 +432,6 @@
 					  ./objects/Inputs/ControlInput.cpp\
 					  ./shared/Numerics/BrentSearch.cpp\
-					  ./shared/Numerics/OptimalSearch.cpp\
-					  ./shared/Numerics/OptFunc.cpp
-
-control_psources=./solutions/control_core.cpp\
+					  ./shared/Numerics/OptimalSearch.cpp \
+					  ./solutions/control_core.cpp\
 					  ./solutions/controltao_core.cpp\
 					  ./solutions/controlrestart.cpp\
@@ -462,8 +449,7 @@
 					      ./modules/ModelProcessorx/Hydrology/CreateNodesHydrology.cpp\
 					      ./modules/ModelProcessorx/Hydrology/CreateConstraintsHydrology.cpp\
-					      ./modules/ModelProcessorx/Hydrology/CreateLoadsHydrology.cpp
-					  
-hydrology_psources  = ./solutions/hydrology_core.cpp\
-					       ./solutions/hydrology_core_step.cpp 
+					      ./modules/ModelProcessorx/Hydrology/CreateLoadsHydrology.cpp \
+						  ./solutions/hydrology_core.cpp\
+						  ./solutions/hydrology_core_step.cpp 
 #}}}
 #Diagnostic sources  {{{1
@@ -480,11 +466,11 @@
 					      ./modules/ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp \
 					      ./modules/ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp \
-							./shared/Elements/CoordinateSystemTransform.cpp\
-							./shared/Elements/TransformLoadVectorCoord.cpp \
-							./shared/Elements/TransformStiffnessMatrixCoord.cpp \
-							./shared/Elements/TransformInvStiffnessMatrixCoord.cpp \
-							./shared/Elements/TransformSolutionCoord.cpp
-diagnostic_psources =./solutions/diagnostic_core.cpp\
-					      ./solvers/solver_stokescoupling_nonlinear.cpp
+						  ./shared/Elements/CoordinateSystemTransform.cpp\
+						  ./shared/Elements/TransformLoadVectorCoord.cpp \
+						  ./shared/Elements/TransformStiffnessMatrixCoord.cpp \
+						  ./shared/Elements/TransformInvStiffnessMatrixCoord.cpp \
+						  ./shared/Elements/TransformSolutionCoord.cpp\
+						  ./solutions/diagnostic_core.cpp\
+						  ./solvers/solver_stokescoupling_nonlinear.cpp
 #}}}
 #Balanced sources  {{{1
@@ -492,6 +478,6 @@
 					    ./modules/ModelProcessorx/Balancethickness/CreateNodesBalancethickness.cpp\
 					    ./modules/ModelProcessorx/Balancethickness/CreateConstraintsBalancethickness.cpp\
-					    ./modules/ModelProcessorx/Balancethickness/CreateLoadsBalancethickness.cpp
-balanced_psources = ./solutions/balancethickness_core.cpp
+						./modules/ModelProcessorx/Balancethickness/CreateLoadsBalancethickness.cpp\
+						./solutions/balancethickness_core.cpp
 #}}}
 #Responses sources  {{{1
@@ -533,6 +519,6 @@
 					  ./modules/ModelProcessorx/SurfaceSlope/CreateNodesSurfaceSlope.cpp \
 					  ./modules/ModelProcessorx/SurfaceSlope/CreateConstraintsSurfaceSlope.cpp\
-					  ./modules/ModelProcessorx/SurfaceSlope/CreateLoadsSurfaceSlope.cpp
-slope_psources = ./solutions/surfaceslope_core.cpp\
+					  ./modules/ModelProcessorx/SurfaceSlope/CreateLoadsSurfaceSlope.cpp\
+					  ./solutions/surfaceslope_core.cpp\
 					  ./solutions/bedslope_core.cpp
 #}}}
@@ -589,6 +575,6 @@
 				./objects/Bamg/Metric.cpp\
 				./objects/Bamg/Metric.h\
-				./objects/Bamg/QuadTree.cpp\
-				./objects/Bamg/QuadTree.h\
+				./objects/Bamg/BamgQuadtree.cpp\
+				./objects/Bamg/BamgQuadtree.h\
 				./objects/Bamg/R2.h\
 				./objects/Bamg/SetOfE4.cpp\
@@ -625,4 +611,24 @@
 				./modules/BamgTriangulatex/BamgTriangulatex.cpp\
 				./modules/BamgTriangulatex/BamgTriangulatex.h
+#}}}
+#Kriging sources  {{{1
+kriging_sources = ./Container/Observations.h\
+						./Container/Observations.cpp\
+						./objects/Kriging/Variogram.h \
+						./objects/Kriging/GaussianVariogram.h\
+						./objects/Kriging/GaussianVariogram.cpp\
+						./objects/Kriging/ExponentialVariogram.h\
+						./objects/Kriging/ExponentialVariogram.cpp\
+						./objects/Kriging/SphericalVariogram.h\
+						./objects/Kriging/SphericalVariogram.cpp\
+						./objects/Kriging/PowerVariogram.h\
+						./objects/Kriging/PowerVariogram.cpp\
+						./objects/Kriging/Quadtree.h\
+						./objects/Kriging/Quadtree.cpp\
+						./objects/Kriging/Observation.h\
+						./objects/Kriging/Observation.cpp\
+						./modules/Krigingx/Krigingx.cpp\
+						./modules/Krigingx/Krigingx.h
+
 #}}}
 #Kml sources  {{{1
@@ -694,23 +700,4 @@
 			     ./objects/KML/KMLFileReadUtils.h
 #}}}
-#Matlab sources  {{{1
-matlab_sources= ./toolkits/matlab/matlabincludes.h\
-				    ./toolkits/matlab/MatlabNArrayToNArray.cpp\
-				    ./toolkits/double/MatlabVectorToDoubleVector.cpp\
-				    ./toolkits/double/double.h\
-				    ./toolkits/double/MatlabMatrixToDoubleMatrix.cpp\
-				    ./io/Matlab/matlabio.h\
-				    ./io/Matlab/CheckNumMatlabArguments.cpp\
-				    ./io/Matlab/mxGetAssignedField.cpp\
-				    ./io/Matlab/WriteMatlabData.cpp\
-				    ./io/Matlab/FetchMatlabData.cpp\
-				    ./io/Matlab/OptionParse.cpp
-#}}}
-#Python sources  {{{1
-python_sources=     ./io/Python/pythonio.h\
-				    ./io/Python/WritePythonData.cpp\
-				    ./io/Python/CheckNumPythonArguments.cpp\
-				    ./io/Python/FetchPythonData.cpp
-#}}}
 #Petsc sources  {{{1
 petsc_sources= ./toolkits/petsc\
@@ -718,8 +705,4 @@
 					./toolkits/petsc/patches/SolverEnum.h\
 					./toolkits/petsc/patches/petscpatches.h\
-					./toolkits/petsc/patches/MatlabMatrixToPetscMatrix.cpp\
-					./toolkits/petsc/patches/MatlabVectorToPetscVector.cpp\
-					./toolkits/petsc/patches/PetscMatrixToMatlabMatrix.cpp\
-					./toolkits/petsc/patches/PetscVectorToMatlabVector.cpp\
 					./toolkits/petsc/patches/VecTranspose.cpp\
 					./toolkits/petsc/patches/VecToMPISerial.cpp\
@@ -732,4 +715,6 @@
 					./toolkits/petsc/patches/SerialToVec.cpp\
 					./toolkits/petsc/patches/VecFree.cpp\
+					./toolkits/petsc/patches/PetscMatrixToDoubleMatrix.cpp\
+					./toolkits/petsc/patches/PetscVectorToDoubleVector.cpp\
 					./toolkits/petsc/patches/VecDuplicatePatch.cpp\
 					./toolkits/petsc/patches/KSPFree.cpp\
@@ -754,6 +739,48 @@
 
 #}}}
-#Serialsources  {{{1
-serial_sources= ./objects/Options/Option.cpp\
+#Mpi sources  {{{1
+mpi_sources= ./toolkits/mpi/mpiincludes.h\
+				./toolkits/mpi/patches/mpipatches.h\
+				./toolkits/mpi/patches/DetermineLocalSize.cpp\
+				./toolkits/mpi/patches/MPI_Upperrow.cpp\
+				./toolkits/mpi/patches/MPI_Lowerrow.cpp\
+				./toolkits/mpi/patches/MPI_Boundariesfromrange.cpp
+#}}}
+#Metis sources  {{{1
+metis_sources= ./toolkits/metis/patches/metispatches.h\
+					./toolkits/metis/patches/METIS_PartMeshNodalPatch.cpp
+#}}}
+#Python sources  {{{1
+python_sources=     ./python/io/pythonio.h\
+					./python/python-binding.h\
+				    ./python/io/WritePythonData.cpp\
+				    ./python/io/CheckNumPythonArguments.cpp\
+				    ./python/io/FetchPythonData.cpp
+
+#}}}
+#Matlab sources  {{{1
+matlab_sources= ./toolkits/matlab/matlabincludes.h\
+				    ./matlab/matlab-binding.h\
+				    ./matlab/io/matlabio.h\
+				    ./matlab/io/MatlabNArrayToNArray.cpp\
+				    ./matlab/io/CheckNumMatlabArguments.cpp\
+				    ./matlab/io/mxGetAssignedField.cpp\
+				    ./matlab/io/WriteMatlabData.cpp\
+				    ./matlab/io/FetchMatlabData.cpp\
+				    ./matlab/io/OptionParse.cpp\
+				    ./matlab/io/MatlabMatrixToMatrix.cpp\
+				    ./matlab/io/MatlabVectorToVector.cpp\
+					 ./matlab/io/MatlabVectorToDoubleVector.cpp\
+					 ./matlab/io/MatlabMatrixToDoubleMatrix.cpp\
+					 ./matlab/io/MatlabMatrixToSeqMat.cpp\
+					 ./matlab/io/MatlabVectorToSeqVec.cpp
+#}}}
+#Matlab and Petsc sources  {{{1
+matlabpetsc_sources= ./matlab/io/MatlabMatrixToPetscMatrix.cpp\
+					 ./matlab/io/MatlabVectorToPetscVector.cpp
+	
+#}}}
+#Modules sources{{{1
+module_sources= ./objects/Options/Option.cpp\
 			./objects/Options/Option.h\
 			./objects/Options/OptionDouble.cpp\
@@ -769,4 +796,6 @@
 			./objects/Options/OptionUtilities.cpp\
 			./objects/Options/OptionUtilities.h\
+			./shared/Alloc/alloc_module.h\
+			./shared/Alloc/alloc_module.cpp\
 			./shared/Threads/issm_threads.h\
 			./shared/Threads/LaunchThread.cpp\
@@ -790,5 +819,4 @@
 			./modules/Chacox/chaco_seconds.cpp\
 			./modules/Chacox/user_params.cpp\
-			./modules/Dakotax/SpawnCoreSerial.cpp\
 			./modules/TriaSearchx/TriaSearchx.h\
 			./modules/TriaSearchx/TriaSearchx.cpp\
@@ -841,67 +869,55 @@
 #}}}
 
+#{{{1 Conditional build-up of sources
 #ISSM sources are a combination of core sources and sources related to specific capabilities (which can 
 #be activated by autotools conditionals 
-#{{{1
+
 
 #First the core
 issm_sources  =  $(core_sources)
-issm_psources =  
 
 #Now the optional source
 if DAKOTA
 issm_sources  +=  $(dakota_sources)
-issm_psources +=  $(dakota_psources)
 endif
 
 if PETSC
 issm_sources  +=  $(petsc_sources)
-issm_psources +=  $(petsc_psources)
 endif
 
 if GSL
 issm_sources  +=  $(gsl_sources)
-issm_psources +=  $(gsl_psources)
-endif
-
+endif
 
 if TRANSIENT
 issm_sources  +=  $(transient_sources)
-issm_psources +=  $(transient_psources)
 endif
 
 if STEADYSTATE
 issm_sources  +=  $(steadystate_sources)
-issm_psources +=  $(steadystate_psources)
 endif
 
 if PROGNOSTIC
 issm_sources  +=  $(prognostic_sources)
-issm_psources +=  $(prognostic_psources)
 endif
 
 if THERMAL
 issm_sources  +=  $(thermal_sources)
-issm_psources +=  $(thermal_psources)
 endif
 
 if CONTROL
 issm_sources  +=  $(control_sources)
-issm_psources +=  $(control_psources)
 endif
 
 if HYDROLOGY
 issm_sources  +=  $(hydrology_sources)
-issm_psources +=  $(hydrology_psources)
 endif
 
 if DIAGNOSTIC
 issm_sources  +=  $(diagnostic_sources)
-issm_psources +=  $(diagnostic_psources)
 endif
 
 if BALANCED
 issm_sources  +=  $(balanced_sources)
-issm_psources +=  $(balanced_psources)
 endif
 
@@ -912,5 +928,4 @@
 if SLOPE
 issm_sources  +=  $(slope_sources)
-issm_psources +=  $(slope_psources)
 endif
 
@@ -926,70 +941,82 @@
 issm_sources +=  $(threed_sources)
 endif
-#}}}
-
-#ISSM serial library {{{1
-if SERIAL
-libISSM_a_SOURCES  = $(issm_sources)
-libISSM_a_SOURCES += $(serial_sources)
-libISSM_a_SOURCES += $(bamg_sources)
-libISSM_a_SOURCES += $(kml_sources)
-libISSM_a_CXXFLAGS = -fPIC -D_SERIAL_ -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_  $(CXXFLAGS) $(CXXOPTFLAGS) 
-#libISSM_a_CXXFLAGS = -D_SERIAL_ -DTRILIBRARY -DANSI_DECLARATORS -DNO_TIMER   $(CXXFLAGS) $(CXXOPTFLAGS) 
+
+if MPI
+issm_sources +=  $(mpi_sources)
+endif
+
+if METIS
+issm_sources +=  $(metis_sources)
+endif
+
+if PETSC
+if MATLAB
+issm_sources +=  $(matlabpetsc_sources)
+endif
+endif
+
+
+#}}}
+#Library flags and sources {{{1
+ALLCXXFLAGS= -fPIC -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_  $(CXXFLAGS) $(CXXOPTFLAGS) 
+
+libISSMCore_a_SOURCES  = $(issm_sources)
+libISSMCore_a_CXXFLAGS = $(ALLCXXFLAGS)
+
+if MODULES
+libISSMModules_a_SOURCES = $(module_sources)
+libISSMModules_a_SOURCES += $(bamg_sources)
+libISSMModules_a_SOURCES += $(kriging_sources)
+libISSMModules_a_SOURCES += $(kml_sources)
+libISSMModules_a_CXXFLAGS = $(ALLCXXFLAGS)
+endif
 
 if PYTHON
-libISSM_a_CXXFLAGS+=  -DNPY_NO_DEPRECATED_API 
-libISSM_a_SOURCES += $(python_sources)
+libISSMPython_a_SOURCES = $(python_sources)
+libISSMPython_a_CXXFLAGS= $(ALLCXXFLAGS)
 endif
 
 if MATLAB
-libISSM_a_SOURCES += $(matlab_sources)
-endif
-
-endif
-#}}}
-#ISSM parallel library {{{1
-if PARALLEL
-libpISSM_a_SOURCES  = $(issm_sources)
-libpISSM_a_SOURCES += $(issm_psources)
-libpISSM_a_CXXFLAGS = -fPIC -D_PARALLEL_   -D_C_ $(CXXFLAGS) $(CXXOPTFLAGS) 
-endif
+libISSMMatlab_a_SOURCES = $(matlab_sources)
+libISSMMatlab_a_CXXFLAGS= $(ALLCXXFLAGS)
+endif
+
 #}}}
 #Overload library, to overload any non-standard symbols. {{{1
-libOverload_a_SOURCES = ./shared/String/stricmp.c
-libOverload_a_CFLAGS  = -fPIC -D_PARALLEL_   -D_C_ $(COPTFLAGS) $(CFLAGS)
+libISSMOverload_a_SOURCES = ./shared/String/stricmp.c
+libISSMOverload_a_CFLAGS  = -fPIC -D_C_ $(COPTFLAGS) $(CFLAGS)
 #}}}
 
 #Executable {{{1
-if NOPARALLEL
-bin_PROGRAMS = 
-else 
 bin_PROGRAMS = issm 
-endif
 
 #Standard libraries
-LDADD = ./libpISSM.a ./libOverload.a
+LDADD = ./libISSMCore.a ./libISSMOverload.a
 
 #External packages
-LDADD += $(PETSCLIB) $(TAOLIB) $(FLIBS) $(PLAPACKLIB) $(MUMPSLIB) $(SCALAPACKLIB) $(BLACSLIB) $(HYPRELIB) $(MLLIB) $(DAKOTALIB) $(METISLIB) $(CHACOLIB) $(SCOTCHLIB) $(BLASLAPACKLIB) $(MKLLIB) $(MPILIB) $(MATHLIB) $(FORTRANLIB) $(GRAPHICSLIB) $(MULTITHREADINGLIB) $(OSLIBS) $(GSLLIB)
+LDADD += $(PETSCLIB) $(TAOLIB) $(PLAPACKLIB) $(MUMPSLIB) $(SCALAPACKLIB) $(BLACSLIB) $(HYPRELIB) $(MLLIB) $(DAKOTALIB) $(METISLIB) $(CHACOLIB) $(SCOTCHLIB) $(BLASLAPACKLIB) $(MKLLIB) $(MPILIB) $(MATHLIB) $(FORTRANLIB) $(GRAPHICSLIB) $(MULTITHREADINGLIB) $(OSLIBS) $(GSLLIB)
+
+if FORTRAN
+LDADD += $(FLIBS)
+endif
 
 issm_SOURCES = solutions/issm.cpp
-issm_CXXFLAGS= -fPIC -D_PARALLEL_ $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) 
+issm_CXXFLAGS= -fPIC $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) 
 #}}}
 #Automatic differentiation: append this fold to the end of the src/c/Makefile.am to get this Makefile.am {{{
 if ADIC2 
-lib_LIBRARIES += libAD.a libpISSMRose.a
+lib_LIBRARIES += libAD.a libISSMRose.a
 
 #ADIC2 library, for automatic differentiation 
 #libAD_a_SOURCES = ./mini1.ad.c
 libAD_a_SOURCES = 
-libAD_a_CFLAGS = -fPIC -D_PARALLEL_   -D_C_ $(COPTFLAGS)
-
+libAD_a_CFLAGS = -fPIC -D_C_ $(COPTFLAGS)
 
 
 #test rose preprocessing 
 %.r2cpp.cpp : %.cpp
-	testTranslator -rose:o $@ -rose:skipfinalCompileStep -DHAVE_CONFIG_H -D_PARALLEL_ -D_C_ -I. -I../.. $(INCLUDES) $<
-libpISSMRose_a_SOURCES = $(libpISSM_a_SOURCES:.cpp=.r2cpp.cpp)
-libpISSMRose_a_CXXFLAGS= -fPIC -D_PARALLEL_ -D_C_ $(CXXOPTFLAGS)
+	testTranslator -rose:o $@ -rose:skipfinalCompileStep -DHAVE_CONFIG_H -D_C_ -I. -I../.. $(INCLUDES) $<
+libISSMRose_a_SOURCES = $(libISSMCore_a_SOURCES:.cpp=.r2cpp.cpp)
+libISSMRose_a_CXXFLAGS= -fPIC -D_C_ $(CXXOPTFLAGS)
 
 
@@ -1003,7 +1030,7 @@
 #Executable
 bin_PROGRAMS +=  issmRose.exe
-issmRose_exe_LDADD = ./libpISSMRose.a $(LDADD)
+issmRose_exe_LDADD = ./libISSMRose.a $(LDADD)
 issmRose_exe_SOURCES = solutions/issm.cpp
-issmRose_exe_CXXFLAGS= -fPIC -D_PARALLEL_  $(CXXOPTFLAGS) $(COPTFLAGS) 
+issmRose_exe_CXXFLAGS= -fPIC $(CXXOPTFLAGS) $(COPTFLAGS) 
 LDADD +=  $(ADIC2LIB) 
 
Index: /issm/trunk/src/c/include/macros.h
===================================================================
--- /issm/trunk/src/c/include/macros.h	(revision 12329)
+++ /issm/trunk/src/c/include/macros.h	(revision 12330)
@@ -40,39 +40,14 @@
 #endif
 /*}}}*/
-
-/* MODULEBOOT/MODULEEND {{{1*/
+/* ISSMBOOT/ISSMEND {{{1*/
 
 /*The following macros hide the error exception handling in a matlab module. Just put 
- * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions 
+ * ISSMBOOT(); and ISSMEND(); at the beginning and end of a module, and c++ exceptions 
  * will be trapped. Really nifty!*/
 
-#ifdef _SERIAL_
-#ifdef _HAVE_MATLAB_ //{{{2
-#define MODULEBOOT(); ModuleBoot(); \
+#define ISSMBOOT(); \
 	try{
 
-#define MODULEEND(); ModuleEnd(); }\
-	catch(ErrorException &exception){\
-		exception.Report(); \
-		mexErrMsgTxt(""); \
-	}\
-	catch (exception& e) {\
-		_printf_(true,"Standard exception: %s\n",e.what());\
-		mexErrMsgTxt(" ");\
-	}
-#endif //}}}
-#ifdef _HAVE_PYTHON_ //{{{2
-#define MODULEBOOT(); ModuleBoot();  \
-	PyObject* output = PyTuple_New(NLHS); if (!output) return NULL;
-
-#define MODULEEND();  ModuleEnd(); \
-						 return output;
-#endif //}}}
-#else 
-//{{{2
-#define MODULEBOOT(); \
-	try{
-
-#define MODULEEND(); }\
+#define ISSMEND(); }\
 	catch(ErrorException &exception){\
 		exception.Report(); \
@@ -82,50 +57,9 @@
 		_printf_(true,"Standard exception: %s\n",e.what());\
 		return 1;\
+	}\
+	catch(...){\
+		_printf_(true,"An unexpected error occurred");\
 	}
-//}}}
-#endif
 /*}}}*/
-/* WRAPPER {{{1*/
-#ifdef _HAVE_MATLAB_
-#define WRAPPER(modulename,...) void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) 
-#endif
-#ifdef _HAVE_PYTHON_
-#define WRAPPER(modulename,...)  \
-\
-static PyObject* modulename(PyObject* self,PyObject* args);\
-static PyMethodDef modulename##_funcs[] = {\
-	{#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\
-	{NULL,NULL,0,NULL}\
-};\
-\
-static struct PyModuleDef modulename##module= {\
-	PyModuleDef_HEAD_INIT,\
-	#modulename,   /* name of module */\
-	NULL, /* module documentation, may be NULL */\
-	-1,       /* size of per-interpreter state of the module,\
-				 or -1 if the module keeps state in global variables. */\
-	modulename##_funcs\
-};\
-\
-PyMODINIT_FUNC PyInit_##modulename(void){\
-\
-	import_array();\
-	return PyModule_Create(&modulename##module);\
-}\
-\
-static PyObject* modulename(PyObject* self,PyObject* args)
 
 #endif
-
-/*}}}*/
-/* CHECKARGUMENTS {{{1*/
-#ifdef _HAVE_MATLAB_
-#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,functionpointer)
-#endif
-#ifdef _HAVE_PYTHON_
-#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer)
-#endif
-/*}}}*/
-
-
-#endif
Index: /issm/trunk/src/c/include/types.h
===================================================================
--- /issm/trunk/src/c/include/types.h	(revision 12329)
+++ /issm/trunk/src/c/include/types.h	(revision 12330)
@@ -16,12 +16,4 @@
 
 /*Define abstract type for I/O: */
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-typedef const mxArray* ConstDataHandle;  //serially, we are reading data from a matlab array.
-typedef mxArray* DataHandle;  
-#else 
-typedef FILE* ConstDataHandle; //in parallel, we are reading data from a file.
-typedef FILE* DataHandle; 
-#endif
 enum param_type { STRING, INTEGER, STRINGARRAY, DOUBLE, DOUBLEVEC, DOUBLEMAT, PETSCVEC, PETSCMAT };
 
@@ -35,5 +27,10 @@
 #endif  
 
-typedef double IssmDouble;
+#ifdef _HAVE_ADOLC_
+typedef adouble IssmDouble;
+#else 
+typedef double IssmDouble; 
+#endif
+
 typedef bool IssmBool;
 
Index: /issm/trunk/src/c/io/PrintfFunction.cpp
===================================================================
--- /issm/trunk/src/c/io/PrintfFunction.cpp	(revision 12329)
+++ /issm/trunk/src/c/io/PrintfFunction.cpp	(revision 12330)
@@ -8,8 +8,4 @@
 #include "../shared/shared.h"
 #include "../include/include.h"
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "mex.h"
-#endif
 
 int PrintfFunction(const char* format,...){
@@ -53,9 +49,5 @@
 
 	/*Ok, if we are running in parallel, get node 0 to print*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	mexPrintf(buffer);
-#else
 	if(my_rank==0)printf(buffer);
-#endif
 
 	/*Clean up and return*/
Index: /issm/trunk/src/c/io/io.h
===================================================================
--- /issm/trunk/src/c/io/io.h	(revision 12329)
+++ /issm/trunk/src/c/io/io.h	(revision 12330)
@@ -15,12 +15,4 @@
 #include "./Disk/diskio.h"
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "./Matlab/matlabio.h"
-#endif
-
-#if defined(_HAVE_PYTHON_) && defined(_SERIAL_)
-#include "./Python/pythonio.h"
-#endif
-
 /*printf: */
 int PrintfFunction(const char* format,...);
Index: /issm/trunk/src/c/issm-binding.h
===================================================================
--- /issm/trunk/src/c/issm-binding.h	(revision 12330)
+++ /issm/trunk/src/c/issm-binding.h	(revision 12330)
@@ -0,0 +1,18 @@
+#ifndef _ISSM_BINDING_H_
+#define _ISSM_BINDING_H_
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#ifdef  _HAVE_MATLAB_MODULES_
+#include "./matlab/matlab-binding.h"
+#endif
+
+#ifdef  _HAVE_PYTHON_MODULES_
+#include "./python/python-binding.h"
+#endif
+
+#endif
Index: /issm/trunk/src/c/matlab/include/matlab_macros.h
===================================================================
--- /issm/trunk/src/c/matlab/include/matlab_macros.h	(revision 12330)
+++ /issm/trunk/src/c/matlab/include/matlab_macros.h	(revision 12330)
@@ -0,0 +1,47 @@
+/* \file matlab macros.h
+ * \brief: macros used for the matlab bindings
+ */
+
+/*Header {{{1*/
+#ifndef _MATLAB_MACROS_H_
+#define _MATLAB_MACROS_H_
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+/*}}}*/
+
+#ifdef _HAVE_MATLAB_
+/* MODULEBOOT/MODULEEND {{{1*/
+
+/*The following macros hide the error exception handling in a matlab module. Just put 
+ * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions 
+ * will be trapped. Really nifty!*/
+//exception.Report(); 
+
+#define MODULEBOOT(); ModuleBoot(); \
+	try{
+
+#define MODULEEND(); ModuleEnd(); }\
+	catch(ErrorException &exception){\
+		mexErrMsgTxt("ISSM Error"); \
+	}\
+	catch (exception &e){\
+		mexErrMsgTxt(exprintf("Standard exception: %s\n",e.what()));\
+	}\
+	catch(...){\
+		mexErrMsgTxt("An unexpected error occurred");\
+	}
+//}}}
+/* WRAPPER {{{1*/
+#define WRAPPER(modulename,...) void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) 
+
+/*}}}*/
+/* CHECKARGUMENTS {{{1*/
+#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,functionpointer)
+/*}}}*/
+#endif
+
+#endif
Index: /issm/trunk/src/c/matlab/io/CheckNumMatlabArguments.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/CheckNumMatlabArguments.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/CheckNumMatlabArguments.cpp	(revision 12330)
@@ -0,0 +1,31 @@
+/*!\file CheckNumMatlabArguments.cpp:
+ * \brief: check number of arguments and report an usage error message.
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+
+#include "../../shared/Exceptions/exceptions.h"
+#include "../../include/include.h"
+#include "mex.h"
+
+int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* __FUNCT__, void (*function)( void )){
+	
+	/*checks on arguments on the matlab side: */
+	if (nrhs==0 && nlhs==0) {
+		/*unless NLHS=0 and NRHS=0, we are just asking for documentation: */
+		if (NRHS==0 && NLHS==0)return 1;
+		/* special case: */
+		function();
+		_error_("usage: see above");
+	}
+	else if (nlhs!=NLHS || nrhs!=NRHS ) {
+		function(); 
+		_error_("usage error.");
+	}
+	return 1;
+}
Index: /issm/trunk/src/c/matlab/io/FetchMatlabData.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/FetchMatlabData.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/FetchMatlabData.cpp	(revision 12330)
@@ -0,0 +1,628 @@
+/*\file FetchData.cpp:
+ * \brief: general I/O interface to fetch data in matlab
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <mex.h>
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "./matlabio.h"
+
+/*Primitive data types*/
+/*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{1*/
+void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){
+
+	double*  outmatrix=NULL;
+	int      outmatrix_rows,outmatrix_cols;
+
+	if(mxIsEmpty(dataref) ){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outmatrix_rows=0;
+		outmatrix_cols=0;
+		outmatrix=NULL;
+	}
+	else if(mxIsClass(dataref,"double") || mxIsClass(dataref,"single")){
+		/*Check dataref is not pointing to NaN: */
+		if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
+			outmatrix_rows=0;
+			outmatrix_cols=0;
+			outmatrix=NULL;
+		}
+		else{
+			/*Convert matlab matrix to double* matrix: */
+			MatlabMatrixToDoubleMatrix(&outmatrix,&outmatrix_rows,&outmatrix_cols,dataref);
+		}
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+			
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pM)*pM=outmatrix_rows;
+	if (pN)*pN=outmatrix_cols;
+
+}
+/*}}}*/
+/*FUNCTION FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{1*/
+void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
+
+	double*  outmatrix=NULL;
+	int      outmatrix_numel,outmatrix_ndims;
+	int*     outmatrix_size=NULL;
+
+	if(mxIsEmpty(dataref) ){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outmatrix_numel=0;
+		outmatrix_ndims=0;
+		outmatrix_size =NULL;
+		outmatrix=NULL;
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Check dataref is not pointing to NaN: */
+		if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){
+			outmatrix_numel=0;
+			outmatrix_ndims=0;
+			outmatrix_size =NULL;
+			outmatrix=NULL;
+		}
+		else{
+
+			/*Convert matlab n-dim array to double* matrix: */
+			MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
+		}
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+			
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pnumel)*pnumel=outmatrix_numel;
+	if (pndims)*pndims=outmatrix_ndims;
+	if (psize )*psize =outmatrix_size;
+	else xfree((void**)&outmatrix_size);
+
+}
+/*}}}*/
+/*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{1*/
+void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){
+
+	int     i,outmatrix_rows,outmatrix_cols;
+	double *doublematrix=NULL;
+	int    *outmatrix=NULL;
+
+	if(mxIsEmpty(dataref) ){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outmatrix_rows=0;
+		outmatrix_cols=0;
+		outmatrix=NULL;
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Check dataref is not pointing to NaN: */
+		if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
+			outmatrix_rows=0;
+			outmatrix_cols=0;
+			outmatrix=NULL;
+		}
+		else{
+
+			/*Convert matlab matrix to double* matrix: */
+			MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
+
+			/*Convert double matrix into integer matrix: */
+			outmatrix=(int*)xmalloc(outmatrix_rows*outmatrix_cols*sizeof(int));
+			for(i=0;i<outmatrix_rows*outmatrix_cols;i++)outmatrix[i]=(int)doublematrix[i];
+		}
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pM)*pM=outmatrix_rows;
+	if (pN)*pN=outmatrix_cols;
+}
+/*}}}*/
+/*FUNCTION FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){{{1*/
+void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref){
+
+	int     i,outmatrix_rows,outmatrix_cols;
+	double *doublematrix=NULL;
+	bool   *outmatrix=NULL;
+
+	if(mxIsEmpty(dataref) ){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outmatrix_rows=0;
+		outmatrix_cols=0;
+		outmatrix=NULL;
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Check dataref is not pointing to NaN: */
+		if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetM(dataref)==1) && (mxGetN(dataref)==1) ){
+			outmatrix_rows=0;
+			outmatrix_cols=0;
+			outmatrix=NULL;
+		}
+		else{
+
+			/*Convert matlab matrix to double* matrix: */
+			MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
+
+			/*Convert double matrix into integer matrix: */
+			outmatrix=(bool*)xmalloc(outmatrix_rows*outmatrix_cols*sizeof(bool));
+			for(i=0;i<outmatrix_rows;i++)outmatrix[i]=(bool)doublematrix[i];
+		}
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pM)*pM=outmatrix_rows;
+	if (pN)*pN=outmatrix_cols;
+}
+/*}}}*/
+/*FUNCTION FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{1*/
+void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
+
+	int      i;
+	int      outmatrix_numel,outmatrix_ndims;
+	int*     outmatrix_size=NULL;
+	double*  doublematrix=NULL;
+	bool*    outmatrix=NULL;
+
+	if(mxIsEmpty(dataref) ){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outmatrix_numel=0;
+		outmatrix_ndims=0;
+		outmatrix_size =NULL;
+		outmatrix=NULL;
+	}
+	else if (mxIsClass(dataref,"logical") ){
+
+		/*Check dataref is not pointing to NaN: */
+		if ( mxIsNaN(*((bool*)mxGetData(dataref))) && (mxGetNumberOfElements(dataref)==1) ){
+			outmatrix_numel=0;
+			outmatrix_ndims=0;
+			outmatrix_size =NULL;
+			outmatrix=NULL;
+		}
+		else{
+
+			/*Convert matlab n-dim array to bool* matrix: */
+			MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
+		}
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Check dataref is not pointing to NaN: */
+		if ( mxIsNaN(*(mxGetPr(dataref))) && (mxGetNumberOfElements(dataref)==1) ){
+			outmatrix_numel=0;
+			outmatrix_ndims=0;
+			outmatrix_size =NULL;
+			outmatrix=NULL;
+		}
+		else{
+
+			/*Convert matlab n-dim array to double* matrix: */
+			MatlabNArrayToNArray(&doublematrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
+
+			/*Convert double matrix into bool matrix: */
+			outmatrix=(bool*)xmalloc(outmatrix_numel*sizeof(bool));
+			for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i];
+			xfree((void**)&doublematrix);
+		}
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+			
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pnumel)*pnumel=outmatrix_numel;
+	if (pndims)*pndims=outmatrix_ndims;
+	if (psize )*psize =outmatrix_size;
+	else xfree((void**)&outmatrix_size);
+
+}
+/*}}}*/
+/*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{1*/
+void FetchData(double** pvector,int* pM,const mxArray* dataref){
+
+	double* outvector=NULL;
+	int outvector_rows;
+
+	if(mxIsEmpty(dataref)){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outvector_rows=0;
+		outvector=NULL;
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Convert matlab vector to double*  vector: */
+		MatlabVectorToDoubleVector(&outvector,&outvector_rows,dataref);
+
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+
+	/*Assign output pointers:*/
+	*pvector=outvector;
+	if (pM)*pM=outvector_rows;
+}
+/*}}}*/
+/*FUNCTION FetchData(int** pvector,int* pM,const mxArray* dataref){{{1*/
+void FetchData(int** pvector,int* pM,const mxArray* dataref){
+
+	int    i;
+	double *doublevector   = NULL;
+	int    *outvector      = NULL;
+	int     outvector_rows;
+
+	if(mxIsEmpty(dataref)){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outvector_rows=0;
+		outvector=NULL;
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Convert matlab vector to double*  vector: */
+		MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);
+
+		/*Convert double vector into integer vector: */
+		outvector=(int*)xmalloc(outvector_rows*sizeof(int));
+		for(i=0;i<outvector_rows;i++)outvector[i]=(int)doublevector[i];
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+
+	/*Assign output pointers:*/
+	*pvector=outvector;
+	if (pM)*pM=outvector_rows;
+}
+/*}}}*/
+/*FUNCTION FetchData(bool** pvector,int* pM,const mxArray* dataref){{{1*/
+void FetchData(bool** pvector,int* pM,const mxArray* dataref){
+
+	int    i;
+	double *doublevector   = NULL;
+	bool   *outvector      = NULL;
+	int     outvector_rows;
+
+	if(mxIsEmpty(dataref)){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outvector_rows=0;
+		outvector=NULL;
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Convert matlab vector to double*  vector: */
+		MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);
+
+		/*Convert double vector into integer vector: */
+		outvector=(bool*)xmalloc(outvector_rows*sizeof(bool));
+		for(i=0;i<outvector_rows;i++)outvector[i]=(bool)doublevector[i];
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+
+	/*Assign output pointers:*/
+	*pvector=outvector;
+	if (pM)*pM=outvector_rows;
+}
+/*}}}*/
+/*FUNCTION FetchData(float** pvector,int* pM,const mxArray* dataref){{{1*/
+void FetchData(float** pvector,int* pM,const mxArray* dataref){
+
+	int    i;
+	double *doublevector   = NULL;
+	float  *outvector      = NULL;
+	int     outvector_rows;
+
+	if(mxIsEmpty(dataref)){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outvector_rows=0;
+		outvector=NULL;
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Convert matlab vector to double*  vector: */
+		MatlabVectorToDoubleVector(&doublevector,&outvector_rows,dataref);
+
+		/*Convert double vector into float vector: */
+		outvector=(float*)xmalloc(outvector_rows*sizeof(float));
+		for(i=0;i<outvector_rows;i++)outvector[i]=(float)doublevector[i];
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+
+	/*Assign output pointers:*/
+	*pvector=outvector;
+	if (pM)*pM=outvector_rows;
+}
+/*}}}*/
+/*FUNCTION FetchData(char** pstring,const mxArray* dataref){{{1*/
+void FetchData(char** pstring,const mxArray* dataref){
+
+	char* outstring=NULL;
+
+
+	/*Ok, the string should be coming directly from the matlab workspace: */
+	if (!mxIsClass(dataref,"char")){
+		_error_("input data_type is not a string!");
+	}
+	else{
+		/*Recover the string:*/
+		int stringlen;
+		
+		stringlen = mxGetM(dataref)*mxGetN(dataref)+1;
+		outstring = (char*)xmalloc(sizeof(mxChar)*stringlen);
+		mxGetString(dataref,outstring,stringlen);
+	}
+
+	/*Assign output pointers:*/
+	*pstring=outstring;
+}
+/*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{1*/
+void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
+
+	int      outmatrix_numel,outmatrix_ndims;
+	int*     outmatrix_size=NULL;
+	char*    outmatrix=NULL;
+
+	if(mxIsEmpty(dataref) ){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		outmatrix_numel=0;
+		outmatrix_ndims=0;
+		outmatrix_size =NULL;
+		outmatrix=NULL;
+	}
+	else if (mxIsClass(dataref,"char") ){
+
+		/*Convert matlab n-dim array to char* matrix: */
+		MatlabNArrayToNArray(&outmatrix,&outmatrix_numel,&outmatrix_ndims,&outmatrix_size,dataref);
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+			
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pnumel)*pnumel=outmatrix_numel;
+	if (pndims)*pndims=outmatrix_ndims;
+	if (psize )*psize =outmatrix_size;
+	else xfree((void**)&outmatrix_size);
+
+}
+/*}}}*/
+/*FUNCTION FetchData(double* pscalar,const mxArray* dataref){{{1*/
+void FetchData(double* pscalar,const mxArray* dataref){
+
+	double scalar;
+
+	if (!mxIsClass(dataref,"double")){
+		_error_("input data_type is not a double!");
+	}
+	else{
+		/*Recover the double: */
+		scalar=mxGetScalar(dataref);
+	}
+
+	/*Assign output pointers:*/
+	*pscalar=scalar;
+}
+/*}}}*/
+/*FUNCTION FetchData(int* pinteger,const mxArray* dataref){{{1*/
+void FetchData(int* pinteger,const mxArray* dataref){
+
+	int integer;
+
+	if (!mxIsClass(dataref,"double")){
+		_error_("input data_type is not a scalar!");
+	}
+	else{
+		/*Recover the double: */
+		integer=(int)mxGetScalar(dataref);
+	}
+
+	/*Assign output pointers:*/
+	*pinteger=integer;
+}
+/*}}}*/
+/*FUNCTION FetchData(bool* pboolean,const mxArray* dataref){{{1*/
+void FetchData(bool* pboolean,const mxArray* dataref){
+
+	bool* mxbool_ptr=NULL;
+
+	if (mxIsClass(dataref,"logical")){
+		if(mxGetM(dataref)!=1) _error_("input data is not of size 1x1");
+		if(mxGetN(dataref)!=1) _error_("input data is not of size 1x1");
+		mxbool_ptr=mxGetLogicals(dataref);
+	}
+	else{
+		_error_("input data_type is not a bool!");
+	}
+
+	*pboolean=*mxbool_ptr;
+}
+/*}}}*/
+
+/*ISSM objects*/
+/*FUNCTION FetchData(Matrix** pmatrix,const mxArray* dataref){{{1*/
+void FetchData(Matrix** pmatrix,const mxArray* dataref){
+
+	Matrix* outmatrix=NULL;
+	int dummy=0;
+
+	if (mxIsClass(dataref,"double") ){
+
+		/*Convert matlab matrix to matrix: */
+		outmatrix=MatlabMatrixToMatrix(dataref);
+
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+}
+/*}}}*/
+/*FUNCTION FetchData(Vector** pvector,const mxArray* dataref){{{1*/
+void FetchData(Vector** pvector,const mxArray* dataref){
+
+	Vector* vector=NULL;
+	int dummy;
+
+	if(mxIsEmpty(dataref)){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		vector=new Vector(0);
+	}
+	else if (mxIsClass(dataref,"double") ){
+
+		/*Convert matlab vector to petsc vector: */
+		vector=MatlabVectorToVector(dataref);
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class %s not supported yet",mxGetClassName(dataref));
+	}
+
+	/*Assign output pointers:*/
+	*pvector=vector;
+}
+/*}}}*/
+/*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{1*/
+void FetchData(BamgGeom** pbamggeom,const mxArray* dataref){
+
+	/*Initialize output*/
+	BamgGeom* bamggeom=new BamgGeom();
+
+	/*Fetch all fields*/
+	FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices"));
+	FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges"));
+	FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], mxGetAssignedField(dataref,0,"Corners"));
+	FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],mxGetAssignedField(dataref,0,"RequiredVertices"));
+	FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], mxGetAssignedField(dataref,0,"RequiredEdges"));
+	FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges"));
+	FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],mxGetAssignedField(dataref,0,"SubDomains"));
+
+	/*Assign output pointers:*/
+	*pbamggeom=bamggeom;
+}
+/*}}}*/
+/*FUNCTION FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){{{1*/
+void FetchData(BamgMesh** pbamgmesh,const mxArray* dataref){
+
+	/*Initialize output*/
+	BamgMesh* bamgmesh=new BamgMesh();
+
+	/*Fetch all fields*/
+	FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],mxGetAssignedField(dataref,0,"Vertices"));
+	FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], mxGetAssignedField(dataref,0,"Edges"));
+	FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], mxGetAssignedField(dataref,0,"Triangles"));
+	FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],mxGetAssignedField(dataref,0,"CrackedEdges"));
+	FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomEdge"));
+	FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],mxGetAssignedField(dataref,0,"VerticesOnGeomVertex"));
+	FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], mxGetAssignedField(dataref,0,"EdgesOnGeomEdge"));
+	FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],mxGetAssignedField(dataref,0,"IssmSegments"));
+
+	/*Assign output pointers:*/
+	*pbamgmesh=bamgmesh;
+}
+/*}}}*/
+/*FUNCTION FetchData(BamgOpts** pbamgopts,const mxArray* dataref){{{1*/
+void FetchData(BamgOpts** pbamgopts,const mxArray* dataref){
+
+	/*Initialize output*/
+	BamgOpts* bamgopts=new BamgOpts();
+
+	/*Fetch all fields*/
+	FetchData(&bamgopts->anisomax,mxGetField(dataref,0,"anisomax"));
+	FetchData(&bamgopts->cutoff,mxGetField(dataref,0,"cutoff"));
+	FetchData(&bamgopts->coeff,mxGetField(dataref,0,"coeff"));
+	FetchData(&bamgopts->errg,mxGetField(dataref,0,"errg"));
+	FetchData(&bamgopts->gradation,mxGetField(dataref,0,"gradation"));
+	FetchData(&bamgopts->Hessiantype,mxGetField(dataref,0,"Hessiantype"));
+	FetchData(&bamgopts->MaxCornerAngle,mxGetField(dataref,0,"MaxCornerAngle"));
+	FetchData(&bamgopts->maxnbv,mxGetField(dataref,0,"maxnbv"));
+	FetchData(&bamgopts->maxsubdiv,mxGetField(dataref,0,"maxsubdiv"));
+	FetchData(&bamgopts->Metrictype,mxGetField(dataref,0,"Metrictype"));
+	FetchData(&bamgopts->nbjacobi,mxGetField(dataref,0,"nbjacobi"));
+	FetchData(&bamgopts->nbsmooth,mxGetField(dataref,0,"nbsmooth"));
+	FetchData(&bamgopts->omega,mxGetField(dataref,0,"omega"));
+	FetchData(&bamgopts->power,mxGetField(dataref,0,"power"));
+	FetchData(&bamgopts->verbose,mxGetField(dataref,0,"verbose"));
+
+	FetchData(&bamgopts->Crack,mxGetField(dataref,0,"Crack"));
+	FetchData(&bamgopts->geometricalmetric,mxGetField(dataref,0,"geometricalmetric"));
+	FetchData(&bamgopts->KeepVertices,mxGetField(dataref,0,"KeepVertices"));
+	FetchData(&bamgopts->splitcorners,mxGetField(dataref,0,"splitcorners"));
+
+	FetchData(&bamgopts->hmin,mxGetField(dataref,0,"hmin"));
+	FetchData(&bamgopts->hmax,mxGetField(dataref,0,"hmax"));
+	FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],mxGetField(dataref,0,"hminVertices"));
+	FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],mxGetField(dataref,0,"hmaxVertices"));
+	FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],mxGetField(dataref,0,"hVertices"));
+	FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],mxGetField(dataref,0,"metric"));
+	FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],mxGetField(dataref,0,"field"));
+	FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],mxGetField(dataref,0,"err"));
+
+	/*Additional checks*/
+	bamgopts->Check();
+
+	/*Assign output pointers:*/
+	*pbamgopts=bamgopts;
+}
+/*}}}*/
+/*FUNCTION FetchData(Options** poptions,const mxArray* dataref){{{1*/
+void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref){
+
+	char   *name   = NULL;
+	Option *option = NULL;
+
+	/*Initialize output*/
+	Options* options=new Options();
+
+	/*Fetch all options*/
+	for (int i=istart; i<nrhs; i=i+2){
+		if (!mxIsClass(pdataref[i],"char")) _error_("Argument %d must be name of option",i+1);
+
+		FetchData(&name,pdataref[i]);
+		if(i+1 == nrhs) _error_("Argument %d must exist and be value of option \"%s\".",i+2,name);
+
+		option=(Option*)OptionParse(name,&pdataref[i+1]);
+		options->AddOption(option);
+		option=NULL;
+	}
+
+	/*Assign output pointers:*/
+	*poptions=options;
+}
+/*}}}*/
Index: /issm/trunk/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabMatrixToDoubleMatrix.cpp	(revision 12330)
@@ -0,0 +1,101 @@
+/* \file MatlabMatrixToDoubleMatrix.cpp
+ * \brief: convert a sparse or dense matlab matrix to a double* pointer
+ */
+
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+
+/*Matlab includes: */
+#include "mex.h"
+
+#include "../../shared/shared.h"
+
+int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){
+
+	int     i,j,count,rows,cols;
+	double *pmxdoublematrix = NULL;
+	float  *pmxsinglematrix = NULL;
+
+	/*output: */
+	double* matrix=NULL;
+
+	/*matlab indices: */
+	mwIndex*    ir=NULL;
+	mwIndex*    jc=NULL;
+
+	/*Ok, first check if we are dealing with a sparse or full matrix: */
+	if (mxIsSparse(mxmatrix)){
+
+		/*Dealing with sparse matrix: recover size first: */
+		pmxdoublematrix=(double*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+		
+		if(rows*cols){
+			matrix=(double*)xcalloc(rows*cols,sizeof(double));
+
+			/*Now, get ir,jc and pr: */
+			ir=mxGetIr(mxmatrix);
+			jc=mxGetJc(mxmatrix);
+
+			/*Now, start inserting data into double* matrix: */
+			count=0;
+			for(i=0;i<cols;i++){
+				for(j=0;j<(jc[i+1]-jc[i]);j++){
+					matrix[rows*ir[count]+i]=pmxdoublematrix[count];
+					count++;
+				}
+			}
+		}
+
+	}
+	else if(mxIsClass(mxmatrix,"double")){
+		/*Dealing with dense matrix: recover pointer and size: */
+		pmxdoublematrix=(double*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+		
+		/*Create serial matrix: */
+		if(rows*cols){
+			matrix=(double*)xcalloc(rows*cols,sizeof(double));
+
+			for(i=0;i<rows;i++){
+				for(j=0;j<cols;j++){
+					matrix[cols*i+j]=(double)pmxdoublematrix[rows*j+i];
+				}
+			}
+		}
+	}
+	else if(mxIsClass(mxmatrix,"single")){
+		/*Dealing with dense matrix: recover pointer and size: */
+		pmxsinglematrix=(float*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+
+		/*Create serial matrix: */
+		if(rows*cols){
+			matrix=(double*)xcalloc(rows*cols,sizeof(double));
+
+			for(i=0;i<rows;i++){
+				for(j=0;j<cols;j++){
+					matrix[cols*i+j]=(double)pmxsinglematrix[rows*j+i];
+				}
+			}
+		}
+	}
+	else{
+		_error_("Matlab matrix type Not implemented yet");
+	}
+
+	/*Assign output pointer: */
+	*pmatrix=matrix;
+	*pmatrix_rows=rows;
+	*pmatrix_cols=cols;
+
+	return 1;
+}
Index: /issm/trunk/src/c/matlab/io/MatlabMatrixToMatrix.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabMatrixToMatrix.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabMatrixToMatrix.cpp	(revision 12330)
@@ -0,0 +1,39 @@
+/*!\file MatlabMatrixToMatrix.cpp
+ */
+
+/*Headers:*/
+/*{{{1*/
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <mex.h>
+#include <stdio.h>
+#include <string.h>
+#include "./matlabio.h"
+#include "../../objects/objects.h"
+#include "../../shared/shared.h"
+#include "../../Container/Container.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+	
+/*}}}*/
+
+Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix){
+
+	int dummy;
+	Matrix* matrix=NULL;
+
+	/*allocate matrix object: */
+	matrix=new Matrix();
+
+	#ifdef _HAVE_PETSC_
+	MatlabMatrixToPetscMatrix(&matrix->matrix,NULL,NULL,mxmatrix);
+	#else
+	matrix->matrix=MatlabMatrixToSeqMat(mxmatrix);
+	#endif
+	
+	return matrix;
+}
Index: /issm/trunk/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabMatrixToPetscMatrix.cpp	(revision 12330)
@@ -0,0 +1,120 @@
+/* \file MatlabMatrixToPetscMatrix.cpp
+ * \brief: convert a sparse or dense matlab matrix to a serial Petsc matrix:
+ */
+
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+
+/*Petsc includes: */
+#include "petscmat.h"
+#include "petscvec.h"
+#include "petscksp.h"
+
+/*Matlab includes: */
+#include "mex.h"
+
+#include "../../shared/shared.h"
+
+int MatlabMatrixToPetscMatrix(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){
+
+	int rows, cols;
+	double* mxmatrix_ptr=NULL;
+	double* tmatrix=NULL;
+	int ierr;
+	int i,j;
+
+	/*output: */
+	Mat matrix=NULL;
+
+	/*matlab indices: */
+	mwIndex*    ir=NULL;
+	mwIndex*    jc=NULL;
+	double* pr=NULL;
+	int     count;
+	int     nnz;
+	int     nz;
+
+	/*petsc indices: */
+	int* idxm=NULL;
+	int* idxn=NULL;
+	
+	/*Ok, first check if we are dealing with a sparse or full matrix: */
+	if (mxIsSparse(mxmatrix)){
+
+		/*Dealing with sparse matrix: recover size first: */
+		mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+		nnz=mxGetNzmax(mxmatrix);
+		if(rows){
+			nz=(int)((double)nnz/(double)rows);
+		}
+		else{
+			nz=0;
+		}
+
+		ierr=MatCreateSeqAIJ(PETSC_COMM_SELF,rows,cols,nz,PETSC_NULL,&matrix);CHKERRQ(ierr);
+
+		/*Now, get ir,jc and pr: */
+		pr=mxGetPr(mxmatrix);
+		ir=mxGetIr(mxmatrix);
+		jc=mxGetJc(mxmatrix);
+
+		/*Now, start inserting data into sparse matrix: */
+		count=0;
+		for(i=0;i<cols;i++){
+			for(j=0;j<(jc[i+1]-jc[i]);j++){
+				MatSetValue(matrix,ir[count],i,pr[count],INSERT_VALUES);
+				count++;
+			}
+		}
+
+	}
+	else{
+
+		/*Dealing with dense matrix: recover pointer and size: */
+		mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+
+		/*transpose, as Petsc now does not allows MAT_COLUMN_ORIENTED matrices in MatSetValues: */
+		tmatrix=(double*)xmalloc(rows*cols*sizeof(double));
+		for(i=0;i<cols;i++){
+			for(j=0;j<rows;j++){
+				*(tmatrix+rows*i+j)=*(mxmatrix_ptr+cols*j+i);
+			}
+		}
+
+		/*Create serial matrix: */
+		ierr=MatCreateSeqDense(PETSC_COMM_SELF,rows,cols,NULL,&matrix);CHKERRQ(ierr);
+
+		/*Insert mxmatrix_ptr values into petsc matrix: */
+		idxm=(int*)xmalloc(rows*sizeof(int));
+		idxn=(int*)xmalloc(cols*sizeof(int));
+
+		for(i=0;i<rows;i++)idxm[i]=i;
+		for(i=0;i<cols;i++)idxn[i]=i;
+
+		ierr=MatSetValues(matrix,rows,idxm,cols,idxn,tmatrix,INSERT_VALUES); CHKERRQ(ierr);
+
+		xfree((void**)&tmatrix);
+
+	}
+
+	/*Assemble matrix: */
+	MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY); 
+	MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY);
+
+
+	/*Assign output pointer: */
+	*pmatrix=matrix;
+	if(pmatrix_rows) *pmatrix_rows=rows;
+	if(pmatrix_cols) *pmatrix_cols=cols;
+
+	return 1;
+}
Index: /issm/trunk/src/c/matlab/io/MatlabMatrixToSeqMat.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabMatrixToSeqMat.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabMatrixToSeqMat.cpp	(revision 12330)
@@ -0,0 +1,29 @@
+/*!\file MatlabMatrixToSeqMat.cpp
+ */
+
+/*Headers:*/
+/*{{{1*/
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <mex.h>
+#include <stdio.h>
+#include <string.h>
+#include "../../toolkits/toolkits.h"
+#include "../../shared/shared.h"
+#include "./matlabio.h"
+
+/*}}}*/
+
+SeqMat* MatlabMatrixToSeqMat(const mxArray* dataref){
+
+	SeqMat* output=NULL;
+
+	output=new SeqMat();
+	MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref);
+	return output;
+
+}
Index: /issm/trunk/src/c/matlab/io/MatlabNArrayToNArray.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabNArrayToNArray.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabNArrayToNArray.cpp	(revision 12330)
@@ -0,0 +1,272 @@
+/* \file MatlabNArrayToNArray.cpp
+ * \brief: convert a sparse or dense matlab n-dimensional array to cpp n-dimensional array
+ */
+
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+
+#include <mex.h>
+
+/*FUNCTION MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{1*/
+int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){
+
+	int  i,j,rows,cols;
+	int  numel,ndims;
+	int *size,*dims;
+	double* mxmatrix_ptr=NULL;
+	const mwSize* ipt=NULL;
+
+	/*output: */
+	double* matrix=NULL;
+
+	/*matlab indices: */
+	mwIndex*    ir=NULL;
+	mwIndex*    jc=NULL;
+	double* pr=NULL;
+	int     count;
+	int     nnz;
+	int     nz;
+
+	/*get Matlab matrix information: */
+	numel=mxGetNumberOfElements(mxmatrix);
+	ndims=mxGetNumberOfDimensions(mxmatrix);
+	ipt  =mxGetDimensions(mxmatrix);
+	size =(int *) xcalloc(ndims,sizeof(int));
+	for (i=0; i<ndims; i++) size[i]=(int)ipt[i];
+
+	/*Ok, first check if we are dealing with a sparse or full matrix: */
+	if (mxIsSparse(mxmatrix)){
+
+		/*Dealing with sparse matrix: recover size first: */
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+		nnz=mxGetNzmax(mxmatrix);
+		nz=(int)((double)nnz/(double)rows);
+
+		matrix=(double*)xcalloc(rows*cols,sizeof(double));
+
+		/*Now, get ir,jc and pr: */
+		ir=mxGetIr(mxmatrix);
+		jc=mxGetJc(mxmatrix);
+		pr=mxGetPr(mxmatrix);
+
+		/*Now, start inserting data into double* matrix: */
+		count=0;
+		for(i=0;i<cols;i++){
+			for(j=0;j<(jc[i+1]-jc[i]);j++){
+				*(matrix+rows*ir[count]+i)=pr[count];
+				count++;
+			}
+		}
+
+	}
+	else{
+
+		/*Dealing with dense matrix: recover pointer and size: */
+		mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
+		
+		/*Create serial matrix: */
+		matrix=(double*)xcalloc(numel,sizeof(double));
+
+		dims=(int *) xcalloc(ndims,sizeof(int));
+		for(i=0;i<numel;i++){
+			ColumnWiseDimsFromIndex(dims,i,size,ndims);
+			j=IndexFromRowWiseDims(dims,size,ndims);
+			*(matrix+j)=*(mxmatrix_ptr+i);
+		}
+		xfree((void**)&dims);
+		
+	}
+
+	/*Assign output pointer: */
+	*pmatrix=matrix;
+	*pmatrix_numel=numel;
+	*pmatrix_ndims=ndims;
+	*pmatrix_size=size;
+
+	return 1;
+}
+/*}}}*/
+/*FUNCTION MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{1*/
+int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){
+
+	int  i,j,rows,cols;
+	int  numel,ndims;
+	int *size,*dims;
+	bool* mxmatrix_ptr=NULL;
+	const mwSize* ipt=NULL;
+
+	/*output: */
+	bool* matrix=NULL;
+
+	/*matlab indices: */
+	mwIndex*    ir=NULL;
+	mwIndex*    jc=NULL;
+	bool*   pm=NULL;
+	int     count;
+	int     nnz;
+	int     nz;
+
+	/*get Matlab matrix information: */
+	numel=mxGetNumberOfElements(mxmatrix);
+	ndims=mxGetNumberOfDimensions(mxmatrix);
+	ipt  =mxGetDimensions(mxmatrix);
+	size =(int *) xcalloc(ndims,sizeof(int));
+	for (i=0; i<ndims; i++) size[i]=(int)ipt[i];
+
+	/*Ok, first check if we are dealing with a sparse or full matrix: */
+	if (mxIsSparse(mxmatrix)){
+
+		/*Dealing with sparse matrix: recover size first: */
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+		nnz=mxGetNzmax(mxmatrix);
+		nz=(int)((double)nnz/(double)rows);
+
+		matrix=(bool*)xcalloc(rows*cols,sizeof(bool));
+
+		/*Now, get ir,jc and pm: */
+		ir=mxGetIr(mxmatrix);
+		jc=mxGetJc(mxmatrix);
+		pm=(bool*)mxGetData(mxmatrix);
+
+		/*Now, start inserting data into bool* matrix: */
+		count=0;
+		for(i=0;i<cols;i++){
+			for(j=0;j<(jc[i+1]-jc[i]);j++){
+				*(matrix+rows*ir[count]+i)=pm[count];
+				count++;
+			}
+		}
+
+	}
+	else{
+
+		/*Dealing with dense matrix: recover pointer and size: */
+		mxmatrix_ptr=(bool*)mxGetData(mxmatrix);
+		
+		/*Create serial matrix: */
+		matrix=(bool*)xcalloc(numel,sizeof(bool));
+
+		dims=(int *) xcalloc(ndims,sizeof(int));
+		for(i=0;i<numel;i++){
+			ColumnWiseDimsFromIndex(dims,i,size,ndims);
+			j=IndexFromRowWiseDims(dims,size,ndims);
+			*(matrix+j)=(bool)*(mxmatrix_ptr+i);
+		}
+		xfree((void**)&dims);
+		
+	}
+
+	/*Assign output pointer: */
+	*pmatrix=matrix;
+	*pmatrix_numel=numel;
+	*pmatrix_ndims=ndims;
+	*pmatrix_size=size;
+
+	return 1;
+}
+/*}}}*/
+/*FUNCTION MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{1*/
+int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){
+
+	int  i,j,rows,cols;
+	int  numel,ndims;
+	int *size,*dims;
+	mxChar* mxmatrix_ptr=NULL;
+	const mwSize* ipt=NULL;
+
+	/*output: */
+	char* matrix=NULL;
+
+	/*matlab indices: */
+	mwIndex*    ir=NULL;
+	mwIndex*    jc=NULL;
+	char*   pm=NULL;
+	int     count;
+	int     nnz;
+	int     nz;
+
+	/*get Matlab matrix information: */
+	numel=mxGetNumberOfElements(mxmatrix);
+	ndims=mxGetNumberOfDimensions(mxmatrix);
+	ipt  =mxGetDimensions(mxmatrix);
+	size =(int *) xcalloc(ndims,sizeof(int));
+	for (i=0; i<ndims; i++) size[i]=(int)ipt[i];
+
+	/*Ok, first check if we are dealing with a sparse or full matrix: */
+	if (mxIsSparse(mxmatrix)){
+
+		/*Dealing with sparse matrix: recover size first: */
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+		nnz=mxGetNzmax(mxmatrix);
+		nz=(int)((double)nnz/(double)rows);
+
+		matrix=(char*)xcalloc(rows*cols,sizeof(double));
+
+		/*Now, get ir,jc and pm: */
+		ir=mxGetIr(mxmatrix);
+		jc=mxGetJc(mxmatrix);
+		pm=(char*)mxGetData(mxmatrix);
+
+		/*Now, start inserting data into char* matrix: */
+		count=0;
+		for(i=0;i<cols;i++){
+			for(j=0;j<(jc[i+1]-jc[i]);j++){
+				*(matrix+rows*ir[count]+i)=(char)pm[count];
+				count++;
+			}
+		}
+
+	}
+	else{
+
+		/*Dealing with dense matrix: recover pointer and size: */
+		mxmatrix_ptr=mxGetChars(mxmatrix);
+		
+		/*Create serial matrix: */
+		matrix=(char*)xcalloc(numel+1,sizeof(mxChar));
+
+		/*looping code adapted from Matlab example explore.c: */
+		int elements_per_page = size[0] * size[1];
+		/* total_number_of_pages = size[2] x size[3] x ... x size[N-1] */
+		int total_number_of_pages = 1;
+		for (i=2; i<ndims; i++) {
+			total_number_of_pages *= size[i];
+		}
+
+		i=0;
+		for (int page=0; page < total_number_of_pages; page++) {
+			int row;
+			/* On each page, walk through each row. */
+			for (row=0; row<size[0]; row++)  {
+				int column;
+				j = (page * elements_per_page) + row;
+
+				/* Walk along each column in the current row. */
+				for (column=0; column<size[1]; column++) {
+					*(matrix+i++)=(char)*(mxmatrix_ptr+j);
+					j += size[0];
+				}
+			}
+		}
+
+	}
+
+	/*Assign output pointer: */
+	*pmatrix=matrix;
+	*pmatrix_numel=numel;
+	*pmatrix_ndims=ndims;
+	*pmatrix_size=size;
+
+	return 1;
+}
+/*}}}*/
Index: /issm/trunk/src/c/matlab/io/MatlabVectorToDoubleVector.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabVectorToDoubleVector.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabVectorToDoubleVector.cpp	(revision 12330)
@@ -0,0 +1,96 @@
+/* \file MatlabVectorToDoubleVector.cpp
+ * \brief: convert a sparse or dense matlab vector to a serial vector:
+ */
+
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+
+#include <string.h>
+
+/*Matlab includes: */
+#include "mex.h"
+
+#include "../../shared/shared.h"
+
+int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector){
+
+	int rows,cols;
+	double* mxvector_ptr=NULL;
+	int ierr;
+	int i,j;
+
+	/*output: */
+	double* vector=NULL;
+
+	/*matlab indices: */
+	mwIndex*    ir=NULL;
+	mwIndex*    jc=NULL;
+	double* pr=NULL;
+	int     count;
+	int     nnz;
+	int     nz;
+
+	/*Ok, first check if we are dealing with a sparse or full vector: */
+	if (mxIsSparse(mxvector)){
+
+		/*Dealing with sparse vector: recover size first: */
+		mxvector_ptr=(double*)mxGetPr(mxvector);
+		rows=mxGetM(mxvector);
+		cols=mxGetN(mxvector);
+		nnz=mxGetNzmax(mxvector);
+		
+		/*Check that input is actualy a vector*/
+		if (cols!=1) _error_("input vector of size %ix%i should have only one column",rows,cols);
+
+		nz=(int)((double)nnz/(double)rows);
+
+		if(rows){
+			vector=(double*)xcalloc(rows,sizeof(double));
+
+			/*Now, get ir,jc and pr: */
+			pr=mxGetPr(mxvector);
+			ir=mxGetIr(mxvector);
+			jc=mxGetJc(mxvector);
+
+			/*Now, start inserting data into sparse vector: */
+			count=0;
+			for(i=0;i<cols;i++){
+				for(j=0;j<(jc[i+1]-jc[i]);j++){
+					vector[ir[count]]=pr[count];
+					count++;
+				}
+			}
+		}
+
+	}
+	else{
+
+		/*Dealing with dense vector: recover pointer and size: */
+		mxvector_ptr=(double*)mxGetPr(mxvector);
+		rows=mxGetM(mxvector);
+		cols=mxGetN(mxvector);
+
+		/*Check that input is actualy a vector*/
+		if (cols!=1) _error_("input vector of size %ix%i should have only one column",rows,cols);
+
+		/*allocate and memcpy*/
+		if(rows){
+			vector=(double*)xmalloc(rows*sizeof(double));
+			memcpy(vector,mxvector_ptr,rows*sizeof(double));
+		}
+		else{
+			vector=NULL;
+		}
+	}
+
+	/*Assign output pointer: */
+	*pvector=vector;
+	*pvector_rows=rows;
+
+	return 1;
+}
Index: /issm/trunk/src/c/matlab/io/MatlabVectorToPetscVector.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabVectorToPetscVector.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabVectorToPetscVector.cpp	(revision 12330)
@@ -0,0 +1,98 @@
+/* \file MatlabVectorToPetscVector.cpp
+ * \brief: convert a sparse or dense matlab vector to a serial Petsc vector:
+ */
+
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+/*Petsc includes: */
+#include "petscmat.h"
+#include "petscvec.h"
+#include "petscksp.h"
+
+/*Matlab includes: */
+#include "mex.h"
+
+#include "../../shared/shared.h"
+
+int MatlabVectorToPetscVector(Vec* pvector,int* pvector_rows,const mxArray* mxvector){
+
+	int rows, cols;
+	double* mxvector_ptr=NULL;
+	int ierr;
+	int i,j;
+
+	/*output: */
+	Vec vector=NULL;
+
+	/*matlab indices: */
+	mwIndex*    ir=NULL;
+	mwIndex*    jc=NULL;
+	double* pr=NULL;
+	int     count;
+	int     nnz;
+	int     nz;
+
+	/*petsc indices: */
+	int* idxm=NULL;
+	
+	/*Ok, first check if we are dealing with a sparse or full vector: */
+	if (mxIsSparse(mxvector)){
+
+		/*Dealing with sparse vector: recover size first: */
+		mxvector_ptr=(double*)mxGetPr(mxvector);
+		rows=mxGetM(mxvector);
+		cols=mxGetN(mxvector);
+		nnz=mxGetNzmax(mxvector);
+		nz=(int)((double)nnz/(double)rows);
+
+		ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr);
+
+		/*Now, get ir,jc and pr: */
+		pr=mxGetPr(mxvector);
+		ir=mxGetIr(mxvector);
+		jc=mxGetJc(mxvector);
+
+		/*Now, start inserting data into sparse vector: */
+		count=0;
+		for(i=0;i<cols;i++){
+			for(j=0;j<(jc[i+1]-jc[i]);j++){
+				VecSetValue(vector,ir[count],pr[count],INSERT_VALUES);
+				count++;
+			}
+		}
+
+	}
+	else{
+
+		/*Dealing with dense vector: recover pointer and size: */
+		mxvector_ptr=(double*)mxGetPr(mxvector);
+		rows=mxGetM(mxvector);
+		cols=mxGetN(mxvector);
+
+		/*Create serial vector: */
+		ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr);
+
+		/*Insert mxvector_ptr values into petsc vector: */
+		idxm=(int*)xmalloc(rows*sizeof(int));
+
+		for(i=0;i<rows;i++)idxm[i]=i;
+
+		ierr=VecSetValues(vector,rows,idxm,mxvector_ptr,INSERT_VALUES);CHKERRQ(ierr);
+
+	}
+
+	/*Assemble vector: */
+	VecAssemblyBegin(vector);
+	VecAssemblyEnd(vector);
+
+	/*Assign output pointer: */
+	*pvector=vector;
+	*pvector_rows=rows;
+
+	return 1;
+}
Index: /issm/trunk/src/c/matlab/io/MatlabVectorToSeqVec.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabVectorToSeqVec.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabVectorToSeqVec.cpp	(revision 12330)
@@ -0,0 +1,29 @@
+/*!\file MatlabVectorToSeqVec.cpp
+ */
+
+/*Headers:*/
+/*{{{1*/
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <mex.h>
+#include <stdio.h>
+#include <string.h>
+#include "../../toolkits/toolkits.h"
+#include "../../shared/shared.h"
+#include "./matlabio.h"
+
+/*}}}*/
+
+SeqVec* MatlabVectorToSeqVec(const mxArray* dataref){
+
+	SeqVec* output=NULL;
+
+	output=new SeqVec();
+	MatlabVectorToDoubleVector(&output->vector,&output->M,dataref);
+	return output;
+
+}
Index: /issm/trunk/src/c/matlab/io/MatlabVectorToVector.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/MatlabVectorToVector.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/MatlabVectorToVector.cpp	(revision 12330)
@@ -0,0 +1,39 @@
+/*!\file MatlabVectorToVector.cpp
+ */
+
+/*Headers:*/
+/*{{{1*/
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <mex.h>
+#include <stdio.h>
+#include <string.h>
+#include "./matlabio.h"
+#include "../../objects/objects.h"
+#include "../../shared/shared.h"
+#include "../../Container/Container.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+	
+/*}}}*/
+
+Vector* MatlabVectorToVector(const mxArray* mxvector){
+
+	int dummy;
+	Vector* vector=NULL;
+
+	/*allocate vector object: */
+	vector=new Vector();
+
+	#ifdef _HAVE_PETSC_
+	MatlabVectorToPetscVector(&vector->vector,&dummy,mxvector);
+	#else
+	vector->vector=MatlabVectorToSeqVec(mxvector);
+	#endif
+	
+	return vector;
+}
Index: /issm/trunk/src/c/matlab/io/OptionParse.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/OptionParse.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/OptionParse.cpp	(revision 12330)
@@ -0,0 +1,191 @@
+/*\file OptionParse.c
+ *\brief: functions to parse the mex options.
+ */
+#ifdef HAVE_CONFIG_H
+    #include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "../../shared/shared.h"
+#include "../../io/io.h"
+#include "../../include/include.h"
+#include "./matlabio.h"
+
+#include <mex.h>
+
+/*FUNCTION OptionDoubleParse {{{1*/
+OptionDouble* OptionDoubleParse( char* name, const mxArray* prhs[]){
+
+	OptionDouble *odouble = NULL;
+
+	/*check and parse the name  */
+	odouble=new OptionDouble;
+	odouble->name =(char *) xmalloc((strlen(name)+1)*sizeof(char));
+	memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"double")){
+		_error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",odouble->name,"double",odouble->name,mxGetClassName(prhs[0]));
+	}
+
+	FetchData(&odouble->values,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]);
+
+	return(odouble);
+}/*}}}*/
+/*FUNCTION OptionLogicalParse {{{1*/
+OptionLogical* OptionLogicalParse( char* name, const mxArray* prhs[]){
+
+	OptionLogical *ological = NULL;
+
+	/*check and parse the name  */
+	ological=new OptionLogical;
+	ological->name =(char*)xmalloc((strlen(name)+1)*sizeof(char));
+	memcpy(ological->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"logical")){
+		_error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ological->name,"logical",ological->name,mxGetClassName(prhs[0]));
+	}
+
+	FetchData(&ological->values,&ological->numel,&ological->ndims,&ological->size,prhs[0]);
+
+	return(ological);
+}/*}}}*/
+/*FUNCTION OptionCharParse {{{1*/
+OptionChar* OptionCharParse( char* name, const mxArray* prhs[]){
+
+	OptionChar  *ochar = NULL;
+
+	/*check and parse the name  */
+	ochar=new OptionChar();
+	ochar->name =(char*)xmalloc((strlen(name)+1)*sizeof(char));
+	memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"char")){
+		_error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ochar->name,"char",ochar->name,mxGetClassName(prhs[0]));
+	}
+
+	FetchData(&ochar->values,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]);
+
+	return(ochar);
+}/*}}}*/
+/*FUNCTION OptionStructParse {{{1*/
+OptionStruct* OptionStructParse( char* name, const mxArray* prhs[]){
+
+	int            i;
+	char           namei[161];
+	OptionStruct  *ostruct    = NULL;
+	Option        *option     = NULL;
+	const mwSize  *ipt        = NULL;
+	const mxArray *structi;
+	mwIndex        sindex;
+
+	/*check and parse the name  */
+	ostruct=new OptionStruct;
+	ostruct->name =(char*)xmalloc((strlen(name)+1)*sizeof(char));
+	memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"struct")){
+		_error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ostruct->name,"struct",ostruct->name,mxGetClassName(prhs[0]));
+	}
+
+	ostruct->numel=mxGetNumberOfElements(prhs[0]);
+	ostruct->ndims=mxGetNumberOfDimensions(prhs[0]);
+	ipt           =mxGetDimensions(prhs[0]);
+	ostruct->size =(int *) xmalloc(ostruct->ndims*sizeof(int));
+	for (i=0; i<ostruct->ndims; i++) ostruct->size[i]=(int)ipt[i];
+	if (ostruct->numel) ostruct->values=(Options**) xmalloc(ostruct->numel*sizeof(Options *));
+
+	/*loop through and process each element of the struct array  */
+	for (sindex=0; sindex<ostruct->numel; sindex++) {
+		ostruct->values[sindex]=new Options;
+
+		/*loop through and process each field for the element  */
+		for (i=0; i<mxGetNumberOfFields(prhs[0]); i++) {
+			sprintf(namei,"%s.%s",name,mxGetFieldNameByNumber(prhs[0],i));
+			structi=mxGetFieldByNumber(prhs[0],sindex,i);
+
+			option=(Option*)OptionParse(namei,&structi);
+			ostruct->values[sindex]->AddObject((Object*)option);
+			option=NULL;
+		}
+	}
+
+	return(ostruct);
+}/*}}}*/
+/*FUNCTION OptionCellParse {{{1*/
+OptionCell* OptionCellParse( char* name, const mxArray* prhs[]){
+
+	int            i;
+	int           *dims;
+	char           namei[161];
+	char           cstr[81];
+	OptionCell    *ocell      = NULL;
+	Option        *option     = NULL;
+	const mwSize  *ipt        = NULL;
+	const mxArray *celli;
+	mwIndex        cindex;
+
+	/*check and parse the name  */
+	ocell=new OptionCell;
+	ocell->name =(char *) xmalloc((strlen(name)+1)*sizeof(char));
+	memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"cell")){
+		_error_("Value of option \"%s\" must be class \"%s\", not class \"%s\".",ocell->name,"cell",ocell->name,mxGetClassName(prhs[0]));
+	}
+
+	ocell->numel=mxGetNumberOfElements(prhs[0]);
+	ocell->ndims=mxGetNumberOfDimensions(prhs[0]);
+	ipt         =mxGetDimensions(prhs[0]);
+	ocell->size =(int *) xmalloc(ocell->ndims*sizeof(int));
+	for (i=0; i<ocell->ndims; i++) ocell->size[i]=(int)ipt[i];
+	ocell->values=new Options;
+
+	/*loop through and process each element of the cell array  */
+	dims=(int *) xmalloc(ocell->ndims*sizeof(int));
+	for (cindex=0; cindex<ocell->numel; cindex++) {
+		ColumnWiseDimsFromIndex(dims,(int)cindex,ocell->size,ocell->ndims);
+		StringFromDims(cstr,dims,ocell->ndims);
+		#ifdef _INTEL_WIN_
+			_snprintf(namei,161,"%s%s",name,cstr);
+		#else
+			snprintf(namei,161,"%s%s",name,cstr);
+		#endif
+		celli=mxGetCell(prhs[0],cindex);
+
+		option=(Option*)OptionParse(namei,&celli);
+		ocell->values->AddObject((Object*)option);
+		option=NULL;
+	}
+	xfree((void**)&dims);
+
+	return(ocell);
+}/*}}}*/
+/*FUNCTION OptionParse{{{1*/
+Option* OptionParse(char* name, const mxArray* prhs[]){
+
+	Option *option = NULL;
+	mxArray       *lhs[1];
+
+	/*parse the value according to the matlab data type  */
+	if     (mxIsClass(prhs[0],"double"))  option=(Option*)OptionDoubleParse(name,prhs);
+	else if(mxIsClass(prhs[0],"logical")) option=(Option*)OptionLogicalParse(name,prhs);
+	else if(mxIsClass(prhs[0],"char"))    option=(Option*)OptionCharParse(name,prhs);
+	else if(mxIsClass(prhs[0],"struct"))  option=(Option*)OptionStructParse(name,prhs);
+	else if(mxIsClass(prhs[0],"cell"))    option=(Option*)OptionCellParse(name,prhs);
+	else {
+		_printf_(true,"  Converting value of option \"%s\" from unrecognized class \"%s\" to class \"%s\".\n",name,mxGetClassName(prhs[0]),"struct");
+		if (!mexCallMATLAB(1,lhs,1,(mxArray**)prhs,"struct")) {
+			option=(Option*)OptionStructParse(name,(const mxArray**)lhs);
+			mxDestroyArray(lhs[0]);
+		}
+		else _error_("Second argument value of option \"%s\" is of unrecognized class \"%s\".",name,mxGetClassName(prhs[0]));
+	}
+
+	return(option);
+}/*}}}*/
Index: /issm/trunk/src/c/matlab/io/PrintfFunction.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/PrintfFunction.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/PrintfFunction.cpp	(revision 12330)
@@ -0,0 +1,58 @@
+/*\file PrintfFunction.c
+ *\brief: this function is used by the _printf_ macro, to take into account the 
+ *fact we may be running on a cluster. 
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+
+#include "mex.h"
+
+int PrintfFunction(char* format,...){
+	/*http://linux.die.net/man/3/vsnprintf*/
+
+	/*string to be printed: */
+	char *buffer = NULL;
+	int   n,size = 100;
+	int         string_size;
+	extern int  my_rank;
+	extern int  num_procs;
+                                                                                                                                                                                                     
+	//variable list of arguments
+	va_list args;
+
+	while(true){
+
+		/*allocate buffer for given string size*/
+		buffer=(char*)xmalloc(size*sizeof(char));
+
+		/* Try to print in the allocated space. */
+		va_start(args, format);
+#ifndef WIN32
+		n=vsnprintf(buffer,size,format,args);
+#else
+		n=vsnprintf(buffer,size,format,args);
+#endif
+		va_end(args);
+
+		/* If that worked, return the string. */
+		if(n>-1 && n<size) break;
+
+		/* Else try again with more space. */
+		if(n>-1)   /* glibc 2.1 */
+		 size=n+1; /* precisely what is needed */
+		else       /* glibc 2.0 */
+		 size*=2;  /* twice the old size */
+
+		xfree((void**)&buffer);
+	}
+
+	/*Ok, if we are running in parallel, get node 0 to print*/
+	if(my_rank==0)printf(buffer);
+
+	/*Clean up and return*/
+	xfree((void**)&buffer);
+	return 1;
+}
Index: /issm/trunk/src/c/matlab/io/WriteMatlabData.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/WriteMatlabData.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/WriteMatlabData.cpp	(revision 12330)
@@ -0,0 +1,310 @@
+/* \file WriteData.c:
+ * \brief: general interface for writing data
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "../../include/include.h"
+#include "../../shared/shared.h"
+#include "./matlabio.h"
+
+#include <mex.h>
+
+
+/*Primitive data types*/
+/*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{1*/
+void WriteData(mxArray** pdataref,double* matrix, int M,int N){
+
+	mxArray *dataref  = NULL;
+	double  *tmatrix  = NULL;
+		
+	if(matrix){
+		/*create the matlab matrixwith Matlab's memory manager */   
+		tmatrix=(double*)mxMalloc(M*N*sizeof(double));
+		for(int i=0;i<M;i++){
+			for(int j=0;j<N;j++){
+				tmatrix[j*M+i]=matrix[i*N+j];
+			}
+		}
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+		mxSetM(dataref,(mwSize)M);
+		mxSetN(dataref,(mwSize)N);
+		mxSetPr(dataref,(double*)tmatrix);
+	}
+	else{
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+	}
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,int* matrix, int M,int N){{{1*/
+void WriteData(mxArray** pdataref,int* matrix, int M,int N){
+
+	mxArray* dataref = NULL;
+	double*  tmatrix = NULL;
+
+	if(matrix){
+		/*convert to double matrix using Matlab's memory manager*/
+		double* tmatrix=(double*)mxMalloc(M*N*sizeof(double));
+		for(int i=0;i<M;i++){
+			for(int j=0;j<N;j++){
+				tmatrix[j*M+i]=(double)matrix[i*N+j];
+			}
+		}
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+		mxSetM(dataref,(mwSize)M);
+		mxSetN(dataref,(mwSize)N);
+		mxSetPr(dataref,(double*)tmatrix);
+	}
+	else{
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+	}
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,double* vector, int M){{{1*/
+void WriteData(mxArray** pdataref,double* vector, int M){
+	
+	mxArray* dataref       = NULL;
+	double*  vector_matlab = NULL;
+
+	if(vector){
+
+		/*create the matlab vector with Matlab's memory manager */
+		vector_matlab=(double*)mxMalloc(M*sizeof(double));
+		for(int i=0;i<M;i++) vector_matlab[i]=vector[i];
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+		mxSetM(dataref,(mwSize)M);
+		mxSetN(dataref,(mwSize)1);
+		mxSetPr(dataref,vector_matlab);
+	}
+	else{
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+	}
+
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,double scalar){{{1*/
+void WriteData(mxArray** pdataref,double scalar){
+
+	*pdataref=mxCreateDoubleScalar(scalar);
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,int integer){{{1*/
+void WriteData(mxArray** pdataref,int integer){
+
+		*pdataref=mxCreateDoubleScalar((double)integer);
+
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,int boolean){{{1*/
+void WriteData(mxArray** pdataref,bool boolean){
+
+	*pdataref=mxCreateDoubleScalar((double)boolean);
+
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,char* string){{{1*/
+void WriteData(mxArray** pdataref,char* string){
+
+		*pdataref=mxCreateString(string);
+}
+/*}}}*/
+
+/*ISSM objects*/
+/*FUNCTION WriteData(mxArray** pdataref,BamgGeom* bamggeom){{{1*/
+void WriteData(mxArray** pdataref,BamgGeom* bamggeom){
+
+	/*Intermediary*/
+	int         i;
+	mxArray    *dataref           = NULL;
+	const int   numfields         = 7;
+	const char *fnames[numfields];
+	mwSize      ndim              = 2;
+	mwSize      dimensions[2]     = {1,1};
+
+	/*Initialize field names*/
+	i=0;
+	fnames[i++] = "Vertices";
+	fnames[i++] = "Edges";
+	fnames[i++] = "TangentAtEdges";
+	fnames[i++] = "RequiredVertices";
+	fnames[i++] = "RequiredEdges";
+	fnames[i++] = "CrackedEdges";
+	fnames[i++] = "SubDomains";
+	_assert_(i==numfields);
+
+	/*Initialize Matlab structure*/
+	dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames);
+
+	/*set each matlab each field*/
+	i=0;
+	i++; SetStructureField(dataref,"Vertices",        bamggeom->VerticesSize[0],        bamggeom->VerticesSize[1],        bamggeom->Vertices);
+	i++; SetStructureField(dataref,"Edges",           bamggeom->EdgesSize[0],           bamggeom->EdgesSize[1],           bamggeom->Edges);
+	i++; SetStructureField(dataref,"TangentAtEdges",  bamggeom->TangentAtEdgesSize[0],  bamggeom->TangentAtEdgesSize[1],  bamggeom->TangentAtEdges);
+	i++; SetStructureField(dataref,"RequiredVertices",bamggeom->RequiredVerticesSize[0],bamggeom->RequiredVerticesSize[1],bamggeom->RequiredVertices);
+	i++; SetStructureField(dataref,"RequiredEdges",   bamggeom->RequiredEdgesSize[0],   bamggeom->RequiredEdgesSize[1],   bamggeom->RequiredEdges);
+	i++; SetStructureField(dataref,"CrackedEdges",    bamggeom->CrackedEdgesSize[0],    bamggeom->CrackedEdgesSize[1],    bamggeom->CrackedEdges);
+	i++; SetStructureField(dataref,"SubDomains",      bamggeom->SubDomainsSize[0],      bamggeom->SubDomainsSize[1],      bamggeom->SubDomains);
+	_assert_(i==numfields);
+
+	/*Assign output*/
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,BamgMesh* bamgmesh){{{1*/
+void WriteData(mxArray** pdataref,BamgMesh* bamgmesh){
+
+	/*Intermediary*/
+	int         i;
+	mxArray    *dataref           = NULL;
+	const int   numfields         = 16;
+	const char *fnames[numfields];
+	mwSize      ndim              = 2;
+	mwSize      dimensions[2]     = {1,1};
+
+	/*Initialize field names*/
+	i=0;
+	fnames[i++] = "Triangles";
+	fnames[i++] = "Vertices";
+	fnames[i++] = "Edges";
+	fnames[i++] = "IssmSegments";
+	fnames[i++] = "IssmEdges";
+	fnames[i++] = "Quadrilaterals";
+	fnames[i++] = "VerticesOnGeomVertex";
+	fnames[i++] = "VerticesOnGeomEdge";
+	fnames[i++] = "EdgesOnGeomEdge";
+	fnames[i++] = "SubDomains";
+	fnames[i++] = "SubDomainsFromGeom";
+	fnames[i++] = "ElementConnectivity";
+	fnames[i++] = "NodalConnectivity";
+	fnames[i++] = "NodalElementConnectivity";
+	fnames[i++] = "CrackedVertices";
+	fnames[i++] = "CrackedEdges";
+	_assert_(i==numfields);
+
+	/*Initialize Matlab structure*/
+	dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames);
+
+	/*set each matlab each field*/
+	i=0;
+	i++; SetStructureField(dataref,"Triangles", bamgmesh->TrianglesSize[0],bamgmesh->TrianglesSize[1], bamgmesh->Triangles);
+	i++; SetStructureField(dataref,"Vertices",bamgmesh->VerticesSize[0], bamgmesh->VerticesSize[1],bamgmesh->Vertices);
+	i++; SetStructureField(dataref,"Edges", bamgmesh->EdgesSize[0],bamgmesh->EdgesSize[1], bamgmesh->Edges);
+	i++; SetStructureField(dataref,"IssmSegments",bamgmesh->IssmSegmentsSize[0], bamgmesh->IssmSegmentsSize[1],bamgmesh->IssmSegments);
+	i++; SetStructureField(dataref,"IssmEdges", bamgmesh->IssmEdgesSize[0],bamgmesh->IssmEdgesSize[1], bamgmesh->IssmEdges);
+	i++; SetStructureField(dataref,"Quadrilaterals",bamgmesh->QuadrilateralsSize[0], bamgmesh->QuadrilateralsSize[1],bamgmesh->Quadrilaterals);
+	i++; SetStructureField(dataref,"VerticesOnGeomVertex",bamgmesh->VerticesOnGeomVertexSize[0],bamgmesh->VerticesOnGeomVertexSize[1], bamgmesh->VerticesOnGeomVertex);
+	i++; SetStructureField(dataref,"VerticesOnGeomEdge",bamgmesh->VerticesOnGeomEdgeSize[0],bamgmesh->VerticesOnGeomEdgeSize[1], bamgmesh->VerticesOnGeomEdge);
+	i++; SetStructureField(dataref,"EdgesOnGeomEdge", bamgmesh->EdgesOnGeomEdgeSize[0], bamgmesh->EdgesOnGeomEdgeSize[1],bamgmesh->EdgesOnGeomEdge);
+	i++; SetStructureField(dataref,"SubDomains",bamgmesh->SubDomainsSize[0], bamgmesh->SubDomainsSize[1],bamgmesh->SubDomains);
+	i++; SetStructureField(dataref,"SubDomainsFromGeom", bamgmesh->SubDomainsFromGeomSize[0], bamgmesh->SubDomainsFromGeomSize[1],bamgmesh->SubDomainsFromGeom);
+	i++; SetStructureField(dataref,"ElementConnectivity",bamgmesh->ElementConnectivitySize[0],bamgmesh->ElementConnectivitySize[1], bamgmesh->ElementConnectivity);
+	i++; SetStructureField(dataref,"NodalConnectivity",bamgmesh->NodalConnectivitySize[0],bamgmesh->NodalConnectivitySize[1], bamgmesh->NodalConnectivity);
+	i++; SetStructureField(dataref,"NodalElementConnectivity", bamgmesh->NodalElementConnectivitySize[0], bamgmesh->NodalElementConnectivitySize[1],bamgmesh->NodalElementConnectivity);
+	i++; SetStructureField(dataref,"CrackedVertices", bamgmesh->CrackedVerticesSize[0],bamgmesh->CrackedVerticesSize[1], bamgmesh->CrackedVertices);
+	i++; SetStructureField(dataref,"CrackedEdges",bamgmesh->CrackedEdgesSize[0], bamgmesh->CrackedEdgesSize[1],bamgmesh->CrackedEdges);
+	_assert_(i==numfields);
+
+	/*Assign output*/
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,Matrix* matrix){{{1*/
+void WriteData(mxArray** pdataref,Matrix* matrix){
+		
+	int      i,j;
+	int      rows,cols;
+	mxArray *dataref     = NULL;
+	double  *matrix_ptr  = NULL;
+	double  *tmatrix_ptr = NULL;
+	
+	if(matrix){
+		
+		#ifdef _HAVE_PETSC_
+		PetscMatrixToDoubleMatrix(&matrix_ptr,&rows,&cols,matrix->matrix);
+		#else
+		matrix_ptr=matrix->matrix->ToSerial();
+		matrix->matrix->GetSize(&rows,&cols);
+		#endif
+
+		/*Now transpose the matrix and allocate with Matlab's memory manager: */
+		tmatrix_ptr=(double*)mxMalloc(rows*cols*sizeof(double));
+		for(i=0;i<rows;i++){
+			for(j=0;j<cols;j++){
+				tmatrix_ptr[j*rows+i]=matrix_ptr[i*cols+j];
+			}
+		}
+		
+		/*create matlab matrix: */
+		dataref=mxCreateDoubleMatrix(0,0,mxREAL);
+		mxSetM(dataref,rows); 
+		mxSetN(dataref,cols);
+		mxSetPr(dataref,tmatrix_ptr);
+
+		/*Free ressources:*/
+		xfree((void**)&matrix_ptr);
+
+	}
+	else{
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+	}
+
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,Vector* vector){{{1*/
+void WriteData(mxArray** pdataref,Vector* vector){
+	
+	mxArray* dataref=NULL;
+	double*  vector_ptr=NULL;
+	double*  vector_matlab=NULL;
+	int      rows;
+	
+	if(vector){
+		/*call toolkit routine: */
+		#ifdef _HAVE_PETSC_
+		PetscVectorToDoubleVector(&vector_ptr,&rows,vector->vector);
+		#else
+		vector_ptr=vector->vector->ToMPISerial();
+		vector->vector->GetSize(&rows);
+		#endif
+		
+		/*now create the matlab vector with Matlab's memory manager */
+		vector_matlab=(double*)mxMalloc(rows*sizeof(double));
+		for(int i=0;i<rows;i++) vector_matlab[i]=vector_ptr[i];
+
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);                         
+		mxSetM(dataref,rows);
+		mxSetN(dataref,1);                                                                                          
+		mxSetPr(dataref,vector_matlab);           
+	}
+	else{
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+	}
+
+	/*Clean-up and return*/
+	xfree((void**)&vector_ptr);
+	*pdataref=dataref;
+}
+/*}}}*/
+
+/*Toolkit*/
+/*FUNCTION SetStructureField{{{1*/
+void SetStructureField(mxArray* dataref,const char* fieldname,int M,int N,double* fieldpointer){
+
+	mxArray* field = NULL;
+
+
+	/*Convert field*/
+	WriteData(&field,fieldpointer,M,N);
+
+	/*Assign to structure*/
+	mxSetField(dataref,0,fieldname,field);
+}
+/*}}}*/
Index: /issm/trunk/src/c/matlab/io/matlabio.h
===================================================================
--- /issm/trunk/src/c/matlab/io/matlabio.h	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/matlabio.h	(revision 12330)
@@ -0,0 +1,86 @@
+/*\file matlabio.h
+ *\brief: I/O for ISSM in matlab mode
+ */
+
+#ifndef _MATLAB_IO_H_
+#define _MATLAB_IO_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif 
+
+#include "../../objects/objects.h"
+#include "../../Container/Container.h"
+#include "../../include/include.h"
+
+#include <mex.h>
+
+void WriteData(mxArray** pdataref,Matrix* matrix);
+void WriteData(mxArray** pdataref,double* matrix, int M,int N);
+void WriteData(mxArray** pdataref,int*    matrix, int M,int N);
+void WriteData(mxArray** pdataref,Vector* vector);
+void WriteData(mxArray** pdataref,double* vector, int M);
+void WriteData(mxArray** pdataref,int integer);
+void WriteData(mxArray** pdataref,bool boolean);
+void WriteData(mxArray** pdataref,double scalar);
+void WriteData(mxArray** pdataref,char* string);
+void WriteData(mxArray** pdataref,BamgGeom* bamggeom);
+void WriteData(mxArray** pdataref,BamgMesh* bamgmesh);
+
+void FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref);
+void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);
+void FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref);
+void FetchData(bool** pmatrix,int* pM,int *pN,const mxArray* dataref);
+void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);
+void FetchData(Matrix** pmatrix,const mxArray* dataref);
+void FetchData(int** pvector,int* pM,const mxArray* dataref);
+void FetchData(float** pvector,int* pM,const mxArray* dataref);
+void FetchData(double** pvector,int* pM,const mxArray* dataref);
+void FetchData(bool** pvector,int* pM,const mxArray* dataref);
+void FetchData(Vector** pvector,const mxArray* dataref);
+void FetchData(char** pstring,const mxArray* dataref);
+void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref);
+void FetchData(double* pscalar,const mxArray* dataref);
+void FetchData(int* pinteger,const mxArray* dataref);
+void FetchData(bool* pbool,const mxArray* dataref);
+void FetchData(BamgGeom** bamggeom,const mxArray* dataref);
+void FetchData(BamgMesh** bamgmesh,const mxArray* dataref);
+void FetchData(BamgOpts** bamgopts,const mxArray* dataref);
+void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref);
+
+Option* OptionParse(char* name, const mxArray* prhs[]);
+OptionDouble*   OptionDoubleParse( char* name, const mxArray* prhs[]);
+OptionLogical*  OptionLogicalParse( char* name, const mxArray* prhs[]);
+OptionChar*     OptionCharParse( char* name, const mxArray* prhs[]);
+OptionStruct*   OptionStructParse( char* name, const mxArray* prhs[]);
+OptionCell*     OptionCellParse( char* name, const mxArray* prhs[]);
+
+mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number, const char* field);
+void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
+int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void ));
+
+/*Matlab to Matrix routines: */
+Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix);
+Vector* MatlabVectorToVector(const mxArray* mxvector);
+
+/*Matlab to double* routines: */
+int MatlabVectorToDoubleVector(double** pvector,int* pvector_rows,const mxArray* mxvector);
+int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix);
+int MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix);
+int MatlabNArrayToNArray(bool** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix);
+int MatlabNArrayToNArray(char** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix);
+
+/*Matlab to SeqMat routines: */
+SeqMat* MatlabMatrixToSeqMat(const mxArray* dataref);
+SeqVec* MatlabVectorToSeqVec(const mxArray* dataref);
+
+/*Matlab to Petsc routines: */
+#ifdef _HAVE_PETSC_
+int MatlabMatrixToPetscMatrix(Mat* matrix,int* prows,int* pcols, const mxArray* mxmatrix);
+int MatlabVectorToPetscVector(Vec* pvector,int* pvector_rows,const mxArray* mxvector);
+#endif
+
+
+#endif	/* _IO_H_ */
Index: /issm/trunk/src/c/matlab/io/mxGetAssignedField.cpp
===================================================================
--- /issm/trunk/src/c/matlab/io/mxGetAssignedField.cpp	(revision 12330)
+++ /issm/trunk/src/c/matlab/io/mxGetAssignedField.cpp	(revision 12330)
@@ -0,0 +1,45 @@
+/*!\file: mxGetAssignedField.c: 
+ * \brief: abstract interface on parallel side for i/o, so it ressembles the serial i/o.
+ *
+ * In serial mode, this routine takes care of returning the field coming 
+ * from the model. If largesize is 1, we are running out of core models in 
+ * matlab, and we need to call the subsref private method from the model object
+ * in order to correctly load the data from disk.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#error "Cannot compile without HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "mex.h"
+
+mxArray* mxGetAssignedField(const mxArray* pmxa_array,int number,const char* field){
+
+	//output
+	mxArray* mxfield=NULL;
+	
+	//input
+	mxArray    *inputs[2];
+	mxArray    *pindex      = NULL;
+	const char *fnames[2];
+	mwSize      ndim        = 2;
+	mwSize      onebyone[2] = {1,1};
+
+	//We want to call the subsasgn method, and get the returned array.This ensures that if we are running 
+	//large sized problems, the data is truly loaded from disk by the model subsasgn class method.
+	inputs[0]=(mxArray*)pmxa_array; //this is the model
+
+	//create index structure used in the assignment (index.type='.' and index.subs='x' for field x for ex)
+	fnames[0] = "type";
+	fnames[1] = "subs";
+	pindex=mxCreateStructArray( ndim,onebyone,2,fnames);
+	mxSetField( pindex, 0, "type",mxCreateString("."));
+	mxSetField( pindex, 0, "subs",mxCreateString(field));
+	inputs[1]=pindex;
+
+	mexCallMATLAB( 1, &mxfield, 2, (mxArray**)inputs, "subsref");
+
+	return mxfield;
+}
Index: /issm/trunk/src/c/matlab/matlab-binding.h
===================================================================
--- /issm/trunk/src/c/matlab/matlab-binding.h	(revision 12330)
+++ /issm/trunk/src/c/matlab/matlab-binding.h	(revision 12330)
@@ -0,0 +1,7 @@
+#ifndef _MATLAB_BINDING_H_
+#define _MATLAB_BINDING_H_
+
+#include "./io/matlabio.h"
+#include "./include/matlab_macros.h"
+
+#endif
Index: /issm/trunk/src/c/modules/Bamgx/Bamgx.cpp
===================================================================
--- /issm/trunk/src/c/modules/Bamgx/Bamgx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/Bamgx/Bamgx.cpp	(revision 12330)
@@ -92,5 +92,5 @@
 
 		//Make Quadtree from background mesh
-		BTh.MakeQuadTree();
+		BTh.MakeBamgQuadtree();
 
 		//Bound hmin and hmax
Index: /issm/trunk/src/c/modules/ConstraintsStatex/RiftConstraintsState.cpp
===================================================================
--- /issm/trunk/src/c/modules/ConstraintsStatex/RiftConstraintsState.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ConstraintsStatex/RiftConstraintsState.cpp	(revision 12330)
@@ -32,5 +32,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD);                
@@ -95,5 +95,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&num_unstable_constraints,&sum_num_unstable_constraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&sum_num_unstable_constraints,1,MPI_INT,0,MPI_COMM_WORLD);                
@@ -135,5 +135,5 @@
 	
 	/*Is there just one found? that would mean we have frozen! : */
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD);                
@@ -195,5 +195,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD);                
@@ -228,5 +228,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD);                
@@ -289,5 +289,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&num_unstable_constraints,&sum_num_unstable_constraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&sum_num_unstable_constraints,1,MPI_INT,0,MPI_COMM_WORLD);                
@@ -329,5 +329,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&max_penetration,&mpi_max_penetration,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&mpi_max_penetration,1,MPI_DOUBLE,0,MPI_COMM_WORLD);                
@@ -368,5 +368,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&num_unstable_constraints,&sum_num_unstable_constraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&sum_num_unstable_constraints,1,MPI_INT,0,MPI_COMM_WORLD);                
Index: /issm/trunk/src/c/modules/ConstraintsStatex/ThermalConstraintsState.cpp
===================================================================
--- /issm/trunk/src/c/modules/ConstraintsStatex/ThermalConstraintsState.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ConstraintsStatex/ThermalConstraintsState.cpp	(revision 12330)
@@ -36,5 +36,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&num_unstable_constraints,&sum_num_unstable_constraints,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&sum_num_unstable_constraints,1,MPI_INT,0,MPI_COMM_WORLD);                
Index: /issm/trunk/src/c/modules/ConstraintsStatex/ThermalIsPresent.cpp
===================================================================
--- /issm/trunk/src/c/modules/ConstraintsStatex/ThermalIsPresent.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ConstraintsStatex/ThermalIsPresent.cpp	(revision 12330)
@@ -28,5 +28,5 @@
 	}
 	
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&found,&mpi_found,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&mpi_found,1,MPI_INT,0,MPI_COMM_WORLD);                
Index: /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.cpp
===================================================================
--- /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.cpp	(revision 12330)
@@ -11,5 +11,5 @@
 #include "./ContourToMeshx.h"
 
-int ContourToMeshx( Vector** pin_nod,Vector** pin_elem, double* index, double* x, double* y,Contour** contours,int numcontours,char* interptype,int nel,int nods, int edgevalue) {
+int ContourToMeshx( Vector** pin_nod,Vector** pin_elem, double* index, double* x, double* y,DataSet* contours,char* interptype,int nel,int nods, int edgevalue) {
 
 	int noerr=1;
@@ -37,5 +37,4 @@
 
 	/*initialize thread parameters: */
-	gate.numcontours=numcontours;
 	gate.contours=contours;
 	gate.nods=nods;
Index: /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h
===================================================================
--- /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h	(revision 12329)
+++ /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h	(revision 12330)
@@ -13,6 +13,5 @@
 typedef struct{
 
-	int numcontours;
-	Contour** contours;
+	DataSet* contours;
 	int nods;
 	int edgevalue;
@@ -25,5 +24,5 @@
 
 /* local prototypes: */
-int ContourToMeshx( Vector** pin_nods,Vector** pin_elem, double* index, double* x, double* y,Contour** contours,int numcontours,char* interptype,int nel,int nods, int edgevalue);
+int ContourToMeshx( Vector** pin_nods,Vector** pin_elem, double* index, double* x, double* y,DataSet* contours,char* interptype,int nel,int nods, int edgevalue);
 
 void* ContourToMeshxt(void* vContourToMeshxThreadStruct);
Index: /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshxt.cpp
===================================================================
--- /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshxt.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshxt.cpp	(revision 12330)
@@ -26,13 +26,7 @@
 
 	/*Contour:*/
-	Contour* contouri=NULL;
-	int      numnodes;
-	double*  xc=NULL;
-	double*  yc=NULL;
-
+	DataSet* contours=NULL;
 
 	/*parameters: */
-	int numcontours;
-	Contour** contours=NULL;
 	int nods;
 	int edgevalue;
@@ -49,5 +43,4 @@
 
 	/*recover parameters :*/
-	numcontours=gate->numcontours;
 	contours=gate->contours;
 	nods=gate->nods;
@@ -61,10 +54,7 @@
 
 	/*Loop through all contours: */
-	for (i=0;i<numcontours;i++){
-		contouri=*(contours+i);
-		numnodes=contouri->nods;
-		xc=contouri->x;
-		yc=contouri->y;
-		IsInPoly(in_nod,xc,yc,numnodes,x,y,i0,i1,edgevalue);
+	for (i=0;i<contours->Size();i++){
+		Contour* contour=(Contour*)contours->GetObjectByOffset(i);
+		IsInPoly(in_nod,contour->x,contour->y,contour->nods,x,y,i0,i1,edgevalue);
 	}
 
Index: /issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.cpp
===================================================================
--- /issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.cpp	(revision 12330)
@@ -38,2 +38,36 @@
 	return 1;
 }
+
+int ContourToNodesx( Vector** pflags,double* x, double* y, int nods, DataSet* contours, int edgevalue){
+
+	int i;
+	int m,n;
+
+	/*Contour:*/
+	Contour* contouri=NULL;
+	int      numnodes;
+	double*  xc=NULL;
+	double*  yc=NULL;
+	double   value;
+
+	/*output: */
+	Vector* flags=NULL;
+
+	flags=new Vector(nods);
+
+	/*Loop through all contours: */
+	if(contours){
+		for (i=0;i<contours->Size();i++){
+			Contour* contour=(Contour*)contours->GetObjectByOffset(i);
+			IsInPoly(flags,contour->x,contour->y,contour->nods,x,y,0,nods,edgevalue);
+		}
+	}
+
+	/*Assemble vector: */
+	flags->Assemble();
+
+	/*Assign output pointers: */
+	*pflags=flags;
+	
+	return 1;
+}
Index: /issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.h
===================================================================
--- /issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.h	(revision 12329)
+++ /issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.h	(revision 12330)
@@ -12,4 +12,5 @@
 /* local prototypes: */
 int ContourToNodesx( Vector** pflags,double* x, double* y, int nods, Contour** contours,int numcontours,int edgevalue);
+int ContourToNodesx( Vector** pflags,double* x, double* y, int nods, DataSet* contours, int edgevalue);
 
 #endif /* _CONTOURTONODESX_H */
Index: /issm/trunk/src/c/modules/Dakotax/Dakotax.cpp
===================================================================
--- /issm/trunk/src/c/modules/Dakotax/Dakotax.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/Dakotax/Dakotax.cpp	(revision 12330)
@@ -51,9 +51,5 @@
 #endif
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void Dakotax(mxArray* femmodel){ 
-#else
 void Dakotax(FemModel* femmodel){ 
-#endif
 
 
@@ -69,9 +65,5 @@
 
 	/*Retrieve parameters: */
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	FetchData((Parameters**)&parameters,mxGetField((mxArray*)femmodel,0,"parameters"));
-	#else
 	parameters=femmodel->parameters;
-	#endif
 
 	/*Recover dakota_input_file, dakota_output_file and dakota_error_file, in the parameters dataset in parallel */
@@ -80,15 +72,9 @@
 	parameters->FindParam(&dakota_error_file,QmuErrNameEnum);
 
-	#ifdef _PARALLEL_
 	if(my_rank==0){
-	#endif
 	
 		// Instantiate/initialize the parallel library and problem description
 		// database objects.
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-			Dakota::ParallelLibrary parallel_lib; //use Dakota's standard library mode constructor
-		#else
-			Dakota::ParallelLibrary parallel_lib("serial"); //use our own ISSM Dakota library mode constructor, which only fires up Dakota on CPU 0. 
-		#endif
+		Dakota::ParallelLibrary parallel_lib("serial"); //use our own ISSM Dakota library mode constructor, which only fires up Dakota on CPU 0. 
 		Dakota::ProblemDescDB problem_db(parallel_lib); 
 
@@ -123,10 +109,7 @@
 		selected_strategy.run_strategy();
 		
-		#ifdef _PARALLEL_
 		//Warn other cpus that we are done running the dakota iterator, by setting the counter to -1:
 		SpawnCore(NULL,0, NULL,NULL,0,femmodel,-1);
-		#endif
 
-	#ifdef _PARALLEL_
 	}
 	else{
@@ -136,5 +119,4 @@
 		}
 	}
-	#endif //#ifdef _PARALLEL_
 
 	/*Free ressources:*/
@@ -143,8 +125,4 @@
 	xfree((void**)&dakota_output_file);
 
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	delete parameters;
-	#endif
-
 	#endif //#ifdef _HAVE_DAKOTA_
 }
Index: /issm/trunk/src/c/modules/Dakotax/Dakotax.h
===================================================================
--- /issm/trunk/src/c/modules/Dakotax/Dakotax.h	(revision 12329)
+++ /issm/trunk/src/c/modules/Dakotax/Dakotax.h	(revision 12330)
@@ -10,14 +10,9 @@
 
 /* local prototypes: */
-int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* femmodel,int counter);
+int  SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* femmodel,int counter);
 int  DescriptorIndex(char* root, int* pindex,char* descriptor);
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void Dakotax(mxArray* femmodel);
-void SpawnCoreSerial(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, mxArray* femmodel,int counter);
-#else
 void Dakotax(FemModel* femmodel);
 void SpawnCoreParallel(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, FemModel* femmodel,int counter);
-#endif
 void DakotaResponses(double* responses,char** responses_descriptors,int numresponses,FemModel* femmodel);
 void DakotaMPI_Bcast(double** pvariables, char*** pvariables_descriptors,int* pnumvariables, int* pnumresponses);
Index: /issm/trunk/src/c/modules/Dakotax/SpawnCore.cpp
===================================================================
--- /issm/trunk/src/c/modules/Dakotax/SpawnCore.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/Dakotax/SpawnCore.cpp	(revision 12330)
@@ -21,12 +21,9 @@
 	/*Branch into a serial SpawnCore and a parallel SpawnCore: */
 
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		SpawnCoreSerial(responses, numresponses, variables, variables_descriptors,numvariables, (mxArray*)femmodel, counter);
-	#else
-		/*Call SpawnCoreParallel unless counter=-1 on cpu0, in which case, bail out and return 0: */
-		MPI_Bcast(&counter,1,MPI_INT,0,MPI_COMM_WORLD); 
-		if(counter==-1)return 0;
-		SpawnCoreParallel(responses, numresponses, variables, variables_descriptors,numvariables, (FemModel*)femmodel,counter);
-	#endif
+	/*Call SpawnCoreParallel unless counter=-1 on cpu0, in which case, bail out and return 0: */
+	MPI_Bcast(&counter,1,MPI_INT,0,MPI_COMM_WORLD); 
+	if(counter==-1)return 0;
+
+	SpawnCoreParallel(responses, numresponses, variables, variables_descriptors,numvariables, (FemModel*)femmodel,counter);
 	return 1;
 }
Index: sm/trunk/src/c/modules/Dakotax/SpawnCoreSerial.cpp
===================================================================
--- /issm/trunk/src/c/modules/Dakotax/SpawnCoreSerial.cpp	(revision 12329)
+++ 	(revision )
@@ -1,71 +1,0 @@
-/*!\file:  SpawnCoreSerial.cpp
- * \brief: run core ISSM solution using Dakota inputs. Call the Serial core solution, using mexCallMATLAB
- * \sa SpawnCore.cpp SpawnCoreParallel.cpp
- *
- */ 
-
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#include "../../objects/objects.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../shared/shared.h"
-#include "./Dakotax.h"
-#include "../../include/include.h"
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void SpawnCoreSerial(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, mxArray* femmodel, int counter){
-
-	int i;
-
-	//inputs to matlab routine
-	mxArray* mxvariables=NULL;
-	double*  variables_copy=NULL;
-	mxArray* mxvariabledescriptors=NULL;
-	mxArray* mxcounter=NULL;
-	mwSize   dims[2]={0};
-
-	//mexCallMATLAB arrays
-	mxArray* array[4];
-
-	//output from SpawnCore in matlab routine.
-	mxArray* mxresponses=NULL;
-
-	/*Create variables and variable descriptors mxArrays that we will feed to the core solution for update of the inputs: */
-	mxvariables=mxCreateDoubleMatrix(numvariables,1,mxREAL);
-	variables_copy=(double*)xmalloc(numvariables*sizeof(double));
-	memcpy(variables_copy,variables,numvariables*sizeof(double));
-	mxSetPr(mxvariables,variables_copy);
-
-	dims[0]=numvariables;
-	dims[1]=1;
-	mxvariabledescriptors=mxCreateCellArray(2,dims);
-	for(i=0;i<numvariables;i++){
-		mxSetCell(mxvariabledescriptors,i,mxCreateString(variables_descriptors[i]));
-	}
-
-	mxcounter=mxCreateDoubleScalar((double)counter);
-
-	//call SpwanCore matlab routine.
-	array[0]=femmodel;
-	array[1]=mxvariables;
-	array[2]=mxvariabledescriptors;
-	array[3]=mxcounter;
-
-	mexCallMATLAB(1,&mxresponses,4,array,"SpawnCore");
-
-	/*copy responses back to dakota: */
-	memcpy(responses,mxGetPr(mxresponses),numresponses*sizeof(double));
-
-	//destroy constructed arrays: 
-	mxDestroyArray(mxvariables);
-	mxDestroyArray(mxvariabledescriptors);
-	mxDestroyArray(mxresponses);
-	mxDestroyArray(mxcounter);
-
-}
-#endif
Index: /issm/trunk/src/c/modules/DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.cpp
===================================================================
--- /issm/trunk/src/c/modules/DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/DragCoefficientAbsGradientx/DragCoefficientAbsGradientx.cpp	(revision 12330)
@@ -27,7 +27,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/ElementResponsex/ElementResponsex.cpp
===================================================================
--- /issm/trunk/src/c/modules/ElementResponsex/ElementResponsex.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ElementResponsex/ElementResponsex.cpp	(revision 12330)
@@ -37,6 +37,8 @@
 
 	/*Broadcast whether we found the element: */
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( &found,&sumfound,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
 	if(!sumfound)_error_("%s%i%s","could not find material with id",index," to compute ElementResponse");
+	#endif
 
 	/*Ok, we found the element, compute responseocity: */
@@ -46,6 +48,8 @@
 
 	/*Broadcast and plug into response: */
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( &cpu_found,&cpu_found,1,MPI_INT,MPI_MAX,MPI_COMM_WORLD);
 	MPI_Bcast(&response,1,MPI_DOUBLE,cpu_found,MPI_COMM_WORLD); 
+	#endif
 
 	*presponse=response;
Index: /issm/trunk/src/c/modules/EnumToStringx/EnumToStringx.cpp
===================================================================
--- /issm/trunk/src/c/modules/EnumToStringx/EnumToStringx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/EnumToStringx/EnumToStringx.cpp	(revision 12330)
@@ -157,4 +157,5 @@
 		case PetscProfilingCurrentFlopsEnum : return "PetscProfilingCurrentFlops";
 		case PetscProfilingSolutionTimeEnum : return "PetscProfilingSolutionTime";
+		case MaxIterationConvergenceFlagEnum : return "MaxIterationConvergenceFlag";
 		case SteadystateMaxiterEnum : return "SteadystateMaxiter";
 		case SteadystateNumRequestedOutputsEnum : return "SteadystateNumRequestedOutputs";
Index: /issm/trunk/src/c/modules/Exp2Kmlx/Exp2Kmlx.cpp
===================================================================
--- /issm/trunk/src/c/modules/Exp2Kmlx/Exp2Kmlx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/Exp2Kmlx/Exp2Kmlx.cpp	(revision 12330)
@@ -61,5 +61,5 @@
 /*  read exp file  */
 
-	if (!DomainOutlineRead(&nprof,&pnvert,&pprofx,&pprofy,&closed,filexp,true))
+	if (!DomainOutlineRead(&nprof,&pnvert,&pprofx,&pprofy,&closed,filexp))
 		_error_("Error reading exp file.");
 	_printf_(true,"Exp2Kmlx -- Reading %d exp profiles from file \"%s\".\n",nprof,filexp);
Index: /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp
===================================================================
--- /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp	(revision 12330)
@@ -156,6 +156,10 @@
 		vec_nodes_on_floatingice->Assemble();
 		
+		#ifdef _HAVE_MPI_
 		MPI_Allreduce(&local_nflipped,&nflipped,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
 		_printf_(VerboseConvergence(),"   Additional number of vertices allowed to unground: %i\n",nflipped);
+		#else
+		nflipped=local_nflipped;
+		#endif
 
 		/*Avoid leaks: */
Index: /issm/trunk/src/c/modules/IceVolumex/IceVolumex.cpp
===================================================================
--- /issm/trunk/src/c/modules/IceVolumex/IceVolumex.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/IceVolumex/IceVolumex.cpp	(revision 12330)
@@ -19,6 +19,10 @@
 		local_ice_volume+=element->IceVolume();
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Reduce(&local_ice_volume,&total_ice_volume,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&total_ice_volume,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
+	#else
+	total_ice_volume=local_ice_volume;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/InputConvergencex/InputConvergencex.cpp
===================================================================
--- /issm/trunk/src/c/modules/InputConvergencex/InputConvergencex.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/InputConvergencex/InputConvergencex.cpp	(revision 12330)
@@ -30,5 +30,5 @@
 
 	/*In parallel, we need to gather the converged status: */
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( (void*)&num_notconverged,(void*)&total_notconverged,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
 	num_notconverged=total_notconverged;
Index: /issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp
===================================================================
--- /issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 12330)
@@ -14,5 +14,5 @@
 
 int InterpFromMeshToMesh2dx(double** pdata_interp,double* index_data,double* x_data,double* y_data,int nods_data,int nels_data,
-			double* data,int data_rows,int data_cols,double* x_interp,double* y_interp,int nods_interp,double* default_values,int num_default_values, Contour** contours, int numcontours){
+			double* data,int data_rows,int data_cols,double* x_interp,double* y_interp,int nods_interp,double* default_values,int num_default_values, DataSet* contours){
 	
 	/*Output*/
@@ -36,5 +36,4 @@
 	bool   skip_bamg=false;
 
-
 	/*Checks*/
 	if (data_cols<=0){
@@ -50,5 +49,5 @@
 	/*If default values supplied, figure out which nodes are inside the contour, including the border of the contour: */
 	if(num_default_values){
-		ContourToNodesx( &vec_incontour,x_interp,y_interp,nods_interp,contours,numcontours,1);
+		ContourToNodesx( &vec_incontour,x_interp,y_interp,nods_interp,contours,1);
 		incontour=vec_incontour->ToMPISerial();
 	}
Index: /issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h
===================================================================
--- /issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h	(revision 12329)
+++ /issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h	(revision 12330)
@@ -10,5 +10,5 @@
 /* local prototypes: */
 int InterpFromMeshToMesh2dx(double** pdata_interp,double* index_data,double* x_data,double* y_data,int nods_data,int nels_data,
-			double* data,int data_rows,int data_cols,double* x_interp,double* y_interp,int nods_interp,double* default_values,int num_default_values,Contour** contours, int numcontours );
+			double* data,int data_rows,int data_cols,double* x_interp,double* y_interp,int nods_interp,double* default_values,int num_default_values,DataSet* contours);
 
 #endif
Index: /issm/trunk/src/c/modules/Krigingx/Krigingx.cpp
===================================================================
--- /issm/trunk/src/c/modules/Krigingx/Krigingx.cpp	(revision 12330)
+++ /issm/trunk/src/c/modules/Krigingx/Krigingx.cpp	(revision 12330)
@@ -0,0 +1,263 @@
+/*!\file:  Kriging.cpp
+ * \brief  "c" core code for Kriging
+ */ 
+
+#include "./Krigingx.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../objects/objects.h"
+#include "../../Container/Observations.h"
+#include "../modules.h"
+
+#ifdef _HAVE_GSL_
+#include <gsl/gsl_linalg.h>
+#endif
+
+#include "../../objects/Kriging/GaussianVariogram.h"
+/*FUNCTION Krigingx{{{*/
+int Krigingx(double** ppredictions,double **perror,double* obs_x, double* obs_y, double* obs_list, int obs_length,double* x_interp,double* y_interp,int n_interp,Options* options){
+
+	/*output*/
+	double *predictions = NULL;
+	double *error       = NULL;
+
+	/*Intermediaries*/
+	int           mindata,maxdata;
+	double        radius;
+	char         *output       = NULL;
+	Variogram    *variogram    = NULL;
+	Observations *observations = NULL;
+
+	/*threading: */
+	KrigingxThreadStruct gate;
+	int num=1;
+#ifdef _MULTITHREADING_
+	num=_NUMTHREADS_;
+#endif
+
+	/*Get Variogram from Options*/
+	ProcessVariogram(&variogram,options);
+	options->Get(&radius,"searchradius",0.);
+	options->Get(&mindata,"mindata",1);
+	options->Get(&maxdata,"maxdata",50);
+
+	/*Process observation dataset*/
+	observations=new Observations(obs_list,obs_x,obs_y,obs_length,options);
+
+	/*Allocate output*/
+	predictions =(double*)xcalloc(n_interp,sizeof(double));
+	error       =(double*)xcalloc(n_interp,sizeof(double));
+
+	/*Get output*/
+	options->Get(&output,"output","prediction");
+
+	if(strcmp(output,"quadtree")==0){
+		observations->QuadtreeColoring(predictions,x_interp,y_interp,n_interp);
+	}
+	else if(strcmp(output,"variomap")==0){
+		observations->Variomap(predictions,x_interp,n_interp);
+	}
+	else if(strcmp(output,"prediction")==0){
+
+		/*initialize thread parameters: */
+		gate.n_interp     = n_interp;
+		gate.x_interp     = x_interp;
+		gate.y_interp     = y_interp;
+		gate.radius       = radius;
+		gate.mindata      = mindata;
+		gate.maxdata      = maxdata;
+		gate.variogram    = variogram;
+		gate.observations = observations;
+		gate.predictions  = predictions;
+		gate.error        = error;
+		gate.percent      = (double*)xcalloc(num,sizeof(double));
+
+		/*launch the thread manager with Krigingxt as a core: */
+		LaunchThread(Krigingxt,(void*)&gate,num);
+		printf("\r      interpolation progress:  100.00%%\n");
+		xfree((void**)&gate.percent);
+	}
+	else{
+		_error_("output '%s' not supported yet",output);
+	}
+
+	/*clean-up and Assign output pointer*/
+	delete variogram;
+	delete observations;
+	xfree((void**)&output);
+	*ppredictions = predictions;
+	*perror       = error;
+	return 1;
+}/*}}}*/
+/*FUNCTION Krigingxt{{{*/
+void* Krigingxt(void* vpthread_handle){
+
+	/*gate variables :*/
+	KrigingxThreadStruct *gate        = NULL;
+	pthread_handle       *handle      = NULL;
+	int my_thread;
+	int num_threads;
+	int i0,i1;
+
+	/*recover handle and gate: */
+	handle      = (pthread_handle*)vpthread_handle;
+	gate        = (KrigingxThreadStruct*)handle->gate;
+	my_thread   = handle->id;
+	num_threads = handle->num;
+
+	/*recover parameters :*/
+	int           n_interp     = gate->n_interp;
+	double       *x_interp     = gate->x_interp;
+	double       *y_interp     = gate->y_interp;
+	double        radius       = gate->radius;
+	int           mindata      = gate->mindata;
+	int           maxdata      = gate->maxdata;
+	Variogram    *variogram    = gate->variogram;
+	Observations *observations = gate->observations;
+	double       *predictions  = gate->predictions;
+	double       *error        = gate->error;
+	double       *percent      = gate->percent;
+
+	/*Intermediaries*/
+	int           i,j,n_obs;
+	double        numerator,denominator,ratio,localpercent;
+	double       *x            = NULL;
+	double       *y            = NULL;
+	double       *obs          = NULL;
+	double       *Gamma        = NULL;
+	double       *GinvG0       = NULL;
+	double       *Ginv1        = NULL;
+	double       *GinvZ        = NULL;
+	double       *gamma0       = NULL;
+	double       *ones         = NULL;
+
+	/*partition loop across threads: */
+	PartitionRange(&i0,&i1,n_interp,num_threads,my_thread);
+	for(int idx=i0;idx<i1;idx++){
+
+		/*Print info*/
+		percent[my_thread]=double(idx-i0)/double(i1-i0)*100.;
+		localpercent=percent[0];
+		for(i=1;i<num_threads;i++) localpercent=min(localpercent,percent[i]);
+		printf("\r      interpolation progress: %5.2lf%%",localpercent);
+
+		/*Get list of observations for current point*/
+		observations->ObservationList(&x,&y,&obs,&n_obs,x_interp[idx],y_interp[idx],radius,maxdata);
+		if(n_obs<mindata){
+			predictions[idx] = -999.0; 
+			error[idx]       = -999.0; 
+			continue;
+		}
+
+		/*Allocate intermediary matrix and vectors*/
+
+		Gamma  = (double*)xmalloc(n_obs*n_obs*sizeof(double));
+		gamma0 = (double*)xmalloc(n_obs*sizeof(double));
+		ones   = (double*)xmalloc(n_obs*sizeof(double));
+
+		/*First: Create semivariogram matrix for observations*/
+		for(i=0;i<n_obs;i++){
+			for(j=0;j<=i;j++){
+				//Gamma[i*n_obs+j] = variogram->SemiVariogram(x[i]-x[j],y[i]-y[j]);
+				Gamma[i*n_obs+j] = variogram->Covariance(x[i]-x[j],y[i]-y[j]);
+				Gamma[j*n_obs+i] = Gamma[i*n_obs+j];
+			}
+		}
+		for(i=0;i<n_obs;i++) ones[i]=1;
+
+		/*Get semivariogram vector associated to this location*/
+		//for(i=0;i<n_obs;i++) gamma0[i] = variogram->SemiVariogram(x[i]-x_interp[idx],y[i]-y_interp[idx]);
+		for(i=0;i<n_obs;i++) gamma0[i] = variogram->Covariance(x[i]-x_interp[idx],y[i]-y_interp[idx]);
+
+		/*Solve the three linear systems*/
+		GslSolve(&GinvG0,Gamma,gamma0,n_obs); // Gamma^-1 gamma0
+		GslSolve(&Ginv1, Gamma,ones,n_obs);   // Gamma^-1 ones
+		GslSolve(&GinvZ, Gamma,obs,n_obs);    // Gamma^-1 Z
+
+		/*Prepare predictor*/
+		numerator=-1.; denominator=0.;
+		for(i=0;i<n_obs;i++) numerator  +=GinvG0[i];
+		for(i=0;i<n_obs;i++) denominator+=Ginv1[i];
+		ratio=numerator/denominator;
+
+		predictions[idx] = 0.;
+		error[idx]       = - numerator*numerator/denominator;
+		for(i=0;i<n_obs;i++) predictions[idx] += (gamma0[i]-ratio)*GinvZ[i];
+		for(i=0;i<n_obs;i++) error[idx] += gamma0[i]*GinvG0[i];
+
+		/*clean-up*/
+		xfree((void**)&x);
+		xfree((void**)&y);
+		xfree((void**)&obs);
+		xfree((void**)&Gamma);
+		xfree((void**)&gamma0);
+		xfree((void**)&ones);
+		xfree((void**)&GinvG0);
+		xfree((void**)&Ginv1);
+		xfree((void**)&GinvZ);
+	}
+
+	return NULL;
+}/*}}}*/
+
+void ProcessVariogram(Variogram **pvariogram,Options* options){/*{{{*/
+
+	/*Intermediaries*/
+	Variogram* variogram = NULL;
+	char      *model     = NULL;
+
+	if(options->GetOption("model")){
+		options->Get(&model,"model");
+		if     (strcmp(model,"gaussian")==0)    variogram = new GaussianVariogram(options);
+		else if(strcmp(model,"exponential")==0) variogram = new ExponentialVariogram(options);
+		else if(strcmp(model,"spherical")==0)   variogram = new SphericalVariogram(options);
+		else if(strcmp(model,"power")==0)       variogram = new PowerVariogram(options);
+		else _error_("variogram %s not supported yet (list of supported variogram: gaussian, exponential, spherical and power)",model);
+	}
+	else variogram = new GaussianVariogram(options);
+
+	/*Assign output pointer*/
+	xfree((void**)&model);
+	*pvariogram = variogram;
+}/*}}}*/
+void GslSolve(double** pX,double* A,double* B,int n){/*{{{*/
+#ifdef _HAVE_GSL_
+
+		/*GSL Matrices and vectors: */
+		int              s;
+		gsl_matrix_view  a;
+		gsl_vector_view  b;
+		gsl_vector      *x = NULL;
+		gsl_permutation *p = NULL;
+
+		/*A will be modified by LU decomposition. Use copy*/
+		double* Acopy = (double*)xmalloc(n*n*sizeof(double));
+		memcpy(Acopy,A,n*n*sizeof(double));
+
+		/*Initialize gsl matrices and vectors: */
+		a = gsl_matrix_view_array (Acopy,n,n);
+		b = gsl_vector_view_array (B,n);
+		x = gsl_vector_alloc (n);
+
+		/*Run LU and solve: */
+		p = gsl_permutation_alloc (n);
+		gsl_linalg_LU_decomp (&a.matrix, p, &s);
+		gsl_linalg_LU_solve (&a.matrix, p, &b.vector, x);
+
+		//printf ("x = \n");
+		//gsl_vector_fprintf (stdout, x, "%g");
+
+		/*Copy result*/
+		double* X = (double*)xmalloc(n*sizeof(double));
+		memcpy(X,gsl_vector_ptr(x,0),n*sizeof(double));
+
+		/*Clean up and assign output pointer*/
+		xfree((void**)&Acopy);
+		gsl_permutation_free(p);
+		gsl_vector_free(x);
+		*pX=X;
+#else
+		_error_("GSL support required");
+#endif
+	}/*}}}*/
Index: /issm/trunk/src/c/modules/Krigingx/Krigingx.h
===================================================================
--- /issm/trunk/src/c/modules/Krigingx/Krigingx.h	(revision 12330)
+++ /issm/trunk/src/c/modules/Krigingx/Krigingx.h	(revision 12330)
@@ -0,0 +1,34 @@
+/*!\file Kriging.h
+ * \brief: header file for Kriging
+ */
+
+#ifndef _KRIGINGX_H
+#define _KRIGINGX_H
+
+#include "../../objects/objects.h"
+#include "../../toolkits/toolkits.h"
+
+class Observations;
+class Variogram;
+
+int  Krigingx(double** ppredictions,double **perror,double* x, double* y, double* observations, int n_obs,double* x_interp,double* y_interp,int n_interp,Options* options);
+void ProcessVariogram(Variogram **pvariogram,Options* options);
+void GslSolve(double** pX,double* A,double* B,int n);
+
+/*threading: */
+typedef struct{
+	int           n_interp;
+	double       *x_interp;
+	double       *y_interp;
+	double        radius;
+	int           mindata;
+	int           maxdata;
+	Variogram    *variogram;
+	Observations *observations;
+	double       *predictions;
+	double       *error;
+	double       *percent;
+}KrigingxThreadStruct;
+
+void* Krigingxt(void*);
+#endif /* _KRIGINGX_H */
Index: /issm/trunk/src/c/modules/MassFluxx/MassFluxx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MassFluxx/MassFluxx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MassFluxx/MassFluxx.cpp	(revision 12330)
@@ -59,5 +59,5 @@
 	}
 
-	#ifdef _PARALLEL_
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( (void*)&mass_flux,(void*)&all_mass_flux,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
 	mass_flux=all_mass_flux;
Index: /issm/trunk/src/c/modules/MaxAbsVxx/MaxAbsVxx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MaxAbsVxx/MaxAbsVxx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MaxAbsVxx/MaxAbsVxx.cpp	(revision 12330)
@@ -31,6 +31,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out maximum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&maxabsvx,&node_maxabsvx,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_maxabsvx,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MaxAbsVyx/MaxAbsVyx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MaxAbsVyx/MaxAbsVyx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MaxAbsVyx/MaxAbsVyx.cpp	(revision 12330)
@@ -32,6 +32,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out maximum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&maxabsvy,&node_maxabsvy,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_maxabsvy,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MaxAbsVzx/MaxAbsVzx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MaxAbsVzx/MaxAbsVzx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MaxAbsVzx/MaxAbsVzx.cpp	(revision 12330)
@@ -31,6 +31,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&maxabsvz,&node_maxabsvz,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_maxabsvz,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MaxVelx/MaxVelx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MaxVelx/MaxVelx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MaxVelx/MaxVelx.cpp	(revision 12330)
@@ -32,6 +32,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out maximum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&maxvel,&node_maxvel,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_maxvel,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MaxVxx/MaxVxx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MaxVxx/MaxVxx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MaxVxx/MaxVxx.cpp	(revision 12330)
@@ -31,6 +31,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&maxvx,&node_maxvx,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_maxvx,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MaxVyx/MaxVyx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MaxVyx/MaxVyx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MaxVyx/MaxVyx.cpp	(revision 12330)
@@ -31,6 +31,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&maxvy,&node_maxvy,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_maxvy,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MaxVzx/MaxVzx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MaxVzx/MaxVzx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MaxVzx/MaxVzx.cpp	(revision 12330)
@@ -32,6 +32,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&maxvz,&node_maxvz,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_maxvz,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MeshPartitionx/MeshPartitionx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MeshPartitionx/MeshPartitionx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MeshPartitionx/MeshPartitionx.cpp	(revision 12330)
@@ -42,5 +42,7 @@
 		/*Partition using Metis:*/
 		if (num_procs>1){
+			#ifdef _HAVE_METIS_
 			METIS_PartMeshNodalPatch(&numberofelements,&numberofnodes, index, &etype, &numflag, &num_procs, &edgecut, epart, npart);
+			#endif
 		}
 		else if (num_procs==1){
@@ -67,5 +69,7 @@
 		/*Partition using Metis:*/
 		if (num_procs>1){
+			#ifdef _HAVE_METIS_
 			METIS_PartMeshNodalPatch(&numberofelements2d,&numberofnodes2d, index2d, &etype2d, &numflag, &num_procs, &edgecut, epart2d, npart2d);
+			#endif
 		}
 		else if (num_procs==1){
Index: /issm/trunk/src/c/modules/MeshProfileIntersectionx/SegmentIntersect.cpp
===================================================================
--- /issm/trunk/src/c/modules/MeshProfileIntersectionx/SegmentIntersect.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MeshProfileIntersectionx/SegmentIntersect.cpp	(revision 12330)
@@ -6,5 +6,5 @@
 int SegmentIntersect(double* palpha, double* pbeta, double* x1, double* y1, double* x2, double* y2){
 
-	/*See ISSM_TIER/src/m/utils/Geometry/SegIntersect.m for matlab routine from which we take this routine: */
+	/*See ISSM_DIR/src/m/utils/Geometry/SegIntersect.m for matlab routine from which we take this routine: */
 
 	/*output: */
Index: /issm/trunk/src/c/modules/MinVelx/MinVelx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MinVelx/MinVelx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MinVelx/MinVelx.cpp	(revision 12330)
@@ -32,6 +32,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&minvel,&node_minvel,1,MPI_DOUBLE,MPI_MIN,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_minvel,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MinVxx/MinVxx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MinVxx/MinVxx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MinVxx/MinVxx.cpp	(revision 12330)
@@ -31,6 +31,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&minvx,&node_minvx,1,MPI_DOUBLE,MPI_MIN,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_minvx,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MinVyx/MinVyx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MinVyx/MinVyx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MinVyx/MinVyx.cpp	(revision 12330)
@@ -31,6 +31,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&minvy,&node_minvy,1,MPI_DOUBLE,MPI_MIN,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_minvy,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/MinVzx/MinVzx.cpp
===================================================================
--- /issm/trunk/src/c/modules/MinVzx/MinVzx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/MinVzx/MinVzx.cpp	(revision 12330)
@@ -31,6 +31,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&minvz,&node_minvz,1,MPI_DOUBLE,MPI_MIN,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_minvz,1,MPI_DOUBLE,0,MPI_COMM_WORLD);   
Index: /issm/trunk/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp	(revision 12330)
@@ -63,5 +63,4 @@
 	else elements_width=6; //penta elements
 
-	#ifdef _PARALLEL_
 	/*Determine parallel partitioning of elements: we use Metis for now. First load the data, then partition*/
 	if(dim==2){
@@ -79,9 +78,4 @@
 	xfree((void**)&elements);
 	xfree((void**)&elements2d);
-
-	#else
-	/*In serial mode, epart is full of 0: all elements belong to cpu 0: */
-	epart=(int*)xcalloc(numberofelements,sizeof(int));
-	#endif
 
 	/*Deal with rifts, they have to be included into one partition only, not several: */
Index: /issm/trunk/src/c/modules/NodalValuex/NodalValuex.cpp
===================================================================
--- /issm/trunk/src/c/modules/NodalValuex/NodalValuex.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/NodalValuex/NodalValuex.cpp	(revision 12330)
@@ -36,10 +36,16 @@
 
 	/*Broadcast whether we found the element: */
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( &found,&sumfound,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
 	if(!sumfound)_error_("%s%i%s%s","could not find element with vertex with id",index," to compute nodal value ",EnumToStringx(natureofdataenum));
+	#endif
 
 	/*Broadcast and plug into response: */
+	#ifdef _HAVE_MPI_
 	MPI_Allreduce ( &cpu_found,&cpu_found,1,MPI_INT,MPI_MAX,MPI_COMM_WORLD);
 	MPI_Bcast(&value,1,MPI_DOUBLE,cpu_found,MPI_COMM_WORLD); 
+	#else
+	value=cpu_found;
+	#endif
 
 	*pnodalvalue=value;
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 12330)
@@ -16,9 +16,5 @@
 #include "../../objects/objects.h"
 		
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,Results* results){
-#else 
 void OutputResultsx(                    Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,Results* results){
-#endif
 
 	extern int  my_rank;
@@ -31,11 +27,4 @@
 	bool        dakota_analysis         = false;
 	
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	const char **fnames      = NULL;
-	mwSize       onebyone[2] = {0,0};
-	mwSize       ndim        = 2;
-	int          nfields=0;
-	#endif
-
 	/*retrieve parameters: */
 	parameters->FindParam(&dakota_analysis,QmuIsdakotaEnum);
@@ -43,7 +32,4 @@
 	if(dakota_analysis){
 		//no need to output anything, Dakota analysis has different outputs
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		*pdataref=mxCreateStructArray( ndim,onebyone,nfields,fnames);
-		#endif
 		return; 
 	}
@@ -56,5 +42,4 @@
 	/*Results do not include the type of solution being run	. In parallel, we output results to a filename, 
 	 *therefore, we need to include the solutiontype into the filename: */
-	#ifdef _PARALLEL_
 	if(my_rank==0){
 		parameters->FindParam(&solutiontype,SolutionTypeEnum);
@@ -88,26 +73,19 @@
 		parameters->SetParam(fid,OutputFilePointerEnum);
 	}
-	#endif
 
-	/*Write results to disk (in parallel), or to memory (in serial mode): */
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		results->Write(pdataref);
-	#else
-		results->Write(parameters);
-	#endif
+	/*Write results to disk: */
+	results->Write(parameters);
 
 	/*Delete and reinitialize results, in parallel: */
-	#ifdef _PARALLEL_
-		results->clear();
+	results->clear();
 
-		/*Close output file? :*/
-		/*WARNING: issm.cpp is taking care of it for now (quick fix)
-		if((step==1) && (time==0)){
-			if(io_gather){
-				if(my_rank==0) pfclose(fid,outputfilename);
-			}
-			else pfclose(fid,cpu_outputfilename);
-		}
-		*/
-	#endif
+	/*Close output file? :*/
+	/*WARNING: issm.cpp is taking care of it for now (quick fix)
+	  if((step==1) && (time==0)){
+	  if(io_gather){
+	  if(my_rank==0) pfclose(fid,outputfilename);
+	  }
+	  else pfclose(fid,cpu_outputfilename);
+	  }
+	*/
 }
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 12329)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 12330)
@@ -14,10 +14,5 @@
 #include "../../Container/Container.h"
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters, Results* results);
-#else
 void OutputResultsx(Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters, Results* results);
-#endif
 
 #endif  /* _OUTPUTRESULTS_H */
Index: /issm/trunk/src/c/modules/ParsePetscOptionsx/ParsePetscOptionsx.cpp
===================================================================
--- /issm/trunk/src/c/modules/ParsePetscOptionsx/ParsePetscOptionsx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ParsePetscOptionsx/ParsePetscOptionsx.cpp	(revision 12330)
@@ -10,4 +10,6 @@
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
 #endif
+
+#include <cstring>
 
 #include "./ParsePetscOptionsx.h"
@@ -92,6 +94,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Ok, broadcast to other cpus: */
+ 	#ifdef _HAVE_MPI_
 	MPI_Bcast(&numanalyses,1,MPI_INT,0,MPI_COMM_WORLD);
 	if(my_rank!=0){
@@ -100,4 +102,5 @@
 	}
 	MPI_Bcast(analyses,numanalyses,MPI_DOUBLE,0,MPI_COMM_WORLD);
+	#endif
 	for(i=0;i<numanalyses;i++){
 		char* string=strings[i];
@@ -106,10 +109,11 @@
 		}
 		if(my_rank==0)stringlength=(strlen(string)+1)*sizeof(char);
+		#ifdef _HAVE_MPI_
 		MPI_Bcast(&stringlength,1,MPI_INT,0,MPI_COMM_WORLD);
 		if(my_rank!=0)string=(char*)xmalloc(stringlength);
 		MPI_Bcast(string,stringlength,MPI_CHAR,0,MPI_COMM_WORLD);
 		if(my_rank!=0)strings[i]=string;
+		#endif
 	}
-	#endif
 
 	/*Ok, out of strings and analyses and numanalyses, create parameters, and plug them into parameters container: */
Index: /issm/trunk/src/c/modules/RheologyBbarAbsGradientx/RheologyBbarAbsGradientx.cpp
===================================================================
--- /issm/trunk/src/c/modules/RheologyBbarAbsGradientx/RheologyBbarAbsGradientx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/RheologyBbarAbsGradientx/RheologyBbarAbsGradientx.cpp	(revision 12330)
@@ -27,7 +27,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/Shp2Kmlx/Shp2Kmlx.h
===================================================================
--- /issm/trunk/src/c/modules/Shp2Kmlx/Shp2Kmlx.h	(revision 12329)
+++ /issm/trunk/src/c/modules/Shp2Kmlx/Shp2Kmlx.h	(revision 12330)
@@ -22,8 +22,6 @@
 
 /* local prototypes: */
-int Shp2Kmlx(char* filshp,char* filkml,
-			 int sgn);
-int Shp2Kmlx(char* filshp,char* filkml,
-			 int sgn,double cm,double sp);
+int Shp2Kmlx(char* filshp,char* filkml, int sgn);
+int Shp2Kmlx(char* filshp,char* filkml, int sgn,double cm,double sp);
 
 #endif  /* _SHP2KMLX_H */
Index: /issm/trunk/src/c/modules/Solverx/Solverx.cpp
===================================================================
--- /issm/trunk/src/c/modules/Solverx/Solverx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/Solverx/Solverx.cpp	(revision 12330)
@@ -34,8 +34,4 @@
 
 		/*In serial mode, the Petsc Options database has not been initialized properly: */
-		#ifdef _SERIAL_
-		parameters->FindParam(&analysis_type,AnalysisTypeEnum);
-		PetscOptionsFromAnalysis(parameters,analysis_type);
-		#endif
 
 		SolverxPetsc(&uf_vector,Kff->matrix,pf->vector,uf0_vector,df_vector,parameters);
Index: /issm/trunk/src/c/modules/Solverx/SolverxPetsc.cpp
===================================================================
--- /issm/trunk/src/c/modules/Solverx/SolverxPetsc.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/Solverx/SolverxPetsc.cpp	(revision 12330)
@@ -43,5 +43,4 @@
 	#endif
 
-
 	/*Display message*/
 	_printf_(VerboseModule(),"   Solving\n");
@@ -52,5 +51,5 @@
 	#endif
 
-	/*First, check that f-set is not NULL, i.e. model is fully constrained: {{{*/
+	/*First, check that f-set is not NULL, i.e. model is fully constrained:*/ 
 	_assert_(Kff);
 	MatGetSize(Kff,&global_m,&global_n); _assert_(global_m==global_m);
@@ -58,6 +57,6 @@
 		*puf=NULL; return;
 	}
-	/*}}}*/
-	/*Initial guess logic here: {{{1*/
+
+	/*Initial guess */
 	/*Now, check that we are not giving an initial guess to the solver, if we are running a direct solver: */
 	#if _PETSC_MAJOR_ >= 3 
@@ -74,54 +73,23 @@
 		MatGetLocalSize(Kff,&local_m,&local_n);uf=NewVec(local_n,fromlocalsize);
 	}
-	/*}}}*/
-	/*Process petsc options to see if we are using special types of external solvers: {{{1*/
+
+	/*Process petsc options to see if we are using special types of external solvers*/
 	PetscOptionsDetermineSolverType(&solver_type);
 
-	/*In serial mode, the matrices have been loaded as MPIAIJ or AIJ matrices. 
-	 We need to convert them if we are going to run the solvers successfully: */
-	#ifdef _SERIAL_
-	#if _PETSC_MAJOR_ == 2 
-	if (solver_type==MUMPSPACKAGE_LU){
-		/*Convert Kff to MATTAIJMUMPS: */
-		MatConvert(Kff,MATAIJMUMPS,MAT_REUSE_MATRIX,&Kff);
+	/*Check the solver is available*/
+	if(solver_type==MUMPSPACKAGE_LU || solver_type==MUMPSPACKAGE_CHOL){
+		#if _PETSC_MAJOR_ >=3
+			#ifndef _HAVE_MUMPS_
+			_error_("requested MUMPS solver, which was not compiled into ISSM!\n");
+			#endif
+		#endif
 	}
-	if (solver_type==MUMPSPACKAGE_CHOL){
-		/*Convert Kff to MATTSBAIJMUMPS: */
-		MatConvert(Kff,MATSBAIJMUMPS,MAT_REUSE_MATRIX,&Kff);
-	}
-	if (solver_type==SPOOLESPACKAGE_LU){
-		/*Convert Kff to MATTSBAIJMUMPS: */
-		MatConvert(Kff,MATAIJSPOOLES,MAT_REUSE_MATRIX,&Kff);
-	}
-	if (solver_type==SPOOLESPACKAGE_CHOL){
-		/*Convert Kff to MATTSBAIJMUMPS: */
-		MatConvert(Kff,MATSBAIJSPOOLES,MAT_REUSE_MATRIX,&Kff);
-	}
-	if (solver_type==SUPERLUDISTPACKAGE){
-		/*Convert Kff to MATTSBAIJMUMPS: */
-		MatConvert(Kff,MATSUPERLU_DIST,MAT_REUSE_MATRIX,&Kff);
-	}
-	if (solver_type==StokesSolverEnum){
-		_error_("Petsc 2 does not support multi-physics solvers");
-	}
-	#endif
-	#endif
-	/*}}}*/
-	/*Check the solver is available: {{{1*/
-	if(solver_type==MUMPSPACKAGE_LU || solver_type==MUMPSPACKAGE_CHOL){
-	#if _PETSC_MAJOR_ >=3
-		#ifndef _HAVE_MUMPS_
-		_error_("requested MUMPS solver, which was not compiled into ISSM!\n");
-		#endif
 
-	#endif
-	}
-	/*}}}*/
-	/*Prepare solver:{{{1*/
+	/*Prepare solver*/
 	KSPCreate(MPI_COMM_WORLD,&ksp);
 	KSPSetOperators(ksp,Kff,Kff,DIFFERENT_NONZERO_PATTERN);
 	KSPSetFromOptions(ksp);
 
-	#if defined(_SERIAL_) && _PETSC_MAJOR_==3
+	#if _PETSC_MAJOR_==3
 	/*Specific solver?: */
 	KSPGetPC(ksp,&pc);
@@ -133,7 +101,5 @@
 		#endif
 	}
-	#endif
 
-	#if defined(_PARALLEL_) && _PETSC_MAJOR_==3
 	/*Stokes: */
 	if (solver_type==StokesSolverEnum){
@@ -155,16 +121,15 @@
 	#endif
 
-	/*}}}*/
-	/*If there is an initial guess for the solution, use it, except if we are using the MUMPS direct solver, where any initial guess will crash Petsc: {{{1*/
+	/*If there is an initial guess for the solution, use it
+	 * except if we are using the MUMPS direct solver
+	 * where any initial guess will crash Petsc*/
 	if (uf0){
-		if( (solver_type!=MUMPSPACKAGE_LU) && (solver_type!=MUMPSPACKAGE_CHOL) && (solver_type!=SPOOLESPACKAGE_LU) && (solver_type!=SPOOLESPACKAGE_CHOL) && (solver_type!=SUPERLUDISTPACKAGE)){
+		if((solver_type!=MUMPSPACKAGE_LU) && (solver_type!=MUMPSPACKAGE_CHOL) && (solver_type!=SPOOLESPACKAGE_LU) && (solver_type!=SPOOLESPACKAGE_CHOL) && (solver_type!=SUPERLUDISTPACKAGE)){
 			KSPSetInitialGuessNonzero(ksp,PETSC_TRUE);
 		}
 	}
-	/*}}}*/
-	
-	if(VerboseSolver())KSPView(ksp,PETSC_VIEWER_STDOUT_WORLD);
 
 	/*Solve: */
+	if(VerboseSolver())KSPView(ksp,PETSC_VIEWER_STDOUT_WORLD);
 	KSPSolve(ksp,pf,uf);
 	
Index: /issm/trunk/src/c/modules/StringToEnumx/StringToEnumx.cpp
===================================================================
--- /issm/trunk/src/c/modules/StringToEnumx/StringToEnumx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/StringToEnumx/StringToEnumx.cpp	(revision 12330)
@@ -161,4 +161,5 @@
 	      else if (strcmp(name,"PetscProfilingCurrentFlops")==0) return PetscProfilingCurrentFlopsEnum;
 	      else if (strcmp(name,"PetscProfilingSolutionTime")==0) return PetscProfilingSolutionTimeEnum;
+	      else if (strcmp(name,"MaxIterationConvergenceFlag")==0) return MaxIterationConvergenceFlagEnum;
 	      else if (strcmp(name,"SteadystateMaxiter")==0) return SteadystateMaxiterEnum;
 	      else if (strcmp(name,"SteadystateNumRequestedOutputs")==0) return SteadystateNumRequestedOutputsEnum;
@@ -259,9 +260,9 @@
 	      else if (strcmp(name,"Input")==0) return InputEnum;
 	      else if (strcmp(name,"IntInput")==0) return IntInputEnum;
-	      else if (strcmp(name,"IntParam")==0) return IntParamEnum;
          else stage=3;
    }
    if(stage==3){
-	      if (strcmp(name,"IntVecParam")==0) return IntVecParamEnum;
+	      if (strcmp(name,"IntParam")==0) return IntParamEnum;
+	      else if (strcmp(name,"IntVecParam")==0) return IntVecParamEnum;
 	      else if (strcmp(name,"MacAyeal2dIceFront")==0) return MacAyeal2dIceFrontEnum;
 	      else if (strcmp(name,"MacAyeal3dIceFront")==0) return MacAyeal3dIceFrontEnum;
@@ -382,9 +383,9 @@
 	      else if (strcmp(name,"StressTensoryz")==0) return StressTensoryzEnum;
 	      else if (strcmp(name,"StressTensorzz")==0) return StressTensorzzEnum;
-	      else if (strcmp(name,"IceVolume")==0) return IceVolumeEnum;
          else stage=4;
    }
    if(stage==4){
-	      if (strcmp(name,"P0")==0) return P0Enum;
+	      if (strcmp(name,"IceVolume")==0) return IceVolumeEnum;
+	      else if (strcmp(name,"P0")==0) return P0Enum;
 	      else if (strcmp(name,"P1")==0) return P1Enum;
 	      else if (strcmp(name,"P1DG")==0) return P1DGEnum;
Index: /issm/trunk/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp
===================================================================
--- /issm/trunk/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/SurfaceAbsVelMisfitx/SurfaceAbsVelMisfitx.cpp	(revision 12330)
@@ -27,7 +27,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.cpp
===================================================================
--- /issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.cpp	(revision 12330)
@@ -28,7 +28,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
-	MPI_Reduce (&S,&S_sum,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD );
+	#ifdef _HAVE_MPI_
+ 	MPI_Reduce (&S,&S_sum,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&S_sum,1,MPI_DOUBLE,0,MPI_COMM_WORLD); 
 	S=S_sum;
+	#endif
 
 	/*add surface area to element inputs:*/
Index: /issm/trunk/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp
===================================================================
--- /issm/trunk/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/SurfaceAverageVelMisfitx/SurfaceAverageVelMisfitx.cpp	(revision 12330)
@@ -31,7 +31,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp
===================================================================
--- /issm/trunk/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/SurfaceLogVelMisfitx/SurfaceLogVelMisfitx.cpp	(revision 12330)
@@ -27,7 +27,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp
===================================================================
--- /issm/trunk/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/SurfaceLogVxVyMisfitx/SurfaceLogVxVyMisfitx.cpp	(revision 12330)
@@ -27,7 +27,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp
===================================================================
--- /issm/trunk/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/SurfaceRelVelMisfitx/SurfaceRelVelMisfitx.cpp	(revision 12330)
@@ -27,7 +27,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/ThicknessAbsGradientx/ThicknessAbsGradientx.cpp
===================================================================
--- /issm/trunk/src/c/modules/ThicknessAbsGradientx/ThicknessAbsGradientx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ThicknessAbsGradientx/ThicknessAbsGradientx.cpp	(revision 12330)
@@ -27,7 +27,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.cpp
===================================================================
--- /issm/trunk/src/c/modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/ThicknessAbsMisfitx/ThicknessAbsMisfitx.cpp	(revision 12330)
@@ -27,7 +27,9 @@
 
 	/*Sum all J from all cpus of the cluster:*/
+	#ifdef _HAVE_MPI_
 	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;
+	#endif
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/modules/TimeAdaptx/TimeAdaptx.cpp
===================================================================
--- /issm/trunk/src/c/modules/TimeAdaptx/TimeAdaptx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/TimeAdaptx/TimeAdaptx.cpp	(revision 12330)
@@ -31,6 +31,6 @@
 	}
 
-	#ifdef _PARALLEL_
 	/*Figure out minimum across the cluster: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce (&min_dt,&node_min_dt,1,MPI_DOUBLE,MPI_MIN,0,MPI_COMM_WORLD );
 	MPI_Bcast(&node_min_dt,1,MPI_DOUBLE,0,MPI_COMM_WORLD);
Index: /issm/trunk/src/c/modules/TriMeshx/TriMeshx.cpp
===================================================================
--- /issm/trunk/src/c/modules/TriMeshx/TriMeshx.cpp	(revision 12329)
+++ /issm/trunk/src/c/modules/TriMeshx/TriMeshx.cpp	(revision 12330)
@@ -10,8 +10,15 @@
 #include "../../toolkits/toolkits.h"
 #include "../../EnumDefinitions/EnumDefinitions.h"
+/*ANSI_DECLARATORS needed to call triangle library: */
+#ifndef ANSI_DECLARATORS
+#define ANSI_DECLARATORS
+#include "triangle.h"
+#undef ANSI_DECLARATORS
+#else
+#include "triangle.h"
+#endif
 /*}}}*/
 
-
-void TriMeshx(Matrix** pindex,Vector** px,Vector** py,Matrix** psegments,Vector** psegmentmarkerlist,DataSet* domain,double area,bool order){
+void TriMeshx(Matrix** pindex,Vector** px,Vector** py,Matrix** psegments,Vector** psegmentmarkerlist,DataSet* domain,DataSet* rifts,double area){
 
 	/*indexing: */
@@ -28,5 +35,5 @@
 
 	/*intermediary: */
-	int      counter,backcounter;
+	int      counter,counter2,backcounter;
 	Contour* contour=NULL;
 
@@ -39,6 +46,11 @@
 	for (i=0;i<domain->Size();i++){
 		contour=(Contour*)domain->GetObjectByOffset(i);
+		in.numberofpoints+=contour->nods-1;
+	}
+	for (i=0;i<rifts->Size();i++){
+		contour=(Contour*)rifts->GetObjectByOffset(i);
 		in.numberofpoints+=contour->nods;
 	}
+
 	/*number of point attributes: */
 	in.numberofpointattributes=1;
@@ -50,4 +62,12 @@
 	for (i=0;i<domain->Size();i++){
 		contour=(Contour*)domain->GetObjectByOffset(i);
+		for (j=0;j<contour->nods-1;j++){
+			in.pointlist[2*counter+0]=contour->x[j];
+			in.pointlist[2*counter+1]=contour->y[j];
+			counter++;
+		}
+	}
+	for (i=0;i<rifts->Size();i++){
+		contour=(Contour*)rifts->GetObjectByOffset(i);
 		for (j=0;j<contour->nods;j++){
 			in.pointlist[2*counter+0]=contour->x[j];
@@ -58,5 +78,5 @@
 	
 	/*fill in the point attribute list: */
-	in.pointattributelist = (REAL *) xmalloc(in.numberofpoints * in.numberofpointattributes * sizeof(REAL));
+	in.pointattributelist = (REAL*)xmalloc(in.numberofpoints*in.numberofpointattributes*sizeof(REAL));
 	for (i=0;i<in.numberofpoints;i++) in.pointattributelist[i] = 0.0;
 	
@@ -65,10 +85,14 @@
 	for(i=0;i<in.numberofpoints;i++) in.pointmarkerlist[i] = 0;
 
-
 	/*Build segments. First figure out number of segments: holes and closed outlines have as many segments as vertices: */
 	in.numberofsegments=0;
 	for (i=0;i<domain->Size();i++){
 		contour=(Contour*)domain->GetObjectByOffset(i);
-		in.numberofsegments+=contour->nods;
+		in.numberofsegments+=contour->nods-1;
+	}
+	for(i=0;i<rifts->Size();i++){
+		contour=(Contour*)rifts->GetObjectByOffset(i);
+		/*for rifts, we have one less segment as we have vertices*/
+		in.numberofsegments+=contour->nods-1;
 	}
 	
@@ -79,5 +103,5 @@
 	for (i=0;i<domain->Size();i++){
 		contour=(Contour*)domain->GetObjectByOffset(i);
-		for (j=0;j<contour->nods-1;j++){
+		for (j=0;j<contour->nods-2;j++){
 			in.segmentlist[2*counter+0]=counter;
 			in.segmentlist[2*counter+1]=counter+1;
@@ -92,5 +116,16 @@
 		 backcounter=counter;
 	}
-
+	counter2=counter;
+	for (i=0;i<rifts->Size();i++){
+		contour=(Contour*)rifts->GetObjectByOffset(i);
+		for (j=0;j<(contour->nods-1);j++){
+			in.segmentlist[2*counter2+0]=counter;
+			in.segmentlist[2*counter2+1]=counter+1;
+			in.segmentmarkerlist[counter2]=2+i;
+			counter2++;
+			counter++;
+		}
+		counter++;
+	}
 	
 	/*Build regions: */
@@ -103,20 +138,19 @@
 		for (i=0;i<domain->Size()-1;i++){
 			contour=(Contour*)domain->GetObjectByOffset(i+1);
-			GridInsideHole(&in.holelist[2*i+0],&in.holelist[2*i+1],contour->nods,contour->x,contour->y);
+			GridInsideHole(&in.holelist[2*i+0],&in.holelist[2*i+1],contour->nods-1,contour->x,contour->y);
 		}
 	}
 
 	/* Make necessary initializations so that Triangle can return a triangulation in `out': */
-
-	out.pointlist = (REAL *) NULL;            
-	out.pointattributelist = (REAL *) NULL;
-	out.pointmarkerlist = (int *) NULL; 
-	out.trianglelist = (int *) NULL;          
-	out.triangleattributelist = (REAL *) NULL;
-	out.neighborlist = (int *) NULL;         
-	out.segmentlist = (int *) NULL;
-	out.segmentmarkerlist = (int *) NULL;
-	out.edgelist = (int *) NULL;             
-	out.edgemarkerlist = (int *) NULL;   
+	out.pointlist             = (REAL*)NULL;
+	out.pointattributelist    = (REAL*)NULL;
+	out.pointmarkerlist       = (int *)NULL;
+	out.trianglelist          = (int *)NULL;
+	out.triangleattributelist = (REAL*)NULL;
+	out.neighborlist          = (int *)NULL;
+	out.segmentlist           = (int *)NULL;
+	out.segmentmarkerlist     = (int *)NULL;
+	out.edgelist              = (int *)NULL;
+	out.edgemarkerlist        = (int *)NULL;
 
 	/* Triangulate the points:.  Switches are chosen to read and write a  */
@@ -125,12 +159,7 @@
 	/*   produce an edge list (e), a Voronoi diagram (v), and a triangle */
 	/*   neighbor list (n).                                              */
-
 	sprintf(options,"%s%lf","pQzDq30ia",area); /*replace V by Q to quiet down the logging*/
-
-  
 	triangulate(options, &in, &out, NULL);
-
 	/*report(&out, 0, 1, 1, 1, 1, 0);*/
-
 
 	/*Allocate index, x and y: */
@@ -141,15 +170,14 @@
 	segmentmarkerlist=(double*)xmalloc(out.numberofsegments*sizeof(double));
 
-	for (i = 0; i < out.numberoftriangles; i++) {
+	for (i = 0; i< out.numberoftriangles; i++) {
 		for (j = 0; j < out.numberofcorners; j++) {
-			*(index+3*i+j)=(double)out.trianglelist[i * out.numberofcorners + j]+1;
-		}
-	}
-	for (i = 0; i < out.numberofpoints; i++) {
-		x[i]=out.pointlist[i * 2 + 0];
-		y[i]=out.pointlist[i * 2 + 1];
-	}
-	
-	for (i = 0; i < out.numberofsegments; i++) {
+			index[3*i+j]=(double)out.trianglelist[i*out.numberofcorners+j]+1;
+		}
+	}
+	for (i = 0; i< out.numberofpoints; i++){
+		x[i]=out.pointlist[i*2+0];
+		y[i]=out.pointlist[i*2+1];
+	}
+	for (i = 0; i<out.numberofsegments;i++){
 		segments[3*i+0]=(double)out.segmentlist[i*2+0]+1;
 		segments[3*i+1]=(double)out.segmentlist[i*2+1]+1;
@@ -157,14 +185,9 @@
 	}
 
-
-
 	/*Associate elements with segments: */
 	AssociateSegmentToElement(&segments,out.numberofsegments,index,out.numberoftriangles);
 
 	/*Order segments so that their normals point outside the domain: */
-	if(order){
-		OrderSegments(&segments,out.numberofsegments, index,out.numberoftriangles);
-	}
-
+	OrderSegments(&segments,out.numberofsegments, index,out.numberoftriangles);
 
 	/*Output : */
@@ -179,4 +202,3 @@
 	*py=new Vector(y,out.numberofpoints);
 	*psegmentmarkerlist=new Vector(segmentmarkerlist,out.numberofsegments);
-
 }
Index: /issm/trunk/src/c/modules/TriMeshx/TriMeshx.h
===================================================================
--- /issm/trunk/src/c/modules/TriMeshx/TriMeshx.h	(revision 12329)
+++ /issm/trunk/src/c/modules/TriMeshx/TriMeshx.h	(revision 12330)
@@ -6,22 +6,10 @@
 #define _TRIMESHX_H_
 
-
-
-/*ANSI_DECLARATORS needed to call triangle library: */
-#ifndef ANSI_DECLARATORS
-#define ANSI_DECLARATORS
-#include "triangle.h"
-#undef ANSI_DECLARATORS
-#else
-#include "triangle.h"
-#endif
-
 #include "string.h"
-
 #include "../../Container/Container.h"
 #include "../../objects/objects.h"
 
 /* local prototypes: */
-void TriMeshx(Matrix** pindex,Vector** px,Vector** py,Matrix** psegments,Vector** psegmentmarkerlist,DataSet* domain,double area,bool order);
+void TriMeshx(Matrix** pindex,Vector** px,Vector** py,Matrix** psegments,Vector** psegmentmarkerlist,DataSet* domain,DataSet* rifts,double area);
 
 #endif  /* _TRIMESHX_H */
Index: /issm/trunk/src/c/modules/modules.h
===================================================================
--- /issm/trunk/src/c/modules/modules.h	(revision 12329)
+++ /issm/trunk/src/c/modules/modules.h	(revision 12330)
@@ -62,4 +62,5 @@
 #include "./Exp2Kmlx/Exp2Kmlx.h"
 #include "./Kml2Expx/Kml2Expx.h"
+#include "./Krigingx/Krigingx.h"
 #include "./Shp2Kmlx/Shp2Kmlx.h"
 #include "./MassFluxx/MassFluxx.h"
@@ -112,7 +113,5 @@
 #include "./TimeAdaptx/TimeAdaptx.h"
 #include "./TriaSearchx/TriaSearchx.h"
-#ifdef _SERIAL_
 #include "./TriMeshx/TriMeshx.h"
-#endif
 #include "./ThicknessAbsMisfitx/ThicknessAbsMisfitx.h"
 #include "./ThicknessAbsGradientx/ThicknessAbsGradientx.h"
Index: /issm/trunk/src/c/objects/Bamg/BamgGeom.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgGeom.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/BamgGeom.cpp	(revision 12330)
@@ -19,20 +19,4 @@
 }
 /*}}}*/
-/*FUNCTION BamgGeom::BamgGeom(mxArray* matlab_struct){{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-BamgGeom::BamgGeom(mxArray* matlab_struct){
-
-	FetchData(&this->Vertices,        &this->VerticesSize[0],        &this->VerticesSize[1],        mxGetAssignedField(matlab_struct,0,"Vertices"));
-	FetchData(&this->Edges,           &this->EdgesSize[0],           &this->EdgesSize[1],           mxGetAssignedField(matlab_struct,0,"Edges"));
-	this->TangentAtEdgesSize[0]=0,    this->TangentAtEdgesSize[1]=0;    this->TangentAtEdges=NULL;
-	FetchData(&this->Corners,         &this->CornersSize[0],         &this->CornersSize[1],         mxGetAssignedField(matlab_struct,0,"Corners"));
-	FetchData(&this->RequiredVertices,&this->RequiredVerticesSize[0],&this->RequiredVerticesSize[1],mxGetAssignedField(matlab_struct,0,"RequiredVertices"));
-	FetchData(&this->RequiredEdges,   &this->RequiredEdgesSize[0],   &this->RequiredEdgesSize[1],   mxGetAssignedField(matlab_struct,0,"RequiredEdges"));
-	FetchData(&this->CrackedEdges,    &this->CrackedEdgesSize[0],    &this->CrackedEdgesSize[1],    mxGetAssignedField(matlab_struct,0,"CrackedEdges"));
-	FetchData(&this->SubDomains,      &this->SubDomainsSize[0],      &this->SubDomainsSize[1],      mxGetAssignedField(matlab_struct,0,"SubDomains"));
-
-}
-#endif
-/*}}}*/
 /*FUNCTION BamgGeom::~BamgGeom(){{{1*/
 BamgGeom::~BamgGeom(){
@@ -49,77 +33,2 @@
 }
 /*}}}*/
-
-/*Methods*/
-/*FUNCTION BamgGeom::SetMatlabStructureFields{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void BamgGeom::SetMatlabStructureFields(mxArray** matlab_struct){
-
-	/*Intermediary*/
-	int         i;
-	mxArray*    output=NULL;
-	const int         numfields=7;
-	const char* fnames[numfields];
-	mwSize      ndim=2;
-	mwSize      dimensions[2]={1,1};
-
-	/*Initialize field names*/
-	i=0;
-	fnames[i++] = "Vertices";
-	fnames[i++] = "Edges";
-	fnames[i++] = "TangentAtEdges";
-	fnames[i++] = "RequiredVertices";
-	fnames[i++] = "RequiredEdges";
-	fnames[i++] = "CrackedEdges";
-	fnames[i++] = "SubDomains";
-	_assert_(i==numfields);
-
-	/*Initialize Matlab structure*/
-	output=mxCreateStructArray(ndim,dimensions,numfields,fnames);
-
-	/*set each matlab each field*/
-	i=0;
-	i++; SetMatlabStructureField(output,"Vertices",        this->VerticesSize[0],        this->VerticesSize[1],        this->Vertices);
-	i++; SetMatlabStructureField(output,"Edges",           this->EdgesSize[0],           this->EdgesSize[1],           this->Edges);
-	i++; SetMatlabStructureField(output,"TangentAtEdges",  this->TangentAtEdgesSize[0],  this->TangentAtEdgesSize[1],  this->TangentAtEdges);
-	i++; SetMatlabStructureField(output,"RequiredVertices",this->RequiredVerticesSize[0],this->RequiredVerticesSize[1],this->RequiredVertices);
-	i++; SetMatlabStructureField(output,"RequiredEdges",   this->RequiredEdgesSize[0],   this->RequiredEdgesSize[1],   this->RequiredEdges);
-	i++; SetMatlabStructureField(output,"CrackedEdges",    this->CrackedEdgesSize[0],    this->CrackedEdgesSize[1],    this->CrackedEdges);
-	i++; SetMatlabStructureField(output,"SubDomains",      this->SubDomainsSize[0],      this->SubDomainsSize[1],      this->SubDomains);
-	_assert_(i==numfields);
-
-	/*Assign output*/
-	*matlab_struct=output;
-
-}
-#endif
-/*}}}*/
-/*FUNCTION BamgGeom::SetMatlabStructureField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void BamgGeom::SetMatlabStructureField(mxArray* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer){
-
-	/*Intermediary*/
-	int         i1,i2;
-	mxArray*    pfield=NULL;
-	mxArray*    pfield2=NULL;
-
-	/*Copy field*/
-	double*  fieldcopy=NULL;
-	if (fieldrows*fieldcols){
-		fieldcopy=(double*)xmalloc(fieldrows*fieldcols*sizeof(double));
-		for(i1=0;i1<fieldrows;i1++){
-			for(i2=0;i2<fieldcols;i2++){
-				fieldcopy[fieldcols*i1+i2]=fieldpointer[fieldcols*i1+i2];
-			}
-		}
-	}
-
-	/*Set matlab field*/
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,fieldcols);
-	mxSetN(pfield,fieldrows);
-	mxSetPr(pfield,fieldcopy);
-	mexCallMATLAB(1,&pfield2,1,&pfield,"transpose");//transpose
-	mxSetField(matlab_struct,0,fieldname,pfield2);
-}
-#endif
-/*}}}*/
Index: /issm/trunk/src/c/objects/Bamg/BamgGeom.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgGeom.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/BamgGeom.h	(revision 12330)
@@ -4,8 +4,4 @@
 #ifndef _BAMGGEOM_H_
 #define _BAMGGEOM_H_
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
 
 class BamgGeom{
@@ -30,13 +26,5 @@
 
 		BamgGeom();
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		BamgGeom(mxArray* matlab_struct);
-		#endif
 		~BamgGeom();
-
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void SetMatlabStructureFields(mxArray** matlab_struct);
-		void SetMatlabStructureField(mxArray* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
-		#endif
 };
 
Index: /issm/trunk/src/c/objects/Bamg/BamgMesh.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgMesh.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/BamgMesh.cpp	(revision 12330)
@@ -18,7 +18,7 @@
 	this->CrackedEdgesSize[0]=0,              this->CrackedEdgesSize[1]=0;             this->CrackedEdges=NULL;
 
-	this->VerticesOnGeomVertexSize[0]=0, this->VerticesOnGeomVertexSize[1]=0;this->VerticesOnGeomVertex=NULL;
-	this->VerticesOnGeomEdgeSize[0]=0,   this->VerticesOnGeomEdgeSize[1]=0;  this->VerticesOnGeomEdge=NULL;
-	this->EdgesOnGeomEdgeSize[0]=0,      this->EdgesOnGeomEdgeSize[1]=0;     this->EdgesOnGeomEdge=NULL;
+	this->VerticesOnGeomVertexSize[0]=0,      this->VerticesOnGeomVertexSize[1]=0;     this->VerticesOnGeomVertex=NULL;
+	this->VerticesOnGeomEdgeSize[0]=0,        this->VerticesOnGeomEdgeSize[1]=0;       this->VerticesOnGeomEdge=NULL;
+	this->EdgesOnGeomEdgeSize[0]=0,           this->EdgesOnGeomEdgeSize[1]=0;          this->EdgesOnGeomEdge=NULL;
 
 	this->IssmEdgesSize[0]=0,                 this->IssmEdgesSize[1]=0;                this->IssmEdges=NULL;
@@ -28,37 +28,5 @@
 	this->NodalConnectivitySize[0]=0,         this->NodalConnectivitySize[1]=0;        this->NodalConnectivity=NULL;
 	this->NodalElementConnectivitySize[0]=0,  this->NodalElementConnectivitySize[1]=0; this->NodalElementConnectivity=NULL;
-
-
 }
-/*}}}*/
-/*FUNCTION BamgMesh::BamgMesh(mxArray* matlab_struct){{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-BamgMesh::BamgMesh(mxArray* matlab_struct){
-
-	int lines,cols;
-
-	FetchData(&this->Vertices,            &this->VerticesSize[0],            &this->VerticesSize[1],            mxGetAssignedField(matlab_struct,0,"Vertices"));
-	FetchData(&this->Edges,               &this->EdgesSize[0],               &this->EdgesSize[1],               mxGetAssignedField(matlab_struct,0,"Edges"));
-	FetchData(&this->Triangles,           &this->TrianglesSize[0],           &this->TrianglesSize[1],           mxGetAssignedField(matlab_struct,0,"Triangles"));
-	this->QuadrilateralsSize[0]=0,        this->QuadrilateralsSize[1]=0;     this->Quadrilaterals=NULL;
-
-	this->SubDomainsSize[0]=0,            this->SubDomainsSize[1]=0;         this->SubDomains=NULL;
-	this->SubDomainsFromGeomSize[0]=0,    this->SubDomainsFromGeomSize[1]=0; this->SubDomainsFromGeom=NULL;
-	this->CrackedVerticesSize[0]=0,       this->CrackedVerticesSize[1]=0;    this->CrackedVertices=NULL;
-	FetchData(&this->CrackedEdges,        &this->CrackedEdgesSize[0],        &this->CrackedEdgesSize[1],        mxGetAssignedField(matlab_struct,0,"CrackedEdges"));
-
-	FetchData(&this->VerticesOnGeomEdge,  &this->VerticesOnGeomEdgeSize[0],  &this->VerticesOnGeomEdgeSize[1],  mxGetAssignedField(matlab_struct,0,"VerticesOnGeomEdge"));
-	FetchData(&this->VerticesOnGeomVertex,&this->VerticesOnGeomVertexSize[0],&this->VerticesOnGeomVertexSize[1],mxGetAssignedField(matlab_struct,0,"VerticesOnGeomVertex"));
-	FetchData(&this->EdgesOnGeomEdge,     &this->EdgesOnGeomEdgeSize[0],     &this->EdgesOnGeomEdgeSize[1],     mxGetAssignedField(matlab_struct,0,"EdgesOnGeomEdge"));
-
-	this->IssmEdgesSize[0]=0,             this->IssmEdgesSize[1]=0;          this->IssmEdges=NULL;
-	FetchData(&this->IssmSegments,        &this->IssmSegmentsSize[0],        &this->IssmSegmentsSize[1],        mxGetAssignedField(matlab_struct,0,"IssmSegments"));
-
-	this->ElementConnectivitySize[0]=0,      this->ElementConnectivitySize[1]=0;      this->ElementConnectivity=NULL;
-	this->NodalConnectivitySize[0]=0,        this->NodalConnectivitySize[1]=0;        this->NodalConnectivity=NULL;
-	this->NodalElementConnectivitySize[0]=0, this->NodalElementConnectivitySize[1]=0; this->NodalElementConnectivity=NULL;
-
-}
-#endif
 /*}}}*/
 /*FUNCTION BamgMesh::~BamgMesh(){{{1*/
@@ -89,95 +57,2 @@
 }
 /*}}}*/
-
-/*Methods*/
-/*FUNCTION BamgMesh::SetMatlabStructureFields{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void BamgMesh::SetMatlabStructureFields(mxArray** matlab_struct){
-
-	/*Intermediary*/
-	int         i;
-	mxArray*    output=NULL;
-	const int         numfields=16;
-	const char* fnames[numfields];
-	mwSize      ndim=2;
-	mwSize      dimensions[2]={1,1};
-
-	/*Initialize field names*/
-	i=0;
-	fnames[i++] = "Triangles";
-	fnames[i++] = "Vertices";
-	fnames[i++] = "Edges";
-	fnames[i++] = "IssmSegments";
-	fnames[i++] = "IssmEdges";
-	fnames[i++] = "Quadrilaterals";
-	fnames[i++] = "VerticesOnGeomVertex";
-	fnames[i++] = "VerticesOnGeomEdge";
-	fnames[i++] = "EdgesOnGeomEdge";
-	fnames[i++] = "SubDomains";
-	fnames[i++] = "SubDomainsFromGeom";
-	fnames[i++] = "ElementConnectivity";
-	fnames[i++] = "NodalConnectivity";
-	fnames[i++] = "NodalElementConnectivity";
-	fnames[i++] = "CrackedVertices";
-	fnames[i++] = "CrackedEdges";
-	_assert_(i==numfields);
-
-	/*Initialize Matlab structure*/
-	output=mxCreateStructArray(ndim,dimensions,numfields,fnames);
-
-	/*set each matlab each field*/
-	i=0;
-	i++; SetMatlabStructureField(output,"Triangles",                this->TrianglesSize[0],                this->TrianglesSize[1],                 this->Triangles);
-	i++; SetMatlabStructureField(output,"Vertices",                 this->VerticesSize[0],                 this->VerticesSize[1],                  this->Vertices);
-	i++; SetMatlabStructureField(output,"Edges",                    this->EdgesSize[0],                    this->EdgesSize[1],                     this->Edges);
-	i++; SetMatlabStructureField(output,"IssmSegments",             this->IssmSegmentsSize[0],             this->IssmSegmentsSize[1],              this->IssmSegments);
-	i++; SetMatlabStructureField(output,"IssmEdges",                this->IssmEdgesSize[0],                this->IssmEdgesSize[1],                 this->IssmEdges);
-	i++; SetMatlabStructureField(output,"Quadrilaterals",           this->QuadrilateralsSize[0],           this->QuadrilateralsSize[1],            this->Quadrilaterals);
-	i++; SetMatlabStructureField(output,"VerticesOnGeomVertex",this->VerticesOnGeomVertexSize[0],this->VerticesOnGeomVertexSize[1], this->VerticesOnGeomVertex);
-	i++; SetMatlabStructureField(output,"VerticesOnGeomEdge",  this->VerticesOnGeomEdgeSize[0],  this->VerticesOnGeomEdgeSize[1],   this->VerticesOnGeomEdge);
-	i++; SetMatlabStructureField(output,"EdgesOnGeomEdge",     this->EdgesOnGeomEdgeSize[0],     this->EdgesOnGeomEdgeSize[1],      this->EdgesOnGeomEdge);
-	i++; SetMatlabStructureField(output,"SubDomains",               this->SubDomainsSize[0],               this->SubDomainsSize[1],                this->SubDomains);
-	i++; SetMatlabStructureField(output,"SubDomainsFromGeom",       this->SubDomainsFromGeomSize[0],       this->SubDomainsFromGeomSize[1],        this->SubDomainsFromGeom);
-	i++; SetMatlabStructureField(output,"ElementConnectivity",      this->ElementConnectivitySize[0],      this->ElementConnectivitySize[1],       this->ElementConnectivity);
-	i++; SetMatlabStructureField(output,"NodalConnectivity",        this->NodalConnectivitySize[0],        this->NodalConnectivitySize[1],         this->NodalConnectivity);
-	i++; SetMatlabStructureField(output,"NodalElementConnectivity", this->NodalElementConnectivitySize[0], this->NodalElementConnectivitySize[1],  this->NodalElementConnectivity);
-	i++; SetMatlabStructureField(output,"CrackedVertices",          this->CrackedVerticesSize[0],          this->CrackedVerticesSize[1],           this->CrackedVertices);
-	i++; SetMatlabStructureField(output,"CrackedEdges",             this->CrackedEdgesSize[0],             this->CrackedEdgesSize[1],              this->CrackedEdges);
-	_assert_(i==numfields);
-
-	/*Assign output*/
-	*matlab_struct=output;
-
-}
-#endif
-/*}}}*/
-/*FUNCTION BamgMesh::SetMatlabStructureField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void BamgMesh::SetMatlabStructureField(mxArray* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer){
-
-	/*Intermediary*/
-	int         i1,i2;
-	mxArray*    pfield=NULL;
-	mxArray*    pfield2=NULL;
-
-	/*Copy field*/
-	double*  fieldcopy=NULL;
-	if (fieldrows*fieldcols){
-		fieldcopy=(double*)xmalloc(fieldrows*fieldcols*sizeof(double));
-		for(i1=0;i1<fieldrows;i1++){
-			for(i2=0;i2<fieldcols;i2++){
-				fieldcopy[fieldcols*i1+i2]=fieldpointer[fieldcols*i1+i2];
-			}
-		}
-	}
-
-	/*Set matlab field*/
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,fieldcols);
-	mxSetN(pfield,fieldrows);
-	mxSetPr(pfield,fieldcopy);
-	mexCallMATLAB(1,&pfield2,1,&pfield,"transpose");//transpose
-	mxSetField(matlab_struct,0,fieldname,pfield2);
-}
-#endif
-/*}}}*/
Index: /issm/trunk/src/c/objects/Bamg/BamgMesh.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgMesh.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/BamgMesh.h	(revision 12330)
@@ -4,8 +4,4 @@
 #ifndef _BAMGMESH_H_
 #define _BAMGMESH_H_
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
 
 class BamgMesh{
@@ -51,14 +47,5 @@
 
 		BamgMesh();
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		BamgMesh(mxArray* matlab_struct);
-		#endif
 		~BamgMesh();
-
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void SetMatlabStructureFields(mxArray** matlab_struct);
-		void SetMatlabStructureField(mxArray* matlab_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
-		#endif
-
 };
 
Index: /issm/trunk/src/c/objects/Bamg/BamgOpts.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgOpts.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/BamgOpts.cpp	(revision 12330)
@@ -40,44 +40,4 @@
 
 }
-/*}}}*/
-/*FUNCTION BamgOpts::BamgOpts(mxArray* matlab_struct){{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-BamgOpts::BamgOpts(mxArray* matlab_struct){
-
-	FetchData(&this->anisomax,mxGetField(matlab_struct,0,"anisomax"));
-	FetchData(&this->cutoff,mxGetField(matlab_struct,0,"cutoff"));
-	FetchData(&this->coeff,mxGetField(matlab_struct,0,"coeff"));
-	FetchData(&this->errg,mxGetField(matlab_struct,0,"errg"));
-	FetchData(&this->gradation,mxGetField(matlab_struct,0,"gradation"));
-	FetchData(&this->Hessiantype,mxGetField(matlab_struct,0,"Hessiantype"));
-	FetchData(&this->MaxCornerAngle,mxGetField(matlab_struct,0,"MaxCornerAngle"));
-	FetchData(&this->maxnbv,mxGetField(matlab_struct,0,"maxnbv"));
-	FetchData(&this->maxsubdiv,mxGetField(matlab_struct,0,"maxsubdiv"));
-	FetchData(&this->Metrictype,mxGetField(matlab_struct,0,"Metrictype"));
-	FetchData(&this->nbjacobi,mxGetField(matlab_struct,0,"nbjacobi"));
-	FetchData(&this->nbsmooth,mxGetField(matlab_struct,0,"nbsmooth"));
-	FetchData(&this->omega,mxGetField(matlab_struct,0,"omega"));
-	FetchData(&this->power,mxGetField(matlab_struct,0,"power"));
-	FetchData(&this->verbose,mxGetField(matlab_struct,0,"verbose"));
-
-	FetchData(&this->Crack,mxGetField(matlab_struct,0,"Crack"));
-	FetchData(&this->geometricalmetric,mxGetField(matlab_struct,0,"geometricalmetric"));
-	FetchData(&this->KeepVertices,mxGetField(matlab_struct,0,"KeepVertices"));
-	FetchData(&this->splitcorners,mxGetField(matlab_struct,0,"splitcorners"));
-
-	FetchData(&this->hmin,mxGetField(matlab_struct,0,"hmin"));
-	FetchData(&this->hmax,mxGetField(matlab_struct,0,"hmax"));
-	FetchData(&this->hminVertices,&this->hminVerticesSize[0],&this->hminVerticesSize[1],mxGetField(matlab_struct,0,"hminVertices"));
-	FetchData(&this->hmaxVertices,&this->hmaxVerticesSize[0],&this->hmaxVerticesSize[1],mxGetField(matlab_struct,0,"hmaxVertices"));
-	FetchData(&this->hVertices,&this->hVerticesSize[0],&this->hVerticesSize[1],mxGetField(matlab_struct,0,"hVertices"));
-	FetchData(&this->metric,&this->metricSize[0],&this->metricSize[1],mxGetField(matlab_struct,0,"metric"));
-	FetchData(&this->field,&this->fieldSize[0],&this->fieldSize[1],mxGetField(matlab_struct,0,"field"));
-	FetchData(&this->err,&this->errSize[0],&this->errSize[1],mxGetField(matlab_struct,0,"err"));
-
-	/*Additional checks*/
-	this->Check();
-
-}
-#endif
 /*}}}*/
 /*FUNCTION BamgOpts::~BamgOpts() {{{1*/
Index: /issm/trunk/src/c/objects/Bamg/BamgOpts.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgOpts.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/BamgOpts.h	(revision 12330)
@@ -5,8 +5,4 @@
 #ifndef _BAMGOPTS_H_
 #define _BAMGOPTS_H_
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
 
 class BamgOpts{
@@ -54,7 +50,4 @@
 
 		BamgOpts();
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		BamgOpts(mxArray* matlab_struct);
-		#endif
 		~BamgOpts();
 
Index: /issm/trunk/src/c/objects/Bamg/BamgQuadtree.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgQuadtree.cpp	(revision 12330)
+++ /issm/trunk/src/c/objects/Bamg/BamgQuadtree.cpp	(revision 12330)
@@ -0,0 +1,598 @@
+#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "../objects.h"
+
+namespace bamg {
+
+	/*MACROS {{{1*/
+	/* 
+	 * 
+	 *    J    j
+	 *    ^    ^
+	 *    |    | +--------+--------+
+	 *    |    | |        |        |
+	 * 1X |    | |   2    |   3    |
+	 *    |    | |        |        |
+	 *    |    | +--------+--------+
+	 *    |    | |        |        |
+	 * 0X |    | |   0    |   1    |
+	 *    |    | |        |        |
+	 *    |    | +--------+--------+
+	 *    |    +-----------------------> i
+	 *    |         
+	 *    |----------------------------> I
+	 *              X0        X1  
+	 *
+	 * box 0 -> I=0 J=0 IJ=00  = 0
+	 * box 1 -> I=1 J=0 IJ=01  = 1
+	 * box 2 -> I=0 J=1 IJ=10  = 2
+	 * box 3 -> I=1 J=1 IJ=11  = 3
+	 */
+#define INTER_SEG(a,b,x,y) (((y) > (a)) && ((x) <(b)))
+#define ABS(i) ((i)<0 ?-(i) :(i))
+#define MAX1(i,j) ((i)>(j) ?(i) :(j))
+#define NORM(i1,j1,i2,j2) MAX1(ABS((i1)-(j1)),ABS((i2)-(j2)))
+
+	//IJ(i,j,l) returns the box number of i and j with respect to l
+	//if !j&l and !i&l -> 0 (box zero: lower left )
+	//if !j&l and  i&l -> 1 (box one:  lower right)
+	//if  j&l and !i&l -> 2 (box two:  upper left )
+	//if  j&l and  i&l -> 3 (box three:upper right)
+#define IJ(i,j,l)  ((j&l) ? ((i&l) ? 3:2 ) :((i&l) ? 1:0 ))
+
+	//I_IJ(k,l) returns l if first  bit of k is 1, else 0
+#define I_IJ(k,l)  ((k&1) ? l:0)
+	//J_IJ(k,l) returns l if second bit of k is 1, else 0
+#define J_IJ(k,l)  ((k&2) ? l:0)
+	/*}}}*/
+	/*DOCUMENTATION What is a BamgQuadtree? {{{1
+	 * A Quadtree is a very simple way to group vertices according
+	 * to their locations. A square that holds all the points of the mesh
+	 * (or the geometry) is divided into 4 boxes. As soon as one box
+	 * hold more than 4 vertices, it is divided into 4 new boxes, etc...
+	 * There cannot be more than MAXDEEP (=30) subdivision.
+	 * This process is like a Dichotomy in dimension 2
+	 *
+	 *  + - -  -    - -    -    - - + -   - + - + - + - -     - - +
+	 *  |                           |       |   | X |             |
+	 *                                      + - + - +
+	 *  |                           |       |   |   |             |
+	 *                              + -   - + - + - +             +
+	 *  |                           |       |       |             |
+	 *                         
+	 *  |                           |       |       |             |
+	 *  + - -  -    - -    -    - - + -   - + -   - + - -     - - +
+	 *  |                           |               |             |
+	 *                         
+	 *  |                           |               |             |
+	 *                         
+	 *  |                           |               |             |
+	 *  |                           |               |             |
+	 *  + - -  -    - -    -    - - + -   -   -   - + - -     - - +
+	 *  |                           |                             |
+	 *                         
+	 *  |                           |                             |
+	 *                         
+	 *  |                           |                             |
+	 *                         
+	 *  |                           |                             |
+	 *  |                           |                             |
+	 *  |                           |                             |
+	 *  |                           |                             |
+	 *  |                           |                             |
+	 *  + - -  -    - -    -    - - + -   -   -   -   - -     - - +
+	 *
+	 * The coordinate system used in a quadtree are integers to avoid
+	 * round-off errors. The vertex in the lower left box has the coordinates
+	 * (0 0) 
+	 * The upper right vertex has the follwing coordinates:
+	 * 2^30 -1           2^30 -1        in decimal
+	 * 0 1 1 1 .... 1    0 1 1 1 .... 1 in binary
+	 *  \--   29  --/     \--   29  --/
+	 * Using binaries is therefore very easy to locate a vertex in a box:
+	 * we just need to look at the bits from the left to the right (See ::Add)
+	 }}}1*/
+
+	/*Constructors/Destructors*/
+	/*FUNCTION BamgQuadtree::BamgQuadtree(){{{1*/
+	BamgQuadtree::BamgQuadtree(){
+
+		/*Number of boxes and vertices*/
+		NbBamgQuadtreeBox=0;
+		NbVertices=0;
+
+		/*Create container*/
+		boxcontainer=new DataSet();
+
+		/*Create Root, pointer toward the main box*/
+		root=NewBamgQuadtreeBox();
+
+		}
+	/*}}}1*/
+	/*FUNCTION BamgQuadtree::BamgQuadtree(Mesh * t,long nbv){{{1*/
+	BamgQuadtree::BamgQuadtree(Mesh * t,long nbv){ 
+
+		/*Number of boxes and vertices*/
+		NbBamgQuadtreeBox=0;
+		NbVertices=0;
+
+		/*Create container*/
+		boxcontainer=new DataSet();
+
+		/*Create Root, pointer toward the main box*/
+		root=NewBamgQuadtreeBox();
+
+		/*Check Sizes*/
+		_assert_(MaxISize>MaxICoor);
+
+		/*Add all vertices of the mesh*/
+		if (nbv==-1) nbv=t->nbv;
+		for (int i=0;i<nbv;i++) Add(t->vertices[i]);
+
+	}
+	/*}}}1*/
+	/*FUNCTION BamgQuadtree::~BamgQuadtree(){{{1*/
+	BamgQuadtree::~BamgQuadtree() {
+		delete boxcontainer;
+		root=NULL;
+	}
+	/*}}}1*/
+
+	/*Methods*/
+	/*FUNCTION BamgQuadtree::Add{{{1*/
+	void  BamgQuadtree::Add(BamgVertex &w){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, BamgQuadtree.cpp/Add)*/
+		BamgQuadtreeBox** pb=NULL;
+		BamgQuadtreeBox*  b=NULL;
+
+		/*Get integer coodinate of current point w*/
+		register long i=w.i.x, j=w.i.y;
+
+		/*Initialize level*/
+		register long level=MaxISize;
+
+		/*Get inital box (the largest)*/
+		pb = &root;
+
+		/*Find the smallest box where w is located*/
+		while((b=*pb) && (b->nbitems<0)){ 
+
+			//shift b->nbitems by -1
+			b->nbitems--;
+
+			//shifted righ by one bit: level=00000010 -> 00000001
+			level >>= 1;
+
+			//Get next subbox according to the bit value (level)
+			pb = &b->b[IJ(i,j,level)];
+		}
+
+		/*OK, we have found b, a Subbox holding vertices (might be full)
+		  check that the vertex is not already in the box*/
+		if (b){      
+			if (b->nbitems > 3 &&  b->v[3] == &w) return;
+			if (b->nbitems > 2 &&  b->v[2] == &w) return;
+			if (b->nbitems > 1 &&  b->v[1] == &w) return;
+			if (b->nbitems > 0 &&  b->v[0] == &w) return;
+		}
+
+		/*check that l is not 0 (this should not happen as MaxDepth = 30)*/
+		_assert_(level>0);
+
+		/*Now, try to add the vertex, if the subbox is full (nbitems=4), we have to divide it
+		  in 4 new subboxes*/
+		while ((b= *pb) && (b->nbitems == 4)){ // the BamgQuadtreeBox is full
+
+			/*Copy the 4 vertices in the current BamgQuadtreebox*/
+			BamgVertex* v4[4];
+			v4[0]= b->v[0];
+			v4[1]= b->v[1];
+			v4[2]= b->v[2];
+			v4[3]= b->v[3];
+
+			/*set nbitems as negative 
+			 * (box full -> holds 4 pointers toward subboxes and not 4 vertices)*/
+			b->nbitems = -b->nbitems;
+
+			/*Initialize the 4 pointers toward the 4 subboxes*/
+			b->b[0]=b->b[1]=b->b[2]=b->b[3]=NULL;
+
+			/*level = 0010000 -> 0001000*/
+			level >>= 1;
+
+			/*Put the four vertices in the new boxes*/
+			for (int k=0;k<4;k++){
+
+				int          ij;
+				/*bb is the new "sub"box of b where v4[k] is located*/
+				BamgQuadtreeBox *bb = b->b[ij=IJ(v4[k]->i.x,v4[k]->i.y,level)];
+
+				// alloc the BamgQuadtreeBox
+				if (!bb) bb=b->b[ij]=NewBamgQuadtreeBox(); 
+
+				/*Copy the current vertex*/
+				bb->v[bb->nbitems++] = v4[k];
+			}
+
+			/*Get the subbox where w (i,j) is located*/
+			pb = &b->b[IJ(i,j,level)];
+		}
+
+		/*alloc the BamgQuadtreeBox if necessary*/
+		if (!(b=*pb)) b=*pb= NewBamgQuadtreeBox();
+
+		/*Add w*/
+		b->v[b->nbitems++]=&w;
+
+		//Increase NbVertices by one (we have one new vertex)
+		NbVertices++;
+	}
+	/*}}}1*/
+	/*FUNCTION BamgQuadtree::NearestVertex{{{1*/
+	BamgVertex*  BamgQuadtree::NearestVertex(Icoor1 i,Icoor1 j) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, BamgQuadtree.cpp/NearestVertex)*/
+
+		/*Intermediaries*/
+		BamgQuadtreeBox *pb[MaxDepth];
+		int          pi[MaxDepth];
+		Icoor1       ii[MaxDepth];
+		Icoor1       jj[MaxDepth];
+		int          level;
+		long         n0;
+		BamgQuadtreeBox *b;
+		long         h0;
+		long         h = MaxISize;
+		long         hb= MaxISize;
+		Icoor1       i0=0,j0=0;
+
+		/*initial output as NULL (no vertex found)*/
+		BamgVertex*  nearest_v=NULL;
+
+		/*Project w coordinates (i,j) onto [0,MaxISize-1] x [0,MaxISize-1] -> (iplus,jplus)*/
+		Icoor1 iplus( i<MaxISize ? (i<0?0:i) : MaxISize-1);
+		Icoor1 jplus( j<MaxISize ? (j<0?0:j) : MaxISize-1);
+
+		/*Get initial Quadtree box (largest)*/
+		b = root;
+
+		/*if the tree is empty, return NULL pointer*/
+		if (!root->nbitems) return nearest_v; 
+
+		/*else, find the smallest non-empty BamgQuadtreeBox containing  the point (i,j)*/
+		while((n0=b->nbitems)<0){
+
+			Icoor1       hb2 = hb >> 1;             //size of the current box
+			int          k   = IJ(iplus,jplus,hb2); //box number (0,1,2 or 3)
+			BamgQuadtreeBox *b0  = b->b[k];             //pointer toward current box
+
+			/* break if NULL box or empty (Keep previous box b)*/
+			if (( b0 == NULL) || (b0->nbitems == 0)) break;
+
+			/*Get next Quadtree box*/
+			b=b0;	
+			i0 += I_IJ(k,hb2); // i orign of BamgQuadtreeBox (macro)
+			j0 += J_IJ(k,hb2); // j orign of BamgQuadtreeBox 
+			hb = hb2;          // size of the box (in Int)
+		}
+
+		/*The box b, is the smallest box containing the point (i,j) and
+		 * has the following properties:
+		 * - n0: number of items (>0 if vertices, else boxes)
+		 * - hb: box size (int)
+		 * - i0: x coordinate of the lower left corner
+		 * - j0: y coordinate of the lower left corner*/
+
+		/* if the current subbox is holding vertices, we are almost done*/
+		if (n0>0){  
+			//loop over the vertices of the box and find the closest vertex
+			for(int k=0;k<n0;k++){
+
+				/*get integer coordinates of current vertex*/
+				I2 i2=b->v[k]->i;
+
+				/*Compute norm with w*/
+				h0=NORM(iplus,i2.x,jplus,i2.y);
+
+				/*is it smaller than previous value*/
+				if (h0<h){
+					h = h0;
+					nearest_v = b->v[k];
+				}
+			}
+			/*return closest vertex*/
+			return nearest_v;
+		}
+
+		/* general case: the current box is empty, we have to go backwards
+			and find the closest not-empty box and find the closest vertex*/
+
+		/*Initialize search variables*/
+		pb[0]=b;                             //pointer toward the box b
+		pi[0]=b->nbitems>0?(int)b->nbitems:4;//number of boxes in b
+		ii[0]=i0;                            //i coordinate of the box lowest left corner
+		jj[0]=j0;                            //j coordinate of the box lowest left corner
+
+		/*initialize h: smallest box size, containing a vertex close to w*/
+		h=hb;
+
+		/*Main loop*/
+		level=0;
+		do {
+
+			/*get current box*/
+			b= pb[level];
+
+			/*Loop over the items in current box (if not empty!)*/
+			while (pi[level]){
+
+				/*We are looping now over the items of b. k is the current index (in [0 3])*/
+				pi[level]--;
+				int k=pi[level];
+
+				/*if the current subbox is holding vertices (b->nbitems<0 is subboxes)*/
+				if (b->nbitems>0){
+					I2 i2=b->v[k]->i;
+					h0 = NORM(iplus,i2.x,jplus,i2.y);
+					if (h0<h){
+						h=h0;
+						nearest_v=b->v[k];
+					}
+				}
+				/*else: current box b is pointing toward 4 boxes
+				 * test sub-box k and go deeper into the tree if it is non empty
+				 * and contains the point w modulo a size h that is either the size of the smallest
+				 * non empty box containing w, or the closest point to w (so far) */
+				else{
+					BamgQuadtreeBox* b0=b;
+
+					/*if the next box exists:*/
+					if (b=b->b[k]){
+
+						/*Get size (hb) and coordinates of the current sub-box lowest left corner*/
+						hb>>=1;
+						Icoor1 iii = ii[level]+I_IJ(k,hb);
+						Icoor1 jjj = jj[level]+J_IJ(k,hb);
+
+						/*if the current point (iplus,jplus) is in b (modulo h), this box is good:
+						 * it is holding vertices that are close to w */
+						if (INTER_SEG(iii,iii+hb,iplus-h,iplus+h) && INTER_SEG(jjj,jjj+hb,jplus-h,jplus+h)){
+							level++;
+							pb[level]= b;
+							pi[level]= b->nbitems>0 ?(int)  b->nbitems : 4  ;
+							ii[level]= iii;
+							jj[level]= jjj;
+						}
+
+						//else go backwards
+						else{
+							//shifted righ by one bit: hb=001000000 -> 01000000
+							b=b0;
+							hb<<=1;
+						}
+					}
+					else{
+						/*Current box is NULL, go to next subbox of b (k=k-1)*/
+						b=b0;
+					}
+				}
+			}
+
+			/*We have found a vertex, now, let's try the other boxes of the previous level
+			 * in case there is a vertex closest to w that has not yet been tested*/
+			hb <<= 1;
+		} while (level--);
+
+		/*return nearest_v, nearest vertex*/
+		return nearest_v;
+
+	}
+	/*}}}1*/
+	/*FUNCTION BamgQuadtree::NearestVertexWithNormal{{{1*/
+	BamgVertex*  BamgQuadtree::NearestVertexWithNormal(Icoor1 i,Icoor1 j) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, BamgQuadtree.cpp/NearestVertexWithNormal)*/
+
+		BamgQuadtreeBox * pb[ MaxDepth ];
+		int  pi[ MaxDepth  ];
+		Icoor1 ii[  MaxDepth ], jj [ MaxDepth];
+		int l; // level
+		BamgQuadtreeBox * b;
+		long     h =MaxISize,h0;
+		long     hb=MaxISize;
+		Icoor1  i0=0,j0=0;
+		Icoor1  iplus( i<MaxISize?(i<0?0:i):MaxISize-1);
+		Icoor1  jplus( j<MaxISize?(j<0?0:j):MaxISize-1);
+
+		BamgVertex *vn=0;
+
+		// init for optimisation ---
+		b = root;
+		register long  n0;
+		if (!root->nbitems)
+		 return vn; // empty tree 
+
+		while( (n0 = b->nbitems) < 0) 
+		  {
+			// search the non empty 
+			// BamgQuadtreeBox containing  the point (i,j)
+			register Icoor1 hb2 = hb >> 1 ;
+			register  int k = IJ(iplus,jplus,hb2);// BamgQuadtreeBox number of size hb2 contening i;j
+			register BamgQuadtreeBox * b0= b->b[k];
+			if ( ( b0 == 0) || (b0->nbitems == 0) ) 
+			 break; // null box or empty   => break 	    
+			b=b0;	
+			i0 += I_IJ(k,hb2); // i orign of BamgQuadtreeBox
+			j0 += J_IJ(k,hb2); // j orign of BamgQuadtreeBox 
+			hb = hb2; 
+		  }
+
+
+		if ( n0 > 0) 
+		  {  
+			for(register int k=0;k<n0;k++)
+			  {
+				I2 i2 =  b->v[k]->i;
+				//   try if is in the right direction -- 
+				h0 = NORM(iplus,i2.x,jplus,i2.y);
+				if (h0 <h) {
+					h = h0;
+					vn = b->v[k];}
+			  }
+			if (vn) return vn; 
+		  }
+		// general case -----
+		// INITIALISATION OF THE HEAP 
+		l =0; // level 
+		pb[0]= b;
+		pi[0]=b->nbitems>0 ?(int)  b->nbitems : 4  ;
+		ii[0]=i0;
+		jj[0]=j0;
+		h=hb;
+		do {   // walk on the tree  
+			b= pb[l];
+			while (pi[l]--) // loop on 4 element of the box
+			  { 	      
+				int k = pi[l];
+
+				if (b->nbitems>0) // BamgVertex BamgQuadtreeBox none empty
+				  { 
+					I2 i2 =  b->v[k]->i;
+					// if good direction when try -- 
+
+					h0 = NORM(iplus,i2.x,jplus,i2.y);
+					if (h0 <h) 
+					  {
+						h = h0;
+						vn = b->v[k];
+					  }
+				  }
+				else // Pointer BamgQuadtreeBox 
+				  { 
+					register BamgQuadtreeBox *b0=b;
+					if ((b=b->b[k])) 
+					  {
+						hb >>=1 ; // div by 2
+						register Icoor1 iii = ii[l]+I_IJ(k,hb);
+						register Icoor1 jjj = jj[l]+J_IJ(k,hb);
+
+						if  (INTER_SEG(iii,iii+hb,iplus-h,iplus+h) && INTER_SEG(jjj,jjj+hb,jplus-h,jplus+h)) 
+						  {
+							pb[++l]=  b;
+							pi[l]= b->nbitems>0 ?(int)  b->nbitems : 4  ;
+							ii[l]= iii;
+							jj[l]= jjj;
+
+						  }
+						else
+						 b=b0, hb <<=1 ;
+					  }
+					else
+					 b=b0;
+				  }
+			  }
+			hb <<= 1; // mul by 2 
+		} while (l--);
+
+		return vn;
+	}
+	/*}}}1*/
+	/*FUNCTION BamgQuadtree::NewBamgQuadtreeBox {{{1*/
+	BamgQuadtree::BamgQuadtreeBox* BamgQuadtree::NewBamgQuadtreeBox(void){
+
+		/*Output*/
+		BamgQuadtreeBox* newbox=NULL;
+
+		/*Create and initialize a new box*/
+		newbox=new BamgQuadtreeBox;
+		newbox->nbitems=0;
+		newbox->b[0]=NULL;
+		newbox->b[1]=NULL;
+		newbox->b[2]=NULL;
+		newbox->b[3]=NULL;
+
+		/*Add root to the container*/
+		boxcontainer->AddObject(newbox);
+
+		/*Increase counter*/
+		NbBamgQuadtreeBox++;
+
+		/*currentbox now points toward next quadtree box*/
+		return newbox;
+	}/*}}}*/
+	/*FUNCTION BamgQuadtree::ToClose {{{1*/
+	BamgVertex*   BamgQuadtree::ToClose(BamgVertex & v,double seuil,Icoor1 hx,Icoor1 hy){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, BamgQuadtree.cpp/ToClose)*/
+
+		const Icoor1 i=v.i.x;
+		const Icoor1 j=v.i.y;
+		const R2 X(v.r);
+		const Metric  Mx(v.m);
+
+		BamgQuadtreeBox * pb[ MaxDepth ];
+		int  pi[ MaxDepth  ];
+		Icoor1 ii[  MaxDepth ], jj [ MaxDepth];
+		register int l=0; // level
+		register BamgQuadtreeBox * b;
+		Icoor1 h=MaxISize;
+		Icoor1 hb =  MaxISize;
+		Icoor1 i0=0,j0=0;
+
+		//  BamgVertex *vn=0;
+
+		if (!root->nbitems)
+		 return 0; // empty tree 
+
+		// general case -----
+		pb[0]=root;
+		pi[0]=root->nbitems>0 ?(int)  root->nbitems : 4  ;
+		ii[0]=i0;
+		jj[0]=j0;
+		h=hb;
+		do {    
+			b= pb[l];
+			while (pi[l]--){ 	      
+				register int k = pi[l];
+
+				if (b->nbitems>0){ // BamgVertex BamgQuadtreeBox none empty
+					I2 i2 =  b->v[k]->i;
+					if ( ABS(i-i2.x) <hx && ABS(j-i2.y) <hy )
+					  {
+						R2 XY(X,b->v[k]->r);
+						double dd;
+						if( (dd= LengthInterpole(Mx(XY), b->v[k]->m(XY)))  < seuil ){
+							return b->v[k]; 
+						}
+					  }
+				}
+				else{ // Pointer BamgQuadtreeBox 
+					register BamgQuadtreeBox *b0=b;
+					if ((b=b->b[k])){
+						hb >>=1 ; // div by 2
+						register long iii = ii[l]+I_IJ(k,hb);
+						register long jjj = jj[l]+J_IJ(k,hb);
+
+						if  (INTER_SEG(iii,iii+hb,i-hx,i+hx) && INTER_SEG(jjj,jjj+hb,j-hy,j+hy)){
+							pb[++l]=  b;
+							pi[l]= b->nbitems>0 ?(int)  b->nbitems : 4  ;
+							ii[l]= iii;
+							jj[l]= jjj;
+
+						}
+						else{
+							b=b0;
+							hb <<=1 ;
+						}
+					}
+					else{
+						b=b0;
+					}
+				}
+			}
+			hb <<= 1; // mul by 2 
+		} while (l--);
+
+		return 0;
+	}
+	/*}}}1*/
+}
Index: /issm/trunk/src/c/objects/Bamg/BamgQuadtree.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgQuadtree.h	(revision 12330)
+++ /issm/trunk/src/c/objects/Bamg/BamgQuadtree.h	(revision 12330)
@@ -0,0 +1,60 @@
+/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, BamgQuadtree.h)*/
+#ifndef _BAMGQUADTREE_H
+#define _BAMGQUADTREE_H
+
+#include "./include.h"
+
+namespace bamg {
+
+	const int  MaxDepth = 30;
+	const long MaxISize = ( 1L << MaxDepth);  // = 2^30 : 010000000000..000 (bitwise operation)
+
+	class BamgVertex;
+
+	class BamgQuadtree{
+
+		private:
+
+			/*A quadtree box contains a maximum of 4 vertices. 4 other quadtree boxes are
+			 * created if a fifth vertex is added to the same box. A Quadtree box is therefore
+			 * composed of EITHER:
+			 * - up to 4 vertices
+			 * - 4 "sub" quadtree boxes*/
+			class BamgQuadtreeBox: public Object{ 
+				public:
+					int nbitems; // number of current vertices in the box
+					union{
+						BamgQuadtreeBox* b[4];
+						BamgVertex*  v[4];
+					};
+					/*Object functions*/
+					void    Echo()       {_error_("not implemented yet"); };
+					void    DeepEcho()   {_error_("not implemented yet"); };
+					int     Id()         {_error_("not implemented yet"); };
+					int     MyRank()     {_error_("not implemented yet"); };
+					int     ObjectEnum() {_error_("not implemented yet"); };
+					Object *copy()       {_error_("not implemented yet"); };
+			};
+
+			/*BamgQuadtree private Fields*/
+			DataSet* boxcontainer;
+
+		public:
+
+			/*BamgQuadtree public Fields*/
+			BamgQuadtreeBox* root;
+			long         NbBamgQuadtreeBox;
+			long         NbVertices;
+
+			BamgQuadtree();
+			BamgQuadtree(Mesh *t,long nbv=-1);
+			~BamgQuadtree();
+
+			BamgVertex      *NearestVertex(Icoor1 i,Icoor1 j);
+			BamgVertex      *NearestVertexWithNormal(Icoor1  i,Icoor1 j);
+			BamgQuadtreeBox *NewBamgQuadtreeBox(void);
+			BamgVertex      *ToClose(BamgVertex &,double ,Icoor1,Icoor1);
+			void             Add(BamgVertex &w);
+	};
+}
+#endif
Index: /issm/trunk/src/c/objects/Bamg/Geometry.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/Geometry.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/Geometry.cpp	(revision 12330)
@@ -505,5 +505,5 @@
 		float             *eangle   = new float[nbe];
 		double             eps      = 1e-20;
-		QuadTree           quadtree; // build quadtree to find duplicates
+		BamgQuadtree           quadtree; // build quadtree to find duplicates
 		BamgVertex        *v0       = vertices;
 		GeomVertex *v0g      = (GeomVertex*) (void*)v0;
Index: /issm/trunk/src/c/objects/Bamg/Geometry.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/Geometry.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/Geometry.h	(revision 12330)
@@ -12,5 +12,5 @@
 
 	class Triangle;
-	class QuadTree;
+	class BamgQuadtree;
 	class GeomSubDomain;
 	class Edge;
@@ -20,17 +20,17 @@
 		public:
 
-			long                  NbRef;                         // counter of ref on the this class if 0 we can delete
-			long                  nbv;                           // number of vertices
-			long                  nbe;                           // number of edges
-			long                  nbsubdomains;
-			long                  nbcurves;
+			long           NbRef;                 // counter of ref on the this class if 0 we can delete
+			long           nbv;                   // number of vertices
+			long           nbe;                   // number of edges
+			long           nbsubdomains;
+			long           nbcurves;
 			GeomVertex    *vertices;
 			GeomEdge      *edges;
-			QuadTree             *quadtree;
+			BamgQuadtree  *quadtree;
 			GeomSubDomain *subdomains;
-			Curve                *curves;
-			R2                    pmin,pmax;                     // domain extrema coordinates
-			double                coefIcoor;                     // coef to integer Icoor1;
-			double                MaxCornerAngle;
+			Curve         *curves;
+			R2             pmin,pmax;             // domain extrema coordinates
+			double         coefIcoor;             // coef to integer Icoor1;
+			double         MaxCornerAngle;
 
 			//Constructor/Destructors
@@ -44,5 +44,5 @@
 			GeomVertex       &operator[](long i) { return vertices[i];       };
 			const GeomEdge   &operator()(long i) const { return edges[i];    };
-			GeomEdge         &operator()(long  i) { return edges[i];                };
+			GeomEdge         &operator()(long  i) { return edges[i];         };
 
 			//Methods
Index: /issm/trunk/src/c/objects/Bamg/Mesh.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/Mesh.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/Mesh.cpp	(revision 12330)
@@ -2885,5 +2885,5 @@
 
 		//build quadtree
-		if (!quadtree)  quadtree = new QuadTree(this,0);
+		if (!quadtree)  quadtree = new BamgQuadtree(this,0);
 		quadtree->Add(*v0);
 		quadtree->Add(*v1);
@@ -3107,10 +3107,10 @@
 	}
 	/*}}}1*/
-	/*FUNCTION Mesh::MakeQuadTree{{{1*/
-	void Mesh::MakeQuadTree() {  
-		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/MakeQuadTree)*/
+	/*FUNCTION Mesh::MakeBamgQuadtree{{{1*/
+	void Mesh::MakeBamgQuadtree() {  
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/MakeBamgQuadtree)*/
 
 		long int verbose=0;
-		if (  !quadtree )  quadtree = new QuadTree(this);
+		if (  !quadtree )  quadtree = new BamgQuadtree(this);
 
 	}
@@ -3622,5 +3622,5 @@
 
 	if (!quadtree) delete quadtree; //ReInitialise;
-	quadtree = new QuadTree(this,0);
+	quadtree = new BamgQuadtree(this,0);
 	quadtree->Add(*v0);
 	quadtree->Add(*v1);
@@ -3900,5 +3900,5 @@
 		if (quadtree){
 			delete quadtree;
-			quadtree = new QuadTree(this);
+			quadtree = new BamgQuadtree(this);
 		}
 
@@ -4116,5 +4116,5 @@
 
 	delete [] tstart;
-	if (quadtree) quadtree= new QuadTree(this);
+	if (quadtree) quadtree= new BamgQuadtree(this);
 }
 /*}}}1*/
Index: /issm/trunk/src/c/objects/Bamg/Mesh.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/Mesh.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/Mesh.h	(revision 12330)
@@ -17,5 +17,5 @@
 	class Geometry;
 	class CrackedEdge;
-	class QuadTree;
+	class BamgQuadtree;
 	class SubDomain;
 
@@ -29,5 +29,5 @@
 			Triangle                     *triangles;
 			Edge                         *edges;
-			QuadTree                     *quadtree;
+			BamgQuadtree                 *quadtree;
 			BamgVertex                  **orderedvertices;
 			SubDomain                    *subdomains;
@@ -94,5 +94,5 @@
 			void MakeQuadrangles(double costheta);
 			int  SplitElement(int choice);
-			void MakeQuadTree();
+			void MakeBamgQuadtree();
 			void NewPoints(Mesh &,BamgOpts* bamgopts,int KeepVertices=1);
 			long InsertNewPoints(long nbvold,long & NbTSwap) ; 
Index: /issm/trunk/src/c/objects/Bamg/Metric.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/Metric.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Bamg/Metric.h	(revision 12330)
@@ -5,4 +5,5 @@
 #include "../../shared/Bamg/shared.h"
 #include "R2.h"
+#include <math.h>
 
 namespace bamg {
Index: sm/trunk/src/c/objects/Bamg/QuadTree.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/QuadTree.cpp	(revision 12329)
+++ 	(revision )
@@ -1,598 +1,0 @@
-#include <limits.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "../objects.h"
-
-namespace bamg {
-
-	/*MACROS {{{1*/
-	/* 
-	 * 
-	 *    J    j
-	 *    ^    ^
-	 *    |    | +--------+--------+
-	 *    |    | |        |        |
-	 * 1X |    | |   2    |   3    |
-	 *    |    | |        |        |
-	 *    |    | +--------+--------+
-	 *    |    | |        |        |
-	 * 0X |    | |   0    |   1    |
-	 *    |    | |        |        |
-	 *    |    | +--------+--------+
-	 *    |    +-----------------------> i
-	 *    |         
-	 *    |----------------------------> I
-	 *              X0        X1  
-	 *
-	 * box 0 -> I=0 J=0 IJ=00  = 0
-	 * box 1 -> I=1 J=0 IJ=01  = 1
-	 * box 2 -> I=0 J=1 IJ=10  = 2
-	 * box 3 -> I=1 J=1 IJ=11  = 3
-	 */
-#define INTER_SEG(a,b,x,y) (((y) > (a)) && ((x) <(b)))
-#define ABS(i) ((i)<0 ?-(i) :(i))
-#define MAX1(i,j) ((i)>(j) ?(i) :(j))
-#define NORM(i1,j1,i2,j2) MAX1(ABS((i1)-(j1)),ABS((i2)-(j2)))
-
-	//IJ(i,j,l) returns the box number of i and j with respect to l
-	//if !j&l and !i&l -> 0 (box zero: lower left )
-	//if !j&l and  i&l -> 1 (box one:  lower right)
-	//if  j&l and !i&l -> 2 (box two:  upper left )
-	//if  j&l and  i&l -> 3 (box three:upper right)
-#define IJ(i,j,l)  ((j&l) ? ((i&l) ? 3:2 ) :((i&l) ? 1:0 ))
-
-	//I_IJ(k,l) returns l if first  bit of k is 1, else 0
-#define I_IJ(k,l)  ((k&1) ? l:0)
-	//J_IJ(k,l) returns l if second bit of k is 1, else 0
-#define J_IJ(k,l)  ((k&2) ? l:0)
-	/*}}}*/
-	/*DOCUMENTATION What is a QuadTree? {{{1
-	 * A Quadtree is a very simple way to group vertices according
-	 * to their locations. A square that holds all the points of the mesh
-	 * (or the geometry) is divided into 4 boxes. As soon as one box
-	 * hold more than 4 vertices, it is divided into 4 new boxes, etc...
-	 * There cannot be more than MAXDEEP (=30) subdivision.
-	 * This process is like a Dichotomy in dimension 2
-	 *
-	 *  + - -  -    - -    -    - - + -   - + - + - + - -     - - +
-	 *  |                           |       |   | X |             |
-	 *                                      + - + - +
-	 *  |                           |       |   |   |             |
-	 *                              + -   - + - + - +             +
-	 *  |                           |       |       |             |
-	 *                         
-	 *  |                           |       |       |             |
-	 *  + - -  -    - -    -    - - + -   - + -   - + - -     - - +
-	 *  |                           |               |             |
-	 *                         
-	 *  |                           |               |             |
-	 *                         
-	 *  |                           |               |             |
-	 *  |                           |               |             |
-	 *  + - -  -    - -    -    - - + -   -   -   - + - -     - - +
-	 *  |                           |                             |
-	 *                         
-	 *  |                           |                             |
-	 *                         
-	 *  |                           |                             |
-	 *                         
-	 *  |                           |                             |
-	 *  |                           |                             |
-	 *  |                           |                             |
-	 *  |                           |                             |
-	 *  |                           |                             |
-	 *  + - -  -    - -    -    - - + -   -   -   -   - -     - - +
-	 *
-	 * The coordinate system used in a quadtree are integers to avoid
-	 * round-off errors. The vertex in the lower left box has the coordinates
-	 * (0 0) 
-	 * The upper right vertex has the follwing coordinates:
-	 * 2^30 -1           2^30 -1        in decimal
-	 * 0 1 1 1 .... 1    0 1 1 1 .... 1 in binary
-	 *  \--   29  --/     \--   29  --/
-	 * Using binaries is therefore very easy to locate a vertex in a box:
-	 * we just need to look at the bits from the left to the right (See ::Add)
-	 }}}1*/
-
-	/*Constructors/Destructors*/
-	/*FUNCTION QuadTree::QuadTree(){{{1*/
-	QuadTree::QuadTree(){
-
-		/*Number of boxes and vertices*/
-		NbQuadTreeBox=0;
-		NbVertices=0;
-
-		/*Create container*/
-		boxcontainer=new DataSet();
-
-		/*Create Root, pointer toward the main box*/
-		root=NewQuadTreeBox();
-
-		}
-	/*}}}1*/
-	/*FUNCTION QuadTree::QuadTree(Mesh * t,long nbv){{{1*/
-	QuadTree::QuadTree(Mesh * t,long nbv){ 
-
-		/*Number of boxes and vertices*/
-		NbQuadTreeBox=0;
-		NbVertices=0;
-
-		/*Create container*/
-		boxcontainer=new DataSet();
-
-		/*Create Root, pointer toward the main box*/
-		root=NewQuadTreeBox();
-
-		/*Check Sizes*/
-		_assert_(MaxISize>MaxICoor);
-
-		/*Add all vertices of the mesh*/
-		if (nbv==-1) nbv=t->nbv;
-		for (int i=0;i<nbv;i++) Add(t->vertices[i]);
-
-	}
-	/*}}}1*/
-	/*FUNCTION QuadTree::~QuadTree(){{{1*/
-	QuadTree::~QuadTree() {
-		delete boxcontainer;
-		root=NULL;
-	}
-	/*}}}1*/
-
-	/*Methods*/
-	/*FUNCTION QuadTree::Add{{{1*/
-	void  QuadTree::Add(BamgVertex &w){
-		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/Add)*/
-		QuadTreeBox** pb=NULL;
-		QuadTreeBox*  b=NULL;
-
-		/*Get integer coodinate of current point w*/
-		register long i=w.i.x, j=w.i.y;
-
-		/*Initialize level*/
-		register long level=MaxISize;
-
-		/*Get inital box (the largest)*/
-		pb = &root;
-
-		/*Find the smallest box where w is located*/
-		while((b=*pb) && (b->nbitems<0)){ 
-
-			//shift b->nbitems by -1
-			b->nbitems--;
-
-			//shifted righ by one bit: level=00000010 -> 00000001
-			level >>= 1;
-
-			//Get next subbox according to the bit value (level)
-			pb = &b->b[IJ(i,j,level)];
-		}
-
-		/*OK, we have found b, a Subbox holding vertices (might be full)
-		  check that the vertex is not already in the box*/
-		if (b){      
-			if (b->nbitems > 3 &&  b->v[3] == &w) return;
-			if (b->nbitems > 2 &&  b->v[2] == &w) return;
-			if (b->nbitems > 1 &&  b->v[1] == &w) return;
-			if (b->nbitems > 0 &&  b->v[0] == &w) return;
-		}
-
-		/*check that l is not 0 (this should not happen as MaxDeep = 30)*/
-		_assert_(level>0);
-
-		/*Now, try to add the vertex, if the subbox is full (nbitems=4), we have to divide it
-		  in 4 new subboxes*/
-		while ((b= *pb) && (b->nbitems == 4)){ // the QuadTreeBox is full
-
-			/*Copy the 4 vertices in the current QuadTreebox*/
-			BamgVertex* v4[4];
-			v4[0]= b->v[0];
-			v4[1]= b->v[1];
-			v4[2]= b->v[2];
-			v4[3]= b->v[3];
-
-			/*set nbitems as negative 
-			 * (box full -> holds 4 pointers toward subboxes and not 4 vertices)*/
-			b->nbitems = -b->nbitems;
-
-			/*Initialize the 4 pointers toward the 4 subboxes*/
-			b->b[0]=b->b[1]=b->b[2]=b->b[3]=NULL;
-
-			/*level = 0010000 -> 0001000*/
-			level >>= 1;
-
-			/*Put the four vertices in the new boxes*/
-			for (int k=0;k<4;k++){
-
-				int          ij;
-				/*bb is the new "sub"box of b where v4[k] is located*/
-				QuadTreeBox *bb = b->b[ij=IJ(v4[k]->i.x,v4[k]->i.y,level)];
-
-				// alloc the QuadTreeBox
-				if (!bb) bb=b->b[ij]=NewQuadTreeBox(); 
-
-				/*Copy the current vertex*/
-				bb->v[bb->nbitems++] = v4[k];
-			}
-
-			/*Get the subbox where w (i,j) is located*/
-			pb = &b->b[IJ(i,j,level)];
-		}
-
-		/*alloc the QuadTreeBox if necessary*/
-		if (!(b=*pb)) b=*pb= NewQuadTreeBox();
-
-		/*Add w*/
-		b->v[b->nbitems++]=&w;
-
-		//Increase NbVertices by one (we have one new vertex)
-		NbVertices++;
-	}
-	/*}}}1*/
-	/*FUNCTION QuadTree::NearestVertex{{{1*/
-	BamgVertex*  QuadTree::NearestVertex(Icoor1 i,Icoor1 j) {
-		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/NearestVertex)*/
-
-		/*Intermediaries*/
-		QuadTreeBox *pb[MaxDeep];
-		int          pi[MaxDeep];
-		Icoor1       ii[MaxDeep];
-		Icoor1       jj[MaxDeep];
-		int          level;
-		long         n0;
-		QuadTreeBox *b;
-		long         h0;
-		long         h = MaxISize;
-		long         hb= MaxISize;
-		Icoor1       i0=0,j0=0;
-
-		/*initial output as NULL (no vertex found)*/
-		BamgVertex*  nearest_v=NULL;
-
-		/*Project w coordinates (i,j) onto [0,MaxISize-1] x [0,MaxISize-1] -> (iplus,jplus)*/
-		Icoor1 iplus( i<MaxISize ? (i<0?0:i) : MaxISize-1);
-		Icoor1 jplus( j<MaxISize ? (j<0?0:j) : MaxISize-1);
-
-		/*Get initial Quadtree box (largest)*/
-		b = root;
-
-		/*if the tree is empty, return NULL pointer*/
-		if (!root->nbitems) return nearest_v; 
-
-		/*else, find the smallest non-empty QuadTreeBox containing  the point (i,j)*/
-		while((n0=b->nbitems)<0){
-
-			Icoor1       hb2 = hb >> 1;             //size of the current box
-			int          k   = IJ(iplus,jplus,hb2); //box number (0,1,2 or 3)
-			QuadTreeBox *b0  = b->b[k];             //pointer toward current box
-
-			/* break if NULL box or empty (Keep previous box b)*/
-			if (( b0 == NULL) || (b0->nbitems == 0)) break;
-
-			/*Get next Quadtree box*/
-			b=b0;	
-			i0 += I_IJ(k,hb2); // i orign of QuadTreeBox (macro)
-			j0 += J_IJ(k,hb2); // j orign of QuadTreeBox 
-			hb = hb2;          // size of the box (in Int)
-		}
-
-		/*The box b, is the smallest box containing the point (i,j) and
-		 * has the following properties:
-		 * - n0: number of items (>0 if vertices, else boxes)
-		 * - hb: box size (int)
-		 * - i0: x coordinate of the lower left corner
-		 * - j0: y coordinate of the lower left corner*/
-
-		/* if the current subbox is holding vertices, we are almost done*/
-		if (n0>0){  
-			//loop over the vertices of the box and find the closest vertex
-			for(int k=0;k<n0;k++){
-
-				/*get integer coordinates of current vertex*/
-				I2 i2=b->v[k]->i;
-
-				/*Compute norm with w*/
-				h0=NORM(iplus,i2.x,jplus,i2.y);
-
-				/*is it smaller than previous value*/
-				if (h0<h){
-					h = h0;
-					nearest_v = b->v[k];
-				}
-			}
-			/*return closest vertex*/
-			return nearest_v;
-		}
-
-		/* general case: the current box is empty, we have to go backwards
-			and find the closest not-empty box and find the closest vertex*/
-
-		/*Initialize search variables*/
-		pb[0]=b;                             //pointer toward the box b
-		pi[0]=b->nbitems>0?(int)b->nbitems:4;//number of boxes in b
-		ii[0]=i0;                            //i coordinate of the box lowest left corner
-		jj[0]=j0;                            //j coordinate of the box lowest left corner
-
-		/*initialize h: smallest box size, containing a vertex close to w*/
-		h=hb;
-
-		/*Main loop*/
-		level=0;
-		do {
-
-			/*get current box*/
-			b= pb[level];
-
-			/*Loop over the items in current box (if not empty!)*/
-			while (pi[level]){
-
-				/*We are looping now over the items of b. k is the current index (in [0 3])*/
-				pi[level]--;
-				int k=pi[level];
-
-				/*if the current subbox is holding vertices (b->nbitems<0 is subboxes)*/
-				if (b->nbitems>0){
-					I2 i2=b->v[k]->i;
-					h0 = NORM(iplus,i2.x,jplus,i2.y);
-					if (h0<h){
-						h=h0;
-						nearest_v=b->v[k];
-					}
-				}
-				/*else: current box b is pointing toward 4 boxes
-				 * test sub-box k and go deeper into the tree if it is non empty
-				 * and contains the point w modulo a size h that is either the size of the smallest
-				 * non empty box containing w, or the closest point to w (so far) */
-				else{
-					QuadTreeBox* b0=b;
-
-					/*if the next box exists:*/
-					if (b=b->b[k]){
-
-						/*Get size (hb) and coordinates of the current sub-box lowest left corner*/
-						hb>>=1;
-						Icoor1 iii = ii[level]+I_IJ(k,hb);
-						Icoor1 jjj = jj[level]+J_IJ(k,hb);
-
-						/*if the current point (iplus,jplus) is in b (modulo h), this box is good:
-						 * it is holding vertices that are close to w */
-						if (INTER_SEG(iii,iii+hb,iplus-h,iplus+h) && INTER_SEG(jjj,jjj+hb,jplus-h,jplus+h)){
-							level++;
-							pb[level]= b;
-							pi[level]= b->nbitems>0 ?(int)  b->nbitems : 4  ;
-							ii[level]= iii;
-							jj[level]= jjj;
-						}
-
-						//else go backwards
-						else{
-							//shifted righ by one bit: hb=001000000 -> 01000000
-							b=b0;
-							hb<<=1;
-						}
-					}
-					else{
-						/*Current box is NULL, go to next subbox of b (k=k-1)*/
-						b=b0;
-					}
-				}
-			}
-
-			/*We have found a vertex, now, let's try the other boxes of the previous level
-			 * in case there is a vertex closest to w that has not yet been tested*/
-			hb <<= 1;
-		} while (level--);
-
-		/*return nearest_v, nearest vertex*/
-		return nearest_v;
-
-	}
-	/*}}}1*/
-	/*FUNCTION QuadTree::NearestVertexWithNormal{{{1*/
-	BamgVertex*  QuadTree::NearestVertexWithNormal(Icoor1 i,Icoor1 j) {
-		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/NearestVertexWithNormal)*/
-
-		QuadTreeBox * pb[ MaxDeep ];
-		int  pi[ MaxDeep  ];
-		Icoor1 ii[  MaxDeep ], jj [ MaxDeep];
-		int l; // level
-		QuadTreeBox * b;
-		long     h =MaxISize,h0;
-		long     hb=MaxISize;
-		Icoor1  i0=0,j0=0;
-		Icoor1  iplus( i<MaxISize?(i<0?0:i):MaxISize-1);
-		Icoor1  jplus( j<MaxISize?(j<0?0:j):MaxISize-1);
-
-		BamgVertex *vn=0;
-
-		// init for optimisation ---
-		b = root;
-		register long  n0;
-		if (!root->nbitems)
-		 return vn; // empty tree 
-
-		while( (n0 = b->nbitems) < 0) 
-		  {
-			// search the non empty 
-			// QuadTreeBox containing  the point (i,j)
-			register Icoor1 hb2 = hb >> 1 ;
-			register  int k = IJ(iplus,jplus,hb2);// QuadTreeBox number of size hb2 contening i;j
-			register QuadTreeBox * b0= b->b[k];
-			if ( ( b0 == 0) || (b0->nbitems == 0) ) 
-			 break; // null box or empty   => break 	    
-			b=b0;	
-			i0 += I_IJ(k,hb2); // i orign of QuadTreeBox
-			j0 += J_IJ(k,hb2); // j orign of QuadTreeBox 
-			hb = hb2; 
-		  }
-
-
-		if ( n0 > 0) 
-		  {  
-			for(register int k=0;k<n0;k++)
-			  {
-				I2 i2 =  b->v[k]->i;
-				//   try if is in the right direction -- 
-				h0 = NORM(iplus,i2.x,jplus,i2.y);
-				if (h0 <h) {
-					h = h0;
-					vn = b->v[k];}
-			  }
-			if (vn) return vn; 
-		  }
-		// general case -----
-		// INITIALISATION OF THE HEAP 
-		l =0; // level 
-		pb[0]= b;
-		pi[0]=b->nbitems>0 ?(int)  b->nbitems : 4  ;
-		ii[0]=i0;
-		jj[0]=j0;
-		h=hb;
-		do {   // walk on the tree  
-			b= pb[l];
-			while (pi[l]--) // loop on 4 element of the box
-			  { 	      
-				int k = pi[l];
-
-				if (b->nbitems>0) // BamgVertex QuadTreeBox none empty
-				  { 
-					I2 i2 =  b->v[k]->i;
-					// if good direction when try -- 
-
-					h0 = NORM(iplus,i2.x,jplus,i2.y);
-					if (h0 <h) 
-					  {
-						h = h0;
-						vn = b->v[k];
-					  }
-				  }
-				else // Pointer QuadTreeBox 
-				  { 
-					register QuadTreeBox *b0=b;
-					if ((b=b->b[k])) 
-					  {
-						hb >>=1 ; // div by 2
-						register Icoor1 iii = ii[l]+I_IJ(k,hb);
-						register Icoor1 jjj = jj[l]+J_IJ(k,hb);
-
-						if  (INTER_SEG(iii,iii+hb,iplus-h,iplus+h) && INTER_SEG(jjj,jjj+hb,jplus-h,jplus+h)) 
-						  {
-							pb[++l]=  b;
-							pi[l]= b->nbitems>0 ?(int)  b->nbitems : 4  ;
-							ii[l]= iii;
-							jj[l]= jjj;
-
-						  }
-						else
-						 b=b0, hb <<=1 ;
-					  }
-					else
-					 b=b0;
-				  }
-			  }
-			hb <<= 1; // mul by 2 
-		} while (l--);
-
-		return vn;
-	}
-	/*}}}1*/
-	/*FUNCTION QuadTree::NewQuadTreeBox {{{1*/
-	QuadTree::QuadTreeBox* QuadTree::NewQuadTreeBox(void){
-
-		/*Output*/
-		QuadTreeBox* newbox=NULL;
-
-		/*Create and initialize a new box*/
-		newbox=new QuadTreeBox;
-		newbox->nbitems=0;
-		newbox->b[0]=NULL;
-		newbox->b[1]=NULL;
-		newbox->b[2]=NULL;
-		newbox->b[3]=NULL;
-
-		/*Add root to the container*/
-		boxcontainer->AddObject(newbox);
-
-		/*Increase counter*/
-		NbQuadTreeBox++;
-
-		/*currentbox now points toward next quadtree box*/
-		return newbox;
-	}/*}}}*/
-	/*FUNCTION QuadTree::ToClose {{{1*/
-	BamgVertex*   QuadTree::ToClose(BamgVertex & v,double seuil,Icoor1 hx,Icoor1 hy){
-		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/ToClose)*/
-
-		const Icoor1 i=v.i.x;
-		const Icoor1 j=v.i.y;
-		const R2 X(v.r);
-		const Metric  Mx(v.m);
-
-		QuadTreeBox * pb[ MaxDeep ];
-		int  pi[ MaxDeep  ];
-		Icoor1 ii[  MaxDeep ], jj [ MaxDeep];
-		register int l=0; // level
-		register QuadTreeBox * b;
-		Icoor1 h=MaxISize;
-		Icoor1 hb =  MaxISize;
-		Icoor1 i0=0,j0=0;
-
-		//  BamgVertex *vn=0;
-
-		if (!root->nbitems)
-		 return 0; // empty tree 
-
-		// general case -----
-		pb[0]=root;
-		pi[0]=root->nbitems>0 ?(int)  root->nbitems : 4  ;
-		ii[0]=i0;
-		jj[0]=j0;
-		h=hb;
-		do {    
-			b= pb[l];
-			while (pi[l]--){ 	      
-				register int k = pi[l];
-
-				if (b->nbitems>0){ // BamgVertex QuadTreeBox none empty
-					I2 i2 =  b->v[k]->i;
-					if ( ABS(i-i2.x) <hx && ABS(j-i2.y) <hy )
-					  {
-						R2 XY(X,b->v[k]->r);
-						double dd;
-						if( (dd= LengthInterpole(Mx(XY), b->v[k]->m(XY)))  < seuil ){
-							return b->v[k]; 
-						}
-					  }
-				}
-				else{ // Pointer QuadTreeBox 
-					register QuadTreeBox *b0=b;
-					if ((b=b->b[k])){
-						hb >>=1 ; // div by 2
-						register long iii = ii[l]+I_IJ(k,hb);
-						register long jjj = jj[l]+J_IJ(k,hb);
-
-						if  (INTER_SEG(iii,iii+hb,i-hx,i+hx) && INTER_SEG(jjj,jjj+hb,j-hy,j+hy)){
-							pb[++l]=  b;
-							pi[l]= b->nbitems>0 ?(int)  b->nbitems : 4  ;
-							ii[l]= iii;
-							jj[l]= jjj;
-
-						}
-						else{
-							b=b0;
-							hb <<=1 ;
-						}
-					}
-					else{
-						b=b0;
-					}
-				}
-			}
-			hb <<= 1; // mul by 2 
-		} while (l--);
-
-		return 0;
-	}
-	/*}}}1*/
-}
Index: sm/trunk/src/c/objects/Bamg/QuadTree.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/QuadTree.h	(revision 12329)
+++ 	(revision )
@@ -1,66 +1,0 @@
-/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.h)*/
-#ifndef _QUADTREE_H
-#define _QUADTREE_H
-
-#include "./include.h"
-
-namespace bamg {
-
-	const int  MaxDeep  = 30;
-	const long MaxISize = ( 1L << MaxDeep);  // = 2^30 : 010000000000..000 (bitwise operation)
-
-	class BamgVertex;
-
-	class QuadTree{
-
-		private:
-
-			/*A quadtree box contains a maximum of 4 vertices. 4 other quadtree boxes are
-			 * created if a fifth vertex is added to the same box. A Quadtree box is therefore
-			 * composed of EITHER:
-			 * - up to 4 vertices
-			 * - 4 "sub" quadtree boxes*/
-			class QuadTreeBox: public Object{ 
-				public:
-					int nbitems; // number of current vertices in the box
-					union{
-						QuadTreeBox* b[4];
-						BamgVertex*  v[4];
-					};
-					/*Object functions*/
-					void  Echo(){_error_("not implemented yet");};
-					void  DeepEcho(){_error_("not implemented yet");};
-					int   Id(){_error_("not implemented yet");};
-					int   MyRank(){_error_("not implemented yet");};
-					#ifdef _SERIAL_
-					void  Marshall(char** pmarshalled_dataset){_error_("not implemented yet");};
-					int   MarshallSize(){_error_("not implemented yet");};
-					void  Demarshall(char** pmarshalled_dataset){_error_("not implemented yet");};
-					#endif
-					int   ObjectEnum(){_error_("not implemented yet");};
-					Object* copy(){_error_("not implemented yet");};
-			};
-
-			/*QuadTree private Fields*/
-			DataSet* boxcontainer;
-
-		public:
-
-			/*QuadTree public Fields*/
-			QuadTreeBox* root;
-			long         NbQuadTreeBox;
-			long         NbVertices;
-
-			QuadTree();
-			QuadTree(Mesh *t,long nbv=-1);
-			~QuadTree();
-
-			BamgVertex*  NearestVertex(Icoor1 i,Icoor1 j);
-			BamgVertex*  NearestVertexWithNormal(Icoor1 i,Icoor1 j);
-			QuadTreeBox* NewQuadTreeBox(void);
-			BamgVertex*  ToClose(BamgVertex & ,double ,Icoor1,Icoor1);
-			void         Add( BamgVertex & w);
-
-	};
-}
-#endif
Index: /issm/trunk/src/c/objects/Constraints/Constraint.h
===================================================================
--- /issm/trunk/src/c/objects/Constraints/Constraint.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Constraints/Constraint.h	(revision 12330)
@@ -11,8 +11,6 @@
 /*Headers:*/
 /*{{{1*/
+class Nodes;
 #include "../Object.h"
-
-class Nodes;
-
 #include "../../toolkits/toolkits.h"
 /*}}}*/
Index: /issm/trunk/src/c/objects/Constraints/SpcDynamic.cpp
===================================================================
--- /issm/trunk/src/c/objects/Constraints/SpcDynamic.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Constraints/SpcDynamic.cpp	(revision 12330)
@@ -72,68 +72,4 @@
 }
 /*}}}1*/
-#ifdef _SERIAL_
-/*FUNCTION SpcDynamic::Marshall {{{1*/
-void  SpcDynamic::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of SpcDynamic: */
-	enum_type=SpcDynamicEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall SpcDynamic data: */
-	memcpy(marshalled_dataset,&sid,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(marshalled_dataset,&nodeid,sizeof(nodeid));marshalled_dataset+=sizeof(nodeid);
-	memcpy(marshalled_dataset,&dof,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(marshalled_dataset,&isset,sizeof(isset));marshalled_dataset+=sizeof(isset);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-/*FUNCTION SpcDynamic::MarshallSize {{{1*/
-int   SpcDynamic::MarshallSize(){
-
-	return sizeof(sid)
-		+sizeof(nodeid)
-		+sizeof(dof)
-		+sizeof(value)
-		+sizeof(isset)
-		+sizeof(analysis_type)
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}1*/
-/*FUNCTION SpcDynamic::Demarshall {{{1*/
-void  SpcDynamic::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&sid,marshalled_dataset,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(&nodeid,marshalled_dataset,sizeof(nodeid));marshalled_dataset+=sizeof(nodeid);
-	memcpy(&dof,marshalled_dataset,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(&isset,marshalled_dataset,sizeof(isset));marshalled_dataset+=sizeof(isset);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-#endif
 /*FUNCTION SpcDynamic::ObjectEnum{{{1*/
 int SpcDynamic::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Constraints/SpcDynamic.h
===================================================================
--- /issm/trunk/src/c/objects/Constraints/SpcDynamic.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Constraints/SpcDynamic.h	(revision 12330)
@@ -34,9 +34,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Constraints/SpcStatic.cpp
===================================================================
--- /issm/trunk/src/c/objects/Constraints/SpcStatic.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Constraints/SpcStatic.cpp	(revision 12330)
@@ -75,65 +75,4 @@
 }
 /*}}}1*/
-#ifdef _SERIAL_
-/*FUNCTION SpcStatic::Marshall {{{1*/
-void  SpcStatic::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of SpcStatic: */
-	enum_type=SpcStaticEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall SpcStatic data: */
-	memcpy(marshalled_dataset,&sid,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(marshalled_dataset,&nodeid,sizeof(nodeid));marshalled_dataset+=sizeof(nodeid);
-	memcpy(marshalled_dataset,&dof,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-/*FUNCTION SpcStatic::MarshallSize {{{1*/
-int   SpcStatic::MarshallSize(){
-
-	return sizeof(sid)
-		+sizeof(nodeid)
-		+sizeof(dof)
-		+sizeof(value)
-		+sizeof(analysis_type)
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}1*/
-/*FUNCTION SpcStatic::Demarshall {{{1*/
-void  SpcStatic::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&sid,marshalled_dataset,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(&nodeid,marshalled_dataset,sizeof(nodeid));marshalled_dataset+=sizeof(nodeid);
-	memcpy(&dof,marshalled_dataset,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-#endif
 /*FUNCTION SpcStatic::ObjectEnum{{{1*/
 int SpcStatic::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Constraints/SpcStatic.h
===================================================================
--- /issm/trunk/src/c/objects/Constraints/SpcStatic.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Constraints/SpcStatic.h	(revision 12330)
@@ -33,9 +33,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Constraints/SpcTransient.cpp
===================================================================
--- /issm/trunk/src/c/objects/Constraints/SpcTransient.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Constraints/SpcTransient.cpp	(revision 12330)
@@ -87,76 +87,4 @@
 }
 /*}}}1*/
-#ifdef _SERIAL_
-/*FUNCTION SpcTransient::Marshall {{{1*/
-void  SpcTransient::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of SpcTransient: */
-	enum_type=SpcTransientEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall SpcTransient data: */
-	memcpy(marshalled_dataset,&sid,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(marshalled_dataset,&nodeid,sizeof(nodeid));marshalled_dataset+=sizeof(nodeid);
-	memcpy(marshalled_dataset,&dof,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(marshalled_dataset,&nsteps,sizeof(nsteps));marshalled_dataset+=sizeof(nsteps);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-	if(nsteps){
-		memcpy(marshalled_dataset,values,nsteps*sizeof(double));marshalled_dataset+=nsteps*sizeof(double);
-		memcpy(marshalled_dataset,times,nsteps*sizeof(double));marshalled_dataset+=nsteps*sizeof(double);
-	}
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-/*FUNCTION SpcTransient::MarshallSize {{{1*/
-int   SpcTransient::MarshallSize(){
-
-	return sizeof(sid)
-		+sizeof(nodeid)
-		+sizeof(dof)
-		+sizeof(nsteps)
-		+nsteps*2*sizeof(double)
-		+sizeof(analysis_type)
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}1*/
-/*FUNCTION SpcTransient::Demarshall {{{1*/
-void  SpcTransient::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&sid,marshalled_dataset,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(&nodeid,marshalled_dataset,sizeof(nodeid));marshalled_dataset+=sizeof(nodeid);
-	memcpy(&dof,marshalled_dataset,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(&nsteps,marshalled_dataset,sizeof(nsteps));marshalled_dataset+=sizeof(nsteps);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-	if(nsteps){
-		values=(double*)xmalloc(nsteps*sizeof(double));
-		times=(double*)xmalloc(nsteps*sizeof(double));
-		memcpy(values,marshalled_dataset,nsteps*sizeof(double));marshalled_dataset+=nsteps*sizeof(double);
-		memcpy(times,marshalled_dataset,nsteps*sizeof(double));marshalled_dataset+=nsteps*sizeof(double);
-	}
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-#endif
 /*FUNCTION SpcTransient::ObjectEnum{{{1*/
 int SpcTransient::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Constraints/SpcTransient.h
===================================================================
--- /issm/trunk/src/c/objects/Constraints/SpcTransient.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Constraints/SpcTransient.h	(revision 12330)
@@ -35,9 +35,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Contour.cpp
===================================================================
--- /issm/trunk/src/c/objects/Contour.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Contour.cpp	(revision 12330)
@@ -9,4 +9,5 @@
 #endif
 
+#include <string.h>
 #include "./objects.h"
 #include "../include/include.h"
@@ -79,71 +80,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION Contour::Marshall{{{1*/
-void  Contour::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputssize;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Contour: */
-	enum_type=ContourEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall Contour data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&nods,sizeof(nods));marshalled_dataset+=sizeof(nods);
-	memcpy(marshalled_dataset,&closed,sizeof(closed));marshalled_dataset+=sizeof(closed);
-	memcpy(marshalled_dataset,x,nods*sizeof(double));marshalled_dataset+=nods*sizeof(double);
-	memcpy(marshalled_dataset,y,nods*sizeof(double));marshalled_dataset+=nods*sizeof(double);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Contour::MarshallSize{{{1*/
-int   Contour::MarshallSize(){
-
-	return sizeof(id)+
-		sizeof(nods)+
-		sizeof(closed)+
-		2*nods*sizeof(double)+
-		sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Contour::Demarshall{{{1*/
-void  Contour::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&nods,marshalled_dataset,sizeof(nods));marshalled_dataset+=sizeof(nods);
-	memcpy(&closed,marshalled_dataset,sizeof(closed));marshalled_dataset+=sizeof(closed);
-
-	if(nods){
-		this->x=(double*)xmalloc(nods*sizeof(double));
-		this->y=(double*)xmalloc(nods*sizeof(double));
-		memcpy(x,marshalled_dataset,nods*sizeof(double));marshalled_dataset+=nods*sizeof(double);
-		memcpy(y,marshalled_dataset,nods*sizeof(double));marshalled_dataset+=nods*sizeof(double);
-	}
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION Contour::ObjectEnum{{{1*/
 int Contour::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Contour.h
===================================================================
--- /issm/trunk/src/c/objects/Contour.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Contour.h	(revision 12330)
@@ -20,11 +20,11 @@
 		int     id;
 		int	  nods;  //number of vertices in the contour
-		double* x;
-		double* y;
+		IssmDouble* x;
+		IssmDouble* y;
 		bool    closed; //is this contour closed?
 
 		/*Contour constructors, destructors {{{1*/
 		Contour();
-		Contour(int id, int nods, double* x, double* y,bool closed);
+		Contour(int id, int nods, IssmDouble* x, IssmDouble* y,bool closed);
 		~Contour();
 		/*}}}*/
@@ -34,9 +34,4 @@
 		int   Id(void);
 		int   MyRank(void);
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize(void);
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum(void);
 		Object* copy(void);
Index: /issm/trunk/src/c/objects/DofIndexing.cpp
===================================================================
--- /issm/trunk/src/c/objects/DofIndexing.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/DofIndexing.cpp	(revision 12330)
@@ -208,128 +208,3 @@
 }		
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DofIndexing::Marshall{{{1*/
-void  DofIndexing::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	bool  flagdoftype; //to indicate if there are some doftype or if NULL
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*preliminary: */
-	if(this->doftype)flagdoftype=true;
-	else             flagdoftype=false;
-
-	/*get enum type of DofIndexing: */
-	enum_type=DofIndexingEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall DofIndexing data: */
-	memcpy(marshalled_dataset,&gsize,sizeof(gsize));marshalled_dataset+=sizeof(gsize);
-	memcpy(marshalled_dataset,&fsize,sizeof(fsize));marshalled_dataset+=sizeof(fsize);
-	memcpy(marshalled_dataset,&ssize,sizeof(ssize));marshalled_dataset+=sizeof(ssize);
-	memcpy(marshalled_dataset,&flagdoftype,sizeof(flagdoftype));marshalled_dataset+=sizeof(flagdoftype);
-	memcpy(marshalled_dataset,&clone,sizeof(clone));marshalled_dataset+=sizeof(clone);
-	
-	if(this->gsize>0){
-		memcpy(marshalled_dataset,f_set,gsize*sizeof(bool));marshalled_dataset+=gsize*sizeof(bool);
-		memcpy(marshalled_dataset,s_set,gsize*sizeof(bool));marshalled_dataset+=gsize*sizeof(bool);
-		memcpy(marshalled_dataset,svalues,gsize*sizeof(double)); marshalled_dataset+=gsize*sizeof(double);
-		if(flagdoftype){ memcpy(marshalled_dataset,doftype,gsize*sizeof(int)); marshalled_dataset+=gsize*sizeof(int); }
-		memcpy(marshalled_dataset,gdoflist,gsize*sizeof(int)); marshalled_dataset+=gsize*sizeof(int);
-	}
-	if(this->fsize>0 && this->fsize!=UNDEF){ memcpy(marshalled_dataset,fdoflist,fsize*sizeof(int)); marshalled_dataset+=fsize*sizeof(int);}
-	if(this->ssize>0 && this->ssize!=UNDEF){ memcpy(marshalled_dataset,sdoflist,ssize*sizeof(int)); marshalled_dataset+=ssize*sizeof(int);}
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION DofIndexing::MarshallSize{{{1*/
-int   DofIndexing::MarshallSize(){
-
-	int size=0;
-
-	size+=4*sizeof(int)+sizeof(bool);
-	if(this->gsize>0){
-		size+= 2*this->gsize*sizeof(bool)+
-			   this->gsize*sizeof(double)+
-			   this->gsize*sizeof(int);
-		if(this->doftype)size+=this->gsize*sizeof(int);
-	}
-	if(this->fsize>0 && this->fsize!=UNDEF)size+=this->fsize*sizeof(int);
-	if(this->ssize>0 && this->ssize!=UNDEF)size+=this->ssize*sizeof(int);
-
-	size+=sizeof(int); //sizeof(int) for enum type
-
-	return size;
-}
-/*}}}*/
-/*FUNCTION DofIndexing::Demarshall{{{1*/
-void  DofIndexing::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type;
-	bool  flagdoftype;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of object since DofIndexing is not directly called by DataSet: */
-	memcpy(&enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-
-	/*easy part: */
-	memcpy(&gsize,marshalled_dataset,sizeof(gsize));marshalled_dataset+=sizeof(gsize);
-	memcpy(&fsize,marshalled_dataset,sizeof(fsize));marshalled_dataset+=sizeof(fsize);
-	memcpy(&ssize,marshalled_dataset,sizeof(ssize));marshalled_dataset+=sizeof(ssize);
-	memcpy(&flagdoftype,marshalled_dataset,sizeof(flagdoftype));marshalled_dataset+=sizeof(flagdoftype);
-	memcpy(&clone,marshalled_dataset,sizeof(clone));marshalled_dataset+=sizeof(clone);
-	
-	/*Allocate: */
-	if(this->gsize>0){
-		this->f_set=(bool*)xmalloc(this->gsize*sizeof(bool));
-		this->s_set=(bool*)xmalloc(this->gsize*sizeof(bool));
-		this->svalues=(double*)xmalloc(this->gsize*sizeof(double));
-		if(flagdoftype)this->doftype=(int*)xmalloc(this->gsize*sizeof(int));
-		else           this->doftype=NULL;
-		this->gdoflist=(int*)xmalloc(this->gsize*sizeof(int));
-	}
-	else{
-		this->f_set=NULL;
-		this->s_set=NULL;
-		this->svalues=NULL;
-		this->doftype=NULL;
-		this->gdoflist=NULL;
-	}
-	if(this->fsize>0)
-	 this->fdoflist=(int*)xmalloc(this->fsize*sizeof(int));
-	else
-	 this->fdoflist=NULL;
-	if(this->ssize>0)
-	 this->sdoflist=(int*)xmalloc(this->ssize*sizeof(int));
-	else
-	 this->sdoflist=NULL;
-
-	/*Copy arrays: */
-	if(this->gsize>0){
-		memcpy(f_set,marshalled_dataset,gsize*sizeof(bool));marshalled_dataset+=gsize*sizeof(bool);
-		memcpy(s_set,marshalled_dataset,gsize*sizeof(bool));marshalled_dataset+=gsize*sizeof(bool);
-		memcpy(svalues,marshalled_dataset,gsize*sizeof(double));marshalled_dataset+=gsize*sizeof(double);
-		if(flagdoftype){memcpy(doftype,marshalled_dataset,gsize*sizeof(int));marshalled_dataset+=gsize*sizeof(int); }
-		memcpy(gdoflist,marshalled_dataset,gsize*sizeof(int));marshalled_dataset+=gsize*sizeof(int);
-	}
-	
-	if(this->fsize>0 && this->fsize!=UNDEF){ memcpy(this->fdoflist,marshalled_dataset,this->fsize*sizeof(int));marshalled_dataset+=this->fsize*sizeof(int); }
-	if(this->ssize>0 && this->ssize!=UNDEF){ memcpy(this->sdoflist,marshalled_dataset,this->ssize*sizeof(int));marshalled_dataset+=this->ssize*sizeof(int); }
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
-
+
Index: /issm/trunk/src/c/objects/DofIndexing.h
===================================================================
--- /issm/trunk/src/c/objects/DofIndexing.h	(revision 12329)
+++ /issm/trunk/src/c/objects/DofIndexing.h	(revision 12330)
@@ -5,4 +5,6 @@
 #ifndef _DOFINDEXING_H_
 #define  _DOFINDEXING_H_
+
+#include "../include/include.h"
 
 class DofIndexing{
@@ -21,5 +23,5 @@
 		bool*     f_set; //is dof on f-set (on which we solve)
 		bool*     s_set; //is dof on s-set (on which boundary conditions -dirichlet- are applied)
-		double*   svalues; //list of constraint values. size g_size, for ease of use.
+		IssmDouble*   svalues; //list of constraint values. size g_size, for ease of use.
 
 		/*types of dofs: */
@@ -43,9 +45,4 @@
 		void  Echo(void); 
 		void  DeepEcho(void); 
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		void  copy(DofIndexing* properties);
 		/*}}}*/
Index: /issm/trunk/src/c/objects/ElementResults/BoolElementResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ElementResults/BoolElementResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ElementResults/BoolElementResult.cpp	(revision 12330)
@@ -64,61 +64,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION BoolElementResult::Marshall{{{1*/
-void  BoolElementResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of BoolElementResult: */
-	enum_value=BoolElementResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall BoolElementResult data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION BoolElementResult::Demarshall{{{1*/
-void  BoolElementResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION BoolElementResult::MarshallSize{{{1*/
-int   BoolElementResult::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(enum_type)
-		+sizeof(time)
-		+sizeof(step)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-#endif
 /*FUNCTION BoolElementResult::ObjectEnum{{{1*/
 int BoolElementResult::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/ElementResults/BoolElementResult.h
===================================================================
--- /issm/trunk/src/c/objects/ElementResults/BoolElementResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ElementResults/BoolElementResult.h	(revision 12330)
@@ -35,9 +35,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/ElementResults/DoubleElementResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ElementResults/DoubleElementResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ElementResults/DoubleElementResult.cpp	(revision 12330)
@@ -64,61 +64,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleElementResult::Marshall{{{1*/
-void  DoubleElementResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleElementResult: */
-	enum_value=DoubleElementResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleElementResult data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleElementResult::Demarshall{{{1*/
-void  DoubleElementResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION DoubleElementResult::MarshallSize{{{1*/
-int   DoubleElementResult::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(enum_type)
-		+sizeof(time)
-		+sizeof(step)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleElementResult::ObjectEnum{{{1*/
 int DoubleElementResult::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/ElementResults/DoubleElementResult.h
===================================================================
--- /issm/trunk/src/c/objects/ElementResults/DoubleElementResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ElementResults/DoubleElementResult.h	(revision 12330)
@@ -35,9 +35,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/ElementResults/PentaP1ElementResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ElementResults/PentaP1ElementResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ElementResults/PentaP1ElementResult.cpp	(revision 12330)
@@ -67,61 +67,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION PentaP1ElementResult::Marshall{{{1*/
-void  PentaP1ElementResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of PentaP1ElementResult: */
-	enum_value=PentaP1ElementResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall PentaP1ElementResult data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&values,sizeof(values));marshalled_dataset+=sizeof(values);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION PentaP1ElementResult::MarshallSize{{{1*/
-int   PentaP1ElementResult::MarshallSize(){
-	
-	return sizeof(values)+
-		+sizeof(enum_type)
-		+sizeof(time)
-		+sizeof(step)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION PentaP1ElementResult::Demarshall{{{1*/
-void  PentaP1ElementResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&values,marshalled_dataset,sizeof(values));marshalled_dataset+=sizeof(values);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION PentaP1ElementResult::ObjectEnum{{{1*/
 int PentaP1ElementResult::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/ElementResults/PentaP1ElementResult.h
===================================================================
--- /issm/trunk/src/c/objects/ElementResults/PentaP1ElementResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ElementResults/PentaP1ElementResult.h	(revision 12330)
@@ -34,9 +34,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/ElementResults/TriaP1ElementResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ElementResults/TriaP1ElementResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ElementResults/TriaP1ElementResult.cpp	(revision 12330)
@@ -66,62 +66,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION TriaP1ElementResult::Marshall{{{1*/
-void  TriaP1ElementResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of TriaP1ElementResult: */
-	enum_value=TriaP1ElementResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall TriaP1ElementResult data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&values,sizeof(values));marshalled_dataset+=sizeof(values);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION TriaP1ElementResult::MarshallSize{{{1*/
-int   TriaP1ElementResult::MarshallSize(){
-	
-	return sizeof(values)
-		+sizeof(enum_type)
-		+sizeof(time)
-		+sizeof(step)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION TriaP1ElementResult::Demarshall{{{1*/
-void  TriaP1ElementResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&values,marshalled_dataset,sizeof(values));marshalled_dataset+=sizeof(values);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION TriaP1ElementResult::ObjectEnum{{{1*/
 int TriaP1ElementResult::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/ElementResults/TriaP1ElementResult.h
===================================================================
--- /issm/trunk/src/c/objects/ElementResults/TriaP1ElementResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ElementResults/TriaP1ElementResult.h	(revision 12330)
@@ -33,9 +33,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Elements/Penta.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 12330)
@@ -142,161 +142,4 @@
 }
 /*}}}*/
-
-/*Marshall*/
-#ifdef _SERIAL_
-/*FUNCTION Penta::Marshall {{{1*/
-void  Penta::Marshall(char** pmarshalled_dataset){
-
-	int   i;
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-	char* marshalled_results=NULL;
-	int   marshalled_results_size;
-	int   flaghook; //to indicate if hook is NULL or exists
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Penta: */
-	enum_type=PentaEnum;
-
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*marshall Penta data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&sid,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(marshalled_dataset,&numanalyses,sizeof(numanalyses));marshalled_dataset+=sizeof(numanalyses);
-
-	/*Mershall Ref: */
-	for(i=0;i<numanalyses;i++){
-		memcpy(marshalled_dataset,&element_type_list[i],sizeof(element_type_list[i]));marshalled_dataset+=sizeof(element_type_list[i]);
-	}
-
-	/*Marshall hooks: */
-	for(i=0;i<numanalyses;i++){
-		if(hnodes[i]){
-			/*Set flag to 1 as there is a hook */
-			flaghook=1;
-			memcpy(marshalled_dataset,&flaghook,sizeof(flaghook));marshalled_dataset+=sizeof(flaghook);
-			hnodes[i]->Marshall(&marshalled_dataset);
-		}
-		else{
-			/*Set flag to 0 and do not marshall flag as there is no Hook */
-			flaghook=0;
-			memcpy(marshalled_dataset,&flaghook,sizeof(flaghook));marshalled_dataset+=sizeof(flaghook);
-		}
-	}
-	hmatice->Marshall(&marshalled_dataset);
-	hmatpar->Marshall(&marshalled_dataset);
-	hneighbors->Marshall(&marshalled_dataset);
-
-	/*Marshall inputs and results: */
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	marshalled_results_size=results->MarshallSize();
-	marshalled_results=results->Marshall();
-	memcpy(marshalled_dataset,marshalled_results,marshalled_results_size*sizeof(char));
-	marshalled_dataset+=marshalled_results_size;
-
-	/*parameters: don't do anything about it. parameters are marshalled somewhere else!*/
-
-	xfree((void**)&marshalled_inputs);
-	xfree((void**)&marshalled_results);
-
-	/*marshall horizontal neighbors: */
-	memcpy(marshalled_dataset,horizontalneighborsids,3*sizeof(int));marshalled_dataset+=3*sizeof(int);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Penta::MarshallSize {{{1*/
-int   Penta::MarshallSize(){
-
-	int i;
-	int hnodes_size=0;;
-
-	for(i=0;i<numanalyses;i++){
-		hnodes_size+=sizeof(int); //Flag 0 or 1
-		if (hnodes[i]) hnodes_size+=hnodes[i]->MarshallSize();
-	}
-
-	return sizeof(id)
-		+sizeof(sid)
-		+hnodes_size
-		+sizeof(numanalyses)
-		+numanalyses*sizeof(int) //element_type_lists
-		+hmatice->MarshallSize()
-		+hmatpar->MarshallSize()
-		+hneighbors->MarshallSize()
-		+inputs->MarshallSize()
-		+results->MarshallSize()
-		+3*sizeof(int)
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Penta::Demarshall {{{1*/
-void  Penta::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-	int flaghook;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&sid,marshalled_dataset,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(&numanalyses,marshalled_dataset,sizeof(numanalyses));marshalled_dataset+=sizeof(numanalyses);
-
-	/*demarshall Ref: */
-	this->element_type_list=(int*)xmalloc(this->numanalyses*sizeof(int));
-	for(i=0;i<numanalyses;i++){ memcpy(&element_type_list[i],marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);}
-
-	/*allocate dynamic memory: */
-	this->hnodes=new Hook*[this->numanalyses];
-	/*demarshall hooks: */
-	for(i=0;i<numanalyses;i++){
-		memcpy(&flaghook,marshalled_dataset,sizeof(flaghook));marshalled_dataset+=sizeof(flaghook);
-		if(flaghook){ // there is a hook so demarshall it
-			hnodes[i]=new Hook();
-			hnodes[i]->Demarshall(&marshalled_dataset);
-		}
-		else hnodes[i]=NULL; //There is no hook so it is NULL
-	}
-	hmatice=new Hook(); hmatice->Demarshall(&marshalled_dataset);
-	hmatpar=new Hook(); hmatpar->Demarshall(&marshalled_dataset);
-	hneighbors=new Hook(); hneighbors->Demarshall(&marshalled_dataset);
-
-	/*pointers are garbage, until configuration is carried out: */
-	nodes=NULL;
-	matice=NULL;
-	matpar=NULL;
-	verticalneighbors=NULL;
-
-	/*demarshall inputs and results: */
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-	results=(Results*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*parameters: may not exist even yet, so let Configure handle it: */
-	this->parameters=NULL;
-
-	/*neighbors: */
-	memcpy(&this->horizontalneighborsids,marshalled_dataset,3*sizeof(int));marshalled_dataset+=3*sizeof(int);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 
 /*Other*/
Index: /issm/trunk/src/c/objects/Elements/Penta.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Elements/Penta.h	(revision 12330)
@@ -55,9 +55,4 @@
 		int		  ObjectEnum();
 		int		  Id(); 
-		#ifdef _SERIAL_
-		void	  Marshall(char** pmarshalled_dataset);
-		int		  MarshallSize();
-		void	  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int		  MyRank();
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Elements/Tria.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 12330)
@@ -122,158 +122,4 @@
 }
 /*}}}*/
-
-/*Marshall*/
-#ifdef _SERIAL_
-/*FUNCTION Tria::Marshall {{{1*/
-void  Tria::Marshall(char** pmarshalled_dataset){
-
-	int   i;
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-	char* marshalled_results=NULL;
-	int   marshalled_results_size;
-	int   flaghook; //to indicate if hook is NULL or exists
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Tria: */
-	enum_type=TriaEnum;
-
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*marshall Tria data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&sid,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(marshalled_dataset,&numanalyses,sizeof(numanalyses));marshalled_dataset+=sizeof(numanalyses);
-
-	/*Mershall Ref: */
-	for(i=0;i<numanalyses;i++){
-		memcpy(marshalled_dataset,&element_type_list[i],sizeof(element_type_list[i]));marshalled_dataset+=sizeof(element_type_list[i]);
-	}
-
-	/*Marshall hooks: */
-	for(i=0;i<numanalyses;i++){
-		if(hnodes[i]){
-			/*Set flag to 1 as there is a hook */
-			flaghook=1;
-			memcpy(marshalled_dataset,&flaghook,sizeof(flaghook));marshalled_dataset+=sizeof(flaghook);
-			hnodes[i]->Marshall(&marshalled_dataset);
-		}
-		else{
-			/*Set flag to 0 and do not marshall flag as there is no Hook */
-			flaghook=0;
-			memcpy(marshalled_dataset,&flaghook,sizeof(flaghook));marshalled_dataset+=sizeof(flaghook);
-		}
-	}
-	hmatice->Marshall(&marshalled_dataset);
-	hmatpar->Marshall(&marshalled_dataset);
-
-	/*Marshall inputs: */
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	/*Marshall results: */
-	marshalled_results_size=results->MarshallSize();
-	marshalled_results=results->Marshall();
-	memcpy(marshalled_dataset,marshalled_results,marshalled_results_size*sizeof(char));
-	marshalled_dataset+=marshalled_results_size;
-
-	/*parameters: don't do anything about it. parameters are marshalled somewhere else!*/
-
-	xfree((void**)&marshalled_inputs);
-	xfree((void**)&marshalled_results);
-
-	/*marshall horizontal neighbors: */
-	memcpy(marshalled_dataset,horizontalneighborsids,3*sizeof(int));marshalled_dataset+=3*sizeof(int);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Tria::MarshallSize {{{1*/
-int   Tria::MarshallSize(){
-
-	int i;
-	int hnodes_size=0;;
-
-	for(i=0;i<numanalyses;i++){
-		hnodes_size+=sizeof(int); //Flag 0 or 1
-		if (hnodes[i]) hnodes_size+=hnodes[i]->MarshallSize();
-	}
-
-	return sizeof(id)
-	  +sizeof(sid)
-	  +hnodes_size
-	  +sizeof(numanalyses)
-	  +numanalyses*sizeof(int) //element_type_lists
-	  +hmatice->MarshallSize()
-	  +hmatpar->MarshallSize()
-	  +inputs->MarshallSize()
-	  +results->MarshallSize()
-	  +3*sizeof(int)
-	  +sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Tria::Demarshall {{{1*/
-void  Tria::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int i;
-	int flaghook;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&sid,marshalled_dataset,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(&numanalyses,marshalled_dataset,sizeof(numanalyses));marshalled_dataset+=sizeof(numanalyses);
-
-	/*demarshall Ref: */
-	this->element_type_list=(int*)xmalloc(this->numanalyses*sizeof(int));
-	for(i=0;i<numanalyses;i++){ memcpy(&element_type_list[i],marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);}
-
-	/*allocate dynamic memory: */
-	this->hnodes=new Hook*[this->numanalyses];
-	/*demarshall hooks: */
-	for(i=0;i<numanalyses;i++){
-		memcpy(&flaghook,marshalled_dataset,sizeof(flaghook));marshalled_dataset+=sizeof(flaghook);
-		if(flaghook){ // there is a hook so demarshall it
-			hnodes[i]=new Hook();
-			hnodes[i]->Demarshall(&marshalled_dataset);
-		}
-		else hnodes[i]=NULL; //There is no hook so it is NULL
-	}
-	hmatice=new Hook(); hmatice->Demarshall(&marshalled_dataset);
-	hmatpar=new Hook(); hmatpar->Demarshall(&marshalled_dataset);
-
-	/*pointers are garbabe, until configuration is carried out: */
-	nodes=NULL;
-	matice=NULL;
-	matpar=NULL;
-	
-	/*demarshall inputs: */
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-	results=(Results*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*parameters: may not exist even yet, so let Configure handle it: */
-	this->parameters=NULL;
-
-	/*neighbors: */
-	memcpy(&this->horizontalneighborsids,marshalled_dataset,3*sizeof(int));marshalled_dataset+=3*sizeof(int);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 
 /*Other*/
@@ -783,5 +629,8 @@
 		basal_melting_input->GetInputValue(&basal_melting_g,gauss);
 		thickness_input->GetInputValue(&thickness_g,gauss);
-		if(basal_melting_correction_input) basal_melting_correction_input->GetInputValue(&basal_melting_correction_g,gauss);
+		if(basal_melting_correction_input)
+		 basal_melting_correction_input->GetInputValue(&basal_melting_correction_g,gauss);
+		else
+		 basal_melting_correction_g=0.;
 
 		for(i=0;i<numdof;i++) pe->values[i]+=Jdettria*gauss->weight*(thickness_g+dt*(surface_mass_balance_g-basal_melting_g-basal_melting_correction_g))*L[i];
Index: /issm/trunk/src/c/objects/Elements/Tria.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Tria.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Elements/Tria.h	(revision 12330)
@@ -51,9 +51,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.cpp	(revision 12330)
@@ -68,64 +68,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION BoolExternalResult::Marshall{{{1*/
-void  BoolExternalResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of BoolExternalResult: */
-	enum_value=BoolExternalResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall BoolExternalResult data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION BoolExternalResult::MarshallSize{{{1*/
-int   BoolExternalResult::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(id)
-		+sizeof(enum_type)
-		+sizeof(step)
-		+sizeof(time)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION BoolExternalResult::Demarshall{{{1*/
-void  BoolExternalResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION BoolExternalResult::ObjectEnum{{{1*/
 int BoolExternalResult::ObjectEnum(void){
@@ -185,17 +125,4 @@
 }
 /*}}}*/
-/*FUNCTION BoolExternalResult::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void BoolExternalResult::SetMatlabField(mxArray* dataref){
-
-	char* name=NULL;
-	this->GetResultName(&name);
-	
-	mxSetField( dataref, this->step-1, name,mxCreateDoubleScalar((double)value));
-	mxSetField( dataref, this->step-1, "time",mxCreateDoubleScalar((double)this->time)); 
-	mxSetField( dataref, this->step-1, "step",mxCreateDoubleScalar((double)this->step)); 
-}
-#endif
-/*}}}*/
 /*FUNCTION BoolExternalResult::GetStep{{{1*/
 int BoolExternalResult::GetStep(void){
Index: /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.h	(revision 12330)
@@ -15,9 +15,4 @@
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
 #endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
-
 
 #include "./ExternalResult.h"
@@ -47,9 +42,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -59,9 +49,6 @@
 		void  WriteData(FILE* fid,bool io_gather);
 		void  GetResultName(char**);
-	    #if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		int   GetStep(void);
 		/*}}}*/
 };
-#endif  /* _BOOLEXTERNALRESULT_H */
+#endif
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.cpp	(revision 12330)
@@ -68,64 +68,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleExternalResult::Marshall{{{1*/
-void  DoubleExternalResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleExternalResult: */
-	enum_value=DoubleExternalResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleExternalResult data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleExternalResult::MarshallSize{{{1*/
-int   DoubleExternalResult::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(id)
-		+sizeof(enum_type)
-		+sizeof(step)
-		+sizeof(time)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION DoubleExternalResult::Demarshall{{{1*/
-void  DoubleExternalResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleExternalResult::ObjectEnum{{{1*/
 int DoubleExternalResult::ObjectEnum(void){
@@ -181,17 +121,4 @@
 }
 /*}}}*/
-/*FUNCTION DoubleExternalResult::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void DoubleExternalResult::SetMatlabField(mxArray* dataref){
-
-	char* name=NULL;
-	this->GetResultName(&name);
-	mxSetField( dataref,this->step-1, name,mxCreateDoubleScalar(value));
-	mxSetField( dataref, this->step-1, "time",mxCreateDoubleScalar((double)this->time)); 
-	mxSetField( dataref, this->step-1, "step",mxCreateDoubleScalar((double)this->step)); 
-
-}
-#endif
-/*}}}*/
 /*FUNCTION DoubleExternalResult::GetStep{{{1*/
 int DoubleExternalResult::GetStep(void){
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.h	(revision 12330)
@@ -14,8 +14,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -48,9 +44,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -60,7 +51,4 @@
 		void  WriteData(FILE* fid,bool io_gather);
 		void  GetResultName(char**);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		int   GetStep(void);
 		/*}}}*/
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.cpp	(revision 12330)
@@ -96,73 +96,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleMatExternalResult::Marshall{{{1*/
-void  DoubleMatExternalResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleMatExternalResult: */
-	enum_value=DoubleMatExternalResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleMatExternalResult data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(marshalled_dataset,&N,sizeof(N));marshalled_dataset+=sizeof(N);
-	memcpy(marshalled_dataset,values,M*sizeof(double));marshalled_dataset+=M*sizeof(double);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleMatExternalResult::MarshallSize{{{1*/
-int   DoubleMatExternalResult::MarshallSize(){
-	
-	return sizeof(M)
-		+sizeof(N)
-		+M*N*sizeof(double)
-		+sizeof(id)
-		+sizeof(enum_type)
-		+sizeof(step)
-		+sizeof(time)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION DoubleMatExternalResult::Demarshall{{{1*/
-void  DoubleMatExternalResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(&N,marshalled_dataset,sizeof(N));marshalled_dataset+=sizeof(N);
-	values=(double*)xmalloc(M*N*sizeof(double));
-	memcpy(values,marshalled_dataset,M*N*sizeof(double));marshalled_dataset+=M*N*sizeof(double);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleMatExternalResult::ObjectEnum{{{1*/
 int DoubleMatExternalResult::ObjectEnum(void){
@@ -222,37 +153,4 @@
 }
 /*}}}*/
-/*FUNCTION DoubleMatExternalResult::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void DoubleMatExternalResult::SetMatlabField(mxArray* dataref){
-
-	mxArray* pfield=NULL;
-	mxArray* pfield2=NULL;
-	char* name=NULL;
-	double* doublemat=NULL;
-
-	/*Make a copy of the value, to be used by matlab: */
-	doublemat=(double*)xmalloc(M*N*sizeof(double));
-	memcpy(doublemat,values,M*N*sizeof(double));
-
-	/*recover name: */
-	this->GetResultName(&name);
-				
-	/*create matlab matrix: */
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,N);
-	mxSetN(pfield,M);
-	mxSetPr(pfield,doublemat);
-	
-	/*transpose the matrix, from c to matlab format */
-	mexCallMATLAB(1,&pfield2, 1, &pfield, "transpose");
-
-	/*set tranpose matrix inside the dataref structure: */
-	mxSetField( dataref, this->step-1, name,pfield2);
-	mxSetField( dataref, this->step-1, "time",mxCreateDoubleScalar((double)this->time));
-	mxSetField( dataref, this->step-1, "step",mxCreateDoubleScalar((double)this->step));
-
-}
-#endif
-/*}}}*/
 /*FUNCTION DoubleMatExternalResult::GetStep{{{1*/
 int DoubleMatExternalResult::GetStep(void){
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.h	(revision 12330)
@@ -14,9 +14,4 @@
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
 #endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
-
 
 #include "./ExternalResult.h"
@@ -49,9 +44,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -61,7 +51,4 @@
 		void  WriteData(FILE* fid,bool io_gather);
 		void  GetResultName(char**);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		int   GetStep(void);
 		/*}}}*/
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.cpp	(revision 12330)
@@ -87,70 +87,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleVecExternalResult::Marshall{{{1*/
-void  DoubleVecExternalResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleVecExternalResult: */
-	enum_value=DoubleVecExternalResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleVecExternalResult data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(marshalled_dataset,values,M*sizeof(double));marshalled_dataset+=M*sizeof(double);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleVecExternalResult::MarshallSize{{{1*/
-int   DoubleVecExternalResult::MarshallSize(){
-	
-	return sizeof(M)
-		+M*sizeof(double)
-		+sizeof(id)
-		+sizeof(enum_type)
-		+sizeof(step)
-		+sizeof(time)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION DoubleVecExternalResult::Demarshall{{{1*/
-void  DoubleVecExternalResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	values=(double*)xmalloc(M*sizeof(double));
-	memcpy(values,marshalled_dataset,M*sizeof(double));marshalled_dataset+=M*sizeof(double);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleVecExternalResult::ObjectEnum{{{1*/
 int DoubleVecExternalResult::ObjectEnum(void){
@@ -206,32 +140,4 @@
 }
 /*}}}*/
-/*FUNCTION DoubleVecExternalResult::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void DoubleVecExternalResult::SetMatlabField(mxArray* dataref){
-
-	mxArray *pfield    = NULL;
-	double  *doublemat = NULL;
-	char    *name      = NULL;
-	double  *doublevec = NULL;
-
-	/*Make a copy of the value, to be used by matlab: */
-	doublevec=(double*)xmalloc(M*sizeof(double));
-	memcpy(doublevec,values,M*sizeof(double));
-
-	/*recover name: */
-	this->GetResultName(&name);
-				
-	/*create matlab matrix: */
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,M);
-	mxSetN(pfield,1);
-	mxSetPr(pfield,doublevec);
-
-	mxSetField( dataref, this->step-1, name,pfield);
-	mxSetField( dataref, this->step-1, "time",mxCreateDoubleScalar((double)this->time)); 
-	mxSetField( dataref, this->step-1, "step",mxCreateDoubleScalar((double)this->step)); 
-}
-#endif
-/*}}}*/
 /*FUNCTION DoubleVecExternalResult::GetStep{{{1*/
 int DoubleVecExternalResult::GetStep(void){
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.h	(revision 12330)
@@ -14,9 +14,4 @@
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
 #endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
-
 
 #include "./ExternalResult.h"
@@ -48,9 +43,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -60,7 +50,4 @@
 		void  WriteData(FILE* fid,bool io_gather);
 		void  GetResultName(char**);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		int   GetStep(void);
 		/*}}}*/
Index: /issm/trunk/src/c/objects/ExternalResults/ExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/ExternalResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/ExternalResult.h	(revision 12330)
@@ -16,8 +16,4 @@
 #endif
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
-
 #include "../Object.h"
 #include "../Node.h"
@@ -33,7 +29,4 @@
 		virtual void  WriteData(FILE* fid,bool io_gather)=0;
 		virtual void  GetResultName(char**)=0;
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		virtual void  SetMatlabField(mxArray* dataref)=0;
-		#endif
 		virtual int   GetStep(void)=0;
 		/*}}}*/
Index: /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.cpp	(revision 12330)
@@ -68,64 +68,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION IntExternalResult::Marshall{{{1*/
-void  IntExternalResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of IntExternalResult: */
-	enum_value=IntExternalResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall IntExternalResult data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION IntExternalResult::MarshallSize{{{1*/
-int   IntExternalResult::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(id)
-		+sizeof(enum_type)
-		+sizeof(step)
-		+sizeof(time)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION IntExternalResult::Demarshall{{{1*/
-void  IntExternalResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION IntExternalResult::ObjectEnum{{{1*/
 int IntExternalResult::ObjectEnum(void){
@@ -185,18 +125,4 @@
 }
 /*}}}*/
-/*FUNCTION IntExternalResult::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void IntExternalResult::SetMatlabField(mxArray* dataref){
-
-	char* name=NULL;
-	this->GetResultName(&name);
-
-	mxSetField( dataref, this->step-1, name,mxCreateDoubleScalar(value));
-	mxSetField( dataref, this->step-1, "time",mxCreateDoubleScalar((double)this->time)); 
-	mxSetField( dataref, this->step-1, "step",mxCreateDoubleScalar((double)this->step)); 
-
-}
-#endif
-/*}}}*/
 /*FUNCTION IntExternalResult::GetStep{{{1*/
 int IntExternalResult::GetStep(void){
Index: /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.h	(revision 12330)
@@ -14,8 +14,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -46,9 +42,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -58,7 +49,4 @@
 		void  WriteData(FILE* fid,bool io_gather);
 		void  GetResultName(char**);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		int   GetStep(void);
 		/*}}}*/
Index: /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.cpp	(revision 12330)
@@ -80,108 +80,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION PetscVecExternalResult::Marshall{{{1*/
-void  PetscVecExternalResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-	int   M;
-	double* serial_value=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of PetscVecExternalResult: */
-	enum_value=PetscVecExternalResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall PetscVecExternalResult data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-	
-	if(value){
-		VecGetSize(value,&M);
-		VecToMPISerial(&serial_value,value);
-		memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-		memcpy(marshalled_dataset,serial_value,M*sizeof(double));marshalled_dataset+=(M*sizeof(double));
-	}
-	else{
-		M=0;
-		memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	}
-	/*Free ressources:*/
-	xfree((void**)&serial_value);
-
-	/*return:*/
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION PetscVecExternalResult::MarshallSize{{{1*/
-int   PetscVecExternalResult::MarshallSize(){
-
-	int M=0;
-	if(value)VecGetSize(value,&M);
-
-	return sizeof(M)+M*sizeof(double)
-		+sizeof(id)
-		+sizeof(enum_type)
-		+sizeof(step)
-		+sizeof(time)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION PetscVecExternalResult::Demarshall{{{1*/
-void  PetscVecExternalResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-	int   M;
-	double* serial_vec=NULL;
-	int*    idxm=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-	
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	if(M){
-		serial_vec=(double*)xmalloc(M*sizeof(double));
-		memcpy(serial_vec,marshalled_dataset,M*sizeof(double));marshalled_dataset+=(M*sizeof(double));
-
-		value=NewVec(M);
-		idxm=(int*)xmalloc(M*sizeof(int));
-		for(i=0;i<M;i++)idxm[i]=i;
-		VecSetValues(value,M,idxm,serial_vec,INSERT_VALUES);
-
-		VecAssemblyBegin(value);
-		VecAssemblyEnd(value);
-
-		
-	}
-	else{
-		value=NULL;
-	}
-
-	/*Free ressources:*/
-	xfree((void**)&serial_vec);
-	xfree((void**)&idxm);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-#endif
 /*FUNCTION PetscVecExternalResult::ObjectEnum{{{1*/
 int PetscVecExternalResult::ObjectEnum(void){
@@ -244,29 +140,4 @@
 }
 /*}}}*/
-/*FUNCTION PetscVecExternalResult::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  PetscVecExternalResult::SetMatlabField(mxArray* dataref){
-
-	mxArray* pfield=NULL;
-	char* name=NULL;
-	double* doublevec=NULL;
-	int M;
-	
-	VecToMPISerial(&doublevec,value);
-	VecGetSize(value,&M);
-	this->GetResultName(&name);
-	
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,M);
-	mxSetN(pfield,1);
-	mxSetPr(pfield,doublevec);
-	
-	mxSetField( dataref, this->step-1, name, pfield);
-	mxSetField( dataref, this->step-1, "time",mxCreateDoubleScalar((double)this->time)); 
-	mxSetField( dataref, this->step-1, "step",mxCreateDoubleScalar((double)this->step)); 
-
-}
-#endif
-/*}}}*/
 /*FUNCTION PetscVecExternalResult::GetStep{{{1*/
 int PetscVecExternalResult::GetStep(void){
Index: /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.h	(revision 12330)
@@ -15,9 +15,4 @@
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
 #endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
-
 
 #include "./ExternalResult.h"
@@ -48,9 +43,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -60,7 +50,4 @@
 		void  WriteData(FILE* fid,bool io_gather);
 		void  GetResultName(char**);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		int   GetStep(void);
 		/*}}}*/
Index: /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.cpp	(revision 12330)
@@ -71,77 +71,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION StringExternalResult::Marshall{{{1*/
-void  StringExternalResult::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-	int   stringsize;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of StringExternalResult: */
-	enum_value=StringExternalResultEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-
-	/*marshall data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	stringsize=strlen(this->value)+1;
-	
-	memcpy(marshalled_dataset,&stringsize,sizeof(stringsize));marshalled_dataset+=sizeof(stringsize);
-	memcpy(marshalled_dataset,this->value,stringsize*sizeof(char));marshalled_dataset+=stringsize*sizeof(char);
-	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION StringExternalResult::MarshallSize{{{1*/
-int   StringExternalResult::MarshallSize(){
-
-	int stringsize;
-	stringsize=strlen(this->value)+1;
-	
-	return sizeof(int)+
-		+stringsize*sizeof(char)
-		+sizeof(id)
-		+sizeof(enum_type)
-		+sizeof(step)
-		+sizeof(time)
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION StringExternalResult::Demarshall{{{1*/
-void  StringExternalResult::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-	int   stringsize;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	memcpy(&stringsize,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-	
-	this->value=(char*)xmalloc(stringsize*sizeof(char));
-	memcpy(value,marshalled_dataset,stringsize*sizeof(char));marshalled_dataset+=stringsize*sizeof(char);
-	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
-	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION StringExternalResult::ObjectEnum{{{1*/
 int StringExternalResult::ObjectEnum(void){
@@ -197,19 +124,4 @@
 }
 /*}}}*/
-/*FUNCTION StringExternalResult::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  StringExternalResult::SetMatlabField(mxArray* dataref){
-	
-	char* name=NULL;
-
-	this->GetResultName(&name);
-
-	mxSetField( dataref, this->step-1, name, mxCreateString(value));
-	mxSetField( dataref, this->step-1, "time",mxCreateDoubleScalar((double)this->time)); 
-	mxSetField( dataref, this->step-1, "step",mxCreateDoubleScalar((double)this->step)); 
-
-}
-#endif
-/*}}}*/
 /*FUNCTION StringExternalResult::GetStep{{{1*/
 int StringExternalResult::GetStep(void){
Index: /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.h	(revision 12329)
+++ /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.h	(revision 12330)
@@ -15,9 +15,4 @@
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
 #endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
-
 
 #include "./ExternalResult.h"
@@ -48,9 +43,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -60,7 +50,4 @@
 		void  WriteData(FILE* fid,bool io_gather);
 		void  GetResultName(char**);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		int   GetStep(void);
 		/*}}}*/
Index: /issm/trunk/src/c/objects/FemModel.cpp
===================================================================
--- /issm/trunk/src/c/objects/FemModel.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/FemModel.cpp	(revision 12330)
@@ -22,5 +22,4 @@
 /*FUNCTION FemModel::constructor {{{1*/
 FemModel::FemModel(char* inputfilename, char* outputfilename, const int in_solution_type,const int* analyses,const int nummodels){
-#ifdef _PARALLEL_
 
 	/*intermediary*/
@@ -75,6 +74,4 @@
 	/*Add output file name to parameters: */
 	this->parameters->AddObject(new StringParam(OutputfilenameEnum,outputfilename));
-
-#endif
 
 }
Index: /issm/trunk/src/c/objects/Hook.cpp
===================================================================
--- /issm/trunk/src/c/objects/Hook.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Hook.cpp	(revision 12330)
@@ -118,91 +118,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION Hook::Marshall{{{1*/
-void Hook::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Hook: */
-	enum_type=HookEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall Hook data: */
-	memcpy(marshalled_dataset,&num,sizeof(num));marshalled_dataset+=sizeof(num);
-	for(i=0;i<num;i++){
-		memcpy(marshalled_dataset,&this->ids[i],sizeof(int));marshalled_dataset+=sizeof(int);
-		memcpy(marshalled_dataset,&this->offsets[i],sizeof(int));marshalled_dataset+=sizeof(int);
-	}
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Hook::MarshallSize{{{1*/
-int Hook::MarshallSize(){
-
-	return 
-		sizeof(num)+
-		num*sizeof(int)+
-		num*sizeof(int)+
-		sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Hook::Demarshall{{{1*/
-void Hook::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-	int   enum_type;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of object since Hook is not directly called by DataSet: */
-	memcpy(&enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-
-	memcpy(&num,marshalled_dataset,sizeof(num));marshalled_dataset+=sizeof(num);
-	
-	/*allocate: */
-	if (num<0){
-		_error_("cannot demarshall Hook as num<=0");
-	}
-	else if (num==0){
-		this->ids=NULL;
-		this->offsets=NULL;
-		this->objects=NULL;
-	}
-	else{
-
-		this->ids=(int*)xmalloc(num*sizeof(int));
-		this->offsets=(int*)xmalloc(num*sizeof(int));
-
-		/*demarshall allocated ids and offsets: */
-		_assert_(num<1000);
-		for (i=0;i<num;i++){
-			memcpy(&this->ids[i],marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-			memcpy(&this->offsets[i],marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-		}
-
-		/*nullify object pointers */
-		this->objects=(Object**)xmalloc(num*sizeof(Object*));
-		for (i=0;i<num;i++){
-			this->objects[i]=NULL;
-		}
-	}
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION Hook::copy {{{1*/
 Object* Hook::copy(void){
Index: /issm/trunk/src/c/objects/Hook.h
===================================================================
--- /issm/trunk/src/c/objects/Hook.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Hook.h	(revision 12330)
@@ -34,9 +34,4 @@
 		void       Echo(void);
 		void       DeepEcho(void);
-		#ifdef _SERIAL_
-		void       Marshall(char** pmarshalled_dataset);
-		int        MarshallSize();
-		void       Demarshall(char** pmarshalled_dataset);
-		#endif
 		Object*    copy(void);
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Inputs/BoolInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/BoolInput.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/BoolInput.cpp	(revision 12330)
@@ -59,55 +59,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION BoolInput::Marshall{{{1*/
-void  BoolInput::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of BoolInput: */
-	enum_value=BoolInputEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall BoolInput data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION BoolInput::MarshallSize{{{1*/
-int   BoolInput::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION BoolInput::Demarshall{{{1*/
-void  BoolInput::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION BoolInput::ObjectEnum{{{1*/
 int BoolInput::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Inputs/BoolInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/BoolInput.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/BoolInput.h	(revision 12330)
@@ -31,9 +31,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Inputs/ControlInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/ControlInput.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/ControlInput.cpp	(revision 12330)
@@ -90,212 +90,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION ControlInput::Marshall{{{1*/
-void  ControlInput::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-	int   flag;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of ControlInput: */
-	enum_value=ControlInputEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall enum_type: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&control_id,sizeof(control_id));marshalled_dataset+=sizeof(control_id);
-
-	/*marshal values*/
-	if(!values){
-		flag=0;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-	}
-	else{
-		flag=1;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-		this->values->Marshall(&marshalled_dataset);
-	}
-
-	/*marshal savedvalues*/
-	if(!savedvalues){
-		flag=0;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-	}
-	else{
-		flag=1;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-		this->savedvalues->Marshall(&marshalled_dataset);
-	}
-
-	/*marshal minvalues*/
-	if(!minvalues){
-		flag=0;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-	}
-	else{
-		flag=1;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-		this->minvalues->Marshall(&marshalled_dataset);
-	}
-
-	/*marshal maxvalues*/
-	if(!maxvalues){
-		flag=0;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-	}
-	else{
-		flag=1;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-		this->maxvalues->Marshall(&marshalled_dataset);
-	}
-
-	/*marshal gradient*/
-	if(!gradient){
-		flag=0;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-	}
-	else{
-		flag=1;
-		memcpy(marshalled_dataset,&flag,sizeof(flag));marshalled_dataset+=sizeof(flag);
-		this->gradient->Marshall(&marshalled_dataset);
-	}
-
-	/*clean up and assign output pointer*/
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION ControlInput::MarshallSize{{{1*/
-int   ControlInput::MarshallSize(){
-	
-	int size=0;
-
-	size=sizeof(enum_type)+
-	  +sizeof(control_id)
-	  +5*sizeof(int) //5 flags
-	  +sizeof(int); //sizeof(int) for enum value
-
-	if(values)     size+=values->MarshallSize();
-	if(savedvalues)size+=savedvalues->MarshallSize();
-	if(minvalues)size+=minvalues->MarshallSize();
-	if(maxvalues)size+=maxvalues->MarshallSize();
-	if(gradient)   size+=gradient->MarshallSize();
-	return size;
-}
-/*}}}*/
-/*FUNCTION ControlInput::Demarshall{{{1*/
-void  ControlInput::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   flag,input_enum_type;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&control_id,marshalled_dataset,sizeof(control_id));marshalled_dataset+=sizeof(control_id);
-
-	/*Demarshal values*/
-	memcpy(&flag,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-	if(flag){
-		memcpy(&input_enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-		if(input_enum_type==PentaP1InputEnum){
-			values=new PentaP1Input();
-			values->Demarshall(&marshalled_dataset);
-		}
-		else if(input_enum_type==TriaP1InputEnum){
-			values=new TriaP1Input();
-			values->Demarshall(&marshalled_dataset);
-		}
-		else _error_("Not supported yet");
-	}
-	else{
-		values=NULL;
-	}
-
-	/*Demarshal savedvalues*/
-	memcpy(&flag,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-	if(flag){
-		memcpy(&input_enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-		if(input_enum_type==PentaP1InputEnum){
-			savedvalues=new PentaP1Input();
-			savedvalues->Demarshall(&marshalled_dataset);
-		}
-		else if(input_enum_type==TriaP1InputEnum){
-			savedvalues=new TriaP1Input();
-			savedvalues->Demarshall(&marshalled_dataset);
-		}
-		else _error_("Not supported yet");
-	}
-	else{
-		savedvalues=NULL;
-	}
-
-	/*Demarshal minvalues*/
-	memcpy(&flag,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-	if(flag){
-		memcpy(&input_enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-		if(input_enum_type==PentaP1InputEnum){
-			minvalues=new PentaP1Input();
-			minvalues->Demarshall(&marshalled_dataset);
-		}
-		else if(input_enum_type==TriaP1InputEnum){
-			minvalues=new TriaP1Input();
-			minvalues->Demarshall(&marshalled_dataset);
-		}
-		else _error_("Not supported yet");
-	}
-	else{
-		minvalues=NULL;
-	}
-
-	/*Demarshal maxvalues*/
-	memcpy(&flag,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-	if(flag){
-		memcpy(&input_enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-		if(input_enum_type==PentaP1InputEnum){
-			maxvalues=new PentaP1Input();
-			maxvalues->Demarshall(&marshalled_dataset);
-		}
-		else if(input_enum_type==TriaP1InputEnum){
-			maxvalues=new TriaP1Input();
-			maxvalues->Demarshall(&marshalled_dataset);
-		}
-		else _error_("Not supported yet");
-	}
-	else{
-		maxvalues=NULL;
-	}
-
-	/*Demarshal gradient*/
-	memcpy(&flag,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-	if(flag){
-		memcpy(&input_enum_type,marshalled_dataset,sizeof(int)); marshalled_dataset+=sizeof(int);
-		if(input_enum_type==PentaP1InputEnum){
-			gradient=new PentaP1Input();
-			gradient->Demarshall(&marshalled_dataset);
-		}
-		else if(input_enum_type==TriaP1InputEnum){
-			gradient=new TriaP1Input();
-			gradient->Demarshall(&marshalled_dataset);
-		}
-		else _error_("Not supported yet");
-	}
-	else{
-		gradient=NULL;
-	}
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION ControlInput::ObjectEnum{{{1*/
 int ControlInput::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Inputs/ControlInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/ControlInput.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/ControlInput.h	(revision 12330)
@@ -35,9 +35,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Inputs/DatasetInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/DatasetInput.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/DatasetInput.cpp	(revision 12330)
@@ -61,68 +61,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DatasetInput::Marshall{{{1*/
-void  DatasetInput::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DatasetInput: */
-	enum_value=DatasetInputEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall enum_type: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*marshal inputs*/
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	/*clean up and assign output pointer*/
-	xfree((void**)&marshalled_inputs);
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DatasetInput::MarshallSize{{{1*/
-int   DatasetInput::MarshallSize(){
-	
-	int size=0;
-
-	size=sizeof(enum_type)+
-	  +inputs->MarshallSize()
-	  +sizeof(int); //sizeof(int) for enum value
-
-	return size;
-}
-/*}}}*/
-/*FUNCTION DatasetInput::Demarshall{{{1*/
-void  DatasetInput::Demarshall(char** pmarshalled_dataset){
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*Demarshal values*/
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DatasetInput::ObjectEnum{{{1*/
 int DatasetInput::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Inputs/DatasetInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/DatasetInput.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/DatasetInput.h	(revision 12330)
@@ -31,9 +31,4 @@
 		int   Id();
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Inputs/DoubleInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/DoubleInput.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/DoubleInput.cpp	(revision 12330)
@@ -59,55 +59,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleInput::Marshall{{{1*/
-void  DoubleInput::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleInput: */
-	enum_value=DoubleInputEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleInput data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleInput::MarshallSize{{{1*/
-int   DoubleInput::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION DoubleInput::Demarshall{{{1*/
-void  DoubleInput::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleInput::ObjectEnum{{{1*/
 int DoubleInput::ObjectEnum(void){
@@ -159,9 +108,5 @@
 /*FUNCTION DoubleInput::GetInputValue(bool* pvalue) {{{1*/
 void DoubleInput::GetInputValue(bool* pvalue){
-#ifdef _SERIAL_
-	*pvalue=(bool)value;
-#else
 	_error_("Double input of enum %s cannot return a boolean",EnumToStringx(enum_type));
-#endif
 
 }
@@ -169,9 +114,5 @@
 /*FUNCTION DoubleInput::GetInputValue(int* pvalue){{{1*/
 void DoubleInput::GetInputValue(int* pvalue){
-#ifdef _SERIAL_
-	*pvalue=(int)value;
-#else
 	_error_("Double input of enum %i (%s) cannot return an integer",enum_type,EnumToStringx(enum_type));
-#endif
 
 }
Index: /issm/trunk/src/c/objects/Inputs/DoubleInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/DoubleInput.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/DoubleInput.h	(revision 12330)
@@ -30,9 +30,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Inputs/IntInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/IntInput.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/IntInput.cpp	(revision 12330)
@@ -54,55 +54,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION IntInput::Marshall{{{1*/
-void  IntInput::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of IntInput: */
-	enum_value=IntInputEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall IntInput data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION IntInput::MarshallSize{{{1*/
-int   IntInput::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION IntInput::Demarshall{{{1*/
-void  IntInput::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION IntInput::ObjectEnum{{{1*/
 int IntInput::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Inputs/IntInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/IntInput.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/IntInput.h	(revision 12330)
@@ -31,9 +31,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Inputs/PentaP1Input.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/PentaP1Input.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/PentaP1Input.cpp	(revision 12330)
@@ -70,55 +70,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION PentaP1Input::Marshall{{{1*/
-void  PentaP1Input::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of PentaP1Input: */
-	enum_value=PentaP1InputEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall PentaP1Input data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&values,sizeof(values));marshalled_dataset+=sizeof(values);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION PentaP1Input::MarshallSize{{{1*/
-int   PentaP1Input::MarshallSize(){
-	
-	return sizeof(values)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION PentaP1Input::Demarshall{{{1*/
-void  PentaP1Input::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&values,marshalled_dataset,sizeof(values));marshalled_dataset+=sizeof(values);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION PentaP1Input::ObjectEnum{{{1*/
 int PentaP1Input::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Inputs/PentaP1Input.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/PentaP1Input.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/PentaP1Input.h	(revision 12330)
@@ -31,9 +31,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Inputs/TransientInput.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/TransientInput.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/TransientInput.cpp	(revision 12330)
@@ -85,77 +85,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION TransientInput::Marshall{{{*/
-void  TransientInput::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of TransientInput: */
-	enum_value=TransientInputEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-
-	/*marshall TransientInput data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&numtimesteps,sizeof(numtimesteps));marshalled_dataset+=sizeof(numtimesteps);
-	memcpy(marshalled_dataset,timesteps,numtimesteps*sizeof(double));marshalled_dataset+=numtimesteps*sizeof(double);
-
-	/*marshal inputs*/
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	/*clean up and assign output pointer*/
-	xfree((void**)&marshalled_inputs);
-	*pmarshalled_dataset=marshalled_dataset;
-
-}
-/*}}}*
-/*FUNCTION TransientInput::MarshallSize{{{*/
-int   TransientInput::MarshallSize(){
-
-	return 
-		+sizeof(enum_type)+
-		+sizeof(numtimesteps)+
-		+inputs->MarshallSize()
-		+numtimesteps*sizeof(double)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION TransientInput::Demarshall{{{*/
-void  TransientInput::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&numtimesteps,marshalled_dataset,sizeof(numtimesteps));marshalled_dataset+=sizeof(numtimesteps);
-
-	/*allocate: */
-	timesteps=(double*)xmalloc(numtimesteps*sizeof(double));
-	memcpy(timesteps,marshalled_dataset,numtimesteps*sizeof(double));marshalled_dataset+=numtimesteps*sizeof(double);
-
-	/*Demarshal values*/
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-
-}
-/*}}}*/
-#endif
 /*FUNCTION TransientInput::ObjectEnum{{{*/
 int TransientInput::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Inputs/TransientInput.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/TransientInput.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/TransientInput.h	(revision 12330)
@@ -34,9 +34,4 @@
 		int   Id();
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Inputs/TriaP1Input.cpp
===================================================================
--- /issm/trunk/src/c/objects/Inputs/TriaP1Input.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/TriaP1Input.cpp	(revision 12330)
@@ -70,55 +70,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION TriaP1Input::Marshall{{{1*/
-void  TriaP1Input::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of TriaP1Input: */
-	enum_value=TriaP1InputEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall TriaP1Input data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&values,sizeof(values));marshalled_dataset+=sizeof(values);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION TriaP1Input::MarshallSize{{{1*/
-int   TriaP1Input::MarshallSize(){
-	
-	return sizeof(values)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION TriaP1Input::Demarshall{{{1*/
-void  TriaP1Input::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&values,marshalled_dataset,sizeof(values));marshalled_dataset+=sizeof(values);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION TriaP1Input::ObjectEnum{{{1*/
 int TriaP1Input::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Inputs/TriaP1Input.h
===================================================================
--- /issm/trunk/src/c/objects/Inputs/TriaP1Input.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Inputs/TriaP1Input.h	(revision 12330)
@@ -31,9 +31,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/IoModel.cpp
===================================================================
--- /issm/trunk/src/c/objects/IoModel.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/IoModel.cpp	(revision 12330)
@@ -45,4 +45,7 @@
 	this->fid=iomodel_handle;
 
+	/*Check that Enums are Synchronized*/
+	this->CheckEnumSync();
+
 	/*Initialize and read constants:*/
 	this->constants=new Parameters();
@@ -89,4 +92,47 @@
 /*}}}*/
 
+/*FUNCTION IoModel::CheckEnumSync{{{1*/
+void  IoModel::CheckEnumSync(void){
+
+	extern int my_rank;
+	int record_enum = 0;
+
+
+	/*Check that some fields have been allocated*/
+	_assert_(this->fid || my_rank);
+
+
+	/*Go find in the binary file, the position of the data we want to fetch: */
+	if(my_rank==0){ //cpu 0
+
+		/*First set FILE* position to the beginning of the file: */
+		fseek(this->fid,0,SEEK_SET);
+
+		/*Get first Enum*/
+		if(fread(&record_enum,sizeof(int),1,this->fid)==0){
+			_error_("Marshalled file is empty");
+		}
+		else{
+			if(record_enum!=MaximumNumberOfEnums){
+				printf("\n");
+				printf("=========================================================================\n");
+				printf(" Enums in marshalled file are not compatible with compiled code          \n");
+				printf("                                                                         \n");
+				printf("   * If you are running ISSM on a remote cluster:                        \n");
+				printf("     make sure that you are using the same version of ISSM on your local \n");
+				printf("     machine and remote cluster (you might need to run svn update)       \n");
+				printf("   * If you are running ISSM on your local machine:                      \n");
+				printf("     make sure that all the code is compiled (modules and executables)   \n");
+				printf("   * If you are a developer and just added a new Enum:                   \n");
+				printf("     you might need to run ./Synchronize.sh in src/c/EnumDefinitions     \n");
+				printf("     and recompile                                                       \n");
+				printf("=========================================================================\n");
+				printf("\n");
+				_error_("Enums not consistent (See error message above)");
+			}
+		}
+	}
+}
+/*}}}*/
 /*FUNCTION IoModel::Constant(bool* poutput,int constant_enum){{{1*/
 void IoModel::Constant(bool* poutput,int constant_enum){
@@ -198,5 +244,7 @@
 				/*Ok, we have reached the end of the file. break: */
 				record_code=0; //0 means bailout
+				#ifdef _HAVE_MPI_
 				MPI_Bcast(&record_code,1,MPI_INT,0,MPI_COMM_WORLD);  /*tell others cpus we are bailing: */
+				#endif
 				break;
 			}
@@ -207,4 +255,5 @@
 				fread(&record_code,sizeof(int),1,this->fid);
 					
+				#ifdef _HAVE_MPI_
 				/*Tell other cpus what we are doing: */
 				MPI_Bcast(&record_code,1,MPI_INT,0,MPI_COMM_WORLD);  /*tell other cpus what we are going to do: */
@@ -213,11 +262,13 @@
 				MPI_Bcast(&record_enum,1,MPI_INT,0,MPI_COMM_WORLD);  
 				MPI_Bcast(&record_length,1,MPI_INT,0,MPI_COMM_WORLD);  
+				#endif
 				
-
 				switch(record_code){
 					case 1: 
 						/*Read the boolean and broadcast it to other cpus:*/
 						if(fread(&booleanint,sizeof(int),1,this->fid)!=1) _error_(" could not read boolean ");
+						#ifdef _HAVE_MPI_
 						MPI_Bcast(&booleanint,1,MPI_INT,0,MPI_COMM_WORLD); 
+						#endif
 
 						/*create BoolParam: */
@@ -228,5 +279,7 @@
 						/*Read the integer and broadcast it to other cpus:*/
 						if(fread(&integer,sizeof(int),1,this->fid)!=1) _error_(" could not read integer ");
+						#ifdef _HAVE_MPI_
 						MPI_Bcast(&integer,1,MPI_INT,0,MPI_COMM_WORLD); 
+						#endif
 
 						/*create IntParam: */
@@ -237,5 +290,7 @@
 						/*Read the scalar and broadcast it to other cpus:*/
 						if(fread(&scalar,sizeof(double),1,this->fid)!=1) _error_(" could not read scalar ");
+						#ifdef _HAVE_MPI_
 						MPI_Bcast(&scalar,1,MPI_DOUBLE,0,MPI_COMM_WORLD); 
+						#endif
 
 						/*create DoubleParam: */
@@ -246,5 +301,7 @@
 						/*We have to read a string from disk. First read the dimensions of the string, then the string: */
 						if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_(" could not read length of string ");
+						#ifdef _HAVE_MPI_
 						MPI_Bcast(&string_size,1,MPI_INT,0,MPI_COMM_WORLD); 
+						#endif
 
 						if(string_size){
@@ -254,5 +311,7 @@
 							/*Read string, then broadcast: */
 							if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_("  could not read string ");
+							#ifdef _HAVE_MPI_
 							MPI_Bcast(string,string_size,MPI_CHAR,0,MPI_COMM_WORLD); 
+							#endif
 						}
 						else{
@@ -308,4 +367,5 @@
 		}
 	} //}}}
+	#ifdef _HAVE_MPI_
 	else{ //cpu ~0 {{{2
 		for(;;){ //wait on cpu 0
@@ -377,4 +437,5 @@
 		}
 	} //}}}
+	#endif
 }
 /*}}}*/
@@ -399,5 +460,7 @@
 		if(fread(&booleanint,sizeof(int),1,fid)!=1) _error_(" could not read boolean ");
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&booleanint,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	/*cast to bool: */
@@ -428,5 +491,7 @@
 	}
 
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&integer,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	/*Assign output pointers: */
@@ -456,5 +521,7 @@
 		if(fread(&scalar,sizeof(double),1,fid)!=1)_error_(" could not read scalar ");
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&scalar,1,MPI_DOUBLE,0,MPI_COMM_WORLD); 
+	#endif
 
 	/*Assign output pointers: */
@@ -487,5 +554,7 @@
 	}
 
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&string_size,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	/*Now allocate string: */
@@ -498,5 +567,7 @@
 			if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_("  could not read string ");
 		}
+		#ifdef _HAVE_MPI_
 		MPI_Bcast(string,string_size,MPI_CHAR,0,MPI_COMM_WORLD); 
+		#endif
 	}
 	else{
@@ -538,10 +609,14 @@
 	}
 
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	if(my_rank==0){  
 		if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
 	}
-	MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#ifdef _HAVE_MPI_
+	MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD);
+	#endif
 
 	/*Now allocate matrix: */
@@ -554,5 +629,7 @@
 		}
 		
+		#ifdef _HAVE_MPI_
 		MPI_Bcast(matrix,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 
+		#endif
 	}
 
@@ -602,10 +679,14 @@
 		if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	if(my_rank==0){  
 		if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	/*Now allocate matrix: */
@@ -617,5 +698,7 @@
 			if(fread(matrix,M*N*sizeof(double),1,fid)!=1) _error_("could not read matrix ");
 		}
+		#ifdef _HAVE_MPI_
 		MPI_Bcast(matrix,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 
+		#endif
 	}
 
@@ -652,5 +735,7 @@
 		if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_(" could not read length of string array");
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&numstrings,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	/*Now allocate string array: */
@@ -665,5 +750,7 @@
 				if(fread(&string_size,sizeof(int),1,fid)!=1) _error_(" could not read length of string ");
 			}
+			#ifdef _HAVE_MPI_
 			MPI_Bcast(&string_size,1,MPI_INT,0,MPI_COMM_WORLD); 
+			#endif
 			if(string_size){
 				string=(char*)xmalloc((string_size+1)*sizeof(char));
@@ -674,5 +761,7 @@
 					if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_("  could not read string ");
 				}
+				#ifdef _HAVE_MPI_
 				MPI_Bcast(string,string_size,MPI_CHAR,0,MPI_COMM_WORLD); 
+				#endif
 			}
 			else{
@@ -717,5 +806,7 @@
 		if(fread(&numrecords,sizeof(int),1,fid)!=1) _error_("could not read number of records in matrix array ");
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&numrecords,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	if(numrecords){
@@ -738,10 +829,14 @@
 				if(fread(&M,sizeof(int),1,fid)!=1) _error_("%s%i%s","could not read number of rows in ",i,"th matrix of matrix array");
 			}
+			#ifdef _HAVE_MPI_
 			MPI_Bcast(&M,1,MPI_INT,0,MPI_COMM_WORLD); 
+			#endif
 
 			if(my_rank==0){  
 				if(fread(&N,sizeof(int),1,fid)!=1) _error_("%s%i%s","could not read number of columns in ",i,"th matrix of matrix array");
 			}
+			#ifdef _HAVE_MPI_
 			MPI_Bcast(&N,1,MPI_INT,0,MPI_COMM_WORLD); 
+			#endif
 
 			/*Now allocate matrix: */
@@ -754,5 +849,7 @@
 				}
 
+				#ifdef _HAVE_MPI_
 				MPI_Bcast(matrix,M*N,MPI_DOUBLE,0,MPI_COMM_WORLD); 
+				#endif
 			}
 
@@ -1047,11 +1144,15 @@
 		}
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&found,1,MPI_INT,0,MPI_COMM_WORLD); 
 	if(!found)_error_("%s %s ","could not find data with name",EnumToStringx(data_enum));
+	#endif
 
 	/*Broadcast code and vector type: */
+	#ifdef _HAVE_MPI_
 	MPI_Bcast(&record_code,1,MPI_INT,0,MPI_COMM_WORLD); 
 	MPI_Bcast(&vector_type,1,MPI_INT,0,MPI_COMM_WORLD); 
 	if(record_code==5) MPI_Bcast(&vector_type,1,MPI_INT,0,MPI_COMM_WORLD); 
+	#endif
 
 	/*Assign output pointers:*/
Index: /issm/trunk/src/c/objects/IoModel.h
===================================================================
--- /issm/trunk/src/c/objects/IoModel.h	(revision 12329)
+++ /issm/trunk/src/c/objects/IoModel.h	(revision 12330)
@@ -19,6 +19,6 @@
 	private: 
 		FILE        *fid;         //pointer to input file
-		double     **data;        //this dataset holds temporary data, memory intensive.
-		Parameters  *constants;   //this dataset holds all double, int, bool and char *parameters read in from the input file.*
+		IssmDouble     **data;        //this dataset holds temporary data, memory intensive.
+		Parameters  *constants;   //this dataset holds all IssmDouble, int, bool and char *parameters read in from the input file.*
 
 	public:
@@ -41,23 +41,24 @@
 
 		/*Input/Output*/
-		void        Constant(bool   *poutput,int constant_enum);
-		void        Constant(int    *poutput,int constant_enum);
-		void        Constant(double *poutput,int constant_enum);
-		void        Constant(char  **poutput,int constant_enum);
-		Param      *CopyConstantObject(int constant_enum);
-		double     *Data(int dataenum);
-		void        DeleteData(int num,...);
-		void        FetchConstants(void);
-		void        FetchData(bool*     pboolean,int data_enum);
-		void        FetchData(int*      pinteger,int data_enum);
-		void        FetchData(double*   pscalar,int data_enum);
-		void        FetchData(char**    pstring,int data_enum);
-		void        FetchData(int** pmatrix,int* pM,int* pN,int data_enum);
-		void        FetchData(double**  pscalarmatrix,int* pM,int* pN,int data_enum);
-		void        FetchData(char***   pstringarray,int* pnumstrings,int data_enum);
-		void        FetchData(double*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum);
-		void        FetchData(int num,...);
-		void        FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,double default_value=0);
-		FILE*       SetFilePointerToData(int* pcode,int* pvector_type, int data_enum);
+		void    CheckEnumSync(void);
+		void    Constant(bool   *poutput,int constant_enum);
+		void    Constant(int    *poutput,int constant_enum);
+		void    Constant(IssmDouble *poutput,int constant_enum);
+		void    Constant(char  **poutput,int constant_enum);
+		Param  *CopyConstantObject(int constant_enum);
+		IssmDouble *Data(int dataenum);
+		void    DeleteData(int num,...);
+		void    FetchConstants(void);
+		void    FetchData(bool*     pboolean,int data_enum);
+		void    FetchData(int*      pinteger,int data_enum);
+		void    FetchData(IssmDouble*   pscalar,int data_enum);
+		void    FetchData(char**    pstring,int data_enum);
+		void    FetchData(int** pmatrix,int* pM,int* pN,int data_enum);
+		void    FetchData(IssmDouble**  pscalarmatrix,int* pM,int* pN,int data_enum);
+		void    FetchData(char***   pstringarray,int* pnumstrings,int data_enum);
+		void    FetchData(IssmDouble*** pmatrixarray,int** pmdims,int** pndims, int* pnumrecords,int data_enum);
+		void    FetchData(int num,...);
+		void    FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,IssmDouble default_value=0);
+		FILE*   SetFilePointerToData(int* pcode,int* pvector_type, int data_enum);
 };
 
Index: /issm/trunk/src/c/objects/Kriging/ExponentialVariogram.cpp
===================================================================
--- /issm/trunk/src/c/objects/Kriging/ExponentialVariogram.cpp	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/ExponentialVariogram.cpp	(revision 12330)
@@ -0,0 +1,92 @@
+/*!\file ExponentialVariogram.c
+ * \brief: implementation of the ExponentialVariogram object
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "../objects.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+
+/*ExponentialVariogram constructors and destructor*/
+/*FUNCTION ExponentialVariogram::ExponentialVariogram(){{{1*/
+ExponentialVariogram::ExponentialVariogram(){
+	this->nugget = 0.2;
+	this->sill   = 1;
+	this->range  = SQRT3;
+	return;
+}
+/*}}}*/
+/*FUNCTION ExponentialVariogram::ExponentialVariogram(Options* options){{{1*/
+ExponentialVariogram::ExponentialVariogram(Options* options){
+
+	/*Defaults*/
+	this->nugget = 0.2;
+	this->sill   = 1;
+	this->range  = SQRT3;
+
+	/*Overwrite from options*/
+	if(options->GetOption("nugget")) options->Get(&this->nugget,"nugget");
+	if(options->GetOption("sill"))   options->Get(&this->sill,"sill");
+	if(options->GetOption("range"))  options->Get(&this->range,"range");
+
+	/*Checks*/
+	if(nugget==sill) _error_("nugget and sill cannot be equal (constant semivariogram not allowed)");
+}
+/*}}}*/
+/*FUNCTION ExponentialVariogram::~ExponentialVariogram(){{{1*/
+ExponentialVariogram::~ExponentialVariogram(){
+	return;
+}
+/*}}}*/
+
+/*Object virtual functions definitions:*/
+/*FUNCTION ExponentialVariogram::Echo {{{1*/
+void ExponentialVariogram::Echo(void){
+	printf("ExponentialVariogram\n");
+	printf("   nugget: %g\n",this->nugget);
+	printf("   sill  : %g\n",this->sill);
+	printf("   range : %g\n",this->range);
+}
+/*}}}*/
+
+/*Variogram function*/
+/*FUNCTION ExponentialVariogram::Covariance{{{1*/
+double ExponentialVariogram::Covariance(double deltax,double deltay){
+	/*The covariance can be deduced from the variogram from the following
+	 * relationship:
+	 *    2 gamma = C(x,x) + C(y,y) -2 C(x,y)
+	 * so
+	 *    C(h) = sill - gamma                                            */
+	double h,a,cova;
+
+	/*Calculate length*/
+	h=sqrt(pow(deltax,2.)+pow(deltay,2.));
+
+	/*return covariance*/
+	a     = 1./3.;
+	cova = (sill-nugget)*exp(-h/(a*range));
+	return cova;
+}
+/*}}}*/
+/*FUNCTION ExponentialVariogram::SemiVariogram{{{1*/
+double ExponentialVariogram::SemiVariogram(double deltax,double deltay){
+	/*http://en.wikipedia.org/wiki/Variogram*/
+	double h,a,gamma;
+
+	/*Calculate length*/
+	h=sqrt(pow(deltax,2.)+pow(deltay,2.));
+
+	/*return semi-variogram*/
+	a     = 1./3.;
+	gamma = (sill-nugget)*(1-exp(-h/(a*range))) + nugget;
+	return gamma;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Kriging/ExponentialVariogram.h
===================================================================
--- /issm/trunk/src/c/objects/Kriging/ExponentialVariogram.h	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/ExponentialVariogram.h	(revision 12330)
@@ -0,0 +1,35 @@
+/*! \file ExponentialVariogram.h 
+ *  \brief: header file for triavertexinput object
+ */
+
+#ifndef _EXPONENTIALVARIOGRAM_H_
+#define _EXPONENTIALVARIOGRAM_H_
+
+/*Headers:*/
+#include "./Variogram.h"
+
+class ExponentialVariogram: public Variogram{
+
+	public:
+		double nugget; //The height of the jump of the semivariogram at the discontinuity at the origin
+		double sill;   //Limit of the variogram tending to infinity lag distances
+		double range;  //The distance in which the difference of the variogram from the sill becomes negligible
+
+		/*ExponentialVariogram constructors, destructors*/
+		ExponentialVariogram();
+		ExponentialVariogram(Options* options);
+		~ExponentialVariogram();
+
+		/*Object virtual functions definitions*/
+		void  Echo();
+		void  DeepEcho(){_error_("Not implemented yet");};
+		int   Id(){_error_("Not implemented yet");}; 
+		int   MyRank(){_error_("Not implemented yet");};
+		int   ObjectEnum(){_error_("Not implemented yet");};
+		Object* copy(){_error_("Not implemented yet");};
+
+		/*Variogram functions*/
+		double SemiVariogram(double deltax,double deltay);
+		double Covariance(double deltax,double deltay);
+};
+#endif  /* _EXPONENTIALVARIOGRAM_H */
Index: /issm/trunk/src/c/objects/Kriging/GaussianVariogram.cpp
===================================================================
--- /issm/trunk/src/c/objects/Kriging/GaussianVariogram.cpp	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/GaussianVariogram.cpp	(revision 12330)
@@ -0,0 +1,98 @@
+/*!\file GaussianVariogram.c
+ * \brief: implementation of the GaussianVariogram object
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "../objects.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+
+/*GaussianVariogram constructors and destructor*/
+/*FUNCTION GaussianVariogram::GaussianVariogram(){{{1*/
+GaussianVariogram::GaussianVariogram(){
+	this->nugget = 0.2;
+	this->sill   = 1;
+	this->range  = SQRT3;
+	return;
+}
+/*}}}*/
+/*FUNCTION GaussianVariogram::GaussianVariogram(Options* options){{{1*/
+GaussianVariogram::GaussianVariogram(Options* options){
+
+	/*Defaults*/
+	this->nugget = 0.2;
+	this->sill   = 1;
+	this->range  = SQRT3;
+
+	/*Overwrite from options*/
+	if(options->GetOption("nugget")) options->Get(&this->nugget,"nugget");
+	if(options->GetOption("sill"))   options->Get(&this->sill,"sill");
+	if(options->GetOption("range"))  options->Get(&this->range,"range");
+
+	/*Checks*/
+	if(nugget==sill) _error_("nugget and sill cannot be equal (constant semivariogram not allowed)");
+}
+/*}}}*/
+/*FUNCTION GaussianVariogram::~GaussianVariogram(){{{1*/
+GaussianVariogram::~GaussianVariogram(){
+	return;
+}
+/*}}}*/
+
+/*Object virtual functions definitions:*/
+/*FUNCTION GaussianVariogram::Echo {{{1*/
+void GaussianVariogram::Echo(void){
+	printf("GaussianVariogram\n");
+	printf("   nugget: %g\n",this->nugget);
+	printf("   sill  : %g\n",this->sill);
+	printf("   range : %g\n",this->range);
+}
+/*}}}*/
+
+/*Variogram function*/
+/*FUNCTION GaussianVariogram::Covariance{{{1*/
+double GaussianVariogram::Covariance(double deltax,double deltay){
+	/*The covariance can be deduced from the variogram from the following
+	 * relationship:
+	 *    2 gamma = C(x,x) + C(y,y) -2 C(x,y)
+	 * so
+	 *    C(h) = sill - gamma                                            */
+	double h2,a,cova;
+
+	/*Calculate length square*/
+	h2=pow(deltax,2.)+pow(deltay,2.);
+
+	/*return covariance*/
+	a     = 1./3.;
+	cova = (sill-nugget)*exp(-h2/(a*range*range));
+
+	if(h2<0.0000001) cova = sill;
+
+	return cova;
+}
+/*}}}*/
+/*FUNCTION GaussianVariogram::SemiVariogram{{{1*/
+double GaussianVariogram::SemiVariogram(double deltax,double deltay){
+	/*http://en.wikipedia.org/wiki/Variogram*/
+	double h2,a,gamma;
+
+	/*Calculate length square*/
+	h2=pow(deltax,2.)+pow(deltay,2.);
+
+	/*return semi-variogram*/
+	a     = 1./3.;
+	gamma = (sill-nugget)*(1.-exp(-h2/(a*range*range))) + nugget;
+
+	//if(h2>1000*1000) printf("gamma = %g h= %g\n",gamma,sqrt(h2));
+	printf("h = %g gamma = %g\n",sqrt(h2),gamma);
+	return gamma;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Kriging/GaussianVariogram.h
===================================================================
--- /issm/trunk/src/c/objects/Kriging/GaussianVariogram.h	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/GaussianVariogram.h	(revision 12330)
@@ -0,0 +1,35 @@
+/*! \file GaussianVariogram.h 
+ *  \brief: header file for triavertexinput object
+ */
+
+#ifndef _GAUSSIANVARIOGRAM_H_
+#define _GAUSSIANVARIOGRAM_H_
+
+/*Headers:*/
+#include "./Variogram.h"
+
+class GaussianVariogram: public Variogram{
+
+	public:
+		double nugget; //The height of the jump of the semivariogram at the discontinuity at the origin
+		double sill;   //Limit of the variogram tending to infinity lag distances
+		double range;  //The distance in which the difference of the variogram from the sill becomes negligible
+
+		/*GaussianVariogram constructors, destructors*/
+		GaussianVariogram();
+		GaussianVariogram(Options* options);
+		~GaussianVariogram();
+
+		/*Object virtual functions definitions*/
+		void  Echo();
+		void  DeepEcho(){_error_("Not implemented yet");};
+		int   Id(){_error_("Not implemented yet");}; 
+		int   MyRank(){_error_("Not implemented yet");};
+		int   ObjectEnum(){_error_("Not implemented yet");};
+		Object* copy(){_error_("Not implemented yet");};
+
+		/*Variogram functions*/
+		double SemiVariogram(double deltax,double deltay);
+		double Covariance(double deltax,double deltay);
+};
+#endif  /* _GAUSSIANVARIOGRAM_H */
Index: /issm/trunk/src/c/objects/Kriging/Observation.cpp
===================================================================
--- /issm/trunk/src/c/objects/Kriging/Observation.cpp	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/Observation.cpp	(revision 12330)
@@ -0,0 +1,57 @@
+/*!\file Observation.c
+ * \brief: implementation of the Observation object
+ */
+
+#include <stdlib.h>
+#include "../objects.h"
+
+/*Observation constructors and destructor*/
+/*FUNCTION Observation::Observation(){{{1*/
+Observation::Observation(){
+	return;
+}
+/*}}}*/
+/*FUNCTION Observation::Observation(double x,double y,int xi,int yi,int index,double value){{{1*/
+Observation::Observation(double x_in,double y_in,int xi_in,int yi_in,int index_in,double value_in){
+
+	this->x      = x_in;
+	this->y      = y_in;
+	this->xi     = xi_in;
+	this->yi     = yi_in;
+	this->index  = index_in;
+	this->value  = value_in;
+	this->weight = 1.;
+
+}
+/*}}}*/
+/*FUNCTION Observation::~Observation(){{{1*/
+Observation::~Observation(){
+	return;
+}
+/*}}}*/
+
+/*Object virtual functions definitions:*/
+/*FUNCTION Observation::Echo {{{1*/
+void Observation::Echo(void){
+
+	int  bit;
+
+	printf("Observation\n");
+	printf("   index : %i\n",this->index);
+	printf("   x     : %g\n",this->x);
+	printf("   y     : %g\n",this->y);
+	printf("   xi    : "); printbinary(this->xi); printf("\n");
+	printf("   yi    : "); printbinary(this->yi); printf("\n");
+	printf("   weight: %g\n",this->weight);
+	printf("   value : %g\n",this->value);
+}
+/*}}}*/
+
+/*Observations functions*/
+/*FUNCTION Observation::WriteXYObs(double* px,double* py,double* pobs){{{1*/
+void Observation::WriteXYObs(double* px,double* py,double* pobs){
+	*px   = this->x;
+	*py   = this->y;
+	*pobs = this->value;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Kriging/Observation.h
===================================================================
--- /issm/trunk/src/c/objects/Kriging/Observation.h	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/Observation.h	(revision 12330)
@@ -0,0 +1,35 @@
+/*! \file Observation.h 
+ *  \brief: header file for Observation object
+ */
+
+#ifndef _OBSERVATION_H_
+#define _OBSERVATION_H_
+
+#include "../Object.h"
+
+class Observation: public Object{
+
+	public:
+		double x,y;
+		int    xi,yi;
+		int    index;
+		double weight;
+		double value;
+
+		/*Observation constructors, destructors*/
+		Observation();
+		Observation(double x_in,double y_in,int xi_in,int yi_in,int index_in,double value_in);
+		~Observation();
+
+		/*Object virtual functions definitions*/
+		void    Echo();
+		void    DeepEcho()  {_error_("Not implemented yet"); };
+		int     Id()        {_error_("Not implemented yet"); };
+		int     MyRank()    {_error_("Not implemented yet"); };
+		int     ObjectEnum(){_error_("Not implemented yet"); };
+		Object *copy()      {_error_("Not implemented yet"); };
+
+		/*Management*/
+		void WriteXYObs(double* px,double* py,double* pobs);
+};
+#endif  /* _OBSERVATION_*/
Index: /issm/trunk/src/c/objects/Kriging/PowerVariogram.cpp
===================================================================
--- /issm/trunk/src/c/objects/Kriging/PowerVariogram.cpp	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/PowerVariogram.cpp	(revision 12330)
@@ -0,0 +1,94 @@
+/*!\file PowerVariogram.c
+ * \brief: implementation of the PowerVariogram object
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "../objects.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+
+/*PowerVariogram constructors and destructor*/
+/*FUNCTION PowerVariogram::PowerVariogram(){{{1*/
+PowerVariogram::PowerVariogram(){
+	this->nugget = 0.2;
+	this->slope  = 1.;
+	this->power  = 1.;
+	return;
+}
+/*}}}*/
+/*FUNCTION PowerVariogram::PowerVariogram(Options* options){{{1*/
+PowerVariogram::PowerVariogram(Options* options){
+
+	/*Defaults*/
+	this->nugget = 0.2;
+	this->slope  = 1.;
+	this->power  = 1.;
+
+	/*Overwrite from options*/
+	if(options->GetOption("nugget")) options->Get(&this->nugget,"nugget");
+	if(options->GetOption("slope"))  options->Get(&this->slope,"slope");
+	if(options->GetOption("power"))  options->Get(&this->power,"power");
+
+	/*Checks*/
+	if(power<=0 || power>=2) _error_("power must be betwwen 0 and 2 (0 < power < 2)");
+	if(slope<=0) _error_("slope must be positive");
+}
+/*}}}*/
+/*FUNCTION PowerVariogram::~PowerVariogram(){{{1*/
+PowerVariogram::~PowerVariogram(){
+	return;
+}
+/*}}}*/
+
+/*Object virtual functions definitions:*/
+/*FUNCTION PowerVariogram::Echo {{{1*/
+void PowerVariogram::Echo(void){
+	printf("PowerVariogram\n");
+	printf("   nugget: %g\n",this->nugget);
+	printf("   slope : %g\n",this->slope);
+	printf("   power : %g\n",this->power);
+}
+/*}}}*/
+
+/*Variogram function*/
+/*FUNCTION PowerVariogram::Covariance{{{1*/
+double PowerVariogram::Covariance(double deltax,double deltay){
+	/*The covariance can be deduced from the variogram from the following
+	 * relationship:
+	 *    2 gamma = C(x,x) + C(y,y) -2 C(x,y)
+	 * so
+	 *    C(h) = sill - gamma                                            */
+	double h,cova;
+
+	/*Calculate length square*/
+	h=sqrt(pow(deltax,2.)+pow(deltay,2.));
+
+	/*return covariance*/
+	cova = 9999. - this->slope*pow(h,this->power);
+
+	return cova;
+}
+/*}}}*/
+/*FUNCTION PowerVariogram::SemiVariogram{{{1*/
+double PowerVariogram::SemiVariogram(double deltax,double deltay){
+	/*http://en.wikipedia.org/wiki/Variogram*/
+	double h,gamma;
+
+	/*Calculate length square*/
+	h=sqrt(pow(deltax,2.)+pow(deltay,2.));
+
+	/*return semi-variogram*/
+	gamma = this->nugget + this->slope*pow(h,this->power);
+
+	//if(h>1000) printf("gamma = %g h=%g\n",gamma,h);
+	return gamma;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Kriging/PowerVariogram.h
===================================================================
--- /issm/trunk/src/c/objects/Kriging/PowerVariogram.h	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/PowerVariogram.h	(revision 12330)
@@ -0,0 +1,35 @@
+/*! \file PowerVariogram.h 
+ *  \brief: header file for triavertexinput object
+ */
+
+#ifndef _POWERVARIOGRAM_H_
+#define _POWERVARIOGRAM_H_
+
+/*Headers:*/
+#include "./Variogram.h"
+
+class PowerVariogram: public Variogram{
+
+	public:
+		double nugget; //The height of the jump of the semivariogram at the discontinuity at the origin
+		double slope;  
+		double power; 
+
+		/*PowerVariogram constructors, destructors*/
+		PowerVariogram();
+		PowerVariogram(Options* options);
+		~PowerVariogram();
+
+		/*Object virtual functions definitions*/
+		void  Echo();
+		void  DeepEcho(){_error_("Not implemented yet");};
+		int   Id(){_error_("Not implemented yet");}; 
+		int   MyRank(){_error_("Not implemented yet");};
+		int   ObjectEnum(){_error_("Not implemented yet");};
+		Object* copy(){_error_("Not implemented yet");};
+
+		/*Variogram functions*/
+		double SemiVariogram(double deltax,double deltay);
+		double Covariance(double deltax,double deltay);
+};
+#endif  /* _POWERVARIOGRAM_H */
Index: /issm/trunk/src/c/objects/Kriging/Quadtree.cpp
===================================================================
--- /issm/trunk/src/c/objects/Kriging/Quadtree.cpp	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/Quadtree.cpp	(revision 12330)
@@ -0,0 +1,606 @@
+#include "../objects.h"
+/*DOCUMENTATION What is a Quadtree? {{{1
+ * A Quadtree is a very simple way to group vertices according
+ * to their locations. A square that holds all the points of the mesh
+ * (or the geometry) is divided into 4 boxes. As soon as one box
+ * hold more than 4 vertices, it is divided into 4 new boxes, etc...
+ * There cannot be more than MAXDEEP (=30) subdivision.
+ * This process is like a Dichotomy in dimension 2
+ *
+ *  + - -  -    - -    -    - - + -   - + - + - + - -     - - +
+ *  |                           |       |   | X |             |
+ *                                      + - + - +
+ *  |                           |       |   |   |             |
+ *                              + -   - + - + - +             +
+ *  |                           |       |       |             |
+ *                         
+ *  |                           |       |       |             |
+ *  + - -  -    - -    -    - - + -   - + -   - + - -     - - +
+ *  |                           |               |             |
+ *                         
+ *  |                           |               |             |
+ *                         
+ *  |                           |               |             |
+ *  |                           |               |             |
+ *  + - -  -    - -    -    - - + -   -   -   - + - -     - - +
+ *  |                           |                             |
+ *                         
+ *  |                           |                             |
+ *                         
+ *  |                           |                             |
+ *                         
+ *  |                           |                             |
+ *  |                           |                             |
+ *  |                           |                             |
+ *  |                           |                             |
+ *  |                           |                             |
+ *  + - -  -    - -    -    - - + -   -   -   -   - -     - - +
+ *
+ * The coordinate system used in a quadtree are integers to avoid
+ * round-off errors. The vertex in the lower left box has the coordinates
+ * (0 0) 
+ * The upper right vertex has the follwing coordinates:
+ * 2^30 -1           2^30 -1        in decimal
+ * 0 1 1 1 .... 1    0 1 1 1 .... 1 in binary
+ *  \--   29  --/     \--   29  --/
+ * Using binaries is therefore very easy to locate a vertex in a box:
+ * we just need to look at the bits from the left to the right (See ::Add)
+ }}}1*/
+/*MACROS {{{1*/
+/* 
+ * 
+ *    J    j
+ *    ^    ^
+ *    |    | +--------+--------+
+ *    |    | |        |        |
+ * 1X |    | |   2    |   3    |
+ *    |    | |        |        |
+ *    |    | +--------+--------+
+ *    |    | |        |        |
+ * 0X |    | |   0    |   1    |
+ *    |    | |        |        |
+ *    |    | +--------+--------+
+ *    |    +-----------------------> i
+ *    |         
+ *    |----------------------------> I
+ *              X0        X1  
+ *
+ * box 0 -> I=0 J=0 IJ=00  = 0
+ * box 1 -> I=1 J=0 IJ=01  = 1
+ * box 2 -> I=0 J=1 IJ=10  = 2
+ * box 3 -> I=1 J=1 IJ=11  = 3
+ */
+//IJ(i,j,l) returns the box number of i and j with respect to l
+//if !j&l and !i&l -> 0 (box zero: lower left )
+//if !j&l and  i&l -> 1 (box one:  lower right)
+//if  j&l and !i&l -> 2 (box two:  upper left )
+//if  j&l and  i&l -> 3 (box three:upper right)
+#define IJ(i,j,l)  ((j&l) ? ((i&l) ? 3:2 ) :((i&l) ? 1:0 ))
+/*}}}*/
+
+	/*Constructors/Destructors*/
+/*FUNCTION Quadtree::Quadtree(){{{1*/
+Quadtree::Quadtree(){
+	_error_("Constructor not supported");
+
+}
+/*}}}1*/
+/*FUNCTION Quadtree::Quadtree(double xmin,double xmax,double ymin,double ymax,int maxdepth){{{1*/
+Quadtree::Quadtree(double xmin,double xmax,double ymin,double ymax,int maxdepth){
+
+	/*Intermediaries*/
+	double length;
+
+	/*Initialize fields*/
+	this->MaxDepth=maxdepth;
+	this->NbQuadtreeBox=0;
+	this->NbObs=0;
+
+	/*Create container*/
+	this->boxcontainer=new DataSet();
+
+	/*Create Root, pointer toward the main box*/
+	length=max(xmax-xmin,ymax-ymin);
+	this->root=NewQuadtreeBox(xmin+length/2,ymin+length/2,length);
+}
+/*}}}1*/
+	/*FUNCTION Quadtree::~Quadtree(){{{1*/
+	Quadtree::~Quadtree(){
+
+		delete boxcontainer;
+		root=NULL;
+
+	}
+	/*}}}1*/
+
+	/*Methods*/
+/*FUNCTION Quadtree::Add{{{1*/
+void  Quadtree::Add(Observation* observation){
+
+	/*Intermediaries*/
+	int          xi,yi,ij,level,levelbin;
+	QuadtreeBox **pbox    = NULL; // pointer toward current box b
+	QuadtreeBox **pmaster = NULL; // pointer toward master of b
+	QuadtreeBox  *box     = NULL; // current box b
+	QuadtreeBox  *slave   = NULL; // suslaveox of b (if necessary)
+	Observation  *obs[4];
+
+	/*Get integer coodinates*/
+	xi = observation->xi;
+	yi = observation->yi;
+
+	/*Initialize levels*/
+	level    = 0;
+	levelbin = (1L<<this->MaxDepth);// = 2^30
+
+	/*Get inital box (the largest)*/
+	pmaster = &root;
+	pbox    = &root;
+
+	/*Find the smallest box where the observation is located*/
+	while((box=*pbox) && (box->nbitems<0)){ 
+
+		/*Go down one level (levelbin = 00100 -> 00010)*/
+		levelbin>>=1; level+=1; _assert_(level<this->MaxDepth);
+
+		/*Get next box according to the bit value (levelbin)*/
+		pmaster = pbox;
+		pbox    = &box->box[IJ(xi,yi,levelbin)];
+	}
+	_assert_(levelbin>0);
+
+	/*Now, try to add the vertex, if the box is full (nbitems=4), we have to divide it in 4 new boxes*/
+	while((box=*pbox) && (box->nbitems==4)){
+
+		/*Copy the 4 observation in the current Quadtreebox*/
+		obs[0] = box->obs[0];
+		obs[1] = box->obs[1];
+		obs[2] = box->obs[2];
+		obs[3] = box->obs[3];
+
+		/*set nbitems as -1 (now holding boxes instead of observations)*/
+		box->nbitems = -1;
+		box->box[0]  = NULL;
+		box->box[1]  = NULL;
+		box->box[2]  = NULL;
+		box->box[3]  = NULL;
+
+		/*Go down one level (levelbin = 00010 -> 00001)*/
+		levelbin>>=1; level+=1; _assert_(level<this->MaxDepth);
+
+		/*Put the four observations in the new boxes*/
+		for (int k=0;k<4;k++){
+
+			/*Get box for observation number k*/
+			ij    = IJ(obs[k]->xi,obs[k]->yi,levelbin);
+			slave = box->box[ij];
+			if(!slave){
+				box->box[ij] = NewQuadtreeBox(box,ij);
+				slave        = box->box[ij];
+			}
+			slave->obs[slave->nbitems++] = obs[k];
+		}
+
+		/*Get the suslaveox where the current observation is located*/
+		ij      = IJ(xi,yi,levelbin);
+		pmaster = pbox;
+		pbox    = &box->box[ij];
+	}
+
+	/*alloc the QuadtreeBox if necessary and add current observation*/
+	box = *pbox;
+	if(!box){
+		ij  = IJ(xi,yi,levelbin);
+		box = *pbox = NewQuadtreeBox(*pmaster,ij);
+	}
+	box->obs[box->nbitems++]=observation;
+	NbObs++;
+
+}/*}}}*/
+/*FUNCTION Quadtree::AddAndAverage{{{1*/
+void Quadtree::AddAndAverage(double x,double y,double value){
+
+	QuadtreeBox **pbox = NULL;
+	QuadtreeBox  *box  = NULL;
+	int           xi,yi;
+	int           level,levelbin;
+	int           index;
+	double        length,length2;
+
+	/*Get integer coodinates*/
+	this->IntergerCoordinates(&xi,&yi,x,y);
+
+	/*Initialize levels*/
+	level    = 0;
+	levelbin = (1L<<this->MaxDepth);// = 2^30
+
+	/*Get inital box (the largest)*/
+	pbox=&root;
+
+	/*Find the smallest box where this point is located*/
+	while((box=*pbox) && (box->nbitems<0)){ 
+
+		levelbin>>=1; level+=1; 
+
+		pbox = &box->box[IJ(xi,yi,levelbin)];
+	}
+
+	/*Add obervation in this box (should be full)*/
+	if(box && box->nbitems==4){
+		index  = 0;
+		length = pow(box->obs[0]->x - x,2.) + pow(box->obs[0]->y - y,2.);
+		for(int i=1;i<4;i++){
+			length2 = pow(box->obs[i]->x - x,2.) + pow(box->obs[i]->y - y,2.);
+			if(length2<length){
+				index  = i;
+				length = length2;
+			}
+		}
+
+		/*We found the closest observation, now average observation (do not change xi and yi to avoid round off errors*/
+		box->obs[index]->x = (box->obs[index]->weight*box->obs[index]->x + x)/(box->obs[index]->weight+1);
+		box->obs[index]->y = (box->obs[index]->weight*box->obs[index]->y + y)/(box->obs[index]->weight+1);
+		box->obs[index]->xi= int((box->obs[index]->weight*double(box->obs[index]->xi) + double(xi))/(box->obs[index]->weight+1));
+		box->obs[index]->yi= int((box->obs[index]->weight*double(box->obs[index]->yi) + double(yi))/(box->obs[index]->weight+1));
+		box->obs[index]->value   = (box->obs[index]->weight*box->obs[index]->value + value)/(box->obs[index]->weight+1);
+		box->obs[index]->weight += 1;
+	}
+	else{
+		_error_("Box is not full");
+	}
+}/*}}}*/
+/*FUNCTION Quadtree::ClosestObs{{{1*/
+void Quadtree::ClosestObs(int *pindex,double x,double y){
+
+	QuadtreeBox **pbox = NULL;
+	QuadtreeBox  *box  = NULL;
+	int           xi,yi;
+	int           level,levelbin;
+	int           index = -1;
+	double        length,length2;
+
+	/*Get integer coodinates*/
+	this->IntergerCoordinates(&xi,&yi,x,y);
+
+	/*Initialize levels*/
+	level    = 0;
+	levelbin = (1L<<this->MaxDepth);// = 2^30
+
+	/*Get inital box (the largest)*/
+	pbox=&root;
+
+	/*Find the smallest box where this point is located*/
+	while((box=*pbox) && (box->nbitems<0)){ 
+
+		levelbin>>=1; level+=1; 
+
+		pbox = &box->box[IJ(xi,yi,levelbin)];
+	}
+
+	/*Add obervation in this box (should be full)*/
+	if(box && box->nbitems>0){
+		index  = box->obs[0]->index;
+		length = pow(box->obs[0]->x - x,2.) + pow(box->obs[0]->y - y,2.);
+		for(int i=1;i<box->nbitems;i++){
+			length2 = pow(box->obs[i]->x - x,2.) + pow(box->obs[i]->y - y,2.);
+			if(length2<length){
+				index  = box->obs[i]->index;
+				length = length2;
+			}
+		}
+	}
+
+	*pindex=index;
+}/*}}}*/
+/*FUNCTION Quadtree::Echo{{{1*/
+void  Quadtree::Echo(void){
+
+	printf("Quadtree:\n");
+	printf("   MaxDepth      = %i\n",this->MaxDepth);
+	printf("   NbQuadtreeBox = %i\n",this->NbQuadtreeBox);
+	printf("   NbObs         = %i\n",this->NbObs);
+	printf("   root          = %p\n",this->root);
+
+}/*}}}*/
+/*FUNCTION Quadtree::DeepEcho{{{1*/
+void  Quadtree::DeepEcho(void){
+
+	printf("Quadtree:\n");
+	printf("   MaxDepth      = %i\n",this->MaxDepth);
+	printf("   NbQuadtreeBox = %i\n",this->NbQuadtreeBox);
+	printf("   NbObs         = %i\n",this->NbObs);
+	printf("   root          = %p\n",this->root);
+	boxcontainer->Echo();
+
+}/*}}}*/
+/*FUNCTION Quadtree::IntergerCoordinates{{{1*/
+void  Quadtree::IntergerCoordinates(int *xi,int *yi,double x,double y){
+
+	/*Intermediaries*/
+	double coefficient;
+	double xmin,ymin;
+
+	/*Checks in debugging mode*/
+	_assert_(xi && yi);
+	_assert_(this->root);
+
+	/*coeffIcoor is the coefficient used for integer coordinates:
+	 *                (x-xmin)
+	 * xi = (2^30 -1) --------- 
+	 *                 length
+	 * coefficient = (2^30 -1)/length
+	 */
+	coefficient = double((1L<<this->MaxDepth)-1)/(this->root->length);
+	xmin        = this->root->xcenter - this->root->length/2;
+	ymin        = this->root->ycenter - this->root->length/2;
+
+	*xi=int(coefficient*(x - xmin));
+	*yi=int(coefficient*(y - ymin));
+}/*}}}*/
+/*FUNCTION Quadtree::NewQuadtreeBox(double xcenter,double ycenter,double length){{{1*/
+Quadtree::QuadtreeBox* Quadtree::NewQuadtreeBox(double xcenter,double ycenter,double length){
+
+	/*Output*/
+	QuadtreeBox* newbox=NULL;
+
+	/*Create and initialize a new box*/
+	newbox=new QuadtreeBox();
+	newbox->nbitems=0;
+	newbox->xcenter=xcenter;
+	newbox->ycenter=ycenter;
+	newbox->length=length;
+	newbox->box[0]=NULL;
+	newbox->box[1]=NULL;
+	newbox->box[2]=NULL;
+	newbox->box[3]=NULL;
+
+	/*Add to container*/
+	this->boxcontainer->AddObject(newbox);
+	NbQuadtreeBox++;
+
+	/*currentbox now points toward next quadtree box*/
+	return newbox;
+}/*}}}*/
+/*FUNCTION Quadtree::NewQuadtreeBox(QuadtreeBox* master,int index) {{{1*/
+Quadtree::QuadtreeBox* Quadtree::NewQuadtreeBox(QuadtreeBox* master,int index){
+
+	/*Output*/
+	QuadtreeBox* newbox=NULL;
+
+	/*Checks in debugging mode*/
+	_assert_(master);
+
+	/*Create and initialize a new box*/
+	newbox=new QuadtreeBox();
+	newbox->nbitems=0;
+	newbox->box[0]=NULL;
+	newbox->box[1]=NULL;
+	newbox->box[2]=NULL;
+	newbox->box[3]=NULL;
+	switch(index){
+		case 0:
+			newbox->xcenter=master->xcenter - master->length/4;
+			newbox->ycenter=master->ycenter - master->length/4;
+			break;
+		case 1:
+			newbox->xcenter=master->xcenter + master->length/4;
+			newbox->ycenter=master->ycenter - master->length/4;
+			break;
+		case 2:
+			newbox->xcenter=master->xcenter - master->length/4;
+			newbox->ycenter=master->ycenter + master->length/4;
+			break;
+		case 3:
+			newbox->xcenter=master->xcenter + master->length/4;
+			newbox->ycenter=master->ycenter + master->length/4;
+			break;
+		default:
+			_error_("Case %i not supported",index);
+	}
+	newbox->length=master->length/2;
+
+	/*Add to container*/
+	this->boxcontainer->AddObject(newbox);
+	NbQuadtreeBox++;
+
+	/*currentbox now points toward next quadtree box*/
+	return newbox;
+}/*}}}*/
+/*FUNCTION Quadtree::QuadtreeDepth{{{1*/
+void Quadtree::QuadtreeDepth(int* A,int xi,int yi){
+
+	QuadtreeBox **pbox = NULL;
+	QuadtreeBox  *box  = NULL;
+	int           level,levelbin;
+
+	/*Initialize levels*/
+	level    = 0;
+	levelbin = (1L<<this->MaxDepth);// = 2^30
+
+	/*Get inital box (the largest)*/
+	pbox=&root;
+
+	/*Find the smallest box where this point is located*/
+	while((box=*pbox) && (box->nbitems<0)){ 
+
+		levelbin>>=1; level+=1; _assert_(level<this->MaxDepth);
+
+		pbox = &box->box[IJ(xi,yi,levelbin)];
+	}
+	if(box && box->nbitems>0){
+		/*This box is not empty, add one level*/
+		level+=1;
+	}
+
+	*A=level;
+}/*}}}*/
+/*FUNCTION Quadtree::QuadtreeDepth2{{{1*/
+void Quadtree::QuadtreeDepth2(int* A,int xi,int yi){
+
+	QuadtreeBox **pbox = NULL;
+	QuadtreeBox  *box  = NULL;
+	int           level,levelbin;
+
+	/*Initialize levels*/
+	level    = 0;
+	levelbin = (1L<<this->MaxDepth);// = 2^30
+
+	/*Get inital box (the largest)*/
+	pbox=&root;
+
+	/*Find the smallest box where this point is located*/
+	while((box=*pbox) && (box->nbitems<0)){ 
+
+		levelbin>>=1; level+=1; 
+
+		pbox = &box->box[IJ(xi,yi,levelbin)];
+	}
+	if(box && box->nbitems>0){
+		/*This box is not empty, add one level*/
+		level+=1;
+	}
+
+	/*If we were to add the vertex, get level*/
+	if(box && box->nbitems==4){
+		int ij;
+		bool flag=true;
+		while(flag){
+
+			levelbin>>=1; level+=1;
+			if(level>this->MaxDepth){
+				level+=1;
+				break;
+			}
+
+			/*loop over the four observations*/
+			ij=IJ(box->obs[0]->xi,box->obs[0]->yi,levelbin);
+			for (int k=1;k<4;k++){
+				if(IJ(box->obs[k]->xi,box->obs[k]->yi,levelbin) != ij){
+					flag = false;
+				}
+			}
+			if(IJ(xi,yi,levelbin)!=ij){
+				flag = false;
+			}
+		}
+	}
+
+	*A=level;
+}/*}}}*/
+/*FUNCTION Quadtree::RangeSearch{{{1*/
+void Quadtree::RangeSearch(int **pindices,int *pnobs,double x,double y,double range){
+
+	/*Intermediaries*/
+	int  nobs;
+	int *indices = NULL;
+
+	/*Allocate indices (maximum by default*/
+	if(this->NbObs) indices = (int*)xmalloc(this->NbObs*sizeof(int));
+	nobs = 0;
+
+	if(this->root) this->root->RangeSearch(indices,&nobs,x,y,range);
+
+	/*Clean-up and return*/
+	*pnobs=nobs;
+	*pindices=indices;
+
+}/*}}}*/
+
+/*QuadtreeBox methos*/
+/*FUNCTION QuadtreeBox::Echo{{{1*/
+void  Quadtree::QuadtreeBox::Echo(void){
+
+	printf("QuadtreeBox:\n");
+	printf("   nbitems = %i\n",this->nbitems);
+	printf("   xcenter = %g\n",this->xcenter);
+	printf("   ycenter = %g\n",this->ycenter);
+	printf("   length  = %g\n",this->length);
+
+}/*}}}*/
+/*FUNCTION QuadtreeBox::IsWithinRange{{{1*/
+int Quadtree::QuadtreeBox::IsWithinRange(double x,double y,double range){
+
+	/*Return 0 if the 2 boxes do not overlap*/
+	if(this->xcenter+this->length/2 < x-range) return 0;
+	if(this->xcenter-this->length/2 > x+range) return 0;
+	if(this->ycenter+this->length/2 < y-range) return 0;
+	if(this->ycenter-this->length/2 > y+range) return 0;
+
+	/*Return 2 if the this box is included in the range*/
+	if(this->xcenter+this->length/2 <= x+range &&
+		this->ycenter+this->length/2 <= y+range &&
+		this->xcenter-this->length/2 >= x-range &&
+		this->ycenter-this->length/2 >= y-range) return 2;
+
+	/*This is a simple overlap*/
+	return 1;
+
+}/*}}}*/
+/*FUNCTION QuadtreeBox::RangeSearch{{{1*/
+void Quadtree::QuadtreeBox::RangeSearch(int* indices,int *pnobs,double x,double y,double range){
+
+	/*Intermediaries*/
+	int i,nobs;
+
+	/*Recover current number of observations*/
+	nobs = *pnobs;
+
+	switch(this->IsWithinRange(x,y,range)){
+		case 0:
+			/*If this box is not within range, return*/
+			break;
+		case 2:
+			/*This box is included in range*/
+			this->WriteObservations(indices,&nobs);
+			break;
+		case 1:
+			/*This box is partly included*/
+			if(this->nbitems>0){
+				/*If this box has only observations, add indices that are within range*/
+				for(i=0;i<this->nbitems;i++){
+					if(fabs(this->obs[i]->x-x) <= range && fabs(this->obs[i]->y-y) <= range){
+						indices[nobs++]=this->obs[i]->index;
+					}
+				}
+			}
+			else{
+				/*This box points toward boxes*/
+				if(this->box[0]) this->box[0]->RangeSearch(indices,&nobs,x,y,range);
+				if(this->box[1]) this->box[1]->RangeSearch(indices,&nobs,x,y,range);
+				if(this->box[2]) this->box[2]->RangeSearch(indices,&nobs,x,y,range);
+				if(this->box[3]) this->box[3]->RangeSearch(indices,&nobs,x,y,range);
+			}
+			break;
+		default:
+			_error_("Case %i not supported",this->IsWithinRange(x,y,range));
+	}
+
+	/*Assign output pointers: */
+	*pnobs=nobs;
+}/*}}}*/
+/*FUNCTION QuadtreeBox::WriteObservations{{{1*/
+void Quadtree::QuadtreeBox::WriteObservations(int* indices,int *pnobs){
+
+	/*Intermediaries*/
+	int i,nobs;
+
+	/*Recover current number of observations*/
+	nobs = *pnobs;
+
+	if(this->nbitems>0){
+		/*If this box has only observations, add all indices*/
+		for(i=0;i<this->nbitems;i++){
+			indices[nobs++]=this->obs[i]->index;
+		}
+	}
+	else{
+		/*This box points toward boxes, */
+		if(this->box[0]) this->box[0]->WriteObservations(indices,&nobs);
+		if(this->box[1]) this->box[1]->WriteObservations(indices,&nobs);
+		if(this->box[2]) this->box[2]->WriteObservations(indices,&nobs);
+		if(this->box[3]) this->box[3]->WriteObservations(indices,&nobs);
+	}
+
+	/*Assign output pointers: */
+	*pnobs=nobs;
+}/*}}}*/
Index: /issm/trunk/src/c/objects/Kriging/Quadtree.h
===================================================================
--- /issm/trunk/src/c/objects/Kriging/Quadtree.h	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/Quadtree.h	(revision 12330)
@@ -0,0 +1,66 @@
+
+#ifndef _QUADTREE_H
+#define _QUADTREE_H
+
+class Observation;
+
+class Quadtree{
+
+	private:
+		/* A quadtree box contains up to 4 points (locations). 4 new quadtree boxes are
+		 * created if a fifth point is added to the same box. A Quadtree box is therefore
+		 * composed of EITHER:
+		 * - up to 4 vertices
+		 * - 4 "sub" quadtree boxes*/
+
+		class QuadtreeBox: public Object{ 
+			public:
+				int    nbitems; // number of current vertices in the box
+				double xcenter; // x position of the center (double)
+				double ycenter; // x position of the center (double)
+				double length;  // width of the box
+				union{
+					QuadtreeBox *box[4];
+					Observation *obs[4];
+				};
+
+				/*Object functions (Needed because the Quadtree uses a Container*/
+				void    Echo();
+				void    DeepEcho()  {_error_("not implemented yet"); };
+				int     Id()        {_error_("not implemented yet"); };
+				int     MyRank()    {_error_("not implemented yet"); };
+				int     ObjectEnum(){_error_("not implemented yet"); };
+				Object *copy()      {_error_("not implemented yet"); };
+
+				/*Methods*/
+				int          IsWithinRange(double  x,double y,double range);
+				void         RangeSearch(int *indices,int *pnobs,double x,double y,double range);
+				void         WriteObservations(int *indices,int *pnobs);
+
+		};
+
+		/*Quadtree private Fields*/
+		DataSet* boxcontainer;
+
+	public:
+		int          MaxDepth;          // maximum number of subdivision
+		QuadtreeBox *root;              // main box
+		long         NbQuadtreeBox;     // total number of boxes
+		long         NbObs;             // number of points
+
+		Quadtree();
+		Quadtree(double xmin,double xmax,double ymin,double ymax,int maxdepth_in);
+		~Quadtree();
+		void         Add(Observation *observation);
+		void         AddAndAverage(double x,double y,double value);
+		void         ClosestObs(int *pindex,double x,double y);
+		void         DeepEcho(void);
+		void         Echo(void);
+		void         IntergerCoordinates(int *xi,int *yi,double x,double y);
+		QuadtreeBox *NewQuadtreeBox(double xcenter,double ycenter,double length);
+		QuadtreeBox *NewQuadtreeBox(QuadtreeBox* master,int index);
+		void         QuadtreeDepth(int *A,int xi,int yi);
+		void         QuadtreeDepth2(int *A,int xi,int yi);
+		void         RangeSearch(int **pindices,int *pnobs,double x,double y,double range);
+};
+#endif //_QUADTREE_H
Index: /issm/trunk/src/c/objects/Kriging/SphericalVariogram.cpp
===================================================================
--- /issm/trunk/src/c/objects/Kriging/SphericalVariogram.cpp	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/SphericalVariogram.cpp	(revision 12330)
@@ -0,0 +1,98 @@
+/*!\file SphericalVariogram.c
+ * \brief: implementation of the SphericalVariogram object
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "../objects.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+
+/*SphericalVariogram constructors and destructor*/
+/*FUNCTION SphericalVariogram::SphericalVariogram(){{{1*/
+SphericalVariogram::SphericalVariogram(){
+	this->nugget = 0.2;
+	this->sill   = 1;
+	this->range  = SQRT3;
+	return;
+}
+/*}}}*/
+/*FUNCTION SphericalVariogram::SphericalVariogram(Options* options){{{1*/
+SphericalVariogram::SphericalVariogram(Options* options){
+
+	/*Defaults*/
+	this->nugget = 0.2;
+	this->sill   = 1;
+	this->range  = SQRT3;
+
+	/*Overwrite from options*/
+	if(options->GetOption("nugget")) options->Get(&this->nugget,"nugget");
+	if(options->GetOption("sill"))   options->Get(&this->sill,"sill");
+	if(options->GetOption("range"))  options->Get(&this->range,"range");
+
+	/*Checks*/
+	if(nugget==sill) _error_("nugget and sill cannot be equal (constant semivariogram not allowed)");
+}
+/*}}}*/
+/*FUNCTION SphericalVariogram::~SphericalVariogram(){{{1*/
+SphericalVariogram::~SphericalVariogram(){
+	return;
+}
+/*}}}*/
+
+/*Object virtual functions definitions:*/
+/*FUNCTION SphericalVariogram::Echo {{{1*/
+void SphericalVariogram::Echo(void){
+	printf("SphericalVariogram\n");
+	printf("   nugget: %g\n",this->nugget);
+	printf("   sill  : %g\n",this->sill);
+	printf("   range : %g\n",this->range);
+}
+/*}}}*/
+
+/*Variogram function*/
+/*FUNCTION SphericalVariogram::Covariance{{{1*/
+double SphericalVariogram::Covariance(double deltax,double deltay){
+	/*The covariance can be deduced from the variogram from the following
+	 * relationship:
+	 *    2 gamma = C(x,x) + C(y,y) -2 C(x,y)
+	 * so
+	 *    C(h) = sill - gamma                                            */
+	double h,cova;
+
+	/*Calculate length square*/
+	h=sqrt(pow(deltax,2.)+pow(deltay,2.));
+
+	/*return covariance*/
+	if(h<=range)
+	 cova = (sill-nugget)*(1 - (3*h)/(2*range) + pow(h,3.)/(2*pow(range,3.)) );
+	else
+	 cova = 0.;
+
+	return cova;
+}
+/*}}}*/
+/*FUNCTION SphericalVariogram::SemiVariogram{{{1*/
+double SphericalVariogram::SemiVariogram(double deltax,double deltay){
+	/*http://en.wikipedia.org/wiki/Variogram*/
+	double h,gamma;
+
+	/*Calculate length square*/
+	h=sqrt(pow(deltax,2.)+pow(deltay,2.));
+
+	/*return semi-variogram*/
+	if(h<=range)
+	 gamma = (sill-nugget)*( (3*h)/(2*range) - pow(h,3.)/(2*pow(range,3.)) ) + nugget;
+	else
+	 gamma = sill;
+
+	return gamma;
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Kriging/SphericalVariogram.h
===================================================================
--- /issm/trunk/src/c/objects/Kriging/SphericalVariogram.h	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/SphericalVariogram.h	(revision 12330)
@@ -0,0 +1,35 @@
+/*! \file SphericalVariogram.h 
+ *  \brief: header file for triavertexinput object
+ */
+
+#ifndef _SPHERICALVARIOGRAM_H_
+#define _SPHERICALVARIOGRAM_H_
+
+/*Headers:*/
+#include "./Variogram.h"
+
+class SphericalVariogram: public Variogram{
+
+	public:
+		double nugget; //The height of the jump of the semivariogram at the discontinuity at the origin
+		double sill;   //Limit of the variogram tending to infinity lag distances
+		double range;  //The distance in which the difference of the variogram from the sill becomes negligible
+
+		/*SphericalVariogram constructors, destructors*/
+		SphericalVariogram();
+		SphericalVariogram(Options* options);
+		~SphericalVariogram();
+
+		/*Object virtual functions definitions*/
+		void  Echo();
+		void  DeepEcho(){_error_("Not implemented yet");};
+		int   Id(){_error_("Not implemented yet");}; 
+		int   MyRank(){_error_("Not implemented yet");};
+		int   ObjectEnum(){_error_("Not implemented yet");};
+		Object* copy(){_error_("Not implemented yet");};
+
+		/*Variogram functions*/
+		double SemiVariogram(double deltax,double deltay);
+		double Covariance(double deltax,double deltay);
+};
+#endif  /* _SPHERICALVARIOGRAM_H */
Index: /issm/trunk/src/c/objects/Kriging/Variogram.h
===================================================================
--- /issm/trunk/src/c/objects/Kriging/Variogram.h	(revision 12330)
+++ /issm/trunk/src/c/objects/Kriging/Variogram.h	(revision 12330)
@@ -0,0 +1,18 @@
+/*!\file:  Variogram.h
+ * \brief abstract class for Variogram object
+ */ 
+
+#ifndef _VARIOGRAM_H_
+#define _VARIOGRAM_H_
+
+#include "../Object.h"
+
+class Variogram: public Object{
+
+	public: 
+		virtual ~Variogram(){};
+		virtual double SemiVariogram(double deltax,double deltay)=0;
+		virtual double Covariance(double deltax,double deltay)=0;
+
+};
+#endif
Index: /issm/trunk/src/c/objects/Loads/Icefront.cpp
===================================================================
--- /issm/trunk/src/c/objects/Loads/Icefront.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Icefront.cpp	(revision 12330)
@@ -163,92 +163,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION Icefront::Marshall {{{1*/
-void  Icefront::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Icefront: */
-	enum_type=IcefrontEnum;
-
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*marshall Icefront data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	/*Marshall hooks: */
-	hnodes->Marshall(&marshalled_dataset);
-	helement->Marshall(&marshalled_dataset);
-	hmatpar->Marshall(&marshalled_dataset);
-
-	/*Marshall inputs: */
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	/*parameters: don't do anything about it. parameters are marshalled somewhere else!*/
-
-	xfree((void**)&marshalled_inputs);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION Icefront::MarshallSize {{{1*/
-int   Icefront::MarshallSize(){
-	
-	return sizeof(id)
-		+sizeof(analysis_type)
-		+hnodes->MarshallSize()
-		+helement->MarshallSize()
-		+hmatpar->MarshallSize()
-		+inputs->MarshallSize()
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Icefront::Demarshall {{{1*/
-void  Icefront::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	/*demarshall hooks: */
-	hnodes=new Hook(); hnodes->Demarshall(&marshalled_dataset);
-	helement=new Hook(); helement->Demarshall(&marshalled_dataset);
-	hmatpar=new Hook(); hmatpar->Demarshall(&marshalled_dataset);
-	
-	/*pointers are garbabe, until configuration is carried out: */
-	nodes=NULL;
-	element=NULL;
-	matpar=NULL;
-
-	/*demarshall inputs: */
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*parameters: may not exist even yet, so let Configure handle it: */
-	this->parameters=NULL;
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION Icefront::ObjectEnum{{{1*/
 int Icefront::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Loads/Icefront.h
===================================================================
--- /issm/trunk/src/c/objects/Loads/Icefront.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Icefront.h	(revision 12330)
@@ -49,9 +49,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Loads/Numericalflux.cpp
===================================================================
--- /issm/trunk/src/c/objects/Loads/Numericalflux.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Numericalflux.cpp	(revision 12330)
@@ -189,87 +189,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION Numericalflux::Marshall {{{1*/
-void  Numericalflux::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Numericalflux: */
-	enum_type=NumericalfluxEnum;
-
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*marshall Numericalflux data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	/*Marshall hooks: */
-	hnodes->Marshall(&marshalled_dataset);
-	helement->Marshall(&marshalled_dataset);
-
-	/*Marshall inputs: */
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	/*parameters: don't do anything about it. parameters are marshalled somewhere else!*/
-
-	xfree((void**)&marshalled_inputs);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Numericalflux::MarshallSize{{{1*/
-int   Numericalflux::MarshallSize(){
-
-	return sizeof(id)
-		+sizeof(analysis_type)
-		+hnodes->MarshallSize()
-		+helement->MarshallSize()
-		+inputs->MarshallSize()
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Numericalflux::Demarshall {{{1*/
-void  Numericalflux::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	/*demarshall hooks: */
-	hnodes=new Hook(); hnodes->Demarshall(&marshalled_dataset);
-	helement=new Hook(); helement->Demarshall(&marshalled_dataset);
-	
-	/*demarshall inputs: */
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*parameters: may not exist even yet, so let Configure handle it: */
-	this->parameters=NULL;
-	this->element=NULL;
-	this->nodes=NULL;
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION Numericalflux::ObjectEnum{{{1*/
 int Numericalflux::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Loads/Numericalflux.h
===================================================================
--- /issm/trunk/src/c/objects/Loads/Numericalflux.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Numericalflux.h	(revision 12330)
@@ -45,9 +45,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Loads/Pengrid.cpp
===================================================================
--- /issm/trunk/src/c/objects/Loads/Pengrid.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Pengrid.cpp	(revision 12330)
@@ -132,98 +132,4 @@
 }
 /*}}}1*/
-#ifdef _SERIAL_
-/*FUNCTION Pengrid::Marshall {{{1*/
-void  Pengrid::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Tria: */
-	enum_type=PengridEnum;
-
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*marshall Tria data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-	memcpy(marshalled_dataset,&active,sizeof(active));marshalled_dataset+=sizeof(active);
-	memcpy(marshalled_dataset,&zigzag_counter,sizeof(zigzag_counter));marshalled_dataset+=sizeof(zigzag_counter);
-
-	/*Marshall hooks: */
-	hnode->Marshall(&marshalled_dataset);
-	helement->Marshall(&marshalled_dataset);
-	hmatpar->Marshall(&marshalled_dataset);
-
-	/*Marshall inputs: */
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	/*parameters: don't do anything about it. parameters are marshalled somewhere else!*/
-
-	xfree((void**)&marshalled_inputs);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Pengrid::MarshallSize {{{1*/
-int   Pengrid::MarshallSize(){
-	
-	return sizeof(id)
-		+sizeof(analysis_type)
-		+sizeof(active)
-		+sizeof(zigzag_counter)
-		+hnode->MarshallSize()
-		+helement->MarshallSize()
-		+hmatpar->MarshallSize()
-		+inputs->MarshallSize()
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Pengrid::Demarshall {{{1*/
-void  Pengrid::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-	memcpy(&active,marshalled_dataset,sizeof(active));marshalled_dataset+=sizeof(active);
-	memcpy(&zigzag_counter,marshalled_dataset,sizeof(zigzag_counter));marshalled_dataset+=sizeof(zigzag_counter);
-
-	/*demarshall hooks: */
-	hnode=new Hook(); hnode->Demarshall(&marshalled_dataset);
-	helement=new Hook(); helement->Demarshall(&marshalled_dataset);
-	hmatpar=new Hook(); hmatpar->Demarshall(&marshalled_dataset);
-	
-	/*demarshall inputs: */
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*parameters: may not exist even yet, so let Configure handle it: */
-	this->parameters=NULL;
-	this->node=NULL;
-	this->element=NULL;
-	this->matpar=NULL;
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION Pengrid::ObjectEnum{{{1*/
 int Pengrid::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Loads/Pengrid.h
===================================================================
--- /issm/trunk/src/c/objects/Loads/Pengrid.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Pengrid.h	(revision 12330)
@@ -50,9 +50,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Loads/Penpair.cpp
===================================================================
--- /issm/trunk/src/c/objects/Loads/Penpair.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Penpair.cpp	(revision 12330)
@@ -85,67 +85,4 @@
 }
 /*}}}1*/
-#ifdef _SERIAL_
-/*FUNCTION Penpair::Marshall {{{1*/
-void  Penpair::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Penpair: */
-	enum_type=PenpairEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall Penpair data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	/*Marshall hooks*/
-	hnodes->Marshall(&marshalled_dataset);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-/*FUNCTION Penpair::MarshallSize {{{1*/
-int   Penpair::MarshallSize(){
-
-	return sizeof(id)+
-		+sizeof(analysis_type)
-		+hnodes->MarshallSize()
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}1*/
-/*FUNCTION Penpair::Demarshall {{{1*/
-void  Penpair::Demarshall(char** pmarshalled_dataset){
-
-	int i;
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-
-	/*demarshall hooks: */
-	hnodes=new Hook(); hnodes->Demarshall(&marshalled_dataset);
-
-	/*pointers are garbabe, until configuration is carried out: */
-	nodes=NULL;
-	parameters=NULL;
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-#endif
 /*FUNCTION Penpair::ObjectEnum{{{1*/
 int Penpair::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Loads/Penpair.h
===================================================================
--- /issm/trunk/src/c/objects/Loads/Penpair.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Penpair.h	(revision 12330)
@@ -37,9 +37,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Loads/Riftfront.cpp
===================================================================
--- /issm/trunk/src/c/objects/Loads/Riftfront.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Riftfront.cpp	(revision 12330)
@@ -192,123 +192,4 @@
 }
 /*}}}1*/
-#ifdef _SERIAL_
-/*FUNCTION Riftfront::Marshall {{{1*/
-void  Riftfront::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Riftfront: */
-	enum_type=RiftfrontEnum;
-
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*marshall Riftfront data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-	memcpy(marshalled_dataset,&active,sizeof(active));marshalled_dataset+=sizeof(active);
-	memcpy(marshalled_dataset,&normal,sizeof(normal));marshalled_dataset+=sizeof(normal);
-	memcpy(marshalled_dataset,&length,sizeof(length));marshalled_dataset+=sizeof(length);
-	memcpy(marshalled_dataset,&fraction,sizeof(fraction));marshalled_dataset+=sizeof(fraction);
-	memcpy(marshalled_dataset,&frozen,sizeof(frozen));marshalled_dataset+=sizeof(frozen);
-	memcpy(marshalled_dataset,&state,sizeof(state));marshalled_dataset+=sizeof(state);
-	memcpy(marshalled_dataset,&counter,sizeof(counter));marshalled_dataset+=sizeof(counter);
-	memcpy(marshalled_dataset,&prestable,sizeof(prestable));marshalled_dataset+=sizeof(prestable);
-	memcpy(marshalled_dataset,&penalty_lock,sizeof(penalty_lock));marshalled_dataset+=sizeof(penalty_lock);
-	memcpy(marshalled_dataset,&material_converged,sizeof(material_converged));marshalled_dataset+=sizeof(material_converged);
-
-	/*Marshall hooks: */
-	hnodes->Marshall(&marshalled_dataset);
-	helements->Marshall(&marshalled_dataset);
-	hmatpar->Marshall(&marshalled_dataset);
-
-	/*Marshall inputs: */
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	/*parameters: don't do anything about it. parameters are marshalled somewhere else!*/
-
-	xfree((void**)&marshalled_inputs);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Riftfront::MarshallSize {{{1*/
-int   Riftfront::MarshallSize(){
-	
-	return sizeof(id)
-		+sizeof(analysis_type)
-		+sizeof(active)
-		+sizeof(normal)
-		+sizeof(length)
-		+sizeof(fraction)
-		+sizeof(frozen)
-		+sizeof(state)
-		+sizeof(counter)
-		+sizeof(prestable)
-		+sizeof(penalty_lock)
-		+sizeof(material_converged)
-		+hnodes->MarshallSize()
-		+helements->MarshallSize()
-		+hmatpar->MarshallSize()
-		+inputs->MarshallSize()
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Riftfront::Demarshall {{{1*/
-void  Riftfront::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-	memcpy(&active,marshalled_dataset,sizeof(active));marshalled_dataset+=sizeof(active);
-	memcpy(&normal,marshalled_dataset,sizeof(normal));marshalled_dataset+=sizeof(normal);
-	memcpy(&length,marshalled_dataset,sizeof(length));marshalled_dataset+=sizeof(length);
-	memcpy(&fraction,marshalled_dataset,sizeof(fraction));marshalled_dataset+=sizeof(fraction);
-	memcpy(&frozen,marshalled_dataset,sizeof(frozen));marshalled_dataset+=sizeof(frozen);
-	memcpy(&state,marshalled_dataset,sizeof(state));marshalled_dataset+=sizeof(state);
-	memcpy(&counter,marshalled_dataset,sizeof(counter));marshalled_dataset+=sizeof(counter);
-	memcpy(&prestable,marshalled_dataset,sizeof(prestable));marshalled_dataset+=sizeof(prestable);
-	memcpy(&penalty_lock,marshalled_dataset,sizeof(penalty_lock));marshalled_dataset+=sizeof(penalty_lock);
-	memcpy(&material_converged,marshalled_dataset,sizeof(material_converged));marshalled_dataset+=sizeof(material_converged);
-
-	/*demarshall hooks: */
-	hnodes=new Hook();    hnodes->Demarshall(&marshalled_dataset);
-	helements=new Hook(); helements->Demarshall(&marshalled_dataset);
-	hmatpar=new Hook();   hmatpar->Demarshall(&marshalled_dataset);
-
-	/*pointers are garbabe, until configuration is carried out: */
-	nodes=NULL;
-	elements=NULL;
-	matpar=NULL;
-	
-	/*demarshall inputs: */
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*parameters: may not exist even yet, so let Configure handle it: */
-	this->parameters=NULL;
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-#endif
 /*FUNCTION Riftfront::ObjectEnum{{{1*/
 int Riftfront::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Loads/Riftfront.h
===================================================================
--- /issm/trunk/src/c/objects/Loads/Riftfront.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Loads/Riftfront.h	(revision 12330)
@@ -57,9 +57,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Materials/Matice.cpp
===================================================================
--- /issm/trunk/src/c/objects/Materials/Matice.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Materials/Matice.cpp	(revision 12330)
@@ -88,74 +88,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION Matice::Marshall {{{1*/
-void  Matice::Marshall(char** pmarshalled_dataset){
-
-	/*Intermediaries*/
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputs_size;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Matice: */
-	enum_type=MaticeEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall Matice data: */
-	memcpy(marshalled_dataset,&mid,sizeof(mid));marshalled_dataset+=sizeof(mid);
-
-	/*Marshall hooks: */
-	helement->Marshall(&marshalled_dataset);
-
-	/*Marshall inputs: */
-	marshalled_inputs_size=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
-	marshalled_dataset+=marshalled_inputs_size;
-
-	*pmarshalled_dataset=marshalled_dataset;
-
-	/*clean up and return*/
-	xfree((void**)&marshalled_inputs);
-}
-/*}}}*/
-/*FUNCTION Matice::MarshallSize{{{1*/
-int   Matice::MarshallSize(){
-
-	return sizeof(mid)
-	  +helement->MarshallSize()
-	  +inputs->MarshallSize()
-	  +sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Matice::Demarshall {{{1*/
-void  Matice::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&mid,marshalled_dataset,sizeof(mid));marshalled_dataset+=sizeof(mid);
-
-	/*demarshall hooks: */
-	helement=new Hook(); helement->Demarshall(&marshalled_dataset);
-
-	/*demarshall inputs: */
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION Matice::ObjectEnum{{{1*/
 int Matice::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Materials/Matice.h
===================================================================
--- /issm/trunk/src/c/objects/Materials/Matice.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Materials/Matice.h	(revision 12330)
@@ -35,9 +35,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Materials/Matpar.cpp
===================================================================
--- /issm/trunk/src/c/objects/Materials/Matpar.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Materials/Matpar.cpp	(revision 12330)
@@ -90,92 +90,4 @@
 }
 /*}}}1*/
-#ifdef _SERIAL_
-/*FUNCTION Matpar::Marshall {{{1*/
-void  Matpar::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Matpar: */
-	enum_type=MatparEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall Matpar data: */
-	memcpy(marshalled_dataset,&mid,sizeof(mid));marshalled_dataset+=sizeof(mid);
-	memcpy(marshalled_dataset,&rho_ice,sizeof(rho_ice));marshalled_dataset+=sizeof(rho_ice);
-	memcpy(marshalled_dataset,&rho_water,sizeof(rho_water));marshalled_dataset+=sizeof(rho_water);
-	memcpy(marshalled_dataset,&rho_freshwater,sizeof(rho_freshwater));marshalled_dataset+=sizeof(rho_freshwater);
-	memcpy(marshalled_dataset,&mu_water,sizeof(mu_water));marshalled_dataset+=sizeof(mu_water);
-	memcpy(marshalled_dataset,&heatcapacity,sizeof(heatcapacity));marshalled_dataset+=sizeof(heatcapacity);
-	memcpy(marshalled_dataset,&thermalconductivity,sizeof(thermalconductivity));marshalled_dataset+=sizeof(thermalconductivity);
-	memcpy(marshalled_dataset,&latentheat,sizeof(latentheat));marshalled_dataset+=sizeof(latentheat);
-	memcpy(marshalled_dataset,&beta,sizeof(beta));marshalled_dataset+=sizeof(beta);
-	memcpy(marshalled_dataset,&meltingpoint,sizeof(meltingpoint));marshalled_dataset+=sizeof(meltingpoint);
-	memcpy(marshalled_dataset,&referencetemperature,sizeof(referencetemperature));marshalled_dataset+=sizeof(referencetemperature);
-	memcpy(marshalled_dataset,&mixed_layer_capacity,sizeof(mixed_layer_capacity));marshalled_dataset+=sizeof(mixed_layer_capacity);
-	memcpy(marshalled_dataset,&thermal_exchange_velocity,sizeof(thermal_exchange_velocity));marshalled_dataset+=sizeof(thermal_exchange_velocity);
-	memcpy(marshalled_dataset,&g,sizeof(g));marshalled_dataset+=sizeof(g);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-/*FUNCTION Matpar::MarshallSize {{{1*/
-int   Matpar::MarshallSize(){
-
-	return sizeof(mid)+
-		sizeof(rho_ice)+
-		sizeof(rho_water)+
-		sizeof(rho_freshwater)+
-		sizeof(mu_water)+
-		sizeof(heatcapacity)+
-		sizeof(thermalconductivity)+
-		sizeof(latentheat)+
-		sizeof(beta)+
-		sizeof(meltingpoint)+
-		sizeof(referencetemperature)+
-		sizeof(mixed_layer_capacity)+
-		sizeof(thermal_exchange_velocity)+
-		sizeof(g)+
-		sizeof(int); //sizeof(int) for enum type
-}
-/*}}}1*/
-/*FUNCTION Matpar::Demarshall {{{1*/
-void  Matpar::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&mid,marshalled_dataset,sizeof(mid));marshalled_dataset+=sizeof(mid);
-	memcpy(&rho_ice,marshalled_dataset,sizeof(rho_ice));marshalled_dataset+=sizeof(rho_ice);
-	memcpy(&rho_water,marshalled_dataset,sizeof(rho_water));marshalled_dataset+=sizeof(rho_water);
-	memcpy(&rho_freshwater,marshalled_dataset,sizeof(rho_freshwater));marshalled_dataset+=sizeof(rho_freshwater);
-	memcpy(&mu_water,marshalled_dataset,sizeof(mu_water));marshalled_dataset+=sizeof(mu_water);
-	memcpy(&heatcapacity,marshalled_dataset,sizeof(heatcapacity));marshalled_dataset+=sizeof(heatcapacity);
-	memcpy(&thermalconductivity,marshalled_dataset,sizeof(thermalconductivity));marshalled_dataset+=sizeof(thermalconductivity);
-	memcpy(&latentheat,marshalled_dataset,sizeof(latentheat));marshalled_dataset+=sizeof(latentheat);
-	memcpy(&beta,marshalled_dataset,sizeof(beta));marshalled_dataset+=sizeof(beta);
-	memcpy(&meltingpoint,marshalled_dataset,sizeof(meltingpoint));marshalled_dataset+=sizeof(meltingpoint);
-	memcpy(&referencetemperature,marshalled_dataset,sizeof(referencetemperature));marshalled_dataset+=sizeof(referencetemperature);
-	memcpy(&mixed_layer_capacity,marshalled_dataset,sizeof(mixed_layer_capacity));marshalled_dataset+=sizeof(mixed_layer_capacity);
-	memcpy(&thermal_exchange_velocity,marshalled_dataset,sizeof(thermal_exchange_velocity));marshalled_dataset+=sizeof(thermal_exchange_velocity);
-	memcpy(&g,marshalled_dataset,sizeof(g));marshalled_dataset+=sizeof(g);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-#endif
 /*FUNCTION Matpar::ObjectEnum{{{1*/
 int Matpar::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Materials/Matpar.h
===================================================================
--- /issm/trunk/src/c/objects/Materials/Matpar.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Materials/Matpar.h	(revision 12330)
@@ -47,9 +47,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Node.cpp
===================================================================
--- /issm/trunk/src/c/objects/Node.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Node.cpp	(revision 12330)
@@ -193,87 +193,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION Node::Marshall{{{1*/
-void  Node::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-	char* marshalled_inputs=NULL;
-	int   marshalled_inputssize;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Node: */
-	enum_type=NodeEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall Node data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&sid,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(marshalled_dataset,&analysis_type,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-	memcpy(marshalled_dataset,&coord_system,9*sizeof(double));marshalled_dataset+=9*sizeof(double);  
-
-	/*marshall objects: */
-	indexing.Marshall(&marshalled_dataset);
-	hvertex->Marshall(&marshalled_dataset);
-
-	/*Marshall inputs: */
-	marshalled_inputssize=inputs->MarshallSize();
-	marshalled_inputs=inputs->Marshall();
-	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputssize*sizeof(char));
-	marshalled_dataset+=marshalled_inputssize;
-
-	/*Free ressources:*/
-	xfree((void**)&marshalled_inputs);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Node::MarshallSize{{{1*/
-int   Node::MarshallSize(){
-
-	return sizeof(id)+
-		sizeof(sid)+
-		indexing.MarshallSize()+
-		hvertex->MarshallSize()+
-		inputs->MarshallSize()+
-		sizeof(analysis_type)+
-		9*sizeof(double)+
-		sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Node::Demarshall{{{1*/
-void  Node::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&sid,marshalled_dataset,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(&analysis_type,marshalled_dataset,sizeof(analysis_type));marshalled_dataset+=sizeof(analysis_type);
-	memcpy(&coord_system,marshalled_dataset,9*sizeof(double));marshalled_dataset+=9*sizeof(double);
-	
-	/*demarshall objects: */
-	indexing.Demarshall(&marshalled_dataset);
-	hvertex=new Hook(); hvertex->Demarshall(&marshalled_dataset);
-
-	/*demarshall inputs: */
-	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION Node::ObjectEnum{{{1*/
 int Node::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Node.h
===================================================================
--- /issm/trunk/src/c/objects/Node.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Node.h	(revision 12330)
@@ -32,5 +32,5 @@
 		Inputs*        inputs; //properties of this node
 		int            analysis_type;
-		double         coord_system[3][3];
+		IssmDouble         coord_system[3][3];
 
 		/*Node constructors, destructors {{{1*/
@@ -44,9 +44,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy(){_error_("Not implemented yet (similar to Elements)");};
@@ -54,15 +49,15 @@
 		/*Update virtual functions definitions: {{{1*/
 		
-		void  InputUpdateFromVector(double* vector, int name, int type);
+		void  InputUpdateFromVector(IssmDouble* vector, int name, int type);
 		void  InputUpdateFromVector(int* vector, int name, int type);
 		void  InputUpdateFromVector(bool* vector, int name, int type);
-		void  InputUpdateFromMatrixDakota(double* matrix,int nrows, int ncols, int name, int type);
-		void  InputUpdateFromVectorDakota(double* vector, int name, int type);
+		void  InputUpdateFromMatrixDakota(IssmDouble* matrix,int nrows, int ncols, int name, int type);
+		void  InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type);
 		void  InputUpdateFromVectorDakota(int* vector, int name, int type);
 		void  InputUpdateFromVectorDakota(bool* vector, int name, int type);
-		void  InputUpdateFromConstant(double constant, int name);
+		void  InputUpdateFromConstant(IssmDouble constant, int name);
 		void  InputUpdateFromConstant(int constant, int name);
 		void  InputUpdateFromConstant(bool constant, int name);
-		void  InputUpdateFromSolution(double* solution){_error_("Not implemented yet!");}
+		void  InputUpdateFromSolution(IssmDouble* solution){_error_("Not implemented yet!");}
 		void  InputUpdateFromIoModel(int index, IoModel* iomodel){_error_("Not implemented yet!");}
 		/*}}}*/
@@ -75,5 +70,5 @@
 		int    GetVertexId(void);
 #ifdef _HAVE_DIAGNOSTIC_
-		void   GetCoordinateSystem(double* coord_system_out);
+		void   GetCoordinateSystem(IssmDouble* coord_system_out);
 #endif
 		void   SetVertexDof(int in_dof);
@@ -82,5 +77,5 @@
 		int    GetNumberOfDofs(int approximation_enum,int setenum);
 		int    IsClone();
-		void   ApplyConstraint(int dof,double value);
+		void   ApplyConstraint(int dof,IssmDouble value);
 		void   RelaxConstraint(int dof);
 		void   DofInSSet(int dof);
@@ -93,8 +88,8 @@
 		int    GetDofList1(void);
 		int    GetSidList(void);
-		double GetX();
-		double GetY();
-		double GetZ();
-		double GetSigma();
+		IssmDouble GetX();
+		IssmDouble GetY();
+		IssmDouble GetZ();
+		IssmDouble GetSigma();
 		int    IsOnBed();
 		int    IsOnSurface();
@@ -102,7 +97,7 @@
 		int    IsFloating();
 		int    IsGrounded();
-		void   UpdateSpcs(double* ys);
-		void   VecMerge(Vector* ug, double* vector_serial,int setenum);
-		void   VecReduce(Vector* vector, double* ug_serial,int setnum);
+		void   UpdateSpcs(IssmDouble* ys);
+		void   VecMerge(Vector* ug, IssmDouble* vector_serial,int setenum);
+		void   VecReduce(Vector* vector, IssmDouble* ug_serial,int setnum);
 		
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Numerics/ElementVector.cpp
===================================================================
--- /issm/trunk/src/c/objects/Numerics/ElementVector.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Numerics/ElementVector.cpp	(revision 12330)
@@ -166,4 +166,7 @@
 	double* localvalues=NULL;
 
+	/*In debugging mode, check consistency (no NaN, and values not too big)*/
+	this->CheckConsistency();
+
 	if(this->fsize){
 		/*first, retrieve values that are in the f-set from the g-set values vector: */
@@ -200,4 +203,15 @@
 	}
 
+}
+/*}}}*/
+/*FUNCTION ElementVector::CheckConsistency{{{1*/
+void ElementVector::CheckConsistency(void){
+	/*Check element matrix values, only in debugging mode*/
+#ifdef _ISSM_DEBUG_ 
+	for (int i=0;i<this->nrows;i++){
+		if (isnan(this->values[i])) _error_("NaN found in Element Vector");
+		if (fabs( this->values[i])>1.e+50) _error_("Element Vector values exceeds 1.e+50");
+	}
+#endif
 }
 /*}}}*/
Index: /issm/trunk/src/c/objects/Numerics/ElementVector.h
===================================================================
--- /issm/trunk/src/c/objects/Numerics/ElementVector.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Numerics/ElementVector.h	(revision 12330)
@@ -43,4 +43,5 @@
 		void InsertIntoGlobal(Vector* pf);
 		void Echo(void);
+		void CheckConsistency(void);
 		void Init(ElementVector* pe);
 		void SetValue(double scalar);
Index: /issm/trunk/src/c/objects/Numerics/Matrix.cpp
===================================================================
--- /issm/trunk/src/c/objects/Numerics/Matrix.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Numerics/Matrix.cpp	(revision 12330)
@@ -140,38 +140,4 @@
 }
 /*}}}*/
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-/*FUNCTION Matrix::ToMatlabMatrix{{{1*/
-mxArray* Matrix::ToMatlabMatrix(void){
-
-	mxArray* dataref=NULL;
-	#ifdef _HAVE_PETSC_
-	PetscMatrixToMatlabMatrix(&dataref,this->matrix);
-	#else
-	dataref=this->matrix->ToMatlabMatrix();
-	#endif
-	return dataref;
-
-}
-/*}}}*/
-/*FUNCTION MatlabMatrixToMatrix{{{1*/
-Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix){
-
-	int dummy;
-	Matrix* matrix=NULL;
-
-	/*allocate matrix object: */
-	matrix=new Matrix();
-
-	#ifdef _HAVE_PETSC_
-	MatlabMatrixToPetscMatrix(&matrix->matrix,NULL,NULL,mxmatrix);
-	#else
-	matrix->matrix=MatlabMatrixToSeqMat(mxmatrix);
-	#endif
-	
-	return matrix;
-}
-/*}}}*/
-#endif
 /*FUNCTION Matrix::Assemble{{{1*/
 void Matrix::Assemble(void){
Index: /issm/trunk/src/c/objects/Numerics/Matrix.h
===================================================================
--- /issm/trunk/src/c/objects/Numerics/Matrix.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Numerics/Matrix.h	(revision 12330)
@@ -21,7 +21,4 @@
 #endif
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "mex.h"
-#endif
 class Vector;
 
@@ -51,7 +48,4 @@
 		/*Matrix specific routines {{{1*/
 		void Echo(void);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		mxArray* ToMatlabMatrix(void);
-		#endif
 		void Assemble(void);
 		double Norm(NormMode norm_type);
@@ -66,8 +60,4 @@
 
 };
-/*API: */
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-Matrix* MatlabMatrixToMatrix(const mxArray* mxmatrix);
-#endif
 
 #endif //#ifndef _MATRIX_H_
Index: /issm/trunk/src/c/objects/Numerics/Vector.cpp
===================================================================
--- /issm/trunk/src/c/objects/Numerics/Vector.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Numerics/Vector.cpp	(revision 12330)
@@ -85,5 +85,5 @@
 /*}}}*/
 #endif
-#ifdef _HAVE_GSL_
+#if defined(_HAVE_GSL_) && !defined(_HAVE_PETSC_)
 /*FUNCTION Vector::Vector(SeqVec* seq_vec){{{1*/
 Vector::Vector(SeqVec*  seq_vec){
@@ -132,38 +132,4 @@
 }
 /*}}}*/
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-/*FUNCTION Vector::ToMatlabVector{{{1*/
-mxArray* Vector::ToMatlabVector(void){
-
-	mxArray* dataref=NULL;
-	#ifdef _HAVE_PETSC_
-	PetscVectorToMatlabVector(&dataref,this->vector);
-	#else
-	dataref=this->vector->ToMatlabVector();
-	#endif
-	return dataref;
-
-}
-/*}}}*/
-/*FUNCTION MatlabVectorToVector{{{1*/
-Vector* MatlabVectorToVector(const mxArray* mxvector){
-
-	int dummy;
-	Vector* vector=NULL;
-
-	/*allocate vector object: */
-	vector=new Vector();
-
-	#ifdef _HAVE_PETSC_
-	MatlabVectorToPetscVector(&vector->vector,&dummy,mxvector);
-	#else
-	vector->vector=MatlabVectorToSeqVec(mxvector);
-	#endif
-	
-	return vector;
-}
-/*}}}*/
-#endif
 /*FUNCTION Vector::Assemble{{{1*/
 void Vector::Assemble(void){
Index: /issm/trunk/src/c/objects/Numerics/Vector.h
===================================================================
--- /issm/trunk/src/c/objects/Numerics/Vector.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Numerics/Vector.h	(revision 12330)
@@ -21,8 +21,4 @@
 #endif
 		
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "mex.h"
-#endif
-
 /*}}}*/
 
@@ -47,5 +43,5 @@
 		Vector(Vec petsc_vec);
 		#endif
-		#ifdef _HAVE_GSL_
+		#if defined(_HAVE_GSL_) && !defined(_HAVE_PETSC_)
 		Vector(SeqVec*  seq_vec);
 		#endif
@@ -54,7 +50,4 @@
 		/*Vector specific routines {{{1*/
 		void Echo(void);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		mxArray* ToMatlabVector(void);
-		#endif
 		void    AXPY(Vector *X, double a);
 		void    AYPX(Vector *X, double a);
@@ -77,8 +70,4 @@
 };
 
-/*API: */
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-Vector* MatlabVectorToVector(const mxArray* mxvector);
-#endif
 
 #endif //#ifndef _VECTOR_H_
Index: /issm/trunk/src/c/objects/Object.h
===================================================================
--- /issm/trunk/src/c/objects/Object.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Object.h	(revision 12330)
@@ -21,9 +21,4 @@
 		virtual int   Id()=0;
 		virtual int   MyRank()=0;
-		#ifdef _SERIAL_
-		virtual void  Marshall(char** pmarshalled_dataset)=0;
-		virtual int   MarshallSize()=0;
-		virtual void  Demarshall(char** pmarshalled_dataset)=0;
-		#endif
 		virtual int   ObjectEnum()=0;
 		virtual Object* copy()=0;
Index: /issm/trunk/src/c/objects/OptArgs.h
===================================================================
--- /issm/trunk/src/c/objects/OptArgs.h	(revision 12329)
+++ /issm/trunk/src/c/objects/OptArgs.h	(revision 12330)
@@ -6,19 +6,8 @@
 #define _OPTARGS_H_
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-
-#include "mex.h"
-struct OptArgs{
-	char* function_name;
-	mxArray* femmodel;
-};
-
-#else
-
 class Model;
 struct OptArgs{
 	FemModel* femmodel;
 };
-#endif
 
 #endif
Index: /issm/trunk/src/c/objects/OptPars.h
===================================================================
--- /issm/trunk/src/c/objects/OptPars.h	(revision 12329)
+++ /issm/trunk/src/c/objects/OptPars.h	(revision 12330)
@@ -8,7 +8,7 @@
 struct OptPars{
 
-	double xmin;
-	double xmax;
-	double cm_jump;
+	IssmDouble xmin;
+	IssmDouble xmax;
+	IssmDouble cm_jump;
 	int maxiter;
 
Index: /issm/trunk/src/c/objects/Options/Option.h
===================================================================
--- /issm/trunk/src/c/objects/Options/Option.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Options/Option.h	(revision 12330)
@@ -33,9 +33,4 @@
 		int   Id(){_error_("Not implemented yet");};
 		int   MyRank(){_error_("Not implemented yet");};
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		int   MarshallSize(){_error_("Not implemented yet");};
-		void  Demarshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		#endif
 		int   ObjectEnum(){return OptionEnum;};
 		Object* copy(){_error_("Not implemented yet");};
@@ -47,4 +42,5 @@
 		virtual int   NDims()=0;
 		virtual int*  Size()=0;
+		virtual void  Get(int* pvalue)=0;
 		virtual void  Get(double* pvalue)=0;
 		virtual void  Get(bool* pvalue)=0;
Index: /issm/trunk/src/c/objects/Options/OptionCell.h
===================================================================
--- /issm/trunk/src/c/objects/Options/OptionCell.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Options/OptionCell.h	(revision 12330)
@@ -30,9 +30,4 @@
 		int   Id(){_error_("Not implemented yet");};
 		int   MyRank(){_error_("Not implemented yet");};
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		int   MarshallSize(){_error_("Not implemented yet");};
-		void  Demarshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		#endif
 		int   ObjectEnum(){return OptionCellEnum;};
 		Object* copy(){_error_("Not implemented yet");};
@@ -44,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue){_error_("An OptionCell object cannot return a int");};
 		void  Get(double* pvalue){_error_("An OptionCell object cannot return a double");};
 		void  Get(bool* pvalue){  _error_("An OptionCell object cannot return a bool");};
Index: /issm/trunk/src/c/objects/Options/OptionChar.h
===================================================================
--- /issm/trunk/src/c/objects/Options/OptionChar.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Options/OptionChar.h	(revision 12330)
@@ -30,9 +30,4 @@
 		int   Id(){_error_("Not implemented yet");};
 		int   MyRank(){_error_("Not implemented yet");};
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		int   MarshallSize(){_error_("Not implemented yet");};
-		void  Demarshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		#endif
 		int   ObjectEnum(){return OptionCharEnum;};
 		Object* copy(){_error_("Not implemented yet");};
@@ -44,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue){_error_("An OptionChar object cannot return a int");};
 		void  Get(double* pvalue){_error_("An OptionChar object cannot return a double");};
 		void  Get(bool* pvalue){  _error_("An OptionChar object cannot return a bool");};
Index: /issm/trunk/src/c/objects/Options/OptionDouble.cpp
===================================================================
--- /issm/trunk/src/c/objects/Options/OptionDouble.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Options/OptionDouble.cpp	(revision 12330)
@@ -120,4 +120,16 @@
 }
 /*}}}*/
+/*FUNCTION OptionDouble::Get(int* pvalue) {{{1*/
+void OptionDouble::Get(int* pvalue){
+
+	/*We should first check that the size is one*/
+	if(this->NumEl()!=1){
+		_error_("option \"%s\" has %i elements and cannot return a single int",this->name,this->NumEl());
+	}
+
+	/*Assign output pointer*/
+	*pvalue=(int)this->values[0];
+}
+/*}}}*/
 /*FUNCTION OptionDouble::Get(double* pvalue) {{{1*/
 void OptionDouble::Get(double* pvalue){
Index: /issm/trunk/src/c/objects/Options/OptionDouble.h
===================================================================
--- /issm/trunk/src/c/objects/Options/OptionDouble.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Options/OptionDouble.h	(revision 12330)
@@ -30,9 +30,4 @@
 		int   Id(){_error_("Not implemented yet");};
 		int   MyRank(){_error_("Not implemented yet");};
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		int   MarshallSize(){_error_("Not implemented yet");};
-		void  Demarshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		#endif
 		int   ObjectEnum(){return OptionDoubleEnum;};
 		Object* copy(){_error_("Not implemented yet");};
@@ -44,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue);
 		void  Get(double* pvalue);
 		void  Get(bool* pvalue){  _error_("An OptionDouble object cannot return a bool");};
Index: /issm/trunk/src/c/objects/Options/OptionLogical.h
===================================================================
--- /issm/trunk/src/c/objects/Options/OptionLogical.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Options/OptionLogical.h	(revision 12330)
@@ -30,9 +30,4 @@
 		int   Id(){_error_("Not implemented yet");};
 		int   MyRank(){_error_("Not implemented yet");};
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		int   MarshallSize(){_error_("Not implemented yet");};
-		void  Demarshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		#endif
 		int   ObjectEnum(){return OptionLogicalEnum;};
 		Object* copy(){_error_("Not implemented yet");};
@@ -44,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue){_error_("An OptionLogical object cannot return a int");};
 		void  Get(double* pvalue){_error_("An OptionLogical object cannot return a double");};
 		void  Get(bool* pvalue);
Index: /issm/trunk/src/c/objects/Options/OptionStruct.h
===================================================================
--- /issm/trunk/src/c/objects/Options/OptionStruct.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Options/OptionStruct.h	(revision 12330)
@@ -30,9 +30,4 @@
 		int   Id(){_error_("Not implemented yet");};
 		int   MyRank(){_error_("Not implemented yet");};
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		int   MarshallSize(){_error_("Not implemented yet");};
-		void  Demarshall(char** pmarshalled_dataset){_error_("Not implemented yet");};
-		#endif
 		int   ObjectEnum(){return OptionStructEnum;};
 		Object* copy(){_error_("Not implemented yet");};
@@ -44,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue){_error_("An OptionStruct object cannot return a int");};
 		void  Get(double* pvalue){_error_("An OptionStruct object cannot return a double");};
 		void  Get(bool* pvalue){  _error_("An OptionStruct object cannot return a bool");};
Index: /issm/trunk/src/c/objects/Params/BoolParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/BoolParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/BoolParam.cpp	(revision 12330)
@@ -62,55 +62,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION BoolParam::Marshall{{{1*/
-void  BoolParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of BoolParam: */
-	enum_value=BoolParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall BoolParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION BoolParam::MarshallSize{{{1*/
-int   BoolParam::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION BoolParam::Demarshall{{{1*/
-void  BoolParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION BoolParam::ObjectEnum{{{1*/
 int BoolParam::ObjectEnum(void){
@@ -134,13 +83,4 @@
 }
 /*}}}*/
-/*FUNCTION BoolParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  BoolParam::SetMatlabField(mxArray* dataref){
-	char* name=NULL;
-	this->GetParameterName(&name);
-	mxSetField( dataref, 0, name,mxCreateDoubleScalar((double)value));
-}
-#endif
-/*}}}*/
 /*FUNCTION BoolParam::UnitConversion{{{1*/
 void  BoolParam::UnitConversion(int direction_enum){
Index: /issm/trunk/src/c/objects/Params/BoolParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/BoolParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/BoolParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -41,9 +37,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -81,7 +72,4 @@
 		
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.cpp	(revision 12330)
@@ -127,111 +127,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleMatArrayParam::Marshall{{{1*/
-void  DoubleMatArrayParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleMatArrayParam: */
-	enum_value=DoubleMatArrayParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleMatArrayParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	if(M){
-		memcpy(marshalled_dataset,mdim_array,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
-		memcpy(marshalled_dataset,ndim_array,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
-		for(i=0;i<M;i++){
-			double* matrix=this->array[i];
-			int     m=this->mdim_array[i];
-			int     n=this->ndim_array[i];
-			memcpy(marshalled_dataset,&m,sizeof(m));marshalled_dataset+=sizeof(m);
-			memcpy(marshalled_dataset,&n,sizeof(n));marshalled_dataset+=sizeof(n);
-			if(m*n)memcpy(marshalled_dataset,matrix,m*n*sizeof(double));marshalled_dataset+=m*n*sizeof(double);
-		}
-	}
-	
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleMatArrayParam::MarshallSize{{{1*/
-int   DoubleMatArrayParam::MarshallSize(){
-
-	int size=0;
-	int i;
-
-	size+=sizeof(enum_type)+
-		sizeof(M)+
-		M*sizeof(int)+
-		M*sizeof(int);
-
-	for(i=0;i<M;i++){
-		int     m=this->mdim_array[i];
-		int     n=this->ndim_array[i];
-		size+=sizeof(m)+sizeof(n)+m*n*sizeof(double);
-	}
-	size+=sizeof(int); //sizeof(int) for enum value
-
-	return  size;
-}
-/*}}}*/
-/*FUNCTION DoubleMatArrayParam::Demarshall{{{1*/
-void  DoubleMatArrayParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-	double* matrix=NULL;
-	int     m,n;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum value, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	
-	/*data: */
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	if(M){
-		this->mdim_array=(int*)xmalloc(M*sizeof(int));
-		this->ndim_array=(int*)xmalloc(M*sizeof(int));
-		memcpy(this->mdim_array,marshalled_dataset,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
-		memcpy(this->ndim_array,marshalled_dataset,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
-
-		this->array=(double**)xmalloc(M*sizeof(double*));
-		for(i=0;i<M;i++){
-			memcpy(&m,marshalled_dataset,sizeof(m));marshalled_dataset+=sizeof(m);
-			memcpy(&n,marshalled_dataset,sizeof(n));marshalled_dataset+=sizeof(n);
-			if(m*n){
-				matrix=(double*)xmalloc(m*n*sizeof(double));
-				memcpy(matrix,marshalled_dataset,m*n*sizeof(double));marshalled_dataset+=m*n*sizeof(double);
-			}
-			else{
-				matrix=NULL;
-			}
-			this->array[i]=matrix;
-		}
-	}
-	else{
-		this->array=NULL;
-		this->mdim_array=NULL;
-		this->ndim_array=NULL;
-	}
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleMatArrayParam::ObjectEnum{{{1*/
 int DoubleMatArrayParam::ObjectEnum(void){
@@ -307,44 +200,4 @@
 	EnumToStringx(pname,this->enum_type);
 }
-/*}}}*/
-/*FUNCTION StringArrayParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  DoubleMatArrayParam::SetMatlabField(mxArray* dataref){
-	
-	int      i,m,n;
-	double*  matrix=NULL;
-	double*  outmatrix=NULL;
-	char*    name=NULL;
-	mwSize   dims[2]={0};
-	mxArray* pfield=NULL;
-	mxArray* pfield2=NULL;
-	mxArray* pfield3=NULL;
-	
-	this->GetParameterName(&name);
-	dims[0]=this->M;
-	dims[1]=1;
-	pfield=mxCreateCellArray(2,dims);
-
-	for(i=0;i<this->M;i++){
-		matrix=this->array[i];
-		m=this->mdim_array[i];
-		n=this->ndim_array[i];
-		outmatrix=(double*)xmalloc(m*n*sizeof(double));
-		memcpy(outmatrix,matrix,m*n*sizeof(double));
-	
-		pfield2=mxCreateDoubleMatrix(0,0,mxREAL);
-		mxSetM(pfield2,n);
-		mxSetN(pfield2,m);
-		mxSetPr(pfield2,outmatrix);
-
-		//transpose the outmatrix, written directly to matlab! from C to matlab.
-		mexCallMATLAB(1,&pfield3, 1, &pfield2, "transpose");
-	
-		mxSetCell(pfield,i,pfield3);
-	}
-	
-	mxSetField( dataref, 0, name,pfield);
-}
-#endif
 /*}}}*/
 /*FUNCTION DoubleMatArrayParam::SetValue(double** array, int M, int* mdim_array, int* ndim_array){{{1*/
Index: /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -44,9 +40,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -84,7 +75,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Params/DoubleMatParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleMatParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleMatParam.cpp	(revision 12330)
@@ -78,64 +78,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleMatParam::Marshall{{{1*/
-void  DoubleMatParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleMatParam: */
-	enum_value=DoubleMatParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleMatParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(marshalled_dataset,&N,sizeof(N));marshalled_dataset+=sizeof(N);
-	memcpy(marshalled_dataset,value,M*N*sizeof(double));marshalled_dataset+=M*N*sizeof(double);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleMatParam::MarshallSize{{{1*/
-int   DoubleMatParam::MarshallSize(){
-	
-	return sizeof(M)
-		+sizeof(N)
-		+M*N*sizeof(double)
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION DoubleMatParam::Demarshall{{{1*/
-void  DoubleMatParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(&N,marshalled_dataset,sizeof(N));marshalled_dataset+=sizeof(N);
-	value=(double*)xmalloc(M*N*sizeof(double));
-	memcpy(value,marshalled_dataset,M*N*sizeof(double));marshalled_dataset+=M*N*sizeof(double);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleMatParam::ObjectEnum{{{1*/
 int DoubleMatParam::ObjectEnum(void){
@@ -169,18 +109,5 @@
 /*FUNCTION DoubleMatParam::GetParameterValue(int** pintarray,int* pM,int* pN){{{1*/
 void  DoubleMatParam::GetParameterValue(int** pintarray,int* pM,int* pN){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	int* output=NULL;
-	int  i;
-
-	output=(int*)xmalloc((int)(M*N*sizeof(int)));
-	for(i=0;i<M*N;i++) output[i]=(int)value[i];
-
-	/*Assign output pointers:*/
-	if(pM) *pM=M;
-	if(pN) *pN=N;
-	*pintarray=output;
-#else
 	_error_("DoubleMat of enum %i (%s) cannot return an array of int",enum_type,EnumToStringx(enum_type));
-#endif
 }
 /*}}}*/
@@ -189,27 +116,4 @@
 	EnumToStringx(pname,this->enum_type);
 }
-/*}}}*/
-/*FUNCTION DoubleMatParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  DoubleMatParam::SetMatlabField(mxArray* dataref){
-
-	mxArray* pfield=NULL;
-	mxArray* pfield2=NULL;
-	double* doublemat=NULL;
-	char* name=NULL;
-	
-	this->GetParameterName(&name);
-	this->GetParameterValue(&doublemat,NULL,NULL);
-				
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,N);
-	mxSetN(pfield,M);
-	mxSetPr(pfield,doublemat);
-	
-	//transpose the matrix, written directly to matlab! from C to matlab.
-	mexCallMATLAB(1,&pfield2, 1, &pfield, "transpose");
-	mxSetField( dataref, 0, name,pfield2);
-}
-#endif
 /*}}}*/
 /*FUNCTION DoubleMatParam::SetValue{{{1*/
Index: /issm/trunk/src/c/objects/Params/DoubleMatParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleMatParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleMatParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -43,9 +39,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -84,7 +75,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Params/DoubleParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleParam.cpp	(revision 12330)
@@ -59,55 +59,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleParam::Marshall{{{1*/
-void  DoubleParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleParam: */
-	enum_value=DoubleParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleParam::MarshallSize{{{1*/
-int   DoubleParam::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION DoubleParam::Demarshall{{{1*/
-void  DoubleParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleParam::ObjectEnum{{{1*/
 int DoubleParam::ObjectEnum(void){
@@ -133,99 +82,31 @@
 /*FUNCTION DoubleParam::GetParameterValue(int* pinteger){{{1*/
 void DoubleParam::GetParameterValue(int* pinteger){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	*pinteger=(int)value;
-#else
 	_error_("Double param of enum %i (%s) cannot return an integer",enum_type,EnumToStringx(enum_type));
-#endif
 }
 /*}}}*/
 /*FUNCTION DoubleParam::GetParameterValue(bool* pbool){{{1*/
 void DoubleParam::GetParameterValue(bool* pbool){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-
-	/*If debugging mode, cheeck that the double is 0 or 1*/
-	_assert_(value==0 || value==1);
-	*pbool=(bool)value;
-
-#else
 	_error_("Double param of enum %i (%s) cannot return an bool",enum_type,EnumToStringx(enum_type));
-#endif
 }
 /*}}}*/
 /*FUNCTION DoubleParam::GetParameterValue(int** pintarray,int* pM){{{1*/
 void DoubleParam::GetParameterValue(int** pintarray,int* pM){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	int* output=NULL;
-
-	output=(int*)xmalloc(1*sizeof(int));
-	*output=(int)value;
-
-	/*Assign output pointers:*/
-	if(pM) *pM=1;
-	*pintarray=output;
-#else
 	_error_("Double param of enum %i (%s) cannot return an array of integers",enum_type,EnumToStringx(enum_type));
-#endif
 }
 /*}}}*/
 /*FUNCTION DoubleParam::GetParameterValue(int** pintarray,int* pM,int* pN){{{1*/
 void DoubleParam::GetParameterValue(int** pintarray,int* pM,int* pN){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	int* output=NULL;
-
-	output=(int*)xmalloc(1*sizeof(int));
-	*output=(int)value;
-
-	/*Assign output pointers:*/
-	if(pM) *pM=1;
-	if(pN) *pN=1;
-	*pintarray=output;
-#else
 	_error_("Double param of enum %i (%s) cannot return an array of integers",enum_type,EnumToStringx(enum_type));
-#endif
 }
 /*}}}*/
 /*FUNCTION DoubleParam::GetParameterValue(double** pdoublearray,int* pM){{{1*/
 void DoubleParam::GetParameterValue(double** pdoublearray,int* pM){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	double* output=NULL;
-
-	output=(double*)xmalloc(1*sizeof(double));
-	*output=(double)value;
-
-	/*Assign output podoubleers:*/
-	if(pM) *pM=1;
-	*pdoublearray=output;
-#else
 	_error_("Double param of enum %i (%s) cannot return an array of double",enum_type,EnumToStringx(enum_type));
-#endif
 }
 /*}}}*/
 /*FUNCTION DoubleParam::GetParameterValue(double** pdoublearray,int* pM,int* pN){{{1*/
 void DoubleParam::GetParameterValue(double** pdoublearray,int* pM,int* pN){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	double* output=NULL;
-
-	output=(double*)xmalloc(1*sizeof(double));
-	*output=(double)value;
-
-	/*Assign output podoubleers:*/
-	if(pM) *pM=1;
-	if(pN) *pN=1;
-	*pdoublearray=output;
-#else
 	_error_("Double param of enum %i (%s) cannot return an array of double",enum_type,EnumToStringx(enum_type));
-#endif
 }
-/*}}}*/
-/*FUNCTION DoubleParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  DoubleParam::SetMatlabField(mxArray* dataref){
-
-	char* name=NULL;
-	this->GetParameterName(&name);
-	mxSetField( dataref, 0, name,mxCreateDoubleScalar(value));
-}
-#endif
 /*}}}*/
 /*FUNCTION DoubleParam::UnitConversion{{{1*/
Index: /issm/trunk/src/c/objects/Params/DoubleParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -42,9 +38,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -82,7 +73,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Params/DoubleTransientMatParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleTransientMatParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleTransientMatParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
Index: /issm/trunk/src/c/objects/Params/DoubleVecParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleVecParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleVecParam.cpp	(revision 12330)
@@ -75,61 +75,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION DoubleVecParam::Marshall{{{1*/
-void  DoubleVecParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of DoubleVecParam: */
-	enum_value=DoubleVecParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall DoubleVecParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(marshalled_dataset,values,M*sizeof(double));marshalled_dataset+=M*sizeof(double);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION DoubleVecParam::MarshallSize{{{1*/
-int   DoubleVecParam::MarshallSize(){
-	
-	return sizeof(M)
-		+M*sizeof(double)
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION DoubleVecParam::Demarshall{{{1*/
-void  DoubleVecParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	values=(double*)xmalloc(M*sizeof(double));
-	memcpy(values,marshalled_dataset,M*sizeof(double));marshalled_dataset+=M*sizeof(double);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION DoubleVecParam::ObjectEnum{{{1*/
 int DoubleVecParam::ObjectEnum(void){
@@ -181,18 +124,5 @@
 /*FUNCTION DoubleVecParam::GetParameterValue(int** pintarray,int* pM){{{1*/
 void  DoubleVecParam::GetParameterValue(int** pintarray,int* pM){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	int* output=NULL;
-	int i;
-
-	/*Cast values into integers*/
-	output=(int*)xmalloc(M*sizeof(int));
-	for(i=0;i<M;i++) output[i]=(int)values[i];
-
-	/*Assign output pointers:*/
-	if(pM) *pM=M;
-	*pintarray=output;
-#else
 	_error_("DoubleVec param of enum %i (%s) cannot return an array of int",enum_type,EnumToStringx(enum_type));
-#endif
 }
 /*}}}*/
@@ -201,24 +131,4 @@
 	EnumToStringx(pname,this->enum_type);
 }
-/*}}}*/
-/*FUNCTION DoubleVecParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  DoubleVecParam::SetMatlabField(mxArray* dataref){
-
-	char* name=NULL;
-	double* doublevec=NULL;
-	mxArray* pfield=NULL;
-
-	this->GetParameterValue(&doublevec,NULL);
-	this->GetParameterName(&name);
-				
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,M);
-	mxSetN(pfield,1);
-	mxSetPr(pfield,doublevec);
-	
-	mxSetField( dataref, 0, name, pfield);
-}
-#endif
 /*}}}*/
 /*FUNCTION DoubleVecParam::SetValue{{{1*/
Index: /issm/trunk/src/c/objects/Params/DoubleVecParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleVecParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/DoubleVecParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -42,9 +38,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -82,7 +73,4 @@
 		
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/Params/FileParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/FileParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/FileParam.cpp	(revision 12330)
@@ -62,22 +62,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION FileParam::Marshall{{{1*/
-void  FileParam::Marshall(char** pmarshalled_dataset){
-
-	_error_("FileParam is a pointer and cannot be marshalled");
-}
-/*}}}*/
-/*FUNCTION FileParam::MarshallSize{{{1*/
-int   FileParam::MarshallSize(){
-	_error_("FileParam is a pointer and cannot be marshalled");
-}
-/*}}}*/
-/*FUNCTION FileParam::Demarshall{{{1*/
-void  FileParam::Demarshall(char** pmarshalled_dataset){
-	_error_("FileParam is a pointer and cannot be marshalled");
-}
-/*}}}*/
-#endif
 /*FUNCTION FileParam::ObjectEnum{{{1*/
 int FileParam::ObjectEnum(void){
@@ -101,12 +83,4 @@
 }
 /*}}}*/
-/*FUNCTION FileParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  FileParam::SetMatlabField(mxArray* dataref){
-	
-	_error_("FileParam is a pointer and cannot be converted into a matlab object");
-}
-#endif
-/*}}}*/
 /*FUNCTION FileParam::UnitConversion{{{1*/
 void  FileParam::UnitConversion(int direction_enum){
Index: /issm/trunk/src/c/objects/Params/FileParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/FileParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/FileParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -41,9 +37,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -81,7 +72,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Params/IntMatParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/IntMatParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/IntMatParam.cpp	(revision 12330)
@@ -78,64 +78,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION IntMatParam::Marshall{{{1*/
-void  IntMatParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of IntMatParam: */
-	enum_value=IntMatParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall IntMatParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(marshalled_dataset,&N,sizeof(N));marshalled_dataset+=sizeof(N);
-	memcpy(marshalled_dataset,value,M*N*sizeof(int));marshalled_dataset+=M*N*sizeof(int);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION IntMatParam::MarshallSize{{{1*/
-int   IntMatParam::MarshallSize(){
-	
-	return sizeof(M)
-		+sizeof(N)
-		+M*N*sizeof(int)
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION IntMatParam::Demarshall{{{1*/
-void  IntMatParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(&N,marshalled_dataset,sizeof(N));marshalled_dataset+=sizeof(N);
-	value=(int*)xmalloc(M*N*sizeof(int));
-	memcpy(value,marshalled_dataset,M*N*sizeof(int));marshalled_dataset+=M*N*sizeof(int);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION IntMatParam::ObjectEnum{{{1*/
 int IntMatParam::ObjectEnum(void){
@@ -172,33 +112,4 @@
 }
 /*}}}*/
-/*FUNCTION IntMatParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  IntMatParam::SetMatlabField(mxArray* dataref){
-
-	char    *name        = NULL;
-	double  *doublearray = NULL;
-	int     *intarray    = NULL;
-	mxArray *pfield      = NULL;
-	mxArray *pfield2     = NULL;
-
-	this->GetParameterValue(&intarray,NULL,NULL);
-	this->GetParameterName(&name);
-
-	/*cast intarray into doublearray for Matlab*/
-	doublearray=(double*)xmalloc(M*N*sizeof(double));
-	for(int i=0;i<M*N;i++)doublearray[i]=(double)intarray[i];
-	xfree((void**)&intarray);
-
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,M);
-	mxSetN(pfield,N);
-	mxSetPr(pfield,doublearray);
-
-	//transpose the matrix, written directly to matlab! from C to matlab.
-	mexCallMATLAB(1,&pfield2, 1, &pfield, "transpose");
-	mxSetField( dataref, 0, name,pfield2);
-}
-#endif
-/*}}}*/
 /*FUNCTION IntMatParam::SetValue{{{1*/
 void  IntMatParam::SetValue(int* intarray,int in_M,int in_N){
Index: /issm/trunk/src/c/objects/Params/IntMatParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/IntMatParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/IntMatParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -43,9 +39,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -83,7 +74,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Params/IntParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/IntParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/IntParam.cpp	(revision 12330)
@@ -62,55 +62,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION IntParam::Marshall{{{1*/
-void  IntParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of IntParam: */
-	enum_value=IntParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall IntParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&value,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION IntParam::MarshallSize{{{1*/
-int   IntParam::MarshallSize(){
-	
-	return sizeof(value)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION IntParam::Demarshall{{{1*/
-void  IntParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(&value,marshalled_dataset,sizeof(value));marshalled_dataset+=sizeof(value);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION IntParam::ObjectEnum{{{1*/
 int IntParam::ObjectEnum(void){
@@ -134,14 +83,4 @@
 }
 /*}}}*/
-/*FUNCTION IntParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  IntParam::SetMatlabField(mxArray* dataref){
-	
-	char* name=NULL;
-	this->GetParameterName(&name);
-	mxSetField( dataref, 0, name,mxCreateDoubleScalar((double)value));
-}
-#endif
-/*}}}*/
 /*FUNCTION IntParam::UnitConversion{{{1*/
 void  IntParam::UnitConversion(int direction_enum){
Index: /issm/trunk/src/c/objects/Params/IntParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/IntParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/IntParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -42,9 +38,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -82,7 +73,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Params/IntVecParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/IntVecParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/IntVecParam.cpp	(revision 12330)
@@ -91,63 +91,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION IntVecParam::Marshall{{{1*/
-void  IntVecParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of IntVecParam: */
-	enum_value=IntVecParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall IntVecParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	if(M)memcpy(marshalled_dataset,values,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION IntVecParam::MarshallSize{{{1*/
-int   IntVecParam::MarshallSize(){
-	
-	return sizeof(M)+
-		+M*sizeof(int)
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION IntVecParam::Demarshall{{{1*/
-void  IntVecParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	if(M) {
-		values=(int*)xmalloc(M*sizeof(int));
-		memcpy(values,marshalled_dataset,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
-	}
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION IntVecParam::ObjectEnum{{{1*/
 int IntVecParam::ObjectEnum(void){
@@ -185,33 +126,4 @@
 }
 /*}}}*/
-/*FUNCTION IntVecParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  IntVecParam::SetMatlabField(mxArray* dataref){
-
-	char    *name      = NULL;
-	double  *doublevec = NULL;
-	int     *intvec    = NULL;
-	mxArray *pfield    = NULL;
-
-	this->GetParameterValue(&intvec,NULL);
-	this->GetParameterName(&name);
-
-	/*cast intvec into doublevec for Matlab*/
-	if(M){
-		doublevec=(double*)xmalloc(M*sizeof(double));
-		for(int i=0;i<M;i++)doublevec[i]=(double)intvec[i];
-	}
-	else doublevec=NULL;
-	xfree((void**)&intvec);
-				
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,M);
-	mxSetN(pfield,1);
-	mxSetPr(pfield,doublevec);
-	
-	mxSetField(dataref, 0, name, pfield);
-}
-#endif
-/*}}}*/
 /*FUNCTION IntVecParam::SetValue{{{1*/
 void  IntVecParam::SetValue(int* intarray,int in_M){
Index: /issm/trunk/src/c/objects/Params/IntVecParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/IntVecParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/IntVecParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -43,9 +39,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -83,7 +74,4 @@
 		
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/Params/MatrixParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/MatrixParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/MatrixParam.cpp	(revision 12330)
@@ -70,93 +70,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION MatrixParam::Marshall{{{1*/
-void  MatrixParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-	int   M,N;
-	double* serial_mat=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of MatrixParam: */
-	enum_value=MatrixParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall MatrixParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	if(value){
-		value->GetSize(&M,&N);
-		serial_mat=value->ToSerial();
-		memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-		memcpy(marshalled_dataset,&N,sizeof(N));marshalled_dataset+=sizeof(N);
-		memcpy(marshalled_dataset,serial_mat,M*N*sizeof(double));marshalled_dataset+=(M*N*sizeof(double));
-	}
-	else{
-		M=0;
-		N=0;
-		memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-		memcpy(marshalled_dataset,&N,sizeof(N));marshalled_dataset+=sizeof(N);
-	}
-	
-	/*Free ressources:*/
-	xfree((void**)&serial_mat);
-
-	/*return:*/
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION MatrixParam::MarshallSize{{{1*/
-int   MatrixParam::MarshallSize(){
-
-	int M=0;
-	int N=0;
-	if(value)value->GetSize(&M,&N);
-			
-	return sizeof(M)+
-		sizeof(N)+
-		M*N*sizeof(double)+
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION MatrixParam::Demarshall{{{1*/
-void  MatrixParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   M,N;
-	double* serial_mat=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	memcpy(&N,marshalled_dataset,sizeof(N));marshalled_dataset+=sizeof(N);
-	if(M!=0 && N!=0){
-		serial_mat=(double*)xmalloc(M*N*sizeof(double));
-		memcpy(serial_mat,marshalled_dataset,M*N*sizeof(double));marshalled_dataset+=(M*N*sizeof(double));
-		value=new Matrix(serial_mat,M,N,.001);
-	}
-	else{
-		value=NULL;
-	}
-
-	/*Free ressources:*/
-	xfree((void**)&serial_mat);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-#endif
 /*FUNCTION MatrixParam::ObjectEnum{{{1*/
 int MatrixParam::ObjectEnum(void){
@@ -190,25 +101,4 @@
 }
 /*}}}*/
-/*FUNCTION MatrixParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  MatrixParam::SetMatlabField(mxArray* dataref){
-	
-	char* name=NULL;
-	int   M,N;
-	double* doublemat=NULL;
-	mxArray* pfield=NULL;
-
-	doublemat=value->ToSerial();
-	value->GetSize(&M,&N);
-	this->GetParameterName(&name);
-				
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,M);
-	mxSetN(pfield,N);
-	mxSetPr(pfield,doublemat);
-	mxSetField( dataref, 0, name, pfield);
-}
-#endif
-/*}}}*/
 /*FUNCTION MatrixParam::SetValue{{{1*/
 void  MatrixParam::SetValue(Matrix* matrix){
Index: /issm/trunk/src/c/objects/Params/MatrixParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/MatrixParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/MatrixParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -42,9 +38,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -82,7 +73,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Params/Param.h
===================================================================
--- /issm/trunk/src/c/objects/Params/Param.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/Param.h	(revision 12330)
@@ -14,8 +14,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -60,7 +56,4 @@
 		virtual void  UnitConversion(int direction_enum)=0;
 		virtual void  GetParameterName(char**pname)=0;
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		virtual void  SetMatlabField(mxArray* dataref)=0;
-		#endif
 };
 #endif
Index: /issm/trunk/src/c/objects/Params/StringArrayParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/StringArrayParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/StringArrayParam.cpp	(revision 12330)
@@ -92,96 +92,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION StringArrayParam::Marshall{{{1*/
-void  StringArrayParam::Marshall(char** pmarshalled_dataset){
-
-	int   i;
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-	int   stringsize;
-	char* string=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of StringArrayParam: */
-	enum_value=StringArrayParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	memcpy(marshalled_dataset,&numstrings,sizeof(numstrings));marshalled_dataset+=sizeof(numstrings);
-	for(i=0;i<numstrings;i++){
-		string=this->value[i];
-		stringsize=strlen(string)+1;
-		
-		memcpy(marshalled_dataset,&stringsize,sizeof(stringsize));marshalled_dataset+=sizeof(stringsize);
-		memcpy(marshalled_dataset,string,stringsize*sizeof(char));marshalled_dataset+=stringsize*sizeof(char);
-	}
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION StringArrayParam::MarshallSize{{{1*/
-int   StringArrayParam::MarshallSize(){
-
-	int i;
-	int marshallsize=0;
-	int stringsize;
-	char* string=NULL;
-
-	marshallsize+=sizeof(numstrings);
-
-	for(i=0;i<numstrings;i++){
-		string=this->value[i];
-		stringsize=strlen(string)+1;
-		marshallsize+=sizeof(stringsize);
-		marshallsize+=stringsize*sizeof(char);
-	}
-	
-	marshallsize+=sizeof(enum_type);
-	marshallsize+=sizeof(int); //sizeof(int) for enum value
-
-	return marshallsize;
-}
-/*}}}*/
-/*FUNCTION StringArrayParam::Demarshall{{{1*/
-void  StringArrayParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-	int   stringsize;
-	char* string=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	memcpy(&numstrings,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-	if(numstrings){
-		this->value=(char**)xmalloc(numstrings*sizeof(char*));
-
-		for(i=0;i<numstrings;i++){
-			memcpy(&stringsize,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-
-			string=(char*)xmalloc(stringsize*sizeof(char));
-			memcpy(string,marshalled_dataset,stringsize*sizeof(char));marshalled_dataset+=stringsize*sizeof(char);
-
-			this->value[i]=string;
-		}
-	}
-	else this->value=NULL;
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION StringArrayParam::ObjectEnum{{{1*/
 int StringArrayParam::ObjectEnum(void){
@@ -236,26 +144,4 @@
 }
 /*}}}*/
-/*FUNCTION StringArrayParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  StringArrayParam::SetMatlabField(mxArray* dataref){
-	
-	int      i;
-	char*    name=NULL;
-	mwSize   dims[2]={0};
-	mxArray* pfield=NULL;
-	
-	this->GetParameterName(&name);
-
-	dims[0]=this->numstrings;
-	dims[1]=1;
-	pfield=mxCreateCellArray(2,dims);
-	for(i=0;i<this->numstrings;i++){
-		char* string=value[i];
-		mxSetCell(pfield,i,mxCreateString(string));
-	}
-	mxSetField( dataref, 0, name,pfield);
-}
-#endif
-/*}}}*/
 /*FUNCTION StringArrayParam::SetValue{{{1*/
 void  StringArrayParam::SetValue(char** stringarray,int M){
Index: /issm/trunk/src/c/objects/Params/StringArrayParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/StringArrayParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/StringArrayParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -44,9 +40,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -84,7 +75,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/Params/StringParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/StringParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/StringParam.cpp	(revision 12330)
@@ -64,68 +64,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION StringParam::Marshall{{{1*/
-void  StringParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-	int   stringsize;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of StringParam: */
-	enum_value=StringParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-
-	/*marshall data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	stringsize=strlen(this->value)+1;
-	
-	memcpy(marshalled_dataset,&stringsize,sizeof(stringsize));marshalled_dataset+=sizeof(stringsize);
-	memcpy(marshalled_dataset,this->value,stringsize*sizeof(char));marshalled_dataset+=stringsize*sizeof(char);
-
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION StringParam::MarshallSize{{{1*/
-int   StringParam::MarshallSize(){
-
-	int stringsize;
-	stringsize=strlen(this->value)+1;
-	
-	return sizeof(int)+
-		stringsize*sizeof(char)+
-		sizeof(enum_type)+
-		sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION StringParam::Demarshall{{{1*/
-void  StringParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-	int   stringsize;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	memcpy(&stringsize,marshalled_dataset,sizeof(int));marshalled_dataset+=sizeof(int);
-	
-	this->value=(char*)xmalloc(stringsize*sizeof(char));
-	memcpy(this->value,marshalled_dataset,stringsize*sizeof(char));marshalled_dataset+=stringsize*sizeof(char);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION StringParam::ObjectEnum{{{1*/
 int StringParam::ObjectEnum(void){
@@ -164,15 +100,4 @@
 }
 /*}}}*/
-/*FUNCTION StringParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  StringParam::SetMatlabField(mxArray* dataref){
-	
-	char* name=NULL;
-
-	this->GetParameterName(&name);
-	mxSetField( dataref, 0, name, mxCreateString(value));
-}
-#endif
-/*}}}*/
 /*FUNCTION StringParam::SetValue{{{1*/
 void  StringParam::SetValue(char* string){
Index: /issm/trunk/src/c/objects/Params/StringParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/StringParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/StringParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -42,9 +38,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -82,7 +73,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Params/VectorParam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Params/VectorParam.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/VectorParam.cpp	(revision 12330)
@@ -72,88 +72,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION VectorParam::Marshall{{{1*/
-void  VectorParam::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_value=0;
-	int   M;
-	double* serial_value=NULL;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum value of VectorParam: */
-	enum_value=VectorParamEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
-	
-	/*marshall VectorParam data: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	if(value){
-		value->GetSize(&M);
-		serial_value=value->ToMPISerial();
-		memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-		memcpy(marshalled_dataset,serial_value,M*sizeof(double));marshalled_dataset+=(M*sizeof(double));
-	}
-	else{
-		M=0;
-		memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
-	}
-	/*Free ressources:*/
-	xfree((void**)&serial_value);
-
-	/*return:*/
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-/*FUNCTION VectorParam::MarshallSize{{{1*/
-int   VectorParam::MarshallSize(){
-
-	int M=0;
-	if(value)value->GetSize(&M);
-
-	return sizeof(M)+M*sizeof(double)
-		+sizeof(enum_type)+
-		+sizeof(int); //sizeof(int) for enum value
-}
-/*}}}*/
-/*FUNCTION VectorParam::Demarshall{{{1*/
-void  VectorParam::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-	double* serial_vec=NULL;
-	int   M;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*data: */
-	
-	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
-	if(M){
-		serial_vec=(double*)xmalloc(M*sizeof(double));
-		memcpy(serial_vec,marshalled_dataset,M*sizeof(double));marshalled_dataset+=(M*sizeof(double));
-
-		value=new Vector(serial_vec,M);
-	}
-	else{
-		value=NULL;
-	}
-
-	/*Free ressources:*/
-	xfree((void**)&serial_vec);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-}
-/*}}}*/
-#endif
 /*FUNCTION VectorParam::ObjectEnum{{{1*/
 int VectorParam::ObjectEnum(void){
@@ -188,26 +104,4 @@
 }
 /*}}}*/
-/*FUNCTION VectorParam::SetMatlabField{{{1*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-void  VectorParam::SetMatlabField(mxArray* dataref){
-
-	mxArray* pfield=NULL;
-	char* name=NULL;
-	double* doublevec=NULL;
-	int M;
-	
-	doublevec=value->ToMPISerial();
-	value->GetSize(&M);
-	this->GetParameterName(&name);
-	
-	pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(pfield,M);
-	mxSetN(pfield,1);
-	mxSetPr(pfield,doublevec);
-	
-	mxSetField( dataref, 0, name, pfield);
-}
-#endif
-/*}}}*/
 /*FUNCTION VectorParam::SetValue{{{1*/
 void  VectorParam::SetValue(Vector* vector){
Index: /issm/trunk/src/c/objects/Params/VectorParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/VectorParam.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Params/VectorParam.h	(revision 12330)
@@ -13,8 +13,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
 #endif
 
@@ -42,9 +38,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -82,7 +73,4 @@
 
 		void GetParameterName(char**pname);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		void  SetMatlabField(mxArray* dataref);
-		#endif
 
 		/*}}}*/
Index: /issm/trunk/src/c/objects/Patch.cpp
===================================================================
--- /issm/trunk/src/c/objects/Patch.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Patch.cpp	(revision 12330)
@@ -120,13 +120,15 @@
 	int         node_numrows;
 	double     *total_values  = NULL;
+	#ifdef _HAVE_MPI_
 	MPI_Status  status;
+	#endif
 
-	#ifdef _SERIAL_
-	return; //nothing to be done
-	#endif
-	
 	/*First, figure out total number of rows combining all the cpus: */
+	#ifdef _HAVE_MPI_
 	MPI_Reduce(&this->numrows,&total_numrows,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&total_numrows,1,MPI_INT,0,MPI_COMM_WORLD);
+	#else
+	total_numrows=this->numrows;
+	#endif
 
 	/*return if patch empty*/
@@ -144,4 +146,5 @@
 
 	/*Now, ask other nodes to send their values: */
+	#ifdef _HAVE_MPI_
 	for (i=1;i<num_procs;i++){
 		if (my_rank==i){ 
@@ -155,4 +158,5 @@
 		}
 	}	
+	#endif
 
 	/*Now, node 0 has total_values, of size total_numrows*this->numcols. Update the fields in the patch, to reflect this new 
@@ -163,7 +167,9 @@
 		this->values=total_values;
 	}
+	#ifdef _HAVE_MPI_
 	else{
 		this->numrows=0;
 		xfree((void**)&this->values);
 	}
+	#endif
 }/*}}}*/
Index: /issm/trunk/src/c/objects/Patch.h
===================================================================
--- /issm/trunk/src/c/objects/Patch.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Patch.h	(revision 12330)
@@ -34,5 +34,5 @@
 		int     maxnodes;    // maxnodes corresponds to the largest amout of nodes on a given element, determined by the interpolation type.
 		
-		double* values;  //result values
+		IssmDouble* values;  //result values
 
 		Patch();
@@ -40,5 +40,5 @@
 		~Patch();
 		void fillelementinfo(int row, int element_id, int* vertices_ids, int num_vertices);
-		void fillresultinfo(int row,int enum_type,int step, double time, int interpolation, double* nodal_values, int num_nodes);
+		void fillresultinfo(int row,int enum_type,int step, IssmDouble time, int interpolation, IssmDouble* nodal_values, int num_nodes);
 		void Gather(void);
 
Index: /issm/trunk/src/c/objects/Segment.cpp
===================================================================
--- /issm/trunk/src/c/objects/Segment.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Segment.cpp	(revision 12330)
@@ -71,22 +71,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION Segment::Marshall{{{1*/
-void  Segment::Marshall(char** pmarshalled_dataset){
-
-	_error_(" not supported yet!");
-}
-/*}}}*/
-/*FUNCTION Segment::MarshallSize{{{1*/
-int   Segment::MarshallSize(){
-	_error_(" not supported yet!");
-}
-/*}}}*/
-/*FUNCTION Segment::Demarshall{{{1*/
-void  Segment::Demarshall(char** pmarshalled_dataset){
-	_error_(" not supported yet!");
-}
-/*}}}*/
-#endif
 /*FUNCTION Segment::ObjectEnum{{{1*/
 int Segment::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Segment.h
===================================================================
--- /issm/trunk/src/c/objects/Segment.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Segment.h	(revision 12330)
@@ -15,12 +15,12 @@
 	public:
 		int eid;
-		double x1;
-		double y1;
-		double x2;
-		double y2;
+		IssmDouble x1;
+		IssmDouble y1;
+		IssmDouble x2;
+		IssmDouble y2;
 
 		/*Segment constructors, destructors {{{1*/
 		Segment();
-		Segment(int eid,double x1,double y1, double x2, double y2);
+		Segment(int eid,IssmDouble x1,IssmDouble y1, IssmDouble x2, IssmDouble y2);
 		~Segment();
 		/*}}}*/
@@ -30,9 +30,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
Index: /issm/trunk/src/c/objects/Update.h
===================================================================
--- /issm/trunk/src/c/objects/Update.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Update.h	(revision 12330)
@@ -15,17 +15,17 @@
 	public:
 
-		virtual void  InputUpdateFromVector(double* vector, int name, int type)=0;
+		virtual void  InputUpdateFromVector(IssmDouble* vector, int name, int type)=0;
 		virtual void  InputUpdateFromVector(int* vector, int name, int type)=0;
 		virtual void  InputUpdateFromVector(bool* vector, int name, int type)=0; 
 		#ifdef _HAVE_DAKOTA_
-		virtual void  InputUpdateFromMatrixDakota(double* matrix, int rows, int ncols, int name, int type)=0;
-		virtual void  InputUpdateFromVectorDakota(double* vector, int name, int type)=0;
+		virtual void  InputUpdateFromMatrixDakota(IssmDouble* matrix, int rows, int ncols, int name, int type)=0;
+		virtual void  InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type)=0;
 		virtual void  InputUpdateFromVectorDakota(int* vector, int name, int type)=0;
 		virtual void  InputUpdateFromVectorDakota(bool* vector, int name, int type)=0;
 		#endif
-		virtual void  InputUpdateFromConstant(double constant, int name)=0;
+		virtual void  InputUpdateFromConstant(IssmDouble constant, int name)=0;
 		virtual void  InputUpdateFromConstant(int constant, int name)=0;
 		virtual void  InputUpdateFromConstant(bool constant, int name)=0;
-		virtual void  InputUpdateFromSolution(double* solution)=0;
+		virtual void  InputUpdateFromSolution(IssmDouble* solution)=0;
 		virtual void  InputUpdateFromIoModel(int index, IoModel* iomodel)=0;
 
Index: /issm/trunk/src/c/objects/Vertex.cpp
===================================================================
--- /issm/trunk/src/c/objects/Vertex.cpp	(revision 12329)
+++ /issm/trunk/src/c/objects/Vertex.cpp	(revision 12330)
@@ -92,78 +92,4 @@
 }
 /*}}}*/
-#ifdef _SERIAL_
-/*FUNCTION Vertex::Marshall {{{1*/
-void  Vertex::Marshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   enum_type=0;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*get enum type of Vertex: */
-	enum_type=VertexEnum;
-
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-
-	/*marshall Vertex data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&sid,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(marshalled_dataset,&x,sizeof(x));marshalled_dataset+=sizeof(x);
-	memcpy(marshalled_dataset,&y,sizeof(y));marshalled_dataset+=sizeof(y);
-	memcpy(marshalled_dataset,&z,sizeof(z));marshalled_dataset+=sizeof(z);
-	memcpy(marshalled_dataset,&sigma,sizeof(sigma));marshalled_dataset+=sizeof(sigma);
-	memcpy(marshalled_dataset,&connectivity,sizeof(connectivity));marshalled_dataset+=sizeof(connectivity);
-	memcpy(marshalled_dataset,&dof,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(marshalled_dataset,&clone,sizeof(clone));marshalled_dataset+=sizeof(clone);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-/*FUNCTION Vertex::MarshallSize {{{1*/
-int   Vertex::MarshallSize(){
-	
-	return sizeof(id)+
-		sizeof(sid)+
-		sizeof(x)+
-		sizeof(y)+
-		sizeof(z)+
-		sizeof(sigma)+
-		sizeof(connectivity)+
-		sizeof(dof)+
-		sizeof(clone)+
-		+sizeof(int); //sizeof(int) for enum type
-}
-/*}}}*/
-/*FUNCTION Vertex::Demarshall {{{1*/
-void  Vertex::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=NULL;
-	int   i;
-
-	/*recover marshalled_dataset: */
-	marshalled_dataset=*pmarshalled_dataset;
-
-	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
-	 *object data (thanks to DataSet::Demarshall):*/
-
-	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&sid,marshalled_dataset,sizeof(sid));marshalled_dataset+=sizeof(sid);
-	memcpy(&x,marshalled_dataset,sizeof(x));marshalled_dataset+=sizeof(x);
-	memcpy(&y,marshalled_dataset,sizeof(y));marshalled_dataset+=sizeof(y);
-	memcpy(&z,marshalled_dataset,sizeof(z));marshalled_dataset+=sizeof(z);
-	memcpy(&sigma,marshalled_dataset,sizeof(sigma));marshalled_dataset+=sizeof(sigma);
-	memcpy(&connectivity,marshalled_dataset,sizeof(connectivity));marshalled_dataset+=sizeof(connectivity);
-	memcpy(&dof,marshalled_dataset,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(&clone,marshalled_dataset,sizeof(clone));marshalled_dataset+=sizeof(clone);
-
-	/*return: */
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}*/
-#endif
 /*FUNCTION Vertex::ObjectEnum{{{1*/
 int Vertex::ObjectEnum(void){
Index: /issm/trunk/src/c/objects/Vertex.h
===================================================================
--- /issm/trunk/src/c/objects/Vertex.h	(revision 12329)
+++ /issm/trunk/src/c/objects/Vertex.h	(revision 12330)
@@ -25,8 +25,8 @@
 		int    id;
 		int    sid;            //sid for "serial" id, ie the rank of this vertex in the vertices dataset, if the dataset was serial on 1 cpu.
-		double x;
-		double y;
-		double z;
-		double sigma;          //sigma coordinate: (z-bed)/thickness
+		IssmDouble x;
+		IssmDouble y;
+		IssmDouble z;
+		IssmDouble sigma;          //sigma coordinate: (z-bed)/thickness
 		int    connectivity;   //number of vertices connected to this vertex
 
@@ -37,6 +37,6 @@
 		/*Vertex constructors, destructors {{{1*/
 		Vertex();
-		Vertex(int id, int sid,double x, double y, double z, double sigma, int connectivity); 
-		void Init(int id, int sid, double x, double y, double z, double sigma,int connectivity);
+		Vertex(int id, int sid,IssmDouble x, IssmDouble y, IssmDouble z, IssmDouble sigma, int connectivity); 
+		void Init(int id, int sid, IssmDouble x, IssmDouble y, IssmDouble z, IssmDouble sigma,int connectivity);
 		Vertex(int id, int sid, int i, IoModel* iomodel);
 		~Vertex();
@@ -47,9 +47,4 @@
 		int   Id(); 
 		int   MyRank();
-		#ifdef _SERIAL_
-		void  Marshall(char** pmarshalled_dataset);
-		int   MarshallSize();
-		void  Demarshall(char** pmarshalled_dataset);
-		#endif
 		int   ObjectEnum();
 		Object* copy();
@@ -65,5 +60,5 @@
 		int   Sid(void); 
 		int   Connectivity(void); 
-		void  UpdatePosition(Vector* vz,Parameters* parameters,double* thickness,double* bed);
+		void  UpdatePosition(Vector* vz,Parameters* parameters,IssmDouble* thickness,IssmDouble* bed);
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/objects.h
===================================================================
--- /issm/trunk/src/c/objects/objects.h	(revision 12329)
+++ /issm/trunk/src/c/objects/objects.h	(revision 12330)
@@ -170,6 +170,15 @@
 #include "./Bamg/Mesh.h"
 #include "./Bamg/Geometry.h"
-#include "./Bamg/QuadTree.h"
+#include "./Bamg/BamgQuadtree.h"
 #include "./Bamg/SetOfE4.h"
 
+/*Kriging*/
+#include "./Kriging/Variogram.h"
+#include "./Kriging/GaussianVariogram.h"
+#include "./Kriging/ExponentialVariogram.h"
+#include "./Kriging/SphericalVariogram.h"
+#include "./Kriging/PowerVariogram.h"
+#include "./Kriging/Quadtree.h"
+#include "./Kriging/Observation.h"
+
 #endif
Index: /issm/trunk/src/c/python/include/python_macros.h
===================================================================
--- /issm/trunk/src/c/python/include/python_macros.h	(revision 12330)
+++ /issm/trunk/src/c/python/include/python_macros.h	(revision 12330)
@@ -0,0 +1,82 @@
+/* \file python_macros.h
+ * \brief: macros used for the python bindings
+ */
+
+#ifndef _PYTHON_MACROS_H_
+#define _PYTHON_MACROS_H_
+
+/*Header {{{1*/
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+/*}}}*/
+
+#ifdef _HAVE_PYTHON_
+/* MODULEBOOT/MODULEEND {{{1*/
+
+/*The following macros hide the error exception handling in a matlab module. Just put 
+ * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions 
+ * will be trapped. Really nifty!*/
+
+#define MODULEBOOT(); ModuleBoot();  \
+	PyObject* output = PyTuple_New(NLHS); if (!output) return NULL;\
+			int nrhs = (int)PyTuple_Size(args);
+
+#define MODULEEND();  ModuleEnd(); \
+						 return output;
+//}}}
+#if _PYTHON_MAJOR_ >=3
+/* WRAPPER 3.2 {{{1*/
+#define WRAPPER(modulename,...)  \
+\
+static PyObject* modulename(PyObject* self,PyObject* args);\
+static PyMethodDef modulename##_funcs[] = {\
+	{#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\
+	{NULL,NULL,0,NULL}\
+};\
+\
+static struct PyModuleDef modulename##module= {\
+	PyModuleDef_HEAD_INIT,\
+	#modulename,   /* name of module */\
+	NULL, /* module documentation, may be NULL */\
+	-1,       /* size of per-interpreter state of the module,\
+				 or -1 if the module keeps state in global variables. */\
+	modulename##_funcs\
+};\
+\
+PyMODINIT_FUNC PyInit_##modulename(void){\
+\
+	import_array();\
+	return PyModule_Create(&modulename##module);\
+}\
+\
+static PyObject* modulename(PyObject* self,PyObject* args)
+/*}}}*/
+#else
+/* WRAPPER 2.7 {{{1*/
+#define WRAPPER(modulename,...)  \
+\
+static PyObject* modulename(PyObject* self,PyObject* args);\
+static PyMethodDef modulename##_funcs[] = {\
+	{#modulename, (PyCFunction)modulename, METH_VARARGS, ""},\
+	{NULL,NULL,0,NULL}\
+};\
+\
+PyMODINIT_FUNC init##modulename(void){\
+\
+	import_array();\
+	(void) Py_InitModule(#modulename, modulename##_funcs);\
+}\
+\
+static PyObject* modulename(PyObject* self,PyObject* args)
+/*}}}*/
+#endif
+/* CHECKARGUMENTS {{{1*/
+#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer)
+/*}}}*/
+#endif
+
+#endif
Index: /issm/trunk/src/c/python/io/CheckNumPythonArguments.cpp
===================================================================
--- /issm/trunk/src/c/python/io/CheckNumPythonArguments.cpp	(revision 12330)
+++ /issm/trunk/src/c/python/io/CheckNumPythonArguments.cpp	(revision 12330)
@@ -0,0 +1,36 @@
+/*!\file CheckNumPythonArguments.cpp:
+ * \brief: check number of arguments and report an usage error message.
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#define NO_IMPORT
+
+#include "../../toolkits/toolkits.h"
+#include "../../shared/Exceptions/exceptions.h"
+#include "../../include/include.h"
+
+int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void )){
+
+	Py_ssize_t size=0;
+
+	/*figure out size of tuple in input: */
+	size=PyTuple_Size(inputs);
+	
+	/*check on requested size: */
+	if (size==0){
+		function();
+		_error_("usage: see above");
+	}
+	else if (size!=NRHS ) {
+		function(); 
+		_error_("usage error.");
+	}
+	return 1;
+}
Index: /issm/trunk/src/c/python/io/FetchPythonData.cpp
===================================================================
--- /issm/trunk/src/c/python/io/FetchPythonData.cpp	(revision 12330)
+++ /issm/trunk/src/c/python/io/FetchPythonData.cpp	(revision 12330)
@@ -0,0 +1,137 @@
+/*\file FetchData.cpp:
+ * \brief: general I/O interface to fetch data in python
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#define NO_IMPORT
+
+#include "../../toolkits/toolkits.h"
+#include "../../include/include.h"
+#include "../../shared/shared.h"
+
+/*Primitive data types*/
+/*FUNCTION FetchData(double* pscalar,PyObject* py_float){{{1*/
+void FetchData(double* pscalar,PyObject* py_float){
+
+	double scalar;
+
+	/*return internal value: */
+	scalar=PyFloat_AsDouble(py_float);
+
+	/*output: */
+	*pscalar=scalar;
+}
+/*}}}*/
+/*FUNCTION FetchData(int* pinteger,PyObject* py_long){{{1*/
+void FetchData(int* pinteger, PyObject* py_long){
+
+	int integer;
+
+	/*return internal value: */
+	integer=(int)PyLong_AsLong(py_long);
+
+	/*output: */
+	*pinteger=integer;
+}
+/*}}}*/
+/*FUNCTION FetchData(bool* pboolean,PyObject* py_boolean){{{1*/
+void FetchData(bool* pboolean,PyObject* py_boolean){
+
+	bool boolean;
+	
+	/*check this is indeed a subtype of long type: */
+	if(!PyBool_Check(py_boolean))_error_("expecting a boolean in input!");
+
+	/*extract boolean: */
+	boolean=(bool)PyLong_AsLong(py_boolean);
+
+	/*simple copy: */
+	*pboolean=boolean;
+	
+}
+/*}}}*/
+/*FUNCTION FetchData(double** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{1*/
+void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_matrix){
+
+	/*output: */
+	double* matrix=NULL;
+	int M,N;
+	int ndim;
+	npy_intp*  dims=NULL;
+
+	/*retrive dimensions: */
+	ndim=PyArray_NDIM((const PyArrayObject*)py_matrix);
+	if(ndim!=2)_error_("expecting an MxN matrix in input!");
+	dims=PyArray_DIMS((PyArrayObject*)py_matrix);
+	M=dims[0]; N=dims[1];
+	
+	/*retrieve internal value: */
+	matrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);
+
+	/*output: */
+	if(pM)*pM=M;
+	if(pN)*pN=N;
+	if(pmatrix)*pmatrix=matrix;
+}
+/*}}}*/
+/*FUNCTION FetchData(double** pvector,int* pM, PyObject* py_vector){{{1*/
+void FetchData(double** pvector,int* pM,PyObject* py_vector){
+
+	/*output: */
+	double* vector=NULL;
+	int M;
+	int ndim;
+	npy_intp*  dims=NULL;
+
+	/*retrive dimensions: */
+	ndim=PyArray_NDIM((const PyArrayObject*)py_vector);
+	if(ndim!=1)_error_("expecting an Mx1 vector in input!");
+	dims=PyArray_DIMS((PyArrayObject*)py_vector);
+	M=dims[0]; 
+	
+	/*retrieve internal value: */
+	vector=(double*)PyArray_DATA((PyArrayObject*)py_vector);
+
+	/*output: */
+	if(pM)*pM=M;
+	if(pvector)*pvector=vector;
+}
+/*}}}*/
+
+/*Python version dependent: */
+#if _PYTHON_MAJOR_ >= 3 
+/*FUNCTION FetchData(char** pstring,PyObject* py_unicode){{{1*/
+void FetchData(char** pstring,PyObject* py_unicode){
+
+	PyObject* py_bytes;
+	char* string=NULL;
+
+	
+	/*convert to bytes format: */
+	PyUnicode_FSConverter(py_unicode,&py_bytes);
+
+	/*convert from bytes to string: */
+	string=PyBytes_AS_STRING(py_bytes);
+	
+	*pstring=string;
+}
+/*}}}*/
+#else
+/*FUNCTION FetchData(char** pstring,PyObject* py_string){{{1*/
+void FetchData(char** pstring,PyObject* py_string){
+
+	char* string=NULL;
+
+	/*extract internal string: */
+	string=PyString_AsString(py_string);
+	
+	*pstring=string;
+}
+/*}}}*/
+#endif
Index: /issm/trunk/src/c/python/io/WritePythonData.cpp
===================================================================
--- /issm/trunk/src/c/python/io/WritePythonData.cpp	(revision 12330)
+++ /issm/trunk/src/c/python/io/WritePythonData.cpp	(revision 12330)
@@ -0,0 +1,78 @@
+/* \file WriteData.c:
+ * \brief: general interface for writing data
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#define NO_IMPORT
+
+#include "../../toolkits/toolkits.h"
+#include "../../include/include.h"
+#include "../../modules/modules.h"
+#include "../../Container/Container.h"
+#include "../../shared/shared.h"
+#include "../../io/io.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+
+
+/*FUNCTION WriteData(PyObject* py_tuple,int index,char* string){{{1*/
+void WriteData(PyObject* py_tuple, int index, char* string){
+	
+	PyTuple_SetItem(py_tuple, index, PyUnicode_FromString(string));
+
+}
+/*}}}*/
+/*FUNCTION WriteData(PyObject* tuple,int index,Matrix* matrix){{{1*/
+void WriteData(PyObject* tuple,int index,Matrix* matrix){
+	
+	int M,N;
+	double* buffer=NULL;
+	npy_intp dims[2]={0,0};
+	PyObject* array=NULL;
+	
+	buffer=matrix->ToSerial();
+	matrix->GetSize(&M,&N);
+	dims[0]=(npy_intp)M;
+	dims[1]=(npy_intp)N;
+	array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,buffer);
+	
+	PyTuple_SetItem(tuple, index, array);
+
+
+}
+/*FUNCTION WriteData(PyObject* py_tuple,int index,Vector* vector){{{1*/
+void WriteData(PyObject* tuple,int index,Vector* vector){
+	
+	int M;
+	double* buffer=NULL;
+	npy_intp dim=10;
+	PyObject* array=NULL;
+	
+	buffer=vector->ToMPISerial();
+	vector->GetSize(&M);
+	dim=(npy_intp)M;
+	array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer);
+	
+	PyTuple_SetItem(tuple, index, array);
+
+
+}
+/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index, double* matrix, int M, int N){{{1*/
+void WriteData(PyObject* tuple, int index, double* matrix, int M,int N){
+	
+	npy_intp dims[2]={0,0};
+	PyObject* array=NULL;
+	
+	dims[0]=(npy_intp)M;
+	dims[1]=(npy_intp)N;
+	array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,matrix);
+	
+	PyTuple_SetItem(tuple, index, array);
+
+}
Index: /issm/trunk/src/c/python/io/pythonio.h
===================================================================
--- /issm/trunk/src/c/python/io/pythonio.h	(revision 12330)
+++ /issm/trunk/src/c/python/io/pythonio.h	(revision 12330)
@@ -0,0 +1,56 @@
+/*\file pythonio.h
+ *\brief: I/O for ISSM in python mode
+ */
+
+#ifndef _PYTHON_IO_H_
+#define _PYTHON_IO_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif 
+
+
+#include "../../objects/objects.h"
+#include "../../Container/Container.h"
+#include "../../include/include.h"
+
+class DataSet;
+class Parameters;
+
+//void WriteData(PyObject* py_tuple,DataSet* dataset);
+//void WriteData(PyObject* py_tuple,int*    matrix, int M,int N);
+//void WriteData(PyObject* py_tuple,double* vector, int M);
+//void WriteData(PyObject* py_tuple,int integer);
+//void WriteData(PyObject* py_tuple,bool boolean);
+//void WriteData(PyObject* py_tuple,double scalar);
+//void WriteData(DataHandle* py_tuple,Parameters* parameters);
+void WriteData(PyObject* py_tuple, int index, double* matrix, int M,int N);
+void WriteData(PyObject* py_tuple, int index, char* string);
+void WriteData(PyObject* py_tuple, int index, Matrix* matrix);
+void WriteData(PyObject* py_tuple, int index, Vector* vector);
+
+
+//void FetchData(DataSet** pdataset,PyObject* py_ref);
+//void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,PyObject* py_ref);
+//void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_ref);
+//void FetchData(bool** pmatrix,int* pM,int *pN,PyObject* py_ref);
+//void FetchData(bool** pmatrix,int* pnumel,int* pndims,int** psize,PyObject* py_ref);
+//void FetchData(Matrix** pmatrix,PyObject* py_ref);
+//void FetchData(int** pvector,int* pM,PyObject* py_ref);
+//void FetchData(float** pvector,int* pM,PyObject* py_ref);
+//void FetchData(bool** pvector,int* pM,PyObject* py_ref);
+//void FetchData(Vector** pvector,PyObject* py_ref);
+//void FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,PyObject* py_ref);
+//void FetchData(Parameters** pparameters, DataHandle py_ref);
+void FetchData(double** pvector,int* pM,PyObject* py_ref);
+void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_array);
+void FetchData(char** pstring,PyObject* py_unicode);
+void FetchData(double* pscalar,PyObject* py_float);
+void FetchData(int* pinteger,PyObject* py_long);
+void FetchData(bool* pbool,PyObject* py_boolean);
+
+int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void ));
+
+#endif	/* _IO_H_ */
Index: /issm/trunk/src/c/python/python-binding.h
===================================================================
--- /issm/trunk/src/c/python/python-binding.h	(revision 12330)
+++ /issm/trunk/src/c/python/python-binding.h	(revision 12330)
@@ -0,0 +1,7 @@
+#ifndef _PYTHON_BINDING_H_
+#define _PYTHON_BINDING_H_
+
+#include "./io/pythonio.h"
+#include "./include/python_macros.h"
+
+#endif
Index: /issm/trunk/src/c/shared/Alloc/alloc.cpp
===================================================================
--- /issm/trunk/src/c/shared/Alloc/alloc.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Alloc/alloc.cpp	(revision 12330)
@@ -19,8 +19,4 @@
 #endif
 
-#if defined(_SERIAL_) && defined(_HAVE_MATLAB_)
-#include "mex.h"
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
@@ -37,11 +33,6 @@
 	if(!size)_error_(" attempting to 0 size allocation!");
 
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	/* Use the matlab api to do the allocation: */
-	memptr=mxMalloc(size);
-	#else
 	/* Use the c library to do the allocation: */
 	memptr=malloc(size);
-	#endif
 	if(!memptr) _error_("memory allocation failed!");
 
@@ -55,11 +46,6 @@
 	if(!size)_error_("attempting to 0 size allocation!");
 
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	/* Use the matlab api to do the allocation: */
-	memptr=mxCalloc(n,size);
-	#else
 	/* Use the c library to do the allocation: */
 	memptr=calloc(n,size);
-	#endif
 	if(!memptr) _error_("memory allocation failed!");
 
@@ -70,9 +56,5 @@
 
 	if (pv && *pv){
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-			mxFree(*pv);
-		#else
-			free(*pv);
-		#endif
+		free(*pv);
 
 		*pv=NULL;
@@ -83,16 +65,8 @@
 	
 	if (pv && *pv){
-		#ifdef _PARALLEL_ 
 		/*There is no mxDelete in the Matlab API -> using delete trips up Matlab. So we 
 		 * don't actually free memory in Matlab, we let the memory manager do that. We only
 		 * free in parallel: */
 		delete *pv;
-		#else
-		/*Actually, still get rid of internal Petsc matrix. Quick fix until Matlab handles C++ 
-		 * correctly: */
-		#ifdef _HAVE_PETSC_
-			MatFree(&(*pv)->matrix);
-		#endif
-		#endif
 		*pv=NULL;
 	}
@@ -102,16 +76,8 @@
 
 	if (pv && *pv){
-		#ifdef _PARALLEL_ 
 		/*There is no mxDelete in the Matlab API -> using delete trips up Matlab. So we 
 		 * don't actually free memory in Matlab, we let the memory manager do that. We only
 		 * free in parallel: */
 		delete *pv;
-		#else
-		/*Actually, still get rid of internal Petsc vector. Quick fix until Matlab handles C++ 
-		 * correctly: */
-		#ifdef _HAVE_PETSC_
-			VecFree(&(*pv)->vector);
-		#endif
-		#endif
 		*pv=NULL;
 	}
@@ -124,10 +90,5 @@
 	
 	if(!size)_error_("attempting to realloc to zero");
-
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-	value = (void*)mxRealloc(pv,size);
-	#else
 	value = (void*)realloc(pv,size);
-	#endif
 
 	if (value == NULL) {
Index: /issm/trunk/src/c/shared/Alloc/alloc_module.cpp
===================================================================
--- /issm/trunk/src/c/shared/Alloc/alloc_module.cpp	(revision 12330)
+++ /issm/trunk/src/c/shared/Alloc/alloc_module.cpp	(revision 12330)
@@ -0,0 +1,41 @@
+/* \file alloc_module.h
+ */
+
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile without HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include  "./alloc_module.h"
+#include "../Exceptions/exceptions.h"
+#include "../../include/include.h"
+#include "../../objects/objects.h"
+
+void xdelete_module(Matrix** pv){
+	
+	if (pv && *pv){
+		/*Actually, still get rid of internal Petsc matrix. Quick fix until Matlab handles C++ 
+		 * correctly: */
+		#ifdef _HAVE_PETSC_
+			MatFree(&(*pv)->matrix);
+		#endif
+		*pv=NULL;
+	}
+}
+
+void xdelete_module(Vector** pv){
+
+	if (pv && *pv){
+		/*Actually, still get rid of internal Petsc vector. Quick fix until Matlab handles C++ 
+		 * correctly: */
+		#ifdef _HAVE_PETSC_
+			VecFree(&(*pv)->vector);
+		#endif
+		*pv=NULL;
+	}
+}
Index: /issm/trunk/src/c/shared/Alloc/alloc_module.h
===================================================================
--- /issm/trunk/src/c/shared/Alloc/alloc_module.h	(revision 12330)
+++ /issm/trunk/src/c/shared/Alloc/alloc_module.h	(revision 12330)
@@ -0,0 +1,11 @@
+/* \file alloc.h
+ */
+
+#ifndef _ALLOC_MODULE_H_
+#define _ALLOC_MODULE_H_
+class Matrix;
+class Vector;
+void xdelete_module(Matrix** pvptr);
+void xdelete_module(Vector** pvptr);
+
+#endif
Index: /issm/trunk/src/c/shared/Alloc/xNewDelete.h
===================================================================
--- /issm/trunk/src/c/shared/Alloc/xNewDelete.h	(revision 12330)
+++ /issm/trunk/src/c/shared/Alloc/xNewDelete.h	(revision 12330)
@@ -0,0 +1,25 @@
+/* \file xNewDelete.h
+ * \brief: header file for templated new/delete checking for non-null pointers
+ */
+
+#ifndef _XNEWDELETE_H_
+#define _XNEWDELETE_H_
+
+#include <cassert>
+
+template <class T> 
+T* xNew(unsigned int size) {
+  T* aT_p=new T[size];
+  assert(aT_p);
+  return aT_p;
+};
+
+template <class T>
+void xDelete(T*& aT_p) { 
+  if (aT_p) 
+    delete []aT_p;
+  aT_p=0;
+};
+
+#endif
+
Index: /issm/trunk/src/c/shared/Elements/elements.h
===================================================================
--- /issm/trunk/src/c/shared/Elements/elements.h	(revision 12329)
+++ /issm/trunk/src/c/shared/Elements/elements.h	(revision 12330)
@@ -47,4 +47,15 @@
 	printf("\n");
 }
+inline void printbinary(int n) {
+	unsigned int i=1L<<(sizeof(n)*8-1);
+
+	while (i>0) {
+		if (n&i)
+		 printf("1");
+		else
+		 printf("0");
+		i>>=1;
+	}
+}
 
 #endif //ifndef _SHARED_ELEMENTS_H_
Index: /issm/trunk/src/c/shared/Exceptions/Exceptions.cpp
===================================================================
--- /issm/trunk/src/c/shared/Exceptions/Exceptions.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Exceptions/Exceptions.cpp	(revision 12330)
@@ -11,7 +11,4 @@
 #include "../shared.h"
 #include "../../include/include.h"
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "mex.h"
-#endif
 
 ErrorException::ErrorException(const string &what_arg){
@@ -32,4 +29,8 @@
 
 ErrorException::~ErrorException() throw(){
+	extern int num_procs;
+	/*We want the report only for matlab modules, otherwise we get twice the report
+	 * We assume that if num_procs==1, it is a module (FIXME)*/
+	if(num_procs==1) this->Report();
 }
 
@@ -40,4 +41,5 @@
 void ErrorException::Report(){
 	extern int my_rank;
+	extern int num_procs;
 
 	if (function_name=="" || file_line==0){ //WINDOWS
@@ -45,11 +47,12 @@
 	}
 	else{
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-			mexErrMsgTxt(exprintf("\n??? Error using ==> %s at %i\n%s error message: %s\n",
-							file_name.c_str(),file_line,function_name.c_str(),what()));
-		#else
+		if(num_procs==1){
+			printf("\n??? Error using ==> %s:%i\n",file_name.c_str(),file_line);
+			printf("%s error message: %s\n\n",function_name.c_str(),what());
+		}
+		else{
 			printf("\n[%i] ??? Error using ==> %s:%i\n",my_rank,file_name.c_str(),file_line);
 			printf("[%i] %s error message: %s\n\n",my_rank,function_name.c_str(),what());
-		#endif
+		}
 	}
 	return;
Index: /issm/trunk/src/c/shared/Exceptions/exceptions.h
===================================================================
--- /issm/trunk/src/c/shared/Exceptions/exceptions.h	(revision 12329)
+++ /issm/trunk/src/c/shared/Exceptions/exceptions.h	(revision 12330)
@@ -23,11 +23,8 @@
 
 	public:
-
 	ErrorException(const string &what_arg); //for windows
 	ErrorException(string what_file,string what_function,int what_line,string what_arg);//UNIX
 	~ErrorException() throw();
-
 	virtual const char *what() const throw();
-
 	void Report();
 
Index: /issm/trunk/src/c/shared/Exp/DomainOutlineRead.cpp
===================================================================
--- /issm/trunk/src/c/shared/Exp/DomainOutlineRead.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Exp/DomainOutlineRead.cpp	(revision 12330)
@@ -13,6 +13,5 @@
 #include "../../Container/DataSet.h"
 
-int DomainOutlineRead(int* pnprof,int** pprofnvertices,double*** ppprofx,double*** ppprofy,bool** pclosed,char* domainname,bool whole=true){
-
+int DomainOutlineRead(int* pnprof,int** pprofnvertices,double*** ppprofx,double*** ppprofy,bool** pclosed,char* domainname){
 	
 	/*indexing: */
@@ -102,7 +101,4 @@
 		if((x[0]==x[n-1]) && (y[0]==y[n-1])){
 			cl=true;
-			if (!whole) {
-				n=n-1;
-			}
 		}
 
@@ -126,30 +122,30 @@
 }
 
-DataSet* DomainOutlineRead(char* domainname,bool whole=true){
-
-	/*indexing: */
-	int i;
+DataSet* DomainOutlineRead(char* domainname){
 
 	/*intermediary: */
-	int nprof;
-	int* profnvertices=NULL;
-	double** pprofx=NULL;
-	double** pprofy=NULL;
-
-	Contour* contour=NULL;
+	int       nprof;
+	int      *profnvertices = NULL;
+	double  **pprofx        = NULL;
+	double  **pprofy        = NULL;
+	Contour  *contour       = NULL;
 
 	/*output: */
 	DataSet* domain=NULL;
 
-	/*get domain outline from intermediary function:*/
-	DomainOutlineRead(&nprof,&profnvertices,&pprofx, &pprofy, NULL,domainname,whole);
+	/*If domainname is an empty string, return empty dataset*/
+	if (strcmp(domainname,"")==0){
+		nprof=0;
+	}
+	else{
+		DomainOutlineRead(&nprof,&profnvertices,&pprofx, &pprofy, NULL,domainname);
+	}
 
 	/*now create dataset of contours: */
 	domain=new DataSet(0);
 
-	for(i=0;i<nprof;i++){
+	for(int i=0;i<nprof;i++){
 		domain->AddObject(new Contour(i,profnvertices[i],pprofx[i],pprofy[i],1));
 	}
-
 	return domain;
 }
Index: /issm/trunk/src/c/shared/Exp/DomainOutlineWrite.cpp
===================================================================
--- /issm/trunk/src/c/shared/Exp/DomainOutlineWrite.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Exp/DomainOutlineWrite.cpp	(revision 12330)
@@ -11,5 +11,5 @@
 #include "../Exceptions/exceptions.h"
 
-int DomainOutlineWrite(int nprof,int* profnvertices,double** pprofx,double** pprofy,bool* closed,char* domainname,bool whole=true){
+int DomainOutlineWrite(int nprof,int* profnvertices,double** pprofx,double** pprofy,bool* closed,char* domainname){
 
 	
@@ -20,11 +20,4 @@
 	/*I/O: */
 	FILE* fid=NULL;
-
-	/*input: */
-//	int nprof; //number of profiles in the domainname file
-//	int* profnvertices=NULL; //array holding the number of vertices for the nprof profiles
-//	double** pprofx=NULL; //array of profiles x coordinates
-//	double** pprofy=NULL; //array of profiles y coordinates
-//	bool* closed=NULL; //array holding closed flags for the nprof profiles
 
 	/*open domain outline file for writing: */
@@ -43,8 +36,5 @@
 		
 		/*Write number of profile vertices: */
-		if(closed[counter] && !whole)
-			fprintf(fid,"%u %s\n",profnvertices[counter]+1,"1.");
-		else
-			fprintf(fid,"%u %s\n",profnvertices[counter]  ,"1.");
+		fprintf(fid,"%u %s\n",profnvertices[counter]  ,"1.");
 	
 		/*Write next line: */
@@ -55,8 +45,4 @@
 			fprintf(fid,"%lf\t%lf\n",pprofx[counter][i],pprofy[counter][i]);
 		}
-
-		/*Now check that we are dealing with open contours: */
-		if(closed[counter] && !whole)
-			fprintf(fid,"%lf\t%lf\n",pprofx[counter][0],pprofy[counter][0]);
 
 		/*Write blank line: */
Index: /issm/trunk/src/c/shared/Exp/exp.h
===================================================================
--- /issm/trunk/src/c/shared/Exp/exp.h	(revision 12329)
+++ /issm/trunk/src/c/shared/Exp/exp.h	(revision 12330)
@@ -13,9 +13,9 @@
 int IsOutsidePoly(Vector* in,double* xc,double* yc,int numvertices,double* x,double* y,int i0,int i1, int edgevalue);
 int IsInPolySerial(double* in,double* xc,double* yc,int numvertices,double* x,double* y,int nods, int edgevalue);
-int DomainOutlineWrite(int nprof,int* profnvertices,double** pprofx,double** pprofy,bool* closed,char* domainname,bool whole);
+int DomainOutlineWrite(int nprof,int* profnvertices,double** pprofx,double** pprofy,bool* closed,char* domainname);
 int pnpoly(int npol, double *xp, double *yp, double x, double y, int edgevalue);
 
-int      DomainOutlineRead(int* pnprof,int** pprofnvertices,double*** ppprofx,double*** ppprofy,bool** pclosed,char* domainname,bool whole);
-DataSet* DomainOutlineRead(char* domainname,bool whole);
+int      DomainOutlineRead(int* pnprof,int** pprofnvertices,double*** ppprofx,double*** ppprofy,bool** pclosed,char* domainname);
+DataSet* DomainOutlineRead(char* domainname);
 
 
Index: sm/trunk/src/c/shared/Numerics/OptFunc.cpp
===================================================================
--- /issm/trunk/src/c/shared/Numerics/OptFunc.cpp	(revision 12329)
+++ 	(revision )
@@ -1,41 +1,0 @@
-/*!\file:  OptFunc.cpp
- * \brief: "C" code wrapper to matlab objectivefunctionC call
- */ 
-
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "mex.h"
-double OptFunc(double scalar, OptArgs* optargs){
-	
-	/*output: */
-	double J;
-
-	mxArray*   inputs[2];
-	mxArray*   psearch_scalar=NULL;
-	mxArray*   mxJ=NULL;
-
-	psearch_scalar=mxCreateDoubleScalar(scalar);
-	inputs[0]=psearch_scalar;
-	inputs[1]=optargs->femmodel;
-
-	mexCallMATLAB(1,&mxJ,2,(mxArray**)inputs, optargs->function_name);
-
-	/*extract misfit from mxArray*/
-	J=mxGetScalar(mxJ);
-
-	return J;
-}
-#else
-double OptFunc(double scalar, OptArgs* optargs){
-	_error_(" not implemented yet");
-}
-#endif
Index: /issm/trunk/src/c/shared/Numerics/OptionsFromAnalysis.cpp
===================================================================
--- /issm/trunk/src/c/shared/Numerics/OptionsFromAnalysis.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Numerics/OptionsFromAnalysis.cpp	(revision 12330)
@@ -8,4 +8,6 @@
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
 #endif
+
+#include <cstring>
 
 #include "../../objects/objects.h"
@@ -30,11 +32,5 @@
 	parameters->FindParam(&strings,&numanalyses,PetscOptionsStringsEnum);
 
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_) //do not take this away, because ISSM loads analyses as a Double Param instead of a DoubleVec Param  when running with only 1 analysis
-	if(numanalyses==1){ analyses=(double*)xmalloc(1*sizeof(double)); parameters->FindParam(analyses,PetscOptionsAnalysesEnum);
-	}
-	else parameters->FindParam(&analyses,&dummy,PetscOptionsAnalysesEnum);
-	#else
 	parameters->FindParam(&analyses,&dummy,PetscOptionsAnalysesEnum);
-	#endif
 
 	if(numanalyses==0)return NULL; //we did not find petsc options, don't bother.
Index: /issm/trunk/src/c/shared/Numerics/Synchronize.sh
===================================================================
--- /issm/trunk/src/c/shared/Numerics/Synchronize.sh	(revision 12329)
+++ /issm/trunk/src/c/shared/Numerics/Synchronize.sh	(revision 12330)
@@ -2,5 +2,5 @@
 #Synchronize Verbosity
 #first remove existing files
-rm $ISSM_TIER/src/m/shared/Verb*.m
+rm $ISSM_DIR/src/m/shared/Verb*.m
 
 echo "Synchronizing Verbosity levels..."
@@ -29,7 +29,4 @@
 #include "../../include/macros.h"
 #include "../Exceptions/exceptions.h"
-#ifdef _SERIAL_
-#include <mex.h>
-#endif
 /*}}}*/
 
@@ -54,5 +51,5 @@
 
 	#Add Verbosity Matlab file{{{
-	cat <<END > $ISSM_TIER"/src/m/shared/"$(echo $FILENAME".m")
+	cat <<END > $ISSM_DIR"/src/m/shared/"$(echo $FILENAME".m")
 function bool=$(echo $FILENAME)()
 %$(echo $FILENAME | awk {'print toupper($1)'}) - Return true if $(echo $LEVELNAME | awk {'print tolower($1)'}) level is activated
@@ -140,42 +137,16 @@
 	if(level<0) _error_("vebosity level should be a positive integer (user provided %i)",level);
 
-#ifdef _SERIAL_
-
-	mxArray* output=NULL;
-	mxArray* input=NULL;
-	input=mxCreateDoubleScalar((double)level);
-
-	mexCallMATLAB(0,&output,1,&input,"SetVerbosityLevel");
-#else
-
 	verbositylevel = level;
 
-#endif
 }/*}}}*/
 /*FUNCTION GetVerbosityLevel {{{*/
 int  GetVerbosityLevel(void){
-#ifdef _SERIAL_
-
-	mxArray* output=NULL;
-	mxArray* input=NULL;
-	double   level;
-
-	mexCallMATLAB(1,&output,0,&input,"GetVerbosityLevel");
-	level=mxGetScalar(output);
-
-	verbositylevel = (int)level;
-	return verbositylevel;
-
-#else
-
 	_assert_(verbositylevel>=0);
 	return verbositylevel;
-
-#endif
 }/*}}}*/
 END
 #}}}
 #Complete verbose.m {{{1
-VERBOSEPATH="$ISSM_TIER/src/m/classes/verbose.m"
+VERBOSEPATH="$ISSM_DIR/src/m/classes/verbose.m"
 cat $VERBOSEPATH  | sed "/%BEGINFIELDS/,$ d"  > temp_begin
 cat $VERBOSEPATH  | sed "1,/%ENDFIELDS/d" > temp_end
Index: /issm/trunk/src/c/shared/Numerics/Verbosity.cpp
===================================================================
--- /issm/trunk/src/c/shared/Numerics/Verbosity.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Numerics/Verbosity.cpp	(revision 12330)
@@ -18,7 +18,4 @@
 #include "../../include/macros.h"
 #include "../Exceptions/exceptions.h"
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include <mex.h>
-#endif
 /*}}}*/
 
@@ -39,36 +36,12 @@
 	if(level<0) _error_("vebosity level should be a positive integer (user provided %i)",level);
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-
-	mxArray* output=NULL;
-	mxArray* input=NULL;
-	input=mxCreateDoubleScalar((double)level);
-
-	mexCallMATLAB(0,&output,1,&input,"SetVerbosityLevel");
-#else
-
 	verbositylevel = level;
 
-#endif
 }/*}}}*/
 /*FUNCTION GetVerbosityLevel {{{*/
 int  GetVerbosityLevel(void){
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-
-	mxArray* output=NULL;
-	mxArray* input=NULL;
-	double   level;
-
-	mexCallMATLAB(1,&output,0,&input,"GetVerbosityLevel");
-	level=mxGetScalar(output);
-
-	verbositylevel = (int)level;
-	return verbositylevel;
-
-#else
 
 	_assert_(verbositylevel>=0);
 	return verbositylevel;
 
-#endif
 }/*}}}*/
Index: /issm/trunk/src/c/shared/Numerics/XZvectorsToCoordinateSystem.cpp
===================================================================
--- /issm/trunk/src/c/shared/Numerics/XZvectorsToCoordinateSystem.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Numerics/XZvectorsToCoordinateSystem.cpp	(revision 12330)
@@ -1,6 +1,6 @@
-#include "../../io/Matlab/matlabio.h"
 #include "../Alloc/alloc.h"
 #include "../../include/include.h"
 #include "../Exceptions/exceptions.h"
+#include "./isnan.h"
 #include <math.h>
 
Index: sm/trunk/src/c/shared/Sorting/Quicksort.c
===================================================================
--- /issm/trunk/src/c/shared/Sorting/Quicksort.c	(revision 12329)
+++ 	(revision )
@@ -1,19 +1,0 @@
-void swap(int *a, int *b) {
-	int t=*a; *a=*b; *b=t;
-}
-void sort(int arr[], int beg, int end) {
-	  
-	if (end > beg + 1) {
-		int piv = arr[beg], l = beg + 1, r = end;
-		while (l < r)
-		{
-			if (arr[l] <= piv)
-				l++;
-			else
-				swap(&arr[l], &arr[--r]);
-		}
-		swap(&arr[--l], &arr[beg]);
-		sort(arr, beg, l);
-		sort(arr, r, end);
-	}
-}
Index: /issm/trunk/src/c/shared/Sorting/binary_search.cpp
===================================================================
--- /issm/trunk/src/c/shared/Sorting/binary_search.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Sorting/binary_search.cpp	(revision 12330)
@@ -11,9 +11,9 @@
 #include <stdio.h>
 
-int binary_search(int* poffset,int target, int* sorted_integers,int num_integers){
+int binary_search(int* poffset,int target,int* sorted_integers,int num_integers){
 
 	/*output: */
 	int offset;  //offset, if found
-	int found=0;  //found=0 if target is not found, 1 otherwise.
+	int found=0; //found=0 if target is not found, 1 otherwise.
 
 	/*intermediary: */
@@ -64,3 +64,2 @@
 	return found;
 }
-
Index: /issm/trunk/src/c/shared/Sorting/sorting.h
===================================================================
--- /issm/trunk/src/c/shared/Sorting/sorting.h	(revision 12329)
+++ /issm/trunk/src/c/shared/Sorting/sorting.h	(revision 12330)
@@ -6,7 +6,5 @@
 #define  _SORTING_H_
 
-int binary_search(int* poffset,int target, int* sorted_integers,int num_integers);
-
+int binary_search(int* poffset,int target,int* sorted_integers,int num_integers);
 
 #endif //ifndef _SORTING_H_
-
Index: /issm/trunk/src/c/shared/Threads/LaunchThread.cpp
===================================================================
--- /issm/trunk/src/c/shared/Threads/LaunchThread.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/Threads/LaunchThread.cpp	(revision 12330)
@@ -67,4 +67,3 @@
 	function((void*)&handle);
 	#endif
-
 }
Index: /issm/trunk/src/c/shared/TriMesh/SplitMeshForRifts.cpp
===================================================================
--- /issm/trunk/src/c/shared/TriMesh/SplitMeshForRifts.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/TriMesh/SplitMeshForRifts.cpp	(revision 12330)
@@ -47,8 +47,7 @@
 	segmentmarkerlist=*psegmentmarkerlist;
 
-
 	/*Establish list of segments that belong to a rift: */
-	RiftSegmentsFromSegments(&nriftsegs,&riftsegments,nel,index,nsegs,segments); /*riftsegments of size nriftsegsx4 (4 for first element on segment,second element, 
-																				   first node and second snode)*/
+	/*riftsegments of size nriftsegsx4 (4 for first element on segment,second element,first node and second snode)*/
+	RiftSegmentsFromSegments(&nriftsegs,&riftsegments,nel,index,nsegs,segments);
 
 	/*Go through all nodes of the rift segments, and start splitting the mesh: */
@@ -57,5 +56,5 @@
 		for (j=0;j<2;j++){
 	
-			node=*(riftsegments+4*i+j+2);
+			node=riftsegments[4*i+j+2];
 			if(flags[node-1]){
 				/*This node was already split, skip:*/
@@ -70,7 +69,11 @@
 				DetermineGridElementListOnOneSideOfRift(&NumGridElementListOnOneSideOfRift,&GridElementListOnOneSideOfRift,i,nriftsegs,riftsegments,node,index,nel);
 			
-				/*Summary: we have for node, a list of elements (GridElementListOnOneSideOfRift, of size NumGridElementListOnOneSideOfRift) that all contain node 
-				 *and that are on the same side of the rift. For all these elements, we clone node into another node, and we swap all instances of node in the triangulation 
-				 *for those elements, to the new node.*/
+				/*Summary: we have for node, a list of elements
+				 * (GridElementListOnOneSideOfRift, of size
+				 * NumGridElementListOnOneSideOfRift) that all contain node 
+				 *and that are on the same side of the rift. For all these
+				 elements, we clone node into another node, and we swap all
+				 instances of node in the triangulation *for those elements, to the
+				 new node.*/
 				
 				//augment number of nodes 
@@ -94,5 +97,5 @@
 
 	/*update segments: they got modified completely by adding new nodes.*/
-	UpdateSegments(&segments,&segmentmarkerlist, &nsegs,index,x,y,riftsegments,nriftsegs);
+	UpdateSegments(&segments,&segmentmarkerlist, &nsegs,index,x,y,riftsegments,nriftsegs,nods,nel);
 
 	/*Assign output pointers: */
Index: /issm/trunk/src/c/shared/TriMesh/TriMeshUtils.cpp
===================================================================
--- /issm/trunk/src/c/shared/TriMesh/TriMeshUtils.cpp	(revision 12329)
+++ /issm/trunk/src/c/shared/TriMesh/TriMeshUtils.cpp	(revision 12330)
@@ -11,4 +11,5 @@
 
 #define RIFTPENALTYPAIRSWIDTH 8
+/*FUNCTION IsGridOnRift{{{*/
 int IsGridOnRift(int* riftsegments, int nriftsegs, int node){
 
@@ -32,7 +33,6 @@
 		return 0;
 	}
-}
-				
-
+}/*}}}*/
+/*FUNCTION GridElementsList{{{*/
 int GridElementsList(int** pGridElements, int* pNumGridElements,int node,double * index,int nel){
 
@@ -87,7 +87,6 @@
 	*pNumGridElements=NumGridElements;
 	return noerr;
-}
-
-
+}/*}}}*/
+/*FUNCTION IsNeighbor{{{*/
 int IsNeighbor(int el1,int el2,double* index){
 	/*From a triangulation held in index, figure out if elements 1 and 2 have two nodes in common: */
@@ -105,7 +104,6 @@
 		return 0;
 	}
-}
-							
-
+}/*}}}*/
+/*FUNCTION IsOnRift{{{*/
 int IsOnRift(int el,int nriftsegs,int* riftsegments){
 	/*From a list of elements segments, figure out if el belongs to it: */
@@ -117,11 +115,6 @@
 	}
 	return 0;
-}
-
-
-/******************************************************************************************************************************
-                                   RiftSegmentsFromSegments
-******************************************************************************************************************************/
-
+}/*}}}*/
+/*FUNCTION RiftSegmentsFromSegments{{{*/
 void RiftSegmentsFromSegments(int* pnriftsegs, int** priftsegments, int nel, double* index, int nsegs,double* segments){
 	
@@ -189,10 +182,6 @@
 	*priftsegments=riftsegments;
 	*pnriftsegs=nriftsegs;
-}
-
-/******************************************************************************************************************************
-                                   DetermineGridElementListOnOneSideOfRift
-******************************************************************************************************************************/
-
+}/*}}}*/
+/*FUNCTION DetermineGridElementListOnOneSideOfRift{{{*/
 int DetermineGridElementListOnOneSideOfRift(int* pNumGridElementListOnOneSideOfRift, int** pGridElementListOnOneSideOfRift, int segmentnumber, int nriftsegs, int* riftsegments, int node,double* index,int nel){
 
@@ -257,11 +246,7 @@
 	*pGridElementListOnOneSideOfRift=GridElementListOnOneSideOfRift;
 	return noerr;
-}
-
-/******************************************************************************************************************************
-                                   UpdateSegments
-******************************************************************************************************************************/
-
-int UpdateSegments(double** psegments,double** psegmentmarkerlist, int* pnsegs, double* index, double* x,double* y,int* riftsegments,int nriftsegs){
+}/*}}}*/
+/*FUNCTION UpdateSegments{{{*/
+int UpdateSegments(double** psegments,double** psegmentmarkerlist, int* pnsegs, double* index, double* x,double* y,int* riftsegments,int nriftsegs,int nods,int nel){
 
 	int noerr=1;
@@ -284,8 +269,8 @@
 	/*First, update the existing segments to the new nodes :*/
 	for (i=0;i<nriftsegs;i++){
-		el1=*(riftsegments+4*i+0);
-		el2=*(riftsegments+4*i+1);
+		el1=riftsegments[4*i+0];
+		el2=riftsegments[4*i+1];
 		for (j=0;j<nsegs;j++){
-			if (*(segments+3*j+2)==(el1+1)){
+			if (segments[3*j+2]==(el1+1)){
 				/*segment j is the same as rift segment i.Let's update segments[j][:] using  element el1 and the corresponding rift segment.
 				 *Because riftsegments does not represent a list of rift segments anymore (it got heavily modified in SplitElementsForRifts, 
@@ -293,5 +278,5 @@
 				for (k=0;k<3;k++){
 					if ((x[(int)*(index+el1*3+k)-1]==x[(int)*(segments+3*j+0)-1]) && (y[(int)*(index+el1*3+k)-1]==y[(int)*(segments+3*j+0)-1])){
-						*(segments+3*j+0)=*(index+el1*3+k);
+						*(segments+3*j+0)=*(index+el1*3+k); _assert_(segments[3*j+0]<nods+1);
 						break;
 					}
@@ -299,5 +284,5 @@
 				for (k=0;k<3;k++){
 					if ((x[(int)*(index+el1*3+k)-1]==x[(int)*(segments+3*j+1)-1])  && (y[(int)*(index+el1*3+k)-1]==y[(int)*(segments+3*j+1)-1])){
-						*(segments+3*j+1)=*(index+el1*3+k);
+						*(segments+3*j+1)=*(index+el1*3+k); _assert_(segments[3*j+1]<nods+1);
 						break;
 					}
@@ -308,5 +293,5 @@
 				for (k=0;k<3;k++){
 					if ((x[(int)*(index+el2*3+k)-1]==x[(int)*(segments+3*j+0)-1]) && (y[(int)*(index+el2*3+k)-1]==y[(int)*(segments+3*j+0)-1])){
-						*(segments+3*(nsegs+i)+0)=*(index+el2*3+k);
+						*(segments+3*(nsegs+i)+0)=*(index+el2*3+k); _assert_(segments[3*(nsegs+i)+0]<nods+1);
 						break;
 					}
@@ -314,5 +299,5 @@
 				for (k=0;k<3;k++){
 					if ((x[(int)*(index+el2*3+k)-1]==x[(int)*(segments+3*j+1)-1]) && (y[(int)*(index+el2*3+k)-1]==y[(int)*(segments+3*j+1)-1])){
-						*(segments+3*(nsegs+i)+1)=*(index+el2*3+k);
+						*(segments+3*(nsegs+i)+1)=*(index+el2*3+k); _assert_(segments[3*(nsegs+i)+1]<nods+1);
 						break;
 					}
@@ -324,5 +309,5 @@
 				for (k=0;k<3;k++){
 					if ((x[(int)*(index+el2*3+k)-1]==x[(int)*(segments+3*j+0)-1]) && (y[(int)*(index+el2*3+k)-1]==y[(int)*(segments+3*j+0)-1])){
-						*(segments+3*j+0)=*(index+el2*3+k);
+						*(segments+3*j+0)=*(index+el2*3+k); _assert_(segments[3*j+0]<nods+1);
 						break;
 					}
@@ -330,5 +315,5 @@
 				for (k=0;k<3;k++){
 					if ((x[(int)*(index+el2*3+k)-1]==x[(int)*(segments+3*j+1)-1]) && (y[(int)*(index+el2*3+k)-1]==y[(int)*(segments+3*j+1)-1])){
-						*(segments+3*j+1)=*(index+el2*3+k);
+						*(segments+3*j+1)=*(index+el2*3+k);_assert_(segments[3*j+1]<nods+1);
 						break;
 					}
@@ -339,5 +324,5 @@
 				for (k=0;k<3;k++){
 					if ((x[(int)*(index+el1*3+k)-1]==x[(int)*(segments+3*j+0)-1]) && (y[(int)*(index+el1*3+k)-1]==y[(int)*(segments+3*j+0)-1])){
-						*(segments+3*(nsegs+i)+0)=*(index+el1*3+k);
+						*(segments+3*(nsegs+i)+0)=*(index+el1*3+k);_assert_(segments[3*(nsegs+i)+0]<nods+1);
 						break;
 					}
@@ -345,5 +330,5 @@
 				for (k=0;k<3;k++){
 					if ((x[(int)*(index+el1*3+k)-1]==x[(int)*(segments+3*j+1)-1]) && (y[(int)*(index+el1*3+k)-1]==y[(int)*(segments+3*j+1)-1])){
-						*(segments+3*(nsegs+i)+1)=*(index+el1*3+k);
+						*(segments+3*(nsegs+i)+1)=*(index+el1*3+k);_assert_(segments[3*(nsegs+i)+1]<nods+1);
 						break;
 					}
@@ -360,9 +345,6 @@
 	
 	return noerr;
-}
-
-/******************************************************************************************************************************
-                                   pnpoly
-******************************************************************************************************************************/
+}/*}}}*/
+/*FUNCTION pnpoly{{{*/
 int pnpoly(int npol, double *xp, double *yp, double x, double y) {
 	int i, j, c = 0;
@@ -374,33 +356,6 @@
 	}
 	return c;
-}
-
-/******************************************************************************************************************************
-                                   IsInPoly
-******************************************************************************************************************************/
-//void IsInPoly(double* in,double* xc,double* yc,int numnodes,double* x,double* y,int nods){
-//
-//	int i;
-//	double x0,y0;
-//
-//	/*Go through all nodes of the mesh:*/
-//	for (i=0;i<nods;i++){
-//		if (in[i]){
-//			/*this node already is inside one of the contours, continue*/
-//			continue;
-//		}
-//		/*pick up node: */
-//		x0=x[i];
-//		y0=y[i];
-//		if (pnpoly(numnodes,xc,yc,x0,y0)){
-//			in[i]=1;
-//		}
-//	}
-//}
-
-/******************************************************************************************************************************
-                                   FindElement
-******************************************************************************************************************************/
-
+}/*}}}*/
+/*FUNCTION FindElement{{{*/
 int FindElement(double A,double B,double* index,int nel){
 
@@ -414,10 +369,7 @@
 	}
 	return el;
-}
-/******************************************************************************************************************************
-                                   SplitRiftSegments
-******************************************************************************************************************************/
-
-int SplitRiftSegments(double** psegments,double** psegmentmarkerlist, int* pnumsegs, int* pnumrifts,int** priftsnumsegs,double*** priftssegments,int numrifts){
+}/*}}}*/
+/*FUNCTION SplitRiftSegments{{{*/
+int SplitRiftSegments(double** psegments,double** psegmentmarkerlist, int* pnumsegs, int* pnumrifts,int** priftsnumsegs,double*** priftssegments,int numrifts,int nods,int nel){
 
 	/*Using segment markers, wring out the rift segments from the segments. Rift markers are 
@@ -461,7 +413,7 @@
 	for (i=0;i<numsegs;i++){
 		if (segmentmarkerlist[i]==1){
-			*(new_segments+3*counter+0)=*(segments+3*i+0);
-			*(new_segments+3*counter+1)=*(segments+3*i+1);
-			*(new_segments+3*counter+2)=*(segments+3*i+2);
+			new_segments[3*counter+0]=segments[3*i+0];
+			new_segments[3*counter+1]=segments[3*i+1];
+			new_segments[3*counter+2]=segments[3*i+2];
 			new_segmentmarkers[counter]=segmentmarkerlist[i];
 			counter++;
@@ -484,7 +436,7 @@
 		for (j=0;j<numsegs;j++){
 			if (segmentmarkerlist[j]==(2+i)){
-				*(riftsegment+3*counter+0)=*(segments+3*j+0);
-				*(riftsegment+3*counter+1)=*(segments+3*j+1);
-				*(riftsegment+3*counter+2)=*(segments+3*j+2);
+				riftsegment[3*counter+0]=segments[3*j+0];_assert_(riftsegment[3*counter+0]<nods+1);
+				riftsegment[3*counter+1]=segments[3*j+1];_assert_(riftsegment[3*counter+1]<nods+1);
+				riftsegment[3*counter+2]=segments[3*j+2];_assert_(riftsegment[3*counter+2]<nel+1);
 				counter++;
 			}
@@ -504,10 +456,6 @@
 	*priftsnumsegs=riftsnumsegs;
 	return noerr;
-}
-
-/******************************************************************************************************************************
-                                   PairRiftElements
-******************************************************************************************************************************/
-
+}/*}}}*/
+/*FUNCTION PairRiftElements{{{*/
 int PairRiftElements(int** priftsnumpairs, double*** priftspairs,int numrifts,int* riftsnumsegments, double** riftssegments,double* x,double* y){
 
@@ -558,15 +506,6 @@
 
 	return noerr;
-}
-
-
-/******************************************************************************************************************************
-                                   RemoveRifts
-******************************************************************************************************************************/
-
-double dabs(double x){
-	if (x<0)x=-x;
-	return x;
-}
+}/*}}}*/
+/*FUNCTION RemoveRifts{{{*/
 int RemoveRifts(double** pindex,double** px,double** py,int* pnods,double** psegments,int* pnumsegs,int numrifts1,int* rifts1numsegs,double** rifts1segments,double** rifts1pairs,int nel){
 
@@ -615,6 +554,6 @@
 		if (y[i]<ymin)ymin=y[i];
 	}
-	xmin=xmin-dabs(xmin); 
-	ymin=ymin-dabs(ymin);
+	xmin=xmin-fabs(xmin); 
+	ymin=ymin-fabs(ymin);
 
 	/*Initialize two arrays, one for nodes that are going to be merged, the other with corresponding nodes being merge into: */
@@ -751,10 +690,6 @@
 
 	return noerr;
-}
-
-/******************************************************************************************************************************
-                                   IsRiftPresent
-******************************************************************************************************************************/
-
+}/*}}}*/
+/*FUNCTION IsRiftPresent{{{*/
 int IsRiftPresent(int* priftflag,int* pnumrifts, double* segmentmarkerlist,int nsegs){
 
@@ -783,11 +718,7 @@
 
 	return noerr;
-}
-
-/******************************************************************************************************************************
-                                   OrderRifts
-******************************************************************************************************************************/
-
-int OrderRifts(double** priftstips, double** riftssegments,double** riftspairs,int numrifts,int* riftsnumsegments,double* x,double* y){
+}/*}}}*/
+/*FUNCTION OrderRifts{{{*/
+int OrderRifts(double** priftstips, double** riftssegments,double** riftspairs,int numrifts,int* riftsnumsegments,double* x,double* y,int nods,int nels){
 	
 	int noerr=1;
@@ -811,5 +742,4 @@
 	/*output: */
 	double* riftstips=NULL;
-
 
 	/*Allocate byproduct of this routine, riftstips: */
@@ -822,5 +752,4 @@
 		numsegs=riftsnumsegments[i];
 	
-			
 		/*Allocate copy of riftsegments and riftpairs, 
 		 *as well as ordering vector: */
@@ -847,5 +776,7 @@
 			}
 			/* Make sure node3 faces node1 and node4 faces node2: */
-			if ((x[node1]==x[node4]) && (y[node1]==y[node4])){
+			_assert_(node1<nods+1 && node4<nods+1);
+			_assert_(node1>0 && node4>0);
+			if ((x[node1-1]==x[node4-1]) && (y[node1-1]==y[node4-1])){
 				/*Swap node3 and node4:*/
 				temp_node=node3;
@@ -943,10 +874,6 @@
 	*priftstips=riftstips;
 	return noerr;
-}
-
-/******************************************************************************************************************************
-                                   PenaltyPairs
-******************************************************************************************************************************/
-
+}/*}}}*/
+/*FUNCTION PenaltyPairs{{{*/
 int PenaltyPairs(double*** priftspenaltypairs,int** priftsnumpenaltypairs,int numrifts,double** riftssegments,
 		int* riftsnumsegs,double** riftspairs,double* riftstips,double* x,double* y){
Index: /issm/trunk/src/c/shared/TriMesh/trimesh.h
===================================================================
--- /issm/trunk/src/c/shared/TriMesh/trimesh.h	(revision 12329)
+++ /issm/trunk/src/c/shared/TriMesh/trimesh.h	(revision 12330)
@@ -6,20 +6,13 @@
 #define _SHARED_TRIMESH_H
 
-
 #include <stdio.h>
 #include <math.h>
 
-
-
 //#define REAL double //took  it out because it may conflict with stdlib.h defines. put back if necessary
-
 int AssociateSegmentToElement(double** psegments,int nseg, double* index,int nel);
 int OrderSegments(double** psegments,int nseg, double* index,int nel);
-		
 int GridInsideHole(double* px0,double* py0,int n,double* x,double* y);
 int FindElement(double A,double B,double* index,int nel);
-
 int SplitMeshForRifts(int* pnel,double** pindex,int* pnods,double** px,double** py,int* pnsegs,double** psegments,double** psegmentmarkerlist);
-
 int IsGridOnRift(int* riftsegments, int nriftsegs, int node);
 int GridElementsList(int** pGridElements, int* pNumGridElements,int node,double * index,int nel);
@@ -28,17 +21,15 @@
 void RiftSegmentsFromSegments(int* pnriftsegs, int** priftsegments, int nel, double* index, int nsegs,double* segments);
 int DetermineGridElementListOnOneSideOfRift(int* pNumGridElementListOnOneSideOfRift, int** pGridElementListOnOneSideOfRift, int segmentnumber, int nriftsegs, int* riftsegments, int node,double* index,int nel);
-int UpdateSegments(double** psegments,double** psegmentmarkerlist, int* pnsegs, double* index, double* x,double* y,int* riftsegments,int nriftsegs);
+int UpdateSegments(double** psegments,double** psegmentmarkerlist, int* pnsegs, double* index, double* x,double* y,int* riftsegments,int nriftsegs,int nods,int nel);
 int pnpoly(int npol, double *xp, double *yp, double x, double y);
 int FindElement(double A,double B,double* index,int nel);
 int RemoveRifts(double** pindex,double** px,double** py,int* pnods,double** psegments,int* pnumsegs,int numrifts1,int* rifts1numsegs,double** rifts1segments,double** rifts1pairs,int nel);
 int IsRiftPresent(int* priftflag,int* pnumrifts, double* segmentmarkerlist,int nsegs);
-int SplitRiftSegments(double** psegments,double** psegmentmarkerlist, int* pnumsegs, int* pnumrifts,int** priftsnumsegs,double*** priftssegments,int numrifts);
-int OrderRifts(double** priftstips, double** riftssegments,double** riftspairs,int numrifts,int* riftsnumsegments,double* x,double* y);
+int SplitRiftSegments(double** psegments,double** psegmentmarkerlist, int* pnumsegs, int* pnumrifts,int** priftsnumsegs,double*** priftssegments,int numrifts,int nods,int nels);
+int OrderRifts(double** priftstips, double** riftssegments,double** riftspairs,int numrifts,int* riftsnumsegments,double* x,double* y,int nods,int nels);
 int PenaltyPairs(double*** priftspenaltypairs,int** priftsnumpenaltypairs,int numrifts,double**  riftssegments,
 		int* riftsnumsegments,double** riftspairs,double* riftstips,double* x,double* y);
-
 int RemoveCornersFromRifts(double** pindex,int* pnel,double** px,double** py,int* pnods, double* segments,double* segmentmarkers,int num_seg);
 int PairRiftElements(int** priftsnumpairs, double*** priftspairs,int numrifts,int* riftsnumsegments, double** riftssegments,double* x,double* y);
 
-
 #endif  /* _SHARED_TRIMESH_H */
Index: /issm/trunk/src/c/shared/Wrapper/wrappershared.h
===================================================================
--- /issm/trunk/src/c/shared/Wrapper/wrappershared.h	(revision 12329)
+++ /issm/trunk/src/c/shared/Wrapper/wrappershared.h	(revision 12330)
@@ -8,8 +8,6 @@
 #include "../../objects/objects.h"
 
-#ifdef _SERIAL_
 int ModuleBoot(void);
 int ModuleEnd(void);
-#endif
 
 #endif
Index: /issm/trunk/src/c/shared/shared.h
===================================================================
--- /issm/trunk/src/c/shared/shared.h	(revision 12329)
+++ /issm/trunk/src/c/shared/shared.h	(revision 12330)
@@ -8,4 +8,5 @@
 
 #include "Alloc/alloc.h"
+#include "Alloc/alloc_module.h"
 #include "Exceptions/exceptions.h"
 #include "Exp/exp.h"
Index: /issm/trunk/src/c/solutions/ProcessArguments.cpp
===================================================================
--- /issm/trunk/src/c/solutions/ProcessArguments.cpp	(revision 12329)
+++ /issm/trunk/src/c/solutions/ProcessArguments.cpp	(revision 12330)
@@ -4,4 +4,6 @@
 
 #include <stdio.h>
+#include <cstring>
+
 #include "../shared/shared.h"
 #include "../include/include.h"
Index: /issm/trunk/src/c/solutions/issm.cpp
===================================================================
--- /issm/trunk/src/c/solutions/issm.cpp	(revision 12329)
+++ /issm/trunk/src/c/solutions/issm.cpp	(revision 12330)
@@ -35,9 +35,5 @@
 	int      ierr;
 
-	MODULEBOOT();
-
-	#ifndef _PARALLEL_
-	_error_(" parallel executable was compiled without support of parallel libraries!");
-	#endif
+	ISSMBOOT();
 
 	/*Initialize environments: Petsc, MPI, etc...: */
@@ -46,12 +42,20 @@
 	if(ierr) _error_("Could not initialize Petsc");
 	#else
+	#ifdef _HAVE_MPI_
 	MPI_Init(&argc,&argv);
 	#endif
+	#endif
 
+	#ifdef _HAVE_MPI_
 	MPI_Barrier(MPI_COMM_WORLD); start=MPI_Wtime();
+	#else
+	start=(double)clock();
+	#endif
 
 	/*Size and rank: */
+	#ifdef _HAVE_MPI_
 	MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);  
 	MPI_Comm_size(MPI_COMM_WORLD,&num_procs); 
+	#endif
 
 	/*First process inputs*/
@@ -66,5 +70,9 @@
 	
 	/*Create femmodel, using input file: */
+	#ifdef _HAVE_MPI_
 	MPI_Barrier(MPI_COMM_WORLD); start_init=MPI_Wtime();
+	#else
+	start_init=(double)clock();
+	#endif
 	femmodel=new FemModel(binfilename,outbinfilename,solution_type,analyses,numanalyses);
 	
@@ -86,8 +94,17 @@
 	femmodel->parameters->FindParam(&control_analysis,InversionIscontrolEnum);
 	femmodel->parameters->FindParam(&tao_analysis,InversionTaoEnum);
+	#ifdef _HAVE_MPI_
 	MPI_Barrier(MPI_COMM_WORLD); finish_init=MPI_Wtime();
+	#else
+	finish_init=(double)clock();
+	#endif
 
 	_printf_(true,"call computational core:\n");
+	#ifdef _HAVE_MPI_
 	MPI_Barrier(MPI_COMM_WORLD); start_core=MPI_Wtime( );
+	#else
+	start_core=(double)clock();
+	#endif
+	
 	if(dakota_analysis){
 		#ifdef _HAVE_DAKOTA_
@@ -110,6 +127,10 @@
 		solutioncore(femmodel);
 	}
+	#ifdef _HAVE_MPI_
 	MPI_Barrier(MPI_COMM_WORLD); finish_core=MPI_Wtime( );
-
+	#else
+	finish_core=(double)clock();
+	#endif
+	
 	_printf_(true,"write results to disk:\n");
 	OutputResultsx(femmodel->elements, femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,femmodel->results);
@@ -131,21 +152,31 @@
 
 	/*Get finish time and close*/
+	#ifdef _HAVE_MPI_
 	MPI_Barrier(MPI_COMM_WORLD); finish = MPI_Wtime( );
 	_printf_(true,"\n   %-34s %f seconds  \n","FemModel initialization elapsed time:",finish_init-start_init);
 	_printf_(true,"   %-34s %f seconds  \n","Core solution elapsed time:",finish_core-start_core);
 	_printf_(true,"\n   %s %i hrs %i min %i sec\n\n","Total elapsed time:",int((finish-start)/3600),int(int(finish-start)%3600/60),int(finish-start)%60);
+	#else
+	finish=(double)clock();
+	_printf_(true,"\n   %-34s %f seconds  \n","FemModel initialization elapsed time:",(finish_init-start_init)/CLOCKS_PER_SEC);
+	_printf_(true,"   %-34s %f seconds  \n","Core solution elapsed time:",(finish_core-start_core)/CLOCKS_PER_SEC);
+	_printf_(true,"\n   %s %i hrs %i min %i sec\n\n","Total elapsed time:",int((finish-start)/3600/CLOCKS_PER_SEC),int(int((finish-start)/CLOCKS_PER_SEC)%3600/60),(int(finish-start)/CLOCKS_PER_SEC)%60);
+	#endif
 	
+		
 	
+	#ifdef _HAVE_PETSC_
 	_printf_(true,"closing MPI and Petsc\n");
-	#ifdef _HAVE_PETSC_
 	PetscFinalize(); 
 	#else
+	#ifdef _HAVE_MPI_
+	_printf_(true,"closing MPI and Petsc\n");
 	MPI_Finalize();
+	#endif
 	#endif
 	
 	/*end module: */
-	MODULEEND();
+	ISSMEND();
 
 	return 0; //unix success return;
 }
-
Index: /issm/trunk/src/c/solvers/solver_newton.cpp
===================================================================
--- /issm/trunk/src/c/solvers/solver_newton.cpp	(revision 12329)
+++ /issm/trunk/src/c/solvers/solver_newton.cpp	(revision 12330)
@@ -67,7 +67,17 @@
 		convergence(&converged,Kff,pf,uf,old_uf,femmodel->parameters); 
 		xdelete(&Kff); xdelete(&pf);
-		if(converged==true) break;
+		if(converged==true){	
+			bool max_iteration_state=false;
+			int tempStep=1;
+			double tempTime=1.0;
+			femmodel->results->AddObject(new BoolExternalResult(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
+			break;
+		}
 		if(count>=max_nonlinear_iterations){
-			_printf_(true,"   maximum number of iterations (%i) exceeded\n",max_nonlinear_iterations); 
+			_printf_(true,"   maximum number of Newton iterations (%i) exceeded\n",max_nonlinear_iterations); 
+			bool max_iteration_state=true;
+			int tempStep=1;
+			double tempTime=1.0;
+			femmodel->results->AddObject(new BoolExternalResult(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
 			break;
 		}
Index: /issm/trunk/src/c/solvers/solver_nonlinear.cpp
===================================================================
--- /issm/trunk/src/c/solvers/solver_nonlinear.cpp	(revision 12329)
+++ /issm/trunk/src/c/solvers/solver_nonlinear.cpp	(revision 12330)
@@ -85,10 +85,20 @@
 		/*Increase count: */
 		count++;
-		if(converged==true)break;
+		if(converged==true){
+			bool max_iteration_state=false;
+			int tempStep=1;
+			double tempTime=1.0;
+			femmodel->results->AddObject(new BoolExternalResult(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
+			break;
+		}
 		if(count>=max_nonlinear_iterations){
-			_printf_(true,"   maximum number of iterations (%i) exceeded\n",max_nonlinear_iterations); 
+			_printf_(true,"   maximum number of nonlinear iterations (%i) exceeded\n",max_nonlinear_iterations); 
 			converged=true;
-		InputUpdateFromConstantx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,converged,ConvergedEnum);
-		InputUpdateFromSolutionx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,ug);
+			InputUpdateFromConstantx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,converged,ConvergedEnum);
+			InputUpdateFromSolutionx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,ug);		
+			bool max_iteration_state=true;
+			int tempStep=1;
+			double tempTime=1.0;
+			femmodel->results->AddObject(new BoolExternalResult(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
 			break;
 		}
Index: /issm/trunk/src/c/toolkits/issm/SeqMat.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/issm/SeqMat.cpp	(revision 12329)
+++ /issm/trunk/src/c/toolkits/issm/SeqMat.cpp	(revision 12330)
@@ -92,52 +92,4 @@
 }
 /*}}}*/
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-/*FUNCTION SeqMat::ToMatlabMatrix{{{1*/
-mxArray* SeqMat::ToMatlabMatrix(void){
-
-	/*Intermediary: */
-	double* buffer=NULL;
-	mxArray* pfield=NULL;
-	
-	/*output: */
-	mxArray* dataref=NULL;
-
-	/*copy vector into a new buffer: */
-	if(this->M*this->N){
-		buffer=(double*)xmalloc(this->M*this->N*sizeof(double));
-		memcpy(buffer,this->matrix,M*N*sizeof(double));
-
-		pfield=mxCreateDoubleMatrix(0,0,mxREAL);
-		mxSetM(pfield,this->N);
-		mxSetN(pfield,this->M);
-		mxSetPr(pfield,buffer);
-		
-		//transpose the matrix, written directly to matlab! from C to matlab.
-		mexCallMATLAB(1,&dataref, 1, &pfield, "transpose");
-	}
-	else dataref=mxCreateDoubleMatrix(0,0,mxREAL);
-
-	/*do not erase buffer!: */
-	return dataref;
-
-}
-
-
-	
-	
-/*}}}*/
-/*FUNCTION MatlabMatrixToSeqMat{{{1*/
-SeqMat* MatlabMatrixToSeqMat(const mxArray* dataref){
-
-	SeqMat* output=NULL;
-
-	output=new SeqMat();
-	MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref);
-	return output;
-
-}
-/*}}}*/
-#endif
 /*FUNCTION SeqMat::Assemble{{{1*/
 void SeqMat::Assemble(void){
Index: /issm/trunk/src/c/toolkits/issm/SeqMat.h
===================================================================
--- /issm/trunk/src/c/toolkits/issm/SeqMat.h	(revision 12329)
+++ /issm/trunk/src/c/toolkits/issm/SeqMat.h	(revision 12330)
@@ -15,8 +15,4 @@
 
 #include "../toolkitsenums.h"
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "mex.h"
-#endif
 
 /*}}}*/
@@ -40,7 +36,4 @@
 		/*SeqMat specific routines {{{1*/
 		void Echo(void);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		mxArray* ToMatlabMatrix(void);
-		#endif
 		void Assemble(void);
 		double Norm(NormMode norm_type);
@@ -56,8 +49,3 @@
 };
 		
-/*API :*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-SeqMat*  MatlabMatrixToSeqMat(const mxArray* dataref);
-#endif
-
 #endif //#ifndef _SEQMAT_H_
Index: /issm/trunk/src/c/toolkits/issm/SeqVec.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/issm/SeqVec.cpp	(revision 12329)
+++ /issm/trunk/src/c/toolkits/issm/SeqVec.cpp	(revision 12330)
@@ -66,42 +66,4 @@
 /*}}}*/
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-/*FUNCTION SeqVec::ToMatlabVector{{{1*/
-mxArray* SeqVec::ToMatlabVector(void){
-
-	double* buffer=NULL;
-	
-	mxArray* dataref=NULL;
-
-	/*copy vector into a new buffer: */
-	if(this->M){
-		buffer=(double*)xmalloc(this->M*sizeof(double));
-		memcpy(buffer,vector,M*sizeof(double));
-
-		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
-		mxSetM(dataref,this->M);
-		mxSetN(dataref,1);
-		mxSetPr(dataref,buffer);	
-	}
-	else dataref = mxCreateDoubleMatrix(0,0,mxREAL);
-
-
-	/*do not erase buffer!: */
-	return dataref;
-
-}
-/*}}}*/
-/*FUNCTION MatlabVectorToSeqVec{{{1*/
-SeqVec* MatlabVectorToSeqVec(const mxArray* dataref){
-
-	SeqVec* output=NULL;
-
-	output=new SeqVec();
-	MatlabVectorToDoubleVector(&output->vector,&output->M,dataref);
-	return output;
-
-}
-/*}}}*/
-#endif
 /*FUNCTION SeqVec::Assemble{{{1*/
 void SeqVec::Assemble(void){
Index: /issm/trunk/src/c/toolkits/issm/SeqVec.h
===================================================================
--- /issm/trunk/src/c/toolkits/issm/SeqVec.h	(revision 12329)
+++ /issm/trunk/src/c/toolkits/issm/SeqVec.h	(revision 12330)
@@ -15,8 +15,4 @@
 
 #include "../toolkitsenums.h"
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "mex.h"
-#endif
 
 /*}}}*/
@@ -37,7 +33,4 @@
 		/*SeqVec specific routines {{{1*/
 		void Echo(void);
-		#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		mxArray* ToMatlabVector(void);
-		#endif
 		void Assemble(void);
 		void SetValues(int ssize, int* list, double* values, InsMode mode);
@@ -59,9 +52,3 @@
 };
 
-
-/*API :*/
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-SeqVec*  MatlabVectorToSeqVec(const mxArray* dataref);
-#endif
-
 #endif //#ifndef _SEQVEC_H_
Index: /issm/trunk/src/c/toolkits/petsc/patches/MatInvert.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/MatInvert.cpp	(revision 12329)
+++ /issm/trunk/src/c/toolkits/petsc/patches/MatInvert.cpp	(revision 12330)
@@ -55,10 +55,6 @@
 	MatAssemblyBegin(inv,MAT_FINAL_ASSEMBLY);
 	MatAssemblyEnd(inv,MAT_FINAL_ASSEMBLY);
-
-	#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-		MatConvert(inv, MATSEQAIJ,MAT_REUSE_MATRIX,&inv);
-	#else
-		MatConvert(inv, MATMPIAIJ,MAT_REUSE_MATRIX,&inv);
-	#endif
+		
+	MatConvert(inv, MATMPIAIJ,MAT_REUSE_MATRIX,&inv);
 	
 	/*Free ressources:*/
Index: sm/trunk/src/c/toolkits/petsc/patches/MatlabMatrixToPetscMatrix.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/MatlabMatrixToPetscMatrix.cpp	(revision 12329)
+++ 	(revision )
@@ -1,123 +1,0 @@
-/* \file MatlabMatrixToPetscMatrix.cpp
- * \brief: convert a sparse or dense matlab matrix to a serial Petsc matrix:
- */
-
-
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-
-/*Petsc includes: */
-#include "petscmat.h"
-#include "petscvec.h"
-#include "petscksp.h"
-
-/*Matlab includes: */
-#include "mex.h"
-
-#include "../../../shared/shared.h"
-
-int MatlabMatrixToPetscMatrix(Mat* pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){
-
-	int rows, cols;
-	double* mxmatrix_ptr=NULL;
-	double* tmatrix=NULL;
-	int ierr;
-	int i,j;
-
-	/*output: */
-	Mat matrix=NULL;
-
-	/*matlab indices: */
-	mwIndex*    ir=NULL;
-	mwIndex*    jc=NULL;
-	double* pr=NULL;
-	int     count;
-	int     nnz;
-	int     nz;
-
-	/*petsc indices: */
-	int* idxm=NULL;
-	int* idxn=NULL;
-	
-	/*Ok, first check if we are dealing with a sparse or full matrix: */
-	if (mxIsSparse(mxmatrix)){
-
-		/*Dealing with sparse matrix: recover size first: */
-		mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
-		rows=mxGetM(mxmatrix);
-		cols=mxGetN(mxmatrix);
-		nnz=mxGetNzmax(mxmatrix);
-		if(rows){
-			nz=(int)((double)nnz/(double)rows);
-		}
-		else{
-			nz=0;
-		}
-
-		ierr=MatCreateSeqAIJ(PETSC_COMM_SELF,rows,cols,nz,PETSC_NULL,&matrix);CHKERRQ(ierr);
-
-		/*Now, get ir,jc and pr: */
-		pr=mxGetPr(mxmatrix);
-		ir=mxGetIr(mxmatrix);
-		jc=mxGetJc(mxmatrix);
-
-		/*Now, start inserting data into sparse matrix: */
-		count=0;
-		for(i=0;i<cols;i++){
-			for(j=0;j<(jc[i+1]-jc[i]);j++){
-				MatSetValue(matrix,ir[count],i,pr[count],INSERT_VALUES);
-				count++;
-			}
-		}
-
-	}
-	else{
-
-		/*Dealing with dense matrix: recover pointer and size: */
-		mxmatrix_ptr=(double*)mxGetPr(mxmatrix);
-		rows=mxGetM(mxmatrix);
-		cols=mxGetN(mxmatrix);
-
-		/*transpose, as Petsc now does not allows MAT_COLUMN_ORIENTED matrices in MatSetValues: */
-		tmatrix=(double*)xmalloc(rows*cols*sizeof(double));
-		for(i=0;i<cols;i++){
-			for(j=0;j<rows;j++){
-				*(tmatrix+rows*i+j)=*(mxmatrix_ptr+cols*j+i);
-			}
-		}
-
-		/*Create serial matrix: */
-		ierr=MatCreateSeqDense(PETSC_COMM_SELF,rows,cols,NULL,&matrix);CHKERRQ(ierr);
-
-		/*Insert mxmatrix_ptr values into petsc matrix: */
-		idxm=(int*)xmalloc(rows*sizeof(int));
-		idxn=(int*)xmalloc(cols*sizeof(int));
-
-		for(i=0;i<rows;i++)idxm[i]=i;
-		for(i=0;i<cols;i++)idxn[i]=i;
-
-		ierr=MatSetValues(matrix,rows,idxm,cols,idxn,tmatrix,INSERT_VALUES); CHKERRQ(ierr);
-
-		xfree((void**)&tmatrix);
-
-	}
-
-	/*Assemble matrix: */
-	MatAssemblyBegin(matrix,MAT_FINAL_ASSEMBLY); 
-	MatAssemblyEnd(matrix,MAT_FINAL_ASSEMBLY);
-
-
-	/*Assign output pointer: */
-	*pmatrix=matrix;
-	if(pmatrix_rows) *pmatrix_rows=rows;
-	if(pmatrix_cols) *pmatrix_cols=cols;
-
-	return 1;
-}
-#endif
Index: sm/trunk/src/c/toolkits/petsc/patches/MatlabVectorToPetscVector.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/MatlabVectorToPetscVector.cpp	(revision 12329)
+++ 	(revision )
@@ -1,102 +1,0 @@
-/* \file MatlabVectorToPetscVector.cpp
- * \brief: convert a sparse or dense matlab vector to a serial Petsc vector:
- */
-
-
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-
-/*Petsc includes: */
-#include "petscmat.h"
-#include "petscvec.h"
-#include "petscksp.h"
-
-/*Matlab includes: */
-#include "mex.h"
-
-#include "../../../shared/shared.h"
-
-int MatlabVectorToPetscVector(Vec* pvector,int* pvector_rows,const mxArray* mxvector){
-
-	int rows, cols;
-	double* mxvector_ptr=NULL;
-	int ierr;
-	int i,j;
-
-	/*output: */
-	Vec vector=NULL;
-
-	/*matlab indices: */
-	mwIndex*    ir=NULL;
-	mwIndex*    jc=NULL;
-	double* pr=NULL;
-	int     count;
-	int     nnz;
-	int     nz;
-
-	/*petsc indices: */
-	int* idxm=NULL;
-	
-	/*Ok, first check if we are dealing with a sparse or full vector: */
-	if (mxIsSparse(mxvector)){
-
-		/*Dealing with sparse vector: recover size first: */
-		mxvector_ptr=(double*)mxGetPr(mxvector);
-		rows=mxGetM(mxvector);
-		cols=mxGetN(mxvector);
-		nnz=mxGetNzmax(mxvector);
-		nz=(int)((double)nnz/(double)rows);
-
-		ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr);
-
-		/*Now, get ir,jc and pr: */
-		pr=mxGetPr(mxvector);
-		ir=mxGetIr(mxvector);
-		jc=mxGetJc(mxvector);
-
-		/*Now, start inserting data into sparse vector: */
-		count=0;
-		for(i=0;i<cols;i++){
-			for(j=0;j<(jc[i+1]-jc[i]);j++){
-				VecSetValue(vector,ir[count],pr[count],INSERT_VALUES);
-				count++;
-			}
-		}
-
-	}
-	else{
-
-		/*Dealing with dense vector: recover pointer and size: */
-		mxvector_ptr=(double*)mxGetPr(mxvector);
-		rows=mxGetM(mxvector);
-		cols=mxGetN(mxvector);
-
-		/*Create serial vector: */
-		ierr=VecCreateSeq(PETSC_COMM_SELF,rows,&vector);CHKERRQ(ierr);
-
-		/*Insert mxvector_ptr values into petsc vector: */
-		idxm=(int*)xmalloc(rows*sizeof(int));
-
-		for(i=0;i<rows;i++)idxm[i]=i;
-
-		ierr=VecSetValues(vector,rows,idxm,mxvector_ptr,INSERT_VALUES);CHKERRQ(ierr);
-
-	}
-
-	/*Assemble vector: */
-	VecAssemblyBegin(vector);
-	VecAssemblyEnd(vector);
-
-	/*Assign output pointer: */
-	*pvector=vector;
-	*pvector_rows=rows;
-
-	return 1;
-}
-#endif
Index: /issm/trunk/src/c/toolkits/petsc/patches/NewMat.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/NewMat.cpp	(revision 12329)
+++ /issm/trunk/src/c/toolkits/petsc/patches/NewMat.cpp	(revision 12330)
@@ -68,5 +68,10 @@
 
 	#ifdef _HAVE_PETSCDEV_
-	MatCreateAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 
+	if(sparsity==1){
+		MatCreateDense(MPI_COMM_WORLD,m,n,M,N,NULL,&outmatrix); 
+	}
+	else{
+		MatCreateAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 
+	}
 	#else
 	MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix); 
Index: /issm/trunk/src/c/toolkits/petsc/patches/PetscMatrixToDoubleMatrix.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/PetscMatrixToDoubleMatrix.cpp	(revision 12330)
+++ /issm/trunk/src/c/toolkits/petsc/patches/PetscMatrixToDoubleMatrix.cpp	(revision 12330)
@@ -0,0 +1,51 @@
+/* \file PetscMatrixToDoubleMatrix.cpp
+ * \brief: convert a sparse or dense Petsc matrix into a matlab matrix
+ */
+
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <string>
+
+/*Petsc includes: */
+#include "petscmat.h"
+#include "petscvec.h"
+#include "petscksp.h"
+
+/*Petsc includes: */
+#include "../../../shared/shared.h"
+
+
+void PetscMatrixToDoubleMatrix(double** pmatrix, int* prows, int* pcols,Mat petsc_matrix){
+
+	int i,j,k;
+
+	/*output: */
+	double* matrix=NULL;
+	int     rows,cols;
+
+	/*intermediary: */
+	int*    idxm=NULL;
+	int*    idxn=NULL;
+
+	/*Some needed information: */
+	MatGetSize(petsc_matrix,&rows,&cols);
+
+	idxm=(int*)xmalloc(rows*sizeof(int));
+	idxn=(int*)xmalloc(cols*sizeof(int));
+
+	for(i=0;i<rows;i++)idxm[i]=i;
+	for(i=0;i<cols;i++)idxn[i]=i;
+
+	matrix=(double*)xmalloc(rows*cols*sizeof(double));
+	MatGetValues(petsc_matrix,rows,idxm,cols,idxn,matrix);
+
+	/*Assign output pointers: */
+	*pmatrix=matrix;
+	*prows=rows;
+	*pcols=cols;
+}
Index: sm/trunk/src/c/toolkits/petsc/patches/PetscMatrixToMatlabMatrix.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/PetscMatrixToMatlabMatrix.cpp	(revision 12329)
+++ 	(revision )
@@ -1,150 +1,0 @@
-/* \file PetscMatrixToMatlabMatrix.cpp
- * \brief: convert a sparse or dense Petsc matrix into a matlab matrix
- */
-
-
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-
-/*Petsc includes: */
-#include "petscmat.h"
-#include "petscvec.h"
-#include "petscksp.h"
-
-/*Petsc includes: */
-#include "mex.h"
-
-#include "../../../shared/shared.h"
-#include <string>
-
-
-int PetscMatrixToMatlabMatrix(mxArray** pdataref,Mat tmatrix){
-
-	int i,j,k;
-
-	/*output: */
-	mxArray* dataref=NULL;
-	int    rows,cols;
-
-	int ncols;
-	int nnz=0;
-	int nzmax=0;
-	const int* columns=NULL;
-	const double* column_values=NULL;
-	double* matrix_ptr=NULL;
-
-	/*compress row format: */
-	double* val=NULL;
-	mwIndex*    col_ind=NULL;
-	mwIndex*    row_ptr=NULL;
-
-	/*petsc type: */
-	const char* type=NULL;
-	int*    idxm=NULL;
-	int*    idxn=NULL;
-	Mat     matrix=NULL;
-
-	
-	/*First off, we need to transpose the matrix using the Petsc API. We tried using the transpose operation from 
-	 * Matlab, but this ends up creating issues with lost pointers and references: */
-	MatTranspose(tmatrix,MAT_INITIAL_MATRIX,&matrix);
-
-	/*Some needed information: */
-	MatGetType(matrix,&type);
-	MatGetSize(matrix,&rows,&cols);
-
-	if (strcmp(type,MATSEQAIJ)==0){
-		
-		/*Dealing with a sparse sequential matrix: build ir, jc and val, as though it was a row comvalessed 
-		 *format, instead of a column comvalessed format. We'll transpose later.*/
-
-		/*First get nnz: */
-		nnz=0;
-		for(i=0;i<rows;i++){
-			MatGetRow(matrix,i,&ncols,&columns,&column_values);
-			nnz+=ncols;
-			MatRestoreRow(matrix,i,&ncols,&columns,&column_values);
-		}
-
-		if(nnz){
-			nzmax=nnz;
-		}
-		else{
-			nzmax=1; //so a null matrix can be returned.
-		}
-
-		val=(double*)xcalloc(nzmax,sizeof(double));
-		col_ind=(mwIndex*)xcalloc(nzmax,sizeof(mwIndex));
-		row_ptr=(mwIndex*)xcalloc((rows+1),sizeof(mwIndex));
-
-		j=0;
-
-		for(i=0;i<rows;i++){
-
-			/*Get row from petsc matrix: */
-			MatGetRow(matrix,i,&ncols,&columns,&column_values);
-
-			/*copy values: */
-			if(ncols)memcpy( val+j, column_values,ncols*sizeof(double));
-			  
-			for(k=0;k<ncols;k++) col_ind[j+k]=(mwIndex)columns[k];
-			row_ptr[i]=(mwIndex)j;
-			
-			j+=ncols;
-			
-			/*restore petsc row, otherwise we are leaking memory: */
-			MatRestoreRow(matrix,i,&ncols,&columns,&column_values);
-		}
-		row_ptr[rows]=(mwIndex)nnz;
-
-		/*Ok, allocate arrays: */
-		dataref = mxCreateSparse((mwSize)0,(mwSize)0,(mwSize)0,mxREAL);
-	
-		/* free first to avoid mem leaks...: */
-		mxFree(mxGetData(dataref));
-		mxFree(mxGetIr(dataref));
-		mxFree(mxGetJc(dataref));
-		
-		/* ...then set data: */
-		mxSetM(dataref,(mwSize)cols);
-		mxSetN(dataref,(mwSize)rows);
-		mxSetNzmax(dataref,(mwSize)nzmax);
-		mxSetData( dataref, val);
-		mxSetIr(dataref,col_ind);
-		mxSetJc(dataref,row_ptr);
-
-	}
-	else{
-		/*Dealing with a dense sequential matrix: recover pointer to the data in the Petsc matrix*/
-
-		idxm=(int*)xmalloc(rows*sizeof(int));
-		idxn=(int*)xmalloc(cols*sizeof(int));
-
-		for(i=0;i<rows;i++)idxm[i]=i;
-		for(i=0;i<cols;i++)idxn[i]=i;
-
-		matrix_ptr=(double*)xmalloc(rows*cols*sizeof(double));
-		MatGetValues(matrix,rows,idxm,cols,idxn,matrix_ptr);
-
-		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
-		mxSetM(dataref,cols);
-		mxSetN(dataref,rows);
-		mxSetPr(dataref,(double*)matrix_ptr);	
-	}
-
-	/*Free ressources:*/
-	MatFree(&matrix);
-
-	/*Assign output pointers: */
-	*pdataref=dataref;
-
-	return 1;
-}
-
-#endif  
Index: /issm/trunk/src/c/toolkits/petsc/patches/PetscVectorToDoubleVector.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/PetscVectorToDoubleVector.cpp	(revision 12330)
+++ /issm/trunk/src/c/toolkits/petsc/patches/PetscVectorToDoubleVector.cpp	(revision 12330)
@@ -0,0 +1,44 @@
+/* \file PetscVectorToDoubleVector.cpp
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include <string>
+
+/*Petsc includes: */
+#include "petscmat.h"
+#include "petscvec.h"
+#include "petscksp.h"
+
+#include "../../../shared/shared.h"
+
+void PetscVectorToDoubleVector(double** pvector, int* prows, Vec petsc_vector){
+
+	int     i;
+	int     rows;
+	int    *idxm   = NULL;
+	double *vector = NULL;
+
+	/*Get size of vector: */
+	if(petsc_vector){
+		VecGetSize(petsc_vector,&rows);
+		if(rows){
+			idxm=(int*)xmalloc(rows*sizeof(int));
+			vector=(double*)xmalloc(rows*sizeof(double));
+			for(i=0;i<rows;i++)idxm[i]=i;
+
+			VecGetValues(petsc_vector,rows,idxm,vector);
+		}
+	}
+	else{
+		rows=0;
+	}
+
+	/*Assign output pointers: */
+	*pvector=vector;
+	*prows=rows;
+}
Index: sm/trunk/src/c/toolkits/petsc/patches/PetscVectorToMatlabVector.cpp
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/PetscVectorToMatlabVector.cpp	(revision 12329)
+++ 	(revision )
@@ -1,66 +1,0 @@
-/* \file PetscVectorToMatlabVector.cpp
- * \brief: convert a sparse or dense Petsc vector into a matlab vector
- */
-
-
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-
-/*Petsc includes: */
-#include "petscmat.h"
-#include "petscvec.h"
-#include "petscksp.h"
-
-/*Petsc includes: */
-#include "mex.h"
-
-#include "../../../shared/shared.h"
-#include <string>
-
-
-int PetscVectorToMatlabVector(mxArray** pdataref,Vec vector){
-
-	int     i;
-	int     rows;
-	int    *idxm   = NULL;
-	double *values = NULL;
-
-	/*output: */
-	mxArray* dataref=NULL;
-
-	/*Get size of vector: */
-	if(vector){
-		VecGetSize(vector,&rows);
-		if(rows){
-			idxm=(int*)xmalloc(rows*sizeof(int));
-			values=(double*)xmalloc(rows*sizeof(double));
-			for(i=0;i<rows;i++)idxm[i]=i;
-
-			VecGetValues(vector,rows,idxm,values);
-		}
-	}
-	else{
-		rows=0;
-	}
-
-	/*Using values, build a matlab vector: */
-	dataref = mxCreateDoubleMatrix(0,0,mxREAL);
-	mxSetM(dataref,rows);
-	mxSetN(dataref,1);
-	mxSetPr(dataref,(double*)values);	
-
-	/*Some logic here to make the vector sparse? Although this could slow down the code quite a bit: */
-
-	/*Assign output pointers: */
-	*pdataref=dataref;
-
-	return 1;
-}
-
-#endif  //#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
Index: /issm/trunk/src/c/toolkits/petsc/patches/petscpatches.h
===================================================================
--- /issm/trunk/src/c/toolkits/petsc/patches/petscpatches.h	(revision 12329)
+++ /issm/trunk/src/c/toolkits/petsc/patches/petscpatches.h	(revision 12330)
@@ -15,12 +15,4 @@
 
 class Parameters;
-
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "mex.h"
-int MatlabMatrixToPetscMatrix(Mat* matrix,int* prows,int* pcols, const mxArray* mxmatrix);
-int MatlabVectorToPetscVector(Vec* pvector,int* pvector_rows,const mxArray* mxvector);
-int PetscMatrixToMatlabMatrix(mxArray** pdataref,Mat matrix);
-int PetscVectorToMatlabVector(mxArray** pdataref,Vec vector);
-#endif
 
 Vec NewVec(int size,bool fromlocalsize=false);
@@ -51,3 +43,6 @@
 MatType ISSMToPetscMatrixType(MatrixType type);
 
+void PetscMatrixToDoubleMatrix(double** pmatrix, int* prows, int* pcols,Mat matrix);
+void PetscVectorToDoubleVector(double** pvector, int* prows, Vec vector);
+
 #endif
Index: /issm/trunk/src/c/toolkits/python/pythonincludes.h
===================================================================
--- /issm/trunk/src/c/toolkits/python/pythonincludes.h	(revision 12329)
+++ /issm/trunk/src/c/toolkits/python/pythonincludes.h	(revision 12330)
@@ -7,8 +7,19 @@
 
 
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#if _PYTHON_MAJOR_ == 2
+#undef NPY_NO_DEPRECATED_API
+#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
+#else
+#define NPY_NO_DEPRECATED_API 
+#endif
+
 #include "Python.h"
 #include "arrayobject.h"
-
-
 
 #ifdef _HAVE_BOOST_
Index: /issm/trunk/src/c/toolkits/toolkits.h
===================================================================
--- /issm/trunk/src/c/toolkits/toolkits.h	(revision 12329)
+++ /issm/trunk/src/c/toolkits/toolkits.h	(revision 12330)
@@ -12,5 +12,5 @@
 #endif
 
-#if defined(_HAVE_PYTHON_) && defined(_SERIAL_)
+#ifdef _HAVE_PYTHON_
 #include "./python/pythonincludes.h"
 #endif
@@ -20,13 +20,13 @@
 #endif
 
-#if defined(_HAVE_MATLAB_) && defined(_SERIAL_)
-#include "./matlab/matlabincludes.h"
+#ifdef _HAVE_MPI_
+#include "./mpi/mpiincludes.h"
 #endif
 
+#ifdef _HAVE_METIS_
+#include "./metis/metisincludes.h"
+#endif
 
-#include "./mpi/mpiincludes.h"
-#include "./metis/metisincludes.h"
 #include "./triangle/triangleincludes.h"
-#include "./double/double.h"
 #include "./toolkitsenums.h"
 #include "./issm/issmtoolkit.h"
Index: /issm/trunk/src/c/toolkits/triangle/triangleincludes.h
===================================================================
--- /issm/trunk/src/c/toolkits/triangle/triangleincludes.h	(revision 12329)
+++ /issm/trunk/src/c/toolkits/triangle/triangleincludes.h	(revision 12330)
@@ -6,6 +6,4 @@
 #define _TRIANGLE_INCLUDES_H_
 
-#ifdef _SERIAL_
-
 #ifdef _C_ //only valid for iso C, not C++
 /*Triangle includes: */
@@ -13,6 +11,4 @@
 #endif //#ifdef _C_
 
-#endif //ifdef _SERIAL_
-
 
 #endif
