Index: issm/trunk/src/c/Bamgx/Bamgx.cpp
===================================================================
--- issm/trunk/src/c/Bamgx/Bamgx.cpp	(revision 2912)
+++ issm/trunk/src/c/Bamgx/Bamgx.cpp	(revision 2913)
@@ -25,5 +25,4 @@
 int Bamgx(BamgMesh* bamgmesh,BamgGeom* bamggeom,BamgOpts* bamgopts){
 	
-	int noerr=1;
 
 	/*output: */
@@ -37,21 +36,21 @@
 	int    maxnbv;
 	double hmin,hmax;
+	double err,errg,coef;
 	double cutoff;
 	int    verbosity;
-
-	/*Bamg variables: */
+	int    Hessiantype,NbSmooth;
+	double power;
+	double omega;
+
+	/*intermediary*/
+	int noerr=1;
 	int i,j,num;
 	int AbsError=0,nbjacoby=1,allquad=0;
 	double costheta=2;
 	double anisomax = 1e6;
-	double err=0.01,errg=0.1,coef=1;
 	int KeepBackVertices=1;
 	double hminaniso=1e-100; 
 	const double  boundmaxsubdiv = 10;
 	double  maxsubdiv=boundmaxsubdiv;
-	double omega=1.8;
-	int NbSmooth=3;
-	int ChoiseHessien = 0;
-	double power=1;
 	int Rescaling=1;
 
@@ -61,4 +60,11 @@
 	/*Bamg options*/
 	iso=bamgopts->iso;
+	err=bamgopts->err;
+	errg=bamgopts->errg;
+	Hessiantype=bamgopts->Hessiantype;
+	power=bamgopts->power;
+	NbSmooth=bamgopts->NbSmooth;
+	omega=bamgopts->omega;
+	coef=bamgopts->coef;
 	maxnbv=bamgopts->maxnbv;
 	hmin=bamgopts->hmin;
@@ -135,11 +141,15 @@
 			BTh.ReadMetric(bamgopts,hmin,hmax,coef);
 		}
-		else if (bamgopts->field){
-			if (verbosity>1) printf("   Generating Metric from solution field...\n");
-			BTh.IntersectConsMetric(bamgopts->field,1,0,hmin,hmax,sqrt(err)*coef,1e30,AbsError?0.0:cutoff,nbjacoby,Rescaling,power,ChoiseHessien);
-		}
-		else { // init with hmax 
+		else { 
+
+			// init with hmax 
 			Metric Mhmax(hmax);
 			for (Int4 iv=0;iv<BTh.nbv;iv++) BTh[iv].m = Mhmax;
+
+			//use present fields to generate metric if present
+			if (bamgopts->field){
+				if (verbosity>1) printf("   Generating Metric from solution field...\n");
+				BTh.IntersectConsMetric(bamgopts->field,1,0,hmin,hmax,sqrt(err)*coef,1e30,AbsError?0.0:cutoff,nbjacoby,Rescaling,power,Hessiantype);
+			}
 		}
 
Index: issm/trunk/src/c/Bamgx/objects/Geometry.cpp
===================================================================
--- issm/trunk/src/c/Bamgx/objects/Geometry.cpp	(revision 2912)
+++ issm/trunk/src/c/Bamgx/objects/Geometry.cpp	(revision 2913)
@@ -689,5 +689,4 @@
 				}
 			}
-			printf("ord = %i\n",ord);
 
 			// angular test on current vertex to guess whether it is a corner (ord = number of edges horlding i)
Index: issm/trunk/src/c/Bamgx/objects/Triangles.cpp
===================================================================
--- issm/trunk/src/c/Bamgx/objects/Triangles.cpp	(revision 2912)
+++ issm/trunk/src/c/Bamgx/objects/Triangles.cpp	(revision 2913)
@@ -2905,6 +2905,5 @@
 
 				 R2 Grads = (nAB * sC + nBC * sA + nCA * sB ) /detT[i] ;
-				 if(choice) 
-					{
+				 if(choice){
 					 int nbb = 0;
 					 Real8 dd = detT[i];
@@ -2981,6 +2980,5 @@
 
 					}
-				 else
-					{
+				 else {
 
 					 // if edge on boundary no contribution  => normal = 0
Index: issm/trunk/src/c/objects/BamgOpts.h
===================================================================
--- issm/trunk/src/c/objects/BamgOpts.h	(revision 2912)
+++ issm/trunk/src/c/objects/BamgOpts.h	(revision 2913)
@@ -11,4 +11,8 @@
 	int     maxnbv;
 	double  MaximalAngleOfCorner;
+	int     Hessiantype;
+	double  power;
+	int     NbSmooth;
+	double  omega;
 	double  hmin;
 	double  hmax;
@@ -17,4 +21,7 @@
 	int     splitcorners;
 	int     verbose;
+	double  err;
+	double  errg;
+	double  coef;
 	double* metric;
 	double* field;
Index: issm/trunk/src/c/objects/Param.cpp
===================================================================
--- issm/trunk/src/c/objects/Param.cpp	(revision 2912)
+++ issm/trunk/src/c/objects/Param.cpp	(revision 2913)
@@ -698,4 +698,7 @@
 		memcpy(doublevec,value,M*sizeof(double));
 	}
+	else{
+		xfree((void**)&doublevec); doublevec=NULL;
+	}
 	ndof=0; //this vector will not be repartitioned.
 
Index: issm/trunk/src/m/classes/public/bamg.m
===================================================================
--- issm/trunk/src/m/classes/public/bamg.m	(revision 2912)
+++ issm/trunk/src/m/classes/public/bamg.m	(revision 2913)
@@ -77,4 +77,11 @@
 % Bamg Options {{{1
 bamg_options.iso=getfieldvalue(options,'iso',0);
+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.power=getfieldvalue(options,'power',1);
+bamg_options.Hessiantype=getfieldvalue(options,'Hessiantype',0);
+bamg_options.NbSmooth=getfieldvalue(options,'NbSmooth',3);
+bamg_options.omega=getfieldvalue(options,'omega',1.8);
 bamg_options.maxnbv=getfieldvalue(options,'maxnbv',10^6);
 bamg_options.MaximalAngleOfCorner=getfieldvalue(options,'MaximalAngleOfCorner',10);
@@ -85,6 +92,6 @@
 bamg_options.verbose=getfieldvalue(options,'verbose',1);
 bamg_options.splitcorners=getfieldvalue(options,'splitcorners',1);
-bamg_options.metric=getfieldvalue(options,'metric',zeros(0,3));
-bamg_options.field=getfieldvalue(options,'field',zeros(0,1));
+bamg_options.metric=getfieldvalue(options,'metric',[]);
+bamg_options.field=getfieldvalue(options,'field',[]);
 %}}}
 
Index: issm/trunk/src/mex/Bamg/Bamg.cpp
===================================================================
--- issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2912)
+++ issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2913)
@@ -34,4 +34,8 @@
 	int    iso,maxnbv,verbose,splitcorners;
 	double hmin,hmax;
+	double err,errg,coef;
+	double power;
+	int    Hessiantype,NbSmooth;
+	double omega;
 	double gradation;
 	double cutoff;
@@ -104,4 +108,18 @@
 	FetchData(&iso,mxGetField(BAMGOPTIONS,0,"iso"));
 	bamgopts.iso=iso;
+	FetchData(&err,mxGetField(BAMGOPTIONS,0,"err"));
+	bamgopts.err=err;
+	FetchData(&errg,mxGetField(BAMGOPTIONS,0,"errg"));
+	bamgopts.errg=errg;
+	FetchData(&coef,mxGetField(BAMGOPTIONS,0,"coef"));
+	bamgopts.coef=coef;
+	FetchData(&Hessiantype,mxGetField(BAMGOPTIONS,0,"Hessiantype"));
+	bamgopts.Hessiantype=Hessiantype;
+	FetchData(&power,mxGetField(BAMGOPTIONS,0,"power"));
+	bamgopts.power=power;
+	FetchData(&NbSmooth,mxGetField(BAMGOPTIONS,0,"NbSmooth"));
+	bamgopts.NbSmooth=NbSmooth;
+	FetchData(&omega,mxGetField(BAMGOPTIONS,0,"omega"));
+	bamgopts.omega=omega;
 	FetchData(&maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
 	bamgopts.maxnbv=maxnbv;
