Index: /issm/trunk-jpl/src/c/Container/DataSet.cpp
===================================================================
--- /issm/trunk-jpl/src/c/Container/DataSet.cpp	(revision 12014)
+++ /issm/trunk-jpl/src/c/Container/DataSet.cpp	(revision 12015)
@@ -84,329 +84,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-jpl/src/c/Container/DataSet.h
===================================================================
--- /issm/trunk-jpl/src/c/Container/DataSet.h	(revision 12014)
+++ /issm/trunk-jpl/src/c/Container/DataSet.h	(revision 12015)
@@ -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-jpl/src/c/Container/Options.cpp
===================================================================
--- /issm/trunk-jpl/src/c/Container/Options.cpp	(revision 12014)
+++ /issm/trunk-jpl/src/c/Container/Options.cpp	(revision 12015)
@@ -20,7 +20,5 @@
 #include "../shared/shared.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
-#if _SERIAL_
 #include "../io/io.h"
-#endif
 /*}}}*/
 
@@ -31,30 +29,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(){
Index: /issm/trunk-jpl/src/c/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/c/Makefile.am	(revision 12014)
+++ /issm/trunk-jpl/src/c/Makefile.am	(revision 12015)
@@ -727,4 +727,5 @@
 #Python sources  {{{1
 python_sources=     ./python/io/pythonio.h\
+					./python/python-binding.h\
 				    ./python/io/WritePythonData.cpp\
 				    ./python/io/CheckNumPythonArguments.cpp\
@@ -740,4 +741,5 @@
 #Matlab sources  {{{1
 matlab_sources= ./toolkits/matlab/matlabincludes.h\
+				    ./matlab/matlab-binding.h\
 				    ./matlab/io/matlabio.h\
 				    ./matlab/io/MatlabNArrayToNArray.cpp\
Index: /issm/trunk-jpl/src/c/include/macros.h
===================================================================
--- /issm/trunk-jpl/src/c/include/macros.h	(revision 12014)
+++ /issm/trunk-jpl/src/c/include/macros.h	(revision 12015)
@@ -40,5 +40,4 @@
 #endif
 /*}}}*/
-
 /* MODULEBOOT/MODULEEND {{{1*/
 
@@ -47,14 +46,4 @@
  * will be trapped. Really nifty!*/
 
-#ifdef _SERIAL_
-#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{
@@ -69,41 +58,4 @@
 		return 1;\
 	}
-//}}}
-#endif
-/*}}}*/
-/* WRAPPER {{{1*/
-#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_PYTHON_
-#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer)
-#endif
 /*}}}*/
 
Index: /issm/trunk-jpl/src/c/matlab/include/matlab_macros.h
===================================================================
--- /issm/trunk-jpl/src/c/matlab/include/matlab_macros.h	(revision 12014)
+++ /issm/trunk-jpl/src/c/matlab/include/matlab_macros.h	(revision 12015)
@@ -1,4 +1,4 @@
-/* \file macros.h
- * \brief: global macros used in the whole code
+/* \file matlab macros.h
+ * \brief: macros used for the matlab bindings
  */
 
Index: /issm/trunk-jpl/src/c/python/include/python_macros.h
===================================================================
--- /issm/trunk-jpl/src/c/python/include/python_macros.h	(revision 12015)
+++ /issm/trunk-jpl/src/c/python/include/python_macros.h	(revision 12015)
@@ -0,0 +1,59 @@
+/* \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
+/*}}}*/
+
+/* 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;
+
+#define MODULEEND();  ModuleEnd(); \
+						 return output;
+//}}}
+/* WRAPPER {{{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)
+/*}}}*/
+/* CHECKARGUMENTS {{{1*/
+#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer)
+/*}}}*/
+
+#endif
Index: /issm/trunk-jpl/src/c/python/python-binding.h
===================================================================
--- /issm/trunk-jpl/src/c/python/python-binding.h	(revision 12015)
+++ /issm/trunk-jpl/src/c/python/python-binding.h	(revision 12015)
@@ -0,0 +1,6 @@
+#ifndef _PYTHON_BINDING_H_
+#define _PYTHON_BINDING_H_
+
+#include "./io/pythonio.h"
+#include "./include/python_macros.h"
+#endif
Index: /issm/trunk-jpl/src/c/shared/shared.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/shared.h	(revision 12014)
+++ /issm/trunk-jpl/src/c/shared/shared.h	(revision 12015)
@@ -8,4 +8,5 @@
 
 #include "Alloc/alloc.h"
+#include "Alloc/alloc_module.h"
 #include "Exceptions/exceptions.h"
 #include "Exp/exp.h"
Index: /issm/trunk-jpl/src/mex/TriMesh/TriMesh.cpp
===================================================================
--- /issm/trunk-jpl/src/mex/TriMesh/TriMesh.cpp	(revision 12014)
+++ /issm/trunk-jpl/src/mex/TriMesh/TriMesh.cpp	(revision 12015)
@@ -50,9 +50,9 @@
 	/*free ressources: */
 	delete domain;
-	xdelete(&index);
-	xdelete(&x);
-	xdelete(&y);
-	xdelete(&segments);
-	xdelete(&segmentmarkerlist);
+	xdelete_module(&index);
+	xdelete_module(&x);
+	xdelete_module(&y);
+	xdelete_module(&segments);
+	xdelete_module(&segmentmarkerlist);
 
 	/*end module: */
