Index: /issm/trunk/src/c/Bamgx/Bamgx.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/Bamgx.cpp	(revision 2780)
+++ /issm/trunk/src/c/Bamgx/Bamgx.cpp	(revision 2781)
@@ -39,10 +39,18 @@
 	int     nelout, nodsout;
 
+	/*Bamg options*/
+	int    iso;
+	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 nbvx = 1000000;
-	int iso =0,AbsError=0,nbjacoby=1,allquad=0;
+	int AbsError=0,nbjacoby=1,allquad=0;
 	int NoMeshReconstruction=0;
 	int Rescaling = 1;
@@ -50,5 +58,5 @@
 	Real8 cutoffradian=-1;
 	double anisomax = 1e6;
-	double err=0.01,errg=0.1,coef=1,hmin=1.e-100,hmax=1.e17,gradation=1.2,cutoff=1e-5;
+	double err=0.01,errg=0.1,coef=1;
 	int KeepBackVertices=1;
 	double hminaniso=1e-100; 
@@ -61,5 +69,4 @@
 	Int4 nbsolbb=0,lsolbb=0;
 	Int4 nbsolBB=0,lsolBB=0;
-	int SplitEdgeWith2Boundary=0;
 	int rbbeqMbb=0,rBBeqMBB=0;
 	int ChoiseHessien = 0;
@@ -69,26 +76,21 @@
 		 *fnopo=0,*fftq=0,*fam=0,*famdba=0,*rbb=0,*rBB=0,*wbb=0,*wBB=0,
 		 *fMbb=0,*foM=0,*fMBB=0;
-	long int verbosity =10;
 	char *datargv[128] ;
 	int datargc=1;
 	datargv[0]= datargv[1]=0;// for create a error if no parameter 
 
-	/*testing*/
-	int splitpbedge=1;
-
 	/*Bamg options*/
 	iso=bamgargs->iso;
+	maxnbv=bamgargs->maxnbv;
 	hmin=bamgargs->hmin;
 	hmax=bamgargs->hmax;
 	gradation=bamgargs->gradation;
 	cutoff=bamgargs->cutoff;
-
-	/*Recover options from inputs: */
-	if(splitpbedge)SplitEdgeWith2Boundary=1;
+	verbosity=bamgargs->verbose;
+	splitcorners=bamgargs->splitcorners;
 
 	// some verification
 	NoMeshReconstruction= fmeshr !=0;
 	if (!fmeshback) fmeshback=fmeshr;
-	
 	if ( maxsubdiv > boundmaxsubdiv || maxsubdiv <= 1.0)
 	{
@@ -96,6 +98,5 @@
 		exit(3);
 	}
-	if (iso) 
-		anisomax=1;
+	if (iso) anisomax=1;
 	if (!(fmetrix||fMbb))
 		NbSmooth=0; // no metric -> no smoothing 
@@ -113,5 +114,5 @@
 		/*Mesh generation {{{1*/
 		if (verbosity>0) printf("Construction of a mesh from a given geometry\n");
-		Geometry Gh(bamggeom);
+		Geometry Gh(bamggeom,bamgargs);
 		hmin = Max(hmin,Gh.MinimalHmin());
 		hmax = Min(hmax,Gh.MaximalHmax());
@@ -128,5 +129,9 @@
 
 		//generate mesh
-		Triangles Th(nbvx,Gh);
+		Triangles Th(maxnbv,Gh);
+		if(splitcorners) Th.SplitInternalEdgeWithBorderVertices();
+		Th.ReNumberingTheTriangleBySubDomain();
+		//if(NbSmooth>0) Th.SmoothingVertex(NbSmooth,omega);
+		Th.SmoothingVertex(3,omega);
 
 		//Build output
@@ -161,5 +166,5 @@
 
 		/*Read background mesh from simple delaunay triangulation: */
-		Triangles BTh(bamgmesh->index,bamgmesh->x,bamgmesh->y,bamgmesh->numberofelements,bamgmesh->numberofnodes,nbvx,cutoffradian); // read the background mesh 
+		Triangles BTh(bamgmesh,bamgargs); // read the background mesh 
 
 		hmin = Max(hmin,BTh.MinimalHmin());
@@ -232,6 +237,6 @@
 
 			Triangles & Th( *(NoMeshReconstruction 
-							?  new Triangles(*Thr,&Thr->Gh,Thb,nbvx) // copy the mesh + free space to modification  
-							:  new Triangles(nbvx,BTh,KeepBackVertices)     // construct a new mesh 
+							?  new Triangles(*Thr,&Thr->Gh,Thb,maxnbv) // copy the mesh + free space to modification  
+							:  new Triangles(maxnbv,BTh,KeepBackVertices)     // construct a new mesh 
 							));
 			if (Thr != &BTh) delete Thr;
@@ -241,5 +246,5 @@
 			if (allquad)
 			 Th.SplitElement(allquad==2);
-			if(SplitEdgeWith2Boundary)
+			if(splitcorners)
 			 Th.SplitInternalEdgeWithBorderVertices();
 			Th.ReNumberingTheTriangleBySubDomain();
Index: /issm/trunk/src/c/Bamgx/Mesh2.h
===================================================================
--- /issm/trunk/src/c/Bamgx/Mesh2.h	(revision 2780)
+++ /issm/trunk/src/c/Bamgx/Mesh2.h	(revision 2781)
@@ -802,5 +802,5 @@
   ~Triangles(); 
   Triangles(const char * ,Real8=-1) ;
-  Triangles(double* elements, double* x, double* y, int nel, int nods,int NBV, Real8=-1);
+  Triangles(BamgMesh* bamgmesh,BamgArgs* bamgargs);
   
   Triangles(Int4 nbvx,Triangles & BT,int keepBackVertices=1)
@@ -898,5 +898,5 @@
 
   void Read(MeshIstream &,int version,Real8 cutoffradian);
-  void ReadFromMatlabMesh(double* elements,double* x,double* y,int nel,int nods,int inbvx,Real8 cutoffradian);
+  void ReadFromMatlabMesh(BamgMesh* bamgmesh, BamgArgs* bamgargs);
   void Read_am_fmt(MeshIstream &);
   void Read_amdba(MeshIstream &);
@@ -984,5 +984,5 @@
   Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
   void ReadGeometry(const char * ) ;
-  void ReadGeometry(BamgGeom* bamggeom);
+  void ReadGeometry(BamgGeom* bamggeom, BamgArgs* bamgargs);
   void ReadGeometry(MeshIstream & ,const char *)  ;
 
@@ -990,5 +990,5 @@
   Geometry() {EmptyGeometry();}// empty Geometry
   void AfterRead();
-  Geometry(BamgGeom* bamggeom) {EmptyGeometry();OnDisk=1;ReadGeometry(bamggeom);AfterRead();}
+  Geometry(BamgGeom* bamggeom, BamgArgs* bamgargs) {EmptyGeometry();OnDisk=1;ReadGeometry(bamggeom,bamgargs);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 2780)
+++ /issm/trunk/src/c/Bamgx/MeshRead.cpp	(revision 2781)
@@ -39,32 +39,28 @@
 static const  Direction NoDirOfSearch=Direction();
 
-void Triangles::ReadFromMatlabMesh(double* elements,double* x,double* y,int nel,int nods,int NBV,Real8 cutoffradian){
-
-	long int verbosity=0;
-
+void Triangles::ReadFromMatlabMesh(BamgMesh* bamgmesh, BamgArgs* bamgargs){
+
+	int verbosity;
 	Real8 hmin = HUGE_VAL;// the infinie value 
-	
+	Int4 i1,i2,i3,iref;
 	Int4 i;
-	Int4 dim=0;
 	Int4 hvertices =0;
 	Int4 ifgeom=0;
 	Metric M1(1);
-	int field=0;
-	int showfield=0;
-	
-	field=0;
-	dim=2;
-	nbv=NBV;
-	nbvx=NBV;
-	nbiv = NBV;
-
-
-	vertices=(Vertex*)xmalloc(nbvx*sizeof(Vertex));
-	ordre=(Vertex**)xmalloc(nbvx*sizeof(Vertex*));
-
-	for (i=0;i<nods;i++){
-				
-		vertices[i].r.x=x[i];
-		vertices[i].r.y=y[i];
+	Int4 dim=2;
+
+	nbv=bamgmesh->numberofnodes;
+	nbvx=bamgargs->maxnbv;
+	nbt=bamgmesh->numberofelements;
+	nbtx=2*nbvx-2; // for filling The Holes and quadrilaterals 
+	nbiv=nbvx;
+
+	vertices=(Vertex*)xmalloc(nbv*sizeof(Vertex));
+	ordre=(Vertex**)xmalloc(nbv*sizeof(Vertex*));
+
+	/*Create Vertices*/
+	for (i=0;i<bamgmesh->numberofnodes;i++){
+		vertices[i].r.x=bamgmesh->x[i];
+		vertices[i].r.y=bamgmesh->y[i];
 		vertices[i].ReferenceNumber=1;
 		vertices[i].DirOfSearch =NoDirOfSearch;
@@ -73,24 +69,18 @@
 	}
 
-	nbtx =  2*nbvx-2; // for filling The Holes and quadrilaterals 
-
-	triangles =(Triangle*)xmalloc(nbtx*sizeof(Triangle));
-	nbt =0;
-	for (i=0;i<nel;i++){
-		Int4 i1,i2,i3,iref;
-		Triangle & t = triangles[nbt++];
-		i1=(Int4)*(elements+i*3+0);
-		i2=(Int4)*(elements+i*3+1);
-		i3=(Int4)*(elements+i*3+2);
-
-		iref=1;
-		t = Triangle(this,i1-1,i2-1,i3-1);
-		t.color=iref;
-	}
-
-	/*build geometry: */
-	ConsGeometry(cutoffradian);	
+	/*Create triangles*/
+	triangles=(Triangle*)xmalloc(nbt*sizeof(Triangle));
+	for (i=0;i<bamgmesh->numberofelements;i++){
+		Triangle & t = triangles[i];
+		i1=(Int4)bamgmesh->index[i*3+0]-1; //for C indexing
+		i2=(Int4)bamgmesh->index[i*3+1]-1; //for C indexing
+		i3=(Int4)bamgmesh->index[i*3+2]-1; //for C indexing
+		t=Triangle(this,i1,i2,i3);
+		t.color=1;
+	}
+
+	/*Recreate geometry: */
+	ConsGeometry(-1);	//MaximalAngleOfCorner is actually in BamgGeom...
 	Gh.AfterRead();
-
 }
 
@@ -969,18 +959,16 @@
 }
 
-Triangles::Triangles(double* elements, double* x, double* y, int nel, int nods,int NBV,Real8 cutoffradian) : Gh(*(new Geometry())), BTh(*this){ 
+Triangles::Triangles(BamgMesh* bamgmesh, BamgArgs* bamgargs):Gh(*(new Geometry())),BTh(*this){ 
 
   PreInit(0,"none");
   OnDisk = 1;
-  printf("ok1\n");
-
-  ReadFromMatlabMesh(elements,x,y,nel,nods,NBV,cutoffradian);
+
+  ReadFromMatlabMesh(bamgmesh,bamgargs);
   printf("ok2\n");
 
   SetIntCoor();
-  printf("ok3\n");
 
   FillHoleInMesh();
-  printf("ok4\n");
+  throw ErrorException(__FUNCT__,exprintf("test test")); 
 
 
@@ -998,8 +986,7 @@
 }
 
-void Geometry::ReadGeometry(BamgGeom* bamggeom){
-
-	int verbose=1;
-	assert(empty());
+void Geometry::ReadGeometry(BamgGeom* bamggeom,BamgArgs* bamgargs){
+
+	int verbose;
 	nbiv=nbv=nbvx=0;
 	nbe=nbt=nbtx=0;
@@ -1016,4 +1003,5 @@
 	nbvx = nbv;
 	nbiv = nbv;
+	verbose=bamgargs->verbose;
 
 	//some checks
@@ -1231,5 +1219,5 @@
 	if(bamggeom->SubDomain){
 		Int4 i0,i1,i2,i3;
-		if(verbose>3) printf("Reading SubDomain");
+		if(verbose>3) printf("Reading SubDomain\n");
 		NbSubDomains=bamggeom->NumSubDomain;
 		subdomains = new GeometricalSubDomain[NbSubDomains];
Index: /issm/trunk/src/c/objects/BamgArgs.h
===================================================================
--- /issm/trunk/src/c/objects/BamgArgs.h	(revision 2780)
+++ /issm/trunk/src/c/objects/BamgArgs.h	(revision 2781)
@@ -8,9 +8,13 @@
 struct BamgArgs{
 
-	int    iso;
-	double hmin;
-	double hmax;
-	double gradation;
-	double cutoff;
+	int     iso;
+	int     maxnbv;
+	double  hmin;
+	double  hmax;
+	double  gradation;
+	double  cutoff;
+	int     splitcorners;
+	int     verbose;
+	double* metric;
 
 };
Index: /issm/trunk/src/m/classes/public/bamg.m
===================================================================
--- /issm/trunk/src/m/classes/public/bamg.m	(revision 2780)
+++ /issm/trunk/src/m/classes/public/bamg.m	(revision 2781)
@@ -19,4 +19,5 @@
 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);
@@ -66,8 +67,12 @@
 % Bamg Options {{{1
 bamg_options.iso=getfieldvalue(options,'iso',0);
+bamg_options.maxnbv=getfieldvalue(options,'maxnbv',10^6);
 bamg_options.hmin=getfieldvalue(options,'hmin',10^-100);
 bamg_options.hmax=getfieldvalue(options,'hmax',10^100);
 bamg_options.gradation=getfieldvalue(options,'gradation',1.2);
 bamg_options.cutoff=getfieldvalue(options,'cutoff',10^-5);
+bamg_options.verbose=getfieldvalue(options,'verbose',1);
+bamg_options.splitcorners=getfieldvalue(options,'splitcorners',1);
+bamg_options.metric=getfieldvalue(options,'metric',zeros(0,3));
 %}}}
 
Index: /issm/trunk/src/mex/Bamg/Bamg.cpp
===================================================================
--- /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2780)
+++ /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2781)
@@ -26,12 +26,14 @@
 	double* Edges=NULL;
 	double* hVertices=NULL;
+	double  MaximalAngleOfCorner;
 	int     NumSubDomain;
 	double* SubDomain=NULL;
 
 	/*Options inputs*/
-	int    iso;
+	int    iso,maxnbv,verbose,splitcorners;
 	double hmin,hmax;
 	double gradation;
 	double cutoff;
+	double* metric;
 
 	/*Boot module: */
@@ -55,5 +57,6 @@
 	bamggeom.MetricVertices=NULL;
 	bamggeom.h1h2VpVertices=NULL;
-	bamggeom.MaximalAngleOfCorner=10;
+	FetchData(&MaximalAngleOfCorner,mxGetField(BAMGGEOMETRY,0,"MaximalAngleOfCorner"));
+	bamggeom.MaximalAngleOfCorner=MaximalAngleOfCorner;
 	bamggeom.NumTangentAtEdges=0;
 	bamggeom.TangentAtEdges=NULL;
@@ -84,4 +87,6 @@
 	FetchData(&iso,mxGetField(BAMGOPTIONS,0,"iso"));
 	bamgargs.iso=iso;
+	FetchData(&maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
+	bamgargs.maxnbv=maxnbv;
 	FetchData(&hmin,mxGetField(BAMGOPTIONS,0,"hmin"));
 	bamgargs.hmin=hmin;
@@ -92,4 +97,10 @@
 	FetchData(&cutoff,mxGetField(BAMGOPTIONS,0,"cutoff"));
 	bamgargs.cutoff=cutoff;
+	FetchData(&verbose,mxGetField(BAMGOPTIONS,0,"verbose"));
+	bamgargs.verbose=verbose;
+	FetchData(&splitcorners,mxGetField(BAMGOPTIONS,0,"splitcorners"));
+	bamgargs.splitcorners=splitcorners;
+	FetchData(&metric,NULL,NULL,mxGetField(BAMGOPTIONS,0,"metric"));
+	bamgargs.metric=metric;
 
 	/*!Generate internal degree of freedom numbers: */
