Index: /issm/trunk/src/c/Bamgx/MeshRead.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/MeshRead.cpp	(revision 2777)
+++ /issm/trunk/src/c/Bamgx/MeshRead.cpp	(revision 2778)
@@ -1239,6 +1239,6 @@
 			i2=(int)bamggeom->SubDomain[i*4+2];
 			i3=(int)bamggeom->SubDomain[i*4+3];
-			if (i0!=2) throw ErrorException(__FUNCT__,exprintf("Bad Subdomain definition: first number should be 2"));
-			if (i1>nbe || i1<=0) throw ErrorException(__FUNCT__,exprintf("Bad Subdomain definition: second number should in [1 %i]",nbe));
+			if (i0!=2) throw ErrorException(__FUNCT__,exprintf("Bad Subdomain definition: first number should be 2 (for Edges)"));
+			if (i1>nbe || i1<=0) throw ErrorException(__FUNCT__,exprintf("Bad Subdomain definition: second number should in [1 %i] (edge number)",nbe));
 			subdomains[i].edge=edges + (i1-1);
 			subdomains[i].sens = (int) i2;
Index: /issm/trunk/src/m/classes/public/bamg.m
===================================================================
--- /issm/trunk/src/m/classes/public/bamg.m	(revision 2777)
+++ /issm/trunk/src/m/classes/public/bamg.m	(revision 2778)
@@ -5,5 +5,5 @@
 %      md=bamg(md,varargin);
 
-%process options {{{1
+%process options
 options=pairoptions(varargin{:});
 
@@ -11,19 +11,39 @@
 bamg_options=struct();
 bamg_geometry=struct();
+bamg_mesh=struct();
 
-%fill out the geometry
-bamg_geometry.Vertices=getfieldvalue(options,'Vertices',NaN);
-bamg_geometry.NumVertices=size(bamg_geometry.Vertices,1);
-bamg_geometry.Edges=getfieldvalue(options,'Edges',NaN);
-bamg_geometry.NumEdges=size(bamg_geometry.Edges,1);
-bamg_geometry.hVertices=getfieldvalue(options,'hVertices',NaN);
+%get domainoutline
+domainfile=getfieldvalueerr(options,'domain');
+resolution=getfieldvalue(options,'resolution',5000);
+if ~exist(domainfile,'file')
+	error(['bamg error message: file ' domainfile ' not found ']);
+else
+	domain=expread(domainfile);
 
-bamg_options.fgeom=getfieldvalueerr(options,'fgeom');
-%}}}
+	%build geometry
+	count=0;
+	bamg_geometry.Vertices=zeros(0,3);
+	bamg_geometry.Edges=zeros(0,3);
+	bamg_geometry.hVertices=zeros(0,1);
+	bamg_geometry.SubDomain=zeros(0,3);
+	for i=1:length(domain),
+		nods=domain(i).nods-1; %the domain are closed 1=end;
+		bamg_geometry.Vertices=[bamg_geometry.Vertices; [domain(i).x(1:nods) domain(i).y(1:nods) ones(nods,1)]];
+		bamg_geometry.Edges=[bamg_geometry.Edges; [transp(count+1:count+nods) transp([count+2:count+nods count+1])  ones(nods,1)]];
+		bamg_geometry.hVertices=[bamg_geometry.hVertices; resolution*ones(nods,1)];
+		if i>1,
+			bamg_geometry.SubDomain=[2 count+1 1 1];
+		end
+		count=count+nods;
+	end
+	bamg_geometry.NumVertices=size(bamg_geometry.Vertices,1);
+	bamg_geometry.NumEdges=size(bamg_geometry.Edges,1);
+	bamg_geometry.NumSubDomain=size(bamg_geometry.SubDomain,1);
+end
 
 %call Bamg
 [elements,x,y]=Bamg(bamg_geometry,bamg_options);
 
-% plug results onto model {{{1
+% plug results onto model
 md.x=x;
 md.y=y;
@@ -35,3 +55,2 @@
 md.z=zeros(md.numberofgrids,1);
 md.type='2d';
-%}}}
Index: /issm/trunk/src/mex/Bamg/Bamg.cpp
===================================================================
--- /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2777)
+++ /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2778)
@@ -20,4 +20,6 @@
 	double* Edges=NULL;
 	double* hVertices=NULL;
+	int     NumSubDomain;
+	double* SubDomain=NULL;
 
 
@@ -29,5 +31,5 @@
 
 	/*process inputs*/
-	FetchData(&geomfile,mxGetField(BAMGOPTIONS,0,"fgeom"));
+	//FetchData(&geomfile,mxGetField(BAMGOPTIONS,0,"fgeom"));
 
 	FetchData(&NumVertices,mxGetField(BAMGGEOMETRY,0,"NumVertices"));
@@ -36,4 +38,6 @@
 	FetchData(&Edges,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"Edges"));
 	FetchData(&hVertices,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"hVertices"));
+	FetchData(&NumSubDomain,mxGetField(BAMGGEOMETRY,0,"NumSubDomain"));
+	FetchData(&SubDomain,NULL,NULL,mxGetField(BAMGGEOMETRY,0,"SubDomain"));
 
 	/*create bamg geometry input*/
@@ -55,9 +59,9 @@
 	bamggeom.NumRequiredEdges=0;
 	bamggeom.RequiredEdges=NULL;
-	bamggeom.NumSubDomain=0;
-	bamggeom.SubDomain=NULL;
+	bamggeom.NumSubDomain=NumSubDomain;
+	bamggeom.SubDomain=SubDomain;
 
 	/*create bamg mesh input*/
-	bamgargs.geomfile=geomfile;
+	//bamgargs.geomfile=geomfile;
 
 	/*create bamg mesh input*/
@@ -72,8 +76,9 @@
 
 	/*Free ressources: */
-	xfree((void**)&geomfile);
+	//xfree((void**)&geomfile);
 	xfree((void**)&Vertices);
 	xfree((void**)&Edges);
 	xfree((void**)&hVertices);
+	xfree((void**)&SubDomain);
 
 	/*end module: */
