diff --git a/DESCRIPTION b/DESCRIPTION
index 9f94dbd24713324c83e1cfe68217e7c9ba224423..242a2412bd0af1f9c85679f5c839d15a228f1420 100755
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,18 +1,21 @@
 Package: ads
 Type: Package
 Title: Spatial Point Patterns Analysis
-Version: 1.5-3
-Date: 2018-03-29
+Version: 1.5-4
+Date: 2020-09-11
 Authors@R: c(person("Raphael", "Pelissier", role="aut", email="raphael.pelissier@ird.fr"),
              person("Francois", "Goreau", role="aut"),
              person("Philippe", "Verley", role=c("ctb", "cre"), email="philippe.verley@ird.fr"))
 Author: Raphael Pelissier [aut], Francois Goreau [aut], Philippe Verley [ctb, cre]
-Maintainer: Philippe Verley <philippe.verley@ird.fr>
-Imports: ade4, spatstat
-Description: Perform first- and second-order multi-scale analyses derived from Ripley K-function, for univariate,
+Maintainer: Raphael Pelissier <Raphael.Pelissier@ird.fr>
+Imports: ade4, spatstat.geom
+Description: Perform first- and second-order multi-scale analyses derived from Ripley K-function (Ripley B. D. (1977) <doi:10.1111/j.2517-6161.1977.tb01615.x>), for univariate,
  multivariate and marked mapped data in rectangular, circular or irregular shaped sampling windows, with tests of 
  statistical significance based on Monte Carlo simulations.
+Depends: R (>= 3.5.0)
 License: GPL-2
 NeedsCompilation: yes
 Repository: CRAN
-RoxygenNote: 6.0.1
+Date/Publication: 2020-09-11 12:20:07 UTC
+Packaged: 2020-09-11 11:19:29 UTC; rpelissier
+RoxygenNote: 7.1.1
diff --git a/INDEX b/INDEX
index 309fd0e80ccd4a42a8f4e902cc991cad8578cf15..a6c7ef218032904d5f7a752b0a6b65a1efa5eac5 100755
--- a/INDEX
+++ b/INDEX
@@ -1,14 +1,14 @@
 Allogny       Spatial pattern of oaks suffering from frost shake in Allogny, France.
 BPoirier      Tree spatial pattern in Beau Poirier plot, Haye forest, France.
 Couepia       Spatial pattern of Couepia caryophylloides in Paracou, a canopy tree species of French Guiana.
-demopat		    Artificial data point pattern from \code{spatstat} package.
+demopat       Artificial data point pattern from \code{spatstat.data} package.
 Paracou15     Spatial pattern of trees in plot 15 of Paracou experimental station, French Guiana.
 area.swin     Area of a sampling window.
 dval          Multiscale local density of a spatial point pattern.
 inside.swin   Test wether points are inside a sampling window.
 k12fun        Multiscale second-order neigbourhood analysis of a bivariate spatial point pattern.
 k12val        Multiscale local second-order neighbour density of a bivariate spatial point pattern.
-kdfun		      Multiscale second-order neigbourhood analysis of phylogentic/functional spatial structure of a multivariate spatial point pattern. 
+kdfun         Multiscale second-order neigbourhood analysis of phylogentic/functional spatial structure of a multivariate spatial point pattern. 
 kfun          Multiscale second-order neigbourhood analysis of an univariate spatial point pattern.
 kmfun         Multiscale second-order neigbourhood analysis of a marked spatial point pattern.
 kp.fun        (Formerly ki.fun) Multiscale second-order neigbourhood analysis of a multivariate spatial point pattern.
diff --git a/NAMESPACE b/NAMESPACE
index 8949b00bfed86d2c4148335c7527558592130003..976578022125b26ee9a17d14059fa89f65aac953 100755
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,11 +1,20 @@
-importFrom(ade4,"divc","is.euclid")
-importFrom(spatstat,"border","bounding.box.xy","area.owin")
-importFrom("graphics", "abline", "barplot", "layout", "lines", "par",
-             "plot", "plot.default", "points", "polygon", "symbols",
-             "text")
-importFrom("stats", "as.dist", "var")
-importFrom("utils", "read.table", "str")
+# load DLL
+useDynLib(ads, .registration = TRUE, .fixes = "C_")
 
+# Import external pkg names
+importFrom(ade4,
+           divc, is.euclid)
+importFrom(spatstat.geom,
+           border, bounding.box.xy, area.owin)
+importFrom(graphics,
+           abline, barplot, layout, lines, par, plot, plot.default, points,
+           polygon, symbols, text)
+importFrom(stats,
+           as.dist, var)
+importFrom(utils,
+           read.table, str)
+
+# Export all names (should be improved in the future)
 export(
 	k12fun,
 	k12val,
@@ -17,7 +26,6 @@ export(
 	krfun,
 	ksfun,
 	kval,
-	
 	swin,
 	area.swin,
 	inside.swin,
@@ -26,15 +34,10 @@ export(
 	mimetic,
 	owin2swin,
 	spp,
-	triangulate
-)
-
-exportClasses(
-	fads,
+	triangulate,
 	mimetic,
 	spp,
-	swin,
-	vads
+	swin
 )
 
 S3method(plot, kfun, plot.fads.kfun)
@@ -76,5 +79,3 @@ S3method(summary, swin)
 S3method(summary, dval, summary.vads.dval)
 S3method(summary, k12val, summary.vads.k12val)
 S3method(summary, kval, summary.vads.kval)
-
-useDynLib(ads, .registration=TRUE)
diff --git a/R/fads.R b/R/fads.R
index 90e6f3ea3a0fc341bdab8f8ff1ebde92567ee33a..c0afdfb726e86b9bf939ad4a77192caf368b2e8d 100755
--- a/R/fads.R
+++ b/R/fads.R
@@ -790,15 +790,15 @@ kmfun<-function(p,upto,by,nsim=0,alpha=0.01) {
 					PACKAGE="ads")	
 		}
 		else { #with CI
-			res<-.C("corr_tr_disq_ic",
+			res<-.C("ripley_tr_disq_ic",
 					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
-					as.double(x0),as.double(y0),as.double(r0),
+					as.double(x0),as.double(y0),as.double(r0),as.double(intensity),
 					as.integer(nbTri),as.double(tri$ax),as.double(tri$ay),as.double(tri$bx),as.double(tri$by),as.double(tri$cx),as.double(tri$cy),
 					as.integer(tmax),as.double(by),
 					as.integer(nsim),as.double(alpha),
 					gm=double(tmax),km=double(tmax),
 					gmic1=double(tmax),gmic2=double(tmax),kmic1=double(tmax),kmic2=double(tmax),
-					gmval=double(tmax),kmval=double(tmax),
+					gmval=double(tmax),kmval=double(tmax),lmval=double(tmax),nmval=double(tmax),
 					PACKAGE="ads")	
 		}
 	}
diff --git a/R/swin.R b/R/swin.R
index fc17c57bdb66804349df42c93615546b71d78526..e5b8cc742507ea0b149f4c0d17f4f3b14b8591f7 100755
--- a/R/swin.R
+++ b/R/swin.R
@@ -171,6 +171,7 @@ plot.swin<-function (x,main,edge,scale=TRUE,add=FALSE,csize=1,...) {
 inside.swin<-function(x,y,w,bdry=TRUE) {
 	stopifnot(inherits(w,"swin"))
 	stopifnot(length(x)==length(y))
+	inside<-vector(mode="logical",length=length(x))
 	if("rectangle"%in%w$type)
 		inside<-in.rectangle(x,y,w$xmin,w$ymin,w$xmax,w$ymax,bdry)
 	else if("circle"%in%w$type)
@@ -179,9 +180,8 @@ inside.swin<-function(x,y,w,bdry=TRUE) {
 		stop("invalid window type")
 	if("complex"%in%w$type) {
 		tri<-w$triangles
-		for(i in 1:nrow(tri)) 
-			inside[in.triangle(x,y,tri$ax[i],tri$ay[i],tri$bx[i],tri$by[i],tri$cx[i],tri$cy[i])]<-FALSE
-	}   
+		inside[in.triangle(x,y,tri$ax,tri$ay,tri$bx,tri$by,tri$cx,tri$cy,bdry)]<-FALSE
+	}  
 	return(inside)
 }
 
@@ -200,7 +200,7 @@ owin2swin<-function(w) {
 		else { #polygon with holes
 			stopifnot(w$bdry[[1]]$hole==FALSE)
 			bb<-bounding.box.xy(w$bdry[[1]][1:2])
-			if((bb$xrange==w$xrange)&&(bb$yrange==w$yrange)&&(area.owin(bb)==w$bdry[[1]]$area)) {	#first poly is rectangular window frame
+			if(all(bb$xrange==w$xrange)&&all(bb$yrange==w$yrange)&&(area.owin(bb)==w$bdry[[1]]$area)) {	#first poly is rectangular window frame
 				outer.poly<-data.frame(x=c(rep(w$xrange[1],2),rep(w$xrange[2],2)),y=c(w$yrange,w$yrange[2:1]))
 				for(i in 2:length(w$bdry)) {
 					stopifnot(w$bdry[[i]]$hole==TRUE)
diff --git a/R/triangulate.R b/R/triangulate.R
index e263ba860908e5f1b9663f03e11dbed192fb30ff..9453baeb68d07d7e7470184d32174e0ae4469f21 100755
--- a/R/triangulate.R
+++ b/R/triangulate.R
@@ -44,7 +44,7 @@ triangulate<-function(outer.poly,holes) {
 		vertY<-outer.poly$y
 		nbtri<-(nbpts-2)
 	}
-	tri<-.C("c_triangulate",
+	tri<-.C("triangulate",
 		as.integer(nbpoly),as.integer(nbpts),as.integer(nbptot),as.double(vertX),as.double(vertY),as.integer(nbtri),
 		X1=double(nbtri),Y1=double(nbtri),X2=double(nbtri),Y2=double(nbtri),X3=double(nbtri),Y3=double(nbtri),
 		PACKAGE="ads")
diff --git a/R/util.R b/R/util.R
index 8bdc178356bb8da2e9d9009ad387e2e36762ae64..985ee28f670123d2eb56d9564562267daa0c226d 100755
--- a/R/util.R
+++ b/R/util.R
@@ -11,7 +11,7 @@ overlapping.polygons<-function(listpoly) {
 	return(res)
 }
 
-#from area.xypolygon{spatstat}
+#from area.xypolygon{spatstat.geom}
 #return area>0 when (xp,yp) vertices are ranked anticlockwise
 #or area<0 when (xp,yp) vertices are ranked clockwise
 area.poly<-function(xp,yp) {
@@ -44,17 +44,61 @@ in.rectangle<-function(x,y,xmin,ymin,xmax,ymax,bdry=TRUE) {
 	stopifnot(length(x)==length(y))
 	stopifnot((xmax-xmin)>0)
 	stopifnot((ymax-ymin)>0)
-	rect<-list(x=c(xmin,xmax,xmax,xmin),y=c(ymin,ymin,ymax,ymax))
-	return(in.poly(x,y,rect,bdry))
+	l<-length(x)
+	inside<-vector(mode="logical",length=l)
+	for(i in 1:l) {
+		if(bdry) {
+			if(x[i]>=xmin&&x[i]<=xmax&&y[i]>=ymin&&y[i]<=ymax)
+				inside[i]<-TRUE
+		}
+		else {
+			if(x[i]>xmin&&x[i]<xmax&&y[i]>ymin&&y[i]<ymax)
+				inside[i]<-TRUE
+		}
+	}
+	return(inside)
 }
 
+#modified from inside.triangle(spatstat.utils)
 in.triangle<-function(x,y,ax,ay,bx,by,cx,cy,bdry=TRUE) {
 	stopifnot(length(x)==length(y))
-	tri<-list(x=c(ax,bx,cx),y=c(ay,by,cy))
-	return(in.poly(x,y,tri,bdry))
+	p<-length(x)
+	inside<-vector(mode="logical",length=p)
+	t<-length(ax)
+	stopifnot(all(c(length(ay),length(bx),length(by),length(cx),length(cy))==t))
+	intri<-matrix(0,p,t)
+	for(j in 1:t) {
+		v0x <- cx[j] - ax[j]
+    	v0y <- cy[j] - ay[j]
+    	v1x <- bx[j] - ax[j]
+    	v1y <- by[j] - ay[j]
+		dot00 <- v0x^2 + v0y^2
+    	dot01 <- v0x * v1x + v0y * v1y
+		dot11 <- v1x^2 + v1y^2
+		for(i in 1:p) {
+			if(!inside[i]) {
+				v2x <- x[i] - ax[j]
+    			v2y <- y[i] - ay[j]
+				dot02 <- v0x * v2x + v0y * v2y
+    			dot12 <- v1x * v2x + v1y * v2y
+    			Denom <- dot00 * dot11 - dot01 * dot01
+    			u <- dot11 * dot02 - dot01 * dot12
+    			v <- dot00 * dot12 - dot01 * dot02
+				if(bdry) {
+          			if((u >= 0) & (v >= 0) & (u + v <= Denom))
+            			inside[i]<-TRUE
+        		}
+        		else {
+          			if((u > 0) & (v > 0) & (u + v < Denom))
+              			inside[i]<-TRUE
+        		}
+			}
+		}	
+	}
+	return(inside)			
 }
 
-#modified from plot.ppp{spatstat}
+#modified from plot.ppp{spatstat.core}
 adjust.marks.size<-function(marks,window,maxsize=NULL) {
 	if(is.null(maxsize)) {
 		if("rectangle"%in%window$type)
@@ -233,36 +277,27 @@ overlap.trapez <- function(xa, ya, xb, yb, verb=FALSE) {
   return(signfactor * areaT)
 }
 
-#TRUE: les points sur la bordure sont = inside
+#Points on boundary are considered outside. No alternative option implemented yet.
 in.poly<-function(x,y,poly,bdry=TRUE) {
+	if(bdry) {
+		bdry<-FALSE
+		warning("argument 'bdry' automatically set to FALSE. No alternative implemented yet")
+	}
 	stopifnot(is.poly(poly))
 	xp <- poly$x
 	yp <- poly$y
 	npts <- length(x)
-	nedges <- length(xp)   # sic
-
-  score <- rep(0, npts)
-  on.boundary <- rep(FALSE, npts)
-	temp <- .Fortran(
-		"inpoly",
-		x=as.double(x),
-		y=as.double(y),
-		xp=as.double(xp),
-		yp=as.double(yp),
-		npts=as.integer(npts),
-		nedges=as.integer(nedges),
-		score=as.double(score),
-		onbndry=as.logical(on.boundary),
-		PACKAGE="ads"
-	)
-	score <- temp$score
-	on.boundary <- temp$onbndry
-	score[on.boundary] <- 1
-	res<-rep(FALSE,npts)
-	res[score==(-1)]<-TRUE
-	if(bdry)
-		res[score==1]<-TRUE
-	return(res)
+	nedg <- length(poly$x)   # sic
+	xmi<-ifelse(min(x)<=min(poly$x),min(x),min(poly$x))
+	ymi<-ifelse(max(x)>=max(poly$x),max(x),max(poly$x))
+	polxrange<-ifelse(min(y)<=min(poly$y),min(y),min(poly$y))
+	polyrange<-ifelse(max(y)>=max(poly$y),max(y),max(poly$y))
+	res <- .C("pnpoly",
+ 				as.double(x),as.double(y),as.double(poly$x),
+ 				as.double(poly$y),as.integer(npts),as.integer(nedg),as.double(xmi),
+		 		as.double(ymi),as.double(polxrange),as.double(polyrange),score=double(npts),
+				PACKAGE="ads")
+	return(as.logical(res$score))
 }
 
 ####################
@@ -307,6 +342,16 @@ read.tri<-function(X) {
 	return(res)
 }
 
+transpose<-function(x,y) {
+
+	nbTri<-length(x)/3
+	
+	res<-.C("transpose",x=as.double(x),y=as.double(y),nbTri=as.integer(nbTri),
+			x1=double(nbTri),y1=double(nbTri),x2=double(nbTri),y2=double(nbTri),
+			x3=double(nbTri),y3=double(nbTri),PACKAGE="ads")
+		
+	list(x1=res$x1,y1=res$y1,x2=res$x2,y2=res$y2,x3=res$x3,y3=res$y3)
+}
 ##############
 #subsetting dist objects
 #sub is a logical vector of True/False
diff --git a/R/zzz.R b/R/zzz.R
new file mode 100644
index 0000000000000000000000000000000000000000..e3298662b689e57f857bce3cfa21d85e690c039a
--- /dev/null
+++ b/R/zzz.R
@@ -0,0 +1,14 @@
+##########################################################################
+## start-up and clean-up functions
+#########################################################################
+
+.onAttach <- function(...) {
+  # echo output to screen
+  packageStartupMessage("##\n## ads R package \n",
+                        "## For Spatial Point Patterns Analysis \n",
+                        "##\n")
+}
+
+.onUnload <- function(libpath) {
+  library.dynam.unload("ads", libpath)
+}
\ No newline at end of file
diff --git a/data/Paracou15.rda b/data/Paracou15.rda
index b0783a29fe6933739891790764d2eeedf223b8b1..fa1aec405056325c47efaedb703db7dcd283b337 100755
Binary files a/data/Paracou15.rda and b/data/Paracou15.rda differ
diff --git a/inst/CITATION b/inst/CITATION
index f6441168cf519c632a9873676456a7e5a43b5e7a..89c38f7d61e4fd8fdab9ca2eff02c62e2d12c9dc 100644
--- a/inst/CITATION
+++ b/inst/CITATION
@@ -9,12 +9,12 @@ citEntry(entry = "Article",
   volume       = "63",
   number       = "6",
   pages        = "1--18",
-  url          = "http://www.jstatsoft.org/v63/i06/",
+  url          = "http://dx.doi.org/10.18637/jss.v063.i06",
 
   textVersion  =
   paste("Raphael Pelissier, Francois Goreaud (2015).",
         "ads Package for R: A Fast Unbiased Implementation of the K-function Family for Studying Spatial Point Patterns in Irregular-Shaped Sampling Windows.",
         "Journal of Statistical Software, 63(6), 1-18.",
-        "URL http://www.jstatsoft.org/v63/i06/.")
+        "URL http://dx.doi.org/10.18637/jss.v063.i06.")
 )
 
diff --git a/man/Allogny.Rd b/man/Allogny.Rd
index c6a82c9d8df29ec114c8c80f189f1011ece6b59a..2f6893c54667225f187d242d219ebcc5a29fde60 100755
--- a/man/Allogny.Rd
+++ b/man/Allogny.Rd
@@ -1,27 +1,27 @@
 \name{Allogny}
-\encoding{latin1}
-\alias{Allogny}
-\docType{data}
-\title{Spatial pattern of oaks suffering from frost shake in Allogny, France.}
-\description{
-Spatial pattern of sound and splited oaks (\emph{Quercus petraea}) suffering from frost shake in a 2.35-ha plot in Allogny, France.
-}
-\usage{data(Allogny)}
-\format{
-A list with 4 components:\cr
-\code{$rect   } is a vector of coordinates \eqn{(xmin,ymin,xmax,ymax)} of the origin and the opposite corner of a 125 by 188 m square plot.\cr
-\code{$trees  } is a list of tree coordinates \eqn{(x,y)}.\cr
-\code{$status } is a factor with 2 levels \eqn{("splited","sound")}.\cr
-}
-\source{
-  Grandjean, G., Jabiol, B., Bruchiamacchie, M. and Roustan, F. 1990. \emph{Recherche de corrélations entre les paramètres édaphiques, et plus spécialement texture, hydromorphie et drainage interne, et la réponse individuelle des chenes sessiles et pédonculés à la gélivure.} Rapport de recherche ENITEF, Nogent sur Vernisson, France.
-}
-\references{
-Goreaud, F. & Pélissier, R. 2003. Avoiding misinterpretation of biotic interactions with the intertype \emph{K12}-function: population independence vs. random labelling hypotheses. \emph{Journal of Vegetation Science}, 14: 681-692.
-}
-\examples{
-data(Allogny)
-allo.spp <- spp(Allogny$trees, mark=Allogny$status, window=Allogny$rect)
-plot(allo.spp)
-}
-\keyword{datasets}
+\encoding{latin1}
+\alias{Allogny}
+\docType{data}
+\title{Spatial pattern of oaks suffering from frost shake in Allogny, France.}
+\description{
+Spatial pattern of sound and splited oaks (\emph{Quercus petraea}) suffering from frost shake in a 2.35-ha plot in Allogny, France.
+}
+\usage{data(Allogny)}
+\format{
+A list with 4 components:\cr
+\code{$rect   } is a vector of coordinates \eqn{(xmin,ymin,xmax,ymax)} of the origin and the opposite corner of a 125 by 188 m square plot.\cr
+\code{$trees  } is a list of tree coordinates \eqn{(x,y)}.\cr
+\code{$status } is a factor with 2 levels \eqn{("splited","sound")}.\cr
+}
+\source{
+  Grandjean, G., Jabiol, B., Bruchiamacchie, M. and Roustan, F. 1990. \emph{Recherche de corrélations entre les paramètres édaphiques, et plus spécialement texture, hydromorphie et drainage interne, et la réponse individuelle des chenes sessiles et pédonculés à la gélivure.} Rapport de recherche ENITEF, Nogent sur Vernisson, France.
+}
+\references{
+Goreaud, F. & Pélissier, R. 2003. Avoiding misinterpretation of biotic interactions with the intertype \emph{K12}-function: population independence vs. random labelling hypotheses. \emph{Journal of Vegetation Science}, 14: 681-692.
+}
+\examples{
+data(Allogny)
+allo.spp <- spp(Allogny$trees, mark=Allogny$status, window=Allogny$rect)
+plot(allo.spp)
+}
+\keyword{datasets}
diff --git a/man/BPoirier.Rd b/man/BPoirier.Rd
index d5a66222eeaf84ea21863e3771587e2cbb930dfc..1979a29a521f27daf72c4c8f323380a3852180f2 100755
--- a/man/BPoirier.Rd
+++ b/man/BPoirier.Rd
@@ -1,34 +1,34 @@
-\encoding{latin1}
-\name{BPoirier}
-\alias{BPoirier}
-\docType{data}
-\title{Tree spatial pattern in Beau Poirier plot, Haye forest, France}
-\description{
-Spatial pattern of 162 beeches, 72 oaks and 3 hornbeams in a 1-ha 140 yr-old temperate forest plot in Haye, France. 
-}
-\usage{data(BPoirier)}
-\format{
-A list with 8 components:\cr
-\code{$rect    } is a vector of coordinates \eqn{(xmin,ymin,xmax,ymax)} of the origin and the opposite corner of a 110 by 90 m rectangular plot.\cr
-\code{$tri1    } is a list of vertice coordinates \eqn{(ax,ay,bx,by,cx,cy)} of contiguous triangles covering the denser part of the plot.\cr
-\code{$tri2    } is a list of vertice coordinates \eqn{(ax,ay,bx,by,cx,cy)} of contiguous triangles covering the sparser part of the plot.\cr
-\code{$poly1   } is a list of vertice coordinates \eqn{(x,y)} of the polygon enclosing \code{BPoirier$tri1}.\cr
-\code{$poly2   } is a list of two polygons vertice coordinates \eqn{(x,y)} enclosing \code{BPoirier$tri2}.\cr
-\code{$trees   } is a list of tree coordinates \eqn{(x,y)}.\cr
-\code{$species } is a factor with 3 levels \eqn{("beech","oak","hornbeam")} corresponding to species names of the trees.\cr
-\code{$dbh     } is a vector of tree size (diameter at breast height in cm). 
-}
-\source{
-Pardé, J. 1981. De 1882 à 1976/80 : les places d'expèrience de sylviculture du hetre en foret domainiale de Haye. \emph{Revue Forestière Française}, 33: 41-64.
-}
-
-\references{
-Goreaud, F. 2000. \emph{Apports de l'analyse de la structure spatiale en foret tempérée à l'étude et la modélisation des peuplements complexes}. Thèse de doctorat, ENGREF, Nancy, France.\cr\cr
-Pélissier, R. & Goreaud, F. 2001. A practical approach to the study of spatial structure in simple cases of heterogeneous vegetation. \emph{Journal of Vegetation Science}, 12: 99-108.
-}
-\examples{
-data(BPoirier)
-BP.spp <- spp(BPoirier$trees, mark=BPoirier$species, window=BPoirier$rect)
-plot(BP.spp)
-}
-\keyword{datasets}
+\encoding{latin1}
+\name{BPoirier}
+\alias{BPoirier}
+\docType{data}
+\title{Tree spatial pattern in Beau Poirier plot, Haye forest, France}
+\description{
+Spatial pattern of 162 beeches, 72 oaks and 3 hornbeams in a 1-ha 140 yr-old temperate forest plot in Haye, France. 
+}
+\usage{data(BPoirier)}
+\format{
+A list with 8 components:\cr
+\code{$rect    } is a vector of coordinates \eqn{(xmin,ymin,xmax,ymax)} of the origin and the opposite corner of a 110 by 90 m rectangular plot.\cr
+\code{$tri1    } is a list of vertice coordinates \eqn{(ax,ay,bx,by,cx,cy)} of contiguous triangles covering the denser part of the plot.\cr
+\code{$tri2    } is a list of vertice coordinates \eqn{(ax,ay,bx,by,cx,cy)} of contiguous triangles covering the sparser part of the plot.\cr
+\code{$poly1   } is a list of vertice coordinates \eqn{(x,y)} of the polygon enclosing \code{BPoirier$tri1}.\cr
+\code{$poly2   } is a list of two polygons vertice coordinates \eqn{(x,y)} enclosing \code{BPoirier$tri2}.\cr
+\code{$trees   } is a list of tree coordinates \eqn{(x,y)}.\cr
+\code{$species } is a factor with 3 levels \eqn{("beech","oak","hornbeam")} corresponding to species names of the trees.\cr
+\code{$dbh     } is a vector of tree size (diameter at breast height in cm). 
+}
+\source{
+Pardé, J. 1981. De 1882 à 1976/80 : les places d'expèrience de sylviculture du hetre en foret domainiale de Haye. \emph{Revue Forestière Française}, 33: 41-64.
+}
+
+\references{
+Goreaud, F. 2000. \emph{Apports de l'analyse de la structure spatiale en foret tempérée à l'étude et la modélisation des peuplements complexes}. Thèse de doctorat, ENGREF, Nancy, France.\cr\cr
+Pélissier, R. & Goreaud, F. 2001. A practical approach to the study of spatial structure in simple cases of heterogeneous vegetation. \emph{Journal of Vegetation Science}, 12: 99-108.
+}
+\examples{
+data(BPoirier)
+BP.spp <- spp(BPoirier$trees, mark=BPoirier$species, window=BPoirier$rect)
+plot(BP.spp)
+}
+\keyword{datasets}
diff --git a/man/Couepia.Rd b/man/Couepia.Rd
index 16576221de4fa357876702a9cd52dae143ec065a..34535664a88cd0b0cc1234bba393de2c60dd4f9f 100755
--- a/man/Couepia.Rd
+++ b/man/Couepia.Rd
@@ -1,28 +1,28 @@
-\encoding{latin1}
-\name{Couepia}
-\alias{Couepia}
-\docType{data}
-\title{Spatial pattern of Couepia caryophylloides in Paracou, a canopy tree species of French Guiana.}
-\description{
-Spatial pattern of 34 mature individuals and 173 young individuals of the tree species \emph{Couepia caryophylloides} (Chrysobalanaceae) in a 25-ha forest plot in Paracou, French Guiana.
-}
-\usage{data(Couepia)}
-\format{
-A list with 4 components:\cr
-\code{$rect  } is a vector of coordinates \eqn{(xmin,ymin,xmax,ymax)} of the origin and the opposite corner of a 500 by 500 m rectangular plot.\cr
-\code{$tri   } is a list of vertice coordinates \eqn{(ax,ay,bx,by,cx,cy)} of contiguous triangles covering swampy parts of the plot.\cr
-\code{$trees } is a list of tree coordinates \eqn{(x,y)}.\cr
-\code{$stage } is a factor with 2 levels \eqn{("mature","young")}.\cr
-}
-\source{
-  Collinet, F. 1997. \emph{Essai de regroupement des principales espèces structurantes d'une foret dense humide d'après l'analyse de leur répartition spatiale (foret de Paracou - Guyane).} Thèse de doctorat, Université Claude Bernard, Lyon, France.
-}
-\references{
-Goreaud, F. & Pélissier, R. 2003. Avoiding misinterpretation of biotic interactions with the intertype \emph{K12}-function: population independence vs. random labelling hypotheses. \emph{Journal of Vegetation Science}, 14: 681-692.
-}
-\examples{
-data(Couepia)
-coca.spp <- spp(Couepia$trees, mark=Couepia$stage, window=Couepia$rect, triangles=Couepia$tri)
-plot(coca.spp)
-}
-\keyword{datasets}
+\encoding{latin1}
+\name{Couepia}
+\alias{Couepia}
+\docType{data}
+\title{Spatial pattern of Couepia caryophylloides in Paracou, a canopy tree species of French Guiana.}
+\description{
+Spatial pattern of 34 mature individuals and 173 young individuals of the tree species \emph{Couepia caryophylloides} (Chrysobalanaceae) in a 25-ha forest plot in Paracou, French Guiana.
+}
+\usage{data(Couepia)}
+\format{
+A list with 4 components:\cr
+\code{$rect  } is a vector of coordinates \eqn{(xmin,ymin,xmax,ymax)} of the origin and the opposite corner of a 500 by 500 m rectangular plot.\cr
+\code{$tri   } is a list of vertice coordinates \eqn{(ax,ay,bx,by,cx,cy)} of contiguous triangles covering swampy parts of the plot.\cr
+\code{$trees } is a list of tree coordinates \eqn{(x,y)}.\cr
+\code{$stage } is a factor with 2 levels \eqn{("mature","young")}.\cr
+}
+\source{
+  Collinet, F. 1997. \emph{Essai de regroupement des principales espèces structurantes d'une foret dense humide d'après l'analyse de leur répartition spatiale (foret de Paracou - Guyane).} Thèse de doctorat, Université Claude Bernard, Lyon, France.
+}
+\references{
+Goreaud, F. & Pélissier, R. 2003. Avoiding misinterpretation of biotic interactions with the intertype \emph{K12}-function: population independence vs. random labelling hypotheses. \emph{Journal of Vegetation Science}, 14: 681-692.
+}
+\examples{
+data(Couepia)
+coca.spp <- spp(Couepia$trees, mark=Couepia$stage, window=Couepia$rect, triangles=Couepia$tri)
+plot(coca.spp)
+}
+\keyword{datasets}
diff --git a/man/area.swin.Rd b/man/area.swin.Rd
index d6042f29d1c120723baaa95ee72fe0581c0c7921..296f2e205fe7d0d8b5b4f19a50d3944e590b107b 100755
--- a/man/area.swin.Rd
+++ b/man/area.swin.Rd
@@ -1,45 +1,45 @@
-\encoding{latin1}
-\name{area.swin}
-\alias{area.swin}
-\title{Area of a sampling window}
-\description{
-  Function \code{area.swin} computes the area of a sampling window.
-}
-\usage{
-area.swin(w)
-}
-\arguments{
-  \item{w}{an object of class \code{"swin"} defining the sampling window.}
-}
-\details{
-For \code{"simple"} sampling windows, returns simply the area of the rectangle or circle delineating the study region.\cr
-For \code{"complex"} sampling windows, returns the area of the initial rectangle or circle, minus the total area of the 
-triangles to remove (see \code{\link{swin}}).
-}
-\value{
-The area of the sampling window.
-}
-\author{
-  \email{Raphael.Pelissier@ird.fr}
-}
-\seealso{
-  \code{\link{swin}}.
-}
-\examples{
-  #rectangle of size [0,110] x [0,90]
-  wr<-swin(c(0,0,110,90))
-  area.swin(wr)
-  
-  #circle with radius 50 centred on (55,45)
-  wc<-swin(c(55,45,50))
-  area.swin(wc)
-  
- # polygon (diamond shape)
- t1 <- c(0,0,55,0,0,45)
- t2 <- c(55,0,110,0,110,45)
- t3 <- c(0,45,0,90,55,90)
- t4 <- c(55,90,110,90,110,45)
- wp <- swin(wr, rbind(t1,t2,t3,t4))
- area.swin(wp)
-}
-\keyword{spatial}
+\encoding{latin1}
+\name{area.swin}
+\alias{area.swin}
+\title{Area of a sampling window}
+\description{
+  Function \code{area.swin} computes the area of a sampling window.
+}
+\usage{
+area.swin(w)
+}
+\arguments{
+  \item{w}{an object of class \code{"swin"} defining the sampling window.}
+}
+\details{
+For \code{"simple"} sampling windows, returns simply the area of the rectangle or circle delineating the study region.\cr
+For \code{"complex"} sampling windows, returns the area of the initial rectangle or circle, minus the total area of the 
+triangles to remove (see \code{\link{swin}}).
+}
+\value{
+The area of the sampling window.
+}
+\author{
+  \email{Raphael.Pelissier@ird.fr}
+}
+\seealso{
+  \code{\link{swin}}.
+}
+\examples{
+  \dontrun{rectangle of size [0,110] x [0,90]}
+  wr<-swin(c(0,0,110,90))
+  area.swin(wr)
+  
+  \dontrun{circle with radius 50 centred on (55,45)}
+  wc<-swin(c(55,45,50))
+  area.swin(wc)
+  
+ \dontrun{polygon (diamond shape)}
+ t1 <- c(0,0,55,0,0,45)
+ t2 <- c(55,0,110,0,110,45)
+ t3 <- c(0,45,0,90,55,90)
+ t4 <- c(55,90,110,90,110,45)
+ wp <- swin(wr, rbind(t1,t2,t3,t4))
+ area.swin(wp)
+}
+\keyword{spatial}
diff --git a/man/demopat.Rd b/man/demopat.Rd
index f6cb08165afce8743dcddeb4fc99b212f043931d..d8ddf2a200fe001f3fa7a7665599ae43e5afaf72 100755
--- a/man/demopat.Rd
+++ b/man/demopat.Rd
@@ -1,22 +1,22 @@
-\name{demopat}
-\encoding{latin1}
-\alias{demopat}
-\docType{data}
-\title{Artificial Data Point Pattern from \code{spatstat} package.}
-\description{
-This is an artificial dataset, for use in testing and demonstrating compatibility between \code{spatstat} and \code{ads} objects. It is a multitype point pattern in an irregular polygonal window.
- There are two types of points. The window contains a polygonal hole.
-}
-\usage{data(demopat)}
-\format{
-An object of class "ppp" representing a \code{spatstat} point pattern.
-}
-\source{
- data(demopat) in \code{spatstat} 
-}
-\examples{
-	data(demopat)
-	demo.spp<-ppp2spp(demopat)
-	plot(demo.spp)
-}
-\keyword{datasets}
+\name{demopat}
+\encoding{latin1}
+\alias{demopat}
+\docType{data}
+\title{Artificial Data Point Pattern from \code{spatstat} package.}
+\description{
+This is an artificial dataset, for use in testing and demonstrating compatibility between \code{spatstat} and \code{ads} objects. It is a multitype point pattern in an irregular polygonal window.
+ There are two types of points. The window contains a polygonal hole.
+}
+\usage{data(demopat)}
+\format{
+An object of class "ppp" representing a \code{spatstat} point pattern.
+}
+\source{
+ data(demopat) in \code{spatstat} 
+}
+\examples{
+	data(demopat)
+	demo.spp<-ppp2spp(demopat)
+	plot(demo.spp)
+}
+\keyword{datasets}
diff --git a/man/dval.Rd b/man/dval.Rd
index 89e6050dfa3243492fd0537890867c41f8cf7a33..a5fb61e737179496d447e41c98480773ea18ca7a 100755
--- a/man/dval.Rd
+++ b/man/dval.Rd
@@ -51,22 +51,22 @@ dval(p, upto, by, nx, ny)
 \examples{
   data(BPoirier)
   BP <- BPoirier
-  # spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]
+  \dontrun{spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]}
   swr <- spp(BP$trees, win=BP$rect)
   dswr <- dval(swr,25,1,11,9)
   summary(dswr)
   plot(dswr)
   
-  # spatial point pattern in a circle with radius 50 centred on (55,45)
+  \dontrun{spatial point pattern in a circle with radius 50 centred on (55,45)}
   swc <- spp(BP$trees, win=c(55,45,45))
   dswc <- dval(swc,25,1,9,9)
   summary(dswc)
   plot(dswc)
   
-  # spatial point pattern in a complex sampling window
+  \dontrun{spatial point pattern in a complex sampling window}
   swrt <- spp(BP$trees, win=BP$rect, tri=BP$tri1)
   dswrt <- dval(swrt,25,1,11,9)
   summary(dswrt)
   plot(dswrt)
 }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/inside.swin.Rd b/man/inside.swin.Rd
index d4fed90b4f8ce43d6a92ab54ff77a03c606b316d..1807694c91a5f9574cd51f88027be3475606cbd4 100755
--- a/man/inside.swin.Rd
+++ b/man/inside.swin.Rd
@@ -1,42 +1,42 @@
-\encoding{latin1}
-\name{inside.swin}
-\alias{inside.swin}
-\title{Test wether points are inside a sampling window}
-\description{
- Function \code{inside.swin} tests whether points lie inside or outside a given sampling window.
-}
-\usage{
-inside.swin(x, y, w, bdry=TRUE)
-}
-\arguments{
-  \item{x}{a vector of \code{x} coordinates of points.}
-  \item{y}{a vector of \code{y} coordinates of points.}
-  \item{w}{an object of class \code{"swin"} (see \code{\link{swin}}) defining the sampling window.}
-  \item{bdry}{by default \code{bdry = TRUE}. If \code{FALSE}, points located 
-  on the boundary of the sampling window are considered to be outside.}
-}
-\value{
-  A logical vector whose \code{ith} entry is \code{TRUE} if the corresponding point \eqn{(x[i],y[i])} is inside w, \code{FALSE} otherwise.
-}
-\note{
- For \code{"complex"} sampling windows, points inside the triangles to remove or on their boundary, are considered outside.  
-}
-\author{
-  \email{Raphael.Pelissier@ird.fr}
-}
-\seealso{
-  \code{\link{swin}}.
-}
-\examples{
-  data(BPoirier)
-  BP <- BPoirier
-  wr <- swin(BP$rect)
-  sum(inside.swin(BP$trees$x, BP$trees$y, wr))
-  
-  wc <- swin(c(55,45,45))
-  sum(inside.swin(BP$trees$x, BP$trees$y, wc))
-  
-  wrt <- swin(BP$rect, triangles=BP$tri1)
-  sum(inside.swin(BP$trees$x, BP$trees$y,wrt))
-}
+\encoding{latin1}
+\name{inside.swin}
+\alias{inside.swin}
+\title{Test wether points are inside a sampling window}
+\description{
+ Function \code{inside.swin} tests whether points lie inside or outside a given sampling window.
+}
+\usage{
+inside.swin(x, y, w, bdry=TRUE)
+}
+\arguments{
+  \item{x}{a vector of \code{x} coordinates of points.}
+  \item{y}{a vector of \code{y} coordinates of points.}
+  \item{w}{an object of class \code{"swin"} (see \code{\link{swin}}) defining the sampling window.}
+  \item{bdry}{by default \code{bdry = TRUE}. If \code{FALSE}, points located 
+  on the boundary of the sampling window are considered to be outside.}
+}
+\value{
+  A logical vector whose \code{ith} entry is \code{TRUE} if the corresponding point \eqn{(x[i],y[i])} is inside w, \code{FALSE} otherwise.
+}
+\note{
+ For \code{"complex"} sampling windows, points inside the triangles to remove or on their boundary, are considered outside.  
+}
+\author{
+  \email{Raphael.Pelissier@ird.fr}
+}
+\seealso{
+  \code{\link{swin}}.
+}
+\examples{
+  data(BPoirier)
+  BP <- BPoirier
+  wr <- swin(BP$rect)
+  sum(inside.swin(BP$trees$x, BP$trees$y, wr))
+  
+  wc <- swin(c(55,45,45))
+  sum(inside.swin(BP$trees$x, BP$trees$y, wc))
+  
+  wrt <- swin(BP$rect, triangles=BP$tri1)
+  sum(inside.swin(BP$trees$x, BP$trees$y,wrt))
+}
 \keyword{spatial}
\ No newline at end of file
diff --git a/man/internal.Rd b/man/internal.Rd
index b2d64c4a6576d63b2fe2cba07378179f56de5370..c674c5e3cd9dfd7284896cfcf23356b9dcc4978e 100755
--- a/man/internal.Rd
+++ b/man/internal.Rd
@@ -32,6 +32,7 @@
 \alias{summary.vads.kval}
 \alias{testIC}
 \alias{testInteger}
+\alias{transpose}
 \alias{subsetdist}       
 \title{Internal ads functions}
 \description{
@@ -58,8 +59,9 @@ sortmat(dis,ind)
 subsetdist(dis,sub)
 testIC(nbSimu, lev)
 testInteger(i)
+transpose(x, y)
 }
 \details{
   These are usually not to be called by the user.
 }
-\keyword{internal}
\ No newline at end of file
+\keyword{internal}
diff --git a/man/k12fun.Rd b/man/k12fun.Rd
index 9b903949cde222916c07cf5074e0842ae3987396..80a0e626b682ddc1e3e92fbb87b2e6a64ae457f5 100755
--- a/man/k12fun.Rd
+++ b/man/k12fun.Rd
@@ -96,7 +96,7 @@ k12fun(p, upto, by, nsim=0, H0=c("pitor","pimim","rl"), prec=0.01, nsimax=3000,
 \examples{
   data(BPoirier)
   BP <- BPoirier
-  # spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]
+  \dontrun{spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]}
   swrm <- spp(BP$trees, win=BP$rect, marks=BP$species)
   #testing population independence hypothesis
   k12swrm.pi <- k12fun(swrm, 25, 1, 500, marks=c("beech","oak"))
@@ -105,17 +105,16 @@ k12fun(p, upto, by, nsim=0, H0=c("pitor","pimim","rl"), prec=0.01, nsimax=3000,
   k12swrm.rl <- k12fun(swrm, 25, 1, 500, H0="rl", marks=c("beech","oak"))
   plot(k12swrm.rl)
 
-  # spatial point pattern in a circle with radius 50 centred on (55,45)
+  \dontrun{spatial point pattern in a circle with radius 50 centred on (55,45)}
   swc <- spp(BP$trees, win=c(55,45,45), marks=BP$species)
   k12swc.pi <- k12fun(swc, 25, 1, 500, marks=c("beech","oak"))
   plot(k12swc.pi)
   
-  # spatial point pattern in a complex sampling window
+  \dontrun{spatial point pattern in a complex sampling window}
   swrt.rl <- spp(BP$trees, win=BP$rect, tri=BP$tri2, marks=BP$species)
   k12swrt.rl <- k12fun(swrt.rl, 25, 1, 500, H0="rl",marks=c("beech","oak"))
   plot(k12swrt.rl)
-  #testing population independence hypothesis
-  #requires minimizing the outer polygon
+  \dontrun{testing population independence hypothesis requires minimizing the outer polygon}
   xr<-range(BP$tri3$ax,BP$tri3$bx,BP$tri3$cx)
   yr<-range(BP$tri3$ay,BP$tri3$by,BP$tri3$cy)
   rect.min<-swin(c(xr[1], yr[1], xr[2], yr[2]))
@@ -123,4 +122,4 @@ k12fun(p, upto, by, nsim=0, H0=c("pitor","pimim","rl"), prec=0.01, nsimax=3000,
   k12swrt.pi <- k12fun(swrt.pi, 25, 1, nsim = 500, marks = c("beech", "oak"))
   plot(k12swrt.pi)
 }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/k12val.Rd b/man/k12val.Rd
index 6c70d679f3f923ee702aabcf53d4d69b119b0350..c099f18d7a353e765427f1163615d50dd7e4e9c7 100755
--- a/man/k12val.Rd
+++ b/man/k12val.Rd
@@ -1,73 +1,73 @@
-\encoding{latin1}
-\name{k12val}
-\alias{k12val}
-\alias{print.k12val}
-\alias{summary.k12val}
-\alias{print.summary.k12val}
-\title{Multiscale local second-order neighbour density of a bivariate spatial point pattern}
-\description{
- Computes local second-order neighbour density estimates for a bivariate spatial point pattern, i.e. the number of neighbours of type 2 per unit area
-  within sample circles of regularly increasing radii \eqn{r}, centred at each type 1 point of the pattern (see Details). 
-}
-\usage{
- k12val(p, upto, by, marks)
-}
-\arguments{
-  \item{p}{a \code{"spp"} object defining a multivariate spatial point pattern in a given sampling window (see \code{\link{spp}}).}
-  \item{upto }{maximum radius of the sample circles (see Details).}
-  \item{by }{interval length between successive sample circles radii (see Details).}
-  \item{marks}{by default \code{c(1,2)}, otherwise a vector of two numbers or character strings identifying the types (the \code{p$marks} levels)
-  of points of type 1 and 2, respectively.}
-}
-\details{
-  Function \code{K12val} returns individual values of \emph{K12(r)} and associated functions (see \code{\link{k12fun}})
- estimated at each type 1 point of the pattern. For a given distance \emph{r}, these values can be mapped within the sampling window, as in
- Getis & Franklin 1987 or Pélissier & Goreaud 2001. 
-}
-\value{
- A list of class \code{c("vads","k12val")} with essentially the following components:
- \item{r }{a vector of regularly spaced distances (\code{seq(by,upto,by)}).}
- \item{xy }{a data frame with 2 components giving \eqn{(x,y)} coordinates of type 1 points of the pattern.}
- \item{g12val }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the bivariate pair density function \eqn{g12(r)}.}
- \item{n12val }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the bivariate neighbour density function \eqn{n12(r)}.}
- \item{k12val }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the intertype function \eqn{K12(r)}.}
- \item{l12val }{a matrix of size \eqn{(length(xy),length(r))} giving individual values the modified intertype function \eqn{L12(r)}.}
-}
-\references{ 
- Getis, A. and Franklin, J. 1987. Second-order neighborhood analysis of mapped point patterns. \emph{Ecology}, 68:473-477.\cr\cr
-  Pélissier, R. and Goreaud, F. 2001. A practical approach to the study of spatial structure in simple cases of heterogeneous vegetation. \emph{Journal of Vegetation Science}, 12:99-108.
-}
-\author{
-	\email{Raphael.Pelissier@ird.fr}
-}
-\note{
- There are printing, summary and plotting methods for \code{"vads"} objects.
-}
-\seealso{ 
-	\code{\link{plot.vads}},
-	\code{\link{k12fun}},
-	\code{\link{dval}},
-	\code{\link{kval}}.
-}
-\examples{
-  data(BPoirier)
-  BP <- BPoirier
-  # spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]
-  swrm <- spp(BP$trees, win=BP$rect, marks=BP$species)
-  k12vswrm <- k12val(swrm, 25, 1, marks=c("beech","oak"))
-  summary(k12vswrm)
-  plot(k12vswrm)
- 
-  # spatial point pattern in a circle with radius 50 centred on (55,45)
-  swc <- spp(BP$trees, win=c(55,45,45), marks=BP$species)
-  k12vswc <- k12val(swc, 25, 1, marks=c("beech","oak"))
-  summary(k12vswc)
-  plot(k12vswc)
-  
-  # spatial point pattern in a complex sampling window
-  swrt <- spp(BP$trees, win=BP$rect, tri=BP$tri2, marks=BP$species)
-  k12vswrt <- k12val(swrt, 25, 1, marks=c("beech","oak"))
-  summary(k12vswrt)
-  plot(k12vswrt)
-}
-\keyword{spatial}
+\encoding{latin1}
+\name{k12val}
+\alias{k12val}
+\alias{print.k12val}
+\alias{summary.k12val}
+\alias{print.summary.k12val}
+\title{Multiscale local second-order neighbour density of a bivariate spatial point pattern}
+\description{
+ Computes local second-order neighbour density estimates for a bivariate spatial point pattern, i.e. the number of neighbours of type 2 per unit area
+  within sample circles of regularly increasing radii \eqn{r}, centred at each type 1 point of the pattern (see Details). 
+}
+\usage{
+ k12val(p, upto, by, marks)
+}
+\arguments{
+  \item{p}{a \code{"spp"} object defining a multivariate spatial point pattern in a given sampling window (see \code{\link{spp}}).}
+  \item{upto }{maximum radius of the sample circles (see Details).}
+  \item{by }{interval length between successive sample circles radii (see Details).}
+  \item{marks}{by default \code{c(1,2)}, otherwise a vector of two numbers or character strings identifying the types (the \code{p$marks} levels)
+  of points of type 1 and 2, respectively.}
+}
+\details{
+  Function \code{K12val} returns individual values of \emph{K12(r)} and associated functions (see \code{\link{k12fun}})
+ estimated at each type 1 point of the pattern. For a given distance \emph{r}, these values can be mapped within the sampling window, as in
+ Getis & Franklin 1987 or Pélissier & Goreaud 2001. 
+}
+\value{
+ A list of class \code{c("vads","k12val")} with essentially the following components:
+ \item{r }{a vector of regularly spaced distances (\code{seq(by,upto,by)}).}
+ \item{xy }{a data frame with 2 components giving \eqn{(x,y)} coordinates of type 1 points of the pattern.}
+ \item{g12val }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the bivariate pair density function \eqn{g12(r)}.}
+ \item{n12val }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the bivariate neighbour density function \eqn{n12(r)}.}
+ \item{k12val }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the intertype function \eqn{K12(r)}.}
+ \item{l12val }{a matrix of size \eqn{(length(xy),length(r))} giving individual values the modified intertype function \eqn{L12(r)}.}
+}
+\references{ 
+ Getis, A. and Franklin, J. 1987. Second-order neighborhood analysis of mapped point patterns. \emph{Ecology}, 68:473-477.\cr\cr
+  Pélissier, R. and Goreaud, F. 2001. A practical approach to the study of spatial structure in simple cases of heterogeneous vegetation. \emph{Journal of Vegetation Science}, 12:99-108.
+}
+\author{
+	\email{Raphael.Pelissier@ird.fr}
+}
+\note{
+ There are printing, summary and plotting methods for \code{"vads"} objects.
+}
+\seealso{ 
+	\code{\link{plot.vads}},
+	\code{\link{k12fun}},
+	\code{\link{dval}},
+	\code{\link{kval}}.
+}
+\examples{
+  data(BPoirier)
+  BP <- BPoirier
+  \dontrun{spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]}
+  swrm <- spp(BP$trees, win=BP$rect, marks=BP$species)
+  k12vswrm <- k12val(swrm, 25, 1, marks=c("beech","oak"))
+  summary(k12vswrm)
+  plot(k12vswrm)
+ 
+  \dontrun{spatial point pattern in a circle with radius 50 centred on (55,45)}
+  swc <- spp(BP$trees, win=c(55,45,45), marks=BP$species)
+  k12vswc <- k12val(swc, 25, 1, marks=c("beech","oak"))
+  summary(k12vswc)
+  plot(k12vswc)
+  
+  \dontrun{spatial point pattern in a complex sampling window}
+  swrt <- spp(BP$trees, win=BP$rect, tri=BP$tri2, marks=BP$species)
+  k12vswrt <- k12val(swrt, 25, 1, marks=c("beech","oak"))
+  summary(k12vswrt)
+  plot(k12vswrt)
+}
+\keyword{spatial}
diff --git a/man/kdfun.Rd b/man/kdfun.Rd
index 735a4365c68a64501be5a839f3fc9dcf6ce9a5cc..c750e416235aa68f11cca80a4c58a93859a95267 100755
--- a/man/kdfun.Rd
+++ b/man/kdfun.Rd
@@ -67,26 +67,26 @@ kdfun(p, upto, by, dis, nsim=0, alpha = 0.01)
 \examples{
   data(Paracou15)
   P15<-Paracou15
-  # spatial point pattern in a rectangle sampling window of size 125 x 125
+  \dontrun{spatial point pattern in a rectangle sampling window of size 125 x 125}
   swmr <- spp(P15$trees, win = c(175, 175, 250, 250), marks = P15$species)
-  # testing the species equivalence hypothesis
+  \dontrun{testing the species equivalence hypothesis}
   kdswmr <- kdfun(swmr, dis = P15$spdist, 50, 2, 100)
-  #running more simulations is slow
-  #kdswmr <- drfun(swmr, dis = P15$spdist, 50, 2, 500)
+  \dontrun{running more simulations is slow}
+  \donttest{kdswmr <- kdfun(swmr, dis = P15$spdist, 50, 2, 500)}
   plot(kdswmr)
 
-  # spatial point pattern in a circle with radius 50 centred on (125,125)
+ \dontrun{spatial point pattern in a circle with radius 50 centred on (125,125)}
   swmc <- spp(P15$trees, win = c(125,125,50), marks = P15$species)
   kdswmc <- kdfun(swmc, dis = P15$spdist, 50, 2, 100)
-  #running more simulations is slow
-  #kdswmc <- kdfun(swmc, dis = P15$spdist, 50, 2, 500)
+  \dontrun{running more simulations is slow}
+  \donttest{kdswmc <- kdfun(swmc, dis = P15$spdist, 50, 2, 500)}
   plot(kdswmc)
   
-  # spatial point pattern in a complex sampling window
+ \dontrun{spatial point pattern in a complex sampling window}
   swrt <- spp(P15$trees, win = c(125,125,250,250), tri = P15$tri, marks = P15$species)
   kdswrt <- kdfun(swrt, dis = P15$spdist, 50, 2, 100)
-  #running simulations is slow
-  #kdswrt <- kdfun(swrt, dis = P15$spdist, 50, 2, 500)
+  \dontrun{running simulations is slow}
+  \donttest{kdswrt <- kdfun(swrt, dis = P15$spdist, 50, 2, 500)}
   plot(kdswrt)
 }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/kfun.Rd b/man/kfun.Rd
index 43a130559ec8b6ff0861193bcc1fcfcb48687958..ae21fd018baac573417fc7238ca8aa552c58c623 100755
--- a/man/kfun.Rd
+++ b/man/kfun.Rd
@@ -82,19 +82,19 @@ kfun(p, upto, by, nsim=0, prec=0.01, alpha=0.01)
 \examples{
   data(BPoirier)
   BP <- BPoirier
-  # spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]
+  \dontrun{spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]}
   swr <- spp(BP$trees, win=BP$rect)
   kswr <- kfun(swr,25,1,500)
   plot(kswr)
 
-  # spatial point pattern in a circle with radius 50 centred on (55,45)
+  \dontrun{spatial point pattern in a circle with radius 50 centred on (55,45)}
   swc <- spp(BP$trees, win=c(55,45,45))
   kswc <- kfun(swc, 25, 1, 500)
   plot(kswc)
   
-  # spatial point pattern in a complex sampling window
+  \dontrun{spatial point pattern in a complex sampling window}
   swrt <- spp(BP$trees, win=BP$rect, tri=BP$tri1)
   kswrt <- kfun(swrt, 25, 1, 500)
   plot(kswrt)
 }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/kmfun.Rd b/man/kmfun.Rd
index bc39f5a49f988c43b2ac5a86418d750a6508e0fa..0e6fb60b4055e1e7db0535f4cf9ecf7fcb755fe6 100755
--- a/man/kmfun.Rd
+++ b/man/kmfun.Rd
@@ -70,17 +70,17 @@ Ripley B.D. 1977. Modelling spatial patterns. \emph{Journal of the Royal Statist
 \examples{
   data(BPoirier)
   BP <- BPoirier
-  # spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]
+  \dontrun{spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]}
   swrm <- spp(BP$trees, win=BP$rect, marks=BP$dbh)
   kmswrm <- kmfun(swrm, 25, 2, 500)
   plot(kmswrm)
   
-  # spatial point pattern in a circle with radius 50 centred on (55,45)
+  \dontrun{spatial point pattern in a circle with radius 50 centred on (55,45)}
   swc <- spp(BP$trees, win=c(55,45,45), marks=BP$dbh)
   kmswc <- kmfun(swc, 25, 2, 500)
   plot(kmswc)
 
-  # spatial point pattern in a complex sampling window
+  \dontrun{spatial point pattern in a complex sampling window}
   swrt <- spp(BP$trees, win=BP$rect, tri=BP$tri2, marks=BP$dbh)
   kmswrt <- kmfun(swrt, 25, 2, 500)
   plot(kmswrt)
diff --git a/man/kp.fun.Rd b/man/kp.fun.Rd
index c42e544dcb208b975cdfbf35a89c1cec66f80103..45d9d9641f92377b1373808b5bffa6ab75df5157 100755
--- a/man/kp.fun.Rd
+++ b/man/kp.fun.Rd
@@ -46,17 +46,17 @@ kp.fun(p, upto, by)
 \examples{
   data(BPoirier)
   BP <- BPoirier
-  # multivariate spatial point pattern in a rectangle sampling window 
+  \dontrun{multivariate spatial point pattern in a rectangle sampling window}
   swrm <- spp(BP$trees, win=BP$rect, marks=BP$species)
   kp.swrm <- kp.fun(swrm, 25, 1)
   plot(kp.swrm)
   
- # multivariate spatial point pattern in a circle with radius 50 centred on (55,45)
+ \dontrun{multivariate spatial point pattern in a circle with radius 50 centred on (55,45)}
   swcm <- spp(BP$trees, win=c(55,45,45), marks=BP$species)
   kp.swcm <- kp.fun(swcm, 25, 1)
   plot(kp.swcm)
   
-  # multivariate spatial point pattern in a complex sampling window
+  \dontrun{multivariate spatial point pattern in a complex sampling window}
   swrtm <- spp(BP$trees, win=BP$rect, tri=BP$tri2, marks=BP$species)
   kp.swrtm <- kp.fun(swrtm, 25, 1)
   plot(kp.swrtm)
diff --git a/man/kpqfun.Rd b/man/kpqfun.Rd
index 3fa67d10513b18c5391d2d8341fcd570cc0666fb..31243d7ebbbe0de6a192a34fd48e47e5e28f1a03 100755
--- a/man/kpqfun.Rd
+++ b/man/kpqfun.Rd
@@ -47,17 +47,17 @@ A list of class \code{"fads"} with essentially the following components:
 \examples{
   data(BPoirier)
   BP <- BPoirier
-  # multivariate spatial point pattern in a rectangle sampling window 
+ \dontrun{multivariate spatial point pattern in a rectangle sampling window}
   swrm <- spp(BP$trees, win=BP$rect, marks=BP$species)
   kpqswrm <- kpqfun(swrm, 25, 1)
   plot(kpqswrm)
   
- # multivariate spatial point pattern in a circle with radius 50 centred on (55,45)
+ \dontrun{multivariate spatial point pattern in a circle with radius 50 centred on (55,45)}
   swcm <- spp(BP$trees, win=c(55,45,45), marks=BP$species)
   kpqswcm <- kpqfun(swcm, 25, 1)
   plot(kpqswcm)
   
-  # multivariate spatial point pattern in a complex sampling window
+  \dontrun{multivariate spatial point pattern in a complex sampling window}
   swrtm <- spp(BP$trees, win=BP$rect, tri=BP$tri2, marks=BP$species)
   kpqswrtm <- kpqfun(swrtm, 25, 1)
   plot(kpqswrtm)
diff --git a/man/krfun.Rd b/man/krfun.Rd
index 4232582d526e9ad8f632a0ae8b226761598f0a6c..dba05d15c87591688b49f4665a2d6d6ae8a7ea7b 100755
--- a/man/krfun.Rd
+++ b/man/krfun.Rd
@@ -54,7 +54,7 @@ The species equivalence hypothesis (H0 = "se") is tested by randomizing the betw
 \references{
  Rao, C.R. 1982. Diversity and dissimilarity coefficient: a unified approach. \emph{Theoretical Population Biology}, 21:24-43.
 
- Shimatani, K. 2001. On the measurement of species diversity incorporating species differences. \emph{Oïkos}, 93, 135-147.
+ Shimatani, K. 2001. On the measurement of species diversity incorporating species differences. \emph{Oikos}, 93, 135-147.
  
  Goreaud F. & Pélissier R. 1999. On explicit formulas of edge effect correction for Ripley's K-function. \emph{Journal of Vegetation Science}, 10:433-438.
 
@@ -77,31 +77,31 @@ The species equivalence hypothesis (H0 = "se") is tested by randomizing the betw
 \examples{
   data(Paracou15)
   P15<-Paracou15
-  # spatial point pattern in a rectangle sampling window of size 125 x 125
+  \dontrun{spatial point pattern in a rectangle sampling window of size 125 x 125}
   swmr <- spp(P15$trees, win = c(175, 175, 250, 250), marks = P15$species)
-  # testing the random labeling hypothesis
+  \dontrun{testing the random labeling hypothesis}
   krwmr.rl <- krfun(swmr, dis = P15$spdist, H0 = "rl", 25, 2, 50)
-  #running more simulations is slow
-  #krwmr.rl <- krfun(swmr, dis = P15$spdist, H0 = "rl", 25, 2, 500)
+  \dontrun{running more simulations is slow}
+  \donttest{krwmr.rl <- krfun(swmr, dis = P15$spdist, H0 = "rl", 25, 2, 500)}
   plot(krwmr.rl)
-  # testing the species equivalence hypothesis
+  \dontrun{testing the species equivalence hypothesis}
   krwmr.se <- krfun(swmr, dis = P15$spdist, H0 = "se", 25, 2, 50)
-  #running more simulations is slow
-  #krwmr.se <- krfun(swmr, dis = P15$spdist, H0 = "se", 25, 2, 500)
+  \dontrun{running more simulations is slow}
+  \donttest{krwmr.se <- krfun(swmr, dis = P15$spdist, H0 = "se", 25, 2, 500)}
   plot(krwmr.se)
 
-  # spatial point pattern in a circle with radius 50 centred on (125,125)
+  \dontrun{spatial point pattern in a circle with radius 50 centred on (125,125)}
   swmc <- spp(P15$trees, win = c(125,125,50), marks = P15$species)
   krwmc <- krfun(swmc, dis = P15$spdist, H0 = "rl", 25, 2, 100)
-  #running more simulations is slow
-  #krwmc <- krfun(swmc, dis = P15$spdist, H0 = "rl, 25, 2, 500)
+  \dontrun{running more simulations is slow}
+  \donttest{krwmc <- krfun(swmc, dis = P15$spdist, H0 = "rl", 25, 2, 500)}
   plot(krwmc)
   
-  # spatial point pattern in a complex sampling window
+  \dontrun{spatial point pattern in a complex sampling window}
   swrt <- spp(P15$trees, win = c(125,125,250,250), tri = P15$tri, marks = P15$species)
   krwrt <- krfun(swrt, dis = P15$spdist, H0 = "rl", 25, 2)
-  #running simulations is slow
-  #krwrt <- krfun(swrt, dis = P15$spdist, H0 = "rl", 25, 2, 500)
+  \dontrun{running simulations is slow}
+  \donttest{krwrt <- krfun(swrt, dis = P15$spdist, H0 = "rl", 25, 2, 500)}
   plot(krwrt)
 }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/ksfun.Rd b/man/ksfun.Rd
index 55259a2d0543bdef412b314b42fddec9f72035fa..cd96eb47bf4a4b10069eb0e984aadd7dd188fff3 100755
--- a/man/ksfun.Rd
+++ b/man/ksfun.Rd
@@ -52,7 +52,7 @@ ksfun(p, upto, by, nsim=0, alpha=0.01)
 \references{
  Shimatani K. 2001. Multivariate point processes and spatial variation in species diversity. \emph{Forest Ecology and Managaement}, 142:215-229.
 
- Eckel, S., Fleisher, F., Grabarnik, P. and Schmidt V. 2008. An investigation of the spatial correlations for relative purchasing power in Baden-Württemberg. \emph{AstA - Advances in Statistical Analysis}, 92:135-152.
+ Eckel, S., Fleisher, F., Grabarnik, P. and Schmidt V. 2008. An investigation of the spatial correlations for relative purchasing power in Baden-Wurttemberg. \emph{AstA - Advances in Statistical Analysis}, 92:135-152.
  
  Simpson, E.H. 1949. Measurement of diversity. \emph{Nature}, 688:163.
  
@@ -75,19 +75,19 @@ ksfun(p, upto, by, nsim=0, alpha=0.01)
 \examples{
   data(Paracou15)
   P15<-Paracou15
-  # spatial point pattern in a rectangle sampling window of size 125 x 125
+  \dontrun{spatial point pattern in a rectangle sampling window of size 125 x 125}
   swmr <- spp(P15$trees, win = c(125, 125, 250, 250), marks = P15$species)
   kswmr <- ksfun(swmr, 50, 5, 500)
   plot(kswmr)
 
-  # spatial point pattern in a circle with radius 50 centred on (125,125)
+  \dontrun{spatial point pattern in a circle with radius 50 centred on (125,125)}
   swmc <- spp(P15$trees, win = c(125, 125, 50), marks = P15$species)
   kswmc <- ksfun(swmc, 50, 5, 500)
   plot(kswmc)
   
-  # spatial point pattern in a complex sampling window
+  \dontrun{spatial point pattern in a complex sampling window}
   swrt <- spp(P15$trees, win = c(125, 125, 250, 250), tri=P15$tri, marks=P15$species)
   kswrt <- ksfun(swrt, 50, 5, 500)
   plot(kswrt)
 }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/kval.Rd b/man/kval.Rd
index ac9f740c4f4fa4f6e0e06b15294b3c9ef4347648..11f5a8dc2711c111bdb4a7aed8707bf4965191c9 100755
--- a/man/kval.Rd
+++ b/man/kval.Rd
@@ -1,74 +1,74 @@
-\encoding{latin1}
-\name{kval}
-\alias{kval}
-\alias{print.kval}
-\alias{summary.kval}
-\alias{print.summary.kval}
-\title{Multiscale local second-order neighbour density of a spatial point pattern}
-\description{
- Computes local second-order neighbour density estimates for an univariate spatial point pattern, i.e. the number of neighbours per unit area
-  within sample circles of regularly increasing radii \eqn{r}, centred at each point of the pattern (see Details). 
-}
-\usage{
-  kval(p, upto, by)
-}
-\arguments{
-  \item{p}{a \code{"spp"} object defining a spatial point pattern in a given sampling window (see \code{\link{spp}}).}
-  \item{upto }{maximum radius of the sample circles (see Details).}
-  \item{by }{interval length between successive sample circles radii (see Details).}
-}
-\details{
- Function \code{kval} returns indivdiual values of \emph{K(r)} and associated functions (see \code{\link{kfun}})
- estimated for each point of the pattern. For a given distance \emph{r}, these values can be mapped within the sampling window 
- (Getis & Franklin 1987, Pélissier & Goreaud 2001).  
-}
-\value{
-A list of class \code{c("vads","kval")} with essentially the following components:
- \item{r }{a vector of regularly spaced out distances (\code{seq(by,upto,by)}).}
- \item{xy }{a data frame with 2 components giving \eqn{(x,y)} coordinates of points of the pattern.}
- \item{gval }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the pair density function \eqn{g(r)}.}
- \item{nval }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the neighbour density function \eqn{n(r)}.}
- \item{kval }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of Ripley's function \eqn{K(r)}.}
- \item{lval }{a matrix of size \eqn{(length(xy),length(r))} giving individual values the modified Ripley's function \eqn{L(r)}.}
- }
-\references{ 
-  Getis, A. and Franklin, J. 1987. Second-order neighborhood analysis of mapped point patterns. \emph{Ecology}, 68:473-477.\cr\cr
-  Pélissier, R. and Goreaud, F. 2001. A practical approach to the study of spatial structure in simple cases of heterogeneous vegetation. \emph{Journal of Vegetation Science}, 12:99-108.
-}
-\author{
-	\email{Raphael.Pelissier@ird.fr}
-}
-\note{
- There are printing, summary and plotting methods for \code{"vads"} objects.
-}
-\section{Warning }{
-  Function \code{kval} ignores the marks of multivariate and marked point patterns (they are all considered to be univariate patterns).
-}
-\seealso{
-	\code{\link{plot.vads}},
-	\code{\link{kfun}},
-	\code{\link{dval}},
-	\code{\link{k12val}}.
-}
-\examples{
-  data(BPoirier)
-  BP <- BPoirier
-  # spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]
-  swr <- spp(BP$trees, win=BP$rect)
-  kvswr <- kval(swr, 25, 1)
-  summary(kvswr)
-  plot(kvswr)
-
-  # spatial point pattern in a circle with radius 50 centred on (55,45)
-  swc <- spp(BP$trees, win=c(55,45,45))
-  kvswc <- kval(swc, 25, 1)
-  summary(kvswc)
-  plot(kvswc)
-  
-  # spatial point pattern in a complex sampling window
-  swrt <- spp(BP$trees, win=BP$rect, tri=BP$tri1)
-  kvswrt <- kval(swrt, 25, 1)
-  summary(kvswrt)
-  plot(kvswrt)
-}
-\keyword{spatial}
\ No newline at end of file
+\encoding{latin1}
+\name{kval}
+\alias{kval}
+\alias{print.kval}
+\alias{summary.kval}
+\alias{print.summary.kval}
+\title{Multiscale local second-order neighbour density of a spatial point pattern}
+\description{
+ Computes local second-order neighbour density estimates for an univariate spatial point pattern, i.e. the number of neighbours per unit area
+  within sample circles of regularly increasing radii \eqn{r}, centred at each point of the pattern (see Details). 
+}
+\usage{
+  kval(p, upto, by)
+}
+\arguments{
+  \item{p}{a \code{"spp"} object defining a spatial point pattern in a given sampling window (see \code{\link{spp}}).}
+  \item{upto }{maximum radius of the sample circles (see Details).}
+  \item{by }{interval length between successive sample circles radii (see Details).}
+}
+\details{
+ Function \code{kval} returns indivdiual values of \emph{K(r)} and associated functions (see \code{\link{kfun}})
+ estimated for each point of the pattern. For a given distance \emph{r}, these values can be mapped within the sampling window 
+ (Getis & Franklin 1987, Pélissier & Goreaud 2001).  
+}
+\value{
+A list of class \code{c("vads","kval")} with essentially the following components:
+ \item{r }{a vector of regularly spaced out distances (\code{seq(by,upto,by)}).}
+ \item{xy }{a data frame with 2 components giving \eqn{(x,y)} coordinates of points of the pattern.}
+ \item{gval }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the pair density function \eqn{g(r)}.}
+ \item{nval }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of the neighbour density function \eqn{n(r)}.}
+ \item{kval }{a matrix of size \eqn{(length(xy),length(r))} giving individual values of Ripley's function \eqn{K(r)}.}
+ \item{lval }{a matrix of size \eqn{(length(xy),length(r))} giving individual values the modified Ripley's function \eqn{L(r)}.}
+ }
+\references{ 
+  Getis, A. and Franklin, J. 1987. Second-order neighborhood analysis of mapped point patterns. \emph{Ecology}, 68:473-477.\cr\cr
+  Pélissier, R. and Goreaud, F. 2001. A practical approach to the study of spatial structure in simple cases of heterogeneous vegetation. \emph{Journal of Vegetation Science}, 12:99-108.
+}
+\author{
+	\email{Raphael.Pelissier@ird.fr}
+}
+\note{
+ There are printing, summary and plotting methods for \code{"vads"} objects.
+}
+\section{Warning }{
+  Function \code{kval} ignores the marks of multivariate and marked point patterns (they are all considered to be univariate patterns).
+}
+\seealso{
+	\code{\link{plot.vads}},
+	\code{\link{kfun}},
+	\code{\link{dval}},
+	\code{\link{k12val}}.
+}
+\examples{
+  data(BPoirier)
+  BP <- BPoirier
+  \dontrun{spatial point pattern in a rectangle sampling window of size [0,110] x [0,90]}
+  swr <- spp(BP$trees, win=BP$rect)
+  kvswr <- kval(swr, 25, 1)
+  summary(kvswr)
+  plot(kvswr)
+
+  \dontrun{spatial point pattern in a circle with radius 50 centred on (55,45)}
+  swc <- spp(BP$trees, win=c(55,45,45))
+  kvswc <- kval(swc, 25, 1)
+  summary(kvswc)
+  plot(kvswc)
+  
+  \dontrun{spatial point pattern in a complex sampling window}
+  swrt <- spp(BP$trees, win=BP$rect, tri=BP$tri1)
+  kvswrt <- kval(swrt, 25, 1)
+  summary(kvswrt)
+  plot(kvswrt)
+}
+\keyword{spatial}
diff --git a/man/mimetic.Rd b/man/mimetic.Rd
index a7ea80973f4677883b7324a377a55356ccd88518..d2ad7dbb3fc21a0a7e7c6e95e19a3d04ca35c9e9 100755
--- a/man/mimetic.Rd
+++ b/man/mimetic.Rd
@@ -48,17 +48,17 @@ mimetic(x,upto=NULL,by=NULL,prec=NULL,nsimax=3000,conv=50)
 \examples{
   data(BPoirier)
   BP<-BPoirier
-  # performing point pattern analysis in a rectangle sampling window
+  \dontrun{performing point pattern analysis in a rectangle sampling window}
   swr <- spp(BP$trees, win=BP$rect)
   plot(swr)
   
-  # performing the mimetic point process from "spp" object
+  \dontrun{performing the mimetic point process from "spp" object}
   mimswr <- mimetic(swr, 20, 2)
   plot(mimswr)
 
-   # performing the mimetic point process from "fads" object
+  \dontrun{performing the mimetic point process from "fads" object}
   mimkswr <- mimetic(kfun(swr, 20, 2))
   plot(mimkswr)
   
   }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/plot.fads.Rd b/man/plot.fads.Rd
index 409277b1057e5886e399f866d942bc2aaf70cb25..cb629ecceff9c9651a218718dbf2a94bb23994a4 100755
--- a/man/plot.fads.Rd
+++ b/man/plot.fads.Rd
@@ -47,17 +47,17 @@
 \examples{
   data(BPoirier)
   BP <- BPoirier
-  # Ripley's function 
+  \dontrun{Ripley's function}
   swr <- spp(BP$trees, win=BP$rect)
   k.swr <- kfun(swr, 25, 1, 500)
   plot(k.swr)
   
-  # Intertype function
+  \dontrun{Intertype function}
   swrm <- spp(BP$trees, win=BP$rect, marks=BP$species)
   k12.swrm <- k12fun(swrm, 25, 1, 500, marks=c("beech","oak"))
   plot(k12.swrm, opt="L", cols=1)
   
-  # Mark correlation function
+  \dontrun{Mark correlation function}
   swrm <- spp(BP$trees, win=BP$rect, marks=BP$dbh)
   km.swrm <- kmfun(swrm, 25, 1, 500)
   plot(km.swrm, main="Example 1", sub=NULL, legend=FALSE)
diff --git a/man/plot.spp.Rd b/man/plot.spp.Rd
index 9f0503a15500420ab9cc6f418e08985b080c1170..9454e65a5d89ce53a53cc91562fae3bae38256ec 100755
--- a/man/plot.spp.Rd
+++ b/man/plot.spp.Rd
@@ -67,32 +67,29 @@ Then the points themselves are plotted, in a fashion that depends on the type of
   data(BPoirier)
   BP<-BPoirier
   
-  # a univariate point pattern in a rectangle sampling window
+  \dontrun{a univariate point pattern in a rectangle sampling window}
   plot(spp(BP$trees, win=BP$rect))
   
- # a univariate point pattern in a circular sampling window
- #with all points and graduations displayed
+  \dontrun{a univariate point pattern in a circular sampling window}
  plot(spp(BP$trees, win=c(55,45,45)), out=TRUE, scale=TRUE)
  
- # a univariate point pattern in a complex sampling window
- #with points outside the sampling window displayed (in red colour)
+ \dontrun{a univariate point pattern in a complex sampling window}
+ \dontrun{(points outside the sampling window displayed in red colour)}
  plot(spp(BP$trees, win=BP$rect, tri=BP$tri1), out=TRUE)
   
- # a multivariate point pattern in a rectangle sampling window
+ \dontrun{a multivariate point pattern in a rectangle sampling window}
  plot(spp(BP$trees, win=BP$rect, marks=BP$species))
  
- # a multivariate point pattern in a circular sampling window
- #with all points inside the sampling window displayed in blue colour
- #and all points outside displayed with the symbol "+" in red colour
+ \dontrun{a multivariate point pattern in a circular sampling window}
+ \dontrun{(points inside/outside the sampling window displayed in blue colour/as red crosses)}
  plot(spp(BP$trees, win=c(55,45,45), marks=BP$species), out=TRUE, cols=c("blue","blue","blue"), 
  chars.out=c("+","+","+"), cols.out=c("red","red","red"))
  
- # a marked point pattern in a rectangle sampling window
- #with circles in green colour
+  \dontrun{a marked point pattern in a rectangle sampling window with circles in green colour}
   plot(spp(BP$trees, win=BP$rect, marks=BP$dbh), cols="green")
 
- # a marked point pattern in a circular sampling window
- #with squares in red colour inside and circles in blue colour outside
+  \dontrun{a marked point pattern in a circular sampling window}
+  \dontrun{(squares in red colour inside and circles in blue colour outside)}
   plot(spp(BP$trees, win=c(55,45,45), marks=BP$dbh), out=TRUE, chars="squares", 
   cols="red", cols.out="blue")
 }
diff --git a/man/plot.vads.Rd b/man/plot.vads.Rd
index 6deced86b6eed3680ebbd1ba8e74a50f8eab9f72..a2f212ec140e6598e53204a17627d4fd5c839741 100755
--- a/man/plot.vads.Rd
+++ b/man/plot.vads.Rd
@@ -54,19 +54,19 @@ type of \code{'vads'} object:
 \examples{
   data(BPoirier)
   BP <- BPoirier
-  # local density in a rectangle sampling window
+  \dontrun{local density in a rectangle sampling window}
   dswr <- dval(spp(BP$trees, win=BP$rect), 25, 1, 11, 9)
   plot(dswr)
-  # display only distance r from 5 to 10 with null symbols as red crosses
+  \dontrun{display only distance r from 5 to 10 with null symbols as red crosses}
   plot(dswr, select=c(5:10), char0=3, col0="red")
   
-  # local L(r) values in a circular sampling window
+  \dontrun{local L(r) values in a circular sampling window}
   lvswc <- kval(spp(BP$trees, win=c(55,45,45)), 25, 0.5)
   plot(lvswc)
-  # display square symbols in blue for selected values of r and remove title
+  \dontrun{display square symbols in blue for selected values of r and remove title}
   plot(lvswc, chars="squares", cols="blue", select=c(5,7.5,10,12.5,15), main=NULL)
   
-   # local K12(r) values (1="beech", 2="oak") in a complex sampling window
+  \dontrun{local K12(r) values (1="beech", 2="oak") in a complex sampling window}
   k12swrt <- k12val(spp(BP$trees, win=BP$rect, tri=BP$tri1, marks=BP$species), 25, 1)
   plot(k12swrt, opt="kval")
 }
diff --git a/man/spp.Rd b/man/spp.Rd
index 93c86d9f3b95a578a7e18637ceea48cea89ecff4..39f97cc8cf475e4c61008f882c60c2b50b7c087d 100755
--- a/man/spp.Rd
+++ b/man/spp.Rd
@@ -74,40 +74,40 @@ Function \code{ppp2spp} converts an \code{\link[spatstat]{ppp.object}} from pack
 \examples{
 	data(BPoirier)
 	BP <- BPoirier
-	# univariate pattern in a rectangle of size [0,110] x [0,90]
+	\dontrun{univariate pattern in a rectangle of size [0,110] x [0,90]}
 	swr <- spp(BP$trees, win=BP$rect)
-	# an alternative using atomic vectors of point coordinates
-	#swr <- spp(BP$trees, win=BP$rect) 
+	\dontrun{an alternative using atomic vectors of point coordinates}
+	swr <- spp(BP$trees, win=BP$rect) 
 	summary(swr)
 	plot(swr)
 	
-	# univariate pattern in a circle with radius 50 centred on (55,45)
+	\dontrun{univariate pattern in a circle with radius 50 centred on (55,45)}
 	swc <- spp(BP$trees, win=c(55,45,50))
 	summary(swc)
 	plot(swc)
 	plot(swc, out=TRUE) # plot points outside the circle
 
-	# multivariate pattern in a rectangle of size [0,110] x [0,90]
+	\dontrun{multivariate pattern in a rectangle of size [0,110] x [0,90]}
 	swrm <- spp(BP$trees, win=BP$rect, marks=BP$species)
 	summary(swrm)
 	plot(swrm)
 	plot(swrm, chars=c("b","h","o")) # replace symbols by letters
 	
-	# marked pattern in a rectangle of size [0,110] x [0,90]
+	\dontrun{marked pattern in a rectangle of size [0,110] x [0,90]}
 	swrn <- spp(BP$trees, win=BP$rect, marks=BP$dbh)
 	summary(swrn)
 	plot(swrn)
 	
-	# multivariate pattern in a complex sampling window
+	\dontrun{multivariate pattern in a complex sampling window}
 	swrt <- spp(BP$trees, win=BP$rect, tri=BP$tri1, marks=BP$species)
 	summary(swrt)
 	plot(swrt)
 	plot(swrt, out=TRUE) # plot points outside the sampling window
 	
 	
-	#converting a ppp object from spatstat
+	\dontrun{converting a ppp object from spatstat}
 	data(demopat)
 	demo.spp<-ppp2spp(demopat)
 	plot(demo.spp)
 }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/swin.Rd b/man/swin.Rd
index 8fcf150425aa62b076fb00a5d3134fa62a294437..bce930f995728822e9cdb6eca42490bfc0690981 100755
--- a/man/swin.Rd
+++ b/man/swin.Rd
@@ -70,17 +70,17 @@ Function \code{owin2swin} converts an \code{\link[spatstat]{owin.object}} from p
  \email{Raphael.Pelissier@ird.fr}
 }
 \examples{
-  #rectangle of size [0,110] x [0,90]
+  \dontrun{rectangle of size [0,110] x [0,90]}
   wr <- swin(c(0,0,110,90))
   summary(wr)
   plot(wr)
   
-  #circle with radius 50 centred on (55,45)
+  \dontrun{circle with radius 50 centred on (55,45)}
   wc <- swin(c(55,45,50))
   summary(wc)
   plot(wc)
   
- # polygon (diamond shape)
+ \dontrun{polygon (diamond shape)}
  t1 <- c(0,0,55,0,0,45)
  t2 <- c(55,0,110,0,110,45)
  t3 <- c(0,45,0,90,55,90)
@@ -89,21 +89,21 @@ Function \code{owin2swin} converts an \code{\link[spatstat]{owin.object}} from p
  summary(wp)
  plot(wp)
  
- #rectangle with a hole
+ \dontrun{rectangle with a hole}
  h1 <- c(25,45,55,75,85,45)
  h2 <- c(25,45,55,15,85,45)
  wrh <- swin(wr, rbind(h1,h2))
  summary(wrh)
  plot(wrh)
 
- #circle with a hole
+ \dontrun{circle with a hole}
  wch <- swin(wc, rbind(h1,h2))
  summary(wch)
  plot(wch)
  
- #converting an owin object from spatstat
+ \dontrun{converting an owin object from spatstat}
  data(demopat)
  demo.swin<-owin2swin(demopat$window)
  plot(demo.swin)
 }
-\keyword{spatial}
\ No newline at end of file
+\keyword{spatial}
diff --git a/man/triangulate.Rd b/man/triangulate.Rd
index e2a4579553797a443f3b0f55fddf26dc3b14f800..d15e2fdb01f977ab37dccc5f13c9ad0b41cc09b4 100755
--- a/man/triangulate.Rd
+++ b/man/triangulate.Rd
@@ -43,19 +43,19 @@ is \eqn{(n-2)+2t}, with \eqn{n<200} in this version of the program.
   BP <- BPoirier
   plot(BP$poly1$x, BP$poly1$y)
   
-  # a single polygon triangulation
+  \dontrun{a single polygon triangulation}
   tri1 <- triangulate(BP$poly1)
   plot(swin(BP$rect, tri1))
   
-  # a single polygon with a hole
-  #tri2 <- triangulate(c(-10,-10,120,100), BP$poly1)
-  #plot(swin(c(-10,-10,120,100), tri2))
+  \dontrun{a single polygon with a hole}
+  \donttest{tri2 <- triangulate(c(-10,-10,120,100), BP$poly1)
+  plot(swin(c(-10,-10,120,100), tri2))}
   
-  # the same with narrower outer polygon
-  #tri3 <- lapply(BP$poly2,triangulate)
-  #tri3<-do.call(rbind,tri3)
-  #xr<-range(tri3$ax,tri3$bx,tri3$cx)
-  #yr<-range(tri3$ay,tri3$by,tri3$cy)
-  #plot(swin(c(xr[1],yr[1],xr[2],yr[2]), tri3))
-  }
+  \dontrun{the same with narrower outer polygon}
+  \donttest{tri3 <- lapply(BP$poly2,triangulate)
+  tri3<-do.call(rbind,tri3)
+  xr<-range(tri3$ax,tri3$bx,tri3$cx)
+  yr<-range(tri3$ay,tri3$by,tri3$cy)
+  plot(swin(c(xr[1],yr[1],xr[2],yr[2]), tri3))}
+}
 \keyword{spatial}
diff --git a/src/Zlibs.c b/src/Zlibs.c
index 362f14b74b01523e759b57696b889f55d18dde3b..a1619054e70a80ca64fe9ecc3b4bf0895b505f8a 100755
--- a/src/Zlibs.c
+++ b/src/Zlibs.c
@@ -2458,11 +2458,11 @@ int intertype_rect_ic(int *point_nb1, double *x1, double *y1, int *point_nb2, do
                       int *t2, double *dt, int *nbSimu, int *h0, double *prec, int *nsimax, int *conv, int *rep, double *lev, double *g, double *k,
                       double *gic1, double *gic2, double *kic1, double *kic2, double *gval, double *kval, double *lval, double *nval)
     {
-    int i, j, i0, i1, i2, ptot, r;
+    int i, j, i0, i1, i2, r;
     double **gic, **kic;
     double *gg, *kk, *ll, *nn;
     double *gt, *kt, *lt, *nt;
-    int erreur=0, mess;
+    int erreur=0;
     int *type;
     //double *x,*y,*cost,surface,*xx,*yy;
     double *x, *y, *cost, densite_1, densite_2, densite_tot;
@@ -2522,7 +2522,6 @@ int intertype_rect_ic(int *point_nb1, double *x1, double *y1, int *point_nb2, do
         vecalloc(&kt, *t2);
         vecalloc(&lt, *t2);
         vecalloc(&nt, *t2);
-        /*ptot=*point_nb1+*point_nb2;*/
         erreur=ripley_rect(&point_nbtot, x, y, xmi, xma, ymi, yma, t2, dt, gt, kt);
         if (erreur!=0) return -1;
         for (j=0; j<*t2; j++)
@@ -2700,11 +2699,11 @@ int intertype_disq_ic(int *point_nb1, double *x1, double *y1, int *point_nb2, do
                       int *nsimax, int *conv, int *rep, double *lev, double *g, double *k, double *gic1, double *gic2,
                       double *kic1, double *kic2, double *gval, double *kval, double *lval, double *nval)
     {
-    int i, j, i0, i1, i2, ptot, r;
+    int i, j, i0, i1, i2, r;
     double **gic, **kic;
     double *gt, *kt, *lt, *nt;
     double *gg, *kk, *ll, *nn;
-    int erreur=0, mess;
+    int erreur=0;
     int *type;
     double *x, *y, *cost, densite_1, densite_2, densite_tot;
     int point_nb=0, point_nbtot;
@@ -2941,11 +2940,11 @@ int intertype_tr_rect_ic(int *point_nb1, double *x1, double *y1, int *point_nb2,
                          int *t2, double *dt, int *nbSimu, int *h0, double *prec, int *nsimax, int *conv, int *rep, double *lev, double *g, double *k,
                          double *gic1, double *gic2, double *kic1, double *kic2, double *gval, double *kval, double *lval, double *nval)
     {
-    int i, j, i0, i1, i2, ptot, r;
+    int i, j, i0, i1, i2, r;
     double **gic, **kic;
     double *gg, *kk, *ll, *nn;
     double *gt, *kt, *lt, *nt;
-    int erreur=0, mess;
+    int erreur=0;
     int *type;
     double *x, *y, *cost, densite_1, densite_2, densite_tot;
     int point_nb=0, point_nbtot;
@@ -3183,11 +3182,11 @@ int intertype_tr_disq_ic(int *point_nb1, double *x1, double *y1, int *point_nb2,
                          int *t2, double *dt, int *nbSimu, int *h0, double *prec, int *nsimax, int *conv, int *rep, double *lev, double *g, double *k,
                          double *gic1, double *gic2, double *kic1, double *kic2, double *gval, double *kval, double *lval, double *nval)
     {
-    int i, j, i0, i1, i2, ptot, r;
+    int i, j, i0, i1, i2, r;
     double **gic, **kic;
     double *gg, *kk, *ll, *nn;
     double *gt, *kt, *lt, *nt;
-    int erreur=0, mess;
+    int erreur=0;
     int *type;
     double *x, *y, *cost, densite_1, densite_2, densite_tot;
     int point_nb=0, point_nbtot;
@@ -6145,7 +6144,7 @@ int rao_rect(int *point_nb, double *x, double *y, double *xmi, double *xma, doub
     complete_tab(*point_nb, xx, yy, type, compt, l, x, y);
 
     int erreur;
-    double intensity1, point_nb2, point_nb1, intensity2;
+    double intensity1, intensity2;
     double intensity=*point_nb/(*surface);
     double *gii, *kii;
     vecalloc(&gii, *t2);
@@ -6285,7 +6284,7 @@ int rao_rect_ic(int *point_nb, double *x, double *y, double *xmi, double *xma, d
 
     //Ripley for all points	
     int erreur;
-    double intensity1, point_nb2, point_nb1, intensity2;
+    double intensity1, intensity2;
     double intensity=*point_nb/(*surface);
     double *gii, *kii;
     vecalloc(&gii, *t2);
@@ -6546,7 +6545,7 @@ int rao_disq(int *point_nb, double *x, double *y, double *x0, double *y0, double
     complete_tab(*point_nb, xx, yy, type, compt, l, x, y);
 
     int erreur;
-    double intensity1, point_nb1, point_nb2, intensity2;
+    double intensity1, intensity2;
     double intensity=*point_nb/(*surface);
     double *gii, *kii;
     vecalloc(&gii, *t2);
@@ -6683,8 +6682,8 @@ int rao_disq_ic(int *point_nb, double *x, double *y, double *x0, double *y0, dou
     complete_tab(*point_nb, xx, yy, type, compt, l, x, y);
 
     //Ripley for all points	
-    int erreur, ind;
-    double intensity1, point_nb1, point_nb2, intensity2;
+    int erreur;
+    double intensity1, intensity2;
     double intensity=*point_nb/(*surface);
     double *gii, *kii;
     vecalloc(&gii, *t2);
@@ -6940,7 +6939,7 @@ int rao_tr_rect(int *point_nb, double *x, double *y, double *xmi, double *xma, d
     complete_tab(*point_nb, xx, yy, type, compt, l, x, y);
 
     int erreur;
-    double intensity1, point_nb2, point_nb1, intensity2;
+    double intensity1, intensity2;
     double intensity=*point_nb/(*surface);
     double *gii, *kii;
     vecalloc(&gii, *t2);
@@ -7076,7 +7075,7 @@ int rao_tr_disq(int *point_nb, double *x, double *y, double *x0, double *y0,
     complete_tab(*point_nb, xx, yy, type, compt, l, x, y);
 
     int erreur;
-    double intensity1, point_nb2, point_nb1, intensity2;
+    double intensity1, intensity2;
     double intensity=*point_nb/(*surface);
     double *gii, *kii;
     vecalloc(&gii, *t2);
@@ -7213,7 +7212,7 @@ int rao_tr_rect_ic(int *point_nb, double *x, double *y, double *xmi, double *xma
 
     //Ripley for all points	
     int erreur;
-    double intensity1, point_nb2, point_nb1, intensity2;
+    double intensity1, intensity2;
     double intensity=*point_nb/(*surface);
     double *gii, *kii;
     vecalloc(&gii, *t2);
@@ -7474,7 +7473,7 @@ int rao_tr_disq_ic(int *point_nb, double *x, double *y, double *x0, double *y0,
 
     //Ripley for all points	
     int erreur;
-    double intensity1, point_nb2, point_nb1, intensity2;
+    double intensity1, intensity2;
     double intensity=*point_nb/(*surface);
     double *gii, *kii;
     vecalloc(&gii, *t2);
@@ -7705,7 +7704,7 @@ int rao_tr_disq_ic(int *point_nb, double *x, double *y, double *x0, double *y0,
 int randomdist(int *vec, int nb_type, double *mat, double *matp)
     {
     int i, j, a, jj;
-    int mat_size, rowvec, colvec, ind;
+    int rowvec, colvec, ind;
     int erreur=0;
 
     GetRNGstate();
@@ -8368,8 +8367,8 @@ int shen(int *point_nb, double *x, double *y,
     complete_tab(*point_nb, xx, yy, type, compt, l, x, y);
 
     int erreur;
-    double intensity1, point_nb2, point_nb1, intensity2;
-    double intensity=*point_nb/(*surface);
+    double intensity1, intensity2;
+    //double intensity=*point_nb/(*surface);
     double *gsii, *ksii, *grii, *krii;
     vecalloc(&gsii, *t2);
     vecalloc(&ksii, *t2);
@@ -8490,8 +8489,8 @@ int shen_ic(int *point_nb, double *x, double *y,
     complete_tab(*point_nb, xx, yy, type, compt, l, x, y);
 
     int erreur;
-    double intensity1, point_nb2, point_nb1, intensity2;
-    double intensity=*point_nb/(*surface);
+    double intensity1, intensity2;
+    //double intensity=*point_nb/(*surface);
     double *gsii, *ksii, *grii, *krii;
     vecalloc(&gsii, *t2);
     vecalloc(&ksii, *t2);
diff --git a/src/Zlibs.h b/src/Zlibs.h
index 920b26904977fa749349644496b6b92ef8998ce6..e55e40106bb495440ced3f6425adc496b5c31c6c 100755
--- a/src/Zlibs.h
+++ b/src/Zlibs.h
@@ -1,87 +1,152 @@
-int corr_disq_ic(int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*);
-int corr_disq(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*); 
-int corr_rect_ic(int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*); 
-int corr_rect(int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int corr_tr_disq_ic(int*,double*x,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*);
-int corr_tr_disq(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*); 
-int corr_tr_rect_ic(int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*); 
-int corr_tr_rect(int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int density_disq(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,int*,double*); 
-int density_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,int*,double*);
-int density_tr_disq(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,int*,double*); 
-int density_tr_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,int*,double*); 
+double un_point(double,double,double,double,double,double,double,double,double);
 double deux_point(double,double,double,double,double,double,double,double,double);
-double deuxbord_point(double,double,double,double,double,double,double,double,double);
+double ununun_point(double,double,double,double,double,double,double,double,double);
+double trois_point(double,double,double,double,double,double,double,double,double);
 double deuxun_point(double,double,double,double,double,double,double,double,double);
-double echange_point_disq(int,double*,double*,double,double,double,double,double,double,double*,int*,double*,double*,double*); 
-double echange_point_rect(int,double*,double*,double,double,double,double,double,double,double,double*,int*,double*,double*,double*); 
-double echange_point_tr_disq(int,double*,double*,double,double,double,int*,double*,double*,double*,double*,double*,double*,double,double,double,double*,int*,double*,double*,double*); 
-double echange_point_tr_rect(int,double*,double*,double,double,double,double,int*,double*,double*,double*,double*,double*,double*,double,double,double,double*,int*,double*,double*,double*); 
-void ic(int,int,double**,double**,double*,double*,int);
+double deuxbord_point(double,double,double,double,double,double,double,double,double);
+
 int in_droite(double,double,double,double,double,double,double,double,int);
 int in_triangle(double,double,double,double,double,double,double,double,int);
-int intertype_disq_ic(int*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*); 
-int intertype_disq(int*,double*,double*,int*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int intertype_rect_ic(int*,double*,double*,int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*); 
-int intertype_rect(int*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int intertype_tr_disq_ic(int*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*);
-int intertype_tr_disq(int*,double*,double*,int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int intertype_tr_rect_ic(int*,double*,double*,int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*);
-int intertype_tr_rect(int*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*); 
-int intertype(int*,double*,double*,int*,double*,double*,int*,double*,double*,double*);
-int intertypelocal_disq(int*,double*,double*,int*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int intertypelocal_rect(int*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int intertypelocal_tr_disq(int*,double*,double*,int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*); 
-int intertypelocal_tr_rect(int*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int mimetic_disq(int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,int*,int*,double*,double*,double*,double*,double*,int*); 
-int mimetic_rect(int*,double*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,int*,int*,double*,double*,double*,double*,double*,int*);
-int mimetic_tr_disq(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*cy,double*,int*,double*,double*,int*,int*,double*,double*,double*,double*,double*,int*); 
-int mimetic_tr_rect(int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,int*,int*,double*,double*,double*,double*,double*,int*);
+
+void ic(int,int,double **,double **,double *,double *,int);
+
+double perim_in_rect(double, double, double, double, double, double, double);
 double perim_in_disq(double,double,double,double,double,double);
-double perim_in_rect(double,double,double,double,double,double,double);
-double perim_triangle(double,double,double,int,double*,double*,double*,double*,double*,double*);
-int randlabelling(double*,double*,int,double*,double*,int,double*,double*,int*); 
-void randmark(int ,double*,double*); 
-int randomdist(int*,int,double*,double*); 
-int randomlab(double*,double*,int,int*,int,double**,int*,double**);
-int randshifting_disq(int*,double*,double*,int,double*,double*,double,double,double,double); 
-int randshifting_rect(int*,double*,double*,int,double*,double*,double,double,double,double,double); 
-int randshifting_tr_disq(int*,double*,double*,int,double*,double*,double,double,double,int,double*,double*,double*,double*,double*,double*,double);
-int randshifting_tr_rect(int*,double*,double*,int,double*,double*,double,double,double,double,int,double*,double*,double*,double*,double*,double*,double);
-int rao_disq_ic(int*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*);
-int rao_disq(int*,double*,double*,double*,double*,double*,int*,double*,int*,int*,int*,double*,double*,double*,double*,double*,double*,double*,int*);
-int rao_rect_ic(int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*); 
-int rao_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,int*,double*,double*,double*,double*,double*,double*,double*,int*); 
-int rao_tr_disq_ic(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*); 
-int rao_tr_disq(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,int*,double*,double*,double*,double*,double*,double*,double*,int*); 
-int rao_tr_rect_ic(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*); 
-int rao_tr_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,int*,double*,double*,double*,double*,double*,double*,double*,int*);
-int ripley_disq_ic(int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*); 
-int ripley_disq(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int ripley_rect_ic(int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*); 
-int ripley_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int ripley_tr_disq_ic(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*); 
-int ripley_tr_disq(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int ripley_tr_rect_ic(int*,double*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*); 
-int ripley_tr_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int ripleylocal_disq(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int ripleylocal_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int ripleylocal_tr_disq(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int ripleylocal_tr_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*); 
-void s_alea_disq(int,double*,double*,double,double,double,double);
+double perim_triangle(double,double,double,int,double *,double *,double *,double *,double *,double *);
+
+extern int ripley_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
+extern int ripley_disq(int *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+extern int ripley_tr_rect(int *,double *,double *,double *,double *,double *,double *,int *,double *,double *,
+                   double *,double *,double *,double *,int *,double *,double *,double *);
+extern int ripley_tr_disq(int *,double *,double *,double *,double *,double *,int *,double *,double *,double *,double *,
+                   double *,double *,int *,double *,double *,double *);
+
+extern int ripley_rect_ic(int *,double *,double *,double *,double *,double *,double *,double *,int *,double *,int *,
+                   double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *);
+extern int ripley_disq_ic(int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,double *,
+                   double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *);
+extern int ripley_tr_rect_ic(int *,double *,double *,double *,double *,double *,double *,double *,int *, double *,
+                      double *,double *,double *,double *,double *,int *,double *,int *,double *,double *,double *,double *,
+                      double *,double *,double *,double *,double *,double *,double *,double *);
+extern int ripley_tr_disq_ic(int *,double *,double *,double *,double *,double *,double *,int *, double *, double *,
+                      double *,double *,double *,double *,int *,double *,int *,double *,double *,double *,double *,double *,
+                      double *,double *,double *,double *,double *,double *,double *);
+
+extern int ripleylocal_rect(int*,double *,double *,double*,double*,double*,double*,int*,double*,double *,double *);
+extern int ripleylocal_disq(int *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+extern int ripleylocal_tr_rect(int *,double *,double *,double *,double *,double *,double *,int *,
+                        double *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+extern int ripleylocal_tr_disq(int *,double *,double *,double *,double *,double *,int *,
+                        double *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+
+extern int density_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,int*,double*);
+extern int density_disq(int*,double *,double *,double*,double*,double*,int*,double*,double *,double *,int*,double *);
+extern int density_tr_rect(int*,double *,double *,double*,double*,double*,double*,int*,double *,double *,double *,
+                    double *,double *,double *,int*,double*,double *,double *,int*,double *);
+extern int density_tr_disq(int*,double *,double *,double*,double*,double*,int*,double *,double *,double *,double *,
+                    double *,double *,int*,double*,double *,double *,int*,double *);
+
+extern int intertype_rect(int *,double *,double *,int *,double *,double *,double *,double *,double *,double *,
+                   int *,double *,double *,double *);
+extern int intertype_disq(int *,double *,double *,int *,double *,double *,double *,double *,double *,int *,
+                   double *,double *,double *);
+extern int intertype_tr_rect(int *,double *,double *,int *,double *,double *,double *,double *,double *,double *,int *,
+                      double *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+extern int intertype_tr_disq(int *,double *,double *,int *,double *,double *,double *,double *,double *,int *,
+                      double *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+
+extern int intertype_rect_ic(int *,double *,double *,int *,double *,double *,double *,double *,double *,double *,
+                      double *,int *,double *,int *,int *,double *,int *, int *, int *, double *,double *,double *,double *,double *,double *,double *,
+                      double *,double *,double *,double *);
+extern int intertype_disq_ic(int *,double *,double *,int *,double *,double *,double *,double *,double *,double *,int *,
+                      double *,int *,int *,double *,int *,int *,int *,double *,double *,double *,double *,double *,double *,double *,double *,
+                      double *,double *,double *);
+extern int intertype_tr_rect_ic(int *,double *,double *,int *,double *,double *,double *,double *,double *,double *,
+                         double *,int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,int *,double *,int *,int *,int *,double *,
+                         double *,double *,double *,double *,double *,double *,double *,double *,double *,double *);
+extern int intertype_tr_disq_ic(int *,double *,double *,int *, double *, double *,double *,double *,double *,double *,
+                         int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,int *,double *,int *,int *,int*,double *,double *,
+                         double *,double *,double *,double *,double *,double *,double *,double *,double *);
+
+extern int intertypelocal_rect(int*,double *,double *,int*,double *,double *,double*,double*,double*,double*,
+                        int*,double*,double *,double *);
+extern int intertypelocal_disq(int *,double *,double *,int *,double *,double *,double *,double *,	double *,int *,
+                        double *,double *,double *);
+extern int intertypelocal_tr_rect(int *,double *,double *,int *,double *,double *,double *,double *,double *,double *,
+                           int *,double *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+extern int intertypelocal_tr_disq(int *,double *,double *,int *,double *,double *,double *,double *,double *,int *,
+                           double *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+
 void s_alea_rect(int,double[],double[],double,double,double,double,double);
-void s_alea_tr_disq(int ,double*,double*,double,double,double,int,double*,double*,double*,double*,double*,double*,double);
-void s_alea_tr_rect(int,double*,double*,double,double,double,double,int,double*,double*,double*,double*,double*,double*,double); 
-int shen_ic(int*,double*,double*,int*,double*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*); 
-int shen(int*,double*,double*,int*,double*,int*,int*,double*,double*,double*,double*,double*,int*); 
-int shimatani_disq_ic(int*,double*,double*,double*,double*,double*,int*,double*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*);
-int shimatani_disq(int*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,double*,double*,int*);
-int shimatani_rect_ic(int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*); 
-int shimatani_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,double*,double*,int*);
-int shimatani_tr_disq_ic(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*); 
-int shimatani_tr_disq(int*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,double*,double*,int*);
-int shimatani_tr_rect_ic(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,double*,int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,double*,double*,int*);
-int shimatani_tr_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,double*,double*,int*); 
-double trois_point(double,double,double,double,double,double,double,double,double);
-double un_point(double,double,double,double,double,double,double,double,double);
-double ununun_point(double,double,double,double,double,double,double,double,double);
+void s_alea_disq(int,double *,double *,double,double,double,double);
+void s_alea_tr_rect(int,double *,double *,double,double,double,double,int,double *,double *,double *,double *,
+                    double *,double *,double);
+void s_alea_tr_disq(int ,double *,double *,double,double,double,int,double *,double *,double *,double *,
+                    double *,double *,double);
+
+int randlabelling(double *, double *, int, double *, double *,int, double *, double *,int *);
+int randshifting_rect(int *,double *,double *,int,double *,double *,double,double,double,double,double);
+int randshifting_disq(int *,double *,double *,int,double *,double *,double,double,double,double);
+int randshifting_tr_rect(int *,double *,double *,int,double *,double *,double,double,double,double,int,
+                         double *,double *,double *,double *,double *,double *,double);
+int randshifting_tr_disq(int *,double *,double *,int,double *,double *,double,double,double,int,
+                         double *,double *,double *,double *,double *,double *,double);
+int randomlab(double *,double *,int,int *,int,double **,int *,double **);
+void randmark(int ,double *,double *);
+int randomdist(int *,int,double *,double *);
+extern int corr_rect(int *,double *,double *,double *, double *,double *,double *,double *,int *,double *,double *,double *);
+extern int corr_disq(int *,double *,double *,double *, double *,double *,double *,int *,double *,double *,double *);
+extern int corr_tr_rect(int *,double *,double *,double *, double *,double *,double *,double *,int *, double *, double *, double *, double *, double *, double *,int *,double *,double *,double *);
+extern int corr_tr_disq(int *,double *,double *,double *, double *,double *,double *,int *,double *,double *,double *,double *,double *,double *,int *,double *,double *,double *);
+extern int corr_rect_ic(int *,double *,double *,double *, double *,double *,double *,double *,int *,double *,int *, double *,double *,double *,double *,double *, double *,double *, double *, double *);
+extern int corr_disq_ic(int *,double *,double *,double *, double *,double *,double *,int *,double *,int *, double *,double *,double *,double *,double *, double *,double *, double *, double *);
+extern int corr_tr_rect_ic(int *,double *,double *,double *, double *,double *,double *,double *,int *, double *, double *, double *, double *, double *, double *,int *,double *,int *, double *,double *,double *,double *,double *, double *,double *, double *, double *);
+extern int corr_tr_disq_ic(int *,double *x,double *,double *, double *,double *,double *,int *, double *, double *, double *, double *, double *, double *,int *,double *,int *, double *,double *,double *,double *,double *, double *,double *, double *, double *);
+extern int shimatani_rect(int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,int *,double *,double *, double *,int *);
+extern int shimatani_disq(int *,double *,double *, double *,double *,double *,int *,double *,int *,int *,double *,double *, double *,int *);
+extern int shimatani_tr_rect(int *,double *,double *, double *,double *,double *,double *,int *, double *, double *, double *, double *, double *, double *, int *,double *,int *,int *,double *,double *, double *,int *);
+extern int shimatani_tr_disq(int *,double *,double *, double *,double *,double *,int *, double *, double *, double *, double *, double *, double *, int *,double *,int *,int *,double *,double *, double *,int *);
+extern int shimatani_rect_ic(int *,double *,double *, double *,double *,double *,double *,int *,double *,int *,double *,int *,int *,double *,double *,
+                      double *, double *,double *,double *,double *,double *,double *,double *,int *);
+extern int shimatani_disq_ic(int *,double *,double *, double *,double *,double *,int *,double *,int *,double *,int *,int *,double *,double *,
+                      double *, double *,double *,double *,double *,double *,double *,double *,int *);
+extern int shimatani_tr_rect_ic(int *,double *,double *, double *,double *,double *,double *,int *, double *, double *, double *, double *, double *, double *,
+                         int *,double *,int *,double *,int *,int *,double *,double *,double *, double *,double *,double *,double *,double *,double *,double *,int *);
+extern int shimatani_tr_disq_ic(int *,double *,double *, double *,double *,double *,int *, double *, double *, double *, double *, double *, double *,
+                         int *,double *,int *,double *,int *,int *,double *,double *,double *, double *,double *,double *,double *,double *,double *,double *,int *);
+
+extern int rao_rect(int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,int *,int *,double *,double *,double *,double *,
+             double *,double *,double *,int *);
+extern int rao_rect_ic(int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,int *,double *,int *,int *,double *,double *,
+                double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,int *);
+extern int rao_disq(int *,double *,double *,double *,double *,double *,int *,double *,int *,int *,int *,double *,double *,double *,double *,
+             double *,double *,double *,int *);
+extern int rao_disq_ic(int *,double *,double *,double *,double *,double *,int *,double *,int *,int *,double *,int *,int *,double *,double *,
+                double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,int *);
+extern int rao_tr_rect(int *,double *,double *,double *,double *,double *,double *,int *,double *,double *,double *,double *,double *,double *,
+                int *,double *,int *,int *,int *,double *,double *,double *,double *,double *,double *,double *,int *);
+
+extern int rao_tr_rect_ic(int *,double *,double *,double *,double *,double *,double *,int *,double *,double *,double *,double *,double *,double *,
+                   int *,double *,int *,int *,double *,int *,int *,double *,double *,double *,double *,double *,double *,double *,double *,
+                   double *,double *,double *,double *,double *,int *);
+extern int rao_tr_disq(int *,double *,double *,double *,double *,double *,int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,int *,int *,
+                double *,double *,double *,double *,double *,double *,double *,int *);
+extern int rao_tr_disq_ic(int *,double *,double *,double *,double *,double *,int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,int *,double *,
+                   int *,int *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,int *);
+
+extern int mimetic_rect(int *,double *,double *, double *,double *,double *,double *,double *,double *, int *,double *,double *,int *,int *,double *,double *,double *,double *,double *,int *);
+extern int mimetic_disq(int *,double *,double *,double *,double *,double *,double *,double *, int *, double *, double *, int *, int *, double *,double *,double *,double *,double *,int *);
+extern int mimetic_tr_rect(int *,double *,double *, double *,double *,double *,double *,double *,int *, double *, double *, double *, double *, double *, double *,
+                    double *, int *, double *, double *, int *, int *, double *,double *, double *,double *,double *,int *);
+extern int mimetic_tr_disq(int *,double *,double *, double *,double *,double *,double *,int *, double *,double *,double *,double *,double *,double *cy,
+                    double *, int *, double *, double *, int *, int *, double *,double *,double *,double *,double *,int *);
+double echange_point_rect(int,double *,double *,double,double,double,double,double,double,double,double *,int *,double *,double *,double *);
+double echange_point_disq(int,double *,double *,double,double,double,double,double,double,double *,int *,double *,double *,double *);
+double echange_point_tr_rect(int,double *,double *,double,double,double,double,int *,double *,double *,double *,double *,double *,double *,
+                             double,double,double,double *,int *,double *,double *,double *);
+double echange_point_tr_disq(int,double *,double *,double,double,double,int *,double *,double *,double *,double *,double *,double *,
+                             double,double,double,double *,int *,double *,double *,double *);
+extern int shen(int *,double *,double *,int *,double *,int *,int *,double *,double *,double *,double *, double *, int *);
+extern int shen_ic(int *,double *,double *,int *,double *,int *,double *,int *,int *,double *,double *,double *,
+            double *, double *, double *,double *,double *,double *,double *,double *,int *);
+int intertype(int *,double *,double *,int *, double *, double *,int *,double *,double *,double *);
diff --git a/src/adssub.c b/src/adssub.c
index 2ed04ba06c7bad388118c4ab1983e7d67091a5e3..41e605ecd534993aab1318ddb5c0bb9fea0509e1 100755
--- a/src/adssub.c
+++ b/src/adssub.c
@@ -347,3 +347,57 @@ void complete_tab(int point_nb,double **xx,double **yy,int *type,int *compt,int
 	return ;
 }
 
+
+
+/*test wether points are inside a polygon (points on boundaries are considered outside)*/
+void pnpoly(double *testx, double *testy, double *vertx, double *verty, int *npts, int *nvert, double *xmi, double *ymi, double *pxr, double *pyr, double *score) {
+  
+	int i, j, k;
+	int nedg=*nvert;
+
+	/*so as to shift all coordinates to positive values only*/
+/*	if(*xmi<0) {
+		for(i=0;i<*npts;i++) {
+			testx[i]=testx[i]-*xmi;
+		}
+		for(i=0;i<*nvert;i++) {
+			vertx[i]=vertx[i]-*xmi;
+		}
+		for(i=0;i<2;i++) {
+			pxr[i]=pxr[i]-*xmi;
+		}
+		//decalVal(testx,*npts,-*xmi);
+		//decalVal(vertx,*nvert,-*xmi);
+		//decalVal(pxr,2,-*xmi);
+	}
+	if(*ymi<0) {
+		for(i=0;i<*npts;i++) {
+			testy[i]=testy[i]-*ymi;
+		}
+		for(i=0;i<*nvert;i++) {
+			verty[i]=verty[i]-*ymi;
+		}
+		for(i=0;i<2;i++) {
+			pyr[i]=pyr[i]-*ymi;
+		}
+		//decalVal(testy,*npts,-*ymi);
+		//decalVal(verty,*nvert,-*ymi);
+		//decalVal(pyr,2,-*ymi);
+	}*/
+
+  	for(k=0;k<*npts;k++) {
+		score[k]=0;
+		//for (i=0, j=(nedg-1); i <nedg; j = i++) {
+		j=(nedg-1);
+		for (i=0; i <nedg; i++) {
+				
+			if ((((verty[i] <= testy[k]) && (testy[k] < verty[j])) || ((verty[j] <= testy[k]) && (testy[k] < verty[i]))) && (testx[k] < (vertx[j] - vertx[i]) * (testy[k] - verty[i]) / (verty[j] - verty[i]) + vertx[i]))
+				{score[k] = 1;}	
+			j=i;
+			
+  		}
+		// We're outside the polygon!
+		/*if (testx[k] <= pxr[1] || testx[k] >= pxr[2] || testy[k] <= pyr[1] || testy[k] >= pyr[2]) 
+		{score[k]=0;}*/
+	}	
+}
diff --git a/src/adssub.h b/src/adssub.h
index 85e85ff14d16dfc30bfd6dd508e8dee17871baaf..2452d4b9a6a423eb0c4a9cc5e33f6f38fff3b471 100755
--- a/src/adssub.h
+++ b/src/adssub.h
@@ -3,26 +3,33 @@
 #include <limits.h>
 #include <R_ext/PrtUtil.h>
 
-double bacos(double);
-void complete_tab(int,double**,double**,int*,int*,int*,double*,double*); 
-void decalCirc(int,double*,double*,double*,double*,double); 
-void decalCirc2(int,double*,double*,int,double*,double*,double*,double*,double); 
-void decalCircTri(int,double*,double*,double*,double*,double, int,double*,double*,double*,double*,double*,double*);
-void decalCircTri2(int,double*,double*,int,double*,double*,double*,double*,double,int,double*,double*,double*,double*,double*,double*); 
-void decalRect(int,double*,double*,double*,double*,double*,double*); 
-void decalRect2(int,double*,double*,int,double*,double*,double*,double*,double*,double*); 
-void decalRectTri(int,double*,double*,double*,double*,double*,double*, int,double*,double*,double*,double*,double*,double*);
-void decalRectTri2(int,double*,double*,int,double*,double*,double*,double*,double*,double*, int,double*,double*,double*,double*,double*,double*);
-void decalSample(int,double*,double*,double,double); 
-void decalVal(double*,int,double); 
-void freeinttab(int**); 
-void freeintvec(int*); 
-void freetab(double**); 
-void freevec(double*); 
-double Pi(); 
-void progress(int,int*,int); 
-void taballoc(double***,int,int); 
-double** taballoca(int,int*); 
-void tabintalloc(int***,int,int); 
-void vecalloc(double**,int);
-void vecintalloc(int**,int);
+double Pi();
+void progress(int,int*, int);
+/*double alea ();*/
+void freeintvec (int *);
+void freetab (double **);
+void freevec (double *);
+void taballoc (double ***,int,int);
+void tabintalloc (int ***,int,int);
+void freeinttab (int **);
+void vecalloc (double **vec, int n);
+void vecintalloc (int **vec, int n);
+double bacos(double a);
+void decalVal(double *,int,double);
+void decalRect(int,double *,double *,double *,double *,double *,double *);
+void decalCirc(int,double *,double *,double *,double *,double);
+void decalRectTri(int,double *,double *,double *,double *,double *,double *,
+	int,double *,double *,double *,double *,double *,double *);
+void decalCircTri(int,double *,double *,double *,double *,double,
+	int,double *,double *,double *,double *,double *,double *);
+void decalRect2(int,double *,double *,int,double *,double *,double *,double *,double *,double *);
+void decalCirc2(int,double *,double *,int,double *,double *,double *,double *,double);
+void decalRectTri2(int,double *,double *,int,double *,double *,double *,double *,double *,double *,
+	int,double *,double *,double *,double *,double *,double *);
+void decalCircTri2(int,double *,double *,int,double *,double *,double *,double *,double,int,
+	double *,double *,double *,double *,double *,double *);
+void decalSample(int,double *,double *,double,double);
+//void decalPoly(int ,double *, double *,double *, double *, double *, double *,int ,double *, double *);
+double** taballoca(int,int *);
+void complete_tab(int,double **,double **,int *,int *,int *,double *,double *);
+extern void pnpoly(double *, double *, double *, double *, int *, int *, double *, double *, double *, double *, double *);
diff --git a/src/init.c b/src/init.c
index f7bfb7dd9bbf539382ac30f5512afa5def2a1dfc..1e1728d683d77f4bdb043e75781b6a9b81d2fb57 100644
--- a/src/init.c
+++ b/src/init.c
@@ -1,82 +1,81 @@
-#include <R_ext/RS.h>
+#include <R.h>
+#include <Rinternals.h>
 #include <stdlib.h> // for NULL
 #include <R_ext/Rdynload.h>
-#include "Zlibs.h"
 #include "triangulate.h"
+#include "Zlibs.h"
+#include "adssub.h"
 
-/* .Fortran calls */
-extern void F77_NAME(inpoly)(void *, void *, void *, void *, void *, void *, void *, void *);
+// Generated by using tools::package_native_routine_registration_skeleton(dir)
 
+extern int triangulate(int *npoly, int *tabpt, int *nptTot,double *vertX, double *vertY, int *ntri,
+                       double *X1, double *Y1,double *X2, double *Y2,double *X3, double *Y3);
+  
 static const R_CMethodDef CEntries[] = {
-    {"corr_disq",              (DL_FUNC) &corr_disq,              11},
-    {"corr_disq_ic",           (DL_FUNC) &corr_disq_ic,           19},
-    {"corr_rect",              (DL_FUNC) &corr_rect,              12},
-    {"corr_rect_ic",           (DL_FUNC) &corr_rect_ic,           20},
-    {"corr_tr_disq",           (DL_FUNC) &corr_tr_disq,           18},
-    {"corr_tr_disq_ic",        (DL_FUNC) &corr_tr_disq_ic,        26},
-    {"corr_tr_rect",           (DL_FUNC) &corr_tr_rect,           19},
-    {"corr_tr_rect_ic",        (DL_FUNC) &corr_tr_rect_ic,        27},
-    {"density_disq",           (DL_FUNC) &density_disq,           12},
-    {"density_rect",           (DL_FUNC) &density_rect,           13},
-    {"density_tr_disq",        (DL_FUNC) &density_tr_disq,        19},
-    {"density_tr_rect",        (DL_FUNC) &density_tr_rect,        20},
-    {"intertype_disq",         (DL_FUNC) &intertype_disq,         13},
-    {"intertype_disq_ic",      (DL_FUNC) &intertype_disq_ic,      29},
-    {"intertype_rect",         (DL_FUNC) &intertype_rect,         14},
-    {"intertype_rect_ic",      (DL_FUNC) &intertype_rect_ic,      30},
-    {"intertype_tr_disq",      (DL_FUNC) &intertype_tr_disq,      20},
-    {"intertype_tr_disq_ic",   (DL_FUNC) &intertype_tr_disq_ic,   36},
-    {"intertype_tr_rect",      (DL_FUNC) &intertype_tr_rect,      21},
-    {"intertype_tr_rect_ic",   (DL_FUNC) &intertype_tr_rect_ic,   37},
-    {"intertypelocal_disq",    (DL_FUNC) &intertypelocal_disq,    13},
-    {"intertypelocal_rect",    (DL_FUNC) &intertypelocal_rect,    14},
-    {"intertypelocal_tr_disq", (DL_FUNC) &intertypelocal_tr_disq, 20},
-    {"intertypelocal_tr_rect", (DL_FUNC) &intertypelocal_tr_rect, 21},
-    {"mimetic_disq",           (DL_FUNC) &mimetic_disq,           19},
-    {"mimetic_rect",           (DL_FUNC) &mimetic_rect,           20},
-    {"mimetic_tr_disq",        (DL_FUNC) &mimetic_tr_disq,        26},
-    {"mimetic_tr_rect",        (DL_FUNC) &mimetic_tr_rect,        27},
-    {"rao_disq",               (DL_FUNC) &rao_disq,               19},
-    {"rao_disq_ic",            (DL_FUNC) &rao_disq_ic,            27},
-    {"rao_rect",               (DL_FUNC) &rao_rect,               20},
-    {"rao_rect_ic",            (DL_FUNC) &rao_rect_ic,            28},
-    {"rao_tr_disq",            (DL_FUNC) &rao_tr_disq,            26},
-    {"rao_tr_disq_ic",         (DL_FUNC) &rao_tr_disq_ic,         34},
-    {"rao_tr_rect",            (DL_FUNC) &rao_tr_rect,            27},
-    {"rao_tr_rect_ic",         (DL_FUNC) &rao_tr_rect_ic,         35},
-    {"ripley_disq",            (DL_FUNC) &ripley_disq,            10},
-    {"ripley_disq_ic",         (DL_FUNC) &ripley_disq_ic,         22},
-    {"ripley_rect",            (DL_FUNC) &ripley_rect,            11},
-    {"ripley_rect_ic",         (DL_FUNC) &ripley_rect_ic,         23},
-    {"ripley_tr_disq",         (DL_FUNC) &ripley_tr_disq,         17},
-    {"ripley_tr_disq_ic",      (DL_FUNC) &ripley_tr_disq_ic,      29},
-    {"ripley_tr_rect",         (DL_FUNC) &ripley_tr_rect,         18},
-    {"ripley_tr_rect_ic",      (DL_FUNC) &ripley_tr_rect_ic,      30},
-    {"ripleylocal_disq",       (DL_FUNC) &ripleylocal_disq,       10},
-    {"ripleylocal_rect",       (DL_FUNC) &ripleylocal_rect,       11},
-    {"ripleylocal_tr_disq",    (DL_FUNC) &ripleylocal_tr_disq,    17},
-    {"ripleylocal_tr_rect",    (DL_FUNC) &ripleylocal_tr_rect,    18},
-    {"shen",                   (DL_FUNC) &shen,                   13},
-    {"shen_ic",                (DL_FUNC) &shen_ic,                21},
-    {"shimatani_disq",         (DL_FUNC) &shimatani_disq,         14},
-    {"shimatani_disq_ic",      (DL_FUNC) &shimatani_disq_ic,      23},
-    {"shimatani_rect",         (DL_FUNC) &shimatani_rect,         15},
-    {"shimatani_rect_ic",      (DL_FUNC) &shimatani_rect_ic,      24},
-    {"shimatani_tr_disq",      (DL_FUNC) &shimatani_tr_disq,      21},
-    {"shimatani_tr_disq_ic",   (DL_FUNC) &shimatani_tr_disq_ic,   30},
-    {"shimatani_tr_rect",      (DL_FUNC) &shimatani_tr_rect,      22},
-    {"shimatani_tr_rect_ic",   (DL_FUNC) &shimatani_tr_rect_ic,   31},
-    {"c_triangulate",          (DL_FUNC) &c_triangulate,          12},
-    {NULL, NULL, 0}
-};
-
-static const R_FortranMethodDef FortranEntries[] = {
-    {"inpoly", (DL_FUNC) &F77_NAME(inpoly), 8},
-    {NULL, NULL, 0}
+  {"corr_disq",              (DL_FUNC) &corr_disq,              11},
+  {"corr_disq_ic",           (DL_FUNC) &corr_disq_ic,           19},
+  {"corr_rect",              (DL_FUNC) &corr_rect,              12},
+  {"corr_rect_ic",           (DL_FUNC) &corr_rect_ic,           20},
+  {"corr_tr_disq",           (DL_FUNC) &corr_tr_disq,           18},
+  {"corr_tr_rect",           (DL_FUNC) &corr_tr_rect,           19},
+  {"corr_tr_rect_ic",        (DL_FUNC) &corr_tr_rect_ic,        27},
+  {"density_disq",           (DL_FUNC) &density_disq,           12},
+  {"density_rect",           (DL_FUNC) &density_rect,           13},
+  {"density_tr_disq",        (DL_FUNC) &density_tr_disq,        19},
+  {"density_tr_rect",        (DL_FUNC) &density_tr_rect,        20},
+  {"intertype_disq",         (DL_FUNC) &intertype_disq,         13},
+  {"intertype_disq_ic",      (DL_FUNC) &intertype_disq_ic,      29},
+  {"intertype_rect",         (DL_FUNC) &intertype_rect,         14},
+  {"intertype_rect_ic",      (DL_FUNC) &intertype_rect_ic,      30},
+  {"intertype_tr_disq",      (DL_FUNC) &intertype_tr_disq,      20},
+  {"intertype_tr_disq_ic",   (DL_FUNC) &intertype_tr_disq_ic,   36},
+  {"intertype_tr_rect",      (DL_FUNC) &intertype_tr_rect,      21},
+  {"intertype_tr_rect_ic",   (DL_FUNC) &intertype_tr_rect_ic,   37},
+  {"intertypelocal_disq",    (DL_FUNC) &intertypelocal_disq,    13},
+  {"intertypelocal_rect",    (DL_FUNC) &intertypelocal_rect,    14},
+  {"intertypelocal_tr_disq", (DL_FUNC) &intertypelocal_tr_disq, 20},
+  {"intertypelocal_tr_rect", (DL_FUNC) &intertypelocal_tr_rect, 21},
+  {"mimetic_disq",           (DL_FUNC) &mimetic_disq,           19},
+  {"mimetic_rect",           (DL_FUNC) &mimetic_rect,           20},
+  {"mimetic_tr_disq",        (DL_FUNC) &mimetic_tr_disq,        26},
+  {"mimetic_tr_rect",        (DL_FUNC) &mimetic_tr_rect,        27},
+  {"pnpoly",                 (DL_FUNC) &pnpoly,                 11},
+  {"rao_disq",               (DL_FUNC) &rao_disq,               19},
+  {"rao_disq_ic",            (DL_FUNC) &rao_disq_ic,            27},
+  {"rao_rect",               (DL_FUNC) &rao_rect,               20},
+  {"rao_rect_ic",            (DL_FUNC) &rao_rect_ic,            28},
+  {"rao_tr_disq",            (DL_FUNC) &rao_tr_disq,            26},
+  {"rao_tr_disq_ic",         (DL_FUNC) &rao_tr_disq_ic,         34},
+  {"rao_tr_rect",            (DL_FUNC) &rao_tr_rect,            27},
+  {"rao_tr_rect_ic",         (DL_FUNC) &rao_tr_rect_ic,         35},
+  {"ripley_disq",            (DL_FUNC) &ripley_disq,            10},
+  {"ripley_disq_ic",         (DL_FUNC) &ripley_disq_ic,         22},
+  {"ripley_rect",            (DL_FUNC) &ripley_rect,            11},
+  {"ripley_rect_ic",         (DL_FUNC) &ripley_rect_ic,         23},
+  {"ripley_tr_disq",         (DL_FUNC) &ripley_tr_disq,         17},
+  {"ripley_tr_disq_ic",      (DL_FUNC) &ripley_tr_disq_ic,      29},
+  {"ripley_tr_rect",         (DL_FUNC) &ripley_tr_rect,         18},
+  {"ripley_tr_rect_ic",      (DL_FUNC) &ripley_tr_rect_ic,      30},
+  {"ripleylocal_disq",       (DL_FUNC) &ripleylocal_disq,       10},
+  {"ripleylocal_rect",       (DL_FUNC) &ripleylocal_rect,       11},
+  {"ripleylocal_tr_disq",    (DL_FUNC) &ripleylocal_tr_disq,    17},
+  {"ripleylocal_tr_rect",    (DL_FUNC) &ripleylocal_tr_rect,    18},
+  {"shen",                   (DL_FUNC) &shen,                   13},
+  {"shen_ic",                (DL_FUNC) &shen_ic,                21},
+  {"shimatani_disq",         (DL_FUNC) &shimatani_disq,         14},
+  {"shimatani_disq_ic",      (DL_FUNC) &shimatani_disq_ic,      23},
+  {"shimatani_rect",         (DL_FUNC) &shimatani_rect,         15},
+  {"shimatani_rect_ic",      (DL_FUNC) &shimatani_rect_ic,      24},
+  {"shimatani_tr_disq",      (DL_FUNC) &shimatani_tr_disq,      21},
+  {"shimatani_tr_disq_ic",   (DL_FUNC) &shimatani_tr_disq_ic,   30},
+  {"shimatani_tr_rect",      (DL_FUNC) &shimatani_tr_rect,      22},
+  {"shimatani_tr_rect_ic",   (DL_FUNC) &shimatani_tr_rect_ic,   31},
+  {"triangulate",            (DL_FUNC) &triangulate,            12},
+  {NULL, NULL, 0}
 };
 
 void R_init_ads(DllInfo *dll)
 {
-    R_registerRoutines(dll, CEntries, NULL, FortranEntries, NULL);
-    R_useDynamicSymbols(dll, FALSE);
-}
\ No newline at end of file
+  R_registerRoutines(dll, CEntries, NULL, NULL, NULL);
+  R_useDynamicSymbols(dll, FALSE);
+}
diff --git a/src/spatstatsub.f b/src/spatstatsub.f
deleted file mode 100755
index f186cb82af40012e8ef725635872b4f2faab5e75..0000000000000000000000000000000000000000
--- a/src/spatstatsub.f
+++ /dev/null
@@ -1,47 +0,0 @@
-C Output from Public domain Ratfor, version 1.0
-      subroutine inpoly(x,y,xp,yp,npts,nedges,score,onbndry)
-      implicit double precision(a-h,o-z)
-      dimension x(npts), y(npts), xp(nedges), yp(nedges), score(npts)
-      logical onbndry(npts)
-      zero = 0.d0
-      half = 0.5d0
-      one = 1.d0
-      do23000 i = 1,nedges 
-      x0 = xp(i)
-      y0 = yp(i)
-      if(i .eq. nedges)then
-      x1 = xp(1)
-      y1 = yp(1)
-      else
-      x1 = xp(i+1)
-      y1 = yp(i+1)
-      endif
-      dx = x1 - x0
-      dy = y1 - y0
-      do23004 j = 1,npts 
-      xcrit = (x(j) - x0)*(x(j) - x1)
-      if(xcrit .le. zero)then
-      if(xcrit .eq. zero)then
-      contrib = half
-      else
-      contrib = one
-      endif
-      ycrit = y(j)*dx - x(j)*dy + x0*dy - y0*dx
-      if((dx .lt. 0 .and. ycrit .ge. zero) .or. (dx .gt. zero .and. ycri
-     *t .lt. zero))then
-      score(j) = score(j) - sign(one,dx)*contrib
-      onbndry(j) = onbndry(j) .or. (ycrit .eq. zero)
-      else
-      if(dx .eq. zero)then
-      if(x(j) .eq. x0)then
-      ycrit = (y(j) - y0)*(y(j) - y1)
-      onbndry(j) = onbndry(j) .or. (ycrit .le. zero)
-      endif
-      endif
-      endif
-      endif
-23004 continue
-23000 continue
-      return
-      end
-      
diff --git a/src/triangulate.c b/src/triangulate.c
index 7193f5285531045c00010facfcf4a6443fae9bed..3a58f2d629cef6f8cd6fce3f71746df08fe0acb5 100755
--- a/src/triangulate.c
+++ b/src/triangulate.c
@@ -2126,81 +2126,3 @@ int is_point_inside_polygon(vertex)
   return _greater_than_equal_to(&seg[rseg].v1, &seg[rseg].v0);
 }
 
-int c_triangulate(int *npoly, int *tabpt, int *nptTot,double *vertX, double *vertY, int *ntri, double *X1, double *Y1,double *X2, double *Y2,double *X3, double *Y3) {
-  int i,j,k,l;
-  int **triangles;
-  double **vertices;
-  double *x,*y;
-  tabintalloc(&triangles,*ntri,3);
-  taballoc(&vertices,*nptTot+1,2);
-  l=0;
-  for(i=0;i<*npoly;i++) {
-    int npt=tabpt[i];
-    vecalloc(&x,npt+1);
-    vecalloc(&y,npt+1);
-    for(j=1;j<=npt;j++) {
-      k=j+l-1;
-      x[j]=vertX[k];
-      y[j]=vertY[k];
-    }
-    if(i==0) {
-      if(testclock(x,y,npt)) { /*clockwise order*/
-k=npt;
-        for(j=1;j<=npt;j++) {
-          vertices[j+l][0]=x[k];
-          vertices[j+l][1]=y[k];
-          k--;
-        }
-      }
-      else { /*anti-clockwise order*/
-for(j=1;j<=npt;j++) {
-  vertices[j+l][0]=x[j];
-  vertices[j+l][1]=y[j];
-}
-      }
-    }
-    else {
-      if(!testclock(x,y,npt)) { /*anti-clockwise order*/
-k=npt;
-        for(j=1;j<=npt;j++) {
-          vertices[j+l][0]=x[k];
-          vertices[j+l][1]=y[k];
-          k--;
-        }
-      }
-      else { /*clockwise order*/
-for(j=1;j<=npt;j++) {
-  vertices[j+l][0]=x[j];
-  vertices[j+l][1]=y[j];
-}
-      }
-    }
-    l+=npt;
-    freevec(x);
-    freevec(y);
-  }
-  
-  /*Test de l'unicite des points*/
-  for(i=2;i<=*nptTot;i++) {
-    for(j=1;j<i;j++) {
-      if((vertices[i][0]==vertices[j][0])&&(vertices[i][1]==vertices[j][1])) {
-        Rprintf("Error : Duplicate input vertices\n");
-        return -1;
-      }
-    }
-  }
-  triangulate_polygon(*npoly,tabpt,vertices,triangles);
-  for(i=0;i<*ntri;i++) {
-    X1[i]=vertices[triangles[i][2]][0];
-    Y1[i]=vertices[triangles[i][2]][1];
-    X2[i]=vertices[triangles[i][1]][0];
-    Y2[i]=vertices[triangles[i][1]][1];
-    X3[i]=vertices[triangles[i][0]][0];
-    Y3[i]=vertices[triangles[i][0]][1];
-  }
-  freeinttab(triangles);
-  freetab(vertices);
-  return 0;
-}
-
-
diff --git a/src/triangulate.h b/src/triangulate.h
index 50a0b50bb454223076cb071d20447f1c5b2f562e..baa3568cb55ce5d23f2a95c9547d6b612802f090 100755
--- a/src/triangulate.h
+++ b/src/triangulate.h
@@ -88,7 +88,7 @@ typedef struct {
 #define LASTPT  2
 
 
-#define INFINITY 1<<30 
+#define INFINITY 1<<30
 #define C_EPS 1.0e-7		/* tolerance value: Used for making */
 				/* all decisions about collinearity or */
 				/* left/right of segment. Decrease */
@@ -140,20 +140,26 @@ extern node_t qs[QSIZE];		/* Query structure */
 extern trap_t tr[TRSIZE];		/* Trapezoid structure */
 extern segment_t seg[SEGSIZE];		/* Segment table */
 
+
 /* Functions */
-extern int c_triangulate(int*, int *, int *,double *, double *, int *, double *, double *,double *, double *,double *, double *);
+
 extern int triangulate_polygon(int, int *, double**,int**);
 extern int is_point_inside_polygon(double *);
+
 int triangulate_polygon(int, int [], double**, int**);
+
 int testclock(double *,double *,int);
+
 extern int monotonate_trapezoids(int);
 extern int triangulate_monotone_polygons(int, int, int**);
+
 extern int _greater_than(point_t *, point_t *);
 extern int _equal_to(point_t *, point_t *);
 extern int _greater_than_equal_to(point_t *, point_t *);
 extern int _less_than(point_t *, point_t *);
 extern int locate_endpoint(point_t *, point_t *, int);
 extern int construct_trapezoids(int);
+
 extern int generate_random_ordering(int);
 extern int choose_segment(void);
 extern int read_segments(char *, int *);
diff --git a/src/util.c b/src/util.c
new file mode 100755
index 0000000000000000000000000000000000000000..c6e6a236a617c2db3bb5188b710a2891ea10afbf
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,80 @@
+#include "adssub.h"
+#include "triangulate.h"
+
+int triangulate(int *npoly, int *tabpt, int *nptTot,double *vertX, double *vertY, int *ntri,
+double *X1, double *Y1,double *X2, double *Y2,double *X3, double *Y3) {
+	int i,j,k,l;
+	int **triangles;
+	double **vertices;
+	double *x,*y;
+	tabintalloc(&triangles,*ntri,3);
+	taballoc(&vertices,*nptTot+1,2);
+	l=0;
+	for(i=0;i<*npoly;i++) {
+		int npt=tabpt[i];
+		vecalloc(&x,npt+1);
+		vecalloc(&y,npt+1);
+		for(j=1;j<=npt;j++) {
+			k=j+l-1;
+			x[j]=vertX[k];
+			y[j]=vertY[k];
+		}
+		if(i==0) {
+			if(testclock(x,y,npt)) { /*clockwise order*/
+				k=npt;
+				for(j=1;j<=npt;j++) {
+					vertices[j+l][0]=x[k];
+					vertices[j+l][1]=y[k];
+					k--;
+				}
+			}
+			else { /*anti-clockwise order*/
+				for(j=1;j<=npt;j++) {
+					vertices[j+l][0]=x[j];
+					vertices[j+l][1]=y[j];
+				}
+			}
+		}
+		else {
+			if(!testclock(x,y,npt)) { /*anti-clockwise order*/
+				k=npt;
+				for(j=1;j<=npt;j++) {
+					vertices[j+l][0]=x[k];
+					vertices[j+l][1]=y[k];
+					k--;
+				}
+			}
+			else { /*clockwise order*/
+				for(j=1;j<=npt;j++) {
+					vertices[j+l][0]=x[j];
+					vertices[j+l][1]=y[j];
+				}
+			}
+		}
+		l+=npt;
+		freevec(x);
+		freevec(y);
+	}
+
+	/*Test de l'unicite des points*/
+	for(i=2;i<=*nptTot;i++) {
+		for(j=1;j<i;j++) {
+			if((vertices[i][0]==vertices[j][0])&&(vertices[i][1]==vertices[j][1])) {
+				Rprintf("Error : Duplicate input vertices\n");
+				return -1;
+			}
+		}
+	}
+	triangulate_polygon(*npoly,tabpt,vertices,triangles);
+	for(i=0;i<*ntri;i++) {
+		X1[i]=vertices[triangles[i][2]][0];
+		Y1[i]=vertices[triangles[i][2]][1];
+		X2[i]=vertices[triangles[i][1]][0];
+		Y2[i]=vertices[triangles[i][1]][1];
+		X3[i]=vertices[triangles[i][0]][0];
+		Y3[i]=vertices[triangles[i][0]][1];
+	}
+	freeinttab(triangles);
+	freetab(vertices);
+	return 0;
+}