Index: /issm/trunk/src/c/Bamgx/Bamgx.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/Bamgx.cpp	(revision 2789)
+++ /issm/trunk/src/c/Bamgx/Bamgx.cpp	(revision 2790)
@@ -29,5 +29,5 @@
 using namespace std;
 
-int Bamgx(BamgMesh* bamgmesh,BamgGeom* bamggeom,BamgArgs* bamgargs){
+int Bamgx(BamgMesh* bamgmesh,BamgGeom* bamggeom,BamgOpts* bamgopts){
 	
 	int noerr=1;
@@ -43,17 +43,11 @@
 	int    maxnbv;
 	double hmin,hmax;
-	double gradation;
 	double cutoff;
 	int    verbosity;
-	int    splitcorners;
 
 	/*Bamg variables: */
 	int i,j,num;
-	hinterpole=1; // by def interpolation a h 
-	int fileout=0;
 	int AbsError=0,nbjacoby=1,allquad=0;
-	int Rescaling = 1;
 	double costheta=2;
-	Real8 cutoffradian=-1;
 	double anisomax = 1e6;
 	double err=0.01,errg=0.1,coef=1;
@@ -64,47 +58,25 @@
 	double omega=1.8;
 	int NbSmooth=3;
-	double *solMbb =0,*solMBB=0;
-	int  *typesolsBB =0;
-	Int4 nbsolbb=0,lsolbb=0;
-	Int4 nbsolBB=0,lsolBB=0;
-	int rbbeqMbb=0,rBBeqMBB=0;
-	int ChoiseHessien = 0;
-	double power=1;
-	Triangles *Thr=0,*Thb=0;
-	char *fmeshback=0,*fmeshout=0,*fmeshr=0,*fmetrix=0,*famfmt=0,*fmsh=0,
-		 *fnopo=0,*fftq=0,*fam=0,*famdba=0,*rbb=0,*rBB=0,*wbb=0,*wBB=0,
-		 *fMbb=0,*foM=0,*fMBB=0;
-	char *datargv[128] ;
-	int datargc=1;
-	datargv[0]= datargv[1]=0;// for create a error if no parameter 
+	Triangles* Thr=NULL;
+	Triangles* Thb=NULL;
 
 	/*Bamg options*/
-	iso=bamgargs->iso;
-	maxnbv=bamgargs->maxnbv;
-	hmin=bamgargs->hmin;
-	hmax=bamgargs->hmax;
-	gradation=bamgargs->gradation;
-	cutoff=bamgargs->cutoff;
-	verbosity=bamgargs->verbose;
-	splitcorners=bamgargs->splitcorners;
+	iso=bamgopts->iso;
+	maxnbv=bamgopts->maxnbv;
+	hmin=bamgopts->hmin;
+	hmax=bamgopts->hmax;
+	cutoff=bamgopts->cutoff;
+	verbosity=bamgopts->verbose;
 
 	// some verification
-	if ( maxsubdiv > boundmaxsubdiv || maxsubdiv <= 1.0)
-	{
+	if ( maxsubdiv > boundmaxsubdiv || maxsubdiv <= 1.0){
 		cerr << " -maxsubdiv " << maxsubdiv << " is not in ]1,"<< boundmaxsubdiv << "]" << endl;
 		exit(3);
 	}
 	if (iso) anisomax=1;
-	if (!(fmetrix||fMbb))
-		NbSmooth=0; // no metric -> no smoothing 
-	if( ! rbb) // to set the rbb filename by default 
-		rbb=fMbb;
-	if( ! rBB) // to set the rbb filename by default 
-		rBB=fMBB;
-
-	if (fMbb && rbb) 
-		rbbeqMbb = !strcmp(rbb,fMbb);
-	if (fMBB && rBB) 
-		rBBeqMBB = !strcmp(rBB,fMBB);
+	// no metric -> no smoothing 
+	if (bamgopts->metric==NULL){
+		NbSmooth=0; 
+	}
 
 	if(bamgmesh->NumTriangles==0){
@@ -113,5 +85,5 @@
 		if (verbosity>0) printf("Construction of a mesh from a given geometry\n");
 		if (verbosity>1) printf("   Processing geometry...\n");
-		Geometry Gh(bamggeom,bamgargs);
+		Geometry Gh(bamggeom,bamgopts);
 		hmin = Max(hmin,Gh.MinimalHmin());
 		hmax = Min(hmax,Gh.MaximalHmax());
@@ -131,5 +103,5 @@
 		if (verbosity>1) printf("   Generating Mesh...\n");
 		Triangles Th(maxnbv,Gh);
-		if(splitcorners) Th.SplitInternalEdgeWithBorderVertices();
+		if(bamgopts->splitcorners) Th.SplitInternalEdgeWithBorderVertices();
 		Th.ReNumberingTheTriangleBySubDomain();
 		//if(NbSmooth>0) Th.SmoothingVertex(NbSmooth,omega);
@@ -169,5 +141,5 @@
 		if (verbosity>0) printf("Anisotropic mesh adaptation\n");
 		if (verbosity>1) printf("   Processing initial mesh and geometry...\n");
-		Triangles BTh(bamgmesh,bamgargs); 
+		Triangles BTh(bamgmesh,bamgopts); 
 		hmin = Max(hmin,BTh.MinimalHmin());
 		hmax = Min(hmax,BTh.MaximalHmax());
@@ -178,6 +150,6 @@
 		//build metric if not given in input
 		if (verbosity>1) printf("   Processing Metric...\n");
-		if (bamgargs->metric){
-			BTh.ReadMetric(bamgargs,hmin,hmax,coef);
+		if (bamgopts->metric){
+			BTh.ReadMetric(bamgopts,hmin,hmax,coef);
 		}
 		else { // init with hmax 
@@ -188,5 +160,5 @@
 
 		BTh.IntersectGeomMetric(errg,iso);
-		if(gradation) BTh.SmoothMetric(gradation);
+		if(bamgopts->gradation) BTh.SmoothMetric(bamgopts->gradation);
 		BTh.MaxSubDivision(maxsubdiv);
 		BTh.BoundAnisotropy(anisomax,hminaniso);
@@ -196,21 +168,12 @@
 		Triangles & Th( *(0 ?  new Triangles(*Thr,&Thr->Gh,Thb,maxnbv) :  new Triangles(maxnbv,BTh,KeepBackVertices)));
 		if (Thr != &BTh) delete Thr;
-
-		if(costheta<=1.0){
-			Th.MakeQuadrangles(costheta);
-		}
-		if (allquad){
-			Th.SplitElement(allquad==2);
-		}
-		if(splitcorners){
-			Th.SplitInternalEdgeWithBorderVertices();
-		}
+		if(costheta<=1.0) Th.MakeQuadrangles(costheta);
+		if (allquad) Th.SplitElement(allquad==2);
+		if(bamgopts->splitcorners) Th.SplitInternalEdgeWithBorderVertices();
 		Th.ReNumberingTheTriangleBySubDomain();
-
 		if(NbSmooth>0) Th.SmoothingVertex(NbSmooth,omega);
-
 		Th.BTh.ReMakeTriangleContainingTheVertex();
 
-		//info
+		//display info
 		if(verbosity>0) {
 			if (Th.nbt-Th.NbOutT-Th.NbOfQuad*2){
@@ -247,5 +210,5 @@
 
 		/*clean up*/
-		//delete &Th;
+		delete &Th; //TEST crash
 		/*}}}*/
 	}
Index: /issm/trunk/src/c/Bamgx/Bamgx.h
===================================================================
--- /issm/trunk/src/c/Bamgx/Bamgx.h	(revision 2789)
+++ /issm/trunk/src/c/Bamgx/Bamgx.h	(revision 2790)
@@ -9,5 +9,5 @@
 
 /* local prototypes: */
-int     Bamgx(BamgMesh* bamgmesh,BamgGeom* bamggeom,BamgArgs* bamgargs);
+int     Bamgx(BamgMesh* bamgmesh,BamgGeom* bamggeom,BamgOpts* bamgopts);
 
 #endif  /* _BAMGX_H */
Index: /issm/trunk/src/c/Bamgx/Mesh2.h
===================================================================
--- /issm/trunk/src/c/Bamgx/Mesh2.h	(revision 2789)
+++ /issm/trunk/src/c/Bamgx/Mesh2.h	(revision 2790)
@@ -802,5 +802,5 @@
   ~Triangles(); 
   Triangles(const char * ,Real8=-1) ;
-  Triangles(BamgMesh* bamgmesh,BamgArgs* bamgargs);
+  Triangles(BamgMesh* bamgmesh,BamgOpts* bamgopts);
   
   Triangles(Int4 nbvx,Triangles & BT,int keepBackVertices=1)
@@ -898,5 +898,5 @@
 
   void Read(MeshIstream &,int version,Real8 cutoffradian);
-  void ReadFromMatlabMesh(BamgMesh* bamgmesh, BamgArgs* bamgargs);
+  void ReadFromMatlabMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts);
   void Read_am_fmt(MeshIstream &);
   void Read_amdba(MeshIstream &);
@@ -906,5 +906,5 @@
   void Read_msh(MeshIstream &);
 
-  void ReadMetric(BamgArgs* bamgargs,const Real8 hmin,const Real8 hmax,const Real8 coef);
+  void ReadMetric(BamgOpts* bamgopts,const Real8 hmin,const Real8 hmax,const Real8 coef);
   void IntersectConsMetric(const double * s,const Int4 nbsol,const int * typsols,
 			   const  Real8 hmin,const Real8 hmax, const Real8 coef,
@@ -984,5 +984,5 @@
   Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
   void ReadGeometry(const char * ) ;
-  void ReadGeometry(BamgGeom* bamggeom, BamgArgs* bamgargs);
+  void ReadGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
   void ReadGeometry(MeshIstream & ,const char *)  ;
 
@@ -990,5 +990,5 @@
   Geometry() {EmptyGeometry();}// empty Geometry
   void AfterRead();
-  Geometry(BamgGeom* bamggeom, BamgArgs* bamgargs) {EmptyGeometry();OnDisk=1;ReadGeometry(bamggeom,bamgargs);AfterRead();}
+  Geometry(BamgGeom* bamggeom, BamgOpts* bamgopts) {EmptyGeometry();OnDisk=1;ReadGeometry(bamggeom,bamgopts);AfterRead();}
   Geometry(const char * filename) {EmptyGeometry();OnDisk=1;ReadGeometry(filename);AfterRead();}
 
Index: /issm/trunk/src/c/Bamgx/MeshRead.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/MeshRead.cpp	(revision 2789)
+++ /issm/trunk/src/c/Bamgx/MeshRead.cpp	(revision 2790)
@@ -39,5 +39,5 @@
 static const  Direction NoDirOfSearch=Direction();
 
-void Triangles::ReadFromMatlabMesh(BamgMesh* bamgmesh, BamgArgs* bamgargs){
+void Triangles::ReadFromMatlabMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts){
 
 	int verbose;
@@ -50,5 +50,5 @@
 	int Version=1,dim=2;
 
-	verbose=bamgargs->verbose;
+	verbose=bamgopts->verbose;
 
 	nbv=bamgmesh->NumVertices;
@@ -264,5 +264,5 @@
 		printf("Warning: mesh present but no geometry found. Reconstructing...\n");
 		/*Recreate geometry: */
-		ConsGeometry(-1);	//TESTTESTTESTTEST MaximalAngleOfCorner is actually in BamgGeom...
+		ConsGeometry(bamgopts->MaximalAngleOfCorner*Pi/180);
 		Gh.AfterRead();
 	}
@@ -1141,10 +1141,10 @@
 }
 
-Triangles::Triangles(BamgMesh* bamgmesh, BamgArgs* bamgargs):Gh(*(new Geometry())),BTh(*this){ 
+Triangles::Triangles(BamgMesh* bamgmesh, BamgOpts* bamgopts):Gh(*(new Geometry())),BTh(*this){ 
 
   PreInit(0,"none");
   OnDisk = 1;
 
-  ReadFromMatlabMesh(bamgmesh,bamgargs);
+  ReadFromMatlabMesh(bamgmesh,bamgopts);
   SetIntCoor();
   FillHoleInMesh();
@@ -1161,5 +1161,5 @@
 }
 
-void Geometry::ReadGeometry(BamgGeom* bamggeom,BamgArgs* bamgargs){
+void Geometry::ReadGeometry(BamgGeom* bamggeom,BamgOpts* bamgopts){
 
 	int verbose;
@@ -1178,5 +1178,5 @@
 	nbvx = nbv;
 	nbiv = nbv;
-	verbose=bamgargs->verbose;
+	verbose=bamgopts->verbose;
 
 	//some checks
@@ -1314,7 +1314,7 @@
 
 	//MaximalAngleOfCorner
-	if (bamggeom->MaximalAngleOfCorner){
+	if (bamgopts->MaximalAngleOfCorner){
 		if(verbose>3) printf("      processing MaximalAngleOfCorner\n");
-		MaximalAngleOfCorner=bamggeom->MaximalAngleOfCorner*Pi/180;
+		MaximalAngleOfCorner=bamgopts->MaximalAngleOfCorner*Pi/180;
 	}
 	else{
Index: /issm/trunk/src/c/Bamgx/Metric.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/Metric.cpp	(revision 2789)
+++ /issm/trunk/src/c/Bamgx/Metric.cpp	(revision 2790)
@@ -805,9 +805,9 @@
 
 
-void Triangles::ReadMetric(BamgArgs* bamgargs,const Real8 hmin1=1.0e-30,const Real8 hmax1=1.0e30,const Real8 coef=1)
+void Triangles::ReadMetric(BamgOpts* bamgopts,const Real8 hmin1=1.0e-30,const Real8 hmax1=1.0e30,const Real8 coef=1)
 {
 	int  i,j;
 
-	if(bamgargs->verbose>3) printf("      processing metric\n");
+	if(bamgopts->verbose>3) printf("      processing metric\n");
 
 	Real8 hmin = Max(hmin1,MinimalHmin());
@@ -820,12 +820,12 @@
 		Real8 h;
 		if (j == 1){
-			h=bamgargs->metric[i];
+			h=bamgopts->metric[i];
 			vertices[i].m=Metric(Max(hmin,Min(hmax, h*coef)));
 		}
 		else if (j==3){
 			Real8 a,b,c;	     
-			a=bamgargs->metric[i*3+0];
-			b=bamgargs->metric[i*3+1];
-			c=bamgargs->metric[i*3+2];
+			a=bamgopts->metric[i*3+0];
+			b=bamgopts->metric[i*3+1];
+			c=bamgopts->metric[i*3+2];
 			MetricAnIso M(a,b,c);
 			MatVVP2x2 Vp(M/coef);
Index: sm/trunk/src/c/objects/BamgArgs.h
===================================================================
--- /issm/trunk/src/c/objects/BamgArgs.h	(revision 2789)
+++ 	(revision )
@@ -1,21 +1,0 @@
-/*!\file:  BamgArgs.h
- * \brief place holder for optimization function arguments
- */ 
-
-#ifndef BAMGARGS_H_
-#define BAMGARGS_H_
-
-struct BamgArgs{
-
-	int     iso;
-	int     maxnbv;
-	double  hmin;
-	double  hmax;
-	double  gradation;
-	double  cutoff;
-	int     splitcorners;
-	int     verbose;
-	double* metric;
-
-};
-#endif
Index: /issm/trunk/src/c/objects/BamgGeom.h
===================================================================
--- /issm/trunk/src/c/objects/BamgGeom.h	(revision 2789)
+++ /issm/trunk/src/c/objects/BamgGeom.h	(revision 2790)
@@ -18,6 +18,4 @@
 	double* h1h2VpVertices;
 
-	double  MaximalAngleOfCorner;
-
 	int     NumTangentAtEdges;
 	double* TangentAtEdges;
Index: /issm/trunk/src/c/objects/BamgOpts.h
===================================================================
--- /issm/trunk/src/c/objects/BamgOpts.h	(revision 2790)
+++ /issm/trunk/src/c/objects/BamgOpts.h	(revision 2790)
@@ -0,0 +1,22 @@
+/*!\file:  BamgOpts.h
+ * \brief place holder for optimization function arguments
+ */ 
+
+#ifndef BAMGOPTS_H_
+#define BAMGOPTS_H_
+
+struct BamgOpts{
+
+	int     iso;
+	int     maxnbv;
+	double  MaximalAngleOfCorner;
+	double  hmin;
+	double  hmax;
+	double  gradation;
+	double  cutoff;
+	int     splitcorners;
+	int     verbose;
+	double* metric;
+
+};
+#endif
Index: /issm/trunk/src/c/objects/objects.h
===================================================================
--- /issm/trunk/src/c/objects/objects.h	(revision 2789)
+++ /issm/trunk/src/c/objects/objects.h	(revision 2790)
@@ -41,6 +41,5 @@
 #include "./BamgGeom.h"
 #include "./BamgMesh.h"
-#include "./BamgArgs.h"
-
+#include "./BamgOpts.h"
 
 #endif
Index: /issm/trunk/src/m/classes/public/bamg.m
===================================================================
--- /issm/trunk/src/m/classes/public/bamg.m	(revision 2789)
+++ /issm/trunk/src/m/classes/public/bamg.m	(revision 2790)
@@ -19,5 +19,4 @@
 bamg_geometry.Edges=zeros(0,3);
 bamg_geometry.hVertices=zeros(0,1);
-bamg_geometry.MaximalAngleOfCorner=getfieldvalue(options,'MaximalAngleOfCorner',10);
 bamg_geometry.NumSubDomain=0;
 bamg_geometry.SubDomain=zeros(0,3);
@@ -67,4 +66,5 @@
 bamg_options.iso=getfieldvalue(options,'iso',0);
 bamg_options.maxnbv=getfieldvalue(options,'maxnbv',10^6);
+bamg_options.MaximalAngleOfCorner=getfieldvalue(options,'MaximalAngleOfCorner',10);
 bamg_options.hmin=getfieldvalue(options,'hmin',10^-100);
 bamg_options.hmax=getfieldvalue(options,'hmax',10^100);
Index: /issm/trunk/src/mex/Bamg/Bamg.cpp
===================================================================
--- /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2789)
+++ /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2790)
@@ -9,5 +9,5 @@
 	int   noerr=1;
 	int   i;
-	BamgArgs bamgargs;
+	BamgOpts bamgopts;
 	BamgMesh bamgmesh;
 	BamgGeom bamggeom;
@@ -55,6 +55,4 @@
 	bamggeom.MetricVertices=NULL;
 	bamggeom.h1h2VpVertices=NULL;
-	FetchData(&MaximalAngleOfCorner,mxGetField(BAMGGEOMETRY,0,"MaximalAngleOfCorner"));
-	bamggeom.MaximalAngleOfCorner=MaximalAngleOfCorner;
 	bamggeom.NumTangentAtEdges=0;
 	bamggeom.TangentAtEdges=NULL;
@@ -93,24 +91,26 @@
 	/*create bamg options input*/
 	FetchData(&iso,mxGetField(BAMGOPTIONS,0,"iso"));
-	bamgargs.iso=iso;
+	bamgopts.iso=iso;
 	FetchData(&maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
-	bamgargs.maxnbv=maxnbv;
+	bamgopts.maxnbv=maxnbv;
 	FetchData(&hmin,mxGetField(BAMGOPTIONS,0,"hmin"));
-	bamgargs.hmin=hmin;
+	bamgopts.hmin=hmin;
 	FetchData(&hmax,mxGetField(BAMGOPTIONS,0,"hmax"));
-	bamgargs.hmax=hmax;
+	bamgopts.hmax=hmax;
 	FetchData(&gradation,mxGetField(BAMGOPTIONS,0,"gradation"));
-	bamgargs.gradation=gradation;
+	bamgopts.gradation=gradation;
 	FetchData(&cutoff,mxGetField(BAMGOPTIONS,0,"cutoff"));
-	bamgargs.cutoff=cutoff;
+	bamgopts.cutoff=cutoff;
 	FetchData(&verbose,mxGetField(BAMGOPTIONS,0,"verbose"));
-	bamgargs.verbose=verbose;
+	bamgopts.verbose=verbose;
 	FetchData(&splitcorners,mxGetField(BAMGOPTIONS,0,"splitcorners"));
-	bamgargs.splitcorners=splitcorners;
+	bamgopts.splitcorners=splitcorners;
+	FetchData(&MaximalAngleOfCorner,mxGetField(BAMGOPTIONS,0,"MaximalAngleOfCorner"));
+	bamgopts.MaximalAngleOfCorner=MaximalAngleOfCorner;
 	FetchData(&metric,NULL,NULL,mxGetField(BAMGOPTIONS,0,"metric"));
-	bamgargs.metric=metric;
+	bamgopts.metric=metric;
 
 	/*!Generate internal degree of freedom numbers: */
-	Bamgx(&bamgmesh,&bamggeom,&bamgargs);
+	Bamgx(&bamgmesh,&bamggeom,&bamgopts);
 
 	/*write output datasets: */
