Index: /issm/trunk/src/m/classes/public/bamg.m
===================================================================
--- /issm/trunk/src/m/classes/public/bamg.m	(revision 3657)
+++ /issm/trunk/src/m/classes/public/bamg.m	(revision 3658)
@@ -39,4 +39,7 @@
 %   - rifts : followed by an ARGUS file that prescribes the rifts
 %   - toltip: tolerance to move tip on an existing point of the domain outline
+%   - tracks: followed by an ARGUS file that prescribes the tracks that the mesh will stick to
+%   - tol:    if the distance between 2 points of the domain outline is less than tol, they
+%             will be merged
 %
 %   Examples:
@@ -200,4 +203,26 @@
 	end
 
+	%Deal with tracks
+	if exist(options,'tracks'),
+
+		%Check that file exists
+		trackfile=getfieldvalueerr(options,'tracks');
+		if ~exist(trackfile,'file')
+			error(['bamg error message: file ' trackfile ' not found ']);
+		end
+		track=expread(trackfile);
+
+		for i=1:length(track),
+
+			%Add all points to bamg_geometry
+			nods=track(i).nods;
+			bamg_geometry.Vertices=[bamg_geometry.Vertices; [track(i).x(1:nods) track(i).y(1:nods) 3*ones(nods,1)]];
+			bamg_geometry.Edges=[bamg_geometry.Edges; [transpose(count+1:count+nods-1) transpose([count+2:count+nods])  3*ones(nods-1,1)]];
+
+			%update counter
+			count=count+nods;
+		end
+	end
+
 	if exist(options,'hVertices'),
 		bamg_geometry.hVertices=getfieldvalueerr(options,'hVertices');
@@ -206,4 +231,7 @@
 		end
 	end
+
+	%process geom
+	bamg_geometry=processgeometry(bamg_geometry,getfieldvalue(options,'tol',NaN),domain(1));
 
 elseif isstruct(md.bamg),
Index: /issm/trunk/src/m/classes/public/processgeometry.m
===================================================================
--- /issm/trunk/src/m/classes/public/processgeometry.m	(revision 3658)
+++ /issm/trunk/src/m/classes/public/processgeometry.m	(revision 3658)
@@ -0,0 +1,137 @@
+function geom=processgeometry(geom,tol,outline);
+
+%Deal with edges
+disp('Checking Edge crossing...');
+i=0;
+while (i<size(geom.Edges,1)),
+
+	%edge counter
+	i=i+1;
+
+	%Get coordinates
+	x1=geom.Vertices(geom.Edges(i,1),1);
+	y1=geom.Vertices(geom.Edges(i,1),2);
+	x2=geom.Vertices(geom.Edges(i,2),1);
+	y2=geom.Vertices(geom.Edges(i,2),2);
+
+	j=i+1; %test edges located AFTER i only
+	while (j<size(geom.Edges,1)),
+
+		%edge counter
+		j=j+1;
+
+		%Skip if the two edges already have a vertex in common
+		if any(ismember(geom.Edges(i,1:2),geom.Edges(j,1:2))),
+			continue
+		end
+
+		%Get coordinates
+		x3=geom.Vertices(geom.Edges(j,1),1);
+		y3=geom.Vertices(geom.Edges(j,1),2);
+		x4=geom.Vertices(geom.Edges(j,2),1);
+		y4=geom.Vertices(geom.Edges(j,2),2);
+
+		%Check if the two edges are crossing one another
+		if SegIntersect([x1 y1; x2 y2],[x3 y3; x4 y4]),
+
+			%Get coordinate of intersection point (http://mathworld.wolfram.com/Line-LineIntersection.html)
+			x=det([det([x1 y1; x2 y2])  x1-x2;det([x3 y3; x4 y4])  x3-x4])/det([x1-x2 y1-y2;x3-x4 y3-y4]);
+			y=det([det([x1 y1; x2 y2])  y1-y2;det([x3 y3; x4 y4])  y3-y4])/det([x1-x2 y1-y2;x3-x4 y3-y4]);
+
+			%Add vertex to the list of vertices
+			geom.Vertices(end+1,:)=[x y 1];
+			id=size(geom.Vertices,1);
+
+			%Update edges i and j
+			edgei=geom.Edges(i,:);
+			edgej=geom.Edges(j,:);
+			geom.Edges(i,:)    =[edgei(1) id       edgei(3)];
+			geom.Edges(end+1,:)=[id       edgei(2) edgei(3)];
+			geom.Edges(j,:)    =[edgej(1) id       edgej(3)];
+			geom.Edges(end+1,:)=[id       edgej(2) edgej(3)];
+
+			%update current edge second tip
+			x2=x; y2=y;
+		end
+	end
+
+end
+
+%Check point spacing
+if ~isnan(tol),
+	disp('Checking point spacing...');
+	i=0;
+	while (i<size(geom.Vertices,1)),
+
+		%vertex counter
+		i=i+1;
+
+		%Get coordinates
+		x1=geom.Vertices(i,1);
+		y1=geom.Vertices(i,2);
+
+		j=i; %test edges located AFTER i only
+		while (j<size(geom.Vertices,1)),
+
+			%vertex counter
+			j=j+1;
+
+			%Get coordinates
+			x2=geom.Vertices(j,1);
+			y2=geom.Vertices(j,2);
+
+			%Check whether the two vertices are too close
+			if ((x2-x1)^2+(y2-y1)^2<tol^2)
+
+				%Remove points from list of Vertices
+				geom.Vertices(j,:)=[];
+
+				%update edges
+				posedges=find(ismember(geom.Edges,j));
+				geom.Edges(posedges)=i;
+				posedges=find(geom.Edges>j);
+				geom.Edges(posedges)=geom.Edges(posedges)-1;
+
+				%update counter
+				j=j-1;
+
+			end
+		end
+	end
+end
+%remove empty edges
+geom.Edges(find(geom.Edges(:,1)==geom.Edges(:,2)),:)=[];
+
+%Check point outside
+disp('Checking for points outside the domain...');
+i=0;
+num=0;
+while (i<size(geom.Vertices,1)),
+
+	%vertex counter
+	i=i+1;
+
+	%Get coordinates
+	x=geom.Vertices(i,1);
+	y=geom.Vertices(i,2);
+
+	%Check that the point is inside the domain
+	if (~ContourToNodes(x,y,outline(1),1)),
+
+		%Remove points from list of Vertices
+		num=num+1;
+		geom.Vertices(i,:)=[];
+
+		%update edges
+		[posedges dummy]=find(geom.Edges==i);
+		geom.Edges(posedges,:)=[];
+		posedges=find(geom.Edges>i);
+		geom.Edges(posedges)=geom.Edges(posedges)-1;
+
+		%update counter
+		i=i-1;
+	end
+end
+if num,
+	disp(['WARNING: ' num2str(num) 'points outside the domain outline have been removed']);
+end
Index: /issm/trunk/src/m/classes/public/queue/QueueRequirements.m
===================================================================
--- /issm/trunk/src/m/classes/public/queue/QueueRequirements.m	(revision 3657)
+++ /issm/trunk/src/m/classes/public/queue/QueueRequirements.m	(revision 3658)
@@ -14,5 +14,5 @@
 
 	available_queues={'debug','shortq','longq','specialq'};
-	queue_requirements_time=[60 180 720 1440];
+	queue_requirements_time=[60*1 60*3 60*17 1440];
 	queue_requirements_np=[32 128 256 256];
 	queue_requirements_modulo=[1 1 1 1];
