find.first.gap<-function(x,gap.prop=10) {
 lenx<-length(x)
 newx<-sort(x)-min(x)
 not.found<-1
 gap.pos<-2
 # set the 
 mean.diff<-newx[2]-newx[1]
 while(not.found && gap.pos <= lenx) {
  this.diff<-newx[gap.pos]-newx[gap.pos-1]
  print(c(mean.diff,this.diff))
  if(mean.diff != 0) {
   if(this.diff/mean.diff >= gap.prop) not.found<-0
   else gap.pos<-gap.pos+1
  }
  else gap.pos<-gap.pos+1
  mean.diff<-(this.diff+mean.diff*(gap.pos-1))/gap.pos
 }
 return(newx[gap.pos]+min(x))
}
