diff --git a/DESCRIPTION b/DESCRIPTION
index cd85fe73c40878a4e9a92b5f8fb16b6441231818..84334d335b35c62c2768ce814f0a97c708a96540 100755
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,16 +1,17 @@
 Package: ads
 Type: Package
-Title: Spatial point patterns analysis
-Version: 1.5-2.2
-Date: 2015-01-13
-Author: R. Pelissier and F. Goreaud
-Maintainer: Raphael Pelissier <Raphael.Pelissier@ird.fr>
-Imports: ade4, spatstat
-Description: Perform first- and second-order multi-scale analyses derived from Ripley K-function, for univariate,
+Title: Spatial Point Patterns Analysis
+Version: 1.5-6
+Date: 2022-05-11
+Author: Raphael Pelissier [aut], Francois Goreau [aut], Philippe Verley [ctb, cre]
+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
-Packaged: 2015-01-13 12:09:18 UTC; root
 NeedsCompilation: yes
 Repository: CRAN
-Date/Publication: 2015-01-13 14:49:23
+RoxygenNote: 7.1.2
+Language: en-GB
diff --git a/INDEX b/INDEX
index 18df450a8124d9ed5a277efdd26c719cfb3a68c4..a6c7ef218032904d5f7a752b0a6b65a1efa5eac5 100755
--- a/INDEX
+++ b/INDEX
@@ -1,31 +1,20 @@
 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.
-Paracou15     Spatial pattern of trees in plot 15 of Paracou experimental station,
-              French Guiana.
+Couepia       Spatial pattern of Couepia caryophylloides in Paracou, a canopy tree species of French Guiana.
+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. 
-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.
-kpqfun        (Formerly kijfun) Multiscale second-order neigbourhood analysis of a 
-              multivariate spatial point pattern.
-krfun         Multiscale second-order neigbourhood analysis of a multivariate spatial 
-              point pattern using Rao quadratic entropy.
-ksfun         Multiscale second-order neigbourhood analysis of a multivariate spatial 
-              point pattern using Simpson diversity.
+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. 
+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.
+kpqfun        (Formerly kijfun) Multiscale second-order neigbourhood analysis of a multivariate spatial point pattern.
+krfun         Multiscale second-order neigbourhood analysis of a multivariate spatial point pattern using Rao quadratic entropy.
+ksfun         Multiscale second-order neigbourhood analysis of a multivariate spatial point pattern using Simpson diversity.
 kval          Multiscale local second-order neighbour density of a spatial point pattern.
 mimetic       Univariate point pattern replication by mimetic point process.
 plot.fads     Plot second-order neigbourhood functions.
diff --git a/MD5 b/MD5
deleted file mode 100644
index a20da8ff7af0609bc7bce5ffa5b87d1783690d64..0000000000000000000000000000000000000000
--- a/MD5
+++ /dev/null
@@ -1,55 +0,0 @@
-2755553481e78a8f5b6ef00d43e983a5 *DESCRIPTION
-68a58538a504c7cfa73472d87053be45 *INDEX
-7478c6d745db573c9d03ebc59bdc969c *NAMESPACE
-f6aac0fb4ef187df6521cbb2d9ffc9cf *R/fads.R
-7a71372e86fd8aadfc770b261cd953ca *R/mimetic.R
-e87bd01e08a83a7b1c52b2a4a7e5df35 *R/plot.fads.R
-95d2bc01bd2779736c826a21c83b62f3 *R/plot.vads.R
-6317d29d7e9045d55b1a41906e867462 *R/print.fads.R
-d0f79442970e383cf8c3bd1677320b53 *R/print.vads.R
-c4b216a6fb57acb020f5e21682f7ed13 *R/spp.R
-96dada922fee237e190207f544de8ed3 *R/summary.vads.R
-c5d76ac2aa5f6fa68c0cfd08f197989e *R/swin.R
-34b15c6ed440f88d868d3ab3b93db3b8 *R/triangulate.R
-a322bba8d53aff07f9a8ce9a69c89aef *R/util.R
-f2c452832a53eb1ed6d168b59918d52a *R/vads.R
-31fa89b542936dac1031133b12ef530c *data/Allogny.rda
-5450b84c345240671b3410af7c70bc44 *data/BPoirier.rda
-24fea786746fc897f8918300f2f2c544 *data/Couepia.rda
-a014cac4bc9abd4f40123a762939c8ca *data/Paracou15.rda
-674867657e9a3df07b6eced02aa022a1 *data/demopat.rda
-c7cd00087730e79e06e8c0d937d0b1f7 *inst/CITATION
-94a8b147b3d2730b0c3869a7e1a2592f *man/Allogny.Rd
-1755cf31329228337e0b8039af2b6daf *man/BPoirier.Rd
-d912451f743e11a9fbe50c8a6ef13b15 *man/Couepia.Rd
-4f272a7a2e7528da43c0d2ef8685921b *man/Paracou15.Rd
-b3c89a3bcb5db0d5fc9e93d8305df8c8 *man/area.swin.Rd
-d7b568c5332aad81bf4fb9f2bd4efed7 *man/demopat.Rd
-9b09cc667ab5d522e4a3a77c8b711159 *man/dval.Rd
-cd9ec1a82e0ee4e372e7ebd9c11233e4 *man/inside.swin.Rd
-e85df8cba02e1d7ae44b447ef05f0e3f *man/internal.Rd
-18f7794bc004e9b9599486a725f7da5b *man/k12fun.Rd
-26a82fbf3be668f7c74dd4f1b9fd93e4 *man/k12val.Rd
-f4c594ec01933acd9d9cae7e797685fe *man/kdfun.Rd
-aa725a3e6b7183290f7dd758d594810c *man/kfun.Rd
-ea3edb1e20ecd5aa794f48c9fa5ee0e5 *man/kmfun.Rd
-0e606a71b6ec6f730bdd0d1498834dbc *man/kp.fun.Rd
-500b63ba993de0b1f8a7d7f92765403b *man/kpqfun.Rd
-d388b950333aad22313c76d82f51c749 *man/krfun.Rd
-9970f6e4573f2e241de12d62ab201e23 *man/ksfun.Rd
-d5d294338860db9a406208f219f05f5e *man/kval.Rd
-1037e7421f3a50f15fcb07e88dcc260c *man/mimetic.Rd
-5bff5bb53402d742900fe12ed542877b *man/plot.fads.Rd
-7e88d95ac70e452257a939a70f9a1a76 *man/plot.spp.Rd
-c30babaf1b550ec45fa0f1bd89f967e5 *man/plot.vads.Rd
-2c61afcc548ad6440240664252a645a5 *man/spp.Rd
-cfe40689a11ec983e9b9bb4b759aaa26 *man/swin.Rd
-c04839dd6cd8eb396d512260a23dc7fd *man/triangulate.Rd
-22fae7567dd07dddf2ea00cb023c2be5 *src/Zlibs.c
-109615f7005a5a6e02b98bcf1a904551 *src/Zlibs.h
-3d7a3f0a98ac75ad014cc91fbe2d0579 *src/adssub.c
-bd642dbad07c62b2f39fae4c5640f93a *src/adssub.h
-8a3dad68f1826270eef7ea08e098dfc5 *src/spatstatsub.f
-5aa9f5862ef5b0e8bbcc327021e1489a *src/triangulate.c
-e482b9d18794f53adaed3f2c98edd19a *src/triangulate.h
-fb07aec2cf6396cab654966e2757ab5c *src/util.c
diff --git a/NAMESPACE b/NAMESPACE
index 7f723b74c0a0bf9d738e160054c72c30a7bee2d2..976578022125b26ee9a17d14059fa89f65aac953 100755
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,8 +1,81 @@
+# load DLL
+useDynLib(ads, .registration = TRUE, .fixes = "C_")
+
 # Import external pkg names
-# import(ade4, spatstat)
-importFrom(ade4,"divc","is.euclid")
-importFrom(spatstat,"border","bounding.box.xy","area.owin")
+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)
-exportPattern(".")
-# load DLL
-useDynLib(ads)
+export(
+	k12fun,
+	k12val,
+	kdfun,
+	kfun,
+	kmfun,
+	kp.fun,
+	kpqfun,
+	krfun,
+	ksfun,
+	kval,
+	swin,
+	area.swin,
+	inside.swin,
+	ppp2spp,
+	dval,
+	mimetic,
+	owin2swin,
+	spp,
+	triangulate,
+	mimetic,
+	spp,
+	swin
+)
+
+S3method(plot, kfun, plot.fads.kfun)
+S3method(plot, kdfun, plot.fads.kdfun)
+S3method(plot, k12fun, plot.fads.k12fun)
+S3method(plot, kpqfun, plot.fads.kpqfun)
+S3method(plot, kp.fun, plot.fads.kp.fun)
+S3method(plot, kmfun, plot.fads.kmfun)
+S3method(plot, ksfun, plot.fads.ksfun)
+S3method(plot, krfun, plot.fads.krfun)
+S3method(plot, mimetic)
+S3method(plot, spp)
+S3method(plot, swin)
+S3method(plot, dval, plot.vads.dval)
+S3method(plot, k12val, plot.vads.k12val)
+S3method(plot, kval, plot.vads.kval)
+
+S3method(print, kfun, print.fads.kfun)
+S3method(print, kdfun, print.fads.kdfun)
+S3method(print, k12fun, print.fads.k12fun)
+S3method(print, kpqfun, print.fads.kpqfun)
+S3method(print, kp.fun, print.fads.kp.fun)
+S3method(print, kmfun, print.fads.kmfun)
+S3method(print, ksfun, print.fads.ksfun)
+S3method(print, krfun, print.fads.krfun)
+S3method(print, spp)
+S3method(print, swin)
+S3method(print, dval, print.vads.dval)
+S3method(print, k12val, print.vads.k12val)
+S3method(print, kval, print.vads.kval)
+S3method(print, summary.dval)
+S3method(print, summary.k12val)
+S3method(print, summary.kval)
+S3method(print, summary.spp)
+S3method(print, summary.swin)
+
+S3method(summary, spp)
+S3method(summary, swin)
+S3method(summary, dval, summary.vads.dval)
+S3method(summary, k12val, summary.vads.k12val)
+S3method(summary, kval, summary.vads.kval)
diff --git a/R/fads.R b/R/fads.R
index dd947c22d0d849edef16365faa74e72086916812..c0afdfb726e86b9bf939ad4a77192caf368b2e8d 100755
--- a/R/fads.R
+++ b/R/fads.R
@@ -1,1255 +1,1255 @@
-kfun<-function(p,upto,by,nsim=0,prec=0.01,alpha=0.01) {
-	# checking for input parameters
-	stopifnot(inherits(p,"spp"))
-	if(p$type!="univariate")
-		warning(paste(p$type,"point pattern has been considered to be univariate\n"))
-	stopifnot(is.numeric(upto))
-	stopifnot(upto>=1)
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	stopifnot(is.numeric(nsim))
-	stopifnot(nsim>=0)
-	nsim<-testInteger(nsim)	
-	stopifnot(is.numeric(prec))
-	stopifnot(prec>=0)
-	stopifnot(is.numeric(alpha))
-	stopifnot(alpha>=0)
-	if(nsim>0) testIC(nsim,alpha)
-
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-		stop("invalid window type")
-	intensity<-p$n/area.swin(p$window)
-	
-	if(cas==1) { #rectangle
-		if(nsim==0) { #without CI
-			res<-.C("ripley_rect",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					as.integer(tmax),as.double(by),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("ripley_rect_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),as.double(intensity),
-					as.integer(tmax),as.double(by),
-					as.integer(nsim),as.double(prec),as.double(alpha),
-					g=double(tmax),k=double(tmax),
-					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==2) { #circle
-		if(nsim==0) { #without CI
-			res<-.C("ripley_disq",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(x0),as.double(y0),as.double(r0),
-					as.integer(tmax),as.double(by),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}
-		else { #with CI
-			res<-.C("ripley_disq_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(x0),as.double(y0),as.double(r0),as.double(intensity),
-					as.integer(tmax),as.double(by),
-					as.integer(nsim),as.double(prec),as.double(alpha),
-					g=double(tmax),k=double(tmax),
-					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
-					PACKAGE="ads")
-		}	
-	}
-	else if(cas==3) { #complex within rectangle
-		if(nsim==0) { #without CI
-			res<-.C("ripley_tr_rect",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}
-		else { #with CI
-			res<-.C("ripley_tr_rect_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),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(prec),as.double(alpha),
-					g=double(tmax),k=double(tmax),
-					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
-					PACKAGE="ads")	
-		}	
-	}
-	else if(cas==4) { #complex within circle
-		if(nsim==0) { #without CI		
-			res<-.C("ripley_tr_disq",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(x0),as.double(y0),as.double(r0),
-					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),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")	
-		}
-		else { #with CI
-			res<-.C("ripley_tr_disq_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					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(prec),as.double(alpha),
-					g=double(tmax),k=double(tmax),
-					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
-					PACKAGE="ads")	
-		}
-	}
-	# formatting results
-	ds<-c(pi,diff(pi*r^2))
-	g<-data.frame(obs=res$g/(intensity*ds),theo=rep(1,tmax))
-	n<-data.frame(obs=res$k/(pi*r^2),theo=rep(intensity,tmax))
-	k<-data.frame(obs=res$k/intensity,theo=pi*r^2)
-	l<-data.frame(obs=sqrt(res$k/(intensity*pi))-r,theo=rep(0,tmax))
-	if(nsim>0) {
-		g<-cbind(g,sup=res$gic1/(intensity*ds),inf=res$gic2/(intensity*ds),pval=res$gval/(nsim+1))
-		n<-cbind(n,sup=res$kic1/(pi*r^2),inf=res$kic2/(pi*r^2),pval=res$nval/(nsim+1))
-		k<-cbind(k,sup=res$kic1/intensity,inf=res$kic2/intensity,pval=res$kval/(nsim+1))
-		l<-cbind(l,sup=sqrt(res$kic1/(intensity*pi))-r,inf=sqrt(res$kic2/(intensity*pi))-r,pval=res$lval/(nsim+1))
-	}
-	call<-match.call()
-	res<-list(call=call,r=r,g=g,n=n,k=k,l=l)
-	class(res)<-c("fads","kfun")
-	return(res)
-}
-
-k12fun<-function(p,upto,by,nsim=0,H0=c("pitor","pimim","rl"),prec=0.01,nsimax=3000,conv=50,rep=10,alpha=0.01,marks) {
-	# checking for input parameters
-	options( CBoundsCheck = TRUE )
-	# regle les problemes pour 32-bit
-	stopifnot(inherits(p,"spp"))
-	stopifnot(p$type=="multivariate")
-	stopifnot(is.numeric(upto))
-	stopifnot(upto>=1)
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	stopifnot(is.numeric(nsim))
-	stopifnot(nsim>=0)
-	nsim<-testInteger(nsim)
-	H0<-H0[1]
-	stopifnot(H0=="pitor" || H0=="pimim" || H0=="rl")
-	if(H0=="rl") H0<-1
-	else if(H0=="pitor") H0<-2
-	else H0<-3
-	stopifnot(is.numeric(prec))
-	stopifnot(prec>=0)
-	stopifnot(is.numeric(alpha))
-	stopifnot(alpha>=0)
-	if(nsim>0) testIC(nsim,alpha)
-	if(missing(marks))
-		marks<-c(1,2)
-	stopifnot(length(marks)==2)
-	stopifnot(marks[1]!=marks[2])
-	mark1<-marks[1]
-	mark2<-marks[2]
-	if(is.numeric(mark1))
-		mark1<-levels(p$marks)[testInteger(mark1)]
-	else if(!mark1%in%p$marks) stop(paste("mark \'",mark1,"\' doesn\'t exist",sep=""))
-	if(is.numeric(mark2))
-		mark2<-levels(p$marks)[testInteger(mark2)]
-	else if(!mark2%in%p$marks) stop(paste("mark \'",mark2,"\' doesn\'t exist",sep=""))
-	
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-		stop("invalid window type")
-	surface<-area.swin(p$window)
-	x1<-p$x[p$marks==mark1]
-	y1<-p$y[p$marks==mark1]
-	x2<-p$x[p$marks==mark2]
-	y2<-p$y[p$marks==mark2]
-	nbPts1<-length(x1)
-	nbPts2<-length(x2)
-	intensity2<-nbPts2/surface
-#	intensity<-(nbPts1+nbPts2)/surface
-	
-	# computing intertype functions
-	if(cas==1) { #rectangle
-		if(nsim==0) { #without CI
-			res<-.C("intertype_rect",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),					
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
-					as.integer(tmax),as.double(by),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}
-		else { #with CI
-			res<-.C("intertype_rect_ic",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),as.double(surface),
-					as.integer(tmax),as.double(by),
-					as.integer(nsim),as.integer(H0),as.double(prec),as.integer(nsimax),as.integer(conv),as.integer(rep),as.double(alpha),
-					g=double(tmax),k=double(tmax),
-					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==2) { #circle
-		if(nsim==0) { #without CI
-			res<-.C("intertype_disq",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(x0),as.double(y0),as.double(r0),					
-					as.integer(tmax),as.double(by),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}
-		else { #with CI
-			res<-.C("intertype_disq_ic",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(x0),as.double(y0),as.double(r0),as.double(surface),
-					as.integer(tmax),as.double(by),
-					as.integer(nsim),as.integer(H0),as.double(prec),as.integer(nsimax),as.integer(conv),as.integer(rep),as.double(alpha),
-					g=double(tmax),k=double(tmax),
-					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
-					PACKAGE="ads")		
-		}
-	}
-	else if(cas==3) { #complex within rectangle
-		if(nsim==0) { #without CI
-			res<-.C("intertype_tr_rect",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
-					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),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}
-		else { #with CI
-			res<-.C("intertype_tr_rect_ic",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),as.double(surface),
-					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.integer(H0),as.double(prec),as.integer(nsimax),as.integer(conv),as.integer(rep),as.double(alpha),
-					g=double(tmax),k=double(tmax),
-					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
-					PACKAGE="ads")		
-		}
-	}
-	else if(cas==4) { #complex within circle
-		if(nsim==0) { #without CI
-			res<-.C("intertype_tr_disq",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(x0),as.double(y0),as.double(r0),					
-					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),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}
-		else { #with CI
-			res<-.C("intertype_tr_disq_ic",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(x0),as.double(y0),as.double(r0),as.double(surface),
-					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.integer(H0),as.double(prec),as.integer(nsimax),as.integer(conv),as.integer(rep),as.double(alpha),
-					g=double(tmax),k=double(tmax),
-					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
-					PACKAGE="ads")		
-		}
-	}	
-	# formatting results
-	ds<-c(pi,diff(pi*r^2))
-	g<-res$g/(intensity2*ds)
-	n<-res$k/(pi*r^2)
-	k<-res$k/intensity2
-	l<-sqrt(res$k/(intensity2*pi))-r
-	if(H0==1) {
-		rip<-kfun(spp(c(x1,x2),c(y1,y2),p$window),upto,by)
-		theo<-list(g=rip$g$obs,n=intensity2*rip$k$obs/(pi*r^2),k=rip$k$obs,l=rip$l$obs)
-	}
-	else if (H0==2||H0==3)
-		theo<-list(g=rep(1,tmax),n=rep(intensity2,tmax),k=pi*r^2,l=rep(0,tmax))
-	g<-data.frame(obs=g,theo=theo$g)
-	n<-data.frame(obs=n,theo=theo$n)
-	k<-data.frame(obs=k,theo=theo$k)
-	l<-data.frame(obs=l,theo=theo$l)
-	if(nsim>0) {
-		g<-cbind(g,sup=res$gic1/(intensity2*ds),inf=res$gic2/(intensity2*ds),pval=res$gval/(nsim+1))
-		n<-cbind(n,sup=res$kic1/(pi*r^2),inf=res$kic2/(pi*r^2),pval=res$nval/(nsim+1))
-		k<-cbind(k,sup=res$kic1/intensity2,inf=res$kic2/intensity2,pval=res$kval/(nsim+1))
-		l<-cbind(l,sup=sqrt(res$kic1/(intensity2*pi))-r,inf=sqrt(res$kic2/(intensity2*pi))-r,pval=res$lval/(nsim+1))
-	}	
-	call<-match.call()
-	res<-list(call=call,r=r,g12=g,n12=n,k12=k,l12=l,marks=c(mark1,mark2))
-	class(res)<-c("fads","k12fun")
-	return(res)
-}
-
-kijfun<-kpqfun<-function(p,upto,by) {
-# checking for input parameters
-	stopifnot(inherits(p,"spp"))
-	stopifnot(p$type=="multivariate")
-	stopifnot(is.numeric(upto))
-	stopifnot(upto>=1)
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-	stop("invalid window type")
-	surface<-area.swin(p$window)
-	
-	tabMarks<-levels(p$marks)
-	nbMarks<-length(tabMarks)
-	mpt_nb<-summary(p$marks)	
-# computing RipleyClass
-	gij<-double(tmax*nbMarks^2)
-	kij<-double(tmax*nbMarks^2)
-	lij<-double(tmax*nbMarks^2)
-	nij<-double(tmax*nbMarks^2)
-	for(i in 1:nbMarks) {
-		x1<-p$x[p$marks==tabMarks[i]]
-		y1<-p$y[p$marks==tabMarks[i]]		
-		if(cas==1) { #rectangle
-			res<-.C("ripley_rect",
-					as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					as.integer(tmax),as.double(by),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")
-		}
-		else if(cas==2) { #circle
-			res<-.C("ripley_disq",
-					as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
-					as.double(x0),as.double(y0),as.double(r0),
-					as.integer(tmax),as.double(by),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")
-		}
-		else if(cas==3) { #complex within rectangle
-			res<-.C("ripley_tr_rect",
-					as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")
-		}
-		else if(cas==4) { #complex within circle
-			res<-.C("ripley_tr_disq",
-					as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
-					as.double(x0),as.double(y0),as.double(r0),
-					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),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")
-		}
-		intensity1<-mpt_nb[i]/surface
-		matcol<-(i-1)*nbMarks+i-1
-		j<-(matcol*tmax+1):(matcol*tmax+tmax)
-		ds<-c(pi,diff(pi*r^2))
-		gij[j]<-res$g/(intensity1*ds)
-		nij[j]<-res$k/(pi*r^2)
-		kij[j]<-res$k/intensity1
-		lij[j]<-sqrt(res$k/(intensity1*pi))-r
-		if(i<nbMarks) {
-			for(j in (i+1):nbMarks) {
-				x2<-p$x[p$marks==tabMarks[j]]
-				y2<-p$y[p$marks==tabMarks[j]]		
-				if(cas==1) { #rectangle
-					res<-.C("intertype_rect",
-							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
-							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),					
-							as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
-							as.integer(tmax),as.double(by),
-							g=double(tmax),k=double(tmax),
-							PACKAGE="ads")					
-				}
-				else if(cas==2) { #circle
-					res<-.C("intertype_disq",
-							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
-							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
-							as.double(x0),as.double(y0),as.double(r0),					
-							as.integer(tmax),as.double(by),
-							g=double(tmax),k=double(tmax),
-							PACKAGE="ads")					
-				}
-				else if(cas==3) { #complex within rectangle
-					res<-.C("intertype_tr_rect",
-							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
-							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
-							as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
-							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),
-							g=double(tmax),k=double(tmax),
-							PACKAGE="ads")
-				}
-				else if(cas==4) { #complex within circle
-					res<-.C("intertype_tr_disq",
-							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
-							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
-							as.double(x0),as.double(y0),as.double(r0),					
-							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),
-							g=double(tmax),k=double(tmax),
-							PACKAGE="ads")					
-				}
-				intensity2<-mpt_nb[j]/surface
-				matcol<-(i-1)*nbMarks+j-1
-				k<-(matcol*tmax+1):(matcol*tmax+tmax)
-				gij[k]<-res$g/(intensity2*ds)
-				nij[k]<-res$k/(pi*r^2)
-				kij[k]<-res$k/intensity2
-				lij[k]<-sqrt(res$k/(intensity2*pi))-r				
-				if(cas==1) { #rectangle
-					res<-.C("intertype_rect",
-							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
-							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),											
-							as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
-							as.integer(tmax),as.double(by),
-							g=double(tmax),k=double(tmax),
-							PACKAGE="ads")					
-				}
-				else if(cas==2) { #circle
-					res<-.C("intertype_disq",
-							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
-							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),						
-							as.double(x0),as.double(y0),as.double(r0),					
-							as.integer(tmax),as.double(by),
-							g=double(tmax),k=double(tmax),
-							PACKAGE="ads")					
-				}
-				else if(cas==3) { #complex within rectangle
-					res<-.C("intertype_tr_rect",
-							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
-							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),						
-							as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
-							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),
-							g=double(tmax),k=double(tmax),
-							PACKAGE="ads")
-				}
-				else if(cas==4) { #complex within circle
-					res<-.C("intertype_tr_disq",
-							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
-							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),						
-							as.double(x0),as.double(y0),as.double(r0),					
-							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),
-							g=double(tmax),k=double(tmax),
-							PACKAGE="ads")					
-				}								
-				matcol<-(j-1)*nbMarks+i-1
-				k<-(matcol*tmax+1):(matcol*tmax+tmax)
-				gij[k]<-res$g/(intensity1*ds)
-				nij[k]<-res$k/(pi*r^2)
-				kij[k]<-res$k/intensity1
-				lij[k]<-sqrt(res$k/(intensity1*pi))-r
-			}
-		}
-	}
-	labij<-paste(rep(tabMarks,each=nbMarks),rep(tabMarks,nbMarks),sep="-")
-	gij<-matrix(gij,nrow=tmax,ncol=nbMarks^2)
-	kij<-matrix(kij,nrow=tmax,ncol=nbMarks^2)
-	nij<-matrix(nij,nrow=tmax,ncol=nbMarks^2)
-	lij<-matrix(lij,nrow=tmax,ncol=nbMarks^2)
-	call<-match.call()
-	res<-list(call=call,r=r,labpq=labij,gij=gij,kpq=kij,lpq=lij,npq=nij,intensity=summary(p)$intensity)
-	class(res)<-c("fads","kpqfun")
-	return(res)
-}
-
-ki.fun<-kp.fun<-function(p,upto,by) {
-	# checking for input parameters
-	stopifnot(inherits(p,"spp"))
-		stopifnot(p$type=="multivariate")
-	stopifnot(is.numeric(upto))
-	stopifnot(upto>=1)
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-		stop("invalid window type")
-	surface<-area.swin(p$window)
-
-	tabMarks<-levels(p$marks)
-	nbMarks<-length(tabMarks)
-	mpt_nb<-summary(p$marks)		
-	#computing RipleyAll
-	gis<-double(tmax*nbMarks)
-	kis<-double(tmax*nbMarks)
-	lis<-double(tmax*nbMarks)
-	nis<-double(tmax*nbMarks)
-	for(i in 1:nbMarks) {
-		x1<-p$x[p$marks==tabMarks[i]]
-		y1<-p$y[p$marks==tabMarks[i]]
-		x2<-p$x[p$marks!=tabMarks[i]]
-		y2<-p$y[p$marks!=tabMarks[i]]
-		nbPts1<-mpt_nb[i]
-		nbPts2<-sum(mpt_nb)-nbPts1		
-		if(cas==1) { #rectangle
-			res<-.C("intertype_rect",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),					
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
-					as.integer(tmax),as.double(by),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}
-		else if(cas==2) { #circle
-			res<-.C("intertype_disq",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(x0),as.double(y0),as.double(r0),					
-					as.integer(tmax),as.double(by),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}
-		else if(cas==3) { #complex within rectangle
-			res<-.C("intertype_tr_rect",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
-					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),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")
-		}
-		else if(cas==4) { #complex within circle
-			res<-.C("intertype_tr_disq",
-					as.integer(nbPts1),as.double(x1),as.double(y1),
-					as.integer(nbPts2),as.double(x2),as.double(y2),
-					as.double(x0),as.double(y0),as.double(r0),					
-					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),
-					g=double(tmax),k=double(tmax),
-					PACKAGE="ads")					
-		}		
-		intensity2<-nbPts2/surface
-		j<-((i-1)*tmax+1):((i-1)*tmax+tmax)
-		ds<-c(pi,diff(pi*r^2))
-		gis[j]<-res$g/(intensity2*ds)
-		nis[j]<-res$k/(pi*r^2)
-		kis[j]<-res$k/intensity2
-		lis[j]<-sqrt(res$k/(intensity2*pi))-r
-	}	
-	# formatting results
-	labi<-tabMarks
-	gis<-matrix(gis,nrow=tmax,ncol=nbMarks)
-	kis<-matrix(kis,nrow=tmax,ncol=nbMarks)
-	nis<-matrix(nis,nrow=tmax,ncol=nbMarks)
-	lis<-matrix(lis,nrow=tmax,ncol=nbMarks)
-	call<-match.call()
-	res<-list(call=call,r=r,labp=labi,gp.=gis,kp.=kis,lp.=lis,np.=nis,intensity=summary(p)$intensity)
-	class(res)<-c("fads","kp.fun")
-	return(res)
-}
-
-kmfun<-function(p,upto,by,nsim=0,alpha=0.01) {
-	# checking for input parameters
-	stopifnot(inherits(p,"spp"))
-	stopifnot(p$type=="marked")
-	stopifnot(is.numeric(upto))
-	stopifnot(upto>=1)
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	stopifnot(is.numeric(nsim))
-	stopifnot(nsim>=0)
-	nsim<-testInteger(nsim)
-	#cmoy<-mean(p$marks)
-	cvar<-var(p$marks)
-	stopifnot(is.numeric(alpha))
-	stopifnot(alpha>=0)
-	if(nsim>0) testIC(nsim,alpha)
-
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-		stop("invalid window type")
-	intensity<-p$n/area.swin(p$window)
-	
-	if(cas==1) { #rectangle
-		if(nsim==0) { #without CI
-			res<-.C("corr_rect",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					as.integer(tmax),as.double(by),
-					gm=double(tmax),km=double(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("corr_rect_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==2) { #circle
-		if(nsim==0) { #without CI
-			res<-.C("corr_disq",
-					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.integer(tmax),as.double(by),
-					gm=double(tmax),km=double(tmax),
-					PACKAGE="ads")					
-		}
-		else { #with CI
-			res<-.C("corr_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.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),
-					PACKAGE="ads")
-		}	
-	}
-	else if(cas==3) { #complex within rectangle
-		if(nsim==0) { #without CI
-			res<-.C("corr_tr_rect",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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),
-					gm=double(tmax),km=double(tmax),
-					PACKAGE="ads")					
-		}
-		else { #with CI
-			res<-.C("corr_tr_rect_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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),
-					PACKAGE="ads")	
-		}	
-	}
-	else if(cas==4) { #complex within circle
-		if(nsim==0) { #without CI		
-			res<-.C("corr_tr_disq",
-					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.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),
-					gm=double(tmax),km=double(tmax),
-					PACKAGE="ads")	
-		}
-		else { #with CI
-			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.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),
-					PACKAGE="ads")	
-		}
-	}
-	# formatting results
-	gm<-data.frame(obs=res$gm,theo=rep(0,tmax))
-	km<-data.frame(obs=res$km,theo=rep(0,tmax))
-	if(nsim>0) {
-		gm<-cbind(gm,sup=res$gmic1,inf=res$gmic2,pval=res$gmval/(nsim+1))
-		km<-cbind(km,sup=res$kmic1,inf=res$kmic2,pval=res$kmval/(nsim+1))
-	}
-	call<-match.call()
-	res<-list(call=call,r=r,gm=gm,km=km)
-	class(res)<-c("fads","kmfun")
-	return(res)
-}
-
-ksfun<-function(p,upto,by,nsim=0,alpha=0.01) {
-# checking for input parameters
-	#options( CBoundsCheck = TRUE )
-	stopifnot(inherits(p,"spp"))
-	stopifnot(p$type=="multivariate")
-	stopifnot(is.numeric(upto))
-	stopifnot(upto>=1)
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	stopifnot(is.numeric(nsim))
-	stopifnot(nsim>=0)
-	nsim<-testInteger(nsim)
-	stopifnot(is.numeric(alpha))
-	stopifnot(alpha>=0)
-	if(nsim>0) testIC(nsim,alpha)
-	
-###faire test sur les marks
-	
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-	stop("invalid window type")
-	surface<-area.swin(p$window)
-	intensity<-p$n/surface
-	tabMarks<-levels(p$marks)
-	nbMarks<-nlevels(p$marks)
-#nbMarks<-length(tabMarks)
-	marks<-as.numeric(p$marks)	
-	freq<-as.vector(table(p$marks))
-	D<-1-sum(freq*(freq-1))/(p$n*(p$n-1))
-
-# computing Shimatani	
-	if(cas==1) { #rectangle
-		if(nsim==0) { #without CI
-			res<-.C("shimatani_rect",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					as.integer(tmax),as.double(by),
-					as.integer(nbMarks),as.integer(marks),as.double(surface),gg=double(tmax),kk=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("shimatani_rect_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					as.integer(tmax),as.double(by), as.integer(nsim), as.double(alpha),
-					as.integer(nbMarks),as.integer(marks),as.double(surface),as.double(D),
-					gg=double(tmax),kk=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==2) { #circle
-		if(nsim==0) { #without CI
-			res<-.C("shimatani_disq",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(x0),as.double(y0),as.double(r0),
-					as.integer(tmax),as.double(by),
-					as.integer(nbMarks),as.integer(marks),as.double(surface),gg=double(tmax),kk=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("shimatani_disq_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(x0),as.double(y0),as.double(r0),
-					as.integer(tmax),as.double(by), as.integer(nsim), as.double(alpha),
-					as.integer(nbMarks),as.integer(marks),as.double(surface),as.double(D),
-					gg=double(tmax),kk=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==3) { #complex within rectangle
-		if(nsim==0) { #without CI
-			res<-.C("shimatani_tr_rect",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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(nbMarks),as.integer(marks),as.double(surface),gg=double(tmax),kk=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("shimatani_tr_rect_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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),
-					as.integer(nbMarks),as.integer(marks),as.double(surface),as.double(D),
-					gg=double(tmax),kk=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==4) { #complex within circle
-		if(nsim==0) { #without CI		
-			res<-.C("shimatani_tr_disq",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(x0),as.double(y0),as.double(r0),
-					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(nbMarks),as.integer(marks),as.double(surface),gg=double(tmax),kk=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("shimatani_tr_disq_ic",
-				   as.integer(p$n),as.double(p$x),as.double(p$y),as.double(x0),as.double(y0),as.double(r0),
-				   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),
-				   as.integer(nbMarks),as.integer(marks),as.double(surface),as.double(D),
-				   gg=double(tmax),kk=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-				   gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
-				   PACKAGE="ads")
-		}
-	}		
-	if(sum(res$erreur>0)){
-		message("Error in ", appendLF=F)
-		print(match.call())
-		message("No neigbors within distance intervals:")
-		print(paste(by*(res$erreur[res$erreur>0]-1),"-",by*res$erreur[res$erreur>0]))
-		message("Increase argument 'by'")
-		return(res=NULL)
-	}
-	gs<-data.frame(obs=res$gg/D,theo=rep(1,tmax))
-	ks<-data.frame(obs=res$kk/D,theo=rep(1,tmax))
-	if(nsim>0) {
-		gs<-cbind(gs,sup=res$gic1/D,inf=res$gic2/D,pval=res$gval/(nsim+1))
-		ks<-cbind(ks,sup=res$kic1/D,inf=res$kic2/D,pval=res$kval/(nsim+1))
-	}
-	call<-match.call()
-	res<-list(call=call,r=r,gs=gs,ks=ks)
-	class(res)<-c("fads","ksfun")
-	return(res)
-}
-
-
-#################
-#V2 that calls K12fun
-##############
-krfun<-function(p,upto,by,nsim=0,dis=NULL,H0=c("rl","se"),alpha=0.01) {
-# checking for input parameters
-	stopifnot(inherits(p,"spp"))
-	stopifnot(p$type=="multivariate")
-	stopifnot(is.numeric(upto))
-	stopifnot(upto>=1)
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	H0<-H0[1]
-	stopifnot(H0=="se" || H0=="rl")
-	ifelse(H0=="se",H0<-2,H0<-1)
-	if(is.null(dis)) {
-		stopifnot(H0==1)
-		dis<-as.dist(matrix(1,nlevels(p$marks),nlevels(p$marks)))
-		attr(dis,"Labels")<-levels(p$marks)
-	}
-	stopifnot(inherits(dis,"dist"))
-	stopifnot(attr(dis,"Diag")==FALSE)
-	stopifnot(attr(dis,"Upper")==FALSE)
-	stopifnot(suppressWarnings(is.euclid(dis)))
-###revoir tests sur dis	
-	if(length(levels(p$marks))!=length(labels(dis))) {
-		stopifnot(all(levels(p$marks)%in%labels(dis)))
-#dis<-subsetdist(dis,which(labels(dis)%in%levels(p$marks)))
-		dis<-subsetdist(dis,levels(p$marks))
-		warning("matrix 'dis' have been subsetted to match with levels(p$marks)")
-	}
-#else if(any(labels(dis)!=levels(p$marks))) {
-#		attr(dis,"Labels")<-levels(p$marks)
-#		warning("levels(p$marks) have been assigned to attr(dis, ''Labels'')")
-#	}
-	stopifnot(is.numeric(nsim))
-	stopifnot(nsim>=0)
-	nsim<-testInteger(nsim)
-	stopifnot(is.numeric(alpha))
-	stopifnot(alpha>=0)
-	if(nsim>0) testIC(nsim,alpha)
-	
-###faire test sur les marks
-	
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-		stop("invalid window type")
-	surface<-area.swin(p$window)
-	intensity<-p$n/surface
-	nbMarks<-nlevels(p$marks)
-	marks<-as.numeric(p$marks) # => position du label dans levels(p$marks)
-	dis<-as.dist(sortmat(dis,levels(p$marks)))
-	HD<-suppressWarnings(divc(as.data.frame(unclass(table(p$marks))),sqrt(2*dis),scale=F)[1,1])
-	HD<-HD*p$n/(p$n-1)
-	dis<-as.vector(dis)
-		
-# computing Rao	
-	if(cas==1) { #rectangle
-		if(nsim==0) { #without CI
-			res<-.C("rao_rect",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					as.integer(tmax),as.double(by),as.integer(H0),
-					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("rao_rect_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					as.integer(tmax),as.double(by), as.integer(nsim),as.integer(H0),as.double(alpha),
-					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==2) { #circle
-		if(nsim==0) { #without CI
-			res<-.C("rao_disq",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(x0),as.double(y0),as.double(r0),
-					as.integer(tmax),as.double(by),as.integer(H0),
-					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("rao_disq_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(x0),as.double(y0),as.double(r0),
-					as.integer(tmax),as.double(by), as.integer(nsim),as.integer(H0),as.double(alpha),
-					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==3) { #complex within rectangle
-		if(nsim==0) { #without CI
-			res<-.C("rao_tr_rect",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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(H0),
-					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-		else { #with CI
-			res<-.C("rao_tr_rect_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					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.integer(H0),as.double(alpha),
-					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
-					PACKAGE="ads")
-		}
-	}
-	else if(cas==4) { #complex within circle
-		if(nsim==0) { #without CI	
-			res<-.C("rao_tr_disq",
-				   as.integer(p$n),as.double(p$x),as.double(p$y),
-				   as.double(x0),as.double(y0),as.double(r0),
-				   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(H0),
-				   as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-				   gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),erreur=integer(tmax),
-				   PACKAGE="ads")
-		}
-		else { #with CI (not based on K12)
-			res<-.C("rao_tr_disq_ic",
-					as.integer(p$n),as.double(p$x),as.double(p$y),
-					as.double(x0),as.double(y0),as.double(r0),
-					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.integer(H0),as.double(alpha),
-					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-					gval=double(tmax),kval=double(tmax),serreur=integer(tmax),
-					PACKAGE="ads")
-		}
-	}		
-	if(sum(res$erreur>0)){
-		message("Error in ", appendLF=F)
-		print(match.call())
-		message("No neigbors within distance intervals:")
-		print(paste(by*(res$erreur[res$erreur>0]-1),"-",by*res$erreur[res$erreur>0]))
-		message("Increase argument 'by'")
-		return(res=NULL)
-	}
-	if(H0==1) {
-		theog<-rep(1,tmax)
-		theok<-rep(1,tmax)
-	}
-	if(H0==2) {
-		theog<-res$gs
-		theok<-res$ks
-	}
-	gr<-data.frame(obs=res$gg,theo=theog)
-	kr<-data.frame(obs=res$kk,theo=theok)
-	if(nsim>0) {
-		gr<-cbind(gr,sup=res$gic1,inf=res$gic2,pval=res$gval/(nsim+1))
-		kr<-cbind(kr,sup=res$kic1,inf=res$kic2,pval=res$kval/(nsim+1))
-	}
-	call<-match.call()
-	res<-list(call=call,r=r,gr=gr,kr=kr)
-	class(res)<-c("fads","krfun")
-	return(res)
-}
-
-kdfun<-function(p,upto,by,dis,nsim=0,alpha=0.01) {
-# checking for input parameters
-	stopifnot(inherits(p,"spp"))
-	stopifnot(p$type=="multivariate")
-	if(min(p$x)<0)
-		p$x<-p$x+abs(min(p$x))
-	if(min(p$y)<0)
-		p$y<-p$y+abs(min(p$y))
-	stopifnot(is.numeric(upto))
-	stopifnot(upto>=1)
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	stopifnot(inherits(dis,"dist"))
-	stopifnot(attr(dis,"Diag")==FALSE)
-	stopifnot(attr(dis,"Upper")==FALSE)
-	stopifnot(suppressWarnings(is.euclid(dis)))
-###revoir tests sur dis	
-	if(length(levels(p$marks))!=length(labels(dis))) {
-		stopifnot(all(levels(p$marks)%in%labels(dis)))
-#dis<-subsetdist(dis,which(labels(dis)%in%levels(p$marks)))
-		dis<-subsetdist(dis,levels(p$marks))
-		warning("matrix 'dis' have been subsetted to match with levels(p$marks)")
-	}
-#else if(any(labels(dis)!=levels(p$marks))) {
-#		attr(dis,"Labels")<-levels(p$marks)
-#		warning("levels(p$marks) have been assigned to attr(dis, ''Labels'')")
-#	}
-	stopifnot(is.numeric(nsim))
-	stopifnot(nsim>=0)
-	nsim<-testInteger(nsim)
-	stopifnot(is.numeric(alpha))
-	stopifnot(alpha>=0)
-	if(nsim>0) testIC(nsim,alpha)
-	
-	surface<-area.swin(p$window)
-	intensity<-p$n/surface
-	nbMarks<-nlevels(p$marks)
-	marks<-as.numeric(p$marks) # => position du label dans levels(p$marks)
-	dis<-as.dist(sortmat(dis,levels(p$marks)))
-	HD<-suppressWarnings(divc(as.data.frame(unclass(table(p$marks))),sqrt(2*dis),scale=F)[1,1])
-	HD<-HD*p$n/(p$n-1)
-	dis<-as.vector(dis)
-
-###faire test sur les marks
-	
-	if(nsim==0) { #without CI
-		res<-.C("shen",
-			as.integer(p$n),as.double(p$x),as.double(p$y),
-			as.integer(tmax),as.double(by),
-			as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-			gd=double(tmax),kd=double(tmax),erreur=integer(tmax),
-			PACKAGE="ads")
-	}
-	else { #with CI
-		res<-.C("shen_ic",
-			as.integer(p$n),as.double(p$x),as.double(p$y),
-			as.integer(tmax),as.double(by), as.integer(nsim),as.double(alpha),
-			as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
-			gd=double(tmax),kd=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
-			gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
-			PACKAGE="ads")
-	}	
-	
-	if(sum(res$erreur>0)){
-		message("Error in ", appendLF=F)
-		print(match.call())
-		message("No neigbors within distance intervals:")
-		print(paste(by*(res$erreur[res$erreur>0]-1),"-",by*res$erreur[res$erreur>0]))
-		message("Increase argument 'by'")
-		return(res=NULL)
-	}
-	gd<-data.frame(obs=res$gd,theo=rep(1,tmax))
-	kd<-data.frame(obs=res$kd,theo=rep(1,tmax))
-	if(nsim>0) {
-		gd<-cbind(gd,sup=res$gic1,inf=res$gic2,pval=res$gval/(nsim+1))
-		kd<-cbind(kd,sup=res$kic1,inf=res$kic2,pval=res$kval/(nsim+1))
-	}
-	call<-match.call()
-	res<-list(call=call,r=r,gd=gd,kd=kd)
-	class(res)<-c("fads","kdfun")
-	return(res)
-}
+kfun<-function(p,upto,by,nsim=0,prec=0.01,alpha=0.01) {
+	# checking for input parameters
+	stopifnot(inherits(p,"spp"))
+	if(p$type!="univariate")
+		warning(paste(p$type,"point pattern has been considered to be univariate\n"))
+	stopifnot(is.numeric(upto))
+	stopifnot(upto>=1)
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	stopifnot(is.numeric(nsim))
+	stopifnot(nsim>=0)
+	nsim<-testInteger(nsim)	
+	stopifnot(is.numeric(prec))
+	stopifnot(prec>=0)
+	stopifnot(is.numeric(alpha))
+	stopifnot(alpha>=0)
+	if(nsim>0) testIC(nsim,alpha)
+
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+		stop("invalid window type")
+	intensity<-p$n/area.swin(p$window)
+	
+	if(cas==1) { #rectangle
+		if(nsim==0) { #without CI
+			res<-.C("ripley_rect",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					as.integer(tmax),as.double(by),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("ripley_rect_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),as.double(intensity),
+					as.integer(tmax),as.double(by),
+					as.integer(nsim),as.double(prec),as.double(alpha),
+					g=double(tmax),k=double(tmax),
+					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==2) { #circle
+		if(nsim==0) { #without CI
+			res<-.C("ripley_disq",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(x0),as.double(y0),as.double(r0),
+					as.integer(tmax),as.double(by),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}
+		else { #with CI
+			res<-.C("ripley_disq_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(x0),as.double(y0),as.double(r0),as.double(intensity),
+					as.integer(tmax),as.double(by),
+					as.integer(nsim),as.double(prec),as.double(alpha),
+					g=double(tmax),k=double(tmax),
+					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
+					PACKAGE="ads")
+		}	
+	}
+	else if(cas==3) { #complex within rectangle
+		if(nsim==0) { #without CI
+			res<-.C("ripley_tr_rect",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}
+		else { #with CI
+			res<-.C("ripley_tr_rect_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),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(prec),as.double(alpha),
+					g=double(tmax),k=double(tmax),
+					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
+					PACKAGE="ads")	
+		}	
+	}
+	else if(cas==4) { #complex within circle
+		if(nsim==0) { #without CI		
+			res<-.C("ripley_tr_disq",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(x0),as.double(y0),as.double(r0),
+					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),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")	
+		}
+		else { #with CI
+			res<-.C("ripley_tr_disq_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					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(prec),as.double(alpha),
+					g=double(tmax),k=double(tmax),
+					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
+					PACKAGE="ads")	
+		}
+	}
+	# formatting results
+	ds<-c(pi,diff(pi*r^2))
+	g<-data.frame(obs=res$g/(intensity*ds),theo=rep(1,tmax))
+	n<-data.frame(obs=res$k/(pi*r^2),theo=rep(intensity,tmax))
+	k<-data.frame(obs=res$k/intensity,theo=pi*r^2)
+	l<-data.frame(obs=sqrt(res$k/(intensity*pi))-r,theo=rep(0,tmax))
+	if(nsim>0) {
+		g<-cbind(g,sup=res$gic1/(intensity*ds),inf=res$gic2/(intensity*ds),pval=res$gval/(nsim+1))
+		n<-cbind(n,sup=res$kic1/(pi*r^2),inf=res$kic2/(pi*r^2),pval=res$nval/(nsim+1))
+		k<-cbind(k,sup=res$kic1/intensity,inf=res$kic2/intensity,pval=res$kval/(nsim+1))
+		l<-cbind(l,sup=sqrt(res$kic1/(intensity*pi))-r,inf=sqrt(res$kic2/(intensity*pi))-r,pval=res$lval/(nsim+1))
+	}
+	call<-match.call()
+	res<-list(call=call,r=r,g=g,n=n,k=k,l=l)
+	class(res)<-c("fads","kfun")
+	return(res)
+}
+
+k12fun<-function(p,upto,by,nsim=0,H0=c("pitor","pimim","rl"),prec=0.01,nsimax=3000,conv=50,rep=10,alpha=0.01,marks) {
+	# checking for input parameters
+	options( CBoundsCheck = TRUE )
+	# regle les problemes pour 32-bit
+	stopifnot(inherits(p,"spp"))
+	stopifnot(p$type=="multivariate")
+	stopifnot(is.numeric(upto))
+	stopifnot(upto>=1)
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	stopifnot(is.numeric(nsim))
+	stopifnot(nsim>=0)
+	nsim<-testInteger(nsim)
+	H0<-H0[1]
+	stopifnot(H0=="pitor" || H0=="pimim" || H0=="rl")
+	if(H0=="rl") H0<-1
+	else if(H0=="pitor") H0<-2
+	else H0<-3
+	stopifnot(is.numeric(prec))
+	stopifnot(prec>=0)
+	stopifnot(is.numeric(alpha))
+	stopifnot(alpha>=0)
+	if(nsim>0) testIC(nsim,alpha)
+	if(missing(marks))
+		marks<-c(1,2)
+	stopifnot(length(marks)==2)
+	stopifnot(marks[1]!=marks[2])
+	mark1<-marks[1]
+	mark2<-marks[2]
+	if(is.numeric(mark1))
+		mark1<-levels(p$marks)[testInteger(mark1)]
+	else if(!mark1%in%p$marks) stop(paste("mark \'",mark1,"\' doesn\'t exist",sep=""))
+	if(is.numeric(mark2))
+		mark2<-levels(p$marks)[testInteger(mark2)]
+	else if(!mark2%in%p$marks) stop(paste("mark \'",mark2,"\' doesn\'t exist",sep=""))
+	
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+		stop("invalid window type")
+	surface<-area.swin(p$window)
+	x1<-p$x[p$marks==mark1]
+	y1<-p$y[p$marks==mark1]
+	x2<-p$x[p$marks==mark2]
+	y2<-p$y[p$marks==mark2]
+	nbPts1<-length(x1)
+	nbPts2<-length(x2)
+	intensity2<-nbPts2/surface
+#	intensity<-(nbPts1+nbPts2)/surface
+	
+	# computing intertype functions
+	if(cas==1) { #rectangle
+		if(nsim==0) { #without CI
+			res<-.C("intertype_rect",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),					
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
+					as.integer(tmax),as.double(by),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}
+		else { #with CI
+			res<-.C("intertype_rect_ic",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),as.double(surface),
+					as.integer(tmax),as.double(by),
+					as.integer(nsim),as.integer(H0),as.double(prec),as.integer(nsimax),as.integer(conv),as.integer(rep),as.double(alpha),
+					g=double(tmax),k=double(tmax),
+					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==2) { #circle
+		if(nsim==0) { #without CI
+			res<-.C("intertype_disq",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(x0),as.double(y0),as.double(r0),					
+					as.integer(tmax),as.double(by),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}
+		else { #with CI
+			res<-.C("intertype_disq_ic",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(x0),as.double(y0),as.double(r0),as.double(surface),
+					as.integer(tmax),as.double(by),
+					as.integer(nsim),as.integer(H0),as.double(prec),as.integer(nsimax),as.integer(conv),as.integer(rep),as.double(alpha),
+					g=double(tmax),k=double(tmax),
+					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
+					PACKAGE="ads")		
+		}
+	}
+	else if(cas==3) { #complex within rectangle
+		if(nsim==0) { #without CI
+			res<-.C("intertype_tr_rect",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
+					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),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}
+		else { #with CI
+			res<-.C("intertype_tr_rect_ic",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),as.double(surface),
+					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.integer(H0),as.double(prec),as.integer(nsimax),as.integer(conv),as.integer(rep),as.double(alpha),
+					g=double(tmax),k=double(tmax),
+					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
+					PACKAGE="ads")		
+		}
+	}
+	else if(cas==4) { #complex within circle
+		if(nsim==0) { #without CI
+			res<-.C("intertype_tr_disq",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(x0),as.double(y0),as.double(r0),					
+					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),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}
+		else { #with CI
+			res<-.C("intertype_tr_disq_ic",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(x0),as.double(y0),as.double(r0),as.double(surface),
+					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.integer(H0),as.double(prec),as.integer(nsimax),as.integer(conv),as.integer(rep),as.double(alpha),
+					g=double(tmax),k=double(tmax),
+					gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),lval=double(tmax),nval=double(tmax),
+					PACKAGE="ads")		
+		}
+	}	
+	# formatting results
+	ds<-c(pi,diff(pi*r^2))
+	g<-res$g/(intensity2*ds)
+	n<-res$k/(pi*r^2)
+	k<-res$k/intensity2
+	l<-sqrt(res$k/(intensity2*pi))-r
+	if(H0==1) {
+		rip<-kfun(spp(c(x1,x2),c(y1,y2),p$window),upto,by)
+		theo<-list(g=rip$g$obs,n=intensity2*rip$k$obs/(pi*r^2),k=rip$k$obs,l=rip$l$obs)
+	}
+	else if (H0==2||H0==3)
+		theo<-list(g=rep(1,tmax),n=rep(intensity2,tmax),k=pi*r^2,l=rep(0,tmax))
+	g<-data.frame(obs=g,theo=theo$g)
+	n<-data.frame(obs=n,theo=theo$n)
+	k<-data.frame(obs=k,theo=theo$k)
+	l<-data.frame(obs=l,theo=theo$l)
+	if(nsim>0) {
+		g<-cbind(g,sup=res$gic1/(intensity2*ds),inf=res$gic2/(intensity2*ds),pval=res$gval/(nsim+1))
+		n<-cbind(n,sup=res$kic1/(pi*r^2),inf=res$kic2/(pi*r^2),pval=res$nval/(nsim+1))
+		k<-cbind(k,sup=res$kic1/intensity2,inf=res$kic2/intensity2,pval=res$kval/(nsim+1))
+		l<-cbind(l,sup=sqrt(res$kic1/(intensity2*pi))-r,inf=sqrt(res$kic2/(intensity2*pi))-r,pval=res$lval/(nsim+1))
+	}	
+	call<-match.call()
+	res<-list(call=call,r=r,g12=g,n12=n,k12=k,l12=l,marks=c(mark1,mark2))
+	class(res)<-c("fads","k12fun")
+	return(res)
+}
+
+kijfun<-kpqfun<-function(p,upto,by) {
+# checking for input parameters
+	stopifnot(inherits(p,"spp"))
+	stopifnot(p$type=="multivariate")
+	stopifnot(is.numeric(upto))
+	stopifnot(upto>=1)
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+	stop("invalid window type")
+	surface<-area.swin(p$window)
+	
+	tabMarks<-levels(p$marks)
+	nbMarks<-length(tabMarks)
+	mpt_nb<-summary(p$marks)	
+# computing RipleyClass
+	gij<-double(tmax*nbMarks^2)
+	kij<-double(tmax*nbMarks^2)
+	lij<-double(tmax*nbMarks^2)
+	nij<-double(tmax*nbMarks^2)
+	for(i in 1:nbMarks) {
+		x1<-p$x[p$marks==tabMarks[i]]
+		y1<-p$y[p$marks==tabMarks[i]]		
+		if(cas==1) { #rectangle
+			res<-.C("ripley_rect",
+					as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					as.integer(tmax),as.double(by),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")
+		}
+		else if(cas==2) { #circle
+			res<-.C("ripley_disq",
+					as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
+					as.double(x0),as.double(y0),as.double(r0),
+					as.integer(tmax),as.double(by),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")
+		}
+		else if(cas==3) { #complex within rectangle
+			res<-.C("ripley_tr_rect",
+					as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")
+		}
+		else if(cas==4) { #complex within circle
+			res<-.C("ripley_tr_disq",
+					as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
+					as.double(x0),as.double(y0),as.double(r0),
+					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),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")
+		}
+		intensity1<-mpt_nb[i]/surface
+		matcol<-(i-1)*nbMarks+i-1
+		j<-(matcol*tmax+1):(matcol*tmax+tmax)
+		ds<-c(pi,diff(pi*r^2))
+		gij[j]<-res$g/(intensity1*ds)
+		nij[j]<-res$k/(pi*r^2)
+		kij[j]<-res$k/intensity1
+		lij[j]<-sqrt(res$k/(intensity1*pi))-r
+		if(i<nbMarks) {
+			for(j in (i+1):nbMarks) {
+				x2<-p$x[p$marks==tabMarks[j]]
+				y2<-p$y[p$marks==tabMarks[j]]		
+				if(cas==1) { #rectangle
+					res<-.C("intertype_rect",
+							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
+							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),					
+							as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
+							as.integer(tmax),as.double(by),
+							g=double(tmax),k=double(tmax),
+							PACKAGE="ads")					
+				}
+				else if(cas==2) { #circle
+					res<-.C("intertype_disq",
+							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
+							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
+							as.double(x0),as.double(y0),as.double(r0),					
+							as.integer(tmax),as.double(by),
+							g=double(tmax),k=double(tmax),
+							PACKAGE="ads")					
+				}
+				else if(cas==3) { #complex within rectangle
+					res<-.C("intertype_tr_rect",
+							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
+							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
+							as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
+							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),
+							g=double(tmax),k=double(tmax),
+							PACKAGE="ads")
+				}
+				else if(cas==4) { #complex within circle
+					res<-.C("intertype_tr_disq",
+							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),
+							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
+							as.double(x0),as.double(y0),as.double(r0),					
+							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),
+							g=double(tmax),k=double(tmax),
+							PACKAGE="ads")					
+				}
+				intensity2<-mpt_nb[j]/surface
+				matcol<-(i-1)*nbMarks+j-1
+				k<-(matcol*tmax+1):(matcol*tmax+tmax)
+				gij[k]<-res$g/(intensity2*ds)
+				nij[k]<-res$k/(pi*r^2)
+				kij[k]<-res$k/intensity2
+				lij[k]<-sqrt(res$k/(intensity2*pi))-r				
+				if(cas==1) { #rectangle
+					res<-.C("intertype_rect",
+							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
+							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),											
+							as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
+							as.integer(tmax),as.double(by),
+							g=double(tmax),k=double(tmax),
+							PACKAGE="ads")					
+				}
+				else if(cas==2) { #circle
+					res<-.C("intertype_disq",
+							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
+							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),						
+							as.double(x0),as.double(y0),as.double(r0),					
+							as.integer(tmax),as.double(by),
+							g=double(tmax),k=double(tmax),
+							PACKAGE="ads")					
+				}
+				else if(cas==3) { #complex within rectangle
+					res<-.C("intertype_tr_rect",
+							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
+							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),						
+							as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
+							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),
+							g=double(tmax),k=double(tmax),
+							PACKAGE="ads")
+				}
+				else if(cas==4) { #complex within circle
+					res<-.C("intertype_tr_disq",
+							as.integer(mpt_nb[j]),as.double(x2),as.double(y2),
+							as.integer(mpt_nb[i]),as.double(x1),as.double(y1),						
+							as.double(x0),as.double(y0),as.double(r0),					
+							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),
+							g=double(tmax),k=double(tmax),
+							PACKAGE="ads")					
+				}								
+				matcol<-(j-1)*nbMarks+i-1
+				k<-(matcol*tmax+1):(matcol*tmax+tmax)
+				gij[k]<-res$g/(intensity1*ds)
+				nij[k]<-res$k/(pi*r^2)
+				kij[k]<-res$k/intensity1
+				lij[k]<-sqrt(res$k/(intensity1*pi))-r
+			}
+		}
+	}
+	labij<-paste(rep(tabMarks,each=nbMarks),rep(tabMarks,nbMarks),sep="-")
+	gij<-matrix(gij,nrow=tmax,ncol=nbMarks^2)
+	kij<-matrix(kij,nrow=tmax,ncol=nbMarks^2)
+	nij<-matrix(nij,nrow=tmax,ncol=nbMarks^2)
+	lij<-matrix(lij,nrow=tmax,ncol=nbMarks^2)
+	call<-match.call()
+	res<-list(call=call,r=r,labpq=labij,gij=gij,kpq=kij,lpq=lij,npq=nij,intensity=summary(p)$intensity)
+	class(res)<-c("fads","kpqfun")
+	return(res)
+}
+
+ki.fun<-kp.fun<-function(p,upto,by) {
+	# checking for input parameters
+	stopifnot(inherits(p,"spp"))
+		stopifnot(p$type=="multivariate")
+	stopifnot(is.numeric(upto))
+	stopifnot(upto>=1)
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+		stop("invalid window type")
+	surface<-area.swin(p$window)
+
+	tabMarks<-levels(p$marks)
+	nbMarks<-length(tabMarks)
+	mpt_nb<-summary(p$marks)		
+	#computing RipleyAll
+	gis<-double(tmax*nbMarks)
+	kis<-double(tmax*nbMarks)
+	lis<-double(tmax*nbMarks)
+	nis<-double(tmax*nbMarks)
+	for(i in 1:nbMarks) {
+		x1<-p$x[p$marks==tabMarks[i]]
+		y1<-p$y[p$marks==tabMarks[i]]
+		x2<-p$x[p$marks!=tabMarks[i]]
+		y2<-p$y[p$marks!=tabMarks[i]]
+		nbPts1<-mpt_nb[i]
+		nbPts2<-sum(mpt_nb)-nbPts1		
+		if(cas==1) { #rectangle
+			res<-.C("intertype_rect",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),					
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
+					as.integer(tmax),as.double(by),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}
+		else if(cas==2) { #circle
+			res<-.C("intertype_disq",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(x0),as.double(y0),as.double(r0),					
+					as.integer(tmax),as.double(by),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}
+		else if(cas==3) { #complex within rectangle
+			res<-.C("intertype_tr_rect",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),					
+					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),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")
+		}
+		else if(cas==4) { #complex within circle
+			res<-.C("intertype_tr_disq",
+					as.integer(nbPts1),as.double(x1),as.double(y1),
+					as.integer(nbPts2),as.double(x2),as.double(y2),
+					as.double(x0),as.double(y0),as.double(r0),					
+					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),
+					g=double(tmax),k=double(tmax),
+					PACKAGE="ads")					
+		}		
+		intensity2<-nbPts2/surface
+		j<-((i-1)*tmax+1):((i-1)*tmax+tmax)
+		ds<-c(pi,diff(pi*r^2))
+		gis[j]<-res$g/(intensity2*ds)
+		nis[j]<-res$k/(pi*r^2)
+		kis[j]<-res$k/intensity2
+		lis[j]<-sqrt(res$k/(intensity2*pi))-r
+	}	
+	# formatting results
+	labi<-tabMarks
+	gis<-matrix(gis,nrow=tmax,ncol=nbMarks)
+	kis<-matrix(kis,nrow=tmax,ncol=nbMarks)
+	nis<-matrix(nis,nrow=tmax,ncol=nbMarks)
+	lis<-matrix(lis,nrow=tmax,ncol=nbMarks)
+	call<-match.call()
+	res<-list(call=call,r=r,labp=labi,gp.=gis,kp.=kis,lp.=lis,np.=nis,intensity=summary(p)$intensity)
+	class(res)<-c("fads","kp.fun")
+	return(res)
+}
+
+kmfun<-function(p,upto,by,nsim=0,alpha=0.01) {
+	# checking for input parameters
+	stopifnot(inherits(p,"spp"))
+	stopifnot(p$type=="marked")
+	stopifnot(is.numeric(upto))
+	stopifnot(upto>=1)
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	stopifnot(is.numeric(nsim))
+	stopifnot(nsim>=0)
+	nsim<-testInteger(nsim)
+	#cmoy<-mean(p$marks)
+	cvar<-var(p$marks)
+	stopifnot(is.numeric(alpha))
+	stopifnot(alpha>=0)
+	if(nsim>0) testIC(nsim,alpha)
+
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+		stop("invalid window type")
+	intensity<-p$n/area.swin(p$window)
+	
+	if(cas==1) { #rectangle
+		if(nsim==0) { #without CI
+			res<-.C("corr_rect",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					as.integer(tmax),as.double(by),
+					gm=double(tmax),km=double(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("corr_rect_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==2) { #circle
+		if(nsim==0) { #without CI
+			res<-.C("corr_disq",
+					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.integer(tmax),as.double(by),
+					gm=double(tmax),km=double(tmax),
+					PACKAGE="ads")					
+		}
+		else { #with CI
+			res<-.C("corr_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.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),
+					PACKAGE="ads")
+		}	
+	}
+	else if(cas==3) { #complex within rectangle
+		if(nsim==0) { #without CI
+			res<-.C("corr_tr_rect",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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),
+					gm=double(tmax),km=double(tmax),
+					PACKAGE="ads")					
+		}
+		else { #with CI
+			res<-.C("corr_tr_rect_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(p$marks),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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),
+					PACKAGE="ads")	
+		}	
+	}
+	else if(cas==4) { #complex within circle
+		if(nsim==0) { #without CI		
+			res<-.C("corr_tr_disq",
+					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.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),
+					gm=double(tmax),km=double(tmax),
+					PACKAGE="ads")	
+		}
+		else { #with CI
+			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(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),lmval=double(tmax),nmval=double(tmax),
+					PACKAGE="ads")	
+		}
+	}
+	# formatting results
+	gm<-data.frame(obs=res$gm,theo=rep(0,tmax))
+	km<-data.frame(obs=res$km,theo=rep(0,tmax))
+	if(nsim>0) {
+		gm<-cbind(gm,sup=res$gmic1,inf=res$gmic2,pval=res$gmval/(nsim+1))
+		km<-cbind(km,sup=res$kmic1,inf=res$kmic2,pval=res$kmval/(nsim+1))
+	}
+	call<-match.call()
+	res<-list(call=call,r=r,gm=gm,km=km)
+	class(res)<-c("fads","kmfun")
+	return(res)
+}
+
+ksfun<-function(p,upto,by,nsim=0,alpha=0.01) {
+# checking for input parameters
+	#options( CBoundsCheck = TRUE )
+	stopifnot(inherits(p,"spp"))
+	stopifnot(p$type=="multivariate")
+	stopifnot(is.numeric(upto))
+	stopifnot(upto>=1)
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	stopifnot(is.numeric(nsim))
+	stopifnot(nsim>=0)
+	nsim<-testInteger(nsim)
+	stopifnot(is.numeric(alpha))
+	stopifnot(alpha>=0)
+	if(nsim>0) testIC(nsim,alpha)
+	
+###faire test sur les marks
+	
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+	stop("invalid window type")
+	surface<-area.swin(p$window)
+	intensity<-p$n/surface
+	tabMarks<-levels(p$marks)
+	nbMarks<-nlevels(p$marks)
+#nbMarks<-length(tabMarks)
+	marks<-as.numeric(p$marks)	
+	freq<-as.vector(table(p$marks))
+	D<-1-sum(freq*(freq-1))/(p$n*(p$n-1))
+
+# computing Shimatani	
+	if(cas==1) { #rectangle
+		if(nsim==0) { #without CI
+			res<-.C("shimatani_rect",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					as.integer(tmax),as.double(by),
+					as.integer(nbMarks),as.integer(marks),as.double(surface),gg=double(tmax),kk=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("shimatani_rect_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					as.integer(tmax),as.double(by), as.integer(nsim), as.double(alpha),
+					as.integer(nbMarks),as.integer(marks),as.double(surface),as.double(D),
+					gg=double(tmax),kk=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==2) { #circle
+		if(nsim==0) { #without CI
+			res<-.C("shimatani_disq",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(x0),as.double(y0),as.double(r0),
+					as.integer(tmax),as.double(by),
+					as.integer(nbMarks),as.integer(marks),as.double(surface),gg=double(tmax),kk=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("shimatani_disq_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(x0),as.double(y0),as.double(r0),
+					as.integer(tmax),as.double(by), as.integer(nsim), as.double(alpha),
+					as.integer(nbMarks),as.integer(marks),as.double(surface),as.double(D),
+					gg=double(tmax),kk=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==3) { #complex within rectangle
+		if(nsim==0) { #without CI
+			res<-.C("shimatani_tr_rect",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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(nbMarks),as.integer(marks),as.double(surface),gg=double(tmax),kk=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("shimatani_tr_rect_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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),
+					as.integer(nbMarks),as.integer(marks),as.double(surface),as.double(D),
+					gg=double(tmax),kk=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==4) { #complex within circle
+		if(nsim==0) { #without CI		
+			res<-.C("shimatani_tr_disq",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(x0),as.double(y0),as.double(r0),
+					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(nbMarks),as.integer(marks),as.double(surface),gg=double(tmax),kk=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("shimatani_tr_disq_ic",
+				   as.integer(p$n),as.double(p$x),as.double(p$y),as.double(x0),as.double(y0),as.double(r0),
+				   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),
+				   as.integer(nbMarks),as.integer(marks),as.double(surface),as.double(D),
+				   gg=double(tmax),kk=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+				   gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
+				   PACKAGE="ads")
+		}
+	}		
+	if(sum(res$erreur>0)){
+		message("Error in ", appendLF=F)
+		print(match.call())
+		message("No neigbors within distance intervals:")
+		print(paste(by*(res$erreur[res$erreur>0]-1),"-",by*res$erreur[res$erreur>0]))
+		message("Increase argument 'by'")
+		return(res=NULL)
+	}
+	gs<-data.frame(obs=res$gg/D,theo=rep(1,tmax))
+	ks<-data.frame(obs=res$kk/D,theo=rep(1,tmax))
+	if(nsim>0) {
+		gs<-cbind(gs,sup=res$gic1/D,inf=res$gic2/D,pval=res$gval/(nsim+1))
+		ks<-cbind(ks,sup=res$kic1/D,inf=res$kic2/D,pval=res$kval/(nsim+1))
+	}
+	call<-match.call()
+	res<-list(call=call,r=r,gs=gs,ks=ks)
+	class(res)<-c("fads","ksfun")
+	return(res)
+}
+
+
+#################
+#V2 that calls K12fun
+##############
+krfun<-function(p,upto,by,nsim=0,dis=NULL,H0=c("rl","se"),alpha=0.01) {
+# checking for input parameters
+	stopifnot(inherits(p,"spp"))
+	stopifnot(p$type=="multivariate")
+	stopifnot(is.numeric(upto))
+	stopifnot(upto>=1)
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	H0<-H0[1]
+	stopifnot(H0=="se" || H0=="rl")
+	ifelse(H0=="se",H0<-2,H0<-1)
+	if(is.null(dis)) {
+		stopifnot(H0==1)
+		dis<-as.dist(matrix(1,nlevels(p$marks),nlevels(p$marks)))
+		attr(dis,"Labels")<-levels(p$marks)
+	}
+	stopifnot(inherits(dis,"dist"))
+	stopifnot(attr(dis,"Diag")==FALSE)
+	stopifnot(attr(dis,"Upper")==FALSE)
+	stopifnot(suppressWarnings(is.euclid(dis)))
+###revoir tests sur dis	
+	if(length(levels(p$marks))!=length(labels(dis))) {
+		stopifnot(all(levels(p$marks)%in%labels(dis)))
+#dis<-subsetdist(dis,which(labels(dis)%in%levels(p$marks)))
+		dis<-subsetdist(dis,levels(p$marks))
+		warning("matrix 'dis' have been subsetted to match with levels(p$marks)")
+	}
+#else if(any(labels(dis)!=levels(p$marks))) {
+#		attr(dis,"Labels")<-levels(p$marks)
+#		warning("levels(p$marks) have been assigned to attr(dis, ''Labels'')")
+#	}
+	stopifnot(is.numeric(nsim))
+	stopifnot(nsim>=0)
+	nsim<-testInteger(nsim)
+	stopifnot(is.numeric(alpha))
+	stopifnot(alpha>=0)
+	if(nsim>0) testIC(nsim,alpha)
+	
+###faire test sur les marks
+	
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+		stop("invalid window type")
+	surface<-area.swin(p$window)
+	intensity<-p$n/surface
+	nbMarks<-nlevels(p$marks)
+	marks<-as.numeric(p$marks) # => position du label dans levels(p$marks)
+	dis<-as.dist(sortmat(dis,levels(p$marks)))
+	HD<-suppressWarnings(divc(as.data.frame(unclass(table(p$marks))),sqrt(2*dis),scale=F)[1,1])
+	HD<-HD*p$n/(p$n-1)
+	dis<-as.vector(dis)
+		
+# computing Rao	
+	if(cas==1) { #rectangle
+		if(nsim==0) { #without CI
+			res<-.C("rao_rect",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					as.integer(tmax),as.double(by),as.integer(H0),
+					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("rao_rect_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					as.integer(tmax),as.double(by), as.integer(nsim),as.integer(H0),as.double(alpha),
+					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==2) { #circle
+		if(nsim==0) { #without CI
+			res<-.C("rao_disq",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(x0),as.double(y0),as.double(r0),
+					as.integer(tmax),as.double(by),as.integer(H0),
+					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("rao_disq_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(x0),as.double(y0),as.double(r0),
+					as.integer(tmax),as.double(by), as.integer(nsim),as.integer(H0),as.double(alpha),
+					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==3) { #complex within rectangle
+		if(nsim==0) { #without CI
+			res<-.C("rao_tr_rect",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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(H0),
+					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+		else { #with CI
+			res<-.C("rao_tr_rect_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+					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.integer(H0),as.double(alpha),
+					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
+					PACKAGE="ads")
+		}
+	}
+	else if(cas==4) { #complex within circle
+		if(nsim==0) { #without CI	
+			res<-.C("rao_tr_disq",
+				   as.integer(p$n),as.double(p$x),as.double(p$y),
+				   as.double(x0),as.double(y0),as.double(r0),
+				   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(H0),
+				   as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+				   gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),erreur=integer(tmax),
+				   PACKAGE="ads")
+		}
+		else { #with CI (not based on K12)
+			res<-.C("rao_tr_disq_ic",
+					as.integer(p$n),as.double(p$x),as.double(p$y),
+					as.double(x0),as.double(y0),as.double(r0),
+					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.integer(H0),as.double(alpha),
+					as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+					gg=double(tmax),kk=double(tmax),gs=double(tmax),ks=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+					gval=double(tmax),kval=double(tmax),serreur=integer(tmax),
+					PACKAGE="ads")
+		}
+	}		
+	if(sum(res$erreur>0)){
+		message("Error in ", appendLF=F)
+		print(match.call())
+		message("No neigbors within distance intervals:")
+		print(paste(by*(res$erreur[res$erreur>0]-1),"-",by*res$erreur[res$erreur>0]))
+		message("Increase argument 'by'")
+		return(res=NULL)
+	}
+	if(H0==1) {
+		theog<-rep(1,tmax)
+		theok<-rep(1,tmax)
+	}
+	if(H0==2) {
+		theog<-res$gs
+		theok<-res$ks
+	}
+	gr<-data.frame(obs=res$gg,theo=theog)
+	kr<-data.frame(obs=res$kk,theo=theok)
+	if(nsim>0) {
+		gr<-cbind(gr,sup=res$gic1,inf=res$gic2,pval=res$gval/(nsim+1))
+		kr<-cbind(kr,sup=res$kic1,inf=res$kic2,pval=res$kval/(nsim+1))
+	}
+	call<-match.call()
+	res<-list(call=call,r=r,gr=gr,kr=kr)
+	class(res)<-c("fads","krfun")
+	return(res)
+}
+
+kdfun<-function(p,upto,by,dis,nsim=0,alpha=0.01) {
+# checking for input parameters
+	stopifnot(inherits(p,"spp"))
+	stopifnot(p$type=="multivariate")
+	if(min(p$x)<0)
+		p$x<-p$x+abs(min(p$x))
+	if(min(p$y)<0)
+		p$y<-p$y+abs(min(p$y))
+	stopifnot(is.numeric(upto))
+	stopifnot(upto>=1)
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	stopifnot(inherits(dis,"dist"))
+	stopifnot(attr(dis,"Diag")==FALSE)
+	stopifnot(attr(dis,"Upper")==FALSE)
+	stopifnot(suppressWarnings(is.euclid(dis)))
+###revoir tests sur dis	
+	if(length(levels(p$marks))!=length(labels(dis))) {
+		stopifnot(all(levels(p$marks)%in%labels(dis)))
+#dis<-subsetdist(dis,which(labels(dis)%in%levels(p$marks)))
+		dis<-subsetdist(dis,levels(p$marks))
+		warning("matrix 'dis' have been subsetted to match with levels(p$marks)")
+	}
+#else if(any(labels(dis)!=levels(p$marks))) {
+#		attr(dis,"Labels")<-levels(p$marks)
+#		warning("levels(p$marks) have been assigned to attr(dis, ''Labels'')")
+#	}
+	stopifnot(is.numeric(nsim))
+	stopifnot(nsim>=0)
+	nsim<-testInteger(nsim)
+	stopifnot(is.numeric(alpha))
+	stopifnot(alpha>=0)
+	if(nsim>0) testIC(nsim,alpha)
+	
+	surface<-area.swin(p$window)
+	intensity<-p$n/surface
+	nbMarks<-nlevels(p$marks)
+	marks<-as.numeric(p$marks) # => position du label dans levels(p$marks)
+	dis<-as.dist(sortmat(dis,levels(p$marks)))
+	HD<-suppressWarnings(divc(as.data.frame(unclass(table(p$marks))),sqrt(2*dis),scale=F)[1,1])
+	HD<-HD*p$n/(p$n-1)
+	dis<-as.vector(dis)
+
+###faire test sur les marks
+	
+	if(nsim==0) { #without CI
+		res<-.C("shen",
+			as.integer(p$n),as.double(p$x),as.double(p$y),
+			as.integer(tmax),as.double(by),
+			as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+			gd=double(tmax),kd=double(tmax),erreur=integer(tmax),
+			PACKAGE="ads")
+	}
+	else { #with CI
+		res<-.C("shen_ic",
+			as.integer(p$n),as.double(p$x),as.double(p$y),
+			as.integer(tmax),as.double(by), as.integer(nsim),as.double(alpha),
+			as.integer(nbMarks),as.integer(marks),as.double(dis),as.double(surface),as.double(HD),
+			gd=double(tmax),kd=double(tmax),gic1=double(tmax),gic2=double(tmax),kic1=double(tmax),kic2=double(tmax),
+			gval=double(tmax),kval=double(tmax),erreur=integer(tmax),
+			PACKAGE="ads")
+	}	
+	
+	if(sum(res$erreur>0)){
+		message("Error in ", appendLF=F)
+		print(match.call())
+		message("No neigbors within distance intervals:")
+		print(paste(by*(res$erreur[res$erreur>0]-1),"-",by*res$erreur[res$erreur>0]))
+		message("Increase argument 'by'")
+		return(res=NULL)
+	}
+	gd<-data.frame(obs=res$gd,theo=rep(1,tmax))
+	kd<-data.frame(obs=res$kd,theo=rep(1,tmax))
+	if(nsim>0) {
+		gd<-cbind(gd,sup=res$gic1,inf=res$gic2,pval=res$gval/(nsim+1))
+		kd<-cbind(kd,sup=res$kic1,inf=res$kic2,pval=res$kval/(nsim+1))
+	}
+	call<-match.call()
+	res<-list(call=call,r=r,gd=gd,kd=kd)
+	class(res)<-c("fads","kdfun")
+	return(res)
+}
diff --git a/R/mimetic.R b/R/mimetic.R
index ab0c0048dace8b2a49917f8e9597efa3a1d82a45..c428df8dfcdc9fe47c9d30d06bd54e35d372587d 100755
--- a/R/mimetic.R
+++ b/R/mimetic.R
@@ -2,7 +2,7 @@
 #RP 11/06/2013
 ###################################################
 
-mimetic<-function(x,upto=NULL,by=NULL,prec=NULL,nsimax=3000,conv=50,mask=NULL) {
+mimetic<-function(x,upto=NULL,by=NULL,prec=NULL,nsimax=3000,conv=50) {
 # checking for input parameters 
 	stopifnot(inherits(x,"fads")||inherits(x,"spp"))
 	if(inherits(x,"fads")) {	
@@ -50,35 +50,13 @@ mimetic<-function(x,upto=NULL,by=NULL,prec=NULL,nsimax=3000,conv=50,mask=NULL) {
 					PACKAGE="ads")
 		}
 		else {
-		  if (!missing(mask) && !is.null(mask)) {
-		    stopifnot(inherits(mask, "RasterStack")||inherits(mask, "RasterLayer"))
-		    if (inherits(mask, "RasterStack"))
-		      mask <- mask[[1]]
-		    mask.coord <- coordinates(mask)[!is.na(values(mask)),]
-		    mask.n <- nrow(mask.coord)
-		    mask.x <- mask.coord[,1]
-		    mask.y <- mask.coord[,2]
-		    mask.dx <- abs(mask@extent@xmax-mask@extent@xmin)/mask@ncols
-		    mask.dy <- abs(mask@extent@ymax-mask@extent@ymin)/mask@nrows
-		    mask.spp <- spp(x=mask.coord[,1],y=mask.coord[,2],window=p$window)
-		    res<-.C("mimetic_rect",
-		            as.integer(p$n),as.double(p$x),as.double(p$y),as.double(surface),
-		            as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-		            as.double(mask.spp$n),as.double(mask.spp$x), as.double(mask.spp$y),as.double(mask.dx),as.double(mask.dy),
-		            as.double(prec),as.integer(tmax),as.double(by),
-		            as.double(lobs),as.integer(nsimax),as.integer(conv),cost=double(nsimax),
-		            g=double(tmax),k=double(tmax),xx=double(p$n),yy=double(p$n),mess=as.integer(1),
-		            PACKAGE="ads")
-		  } else {
 			res<-.C("mimetic_rect",
 					as.integer(p$n),as.double(p$x),as.double(p$y),as.double(surface),
 					as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-					as.integer(0),as.double(0), as.double(0),as.double(0),as.double(0),
 					as.double(prec),as.integer(tmax),as.double(by),
 					as.double(lobs),as.integer(nsimax),as.integer(conv),cost=double(nsimax),
 				g=double(tmax),k=double(tmax),xx=double(p$n),yy=double(p$n),mess=as.integer(1),
 				PACKAGE="ads")
-		  }
 		}
 	}
 	else if("circle"%in%p$window$type) {
diff --git a/R/plot.fads.R b/R/plot.fads.R
index badaf431338d968c6f7fdc95fc4f75103b8b1556..7f932b8b68d4905261a5c867f6ad9e370191a624 100755
--- a/R/plot.fads.R
+++ b/R/plot.fads.R
@@ -1,5 +1,5 @@
 plot.fads<-function (x,opt,cols,lty,main,sub,legend,csize,...) {
-	UseMethod("plot.fads")
+  NextMethod()
 }
 
 plot.fads.kfun<-function (x,opt=c("all","L","K","n","g"),cols,lty,main,sub,legend=TRUE,csize=1,...) {
diff --git a/R/plot.vads.R b/R/plot.vads.R
index 9f80ffbdaaebaa0beb626366fba2b9a8c8e97044..7955715d7f819018f2144b5d7ca423306d33b5b5 100755
--- a/R/plot.vads.R
+++ b/R/plot.vads.R
@@ -28,8 +28,7 @@ plot.vads.dval<-function (x,main,opt=c("dval","cval"),select,chars=c("circles","
 	val<-data.frame(adjust.marks.size(val,x$window,if(!missing(maxsize)) maxsize))
 	def.par <- par(no.readonly = TRUE)
 	on.exit(par(def.par))
-	#if(options()$device=="windows")
-	#	csize<-0.75*csize
+
 	if (missing(main)) 
         main <- deparse(substitute(x))
 	mylayout<-layout(matrix(c(rep(1,nf),seq(2,((nf*nf)+1),1)),(nf+1),nf,byrow=TRUE))
@@ -54,14 +53,7 @@ plot.vads.dval<-function (x,main,opt=c("dval","cval"),select,chars=c("circles","
 				text(c(xl[1]+lms[1],xl[2]+lms[2],xl[3]+lms[3]),yl,labels=signif(lm,2),pos=4,cex=1.5)
 			}
 	}
-	#if(!is.null(main)) {
-	#	mylayout<-layout(matrix(c(rep(1,nf),seq(2,((nf*nf)+1),1)),(nf+1),nf,byrow=TRUE))
-	#	plot.default(x$xy$x,x$xy$y,type="n",axes=FALSE)
-	#	text(mean(range(x$xy$x)),mean(range(x$xy$y)),pos=3,cex=2,labels=main)
-		#ajouter une lŽgende ???
-	#}
-	#else
-	#	mylayout<-layout(matrix(seq(1,(nf*nf),1),nf,nf,byrow=TRUE))
+	
 	ifelse(missing(cols),cols<-1,cols<-cols[1])
 	if(!missing(char0)||!missing(col0)) {
 		ifelse(missing(col0),col0<-cols,col0<-col0[1])	
@@ -82,7 +74,6 @@ plot.vads.dval<-function (x,main,opt=c("dval","cval"),select,chars=c("circles","
 					fg=cols,bg=cols,inches=FALSE,add=TRUE,...)
 		}
 	}
-	## mŽthode en courbes de niveaux ?
 }
 
 plot.vads.kval<-function (x,main,opt=c("lval","kval","nval","gval"),select,chars=c("circles","squares"),cols,maxsize,char0,col0,legend=TRUE,csize=1,...) {
@@ -117,14 +108,12 @@ plot.vads.kval<-function (x,main,opt=c("lval","kval","nval","gval"),select,chars
 	else
 		stopifnot(opt%in%c("lval","kval","nval","gval"))
 	v<-val
-	#val<-data.frame(adjust.marks.size(val,x$window,if(!missing(maxsize)) maxsize))
 	val<-data.frame(adjust.marks.size(val,x$window))
 	if(!missing(maxsize))
 		val<-val*maxsize
 	def.par <- par(no.readonly = TRUE)
 	on.exit(par(def.par))
-	#if(options()$device=="windows")
-	#	csize<-0.75*csize
+
 	if (missing(main)) 
         main <- deparse(substitute(x))
 	mylayout<-layout(matrix(c(rep(1,nf),seq(2,((nf*nf)+1),1)),(nf+1),nf,byrow=TRUE))
@@ -155,14 +144,7 @@ plot.vads.kval<-function (x,main,opt=c("lval","kval","nval","gval"),select,chars
 
 			}
 	}
-	#if(!is.null(main)) {
-	#	mylayout<-layout(matrix(c(rep(1,nf),seq(2,((nf*nf)+1),1)),(nf+1),nf,byrow=TRUE))
-	#	plot.default(x$xy$x,x$xy$y,type="n",axes=FALSE)
-	#	text(mean(range(x$xy$x)),mean(range(x$xy$y)),pos=3,cex=2,labels=main)
-		#ajouter une lŽgende ???
-	#}
-	#else
-	#	mylayout<-layout(matrix(seq(1,(nf*nf),1),nf,nf,byrow=TRUE))
+
 	ifelse(missing(cols),cols<-1,cols<-cols[1])
 	if(!missing(char0)||!missing(col0)) {
 		ifelse(missing(col0),col0<-cols,col0<-col0[1])	
@@ -194,7 +176,6 @@ plot.vads.kval<-function (x,main,opt=c("lval","kval","nval","gval"),select,chars
 			}	
 		}
 	}
-	## mŽthode en courbes de niveaux ?
 }
 
 plot.vads.k12val<-function (x,main,opt=c("lval","kval","nval","gval"),select,chars=c("circles","squares"),cols,maxsize,char0,col0,legend=TRUE,csize=1,...) {
@@ -235,8 +216,7 @@ plot.vads.k12val<-function (x,main,opt=c("lval","kval","nval","gval"),select,cha
 		val<-val*maxsize
 	def.par <- par(no.readonly = TRUE)
 	on.exit(par(def.par))
-	#if(options()$device=="windows")
-	#	csize<-0.75*csize
+
 	if (missing(main)) 
         main <- deparse(substitute(x))
 	mylayout<-layout(matrix(c(rep(1,nf),seq(2,((nf*nf)+1),1)),(nf+1),nf,byrow=TRUE))
@@ -265,14 +245,7 @@ plot.vads.k12val<-function (x,main,opt=c("lval","kval","nval","gval"),select,cha
 				text(c(xl[1]+lms[1],xl[2]+lms[2],xl[3]+lms[3]),yl*0.5,labels=signif(-lm,2),pos=4,cex=1)
 			}
 	}
-	#if(!is.null(main)) {
-	#	mylayout<-layout(matrix(c(rep(1,nf),seq(2,((nf*nf)+1),1)),(nf+1),nf,byrow=TRUE))
-	#	plot.default(x$xy$x,x$xy$y,type="n",axes=FALSE)
-	#	text(mean(range(x$xy$x)),mean(range(x$xy$y)),pos=3,cex=2,labels=main)
-		#ajouter une lŽgende ???
-	#}
-	#else
-	#	mylayout<-layout(matrix(seq(1,(nf*nf),1),nf,nf,byrow=TRUE))
+
 	ifelse(missing(cols),cols<-1,cols<-cols[1])
 	if(!missing(char0)||!missing(col0)) {
 		ifelse(missing(col0),col0<-cols,col0<-col0[1])	
@@ -304,5 +277,4 @@ plot.vads.k12val<-function (x,main,opt=c("lval","kval","nval","gval"),select,cha
 			}	
 		}
 	}
-	## mŽthode en courbes de niveaux ?
 }
diff --git a/R/print.fads.R b/R/print.fads.R
index 59708fa107c97550e3e775d8d559ef9ae3c4703c..23142c8a93ca9966356716f946fad42b76c207d2 100755
--- a/R/print.fads.R
+++ b/R/print.fads.R
@@ -1,5 +1,5 @@
 print.fads<-function(x,...) {
-	UseMethod("print.fads")
+	NextMethod()
 }
 
 print.fads.kfun<-function(x,...) {
@@ -7,6 +7,11 @@ print.fads.kfun<-function(x,...) {
 	str(x)	
 }
 
+print.fads.kdfun<-function(x,...) {
+  cat("Multiscale second-order neigbourhood analysis of a spatial phylogenetic or functional diversity pattern from fully mapped data:\n")
+  str(x)   
+}
+
 print.fads.k12fun<-function(x,...) {
 	cat("Bivariate second-order neighbourhood functions:\n")
 	str(x)	
diff --git a/R/print.vads.R b/R/print.vads.R
index b2587a3411ef140ca830a8c41bff579df1856b93..bf8f38fadd93b12b76c6468f5583f684b6145125 100755
--- a/R/print.vads.R
+++ b/R/print.vads.R
@@ -1,72 +1,72 @@
-print.vads<-function(x,...) {
-	UseMethod("print.vads")
-}
-
-print.vads.dval<-function(x,...) {
-	cat("First-order local density values:\n")
-	str(x)
-	#cat("class: ",class(x),"\n")
-    #cat("call: ")
-	#print(x$call)
-	#cat("sampling window :",x$window$type,"\n")
-	#cat("\n")
-	#sumry <- array("", c(1, 4), list(1:1, c("vector", "length", "mode", "content")))
-	#sumry[1, ] <- c("$r", length(x$r), mode(x$r), "distance (r)")
-	#class(sumry) <- "table"
-    #print(sumry)
-	#cat("\n")
-	#sumry <- array("", c(3, 4), list(1:3, c("matrix", "nrow", "ncol", "content")))
-    #sumry[1, ] <- c("$grid", nrow(x$grid), ncol(x$grid), "(x,y) coordinates of the sampling points A")
-	#sumry[2, ] <- c("$count", nrow(x$count), ncol(x$count), "counting function NA(r)")
-	#sumry[3, ] <- c("$density", nrow(x$dens), ncol(x$dens), "local density function nA(r)")
-	#class(sumry) <- "table"
-    #print(sumry)
-}
-
-print.vads.kval<-function(x,...) {
-	cat("Univariate second-order local neighbourhood values:\n")
-	str(x)
-	#cat("class: ",class(x),"\n")
-    #cat("call: ")
-	#print(x$call)
-	#cat("\n")
-	#sumry <- array("", c(1, 4), list(1:1, c("vector", "length", "mode", "content")))
-	#sumry[1, ] <- c("$r", length(x$r), mode(x$r), "distance (r)")
-	#class(sumry) <- "table"
-    #print(sumry)
-	#cat("\n")
-	#sumry <- array("", c(5, 4), list(1:5, c("matrix", "nrow", "ncol", "content")))
-    #sumry[1, ] <- c("$coord", nrow(x$coord), ncol(x$coord), "(x,y) coordinates of points i")
-	#sumry[2, ] <- c("$gi", nrow(x$gi), ncol(x$gi), "individual pair density values gi(r)")
-	#sumry[3, ] <- c("$ni", nrow(x$ni), ncol(x$ni), "individual local neighbour density values ni(r)")
-	#sumry[4, ] <- c("$ki", nrow(x$ki), ncol(x$ki), "individual Ripley's values Ki(r)")
-	#sumry[5, ] <- c("$li", nrow(x$li), ncol(x$li), "modified individual Ripley's values Li(r)")
-	#class(sumry) <- "table"
-    #print(sumry)
-}
-
-print.vads.k12val<-function(x,...) {
-	#verifyclass(x,"k12ival")
-	cat("Bivariate second-order local neighbourhood values:\n")
-	str(x)
-	#cat("class: ",class(x),"\n")
-    #cat("call: ")
-	#print(x$call)
-	#cat("mark1: ",x$marks[1],"\n")
-	#cat("mark2: ",x$marks[2],"\n")
-	#cat("\n")
-	#sumry <- array("", c(1, 4), list(1:1, c("vector", "length", "mode", "content")))
-	#sumry[1, ] <- c("$r", length(x$r), mode(x$r), "distance (r)")
-	#class(sumry) <- "table"
-    #print(sumry)
-	#cat("\n")
-	#sumry <- array("", c(5, 4), list(1:5, c("matrix", "nrow", "ncol", "content")))
-    #sumry[1, ] <- c("$coord1", nrow(x$coord1), ncol(x$coord1), "(x,y) coordinates of points of mark 1")
-	#sumry[2, ] <- c("$g12i", nrow(x$g12i), ncol(x$g12i), "individual pair density values g12i(r)")
-	#sumry[3, ] <- c("$n12i", nrow(x$n12i), ncol(x$n12i), "individual local neighbour density values n12i(r)")
-	#sumry[4, ] <- c("$k12i", nrow(x$k12i), ncol(x$k12i), "individual intertype values K12i(r)")
-	#sumry[5, ] <- c("$l12i", nrow(x$l12i), ncol(x$l12i), "modified intrtype Ripley's values L12i(r)")
-	#class(sumry) <- "table"
-    #print(sumry)
-}
-
+print.vads<-function(x,...) {
+  NextMethod()
+}
+
+print.vads.dval<-function(x,...) {
+	cat("First-order local density values:\n")
+	str(x)
+	#cat("class: ",class(x),"\n")
+    #cat("call: ")
+	#print(x$call)
+	#cat("sampling window :",x$window$type,"\n")
+	#cat("\n")
+	#sumry <- array("", c(1, 4), list(1:1, c("vector", "length", "mode", "content")))
+	#sumry[1, ] <- c("$r", length(x$r), mode(x$r), "distance (r)")
+	#class(sumry) <- "table"
+    #print(sumry)
+	#cat("\n")
+	#sumry <- array("", c(3, 4), list(1:3, c("matrix", "nrow", "ncol", "content")))
+    #sumry[1, ] <- c("$grid", nrow(x$grid), ncol(x$grid), "(x,y) coordinates of the sampling points A")
+	#sumry[2, ] <- c("$count", nrow(x$count), ncol(x$count), "counting function NA(r)")
+	#sumry[3, ] <- c("$density", nrow(x$dens), ncol(x$dens), "local density function nA(r)")
+	#class(sumry) <- "table"
+    #print(sumry)
+}
+
+print.vads.kval<-function(x,...) {
+	cat("Univariate second-order local neighbourhood values:\n")
+	str(x)
+	#cat("class: ",class(x),"\n")
+    #cat("call: ")
+	#print(x$call)
+	#cat("\n")
+	#sumry <- array("", c(1, 4), list(1:1, c("vector", "length", "mode", "content")))
+	#sumry[1, ] <- c("$r", length(x$r), mode(x$r), "distance (r)")
+	#class(sumry) <- "table"
+    #print(sumry)
+	#cat("\n")
+	#sumry <- array("", c(5, 4), list(1:5, c("matrix", "nrow", "ncol", "content")))
+    #sumry[1, ] <- c("$coord", nrow(x$coord), ncol(x$coord), "(x,y) coordinates of points i")
+	#sumry[2, ] <- c("$gi", nrow(x$gi), ncol(x$gi), "individual pair density values gi(r)")
+	#sumry[3, ] <- c("$ni", nrow(x$ni), ncol(x$ni), "individual local neighbour density values ni(r)")
+	#sumry[4, ] <- c("$ki", nrow(x$ki), ncol(x$ki), "individual Ripley's values Ki(r)")
+	#sumry[5, ] <- c("$li", nrow(x$li), ncol(x$li), "modified individual Ripley's values Li(r)")
+	#class(sumry) <- "table"
+    #print(sumry)
+}
+
+print.vads.k12val<-function(x,...) {
+	#verifyclass(x,"k12ival")
+	cat("Bivariate second-order local neighbourhood values:\n")
+	str(x)
+	#cat("class: ",class(x),"\n")
+    #cat("call: ")
+	#print(x$call)
+	#cat("mark1: ",x$marks[1],"\n")
+	#cat("mark2: ",x$marks[2],"\n")
+	#cat("\n")
+	#sumry <- array("", c(1, 4), list(1:1, c("vector", "length", "mode", "content")))
+	#sumry[1, ] <- c("$r", length(x$r), mode(x$r), "distance (r)")
+	#class(sumry) <- "table"
+    #print(sumry)
+	#cat("\n")
+	#sumry <- array("", c(5, 4), list(1:5, c("matrix", "nrow", "ncol", "content")))
+    #sumry[1, ] <- c("$coord1", nrow(x$coord1), ncol(x$coord1), "(x,y) coordinates of points of mark 1")
+	#sumry[2, ] <- c("$g12i", nrow(x$g12i), ncol(x$g12i), "individual pair density values g12i(r)")
+	#sumry[3, ] <- c("$n12i", nrow(x$n12i), ncol(x$n12i), "individual local neighbour density values n12i(r)")
+	#sumry[4, ] <- c("$k12i", nrow(x$k12i), ncol(x$k12i), "individual intertype values K12i(r)")
+	#sumry[5, ] <- c("$l12i", nrow(x$l12i), ncol(x$l12i), "modified intrtype Ripley's values L12i(r)")
+	#class(sumry) <- "table"
+    #print(sumry)
+}
+
diff --git a/R/summary.vads.R b/R/summary.vads.R
index e617af1513c21cb63497eb61ce157d70be825ca2..a5b9d0d455278c2787a3e4c86702c24925727cb4 100755
--- a/R/summary.vads.R
+++ b/R/summary.vads.R
@@ -1,5 +1,5 @@
 summary.vads<-function(object,...) {
-	UseMethod("summary.vads")
+  NextMethod()
 }
 
 summary.vads.dval<-function (object,...) {
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 5b05a24788f4a2f102e3c57c76532ee0a672f1d9..9453baeb68d07d7e7470184d32174e0ae4469f21 100755
--- a/R/triangulate.R
+++ b/R/triangulate.R
@@ -29,7 +29,7 @@ triangulate<-function(outer.poly,holes) {
 	else {
 		# phv 20160823 bug fix: triangulate C function crashes with 4 points polygons and no hole
 		# Bypass the C function and returns 2 triangles made respectively of vertices (1, 2, 3) and (1, 3, 4)
-		if(nrow(outer.poly)==4) {
+		if(length(outer.poly$x)==4) {
 			return(data.frame(
 				ax=c(outer.poly$x[1], outer.poly$x[1]),
 				ay=c(outer.poly$y[1], outer.poly$y[1]),
diff --git a/R/util.R b/R/util.R
index 62905788974ec6bbe084dcca611968827f709df2..f214e782214358e6f4d65760e2520184f20e9766 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,25 @@ overlap.trapez <- function(xa, ya, xb, yb, verb=FALSE) {
   return(signfactor * areaT)
 }
 
-#TRUE: les points sur la bordure sont = inside
-in.poly<-function(x,y,poly,bdry=TRUE) {
+#Points on boundary are considered outside. No alternative option implemented yet.
+in.poly<-function(x,y,poly,bdry=FALSE) {
+	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))
 }
 
 ####################
diff --git a/R/vads.R b/R/vads.R
index a26c740219b7fec733c240606ad1d3a2019d9eb6..0b8cdcaeb7fcecb27b813e5c476762a5437a461c 100755
--- a/R/vads.R
+++ b/R/vads.R
@@ -1,305 +1,296 @@
-dval<-function(p,upto,by,nx,ny) {
-#si multivariŽ, choix du type de points ???
-	stopifnot(inherits(p,"spp"))
-	stopifnot(is.numeric(upto))
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	stopifnot(is.numeric(nx))
-	stopifnot(nx>=1)
-	nx<-testInteger(nx)
-	stopifnot(is.numeric(ny))
-	stopifnot(ny>=1)
-	ny<-testInteger(ny)		
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		xsample<-rep(xmin+(seq(1,nx)-0.5)*(xmax-xmin)/nx,each=ny)
-		ysample<-rep(ymin+(seq(1,ny)-0.5)*(ymax-ymin)/ny,nx)
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		xsample<-rep(x0-r0+(seq(1,nx)-0.5)*2*r0/nx,each=ny)
-		ysample<-rep(y0-r0+(seq(1,ny)-0.5)*2*r0/ny,nx)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-		stop("invalid window type")
-	
-	ok <- inside.swin(xsample, ysample, p$window)
-	xsample<-xsample[ok]
-	ysample<-ysample[ok]
-	stopifnot(length(xsample)==length(ysample))
-	nbSample<-length(xsample)
-	
-	if(cas==1) { #rectangle
-		count<-.C("density_rect",
-				as.integer(p$n),as.double(p$x),as.double(p$y),
-				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-				as.integer(tmax),as.double(by),
-				as.double(xsample),as.double(ysample),as.integer(nbSample),
-				count=double(tmax*nbSample),
-				PACKAGE="ads")$count
-	}
-	else if(cas==2) { #circle
-		count<-.C("density_disq",
-				as.integer(p$n),as.double(p$x),as.double(p$y),
-				as.double(x0),as.double(y0),as.double(r0),
-				as.integer(tmax),as.double(by),
-				as.double(xsample),as.double(ysample),as.integer(nbSample),
-				count=double(tmax*nbSample),
-				PACKAGE="ads")$count
-	}
-	else if(cas==3) { #complex within rectangle
-		count<-.C("density_tr_rect",
-				as.integer(p$n),as.double(p$x),as.double(p$y),
-				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-				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.double(xsample),as.double(ysample),as.integer(nbSample),
-				count=double(tmax*nbSample),
-				PACKAGE="ads")$count
-	}
-	else if(cas==4) { #complex within circle
-		count<-.C("density_tr_disq",
-				as.integer(p$n),as.double(p$x),as.double(p$y),
-				as.double(x0),as.double(y0),as.double(r0),
-				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.double(xsample),as.double(ysample),as.integer(nbSample),
-				count=double(tmax*nbSample),
-				PACKAGE="ads")$count
-	}
-	## rajouter un indice lorsque les disques ne sont pas indŽpendants
-	# formatting results	
-	dens<-count/(pi*r^2)
-	#grid<-matrix(c(xsample,ysample),nrow=nbSample,ncol=2)
-	count<-matrix(count,nrow=nbSample,ncol=tmax,byrow=TRUE)
-	dens<-matrix(dens,nrow=nbSample,ncol=tmax,byrow=TRUE)
-	call<-match.call()	
-	res<-list(call=call,window=p$window,r=r,xy=data.frame(x=xsample,y=ysample),cval=count,dval=dens)
-	class(res)<-c("vads","dval")
-	return(res)	
-}
-
-kval<-function(p,upto,by) {	
-	# checking for input parameters
-	stopifnot(inherits(p,"spp"))
-	if(p$type!="univariate")
-		warning(paste(p$type,"point pattern has been considered to be univariate\n"))
-	stopifnot(is.numeric(upto))
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-		stop("invalid window type")
-	intensity<-p$n/area.swin(p$window)
-
-	#computing ripley local functions
-	if(cas==1) { #rectangle
-		res<-.C("ripleylocal_rect",		
-				as.integer(p$n),as.double(p$x),as.double(p$y),
-				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-				as.integer(tmax),as.double(by),
-				gi=double(p$n*tmax),ki=double(p$n*tmax),
-				PACKAGE="ads")
-	}
-	else if(cas==2) { #circle
-		res<-.C("ripleylocal_disq",
-				as.integer(p$n),as.double(p$x),as.double(p$y),
-				as.double(x0),as.double(y0),as.double(r0),
-				as.integer(tmax),as.double(by),
-				gi=double(p$n*tmax),ki=double(p$n*tmax),
-				PACKAGE="ads")
-	}
-	else if(cas==3) { #complex within rectangle
-		res<-.C("ripleylocal_tr_rect",
-				as.integer(p$n),as.double(p$x),as.double(p$y),
-				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-				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),
-				gi=double(p$n*tmax),ki=double(p$n*tmax),
-				PACKAGE="ads")
-	}
-	else if(cas==4) { #complex within circle
-		res<-.C("ripleylocal_tr_disq",
-				as.integer(p$n),as.double(p$x),as.double(p$y),
-				as.double(x0),as.double(y0),as.double(r0),
-				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),
-				gi=double(p$n*tmax),ki=double(p$n*tmax),
-				PACKAGE="ads")
-	}	
-	# formatting results
-	#coord<-matrix(c(X$x,X$y),nrow=nbPts,ncol=2)
-	#coord<-data.frame(x=p$x,y=p$y)
-	#r<-seq(dr,dr*tmax,dr)
-	#ds<-pi*r^2-pi*seq(0,dr*tmax-dr,dr)^2
-	ds<-c(pi,diff(pi*r^2))
-	gi<-matrix(res$gi/(intensity*ds),nrow=p$n,ncol=tmax,byrow=TRUE)
-	ni<-matrix(res$ki/(pi*r^2),nrow=p$n,ncol=tmax,byrow=TRUE)
-	ki<-matrix(res$ki/intensity,nrow=p$n,ncol=tmax,byrow=TRUE)
-	li<-matrix(sqrt(res$ki/(intensity*pi))-r,nrow=p$n,ncol=tmax,byrow=TRUE)
-	call<-match.call()
-	res<-list(call=call,window=p$window,r=r,xy=data.frame(x=p$x,y=p$y),gval=gi,kval=ki,nval=ni,lval=li)
-	class(res)<-c("vads","kval")
-	return(res)
-}
-
-k12val<-function(p,upto,by,marks) {
-	# checking for input parameters
-	stopifnot(inherits(p,"spp"))
-	stopifnot(p$type=="multivariate")
-	stopifnot(is.numeric(upto))
-	stopifnot(is.numeric(by))
-	stopifnot(by>0)
-	r<-seq(by,upto,by)
-	tmax<-length(r)
-	if(missing(marks))
-		marks<-c(1,2)
-	stopifnot(length(marks)==2)
-	stopifnot(marks[1]!=marks[2])
-	mark1<-marks[1]
-	mark2<-marks[2]
-	if(is.numeric(mark1))
-		mark1<-levels(p$marks)[testInteger(mark1)]
-	else if(!mark1%in%p$marks) stop(paste("mark \'",mark1,"\' doesn\'t exist",sep=""))
-	if(is.numeric(mark2))
-		mark2<-levels(p$marks)[testInteger(mark2)]
-	else if(!mark2%in%p$marks) stop(paste("mark \'",mark2,"\' doesn\'t exist",sep=""))
-	# initializing variables
-	if("rectangle"%in%p$window$type) {
-		cas<-1
-		xmin<-p$window$xmin
-		xmax<-p$window$xmax
-		ymin<-p$window$ymin
-		ymax<-p$window$ymax
-		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
-		if ("complex"%in%p$window$type) {
-			cas<-3
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else if("circle"%in%p$window$type) {
-		cas<-2
-		x0<-p$window$x0
-		y0<-p$window$y0
-		r0<-p$window$r0
-		stopifnot(upto<=r0)
-		if ("complex"%in%p$window$type) {
-			cas<-4
-			tri<-p$window$triangles
-			nbTri<-nrow(tri)
-		}
-	}
-	else
-		stop("invalid window type")
-	surface<-area.swin(p$window)
-	x1<-p$x[p$marks==mark1]
-	y1<-p$y[p$marks==mark1]
-	x2<-p$x[p$marks==mark2]
-	y2<-p$y[p$marks==mark2]
-	nbPts1<-length(x1)
-	nbPts2<-length(x2)
-	intensity2<-nbPts2/surface
-	#computing intertype local functions
-	if(cas==1) { #rectangle
-		res<-.C("intertypelocal_rect",		
-				as.integer(nbPts1),as.double(x1),as.double(y1),
-				as.integer(nbPts2),as.double(x2),as.double(y2),
-				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-				as.integer(tmax),as.double(by),
-				gi=double(nbPts1*tmax),ki=double(nbPts1*tmax),
-				PACKAGE="ads")
-	}
-	else if(cas==2) { #circle
-		res<-.C("intertypelocal_disq",
-				as.integer(nbPts1),as.double(x1),as.double(y1),
-				as.integer(nbPts2),as.double(x2),as.double(y2),
-				as.double(x0),as.double(y0),as.double(r0),
-				as.integer(tmax),as.double(by),
-				gi=double(nbPts1*tmax),ki=double(nbPts1*tmax),
-				PACKAGE="ads")
-	}
-	else if(cas==3) { #complex within rectangle
-		res<-.C("intertypelocal_tr_rect",		
-				as.integer(nbPts1),as.double(x1),as.double(y1),
-				as.integer(nbPts2),as.double(x2),as.double(y2),
-				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
-				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),
-				gi=double(nbPts1*tmax),ki=double(nbPts1*tmax),
-				PACKAGE="ads")
-	}
-	else if(cas==4) { #complex within circle
-		res<-.C("intertypelocal_tr_disq",
-				as.integer(nbPts1),as.double(x1),as.double(y1),
-				as.integer(nbPts2),as.double(x2),as.double(y2),
-				as.double(x0),as.double(y0),as.double(r0),
-				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),
-				gi=double(nbPts1*tmax),ki=double(nbPts1*tmax),
-				PACKAGE="ads")
-	}
-	# formatting results
-	#coord<-matrix(c(x1,y1),nrow=nbPts1,ncol=2)
-	#coord<-data.frame(x1=x1,y1=y1)
-	#r<-seq(dr,dr*tmax,dr)
-	#ds<-pi*r^2-pi*seq(0,dr*tmax-dr,dr)^2
-	ds<-c(pi,diff(pi*r^2))
-	gi<-matrix(res$gi/(intensity2*ds),nrow=nbPts1,ncol=tmax,byrow=TRUE)
-	ni<-matrix(res$ki/(pi*r^2),nrow=nbPts1,ncol=tmax,byrow=TRUE)
-	ki<-matrix(res$ki/intensity2,nrow=nbPts1,ncol=tmax,byrow=TRUE)
-	li<-matrix(sqrt(res$ki/(intensity2*pi))-r,nrow=nbPts1,ncol=tmax,byrow=TRUE)
-	call<-match.call()
-	res<-list(call=call,window=p$window,r=r,xy=data.frame(x=x1,y=y1),g12val=gi,k12val=ki,n12val=ni,l12val=li,marks=c(mark1,mark2))
-	class(res)<-c("vads","k12val")
-	return(res)
-}
-
+dval<-function(p,upto,by,nx,ny) {
+	stopifnot(inherits(p,"spp"))
+	stopifnot(is.numeric(upto))
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	stopifnot(is.numeric(nx))
+	stopifnot(nx>=1)
+	nx<-testInteger(nx)
+	stopifnot(is.numeric(ny))
+	stopifnot(ny>=1)
+	ny<-testInteger(ny)		
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		xsample<-rep(xmin+(seq(1,nx)-0.5)*(xmax-xmin)/nx,each=ny)
+		ysample<-rep(ymin+(seq(1,ny)-0.5)*(ymax-ymin)/ny,nx)
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		xsample<-rep(x0-r0+(seq(1,nx)-0.5)*2*r0/nx,each=ny)
+		ysample<-rep(y0-r0+(seq(1,ny)-0.5)*2*r0/ny,nx)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+		stop("invalid window type")
+	
+	ok <- inside.swin(xsample, ysample, p$window)
+	xsample<-xsample[ok]
+	ysample<-ysample[ok]
+	stopifnot(length(xsample)==length(ysample))
+	nbSample<-length(xsample)
+	
+	if(cas==1) { #rectangle
+		count<-.C("density_rect",
+				as.integer(p$n),as.double(p$x),as.double(p$y),
+				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+				as.integer(tmax),as.double(by),
+				as.double(xsample),as.double(ysample),as.integer(nbSample),
+				count=double(tmax*nbSample),
+				PACKAGE="ads")$count
+	}
+	else if(cas==2) { #circle
+		count<-.C("density_disq",
+				as.integer(p$n),as.double(p$x),as.double(p$y),
+				as.double(x0),as.double(y0),as.double(r0),
+				as.integer(tmax),as.double(by),
+				as.double(xsample),as.double(ysample),as.integer(nbSample),
+				count=double(tmax*nbSample),
+				PACKAGE="ads")$count
+	}
+	else if(cas==3) { #complex within rectangle
+		count<-.C("density_tr_rect",
+				as.integer(p$n),as.double(p$x),as.double(p$y),
+				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+				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.double(xsample),as.double(ysample),as.integer(nbSample),
+				count=double(tmax*nbSample),
+				PACKAGE="ads")$count
+	}
+	else if(cas==4) { #complex within circle
+		count<-.C("density_tr_disq",
+				as.integer(p$n),as.double(p$x),as.double(p$y),
+				as.double(x0),as.double(y0),as.double(r0),
+				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.double(xsample),as.double(ysample),as.integer(nbSample),
+				count=double(tmax*nbSample),
+				PACKAGE="ads")$count
+	}
+	## rajouter un indice lorsque les disques ne sont pas independants
+	# formatting results	
+	dens<-count/(pi*r^2)
+	#grid<-matrix(c(xsample,ysample),nrow=nbSample,ncol=2)
+	count<-matrix(count,nrow=nbSample,ncol=tmax,byrow=TRUE)
+	dens<-matrix(dens,nrow=nbSample,ncol=tmax,byrow=TRUE)
+	call<-match.call()	
+	res<-list(call=call,window=p$window,r=r,xy=data.frame(x=xsample,y=ysample),cval=count,dval=dens)
+	class(res)<-c("vads","dval")
+	return(res)	
+}
+
+kval<-function(p,upto,by) {	
+	# checking for input parameters
+	stopifnot(inherits(p,"spp"))
+	if(p$type!="univariate")
+		warning(paste(p$type,"point pattern has been considered to be univariate\n"))
+	stopifnot(is.numeric(upto))
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+		stop("invalid window type")
+	intensity<-p$n/area.swin(p$window)
+
+	#computing ripley local functions
+	if(cas==1) { #rectangle
+		res<-.C("ripleylocal_rect",		
+				as.integer(p$n),as.double(p$x),as.double(p$y),
+				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+				as.integer(tmax),as.double(by),
+				gi=double(p$n*tmax),ki=double(p$n*tmax),
+				PACKAGE="ads")
+	}
+	else if(cas==2) { #circle
+		res<-.C("ripleylocal_disq",
+				as.integer(p$n),as.double(p$x),as.double(p$y),
+				as.double(x0),as.double(y0),as.double(r0),
+				as.integer(tmax),as.double(by),
+				gi=double(p$n*tmax),ki=double(p$n*tmax),
+				PACKAGE="ads")
+	}
+	else if(cas==3) { #complex within rectangle
+		res<-.C("ripleylocal_tr_rect",
+				as.integer(p$n),as.double(p$x),as.double(p$y),
+				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+				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),
+				gi=double(p$n*tmax),ki=double(p$n*tmax),
+				PACKAGE="ads")
+	}
+	else if(cas==4) { #complex within circle
+		res<-.C("ripleylocal_tr_disq",
+				as.integer(p$n),as.double(p$x),as.double(p$y),
+				as.double(x0),as.double(y0),as.double(r0),
+				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),
+				gi=double(p$n*tmax),ki=double(p$n*tmax),
+				PACKAGE="ads")
+	}	
+	# formatting results
+	ds<-c(pi,diff(pi*r^2))
+	gi<-matrix(res$gi/(intensity*ds),nrow=p$n,ncol=tmax,byrow=TRUE)
+	ni<-matrix(res$ki/(pi*r^2),nrow=p$n,ncol=tmax,byrow=TRUE)
+	ki<-matrix(res$ki/intensity,nrow=p$n,ncol=tmax,byrow=TRUE)
+	li<-matrix(sqrt(res$ki/(intensity*pi))-r,nrow=p$n,ncol=tmax,byrow=TRUE)
+	call<-match.call()
+	res<-list(call=call,window=p$window,r=r,xy=data.frame(x=p$x,y=p$y),gval=gi,kval=ki,nval=ni,lval=li)
+	class(res)<-c("vads","kval")
+	return(res)
+}
+
+k12val<-function(p,upto,by,marks) {
+	# checking for input parameters
+	stopifnot(inherits(p,"spp"))
+	stopifnot(p$type=="multivariate")
+	stopifnot(is.numeric(upto))
+	stopifnot(is.numeric(by))
+	stopifnot(by>0)
+	r<-seq(by,upto,by)
+	tmax<-length(r)
+	if(missing(marks))
+		marks<-c(1,2)
+	stopifnot(length(marks)==2)
+	stopifnot(marks[1]!=marks[2])
+	mark1<-marks[1]
+	mark2<-marks[2]
+	if(is.numeric(mark1))
+		mark1<-levels(p$marks)[testInteger(mark1)]
+	else if(!mark1%in%p$marks) stop(paste("mark \'",mark1,"\' doesn\'t exist",sep=""))
+	if(is.numeric(mark2))
+		mark2<-levels(p$marks)[testInteger(mark2)]
+	else if(!mark2%in%p$marks) stop(paste("mark \'",mark2,"\' doesn\'t exist",sep=""))
+	# initializing variables
+	if("rectangle"%in%p$window$type) {
+		cas<-1
+		xmin<-p$window$xmin
+		xmax<-p$window$xmax
+		ymin<-p$window$ymin
+		ymax<-p$window$ymax
+		stopifnot(upto<=(0.5*max((xmax-xmin),(ymax-ymin))))
+		if ("complex"%in%p$window$type) {
+			cas<-3
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else if("circle"%in%p$window$type) {
+		cas<-2
+		x0<-p$window$x0
+		y0<-p$window$y0
+		r0<-p$window$r0
+		stopifnot(upto<=r0)
+		if ("complex"%in%p$window$type) {
+			cas<-4
+			tri<-p$window$triangles
+			nbTri<-nrow(tri)
+		}
+	}
+	else
+		stop("invalid window type")
+	surface<-area.swin(p$window)
+	x1<-p$x[p$marks==mark1]
+	y1<-p$y[p$marks==mark1]
+	x2<-p$x[p$marks==mark2]
+	y2<-p$y[p$marks==mark2]
+	nbPts1<-length(x1)
+	nbPts2<-length(x2)
+	intensity2<-nbPts2/surface
+	#computing intertype local functions
+	if(cas==1) { #rectangle
+		res<-.C("intertypelocal_rect",		
+				as.integer(nbPts1),as.double(x1),as.double(y1),
+				as.integer(nbPts2),as.double(x2),as.double(y2),
+				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+				as.integer(tmax),as.double(by),
+				gi=double(nbPts1*tmax),ki=double(nbPts1*tmax),
+				PACKAGE="ads")
+	}
+	else if(cas==2) { #circle
+		res<-.C("intertypelocal_disq",
+				as.integer(nbPts1),as.double(x1),as.double(y1),
+				as.integer(nbPts2),as.double(x2),as.double(y2),
+				as.double(x0),as.double(y0),as.double(r0),
+				as.integer(tmax),as.double(by),
+				gi=double(nbPts1*tmax),ki=double(nbPts1*tmax),
+				PACKAGE="ads")
+	}
+	else if(cas==3) { #complex within rectangle
+		res<-.C("intertypelocal_tr_rect",		
+				as.integer(nbPts1),as.double(x1),as.double(y1),
+				as.integer(nbPts2),as.double(x2),as.double(y2),
+				as.double(xmin),as.double(xmax),as.double(ymin),as.double(ymax),
+				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),
+				gi=double(nbPts1*tmax),ki=double(nbPts1*tmax),
+				PACKAGE="ads")
+	}
+	else if(cas==4) { #complex within circle
+		res<-.C("intertypelocal_tr_disq",
+				as.integer(nbPts1),as.double(x1),as.double(y1),
+				as.integer(nbPts2),as.double(x2),as.double(y2),
+				as.double(x0),as.double(y0),as.double(r0),
+				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),
+				gi=double(nbPts1*tmax),ki=double(nbPts1*tmax),
+				PACKAGE="ads")
+	}
+	# formatting results
+	ds<-c(pi,diff(pi*r^2))
+	gi<-matrix(res$gi/(intensity2*ds),nrow=nbPts1,ncol=tmax,byrow=TRUE)
+	ni<-matrix(res$ki/(pi*r^2),nrow=nbPts1,ncol=tmax,byrow=TRUE)
+	ki<-matrix(res$ki/intensity2,nrow=nbPts1,ncol=tmax,byrow=TRUE)
+	li<-matrix(sqrt(res$ki/(intensity2*pi))-r,nrow=nbPts1,ncol=tmax,byrow=TRUE)
+	call<-match.call()
+	res<-list(call=call,window=p$window,r=r,xy=data.frame(x=x1,y=y1),g12val=gi,k12val=ki,n12val=ni,l12val=li,marks=c(mark1,mark2))
+	class(res)<-c("vads","k12val")
+	return(res)
+}
+
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..829caa1a2c6e431cd9ed11d9b98bfae9a38bdc06 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 split 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 correlations entre les parametres edaphiques, et plus specialement texture, hydromorphie et drainage interne, et la reponse individuelle des chenes sessiles et pedoncules ? la gelivure.} Rapport de recherche ENITEF, Nogent sur Vernisson, France.
+}
+\references{
+Goreaud, F. & Pelissier, 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..941b5856eb55d356e8f5dafd93b3edf6a2441b08 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 vertex 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 vertex 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 vertex coordinates \eqn{(x,y)} of the polygon enclosing \code{BPoirier$tri1}.\cr
+\code{$poly2   } is a list of two polygons vertex 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{
+Parde, J. 1981. De 1882 a 1976/80 : les places d'experience de sylviculture du hetre en foret domaniale de Haye. \emph{Revue Forestiere Francaise}, 33: 41-64.
+}
+
+\references{
+Goreaud, F. 2000. \emph{Apports de l'analyse de la structure spatiale en foret temperee a l'etude et la modelisation des peuplements complexes}. These de doctorat, ENGREF, Nancy, France.\cr\cr
+Pelissier, 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..1de6358c650ad57935e1c8cca1dd60e4591082b7 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 vertex 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 especes structurantes d'une foret dense humide d'apres l'analyse de leur repartition spatiale (foret de Paracou - Guyane).} These de doctorat, Universite Claude Bernard, Lyon, France.
+}
+\references{
+Goreaud, F. & P?Pelissier, 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/Paracou15.Rd b/man/Paracou15.Rd
index e3aee182faa318aa70cf9653f3b41d1fd1c75152..a1145ba26e862023f2b85c51d1ffd6318229ab31 100755
--- a/man/Paracou15.Rd
+++ b/man/Paracou15.Rd
@@ -4,7 +4,7 @@
 \docType{data}
 \title{Tree spatial pattern in control plot 15, Paracou experimental station, French Guiana}
 \description{
-Spatial pattern of 4128 trees of 332 diffrent species in a 250 m X 250 m control plot in Paracou experimental station, French Guiana. 
+Spatial pattern of 4128 trees of 332 different species in a 250 m X 250 m control plot in Paracou experimental station, French Guiana. 
 }
 \usage{data(Paracou15)}
 \format{
@@ -15,11 +15,11 @@ A list with 5 components:\cr
 \code{$spdist } is an object of class \code{"dist"} giving between-species distances based on functional traits (see Paine et al. 2011).\cr
 }
 \source{
-Gourlet-Fleury, S., Ferry, B., Molino, J.-F., Petronelli, P. & Schmitt, L. 2004. \emph{Exeprimental plots: key features.} Pp. 3-60 In Gourlet-Fleury, S., Guehl, J.-M. & Laroussinie, O. (Eds.), Ecology and Managament of a Neotropical rainforest - Lessons drawn from Paracou, a long-term experimental research site in French Guiana. Elsevier SAS, France.
+Gourlet-Fleury, S., Ferry, B., Molino, J.-F., Petronelli, P. & Schmitt, L. 2004. \emph{Experimental plots: key features.} Pp. 3-60 In Gourlet-Fleury, S., Guehl, J.-M. & Laroussinie, O. (Eds.), Ecology and Management of a Neotropical rainforest - Lessons drawn from Paracou, a long-term experimental research site in French Guiana. Elsevier SAS, France.
 }
 
 \references{
-Paine, C. E. T., Baraloto, C., Chave, J. & Hérault, B. 2011. Functional traits of individual trees reveal ecological constraints on community assembly in tropical rain forests. \emph{Oikos}, 120: 720-727.\cr\cr
+Paine, C. E. T., Baraloto, C., Chave, J. & Herault, B. 2011. Functional traits of individual trees reveal ecological constraints on community assembly in tropical rain forests. \emph{Oikos}, 120: 720-727.\cr\cr
 }
 \examples{
 data(Paracou15)
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..e96172ee5f24579511034d42f8241f84ab67df0b 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.data} 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.core} point pattern.
+}
+\source{
+ data(demopat) in \code{spatstat.data} 
+}
+\examples{
+	data(demopat)
+	demo.spp<-ppp2spp(demopat)
+	plot(demo.spp)
+}
+\keyword{datasets}
diff --git a/man/dval.Rd b/man/dval.Rd
index 89e6050dfa3243492fd0537890867c41f8cf7a33..a0394509e43f70a46f8358c97a1dffc6bdde6ac7 100755
--- a/man/dval.Rd
+++ b/man/dval.Rd
@@ -22,20 +22,20 @@ dval(p, upto, by, nx, ny)
 \details{
  The local density is estimated for a regular sequence of sample circles radii given by \code{seq(by,upto,by)} (see \code{\link{seq}}).
  The sample circles are centred at the nodes of a regular grid with size \eqn{nx} by \eqn{ny}. Ripley's edge effect correction is applied when 
- the sample circles overlap boundary of the sampling window (see Ripley (1977) or Goreaud & Pélissier (1999) for an extension to circular and complex 
+ the sample circles overlap boundary of the sampling window (see Ripley (1977) or Goreaud & P?Pelissier (1999) for an extension to circular and complex 
  sampling windows). Due to edge effect correction, \code{upto}, the maximum radius of the sample circles, is half the longer side for a rectangle sampling
  window (i.e. \eqn{0.5*max((xmax-xmin),(ymax-ymin))}) and the radius \eqn{r0} for a circular sampling window (see \code{\link{swin}}).
 }
 \value{
  A list of class \code{c("vads","dval")} with essentially the following components:
  \item{r }{a vector of regularly spaced out distances (\code{seq(by,upto,by)}).}
- \item{xy }{a data frame of \eqn{(nx*ny)} observations giving \eqn{(x,y)} coordinates of the centers of the sample circles (the grid nodes).}
+ \item{xy }{a data frame of \eqn{(nx*ny)} observations giving \eqn{(x,y)} coordinates of the centres of the sample circles (the grid nodes).}
  \item{cval }{a matrix of size \eqn{(nx*ny,length(r))} giving the estimated number of points of the pattern per sample circle with radius \eqn{r}.}
  \item{dval }{a matrix of size \eqn{(nx*ny,length(r))} giving the estimated number of points of the pattern per unit area per sample circle with radius \eqn{r}.}
  }
 \references{
-  Goreaud, F. and Pélissier, R. 1999. On explicit formula of edge effect correction for Ripley's \emph{K}-function. \emph{Journal of Vegetation Science}, 10:433-438.\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.\cr\cr
+  Goreaud, F. and P?Pelissier, R. 1999. On explicit formula of edge effect correction for Ripley's \emph{K}-function. \emph{Journal of Vegetation Science}, 10:433-438.\cr\cr
+  P?Pelissier, 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.\cr\cr
   Ripley, B.D. 1977. Modelling spatial patterns. \emph{Journal of the Royal Statistical Society B}, 39:172-212.
 }
 \author{\email{Raphael.Pelissier@ird.fr}}
@@ -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..3b1ab95a9890515d0e8852154b11654747a2d05d 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 whether 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 6920a3f2723939c9facc2a51474a824fc7781319..f8ef8df2d8c7ccb24ce910733f5fe171b3a27f3b 100755
--- a/man/internal.Rd
+++ b/man/internal.Rd
@@ -44,7 +44,7 @@ area.poly(xp, yp)
 convert(x)
 convert2(x)
 in.circle(x, y, x0, y0, r0, bdry=TRUE)
-in.poly(x, y, poly, bdry=TRUE)
+in.poly(x, y, poly, bdry=FALSE)
 in.rectangle(x, y, xmin, ymin, xmax, ymax, bdry=TRUE)
 in.triangle(x, y, ax, ay, bx, by, cx, cy, bdry=TRUE)
 is.poly(p)
@@ -64,4 +64,4 @@ 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..3aafb8d1a9e29d6dafcf13aefcce4cf885531d7c 100755
--- a/man/k12fun.Rd
+++ b/man/k12fun.Rd
@@ -1,9 +1,9 @@
 \encoding{latin1}
 \name{k12fun}
 \alias{k12fun}
-\title{Multiscale second-order neigbourhood analysis of a bivariate spatial point pattern}
+\title{Multiscale second-order neighbourhood analysis of a bivariate spatial point pattern}
 \description{
-  Computes estimates of the intertype \emph{K12}-function and associated neigbourhood functions from a bivariate spatial point pattern 
+  Computes estimates of the intertype \emph{K12}-function and associated neighbourhood functions from a bivariate spatial point pattern 
   in a simple (rectangular or circular) or complex sampling window. Computes optionally local confidence limits of the functions
   under the null hypotheses of population independence or random labelling (see Details).
 }
@@ -28,7 +28,7 @@ k12fun(p, upto, by, nsim=0, H0=c("pitor","pimim","rl"), prec=0.01, nsimax=3000,
    of points of type 1 and 2, respectively.}
 }
 \details{
-  Function \code{k12fun} computes the intertype \eqn{K12(r)} function of second-order neigbourhood analysis and the associated functions \eqn{g12(r)},
+  Function \code{k12fun} computes the intertype \eqn{K12(r)} function of second-order neighbourhood analysis and the associated functions \eqn{g12(r)},
    \eqn{n12(r)} and \eqn{L12(r)}.\cr\cr
   For a homogeneous isotropic bivariate point process of intensities \eqn{\lambda1} and \eqn{\lambda2},
   the second-order property could be characterized by a function \eqn{K12(r)} (Lotwick & Silverman 1982), so that the expected
@@ -43,7 +43,7 @@ k12fun(p, upto, by, nsim=0, H0=c("pitor","pimim","rl"), prec=0.01, nsimax=3000,
   \eqn{O12(r) = \lambda2*g12(r)} (Wiegand & Moloney 2004).\cr\cr
   
   The program introduces an edge effect correction term according to the method proposed by Ripley (1977)
-  and extended to circular and complex sampling windows by Goreaud & Pélissier (1999).\cr\cr
+  and extended to circular and complex sampling windows by Goreaud & Pelissier (1999).\cr\cr
  
   Theoretical values under the null hypothesis of either population independence or random labelling as well as
   local Monte Carlo confidence limits and p-values of departure from the null hypothesis (Besag & Diggle 1977) are estimated at each distance \eqn{r}.\cr
@@ -54,7 +54,7 @@ k12fun(p, upto, by, nsim=0, H0=c("pitor","pimim","rl"), prec=0.01, nsimax=3000,
   to mimic the pattern of type 1 points (see \code{\link{mimetic}}.\cr
   The random labelling hypothesis \code{"rl"} assumes that the probability to bear a given mark is the same for all points of the pattern and
    doesn't depends on neighbours. It is therefore tested conditionally to the whole spatial pattern, by randomizing the marks over the points'
-  locations kept unchanged (see Goreaud & Pélissier 2003 for further details). 
+  locations kept unchanged (see Goreaud & Pelissier 2003 for further details). 
 }
 \value{
   A list of class \code{"fads"} with essentially the following components:
@@ -62,8 +62,8 @@ k12fun(p, upto, by, nsim=0, H0=c("pitor","pimim","rl"), prec=0.01, nsimax=3000,
   \item{g12 }{a data frame containing values of the bivariate pair density function \eqn{g12(r)}.}
   \item{n12 }{a data frame containing values of the bivariate local neighbour density function \eqn{n12(r)}.}
   \item{k12 }{a data frame containing values of the intertype function \eqn{K12(r)}.}
-  \item{l12 }{a data frame containing values of the modified intertype function \eqn{L12(r)}.\cr\cr}
- \item{ }{Each component except \code{r} is a data frame with the following variables:\cr\cr}
+  \item{l12 }{a data frame containing values of the modified intertype function \eqn{L12(r)}.\cr}
+  Each component except \code{r} is a data frame with the following variables:\cr
  \item{obs }{a vector of estimated values for the observed point pattern.}
  \item{theo }{a vector of theoretical values expected under the selected null hypothesis.}
  \item{sup }{(optional) if \code{nsim>0} a vector of the upper local confidence limits of the selected null hypothesis at a significant level \eqn{\alpha}.}
@@ -72,8 +72,8 @@ k12fun(p, upto, by, nsim=0, H0=c("pitor","pimim","rl"), prec=0.01, nsimax=3000,
 }
 \references{
  Besag J.E. & Diggle P.J. 1977. Simple Monte Carlo tests spatial patterns. \emph{Applied Statistics}, 26:327-333.\cr\cr
- 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.\cr\cr
- 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.\cr\cr
+ Goreaud F. & Pelissier R. 1999. On explicit formulas of edge effect correction for Ripley's K-function. \emph{Journal of Vegetation Science}, 10:433-438.\cr\cr
+ Goreaud, F. & Pelissier, 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.\cr\cr
  Lotwick, H.W. & Silverman, B.W. 1982. Methods for analysing spatial processes of several types of points. \emph{Journal of the Royal Statistical Society B}, 44:403-413.\cr\cr
  Ripley B.D. 1977. Modelling spatial patterns. \emph{Journal of the Royal Statistical Society B}, 39:172-192.\cr\cr
  Wiegand, T. & Moloney, K.A. 2004. Rings, circles, and null-models for point pattern analysis in ecology. \emph{Oikos}, 104:209-229.
@@ -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..27561e4ac4efb128afe0201f0d52f4d85e8a6d6b 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?Pelissier & 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?Pelissier, 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..ebd17c18e73a79bf809dcae5468283f8bc5782a1 100755
--- a/man/kdfun.Rd
+++ b/man/kdfun.Rd
@@ -1,7 +1,7 @@
 \encoding{latin1}
 \name{kdfun}
 \alias{kdfun}
-\title{Multiscale second-order neigbourhood analysis of a spatial phylogenetic or functional community pattern from fully mapped data}
+\title{Multiscale second-order neighbourhood analysis of a spatial phylogenetic or functional community pattern from fully mapped data}
 \description{
   Computes distance-dependent estimates of Shen et al. (2014) phylogenetic or functional mark correlation functions from a multivariate spatial point pattern 
   in a simple (rectangular or circular) or complex sampling window. Computes optionally local confidence limits of the functions
@@ -21,13 +21,13 @@ kdfun(p, upto, by, dis, nsim=0, alpha = 0.01)
 }
 \details{
  Function \code{kdfun} computes Shen et al. (2014) \eqn{Kd} and \emph{gd}-functions. For a multivariate point pattern consisting of \eqn{S} species with intensity \eqn{\lambda}p, such functions can be estimated from the bivariate \eqn{Kpq}-functions between each pair of different species \eqn{p} and \eqn{q}.
- Function \code{kdfun} is thus a simple wrapper of \code{\link{k12fun}} (Pélissier & Goreaud 2014):
+ Function \code{kdfun} is thus a simple wrapper of \code{\link{k12fun}} (P?Pelissier & Goreaud 2014):
 
   \eqn{Kd(r) = D * Kr(r) / HD * Ks(r) = D * sum(\lambda p * \lambda q * Kpq(r) * dpq) / HD * sum(\lambda p * \lambda q * Kpq(r))}.\cr
   \eqn{gd(r) = D * g(r) / HD * gs(r) = D * sum(\lambda p * \lambda q * gpq(r) * dpq) / HD * sum(\lambda p * \lambda q * gpq(r))}.\cr\cr
 
   where \eqn{Ks(r)} and \eqn{gs(r)} are distance-dependent versions of Simpson's diversity index, \eqn{D} (see \code{\link{ksfun}}), \eqn{Kr(r)} and \eqn{gr(r)} are distance-dependent versions of Rao's diversity coefficient (see \code{\link{krfun}}); 
-  \eqn{dpq} is the distance between species \eqn{p} and \eqn{q} defined by matrix \code{dis}, typically a taxonomic, phylogentic or functional distance. The advantage here is that as the edge effects vanish between \eqn{Kr(r)} and \eqn{Ks(r)},
+  \eqn{dpq} is the distance between species \eqn{p} and \eqn{q} defined by matrix \code{dis}, typically a taxonomic, phylogenetic or functional distance. The advantage here is that as the edge effects vanish between \eqn{Kr(r)} and \eqn{Ks(r)},
    implementation is fast for a sampling window of any shape. \eqn{Kd(r)} provides the expected phylogenetic or functional distance of two heterospecific individuals a distance less than \emph{r} apart (Shen et al. 2014), while \eqn{gd(r)} 
    provides the same within an annuli between two consecutive distances of \emph{r} and \emph{r-by}.
    
@@ -39,8 +39,8 @@ kdfun(p, upto, by, dis, nsim=0, alpha = 0.01)
  A list of class \code{"fads"} with essentially the following components:
   \item{r }{a vector of regularly spaced out distances (\code{seq(by,upto,by)}).}
   \item{gd }{a data frame containing values of the function \eqn{gd(r)}.}
-  \item{kd }{a data frame containing values of the function \eqn{Kd(r)}.\cr\cr}
-    \item{}{Each component except \code{r} is a data frame with the following variables:\cr\cr}
+  \item{kd }{a data frame containing values of the function \eqn{Kd(r)}.\cr}
+  Each component except \code{r} is a data frame with the following variables:\cr
 \item{obs }{a vector of estimated values for the observed point pattern.}
  \item{theo }{a vector of theoretical values expected under the null hypothesis of species equivalence.}
  \item{sup }{(optional) if \code{nsim>0} a vector of the upper local confidence limits of a random distribution of the null hypothesis at a significant level \eqn{\alpha}.}
@@ -50,7 +50,7 @@ kdfun(p, upto, by, dis, nsim=0, alpha = 0.01)
 \references{
  Shen, G., Wiegand, T., Mi, X. & He, F. (2014). Quantifying spatial phylogenetic structures of fully stem-mapped plant communities. \emph{Methods in Ecology and Evolution}, 4, 1132-1141.
  
- Pélissier, R. & Goreaud, F. ads package for R: A fast unbiased implementation of the K-function family for studying spatial point patterns in irregular-shaped sampling windows. \emph{Journal of Statistical Software}, in press.
+ P?Pelissier, R. & Goreaud, F. ads package for R: A fast unbiased implementation of the K-function family for studying spatial point patterns in irregular-shaped sampling windows. \emph{Journal of Statistical Software}, in press.
  
 }
 \author{\email{Raphael.Pelissier@ird.fr}}
@@ -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..434c30fd668bc30dc58517c6b7f965cd5d3ad0ff 100755
--- a/man/kfun.Rd
+++ b/man/kfun.Rd
@@ -1,9 +1,9 @@
 \encoding{latin1}
 \name{kfun}
 \alias{kfun}
-\title{Multiscale second-order neigbourhood analysis of an univariate spatial point pattern}
+\title{Multiscale second-order neighbourhood analysis of an univariate spatial point pattern}
 \description{
-  Computes estimates of Ripley's \emph{K}-function and associated neigbourhood functions from an univariate spatial point pattern 
+  Computes estimates of Ripley's \emph{K}-function and associated neighbourhood functions from an univariate spatial point pattern 
   in a simple (rectangular or circular) or complex sampling window. Computes optionally local confidence limits of the functions
   under the null hypothesis of Complete Spatial Randomness (see Details).
 }
@@ -33,7 +33,7 @@ kfun(p, upto, by, nsim=0, prec=0.01, alpha=0.01)
   \eqn{O(r) = \lambda*g(r)}.\cr\cr
   
   The program introduces an edge effect correction term according to the method proposed by Ripley (1977)
-  and extended to circular and complex sampling windows by Goreaud & Pélissier (1999).\cr\cr
+  and extended to circular and complex sampling windows by Goreaud & P?Pelissier (1999).\cr\cr
  
   Theoretical values under the null hypothesis of CSR as well as
   local Monte Carlo confidence limits and p-values of departure from CSR (Besag & Diggle 1977) are estimated at each distance \eqn{r}.
@@ -44,8 +44,8 @@ kfun(p, upto, by, nsim=0, prec=0.01, alpha=0.01)
   \item{g }{a data frame containing values of the pair density function \eqn{g(r)}.}
   \item{n }{a data frame containing values of the local neighbour density function \eqn{n(r)}.}
   \item{k }{a data frame containing values of Ripley's function \eqn{K(r)}.}
-  \item{l }{a data frame containing values of the modified Ripley's function \eqn{L(r)}.\cr\cr}
-   \item{}{Each component except \code{r} is a data frame with the following variables:\cr\cr}
+  \item{l }{a data frame containing values of the modified Ripley's function \eqn{L(r)}.\cr}
+  Each component except \code{r} is a data frame with the following variables:\cr
 \item{obs }{a vector of estimated values for the observed point pattern.}
  \item{theo }{a vector of theoretical values expected for a Poisson pattern.}
  \item{sup }{(optional) if \code{nsim>0} a vector of the upper local confidence limits of a Poisson pattern at a significant level \eqn{\alpha}.}
@@ -57,7 +57,7 @@ kfun(p, upto, by, nsim=0, prec=0.01, alpha=0.01)
   
  Besag J.E. & Diggle P.J. 1977. Simple Monte Carlo tests spatial patterns. \emph{Applied Statistics}, 26:327-333.
   
- 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.
+ Goreaud F. & P?Pelissier R. 1999. On explicit formulas of edge effect correction for Ripley's K-function. \emph{Journal of Vegetation Science}, 10:433-438.
 
  Ripley B.D. 1977. Modelling spatial patterns. \emph{Journal of the Royal Statistical Society B}, 39:172-192.
   
@@ -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..55acb9fed8a775a15819cdac5649c3b0fdb06c5e 100755
--- a/man/kmfun.Rd
+++ b/man/kmfun.Rd
@@ -1,9 +1,9 @@
 \encoding{latin1}
 \name{kmfun}
 \alias{kmfun}
-\title{Multiscale second-order neigbourhood analysis of a marked spatial point pattern}
+\title{Multiscale second-order neighbourhood analysis of a marked spatial point pattern}
 \description{
-   Computes estimates of the mark correlation \emph{Km}-function and associated neigbourhood functions from a marked spatial point pattern 
+   Computes estimates of the mark correlation \emph{Km}-function and associated neighbourhood functions from a marked spatial point pattern 
   in a simple (rectangular or circular) or complex sampling window. Computes optionally local confidence limits of the functions
   under the null hypothesis of no correlation between marks (see Details).
 }
@@ -30,7 +30,7 @@ kmfun(p, upto, by, nsim=0, alpha=0.01)
  
  \eqn{gm(r)} is the derivative of \eqn{Km(r)} or pair mark correlation function, which gives the correlation of marks within an annuli between two successive circles with radii \eqn{r} and \eqn{r-by}).\cr\cr
   
-  The program introduces an edge effect correction term according to the method proposed by Ripley (1977) and extended to circular and complex sampling windows by Goreaud & Pélissier (1999).
+  The program introduces an edge effect correction term according to the method proposed by Ripley (1977) and extended to circular and complex sampling windows by Goreaud & P?Pelissier (1999).
   
   Local Monte Carlo confidence limits and p-values of departure from the null hypothesis of no correlation are estimated at each distance \eqn{r}, after reallocating at random the values of \emph{X} over all points of the pattern, the location of trees being kept unchanged.
 }
@@ -38,8 +38,8 @@ kmfun(p, upto, by, nsim=0, alpha=0.01)
  A list of class \code{"fads"} with essentially the following components:
   \item{r }{a vector of regularly spaced out distances (\code{seq(by,upto,by)}).}
   \item{gm }{a data frame containing values of the pair mark correlation function \eqn{gm(r)}.}
-  \item{km }{a data frame containing values of the mark correlation function \eqn{Km(r)}.\cr\cr}
- \item{ }{Each component except \code{r} is a data frame with the following variables:\cr\cr}
+  \item{km }{a data frame containing values of the mark correlation function \eqn{Km(r)}.\cr}
+ Each component except \code{r} is a data frame with the following variables:\cr
  \item{obs }{a vector of estimated values for the observed point pattern.}
  \item{theo }{a vector of theoretical values expected for the null hypothesis of no correlation between marks.}
  \item{sup }{(optional) if \code{nsim>0} a vector of the upper local confidence limits of the null hypothesis at a significant level \eqn{\alpha}.}
@@ -50,11 +50,11 @@ kmfun(p, upto, by, nsim=0, alpha=0.01)
 Applications of this function can be found in Oddou-Muratorio \emph{et al.} (2004) and Madelaine \emph{et al.} (submitted).
 }
 
-  \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
-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.\cr\cr
-Madelaine, C., Pélissier, R., Vincent, G., Molino, J.-F., Sabatier, D., Prévost, M.-F. & de Namur, C. 2007. Mortality and recruitment in a lowland tropical rainforest of French Guiana: effects of soil type and species guild. \emph{Journal of Tropical Ecology}, 23:277-287.
+  \references{Goreaud, F. 2000. \emph{Apports de l'analyse de la structure spatiale en foret tempere a l'etude et la modelisation des peuplements complexes}. These de doctorat, ENGREF, Nancy, France.\cr\cr
+Goreaud F. & P?Pelissier R. 1999. On explicit formulas of edge effect correction for Ripley's K-function. \emph{Journal of Vegetation Science}, 10:433-438.\cr\cr
+Madelaine, C., Pelissier, R., Vincent, G., Molino, J.-F., Sabatier, D., Prevost, M.-F. & de Namur, C. 2007. Mortality and recruitment in a lowland tropical rainforest of French Guiana: effects of soil type and species guild. \emph{Journal of Tropical Ecology}, 23:277-287.
 
-Oddou-Muratorio, S., Demesure-Musch, B., Pélissier, R. & Gouyon, P.-H. 2004. Impacts of gene flow and logging history on the local genetic structure of a scattered tree species, Sorbus torminalis L. \emph{Molecular Ecology}, 13:3689-3702.
+Oddou-Muratorio, S., Demesure-Musch, B., Pelissier, R. & Gouyon, P.-H. 2004. Impacts of gene flow and logging history on the local genetic structure of a scattered tree species, Sorbus torminalis L. \emph{Molecular Ecology}, 13:3689-3702.
 
 Ripley B.D. 1977. Modelling spatial patterns. \emph{Journal of the Royal Statistical Society B}, 39:172-192.
 }
@@ -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..543537d7446b9d5907f1b8f452c3f72027964d42 100755
--- a/man/kp.fun.Rd
+++ b/man/kp.fun.Rd
@@ -2,7 +2,7 @@
 \name{kp.fun}
 \alias{kp.fun}
 \alias{ki.fun}
-\title{ Multiscale second-order neigbourhood analysis of a multivariate spatial point pattern}
+\title{ Multiscale second-order neighbourhood analysis of a multivariate spatial point pattern}
 \description{
 (Formerly \code{ki.fun}) Computes a set of \emph{K12}-functions between all possible marks \eqn{p} and the other marks in
  a multivariate spatial point pattern defined in a simple (rectangular or circular) 
@@ -27,8 +27,8 @@ kp.fun(p, upto, by)
   \item{gp.  }{a data frame containing values of the pair density function \eqn{g12(r)}.}
   \item{np.  }{a data frame containing values of the local neighbour density function \eqn{n12(r)}.}
   \item{kp.  }{a data frame containing values of the \eqn{K12(r)} function.}
-  \item{lp.  }{a data frame containing values of the modified \eqn{L12(r)} function.\cr\cr}
- \item{ }{Each component except \code{r} is a data frame with the following variables:\cr\cr}
+  \item{lp.  }{a data frame containing values of the modified \eqn{L12(r)} function.\cr}
+ Each component except \code{r} is a data frame with the following variables:\cr
  \item{obs }{a vector of estimated values for the observed point pattern.}
  \item{theo }{a vector of theoretical values expected under the null hypothesis of population independence (see \code{\link{k12fun}}).}
 }
@@ -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..c7ae3cded6b8145722684af0522abc5ab9471315 100755
--- a/man/kpqfun.Rd
+++ b/man/kpqfun.Rd
@@ -2,7 +2,7 @@
 \name{kpqfun}
 \alias{kpqfun}
 \alias{kijfun}
-\title{Multiscale second-order neigbourhood analysis of a multivariate spatial point pattern}
+\title{Multiscale second-order neighbourhood analysis of a multivariate spatial point pattern}
 \description{
   (Formerly \code{kijfun}) Computes a set of \emph{K}- and \emph{K12}-functions for all possible pairs of marks \eqn{(p,q)} in a multivariate spatial 
   point pattern defined in a simple (rectangular or circular) 
@@ -27,8 +27,8 @@ A list of class \code{"fads"} with essentially the following components:
   \item{gpq }{a data frame containing values of the pair density functions \eqn{g(r)} and \eqn{g12(r)}.}
   \item{npq }{a data frame containing values of the local neighbour density functions \eqn{n(r)} and \eqn{n12(r)}.}
   \item{kpq }{a data frame containing values of the \eqn{K(r)} and \eqn{K12(r)} functions.}
-\item{lpq }{a data frame containing values of the modified \eqn{L(r)} and \eqn{L12(r)} functions.\cr\cr}
- \item{ }{Each component except \code{r} is a data frame with the following variables:\cr}
+  \item{lpq }{a data frame containing values of the modified \eqn{L(r)} and \eqn{L12(r)} functions.\cr}
+ Each component except \code{r} is a data frame with the following variables:\cr
  \item{obs }{a vector of estimated values for the observed point pattern.}
  \item{theo }{a vector of theoretical values expected under the null hypotheses of spatial randomness (see \code{\link{kfun}}) and
   population independence (see \code{\link{k12fun}}).}
@@ -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..f10656e00159be5ada87f48d22b51e153e0b2f2a 100755
--- a/man/krfun.Rd
+++ b/man/krfun.Rd
@@ -1,7 +1,7 @@
 \encoding{latin1}
 \name{krfun}
 \alias{krfun}
-\title{Multiscale second-order neigbourhood analysis of a multivariate spatial point pattern using Rao quandratic entropy}
+\title{Multiscale second-order neighbourhood analysis of a multivariate spatial point pattern using Rao quadratic entropy}
 \description{
   Computes distance-dependent estimates of Rao's quadratic entropy from a multivariate spatial point pattern 
   in a simple (rectangular or circular) or complex sampling window. Computes optionally local confidence limits of the functions
@@ -23,15 +23,15 @@ krfun(p, upto, by, nsim=0, dis = NULL, H0 = c("rl", "se"), alpha = 0.01)
 \details{
  Function \code{krfun} computes distance-dependent functions of Rao (1982) quadratic entropy (see \code{\link{divc}} in package \code{ade4}).\cr\cr
  For a multivariate point pattern consisting of \eqn{S} species with intensity \eqn{\lambda}p, such functions can be estimated from the bivariate \eqn{Kpq}-functions between each pair of different species \eqn{p} and \eqn{q}.
- Function \code{krfun} is thus a simple wrapper function of \code{\link{k12fun}} and \code{\link{kfun}}, standardized by Rao diversity coefficient (Pélissier & Goreaud 2014):
+ Function \code{krfun} is thus a simple wrapper function of \code{\link{k12fun}} and \code{\link{kfun}}, standardized by Rao diversity coefficient (Pelissier & Goreaud 2014):
 
   \eqn{Kr(r) = sum(\lambda p * \lambda q * Kpq(r)*dpq) / (\lambda * \lambda * K(r) * HD)}.\cr
   \eqn{gr(r) = sum(\lambda p * \lambda q * gpq(r)*dpq) / (\lambda * \lambda * g(r) * HD)}.\cr\cr
 
-  where \eqn{dpq} is the distance between species \eqn{p} and \eqn{q} defined by matrix \code{dis}, typically a taxonomic, phylogentic or functional distance, and \eqn{HD=sum(Np*Nq*dpq/(N(N - 1)))} is the unbiased version of Rao diversity coefficient (see Shimatani 2001). When \code{dis = NULL}, species are considered each other equidistant and \code{krfun} returns the same results than \code{\link{ksfun}}. 
+  where \eqn{dpq} is the distance between species \eqn{p} and \eqn{q} defined by matrix \code{dis}, typically a taxonomic, phylogenetic or functional distance, and \eqn{HD=sum(Np*Nq*dpq/(N(N - 1)))} is the unbiased version of Rao diversity coefficient (see Shimatani 2001). When \code{dis = NULL}, species are considered each other equidistant and \code{krfun} returns the same results than \code{\link{ksfun}}. 
 
 The program introduces an edge effect correction term according to the method proposed by Ripley (1977)
-  and extended to circular and complex sampling windows by Goreaud & Pélissier (1999).\cr\cr
+  and extended to circular and complex sampling windows by Goreaud & Pelissier (1999).\cr\cr
  
 Theoretical values under the null hypothesis of either random labelling or species equivalence as well as local Monte Carlo confidence limits and p-values of departure from the null hypothesis (Besag & Diggle 1977) are estimated at each distance \eqn{r}.
 
@@ -43,8 +43,8 @@ The species equivalence hypothesis (H0 = "se") is tested by randomizing the betw
  A list of class \code{"fads"} with essentially the following components:
   \item{r }{a vector of regularly spaced out distances (\code{seq(by,upto,by)}).}
   \item{gr }{a data frame containing values of the function \eqn{gr(r)}.}
-  \item{kr }{a data frame containing values of the function \eqn{Kr(r)}.\cr\cr}
-    \item{}{Each component except \code{r} is a data frame with the following variables:\cr\cr}
+  \item{kr }{a data frame containing values of the function \eqn{Kr(r)}.\cr}
+  Each component except \code{r} is a data frame with the following variables:\cr
 \item{obs }{a vector of estimated values for the observed point pattern.}
  \item{theo }{a vector of theoretical values expected under the selected null hypothesis.}
  \item{sup }{(optional) if \code{nsim>0} a vector of the upper local confidence limits of a random distribution of the selected null hypothesis at a significant level \eqn{\alpha}.}
@@ -54,13 +54,13 @@ 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.
+ Goreaud F. & Pelissier R. 1999. On explicit formulas of edge effect correction for Ripley's K-function. \emph{Journal of Vegetation Science}, 10:433-438.
 
  Ripley B.D. 1977. Modelling spatial patterns. \emph{Journal of the Royal Statistical Society B}, 39:172-192.
  
- Pélissier, R. & Goreaud, F. 2014. ads package for R: A fast unbiased implementation of the k-function family for studying spatial point patterns in irregular-shaped sampling windows. \emph{Journal of Statistical Software}, in press.
+ Pelissier, R. & Goreaud, F. 2014. ads package for R: A fast unbiased implementation of the k-function family for studying spatial point patterns in irregular-shaped sampling windows. \emph{Journal of Statistical Software}, in press.
  
 }
 \author{\email{Raphael.Pelissier@ird.fr}}
@@ -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..870a25501ae73f94011d8e5dac67d6d6af196ef6 100755
--- a/man/ksfun.Rd
+++ b/man/ksfun.Rd
@@ -1,7 +1,7 @@
 \encoding{latin1}
 \name{ksfun}
 \alias{ksfun}
-\title{Multiscale second-order neigbourhood analysis of a multivariate spatial point pattern using Simpson diversity}
+\title{Multiscale second-order neighbourhood analysis of a multivariate spatial point pattern using Simpson diversity}
 \description{
   Computes estimates of Shimatani \emph{alpha} and \emph{beta} functions of Simpson diversity from a multivariate spatial point pattern 
   in a simple (rectangular or circular) or complex sampling window. Computes optionally local confidence limits of the functions
@@ -21,18 +21,18 @@ ksfun(p, upto, by, nsim=0, alpha=0.01)
 \details{
  Function \code{ksfun} computes Shimatani \eqn{\alpha(r)} and \eqn{\beta(r)} functions of Simpson diversity, called here \eqn{Ks(r)} and \eqn{gs(r)}, respectively.\cr\cr
  For a multivariate point pattern consisting of \eqn{S} species with intensity \eqn{\lambda}p, Shimatani (2001) showed that
-  a distance-dependent measure of Simpson (1949) diversity can be estimated from Ripley (1977) \eqn{K}-function computed for each species separately and for all the points grouped toghether (see also Eckel et al. 2008).
+  a distance-dependent measure of Simpson (1949) diversity can be estimated from Ripley (1977) \eqn{K}-function computed for each species separately and for all the points grouped together (see also Eckel et al. 2008).
   Function \code{ksfun} is thus a simple wrapper function of \code{\link{kfun}}, standardized by Simpson diversity coefficient:
   
   
   \eqn{Ks(r) = 1 - sum(\lambda p * \lambda p * Kp(r)) / (\lambda * \lambda * K(r) * D)} which is a standardized estimator of \eqn{\alpha(r)} in Shimatani (2001).\cr\cr
   \eqn{gs(r) = 1 - sum(\lambda p * \lambda p * gp(r)) / (\lambda * \lambda * g(r) * D)} corresponding to a standardized version of \eqn{\beta(r)} in Shimatani (2001).\cr\cr
   
-  \eqn{Kp(r)} and \eqn{K(r)} (resp. \eqn{gp(r)} and \eqn{g(r)}) are univariate K-functions computed for species \eqn{p} and for all species toghether; \eqn{D = 1 - sum(Np * (Np - 1) / (N*(N - 1)))} is the unbiased version of Simpson diversity,
+  \eqn{Kp(r)} and \eqn{K(r)} (resp. \eqn{gp(r)} and \eqn{g(r)}) are univariate K-functions computed for species \eqn{p} and for all species together; \eqn{D = 1 - sum(Np * (Np - 1) / (N*(N - 1)))} is the unbiased version of Simpson diversity,
   with \eqn{Np} the number of individuals of species \eqn{p} in the sample and \eqn{N = sum(Np)}.
 
   The program introduces an edge effect correction term according to the method proposed by Ripley (1977)
-  and extended to circular and complex sampling windows by Goreaud & Pélissier (1999).\cr\cr
+  and extended to circular and complex sampling windows by Goreaud & P?Pelissier (1999).\cr\cr
  
   The theoretical values of \eqn{gr(r)} and \eqn{Kr(r)} under the null hypothesis of random labelling is 1 for all \eqn{r}.
   Local Monte Carlo confidence limits and p-values of departure from this hypothesis are estimated at each distance \eqn{r} by reallocating at random the species labels among points of the pattern, keeping the point locations unchanged.
@@ -41,22 +41,22 @@ ksfun(p, upto, by, nsim=0, alpha=0.01)
  A list of class \code{"fads"} with essentially the following components:
   \item{r }{a vector of regularly spaced out distances (\code{seq(by,upto,by)}).}
   \item{gs }{a data frame containing values of the function \eqn{gs(r)}.}
-  \item{ks }{a data frame containing values of the function \eqn{Ks(r)}.\cr\cr}
-    \item{}{Each component except \code{r} is a data frame with the following variables:\cr\cr}
+  \item{ks }{a data frame containing values of the function \eqn{Ks(r)}.\cr}
+  Each component except \code{r} is a data frame with the following variables:\cr
 \item{obs }{a vector of estimated values for the observed point pattern.}
  \item{theo }{a vector of theoretical values expected under the null hypothesis of random labelling, i.e. 1 for all \eqn{r}.}
  \item{sup }{(optional) if \code{nsim>0} a vector of the upper local confidence limits of a random distribution of species labels at a significant level \eqn{\alpha}.}
- \item{inf }{(optional) if \code{nsim>0} a vector of the lower local confidence limits of a Prandom distribution of species labels at a significant level \eqn{\alpha}.}
+ \item{inf }{(optional) if \code{nsim>0} a vector of the lower local confidence limits of a random distribution of species labels at a significant level \eqn{\alpha}.}
  \item{pval }{(optional) if \code{nsim>0} a vector of local p-values of departure from a random distribution of species labels.}
 }
 \references{
- Shimatani K. 2001. Multivariate point processes and spatial variation in species diversity. \emph{Forest Ecology and Managaement}, 142:215-229.
+ Shimatani K. 2001. Multivariate point processes and spatial variation in species diversity. \emph{Forest Ecology and Management}, 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.
  
- 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.
+ Goreaud F. & P?Pelissier R. 1999. On explicit formulas of edge effect correction for Ripley's K-function. \emph{Journal of Vegetation Science}, 10:433-438.
 
  Ripley B.D. 1977. Modelling spatial patterns. \emph{Journal of the Royal Statistical Society B}, 39:172-192.
 }
@@ -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..38180c0abd1b4c333aba5a033a1599ea775893cf 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 individual 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?Pelissier & 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?Pelissier, 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..ea22424d6306e432b4865bd5f280ee1e551cbd85 100755
--- a/man/mimetic.Rd
+++ b/man/mimetic.Rd
@@ -13,14 +13,14 @@ mimetic(x,upto=NULL,by=NULL,prec=NULL,nsimax=3000,conv=50)
   \item{x }{either a \code{("fads", "kfun")} object or a \code{"spp"} object of type "univariate" defining a spatial point pattern in a given sampling window (see \code{\link{kfun}} or \code{\link{spp}}).}
   \item{upto }{(optional) maximum radius of the sample circles when \code{x} is a \code{"spp"} object.}
   \item{by }{(optional) interval length between successive sample circles radii when \code{x} is a \code{"spp"} object.}
-  \item{prec }{precision of point coordinates generated during simulations when \code{x} is a \code{"spp"} object. By default prec=0.01 or the value used in fonction \code{kfun} when \code{x} is a \code{("fads", "kfun")} object.}
+  \item{prec }{precision of point coordinates generated during simulations when \code{x} is a \code{"spp"} object. By default prec=0.01 or the value used in function \code{kfun} when \code{x} is a \code{("fads", "kfun")} object.}
   \item{nsimax }{maximum number of simulations allowed. By default the process stops after \code{nsimax=3000} if convergence is not reached.}
   \item{conv }{maximum number of simulations without optimization gain (convergence criterion).}
 }
 \details{
  Function \code{mimetic} uses a stepwise depletion-replacement algorithm to generate a point pattern whose L-function is optimized with regards to an observed one, following the mimetic point process principle (Goreaud et al. 2004).  
- Four points are randomly deleted at each step of the process and replaced by new points that minimize the following cost function:||\eqn{Lobs(r) - Lsim (r)}||)^2. The simulation stops as soon as the cost fonction doesn't decrease 
- after \code{conv} simulations or after a maximum of \code{nsimax} simulations. The process apply to rectangular, circular or comlex sampling windows (see \code{\link{spp}}). There exist a \code{plot} method that displays diagnostic 
+ Four points are randomly deleted at each step of the process and replaced by new points that minimize the following cost function:||\eqn{Lobs(r) - Lsim (r)}||)^2. The simulation stops as soon as the cost function doesn't decrease 
+ after \code{conv} simulations or after a maximum of \code{nsimax} simulations. The process apply to rectangular, circular or complex sampling windows (see \code{\link{spp}}). There exist a \code{plot} method that displays diagnostic 
  plots, i.e. the observed and simulated L-function, the simulated point pattern and the successive values of the cost function. 
 }
 \value{
@@ -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..46da4a598e9c3ff9071e175bbdc7d6001ed56b99 100755
--- a/man/plot.fads.Rd
+++ b/man/plot.fads.Rd
@@ -10,9 +10,9 @@
 \alias{plot.fads.krfun}
 \alias{plot.fads.kdfun}
 \alias{plot.fads.mimetic}
-\title{Plot second-order neigbourhood functions}
+\title{Plot second-order neighbourhood functions}
 \description{
- Plot second-order neigbourhood function estimates returned by functions \code{\link{kfun}, \link{k12fun}, \link{kmfun}}, \cr
+ Plot second-order neighbourhood function estimates returned by functions \code{\link{kfun}, \link{k12fun}, \link{kmfun}}, \cr
  	\code{ \link{kijfun} or \link{ki.fun}}.
 }
 \usage{
@@ -20,9 +20,9 @@
 }
 \arguments{
   \item{x}{an object of class \code{"fads"} (see Details).}
-  \item{opt}{one of \code{c("all","L","K","n","g")} to dislay either all or one of the functions in a single window. By default \code{opt = "all"} for \code{fads} 
+  \item{opt}{one of \code{c("all","L","K","n","g")} to display either all or one of the functions in a single window. By default \code{opt = "all"} for \code{fads} 
   objects of subclass \code{"kfun"}, \code{"k12fun"}, or \code{"kmfun"};  by default \code{opt = "L"} for \code{fads} objects of subclass \code{"kij"}, or \code{"ki."}.}
-  \item{cols}{(optional) coulours used for plotting functions.}
+  \item{cols}{(optional) colours used for plotting functions.}
   \item{lty}{(optional) line types used for plotting functions.}
   \item{main}{by default, the value of argument x, otherwise a text to be displayed as a title of the plot. \code{main=NULL} displays no title.}
   \item{sub}{by default, the name of the function displayed, otherwise a text to be displayed as function subtitle. \code{sub=NULL} displays no subtitle.}
@@ -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..ed44ebd79a5cb80d1b982cc83659387784a0c720 100755
--- a/man/plot.spp.Rd
+++ b/man/plot.spp.Rd
@@ -15,9 +15,9 @@ maxsize, scale=TRUE, add=FALSE, legend=TRUE, csize=1, ...)
   \item{out}{by default \code{out = FALSE}. If \code{TRUE} points of the pattern located outside the sampling window are plotted.}
   \item{use.marks}{by default \code{use.marks = TRUE}. If \code{FALSE} different symbols are not used for each mark of multivariate
    or marked point patterns, so that they are plotted as univariate (see \code{\link{spp}}).}
-  \item{cols}{(optional) the coulour(s) used to plot points located inside the sampling window (see Details).}
+  \item{cols}{(optional) the colour(s) used to plot points located inside the sampling window (see Details).}
   \item{chars}{(optional) plotting character(s) used to plot points located inside the sampling window (see Details).}
-  \item{cols.out}{(optional) if \code{out = TRUE}, the coulour(s) used to plot points located outside the sampling window (see Details).}
+  \item{cols.out}{(optional) if \code{out = TRUE}, the colour(s) used to plot points located outside the sampling window (see Details).}
   \item{chars.out}{(optional) if \code{out = TRUE}, plotting character(s) used to plot points located outside the sampling window (see Details).}
   \item{maxsize}{(optional) maximum size of plotting symbols. By default \code{maxsize} is automatically adjusted to plot size.}
   \item{csize}{scaling factor for font size so that actual font size is \code{par("cex")*csize}. By default \code{csize = 1}.}
@@ -45,11 +45,11 @@ Then the points themselves are plotted, in a fashion that depends on the type of
 	
 	Arguments \code{cols} and \code{cols.out} (if \code{out = TRUE}) determine the colour(s) used to display the points located inside and outside the sampling window, respectively.
 	Colours may be specified as codes or colour names (see \code{\link[graphics]{par}("col")}). For univariate and marked point patterns, \code{cols} and \code{cols.out} are single character strings, while 
-	for multivariate point patterns they are charcater vectors of same length as \code{levels(x$marks)} and \code{levels(x$marksout)}, respectively.
+	for multivariate point patterns they are character vectors of same length as \code{levels(x$marks)} and \code{levels(x$marksout)}, respectively.
 
 	Arguments \code{chars} and \code{chars.out} (if \code{out = TRUE}) determine the symbol(s) used to display the points located inside and outside the sampling window, respectively.
 	Symbols may be specified as codes or character strings (see \code{\link[graphics]{par}("pch")}). For univariate point patterns, \code{chars} and \code{chars.out} are single character strings, while 
-	for multivariate point patterns they are charcater vectors of same length as \code{levels(x$marks)} and \code{levels(x$marksout)}, respectively. For marked point patterns, 
+	for multivariate point patterns they are character vectors of same length as \code{levels(x$marks)} and \code{levels(x$marksout)}, respectively. For marked point patterns, 
 	\code{chars} and \code{chars.out} can only take the value \code{"circles"} or \code{"squares"}.	
 }
 \value{
@@ -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..920a3ca62c8a646bae98707bdb8fa0e820b537f0 100755
--- a/man/plot.vads.Rd
+++ b/man/plot.vads.Rd
@@ -18,10 +18,10 @@
   \item{opt}{(optional) a character string to change the type of values to be plotted (see Details).}
   \item{select}{(optional) a vector of selected distances in \code{x$r}. By default, a multiple window displays all distances.}
   \item{chars}{one of \code{c("circles","squares")} plotting symbols with areas proportional to local density values. By default, circles are plotted.} 
-  \item{cols}{(optional) the coulour used for the plotting symbols. Black colour is the default.}
+  \item{cols}{(optional) the colour used for the plotting symbols. Black colour is the default.}
   \item{maxsize}{(optional) maximum size of the circles/squares plotted. By default, maxsize is automatically adjusted to plot size.}
   \item{char0}{(optional) the plotting symbol used to represent null values. By default, null values are not plotted.}
-  \item{col0}{(optional) the coulour used for the null values plotting symbol. By default, the same as argument \code{cols}.}
+  \item{col0}{(optional) the colour used for the null values plotting symbol. By default, the same as argument \code{cols}.}
   \item{legend}{If \code{legend = TRUE} (the default) a legend for the plotting values is displayed.}
   \item{csize}{scaling factor for font size so that actual font size is \code{par("cex")*csize}. By default \code{csize = 1}.}
   \item{\dots}{extra arguments that will be passed to the plotting functions \code{\link{plot.swin}}, \cr
@@ -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..ab33d60f2542f93f8b720743b6d85910a2d7b961 100755
--- a/man/spp.Rd
+++ b/man/spp.Rd
@@ -24,7 +24,7 @@ ppp2spp(p)
   complex sampling window (see \code{\link{swin}}).}
   \item{marks}{(optional) a vector of mark values, which may be factor levels or numerical values (see Details).}
   \item{int2fac}{if TRUE, integer marks are automatically coerced into factor levels.}
-  \item{p}{a \code{"ppp"} object from package \code{spatstat}.}
+  \item{p}{a \code{"ppp"} object from package \code{spatstat.geom}.}
 }
 \details{
 A spatial point pattern is assumed to have been observed within a specific
@@ -58,11 +58,11 @@ A spatial point pattern is assumed to have been observed within a specific
   \item{\code{$marksout}}{(optional) a vector of the marks attached to points located outside the sampling window.}
 }
 \references{
- Goreaud, F. and Pélissier, R. 1999. On explicit formula of edge effect correction for Ripley's \emph{K}-function. \emph{Journal of Vegetation Science}, 10:433-438.
+ Goreaud, F. and P?Pelissier, R. 1999. On explicit formula of edge effect correction for Ripley's \emph{K}-function. \emph{Journal of Vegetation Science}, 10:433-438.
 }
 \note{
 There are printing, summary and plotting methods for \code{"spp"} objects.\cr
-Function \code{ppp2spp} converts an \code{\link[spatstat]{ppp.object}} from package \code{spatstat} into an \code{"spp"} object.
+Function \code{ppp2spp} converts an \code{\link[spatstat.geom]{ppp.object}} from package \code{spatstat.geom} into an \code{"spp"} object.
 }
 \seealso{
   \code{\link{plot.spp}},
@@ -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.geom}
 	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..e36429d39115ac6a6e4d4c0ca9f03bae711aa178 100755
--- a/man/swin.Rd
+++ b/man/swin.Rd
@@ -22,7 +22,7 @@
    for a rectangle ; \code{c(x0,y0,r0)} for a circle.}
   \item{triangles}{(optional) a list of triangles removed from a simple initial window to define a complex 
   sampling window (see Details).}`
-  \item{w}{a \code{"owin"} object from package \code{spatstat}.}
+  \item{w}{a \code{"owin"} object from package \code{spatstat.geom}.}
 }
 \details{
 A sampling window may be of simple or complex type. A simple sampling window may be a rectangle or a circle.
@@ -51,15 +51,15 @@ A sampling window may be of simple or complex type. A simple sampling window may
  with different arguments:
  \item{\code{$type}}{a vector of two character strings defining the type of sampling window among \code{c("simple","rectangle")}, \code{c("simple","circle")}, \code{c("complex","rectangle")} or \code{c("complex","circle")}.}
  \item{\code{$xmin,$ymin,$xmax,$ymax}}{(optional) coordinates of the origin and the opposite corner for a rectangular sampling window (see details).}
- \item{\code{$x0,$y0,$r0}}{(optional) coordinates of the center and radius for a circular sampling window (see details).}
+ \item{\code{$x0,$y0,$r0}}{(optional) coordinates of the centre and radius for a circular sampling window (see details).}
  \item{\code{$triangles}}{(optional) vertices coordinates of triangles for a complex sampling window (see details).}
 }
 \references{
- Goreaud, F. and Pélissier, R. 1999. On explicit formula of edge effect correction for Ripley's \emph{K}-function. \emph{Journal of Vegetation Science}, 10:433-438.
+ Goreaud, F. and P?Pelissier, R. 1999. On explicit formula of edge effect correction for Ripley's \emph{K}-function. \emph{Journal of Vegetation Science}, 10:433-438.
 }
 \note{
 There are printing, summary and plotting methods for \code{"swin"} objects.\cr
-Function \code{owin2swin} converts an \code{\link[spatstat]{owin.object}} from package \code{spatstat} into an \code{"swin"} object.
+Function \code{owin2swin} converts an \code{\link[spatstat.geom]{owin.object}} from package \code{spatstat.geom} into an \code{"swin"} object.
 }
 \seealso{
   \code{\link{area.swin}},
@@ -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.geom}
  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..78f62ff47f49408c9801d8658f9d188f174bec7b 100755
--- a/man/triangulate.Rd
+++ b/man/triangulate.Rd
@@ -9,7 +9,7 @@
 triangulate(outer.poly, holes)
 }
 \arguments{
-  \item{outer.poly}{a list with two component vectors \code{x} and \code{y} giving vertice coordinates of the polygon 
+  \item{outer.poly}{a list with two component vectors \code{x} and \code{y} giving vertex coordinates of the polygon 
   or a vector \code{(xmin,ymin,xmax,ymax)} giving coordinates \eqn{(ximn,ymin)} and \eqn{(xmax,ymax)} of the origin and the
   opposite corner of a rectangle sampling window (see \code{\link{swin}}).  }
   \item{holes}{(optional) a list (or a list of list) with two component vectors \code{x} and \code{y} giving vertices 
@@ -23,12 +23,12 @@ triangulate(outer.poly, holes)
  }
 \value{
  A list of 6 variables, suitable for using in \code{\link{swin}} and \code{\link{spp}}, and giving the vertices coordinates \eqn{(ax,ay,bx,by,cx,cy)} of the triangles that
- pave the polygon. For a polygon with \emph{t} holes totalling \eqn{n} vertices (outer contour + holes), the number of triangles produced 
+ pave the polygon. For a polygon with \emph{t} holes totaling \eqn{n} vertices (outer contour + holes), the number of triangles produced 
 is \eqn{(n-2)+2t}, with \eqn{n<200} in this version of the program.
 }
 \references{
- Goreaud, F. and Pélissier, R. 1999. On explicit formula of edge effect correction for Ripley's \emph{K}-function. \emph{Journal of Vegetation Science}, 10:433-438.\cr\cr
- Narkhede, A. & Manocha, D. 1995. Fast polygon triangulation based on Seidel's algoritm. Pp 394-397 In A.W. Paeth (Ed.)
+ Goreaud, F. and P?Pelissier, R. 1999. On explicit formula of edge effect correction for Ripley's \emph{K}-function. \emph{Journal of Vegetation Science}, 10:433-438.\cr\cr
+ Narkhede, A. & Manocha, D. 1995. Fast polygon triangulation based on Seidel's algorithm. Pp 394-397 In A.W. Paeth (Ed.)
   \emph{Graphics Gems V}. Academic Press. \url{http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html}.
 }
 \author{
@@ -43,19 +43,12 @@ 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))
-  
-  # 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{a single polygon with a hole}
+  \donttest{tri2 <- triangulate(c(-10,-10,120,100), BP$poly1)
+  plot(swin(c(-10,-10,120,100), tri2))}
+}
 \keyword{spatial}
diff --git a/src/Zlibs.c b/src/Zlibs.c
index e089f9169c5cb4e33b936741c54fc5c638ecee0b..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++)
@@ -2572,7 +2571,7 @@ int intertype_rect_ic(int *point_nb1, double *x1, double *y1, int *point_nb2, do
             r=0;
             while (erreur!=0)
                 {
-                erreur=mimetic_rect(point_nb1, x1, y1, surface, xmi, xma, ymi, yma, 0, NULL, NULL, 0, 0, prec, t2, dt, lt, nsimax, conv, cost, gt, kt, x, y, 0);
+                erreur=mimetic_rect(point_nb1, x1, y1, surface, xmi, xma, ymi, yma, prec, t2, dt, lt, nsimax, conv, cost, gt, kt, x, y, 0);
                 r=r+erreur;
                 if (r==*rep)
                     {
@@ -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;
@@ -3688,30 +3687,6 @@ void s_alea_rect(int point_nb, double x[], double y[],
     PutRNGstate();
     }
 
-void s_alea_rect_mask(int point_nb, double x[], double y[],
-                      double nmask, double *xmask, double *ymask, double dx, double dy,
-                      double xmi, double xma, double ymi, double yma,
-                      double p)
-    {
-    int i, out;
-    size_t ii;
-    double xr, yr;
-    GetRNGstate();
-    for (i=0; i<point_nb; i++)
-        {
-        ii=nmask*unif_rand();
-        out=1;
-        while (out)
-            {
-            x[i]=*(xmask+ii)+((2*unif_rand()-1)*(dx/p))*p;
-            y[i]=*(ymask+ii)+((2*unif_rand()-1)*(dy/p))*p;
-            out=(x[i]<xmi)||(x[i]>xma)||(y[i]<ymi)||(y[i]>yma);
-            }
-        //Rprintf("s_alea_rect_mask, ii %d, xmask %f, ymask %f, x %f, y %f\n", ii, *(xmask+ii), *(ymask+ii), x[i], y[i]);
-        }
-    PutRNGstate();
-    }
-
 /*pour un zone circulaire*/
 void s_alea_disq(int point_nb, double *x, double *y, double x0, double y0, double r0, double p)
     {
@@ -6169,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);
@@ -6309,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);
@@ -6570,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);
@@ -6707,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);
@@ -6964,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);
@@ -7100,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);
@@ -7237,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);
@@ -7498,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);
@@ -7729,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();
@@ -7765,14 +7740,11 @@ int randomdist(int *vec, int nb_type, double *mat, double *matp)
 /*Mimetic point process as in Goreaud et al. 2004     */
 
 /******************************************************/
-int mimetic_rect(int *point_nb, double *x, double *y, double *surface,
-                 double *xmi, double *xma, double *ymi, double *yma,
-                 double *nmask, double *xmask, double *ymask, double *dx, double *dy,
+int mimetic_rect(int *point_nb, double *x, double *y, double *surface, double *xmi, double *xma, double *ymi, double *yma,
                  double *prec, int *t2, double *dt, double *lobs, int *nsimax, int *conv, double *cost,
                  double *g, double *k, double *xx, double *yy, int *mess)
     {
     int i, compteur_c=0, r=0, erreur=0;
-    size_t ii;
     int compteur=0;
     double *l;
     double cout, cout_c;
@@ -7783,30 +7755,9 @@ int mimetic_rect(int *point_nb, double *x, double *y, double *surface,
     double offsetx=((*xmi)<0)?(*xmi):0.;
     double offsety=((*ymi)<0)?(*ymi):0.;
     decalRect(*point_nb, x, y, xmi, xma, ymi, yma);
-    if ((*nmask)>0)
-        {
-        if (offsetx<0.)
-            {
-            for (ii=0; ii<(*nmask); ii++)
-                {
-                double avant= *(xmask+ii);
-                *(xmask+ii)-=offsetx;
-                }
-            }
-        if (offsety<0.)
-            {
-            for (ii=0; ii<(*nmask); ii++)
-                {
-                *(ymask+ii)-=offsety;
-                }
-            }
-        }
 
     //creation of a initial point pattern and cost
-    if ((*nmask)>0)
-        s_alea_rect_mask(*point_nb, x, y, *nmask, xmask, ymask, *dx, *dy, *xmi, *xma, *ymi, *yma, *prec);
-    else
-        s_alea_rect(*point_nb, x, y, *xmi, *xma, *ymi, *yma, *prec);
+    s_alea_rect(*point_nb, x, y, *xmi, *xma, *ymi, *yma, *prec);
     erreur=ripley_rect(point_nb, x, y, xmi, xma, ymi, yma, t2, dt, g, k);
     if (erreur!=0) return -1;
     cout=0;
@@ -7822,7 +7773,7 @@ int mimetic_rect(int *point_nb, double *x, double *y, double *surface,
     cout_c=0;
     while (compteur<*nsimax)
         {
-        cout_c=echange_point_rect(*point_nb, x, y, *xmi, *xma, *ymi, *yma, *nmask, xmask, ymask, *dx, *dy, intensity, *prec, cout, lobs, t2, dt, g, k);
+        cout_c=echange_point_rect(*point_nb, x, y, *xmi, *xma, *ymi, *yma, intensity, *prec, cout, lobs, t2, dt, g, k);
         if (cout==cout_c)
             compteur_c++;
         else
@@ -7858,40 +7809,17 @@ int mimetic_rect(int *point_nb, double *x, double *y, double *surface,
     *xma+=offsetx;
     *ymi+=offsety;
     *yma+=offsety;
-    // Shift mask into original location
-    if ((*nmask)>0)
-        {
-        if (offsetx<0)
-            {
-            for (ii=0; ii<(*nmask); ii++)
-                {
-                xmask[ii]=xmask[ii]+offsetx;
-                }
-            }
-        if (offsety<0)
-            {
-            for (ii=0; ii<(*nmask); ii++)
-                {
-                ymask[ii]=ymask[ii]+offsety;
-                }
-            }
-        }
     free(l);
     return r;
     }
 
-double echange_point_rect(int point_nb, double *x, double *y,
-                          double xmi, double xma, double ymi, double yma,
-                          double nmask, double *xmask, double *ymask, double dx, double dy,
-                          double intensity, double p, double cout, double * lobs,
-                          int *t2, double *dt, double *g, double *k)
+double echange_point_rect(int point_nb, double *x, double *y, double xmi, double xma, double ymi, double yma, double intensity, double p, double cout, double * lobs, int *t2, double *dt, double *g, double *k)
     {
     double xr, yr, xcent[4], ycent[4], n_cout[4], *l, xprec, yprec;
-    int erreur, max, i, j, num, out;
-    size_t ii;
+    int erreur, max, i, j, num;
     vecalloc(&l, *t2);
     GetRNGstate();
-    num=unif_rand()*(point_nb); // numero de l'arbre que l'on retire
+    num=unif_rand()* (point_nb); // numero de l'arbre que l'on retire
     xprec=x[num];
     yprec=y[num];
     xr=xma-xmi;
@@ -7906,22 +7834,8 @@ double echange_point_rect(int point_nb, double *x, double *y,
 
     for (j=0; j<4; j++)
         {
-        if (nmask>0)
-            {
-            ii=nmask*unif_rand();
-            out=1;
-            while (out)
-                {
-                xcent[j]=xmask[ii]+((2*unif_rand()-1)*(dx/p))*p;
-                ycent[j]=ymask[ii]+((2*unif_rand()-1)*(dy/p))*p;
-                out=(xcent[j]<xmi)||(xcent[j]>xma)||(ycent[j]<ymi)||(ycent[j]>yma);
-                }
-            }
-        else
-            {
-            xcent[j]=xmi+(unif_rand()*(xr/p))*p; // coordonn�es (x,y) du point tir�
-            ycent[j]=ymi+(unif_rand()*(yr/p))*p;
-            }
+        xcent[j]=xmi+(unif_rand()*(xr/p))*p; // coordonn�es (x,y) du point tir�
+        ycent[j]=ymi+(unif_rand()*(yr/p))*p;
         x[num]=xcent[j];
         y[num]=ycent[j];
         erreur=ripley_rect(&point_nb, x, y, &xmi, &xma, &ymi, &yma, t2, dt, g, k);
@@ -8453,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);
@@ -8575,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 7b161558a407df1bc2abe5c4c4d91e89e359eabd..e55e40106bb495440ced3f6425adc496b5c31c6c 100755
--- a/src/Zlibs.h
+++ b/src/Zlibs.h
@@ -14,163 +14,139 @@ double perim_in_rect(double, double, double, double, double, double, double);
 double perim_in_disq(double,double,double,double,double,double);
 double perim_triangle(double,double,double,int,double *,double *,double *,double *,double *,double *);
 
-int ripley_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*);
-int ripley_disq(int *,double *,double *,double *,double *,double *,int *,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 ripley_tr_disq(int *,double *,double *,double *,double *,double *,int *,double *,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_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_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_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 ripleylocal_rect(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_tr_rect(int *,double *,double *,double *,double *,double *,double *,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 density_rect(int*,double*,double*,double*,double*,double*,double*,int*,double*,double*,double*,int*,double*);
-int density_disq(int*,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 *);
-int density_tr_disq(int*,double *,double *,double*,double*,double*,int*,double *,double *,double *,double *,
-	double *,double *,int*,double*,double *,double *,int*,double *);
-
-int intertype_rect(int *,double *,double *,int *,double *,double *,double *,double *,double *,double *,
-	int *,double *,double *,double *);
-int intertype_disq(int *,double *,double *,int *,double *,double *,double *,double *,double *,int *,
-	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_tr_disq(int *,double *,double *,int *,double *,double *,double *,double *,double *,int *,
-	double *,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_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_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_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 intertypelocal_rect(int*,double *,double *,int*,double *,double *,double*,double*,double*,double*,
-	int*,double*,double *,double *);
-int intertypelocal_disq(int *,double *,double *,int *,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 intertypelocal_tr_disq(int *,double *,double *,int *,double *,double *,double *,double *,double *,int *,
-	double *,double *,double *,double *,double *,double *,int *,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_rect_mask(int,double[],double[],double,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);
+                    double *,double *,double);
 void s_alea_tr_disq(int ,double *,double *,double,double,double,int,double *,double *,double *,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);
+                         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);
+                         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 *);
-
-int corr_rect(int *,double *,double *,double *, double *,double *,double *,double *,
-int *,double *,double *,double *);
-int corr_disq(int *,double *,double *,double *, double *,double *,double *,
-int *,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 corr_tr_disq(int *,double *,double *,double *, double *,double *,double *,
-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_disq_ic(int *,double *,double *,double *, double *,double *,double *,
-int *,double *,int *, double *,double *,double *,
-double *,double *, double *,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_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 shimatani_rect(int *,double *,double *,double *,double *,double *,double *,int *,double *,int *,int *,double *,double *, double *,int *);
-int shimatani_disq(int *,double *,double *, double *,double *,double *,int *,double *,int *,int *,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 *);
-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_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_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_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_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 rao_rect(int *,double *,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_disq(int *,double *,double *,double *,double *,double *,int *,double *,int *,int *,int *,double *,double *,double *,double *,
-			 double *,double *,double *,int *);
-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_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 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_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_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 mimetic_rect(int *,double *,double *, double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *, int *,double *,double *,int *,int *,double *,double *,double *,double *,double *,int *);
-int mimetic_disq(int *,double *,double *,double *,double *,double *,double *,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 *);
-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,double,double,double,double,double *,int *,double *,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 *);
-
-int shen(int *,double *,double *,int *,double *,int *,int *,double *,double *,double *,double *, double *, int *);
-
-int shen_ic(int *,double *,double *,int *,double *,int *,double *,int *,int *,double *,double *,double *,
-			double *, double *, double *,double *,double *,double *,double *,double *,int *);
+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 baf055427c247eb30c5652e57437eeb17856aa6d..2452d4b9a6a423eb0c4a9cc5e33f6f38fff3b471 100755
--- a/src/adssub.h
+++ b/src/adssub.h
@@ -29,5 +29,7 @@ void decalRectTri2(int,double *,double *,int,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
new file mode 100644
index 0000000000000000000000000000000000000000..1e1728d683d77f4bdb043e75781b6a9b81d2fb57
--- /dev/null
+++ b/src/init.c
@@ -0,0 +1,81 @@
+#include <R.h>
+#include <Rinternals.h>
+#include <stdlib.h> // for NULL
+#include <R_ext/Rdynload.h>
+#include "triangulate.h"
+#include "Zlibs.h"
+#include "adssub.h"
+
+// 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_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, 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.h b/src/triangulate.h
index baa3568cb55ce5d23f2a95c9547d6b612802f090..bd819970f128ab7de296e10bae95520332d7fb7d 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 */