Index: /issm/trunk/src/c/Bamgx/Bamgx.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/Bamgx.cpp	(revision 2941)
+++ /issm/trunk/src/c/Bamgx/Bamgx.cpp	(revision 2942)
@@ -24,11 +24,4 @@
 
 int Bamgx(BamgMesh* bamgmesh,BamgGeom* bamggeom,BamgOpts* bamgopts){
-	
-
-	/*output: */
-	double* VerticesOut=NULL;
-	double* TrianglesOut=NULL;
-	int     NumVerticesOut;
-	int     NumTrianglesOut;
 
 	/*Bamg options*/
@@ -36,5 +29,5 @@
 	int    maxnbv;
 	double hmin,hmax;
-	double coef;
+	double coef,maxsubdiv;
 	int    verbosity;
 	int    NbSmooth;
@@ -46,8 +39,5 @@
 	int allquad=0;
 	double costheta=2;
-	int KeepBackVertices=1;
 	double hminaniso=1e-100; 
-	const double  boundmaxsubdiv = 10;
-	double  maxsubdiv=boundmaxsubdiv;
 
 	Triangles* Thr=NULL;
@@ -60,4 +50,5 @@
 	coef=bamgopts->coef;
 	maxnbv=bamgopts->maxnbv;
+	maxsubdiv=bamgopts->maxsubdiv;
 	hmin=bamgopts->hmin;
 	hmax=bamgopts->hmax;
@@ -65,6 +56,6 @@
 
 	// some verification
-	if ( maxsubdiv > boundmaxsubdiv || maxsubdiv <= 1.0){
-		throw ErrorException(__FUNCT__,exprintf("maxsubdiv %g is should be in ]1,%g]",maxsubdiv,boundmaxsubdiv));
+	if ( maxsubdiv > 10 || maxsubdiv <= 1.0){
+		throw ErrorException(__FUNCT__,exprintf("maxsubdiv (%g) should be in ]1,10]",maxsubdiv));
 	}
 	// no metric -> no smoothing 
@@ -164,5 +155,5 @@
 		if (verbosity>1) printf("   Generating Mesh...\n");
 		Thr=&BTh,Thb=0;
-		Triangles & Th( *(0 ?  new Triangles(*Thr,&Thr->Gh,Thb,maxnbv) :  new Triangles(maxnbv,BTh,KeepBackVertices)));
+		Triangles & Th( *(0 ?  new Triangles(*Thr,&Thr->Gh,Thb,maxnbv) :  new Triangles(maxnbv,BTh,bamgopts->KeepVertices)));
 		if (Thr != &BTh) delete Thr;
 		if(costheta<=1.0) Th.MakeQuadrangles(costheta);
Index: /issm/trunk/src/c/Bamgx/Mesh2.h
===================================================================
--- /issm/trunk/src/c/Bamgx/Mesh2.h	(revision 2941)
+++ /issm/trunk/src/c/Bamgx/Mesh2.h	(revision 2942)
@@ -769,7 +769,7 @@
 						 int SplitElement(int choice);
 						 void MakeQuadTree();
-						 void NewPoints( Triangles &,int KeepBackVertex =1 );
+						 void NewPoints( Triangles &,int KeepVertices =1 );
 						 Int4 InsertNewPoints(Int4 nbvold,Int4 & NbTSwap) ; 
-						 void NewPoints(int KeepBackVertex=1){ NewPoints(*this,KeepBackVertex);}
+						 void NewPoints(int KeepVertices=1){ NewPoints(*this,KeepVertices);}
 						 void ReNumberingTheTriangleBySubDomain(bool justcompress=false);
 						 void ReNumberingVertex(Int4 * renu);
@@ -813,5 +813,5 @@
 						 int CrackMesh();
 		private:
-						 void GeomToTriangles1(Int4 nbvx,int KeepBackVertices=1);// the  real constructor mesh adaption
+						 void GeomToTriangles1(Int4 nbvx,int KeepVertices=1);// the  real constructor mesh adaption
 						 void GeomToTriangles0(Int4 nbvx);// the  real constructor mesh generator
 						 void PreInit(Int4,char * =0 );
Index: /issm/trunk/src/c/Bamgx/objects/Triangles.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Triangles.cpp	(revision 2941)
+++ /issm/trunk/src/c/Bamgx/objects/Triangles.cpp	(revision 2942)
@@ -2891,5 +2891,5 @@
 	/*}}}1*/
 	/*FUNCTION Triangles::GeomToTriangles1{{{1*/
-	void Triangles::GeomToTriangles1(Int4 inbvx,int KeepBackVertices) { 
+	void Triangles::GeomToTriangles1(Int4 inbvx,int KeepVertices) { 
 		Gh.NbRef++;// add a ref to Gh
 
@@ -3227,5 +3227,5 @@
 		FindSubDomain();
 
-		NewPoints(BTh,KeepBackVertices) ;
+		NewPoints(BTh,KeepVertices) ;
 		CurrentTh = 0;
 	}
@@ -3256,8 +3256,8 @@
 	int    verbosity=bamgopts->verbose;
 	double anisomax =bamgopts->anisomax;
-	double err      =bamgopts->err[0]; //to be changed...
+	double errg     =bamgopts->errg;
 
 	Real8 ss[2]={0.00001,0.99999};
-	Real8 errC = 2*sqrt(2*err);
+	Real8 errC = 2*sqrt(2*errg);
 	Real8 hmax = Gh.MaximalHmax();
 	Real8 hmin = Gh.MinimalHmin();
@@ -3662,5 +3662,5 @@
 /*}}}1*/
 	/*FUNCTION Triangles::NewPoints{{{1*/
-	void  Triangles::NewPoints(Triangles & Bh,int KeepBackVertex) {
+	void  Triangles::NewPoints(Triangles & Bh,int KeepVertices) {
 		long int verbosity=2;
 		Int4 nbtold(nbt),nbvold(nbv);
@@ -3673,5 +3673,5 @@
 		nbtold = nbt;
 
-		if (KeepBackVertex && (&Bh != this) && (nbv+Bh.nbv< nbvx)){
+		if (KeepVertices && (&Bh != this) && (nbv+Bh.nbv< nbvx)){
 			//   Bh.SetVertexFieldOn();
 			for (i=0;i<Bh.nbv;i++)
Index: /issm/trunk/src/c/objects/BamgOpts.h
===================================================================
--- /issm/trunk/src/c/objects/BamgOpts.h	(revision 2941)
+++ /issm/trunk/src/c/objects/BamgOpts.h	(revision 2942)
@@ -12,8 +12,10 @@
 	double  MaximalAngleOfCorner;
 	int     Hessiantype;
+	int     Metrictype;
+	int     KeepVertices;
+	double  maxsubdiv;
 	double  power;
 	double  anisomax;
 	int     NbSmooth;
-	int     Metrictype;
 	int     nbjacobi;
 	double  omega;
@@ -25,4 +27,5 @@
 	int     verbose;
 	double*  err;
+	double   errg;
 	double  coef;
 	double* metric;
Index: /issm/trunk/src/m/classes/public/bamg.m
===================================================================
--- /issm/trunk/src/m/classes/public/bamg.m	(revision 2941)
+++ /issm/trunk/src/m/classes/public/bamg.m	(revision 2942)
@@ -77,9 +77,12 @@
 % Bamg Options {{{1
 bamg_options.err=getfieldvalue(options,'err',0.01);
+bamg_options.errg=getfieldvalue(options,'errg',0.1);
 bamg_options.coef=getfieldvalue(options,'coef',1);
+bamg_options.maxsubdiv=getfieldvalue(options,'maxsubdiv',10);
 bamg_options.power=getfieldvalue(options,'power',1);
 bamg_options.nbjacobi=getfieldvalue(options,'nbjacobi',1);
 bamg_options.Hessiantype=getfieldvalue(options,'Hessiantype',0);
 bamg_options.Metrictype=getfieldvalue(options,'Metrictype',0);
+bamg_options.KeepVertices=getfieldvalue(options,'KeepVertices',1);
 bamg_options.NbSmooth=getfieldvalue(options,'NbSmooth',3);
 bamg_options.omega=getfieldvalue(options,'omega',1.8);
Index: /issm/trunk/src/mex/Bamg/Bamg.cpp
===================================================================
--- /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2941)
+++ /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2942)
@@ -34,10 +34,10 @@
 	int    maxnbv,verbose,splitcorners;
 	double hmin,hmax,anisomax;
-	double coef;
+	double coef,maxsubdiv;
 	double power;
 	int    Hessiantype,Metrictype,NbSmooth;
-	int    nbjacobi;
+	int    nbjacobi,KeepVertices;
 	double omega;
-	double gradation;
+	double gradation,errg;
 	double cutoff;
 	double* metric=NULL;
@@ -111,10 +111,16 @@
 	FetchData(&coef,mxGetField(BAMGOPTIONS,0,"coef"));
 	bamgopts.coef=coef;
+	FetchData(&maxsubdiv,mxGetField(BAMGOPTIONS,0,"maxsubdiv"));
+	bamgopts.maxsubdiv=maxsubdiv;
 	FetchData(&Hessiantype,mxGetField(BAMGOPTIONS,0,"Hessiantype"));
 	bamgopts.Hessiantype=Hessiantype;
 	FetchData(&Metrictype,mxGetField(BAMGOPTIONS,0,"Metrictype"));
 	bamgopts.Metrictype=Metrictype;
+	FetchData(&KeepVertices,mxGetField(BAMGOPTIONS,0,"KeepVertices"));
+	bamgopts.KeepVertices=KeepVertices;
 	FetchData(&power,mxGetField(BAMGOPTIONS,0,"power"));
 	bamgopts.power=power;
+	FetchData(&errg,mxGetField(BAMGOPTIONS,0,"errg"));
+	bamgopts.errg=errg;
 	FetchData(&nbjacobi,mxGetField(BAMGOPTIONS,0,"nbjacobi"));
 	bamgopts.nbjacobi=nbjacobi;
