Index: /issm/trunk-jpl/src/c/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/c/Makefile.am	(revision 13748)
+++ /issm/trunk-jpl/src/c/Makefile.am	(revision 13749)
@@ -1,3 +1,3 @@
-AM_CPPFLAGS = @DAKOTAINCL@ @SHAPELIBINCL@ @PETSCINCL@ @SLEPCINCL@ @MPIINCL@ @MATLABINCL@ @METISINCL@ @CHACOINCL@ @SCOTCHINCL@ @PLAPACKINCL@ @BLASLAPACKINCL@ @MKLINCL@ @MUMPSINCL@ @TRIANGLEINCL@ @SPAIINCL@ @HYPREINCL@ @PROMETHEUSINCL@ @SUPERLUINCL@ @SPOOLESINCL@ @PASTIXINCL@ @MLINCL@ @TAOINCL@ @ADIC2INCL@ @ADOLCINCL@ @GSLINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@
+AM_CPPFLAGS = @DAKOTAINCL@ @SHAPELIBINCL@ @PETSCINCL@ @SLEPCINCL@ @MPIINCL@ @METISINCL@ @CHACOINCL@ @SCOTCHINCL@ @PLAPACKINCL@ @BLASLAPACKINCL@ @MKLINCL@ @MUMPSINCL@ @TRIANGLEINCL@ @SPAIINCL@ @HYPREINCL@ @PROMETHEUSINCL@ @SUPERLUINCL@ @SPOOLESINCL@ @PASTIXINCL@ @MLINCL@ @TAOINCL@ @ADIC2INCL@ @ADOLCINCL@ @GSLINCL@ @BOOSTINCL@
 
 EXEEXT=$(ISSMEXT)
@@ -8,13 +8,4 @@
 if SHAREDLIBS
 lib_LTLIBRARIES = libISSMCore.la libISSMOverload.la libISSM.la
-endif
-if PYTHON
-lib_LIBRARIES += libISSMPython.a 
-endif
-if MATLAB
-if SHAREDLIBS
-lib_LTLIBRARIES += libISSMMatlab.la
-endif
-lib_LIBRARIES += libISSMMatlab.a 
 endif
 if WRAPPERS
@@ -764,34 +755,4 @@
 					./toolkits/metis/patches/METIS_PartMeshNodalPatch.cpp
 #}}}
-#Python sources  {{{
-python_sources=     ./python/io/pythonio.h\
-					./python/python-binding.h\
-				    ./python/io/WritePythonData.cpp\
-				    ./python/io/CheckNumPythonArguments.cpp\
-				    ./python/io/FetchPythonData.cpp
-
-#}}}
-#Matlab sources  {{{
-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  {{{
-matlabpetsc_sources= ./matlab/io/MatlabMatrixToPetscMat.cpp\
-					 ./matlab/io/MatlabVectorToPetscVec.cpp
-
-#}}}
 #Wrappers sources{{{
 wrapper_sources= ./shared/Threads/issm_threads.h\
@@ -945,10 +906,4 @@
 endif
 
-if PETSC
-if MATLAB
-issm_sources +=  $(matlabpetsc_sources)
-endif
-endif
-
 if KRIGING
 issm_sources +=  $(pkriging_sources)
@@ -984,17 +939,4 @@
 if SHAREDLIBS
 libISSMWrappers_la_SOURCES = $(libISSMWrappers_a_SOURCES)
-endif
-endif
-
-if PYTHON
-libISSMPython_a_SOURCES = $(python_sources)
-libISSMPython_a_CXXFLAGS= $(ALLCXXFLAGS)
-endif
-
-if MATLAB
-libISSMMatlab_a_SOURCES = $(matlab_sources)
-libISSMMatlab_a_CXXFLAGS= $(ALLCXXFLAGS)
-if SHAREDLIBS
-libISSMMatlab_la_SOURCES = $(libISSMMatlab_a_SOURCES)
 endif
 endif
Index: sm/trunk-jpl/src/c/issm-binding.h
===================================================================
--- /issm/trunk-jpl/src/c/issm-binding.h	(revision 13748)
+++ 	(revision )
@@ -1,18 +1,0 @@
-#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: sm/trunk-jpl/src/c/toolkits/python/pythonincludes.h
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/python/pythonincludes.h	(revision 13748)
+++ 	(revision )
@@ -1,24 +1,0 @@
-/* \file pythonincludes.h
- * \brief all includes for PYTHON layer
- */
-
-#ifndef _PYTHON_INCLUDES_H_
-#define _PYTHON_INCLUDES_H_
-
-#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"
-
-#endif
Index: /issm/trunk-jpl/src/c/toolkits/toolkits.h
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/toolkits.h	(revision 13748)
+++ /issm/trunk-jpl/src/c/toolkits/toolkits.h	(revision 13749)
@@ -10,8 +10,4 @@
 #else
 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#ifdef _HAVE_PYTHON_
-#include "./python/pythonincludes.h"
 #endif
 
@@ -31,4 +27,3 @@
 #include "./toolkitsenums.h"
 #include "./issm/issmtoolkit.h"
-
 #endif
Index: /issm/trunk-jpl/src/wrappers/AverageFilter/AverageFilter.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/AverageFilter/AverageFilter.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/AverageFilter/AverageFilter.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/BamgConvertMesh/BamgConvertMesh.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/BamgConvertMesh/BamgConvertMesh.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/BamgConvertMesh/BamgConvertMesh.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 #include "../../c/io/io.h"
 
Index: /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/BamgMesher/BamgMesher.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/BamgTriangulate/BamgTriangulate.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/BamgTriangulate/BamgTriangulate.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/BamgTriangulate/BamgTriangulate.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/Chaco/Chaco.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/Chaco/Chaco.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/Chaco/Chaco.h	(revision 13749)
@@ -25,5 +25,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/ContourToMesh/ContourToMesh.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/ContourToMesh/ContourToMesh.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/ContourToMesh/ContourToMesh.h	(revision 13749)
@@ -24,5 +24,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 #include "../../c/io/io.h"
 #include "../../c/EnumDefinitions/EnumDefinitions.h"
Index: /issm/trunk-jpl/src/wrappers/ContourToNodes/ContourToNodes.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/ContourToNodes/ContourToNodes.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/ContourToNodes/ContourToNodes.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__
Index: /issm/trunk-jpl/src/wrappers/ElementConnectivity/ElementConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/ElementConnectivity/ElementConnectivity.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/ElementConnectivity/ElementConnectivity.h	(revision 13749)
@@ -24,5 +24,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 #include "../../c/io/io.h"
 #include "../../c/EnumDefinitions/EnumDefinitions.h"
Index: /issm/trunk-jpl/src/wrappers/EnumToString/EnumToString.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/EnumToString/EnumToString.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/EnumToString/EnumToString.h	(revision 13749)
@@ -22,5 +22,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/Exp2Kml/Exp2Kml.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/Exp2Kml/Exp2Kml.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/Exp2Kml/Exp2Kml.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/HoleFiller/HoleFiller.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/HoleFiller/HoleFiller.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/HoleFiller/HoleFiller.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/InternalFront/InternalFront.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/InternalFront/InternalFront.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/InternalFront/InternalFront.h	(revision 13749)
@@ -19,5 +19,5 @@
 #include "../../c/include/globals.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 #include "../../c/io/io.h"
 
Index: /issm/trunk-jpl/src/wrappers/InterpFromGridToMesh/InterpFromGridToMesh.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/InterpFromGridToMesh/InterpFromGridToMesh.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/InterpFromGridToMesh/InterpFromGridToMesh.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/InterpFromMesh2d/InterpFromMesh2d.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/InterpFromMesh2d/InterpFromMesh2d.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/InterpFromMesh2d/InterpFromMesh2d.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h	(revision 13749)
@@ -24,5 +24,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 #include "../../c/io/io.h"
 #include "../../c/EnumDefinitions/EnumDefinitions.h"
Index: /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/KMLFileRead/KMLFileRead.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/KMLFileRead/KMLFileRead.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/KMLFileRead/KMLFileRead.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/KMLMeshWrite/KMLMeshWrite.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/KMLMeshWrite/KMLMeshWrite.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/KMLMeshWrite/KMLMeshWrite.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/KMLOverlay/KMLOverlay.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/KMLOverlay/KMLOverlay.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/KMLOverlay/KMLOverlay.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/Kml2Exp/Kml2Exp.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/Kml2Exp/Kml2Exp.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/Kml2Exp/Kml2Exp.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/Kriging/Kriging.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/Kriging/Kriging.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/Kriging/Kriging.h	(revision 13749)
@@ -20,5 +20,5 @@
 #include "../../c/modules/modules.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/Ll2xy/Ll2xy.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/Ll2xy/Ll2xy.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/Ll2xy/Ll2xy.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/MeshProfileIntersection/MeshProfileIntersection.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/MeshProfileIntersection/MeshProfileIntersection.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/MeshProfileIntersection/MeshProfileIntersection.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__
Index: /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/NodeConnectivity/NodeConnectivity.h	(revision 13749)
@@ -27,5 +27,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 #include "../../c/io/io.h"
 #include "../../c/EnumDefinitions/EnumDefinitions.h"
Index: /issm/trunk-jpl/src/wrappers/PointCloudFindNeighbors/PointCloudFindNeighbors.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/PointCloudFindNeighbors/PointCloudFindNeighbors.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/PointCloudFindNeighbors/PointCloudFindNeighbors.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__
Index: /issm/trunk-jpl/src/wrappers/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/Scotch/Scotch.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/Scotch/Scotch.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/Scotch/Scotch.h	(revision 13749)
@@ -13,5 +13,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
     
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/Shp2Kml/Shp2Kml.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/Shp2Kml/Shp2Kml.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/Shp2Kml/Shp2Kml.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/StringToEnum/StringToEnum.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/StringToEnum/StringToEnum.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/StringToEnum/StringToEnum.h	(revision 13749)
@@ -22,5 +22,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/TriMesh/TriMesh.h	(revision 13749)
@@ -24,5 +24,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 #include "../../c/io/io.h"
 #include "../../c/EnumDefinitions/EnumDefinitions.h"
Index: /issm/trunk-jpl/src/wrappers/TriMeshProcessRifts/TriMeshProcessRifts.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriMeshProcessRifts/TriMeshProcessRifts.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/TriMeshProcessRifts/TriMeshProcessRifts.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/TriaSearch/TriaSearch.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/TriaSearch/TriaSearch.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/TriaSearch/TriaSearch.h	(revision 13749)
@@ -20,5 +20,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/Xy2ll/Xy2ll.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/Xy2ll/Xy2ll.h	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/Xy2ll/Xy2ll.h	(revision 13749)
@@ -21,5 +21,5 @@
 #include "../../c/Container/Container.h"
 #include "../../c/shared/shared.h"
-#include "../../c/issm-binding.h"
+#include "../bindings.h"
 
 #undef __FUNCT__ 
Index: /issm/trunk-jpl/src/wrappers/bindings.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/bindings.h	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/bindings.h	(revision 13749)
@@ -0,0 +1,22 @@
+#ifndef _BINDINGS_H_
+#define _BINDINGS_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/include/matlabincludes.h"
+#include "./matlab/include/wrapper_macros.h"
+#include "./matlab/io/matlabio.h"
+#endif
+
+#ifdef  _HAVE_PYTHON_MODULES_
+#include "./python/include/pythonincludes.h"
+#include "./python/include/wrapper_macros.h"
+#include "./python/io/pythonio.h"
+#endif
+
+#endif
Index: /issm/trunk-jpl/src/wrappers/include/issm-binding.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/include/issm-binding.h	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/include/issm-binding.h	(revision 13749)
@@ -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/include/matlab-macros.h"
+#endif
+
+#ifdef  _HAVE_PYTHON_MODULES_
+#include "../python/include/python-macros.h"
+#endif
+
+#endif
Index: /issm/trunk-jpl/src/wrappers/matlab/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/Makefile.am	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/matlab/Makefile.am	(revision 13749)
@@ -1,9 +1,39 @@
-AM_CPPFLAGS = @DAKOTAINCL@ @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@ @ADOLCINCL@
+AM_CPPFLAGS = @DAKOTAINCL@ @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@
 
 EXEEXT=$(MATLABWRAPPEREXT)
 
+#matlab io{{{
+lib_LIBRARIES = libISSMMatlab.a 
+if SHAREDLIBS
+lib_LTLIBRARIES = libISSMMatlab.la
+else
+lib_LTLIBRARIES =
+endif
+
+io_sources= ./include/matlabincludes.h\
+				./io/matlabio.h\
+				./io/MatlabNArrayToNArray.cpp\
+				./io/CheckNumMatlabArguments.cpp\
+				./io/mxGetAssignedField.cpp\
+				./io/WriteMatlabData.cpp\
+				./io/FetchMatlabData.cpp\
+				./io/OptionParse.cpp\
+				./io/MatlabMatrixToMatrix.cpp\
+				./io/MatlabVectorToVector.cpp\
+				./io/MatlabVectorToDoubleVector.cpp\
+				./io/MatlabMatrixToDoubleMatrix.cpp\
+				./io/MatlabMatrixToSeqMat.cpp\
+				./io/MatlabVectorToSeqVec.cpp
+
+ALLCXXFLAGS= -fPIC -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_  $(CXXFLAGS) $(CXXOPTFLAGS) 
+libISSMMatlab_a_SOURCES = $(io_sources)
+libISSMMatlab_a_CXXFLAGS= $(ALLCXXFLAGS)
+if SHAREDLIBS
+libISSMMatlab_la_SOURCES = $(io_sources)
+endif
+#}}}
 #Wrappers {{{
 if WRAPPERS
-lib_LTLIBRARIES =  AverageFilter.la\
+lib_LTLIBRARIES +=  AverageFilter.la\
 						 BamgMesher.la\
 						 BamgConvertMesh.la\
@@ -46,5 +76,4 @@
 endif
 endif 
-
 #}}}
 #Flags and libraries {{{
@@ -68,7 +97,7 @@
 endif
 if SHAREDLIBS
-deps += ../../c/libISSMMatlab.la 
-else
-deps += ../../c/libISSMMatlab.a
+deps += ./libISSMMatlab.la 
+else
+deps += ./libISSMMatlab.a
 AM_LDFLAGS += --no-warnings 
 endif
Index: /issm/trunk-jpl/src/wrappers/matlab/include/wrapper_macros.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/include/wrapper_macros.h	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/include/wrapper_macros.h	(revision 13749)
@@ -0,0 +1,42 @@
+/* \file matlab macros.h
+ * \brief: macros used for the matlab bindings
+ */
+
+#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 {{{*/
+
+/*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*/
+#define MODULEBOOT(); try{ \
+	IssmComm::SetComm(-1);
+
+#define MODULEEND(); }\
+	catch(ErrorException &exception){\
+		mexErrMsgTxt(exception.MatlabReport()); \
+	}\
+	catch (exception &e){\
+		mexErrMsgTxt(exprintf("Standard exception: %s\n",e.what()));\
+	}\
+	catch(...){\
+		mexErrMsgTxt("An unexpected error occurred");\
+	}
+/*}}}*/
+/* WRAPPER {{{*/
+#define WRAPPER(modulename,...) void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) 
+/*}}}*/
+/* CHECKARGUMENTS {{{*/
+#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,functionpointer)
+/*}}}*/
+#endif
+
+#endif
Index: /issm/trunk-jpl/src/wrappers/matlab/io/CheckNumMatlabArguments.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/CheckNumMatlabArguments.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/CheckNumMatlabArguments.cpp	(revision 13749)
@@ -0,0 +1,23 @@
+/*!\file CheckNumMatlabArguments.cpp:
+ * \brief: check number of arguments and report an usage error message.
+ */
+
+#include "./matlabio.h"
+#include "../../c/shared/Exceptions/exceptions.h"
+
+int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, 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-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp	(revision 13749)
@@ -0,0 +1,691 @@
+/*\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 "./matlabio.h"
+#include "../../c/shared/shared.h"
+
+/*Primitive data types*/
+/*FUNCTION FetchData(double** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
+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") || 
+				mxIsClass(dataref,"int16") || 
+				mxIsClass(dataref,"int8") || 
+				mxIsClass(dataref,"uint8")){
+		/*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{
+			if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){
+				_printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'");
+			}
+			/*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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*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){{{*/
+void FetchData(double** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){
+
+	int     outmatrix_numel,outmatrix_ndims;
+	double *outmatrix       = NULL;
+	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") || 
+				mxIsClass(dataref,"single") || 
+				mxIsClass(dataref,"int16") || 
+				mxIsClass(dataref,"int8") || 
+				mxIsClass(dataref,"uint8")){
+
+		/*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{
+			if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){
+				_printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'");
+			}
+			/*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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pnumel)*pnumel=outmatrix_numel;
+	if (pndims)*pndims=outmatrix_ndims;
+	if (psize )*psize =outmatrix_size;
+	else xDelete<int>(outmatrix_size);
+
+}
+/*}}}*/
+/*FUNCTION FetchData(int** pmatrix,int* pM,int *pN,const mxArray* dataref){{{*/
+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") || 
+				mxIsClass(dataref,"single") || 
+				mxIsClass(dataref,"int16") || 
+				mxIsClass(dataref,"int8") || 
+				mxIsClass(dataref,"uint8")){
+
+		/*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{
+			if(!mxIsClass(dataref,"double") && !mxIsClass(dataref,"single")){
+				_printLine_("Warning: converting matlab data from '" << mxGetClassName(dataref) << "' to 'double'");
+			}
+			/*Convert matlab matrix to double* matrix: */
+			MatlabMatrixToDoubleMatrix(&doublematrix,&outmatrix_rows,&outmatrix_cols,dataref);
+
+			/*Convert double matrix into integer matrix: */
+			outmatrix=xNew<int>(outmatrix_rows*outmatrix_cols);
+			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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*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){{{*/
+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=xNew<bool>(outmatrix_rows*outmatrix_cols);
+			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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*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){{{*/
+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=xNew<bool>(outmatrix_numel);
+			for(i=0;i<outmatrix_numel;i++)outmatrix[i]=(bool)doublematrix[i];
+			xDelete<double>(doublematrix);
+		}
+	}
+	else{
+		/*This is an error: we don't have the correct input!: */
+		_error_("Input parameter of class " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pnumel)*pnumel=outmatrix_numel;
+	if (pndims)*pndims=outmatrix_ndims;
+	if (psize )*psize =outmatrix_size;
+	else xDelete<int>(outmatrix_size);
+
+}
+/*}}}*/
+/*FUNCTION FetchData(double** pvector,int* pM,const mxArray* dataref){{{*/
+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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pvector=outvector;
+	if (pM)*pM=outvector_rows;
+}
+/*}}}*/
+/*FUNCTION FetchData(int** pvector,int* pM,const mxArray* dataref){{{*/
+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=xNew<int>(outvector_rows);
+		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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pvector=outvector;
+	if (pM)*pM=outvector_rows;
+}
+/*}}}*/
+/*FUNCTION FetchData(bool** pvector,int* pM,const mxArray* dataref){{{*/
+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=xNew<bool>(outvector_rows);
+		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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pvector=outvector;
+	if (pM)*pM=outvector_rows;
+}
+/*}}}*/
+/*FUNCTION FetchData(float** pvector,int* pM,const mxArray* dataref){{{*/
+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=xNew<float>(outvector_rows);
+		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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pvector=outvector;
+	if (pM)*pM=outvector_rows;
+}
+/*}}}*/
+/*FUNCTION FetchData(char** pstring,const mxArray* dataref){{{*/
+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 =xNew<char>(stringlen);
+		mxGetString(dataref,outstring,stringlen);
+	}
+
+	/*Assign output pointers:*/
+	*pstring=outstring;
+}/*}}}*/
+/*FUNCTION FetchData(char** pmatrix,int* pnumel,int* pndims,int** psize,const mxArray* dataref){{{*/
+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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+	if (pnumel)*pnumel=outmatrix_numel;
+	if (pndims)*pndims=outmatrix_ndims;
+	if (psize )*psize =outmatrix_size;
+	else xDelete<int>(outmatrix_size);
+
+}
+/*}}}*/
+/*FUNCTION FetchData(double* pscalar,const mxArray* dataref){{{*/
+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){{{*/
+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){{{*/
+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<double>** pmatrix,const mxArray* dataref){{{*/
+void FetchData(Matrix<double>** pmatrix,const mxArray* dataref){
+
+	Matrix<double>* 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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pmatrix=outmatrix;
+}
+/*}}}*/
+/*FUNCTION FetchData(Vector<double>** pvector,const mxArray* dataref){{{*/
+void FetchData(Vector<double>** pvector,const mxArray* dataref){
+
+	Vector<double>* vector=NULL;
+	int dummy;
+
+	if(mxIsEmpty(dataref)){
+		/*Nothing to pick up. Just initialize matrix pointer to NULL: */
+		vector=new Vector<double>(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 " << mxGetClassName(dataref) << " not supported yet");
+	}
+
+	/*Assign output pointers:*/
+	*pvector=vector;
+}
+/*}}}*/
+/*FUNCTION FetchData(BamgGeom** pbamggeom,const mxArray* dataref){{{*/
+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){{{*/
+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){{{*/
+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** pdataref){{{*/
+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 " << i+1 << " must be name of option");
+
+		FetchData(&name,pdataref[i]);
+		if(i+1 == nrhs) _error_("Argument " << i+2 << " must exist and be value of option \"" << name << "\".");
+
+		option=(Option*)OptionParse(name,&pdataref[i+1]);
+		options->AddOption(option);
+		option=NULL;
+	}
+
+	/*Assign output pointers:*/
+	*poptions=options;
+}
+/*}}}*/
+/*FUNCTION FetchData(DataSet** pcontours,const mxArray* dataref){{{*/
+void FetchData(DataSet** pcontours,const mxArray* dataref){
+
+	int              numcontours,index,test1,test2;
+	char            *contourname = NULL;
+	DataSet         *contours    = NULL;
+	Contour<double> *contouri    = NULL;
+
+	if (mxIsClass(dataref,"char")){
+		FetchData(&contourname,dataref);
+		contours=DomainOutlineRead<double>(contourname);
+	}
+	else if(mxIsClass(dataref,"struct")){
+
+		contours=new DataSet(0);
+		numcontours=mxGetNumberOfElements(dataref);
+
+		for(int i=0;i<numcontours;i++){
+
+			contouri=xNew<Contour<double> >(1);
+
+			index = mxGetFieldNumber(dataref,"nods");
+			if(index==-1) _error_("input structure does not have a 'nods' field");
+			FetchData(&contouri->nods,mxGetFieldByNumber(dataref,i,index));
+
+			index = mxGetFieldNumber(dataref,"x");
+			if(index==-1) _error_("input structure does not have a 'x' field");
+			FetchData(&contouri->x,&test1,&test2,mxGetFieldByNumber(dataref,i,index));
+			if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<<contouri->nods<<" 1]");
+
+			index = mxGetFieldNumber(dataref,"y");
+			if(index==-1) _error_("input structure does not have a 'y' field");
+			FetchData(&contouri->y,&test1,&test2,mxGetFieldByNumber(dataref,i,index));
+			if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<<contouri->nods<<" 1]");
+
+			contours->AddObject(contouri);
+		}
+	}
+	else{
+		_error_("Contour is neither a string nor a structure and cannot be loaded ("<<mxGetClassName(dataref)<<" not supported)");
+	}
+
+	/*clean-up and assign output pointer*/
+	xDelete<char>(contourname);
+	*pcontours=contours;
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToDoubleMatrix.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToDoubleMatrix.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToDoubleMatrix.cpp	(revision 13749)
@@ -0,0 +1,130 @@
+/* \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 "./matlabio.h"
+#include "../../c/shared/shared.h"
+
+int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){
+
+	int        i,j,count,rows,cols;
+
+	/*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: */
+		double* pmxmatrix=(double*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+
+		if(rows*cols){
+			matrix=xNewZeroInit<double>(rows*cols);
+
+			/*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]=pmxmatrix[count];
+					count++;
+				}
+			}
+		}
+
+	}
+	else if(mxIsClass(mxmatrix,"double")){
+		/*Dealing with dense matrix: recover pointer and size: */
+		double* pmxmatrix=(double*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+
+		/*Create serial matrix: */
+		if(rows*cols){
+			matrix=xNewZeroInit<double>(rows*cols);
+
+			for(i=0;i<rows;i++){
+				for(j=0;j<cols;j++){
+					matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
+				}
+			}
+		}
+	}
+	else if(mxIsClass(mxmatrix,"single")){
+		/*Dealing with dense matrix: recover pointer and size: */
+		float *pmxmatrix=(float*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+
+		/*Create serial matrix: */
+		if(rows*cols){
+			matrix=xNewZeroInit<double>(rows*cols);
+
+			for(i=0;i<rows;i++){
+				for(j=0;j<cols;j++){
+					matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
+				}
+			}
+		}
+	}
+	else if(mxIsClass(mxmatrix,"int16")){
+		/*Dealing with dense matrix: recover pointer and size: */
+		short int *pmxmatrix=(short*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+
+		/*Create serial matrix: */
+		if(rows*cols){
+			matrix=xNewZeroInit<double>(rows*cols);
+
+			for(i=0;i<rows;i++){
+				for(j=0;j<cols;j++){
+					matrix[cols*i+j]=(double)pmxmatrix[rows*j+i];
+				}
+			}
+		}
+	}
+	else if(mxIsClass(mxmatrix,"uint8")){
+		/*Dealing with dense matrix: recover pointer and size: */
+		char *pmxmatrix=(char*)mxGetPr(mxmatrix);
+		rows=mxGetM(mxmatrix);
+		cols=mxGetN(mxmatrix);
+
+		/*Create serial matrix: */
+		if(rows*cols){
+			matrix=xNewZeroInit<double>(rows*cols);
+
+			for(i=0;i<rows;i++){
+				for(j=0;j<cols;j++){
+					matrix[cols*i+j]=(double)pmxmatrix[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-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToMatrix.cpp	(revision 13749)
@@ -0,0 +1,31 @@
+/*!\file MatlabMatrixToMatrix.cpp
+ */
+
+#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 "./matlabio.h"
+#include "../../c/shared/shared.h"
+#include "../../c/toolkits/toolkits.h"
+
+Matrix<double>* MatlabMatrixToMatrix(const mxArray* mxmatrix){
+
+	int dummy;
+	Matrix<double>* matrix=NULL;
+
+	/*allocate matrix object: */
+	matrix=new Matrix<double>();
+
+	#ifdef _HAVE_PETSC_
+	matrix->pmatrix=MatlabMatrixToPetscMat(mxmatrix);
+	#else
+	matrix->smatrix=MatlabMatrixToSeqMat(mxmatrix);
+	#endif
+
+	return matrix;
+}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToPetscMat.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToPetscMat.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToPetscMat.cpp	(revision 13749)
@@ -0,0 +1,122 @@
+/* \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
+#include "../../c/shared/shared.h"
+
+/*Petsc includes: */
+#include <petscmat.h>
+#include <petscvec.h>
+#include <petscksp.h>
+
+/*Matlab includes: */
+#include "./matlabio.h"
+
+PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix){
+
+	int dummy;
+	PetscMat* matrix=new PetscMat();
+
+	MatlabMatrixToPetscMat(&matrix->matrix, &dummy, &dummy, mxmatrix);
+
+	return matrix;
+}
+int MatlabMatrixToPetscMat(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=xNew<double>(rows*cols);
+		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=xNew<int>(rows);
+		idxn=xNew<int>(cols);
+
+		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);
+
+		xDelete<double>(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-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabMatrixToSeqMat.cpp	(revision 13749)
@@ -0,0 +1,25 @@
+/*!\file MatlabMatrixToSeqMat.cpp
+ */
+
+/*Headers:*/
+#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 "./matlabio.h"
+#include "../../c/toolkits/toolkits.h"
+#include "../../c/shared/shared.h"
+
+SeqMat<double>* MatlabMatrixToSeqMat(const mxArray* dataref){
+
+	SeqMat<double>* output=NULL;
+
+	output=new SeqMat<double>();
+	MatlabMatrixToDoubleMatrix(&output->matrix,&output->M,&output->N,dataref);
+	return output;
+
+}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabNArrayToNArray.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabNArrayToNArray.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabNArrayToNArray.cpp	(revision 13749)
@@ -0,0 +1,250 @@
+/* \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 "./matlabio.h"
+#include "../../c/shared/shared.h"
+#include "../../c/include/include.h"
+
+/*FUNCTION MatlabNArrayToNArray(double** pmatrix,int* pmatrix_numel,int* pmatrix_ndims,int** pmatrix_size,const mxArray* mxmatrix){{{*/
+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;
+
+	/*get Matlab matrix information: */
+	numel=mxGetNumberOfElements(mxmatrix);
+	ndims=mxGetNumberOfDimensions(mxmatrix);
+	ipt  =mxGetDimensions(mxmatrix);
+	size =xNew<int>(ndims);
+	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);
+
+		matrix=xNewZeroInit<double>(rows*cols);
+
+		/*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=xNewZeroInit<double>(numel);
+
+		dims=xNew<int>(ndims);
+		for(i=0;i<numel;i++){
+			ColumnWiseDimsFromIndex(dims,i,size,ndims);
+			j = IndexFromRowWiseDims(dims,size,ndims);
+			matrix[j]=(double)mxmatrix_ptr[i];
+		}
+		xDelete<int>(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){{{*/
+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;
+
+	/*get Matlab matrix information: */
+	numel = mxGetNumberOfElements(mxmatrix);
+	ndims = mxGetNumberOfDimensions(mxmatrix);
+	ipt   = mxGetDimensions(mxmatrix);
+	size  = xNew<int>(ndims);
+	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);
+		matrix=xNewZeroInit<bool>(rows*cols);
+
+		/*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=xNew<bool>(numel);
+		dims=xNew<int>(ndims);
+		for(i=0;i<numel;i++){
+			ColumnWiseDimsFromIndex(dims,i,size,ndims);
+			j=IndexFromRowWiseDims(dims,size,ndims);
+			matrix[j]=(bool)mxmatrix_ptr[i];
+		}
+		xDelete<int>(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){{{*/
+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;
+
+	/*get Matlab matrix information: */
+	numel = mxGetNumberOfElements(mxmatrix);
+	ndims = mxGetNumberOfDimensions(mxmatrix);
+	ipt   = mxGetDimensions(mxmatrix);
+	size  = xNew<int>(ndims);
+	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);
+		matrix=xNew<char>(rows*cols);
+
+		/*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=xNew<char>(numel+1);
+		matrix[numel]='\0';
+
+		/*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-jpl/src/wrappers/matlab/io/MatlabVectorToDoubleVector.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToDoubleVector.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToDoubleVector.cpp	(revision 13749)
@@ -0,0 +1,93 @@
+/* \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 "./matlabio.h"
+#include "../../c/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 " << rows << "x" << cols << " should have only one column");
+
+		nz=(int)((double)nnz/(double)rows);
+
+		if(rows){
+			vector=xNewZeroInit<double>(rows);
+
+			/*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 " << rows << "x" << cols << " should have only one column");
+
+		/*allocate and memcpy*/
+		if(rows){
+			vector=xNew<double>(rows);
+			memcpy(vector,mxvector_ptr,rows*sizeof(double));
+		}
+		else{
+			vector=NULL;
+		}
+	}
+
+	/*Assign output pointer: */
+	*pvector=vector;
+	*pvector_rows=rows;
+
+	return 1;
+}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToPetscVec.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToPetscVec.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToPetscVec.cpp	(revision 13749)
@@ -0,0 +1,106 @@
+/* \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 "./matlabio.h"
+#include "../../c/shared/shared.h"
+
+PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector){
+
+	int dummy;
+	PetscVec* vector=new PetscVec();
+
+	MatlabVectorToPetscVec(&vector->vector,&dummy, mxvector);
+
+	return vector;
+}
+
+int MatlabVectorToPetscVec(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=xNew<int>(rows);
+
+		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-jpl/src/wrappers/matlab/io/MatlabVectorToSeqVec.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToSeqVec.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToSeqVec.cpp	(revision 13749)
@@ -0,0 +1,20 @@
+/*!\file MatlabVectorToSeqVec.cpp
+ */
+
+/*Headers:*/
+#include <mex.h>
+#include <stdio.h>
+#include <string.h>
+#include "./matlabio.h"
+#include "../../c/toolkits/toolkits.h"
+#include "../../c/shared/shared.h"
+
+SeqVec<double>* MatlabVectorToSeqVec(const mxArray* dataref){
+
+	SeqVec<double>* output=NULL;
+
+	output=new SeqVec<double>();
+	MatlabVectorToDoubleVector(&output->vector,&output->M,dataref);
+	return output;
+
+}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/MatlabVectorToVector.cpp	(revision 13749)
@@ -0,0 +1,31 @@
+/*!\file MatlabVectorToVector.cpp
+ */
+
+/*Headers:*/
+#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 "./matlabio.h"
+#include "../../c/shared/shared.h"
+#include "../../c/toolkits/toolkits.h"
+
+Vector<double>* MatlabVectorToVector(const mxArray* mxvector){
+
+	int dummy;
+	Vector<double>* vector=NULL;
+
+	/*allocate vector object: */
+	vector=new Vector<double>();
+
+	#ifdef _HAVE_PETSC_
+	vector->pvector=MatlabVectorToPetscVec(mxvector);
+	#else
+	vector->svector=MatlabVectorToSeqVec(mxvector);
+	#endif
+
+	return vector;
+}
Index: /issm/trunk-jpl/src/wrappers/matlab/io/OptionParse.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/OptionParse.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/OptionParse.cpp	(revision 13749)
@@ -0,0 +1,201 @@
+/*\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 <cstring> 
+#include "./matlabio.h"
+#include "../../c/shared/shared.h"
+#include "../../c/io/io.h"
+
+GenericOption<double>* OptionDoubleParse( char* name, const mxArray* prhs[]){ /*{{{*/
+
+	GenericOption<double> *odouble = NULL;
+
+	/*check and parse the name  */
+	odouble=new GenericOption<double>();
+	odouble->name =xNew<char>(strlen(name)+1);
+	memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));
+	FetchData(&odouble->value,prhs[0]);
+	odouble->numel=1;
+	odouble->ndims=1;
+	odouble->size=NULL;
+
+	return(odouble);
+}/*}}}*/
+GenericOption<double*>* OptionDoubleArrayParse( char* name, const mxArray* prhs[]){ /*{{{*/
+
+	GenericOption<double*> *odouble = NULL;
+
+	/*check and parse the name  */
+	odouble=new GenericOption<double*>();
+	odouble->name =xNew<char>(strlen(name)+1);
+	memcpy(odouble->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"double")){
+		_error_("Value of option \"" << odouble->name  << "\" must be class \"double\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
+	}
+	FetchData(&odouble->value,&odouble->numel,&odouble->ndims,&odouble->size,prhs[0]);
+
+	return(odouble);
+}/*}}}*/
+GenericOption<bool*>* OptionLogicalParse( char* name, const mxArray* prhs[]){ /*{{{*/
+
+	GenericOption<bool*> *ological = NULL;
+
+	/*check and parse the name  */
+	ological=new GenericOption<bool*>();
+	ological->name =xNew<char>(strlen(name)+1);
+	memcpy(ological->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"logical")){
+		_error_("Value of option \"" << ological->name  << "\" must be class \"logical\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
+	}
+	FetchData(&ological->value,&ological->numel,&ological->ndims,&ological->size,prhs[0]);
+
+	return(ological);
+}/*}}}*/
+GenericOption<char*>* OptionCharParse( char* name, const mxArray* prhs[]){ /*{{{*/
+
+	GenericOption<char*>  *ochar = NULL;
+
+	/*check and parse the name  */
+	ochar=new GenericOption<char*>();
+	ochar->name =xNew<char>(strlen(name)+1);
+	memcpy(ochar->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"char")){
+		_error_("Value of option \"" << ochar->name  << "\" must be class \"char\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
+	}
+	FetchData(&ochar->value,&ochar->numel,&ochar->ndims,&ochar->size,prhs[0]);
+
+	return(ochar);
+}/*}}}*/
+GenericOption<Options**>* OptionStructParse( char* name, const mxArray* prhs[]){ /*{{{*/
+
+	int            i;
+	char           namei[161];
+	Option*                   option      = NULL;
+	GenericOption<Options**>  *ostruct    = NULL;
+	const mwSize  *ipt        = NULL;
+	const mxArray *structi;
+	mwIndex        sindex;
+
+	/*check and parse the name  */
+	ostruct=new GenericOption<Options**>();
+	ostruct->name =xNew<char>(strlen(name)+1);
+	memcpy(ostruct->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"struct")){
+		_error_("Value of option \"" << ostruct->name  << "\" must be class \"struct\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
+	}
+	ostruct->numel=mxGetNumberOfElements(prhs[0]);
+	ostruct->ndims=mxGetNumberOfDimensions(prhs[0]);
+	ipt           =mxGetDimensions(prhs[0]);
+	ostruct->size =xNew<int>(ostruct->ndims);
+	for (i=0; i<ostruct->ndims; i++) ostruct->size[i]=(int)ipt[i];
+	if (ostruct->numel) ostruct->value=xNew<Options*>(ostruct->numel);
+
+	/*loop through and process each element of the struct array  */
+	for (sindex=0; sindex<ostruct->numel; sindex++) {
+		ostruct->value[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->value[sindex]->AddObject((Object*)option);
+			option=NULL;
+		}
+	}
+
+	return(ostruct);
+}/*}}}*/
+GenericOption<Options*>* OptionCellParse( char* name, const mxArray* prhs[]){ /*{{{*/
+
+	int            i;
+	int           *dims;
+	char           namei[161];
+	char           cstr[81];
+	GenericOption<Options*> *ocell      = NULL;
+	Option        *option     = NULL;
+	const mwSize  *ipt        = NULL;
+	const mxArray *celli;
+	mwIndex        cindex;
+
+	/*check and parse the name  */
+	ocell=new GenericOption<Options*>();
+	ocell->name =xNew<char>(strlen(name)+1);
+	memcpy(ocell->name,name,(strlen(name)+1)*sizeof(char));
+
+	/*check and parse the value  */
+	if (!mxIsClass(prhs[0],"cell")){
+		_error_("Value of option \"" << ocell->name  << "\" must be class \"cell\", not class \"" << mxGetClassName(prhs[0]) <<"\".");
+	}
+
+	ocell->numel=mxGetNumberOfElements(prhs[0]);
+	ocell->ndims=mxGetNumberOfDimensions(prhs[0]);
+	ipt         =mxGetDimensions(prhs[0]);
+	ocell->size =xNew<int>(ocell->ndims);
+	for (i=0; i<ocell->ndims; i++) ocell->size[i]=(int)ipt[i];
+	ocell->value=new Options;
+
+	/*loop through and process each element of the cell array  */
+	dims=xNew<int>(ocell->ndims);
+	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->value->AddObject((Object*)option);
+		option=NULL;
+	}
+	xDelete<int>(dims);
+
+	return(ocell);
+}/*}}}*/
+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")  && (mxGetNumberOfElements(prhs[0])==1))
+	 option=(Option*)OptionDoubleParse(name,prhs);
+	else if(mxIsClass(prhs[0],"double")  && (mxGetNumberOfElements(prhs[0])!=1))
+	 option=(Option*)OptionDoubleArrayParse(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 {
+		_pprintLine_("  Converting value of option \"" << name << "\" from unrecognized class \"" << mxGetClassName(prhs[0]) << "\" to class \"" << "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 \""<< name <<"\" is of unrecognized class \""<< mxGetClassName(prhs[0]) <<"\".");
+	}
+
+	return(option);
+}/*}}}*/
Index: /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp	(revision 13749)
@@ -0,0 +1,388 @@
+/* \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 "./matlabio.h"
+#include "../../c/shared/shared.h"
+
+/*Primitive data types*/
+/*FUNCTION WriteData(mxArray** pdataref,double* matrix, int M,int N){{{*/
+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){{{*/
+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){{{*/
+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){{{*/
+void WriteData(mxArray** pdataref,double scalar){
+
+	*pdataref=mxCreateDoubleScalar(scalar);
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,int integer){{{*/
+void WriteData(mxArray** pdataref,int integer){
+
+		*pdataref=mxCreateDoubleScalar((double)integer);
+
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,int boolean){{{*/
+void WriteData(mxArray** pdataref,bool boolean){
+
+	*pdataref=mxCreateDoubleScalar((double)boolean);
+
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,char* string){{{*/
+void WriteData(mxArray** pdataref,char* string){
+
+		*pdataref=mxCreateString(string);
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref){{{*/
+void WriteData(mxArray** pdataref){
+
+		;
+
+}
+/*}}}*/
+
+/*ISSM objects*/
+/*FUNCTION WriteData(mxArray** pdataref,BamgGeom* bamggeom){{{*/
+void WriteData(mxArray** pdataref,BamgGeom* bamggeom){
+
+	/*Intermediary*/
+	int         i;
+	mxArray    *dataref           = NULL;
+	const int   numfields         = 8;
+	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++] = "Corners";
+	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,"Corners",         bamggeom->CornersSize[0],         bamggeom->CornersSize[1],         bamggeom->Corners);
+	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){{{*/
+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++] = "Vertices";
+	fnames[i++] = "Edges";
+	fnames[i++] = "Triangles";
+	fnames[i++] = "Quadrilaterals";
+	fnames[i++] = "IssmEdges";
+	fnames[i++] = "IssmSegments";
+	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,"Vertices",bamgmesh->VerticesSize[0], bamgmesh->VerticesSize[1],bamgmesh->Vertices);
+	i++; SetStructureField(dataref,"Edges", bamgmesh->EdgesSize[0],bamgmesh->EdgesSize[1], bamgmesh->Edges);
+	i++; SetStructureField(dataref,"Triangles", bamgmesh->TrianglesSize[0],bamgmesh->TrianglesSize[1], bamgmesh->Triangles);
+	i++; SetStructureField(dataref,"Quadrilaterals",bamgmesh->QuadrilateralsSize[0], bamgmesh->QuadrilateralsSize[1],bamgmesh->Quadrilaterals);
+	i++; SetStructureField(dataref,"IssmEdges", bamgmesh->IssmEdgesSize[0],bamgmesh->IssmEdgesSize[1], bamgmesh->IssmEdges);
+	i++; SetStructureField(dataref,"IssmSegments",bamgmesh->IssmSegmentsSize[0], bamgmesh->IssmSegmentsSize[1],bamgmesh->IssmSegments);
+	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,SeqMat<double>* matrix){{{*/
+void WriteData(mxArray** pdataref,SeqMat<double>* matrix){
+
+	int      i,j;
+	int      rows,cols;
+	mxArray *dataref     = NULL;
+	double  *matrix_ptr  = NULL;
+	double  *tmatrix_ptr = NULL;
+
+	if(matrix){
+
+		matrix_ptr=matrix->ToSerial();
+		matrix->GetSize(&rows,&cols);
+
+		/*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:*/
+		xDelete<double>(matrix_ptr);
+	}
+	else{
+		dataref = mxCreateDoubleMatrix(0,0,mxREAL);
+	}
+
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,SeqVec<double>* vector){{{*/
+void WriteData(mxArray** pdataref,SeqVec<double>* vector){
+
+	mxArray* dataref=NULL;
+	double*  vector_ptr=NULL;
+	double*  vector_matlab=NULL;
+	int      rows;
+
+	if(vector){
+		/*call toolkit routine: */
+		vector_ptr=vector->ToMPISerial();
+		vector->GetSize(&rows);
+
+		/*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*/
+	xDelete<double>(vector_ptr);
+	*pdataref=dataref;
+}
+/*}}}*/
+/*FUNCTION WriteData(mxArray** pdataref,RiftStruct* riftstruct){{{*/
+void WriteData(mxArray** pdataref,RiftStruct* riftstruct){
+
+	/*Intermediary*/
+	int         i;
+	mxArray    *dataref           = NULL;
+	const int   numfields         = 10;
+	const char *fnames[numfields];
+	mwSize      ndim              = 2;
+	mwSize      dimensions[2]     = {1,1};
+
+	/*Initialize field names*/
+	i=0;
+	fnames[i++] = "numsegs";
+	fnames[i++] = "segments";
+	fnames[i++] = "pairs";
+	fnames[i++] = "tips";
+	fnames[i++] = "penaltypairs";
+	fnames[i++] = "fill";
+	fnames[i++] = "friction";
+	fnames[i++] = "fraction";
+	fnames[i++] = "fractionincrement";
+	fnames[i++] = "state";
+	_assert_(i==numfields);
+
+	/*Initialize matlab structure of dimension numrifts*/
+	dimensions[0]=riftstruct->numrifts;
+	dataref=mxCreateStructArray(ndim,dimensions,numfields,fnames);
+
+	/*set each matlab each field*/
+	for(int i=0;i<riftstruct->numrifts;i++){
+		SetStructureFieldi(dataref,i,"numsegs"          ,riftstruct->riftsnumsegments[i]);
+		SetStructureFieldi(dataref,i,"segments"         ,riftstruct->riftsnumsegments[i]    ,3,riftstruct->riftssegments[i]);
+		SetStructureFieldi(dataref,i,"pairs"            ,riftstruct->riftsnumpairs[i]       ,2,riftstruct->riftspairs[i]);
+		SetStructureFieldi(dataref,i,"tips"             ,1                                  ,2,&riftstruct->riftstips[2*i]);
+		SetStructureFieldi(dataref,i,"penaltypairs"     ,riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i]);
+		SetStructureFieldi(dataref,i,"fill"             ,IceEnum);
+		SetStructureFieldi(dataref,i,"friction"         ,0);
+		SetStructureFieldi(dataref,i,"fraction"         ,0.);
+		SetStructureFieldi(dataref,i,"fractionincrement",0.1);
+		SetStructureFieldi(dataref,i,"state"            ,riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i]);
+	}
+
+	/*Assign output*/
+	*pdataref=dataref;
+}
+/*}}}*/
+
+/*Toolkit*/
+/*FUNCTION SetStructureField{{{*/
+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);
+}
+/*}}}*/
+/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){{{*/
+void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int M,int N,double* fieldpointer){
+
+	mxArray* field = NULL;
+
+	/*Convert field*/
+	WriteData(&field,fieldpointer,M,N);
+
+	/*Assign to structure*/
+	mxSetField(dataref,i,fieldname,field);
+}
+/*}}}*/
+/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field){{{*/
+void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldin){
+
+	mxArray* field = NULL;
+
+	/*Convert field*/
+	WriteData(&field,fieldin);
+
+	/*Assign to structure*/
+	mxSetField(dataref,i,fieldname,field);
+}
+/*}}}*/
+/*FUNCTION SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field){{{*/
+void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double fieldin){
+
+	mxArray* field = NULL;
+
+	/*Convert field*/
+	WriteData(&field,fieldin);
+
+	/*Assign to structure*/
+	mxSetField(dataref,i,fieldname,field);
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h	(revision 13749)
@@ -0,0 +1,93 @@
+/*\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 "../include/matlabincludes.h"
+#include "../../c/classes/classes.h"
+#include "../../c/Container/Container.h"
+#include "../../c/include/include.h"
+
+void WriteData(mxArray** pdataref,SeqMat<double>* 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,SeqVec<double>* 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);
+void WriteData(mxArray** pdataref,BamgGeom* bamggeom);
+void WriteData(mxArray** pdataref,BamgMesh* bamgmesh);
+void WriteData(mxArray** pdataref,RiftStruct* riftstruct);
+
+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<double>** 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<double>** 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);
+void FetchData(DataSet** pcontours,const mxArray* dataref);
+
+Option* OptionParse(char* name, const mxArray* prhs[]);
+GenericOption<double>*    OptionDoubleParse( char* name, const mxArray* prhs[]);
+GenericOption<double*>*   OptionDoubleArrayParse( char* name, const mxArray* prhs[]);
+GenericOption<bool*>*     OptionLogicalParse( char* name, const mxArray* prhs[]);
+GenericOption<char*>*     OptionCharParse( char* name, const mxArray* prhs[]);
+GenericOption<Options**>* OptionStructParse( char* name, const mxArray* prhs[]);
+GenericOption<Options*>*  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);
+void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer);
+void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,int field);
+void SetStructureFieldi(mxArray* dataref,int i,const char* fieldname,double field);
+int CheckNumMatlabArguments(int nlhs,int NLHS, int nrhs,int NRHS, const char* THISFUNCTION, void (*function)( void ));
+
+/*Matlab to Matrix routines: */
+Matrix<double>* MatlabMatrixToMatrix(const mxArray* mxmatrix);
+Vector<double>* 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<double>* MatlabMatrixToSeqMat(const mxArray* dataref);
+SeqVec<double>* MatlabVectorToSeqVec(const mxArray* dataref);
+
+/*Matlab to Petsc routines: */
+#ifdef _HAVE_PETSC_
+int MatlabMatrixToPetscMat(Mat* matrix,int* prows,int* pcols, const mxArray* mxmatrix);
+PetscMat* MatlabMatrixToPetscMat(const mxArray* mxmatrix);
+int MatlabVectorToPetscVec(Vec* pvector,int* pvector_rows,const mxArray* mxvector);
+PetscVec* MatlabVectorToPetscVec(const mxArray* mxvector);
+#endif
+
+#endif	/* _IO_H_ */
Index: /issm/trunk-jpl/src/wrappers/matlab/io/mxGetAssignedField.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/matlab/io/mxGetAssignedField.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/matlab/io/mxGetAssignedField.cpp	(revision 13749)
@@ -0,0 +1,39 @@
+/*!\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.
+ */
+
+#include "./matlabio.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-jpl/src/wrappers/python/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/Makefile.am	(revision 13748)
+++ /issm/trunk-jpl/src/wrappers/python/Makefile.am	(revision 13749)
@@ -1,6 +1,27 @@
-AM_CPPFLAGS = @DAKOTAINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@
+AM_CPPFLAGS = @DAKOTAINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@
 
 EXEEXT=$(PYTHONWRAPPEREXT)
 
+#python io{{{
+lib_LIBRARIES = libISSMPython.a 
+if SHAREDLIBS
+lib_LTLIBRARIES = libISSMPython.la
+else
+	lib_LTLIBRARIES =
+endif
+
+io_sources= ./include/pythonincludes.h\
+				./io/pythonio.h\
+				./io/WritePythonData.cpp\
+				./io/CheckNumPythonArguments.cpp\
+				./io/FetchPythonData.cpp
+
+ALLCXXFLAGS= -fPIC -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_  $(CXXFLAGS) $(CXXOPTFLAGS) 
+libISSMPython_a_SOURCES = $(io_sources)
+libISSMPython_a_CXXFLAGS= $(ALLCXXFLAGS)
+if SHAREDLIBS
+libISSMPython_la_SOURCES = $(io_sources)
+endif
+#}}}
 #Wrappers {{{
 if WRAPPERS
@@ -38,7 +59,7 @@
 endif
 if SHAREDLIBS
-deps += ../../c/libISSMPython.la 
+deps += ./libISSMPython.la 
 else
-deps += ../../c/libISSMPython.a
+deps += ./libISSMPython.a
 AM_LDFLAGS += --no-warnings 
 endif
Index: /issm/trunk-jpl/src/wrappers/python/include/wrapper_macros.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/include/wrapper_macros.h	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/python/include/wrapper_macros.h	(revision 13749)
@@ -0,0 +1,92 @@
+/* \file python_macros.h
+ * \brief: macros used for the python bindings
+ */
+
+#ifndef _PY_WRAPPER_MACROS_H_
+#define _PY_WRAPPER_MACROS_H_
+
+#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 {{{*/
+
+/*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*/
+#define MODULEBOOT(); \
+	PyObject *output = PyTuple_New(NLHS); \
+	int       nrhs   = (int)PyTuple_Size(args);  \
+	if(!output) return NULL;\
+	try{ \
+	IssmComm::SetComm(-1);
+
+#define MODULEEND(); }\
+  catch(ErrorException &exception){\
+	  PyErr_SetString(PyExc_TypeError,exception.PythonReport()); \
+	  return NULL;\
+  } \
+	catch (exception &e){\
+		PyErr_SetString(PyExc_TypeError,exprintf("Standard exception: %s\n",e.what()));\
+		return NULL;\
+	}\
+	catch(...){\
+		PyErr_SetString(PyExc_TypeError,"An unexpected error occurred");\
+		return NULL;\
+	}\
+	return output;
+//}}}
+#if _PYTHON_MAJOR_ >=3
+/* WRAPPER 3.2 {{{*/
+#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 {{{*/
+#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 {{{*/
+#define CHECKARGUMENTS(NLHS,NRHS,functionpointer) CheckNumPythonArguments(args, NRHS,functionpointer)
+/*}}}*/
+#endif
+#endif
Index: /issm/trunk-jpl/src/wrappers/python/io/CheckNumPythonArguments.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/io/CheckNumPythonArguments.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/python/io/CheckNumPythonArguments.cpp	(revision 13749)
@@ -0,0 +1,29 @@
+/*!\file CheckNumPythonArguments.cpp:
+ * \brief: check number of arguments and report an usage error message.
+ */
+
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#define NO_IMPORT
+
+#include "./pythonio.h"
+#include "../../c/shared/Exceptions/exceptions.h"
+#include "../../c/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-jpl/src/wrappers/python/io/FetchPythonData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp	(revision 13749)
@@ -0,0 +1,354 @@
+/*\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 "./pythonio.h"
+#include "../../c/include/include.h"
+#include "../../c/shared/shared.h"
+
+/*Primitive data types*/
+/*FUNCTION FetchData(double* pscalar,PyObject* py_float){{{*/
+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){{{*/
+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){{{*/
+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){{{*/
+void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_matrix){
+
+	/*output: */
+	double* dmatrix=NULL;
+	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];
+
+	if (M && N) {
+		/*retrieve internal value: */
+		dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);
+
+		/*copy matrix: */
+		matrix=xNew<double>(M*N);
+		memcpy(matrix,dmatrix,(M*N)*sizeof(double));
+	}
+	else
+		matrix=NULL;
+
+	/*output: */
+	if(pM)*pM=M;
+	if(pN)*pN=N;
+	if(pmatrix)*pmatrix=matrix;
+}
+/*}}}*/
+/*FUNCTION FetchData(int** pmatrix,int* pM, int* pN, PyObject* py_matrix){{{*/
+void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix){
+
+	/*output: */
+	double* dmatrix=NULL;
+	int* matrix=NULL;
+	int M,N;
+
+	/*intermediary:*/
+	int i;
+	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];
+
+	if (M && N) {
+		/*retrieve internal value: */
+		dmatrix=(double*)PyArray_DATA((PyArrayObject*)py_matrix);
+
+		/*transform into integer matrix: */
+		matrix=xNew<int>(M*N);
+		for(i=0;i<M*N;i++)matrix[i]=(int)dmatrix[i];
+	}
+	else
+		matrix=NULL;
+
+	/*output: */
+	if(pM)*pM=M;
+	if(pN)*pN=N;
+	if(pmatrix)*pmatrix=matrix;
+}
+/*}}}*/
+/*FUNCTION FetchData(double** pvector,int* pM, PyObject* py_vector){{{*/
+void FetchData(double** pvector,int* pM,PyObject* py_vector){
+
+	/*output: */
+	double* dvector=NULL;
+	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]; 
+
+	if (M) {
+		/*retrieve internal value: */
+		dvector=(double*)PyArray_DATA((PyArrayObject*)py_vector);
+
+		/*copy vector: */
+		vector=xNew<double>(M);
+		memcpy(vector,dvector,(M)*sizeof(double));
+	}
+	else
+		vector=NULL;
+
+	/*output: */
+	if(pM)*pM=M;
+	if(pvector)*pvector=vector;
+}
+/*}}}*/
+
+/*ISSM objects*/
+/*FUNCTION FetchData(BamgGeom** pbamggeom,PyObject* py_dict){{{*/
+void FetchData(BamgGeom** pbamggeom,PyObject* py_dict){
+
+	/*Initialize output*/
+	BamgGeom* bamggeom=new BamgGeom();
+
+	/*Fetch all fields*/
+	FetchData(&bamggeom->Vertices,&bamggeom->VerticesSize[0],&bamggeom->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices"));
+	FetchData(&bamggeom->Edges, &bamggeom->EdgesSize[0], &bamggeom->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges"));
+	FetchData(&bamggeom->Corners, &bamggeom->CornersSize[0], &bamggeom->CornersSize[1], PyDict_GetItemString(py_dict,"Corners"));
+	FetchData(&bamggeom->RequiredVertices,&bamggeom->RequiredVerticesSize[0],&bamggeom->RequiredVerticesSize[1],PyDict_GetItemString(py_dict,"RequiredVertices"));
+	FetchData(&bamggeom->RequiredEdges, &bamggeom->RequiredEdgesSize[0], &bamggeom->RequiredEdgesSize[1], PyDict_GetItemString(py_dict,"RequiredEdges"));
+	FetchData(&bamggeom->CrackedEdges,&bamggeom->CrackedEdgesSize[0],&bamggeom->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges"));
+	FetchData(&bamggeom->SubDomains,&bamggeom->SubDomainsSize[0],&bamggeom->SubDomainsSize[1],PyDict_GetItemString(py_dict,"SubDomains"));
+
+	/*Assign output pointers:*/
+	*pbamggeom=bamggeom;
+}
+/*}}}*/
+/*FUNCTION FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){{{*/
+void FetchData(BamgMesh** pbamgmesh,PyObject* py_dict){
+
+	/*Initialize output*/
+	BamgMesh* bamgmesh=new BamgMesh();
+
+	/*Fetch all fields*/
+	FetchData(&bamgmesh->Vertices,&bamgmesh->VerticesSize[0],&bamgmesh->VerticesSize[1],PyDict_GetItemString(py_dict,"Vertices"));
+	FetchData(&bamgmesh->Edges, &bamgmesh->EdgesSize[0], &bamgmesh->EdgesSize[1], PyDict_GetItemString(py_dict,"Edges"));
+	FetchData(&bamgmesh->Triangles, &bamgmesh->TrianglesSize[0], &bamgmesh->TrianglesSize[1], PyDict_GetItemString(py_dict,"Triangles"));
+	FetchData(&bamgmesh->CrackedEdges,&bamgmesh->CrackedEdgesSize[0],&bamgmesh->CrackedEdgesSize[1],PyDict_GetItemString(py_dict,"CrackedEdges"));
+	FetchData(&bamgmesh->VerticesOnGeomEdge,&bamgmesh->VerticesOnGeomEdgeSize[0],&bamgmesh->VerticesOnGeomEdgeSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomEdge"));
+	FetchData(&bamgmesh->VerticesOnGeomVertex,&bamgmesh->VerticesOnGeomVertexSize[0],&bamgmesh->VerticesOnGeomVertexSize[1],PyDict_GetItemString(py_dict,"VerticesOnGeomVertex"));
+	FetchData(&bamgmesh->EdgesOnGeomEdge, &bamgmesh->EdgesOnGeomEdgeSize[0], &bamgmesh->EdgesOnGeomEdgeSize[1], PyDict_GetItemString(py_dict,"EdgesOnGeomEdge"));
+	FetchData(&bamgmesh->IssmSegments,&bamgmesh->IssmSegmentsSize[0],&bamgmesh->IssmSegmentsSize[1],PyDict_GetItemString(py_dict,"IssmSegments"));
+
+	/*Assign output pointers:*/
+	*pbamgmesh=bamgmesh;
+}
+/*}}}*/
+/*FUNCTION FetchData(BamgOpts** pbamgopts,PyObject* py_dict){{{*/
+void FetchData(BamgOpts** pbamgopts,PyObject* py_dict){
+
+	/*Initialize output*/
+	BamgOpts* bamgopts=new BamgOpts();
+
+	/*Fetch all fields*/
+	FetchData(&bamgopts->anisomax,PyDict_GetItemString(py_dict,"anisomax"));
+	FetchData(&bamgopts->cutoff,PyDict_GetItemString(py_dict,"cutoff"));
+	FetchData(&bamgopts->coeff,PyDict_GetItemString(py_dict,"coeff"));
+	FetchData(&bamgopts->errg,PyDict_GetItemString(py_dict,"errg"));
+	FetchData(&bamgopts->gradation,PyDict_GetItemString(py_dict,"gradation"));
+	FetchData(&bamgopts->Hessiantype,PyDict_GetItemString(py_dict,"Hessiantype"));
+	FetchData(&bamgopts->MaxCornerAngle,PyDict_GetItemString(py_dict,"MaxCornerAngle"));
+	FetchData(&bamgopts->maxnbv,PyDict_GetItemString(py_dict,"maxnbv"));
+	FetchData(&bamgopts->maxsubdiv,PyDict_GetItemString(py_dict,"maxsubdiv"));
+	FetchData(&bamgopts->Metrictype,PyDict_GetItemString(py_dict,"Metrictype"));
+	FetchData(&bamgopts->nbjacobi,PyDict_GetItemString(py_dict,"nbjacobi"));
+	FetchData(&bamgopts->nbsmooth,PyDict_GetItemString(py_dict,"nbsmooth"));
+	FetchData(&bamgopts->omega,PyDict_GetItemString(py_dict,"omega"));
+	FetchData(&bamgopts->power,PyDict_GetItemString(py_dict,"power"));
+	FetchData(&bamgopts->verbose,PyDict_GetItemString(py_dict,"verbose"));
+
+	FetchData(&bamgopts->Crack,PyDict_GetItemString(py_dict,"Crack"));
+	FetchData(&bamgopts->geometricalmetric,PyDict_GetItemString(py_dict,"geometricalmetric"));
+	FetchData(&bamgopts->KeepVertices,PyDict_GetItemString(py_dict,"KeepVertices"));
+	FetchData(&bamgopts->splitcorners,PyDict_GetItemString(py_dict,"splitcorners"));
+
+	FetchData(&bamgopts->hmin,PyDict_GetItemString(py_dict,"hmin"));
+	FetchData(&bamgopts->hmax,PyDict_GetItemString(py_dict,"hmax"));
+	FetchData(&bamgopts->hminVertices,&bamgopts->hminVerticesSize[0],&bamgopts->hminVerticesSize[1],PyDict_GetItemString(py_dict,"hminVertices"));
+	FetchData(&bamgopts->hmaxVertices,&bamgopts->hmaxVerticesSize[0],&bamgopts->hmaxVerticesSize[1],PyDict_GetItemString(py_dict,"hmaxVertices"));
+	FetchData(&bamgopts->hVertices,&bamgopts->hVerticesSize[0],&bamgopts->hVerticesSize[1],PyDict_GetItemString(py_dict,"hVertices"));
+	FetchData(&bamgopts->metric,&bamgopts->metricSize[0],&bamgopts->metricSize[1],PyDict_GetItemString(py_dict,"metric"));
+	FetchData(&bamgopts->field,&bamgopts->fieldSize[0],&bamgopts->fieldSize[1],PyDict_GetItemString(py_dict,"field"));
+	FetchData(&bamgopts->err,&bamgopts->errSize[0],&bamgopts->errSize[1],PyDict_GetItemString(py_dict,"err"));
+
+	/*Additional checks*/
+	bamgopts->Check();
+
+	/*Assign output pointers:*/
+	*pbamgopts=bamgopts;
+}
+/*}}}*/
+/*FUNCTION FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){{{*/
+void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple){
+
+	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 (!PyString_Check(PyTuple_GetItem(py_tuple,(Py_ssize_t)i))) _error_("Argument " << i+1 << " must be name of option");
+
+		FetchData(&name,PyTuple_GetItem(py_tuple,(Py_ssize_t)i));
+		if(i+1 == nrhs) _error_("Argument " << i+2 << " must exist and be value of option \"" << name << "\".");
+
+		_pprintLine_("FetchData for Options not implemented yet, ignoring option \"" << name << "\"!");
+
+//		option=(Option*)OptionParse(name,&PyTuple_GetItem(py_tuple,(Py_ssize_t)(i+1)));
+//		options->AddOption(option);
+//		option=NULL;
+	}
+
+	/*Assign output pointers:*/
+	*poptions=options;
+}
+/*}}}*/
+/*FUNCTION FetchData(DataSet** pcontours,PyObject* py_list){{{*/
+void FetchData(DataSet** pcontours,PyObject* py_list){
+
+	int              numcontours,test1,test2;
+	char            *contourname = NULL;
+	DataSet         *contours    = NULL;
+	Contour<double> *contouri    = NULL;
+	PyObject        *py_dicti    = NULL;
+	PyObject        *py_item     = NULL;
+
+	if (PyString_Check(py_list)){
+		FetchData(&contourname,py_list);
+		contours=DomainOutlineRead<double>(contourname);
+	}
+	else if(PyList_Check(py_list)){
+
+		contours=new DataSet(0);
+		numcontours=(int)PyList_Size(py_list);
+
+		for(int i=0;i<numcontours;i++){
+
+			contouri=xNew<Contour<double> >(1);
+			py_dicti=PyList_GetItem(py_list,(Py_ssize_t)i);
+
+			py_item = PyDict_GetItemString(py_dicti,"nods");
+			if(!py_item) _error_("input structure does not have a 'nods' field");
+			FetchData(&contouri->nods,py_item);
+
+			py_item = PyDict_GetItemString(py_dicti,"x");
+			if(!py_item) _error_("input structure does not have a 'x' field");
+			FetchData(&contouri->x,&test1,&test2,py_item);
+			if(test1!=contouri->nods || test2!=1) _error_("field x should be of size ["<<contouri->nods<<" 1]");
+
+			py_item = PyDict_GetItemString(py_dicti,"y");
+			if(!py_item) _error_("input structure does not have a 'y' field");
+			FetchData(&contouri->y,&test1,&test2,py_item);
+			if(test1!=contouri->nods || test2!=1) _error_("field y should be of size ["<<contouri->nods<<" 1]");
+
+			contours->AddObject(contouri);
+		}
+	}
+	else{
+		_error_("Contour is neither a string nor a structure and cannot be loaded");
+	}
+
+	/*clean-up and assign output pointer*/
+	xDelete<char>(contourname);
+	*pcontours=contours;
+}
+/*}}}*/
+
+/*Python version dependent: */
+#if _PYTHON_MAJOR_ >= 3 
+/*FUNCTION FetchData(char** pstring,PyObject* py_unicode){{{*/
+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){{{*/
+void FetchData(char** pstring,PyObject* py_string){
+
+	char* string=NULL;
+
+	/*extract internal string: */
+	string=PyString_AsString(py_string);
+
+	/*copy string (note strlen does not include trailing NULL): */
+	*pstring=xNew<char>(strlen(string)+1);
+	memcpy(*pstring,string,(strlen(string)+1)*sizeof(char));
+}
+/*}}}*/
+#endif
Index: /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp	(revision 13749)
@@ -0,0 +1,194 @@
+/* \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 "./pythonio.h"
+#include "../../c/include/include.h"
+#include "../../c/Container/Container.h"
+#include "../../c/shared/shared.h"
+#include "../../c/EnumDefinitions/EnumDefinitions.h"
+
+/*Primitive data types*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index,int integer){{{*/
+void WriteData(PyObject* py_tuple, int index, int integer){
+
+	PyTuple_SetItem(py_tuple, index, PyInt_FromSsize_t((Py_ssize_t)integer));
+
+}/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index,char* string){{{*/
+void WriteData(PyObject* py_tuple, int index, char* string){
+
+	PyTuple_SetItem(py_tuple, index, PyUnicode_FromString(string));
+
+}/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index, double* matrix, int M, int N){{{*/
+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);
+}/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index){{{*/
+void WriteData(PyObject* py_tuple, int index){
+
+	PyTuple_SetItem(py_tuple, index, Py_None);
+
+}/*}}}*/
+
+/*ISSM objects*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){{{*/
+void WriteData(PyObject* py_tuple,int index,BamgGeom* bamggeom){
+
+	PyObject* dict=NULL;
+
+	dict=PyDict_New();
+
+	PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamggeom->VerticesSize,bamggeom->Vertices));
+	PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamggeom->EdgesSize,bamggeom->Edges));
+	PyDict_SetItemString(dict,"TangentAtEdges",PyArrayFromCopiedData(bamggeom->TangentAtEdgesSize,bamggeom->TangentAtEdges));
+	PyDict_SetItemString(dict,"Corners",PyArrayFromCopiedData(bamggeom->CornersSize,bamggeom->Corners));
+	PyDict_SetItemString(dict,"RequiredVertices",PyArrayFromCopiedData(bamggeom->RequiredVerticesSize,bamggeom->RequiredVertices));
+	PyDict_SetItemString(dict,"RequiredEdges",PyArrayFromCopiedData(bamggeom->RequiredEdgesSize,bamggeom->RequiredEdges));
+	PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamggeom->CrackedEdgesSize,bamggeom->CrackedEdges));
+	PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamggeom->SubDomainsSize,bamggeom->SubDomains));
+
+	PyTuple_SetItem(py_tuple, index, dict);
+}
+/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){{{*/
+void WriteData(PyObject* py_tuple,int index,BamgMesh* bamgmesh){
+
+	PyObject* dict=NULL;
+
+	dict=PyDict_New();
+
+	PyDict_SetItemString(dict,"Vertices",PyArrayFromCopiedData(bamgmesh->VerticesSize,bamgmesh->Vertices));
+	PyDict_SetItemString(dict,"Edges",PyArrayFromCopiedData(bamgmesh->EdgesSize,bamgmesh->Edges));
+	PyDict_SetItemString(dict,"Triangles",PyArrayFromCopiedData(bamgmesh->TrianglesSize,bamgmesh->Triangles));
+	PyDict_SetItemString(dict,"Quadrilaterals",PyArrayFromCopiedData(bamgmesh->QuadrilateralsSize,bamgmesh->Quadrilaterals));
+	PyDict_SetItemString(dict,"IssmEdges",PyArrayFromCopiedData(bamgmesh->IssmEdgesSize,bamgmesh->IssmEdges));
+	PyDict_SetItemString(dict,"IssmSegments",PyArrayFromCopiedData(bamgmesh->IssmSegmentsSize,bamgmesh->IssmSegments));
+	PyDict_SetItemString(dict,"VerticesOnGeomVertex",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomVertexSize,bamgmesh->VerticesOnGeomVertex));
+	PyDict_SetItemString(dict,"VerticesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->VerticesOnGeomEdgeSize,bamgmesh->VerticesOnGeomEdge));
+	PyDict_SetItemString(dict,"EdgesOnGeomEdge",PyArrayFromCopiedData(bamgmesh->EdgesOnGeomEdgeSize,bamgmesh->EdgesOnGeomEdge));
+	PyDict_SetItemString(dict,"SubDomains",PyArrayFromCopiedData(bamgmesh->SubDomainsSize,bamgmesh->SubDomains));
+	PyDict_SetItemString(dict,"SubDomainsFromGeom",PyArrayFromCopiedData(bamgmesh->SubDomainsFromGeomSize,bamgmesh->SubDomainsFromGeom));
+	PyDict_SetItemString(dict,"ElementConnectivity",PyArrayFromCopiedData(bamgmesh->ElementConnectivitySize,bamgmesh->ElementConnectivity));
+	PyDict_SetItemString(dict,"NodalConnectivity",PyArrayFromCopiedData(bamgmesh->NodalConnectivitySize,bamgmesh->NodalConnectivity));
+	PyDict_SetItemString(dict,"NodalElementConnectivity",PyArrayFromCopiedData(bamgmesh->NodalElementConnectivitySize,bamgmesh->NodalElementConnectivity));
+	PyDict_SetItemString(dict,"CrackedVertices",PyArrayFromCopiedData(bamgmesh->CrackedVerticesSize,bamgmesh->CrackedVertices));
+	PyDict_SetItemString(dict,"CrackedEdges",PyArrayFromCopiedData(bamgmesh->CrackedEdgesSize,bamgmesh->CrackedEdges));
+
+	PyTuple_SetItem(py_tuple, index, dict);
+}
+/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index,SeqMat<double>* matrix){{{*/
+void WriteData(PyObject* py_tuple,int index,SeqMat<double>* 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(py_tuple, index, array);
+
+}/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index,SeqVec<double>* vector){{{*/
+void WriteData(PyObject* py_tuple,int index,SeqVec<double>* 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(py_tuple, index, array);
+}
+/*}}}*/
+/*FUNCTION WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){{{*/
+void WriteData(PyObject* py_tuple,int index,RiftStruct* riftstruct){
+
+	int i;
+	PyObject* list=NULL;
+	PyObject* dict=NULL;
+
+	list=PyList_New((Py_ssize_t)0);
+
+	for (i=0; i<riftstruct->numrifts; i++) {
+		dict=PyDict_New();
+
+		PyDict_SetItemString(dict,"numsegs"          ,PyInt_FromSsize_t((Py_ssize_t)riftstruct->riftsnumsegments[i]));
+		PyDict_SetItemString(dict,"segments"         ,PyArrayFromCopiedData(riftstruct->riftsnumsegments[i]    ,3,riftstruct->riftssegments[i]));
+		PyDict_SetItemString(dict,"pairs"            ,PyArrayFromCopiedData(riftstruct->riftsnumpairs[i]       ,2,riftstruct->riftspairs[i]));
+		PyDict_SetItemString(dict,"tips"             ,PyArrayFromCopiedData(1                                  ,2,&riftstruct->riftstips[2*i]));
+		PyDict_SetItemString(dict,"penaltypairs"     ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],7,riftstruct->riftspenaltypairs[i]));
+		PyDict_SetItemString(dict,"fill"             ,PyInt_FromSsize_t((Py_ssize_t)IceEnum));
+		PyDict_SetItemString(dict,"friction"         ,PyInt_FromSsize_t((Py_ssize_t)0));
+		PyDict_SetItemString(dict,"fraction"         ,PyFloat_FromDouble(0.));
+		PyDict_SetItemString(dict,"fractionincrement",PyFloat_FromDouble(0.1));
+		PyDict_SetItemString(dict,"state"            ,PyArrayFromCopiedData(riftstruct->riftsnumpenaltypairs[i],1,riftstruct->state[i]));
+
+		PyList_Append(list, dict);
+	}
+
+	PyTuple_SetItem(py_tuple, index, list);
+}
+/*}}}*/
+
+/*Utils*/
+/*FUNCTION PyArrayFromCopiedData(int dims[2],double* data){{{*/
+PyObject* PyArrayFromCopiedData(int dims[2],double* data){
+
+	double* pydata;
+	npy_intp pydims[2]={0,0};
+
+	/*  note that PyArray_SimpleNewFromData does not copy the data, so that when the original
+		 object (e.g. bamggeom,bamgmesh) is deleted, the data is gone.  */
+
+	pydims[0]=(npy_intp)dims[0];
+	pydims[1]=(npy_intp)dims[1];
+	pydata=xNew<IssmDouble>(dims[0]*dims[1]);
+	memcpy(pydata,data,dims[0]*dims[1]*sizeof(double));
+	return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata);
+}
+/*}}}*/
+/*FUNCTION PyArrayFromCopiedData(int dimi,int dimj,double* data){{{*/
+PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data){
+
+	double* pydata;
+	npy_intp pydims[2]={0,0};
+
+	/*  note that PyArray_SimpleNewFromData does not copy the data, so that when the original
+		 object (e.g. bamggeom,bamgmesh) is deleted, the data is gone.  */
+
+	pydims[0]=(npy_intp)dimi;
+	pydims[1]=(npy_intp)dimj;
+	pydata=xNew<IssmDouble>(dimi*dimj);
+	memcpy(pydata,data,dimi*dimj*sizeof(double));
+	return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata);
+}
+/*}}}*/
Index: /issm/trunk-jpl/src/wrappers/python/io/pythonio.h
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/io/pythonio.h	(revision 13749)
+++ /issm/trunk-jpl/src/wrappers/python/io/pythonio.h	(revision 13749)
@@ -0,0 +1,48 @@
+/*\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 "../include/pythonincludes.h"
+#include "../../c/classes/classes.h"
+#include "../../c/Container/Container.h"
+#include "../../c/include/include.h"
+
+void WriteData(PyObject* py_tuple,int index, double* matrix, int M,int N);
+void WriteData(PyObject* py_tuple,int index, int integer);
+void WriteData(PyObject* py_tuple,int index, char* string);
+void WriteData(PyObject* py_tuple,int index);
+void WriteData(PyObject* py_tuple,int index, SeqMat<double>* matrix);
+void WriteData(PyObject* py_tuple,int index, SeqVec<double>* vector);
+void WriteData(PyObject* py_tuple,int index, BamgGeom* bamggeom);
+void WriteData(PyObject* py_tuple,int index, BamgMesh* bamgmesh);
+void WriteData(PyObject* py_tuple,int index, RiftStruct* riftstruct);
+
+void FetchData(double** pvector,int* pM,PyObject* py_ref);
+void FetchData(double** pmatrix,int* pM,int *pN,PyObject* py_array);
+void FetchData(int** pmatrix,int* pM,int *pN,PyObject* py_matrix);
+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);
+void FetchData(BamgGeom** bamggeom,PyObject* py_dict);
+void FetchData(BamgMesh** bamgmesh,PyObject* py_dict);
+void FetchData(BamgOpts** bamgopts,PyObject* py_dict);
+void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple);
+void FetchData(DataSet** pcontours,PyObject* py_list);
+
+int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void ));
+
+/*Utils*/
+PyObject* PyArrayFromCopiedData(int dims[2],double* data);
+PyObject* PyArrayFromCopiedData(int dimi,int dimj,double* data);
+
+#endif	/* _IO_H_ */
