Index: /issm/trunk-jpl/src/c/Container/Observations.cpp
===================================================================
--- /issm/trunk-jpl/src/c/Container/Observations.cpp	(revision 12291)
+++ /issm/trunk-jpl/src/c/Container/Observations.cpp	(revision 12292)
@@ -94,47 +94,71 @@
 /*Methods*/
 /*FUNCTION Observations::ObservationList{{{*/
-void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double range){
+void Observations::ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double radius,int maxdata){
 
 	/*Output and Intermediaries*/
-	int          nobs,i,index;
+	bool         stop;
+	int          nobs,i,j,k,n,counter;
+	double       h2,radius2;
+	int         *indices      = NULL;
+	double      *dists        = NULL;
 	double      *x            = NULL;
 	double      *y            = NULL;
 	double      *obs          = NULL;
 	Observation *observation  = NULL;
-	int         *indices      = NULL;
-
-	/*Treat range*/
-	if(range==0){
-		range=this->quadtree->root->length;
-	}
-
-	/*Find all observations that are in range*/
-	nobs=0;
-	while(nobs==0){
-		xfree((void**)&indices);
-		this->quadtree->RangeSearch(&indices,&nobs,x_interp,y_interp,range);
-		if(!nobs){
-			/*No observation found, double range*/
-			range=2*range;
-		}
-	}
-	/*Check that we do not have more than 50 observations*/
-	//while(nobs>50){
-	//	range=range/2;
-	//	xfree((void**)&indices);
-	//	this->quadtree->RangeSearch(&indices,&nobs,x_interp,y_interp,range);
-	//}
-
-	if(!nobs) _error_("Unexpected error: no observation within current range and more than 50 observations if doubling range");
-
-	/*Allocate vectors*/
-	x   = (double*)xmalloc(nobs*sizeof(double));
-	y   = (double*)xmalloc(nobs*sizeof(double));
-	obs = (double*)xmalloc(nobs*sizeof(double));
-
-	/*Loop over all observations and fill in x, y and obs*/
-	for (i=0;i<nobs;i++){
-		observation=(Observation*)this->GetObjectByOffset(indices[i]);
-		observation->WriteXYObs(&x[i],&y[i],&obs[i]);
+
+	/*Compute radius square*/
+	if(radius==0) radius=this->quadtree->root->length;
+	radius2 = radius*radius;
+
+	/*Find all observations that are in radius*/
+	indices = (int*)xmalloc(this->Size()*sizeof(int));
+	dists   = (double*)xmalloc(this->Size()*sizeof(double));
+	nobs    = 0;
+
+	for (i=0;i<this->Size();i++){
+		observation=(Observation*)this->GetObjectByOffset(i);
+		h2 = (observation->x-x_interp)*(observation->x-x_interp) + (observation->y-y_interp)*(observation->y-y_interp);
+
+		if(nobs==maxdata && h2>radius2) continue;
+		if(nobs<=maxdata){
+			indices[nobs]   = i;
+			dists[nobs]     = h2;
+			nobs++;
+		}
+		if(nobs==1) continue;
+
+		/*Sort all dists up to now*/
+		n=nobs-1;
+		stop = false;
+		for(k=0;k<n-1;k++){
+			if(h2<dists[k]){
+				counter=1;
+				for(int jj=k;jj<n;jj++){
+					j  = n-counter;
+					dists[j+1]   = dists[j];
+					indices[j+1] = indices[j];
+					counter++;
+				}
+				dists[k]   = h2;
+				indices[k] = i;
+				stop = true;
+				break;
+			}
+			if(stop) break;
+		}
+	}  
+	xfree((void**)&dists);
+
+	if(nobs){
+		/*Allocate vectors*/
+		x   = (double*)xmalloc(nobs*sizeof(double));
+		y   = (double*)xmalloc(nobs*sizeof(double));
+		obs = (double*)xmalloc(nobs*sizeof(double));
+
+		/*Loop over all observations and fill in x, y and obs*/
+		for (i=0;i<nobs;i++){
+			observation=(Observation*)this->GetObjectByOffset(indices[i]);
+			observation->WriteXYObs(&x[i],&y[i],&obs[i]);
+		}
 	}
 
Index: /issm/trunk-jpl/src/c/Container/Observations.h
===================================================================
--- /issm/trunk-jpl/src/c/Container/Observations.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/Container/Observations.h	(revision 12292)
@@ -23,5 +23,5 @@
 
 		/*Methods*/
-		void ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double range);
+		void ObservationList(double **px,double **py,double **pobs,int* pnobs,double x_interp,double y_interp,double radius,int maxdata);
 		void QuadtreeColoring(double* A,double *x,double *y,int n);
 		void Variomap(double* gamma,double *x,int n);
Index: /issm/trunk-jpl/src/c/Container/Options.cpp
===================================================================
--- /issm/trunk-jpl/src/c/Container/Options.cpp	(revision 12291)
+++ /issm/trunk-jpl/src/c/Container/Options.cpp	(revision 12292)
@@ -65,4 +65,42 @@
 
 	return 1;
+}
+/*}}}*/
+/*FUNCTION Options::Get(int* pvalue, char* name){{{1*/
+void Options::Get(int* pvalue,const char* name){
+
+	vector<Object*>::iterator object;
+	Option* option=NULL;
+
+	/*Get option*/
+	option=GetOption(name);
+
+	/*If the pointer is not NULL, the option has been found*/
+	if(option){
+		option->Get(pvalue);
+	}
+	/*Else, the Option does not exist, no default provided*/
+	else{
+		_error_("option of name \"%s\" not found, and no default value has been provided",name);
+	}
+}
+/*}}}*/
+/*FUNCTION Options::Get(int* pvalue, char* name,int default_value){{{1*/
+void Options::Get(int* pvalue,const char* name,int default_value){
+
+	vector<Object*>::iterator object;
+	Option* option=NULL;
+
+	/*Get option*/
+	option=GetOption(name);
+
+	/*If the pointer is not NULL, the option has been found*/
+	if(option){
+		option->Get(pvalue);
+	}
+	/*Else, the Option does not exist, a default is provided here*/
+	else{
+		*pvalue=default_value;
+	}
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/Container/Options.h
===================================================================
--- /issm/trunk-jpl/src/c/Container/Options.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/Container/Options.h	(revision 12292)
@@ -22,4 +22,6 @@
 		void Get(double*  pvalue,const char* name);
 		void Get(double*  pvalue,const char* name,double default_value);
+		void Get(int*  pvalue,const char* name);
+		void Get(int*  pvalue,const char* name,int default_value);
 		void Get(bool*    pvalue,const char* name);
 		void Get(bool*    pvalue,const char* name,bool default_value);
Index: /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp	(revision 12291)
+++ /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp	(revision 12292)
@@ -24,5 +24,6 @@
 
 	/*Intermediaries*/
-	double        range;
+	int           mindata,maxdata;
+	double        radius;
 	char         *output       = NULL;
 	Variogram    *variogram    = NULL;
@@ -38,5 +39,7 @@
 	/*Get Variogram from Options*/
 	ProcessVariogram(&variogram,options);
-	options->Get(&range,"searchrange",0.);
+	options->Get(&radius,"searchradius",0.);
+	options->Get(&mindata,"mindata",1);
+	options->Get(&maxdata,"maxdata",50);
 
 	/*Process observation dataset*/
@@ -62,5 +65,7 @@
 		gate.x_interp     = x_interp;
 		gate.y_interp     = y_interp;
-		gate.range        = range;
+		gate.radius       = radius;
+		gate.mindata      = mindata;
+		gate.maxdata      = maxdata;
 		gate.variogram    = variogram;
 		gate.observations = observations;
@@ -106,5 +111,7 @@
 	double       *x_interp     = gate->x_interp;
 	double       *y_interp     = gate->y_interp;
-	double        range        = gate->range;
+	double        radius       = gate->radius;
+	int           mindata      = gate->mindata;
+	int           maxdata      = gate->maxdata;
 	Variogram    *variogram    = gate->variogram;
 	Observations *observations = gate->observations;
@@ -137,8 +144,8 @@
 
 		/*Get list of observations for current point*/
-		observations->ObservationList(&x,&y,&obs,&n_obs,x_interp[idx],y_interp[idx],range);
-		if(n_obs==0){
-			predictions[idx] = -999.; 
-			error[idx]       = -999.; 
+		observations->ObservationList(&x,&y,&obs,&n_obs,x_interp[idx],y_interp[idx],radius,maxdata);
+		if(n_obs<mindata){
+			predictions[idx] = -999.0; 
+			error[idx]       = -999.0; 
 			continue;
 		}
Index: /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.h
===================================================================
--- /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.h	(revision 12292)
@@ -21,5 +21,7 @@
 	double       *x_interp;
 	double       *y_interp;
-	double        range;
+	double        radius;
+	int           mindata;
+	int           maxdata;
 	Variogram    *variogram;
 	Observations *observations;
Index: /issm/trunk-jpl/src/c/objects/Kriging/GaussianVariogram.cpp
===================================================================
--- /issm/trunk-jpl/src/c/objects/Kriging/GaussianVariogram.cpp	(revision 12291)
+++ /issm/trunk-jpl/src/c/objects/Kriging/GaussianVariogram.cpp	(revision 12292)
@@ -75,5 +75,5 @@
 	cova = (sill-nugget)*exp(-h2/(a*range*range));
 
-	//if(h2<0.0000001) cova = sill;
+	if(h2<0.0000001) cova = sill;
 
 	return cova;
Index: /issm/trunk-jpl/src/c/objects/Options/Option.h
===================================================================
--- /issm/trunk-jpl/src/c/objects/Options/Option.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/objects/Options/Option.h	(revision 12292)
@@ -42,4 +42,5 @@
 		virtual int   NDims()=0;
 		virtual int*  Size()=0;
+		virtual void  Get(int* pvalue)=0;
 		virtual void  Get(double* pvalue)=0;
 		virtual void  Get(bool* pvalue)=0;
Index: /issm/trunk-jpl/src/c/objects/Options/OptionCell.h
===================================================================
--- /issm/trunk-jpl/src/c/objects/Options/OptionCell.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/objects/Options/OptionCell.h	(revision 12292)
@@ -39,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue){_error_("An OptionCell object cannot return a int");};
 		void  Get(double* pvalue){_error_("An OptionCell object cannot return a double");};
 		void  Get(bool* pvalue){  _error_("An OptionCell object cannot return a bool");};
Index: /issm/trunk-jpl/src/c/objects/Options/OptionChar.h
===================================================================
--- /issm/trunk-jpl/src/c/objects/Options/OptionChar.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/objects/Options/OptionChar.h	(revision 12292)
@@ -39,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue){_error_("An OptionChar object cannot return a int");};
 		void  Get(double* pvalue){_error_("An OptionChar object cannot return a double");};
 		void  Get(bool* pvalue){  _error_("An OptionChar object cannot return a bool");};
Index: /issm/trunk-jpl/src/c/objects/Options/OptionDouble.cpp
===================================================================
--- /issm/trunk-jpl/src/c/objects/Options/OptionDouble.cpp	(revision 12291)
+++ /issm/trunk-jpl/src/c/objects/Options/OptionDouble.cpp	(revision 12292)
@@ -120,4 +120,16 @@
 }
 /*}}}*/
+/*FUNCTION OptionDouble::Get(int* pvalue) {{{1*/
+void OptionDouble::Get(int* pvalue){
+
+	/*We should first check that the size is one*/
+	if(this->NumEl()!=1){
+		_error_("option \"%s\" has %i elements and cannot return a single int",this->name,this->NumEl());
+	}
+
+	/*Assign output pointer*/
+	*pvalue=(int)this->values[0];
+}
+/*}}}*/
 /*FUNCTION OptionDouble::Get(double* pvalue) {{{1*/
 void OptionDouble::Get(double* pvalue){
Index: /issm/trunk-jpl/src/c/objects/Options/OptionDouble.h
===================================================================
--- /issm/trunk-jpl/src/c/objects/Options/OptionDouble.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/objects/Options/OptionDouble.h	(revision 12292)
@@ -39,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue);
 		void  Get(double* pvalue);
 		void  Get(bool* pvalue){  _error_("An OptionDouble object cannot return a bool");};
Index: /issm/trunk-jpl/src/c/objects/Options/OptionLogical.h
===================================================================
--- /issm/trunk-jpl/src/c/objects/Options/OptionLogical.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/objects/Options/OptionLogical.h	(revision 12292)
@@ -39,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue){_error_("An OptionLogical object cannot return a int");};
 		void  Get(double* pvalue){_error_("An OptionLogical object cannot return a double");};
 		void  Get(bool* pvalue);
Index: /issm/trunk-jpl/src/c/objects/Options/OptionStruct.h
===================================================================
--- /issm/trunk-jpl/src/c/objects/Options/OptionStruct.h	(revision 12291)
+++ /issm/trunk-jpl/src/c/objects/Options/OptionStruct.h	(revision 12292)
@@ -39,4 +39,5 @@
 		int   NDims();
 		int*  Size();
+		void  Get(int* pvalue){_error_("An OptionStruct object cannot return a int");};
 		void  Get(double* pvalue){_error_("An OptionStruct object cannot return a double");};
 		void  Get(bool* pvalue){  _error_("An OptionStruct object cannot return a bool");};
Index: /issm/trunk-jpl/src/c/shared/Threads/LaunchThread.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Threads/LaunchThread.cpp	(revision 12291)
+++ /issm/trunk-jpl/src/c/shared/Threads/LaunchThread.cpp	(revision 12292)
@@ -67,4 +67,3 @@
 	function((void*)&handle);
 	#endif
-
 }
