Index: /issm/trunk/src/mex/Bamg/Bamg.cpp
===================================================================
--- /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2739)
+++ /issm/trunk/src/mex/Bamg/Bamg.cpp	(revision 2739)
@@ -0,0 +1,71 @@
+/*\file Bamg.c
+ *\brief: bamg module.
+ */
+
+#include "./Bamg.h"
+
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*diverse: */
+	int   noerr=1;
+
+	/*inputs: */
+	double* elements=NULL;
+	int     dummy;
+	double* x=NULL;
+	double* y=NULL;
+	double* metric=NULL;
+	int     nods,nel;
+	double  gradation;
+	int     splitpbedge;
+	int     nbv;
+
+	/*output: */
+	double* elementsout=NULL;
+	double* xout=NULL;
+	double* yout=NULL;
+	int     nodsout,nelout;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&BamgUsage);
+
+	/*Input datasets: */
+	FetchData(&elements,&nel,&dummy,ELEMENTS);
+	FetchData(&x,&nods,X);
+	FetchData(&y,&nods,Y);
+	FetchData(&metric,&nods,METRIC);
+	FetchData(&gradation,GRADATION);
+	FetchData(&splitpbedge,SPLITPBEDGE);
+	FetchData(&nbv,NBV);
+	
+	/*!Generate internal degree of freedom numbers: */
+	Bamgx(&elementsout,&xout,&yout,&nelout,&nodsout,elements,x,y,nel,nods,metric,gradation,splitpbedge,nbv);
+
+	/*write output datasets: */
+	WriteData(ELEMENTSOUT,elementsout,nelout,3);
+	WriteData(XOUT,xout,nodsout);
+	WriteData(YOUT,yout,nodsout);
+
+	/*Free ressources: */
+	xfree((void**)&elements);
+	xfree((void**)&x);
+	xfree((void**)&y);
+	xfree((void**)&metric);
+	xfree((void**)&elementsout);
+	xfree((void**)&xout);
+	xfree((void**)&yout);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void BamgUsage(void)
+{
+	_printf_("\n");
+	_printf_("   usage: [elements,x,y]=%s(elements,x,y,metric,gradation,splitpbedge,nbv);\n",__FUNCT__);
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/Bamg/Bamg.h
===================================================================
--- /issm/trunk/src/mex/Bamg/Bamg.h	(revision 2739)
+++ /issm/trunk/src/mex/Bamg/Bamg.h	(revision 2739)
@@ -0,0 +1,40 @@
+
+/*
+	Bamg.h
+*/
+
+
+#ifndef _BAMG_H
+#define _BAMG_H
+
+/* local prototypes: */
+void BamgUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "Bamg"
+
+    
+/* serial input macros: */
+#define ELEMENTS (mxArray*)prhs[0]
+#define X (mxArray*)prhs[1]
+#define Y (mxArray*)prhs[2]
+#define METRIC (mxArray*)prhs[3]
+#define GRADATION (mxArray*)prhs[4]
+#define SPLITPBEDGE (mxArray*)prhs[5]
+#define NBV (mxArray*)prhs[6]
+
+/* serial output macros: */
+#define ELEMENTSOUT (mxArray**)&plhs[0]
+#define XOUT (mxArray**)&plhs[1]
+#define YOUT (mxArray**)&plhs[2]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  3
+#undef NRHS
+#define NRHS  7
+
+#endif  /* _BAMG_H */
+
Index: /issm/trunk/src/mex/Makefile.am
===================================================================
--- /issm/trunk/src/mex/Makefile.am	(revision 2738)
+++ /issm/trunk/src/mex/Makefile.am	(revision 2739)
@@ -6,4 +6,5 @@
 else
 bin_PROGRAMS =  BuildNodeSets\
+				Bamg\
 				ComputePressure\
 				ConfigureObjects \
@@ -47,4 +48,5 @@
 				FieldExtrude\
 				TriMesh\
+				TriMeshNoDensity\
 				TriMeshProcessRifts\
 				TriMeshRefine\
@@ -80,4 +82,8 @@
 			  BuildNodeSets/BuildNodeSets.h
 
+Bamg_SOURCES = Bamg/Bamg.cpp\
+			   Bamg/Bamg.h
+
+
 ComputePressure_SOURCES = ComputePressure/ComputePressure.cpp\
 			  ComputePressure/ComputePressure.h
@@ -204,4 +210,7 @@
 			  TriMesh/TriMesh.h
 
+TriMeshNoDensity_SOURCES = TriMeshNoDensity/TriMeshNoDensity.cpp\
+			  TriMeshNoDensity/TriMeshNoDensity.h
+
 TriMeshProcessRifts_SOURCES = TriMeshProcessRifts/TriMeshProcessRifts.cpp\
 			  TriMeshProcessRifts/TriMeshProcessRifts.h
Index: /issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.cpp
===================================================================
--- /issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.cpp	(revision 2739)
+++ /issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.cpp	(revision 2739)
@@ -0,0 +1,345 @@
+/*
+ * TriMeshNoDensity: out of a domain outline file ( Argus format ), 
+ * use the Triangle package to create a triangular mesh 
+ *
+ */
+
+#include "./TriMeshNoDensity.h"
+
+
+void mexFunction(	int nlhs, mxArray* plhs[],
+					int nrhs, const mxArray* prhs[] )
+{
+
+
+	/*Matlab arrays: */
+	mxArray* pmxa_array=NULL;
+	int i,j;
+	int counter,counter2,backcounter;
+	int prhs_counter;
+	
+	/* returned quantities: */
+
+	double* index=NULL;
+	double* x=NULL;
+	double* y=NULL;
+	double* segments=NULL;
+	double*    segmentmarkerlist=NULL;
+
+	/* input: */
+	char*  domainname=NULL;
+	char*  riftname=NULL;
+	
+	/*Domain outline variables: */
+	int      nprof;
+	int*     profngrids=NULL;
+	double** pprofx=NULL;
+	double** pprofy=NULL;
+	double*  xprof=NULL;
+	double*  yprof=NULL;
+	int      numberofpoints;
+
+	/*Rift outline variables: */
+	int      numrifts;
+	int*     riftsnumgrids=NULL;
+	double** riftsgridsx=NULL;
+	double** riftsgridsy=NULL;
+
+	/* error handling: */
+	int		noerr=1;	
+  
+	/* Triangle structures: */
+	struct triangulateio in,out;
+	char   options[256];
+
+	/* verify correct usage: */
+	if (nlhs==0 && nrhs==0) {
+		/* special case: */
+		TriMeshNoDensityUsage();
+		return;
+	}
+
+	if (!(  (nlhs==5) ||(nrhs==2) || (nrhs==3)  )){
+		mexPrintf("   %s format error.\n", __FUNCT__);
+		TriMeshNoDensityUsage();
+		printf("   ");
+		mexErrMsgTxt(" ");
+	}
+
+	/*Fetch data needed by Triangle: */
+
+	prhs_counter=0;
+	/*First recover the domain outline file name: */
+	if (!mxIsChar(prhs[prhs_counter])){
+		mexPrintf("%s%s\n",__FUNCT__," error message; first argument should be the domain outline file name!");
+		mexErrMsgTxt(" ");
+	}
+	domainname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char));
+	mxGetString(prhs[prhs_counter],domainname,mxGetN(prhs[prhs_counter])+1);
+
+	/*Look for optional rifts file name: */
+	if (nrhs==2){
+		prhs_counter++;
+		if (mxIsChar(prhs[prhs_counter])){
+			riftname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char));
+			mxGetString(prhs[prhs_counter],riftname,mxGetN(prhs[prhs_counter])+1);
+			prhs_counter++;
+		}
+	}
+
+	#ifdef _ISSM_DEBUG_
+	printf("Domain name: %s\n",domainname);
+	printf("Rift name: %s\n",riftname);
+	#endif
+	
+	
+	/*Start reading the domain outline file: */
+	noerr=DomainOutlineRead(&nprof,&profngrids,&pprofx,&pprofy,domainname);
+	if(!noerr){
+		printf("%s%s%s\n",__FUNCT__," error message reading domain outline ",domainname);
+		mexErrMsgTxt(" ");
+	}
+
+	/*Read rifts file if present: */
+	if(riftname){
+		noerr=DomainOutlineRead(&numrifts,&riftsnumgrids,&riftsgridsx,&riftsgridsy,riftname);
+		if(!noerr){
+			printf("%s%s%s\n",__FUNCT__," error message reading rifts outline ",riftname);
+			mexErrMsgTxt(" ");
+		}
+	}
+
+	#ifdef _ISSM_DEBUG_
+	printf("# points in domain outline: %i\n",nprof); 
+	#endif
+	#ifdef _DEBUG2_
+	for (i=0;i<nprof;i++){
+		printf("Profile #%i\n",i);
+		x=pprofx[i];
+		y=pprofy[i];
+		for (j=0;j<profngrids[i];j++){
+			printf("   %lf %lf\n",x[j],y[j]);
+		}
+	}
+	#endif
+
+
+	#ifdef _ISSM_DEBUG_
+	printf("# points in rift outline: %i\n",numrifts); 
+	#endif
+	#ifdef _DEBUG2_
+	for (i=0;i<numrifts;i++){
+		printf("Profile #%i\n",i);
+		x=riftsgridsx[i];
+		y=riftsgridsy[i];
+		for (j=0;j<riftsnumgrids[i];j++){
+			printf("   %lf %lf\n",x[j],y[j]);
+		}
+	}
+	#endif
+
+	/*Create initial triangulation to call triangulate():*/
+	numberofpoints=0;
+	for (i=0;i<nprof;i++){
+		numberofpoints+=profngrids[i];
+	}
+	if (riftname){
+		for (i=0;i<numrifts;i++){
+			numberofpoints+=riftsnumgrids[i];
+		}
+	}
+	in.numberofpoints=numberofpoints;
+
+	in.numberofpointattributes=1;
+	in.pointlist = (REAL *) mxMalloc(in.numberofpoints * 2 * sizeof(REAL));
+
+	counter=0;
+	for (i=0;i<nprof;i++){
+		xprof=pprofx[i];
+		yprof=pprofy[i];
+		for (j=0;j<profngrids[i];j++){
+			in.pointlist[2*counter+0]=xprof[j];
+			in.pointlist[2*counter+1]=yprof[j];
+			counter++;
+		}
+	}
+	if(riftname){
+		for (i=0;i<numrifts;i++){
+			xprof=riftsgridsx[i];
+			yprof=riftsgridsy[i];
+			for (j=0;j<riftsnumgrids[i];j++){
+				in.pointlist[2*counter+0]=xprof[j];
+				in.pointlist[2*counter+1]=yprof[j];
+				counter++;
+			}
+		}
+	}
+	
+	in.pointattributelist = (REAL *) mxMalloc(in.numberofpoints *
+										  in.numberofpointattributes *
+										  sizeof(REAL));
+	for (i=0;i<in.numberofpoints;i++){
+		in.pointattributelist[i] = 0.0;
+	}
+	in.pointmarkerlist = (int *) mxMalloc(in.numberofpoints * sizeof(int));
+	for(i=0;i<in.numberofpoints;i++){
+		in.pointmarkerlist[i] = 0;
+	}
+	
+
+	/*Build segments: */
+	/*Figure out number of segments: holes and closed outlines have as many segments as grids, 
+	 *for rifts, we have one less segment as we have grids*/
+	in.numberofsegments=0;
+	for (i=0;i<nprof;i++){
+		in.numberofsegments+=profngrids[i];
+	}
+	if (riftname){
+		for (i=0;i<numrifts;i++){
+			in.numberofsegments+=riftsnumgrids[i]-1;
+		}
+	}
+	
+	in.segmentlist = (int *) mxMalloc(in.numberofsegments * 2 * sizeof(int));
+	in.segmentmarkerlist = (int *) mxCalloc(in.numberofsegments,sizeof(int));
+	counter=0;
+	backcounter=0;
+	for (i=0;i<nprof;i++){
+		for (j=0;j<(profngrids[i]-1);j++){
+			in.segmentlist[2*counter+0]=counter;
+			in.segmentlist[2*counter+1]=counter+1;
+			in.segmentmarkerlist[counter]=0;
+			counter++;
+		}
+		/*Close this profile: */
+		 in.segmentlist[2*counter+0]=counter;
+		 in.segmentlist[2*counter+1]=backcounter;
+		 in.segmentmarkerlist[counter]=0;
+		 counter++;
+		 backcounter=counter;
+	}
+	counter2=counter;
+	if(riftname){
+		for (i=0;i<numrifts;i++){
+			for (j=0;j<(riftsnumgrids[i]-1);j++){
+				in.segmentlist[2*counter2+0]=counter;
+				in.segmentlist[2*counter2+1]=counter+1;
+				in.segmentmarkerlist[counter2]=2+i;
+				counter2++;
+				counter++;
+			}
+			counter++;
+		}
+	}
+
+	
+	/*Build regions: */
+	in.numberofregions = 0;
+
+	/*Build holes: */
+	in.numberofholes = nprof-1; /*everything is a hole, but for the first profile.*/
+	in.holelist = (REAL *) mxMalloc(in.numberofholes * 2 * sizeof(REAL));
+	for (i=0;i<nprof-1;i++){
+		/*We are looking for a grid that lies inside the hole: */
+		GridInsideHole(&in.holelist[2*i+0],&in.holelist[2*i+1],profngrids[i+1],pprofx[i+1],pprofy[i+1]);
+	}
+
+	/* Make necessary initializations so that Triangle can return a */
+	/*   triangulation in `out': */
+
+	out.pointlist = (REAL *) NULL;            
+	out.pointattributelist = (REAL *) NULL;
+	out.pointmarkerlist = (int *) NULL; 
+	out.trianglelist = (int *) NULL;          
+	out.triangleattributelist = (REAL *) NULL;
+	out.neighborlist = (int *) NULL;         
+	out.segmentlist = (int *) NULL;
+	out.segmentmarkerlist = (int *) NULL;
+	out.edgelist = (int *) NULL;             
+	out.edgemarkerlist = (int *) NULL;   
+
+	/* Triangulate the points:.  Switches are chosen to read and write a  */
+	/*   PSLG (p), preserve the convex hull (c), number everything from  */
+	/*   zero (z), assign a regional attribute to each element (A), and  */
+	/*   produce an edge list (e), a Voronoi diagram (v), and a triangle */
+	/*   neighbor list (n).                                              */
+
+	sprintf(options,"%s%lf","pQzDq30i"); /*replace V by Q to quiet down the logging*/
+  
+	triangulate(options, &in, &out, NULL);
+	/*report(&out, 0, 1, 1, 1, 1, 0);*/
+
+	/*Allocate index, x and y: */
+	index=(double*)mxMalloc(3*out.numberoftriangles*sizeof(double));
+	x=(double*)mxMalloc(out.numberofpoints*sizeof(double));
+	y=(double*)mxMalloc(out.numberofpoints*sizeof(double));
+	segments=(double*)mxMalloc(3*out.numberofsegments*sizeof(double));
+	segmentmarkerlist=(double*)mxMalloc(out.numberofsegments*sizeof(double));
+
+	for (i = 0; i < out.numberoftriangles; i++) {
+		for (j = 0; j < out.numberofcorners; j++) {
+			*(index+3*i+j)=(double)out.trianglelist[i * out.numberofcorners + j]+1;
+		}
+	}
+	for (i = 0; i < out.numberofpoints; i++) {
+		x[i]=out.pointlist[i * 2 + 0];
+		y[i]=out.pointlist[i * 2 + 1];
+	}
+	
+	for (i = 0; i < out.numberofsegments; i++) {
+		segments[3*i+0]=(double)out.segmentlist[i*2+0]+1;
+		segments[3*i+1]=(double)out.segmentlist[i*2+1]+1;
+		segmentmarkerlist[i]=(double)out.segmentmarkerlist[i];
+	}
+
+	/*Associate elements with segments: */
+	noerr=AssociateSegmentToElement(&segments,out.numberofsegments,index,out.numberoftriangles);
+
+	/*Order segments so that their normals point outside the domain: */
+	OrderSegments(&segments,out.numberofsegments, index,out.numberoftriangles);
+
+	/*Output : */
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,out.numberoftriangles);
+	mxSetPr(pmxa_array,index);
+	mexCallMATLAB( 1, &plhs[0], 1, &pmxa_array, "'");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofpoints);
+	mxSetPr(pmxa_array,x);
+	mexCallMATLAB( 1, &plhs[1], 1, &pmxa_array, "'");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofpoints);
+	mxSetPr(pmxa_array,y);
+	mexCallMATLAB( 1, &plhs[2], 1, &pmxa_array, "'");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,3);
+	mxSetN(pmxa_array,out.numberofsegments);
+	mxSetPr(pmxa_array,segments);
+	mexCallMATLAB( 1, &plhs[3], 1, &pmxa_array, "'");
+
+	pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL);
+	mxSetM(pmxa_array,1);
+	mxSetN(pmxa_array,out.numberofsegments);
+	mxSetPr(pmxa_array,segmentmarkerlist);
+	mexCallMATLAB( 1, &plhs[4], 1, &pmxa_array, "'");
+	
+	return;
+}
+
+void TriMeshNoDensityUsage(void)
+{
+	printf("\n");
+	printf("   usage: [index,x,y,segments,segmentmarkers]=TriMeshNoDensity(domainoutlinefilename,riftsoutlinename) \n");
+	printf("      where: index,x,y defines a triangulation, segments is an array made \n");
+	printf("      of exterior segments to the mesh domain outline, segmentmarkers is an array flagging each segment \n");
+	printf("      (if rifts are present, markers >=2 flag them ), outlinefilename an Argus domain outline file.\n");
+	printf("      riftsoutlinename is an Argus domain file, defining rifts (ie: open profiles), \n");
+	printf("      riftsoutlinename is an optional arguments.\n");
+	printf("\n");
+}
Index: /issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.h
===================================================================
--- /issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.h	(revision 2739)
+++ /issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.h	(revision 2739)
@@ -0,0 +1,19 @@
+/*!\file:  TriMeshNoDensity.h
+ * \brief header prototype
+ */ 
+
+#ifndef _TRIMESH_H_
+#define _TRIMESH_H_
+
+#include "mex.h"
+#include "triangle.h"
+#include "string.h"
+
+#include "../../c/issm.h"
+
+void TriMeshNoDensityUsage(void);
+
+#undef __FUNCT__ 
+#define __FUNCT__ "TriMeshNoDensity"
+
+#endif
