Index: /issm/trunk/src/c/shared/Exp/IsInPoly.cpp
===================================================================
--- /issm/trunk/src/c/shared/Exp/IsInPoly.cpp	(revision 8269)
+++ /issm/trunk/src/c/shared/Exp/IsInPoly.cpp	(revision 8270)
@@ -14,7 +14,5 @@
 #endif
 
-
-
-
+/*IsInPoly {{{1*/
 int IsInPoly(Vec in,double* xc,double* yc,int numgrids,double* x,double* y,int i0,int i1, int edgevalue){
 
@@ -56,29 +54,47 @@
 	}
 	 return 1;
-}
-
-int IsOutsidePoly(Vec out,double* xc,double* yc,int numgrids,double* x,double* y,int nods,int edgevalue){
+}/*}}}*/
+/*IsOutsidePoly {{{1*/
+int IsOutsidePoly(Vec in,double* xc,double* yc,int numgrids,double* x,double* y,int i0,int i1, int edgevalue){
 
 	int i,j;
 	double x0,y0;
 	double value;
+	double xmin=xc[0];
+	double xmax=xc[0];
+	double ymin=yc[0];
+	double ymax=yc[0];
+
+	/*Get extrema*/
+	for (i=1;i<numgrids;i++){
+		if(xc[i]<xmin) xmin=xc[i];
+		if(xc[i]>xmax) xmax=xc[i];
+		if(yc[i]<ymin) ymin=yc[i];
+		if(yc[i]>ymax) ymax=yc[i];
+	}
 
 	/*Go through all grids of the mesh:*/
-	for (i=MPI_Lowerrow(nods);i<MPI_Upperrow(nods);i++){
-		/*pick up grid: */
-		x0=x[i];
-		y0=y[i];
-		if (pnpoly(numgrids,xc,yc,x0,y0,edgevalue)){
-			value=0;
+	for (i=i0;i<i1;i++){
+
+		//Get current value of value[i] -> do not change it if != 0
+		VecGetValues(in,1,&i,&value);
+		if (value){
+			/*this grid already is inside one of the contours, continue*/
+			continue;
+		}
+
+		/*pick up grid (x[i],y[i]) and figure out if located inside contour (xc,yc)*/
+		x0=x[i]; y0=y[i];
+		if(x0<xmin || x0>xmax || y0<ymin || y0>ymax){
+			value=1;
 		}
 		else{
-			value=1;
+			value=1-pnpoly(numgrids,xc,yc,x0,y0,edgevalue);
 		}
-		VecSetValues(out,1,&i,&value,INSERT_VALUES);
+		VecSetValues(in,1,&i,&value,INSERT_VALUES);
 	}
-
 	return 1;
-}
-
+}/*}}}*/
+/*pnpoly{{{1*/
 int pnpoly(int npol, double *xp, double *yp, double x, double y, int edgevalue) {
 	int i, j, c = 0;
@@ -110,3 +126,3 @@
 	}
 	return c;
-}
+}/*}}}*/
Index: /issm/trunk/src/c/shared/Exp/exp.h
===================================================================
--- /issm/trunk/src/c/shared/Exp/exp.h	(revision 8269)
+++ /issm/trunk/src/c/shared/Exp/exp.h	(revision 8270)
@@ -10,6 +10,6 @@
 
 int IsInPoly(Vec in,double* xc,double* yc,int numgrids,double* x,double* y,int i0,int i1, int edgevalue);
+int IsOutsidePoly(Vec in,double* xc,double* yc,int numgrids,double* x,double* y,int i0,int i1, int edgevalue);
 int IsInPolySerial(double* in,double* xc,double* yc,int numgrids,double* x,double* y,int nods, int edgevalue);
-int IsOutsidePoly(Vec out,double* xc,double* yc,int numgrids,double* x,double* y,int nods,int edgevalue);
 int DomainOutlineRead(int* pnprof,int** pprofngrids,double*** ppprofx,double*** ppprofy,char* domainname);
 int pnpoly(int npol, double *xp, double *yp, double x, double y, int edgevalue);
