Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 5153)
+++ /issm/trunk/src/c/Makefile.am	(revision 5154)
@@ -67,6 +67,4 @@
 					./objects/Bamg/Triangle.cpp\
 					./objects/Bamg/Triangle.h\
-					./objects/Bamg/Mesh.cpp\
-					./objects/Bamg/Mesh.h\
 					./objects/Bamg/BamgVertex.cpp\
 					./objects/Bamg/BamgVertex.h\
@@ -77,4 +75,6 @@
 					./objects/Bamg/VertexOnVertex.h\
 					./objects/Bamg/VertexOnVertex.cpp\
+					./objects/Bamg/Mesh.cpp\
+					./objects/Bamg/Mesh.h\
 					./objects/Update.h\
 					./objects/Element.h\
@@ -603,6 +603,4 @@
 					./objects/Bamg/Triangle.cpp\
 					./objects/Bamg/Triangle.h\
-					./objects/Bamg/Mesh.h\
-					./objects/Bamg/Mesh.cpp\
 					./objects/Bamg/BamgVertex.cpp\
 					./objects/Bamg/BamgVertex.h\
@@ -612,4 +610,6 @@
 					./objects/Bamg/VertexOnGeom.cpp\
 					./objects/Bamg/VertexOnVertex.h\
+					./objects/Bamg/Mesh.h\
+					./objects/Bamg/Mesh.cpp\
 					./objects/Update.h\
 					./objects/Element.h\
@@ -1106,5 +1106,5 @@
 bin_PROGRAMS = 
 else 
-bin_PROGRAMS = issm.exe 
+bin_PROGRAMS = issm.exe
 endif
 
Index: /issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.cpp
===================================================================
--- /issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.cpp	(revision 5153)
+++ /issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.cpp	(revision 5154)
@@ -21,5 +21,4 @@
 	/*Options*/
 	BamgOpts bamgopts;
-	BamgOptsInit(&bamgopts);
 
 	// read mesh
Index: /issm/trunk/src/c/objects/Bamg/BamgGeom.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgGeom.cpp	(revision 5153)
+++ /issm/trunk/src/c/objects/Bamg/BamgGeom.cpp	(revision 5154)
@@ -2,16 +2,35 @@
 #include "../objects.h"
 
-void BamgGeomInit(BamgGeom* bamggeom){
+/*Constructors/Destructors*/
+/*FUNCTION BamgGeom::BamgGeom(){{{1*/
+BamgGeom::BamgGeom(){
 
-	bamggeom->VerticesSize[0]=0,  bamggeom->VerticesSize[1]=0;  bamggeom->Vertices=NULL;
-	bamggeom->EdgesSize[0]=0,     bamggeom->EdgesSize[1]=0;     bamggeom->Edges=NULL;
-	bamggeom->hVertices=NULL;
-	bamggeom->MetricVertices=NULL;
-	bamggeom->TangentAtEdgesSize[0]=0,    bamggeom->TangentAtEdgesSize[1]=0;    bamggeom->TangentAtEdges=NULL;
-	bamggeom->CornersSize[0]=0,           bamggeom->CornersSize[1]=0;           bamggeom->Corners=NULL;
-	bamggeom->RequiredVerticesSize[0]=0,  bamggeom->RequiredVerticesSize[1]=0;  bamggeom->RequiredVertices=NULL;
-	bamggeom->RequiredEdgesSize[0]=0,     bamggeom->RequiredEdgesSize[1]=0;     bamggeom->RequiredEdges=NULL;
-	bamggeom->CrackedEdgesSize[0]=0,      bamggeom->CrackedEdgesSize[1]=0;      bamggeom->CrackedEdges=NULL;
-	bamggeom->SubDomainsSize[0]=0,        bamggeom->SubDomainsSize[1]=0;        bamggeom->SubDomains=NULL;
+	this->VerticesSize[0]=0,          this->VerticesSize[1]=0;          this->Vertices=NULL;
+	this->EdgesSize[0]=0,             this->EdgesSize[1]=0;             this->Edges=NULL;
+	this->hVertices=NULL;
+	this->MetricVertices=NULL;
+	this->TangentAtEdgesSize[0]=0,    this->TangentAtEdgesSize[1]=0;    this->TangentAtEdges=NULL;
+	this->CornersSize[0]=0,           this->CornersSize[1]=0;           this->Corners=NULL;
+	this->RequiredVerticesSize[0]=0,  this->RequiredVerticesSize[1]=0;  this->RequiredVertices=NULL;
+	this->RequiredEdgesSize[0]=0,     this->RequiredEdgesSize[1]=0;     this->RequiredEdges=NULL;
+	this->CrackedEdgesSize[0]=0,      this->CrackedEdgesSize[1]=0;      this->CrackedEdges=NULL;
+	this->SubDomainsSize[0]=0,        this->SubDomainsSize[1]=0;        this->SubDomains=NULL;
 
 }
+/*}}}*/
+/*FUNCTION BamgGeom::~BamgGeom(){{{1*/
+BamgGeom::~BamgGeom(){
+
+	xfree((void**)&this->Vertices);
+	xfree((void**)&this->EdgesSize);
+	xfree((void**)&this->hVertices);
+	xfree((void**)&this->MetricVertices);
+	xfree((void**)&this->TangentAtEdges);
+	xfree((void**)&this->Corners);
+	xfree((void**)&this->RequiredVertices);
+	xfree((void**)&this->RequiredEdges);
+	xfree((void**)&this->CrackedEdges);
+	xfree((void**)&this->SubDomains);
+
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Bamg/BamgGeom.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgGeom.h	(revision 5153)
+++ /issm/trunk/src/c/objects/Bamg/BamgGeom.h	(revision 5154)
@@ -5,35 +5,29 @@
 #define _BAMGGEOM_H_
 
-struct BamgGeom{
+class BamgGeom{
 
-	int     VerticesSize[2];
-	double* Vertices;
+	public:
+		int     VerticesSize[2];
+		double* Vertices;
+		int     EdgesSize[2];
+		double* Edges;
+		double* hVertices;
+		double* MetricVertices;
+		int     TangentAtEdgesSize[2];
+		double* TangentAtEdges;
+		int     CornersSize[2];
+		double* Corners;
+		int     RequiredVerticesSize[2];
+		double* RequiredVertices;
+		int     RequiredEdgesSize[2];
+		double* RequiredEdges;
+		int     CrackedEdgesSize[2];
+		double* CrackedEdges;
+		int     SubDomainsSize[2];
+		double* SubDomains;
 
-	int     EdgesSize[2];
-	double* Edges;
-
-	double* hVertices;
-	double* MetricVertices;
-
-	int     TangentAtEdgesSize[2];
-	double* TangentAtEdges;
-
-	int     CornersSize[2];
-	double* Corners;
-
-	int     RequiredVerticesSize[2];
-	double* RequiredVertices;
-
-	int     RequiredEdgesSize[2];
-	double* RequiredEdges;
-
-	int     CrackedEdgesSize[2];
-	double* CrackedEdges;
-
-	int     SubDomainsSize[2];
-	double* SubDomains;
+		BamgGeom();
+		~BamgGeom();
 };
 
-void BamgGeomInit(BamgGeom* bamggeom);
-
 #endif
Index: /issm/trunk/src/c/objects/Bamg/BamgMesh.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgMesh.cpp	(revision 5153)
+++ /issm/trunk/src/c/objects/Bamg/BamgMesh.cpp	(revision 5154)
@@ -2,23 +2,49 @@
 #include "../objects.h"
 
-void BamgMeshInit(BamgMesh* bamgmesh){
+/*Constructors/Destructors*/
+/*FUNCTION BamgMesh::BamgMesh(){{{1*/
+BamgMesh::BamgMesh(){
 
-	bamgmesh->VerticesSize[0]=0,      bamgmesh->VerticesSize[1]=0;       bamgmesh->Vertices=NULL;
-	bamgmesh->EdgesSize[0]=0,         bamgmesh->EdgesSize[1]=0;          bamgmesh->Edges=NULL;
-	bamgmesh->TrianglesSize[0]=0,     bamgmesh->TrianglesSize[1]=0;      bamgmesh->Triangles=NULL;
-	bamgmesh->QuadrilateralsSize[0]=0,bamgmesh->QuadrilateralsSize[1]=0; bamgmesh->Quadrilaterals=NULL;
-	bamgmesh->VerticesOnGeometricVertexSize[0]=0, bamgmesh->VerticesOnGeometricVertexSize[1]=0;bamgmesh->VerticesOnGeometricVertex=NULL;
-	bamgmesh->VerticesOnGeometricEdgeSize[0]=0,   bamgmesh->VerticesOnGeometricEdgeSize[1]=0;  bamgmesh->VerticesOnGeometricEdge=NULL;
-	bamgmesh->EdgesOnGeometricEdgeSize[0]=0,      bamgmesh->EdgesOnGeometricEdgeSize[1]=0;     bamgmesh->EdgesOnGeometricEdge=NULL;
-	bamgmesh->SubDomainsSize[0]=0,         bamgmesh->SubDomainsSize[1]=0;          bamgmesh->SubDomains=NULL;
-	bamgmesh->SubDomainsFromGeomSize[0]=0, bamgmesh->SubDomainsFromGeomSize[1]=0;  bamgmesh->SubDomainsFromGeom=NULL;
-	bamgmesh->hVertices=NULL;
-	bamgmesh->IssmEdgesSize[0]=0,  bamgmesh->IssmEdgesSize[1]=0;   bamgmesh->IssmEdges=NULL;
-	bamgmesh->IssmSegmentsSize[0]=0,             bamgmesh->IssmSegmentsSize[1]=0;             bamgmesh->IssmSegments=NULL;
-	bamgmesh->ElementConnectivitySize[0]=0,      bamgmesh->ElementConnectivitySize[1]=0;      bamgmesh->ElementConnectivity=NULL;
-	bamgmesh->NodalConnectivitySize[0]=0,        bamgmesh->NodalConnectivitySize[1]=0;        bamgmesh->NodalConnectivity=NULL;
-	bamgmesh->NodalElementConnectivitySize[0]=0, bamgmesh->NodalElementConnectivitySize[1]=0; bamgmesh->NodalElementConnectivity=NULL;
-	bamgmesh->CrackedVerticesSize[0]=0, bamgmesh->CrackedVerticesSize[1]=0; bamgmesh->CrackedVertices=NULL;
-	bamgmesh->CrackedEdgesSize[0]=0, bamgmesh->CrackedEdgesSize[1]=0; bamgmesh->CrackedEdges=NULL;
+	this->VerticesSize[0]=0,                  this->VerticesSize[1]=0;                 this->Vertices=NULL;
+	this->EdgesSize[0]=0,                     this->EdgesSize[1]=0;                    this->Edges=NULL;
+	this->TrianglesSize[0]=0,                 this->TrianglesSize[1]=0;                this->Triangles=NULL;
+	this->QuadrilateralsSize[0]=0,            this->QuadrilateralsSize[1]=0;           this->Quadrilaterals=NULL;
+	this->VerticesOnGeometricVertexSize[0]=0, this->VerticesOnGeometricVertexSize[1]=0;this->VerticesOnGeometricVertex=NULL;
+	this->VerticesOnGeometricEdgeSize[0]=0,   this->VerticesOnGeometricEdgeSize[1]=0;  this->VerticesOnGeometricEdge=NULL;
+	this->EdgesOnGeometricEdgeSize[0]=0,      this->EdgesOnGeometricEdgeSize[1]=0;     this->EdgesOnGeometricEdge=NULL;
+	this->SubDomainsSize[0]=0,                this->SubDomainsSize[1]=0;               this->SubDomains=NULL;
+	this->SubDomainsFromGeomSize[0]=0,        this->SubDomainsFromGeomSize[1]=0;       this->SubDomainsFromGeom=NULL;
+	this->hVertices=NULL;
+	this->IssmEdgesSize[0]=0,                 this->IssmEdgesSize[1]=0;                this->IssmEdges=NULL;
+	this->IssmSegmentsSize[0]=0,              this->IssmSegmentsSize[1]=0;             this->IssmSegments=NULL;
+	this->ElementConnectivitySize[0]=0,       this->ElementConnectivitySize[1]=0;      this->ElementConnectivity=NULL;
+	this->NodalConnectivitySize[0]=0,         this->NodalConnectivitySize[1]=0;        this->NodalConnectivity=NULL;
+	this->NodalElementConnectivitySize[0]=0,  this->NodalElementConnectivitySize[1]=0; this->NodalElementConnectivity=NULL;
+	this->CrackedVerticesSize[0]=0,           this->CrackedVerticesSize[1]=0;          this->CrackedVertices=NULL;
+	this->CrackedEdgesSize[0]=0,              this->CrackedEdgesSize[1]=0;             this->CrackedEdges=NULL;
 
 }
+/*}}}*/
+/*FUNCTION BamgMesh::~BamgMesh(){{{1*/
+BamgMesh::~BamgMesh(){
+
+	xfree((void**)this->Vertices);
+	xfree((void**)this->Edges);
+	xfree((void**)this->Triangles);
+	xfree((void**)this->Quadrilaterals);
+	xfree((void**)this->VerticesOnGeometricVertex);
+	xfree((void**)this->VerticesOnGeometricEdge);
+	xfree((void**)this->EdgesOnGeometricEdge);
+	xfree((void**)this->SubDomains);
+	xfree((void**)this->SubDomainsFromGeom);
+	xfree((void**)this->hVertices);
+	xfree((void**)this->IssmEdges);
+	xfree((void**)this->IssmSegments);
+	xfree((void**)this->ElementConnectivity);
+	xfree((void**)this->NodalConnectivity);
+	xfree((void**)this->NodalElementConnectivity);
+	xfree((void**)this->CrackedVertices);
+	xfree((void**)this->CrackedEdges);
+
+}
+/*}}}*/
Index: /issm/trunk/src/c/objects/Bamg/BamgMesh.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgMesh.h	(revision 5153)
+++ /issm/trunk/src/c/objects/Bamg/BamgMesh.h	(revision 5154)
@@ -5,61 +5,48 @@
 #define _BAMGMESH_H_
 
-struct BamgMesh{
+class BamgMesh{
 
-	/*Bamg input/output*/
-	int     VerticesSize[2];
-	double* Vertices;
+	public:
 
-	int     EdgesSize[2];
-	double* Edges;
+		int     VerticesSize[2];
+		double* Vertices;
+		int     EdgesSize[2];
+		double* Edges;
+		int     TrianglesSize[2];
+		double* Triangles;
+		int     QuadrilateralsSize[2];
+		double* Quadrilaterals;
+		int     VerticesOnGeometricVertexSize[2];
+		double* VerticesOnGeometricVertex;
+		int     VerticesOnGeometricEdgeSize[2];
+		double* VerticesOnGeometricEdge;
+		int     EdgesOnGeometricEdgeSize[2];
+		double* EdgesOnGeometricEdge;
+		int     SubDomainsSize[2];
+		double* SubDomains;
+		int     SubDomainsFromGeomSize[2];
+		double* SubDomainsFromGeom;
+		int     CrackedVerticesSize[2];
+		double* CrackedVertices;
+		int     CrackedEdgesSize[2];
+		double* CrackedEdges;
+		double* hVertices;
 
-	int     TrianglesSize[2];
-	double* Triangles;
+		/*Output for ISSM*/
+		int     IssmEdgesSize[2];
+		double* IssmEdges;
+		int     IssmSegmentsSize[2];
+		double* IssmSegments;
+		int     ElementConnectivitySize[2];
+		double* ElementConnectivity;
+		int     NodalConnectivitySize[2];
+		double* NodalConnectivity;
+		int     NodalElementConnectivitySize[2];
+		double* NodalElementConnectivity;
 
-	int     QuadrilateralsSize[2];
-	double* Quadrilaterals;
-
-	int     VerticesOnGeometricVertexSize[2];
-	double* VerticesOnGeometricVertex;
-
-	int     VerticesOnGeometricEdgeSize[2];
-	double* VerticesOnGeometricEdge;
-
-	int     EdgesOnGeometricEdgeSize[2];
-	double* EdgesOnGeometricEdge;
-
-	int     SubDomainsSize[2];
-	double* SubDomains;
-
-	int     SubDomainsFromGeomSize[2];
-	double* SubDomainsFromGeom;
-
-	int     CrackedVerticesSize[2];
-	double* CrackedVertices;
-
-	int     CrackedEdgesSize[2];
-	double* CrackedEdges;
-
-	double* hVertices;
-
-	/*Output for ISSM*/
-	int     IssmEdgesSize[2];
-	double* IssmEdges;
-
-	int     IssmSegmentsSize[2];
-	double* IssmSegments;
-
-	int     ElementConnectivitySize[2];
-	double* ElementConnectivity;
-
-	int     NodalConnectivitySize[2];
-	double* NodalConnectivity;
-
-	int     NodalElementConnectivitySize[2];
-	double* NodalElementConnectivity;
+		BamgMesh();
+		~BamgMesh();
 
 };
 
-void BamgMeshInit(BamgMesh* bamgmesh);
-
 #endif
Index: /issm/trunk/src/c/objects/Bamg/BamgOpts.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgOpts.cpp	(revision 5153)
+++ /issm/trunk/src/c/objects/Bamg/BamgOpts.cpp	(revision 5154)
@@ -4,57 +4,74 @@
 #include "../objects.h"
 
-void BamgOptsInit(BamgOpts* bamgopts){
+/*Constructors/Destructors*/
+/*FUNCTION BamgOpts::BamgOpts() {{{1*/
+BamgOpts::BamgOpts(){
 
-	bamgopts->iso=0;
-	bamgopts->maxnbv=0;
-	bamgopts->MaxCornerAngle=0;
-	bamgopts->Hessiantype=0;
-	bamgopts->Metrictype=0;
-	bamgopts->KeepVertices=0;
-	bamgopts->Crack=0;
-	bamgopts->maxsubdiv=0;
-	bamgopts->power=0;
-	bamgopts->anisomax=0;
-	bamgopts->nbsmooth=0;
-	bamgopts->nbjacobi=0;
-	bamgopts->omega=0;
-	bamgopts->hmin=0;
-	bamgopts->hmax=0;
-	bamgopts->hminVertices=NULL;
-	bamgopts->hmaxVertices=NULL;
-	bamgopts->gradation=0;
-	bamgopts->cutoff=0;
-	bamgopts->splitcorners=0;
-	bamgopts->geometricalmetric=0;
-	bamgopts->verbose=0;
-	bamgopts->err=NULL;
-	bamgopts->errg=0;
-	bamgopts->coeff=0;
-	bamgopts->metric=NULL;
-	bamgopts->field=NULL;
-	bamgopts->numfields=0;
+	this->iso=0;
+	this->maxnbv=0;
+	this->MaxCornerAngle=0;
+	this->Hessiantype=0;
+	this->Metrictype=0;
+	this->KeepVertices=0;
+	this->Crack=0;
+	this->maxsubdiv=0;
+	this->power=0;
+	this->anisomax=0;
+	this->nbsmooth=0;
+	this->nbjacobi=0;
+	this->omega=0;
+	this->hmin=0;
+	this->hmax=0;
+	this->hminVertices=NULL;
+	this->hmaxVertices=NULL;
+	this->gradation=0;
+	this->cutoff=0;
+	this->splitcorners=0;
+	this->geometricalmetric=0;
+	this->verbose=0;
+	this->err=NULL;
+	this->errg=0;
+	this->coeff=0;
+	this->metric=NULL;
+	this->field=NULL;
+	this->numfields=0;
 
 }
+/*}}}*/
+/*FUNCTION BamgOpts::~BamgOpts() {{{1*/
+BamgOpts::~BamgOpts(){
 
-void BamgOptsCheck(BamgOpts* bamgopts){
+	xfree((void**)&this->hminVertices);
+	xfree((void**)&this->hmaxVertices);
+	xfree((void**)&this->err);
+	xfree((void**)&this->metric);
+	xfree((void**)&this->field);
+
+}
+/*}}}*/
+
+/*Methods*/
+/*FUNCTION BamgOpts::Check{{{1*/
+void BamgOpts::Check(void){
 
 	int i;
 
-	if (bamgopts->coeff==0) ISSMERROR("'coeff' should be positive");
-	if (bamgopts->maxsubdiv<=1) ISSMERROR("'maxsubdiv' should be >1");
-	if (bamgopts->Crack!=0  && bamgopts->Crack!=1) ISSMERROR("'Crack' supported options are 0 and 1");
-	if (bamgopts->Hessiantype!=0  && bamgopts->Hessiantype!=1) ISSMERROR("'Hessiantype' supported options are 0 and 1");
-	if (bamgopts->Metrictype!=0   && bamgopts->Metrictype!=1 && bamgopts->Metrictype!=2) ISSMERROR("'Metrictype' supported options are 0, 1 and 2");
-	if (bamgopts->KeepVertices!=0 && bamgopts->KeepVertices!=1) ISSMERROR("'KeepVertices' supported options are 0 and 1");
-	if (bamgopts->errg<0) ISSMERROR("'errg' option should be >0");
-	if (bamgopts->nbjacobi<=0) ISSMERROR("'nbjacobi' option should be >0");
-	if (bamgopts->geometricalmetric!=0  && bamgopts->geometricalmetric!=1) ISSMERROR("'geometricalmetric' supported options are 0 and 1");
-	if (bamgopts->nbsmooth<=0) ISSMERROR("'nbsmooth' option should be >0");
-	if (bamgopts->maxnbv<3) ISSMERROR("'maxnbv' option should be >3");
-	if (bamgopts->hmin<=0) ISSMERROR("'hmin' option should be >0");
-	if (bamgopts->hmax<=0 || bamgopts->hmax<bamgopts->hmin) ISSMERROR("'hmax' option should be between 0 and hmin=%g",bamgopts->hmin);
-	if (bamgopts->anisomax<1) ISSMERROR("'anisomax' option should be >=1");
-	if (bamgopts->gradation<1) ISSMERROR("'gradation' option should be >=1");
-	for (i=0;i<bamgopts->numfields;i++) {if (bamgopts->err[i]<=0) ISSMERROR("'err' option should be >0");};
+	if (this->coeff==0) ISSMERROR("'coeff' should be positive");
+	if (this->maxsubdiv<=1) ISSMERROR("'maxsubdiv' should be >1");
+	if (this->Crack!=0  && this->Crack!=1) ISSMERROR("'Crack' supported options are 0 and 1");
+	if (this->Hessiantype!=0  && this->Hessiantype!=1) ISSMERROR("'Hessiantype' supported options are 0 and 1");
+	if (this->Metrictype!=0   && this->Metrictype!=1 && this->Metrictype!=2) ISSMERROR("'Metrictype' supported options are 0, 1 and 2");
+	if (this->KeepVertices!=0 && this->KeepVertices!=1) ISSMERROR("'KeepVertices' supported options are 0 and 1");
+	if (this->errg<0) ISSMERROR("'errg' option should be >0");
+	if (this->nbjacobi<=0) ISSMERROR("'nbjacobi' option should be >0");
+	if (this->geometricalmetric!=0  && this->geometricalmetric!=1) ISSMERROR("'geometricalmetric' supported options are 0 and 1");
+	if (this->nbsmooth<=0) ISSMERROR("'nbsmooth' option should be >0");
+	if (this->maxnbv<3) ISSMERROR("'maxnbv' option should be >3");
+	if (this->hmin<=0) ISSMERROR("'hmin' option should be >0");
+	if (this->hmax<=0 || this->hmax<this->hmin) ISSMERROR("'hmax' option should be between 0 and hmin=%g",this->hmin);
+	if (this->anisomax<1) ISSMERROR("'anisomax' option should be >=1");
+	if (this->gradation<1) ISSMERROR("'gradation' option should be >=1");
+	for (i=0;i<this->numfields;i++) {if (this->err[i]<=0) ISSMERROR("'err' option should be >0");};
 
 }
+/*}}}*/
Index: /issm/trunk/src/c/objects/Bamg/BamgOpts.h
===================================================================
--- /issm/trunk/src/c/objects/Bamg/BamgOpts.h	(revision 5153)
+++ /issm/trunk/src/c/objects/Bamg/BamgOpts.h	(revision 5154)
@@ -6,40 +6,42 @@
 #define _BAMGOPTS_H_
 
-struct BamgOpts{
+class BamgOpts{
 
-	int     iso;
-	int     maxnbv;
-	double  MaxCornerAngle;
-	int     Crack;
-	int     Hessiantype;
-	int     Metrictype;
-	int     KeepVertices;
-	double  maxsubdiv;
-	double  power;
-	double  anisomax;
-	int     nbsmooth;
-	int     nbjacobi;
-	double  omega;
-	double  hmin;
-	double  hmax;
-	double* hminVertices;
-	double* hmaxVertices;
-	double  gradation;
-	double  cutoff;
-	int     splitcorners;
-	int     geometricalmetric;
-	int     verbose;
-	double* err;
-	double  errg;
-	double  coeff;
-	double* metric;
-	double* field;
-	int     numfields;
+	public:
+
+		int     iso;
+		int     maxnbv;
+		double  MaxCornerAngle;
+		int     Crack;
+		int     Hessiantype;
+		int     Metrictype;
+		int     KeepVertices;
+		double  maxsubdiv;
+		double  power;
+		double  anisomax;
+		int     nbsmooth;
+		int     nbjacobi;
+		double  omega;
+		double  hmin;
+		double  hmax;
+		double* hminVertices;
+		double* hmaxVertices;
+		double  gradation;
+		double  cutoff;
+		int     splitcorners;
+		int     geometricalmetric;
+		int     verbose;
+		double* err;
+		double  errg;
+		double  coeff;
+		double* metric;
+		double* field;
+		int     numfields;
+
+		BamgOpts();
+		~BamgOpts();
+
+		void Check(void);
 
 };
-
-void BamgOptsInit(BamgOpts* bamgopts);
-
-void BamgOptsCheck(BamgOpts* bamgopts);
-
 #endif
Index: /issm/trunk/src/c/objects/Bamg/Geometry.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/Geometry.cpp	(revision 5153)
+++ /issm/trunk/src/c/objects/Bamg/Geometry.cpp	(revision 5154)
@@ -290,7 +290,4 @@
 		/*Get options*/
 		verbose=bamgopts->verbose;
-
-		/*Initialize output*/
-		BamgGeomInit(bamggeom);
 
 		/*Vertices*/
Index: /issm/trunk/src/c/objects/Bamg/Mesh.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/Mesh.cpp	(revision 5153)
+++ /issm/trunk/src/c/objects/Bamg/Mesh.cpp	(revision 5154)
@@ -528,7 +528,4 @@
 		/*Get options*/
 		int verbose=bamgopts->verbose;
-
-		/*Initialize output*/
-		BamgMeshInit(bamgmesh);
 
 		/*Build reft that holds the number the subdomain number of each triangle, and the real numbering of the elements*/
Index: /issm/trunk/src/m/solvers/solver_linear.m
===================================================================
--- /issm/trunk/src/m/solvers/solver_linear.m	(revision 5153)
+++ /issm/trunk/src/m/solvers/solver_linear.m	(revision 5154)
@@ -21,4 +21,6 @@
 	%Solve	
 	u_f=Solver(K_ff,p_f,[],femmodel.parameters);
+	size(u_f)
+	error
 	
 	%Merge back to g set
Index: /issm/trunk/src/mex/Bamg/Bamg.cpp
===================================================================
--- /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 5153)
+++ /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 5154)
@@ -13,7 +13,9 @@
 	int   i;
 	int   lines,cols;
-	BamgOpts bamgopts;
-	BamgMesh bamgmesh_in,bamgmesh_out;
-	BamgGeom bamggeom_in,bamggeom_out;
+	BamgOpts *bamgopts=NULL;
+	BamgMesh *bamgmesh_in=NULL;
+	BamgGeom *bamggeom_in=NULL;
+	BamgMesh *bamgmesh_out=NULL;
+	BamgGeom *bamggeom_out=NULL;
 
 	/*Boot module: */
@@ -23,70 +25,74 @@
 	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&BamgUsage);
 
+	/*Initialize variables*/
+	bamgopts=new BamgOpts;
+	bamggeom_in=new BamgGeom;
+	bamgmesh_in=new BamgMesh;
+	bamggeom_out=new BamgGeom;
+	bamgmesh_out=new BamgMesh;
+
 	/*create bamg geometry input*/
-	BamgGeomInit(&bamggeom_in);
-	FetchData(&bamggeom_in.Vertices,        &bamggeom_in.VerticesSize[0],        &bamggeom_in.VerticesSize[1],        mxGetField(BAMGGEOMETRY,0,"Vertices"));
-	FetchData(&bamggeom_in.Edges,           &bamggeom_in.EdgesSize[0],           &bamggeom_in.EdgesSize[1],           mxGetField(BAMGGEOMETRY,0,"Edges"));
-	FetchData(&bamggeom_in.Corners,         &bamggeom_in.CornersSize[0],         &bamggeom_in.CornersSize[1],         mxGetField(BAMGGEOMETRY,0,"Corners"));
-	FetchData(&bamggeom_in.RequiredVertices,&bamggeom_in.RequiredVerticesSize[0],&bamggeom_in.RequiredVerticesSize[1],mxGetField(BAMGGEOMETRY,0,"RequiredVertices"));
-	FetchData(&bamggeom_in.RequiredEdges,   &bamggeom_in.RequiredEdgesSize[0],   &bamggeom_in.RequiredEdgesSize[1],   mxGetField(BAMGGEOMETRY,0,"RequiredEdges"));
-	FetchData(&bamggeom_in.CrackedEdges,    &bamggeom_in.CrackedEdgesSize[0],    &bamggeom_in.CrackedEdgesSize[1],    mxGetField(BAMGGEOMETRY,0,"CrackedEdges"));
-	FetchData(&bamggeom_in.SubDomains,      &bamggeom_in.SubDomainsSize[0],      &bamggeom_in.SubDomainsSize[1],      mxGetField(BAMGGEOMETRY,0,"SubDomains"));
-	FetchData(&bamggeom_in.hVertices,&lines,&cols,mxGetField(BAMGGEOMETRY,0,"hVertices"));
-	if (bamggeom_in.hVertices && (cols!=1 || lines!=bamggeom_in.VerticesSize[0])){ISSMERROR("the size of 'hVertices' should be [%i %i]",bamggeom_in.VerticesSize[0],1);}
+	FetchData(&bamggeom_in->Vertices,        &bamggeom_in->VerticesSize[0],        &bamggeom_in->VerticesSize[1],        mxGetField(BAMGGEOMETRY,0,"Vertices"));
+	FetchData(&bamggeom_in->Edges,           &bamggeom_in->EdgesSize[0],           &bamggeom_in->EdgesSize[1],           mxGetField(BAMGGEOMETRY,0,"Edges"));
+	FetchData(&bamggeom_in->Corners,         &bamggeom_in->CornersSize[0],         &bamggeom_in->CornersSize[1],         mxGetField(BAMGGEOMETRY,0,"Corners"));
+	FetchData(&bamggeom_in->RequiredVertices,&bamggeom_in->RequiredVerticesSize[0],&bamggeom_in->RequiredVerticesSize[1],mxGetField(BAMGGEOMETRY,0,"RequiredVertices"));
+	FetchData(&bamggeom_in->RequiredEdges,   &bamggeom_in->RequiredEdgesSize[0],   &bamggeom_in->RequiredEdgesSize[1],   mxGetField(BAMGGEOMETRY,0,"RequiredEdges"));
+	FetchData(&bamggeom_in->CrackedEdges,    &bamggeom_in->CrackedEdgesSize[0],    &bamggeom_in->CrackedEdgesSize[1],    mxGetField(BAMGGEOMETRY,0,"CrackedEdges"));
+	FetchData(&bamggeom_in->SubDomains,      &bamggeom_in->SubDomainsSize[0],      &bamggeom_in->SubDomainsSize[1],      mxGetField(BAMGGEOMETRY,0,"SubDomains"));
+	FetchData(&bamggeom_in->hVertices,&lines,&cols,mxGetField(BAMGGEOMETRY,0,"hVertices"));
+	if (bamggeom_in->hVertices && (cols!=1 || lines!=bamggeom_in->VerticesSize[0])){ISSMERROR("the size of 'hVertices' should be [%i %i]",bamggeom_in->VerticesSize[0],1);}
 
 	/*create bamg mesh input*/
-	BamgMeshInit(&bamgmesh_in);
-	FetchData(&bamgmesh_in.Triangles,&bamgmesh_in.TrianglesSize[0],&bamgmesh_in.TrianglesSize[1],mxGetField(BAMGMESH,0,"Triangles"));
-	FetchData(&bamgmesh_in.Vertices, &bamgmesh_in.VerticesSize[0], &bamgmesh_in.VerticesSize[1], mxGetField(BAMGMESH,0,"Vertices"));
-	FetchData(&bamgmesh_in.Edges,    &bamgmesh_in.EdgesSize[0],    &bamgmesh_in.EdgesSize[1],    mxGetField(BAMGMESH,0,"Edges"));
-	FetchData(&bamgmesh_in.IssmSegments, &bamgmesh_in.IssmSegmentsSize[0], &bamgmesh_in.IssmSegmentsSize[1], mxGetField(BAMGMESH,0,"IssmSegments"));
-	FetchData(&bamgmesh_in.CrackedEdges,&bamgmesh_in.CrackedEdgesSize[0],&bamgmesh_in.CrackedEdgesSize[1],mxGetField(BAMGMESH,0,"CrackedEdges"));
-	FetchData(&bamgmesh_in.EdgesOnGeometricEdge,&bamgmesh_in.EdgesOnGeometricEdgeSize[0],&bamgmesh_in.EdgesOnGeometricEdgeSize[1],mxGetField(BAMGMESH,0,"EdgesOnGeometricEdge"));
-	FetchData(&bamgmesh_in.VerticesOnGeometricEdge,&bamgmesh_in.VerticesOnGeometricEdgeSize[0],&bamgmesh_in.VerticesOnGeometricEdgeSize[1],mxGetField(BAMGMESH,0,"VerticesOnGeometricEdge"));
-	FetchData(&bamgmesh_in.VerticesOnGeometricVertex,&bamgmesh_in.VerticesOnGeometricVertexSize[0],&bamgmesh_in.VerticesOnGeometricVertexSize[1],mxGetField(BAMGMESH,0,"VerticesOnGeometricVertex"));
-	FetchData(&bamgmesh_in.hVertices,&lines,&cols,mxGetField(BAMGMESH,0,"hVertices"));
-	if (bamgmesh_in.hVertices && (cols!=1 || lines!=bamgmesh_in.VerticesSize[0])){ISSMERROR("the size of 'hVertices' should be [%i %i]",bamgmesh_in.VerticesSize[0],1);}
+	FetchData(&bamgmesh_in->Triangles,&bamgmesh_in->TrianglesSize[0],&bamgmesh_in->TrianglesSize[1],mxGetField(BAMGMESH,0,"Triangles"));
+	FetchData(&bamgmesh_in->Vertices, &bamgmesh_in->VerticesSize[0], &bamgmesh_in->VerticesSize[1], mxGetField(BAMGMESH,0,"Vertices"));
+	FetchData(&bamgmesh_in->Edges,    &bamgmesh_in->EdgesSize[0],    &bamgmesh_in->EdgesSize[1],    mxGetField(BAMGMESH,0,"Edges"));
+	FetchData(&bamgmesh_in->IssmSegments, &bamgmesh_in->IssmSegmentsSize[0], &bamgmesh_in->IssmSegmentsSize[1], mxGetField(BAMGMESH,0,"IssmSegments"));
+	FetchData(&bamgmesh_in->CrackedEdges,&bamgmesh_in->CrackedEdgesSize[0],&bamgmesh_in->CrackedEdgesSize[1],mxGetField(BAMGMESH,0,"CrackedEdges"));
+	FetchData(&bamgmesh_in->EdgesOnGeometricEdge,&bamgmesh_in->EdgesOnGeometricEdgeSize[0],&bamgmesh_in->EdgesOnGeometricEdgeSize[1],mxGetField(BAMGMESH,0,"EdgesOnGeometricEdge"));
+	FetchData(&bamgmesh_in->VerticesOnGeometricEdge,&bamgmesh_in->VerticesOnGeometricEdgeSize[0],&bamgmesh_in->VerticesOnGeometricEdgeSize[1],mxGetField(BAMGMESH,0,"VerticesOnGeometricEdge"));
+	FetchData(&bamgmesh_in->VerticesOnGeometricVertex,&bamgmesh_in->VerticesOnGeometricVertexSize[0],&bamgmesh_in->VerticesOnGeometricVertexSize[1],mxGetField(BAMGMESH,0,"VerticesOnGeometricVertex"));
+	FetchData(&bamgmesh_in->hVertices,&lines,&cols,mxGetField(BAMGMESH,0,"hVertices"));
+	if (bamgmesh_in->hVertices && (cols!=1 || lines!=bamgmesh_in->VerticesSize[0])){ISSMERROR("the size of 'hVertices' should be [%i %i]",bamgmesh_in->VerticesSize[0],1);}
 
 	/*create bamg options input*/
-	BamgOptsInit(&bamgopts);
-	FetchData(&bamgopts.coeff,mxGetField(BAMGOPTIONS,0,"coeff"));
-	FetchData(&bamgopts.maxsubdiv,mxGetField(BAMGOPTIONS,0,"maxsubdiv"));
-	FetchData(&bamgopts.Crack,mxGetField(BAMGOPTIONS,0,"Crack"));
-	FetchData(&bamgopts.Hessiantype,mxGetField(BAMGOPTIONS,0,"Hessiantype"));
-	FetchData(&bamgopts.Metrictype,mxGetField(BAMGOPTIONS,0,"Metrictype"));
-	FetchData(&bamgopts.KeepVertices,mxGetField(BAMGOPTIONS,0,"KeepVertices"));
-	FetchData(&bamgopts.power,mxGetField(BAMGOPTIONS,0,"power"));
-	FetchData(&bamgopts.errg,mxGetField(BAMGOPTIONS,0,"errg"));
-	FetchData(&bamgopts.nbjacobi,mxGetField(BAMGOPTIONS,0,"nbjacobi"));
-	FetchData(&bamgopts.nbsmooth,mxGetField(BAMGOPTIONS,0,"nbsmooth"));
-	FetchData(&bamgopts.omega,mxGetField(BAMGOPTIONS,0,"omega"));
-	FetchData(&bamgopts.maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
-	FetchData(&bamgopts.hmin,mxGetField(BAMGOPTIONS,0,"hmin"));
-	FetchData(&bamgopts.hmax,mxGetField(BAMGOPTIONS,0,"hmax"));
-	FetchData(&bamgopts.anisomax,mxGetField(BAMGOPTIONS,0,"anisomax"));
-	FetchData(&bamgopts.gradation,mxGetField(BAMGOPTIONS,0,"gradation"));
-	FetchData(&bamgopts.cutoff,mxGetField(BAMGOPTIONS,0,"cutoff"));
-	FetchData(&bamgopts.verbose,mxGetField(BAMGOPTIONS,0,"verbose"));
-	FetchData(&bamgopts.splitcorners,mxGetField(BAMGOPTIONS,0,"splitcorners"));
-	FetchData(&bamgopts.geometricalmetric,mxGetField(BAMGOPTIONS,0,"geometricalmetric"));
-	FetchData(&bamgopts.MaxCornerAngle,mxGetField(BAMGOPTIONS,0,"MaxCornerAngle"));
-	FetchData(&bamgopts.hminVertices,&lines,&cols,mxGetField(BAMGOPTIONS,0,"hminVertices"));
-	if (bamgopts.hminVertices && (cols!=1 || lines!=bamgmesh_in.VerticesSize[0])){ISSMERROR("the size of 'hminVertices' should be [%i %i]",bamgmesh_in.VerticesSize[0],1);}
-	FetchData(&bamgopts.hmaxVertices,&lines,&cols,mxGetField(BAMGOPTIONS,0,"hmaxVertices"));
-	if (bamgopts.hmaxVertices && (cols!=1 || lines!=bamgmesh_in.VerticesSize[0])){ISSMERROR("the size of 'hmaxVertices' should be [%i %i]",bamgmesh_in.VerticesSize[0],1);}
-	FetchData(&bamgopts.metric,&lines,&cols,mxGetField(BAMGOPTIONS,0,"metric"));
-	if (bamgopts.metric && (cols!=3 || lines!=bamgmesh_in.VerticesSize[0])){ISSMERROR("the size of 'metric' should be [%i %i]",bamgmesh_in.VerticesSize[0],3);}
-	FetchData(&bamgopts.field,&lines,&bamgopts.numfields,mxGetField(BAMGOPTIONS,0,"field"));
-	if (bamgopts.field && lines!=bamgmesh_in.VerticesSize[0]){ISSMERROR("the size of 'field' should be [%i %i]",bamgmesh_in.VerticesSize[0],bamgopts.numfields);}
-	FetchData(&bamgopts.err,NULL,&cols,mxGetField(BAMGOPTIONS,0,"err"));
-	if (bamgopts.numfields!=0 && cols!=bamgopts.numfields){ISSMERROR("the size of 'err' should be the same as 'field'");}
-	BamgOptsCheck(&bamgopts);
+	FetchData(&bamgopts->coeff,mxGetField(BAMGOPTIONS,0,"coeff"));
+	FetchData(&bamgopts->maxsubdiv,mxGetField(BAMGOPTIONS,0,"maxsubdiv"));
+	FetchData(&bamgopts->Crack,mxGetField(BAMGOPTIONS,0,"Crack"));
+	FetchData(&bamgopts->Hessiantype,mxGetField(BAMGOPTIONS,0,"Hessiantype"));
+	FetchData(&bamgopts->Metrictype,mxGetField(BAMGOPTIONS,0,"Metrictype"));
+	FetchData(&bamgopts->KeepVertices,mxGetField(BAMGOPTIONS,0,"KeepVertices"));
+	FetchData(&bamgopts->power,mxGetField(BAMGOPTIONS,0,"power"));
+	FetchData(&bamgopts->errg,mxGetField(BAMGOPTIONS,0,"errg"));
+	FetchData(&bamgopts->nbjacobi,mxGetField(BAMGOPTIONS,0,"nbjacobi"));
+	FetchData(&bamgopts->nbsmooth,mxGetField(BAMGOPTIONS,0,"nbsmooth"));
+	FetchData(&bamgopts->omega,mxGetField(BAMGOPTIONS,0,"omega"));
+	FetchData(&bamgopts->maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
+	FetchData(&bamgopts->hmin,mxGetField(BAMGOPTIONS,0,"hmin"));
+	FetchData(&bamgopts->hmax,mxGetField(BAMGOPTIONS,0,"hmax"));
+	FetchData(&bamgopts->anisomax,mxGetField(BAMGOPTIONS,0,"anisomax"));
+	FetchData(&bamgopts->gradation,mxGetField(BAMGOPTIONS,0,"gradation"));
+	FetchData(&bamgopts->cutoff,mxGetField(BAMGOPTIONS,0,"cutoff"));
+	FetchData(&bamgopts->verbose,mxGetField(BAMGOPTIONS,0,"verbose"));
+	FetchData(&bamgopts->splitcorners,mxGetField(BAMGOPTIONS,0,"splitcorners"));
+	FetchData(&bamgopts->geometricalmetric,mxGetField(BAMGOPTIONS,0,"geometricalmetric"));
+	FetchData(&bamgopts->MaxCornerAngle,mxGetField(BAMGOPTIONS,0,"MaxCornerAngle"));
+	FetchData(&bamgopts->hminVertices,&lines,&cols,mxGetField(BAMGOPTIONS,0,"hminVertices"));
+	if (bamgopts->hminVertices && (cols!=1 || lines!=bamgmesh_in->VerticesSize[0])){ISSMERROR("the size of 'hminVertices' should be [%i %i]",bamgmesh_in->VerticesSize[0],1);}
+	FetchData(&bamgopts->hmaxVertices,&lines,&cols,mxGetField(BAMGOPTIONS,0,"hmaxVertices"));
+	if (bamgopts->hmaxVertices && (cols!=1 || lines!=bamgmesh_in->VerticesSize[0])){ISSMERROR("the size of 'hmaxVertices' should be [%i %i]",bamgmesh_in->VerticesSize[0],1);}
+	FetchData(&bamgopts->metric,&lines,&cols,mxGetField(BAMGOPTIONS,0,"metric"));
+	if (bamgopts->metric && (cols!=3 || lines!=bamgmesh_in->VerticesSize[0])){ISSMERROR("the size of 'metric' should be [%i %i]",bamgmesh_in->VerticesSize[0],3);}
+	FetchData(&bamgopts->field,&lines,&bamgopts->numfields,mxGetField(BAMGOPTIONS,0,"field"));
+	if (bamgopts->field && lines!=bamgmesh_in->VerticesSize[0]){ISSMERROR("the size of 'field' should be [%i %i]",bamgmesh_in->VerticesSize[0],bamgopts->numfields);}
+	FetchData(&bamgopts->err,NULL,&cols,mxGetField(BAMGOPTIONS,0,"err"));
+	if (bamgopts->numfields!=0 && cols!=bamgopts->numfields){ISSMERROR("the size of 'err' should be the same as 'field'");}
+	bamgopts->Check();
 
 	/*!Generate internal degree of freedom numbers: */
-	Bamgx(&bamgmesh_out,&bamggeom_out,&bamgmesh_in,&bamggeom_in,&bamgopts);
+	Bamgx(bamgmesh_out,bamggeom_out,bamgmesh_in,bamggeom_in,bamgopts);
 
 	/*Generate output Matlab Structures*/
-	WriteData(&bamgmesh_mat,&bamgmesh_out);
-	WriteData(&bamggeom_mat,&bamggeom_out);
+	WriteData(&bamgmesh_mat,bamgmesh_out);
+	WriteData(&bamggeom_mat,bamggeom_out);
 
 	/*assign output datasets: */
Index: /issm/trunk/src/mex/BamgConvertMesh/BamgConvertMesh.cpp
===================================================================
--- /issm/trunk/src/mex/BamgConvertMesh/BamgConvertMesh.cpp	(revision 5153)
+++ /issm/trunk/src/mex/BamgConvertMesh/BamgConvertMesh.cpp	(revision 5154)
@@ -16,6 +16,6 @@
 
 	/*Output*/
-	BamgMesh bamgmesh;
-	BamgGeom bamggeom;
+	BamgMesh* bamgmesh=NULL;
+	BamgGeom* bamggeom=NULL;
 	mxArray* bamgmesh_mat=NULL;
 	mxArray* bamggeom_mat=NULL;
@@ -31,4 +31,8 @@
 	/*checks on arguments on the matlab side: */
 	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&BamgConvertMeshUsage);
+
+	/*Initialize variables*/
+	bamggeom=new BamgGeom;
+	bamgmesh=new BamgMesh;
 
 	/*Input datasets: */
@@ -57,9 +61,9 @@
 	/* Run core computations: */
 	if (verbose) printf("Call core\n");
-	BamgConvertMeshx(&bamgmesh,&bamggeom,index,x,y,nods,nels);
+	BamgConvertMeshx(bamgmesh,bamggeom,index,x,y,nods,nels);
 
 	/*Generate output Matlab Structures*/
-	WriteData(&bamgmesh_mat,&bamgmesh);
-	WriteData(&bamggeom_mat,&bamggeom);
+	WriteData(&bamgmesh_mat,bamgmesh);
+	WriteData(&bamggeom_mat,bamggeom);
 
 	/*assign output datasets: */
