Index: /issm/trunk/src/mex/Bamg/Bamg.cpp
===================================================================
--- /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 3213)
+++ /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 3214)
@@ -48,33 +48,19 @@
 	BamgOptsInit(&bamgopts);
 	FetchData(&bamgopts.coef,mxGetField(BAMGOPTIONS,0,"coef"));
-	if (bamgopts.coef==0) throw ErrorException(__FUNCT__,exprintf("'coef' should be positive"));
 	FetchData(&bamgopts.maxsubdiv,mxGetField(BAMGOPTIONS,0,"maxsubdiv"));
-	if (bamgopts.maxsubdiv<1) throw ErrorException(__FUNCT__,exprintf("'maxsubdiv' should be >=1"));
 	FetchData(&bamgopts.Hessiantype,mxGetField(BAMGOPTIONS,0,"Hessiantype"));
-	if (bamgopts.Hessiantype!=0 && bamgopts.Hessiantype!=1) throw ErrorException(__FUNCT__,exprintf("'Hessiantype' supported options are 0 and 1"));
 	FetchData(&bamgopts.Metrictype,mxGetField(BAMGOPTIONS,0,"Metrictype"));
-	if (bamgopts.Metrictype!=0 && bamgopts.Metrictype!=1 && bamgopts.Metrictype!=2) throw ErrorException(__FUNCT__,exprintf("'Metrictype' supported options are 0, 1 and 2"));
 	FetchData(&bamgopts.KeepVertices,mxGetField(BAMGOPTIONS,0,"KeepVertices"));
-	if (bamgopts.KeepVertices!=0 && bamgopts.KeepVertices!=1) throw ErrorException(__FUNCT__,exprintf("'KeepVertices' supported options are 0 and 1"));
 	FetchData(&bamgopts.renumber,mxGetField(BAMGOPTIONS,0,"renumber"));
-	if (bamgopts.renumber!=0 && bamgopts.renumber!=1 && bamgopts.renumber!=2) throw ErrorException(__FUNCT__,exprintf("'renumber' supported options are 0, 1 and 2"));
 	FetchData(&bamgopts.power,mxGetField(BAMGOPTIONS,0,"power"));
 	FetchData(&bamgopts.errg,mxGetField(BAMGOPTIONS,0,"errg"));
-	if (bamgopts.errg<0) throw ErrorException(__FUNCT__,exprintf("'errg' option should be >0"));
 	FetchData(&bamgopts.nbjacobi,mxGetField(BAMGOPTIONS,0,"nbjacobi"));
-	if (bamgopts.nbjacobi<=0) throw ErrorException(__FUNCT__,exprintf("'nbjacobi' option should be >0"));
 	FetchData(&bamgopts.NbSmooth,mxGetField(BAMGOPTIONS,0,"NbSmooth"));
-	if (bamgopts.NbSmooth<=0) throw ErrorException(__FUNCT__,exprintf("'NbSmooth' option should be >0"));
 	FetchData(&bamgopts.omega,mxGetField(BAMGOPTIONS,0,"omega"));
 	FetchData(&bamgopts.maxnbv,mxGetField(BAMGOPTIONS,0,"maxnbv"));
-	if (bamgopts.maxnbv<3) throw ErrorException(__FUNCT__,exprintf("'maxnbv' option should be >3"));
 	FetchData(&bamgopts.hmin,mxGetField(BAMGOPTIONS,0,"hmin"));
-	if (bamgopts.hmin<=0) throw ErrorException(__FUNCT__,exprintf("'hmin' option should be >0"));
 	FetchData(&bamgopts.hmax,mxGetField(BAMGOPTIONS,0,"hmax"));
-	if (bamgopts.hmax<=0 || bamgopts.hmax<bamgopts.hmin) throw ErrorException(__FUNCT__,exprintf("'hmax' option should be between 0 and hmin=%g",bamgopts.hmin));
 	FetchData(&bamgopts.anisomax,mxGetField(BAMGOPTIONS,0,"anisomax"));
-	if (bamgopts.anisomax<1) throw ErrorException(__FUNCT__,exprintf("'anisomax' option should be >=1"));
 	FetchData(&bamgopts.gradation,mxGetField(BAMGOPTIONS,0,"gradation"));
-	if (bamgopts.gradation<1) throw ErrorException(__FUNCT__,exprintf("'gradation' option should be >=1"));
 	FetchData(&bamgopts.cutoff,mxGetField(BAMGOPTIONS,0,"cutoff"));
 	FetchData(&bamgopts.verbose,mxGetField(BAMGOPTIONS,0,"verbose"));
@@ -87,5 +73,5 @@
 	FetchData(&bamgopts.err,NULL,&cols,mxGetField(BAMGOPTIONS,0,"err"));
 	if (bamgopts.numfields!=0 && cols!=bamgopts.numfields){throw ErrorException(__FUNCT__,exprintf("the size of 'err' should be the same as 'field'"));}
-	for (i=0;i<bamgopts.numfields;i++) {if (bamgopts.err[i]<=0) throw ErrorException(__FUNCT__,exprintf("'err' option should be >0"));};
+	BamgOptsCheck(&bamgopts);
 
 	/*!Generate internal degree of freedom numbers: */
