[GRASS-SVN] r70845 - in grass-addons/grass7/raster/r.pi: . r.pi.corearea r.pi.corrwin r.pi.csr.mw r.pi.energy r.pi.energy.iter r.pi.enn r.pi.enn.iter r.pi.export r.pi.fnn r.pi.graph r.pi.graph.dec r.pi.graph.iter r.pi.graph.red r.pi.grow r.pi.import r.pi.index r.pi.library r.pi.lm r.pi.neigh r.pi.nlm r.pi.nlm.circ r.pi.nlm.stats r.pi.odc r.pi.prob.mw r.pi.prox r.pi.rectangle r.pi.searchtime r.pi.searchtime.iter r.pi.searchtime.mw

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Apr 6 13:56:05 PDT 2017


Author: mmetz
Date: 2017-04-06 13:56:05 -0700 (Thu, 06 Apr 2017)
New Revision: 70845

Added:
   grass-addons/grass7/raster/r.pi/r.pi.corearea/r.pi.corearea.html
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/r.pi.corrwin.html
   grass-addons/grass7/raster/r.pi/r.pi.csr.mw/r.pi.csr.mw.html
   grass-addons/grass7/raster/r.pi/r.pi.energy.iter/r.pi.energy.iter.html
   grass-addons/grass7/raster/r.pi/r.pi.energy/r.pi.energy.html
   grass-addons/grass7/raster/r.pi/r.pi.enn.iter/r.pi.enn.iter.html
   grass-addons/grass7/raster/r.pi/r.pi.enn/r.pi.enn.html
   grass-addons/grass7/raster/r.pi/r.pi.export/r.pi.export.html
   grass-addons/grass7/raster/r.pi/r.pi.fnn/r.pi.fnn.html
   grass-addons/grass7/raster/r.pi/r.pi.graph.dec/r.pi.graph.dec.html
   grass-addons/grass7/raster/r.pi/r.pi.graph.iter/r.pi.graph.iter.html
   grass-addons/grass7/raster/r.pi/r.pi.graph.red/r.pi.graph.red.html
   grass-addons/grass7/raster/r.pi/r.pi.graph/r.pi.graph.html
   grass-addons/grass7/raster/r.pi/r.pi.grow/r.pi.grow.html
   grass-addons/grass7/raster/r.pi/r.pi.import/r.pi.import.html
   grass-addons/grass7/raster/r.pi/r.pi.index/r.pi.index.html
   grass-addons/grass7/raster/r.pi/r.pi.lm/r.pi.lm.html
   grass-addons/grass7/raster/r.pi/r.pi.neigh/r.pi.neigh.html
   grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/r.pi.nlm.circ.html
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/r.pi.nlm.stats.html
   grass-addons/grass7/raster/r.pi/r.pi.nlm/r.pi.nlm.html
   grass-addons/grass7/raster/r.pi/r.pi.odc/r.pi.odc.html
   grass-addons/grass7/raster/r.pi/r.pi.prob.mw/r.pi.prob.mw.html
   grass-addons/grass7/raster/r.pi/r.pi.prox/r.pi.prox.html
   grass-addons/grass7/raster/r.pi/r.pi.rectangle/r.pi.rectangle.html
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/r.pi.searchtime.iter.html
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/r.pi.searchtime.mw.html
   grass-addons/grass7/raster/r.pi/r.pi.searchtime/r.pi.searchtime.html
Removed:
   grass-addons/grass7/raster/r.pi/r.pi.corearea/description.html
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/description.html
   grass-addons/grass7/raster/r.pi/r.pi.csr.mw/description.html
   grass-addons/grass7/raster/r.pi/r.pi.energy.iter/description.html
   grass-addons/grass7/raster/r.pi/r.pi.energy/description.html
   grass-addons/grass7/raster/r.pi/r.pi.enn.iter/description.html
   grass-addons/grass7/raster/r.pi/r.pi.enn/description.html
   grass-addons/grass7/raster/r.pi/r.pi.export/description.html
   grass-addons/grass7/raster/r.pi/r.pi.fnn/description.html
   grass-addons/grass7/raster/r.pi/r.pi.graph.dec/description.html
   grass-addons/grass7/raster/r.pi/r.pi.graph.iter/description.html
   grass-addons/grass7/raster/r.pi/r.pi.graph.red/description.html
   grass-addons/grass7/raster/r.pi/r.pi.graph/description.html
   grass-addons/grass7/raster/r.pi/r.pi.grow/description.html
   grass-addons/grass7/raster/r.pi/r.pi.import/description.html
   grass-addons/grass7/raster/r.pi/r.pi.index/description.html
   grass-addons/grass7/raster/r.pi/r.pi.lm/description.html
   grass-addons/grass7/raster/r.pi/r.pi.neigh/description.html
   grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/description.html
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/description.html
   grass-addons/grass7/raster/r.pi/r.pi.nlm/description.html
   grass-addons/grass7/raster/r.pi/r.pi.odc/description.html
   grass-addons/grass7/raster/r.pi/r.pi.prob.mw/description.html
   grass-addons/grass7/raster/r.pi/r.pi.prox/description.html
   grass-addons/grass7/raster/r.pi/r.pi.rectangle/description.html
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/description.html
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/description.html
   grass-addons/grass7/raster/r.pi/r.pi.searchtime/description.html
Modified:
   grass-addons/grass7/raster/r.pi/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.corearea/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.corearea/description_germaninfo.html
   grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.corearea/func.c
   grass-addons/grass7/raster/r.pi/r.pi.corearea/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.corearea/main.c
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/bufs.c
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/divr_cats.c
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/gather.c
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/intr_cats.c
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/main.c
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/ncb.h
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/null_cats.c
   grass-addons/grass7/raster/r.pi/r.pi.corrwin/readcell.c
   grass-addons/grass7/raster/r.pi/r.pi.csr.mw/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.csr.mw/analysis.c
   grass-addons/grass7/raster/r.pi/r.pi.csr.mw/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.csr.mw/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.csr.mw/main.c
   grass-addons/grass7/raster/r.pi/r.pi.energy.iter/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.energy.iter/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.energy.iter/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.energy.iter/main.c
   grass-addons/grass7/raster/r.pi/r.pi.energy.iter/search.c
   grass-addons/grass7/raster/r.pi/r.pi.energy/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.energy/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.energy/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.energy/main.c
   grass-addons/grass7/raster/r.pi/r.pi.energy/search.c
   grass-addons/grass7/raster/r.pi/r.pi.enn.iter/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.enn.iter/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.enn.iter/func.c
   grass-addons/grass7/raster/r.pi/r.pi.enn.iter/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.enn.iter/main.c
   grass-addons/grass7/raster/r.pi/r.pi.enn/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.enn/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.enn/func.c
   grass-addons/grass7/raster/r.pi/r.pi.enn/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.enn/main.c
   grass-addons/grass7/raster/r.pi/r.pi.enn/matrix.c
   grass-addons/grass7/raster/r.pi/r.pi.export/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.export/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.export/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.export/main.c
   grass-addons/grass7/raster/r.pi/r.pi.fnn/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.fnn/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.fnn/func.c
   grass-addons/grass7/raster/r.pi/r.pi.fnn/heap.c
   grass-addons/grass7/raster/r.pi/r.pi.fnn/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.fnn/main.c
   grass-addons/grass7/raster/r.pi/r.pi.fnn/matrix.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.dec/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.graph.dec/choice.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.dec/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.dec/func.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.dec/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.graph.dec/main.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.iter/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.graph.iter/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.iter/func.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.iter/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.graph.iter/main.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.red/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.graph.red/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.red/func.c
   grass-addons/grass7/raster/r.pi/r.pi.graph.red/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.graph.red/main.c
   grass-addons/grass7/raster/r.pi/r.pi.graph/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.graph/draw.c
   grass-addons/grass7/raster/r.pi/r.pi.graph/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.graph/func.c
   grass-addons/grass7/raster/r.pi/r.pi.graph/hull.c
   grass-addons/grass7/raster/r.pi/r.pi.graph/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.graph/main.c
   grass-addons/grass7/raster/r.pi/r.pi.grow/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.grow/func.c
   grass-addons/grass7/raster/r.pi/r.pi.grow/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.grow/main.c
   grass-addons/grass7/raster/r.pi/r.pi.import/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.import/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.import/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.import/main.c
   grass-addons/grass7/raster/r.pi/r.pi.import/parse.c
   grass-addons/grass7/raster/r.pi/r.pi.index/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.index/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.index/func.c
   grass-addons/grass7/raster/r.pi/r.pi.index/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.index/main.c
   grass-addons/grass7/raster/r.pi/r.pi.library/draw.c
   grass-addons/grass7/raster/r.pi/r.pi.library/r_pi.h
   grass-addons/grass7/raster/r.pi/r.pi.library/stat_method.c
   grass-addons/grass7/raster/r.pi/r.pi.lm/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.lm/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.lm/func.c
   grass-addons/grass7/raster/r.pi/r.pi.lm/main.c
   grass-addons/grass7/raster/r.pi/r.pi.neigh/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.neigh/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.neigh/func.c
   grass-addons/grass7/raster/r.pi/r.pi.neigh/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.neigh/main.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/main.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/fractal.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/func.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/main.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/method.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.nlm/func.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm/list.c
   grass-addons/grass7/raster/r.pi/r.pi.nlm/main.c
   grass-addons/grass7/raster/r.pi/r.pi.odc/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.odc/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.odc/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.odc/main.c
   grass-addons/grass7/raster/r.pi/r.pi.odc/voronoi.c
   grass-addons/grass7/raster/r.pi/r.pi.prob.mw/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.prob.mw/analysis.c
   grass-addons/grass7/raster/r.pi/r.pi.prob.mw/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.prob.mw/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.prob.mw/main.c
   grass-addons/grass7/raster/r.pi/r.pi.prox/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.prox/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.prox/func.c
   grass-addons/grass7/raster/r.pi/r.pi.prox/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.prox/main.c
   grass-addons/grass7/raster/r.pi/r.pi.rectangle/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.rectangle/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.rectangle/main.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/main.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/search.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/main.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/search.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime/Makefile
   grass-addons/grass7/raster/r.pi/r.pi.searchtime/frag.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime/local_proto.h
   grass-addons/grass7/raster/r.pi/r.pi.searchtime/main.c
   grass-addons/grass7/raster/r.pi/r.pi.searchtime/search.c
Log:
r.pi: port to GRASS7 part1

Modified: grass-addons/grass7/raster/r.pi/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -6,7 +6,6 @@
 	r.pi.library \
 	r.pi.corearea \
 	r.pi.corrwin \
-	r.pi.corrwindow \
 	r.pi.csr.mw \
 	r.pi.energy \
 	r.pi.energy.iter \

Modified: grass-addons/grass7/raster/r.pi/r.pi.corearea/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.corearea/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,93 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Edge effects and core area analysis of landcover fragments. This module can compute static edge effects (defined edge depth) and dynamic edge effects (based on surrounding landscape). The impact of the surrounding landscape can be accounted for and the resulting core area is provided.
-
-<h2>NOTES</h2>
-
-This module is generating core areas based on defined edge depths. The edge depths can be increased by the values of a <em>costmap</em> (e.g. urban areas could have a more severe impact than secondary forest on forest fragments). Moreover a friction map (<em> propmap</em> within the fragments can lower the impact of surrounding landcover types and hence an increased edge depth (e.g. a river or escarpment which might lower the edge effects). Moreover a <em> dist_weight</em> can be assigned in order to increase the weight of closer pixel values.
-
-<h3>Distance weight</h3>
-
-The assigned distance weight is computed as:<br>
-w(d) = 1 - (d / d_max)^(tan(dist_weight * 0.5 * pi))<br>
-
-where:<br>
-
-d = Distance of the respective cell
-d_max - the defined maximum distance
-dist_weight - the parameter how to weight the pixel values in the landscape depending on the distance <br>
-
-the <em>dist_weight</em> has a range between 0 and 1 and results in:<br>
-
-0 < dist_weight < 0.5: the weighting curve decreases at low distances to the fragment and lowers to a weight of 0 at d=d_max <br>
-
-dist_weight = 0.5: linear decrease of weight until weight of 0 at d = d_max <br>
-
-0.5 < dist_weight < 1: the weighting curve decreases slowly at low distances and approaches weight value of 0 at higher distances from the fragment, the weight value 0 is reached at d = d_max <br>
-
-dist_weight = 1: no distance weight applied, common static edge depth used
-
-
-
-<h3>propmap</h3>
-
-The <em>propmap</em> minimizes the effect of the edge depth and the surrounding matrix. This has an ecological application if certain landscape features inside a e.g. forest fragment hamper the human impact (edge effects). <br>
-
-two method exist:<br>
-
-propmethod=linear: propagated value = actual value - (propmap value at this position)<br>
-propmethod=exponential: propagated value = actual value / (propmap value at this position) <br>
-
-If 0 is chosen using the linear method, then propagated value=actual value which results in a buffering of the whole region. In order to minimize the impact the value must be larger than 1. For the exponential method a value of below 1 should not be chosen, otherwise it will be propagated infinitely.
-
-
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset using class 5 (forest):
-
-For the computation of variable edge effects a costmap is necessary which need to be defined by the user. Higher costs are resulting in higher edge depths:
-<div class="code"><pre>
-# class - type - costs
-#   1	- developed - 3
-#   2	- agriculture - 2
-#   3	- herbaceous - 1
-#   4	- shrubland - 1
-#   5	- forest - 0
-#   6	- water - 0
-#   7	- sediment - 0
-
-r.mapcalc "costmap_for_corearea = if(landclass96==1,3,if(landclass96==2,2,if(landclass96==3,1,if(landclass96==4,1,if(landclass96==5,0,if(landclass96==6,0,if(landclass96==7,0)))))))"
-
-</pre></div>
-
-
-now the edge depth and the resulting core area can be computed:
-<div class="code"><pre>
-r.pi.corearea input=landclass96 costmap=costmap_for_corearea  output=landcover96_corearea keyval=5 buffer=5 distance=5 angle=90 stats=average propmethod=linear
-</pre></div>
-
-
-the results consist of 2 files:
-landclass96_corearea: the actual resulting core areas
-landclass96_corearea_map: a map showing the edge depths
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.corearea/description_germaninfo.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/description_germaninfo.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/description_germaninfo.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,44 +1,93 @@
-> Was die propmap angeht:
->
-> Wenn du nur 0 Werte nimmst, dann werden die Werte immer unendlich
-> propagiert. Es geht nämlich so:
->
-> propmethod=linear: propagierter Wert = aktueller Wert - (propmap an
-> dieser Stelle)
->
-> propmethod=exponential: propagierter Wert = aktueller Wert / (propmap
-> an dieser Stelle)
->
-> Bei 0 in der map ist also bei linearer Methode immer
-> propagierter Wert = aktueller Wert und daher wird eigentlich alles
-> weggebuffert. Dass da einige übriggeblieben sind, hing mit dem anderen
-> Bug zusammen (oder vllt. gibt's noch einen Bug?). Jedenfalls sollten
-> dann wirklich alle Patches weg sein.
->
-> Um die Weite der Propagierung abzuschwächen muss man die Werte in der
-> Propmap größer als 1 wählen. Bei der exponentiellen Methode sollte
-> grundsätzlich nie ein Wert unter 1 gewählt werden, denn sonst wird
-> auch ins Unendliche propagiert.
+<h2>DESCRIPTION</h2>
 
+Edge effects and core area analysis of landcover fragments. This module can compute static edge effects (defined edge depth) and dynamic edge effects (based on surrounding landscape). The impact of the surrounding landscape can be accounted for and the resulting core area is provided.
 
+<h2>NOTES</h2>
 
+This module is generating core areas based on defined edge depths. The edge depths can be increased by the values of a <em>costmap</em> (e.g. urban areas could have a more severe impact than secondary forest on forest fragments). Moreover a friction map (<em> propmap</em> within the fragments can lower the impact of surrounding landcover types and hence an increased edge depth (e.g. a river or escarpment which might lower the edge effects). Moreover a <em> dist_weight</em> can be assigned in order to increase the weight of closer pixel values.
 
-w(d) = 1 - (d / d_max)^(tan(dist_weight * 0.5 * pi))
+<h3>Distance weight</h3>
 
-dabei ist:
+The assigned distance weight is computed as:<br>
+w(d) = 1 - (d / d_max)^(tan(dist_weight * 0.5 * pi))<br>
 
-d - die Distanz der jeweiligen Zelle
-d_max - die angegebene maximale Distanz
-dist_weight - der Parameter
+where:<br>
 
-Es schaut damit wie folgt aus:
+d = Distance of the respective cell
+d_max - the defined maximum distance
+dist_weight - the parameter how to weight the pixel values in the landscape depending on the distance <br>
 
-0 < dist_weight < 0.5: die Bewertungskurve ist am Anfang steil
-abfallend und wird flacher bis zum Wert 0 bei d = d_max
+the <em>dist_weight</em> has a range between 0 and 1 and results in:<br>
 
-dist_weight = 0.5: linearer Abstieg zum Wert 0 bei d = d_max
+0 < dist_weight < 0.5: the weighting curve decreases at low distances to the fragment and lowers to a weight of 0 at d=d_max <br>
 
-0.5 < dist_weight < 1: Kurve fällt flach und dann immer steiler bis
-zum Wert 0 bei d = d_max
+dist_weight = 0.5: linear decrease of weight until weight of 0 at d = d_max <br>
 
-dist_weight = 1: Keine Distanzbewertung, d.h. so wie vorher
+0.5 < dist_weight < 1: the weighting curve decreases slowly at low distances and approaches weight value of 0 at higher distances from the fragment, the weight value 0 is reached at d = d_max <br>
+
+dist_weight = 1: no distance weight applied, common static edge depth used
+
+
+
+<h3>propmap</h3>
+
+The <em>propmap</em> minimizes the effect of the edge depth and the surrounding matrix. This has an ecological application if certain landscape features inside a e.g. forest fragment hamper the human impact (edge effects). <br>
+
+two method exist:<br>
+
+propmethod=linear: propagated value = actual value - (propmap value at this position)<br>
+propmethod=exponential: propagated value = actual value / (propmap value at this position) <br>
+
+If 0 is chosen using the linear method, then propagated value=actual value which results in a buffering of the whole region. In order to minimize the impact the value must be larger than 1. For the exponential method a value of below 1 should not be chosen, otherwise it will be propagated infinitely.
+
+
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset using class 5 (forest):
+
+For the computation of variable edge effects a costmap is necessary which need to be defined by the user. Higher costs are resulting in higher edge depths:
+<div class="code"><pre>
+# class - type - costs
+#   1	- developed - 3
+#   2	- agriculture - 2
+#   3	- herbaceous - 1
+#   4	- shrubland - 1
+#   5	- forest - 0
+#   6	- water - 0
+#   7	- sediment - 0
+
+r.mapcalc "costmap_for_corearea = if(landclass96==1,3,if(landclass96==2,2,if(landclass96==3,1,if(landclass96==4,1,if(landclass96==5,0,if(landclass96==6,0,if(landclass96==7,0)))))))"
+
+</pre></div>
+
+
+now the edge depth and the resulting core area can be computed:
+<div class="code"><pre>
+r.pi.corearea input=landclass96 costmap=costmap_for_corearea  output=landcover96_corearea keyval=5 buffer=5 distance=5 angle=90 stats=average propmethod=linear
+</pre></div>
+
+
+the results consist of 2 files:
+landclass96_corearea: the actual resulting core areas
+landclass96_corearea_map: a map showing the edge depths
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -94,17 +94,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -136,16 +131,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -159,5 +153,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.corearea/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,26 +1,25 @@
 #include "local_proto.h"
 
-void valmap_output()
+void valmap_output(int nrows, int ncols)
 {
     int out_fd;
+    int row;
     DCELL *result;
 
-    result = (DCELL *) G_allocate_c_raster_buf();
+    result = (DCELL *) Rast_allocate_c_buf();
 
     /* write output */
     /* open the new cellfile  */
-    out_fd = G_open_raster_new("test_valmap", DCELL_TYPE);
+    out_fd = Rast_open_new("test_valmap", DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file test_valmap\n"));
 	exit(EXIT_FAILURE);
     }
 
     /* write the output file */
-    int row, i;
-    Position *p;
 
     for (row = 0; row < nrows; row++) {
-	G_put_d_raster_row(out_fd, &valmap[row * ncols]);
+	Rast_put_d_row(out_fd, &valmap[row * ncols]);
     }
 
     G_free(result);
@@ -28,27 +27,26 @@
 
 /* find one contour strting at the given cell poition */
 Position *find_contour(int *flagbuf, Position start, int dirx, int diry,
-		       Position * list, int patch)
+		       int nrows, int ncols, Position * list, int patch)
 {
     /* start with the given cell */
     int x = start.x;
     int y = start.y;
     int dx = dirx;
     int dy = diry;
-
     int curpos = 0;
 
     list[curpos].x = x;
     list[curpos].y = y;
 
-    while (1) {			// sorry for this while(true) loop
+    while (1) {			/* sorry for this while(true) loop */
 	x += dx;
 	y += dy;
 
 	if (x >= 0 && x < ncols && y >= 0 && y < nrows) {
 	    if (flagbuf[y * ncols + x] == patch + 1) {
 		/* a patch cell is encountered */
-		int neighbors;
+		int tmp;
 
 		/* if it is not the current cell again */
 		if (!(x == list[curpos].x && y == list[curpos].y)) {
@@ -73,7 +71,7 @@
 		y -= dy;
 
 		/* turn left */
-		int tmp = dx;
+		tmp = dx;
 
 		dx = dy;
 		dy = -tmp;
@@ -100,7 +98,7 @@
 	    dx = -dy;
 	    dy = tmp;
 	}
-    }				// while(1)
+    }				/* while(1) */
 
     /* adjust the patch border references */
     curpos++;
@@ -109,13 +107,21 @@
 }
 
 /* find borders of a patch and sort cells accordingly */
-void find_borders_patch(int *flagbuf, int patch)
+void find_borders_patch(int *flagbuf, int patch, int nrows, int ncols)
 {
     /* copy border cells into a separate border array */
     int cell_count = fragments[patch + 1] - fragments[patch];
-    Position border[cell_count * 2];
+    Position *border;
+    PatchBorderList *list;
     int border_count = 0;
     Coords *p;
+    int i;
+    int curpos = 0;
+    int first;
+    int dx = 0;
+    int dy = -1;
+    
+    border = G_malloc(cell_count * 2 * sizeof(Position));
 
     for (p = fragments[patch]; p < fragments[patch + 1]; p++) {
 	if (p->neighbors < 4) {
@@ -126,7 +132,6 @@
     }
 
     /* test output */
-    int i;
 
     /*fprintf(stderr, "Border cells for patch %d:", patch);
        for(i = 0; i < border_count; i++) {
@@ -134,10 +139,10 @@
        }
        fprintf(stderr, "\n"); */
 
-    //G_message("Allocating for patch %d, border_count = %d", patch, border_count);
+    /* G_message("Allocating for patch %d, border_count = %d", patch, border_count); */
 
     /* initialize current patch border list */
-    PatchBorderList *list = patch_borders + patch;
+    list = patch_borders + patch;
 
     list->positions =
 	(Position *) G_malloc(2 * border_count * sizeof(Position));
@@ -155,8 +160,6 @@
     }
 
     /* find the top-left border cell */
-    int curpos = 0;
-    int first;
 
     for (first = i = curpos; i < border_count; i++) {
 	if (border[i].y < border[first].y ||
@@ -166,19 +169,17 @@
 	}
     }
 
-    //G_message("top-left border cell: (%d,%d)", border[first].x, border[first].y);
+    /* G_message("top-left border cell: (%d,%d)", border[first].x, border[first].y); */
 
     /* set direction for the first run */
-    int dx = 0;
-    int dy = -1;
 
     /* repeat until all borders have been found */
-    Position *nextpos = list->positions;
+    do {
+	int pos;
 
-    do {
 	/* find next contour */
 	list->borders[list->count + 1] =
-	    find_contour(flagbuf, border[first], dx, dy,
+	    find_contour(flagbuf, border[first], dx, dy, nrows, ncols,
 			 list->borders[list->count], patch);
 
 	list->count++;
@@ -205,14 +206,13 @@
 
 	/* find a border cell which still has at least one unvisited empty neighbor */
 	first = -1;
-	int pos;
 
 	for (pos = 0; pos < border_count; pos++) {
-	    Position *p = border + pos;
+	    Position *pt = border + pos;
 
-	    int nx, ny;		// neighbor
-	    int x = p->x;
-	    int y = p->y;
+	    int nx, ny;		/* neighbor */
+	    int x = pt->x;
+	    int y = pt->y;
 
 	    /* test right neighbor */
 	    nx = x + 1;
@@ -263,20 +263,22 @@
 }
 
 /* find borders of all patches and sort cells accordingly */
-void find_borders(int *flagbuf)
+void find_borders(int *flagbuf, int nrows, int ncols, int fragcount)
 {
     int i;
 
     for (i = 0; i < fragcount; i++) {
-	//    for(i = 10; i < 11; i++) {
-	//G_message("Border %d", i);
-	find_borders_patch(flagbuf, i);
+	/*
+	for(i = 10; i < 11; i++)
+	G_message("Border %d", i);
+	*/
+	find_borders_patch(flagbuf, i, nrows, ncols);
 
 	G_percent(i + 1, fragcount, 1);
-	//G_message("%d of %d", i, fragcount);
+	/*G_message("%d of %d", i, fragcount); */
     }
 
-    //valmap_output();    
+    /* valmap_output(); */
 }
 
 /* gets normal to the patch border in the given cell's position */
@@ -286,31 +288,31 @@
     Position *border = list.borders[border_index];
     int cell_count =
 	list.borders[border_index + 1] - list.borders[border_index];
+    Position cell1, cell2, cell3;
+    int dx1, dy1, dx2, dy2;
+    double l;
+    Vector2 res = {1.0, 0.0};
 
-    //G_message("Enter: patch = %d, cell_cnt = %d", patch, cell_count);
+    /* G_message("Enter: patch = %d, cell_cnt = %d", patch, cell_count); */
 
     /* handle 1-pixel patches separately */
     if (cell_count <= 1) {
-	return (Vector2) {
-	1.0, 0.0};
+	return res; 
     }
 
-    //    G_message("first cells: (%d, %d)", border[0].x, border[0].y);
+    /*    G_message("first cells: (%d, %d)", border[0].x, border[0].y); */
 
     /* get three consequtive cells */
-    Position cell1 = border[((cell - 1) + cell_count) % cell_count];
-    Position cell2 = border[cell];
-    Position cell3 = border[(cell + 1) % cell_count];
+    cell1 = border[((cell - 1) + cell_count) % cell_count];
+    cell2 = border[cell];
+    cell3 = border[(cell + 1) % cell_count];
 
-    //    G_message("Middle");
+    dx1 = cell2.x - cell1.x;
+    dy1 = cell2.y - cell1.y;
+    dx2 = cell3.x - cell2.x;
+    dy2 = cell3.y - cell2.y;
 
-    int dx1 = cell2.x - cell1.x;
-    int dy1 = cell2.y - cell1.y;
-    int dx2 = cell3.x - cell2.x;
-    int dy2 = cell3.y - cell2.y;
 
-    Vector2 res;
-
     res.x = 0.5 * (dy1 + dy2);
     res.y = -0.5 * (dx1 + dx2);
 
@@ -320,17 +322,16 @@
     }
 
     /* normalize resulting vector */
-    double l = sqrt(res.x * res.x + res.y * res.y);
+    l = sqrt(res.x * res.x + res.y * res.y);
 
     res.x /= l;
     res.y /= l;
 
-    //    G_message("Exit");
     return res;
 }
 
 /* returns a value from the cost map */
-DCELL get_cost_value(int x, int y)
+DCELL get_cost_value(int x, int y, int nrows, int ncols)
 {
     if (x >= 0 && x < ncols && y >= 0 && y < nrows) {
 	return map[y * ncols + x];
@@ -343,12 +344,12 @@
 /* gets an array with values of the cost matrix cells in the range of the effect cone of */
 /* the given cell with the given normal */
 int get_cost_values(DCELL * res, Position cell, Vector2 n, double distance,
-		    double angle, double weight_param)
+		    double angle, double weight_param, int nrows, int ncols)
 {
     int d = (int)distance;
     double ref = cos(0.5 * angle);
 
-    //fprintf(stderr, "Cell (%d, %d): ", cell.x, cell.y);
+    /* fprintf(stderr, "Cell (%d, %d): ", cell.x, cell.y); */
 
     int x, y;
     int count = 0;
@@ -362,7 +363,7 @@
 
 	    double angcos = (dx * n.x + dy * n.y) / l;
 
-	    DCELL val = get_cost_value(x, y);
+	    DCELL val = get_cost_value(x, y, nrows, ncols);
 
 	    if (angcos >= ref && l <= distance && val >= 0) {
 		/* incorporate distance */
@@ -374,27 +375,30 @@
 		res[count] = val;
 		count++;
 
-		//fprintf(stderr, "%0.2f ", val);
+		/* fprintf(stderr, "%0.2f ", val); */
 	    }
 	}
     }
 
-    //fprintf(stderr, "\n");
+    /* fprintf(stderr, "\n"); */
 
     return count;
 }
 
 /* initializes border cell values for propagation */
 void init_border_values(double distance, double angle, int buffer,
-			f_statmethod stat, double dist_weight)
+			f_statmethod stat, double dist_weight,
+			int nrows, int ncols, int fragcount)
 {
     int patch;
     int size = (int)distance * 2 + 1;
+    DCELL *cost_values;
+    double weight_param;
 
     size *= size;
-    DCELL *cost_values = (DCELL *) G_malloc(size * sizeof(DCELL));
+    cost_values = (DCELL *) G_malloc(size * sizeof(DCELL));
 
-    double weight_param = tan(dist_weight * 0.5 * M_PI);
+    weight_param = tan(dist_weight * 0.5 * M_PI);
 
     for (patch = 0; patch < fragcount; patch++) {
 	PatchBorderList list = patch_borders[patch];
@@ -412,30 +416,32 @@
 		int border_count =
 		    list.borders[contour + 1] - list.borders[contour];
 
-		int count;
+		int count, value;
+		DCELL *buf;
 
 		if (border_count == 1) {
 		    count =
 			get_cost_values(cost_values, *p, n, distance,
-					2 * M_PI, weight_param);
+					2 * M_PI, weight_param,
+					nrows, ncols);
 		}
 		else {
 		    count =
 			get_cost_values(cost_values, *p, n, distance, angle,
-					weight_param);
+					weight_param, nrows, ncols);
 		}
 
-		int value = Round(stat(cost_values, count) * (DCELL) buffer);
+		value = Round(stat(cost_values, count) * (DCELL) buffer);
 
-		DCELL *buf = &valmap[p->y * ncols + p->x];
+		buf = &valmap[p->y * ncols + p->x];
 
 		if (*buf >= 0 && *buf < value) {
 		    *buf = value;
 		}
 
-		//G_message("Value for (%d, %d) = %d", p->x, p->y, value);
+		/* G_message("Value for (%d, %d) = %d", p->x, p->y, value); */
 
-		//G_message("Normal to (%d, %d) is (%0.2f, %0.2f)", p->x, p->y, n.x, n.y);
+		/* G_message("Normal to (%d, %d) is (%0.2f, %0.2f)", p->x, p->y, n.x, n.y); */
 	    }
 	}
     }
@@ -503,10 +509,9 @@
 }
 
 /* propagates border values of a patch with a linear decrease */
-void propagate_patch(int patch, int neighbor_count, f_propmethod prop_method)
+void propagate_patch(int patch, int neighbor_count,
+                     f_propmethod prop_method, int nrows, int ncols)
 {
-    PatchBorderList list = patch_borders[patch];
-
     Position *nbr_list =
 	(Position *) G_malloc(neighbor_count * sizeof(Position));
     int cell_count = fragments[patch + 1] - fragments[patch];
@@ -527,26 +532,29 @@
 
     /* propagate values */
     while (top > stack) {
+	int x, y;
+	DCELL value;
+	int nbr_cnt, i;
+
 	/* pop from stack */
 	top--;
-	int x = top->x;
-	int y = top->y;
-	DCELL value = valmap[y * ncols + x];
+	x = top->x;
+	y = top->y;
+	value = valmap[y * ncols + x];
 
 	/* get neighbors */
-	int nbr_cnt =
+	nbr_cnt =
 	    get_neighbors(nbr_list, x, y, ncols, nrows, neighbor_count);
 
 	/* for each neighbor */
-	int i;
+	for (i = 0; i < nbr_cnt; i++) {
+	    DCELL nbr_val, pass_val;
 
-	for (i = 0; i < nbr_cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
-	    DCELL nbr_val = valmap[y * ncols + x];
+	    nbr_val = valmap[y * ncols + x];
 
-	    //int pass_val = value - 1 >= 0 ? value - 1 : 0;
-	    DCELL pass_val = prop_method(value, propmap[y * ncols + x]);
+	    pass_val = prop_method(value, propmap[y * ncols + x]);
 
 	    if (pass_val > nbr_val) {
 		/* pass value and push neighbor on stack */
@@ -562,14 +570,15 @@
 }
 
 /* propagates border values with a linear decrease */
-void propagate(int neighbor_count, f_propmethod prop_method)
+void propagate(int neighbor_count, f_propmethod prop_method,
+               int nrows, int ncols, int fragcount)
 {
+    int patch;
+
     G_message("Propagating Values ...");
 
-    int patch;
-
     for (patch = 0; patch < fragcount; patch++) {
-	propagate_patch(patch, neighbor_count, prop_method);
+	propagate_patch(patch, neighbor_count, prop_method, nrows, ncols);
 
 	G_percent(patch + 1, fragcount, 1);
     }

Modified: grass-addons/grass7/raster/r.pi/r.pi.corearea/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -6,6 +6,7 @@
 #include <unistd.h>
 #include <math.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
@@ -37,24 +38,23 @@
 typedef DCELL(f_propmethod) (DCELL, DCELL);
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* func.c */
-void find_borders(int *flagbuf);
+void find_borders(int *flagbuf, int nrows, int ncols, int fragcount);
 void init_border_values(double distance, double angle, int buffer,
-			f_statmethod stat, double dist_weight);
-void propagate(int neighbor_count, f_propmethod prop_method);
+			f_statmethod stat, double dist_weight,
+			int nrows, int ncols, int fragcount);
+void propagate(int neighbor_count, f_propmethod prop_method,
+               int nrows, int ncols, int fragcount);
 
 /* prop_method.c */
 DCELL linear(DCELL value, DCELL propcost);
 DCELL exponential(DCELL value, DCELL propcost);
 
 /* global variables */
-GLOBAL int nrows, ncols;
 GLOBAL Coords *cells;
 GLOBAL Coords **fragments;
-GLOBAL int fragcount;
-GLOBAL int *flagbuf;
 GLOBAL DCELL *map;
 GLOBAL DCELL *valmap;
 GLOBAL DCELL *propmap;

Modified: grass-addons/grass7/raster/r.pi/r.pi.corearea/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.corearea
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Non-linear core area analysis
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -48,11 +49,8 @@
 
 int main(int argc, char *argv[])
 {
-    /* result */
-    int exitres = 0;
-
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset, *costname, *costmapset,
+    const char *newname, *oldname, *oldmapset, *costname, *costmapset,
 	*propname, *propmapset;
     char fullname[GNAME_MAX];
 
@@ -70,15 +68,14 @@
     f_propmethod *prop_method;
     double dist_weight;
 
-    /* map_type and categories */
-    RASTER_MAP_TYPE map_type;
-
     /* helpers */
     char *str;
-    int row, col, i, j, n;
-    DCELL *values;
+    int nrows, ncols;
+    int row, col, i, n;
     CELL *result;
-    DCELL *d_res;
+    int *flagbuf;
+    int patch;
+    int fragcount;
 
     struct GModule *module;
     struct
@@ -93,12 +90,10 @@
 	struct Flag *adjacent;
     } flag;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Variable edge effects and core area analysis");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -196,34 +191,31 @@
     propname = parm.propmap->answer;
 
     /* test input file existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* test costmap file existance */
-    costmapset = G_find_cell2(costname, "");
-	if (costmapset == NULL)
+    costmapset = G_find_raster2(costname, "");
+    if (costmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), costname);
 
     /* test propmap file existance */
-    if (propname && NULL == (propmapset = G_find_cell2(propname, "")))
+    propmapset = NULL;
+    if (propname && NULL == (propmapset = G_find_raster2(propname, "")))
 	    G_fatal_error(_("Raster map <%s> not found"), propname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
 	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     G_message("rows = %d, cols = %d", nrows, ncols);
 
-    /* get map type */
-    map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
-
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
 
@@ -238,20 +230,28 @@
     angle *= M_PI / 180.0;
 
     /* get statistical method */
+    method = NULL;
     for (i = 0; (str = statmethods[i].name) != 0; i++) {
 	if (strcmp(str, parm.stats->answer) == 0) {
 	    method = statmethods[i].method;
 	    break;
 	}
     }
+    if (!method)
+	G_fatal_error(_("Unknown method <%s> for option <%s>"),
+		      parm.stats->answer, parm.stats->key);
 
     /* get propagation method */
+    prop_method = NULL;
     for (i = 0; (str = propmethods[i].name) != 0; i++) {
 	if (strcmp(str, parm.propmethod->answer) == 0) {
 	    prop_method = propmethods[i].method;
 	    break;
 	}
     }
+    if (!prop_method)
+	G_fatal_error(_("Unknown method <%s> for option <%s>"),
+		      parm.propmethod->answer, parm.propmethod->key);
 
     /* get distance weighting parameter */
     if (parm.dist_weight->answer) {
@@ -272,19 +272,18 @@
     map = (DCELL *) G_malloc(nrows * ncols * sizeof(DCELL));
     valmap = (DCELL *) G_malloc(nrows * ncols * sizeof(DCELL));
     propmap = (DCELL *) G_malloc(nrows * ncols * sizeof(DCELL));
-    result = G_allocate_c_raster_buf();
-    d_res = G_allocate_d_raster_buf();
+    result = Rast_allocate_c_buf();
 
     G_message("Loading Input files ... ");
 
     /* open input file */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read patch map */
     for (row = 0; row < nrows; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval) {
 		flagbuf[row * ncols + col] = 1;
@@ -295,46 +294,46 @@
     }
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* open costmap file */
-    in_fd = G_open_cell_old(costname, oldmapset);
+    in_fd = Rast_open_old(costname, oldmapset);
     if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), costname);
 
-    /* read patch map */
+    /* read cost map */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, &map[row * ncols], row);
+	Rast_get_d_row(in_fd, &map[row * ncols], row);
 
 	for (col = 0; col < ncols; col++) {
-	    if (G_is_d_null_value(&map[row * ncols + col])) {
+	    if (Rast_is_d_null_value(&map[row * ncols + col])) {
 		map[row * ncols + col] = 0.0;
 	    }
 	}
     }
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* open propmap file */
     if (propname) {
-	in_fd = G_open_cell_old(propname, propmapset);
+	in_fd = Rast_open_old(propname, propmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), propname);
 
 	/* read propagation map */
 	for (row = 0; row < nrows; row++) {
-	    G_get_d_raster_row(in_fd, &propmap[row * ncols], row);
+	    Rast_get_d_row(in_fd, &propmap[row * ncols], row);
 
 	    for (col = 0; col < ncols; col++) {
-		if (G_is_d_null_value(&propmap[row * ncols + col])) {
+		if (Rast_is_d_null_value(&propmap[row * ncols + col])) {
 		    propmap[row * ncols + col] = 0.0;
 		}
 	    }
 	}
 
 	/* close cell file */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	for (row = 0; row < nrows; row++) {
@@ -353,7 +352,7 @@
        } */
 
     /* find fragments */
-    writeFragments(flagbuf, nrows, ncols, nbr_count);
+    fragcount = writeFragments(flagbuf, nrows, ncols, nbr_count);
 
     /* create a patch map */
     for (i = 0; i < fragcount; i++) {
@@ -368,21 +367,18 @@
     }
 
     /* allocate memory for border arrays */
-    int cell_cnt = fragments[fragcount] - fragments[0];
-
     patch_borders =
 	(PatchBorderList *) G_malloc((fragcount + 1) *
 				     sizeof(PatchBorderList));
 
     /* find borders */
     G_message("Identifying borders...");
-    find_borders(flagbuf);
+    find_borders(flagbuf, nrows, ncols, fragcount);
 
     /* flagbuf is not needed any more */
     G_free(flagbuf);
 
     /* test output */
-    int patch;
 
     /*G_message("Borders:");
        for(patch = 0; patch < fragcount; patch++) {
@@ -419,9 +415,10 @@
     }
 
     /* initialize border values for propagation */
-    init_border_values(distance, angle, buffer, method, dist_weight);
+    init_border_values(distance, angle, buffer, method, dist_weight,
+                       nrows, ncols, fragcount);
 
-    propagate(nbr_count, prop_method);
+    propagate(nbr_count, prop_method, nrows, ncols, fragcount);
 
     /*G_message("costmap");
        for(row = 0; row < nrows; row++) {
@@ -449,13 +446,13 @@
 
     /* write output */
     /* open the new cellfile  */
-	out_fd = G_open_raster_new(newname, CELL_TYPE);
+	out_fd = Rast_open_new(newname, CELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* write the output file */
     for (row = 0; row < nrows; row++) {
-	G_set_c_null_value(result, ncols);
+	Rast_set_c_null_value(result, ncols);
 
 	for (i = 0; i < fragcount; i++) {
 	    Coords *p;
@@ -469,30 +466,30 @@
 	    }
 	}
 
-	G_put_c_raster_row(out_fd, result);
+	Rast_put_c_row(out_fd, result);
 
 	G_percent(row + 1, 2 * nrows, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* write map */
     /* open the new cellfile  */
     sprintf(fullname, "%s_%s", newname, "map");
-    out_fd = G_open_raster_new(fullname, DCELL_TYPE);
+    out_fd = Rast_open_new(fullname, DCELL_TYPE);
     if (out_fd < 0)
         G_fatal_error(_("Cannot create raster map <%s>"), fullname);
 
     /* write the output file */
     for (row = 0; row < nrows; row++) {
-	G_put_d_raster_row(out_fd, &valmap[row * ncols]);
+	Rast_put_d_row(out_fd, &valmap[row * ncols]);
 
 	G_percent(nrows + row + 1, 2 * nrows, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* free all buffers */
     for (patch = 0; patch < fragcount; patch++) {

Copied: grass-addons/grass7/raster/r.pi/r.pi.corearea/r.pi.corearea.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.corearea/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/r.pi.corearea.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/r.pi.corearea.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,93 @@
+<h2>DESCRIPTION</h2>
+
+Edge effects and core area analysis of landcover fragments. This module can compute static edge effects (defined edge depth) and dynamic edge effects (based on surrounding landscape). The impact of the surrounding landscape can be accounted for and the resulting core area is provided.
+
+<h2>NOTES</h2>
+
+This module is generating core areas based on defined edge depths. The edge depths can be increased by the values of a <em>costmap</em> (e.g. urban areas could have a more severe impact than secondary forest on forest fragments). Moreover a friction map (<em> propmap</em> within the fragments can lower the impact of surrounding landcover types and hence an increased edge depth (e.g. a river or escarpment which might lower the edge effects). Moreover a <em> dist_weight</em> can be assigned in order to increase the weight of closer pixel values.
+
+<h3>Distance weight</h3>
+
+The assigned distance weight is computed as:<br>
+w(d) = 1 - (d / d_max)^(tan(dist_weight * 0.5 * pi))<br>
+
+where:<br>
+
+d = Distance of the respective cell
+d_max - the defined maximum distance
+dist_weight - the parameter how to weight the pixel values in the landscape depending on the distance <br>
+
+the <em>dist_weight</em> has a range between 0 and 1 and results in:<br>
+
+0 < dist_weight < 0.5: the weighting curve decreases at low distances to the fragment and lowers to a weight of 0 at d=d_max <br>
+
+dist_weight = 0.5: linear decrease of weight until weight of 0 at d = d_max <br>
+
+0.5 < dist_weight < 1: the weighting curve decreases slowly at low distances and approaches weight value of 0 at higher distances from the fragment, the weight value 0 is reached at d = d_max <br>
+
+dist_weight = 1: no distance weight applied, common static edge depth used
+
+
+
+<h3>propmap</h3>
+
+The <em>propmap</em> minimizes the effect of the edge depth and the surrounding matrix. This has an ecological application if certain landscape features inside a e.g. forest fragment hamper the human impact (edge effects). <br>
+
+two method exist:<br>
+
+propmethod=linear: propagated value = actual value - (propmap value at this position)<br>
+propmethod=exponential: propagated value = actual value / (propmap value at this position) <br>
+
+If 0 is chosen using the linear method, then propagated value=actual value which results in a buffering of the whole region. In order to minimize the impact the value must be larger than 1. For the exponential method a value of below 1 should not be chosen, otherwise it will be propagated infinitely.
+
+
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset using class 5 (forest):
+
+For the computation of variable edge effects a costmap is necessary which need to be defined by the user. Higher costs are resulting in higher edge depths:
+<div class="code"><pre>
+# class - type - costs
+#   1	- developed - 3
+#   2	- agriculture - 2
+#   3	- herbaceous - 1
+#   4	- shrubland - 1
+#   5	- forest - 0
+#   6	- water - 0
+#   7	- sediment - 0
+
+r.mapcalc "costmap_for_corearea = if(landclass96==1,3,if(landclass96==2,2,if(landclass96==3,1,if(landclass96==4,1,if(landclass96==5,0,if(landclass96==6,0,if(landclass96==7,0)))))))"
+
+</pre></div>
+
+
+now the edge depth and the resulting core area can be computed:
+<div class="code"><pre>
+r.pi.corearea input=landclass96 costmap=costmap_for_corearea  output=landcover96_corearea keyval=5 buffer=5 distance=5 angle=90 stats=average propmethod=linear
+</pre></div>
+
+
+the results consist of 2 files:
+landclass96_corearea: the actual resulting core areas
+landclass96_corearea_map: a map showing the edge depths
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -2,8 +2,8 @@
 
 PGM = r.pi.corrwin
 
-LIBES = $(STATSLIB) $(GISLIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/bufs.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/bufs.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/bufs.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,4 +1,5 @@
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include "ncb.h"
 
 /*
@@ -12,18 +13,17 @@
 int allocate_bufs(void)
 {
     int i;
-
     int bufsize;
 
-    bufsize = (G_window_cols() + 2 * ncb.nsize) * sizeof(DCELL);
+    bufsize = (Rast_window_cols() + 2 * ncb.nsize) * sizeof(DCELL);
 
     ncb.buf1 = (DCELL **) G_malloc(ncb.nsize * sizeof(DCELL *));
     ncb.buf2 = (DCELL **) G_malloc(ncb.nsize * sizeof(DCELL *));
     for (i = 0; i < ncb.nsize; i++) {
 	ncb.buf1[i] = (DCELL *) G_malloc(bufsize);
 	ncb.buf2[i] = (DCELL *) G_malloc(bufsize);
-	G_set_d_null_value(ncb.buf1[i], G_window_cols() + 2 * ncb.nsize);
-	G_set_d_null_value(ncb.buf2[i], G_window_cols() + 2 * ncb.nsize);
+	Rast_set_d_null_value(ncb.buf1[i], Rast_window_cols() + 2 * ncb.nsize);
+	Rast_set_d_null_value(ncb.buf2[i], Rast_window_cols() + 2 * ncb.nsize);
     }
 
     return 0;
@@ -32,7 +32,6 @@
 int rotate_bufs(int bufnumber)
 {
     DCELL *temp;
-
     int i;
 
     if (bufnumber < 1 || bufnumber > 2)

Deleted: grass-addons/grass7/raster/r.pi/r.pi.corrwin/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,32 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-This module computes the correlation between two raster files but unlike
-<em>r.pi.lm</em> within a moving window of a specific size. This module is partly based on <em>r.neighbours</em> and <em>r.covar</em>.
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-Correlation of all pixels within a 7x7 sized window of two rasters (elevation and slope). The output is multiplied by 10000 for 
-<div class="code"><pre>
-r.pi.corrwin input1=slope input2=elevation output=corrwin1 size=7 max=10000
-r.colors corrwin1 col=bgyr
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/divr_cats.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/divr_cats.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/divr_cats.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,8 +1,10 @@
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include "ncb.h"
+
 int divr_cats(void)
 {
-    G_set_cats_fmt("$1 $?different categories$category$", 1.0, 0.0, 0.0, 0.0,
+    Rast_set_cats_fmt("$1 $?different categories$category$", 1.0, 0.0, 0.0, 0.0,
 		   &ncb.cats);
 
     return 0;

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/gather.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/gather.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/gather.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,4 +1,5 @@
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include "ncb.h"
 
 /*
@@ -9,13 +10,12 @@
 
 int gather(DCELL * values, int bufnumber, int offset)
 {
+    int row, col;
+    int n = 0;
+
     if (bufnumber < 1 || bufnumber > 2)
 	return -1;
 
-    int row, col;
-
-    int n = 0;
-
     *values = 0;
 
     for (row = 0; row < ncb.nsize; row++)
@@ -27,8 +27,8 @@
 	    else
 		c = &ncb.buf2[row][offset + col];
 
-	    if (G_is_d_null_value(c))
-		G_set_d_null_value(&values[n], 1);
+	    if (Rast_is_d_null_value(c))
+		Rast_set_d_null_value(&values[n], 1);
 	    else
 		values[n] = *c;
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/intr_cats.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/intr_cats.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/intr_cats.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,9 +1,10 @@
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include "ncb.h"
 
 int intr_cats(void)
 {
-    G_set_cats_fmt("$1% dispersion", 1.0, -1.0, 0.0, 0.0, &ncb.cats);
+    Rast_set_cats_fmt("$1% dispersion", 1.0, -1.0, 0.0, 0.0, &ncb.cats);
 
     return 0;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,6 +1,5 @@
 /* bufs.c */
 extern int allocate_bufs(void);
-
 extern int rotate_bufs(int);
 
 /* gather */

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.corrwin
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Moving window correlation analysis
  *               Put together from pieces of r.covar and r.neighbors
  *
@@ -19,6 +20,7 @@
 #include <unistd.h>
 #include <math.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "ncb.h"
@@ -32,17 +34,14 @@
 int main(int argc, char *argv[])
 {
     char *p, *p1, *p2;
-    int verbose;
-    /* in and out file pointers */
     int in_fd1, in_fd2;
     int out_fd;
     DCELL *result;
-    RASTER_MAP_TYPE map_type1, map_type2;
-    int row, col, i, j;
+    RASTER_MAP_TYPE map_type;
+    int row, col, i;
     int readrow;
     int maxval;
     int nrows, ncols;
-    int n;
     int copycolr;
     struct Colors colr;
     struct GModule *module;
@@ -52,16 +51,12 @@
 	struct Option *size, *max;
 	struct Option *title;
     } parm;
-    struct
-    {
-	struct Flag *quiet;
-    } flag;
     DCELL *values1, *values2;	/* list of neighborhood values */
 
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Moving window correlation analysis.");
 
     parm.input1 = G_define_standard_option(G_OPT_R_INPUT);
@@ -85,8 +80,9 @@
     parm.max->key = "max";
     parm.max->type = TYPE_INTEGER;
     parm.max->required = YES;
+    parm.max->description = _("Scaling factor for results");
     parm.max->description =
-	_("Value to be set for the correlation value 1.0 in order to receive more information of the decimal places, e.g. set it to 1000");
+	_("In order to receive more information of the decimal places, set it to e.g. 1000");
 
     parm.title = G_define_option();
     parm.title->key = "title";
@@ -95,10 +91,6 @@
     parm.title->required = NO;
     parm.title->description = _("Title for resultant raster map");
 
-    flag.quiet = G_define_flag();
-    flag.quiet->key = 'q';
-    flag.quiet->description = _("Run quietly");
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -106,40 +98,39 @@
     p1 = ncb.oldcell1.name = parm.input1->answer;
     p2 = ncb.oldcell2.name = parm.input2->answer;
     /* test input files existance */
-    ncb.oldcell1.mapset = G_find_cell2(p1, "");
+    ncb.oldcell1.mapset = G_find_raster2(p1, "");
     if (ncb.oldcell1.mapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), p1);
-    ncb.oldcell2.mapset = G_find_cell2(p2, "");
+    ncb.oldcell2.mapset = G_find_raster2(p2, "");
     if (ncb.oldcell2.mapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), p2);
 
     /* check if new file name is correct */
     p = ncb.newcell.name = parm.output->answer;
     if (G_legal_filename(p) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), p);
+	G_fatal_error(_("<%s> is an illegal file name"), p);
     ncb.newcell.mapset = G_mapset();
 
     /* get window size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
-    fprintf(stderr, "%d x %d ", nrows, ncols);
+    G_debug(1, "%d x %d ", nrows, ncols);
 
     /* open cell files */
-    in_fd1 = G_open_cell_old(ncb.oldcell1.name, ncb.oldcell1.mapset);
-	if (in_fd1 < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), ncb.oldcell1.name);
-    in_fd2 = G_open_cell_old(ncb.oldcell2.name, ncb.oldcell2.mapset);
-	if (in_fd2 < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), ncb.oldcell2.name);
+    in_fd1 = Rast_open_old(ncb.oldcell1.name, ncb.oldcell1.mapset);
+    if (in_fd1 < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), ncb.oldcell1.name);
+    in_fd2 = Rast_open_old(ncb.oldcell2.name, ncb.oldcell2.mapset);
+    if (in_fd2 < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), ncb.oldcell2.name);
 
-    /* get map types */
-    map_type1 = G_raster_map_type(ncb.oldcell1.name, ncb.oldcell1.mapset);
-    map_type2 = G_raster_map_type(ncb.oldcell2.name, ncb.oldcell2.mapset);
+    /* get map type */
+    map_type = Rast_map_type(ncb.oldcell1.name, ncb.oldcell1.mapset);
 
     /* copy color table? */
     copycolr =
-	(G_read_colors(ncb.oldcell1.name, ncb.oldcell1.mapset, &colr) > 0);
+	(Rast_read_colors(ncb.oldcell1.name, ncb.oldcell1.mapset, &colr) > 0);
 
     /* get the neighborhood size */
     sscanf(parm.size->answer, "%d", &ncb.nsize);
@@ -152,7 +143,7 @@
     allocate_bufs();
     values1 = (DCELL *) G_malloc(ncb.nsize * ncb.nsize * sizeof(DCELL));
     values2 = (DCELL *) G_malloc(ncb.nsize * ncb.nsize * sizeof(DCELL));
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* get title, initialize the category and stat info */
     if (parm.title->answer)
@@ -172,35 +163,30 @@
     }
 
     /* open the new cellfile */
-    out_fd = G_open_raster_new(ncb.newcell.name, map_type1);
+    out_fd = Rast_open_new(ncb.newcell.name, map_type);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), ncb.newcell.name);
+	G_fatal_error(_("Cannot create raster map <%s>"), ncb.newcell.name);
 
-    if ((verbose = !flag.quiet->answer))
-	fprintf(stderr, "Percent complete ... ");
+    G_message(_("Percent complete ... "));
 
     for (row = 0; row < nrows; row++) {
-	if (verbose)
-	    G_percent(row, nrows, 2);
+	G_percent(row, nrows, 2);
 	/* read the next row into buffer */
 	readcell(in_fd1, 1, readrow, nrows, ncols);
 	readcell(in_fd2, 2, readrow, nrows, ncols);
 	readrow++;
 	for (col = 0; col < ncols; col++) {
 	    DCELL sum1 = 0;
-
 	    DCELL sum2 = 0;
-
 	    DCELL mul, mul1, mul2;
-
-	    mul = mul1 = mul2 = 0;
 	    double count = 0;
-
 	    DCELL ii, jj;
 
 	    /* set pointer to actual position in the result */
 	    DCELL *rp = &result[col];
 
+	    mul = mul1 = mul2 = 0;
+
 	    /* gather values from actual window */
 	    gather(values1, 1, col);
 	    gather(values2, 2, col);
@@ -208,18 +194,18 @@
 	    for (i = 0; i < ncb.nsize * ncb.nsize; i++) {
 		/* ignore values if both are nan */
 		if (!
-		    (G_is_d_null_value(&values1[i]) &&
-		     G_is_d_null_value(&values2[i]))) {
-		    if (!G_is_d_null_value(&values1[i])) {
+		    (Rast_is_d_null_value(&values1[i]) &&
+		     Rast_is_d_null_value(&values2[i]))) {
+		    if (!Rast_is_d_null_value(&values1[i])) {
 			sum1 += values1[i];
 			mul1 += values1[i] * values1[i];
 		    }
-		    if (!G_is_d_null_value(&values2[i])) {
+		    if (!Rast_is_d_null_value(&values2[i])) {
 			sum2 += values2[i];
 			mul2 += values2[i] * values2[i];
 		    }
-		    if (!G_is_d_null_value(&values1[i]) &&
-			!G_is_d_null_value(&values2[i]))
+		    if (!Rast_is_d_null_value(&values1[i]) &&
+			!Rast_is_d_null_value(&values2[i]))
 			mul += values1[i] * values2[i];
 		    /* count the number of values actually processed */
 		    count++;
@@ -237,21 +223,20 @@
 	    *rp =
 		maxval * (mul -
 			  sum1 * sum2 / count) / (ii * jj * (count - 1.0));
-	    if (G_is_d_null_value(rp))
-		G_set_d_null_value(rp, 1);
+	    if (Rast_is_d_null_value(rp))
+		Rast_set_d_null_value(rp, 1);
 	}
 	/* write actual result row to the output file */
-	G_put_d_raster_row(out_fd, result);
+	Rast_put_d_row(out_fd, result);
     }
-    if (verbose)
-	G_percent(row, nrows, 2);
+    G_percent(row, nrows, 2);
 
-    G_close_cell(out_fd);
-    G_close_cell(in_fd1);
-    G_close_cell(in_fd2);
+    Rast_close(in_fd1);
+    Rast_close(in_fd2);
+    Rast_close(out_fd);
 
     if (copycolr)
-	G_write_colors(ncb.newcell.name, ncb.newcell.mapset, &colr);
+	Rast_write_colors(ncb.newcell.name, ncb.newcell.mapset, &colr);
 
     exit(EXIT_SUCCESS);
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/ncb.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/ncb.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/ncb.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -11,9 +11,8 @@
     struct
     {
 	char *name;
-	char *mapset;
-    }
-    oldcell1, oldcell2, newcell;
+	const char *mapset;
+    } oldcell1, oldcell2, newcell;
 };
 
 extern struct ncb ncb;

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/null_cats.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/null_cats.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/null_cats.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,12 +1,10 @@
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include "ncb.h"
 
 int null_cats(void)
 {
-    int ncats;
+    Rast_init_cats(ncb.title, &ncb.cats);
 
-    ncats = G_number_of_cats(ncb.newcell.name, ncb.newcell.mapset);
-    G_init_cats(ncats, ncb.title, &ncb.cats);
-
     return 0;
 }

Copied: grass-addons/grass7/raster/r.pi/r.pi.corrwin/r.pi.corrwin.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.corrwin/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/r.pi.corrwin.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/r.pi.corrwin.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,45 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.corrwin</em> provides information concerning the correlation
+of pixels inside a moving window between two raster files.
+<p>
+It calculates correlation of two raster maps by calculating correlation
+function of two corresponding rectangular areas for each raster point and
+writing the result into a new raster map.
+
+<h2>NOTES</h2>
+
+This module computes the correlation between two raster files but 
+unlike <em>r.pi.lm</em> for moving windows of a specific size. This 
+module is partly based on <em>r.neighbours</em> and <em>r.covar</em>.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+Correlation of all pixels within a 7x7 sized window of two rasters 
+(elevation and slope). The output is multiplied by 10000 for higher 
+precision
+<div class="code"><pre>
+g.region rast=elevation -p
+r.pi.corrwin input1=slope input2=elevation output=corrwin1 size=7 max=10000
+r.colors corrwin1 col=bgyr
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.corrwin/readcell.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corrwin/readcell.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.corrwin/readcell.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,5 +1,6 @@
 #include <unistd.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include "ncb.h"
 #include "local_proto.h"
 
@@ -15,13 +16,13 @@
 
     if (row < nrows)
 	if (bufnumber == 1)
-	    G_get_d_raster_row(fd, ncb.buf1[ncb.nsize - 1] + ncb.dist, row);
+	    Rast_get_d_row(fd, ncb.buf1[ncb.nsize - 1] + ncb.dist, row);
 	else
-	    G_get_d_raster_row(fd, ncb.buf2[ncb.nsize - 1] + ncb.dist, row);
+	    Rast_get_d_row(fd, ncb.buf2[ncb.nsize - 1] + ncb.dist, row);
     else if (bufnumber == 1)
-	G_set_d_null_value(ncb.buf1[ncb.nsize - 1] + ncb.dist, ncols);
+	Rast_set_d_null_value(ncb.buf1[ncb.nsize - 1] + ncb.dist, ncols);
     else
-	G_set_d_null_value(ncb.buf2[ncb.nsize - 1] + ncb.dist, ncols);
+	Rast_set_d_null_value(ncb.buf2[ncb.nsize - 1] + ncb.dist, ncols);
 
     return 0;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/analysis.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/analysis.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/analysis.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 int gather_positions(Position * res, int *map, int value, int x, int y,
 		     int sizex, int sizey)
 {
@@ -42,7 +37,6 @@
     /* choose n random positions */
     /* delete used positions, to prevent DCELL choice */
     for (i = 0; i < pos_count; i++) {
-	Position tmp;
 	int pos = Random(cur_size);
 
 	res[cur_pos].x = temp[pos].x;
@@ -85,7 +79,6 @@
 		    int n)
 {
     int i, j;
-    int min;
     int cur_size = count - 1;
     DCELL *temp = (DCELL *) G_malloc(count * sizeof(DCELL));
     int border = n < count ? n : count;
@@ -100,7 +93,6 @@
 	for (j = 0; j < cur_size; j++) {
 	    if (temp[j] < res[i]) {
 		res[i] = temp[j];
-		min = j;
 	    }
 	}
 
@@ -263,7 +255,7 @@
 		value = value / ref_value;
 	    }
 	    else {
-		G_set_d_null_value(&value, 1);
+		Rast_set_d_null_value(&value, 1);
 		progress += n;
 		G_percent(progress, n * nx * ny, 1);
 	    }

Deleted: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,55 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Complete Spatial Randomness (CSR) analysis based on a moving window.  This function uses either the Clark and Evans (1954) or Donnelly (1978) aggregation index for testing of clustering of point patterns.
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-Compute the CSR for the whole landscape of <em>landclass96</em> using class 5 (1000 iteration) using the Clark Evans method:<br>
-<div class="code"><pre>
-v.random output=randompoints n=100 zmin=0.0 zmax=0.0
-v.to.rast input=randompoints output=randompoints  use=val val=1
-r.pi.csr.mw input=randompoints keyval=1 n=1000 method=clark_evans output=csr1
-</pre></div>
-The results for the whole landscape is prompted to the console.
-
-Compute the CSR for a defined moving window size of <em>landclass96</em> using class 5 (1000 iteration, Clark Evans method):<br>
-<div class="code"><pre>
-r.pi.csr.mw input=randompoints keyval=5 n=1000 method=clark_evans size=7 output=csr1
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, double distance);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -81,13 +76,12 @@
 	/* get position from fifo-list */
 	int r = first->y;
 	int c = first->x;
-
-	first++;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, distance);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -120,17 +114,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, double distance)
+int writeFragments(int *flagbuf, int nrows, int ncols, double distance)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -144,5 +136,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -7,6 +7,7 @@
 #include <math.h>
 #include <time.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
@@ -17,6 +18,11 @@
 #define GLOBAL extern
 #endif
 
+typedef struct
+{
+    int x, y;
+} Position;
+
 typedef DCELL(f_statmethod) (DCELL *, int);
 typedef void (f_method) (DCELL * values, int *map, int *mask, int n,
 			  int size);
@@ -31,6 +37,5 @@
 /* global variables */
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.csr.mw
  * AUTHOR(S):    Elshad Shirinov, Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Analysis of CSR (complete spatial randomness) based on movinw window
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -31,34 +32,18 @@
     {0, 0, 0}
 };
 
-struct statmethod
-{
-    f_statmethod *method;	/* routine to compute new value */
-    char *name;			/* method name */
-    char *text;			/* menu display - full description */
-    char *suffix;		/* output suffix */
-};
-
-static struct statmethod statmethods[] = {
-    {average, "average", "average of values", "avg"},
-    {variance, "variance", "variance of values", "var"},
-    {std_deviat, "standard deviation", "standard deviation of values", "dev"},
-    {median, "median", "median of values", "med"},
-    {min, "min", "minimum of values", "min"},
-    {max, "max", "maximum of values", "max"},
-    {0, 0, 0, 0}
-};
-
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* output */
-    char *newname, *newmapset;
+    char *newname;
 
     /* mask */
-    char *maskname, *maskmapset;
+    char *maskname;
+    const char *maskmapset;
 
     /* in and out file pointers */
     int in_fd, out_fd;
@@ -67,30 +52,22 @@
     int keyval;
     int n;
     int size;
-    int method;
     f_method *method_func;
 
     /* maps */
     int *map;
     int *mask;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
     CELL *result;
     DCELL *d_res;
     DCELL *values;
-    int i, j;
-    Coords *p;
+    int i;
     char *str;
     int m;
     int nx, ny;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -102,7 +79,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Complete Spatial Randomness analysis on moving window.");
 
@@ -162,16 +139,17 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* get name of mask */
     maskname = parm.mask->answer;
+    maskmapset = NULL;
 
     /* test costmap existance */
-    if (maskname && (maskmapset = G_find_cell2(maskname, "")) == NULL)
-	        G_fatal_error(_("Raster map <%s> not found"), maskname);
+    if (maskname && (maskmapset = G_find_raster2(maskname, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), maskname);
 
     /* get keyval */
     sscanf(parm.keyval->answer, "%d", &keyval);
@@ -205,14 +183,11 @@
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
-    map_type = DCELL_TYPE;
-
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* test output */
     /*      G_message("TEST OUTPUT :");
@@ -229,22 +204,22 @@
     map = (int *)G_malloc(sx * sy * sizeof(int));
     mask = (int *) G_malloc(sx * sy * sizeof(int));
 
-    result = G_allocate_c_raster_buf();
-    d_res = G_allocate_d_raster_buf();
+    result = Rast_allocate_c_buf();
+    d_res = Rast_allocate_d_buf();
 
     nx = size > 0 ? sx - size + 1 : 1;
     ny = size > 0 ? sy - size + 1 : 1;
     values = (DCELL *) G_malloc(nx * ny * sizeof(Coords));
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
@@ -255,7 +230,7 @@
     G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* test output */
     /*      G_message("map:\n");
@@ -264,14 +239,14 @@
     /* if mask specified, read mask */
     if (maskname) {
 	/* open mask file */
-	in_fd = G_open_cell_old(maskname, maskmapset);
+	in_fd = Rast_open_old(maskname, maskmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), maskname);
 
 	/* read mask */
 	G_message("Reading mask file:");
 	for (row = 0; row < sy; row++) {
-	    G_get_c_raster_row(in_fd, result, row);
+	    Rast_get_c_row(in_fd, result, row);
 	    for (col = 0; col < sx; col++) {
 		mask[row * sx + col] = result[col];
 	    }
@@ -281,7 +256,7 @@
 	G_percent(1, 1, 2);
 
 	/* close mask */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no costmap specified, fill mask with 1 */
@@ -307,13 +282,13 @@
 	G_message("Writing output...");
 
 	/* open the new cellfile  */
-	out_fd = G_open_raster_new(newname, map_type);
+	out_fd = Rast_open_new(newname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    if (row >= size / 2 && row < ny + size / 2) {
 		for (col = 0; col < nx; col++) {
@@ -322,17 +297,16 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
-
+	Rast_close(out_fd);
     }
     else {
-	fprintf(stdout, "\n\noutput = %lf\n\n", values[0]);
+	fprintf(stdout, "\n\noutput = %f\n\n", values[0]);
     }
 
     /* free allocated resources */

Copied: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/r.pi.csr.mw.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.csr.mw/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/r.pi.csr.mw.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/r.pi.csr.mw.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,55 @@
+<h2>DESCRIPTION</h2>
+
+Complete Spatial Randomness (CSR) analysis based on a moving window.  This function uses either the Clark and Evans (1954) or Donnelly (1978) aggregation index for testing of clustering of point patterns.
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+Compute the CSR for the whole landscape of <em>landclass96</em> using class 5 (1000 iteration) using the Clark Evans method:<br>
+<div class="code"><pre>
+v.random output=randompoints n=100 zmin=0.0 zmax=0.0
+v.to.rast input=randompoints output=randompoints  use=val val=1
+r.pi.csr.mw input=randompoints keyval=1 n=1000 method=clark_evans output=csr1
+</pre></div>
+The results for the whole landscape is prompted to the console.
+
+Compute the CSR for a defined moving window size of <em>landclass96</em> using class 5 (1000 iteration, Clark Evans method):<br>
+<div class="code"><pre>
+r.pi.csr.mw input=randompoints keyval=5 n=1000 method=clark_evans size=7 output=csr1
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.energy/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,71 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Isolation or connectivity of singular patches of a defined landcover class using individual-based dispersal models. This function is based on a maximum amount of energy for each individuals dispersing through the landscape which is deminished by a fricition or cost map. Unlike the related function <em>r.pi.energy</em> does this function allows individuals to stay or move within a patch until the energy is depleted.
-
-<h2>NOTES</h2>
-
-Amount of successful immigrants or emigrants are not taken individual into account which emigrated from and immigrated into the same patch (pseudo immigration).
-
-The suitability matrix impacts the step direction, while the costmap relates to the depletion of assigned energy.
-
-If individuals are moving beyond the mapset borders the indivuals are set back to their original source patches.
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-The amount of successful emigrants (*_emi), immigrants (*_imi), the percentage of immigrants per patch (*_imi_percent), the amount of lost indivuals (*_lost), the amount of migrants (*_mig), successful (*_mig_succ) and unsuccessful migrants (_mig_unsucc) can be retrieved using this command:
-<div class="code"><pre>
-r.pi.energy input=landclass96 output=energy1 keyval=5 n=1000 step_length=5 energy=10 percent=80
-</pre></div>
-
-
-introducing costs for movement results in different immigration counts:
-<div class="code"><pre>
-r.mapcalc "cost_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
-r.pi.energy input=landclass96 output=energy1 keyval=5 n=1000 step_length=5 energy=10 percent=80 costmap=cost_raster
-</pre></div>
-
-introducing a suitability for the movement:
-<div class="code"><pre>
-# the suitability for the next step selection is defined as: class 5 and 3 (forest and grassland) have a high suitability, while shrubland (class 4) only a moderate and water and developed areas (class 6 and 1) have a very low suitability:
-r.mapcalc "suit_raster = if(landclass96==5,100,if(landclass96 == 3, 100, if (landclass96==1,1, if(landclass96==6,1,if(landclass96==4,50)))))"
-r.pi.energy input=landclass96 output=energyiter3 keyval=5 n=1000 step_length=5 energy=10 percent=80 suitability=suit_raster
-</pre></div>
-
-further settings can be changed and information retrieved:
-
-setting the perception range to 10 pixel:
-<div class="code"><pre>
-r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 perception=10
-</pre></div>
-
-increasing the attraction to move towards patches to 10:
-<div class="code"><pre>
-r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average multiplicator=10
-</pre></div>
-
-output of each movement location for a defined step frequency. Here every 10th step is provided as output raster:
-<div class="code"><pre>
-r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average out_freq=10
-</pre></div>
-
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.energy.iter.html">r.pi.energy.iter</a>,
-<a href="r.pi.energy.html">r.pi.energy</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -98,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,17 +130,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -164,5 +152,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -7,6 +7,7 @@
 #include <math.h>
 #include <time.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
@@ -20,6 +21,11 @@
 typedef struct
 {
     int x, y;
+} Position;
+
+typedef struct
+{
+    int x, y;
     double dir;
     DCELL energy;
     int finished;
@@ -43,15 +49,13 @@
 typedef DCELL(f_statmethod) (DCELL *, int);
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* search.c */
-void perform_search(int *map, DCELL * costmap, DCELL * suitmap);
+void perform_search(int *map, DCELL * costmap, int n, int fragcount, int sx, int sy);
 
 /* parameters */
-GLOBAL int sx, sy;
 GLOBAL int keyval;
-GLOBAL int n;
 GLOBAL double energy;
 GLOBAL double percent;
 GLOBAL int step_length;
@@ -64,19 +68,18 @@
 /* more global variables */
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 GLOBAL Individual *indi_array;
 GLOBAL int *immigrants;
 GLOBAL int *migrants;
 GLOBAL int *emigrants;
-GLOBAL int *patch_registry;	// ( patch1(indi1, indi2, ...), patch2(...), ... )
+GLOBAL int *patch_registry;	/* ( patch1(indi1, indi2, ...), patch2(...), ... ) */
 GLOBAL int *lost;
 GLOBAL int *migrants_succ;
 GLOBAL int *immi_matrix;
 GLOBAL int *mig_matrix;
 
-GLOBAL char *newname, *newmapset;
+GLOBAL char *newname;
 GLOBAL char outname[GNAME_MAX];
 
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.energy
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Individual-based dispersal model for connectivity analysis - energy-based
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -20,13 +21,16 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* costmap */
-    char *costname, *costmapset;
+    char *costname;
+    const char *costmapset;
 
     /* suitability map */
-    char *suitname, *suitmapset;
+    char *suitname;
+    const char *suitmapset;
 
     /* in and out file pointers */
     int in_fd, out_fd;
@@ -39,24 +43,20 @@
 
     /* other parameters */
     DCELL threshold;
-    char *title;
 
     /* helper variables */
     int row, col;
+    int sx, sy;
     CELL *result;
     DCELL *d_res;
     int neighb_count;
     int i, j;
     Coords *p;
-    char *str;
-    int method;
-    char outname[GNAME_MAX];
     int sum;
     int out_progress, out_max;
+    int fragcount;
+    int n;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -75,7 +75,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Individual-based dispersal model for connectivity analysis - energy based.");
 
@@ -86,17 +86,17 @@
     parm.costmap->type = TYPE_STRING;
     parm.costmap->required = NO;
     parm.costmap->gisprompt = "old,cell,raster";
-    parm.costmap->guisection = "Optional";
     parm.costmap->description = _("Name of the costmap");
+    parm.costmap->guisection = "Optional";
 
     parm.suitability = G_define_option();
     parm.suitability->key = "suitability";
     parm.suitability->type = TYPE_STRING;
     parm.suitability->required = NO;
     parm.suitability->gisprompt = "old,cell,raster";
-    parm.suitability->guisection = "Optional";
     parm.suitability->description =
 	_("Name of the suitability raster with values from 0-100");
+    parm.suitability->guisection = "Optional";
 
     parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
 
@@ -105,26 +105,26 @@
     parm.out_immi->type = TYPE_STRING;
     parm.out_immi->required = NO;
     parm.out_immi->gisprompt = "new,cell,raster";
-    parm.out_immi->guisection = "Optional";
     parm.out_immi->description =
 	_("Name of the optional raster file for patch immigrants count");
+    parm.out_immi->guisection = "Optional";
 
     parm.immi_matrix = G_define_option();
     parm.immi_matrix->key = "immi_matrix";
     parm.immi_matrix->type = TYPE_STRING;
     parm.immi_matrix->required = NO;
     parm.immi_matrix->gisprompt = "new_file,file,output";
-    parm.immi_matrix->guisection = "Optional";
     parm.immi_matrix->description =
 	_("Name for immigrants matrix ASCII-file");
+    parm.immi_matrix->guisection = "Optional";
 
     parm.mig_matrix = G_define_option();
     parm.mig_matrix->key = "mig_matrix";
     parm.mig_matrix->type = TYPE_STRING;
     parm.mig_matrix->required = NO;
     parm.mig_matrix->gisprompt = "new_file,file,output";
-    parm.mig_matrix->guisection = "Optional";
     parm.mig_matrix->description = _("Name for migrants matrix ASCII-file");
+    parm.mig_matrix->guisection = "Optional";
 
     parm.binary_matrix = G_define_option();
     parm.binary_matrix->key = "binary_matrix";
@@ -148,16 +148,16 @@
     parm.keyval->key = "keyval";
     parm.keyval->type = TYPE_INTEGER;
     parm.keyval->required = YES;
-    parm.keyval->guisection = "Required";
     parm.keyval->description = _("Category value of the patches");
+    parm.keyval->guisection = "Required";
 
     parm.step_length = G_define_option();
     parm.step_length->key = "step_length";
     parm.step_length->type = TYPE_INTEGER;
     parm.step_length->required = YES;
-    parm.step_length->guisection = "Required";
     parm.step_length->description =
 	_("Length of a single step measured in pixels");
+    parm.step_length->guisection = "Required";
 
     parm.step_range = G_define_option();
     parm.step_range->key = "step_range";
@@ -172,63 +172,61 @@
     parm.perception->key = "perception";
     parm.perception->type = TYPE_INTEGER;
     parm.perception->required = NO;
-    parm.perception->guisection = "Optional";
     parm.perception->description = _("Perception range");
+    parm.perception->guisection = "Optional";
 
     parm.multiplicator = G_define_option();
     parm.multiplicator->key = "multiplicator";
     parm.multiplicator->type = TYPE_DOUBLE;
     parm.multiplicator->required = NO;
-    parm.multiplicator->guisection = "Optional";
     parm.multiplicator->description = _("Attractivity of patches [1-inf]");
+    parm.multiplicator->guisection = "Optional";
 
     parm.n = G_define_option();
     parm.n->key = "n";
     parm.n->type = TYPE_INTEGER;
     parm.n->required = YES;
-    parm.n->guisection = "Required";
     parm.n->description = _("Number of individuals");
+    parm.n->guisection = "Required";
 
     parm.energy = G_define_option();
     parm.energy->key = "energy";
     parm.energy->type = TYPE_DOUBLE;
     parm.energy->required = YES;
-    parm.energy->guisection = "Required";
     parm.energy->description = _("Initial energy of the individuals");
+    parm.energy->guisection = "Required";
 
     parm.percent = G_define_option();
     parm.percent->key = "percent";
     parm.percent->type = TYPE_DOUBLE;
     parm.percent->required = YES;
-    parm.percent->guisection = "Required";
     parm.percent->description =
 	_("Percentage of finished individuals desired before simulation ends");
+    parm.percent->guisection = "Required";
 
     parm.out_freq = G_define_option();
     parm.out_freq->key = "out_freq";
     parm.out_freq->type = TYPE_INTEGER;
     parm.out_freq->required = NO;
-    parm.out_freq->guisection = "Optional";
     parm.out_freq->description =
 	_("Output an intermediate state of simulation each [out_freq] steps");
+    parm.out_freq->guisection = "Optional";
 
     parm.title = G_define_option();
     parm.title->key = "title";
     parm.title->key_desc = "\"phrase\"";
     parm.title->type = TYPE_STRING;
     parm.title->required = NO;
-    parm.title->guisection = "Optional";
     parm.title->description = _("Title for resultant raster map");
+    parm.title->guisection = "Optional";
 
     flag.adjacent = G_define_flag();
     flag.adjacent->key = 'a';
-    flag.adjacent->guisection = "Required";
     flag.adjacent->description =
 	_("Set for 8 cell-neighbors. 4 cell-neighbors are default");
 
     flag.setback = G_define_flag();
     flag.setback->key = 'b';
-    flag.setback->guisection = "Required";
     flag.setback->description =
 	_("Set if individuals should be set back after leaving area");
 
@@ -250,31 +248,25 @@
     oldname = parm.input->answer;
 
     /* test input file existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* get name of costmap */
     costname = parm.costmap->answer;
+    costmapset = NULL;
 
     /* test costmap existance */
-    if (costname && (costmapset = G_find_cell2(costname, "")) == NULL) {
-	G_warning(_("%s: <%s> raster file not found\n"), G_program_name(),
-		  costname);
-	G_usage();
-	exit(EXIT_FAILURE);
-    }
+    if (costname && (costmapset = G_find_raster2(costname, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), costname);
 
     /* get name of suitability map */
     suitname = parm.suitability->answer;
+    suitmapset = NULL;
 
     /* test costmap existance */
-    if (suitname && (suitmapset = G_find_cell2(suitname, "")) == NULL) {
-	G_warning(_("%s: <%s> raster file not found\n"), G_program_name(),
-		  suitname);
-	G_usage();
-	exit(EXIT_FAILURE);
-    }
+    if (suitname && (suitmapset = G_find_raster2(suitname, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), suitname);
 
     /* get keyval */
     sscanf(parm.keyval->answer, "%d", &keyval);
@@ -341,12 +333,11 @@
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* test output */
     /*fprintf(stderr, "TEST OUTPUT : \n");
@@ -364,33 +355,34 @@
 
     /* allocate map buffers */
     map = (int *)G_malloc(sx * sy * sizeof(int));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
     costmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
     suitmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
-    d_res = G_allocate_d_raster_buf();
+    d_res = Rast_allocate_d_buf();
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     fragments[0] = cells;
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
 	}
 
-	G_percent(row + 1, sy, 1);
+	G_percent(row, sy, 2);
     }
+    G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* test output */
     /*      G_message("map:\n");
@@ -399,26 +391,24 @@
     /* if costmap specified, read costmap */
     if (costname != NULL) {
 	/* open costmap */
-	if ((in_fd = G_open_cell_old(costname, costmapset)) < 0) {
-	    G_fatal_error(_("can't open cell file <%s> in mapset %s\n"),
-			  costname, costmapset);
-	    G_usage();
-	    exit(EXIT_FAILURE);
-	}
+	in_fd = Rast_open_old(costname, costmapset);
+	if (in_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), costname);
 
 	/* read costmap */
 	G_message("Reading costmap:");
 	for (row = 0; row < sy; row++) {
-	    G_get_d_raster_row(in_fd, d_res, row);
+	    Rast_get_d_row(in_fd, d_res, row);
 	    for (col = 0; col < sx; col++) {
 		costmap[row * sx + col] = d_res[col];
 	    }
 
-	    G_percent(row + 1, sy, 1);
+	    G_percent(row, sy, 2);
 	}
+	G_percent(1, 1, 2);
 
 	/* close costmap */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no costmap specified, fill costmap with 1 */
@@ -430,17 +420,13 @@
     /* if suitability map specified, read it */
     if (suitname != NULL) {
 	/* open suitability map */
-	if ((in_fd = G_open_cell_old(suitname, suitmapset)) < 0) {
-	    G_fatal_error(_("can't open cell file <%s> in mapset %s\n"),
-			  suitname, suitmapset);
-	    G_usage();
-	    exit(EXIT_FAILURE);
-	}
+	if ((in_fd = Rast_open_old(suitname, suitmapset)) < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), suitname);
 
 	/* read suitability map */
 	G_message("Reading suitability map file:\n");
 	for (row = 0; row < sy; row++) {
-	    G_get_d_raster_row(in_fd, d_res, row);
+	    Rast_get_d_row(in_fd, d_res, row);
 	    for (col = 0; col < sx; col++) {
 		suitmap[row * sx + col] = d_res[col];
 	    }
@@ -449,7 +435,7 @@
 	}
 
 	/* close suitability map */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no suitability map specified, fill it with 100 */
@@ -463,7 +449,7 @@
        print_d_buffer(costmap, sx, sy); */
 
     /* find fragments */
-    writeFragments(map, sy, sx, neighb_count);
+    fragcount = writeFragments(map, sy, sx, neighb_count);
 
     /* test output */
     /*      print_fragments(); */
@@ -496,7 +482,7 @@
     memset(lost, 0, fragcount * sizeof(int));
 
     /* perform search */
-    perform_search(map, costmap, suitmap);
+    perform_search(map, costmap, n, fragcount, sx, sy);
 
     /* test output */
     /*G_message("Results:");
@@ -519,16 +505,16 @@
 
     /* open the new cellfile  */
     sprintf(outname, "%s_imi", newname);
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
     /* write the output file */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -538,22 +524,22 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(++out_progress, out_max, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* write immigrants percentual */
 
     /* open the new cellfile  */
     sprintf(outname, "%s_imi_percent", newname);
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
@@ -565,7 +551,7 @@
 
     /* write the output file */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -577,28 +563,28 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(++out_progress, out_max, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* write migrants */
 
     /* open the new cellfile  */
     sprintf(outname, "%s_mig", newname);
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
     /* write the output file */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -608,28 +594,28 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(++out_progress, out_max, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* write successful migrants */
 
     /* open the new cellfile  */
     sprintf(outname, "%s_mig_succ", newname);
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
     /* write the output file */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -642,28 +628,28 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(++out_progress, out_max, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
-    /* write successful migrants */
+    /* write unsuccessful migrants */
 
     /* open the new cellfile  */
     sprintf(outname, "%s_mig_unsucc", newname);
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
     /* write the output file */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -677,28 +663,28 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(++out_progress, out_max, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* write emigrants */
 
     /* open the new cellfile  */
     sprintf(outname, "%s_emi", newname);
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
     /* write the output file */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -709,26 +695,26 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(++out_progress, out_max, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     if (!setback) {
 	/* write lost */
 
 	/* open the new cellfile  */
 	sprintf(outname, "%s_lost", newname);
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -739,13 +725,13 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(++out_progress, out_max, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* open ASCII-file or use stdout */
@@ -815,13 +801,14 @@
 	/* write data */
 	for (i = 0; i < fragcount; i++) {
 	    /* calculate sum of all imigrants from patch i */
-	    int sum = 0;
+	    int threshold_count;
 
+	    sum = 0;
 	    for (j = 0; j < fragcount; j++) {
 		sum += immi_matrix[j * fragcount + i];
 	    }
 
-	    int threshold_count = (int)(threshold * (double)sum) / 100;
+	    threshold_count = (int)(threshold * (double)sum) / 100;
 
 	    for (j = 0; j < fragcount; j++) {
 		if (immi_matrix[i * fragcount + j] > threshold_count) {
@@ -855,13 +842,14 @@
 	/* write data */
 	for (i = 0; i < fragcount; i++) {
 	    /* calculate sum of all imigrants from patch i */
-	    int sum = 0;
+	    int threshold_count;
 
+	    sum = 0;
 	    for (j = 0; j < fragcount; j++) {
 		sum += mig_matrix[j * fragcount + i];
 	    }
 
-	    int threshold_count = (int)(threshold * (double)sum) / 100;
+	    threshold_count = (int)(threshold * (double)sum) / 100;
 
 	    for (j = 0; j < fragcount; j++) {
 		if (mig_matrix[i * fragcount + j] > threshold_count) {
@@ -887,16 +875,18 @@
 
 	for (i = 0; i < fragcount; i++) {
 	    /* calculate sum of all imigrants in patch i */
-	    int sum = 0;
+	    int threshold_count;
+	    DCELL value;
 
+	    sum = 0;
 	    for (j = 0; j < fragcount; j++) {
 		sum += immi_matrix[j * fragcount + i];
 	    }
 
 	    /* calculate threshold count */
-	    int threshold_count = (int)(threshold * (double)sum) / 100;
+	    threshold_count = (int)(threshold * (double)sum) / 100;
 
-	    DCELL value = 0;
+	    value = 0;
 
 	    for (j = 0; j < fragcount; j++) {
 		if (immi_matrix[j * fragcount + i] > threshold_count) {
@@ -910,13 +900,13 @@
 	/* diversity */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s_immi", newname, "diversity");
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -926,24 +916,24 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
 	/* diversity percentual */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s_immi_percentual", newname, "diversity");
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -954,13 +944,13 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write antidiversity maps */
@@ -970,16 +960,18 @@
 
 	for (i = 0; i < fragcount; i++) {
 	    /* calculate sum of all imigrants from patch i */
-	    int sum = 0;
+	    int threshold_count;
+	    DCELL value;
 
+	    sum = 0;
 	    for (j = 0; j < fragcount; j++) {
 		sum += immi_matrix[i * fragcount + j];
 	    }
 
 	    /* calculate threshold count */
-	    int threshold_count = (int)(threshold * (double)sum) / 100;
+	    threshold_count = (int)(threshold * (double)sum) / 100;
 
-	    DCELL value = 0;
+	    value = 0;
 
 	    for (j = 0; j < fragcount; j++) {
 		if (immi_matrix[i * fragcount + j] > threshold_count) {
@@ -993,13 +985,13 @@
 	/* antidiversity */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, "antidiversity");
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -1009,24 +1001,24 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
 	/* antidiversity percentual */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, "antidiversity");
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -1037,39 +1029,41 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write diversity map for migrants */
     if (flag.diversity->answer) {
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s_mig", newname, "diversity");
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		/* calculate sum of all migrants from patch i */
-		int sum = 0;
+		int threshold_count;
+		DCELL value;
 
+		sum = 0;
 		for (j = 0; j < fragcount; j++) {
 		    sum += mig_matrix[j * fragcount + i];
 		}
 
 		/* calculate threshold count */
-		int threshold_count = (int)(threshold * (double)sum) / 100;
+		threshold_count = (int)(threshold * (double)sum) / 100;
 
-		DCELL value = 0;
+		value = 0;
 
 		for (j = 0; j < fragcount; j++) {
 		    if (mig_matrix[j * fragcount + i] > threshold_count) {
@@ -1084,21 +1078,23 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write indices for immigrants */
     if (flag.indices->answer) {
+	DCELL *values;
+
 	/* SHANNON */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, "shannon");
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
@@ -1112,27 +1108,27 @@
 	fprintf(stderr, "\n");
 
 	/* calculate indices */
-	DCELL *values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
+	values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
 
 	for (i = 0; i < fragcount; i++) {
 	    int N = 0;
-	    DCELL sum = 0.0;
+	    DCELL dsum = 0.0;
 
 	    for (j = 0; j < fragcount; j++) {
 		int immi = immi_matrix[i * fragcount + j];
 
 		if (immi > 0) {
 		    N += immi;
-		    sum += (DCELL) immi *log((DCELL) immi);
+		    dsum += (DCELL) immi *log((DCELL) immi);
 		}
 	    }
 
-	    values[i] = log((DCELL) N) - sum / (DCELL) N;
+	    values[i] = log((DCELL) N) - dsum / (DCELL) N;
 	}
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -1142,26 +1138,27 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
 	/* SIMPSON */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, "simpson");
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* calculate indices */
 	for (i = 0; i < fragcount; i++) {
 	    int N = 0;
-	    int sum = 0;
 
+	    sum = 0;
+
 	    for (j = 0; j < fragcount; j++) {
 		int immi = immi_matrix[j * fragcount + i];
 
@@ -1174,7 +1171,7 @@
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -1184,7 +1181,7 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
@@ -1192,7 +1189,7 @@
 	G_free(values);
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* free allocated resources */

Copied: grass-addons/grass7/raster/r.pi/r.pi.energy/r.pi.energy.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.energy/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/r.pi.energy.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/r.pi.energy.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,71 @@
+<h2>DESCRIPTION</h2>
+
+Isolation or connectivity of singular patches of a defined landcover class using individual-based dispersal models. This function is based on a maximum amount of energy for each individuals dispersing through the landscape which is deminished by a fricition or cost map. Unlike the related function <em>r.pi.energy</em> does this function allows individuals to stay or move within a patch until the energy is depleted.
+
+<h2>NOTES</h2>
+
+Amount of successful immigrants or emigrants are not taken individual into account which emigrated from and immigrated into the same patch (pseudo immigration).
+
+The suitability matrix impacts the step direction, while the costmap relates to the depletion of assigned energy.
+
+If individuals are moving beyond the mapset borders the indivuals are set back to their original source patches.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+The amount of successful emigrants (*_emi), immigrants (*_imi), the percentage of immigrants per patch (*_imi_percent), the amount of lost indivuals (*_lost), the amount of migrants (*_mig), successful (*_mig_succ) and unsuccessful migrants (_mig_unsucc) can be retrieved using this command:
+<div class="code"><pre>
+r.pi.energy input=landclass96 output=energy1 keyval=5 n=1000 step_length=5 energy=10 percent=80
+</pre></div>
+
+
+introducing costs for movement results in different immigration counts:
+<div class="code"><pre>
+r.mapcalc "cost_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
+r.pi.energy input=landclass96 output=energy1 keyval=5 n=1000 step_length=5 energy=10 percent=80 costmap=cost_raster
+</pre></div>
+
+introducing a suitability for the movement:
+<div class="code"><pre>
+# the suitability for the next step selection is defined as: class 5 and 3 (forest and grassland) have a high suitability, while shrubland (class 4) only a moderate and water and developed areas (class 6 and 1) have a very low suitability:
+r.mapcalc "suit_raster = if(landclass96==5,100,if(landclass96 == 3, 100, if (landclass96==1,1, if(landclass96==6,1,if(landclass96==4,50)))))"
+r.pi.energy input=landclass96 output=energyiter3 keyval=5 n=1000 step_length=5 energy=10 percent=80 suitability=suit_raster
+</pre></div>
+
+further settings can be changed and information retrieved:
+
+setting the perception range to 10 pixel:
+<div class="code"><pre>
+r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 perception=10
+</pre></div>
+
+increasing the attraction to move towards patches to 10:
+<div class="code"><pre>
+r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average multiplicator=10
+</pre></div>
+
+output of each movement location for a defined step frequency. Here every 10th step is provided as output raster:
+<div class="code"><pre>
+r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average out_freq=10
+</pre></div>
+
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.energy.iter.html">r.pi.energy.iter</a>,
+<a href="r.pi.energy.html">r.pi.energy</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy/search.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/search.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/search.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -13,20 +13,19 @@
 /*
    output raster with current simulation state
  */
-void test_output(int *map, int patch, int step, int n)
+void test_output(int *map, int patch, int step, int n, int sx, int sy)
 {
     int out_fd;
-    int row, col, i;
-    char outname[GNAME_MAX];
+    int row, i;
     DCELL *outmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
 
     /* open the new cellfile  */
     sprintf(outname, "%s_patch%d_step%d", newname, patch, step);
 
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
@@ -43,7 +42,7 @@
 	x = indi->x;
 	y = indi->y;
 
-	//              fprintf(stderr, "indi%d: (%d, %d)\n", i, x, y);
+	/*              fprintf(stderr, "indi%d: (%d, %d)\n", i, x, y); */
 	if (!indi->lost) {
 	    outmap[x + y * sx]++;
 	}
@@ -64,11 +63,11 @@
 
     /* write output */
     for (row = 0; row < sy; row++) {
-	G_put_d_raster_row(out_fd, outmap + row * sx);
+	Rast_put_d_row(out_fd, outmap + row * sx);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
     G_free(outmap);
 }
 
@@ -108,7 +107,7 @@
 /*
    picks a random direction pointing outwards a patch
  */
-double pick_dir(int *map, Coords * frag)
+double pick_dir(int *map, Coords * frag, int sx, int sy)
 {
     double dirs[4];
     int i;
@@ -136,18 +135,18 @@
 	    if (res < 0) {
 		res++;
 	    }
-	    //                      res = res < 0 ? 2 * M_PI + res : res;
+	    /* res = res < 0 ? 2 * M_PI + res : res; */
 	    return res;
 	}
     }
 
-    return -1;			// error
+    return -1;			/* error */
 }
 
 /*
    initializes all individuals for a fragment
  */
-void init_individuals(int *map, int frag, int size, int n)
+void init_individuals(int *map, int frag, int size, int n, int sx, int sy)
 {
     int i, border_count, index;
     Coords *cell;
@@ -155,10 +154,10 @@
 
     border_count = sort_frag(fragment, size);
 
-    //      G_message("Initializing");
+    /* G_message("Initializing individuals"); */
 
     for (i = 0; i < n; i++) {
-	//              G_message("border_count = %d", border_count);
+	/* G_message("border_count = %d", border_count); */
 
 	/* pick border cell */
 	index = Random(border_count);
@@ -166,24 +165,26 @@
 
 	indi_array[i].x = cell->x + 0.5;
 	indi_array[i].y = cell->y + 0.5;
-	indi_array[i].dir = pick_dir(map, cell);	//2 * M_PI * Randomf();
+	indi_array[i].dir = pick_dir(map, cell, sx, sy);	/* 2 * M_PI * Randomf(); */
 	indi_array[i].energy = energy;
 	indi_array[i].finished = 0;
 	indi_array[i].immigrated = 0;
 	indi_array[i].last_cat = frag;
 	indi_array[i].lost = 0;
 
-	//              fprintf(stderr, "indi%d: ", i);
-	//              fprintf(stderr, "x=%0.2f, y=%0.2f, dir=%0.2f, finished=%d\n",
-	//                              indi_array[i].x, indi_array[i].y, indi_array[i].dir, indi_array[i].finished);
+	/*
+	              fprintf(stderr, "indi%d: ", i);
+	              fprintf(stderr, "x=%0.2f, y=%0.2f, dir=%0.2f, finished=%d\n",
+	                              indi_array[i].x, indi_array[i].y, indi_array[i].dir, indi_array[i].finished);
+	*/
     }
-    //      G_message("End initialization");
+    /* G_message("End initialization"); */
 }
 
 /*
    sets back an individual, when position is illegal
  */
-void set_back(int *map, int indi, int frag)
+void set_back(int *map, int indi, int frag, int sx, int sy)
 {
     int index;
     Coords *cell;
@@ -196,7 +197,7 @@
 
     indi_array[indi].x = cell->x;
     indi_array[indi].y = cell->y;
-    indi_array[indi].dir = pick_dir(map, cell);
+    indi_array[indi].dir = pick_dir(map, cell, sx, sy);
     indi_array[indi].finished = 0;
     indi_array[indi].last_cat = frag;
 }
@@ -279,7 +280,7 @@
    fills a weighted array with possible next positions
  */
 void pick_nextpos(WeightedCoords * result, int indi, int *map,
-		  DCELL * suitmap, int frag)
+		  DCELL * suitmap, int frag, int sx, int sy)
 {
     int i;
     double ex_step, ex_pos;
@@ -344,7 +345,7 @@
 /*
    performs a single step for an individual
  */
-void indi_step(int indi, int frag, int *map, DCELL * costmap, double step)
+void indi_step(int indi, int frag, int *map, DCELL * costmap, int n, int fragcount, int sx, int sy)
 {
     int i;
     double sum;
@@ -362,7 +363,7 @@
     /* if new position is out of limits, then set back */
     if (newx < 0 || newx >= sx || newy < 0 || newy >= sy) {
 	if (setback) {
-	    set_back(map, indi, frag);
+	    set_back(map, indi, frag, sx, sy);
 	}
 	else {
 	    /* individual is lost */
@@ -403,8 +404,8 @@
 
 	/* if emigrating from a patch */
 	if (last_cell > -1 && last_cell != frag) {
-	    patch_registry[last_cell * n + indi] = 2;	// now migrant
-	    //immigrants[last_cell]--;
+	    patch_registry[last_cell * n + indi] = 2;	/* now migrant */
+	    /* immigrants[last_cell]--; */
 	    migrants[last_cell]++;
 	    mig_matrix[frag * fragcount + last_cell]++;
 	}
@@ -422,10 +423,11 @@
 	}
     }
 
+    /* remember last category */
     individual->last_cat = act_cell;
 
     /* write an array with possible next positions */
-    pick_nextpos(pos_arr, indi, map, costmap, frag);
+    pick_nextpos(pos_arr, indi, map, costmap, frag, sx, sy);
 
     /* if no next position is possible, then set back */
     sum = 0;
@@ -434,7 +436,7 @@
     }
     if (sum == 0) {
 	if (setback) {
-	    set_back(map, indi, frag);
+	    set_back(map, indi, frag, sx, sy);
 	}
 	else {
 	    /* individual is lost */
@@ -456,7 +458,6 @@
 	if (pos_arr[i].weight > rnd)
 	    break;
     }
-
     individual->dir = pos_arr[i].dir;
 
     return;
@@ -465,18 +466,17 @@
 /*
    performs a search run for a single fragment
  */
-DCELL frag_run(int *map, DCELL * costmap, int frag)
+DCELL frag_run(int *map, DCELL * costmap, int frag, int n, int fragcount, int sx, int sy)
 {
     int i, j;
-    DCELL res = 0;
     int step_cnt = 0;
     int finished_cnt = 0;
     int limit = 0.01 * percent * n;
 
-    //      fprintf(stderr, "\nstarting run:\n");
-    //      fprintf(stderr, "limit = %d\n", limit); 
+    /*      fprintf(stderr, "\nstarting run:\n"); */
+    /*      fprintf(stderr, "limit = %d\n", limit); */
 
-    init_individuals(map, frag, fragments[frag + 1] - fragments[frag], n);
+    init_individuals(map, frag, fragments[frag + 1] - fragments[frag], n, sx, sy);
 
     memset(patch_registry, 0, fragcount * n * sizeof(int));
 
@@ -484,14 +484,13 @@
     finished_cnt = 0;
     while (finished_cnt < limit) {
 	if (out_freq > 0 && (step_cnt % out_freq == 0)) {
-	    test_output(map, frag, step_cnt, n);
+	    test_output(map, frag, step_cnt, n, sx, sy);
 	}
 
 	for (i = 0; i < n; i++) {
 	    if (!indi_array[i].finished) {
+		indi_step(i, frag, map, costmap, n, fragcount, sx, sy);
 
-		indi_step(i, frag, map, costmap, step_length);
-
 		/* test if new individuum finished */
 		if (indi_array[i].finished) {
 		    indi_steps[i] = step_cnt;
@@ -521,20 +520,20 @@
     }
 
     if (out_freq > 0 && (step_cnt % out_freq == 0)) {
-	test_output(map, frag, step_cnt, n);
+	test_output(map, frag, step_cnt, n, sx, sy);
     }
 
-    //      fprintf(stderr, "stepcnt = %d\n", step_cnt);
+    /*      fprintf(stderr, "stepcnt = %d\n", step_cnt); */
+
     return (DCELL) step_cnt;
 }
 
 /*
    performs a search run for each fragment
  */
-void perform_search(int *map, DCELL * costmap, DCELL * suitmap)
+void perform_search(int *map, DCELL * costmap, int n, int fragcount, int sx, int sy)
 {
-    int fragment, i;
-    int steps;
+    int fragment;
     f_statmethod func;
 
     /* allocate paths array */
@@ -580,7 +579,7 @@
 
     /* perform a search run for each fragment */
     for (fragment = 0; fragment < fragcount; fragment++) {
-	frag_run(map, costmap, fragment);
+	frag_run(map, costmap, fragment, n, fragcount, sx, sy);
     }
 
     G_free(indi_steps);

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,67 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-This function is based on <em>r.pi.energy</em> but adds the functionality of iterative patch removal for testing of patch importance to maintain the landscape connectivity integrity. Isolation or connectivity of singular patches of a defined landcover class are analysed using individual-based dispersal models. This functions uses a maximum amount of energy for each individuals dispersing through the landscape which is deminished by a fricition or cost map. Unlike the related function <em>r.pi.energy</em> does this function allows individuals to stay or move within a patch until the energy is depleted.
-
-<h2>NOTES</h2>
-
-Amount of successful immigrants or emigrants are not taken individual into account which emigrated from and immigrated into the same patch (pseudo immigration).
-
-The suitability matrix impacts the step direction, while the costmap relates to the depletion of assigned energy.
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-The amount (average) and variance with or without the respective patch of successful emigrants (*_emi), immigrants (*_imi), the percentage of immigrants per patch (*_imi_percent), the amount of lost indivuals (*_lost), the amount of migrants (*_mig), successful (*_mig_succ) and unsuccessful migrants (_mig_unsucc) can be retrieved using this command:
-<div class="code"><pre>
-r.pi.energy.iter input=landclass96 output=energyiter1 keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average,variance
-</pre></div>
-
-introducing costs for movement results in different immigration counts:
-<div class="code"><pre>
-r.mapcalc "cost_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
-r.pi.energy.iter input=landclass96 output=energy1 keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average costmap=cost_raster
-</pre></div>
-
-introducing a suitability for the movement:
-<div class="code"><pre>
-# the suitability for the next step selection is defined as: class 5 and 3 (forest and grassland) have a high suitability, while shrubland (class 4) only a moderate and water and developed areas (class 6 and 1) have a very low suitability:
-r.mapcalc "suit_raster = if(landclass96==5,100,if(landclass96 == 3, 100, if (landclass96==1,1, if(landclass96==6,1,if(landclass96==4,50)))))"
-r.pi.energy.iter input=landclass96 output=energyiter3 keyval=5 n=1000 step_length=5 energy=10 percent=80 suitability=suit_raster stats=average,variance
-</pre></div>
-
-further settings can be changed and information retrieved:
-
-setting the perception range to 10 pixel:
-<div class="code"><pre>
-r.pi.energy.iter input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 perception=10 stats=average
-</pre></div>
-
-increasing the attraction to move towards patches to 10:
-<div class="code"><pre>
-r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average multiplicator=10
-</pre></div>
-
-output of each movement location for a defined step frequency. Here every 10th step is provided as output raster:
-<div class="code"><pre>
-r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average out_freq=10
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.energy.html">r.pi.energy</a>,
-<a href="r.pi.searchtime.html">r.pi.searchtime</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -98,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,17 +130,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -164,5 +152,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -20,6 +20,11 @@
 typedef struct
 {
     int x, y;
+} Position;
+
+typedef struct
+{
+    int x, y;
     double dir;
     DCELL energy;
     int finished;
@@ -43,17 +48,14 @@
 typedef DCELL(f_statmethod) (DCELL *, int);
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* search.c */
-void perform_search(int *map, DCELL * costmap, DCELL * suitmap,
-		    int remove_indi);
+void perform_search(int *map, DCELL * costmap, int remove_indi, int n, int fragcount, int sx, int sy);
 
 
 /* parameters */
-GLOBAL int sx, sy;
 GLOBAL int keyval;
-GLOBAL int n;
 GLOBAL double energy;
 GLOBAL double percent;
 GLOBAL int step_length;
@@ -65,18 +67,17 @@
 /* more global variables */
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 GLOBAL Individual *indi_array;
 GLOBAL int *immigrants;
 GLOBAL int *migrants;
 GLOBAL int *emigrants;
-GLOBAL int *patch_registry;	// ( patch1(indi1, indi2, ...), patch2(...), ... )
+GLOBAL int *patch_registry;	/* ( patch1(indi1, indi2, ...), patch2(...), ... ) */
 GLOBAL int *lost;
 GLOBAL int *migrants_succ;
 GLOBAL char *deleted_arr;
 
-GLOBAL char *newname, *newmapset;
+GLOBAL char *newname;
 GLOBAL char outname[GNAME_MAX];
 
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,8 +3,9 @@
  *
  * MODULE:       r.pi.energy.iter
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
- * PURPOSE:      Individual-based dispersal model for connectivity analysis 
- *                              - energy-based - iterative removal of paches for patch relevance analysis
+ *               Markus Metz (update to GRASS 7)
+ * PURPOSE:      Individual-based dispersal model for connectivity analysis - energy-based
+ *                - iterative removal of patches for patch relevance analysis
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
  *
@@ -39,13 +40,16 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* costmap */
-    char *costname, *costmapset;
+    char *costname;
+    const char *costmapset;
 
     /* suitability map */
-    char *suitname, *suitmapset;
+    char *suitname;
+    const char *suitmapset;
 
     /* in and out file pointers */
     int in_fd, out_fd;
@@ -62,22 +66,20 @@
     int remove_indi;
     int seed;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
+    int sx, sy;
     CELL *result;
     DCELL *d_res;
     int neighb_count;
-    int i, j;
+    int i;
     Coords *p;
     char *str;
     int method;
-    char outname[GNAME_MAX];
-    int sum;
     int out_progress, out_max;
     int frag;
+    int fragcount;
+    int n;
 
     int *dif_immi;
     int *dif_mig;
@@ -94,9 +96,6 @@
     DCELL *dummy;
     DCELL *ref;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -114,7 +113,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Individual-based dispersal model for connectivity analysis (energy based) using iterative patch removal.");
 
@@ -271,22 +270,24 @@
     oldname = parm.input->answer;
 
     /* test input file existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* get name of costmap */
     costname = parm.costmap->answer;
+    costmapset = NULL;
 
     /* test costmap existance */
-    if (costname && (costmapset = G_find_cell2(costname, "")) == NULL)
+    if (costname && (costmapset = G_find_raster2(costname, "")) == NULL)
 	G_fatal_error(_("Raster map <%s> not found"), costname);
 
     /* get name of suitability map */
     suitname = parm.suitability->answer;
+    suitmapset = NULL;
 
-    /* test costmap existance */
-    if (suitname && (suitmapset = G_find_cell2(suitname, "")) == NULL)
+    /* test suitmap existance */
+    if (suitname && (suitmapset = G_find_raster2(suitname, "")) == NULL)
         G_fatal_error(_("Raster map <%s> not found"), suitname);
 
     /* get keyval */
@@ -360,12 +361,11 @@
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* test output */
     /*fprintf(stderr, "TEST OUTPUT : \n");
@@ -384,33 +384,34 @@
 
     /* allocate map buffers */
     map = (int *)G_malloc(sx * sy * sizeof(int));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
     costmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
     suitmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
-    d_res = G_allocate_d_raster_buf();
+    d_res = Rast_allocate_d_buf();
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     fragments[0] = cells;
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
 	}
 
-	G_percent(row + 1, sy, 1);
+	G_percent(row, sy, 2);
     }
+    G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* test output */
     /*      G_message("map:\n");
@@ -419,23 +420,24 @@
     /* if costmap specified, read costmap */
     if (costname != NULL) {
 	/* open costmap */
-	in_fd = G_open_cell_old(costname, costmapset);
+	in_fd = Rast_open_old(costname, costmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), costname);
 
 	/* read costmap */
 	G_message("Reading costmap:");
 	for (row = 0; row < sy; row++) {
-	    G_get_d_raster_row(in_fd, d_res, row);
+	    Rast_get_d_row(in_fd, d_res, row);
 	    for (col = 0; col < sx; col++) {
 		costmap[row * sx + col] = d_res[col];
 	    }
 
-	    G_percent(row + 1, sy, 1);
+	    G_percent(row, sy, 2);
 	}
+	G_percent(1, 1, 2);
 
 	/* close costmap */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no costmap specified, fill costmap with 1 */
@@ -447,13 +449,14 @@
     /* if suitability map specified, read it */
     if (suitname != NULL) {
 	/* open suitability map */
+	in_fd = Rast_open_old(suitname, suitmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), suitname);
 
 	/* read suitability map */
 	G_message("Reading suitability map file:");
 	for (row = 0; row < sy; row++) {
-	    G_get_d_raster_row(in_fd, d_res, row);
+	    Rast_get_d_row(in_fd, d_res, row);
 	    for (col = 0; col < sx; col++) {
 		suitmap[row * sx + col] = d_res[col];
 	    }
@@ -462,7 +465,7 @@
 	}
 
 	/* close suitability map */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no suitability map specified, fill it with 100 */
@@ -476,7 +479,7 @@
        print_d_buffer(costmap, sx, sy); */
 
     /* find fragments */
-    writeFragments(map, sy, sx, neighb_count);
+    fragcount = writeFragments(map, sy, sx, neighb_count);
 
     /* test output */
     /*      print_fragments(); */
@@ -513,7 +516,7 @@
     dif_lost = (int *)G_malloc((fragcount + 1) * fragcount * sizeof(int));
 
     /* perform first reference search run */
-    perform_search(map, costmap, suitmap, remove_indi);
+    perform_search(map, costmap, remove_indi, n, fragcount, sx, sy);
 
     /* test output */
     /* G_message("Reference run:");
@@ -534,7 +537,7 @@
     /* perform test runs */
     for (frag = 0; frag < fragcount; frag++) {
 	deleted_arr[frag] = 1;
-	perform_search(map, costmap, suitmap, remove_indi);
+	perform_search(map, costmap, remove_indi, n, fragcount, sx, sy);
 	deleted_arr[frag] = 0;
 
 	/* G_message("Frag %d deleted:", frag);
@@ -603,8 +606,9 @@
 	}
 	for (method = 0; method < stat_count; method++) {
 	    f_statmethod *func = statmethods[stats[method]].method;
-	    int index = method * fragcount + frag;
 
+	    index = method * fragcount + frag;
+
 	    out_immi[index] = func(dummy, fragcount - 1);
 	    out_mig[index] = func(dummy + fragcount - 1, fragcount - 1);
 	    out_mig_succ[index] =
@@ -656,13 +660,13 @@
 	/* open the new cellfile  */
 	sprintf(outname, "%s_imi_%s", newname,
 		statmethods[stats[method]].suffix);
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (frag = 0; frag < fragcount; frag++) {
 		for (p = fragments[frag]; p < fragments[frag + 1]; p++) {
@@ -672,13 +676,13 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(++out_progress, out_max, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write migrants */
@@ -687,13 +691,13 @@
 	/* open the new cellfile  */
 	sprintf(outname, "%s_mig_%s", newname,
 		statmethods[stats[method]].suffix);
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (frag = 0; frag < fragcount; frag++) {
 		for (p = fragments[frag]; p < fragments[frag + 1]; p++) {
@@ -703,13 +707,13 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(++out_progress, out_max, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write successful migrants */
@@ -718,13 +722,13 @@
 	/* open the new cellfile  */
 	sprintf(outname, "%s_mig_succ_%s", newname,
 		statmethods[stats[method]].suffix);
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (frag = 0; frag < fragcount; frag++) {
 		for (p = fragments[frag]; p < fragments[frag + 1]; p++) {
@@ -734,13 +738,13 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(++out_progress, out_max, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write emigrants */
@@ -749,13 +753,13 @@
 	/* open the new cellfile  */
 	sprintf(outname, "%s_emi_%s", newname,
 		statmethods[stats[method]].suffix);
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (frag = 0; frag < fragcount; frag++) {
 		for (p = fragments[frag]; p < fragments[frag + 1]; p++) {
@@ -765,13 +769,13 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(++out_progress, out_max, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     if (!setback) {
@@ -781,13 +785,13 @@
 	    /* open the new cellfile  */
 	    sprintf(outname, "%s_lost_%s", newname,
 		    statmethods[stats[method]].suffix);
-	    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	    out_fd = Rast_open_new(outname, DCELL_TYPE);
 	    if (out_fd < 0)
 		    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	    /* write the output file */
 	    for (row = 0; row < sy; row++) {
-		G_set_d_null_value(d_res, sx);
+		Rast_set_d_null_value(d_res, sx);
 
 		for (frag = 0; frag < fragcount; frag++) {
 		    for (p = fragments[frag]; p < fragments[frag + 1]; p++) {
@@ -797,13 +801,13 @@
 		    }
 		}
 
-		G_put_d_raster_row(out_fd, d_res);
+		Rast_put_d_row(out_fd, d_res);
 
 		G_percent(++out_progress, out_max, 1);
 	    }
 
 	    /* close output */
-	    G_close_cell(out_fd);
+	    Rast_close(out_fd);
 	}
     }
 

Copied: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/r.pi.energy.iter.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.energy.iter/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/r.pi.energy.iter.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/r.pi.energy.iter.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,67 @@
+<h2>DESCRIPTION</h2>
+
+This function is based on <em>r.pi.energy</em> but adds the functionality of iterative patch removal for testing of patch importance to maintain the landscape connectivity integrity. Isolation or connectivity of singular patches of a defined landcover class are analysed using individual-based dispersal models. This functions uses a maximum amount of energy for each individuals dispersing through the landscape which is deminished by a fricition or cost map. Unlike the related function <em>r.pi.energy</em> does this function allows individuals to stay or move within a patch until the energy is depleted.
+
+<h2>NOTES</h2>
+
+Amount of successful immigrants or emigrants are not taken individual into account which emigrated from and immigrated into the same patch (pseudo immigration).
+
+The suitability matrix impacts the step direction, while the costmap relates to the depletion of assigned energy.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+The amount (average) and variance with or without the respective patch of successful emigrants (*_emi), immigrants (*_imi), the percentage of immigrants per patch (*_imi_percent), the amount of lost indivuals (*_lost), the amount of migrants (*_mig), successful (*_mig_succ) and unsuccessful migrants (_mig_unsucc) can be retrieved using this command:
+<div class="code"><pre>
+r.pi.energy.iter input=landclass96 output=energyiter1 keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average,variance
+</pre></div>
+
+introducing costs for movement results in different immigration counts:
+<div class="code"><pre>
+r.mapcalc "cost_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
+r.pi.energy.iter input=landclass96 output=energy1 keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average costmap=cost_raster
+</pre></div>
+
+introducing a suitability for the movement:
+<div class="code"><pre>
+# the suitability for the next step selection is defined as: class 5 and 3 (forest and grassland) have a high suitability, while shrubland (class 4) only a moderate and water and developed areas (class 6 and 1) have a very low suitability:
+r.mapcalc "suit_raster = if(landclass96==5,100,if(landclass96 == 3, 100, if (landclass96==1,1, if(landclass96==6,1,if(landclass96==4,50)))))"
+r.pi.energy.iter input=landclass96 output=energyiter3 keyval=5 n=1000 step_length=5 energy=10 percent=80 suitability=suit_raster stats=average,variance
+</pre></div>
+
+further settings can be changed and information retrieved:
+
+setting the perception range to 10 pixel:
+<div class="code"><pre>
+r.pi.energy.iter input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 perception=10 stats=average
+</pre></div>
+
+increasing the attraction to move towards patches to 10:
+<div class="code"><pre>
+r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average multiplicator=10
+</pre></div>
+
+output of each movement location for a defined step frequency. Here every 10th step is provided as output raster:
+<div class="code"><pre>
+r.pi.energy input=landclass96 output=energyiter keyval=5 n=1000 step_length=5 energy=10 percent=80 stats=average out_freq=10
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.energy.html">r.pi.energy</a>,
+<a href="r.pi.searchtime.html">r.pi.searchtime</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/search.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/search.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/search.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -13,20 +13,19 @@
 /*
    output raster with current simulation state
  */
-void test_output(int *map, int patch, int step, int n)
+void test_output(int *map, int patch, int step, int n, int sx, int sy)
 {
     int out_fd;
-    int row, col, i;
-    char outname[GNAME_MAX];
+    int row, i;
     DCELL *outmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
 
     /* open the new cellfile  */
     sprintf(outname, "%s_patch%d_step%d", newname, patch, step);
 
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
@@ -43,7 +42,7 @@
 	x = indi->x;
 	y = indi->y;
 
-	//              fprintf(stderr, "indi%d: (%d, %d)\n", i, x, y);
+	/* fprintf(stderr, "indi%d: (%d, %d)\n", i, x, y); */
 	if (!indi->lost) {
 	    outmap[x + y * sx]++;
 	}
@@ -64,11 +63,11 @@
 
     /* write output */
     for (row = 0; row < sy; row++) {
-	G_put_d_raster_row(out_fd, outmap + row * sx);
+	Rast_put_d_row(out_fd, outmap + row * sx);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
     G_free(outmap);
 }
 
@@ -108,7 +107,7 @@
 /*
    picks a random direction pointing outwards a patch
  */
-double pick_dir(int *map, Coords * frag)
+double pick_dir(int *map, Coords * frag, int sx, int sy)
 {
     double dirs[4];
     int i;
@@ -136,18 +135,18 @@
 	    if (res < 0) {
 		res++;
 	    }
-	    //                      res = res < 0 ? 2 * M_PI + res : res;
+	    /* res = res < 0 ? 2 * M_PI + res : res; */
 	    return res;
 	}
     }
 
-    return -1;			// error
+    return -1;			/* error */
 }
 
 /*
    initializes all individuals for a fragment
  */
-void init_individuals(int *map, int frag, int size, int n)
+void init_individuals(int *map, int frag, int size, int n, int sx, int sy)
 {
     int i, border_count, index;
     Coords *cell;
@@ -155,10 +154,10 @@
 
     border_count = sort_frag(fragment, size);
 
-    //      G_message("Initializing");
+    /* G_message("Initializing individuals"); */
 
     for (i = 0; i < n; i++) {
-	//              G_message("border_count = %d", border_count);
+	/* G_message("border_count = %d", border_count); */
 
 	/* pick border cell */
 	index = Random(border_count);
@@ -166,24 +165,26 @@
 
 	indi_array[i].x = cell->x + 0.5;
 	indi_array[i].y = cell->y + 0.5;
-	indi_array[i].dir = pick_dir(map, cell);	//2 * M_PI * Randomf();
+	indi_array[i].dir = pick_dir(map, cell, sx, sy);	/* 2 * M_PI * Randomf(); */
 	indi_array[i].energy = energy;
 	indi_array[i].finished = 0;
 	indi_array[i].immigrated = 0;
 	indi_array[i].last_cat = frag;
 	indi_array[i].lost = 0;
 
-	//              fprintf(stderr, "indi%d: ", i);
-	//              fprintf(stderr, "x=%0.2f, y=%0.2f, dir=%0.2f, finished=%d\n",
-	//                              indi_array[i].x, indi_array[i].y, indi_array[i].dir, indi_array[i].finished);
+	/*
+	              fprintf(stderr, "indi%d: ", i);
+	              fprintf(stderr, "x=%0.2f, y=%0.2f, dir=%0.2f, finished=%d\n",
+	                              indi_array[i].x, indi_array[i].y, indi_array[i].dir, indi_array[i].finished);
+	*/
     }
-    //      G_message("End initialization");
+    /* G_message("End initialization"); */
 }
 
 /*
    sets back an individual, when position is illegal
  */
-void set_back(int *map, int indi, int frag)
+void set_back(int *map, int indi, int frag, int sx, int sy)
 {
     int index;
     Coords *cell;
@@ -196,7 +197,7 @@
 
     indi_array[indi].x = cell->x;
     indi_array[indi].y = cell->y;
-    indi_array[indi].dir = pick_dir(map, cell);
+    indi_array[indi].dir = pick_dir(map, cell, sx, sy);
     indi_array[indi].finished = 0;
     indi_array[indi].last_cat = frag;
 }
@@ -279,7 +280,7 @@
    fills a weighted array with possible next positions
  */
 void pick_nextpos(WeightedCoords * result, int indi, int *map,
-		  DCELL * suitmap, int frag)
+		  DCELL * suitmap, int frag, int sx, int sy)
 {
     int i;
     double ex_step, ex_pos;
@@ -345,7 +346,7 @@
 /*
    performs a single step for an individual
  */
-void indi_step(int indi, int frag, int *map, DCELL * costmap, double step)
+void indi_step(int indi, int frag, int *map, DCELL * costmap, int n, int sx, int sy)
 {
     int i;
     double sum;
@@ -363,7 +364,7 @@
     /* if new position is out of limits, then set back */
     if (newx < 0 || newx >= sx || newy < 0 || newy >= sy) {
 	if (setback) {
-	    set_back(map, indi, frag);
+	    set_back(map, indi, frag, sx, sy);
 	}
 	else {
 	    /* individual is lost */
@@ -408,8 +409,8 @@
 
 	/* if emigrating from a patch */
 	if (last_cell > -1) {
-	    patch_registry[last_cell * n + indi] = 2;	// now migrant
-	    //immigrants[last_cell]--;
+	    patch_registry[last_cell * n + indi] = 2;	/* now migrant */
+	    /* immigrants[last_cell]--; */
 	    migrants[last_cell]++;
 	}
 
@@ -429,7 +430,7 @@
     individual->last_cat = act_cell;
 
     /* write an array with possible next positions */
-    pick_nextpos(pos_arr, indi, map, costmap, frag);
+    pick_nextpos(pos_arr, indi, map, costmap, frag, sx, sy);
 
     /* if no next position is possible, then set back */
     sum = 0;
@@ -438,7 +439,7 @@
     }
     if (sum == 0) {
 	if (setback) {
-	    set_back(map, indi, frag);
+	    set_back(map, indi, frag, sx, sy);
 	}
 	else {
 	    /* individual is lost */
@@ -469,18 +470,17 @@
 /*
    performs a search run for a single fragment
  */
-DCELL frag_run(int *map, DCELL * costmap, int frag)
+DCELL frag_run(int *map, DCELL * costmap, int frag, int n, int fragcount, int sx, int sy)
 {
     int i, j;
-    DCELL res = 0;
     int step_cnt = 0;
     int finished_cnt = 0;
     int limit = 0.01 * percent * n;
 
-    //      fprintf(stderr, "\nstarting run:\n");
-    //      fprintf(stderr, "limit = %d\n", limit); 
+    /*      fprintf(stderr, "\nstarting run:\n"); */
+    /*      fprintf(stderr, "limit = %d\n", limit); */
 
-    init_individuals(map, frag, fragments[frag + 1] - fragments[frag], n);
+    init_individuals(map, frag, fragments[frag + 1] - fragments[frag], n, sx, sy);
 
     memset(patch_registry, 0, fragcount * n * sizeof(int));
 
@@ -488,14 +488,13 @@
     finished_cnt = 0;
     while (finished_cnt < limit) {
 	if (out_freq > 0 && (step_cnt % out_freq == 0)) {
-	    test_output(map, frag, step_cnt, n);
+	    test_output(map, frag, step_cnt, n, sx, sy);
 	}
 
 	for (i = 0; i < n; i++) {
 	    if (!indi_array[i].finished) {
+		indi_step(i, frag, map, costmap, n, sx, sy);
 
-		indi_step(i, frag, map, costmap, step_length);
-
 		/* test if new individuum finished */
 		if (indi_array[i].finished) {
 		    indi_steps[i] = step_cnt;
@@ -526,21 +525,20 @@
     }
 
     if (out_freq > 0 && (step_cnt % out_freq == 0)) {
-	test_output(map, frag, step_cnt, n);
+	test_output(map, frag, step_cnt, n, sx, sy);
     }
 
-    //      fprintf(stderr, "stepcnt = %d\n", step_cnt);
+    /*      fprintf(stderr, "stepcnt = %d\n", step_cnt); */
+
     return (DCELL) step_cnt;
 }
 
 /*
    performs a search run for each fragment
  */
-void perform_search(int *map, DCELL * costmap, DCELL * suitmap,
-		    int remove_indi)
+void perform_search(int *map, DCELL * costmap, int remove_indi, int n, int fragcount, int sx, int sy)
 {
-    int fragment, i;
-    int steps;
+    int fragment;
     f_statmethod func;
 
     /* allocate paths array */
@@ -588,7 +586,7 @@
     /* perform a search run for each fragment */
     for (fragment = 0; fragment < fragcount; fragment++) {
 	if (!(remove_indi && deleted_arr[fragment])) {
-	    frag_run(map, costmap, fragment);
+	    frag_run(map, costmap, n, fragment, fragcount, sx, sy);
 	}
     }
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.enn/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,133 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.pi.enn</em> computes the euclidean distance between patches (1-n NN).
-
-Analysis of n-th euclidean nearest neighbour distance. 
-
-<h2>NOTES</h2>
-
-The user must specify the names of the raster map layers to
-be used for <em>input</em> and <em>output</em>, the <em>keyval</em> the
-<em>method</em> (e.g. distance, area) and <em>statmethod</em> used (i.e.,
-average).
-<p>
-
-Within <em>r.pi.enn</em> the following setting have to be set:
-
-<h3>keyval setting:</h3>
-
-The <em>keyval</em> operator determines which category value is taken for the Patch Index analysis.
-
-<h3>Method setting:</h3>
-
-The <em>method</em> operators determine what measure is applied 
-on the nth NN.
-
-<p>
-<dt><b>Distance</b> 
-
-<dd>The <em>Average</em> computes the average distance of the n NN.
-
-
-<dt><b>Path distance</b> 
-
-<dd>The <em>path_distance</em> computes the actual distance to the n NN.
-
-
-<dt><b>Area</b> 
-
-<dd>The <em>area</em> computes the area of the n NN.
-
-<dt><b>Perimeter</b> 
-
-<dd>The <em>perimeter</em> computes the perimeter of the n NN.
-
-<dt><b>SHAPE Index</b> 
-
-<dd>The <em>shapeindex</em> computes the SHAPE Index of the n NN.
-
-
-<h3>Statmethod setting:</h3>
-
-The <em>statmethod</em> operators determine what statistic measure is applied 
-on the nth NN.
-
-<p>
-<dt><b>Average</b> 
-
-<dd>The <em>Average</em> computes the average distance of the n NN.
-
-
-<dt><b>Variance</b> 
-
-<dd>The <em>Variance</em> computes the variance of the distance of the n NN.
-
-
-<dt><b>Std. Dev.</b> 
-
-<dd>The <em>Std. Dev</em> computes the std. dev. of the distance of the n NN.
-
-
-
-<h3>Number:</h3>
-
-The <em>keyval</em> operator determines which or how many Nearest Neighbour are analysed.
-
-<em> 1,2,5 </em> will analyse the 1, 2 and 5th Nearest Neigbour.
-
-<em> 1-10 </em> will analyse the 1, 2, 3, ... 10th Nearest Neighbour.
-
-<em> 0 </em> will analyse all Nearest Neighbours.
-
-
-<h3>Distancematrix:</h3>
-
-The <em>dmout</em> operator is optional and determines if a distance matrix is written (first NN only).
-
-<em> 1,2,5 </em> will analyse the 1, 2 and 5th Nearest Neigbour.
-
-<em> 1-10 </em> will analyse the 1, 2, 3, ... 10th Nearest Neighbour.
-
-<em> 0 </em> will analyse all Nearest Neighbours.
-
-
-</dl>
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-r.pi.enn input=landclass96 output=dist1.c5 keyval=5 method=distance number=1 statmethod=average 
-# -> gives a map of patches (all of category of 5) with the average distance to their first NN
-
-r.pi.enn input=landclass96 output=dist10.c5 keyval=5 method=distance number=10 statmethod=average 
-# -> gives a map of patches (all of category of 5) with the average distance to their first-10th NN
-
-r.pi.enn input=landclass96 output=dist1.5.10,c5 keyval=5 method=distance number=1,5,10 statmethod=average 
-# -> gives a map of patches (all of category of 5) with the average distance to their first, first-to-fifth and first-to-10th NN
-
-r.pi.enn input=landclass96 output=dist10b.c5 keyval=5 method=path_distance number=10 statmethod=average 
-# -> gives a map of patches (all of category of 5) with the actual distance to the 10th NN
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.fragment.dist.html">r.fragment.dist</a>,
-<a href="r.pi.enn.html">r.pi.enn</a>,
-<a href="r.pi.enn.iter.html">r.pi.enn.iter</a>,
-<a href="r.fragment.neighbors.html">r.fragment.neighbors</a>,
-<a href="r.li.setup.html">r.li</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -98,16 +98,11 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt = getNeighbors(nbr_list, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -139,5 +134,6 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -25,13 +25,13 @@
     Coords *p1, *p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = frags[n2]; p2 < frags[n2 + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -129,7 +129,7 @@
 
 int get_nearest_indices(int count, int *num_array, int num_count)
 {
-    int i, j, tmp;
+    int i;
     int max = 0;
 
     /* get maximum number */
@@ -137,15 +137,14 @@
 
     patch_n = num_array[max] < count - 1 ? num_array[max] : count - 1;
 
-    //      fprintf(stderr, "\n%d nearest patches taken into account.\n\n", patch_n);
+    /* fprintf(stderr, "\n%d nearest patches taken into account.\n\n", patch_n); */
 
     nearest_indices = (int *)G_malloc(count * patch_n * sizeof(int));
 
     /* for all patches */
     for (i = 0; i < count; i++) {
 	/* display progress */
-	if (verbose)
-	    G_percent(i, count, 2);
+	G_percent(i, count, 2);
 
 	get_smallest_n_indices(nearest_indices + i * patch_n, distmatrix,
 			       patch_n, count, i);
@@ -182,6 +181,7 @@
     }
 
     G_free(distances);
+
     return 0;
 }
 
@@ -207,6 +207,7 @@
     }
 
     G_free(areas);
+
     return 0;
 }
 
@@ -240,6 +241,7 @@
     }
 
     G_free(perims);
+
     return 0;
 }
 
@@ -275,6 +277,7 @@
     }
 
     G_free(shapes);
+
     return 0;
 }
 
@@ -289,18 +292,19 @@
 
     /* for all patches */
     for (i = 0; i < count; i++) {
-	// clear flags array
-	memset(flags, 0, count * sizeof(int));
 	int act_patch = i;
 
+	/* clear flags array */
+	memset(flags, 0, count * sizeof(int));
+
 	for (j = 0; j < patch_n; j++) {
-	    // get nearest patch for the act_patch
-	    // ignore those already marked in flags
+	    /* get nearest patch for the act_patch */
+	    /* ignore those already marked in flags */
 	    k = 0;
 	    do {
 		index = nearest_indices[act_patch * patch_n + k++];
 	    } while (flags[index] == 1);
-	    // mark current patch
+	    /* mark current patch */
 	    flags[act_patch] = 1;
 
 	    distances[j] = distmatrix[act_patch * count + index];
@@ -318,5 +322,6 @@
     }
 
     G_free(distances);
+
     return 0;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -6,6 +6,7 @@
 #include <unistd.h>
 #include <math.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
@@ -45,7 +46,6 @@
 GLOBAL Coords **fragments;
 GLOBAL int *flagbuf;
 GLOBAL Coords *actpos;
-GLOBAL int verbose;
 GLOBAL DCELL *distmatrix;
 GLOBAL int *nearest_indices;
 GLOBAL int patch_n;

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.enn
  * AUTHOR(S):    Elshad Shirinov, Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Analysis of n-th euclidean nearest neighbour distance
  *                               and spatial attributes of nearest neighbour patches
  *
@@ -58,7 +59,8 @@
     int exitres = 0;
 
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset;
+    char *newname, *oldname;
+    const char *oldmapset;
     char fullname[GNAME_MAX];
     char title[1024];
 
@@ -67,8 +69,7 @@
     int out_fd;
     DCELL *result;
 
-    /* map_type and categories */
-    RASTER_MAP_TYPE map_type;
+    /* categories */
     struct Categories cats;
 
     int statmethod;
@@ -84,9 +85,7 @@
 
     int row, col, i, j, m;
     int method_count;
-    int readrow;
     int keyval;
-    DCELL range = MAX_DOUBLE;
 
     int n;
     int copycolr;
@@ -101,7 +100,7 @@
     } parm;
     struct
     {
-	struct Flag *adjacent, *quiet;
+	struct Flag *adjacent;
     } flag;
 
     DCELL *values;
@@ -110,12 +109,10 @@
     int parseres[1024];
     int number;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Analysis of n-th Euclidean Nearest Neighbor distance.");
 
@@ -197,10 +194,6 @@
     flag.adjacent->description =
 	_("Set for 8 cell-neighbors. 4 cell-neighbors are default");
 
-    flag.quiet = G_define_flag();
-    flag.quiet->key = 'q';
-    flag.quiet->description = _("Run quietly");
-
     if (G_parser(argc, argv))
 	    exit(EXIT_FAILURE);
 
@@ -208,30 +201,26 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
-    /* get map type */
-    map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
-
     /* copy color table */
-    copycolr = (G_read_colors(oldname, oldmapset, &colr) > 0);
+    copycolr = (Rast_read_colors(oldname, oldmapset, &colr) > 0);
 
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
@@ -284,7 +273,7 @@
     fragments = (Coords **) G_malloc(nrows * ncols * sizeof(Coords *));
     fragments[0] = cells;
     flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* get title, initialize the category and stat info */
     if (parm.title->answer)
@@ -292,21 +281,21 @@
     else
 	sprintf(title, "Fragmentation of file: %s", oldname);
 
-    if ((verbose = !flag.quiet->answer))
-	G_message("Loading patches...");
+    G_message("Loading patches...");
 
     /* find fragments */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, result, row);
+	Rast_get_d_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
 	}
 
-	if (verbose)
-	    G_percent(row, nrows, 2);
+	G_percent(row, nrows, 2);
     }
+    Rast_close(in_fd);
 
+    /* TODO: merge with previous loop */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
 	    if (flagbuf[row * ncols + col] == 1) {
@@ -316,8 +305,7 @@
 	    }
 	}
     }
-    if (verbose)
-	G_percent(nrows, nrows, 2);
+    G_percent(nrows, nrows, 2);
 
     /* generate the distance matrix */
     get_dist_matrix(fragcount);
@@ -337,30 +325,27 @@
 	compute_values = menu[methods[m]].method;
 
 	/* perform current function on the patches */
-	if ((verbose = !flag.quiet->answer))
-	    G_message("Performing operation %s ... ", menu[methods[m]].name);
+	G_message("Performing operation %s ... ", menu[methods[m]].name);
 	values = (DCELL *) G_malloc(fragcount * number * sizeof(DCELL));
 	compute_values(values, fragcount, parseres, number, compute_stat);
 
-	if (verbose)
-	    G_percent(fragcount, fragcount, 2);
+	G_percent(fragcount, fragcount, 2);
 
 	/* write output files */
-	if ((verbose = !flag.quiet->answer))
-	    G_message("Writing output...");
+	G_message("Writing output...");
 
 	/* for all requested patches */
 	for (j = 0; j < number; j++) {
 	    /* open the new cellfile */
 	    sprintf(fullname, "%s.NN%d.%s", newname, parseres[j],
 		    menu[methods[m]].name);
-	    out_fd = G_open_raster_new(fullname, DCELL_TYPE);
+	    out_fd = Rast_open_new(fullname, DCELL_TYPE);
 	    if (out_fd < 0)
 	        G_fatal_error(_("Cannot create raster map <%s>"), fullname);
 
 	    /* write data */
 	    for (row = 0; row < nrows; row++) {
-		G_set_d_null_value(result, ncols);
+		Rast_set_d_null_value(result, ncols);
 
 		for (i = 0; i < fragcount; i++) {
 		    for (actpos = fragments[i]; actpos < fragments[i + 1];
@@ -371,20 +356,18 @@
 		    }
 		}
 
-		G_put_d_raster_row(out_fd, result);
+		Rast_put_d_row(out_fd, result);
 
-		if (verbose)
-		    G_percent(row + nrows * j + nrows * number * m,
-			      nrows * number * method_count, 2);
+		G_percent(row + nrows * j + nrows * number * m,
+			  nrows * number * method_count, 2);
 	    }
 
-	    G_close_cell(out_fd);
+	    Rast_close(out_fd);
 	}
 
     }				/* for each method */
 
-    if (verbose)
-	G_percent(100, 100, 2);
+    G_percent(100, 100, 2);
 
     if (parm.dmout->answer) {
 	exitres =
@@ -397,8 +380,6 @@
 				 fragcount, parseres, number);
     }
 
-    G_close_cell(in_fd);
-
     G_free(cells);
     G_free(fragments);
     G_free(flagbuf);
@@ -407,11 +388,11 @@
     G_free(distmatrix);
     G_free(nearest_indices);
 
-    G_init_cats(0, title, &cats);
-    G_write_cats(newname, &cats);
+    Rast_init_cats(title, &cats);
+    Rast_write_cats(newname, &cats);
 
     if (copycolr)
-	G_write_colors(newname, newmapset, &colr);
+	Rast_write_colors(newname, G_mapset(), &colr);
 
     exit(exitres);
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/matrix.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/matrix.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/matrix.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -4,13 +4,13 @@
 {
     FILE *out_fp;
     int res = 0;
-    char *mapset;
+    const char *mapset;
     int out_fd;
     int row, col, i;
     DCELL *result;
 
     /* allocate memory for result-row */
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* open ASCII-file or use stdout */
     if (!(out_fp = fopen(name, "w"))) {
@@ -33,7 +33,7 @@
 	mapset = G_mapset();
 
 	/* open the new cellfile */
-	out_fd = G_open_raster_new(name, DCELL_TYPE);
+	out_fd = Rast_open_new(name, DCELL_TYPE);
 	if (out_fd < 0) {
 	    char msg[200];
 
@@ -45,7 +45,7 @@
 	else {
 	    /* write data */
 	    for (row = 0; row < nrows; row++) {
-		G_set_d_null_value(result, ncols);
+		Rast_set_d_null_value(result, ncols);
 
 		for (i = 0; i < count; i++) {
 		    for (actpos = frags[i]; actpos < frags[i + 1]; actpos++) {
@@ -55,10 +55,10 @@
 		    }
 		}
 
-		G_put_d_raster_row(out_fd, result);
+		Rast_put_d_row(out_fd, result);
 	    }
 	}
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* free memory */

Copied: grass-addons/grass7/raster/r.pi/r.pi.enn/r.pi.enn.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.enn/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/r.pi.enn.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/r.pi.enn.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,133 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.pi.enn</em> computes the euclidean distance between patches (1-n NN).
+
+Analysis of n-th euclidean nearest neighbour distance. 
+
+<h2>NOTES</h2>
+
+The user must specify the names of the raster map layers to
+be used for <em>input</em> and <em>output</em>, the <em>keyval</em> the
+<em>method</em> (e.g. distance, area) and <em>statmethod</em> used (i.e.,
+average).
+<p>
+
+Within <em>r.pi.enn</em> the following setting have to be set:
+
+<h3>keyval setting:</h3>
+
+The <em>keyval</em> operator determines which category value is taken for the Patch Index analysis.
+
+<h3>Method setting:</h3>
+
+The <em>method</em> operators determine what measure is applied 
+on the nth NN.
+
+<p>
+<dl>
+<dt><b>Distance</b> 
+
+<dd>The <em>Average</em> computes the average distance of the n NN.
+
+
+<dt><b>Path distance</b> 
+
+<dd>The <em>path_distance</em> computes the actual distance to the n NN.
+
+
+<dt><b>Area</b> 
+
+<dd>The <em>area</em> computes the area of the n NN.
+
+<dt><b>Perimeter</b> 
+
+<dd>The <em>perimeter</em> computes the perimeter of the n NN.
+
+<dt><b>SHAPE Index</b> 
+
+<dd>The <em>shapeindex</em> computes the SHAPE Index of the n NN.
+</dl>
+
+<h3>Statmethod setting:</h3>
+
+The <em>statmethod</em> operators determine what statistic measure is applied 
+on the nth NN.
+
+<p>
+<dl>
+<dt><b>Average</b> 
+
+<dd>The <em>Average</em> computes the average distance of the n NN.
+
+
+<dt><b>Variance</b> 
+
+<dd>The <em>Variance</em> computes the variance of the distance of the n NN.
+
+
+<dt><b>Std. Dev.</b> 
+
+<dd>The <em>Std. Dev</em> computes the std. dev. of the distance of the n NN.
+</dl>
+
+
+<h3>Number:</h3>
+
+The <em>keyval</em> operator determines which or how many Nearest Neighbour are analysed.
+
+<em> 1,2,5 </em> will analyse the 1, 2 and 5th Nearest Neigbour.
+
+<em> 1-10 </em> will analyse the 1, 2, 3, ... 10th Nearest Neighbour.
+
+<em> 0 </em> will analyse all Nearest Neighbours.
+
+
+<h3>Distancematrix:</h3>
+
+The <em>dmout</em> operator is optional and determines if a distance matrix is written (first NN only).
+
+<em> 1,2,5 </em> will analyse the 1, 2 and 5th Nearest Neigbour.
+
+<em> 1-10 </em> will analyse the 1, 2, 3, ... 10th Nearest Neighbour.
+
+<em> 0 </em> will analyse all Nearest Neighbours.
+
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+r.pi.enn input=landclass96 output=dist1.c5 keyval=5 method=distance number=1 statmethod=average 
+# -> gives a map of patches (all of category of 5) with the average distance to their first NN
+
+r.pi.enn input=landclass96 output=dist10.c5 keyval=5 method=distance number=10 statmethod=average 
+# -> gives a map of patches (all of category of 5) with the average distance to their first-10th NN
+
+r.pi.enn input=landclass96 output=dist1.5.10,c5 keyval=5 method=distance number=1,5,10 statmethod=average 
+# -> gives a map of patches (all of category of 5) with the average distance to their first, first-to-fifth and first-to-10th NN
+
+r.pi.enn input=landclass96 output=dist10b.c5 keyval=5 method=path_distance number=10 statmethod=average 
+# -> gives a map of patches (all of category of 5) with the actual distance to the 10th NN
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.fragment.dist.html">r.fragment.dist</a>,
+<a href="r.pi.enn.html">r.pi.enn</a>,
+<a href="r.pi.enn.iter.html">r.pi.enn.iter</a>,
+<a href="r.fragment.neighbors.html">r.fragment.neighbors</a>,
+<a href="r.li.setup.html">r.li</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,48 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Patch relevance for Euclidean Nearest Neighbor patches.
-
-<em>r.pi.enn.iter</em> computes distance and area
-differences for the first NN after removal of patch i.
-
-
-<h2>NOTES</h2>
-
-The <em>keyval</em> operator determines which category value is taken for
-the Patch Index analysis.
-
-The <em>method</em> operators determine what measure is applied 
-on the nth NN (area or distance).
-
-Differences of distance/area after removal of patch i are provided as output as well as 
-the amount of patches to be affected by its removal (percent) (PP) and
-the amount of area in these patches (PA - Percent Area)
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-Analysing the differences (average) in distance when patch i of class 5 is removed:
-<div class="code"><pre>
-r.pi.enn.iter input=landclass96 output=dist_iter keyval=5 method=distance statmethod=average 
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.enn.html">r.pi.enn</a>,
-<a href="r.pi.fnn.html">r.pi.fnn</a>,
-<a href="r.pi.searchtime.iter.html">r.pi.searchtime.iter</a>,
-
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -98,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -143,14 +133,12 @@
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
     fragments[0] = cells;
-    Coords *actpos = fragments[0];
 
     /* find fragments */
     for (row = 0; row < nrows; row++) {
@@ -165,5 +153,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -24,13 +24,13 @@
     Coords *p1, *p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = frags[n2]; p2 < frags[n2 + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -41,6 +41,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -154,6 +155,7 @@
     G_free(distmatrix);
     G_free(neighb_indices);
     G_free(differences);
+
     return;
 }
 
@@ -200,5 +202,6 @@
     G_free(distmatrix);
     G_free(neighb_indices);
     G_free(differences);
+
     return;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -7,6 +7,7 @@
 #include <math.h>
 #include <time.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
@@ -20,13 +21,18 @@
 typedef struct
 {
     int x, y;
+} Position;
+
+typedef struct
+{
+    int x, y;
 } Point;
 
 typedef DCELL(f_statmethod) (DCELL *, int);
 typedef void (f_func) (DCELL *, Coords **, int, f_statmethod);
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* func.c */
 void f_distance(DCELL * vals, Coords ** frags, int count,
@@ -35,9 +41,7 @@
 	    f_statmethod statmethod);
 
 /* global parameters */
-GLOBAL int verbose;
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.enn.iter
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Iterative removal of patches and analysis of patch relevance
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -46,7 +47,8 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset, *newname, *newmapset;
+    char *oldname, *newname;
+    const char *oldmapset;
     char outname[GNAME_MAX];
 
     /* in and out file pointers */
@@ -66,15 +68,15 @@
 
     /* helper variables */
     RASTER_MAP_TYPE map_type;
-    int i, j;
+    int i;
     int row, col;
     int nrows, ncols;
     int act_method;
     DCELL *result;
-    struct Cell_head ch, window;
     char *p;
 
     int *flagbuf;
+    int fragcount;
     DCELL *values;
     Coords *actpos;
 
@@ -87,13 +89,13 @@
     } parm;
     struct
     {
-	struct Flag *adjacent, *quiet;
+	struct Flag *adjacent;
     } flag;
 
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Patch relevance for Euclidean Nearest Neighbor patches.");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -149,18 +151,15 @@
     flag.adjacent->description =
 	_("Set for 8 cell-neighbors. 4 cell-neighbors are default");
 
-    flag.quiet = G_define_flag();
-    flag.quiet->key = 'q';
-    flag.quiet->description = _("Run quietly");
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
     /* get name of input file */
     oldname = parm.input->answer;
+    oldmapset = NULL;
 
     /* test input files existance */
-    if (oldname && NULL == (oldmapset = G_find_cell2(oldname, ""))) {
+    if (oldname && NULL == (oldmapset = G_find_raster2(oldname, ""))) {
 	G_warning(_("%s: <%s> raster file not found\n"),
 		  G_program_name(), oldname);
 	exit(EXIT_FAILURE);
@@ -169,17 +168,16 @@
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* get map type */
     map_type = DCELL_TYPE;
@@ -229,18 +227,19 @@
     cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
     fragments = (Coords **) G_malloc(nrows * ncols * sizeof(Coords *));
     flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* find fragments */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, result, row);
+	Rast_get_d_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
 	}
     }
+    Rast_close(in_fd);
 
-    writeFragments(flagbuf, nrows, ncols, neighb_count);
+    fragcount = writeFragments(flagbuf, nrows, ncols, neighb_count);
 
     /* perform actual function on the patches */
     values = (DCELL *) G_malloc(3 * fragcount * sizeof(DCELL));
@@ -249,13 +248,13 @@
     /* open new cellfile  */
     strcpy(outname, newname);
     strcat(outname, ".diff");
-    out_fd = G_open_raster_new(outname, map_type);
-	if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+    out_fd = Rast_open_new(outname, map_type);
+    if (out_fd < 0)
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* write the output file */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(result, ncols);
+	Rast_set_d_null_value(result, ncols);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (actpos = fragments[i]; actpos < fragments[i + 1]; actpos++) {
@@ -265,20 +264,20 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, result);
+	Rast_put_d_row(out_fd, result);
     }
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* open new cellfile  */
     strcpy(outname, newname);
     strcat(outname, ".PP");
-    out_fd = G_open_raster_new(outname, map_type);
-	if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+    out_fd = Rast_open_new(outname, map_type);
+    if (out_fd < 0)
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* write the output file */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(result, ncols);
+	Rast_set_d_null_value(result, ncols);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (actpos = fragments[i]; actpos < fragments[i + 1]; actpos++) {
@@ -288,20 +287,20 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, result);
+	Rast_put_d_row(out_fd, result);
     }
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* open new cellfile  */
     strcpy(outname, newname);
     strcat(outname, ".PA");
-    out_fd = G_open_raster_new(outname, map_type);
-	if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
+    out_fd = Rast_open_new(outname, map_type);
+    if (out_fd < 0)
+	G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
     /* write the output file */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(result, ncols);
+	Rast_set_d_null_value(result, ncols);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (actpos = fragments[i]; actpos < fragments[i + 1]; actpos++) {
@@ -311,15 +310,10 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, result);
+	Rast_put_d_row(out_fd, result);
     }
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
-    if (verbose)
-	G_percent(1, 1, 2);
-
-    G_close_cell(in_fd);
-
     G_free(cells);
     G_free(fragments);
     G_free(flagbuf);

Copied: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/r.pi.enn.iter.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.enn.iter/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/r.pi.enn.iter.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/r.pi.enn.iter.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,48 @@
+<h2>DESCRIPTION</h2>
+
+Patch relevance for Euclidean Nearest Neighbor patches.
+
+<em>r.pi.enn.iter</em> computes distance and area
+differences for the first NN after removal of patch i.
+
+
+<h2>NOTES</h2>
+
+The <em>keyval</em> operator determines which category value is taken for
+the Patch Index analysis.
+
+The <em>method</em> operators determine what measure is applied 
+on the nth NN (area or distance).
+
+Differences of distance/area after removal of patch i are provided as output as well as 
+the amount of patches to be affected by its removal (percent) (PP) and
+the amount of area in these patches (PA - Percent Area)
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+Analysing the differences (average) in distance when patch i of class 5 is removed:
+<div class="code"><pre>
+r.pi.enn.iter input=landclass96 output=dist_iter keyval=5 method=distance statmethod=average 
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.enn.html">r.pi.enn</a>,
+<a href="r.pi.fnn.html">r.pi.fnn</a>,
+<a href="r.pi.searchtime.iter.html">r.pi.searchtime.iter</a>,
+
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.export/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.export/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,58 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-This module exports raster patch values (no single pixels, but single individual patch values), which can be used for subsequent analysis in R and later import into GRASS again, using <a href="r.pi.import.html">r.pi.import</a>.
-
-<h2>NOTES</h2>
-
-This module...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-generating a patch index map for later export:
-<div class="code"><pre>
-r.pi.index input=landclass96 output=landclass96_forestclass5_area keyval=5 method=area
-</pre></div>
-
-export this resulting map:
-<div class="code"><pre>
-r.pi.export input=landclass96_forestclass5_area output=patch_area_out values=patch_area_values id_raster=forestclass5_ID stats=average,variance,min
-</pre></div>
-
-various resulting files are generated:<br>
-<em>patch_area_out</em>: a text file with the <em>average</em>, <em>variance</em> and <em>minimum</em> statistics as defined above and additionally informaton about the percentage coverage (<em>landcover</em>) and the number of fragments (<em>number</em>) of the analysed landcover.
-
-<br>
-
-<em>patch_area_values</em>: a text file with the actual patch values not the statistics. The first column is providing the corresponding patch ID, which is also existing in the <em>forestclass5_ID</em> raster map (here:0-878). The second column is providing the percentage cover of each patch (sum is equal the overall coverage: 0.506). The third column is holding the actual patch index value (here area; e.g. patch 0: 12).
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.export/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,12 +1,7 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(DCELL * flagbuf, Coords * actpos, int row, int col,
-		  int nrows, int ncols, int nbr_cnt);
+		  int nrows, int ncols, int nbr_cnt, int fragcount);
 int getNeighbors(Position * res, DCELL * flagbuf, int x, int y, int nx,
 		 int ny, int nbr_cnt);
 
@@ -19,22 +14,22 @@
 
     switch (nbr_cnt) {
     case 4:			/* von Neumann neighborhood */
-	if (x > 0 && !G_is_d_null_value(&flagbuf[y * nx + x - 1])) {
+	if (x > 0 && !Rast_is_d_null_value(&flagbuf[y * nx + x - 1])) {
 	    res[cnt].x = x - 1;
 	    res[cnt].y = y;
 	    cnt++;
 	}
-	if (y > 0 && !G_is_d_null_value(&flagbuf[(y - 1) * nx + x])) {
+	if (y > 0 && !Rast_is_d_null_value(&flagbuf[(y - 1) * nx + x])) {
 	    res[cnt].x = x;
 	    res[cnt].y = y - 1;
 	    cnt++;
 	}
-	if (x < nx - 1 && !G_is_d_null_value(&flagbuf[y * nx + x + 1])) {
+	if (x < nx - 1 && !Rast_is_d_null_value(&flagbuf[y * nx + x + 1])) {
 	    res[cnt].x = x + 1;
 	    res[cnt].y = y;
 	    cnt++;
 	}
-	if (y < ny - 1 && !G_is_d_null_value(&flagbuf[(y + 1) * nx + x])) {
+	if (y < ny - 1 && !Rast_is_d_null_value(&flagbuf[(y + 1) * nx + x])) {
 	    res[cnt].x = x;
 	    res[cnt].y = y + 1;
 	    cnt++;
@@ -48,7 +43,7 @@
 	for (i = left; i <= right; i++) {
 	    for (j = top; j <= bottom; j++) {
 		if (!(i == x && j == y) &&
-		    !G_is_d_null_value(&flagbuf[j * nx + i])) {
+		    !Rast_is_d_null_value(&flagbuf[j * nx + i])) {
 		    res[cnt].x = i;
 		    res[cnt].y = j;
 		    cnt++;
@@ -62,7 +57,7 @@
 }
 
 Coords *writeFrag(DCELL * flagbuf, Coords * actpos, int row, int col,
-		  int nrows, int ncols, int nbr_cnt)
+		  int nrows, int ncols, int nbr_cnt, int fragcount)
 {
     int x, y, i;
     Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
@@ -73,15 +68,15 @@
     /* count neighbors */
     int neighbors = 0;
 
-    if (col <= 0 || !G_is_d_null_value(&flagbuf[row * ncols + col - 1]))
+    if (col <= 0 || !Rast_is_d_null_value(&flagbuf[row * ncols + col - 1]))
 	neighbors++;
-    if (row <= 0 || !G_is_d_null_value(&flagbuf[(row - 1) * ncols + col]))
+    if (row <= 0 || !Rast_is_d_null_value(&flagbuf[(row - 1) * ncols + col]))
 	neighbors++;
     if (col >= ncols - 1 ||
-	!G_is_d_null_value(&flagbuf[row * ncols + col + 1]))
+	!Rast_is_d_null_value(&flagbuf[row * ncols + col + 1]))
 	neighbors++;
     if (row >= nrows - 1 ||
-	!G_is_d_null_value(&flagbuf[(row + 1) * ncols + col]))
+	!Rast_is_d_null_value(&flagbuf[(row + 1) * ncols + col]))
 	neighbors++;
 
     /* write first cell */
@@ -95,7 +90,7 @@
     id_map[row * ncols + col] = fragcount - 1;
 
     /* delete position from buffer */
-    G_set_d_null_value(&flagbuf[row * ncols + col], 1);
+    Rast_set_d_null_value(&flagbuf[row * ncols + col], 1);
 
     /* push position on fifo-list */
     last->x = col;
@@ -107,17 +102,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -129,15 +119,15 @@
 
 	    /* count neighbors */
 	    neighbors = 0;
-	    if (x <= 0 || !G_is_d_null_value(&flagbuf[y * ncols + x - 1]))
+	    if (x <= 0 || !Rast_is_d_null_value(&flagbuf[y * ncols + x - 1]))
 		neighbors++;
-	    if (y <= 0 || !G_is_d_null_value(&flagbuf[(y - 1) * ncols + x]))
+	    if (y <= 0 || !Rast_is_d_null_value(&flagbuf[(y - 1) * ncols + x]))
 		neighbors++;
 	    if (x >= ncols - 1 ||
-		!G_is_d_null_value(&flagbuf[y * ncols + x + 1]))
+		!Rast_is_d_null_value(&flagbuf[y * ncols + x + 1]))
 		neighbors++;
 	    if (y >= nrows - 1 ||
-		!G_is_d_null_value(&flagbuf[(y + 1) * ncols + x]))
+		!Rast_is_d_null_value(&flagbuf[(y + 1) * ncols + x]))
 		neighbors++;
 
 	    /* set values */
@@ -151,35 +141,33 @@
 	    id_map[y * ncols + x] = fragcount - 1;
 
 	    /* delete position from buffer */
-	    G_set_d_null_value(&flagbuf[y * ncols + x], 1);
+	    Rast_set_d_null_value(&flagbuf[y * ncols + x], 1);
 	}
     }
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(DCELL * flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(DCELL * flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
-	    if (!G_is_d_null_value(&flagbuf[row * ncols + col])) {
+	    if (!Rast_is_d_null_value(&flagbuf[row * ncols + col])) {
 		fragcount++;
 
 		fragments[fragcount] =
 		    writeFrag(flagbuf, fragments[fragcount - 1], row, col,
-			      nrows, ncols, nbr_cnt);
+			      nrows, ncols, nbr_cnt, fragcount);
 	    }
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.export/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -7,6 +7,7 @@
 #include <math.h>
 #include <time.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
@@ -20,7 +21,7 @@
 typedef struct
 {
     int x, y;
-} Point;
+} Position;
 
 typedef struct
 {
@@ -31,13 +32,11 @@
 typedef DCELL(f_statmethod) (DCELL *, int);
 
 /* frag.c */
-void writeFragments(DCELL * flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(DCELL * flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* global variables */
-GLOBAL int verbose;
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 GLOBAL int sx, sy;
 GLOBAL int *id_map;
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.export/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.export
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Export of patch based raster information
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -38,13 +39,14 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* id raster */
-    char *idname, *idmapset;
+    char *idname;
 
     /* patch raster */
-    char *patchname, *patchmapset;
+    char *patchname;
 
     /* in and out file pointers */
     int in_fd;
@@ -53,37 +55,27 @@
     int out_fd;
 
     /* parameters */
-    int keyval;
     int stats[GNAME_MAX];
     int stat_count;
-    int ratio_flag;
     int neighb_count;
 
     /* maps */
     DCELL *map;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
     int *result;
-    DCELL *d_res;
     int i, j, n;
-    int x, y;
     Coords *p;
-    char output_name[GNAME_MAX];
     char *str;
     int method;
     f_statmethod *perform_method;
     DCELL val;
     DCELL *values;
     int count;
-    int area;
+    DCELL area;
+    int fragcount;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -94,13 +86,13 @@
     } parm;
     struct
     {
-	struct Flag *adjacent, *quiet;
+	struct Flag *adjacent;
     } flag;
 
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Export of patch based information.");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -163,10 +155,6 @@
     flag.adjacent->description =
 	_("Set for 8 cell-neighbors. 4 cell-neighbors are default");
 
-    flag.quiet = G_define_flag();
-    flag.quiet->key = 'q';
-    flag.quiet->description = _("Run quietly");
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -174,31 +162,26 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
-    /* get verbose */
-    verbose = !flag.quiet->answer;
-
     /* get number of cell-neighbors */
     neighb_count = flag.adjacent->answer ? 8 : 4;
 
     /* check if the id file name is correct */
     idname = parm.id_rast->answer;
     if (G_legal_filename(idname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), idname);
-	idmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), idname);
 
     /* check if the patch file name is correct */
     patchname = parm.patch_rast->answer;
     if (G_legal_filename(patchname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), patchname);
-	patchmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), patchname);
 
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* scan all statmethod answers */
     stat_count = 0;
@@ -226,36 +209,31 @@
     fragments[0] = cells;
     map = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
     id_map = (int *)G_malloc(sx * sy * sizeof(int));
-    d_res = G_allocate_d_raster_buf();
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
 
-    G_set_c_null_value(id_map, sx * sy);
+    Rast_set_c_null_value(id_map, sx * sy);
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
-    if (verbose)
-	G_message("Reading map:");
+    G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_d_raster_row(in_fd, map + row * sx, row);
+	Rast_get_d_row(in_fd, map + row * sx, row);
 
-	if (verbose)
-	    G_percent(row, sy, 2);
+	G_percent(row, sy, 2);
     }
-    if (verbose)
-	G_percent(1, 1, 2);
+    G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* find fragments */
-    writeFragments(map, sy, sx, neighb_count);
+    fragcount = writeFragments(map, sy, sx, neighb_count);
 
-    if (verbose)
-	G_message("Writing output...");
+    G_message("Writing output...");
 
     /* open ASCII-file or use stdout */
     if (parm.values->answer) {
@@ -271,7 +249,7 @@
 
 	/* write values */
 	for (i = 0; i < fragcount; i++) {
-	    double area = fragments[i + 1] - fragments[i];
+	    area = fragments[i + 1] - fragments[i];
 
 	    values = (DCELL *) G_malloc(area * sizeof(DCELL));
 	    for (p = fragments[i], j = 0; p < fragments[i + 1]; p++, j++) {
@@ -279,7 +257,7 @@
 	    }
 
 	    /* write patch index */
-	    fprintf(out_fp, "%d %lf", i, area / (sx * sy));
+	    fprintf(out_fp, "%d %f", i, area / (sx * sy));
 
 	    /* write patch value */
 	    for (method = 0; method < stat_count; method++) {
@@ -288,7 +266,7 @@
 		perform_method = statmethods[stats[method]].method;
 		outval = perform_method(values, area);
 
-		fprintf(out_fp, " %lf", outval);
+		fprintf(out_fp, " %f", outval);
 	    }
 	    fprintf(out_fp, "\n");
 
@@ -337,7 +315,7 @@
 
     /* write landcover and number of patches */
     area = fragments[fragcount] - fragments[0];
-    fprintf(out_fp, "%lf %d\n", (DCELL) area / (DCELL) (sx * sy), fragcount);
+    fprintf(out_fp, "%f %d\n", (DCELL) area / (DCELL) (sx * sy), fragcount);
 
     G_free(values);
 
@@ -349,43 +327,43 @@
     /* write id raster */
     if (idname) {
 	/* open new cellfile  */
-	out_fd = G_open_raster_new(idname, CELL_TYPE);
+	out_fd = Rast_open_new(idname, CELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), idname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_put_c_raster_row(out_fd, id_map + row * sx);
+	    Rast_put_c_row(out_fd, id_map + row * sx);
 
 	    G_percent(row + 1, 2 * sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write patch raster */
     if (patchname) {
 	/* open new cellfile  */
-	out_fd = G_open_raster_new(patchname, CELL_TYPE);
+	out_fd = Rast_open_new(patchname, CELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), patchname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_c_null_value(result, sx);
+	    Rast_set_c_null_value(result, sx);
 	    for (col = 0; col < sx; col++) {
-		if (!G_is_c_null_value(id_map + row * sx + col)) {
+		if (!Rast_is_c_null_value(id_map + row * sx + col)) {
 		    result[col] = 1;
 		}
 	    }
-	    G_put_c_raster_row(out_fd, result);
+	    Rast_put_c_row(out_fd, result);
 
 	    G_percent(sy + row + 1, 2 * sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* free allocated resources */

Copied: grass-addons/grass7/raster/r.pi/r.pi.export/r.pi.export.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.export/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/r.pi.export.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/r.pi.export.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,58 @@
+<h2>DESCRIPTION</h2>
+
+This module exports raster patch values (no single pixels, but single individual patch values), which can be used for subsequent analysis in R and later import into GRASS again, using <a href="r.pi.import.html">r.pi.import</a>.
+
+<h2>NOTES</h2>
+
+This module...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+generating a patch index map for later export:
+<div class="code"><pre>
+r.pi.index input=landclass96 output=landclass96_forestclass5_area keyval=5 method=area
+</pre></div>
+
+export this resulting map:
+<div class="code"><pre>
+r.pi.export input=landclass96_forestclass5_area output=patch_area_out values=patch_area_values id_raster=forestclass5_ID stats=average,variance,min
+</pre></div>
+
+various resulting files are generated:<br>
+<em>patch_area_out</em>: a text file with the <em>average</em>, <em>variance</em> and <em>minimum</em> statistics as defined above and additionally informaton about the percentage coverage (<em>landcover</em>) and the number of fragments (<em>number</em>) of the analysed landcover.
+
+<br>
+
+<em>patch_area_values</em>: a text file with the actual patch values not the statistics. The first column is providing the corresponding patch ID, which is also existing in the <em>forestclass5_ID</em> raster map (here:0-878). The second column is providing the percentage cover of each patch (sum is equal the overall coverage: 0.506). The third column is holding the actual patch index value (here area; e.g. patch 0: 12).
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.fnn/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,125 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Determine the functional nearest-neighbor distance analysis. 
-
-<em>r.pi.fnn</em> is a patch based ecological/functional nearest
-neighbour analysis module. It computes distance based on a friction map. This module is related to <em>r.pi.enn</em> but more adequat if the ecological connectivity should be analysed.
-
-<h2>NOTES</h2>
-
-The calculation of the ecolgogical nearest neighbour is based on a raster
-with start patches. The actual map can be categorical or continuous but
-the value defined in <em>keyval</em> will be the basis for the patches
-to calculate the methods defined below. These patches will also be in
-the output map.
-
-The calculation of the ecolgogical nearest neighbour is based on a costmap
-(* and 1-infinite) - this map can be binary or continous - high values
-are considered to have high cost issues and the shortest path is the
-one with the lowest amount of costs. "null" values can not be traversed,
-hence these values have to be bypassed. "0" values are not accepted and
-will result in "0" distance.
-
-<p>
-e.g. if a binary map(1 and 2) is used, the the path with the
-lowest amount of "1" is chosen
-
-The <em>number</em> is the amount of nearest neighbours to be taken and
-the calculated distances are processed as assigned in <em>statmethod</em>
-
-Operations which <em>r.pi.fnn</em> can perform are:
-
-<p>
-
-<dt><b>Distance</b> 
-
-<dd>The <em>Distance to Nearest</em> computes the nearest edge-to-edge
-distance between patches. Counting from the focus patch.
-
-<dt><b>path Distance</b> 
-
-<dd>The <em>Distance to Nearest</em> computes the nearest edge-to-edge
-distance between patches. Unlike <em>Distance</em> the distance is
-computed based on subsequent NN not from the focus patch onwards. The
-1th NN is the first patch with the minimal edge-to-edge distance from
-the focus patch, while 2th NN is the patch with the minimal edge-to-edge
-distance from the 1th NN patch and so on. 
-
-<dt><b>Area</b> 
-
-<dd>The <em>Area</em> computes the size of the nearest edge-to-edge
-distance patch. It is based on <em>Distance</em> not on <em>path Distance</em>.
-
-<dt><b>Perimeter</b> 
-
-<dd>The <em>Perimeter</em> computes the Perimeter of the nearest
-edge-to-edge distance patch. It is based on <em>Distance</em> not on
-<em> path Distance</em>.
-
-<dt><b>SHAPE</b> 
-
-<dd>The <em>SHAPE</em> computes the SHAPE Index of the nearest edge-to-edge
-distance patch. It is based on <em>Distance</em> not on <em> path Distance</em>.
-
-
-The <em>statsmethod</em> operators determine calculation is done on the
-distance. <em>Average</em>, <em>Variance</em>,<em>Stddev</em> and
-<em>value</em> can be used.
-
-<dt><b>Average</b> 
-
-<dd>The <em>Average</em> computes the average value defined in
-<em>Operations to perform </em>.
-
-<dt><b>Variance</b> 
-
-<dd>The <em>Variance</em> computes the variance defined in
-<em>Operations to perform </em>.
-
-<dt><b>Stand. Dev.</b> 
-
-<dd>The <em>Stand. Dev.</em> computes the stddev value defined in
-<em>Operations to perform </em>.
-
-<dt><b>Value</b> 
-
-<dd>The <em>patch Distance</em> computes the nearest edge-to-edge distance
-between two patches. The output of <em>value</em> is the actual value.
-E.g. NN==5 of <em>area</em> gives the size of the 5th NN while
-<em>Average</em> gives the average of the area of 1-5th NN.
-
-
-The input options are either one NN: <em>1</em> or several NN separated
-by <em>,</em>: 1,2,5,8 or a range of NN: 1-6.
-
-<p>
-Merging these options is possible as well: 1-5,8,9,13,15-19,22 etc.
-
-</dl>
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-Computing the functional or ecological distance to the first to nth nearest neighrbours using a cost matrix:
-<div class="code"><pre>
-r.mapcalc "cost_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
-r.pi.fnn input=landclass96 keyval=5 costmap=cost_raster output=fnn1 method=distance number=10 statmethod=average
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.enn.html">r.pi.enn</a>,
-<a href="r.pi.index.html">r.pi.index</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -98,16 +98,11 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt = getNeighbors(nbr_list, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -139,5 +134,6 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -18,9 +18,7 @@
 
 DCELL dist(Coords * p1, Coords * p2)
 {
-    int stepcounter = 0;
-
-    /* impementation of A* */
+    /* implementation of A* */
     char *flagmap = (char *)G_malloc(nrows * ncols * sizeof(char));
 
     memset(flagmap, 0, nrows * ncols * sizeof(char));
@@ -28,14 +26,12 @@
 
     heap_insert(p1->x, p1->y, 0, 0);
 
-    //      fprintf(stderr, "from - (%d, %d) -> (%d, %d)", p1->x, p1->y, p2->x, p2->y);
+    /* fprintf(stderr, "from - (%d, %d) -> (%d, %d)", p1->x, p1->y, p2->x, p2->y); */
 
     while (heapsize > 0) {
 	int upx, upy, downx, downy, dx, dy;
-	Path_Coords actpos = heap_delete(0);
+	Path_Coords actposh = heap_delete(0);
 
-	Path_Coords *p;
-
 	/*              char* c;
 
 	   if(stepcounter < 20) {
@@ -49,41 +45,42 @@
 	   } */
 
 	/* if actpos on closed */
-	if (flagmap[actpos.x + actpos.y * ncols] != 0)
+	if (flagmap[actposh.x + actposh.y * ncols] != 0)
 	    continue;
 	/* if actpos is goal */
-	if (actpos.x == p2->x && actpos.y == p2->y) {
+	if (actposh.x == p2->x && actposh.y == p2->y) {
 	    heap_free();
 	    G_free(flagmap);
-	    return actpos.g;
+
+	    return actposh.g;
 	}
 	/* add actpos to closed */
-	flagmap[actpos.x + actpos.y * ncols] = 1;
+	flagmap[actposh.x + actposh.y * ncols] = 1;
 
 	/* go through neighbors */
-	downx = actpos.x > 0 ? -1 : 0;
-	downy = actpos.y > 0 ? -1 : 0;
-	upx = actpos.x < ncols - 1 ? 1 : 0;
-	upy = actpos.y < nrows - 1 ? 1 : 0;
+	downx = actposh.x > 0 ? -1 : 0;
+	downy = actposh.y > 0 ? -1 : 0;
+	upx = actposh.x < ncols - 1 ? 1 : 0;
+	upy = actposh.y < nrows - 1 ? 1 : 0;
 
 	for (dx = downx; dx <= upx; dx++)
 	    for (dy = downy; dy <= upy; dy++)
-		// pick only neighbors, which are trespassable and not on closed list
+		/* pick only neighbors, which are trespassable and not on closed list */
 		if (!(dx == 0 && dy == 0) &&
-		    !G_is_d_null_value(costmap + actpos.x + dx +
-				       (actpos.y + dy) * ncols) &&
-		    flagmap[actpos.x + dx + (actpos.y + dy) * ncols] == 0) {
+		    !Rast_is_d_null_value(costmap + actposh.x + dx +
+				       (actposh.y + dy) * ncols) &&
+		    flagmap[actposh.x + dx + (actposh.y + dy) * ncols] == 0) {
 		    DCELL newf, newg;
 		    int i;
-		    int actx = actpos.x + dx;
-		    int acty = actpos.y + dy;
+		    int actx = actposh.x + dx;
+		    int acty = actposh.y + dy;
 
 		    /* calculate new path cost */
 		    if (dx == 0 || dy == 0)
-			newg = actpos.g + costmap[actx + acty * ncols];
+			newg = actposh.g + costmap[actx + acty * ncols];
 		    else
 			newg =
-			    actpos.g + M_SQRT2 * costmap[actx + acty * ncols];
+			    actposh.g + M_SQRT2 * costmap[actx + acty * ncols];
 
 		    /* calculate new estimate */
 		    newf = newg + euclid_dist(actx, acty, p2->x, p2->y);
@@ -117,6 +114,7 @@
 
     heap_free();
     G_free(flagmap);
+
     return 0;
 }
 
@@ -125,13 +123,13 @@
     Coords *p1, *p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = frags[n2]; p2 < frags[n2 + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -227,7 +225,7 @@
 
 int get_nearest_indices(int count, int *num_array, int num_count)
 {
-    int i, j, tmp;
+    int i;
     int max = 0;
 
     /* get maximum number */
@@ -235,15 +233,14 @@
 
     patch_n = num_array[max] < count - 1 ? num_array[max] : count - 1;
 
-    //      fprintf(stderr, "\n%d nearest patches taken into account.\n\n", patch_n);
+    /* fprintf(stderr, "\n%d nearest patches taken into account.\n\n", patch_n); */
 
     nearest_indices = (int *)G_malloc(count * patch_n * sizeof(int));
 
     /* for all patches */
     for (i = 0; i < count; i++) {
 	/* display progress */
-	if (verbose)
-	    G_percent(i, count, 2);
+	G_percent(i, count, 2);
 
 	get_smallest_n_indices(nearest_indices + i * patch_n, distmatrix,
 			       patch_n, count, i);
@@ -284,6 +281,7 @@
     }
 
     G_free(distances);
+
     return 0;
 }
 
@@ -309,6 +307,7 @@
     }
 
     G_free(areas);
+
     return 0;
 }
 
@@ -342,6 +341,7 @@
     }
 
     G_free(perims);
+
     return 0;
 }
 
@@ -377,6 +377,7 @@
     }
 
     G_free(shapes);
+
     return 0;
 }
 
@@ -391,18 +392,19 @@
 
     /* for all patches */
     for (i = 0; i < count; i++) {
-	// clear flags array
-	memset(flags, 0, count * sizeof(int));
 	int act_patch = i;
 
+	/* clear flags array */
+	memset(flags, 0, count * sizeof(int));
+
 	for (j = 0; j < patch_n; j++) {
-	    // get nearest patch for the act_patch
-	    // ignore those already marked in flags
+	    /* get nearest patch for the act_patch
+	     * ignore those already marked in flags */
 	    k = 0;
 	    do {
 		index = nearest_indices[act_patch * patch_n + k++];
 	    } while (flags[index] == 1);
-	    // mark current patch
+	    /* mark current patch */
 	    flags[act_patch] = 1;
 
 	    distances[j] = distmatrix[act_patch * count + index];
@@ -420,5 +422,6 @@
     }
 
     G_free(distances);
+
     return 0;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/heap.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/heap.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/heap.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -25,13 +25,13 @@
 {
     int son = pos * 2 + 1;
 
-    // actual element has left son
+    /* actual element has left son */
     if (son < heapsize) {
-	// actual element has right son, which is the smaller son
+	/* actual element has right son, which is the smaller son */
 	if (son + 1 < heapsize && heap[son + 1].f < heap[son].f)
 	    son++;
-	// son is now the smaller son
-	// if son smaller then actual element
+	/* son is now the smaller son */
+	/* if son smaller then actual element */
 	if (heap[pos].f > heap[son].f) {
 	    exchange(pos, son);
 	    downheap(son);

Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -60,7 +60,6 @@
 GLOBAL Coords **fragments;
 GLOBAL int *flagbuf;
 GLOBAL Coords *actpos;
-GLOBAL int verbose;
 GLOBAL DCELL *distmatrix;
 GLOBAL int *nearest_indices;
 GLOBAL int patch_n;

Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.fnn
  * AUTHOR(S):    Elshad Shirinov, Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Analysis of n-th functional/ecological nearest neighbour
  *                               distance and spatial attributes of nearest neighbour patches
  *
@@ -58,18 +59,19 @@
     int exitres = 0;
 
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset;
-    char *costname, *costmapset;
+    char *newname, *oldname;
+    const char *oldmapset;
+    char *costname;
+    const char *costmapset;
     char fullname[GNAME_MAX];
     char title[1024];
 
     /* in and out file pointers */
     int in_fd, in_cost;
     int out_fd;
-    DCELL *result, res[30];
+    DCELL *result;
 
-    /* map_type and categories */
-    RASTER_MAP_TYPE map_type;
+    /* categories */
     struct Categories cats;
 
     int statmethod;
@@ -85,9 +87,7 @@
 
     int row, col, i, j, m;
     int method_count;
-    int readrow;
     int keyval;
-    DCELL range = MAX_DOUBLE;
 
     int n;
     int copycolr;
@@ -102,7 +102,7 @@
     } parm;
     struct
     {
-	struct Flag *adjacent, *quiet;
+	struct Flag *adjacent;
     } flag;
 
     DCELL *values;
@@ -111,12 +111,10 @@
     int parseres[1024];
     int number;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Determines patches of given value and performs "
 	  "a nearest-neighbor analysis.");
@@ -207,10 +205,6 @@
     flag.adjacent->description =
 	_("Set for 8 cell-neighbors. 4 cell-neighbors are default");
 
-    flag.quiet = G_define_flag();
-    flag.quiet->key = 'q';
-    flag.quiet->description = _("Run quietly");
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -218,7 +212,7 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
@@ -226,35 +220,31 @@
     costname = parm.costmap->answer;
 
     /* test costmap existance */
-    costmapset = G_find_cell2(costname, "");
-	if (costmapset == NULL)
+    costmapset = G_find_raster2(costname, "");
+    if (costmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), costname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
         G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* open costmap file */
-	in_cost = G_open_cell_old(costname, costmapset);
-	if (in_cost < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), costname);
+    in_cost = Rast_open_old(costname, costmapset);
+    if (in_cost < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), costname);
 
-    /* get map type */
-    map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
-
     /* copy color table */
-    copycolr = (G_read_colors(oldname, oldmapset, &colr) > 0);
+    copycolr = (Rast_read_colors(oldname, oldmapset, &colr) > 0);
 
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
@@ -310,7 +300,7 @@
     fragments = (Coords **) G_malloc(nrows * ncols * sizeof(Coords *));
     fragments[0] = cells;
     flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* get title, initialize the category and stat info */
     if (parm.title->answer)
@@ -318,28 +308,28 @@
     else
 	sprintf(title, "Fragmentation of file: %s", oldname);
 
-    if ((verbose = !flag.quiet->answer))
-	G_message("Loading patches...");
+    G_message("Loading patches...");
 
     /* read costmap */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_cost, result, row);
+	Rast_get_d_row(in_cost, result, row);
 	for (col = 0; col < ncols; col++) {
 	    costmap[row * ncols + col] = result[col];
 	}
     }
+    Rast_close(in_cost);
 
     /* find fragments */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, result, row);
+	Rast_get_d_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
 	}
 
-	if (verbose)
-	    G_percent(row, nrows, 2);
+	G_percent(row, nrows, 2);
     }
+    Rast_close(in_fd);
 
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -350,8 +340,7 @@
 	    }
 	}
     }
-    if (verbose)
-	G_percent(nrows, nrows, 2);
+    G_percent(nrows, nrows, 2);
 
     /* generate the distance matrix */
     get_dist_matrix(fragcount);
@@ -372,17 +361,14 @@
 	compute_values = menu[methods[m]].method;
 
 	/* perform actual function on the patches */
-	if ((verbose = !flag.quiet->answer))
-	    G_message("Performing operation %s ... ", menu[methods[m]].name);
+	G_message("Performing operation %s ... ", menu[methods[m]].name);
 	values = (DCELL *) G_malloc(fragcount * number * sizeof(DCELL));
 	compute_values(values, fragcount, parseres, number, compute_stat);
 
-	if (verbose)
-	    G_percent(fragcount, fragcount, 2);
+	G_percent(fragcount, fragcount, 2);
 
 	/* write output files */
-	if ((verbose = !flag.quiet->answer))
-	    G_message("Writing output...");
+	G_message("Writing output...");
 
 	/* for all requested patches */
 	for (j = 0; j < number; j++) {
@@ -390,13 +376,13 @@
 	    /* open the new cellfile */
 	    sprintf(fullname, "%s.ENN%d.%s", newname, parseres[j],
 		    menu[methods[m]].name);
-	    out_fd = G_open_raster_new(fullname, DCELL_TYPE);
+	    out_fd = Rast_open_new(fullname, DCELL_TYPE);
 	    if (out_fd < 0)
-			G_fatal_error(_("Cannot create raster map <%s>"), fullname);
+		G_fatal_error(_("Cannot create raster map <%s>"), fullname);
 
 	    /* write data */
 	    for (row = 0; row < nrows; row++) {
-		G_set_d_null_value(result, ncols);
+		Rast_set_d_null_value(result, ncols);
 
 		for (i = 0; i < fragcount; i++) {
 		    for (actpos = fragments[i]; actpos < fragments[i + 1];
@@ -407,21 +393,18 @@
 		    }
 		}
 
-		G_put_d_raster_row(out_fd, result);
+		Rast_put_d_row(out_fd, result);
 
-		if (verbose)
-		    G_percent(row + nrows * j + nrows * number * m,
-			      nrows * number * method_count, 2);
+		G_percent(row + nrows * j + nrows * number * m,
+			  nrows * number * method_count, 2);
 	    }
 
-	    G_close_cell(out_fd);
+	    Rast_close(out_fd);
 	}
 
     }				/* for each method */
+    G_percent(100, 100, 2);
 
-    if (verbose)
-	G_percent(100, 100, 2);
-
     if (parm.dmout->answer) {
 	exitres =
 	    writeDistMatrixAndID(parm.dmout->answer, fragments, fragcount);
@@ -433,8 +416,6 @@
 				 fragcount, parseres, number);
     }
 
-    G_close_cell(in_fd);
-
     G_free(cells);
     G_free(fragments);
     G_free(flagbuf);
@@ -442,11 +423,11 @@
     G_free(distmatrix);
     G_free(nearest_indices);
 
-    G_init_cats(0, title, &cats);
-    G_write_cats(newname, &cats);
+    Rast_init_cats(title, &cats);
+    Rast_write_cats(newname, &cats);
 
     if (copycolr)
-	G_write_colors(newname, newmapset, &colr);
+	Rast_write_colors(newname, G_mapset(), &colr);
 
     exit(exitres);
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/matrix.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/matrix.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/matrix.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -4,13 +4,13 @@
 {
     FILE *out_fp;
     int res = 0;
-    char *mapset;
+    const char *mapset;
     int out_fd;
     int row, col, i;
     DCELL *result;
 
     /* allocate memory for result-row */
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* open ASCII-file or use stdout */
     if (!(out_fp = fopen(name, "w"))) {
@@ -35,7 +35,7 @@
 	mapset = G_mapset();
 
 	/* open the new cellfile */
-	out_fd = G_open_raster_new(name, DCELL_TYPE);
+	out_fd = Rast_open_new(name, DCELL_TYPE);
 	if (out_fd < 0) {
 	    char msg[200];
 
@@ -47,7 +47,7 @@
 	else {
 	    /* write data */
 	    for (row = 0; row < nrows; row++) {
-		G_set_d_null_value(result, ncols);
+		Rast_set_d_null_value(result, ncols);
 
 		for (i = 0; i < count; i++) {
 		    for (actpos = frags[i]; actpos < frags[i + 1]; actpos++) {
@@ -57,10 +57,10 @@
 		    }
 		}
 
-		G_put_d_raster_row(out_fd, result);
+		Rast_put_d_row(out_fd, result);
 	    }
 	}
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* free memory */

Copied: grass-addons/grass7/raster/r.pi/r.pi.fnn/r.pi.fnn.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.fnn/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/r.pi.fnn.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/r.pi.fnn.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,125 @@
+<h2>DESCRIPTION</h2>
+
+Determine the functional nearest-neighbor distance analysis. 
+
+<em>r.pi.fnn</em> is a patch based ecological/functional nearest
+neighbour analysis module. It computes distance based on a friction map. This module is related to <em>r.pi.enn</em> but more adequat if the ecological connectivity should be analysed.
+
+<h2>NOTES</h2>
+
+The calculation of the ecolgogical nearest neighbour is based on a raster
+with start patches. The actual map can be categorical or continuous but
+the value defined in <em>keyval</em> will be the basis for the patches
+to calculate the methods defined below. These patches will also be in
+the output map.
+
+The calculation of the ecolgogical nearest neighbour is based on a costmap
+(* and 1-infinite) - this map can be binary or continous - high values
+are considered to have high cost issues and the shortest path is the
+one with the lowest amount of costs. "null" values can not be traversed,
+hence these values have to be bypassed. "0" values are not accepted and
+will result in "0" distance.
+
+<p>
+e.g. if a binary map(1 and 2) is used, the the path with the
+lowest amount of "1" is chosen
+
+The <em>number</em> is the amount of nearest neighbours to be taken and
+the calculated distances are processed as assigned in <em>statmethod</em>
+
+Operations which <em>r.pi.fnn</em> can perform are:
+
+<p>
+
+<dl>
+<dt><b>Distance</b> 
+
+<dd>The <em>Distance to Nearest</em> computes the nearest edge-to-edge
+distance between patches. Counting from the focus patch.
+
+<dt><b>path Distance</b> 
+
+<dd>The <em>Distance to Nearest</em> computes the nearest edge-to-edge
+distance between patches. Unlike <em>Distance</em> the distance is
+computed based on subsequent NN not from the focus patch onwards. The
+1th NN is the first patch with the minimal edge-to-edge distance from
+the focus patch, while 2th NN is the patch with the minimal edge-to-edge
+distance from the 1th NN patch and so on. 
+
+<dt><b>Area</b> 
+
+<dd>The <em>Area</em> computes the size of the nearest edge-to-edge
+distance patch. It is based on <em>Distance</em> not on <em>path Distance</em>.
+
+<dt><b>Perimeter</b> 
+
+<dd>The <em>Perimeter</em> computes the Perimeter of the nearest
+edge-to-edge distance patch. It is based on <em>Distance</em> not on
+<em> path Distance</em>.
+
+<dt><b>SHAPE</b> 
+
+<dd>The <em>SHAPE</em> computes the SHAPE Index of the nearest edge-to-edge
+distance patch. It is based on <em>Distance</em> not on <em> path Distance</em>.
+</dl>
+
+The <em>statsmethod</em> operators determine calculation is done on the
+distance. <em>Average</em>, <em>Variance</em>,<em>Stddev</em> and
+<em>value</em> can be used.
+
+<dl>
+<dt><b>Average</b> 
+
+<dd>The <em>Average</em> computes the average value defined in
+<em>Operations to perform </em>.
+
+<dt><b>Variance</b> 
+
+<dd>The <em>Variance</em> computes the variance defined in
+<em>Operations to perform </em>.
+
+<dt><b>Stand. Dev.</b> 
+
+<dd>The <em>Stand. Dev.</em> computes the stddev value defined in
+<em>Operations to perform </em>.
+
+<dt><b>Value</b> 
+
+<dd>The <em>patch Distance</em> computes the nearest edge-to-edge distance
+between two patches. The output of <em>value</em> is the actual value.
+E.g. NN==5 of <em>area</em> gives the size of the 5th NN while
+<em>Average</em> gives the average of the area of 1-5th NN.
+</dl>
+
+The input options are either one NN: <em>1</em> or several NN separated
+by <em>,</em>: 1,2,5,8 or a range of NN: 1-6.
+
+<p>
+Merging these options is possible as well: 1-5,8,9,13,15-19,22 etc.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+Computing the functional or ecological distance to the first to nth nearest neighrbours using a cost matrix:
+<div class="code"><pre>
+r.mapcalc "cost_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
+r.pi.fnn input=landclass96 keyval=5 costmap=cost_raster output=fnn1 method=distance number=10 statmethod=average
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.enn.html">r.pi.enn</a>,
+<a href="r.pi.index.html">r.pi.index</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -2,9 +2,12 @@
 
 PGM = r.pi.graph
 
-LIBES = $(STATSLIB) $(GISLIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIB_NAME = grass_rpi
+RPI_LIB  = -l$(LIB_NAME)
 
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
+
 include $(MODULE_TOPDIR)/include/Make/Module.make
 
 default: cmd

Deleted: grass-addons/grass7/raster/r.pi/r.pi.graph/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,53 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Graph Theory for connectivity analysis. 
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset using class 5 (forest):
-
-Computing a graph of all patches (4 neighbourhood rule) using a maximum distance of 10 pixel, the Gabriel method and as resulting index the <em> largest patch diameter</em>:
-<div class="code"><pre>
-r.pi.graph input=landclass96 output=landclass96_graph keyval=5 distance=10 neighborhood=gabriel index=largest_patch_diameter
-</pre></div>
-
-the results are 2 files:
-landclass96_graph: the information of the index are provided (here a range of 3-589 of patch diameter)
-landclass96_graph_clusters: the generated cluster IDs are provided (here 16 clusters are identified), doing it with a distance of 5 pixel is resulting in a total of 66 cluster.
-
-
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/draw.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/draw.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/draw.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,75 +1,20 @@
 #include "local_proto.h"
 
-inline void swap(int *a, int *b)
-{
-    int zw = *a;
-
-    *a = *b;
-    *b = zw;
-}
-
-void draw_point(int *map, int val, int x, int y, int sx, int sy, int width)
-{
-    if (width <= 0) {
-	return;
-    }
-
-    if (width == 1) {
-	map[y * sx + x] = val;
-    }
-    else {
-    }
-}
-
-void draw_line(int *map, int val, int x1, int y1, int x2, int y2, int sx,
-	       int sy, int width)
-{
-    int steep = abs(y2 - y1) > abs(x2 - x1);
-
-    if (steep) {
-	swap(&x1, &y1);
-	swap(&x2, &y2);
-    }
-
-    if (x1 > x2) {
-	swap(&x1, &x2);
-	swap(&y1, &y2);
-    }
-
-    int deltax = x2 - x1;
-    int deltay = abs(y2 - y1);
-    int error = deltax / 2;
-    int ystep = y1 < y2 ? 1 : -1;
-    int x;
-    int y = y1;
-
-    for (x = x1; x <= x2; x++) {
-	if (steep) {
-	    draw_point(map, val, y, x, sx, sy, width);
-	}
-	else {
-	    draw_point(map, val, x, y, sx, sy, width);
-	}
-
-	error -= deltay;
-	if (error < 0) {
-	    y += ystep;
-	    error += deltax;
-	}
-    }
-}
-
 void flood_fill(int *map, int val, int x, int y, int sx, int sy)
 {
+    /* setup list of positions to fill */
+    Position *list;
+    Position *begin;
+    Position *end;
+
     /* exit if the position is already set to this value */
     if (map[y * sx + x] == val) {
 	return;
     }
 
-    /* setup list of positions to fill */
-    Position *list = (Position *) G_malloc(sx * sy * sizeof(Position));
-    Position *begin = list;
-    Position *end = list + 1;
+    list = (Position *) G_malloc(sx * sy * sizeof(Position));
+    begin = list;
+    end = list + 1;
 
     /* set first position */
     begin->x = x;
@@ -78,14 +23,14 @@
 
     /* while there are still positions to fill do */
     while (begin < end) {
+	int cur_x = begin->x;
+	int cur_y = begin->y;
+
 	if (end - list >= sx * sy) {
-	    G_message("fill list count: %d", end - list);
+	    G_debug(1, "fill list count: %d", (int)(end - list));
 	    break;
 	}
 
-	int cur_x = begin->x;
-	int cur_y = begin->y;
-
 	/* set all four neighbors on the list */
 	if (cur_x > 0 && map[cur_y * sx + cur_x - 1] != val) {
 	    map[cur_y * sx + cur_x - 1] = val;

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -93,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -135,16 +130,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -158,5 +152,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -17,13 +17,13 @@
     Coords *p1, *p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = frags[n2]; p2 < frags[n2 + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -34,6 +34,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -43,13 +44,13 @@
     Coords *p1, *p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = frags[n2]; p2 < frags[n2 + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -62,6 +63,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -71,9 +73,9 @@
     Coords *p;
     DCELL min = MAX_DOUBLE;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p = frags[patch]; p < frags[patch + 1]; p++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p->neighbors < 4) {
 	    DCELL dx = loc_x - p->x;
 	    DCELL dy = loc_y - p->y;
@@ -84,10 +86,11 @@
 	    }
 	}
     }
+
     return min;
 }
 
-int get_dist_matrix()
+int get_dist_matrix(int fragcount)
 {
     int i, j;
 
@@ -106,7 +109,7 @@
     return 0;
 }
 
-int get_nearest_neighbor(int patch)
+int get_nearest_neighbor(int patch, int fragcount)
 {
     int i;
     int min = -1;
@@ -123,17 +126,20 @@
     return min;
 }
 
-int *FindCluster(int patch, int *curpos, int *flag_arr)
+int *FindCluster(int patch, int *curpos, int *flag_arr, int fragcount)
 {
     int i;
-    int *p;
-    int list[fragcount];
-    int *first = list;
-    int *last = list + 1;
+    int *list;
+    int *first;
+    int *last;
     int offset;
 
+    list = G_malloc(fragcount * sizeof(int));
+
     list[0] = patch;
     flag_arr[patch] = 1;
+    first = list;
+    last = list + 1;
 
     while (first < last) {
 	/* save patch */
@@ -163,14 +169,15 @@
     return curpos;
 }
 
-void FindClusters()
+void FindClusters(int fragcount)
 {
     int i;
+    int *flag_arr;
 
     clusters[0] = patches;
     clustercount = 0;
 
-    int flag_arr[fragcount];
+    flag_arr = G_malloc(fragcount * sizeof(int));
 
     memset(flag_arr, 0, fragcount * sizeof(int));
 
@@ -178,17 +185,19 @@
 	if (flag_arr[i] == 0) {
 	    clustercount++;
 	    clusters[clustercount] =
-		FindCluster(i, clusters[clustercount - 1], flag_arr);
+		FindCluster(i, clusters[clustercount - 1], flag_arr, fragcount);
 	}
     }
+    
+    G_free(flag_arr);
 }
 
-void f_nearest_neighbor(DCELL max_dist)
+void f_nearest_neighbor(DCELL max_dist, int fragcount)
 {
     int i;
 
     for (i = 0; i < fragcount; i++) {
-	int nn = get_nearest_neighbor(i);
+	int nn = get_nearest_neighbor(i, fragcount);
 
 	if (nn > -1 && distmatrix[i * fragcount + nn] < max_dist) {
 	    adjmatrix[i * fragcount + nn] = 1;
@@ -197,7 +206,7 @@
     }
 }
 
-void f_relative_neighbor(DCELL max_dist)
+void f_relative_neighbor(DCELL max_dist, int fragcount)
 {
     int i, j, k;
 
@@ -237,7 +246,7 @@
     }
 }
 
-void f_gabriel(DCELL max_dist)
+void f_gabriel(DCELL max_dist, int fragcount)
 {
     int i, j, k;
 
@@ -277,15 +286,18 @@
     }
 }
 
-void f_spanning_tree(DCELL max_dist)
+void f_spanning_tree(DCELL max_dist, int fragcount)
 {
     int i, j;
-    int parents[fragcount];
-    DCELL distances[fragcount];
+    int *parents;
+    DCELL *distances;
     int curmin;
     int nextmin = 0;
     int parent;
 
+    parents = G_malloc(fragcount * sizeof(int));
+    distances = G_malloc(fragcount * sizeof(DCELL));
+
     /* init parents and distances list */
     for (i = 0; i < fragcount; i++) {
 	parents[i] = -1;
@@ -312,13 +324,13 @@
 
 	/* find the next node for minimum spanning tree */
 	for (j = 0; j < fragcount; j++) {
+	    /* get distance to the current minimum node */
+	    DCELL dist = distmatrix[curmin * fragcount + j];
+
 	    /* skip the current minimum node */
 	    if (j == curmin)
 		continue;
 
-	    /* get distance to the current minimum node */
-	    DCELL dist = distmatrix[curmin * fragcount + j];
-
 	    /* if this distance is smaller than the stored one */
 	    /* then set a new distance and update parent list  */
 	    if (dist < distances[j]) {
@@ -345,9 +357,12 @@
 	   }
 	   fprintf(stderr, "\n"); */
     }
+
+    G_free(parents);
+    G_free(distances);
 }
 
-void f_connectance_index(DCELL * values)
+void f_connectance_index(DCELL * values, int fragcount)
 {
     int i;
     int *p, *q;
@@ -355,7 +370,6 @@
     /* for each cluster */
     for (i = 0; i < clustercount; i++) {
 	int n = clusters[i + 1] - clusters[i];
-	DCELL c = 100.0 / (n * (n - 1) * 0.5);
 	DCELL val = 0;
 
 	/* single patch is 100% connected */
@@ -377,10 +391,10 @@
     }
 }
 
-void f_gyration_radius(DCELL * values)
+void f_gyration_radius(DCELL * values, int fragcount)
 {
     int i;
-    int *p, *q;
+    int *p;
 
     Coords *cell;
 
@@ -412,15 +426,14 @@
     }
 }
 
-void f_cohesion_index(DCELL * values)
+void f_cohesion_index(DCELL * values, int fragcount)
 {
     int i;
-    int *p, *q;
+    int *p;
     Coords *cell;
 
     /* for each cluster */
     for (i = 0; i < clustercount; i++) {
-	int n = clusters[i + 1] - clusters[i];
 	int total_area = 0;
 	DCELL num = 0.0;
 	DCELL denom = 0.0;
@@ -451,7 +464,7 @@
     }
 }
 
-void f_percent_patches(DCELL * values)
+void f_percent_patches(DCELL * values, int fragcount)
 {
     int i;
 
@@ -463,11 +476,10 @@
     }
 }
 
-void f_percent_area(DCELL * values)
+void f_percent_area(DCELL * values, int fragcount)
 {
     int i;
-    int *p, *q;
-    Coords *cell;
+    int *p;
 
     int area_all = fragments[fragcount] - fragments[0];
 
@@ -484,7 +496,7 @@
     }
 }
 
-void f_number_patches(DCELL * values)
+void f_number_patches(DCELL * values, int fragcount)
 {
     int i;
 
@@ -494,7 +506,7 @@
     }
 }
 
-void f_number_links(DCELL * values)
+void f_number_links(DCELL * values, int fragcount)
 {
     int i;
     int *p, *q;
@@ -517,7 +529,7 @@
     }
 }
 
-void f_mean_patch_size(DCELL * values)
+void f_mean_patch_size(DCELL * values, int fragcount)
 {
     int i;
     int *p;
@@ -536,7 +548,7 @@
     }
 }
 
-void f_largest_patch_size(DCELL * values)
+void f_largest_patch_size(DCELL * values, int fragcount)
 {
     int i;
     int *p;
@@ -563,13 +575,13 @@
     Coords *p1, *p2;
     DCELL max = 0.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n]; p1 < frags[n + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = p1 + 1; p2 < frags[n + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -583,7 +595,7 @@
     return max;
 }
 
-void f_largest_patch_diameter(DCELL * values)
+void f_largest_patch_diameter(DCELL * values, int fragcount)
 {
     int i;
     int *p;
@@ -606,18 +618,17 @@
 }
 
 /* implements floyd-warshall algorithm for finding shortest pathes */
-void f_graph_diameter_max(DCELL * values)
+void f_graph_diameter_max(DCELL * values, int fragcount)
 {
     int i, j, k;
+    DCELL *pathmatrix;
 
     /* initialize path matrix */
-    DCELL pathmatrix[fragcount * fragcount * sizeof(DCELL)];
+    pathmatrix = G_malloc(fragcount * fragcount * sizeof(DCELL));
 
     for (i = 0; i < fragcount; i++) {
 	pathmatrix[i * fragcount + i] = 0.0;
 
-	int j;
-
 	for (j = i + 1; j < fragcount; j++) {
 	    int index = i * fragcount + j;
 	    int index_mirror = j * fragcount + i;
@@ -673,4 +684,6 @@
 
 	values[i] = max_dist;
     }
+
+    G_free(pathmatrix);
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/hull.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/hull.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/hull.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -27,30 +27,39 @@
 /* quicksort */
 void sort_vertices(Position * list, int begin, int end, Position ref)
 {
+    int b = begin + 1;
+    int e = end;
+    Position piv;
+    Position tmp;
+
     if (begin >= end)
 	return;
+    
+    piv = list[begin];
 
-    int b = begin + 1;
-    int e = end;
-    Position piv = list[begin];
+    /*
+    G_message("begin=(%d,%d), end=(%d,%d), piv=(%d,%d), ref=(%d,%d)", list[b].x, list[b].y, list[e].x, list[e].y, piv.x, piv.y, ref.x, ref.y);
+    */
 
-    //G_message("begin=(%d,%d), end=(%d,%d), piv=(%d,%d), ref=(%d,%d)", list[b].x, list[b].y, list[e].x, list[e].y, piv.x, piv.y, ref.x, ref.y);
-
     while (b <= e) {
-	//G_message("begin=%d, end=%d, piv=(%d,%d), ref=(%d,%d)", b, e, piv.x, piv.y, ref.x, ref.y);
+	/*
+	G_message("begin=%d, end=%d, piv=(%d,%d), ref=(%d,%d)", b, e, piv.x, piv.y, ref.x, ref.y);
 
-	//G_message("is_less(%d, %d) = %d", list[b].x, list[b].y, is_less(list[b], piv, ref));
+	G_message("is_less(%d, %d) = %d", list[b].x, list[b].y, is_less(list[b], piv, ref));
+	*/
 	while (is_less(list[b], piv, ref)) {
 	    b++;
 	}
-	//G_message("is_bigger(%d, %d) = %d", list[e].x, list[e].y, is_less(piv, list[e], ref));
+	/*
+	G_message("is_bigger(%d, %d) = %d", list[e].x, list[e].y, is_less(piv, list[e], ref));
+	*/
 	while (is_less(piv, list[e], ref)) {
 	    e--;
 	}
 	if (b <= e) {
-	    //G_message("swap %d with %d", b, e);
+	    /* G_message("swap %d with %d", b, e); */
 
-	    Position tmp = list[b];
+	    tmp = list[b];
 
 	    list[b] = list[e];
 	    list[e] = tmp;
@@ -58,8 +67,8 @@
     }
 
     /* put piveau element to its place */
-    //G_message("swap %d with %d", begin, e);
-    Position tmp = list[begin];
+    /* G_message("swap %d with %d", begin, e); */
+    tmp = list[begin];
 
     list[begin] = list[e];
     list[e] = tmp;
@@ -70,28 +79,31 @@
 	sort_vertices(list, b, end, ref);
 }
 
-void convex_hull_cluster(int *map, int cluster)
+void convex_hull_cluster(int *map, int cluster, int nrows, int ncols)
 {
     int i;
     int *p;
     int area = 0;
+    Position *vertices;
+    Position tmp;
+    Position centroid = { 0, 0 };
+    int vertexcount = 0;
 
     /* calculate sum of the patch areas */
     for (p = clusters[cluster]; p < clusters[cluster + 1]; p++) {
 	area += fragments[*p + 1] - fragments[*p];
     }
 
-    //G_message("Cluster%d area = %d", cluster, area);
+    /* G_message("Cluster%d area = %d", cluster, area); */
 
     /* allocate memory for the vertex list */
-    Position *vertices = (Position *) G_malloc((area + 1) * sizeof(Position));
+    vertices = (Position *) G_malloc((area + 1) * sizeof(Position));
 
     /* fill vertex list */
-    int vertexcount = 0;
 
     /* for each patch in the cluster */
     for (p = clusters[cluster]; p < clusters[cluster + 1]; p++) {
-	//G_message("Analyzing Patch%d", *p);
+	/* G_message("Analyzing Patch%d", *p); */
 
 	Coords *c;
 
@@ -110,6 +122,7 @@
     if (vertexcount > 1) {
 	/* find the top-left cell */
 	int min = 0;
+	int k;
 
 	for (i = 0; i < vertexcount; i++) {
 	    if (vertices[i].y < vertices[min].y ||
@@ -120,7 +133,7 @@
 	}
 
 	/* put min at the first position */
-	Position tmp = vertices[0];
+	tmp = vertices[0];
 
 	vertices[0] = vertices[min];
 	vertices[min] = tmp;
@@ -135,8 +148,8 @@
 	sort_vertices(vertices, 1, vertexcount - 1, vertices[0]);
 
 	/* copy min to the last position */
-	//vertices[vertexcount] = vertices[0];
-	//vertexcount++;
+	/* vertices[vertexcount] = vertices[0]; */
+	/* vertexcount++; */
 
 	/*G_message("Vertex list:");
 	   for(i = 0; i < vertexcount; i++) {
@@ -147,7 +160,6 @@
 	/* process points and bridge concave angles */
 	/* first h cells of the result are the hull cells */
 	i = 2;
-	int k;
 
 	for (k = 2; k < vertexcount; k++, i++) {
 	    /* swap cells i and k */
@@ -176,7 +188,6 @@
        }
        fprintf(stderr, "\n"); */
 
-    Position centroid = { 0, 0 };
     for (i = 0; i < vertexcount; i++) {
 	Position p1 = vertices[i];
 	Position p2 = vertices[(i + 1) % vertexcount];
@@ -201,11 +212,11 @@
     G_free(vertices);
 }
 
-void convex_hull(int *map)
+void convex_hull(int *map, int nrows, int ncols)
 {
     int cluster;
 
     for (cluster = 0; cluster < clustercount; cluster++) {
-	convex_hull_cluster(map, cluster);
+	convex_hull_cluster(map, cluster, nrows, ncols);
     }
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -21,50 +21,45 @@
     int x, y;
 } Position;
 
-typedef void (f_neighborhood) (DCELL max_dist);
-typedef void (f_index) ();
+typedef void (f_neighborhood) (DCELL max_dist, int fragcount);
+typedef void (f_index) (DCELL * values, int fragcount);
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* func.c */
-int get_dist_matrix();
-void f_nearest_neighbor(DCELL max_dist);
-void f_relative_neighbor(DCELL max_dist);
-void f_gabriel(DCELL max_dist);
-void f_spanning_tree(DCELL max_dist);
+int get_dist_matrix(int fragcount);
+void f_nearest_neighbor(DCELL max_dist, int fragcount);
+void f_relative_neighbor(DCELL max_dist, int fragcount);
+void f_gabriel(DCELL max_dist, int fragcount);
+void f_spanning_tree(DCELL max_dist, int fragcount);
 
-void f_connectance_index(DCELL * values);
-void f_gyration_radius(DCELL * values);
-void f_cohesion_index(DCELL * values);
-void f_percent_patches(DCELL * values);
-void f_percent_area(DCELL * values);
-void f_number_patches(DCELL * values);
-void f_number_links(DCELL * values);
-void f_mean_patch_size(DCELL * values);
-void f_largest_patch_size(DCELL * values);
-void f_largest_patch_diameter(DCELL * values);
-void f_graph_diameter_max(DCELL * values);
+void f_connectance_index(DCELL * values, int fragcount);
+void f_gyration_radius(DCELL * values, int fragcount);
+void f_cohesion_index(DCELL * values, int fragcount);
+void f_percent_patches(DCELL * values, int fragcount);
+void f_percent_area(DCELL * values, int fragcount);
+void f_number_patches(DCELL * values, int fragcount);
+void f_number_links(DCELL * values, int fragcount);
+void f_mean_patch_size(DCELL * values, int fragcount);
+void f_largest_patch_size(DCELL * values, int fragcount);
+void f_largest_patch_diameter(DCELL * values, int fragcount);
+void f_graph_diameter_max(DCELL * values, int fragcount);
 
-void FindClusters();
+void FindClusters(int fragcount);
 
 DCELL nearest_points(Coords ** frags, int n1, int n2, Coords * np1,
 		     Coords * np2);
 
 /* draw.c */
-void draw_line(int *map, int val, int x1, int y1, int x2, int y2, int sx,
-	       int sy, int width);
 void flood_fill(int *map, int val, int x, int y, int sx, int sy);
 
 /* hull.c */
-void convex_hull(int *map);
+void convex_hull(int *map, int nrows, int ncols);
 
 /* global variables */
-GLOBAL int nrows, ncols;
 GLOBAL Coords *cells;
 GLOBAL Coords **fragments;
-GLOBAL int fragcount;
-GLOBAL int *flagbuf;
 GLOBAL DCELL *distmatrix;
 GLOBAL int *adjmatrix;
 GLOBAL int *patches;

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.graph
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Graph Theory approach for connectivity analysis on patch level
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -65,11 +66,9 @@
 
 int main(int argc, char *argv[])
 {
-    /* result */
-    int exitres = 0;
-
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset;
+    char *newname, *oldname;
+    const char *oldmapset;
     char fullname[GNAME_MAX];
 
     /* in and out file pointers */
@@ -88,7 +87,8 @@
 
     /* helpers */
     char *p;
-    int row, col, i, j, m;
+    int nrows, ncols;
+    int row, col, i;
     int n;
     f_neighborhood *build_graph;
     f_index *calc_index;
@@ -97,6 +97,8 @@
     CELL *result;
     DCELL *d_res;
     CELL *clustermap;
+    int *flagbuf;
+    int fragcount;
 
     struct GModule *module;
     struct
@@ -110,12 +112,11 @@
 	struct Flag *adjacent, *quiet;
     } flag;
 
-    struct Cell_head ch, window;
 
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Graph Theory for connectivity analysis.");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -182,24 +183,23 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* get map type */
     map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
@@ -242,13 +242,13 @@
     fragments = (Coords **) G_malloc(nrows * ncols * sizeof(Coords *));
     fragments[0] = cells;
     flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
 
     G_message("Loading patches...");
 
     /* read map */
     for (row = 0; row < nrows; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
@@ -258,7 +258,7 @@
     }
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /*G_message("map");
        for(row = 0; row < nrows; row++) {
@@ -269,7 +269,7 @@
        } */
 
     /* find fragments */
-    writeFragments(flagbuf, nrows, ncols, nbr_count);
+    fragcount = writeFragments(flagbuf, nrows, ncols, nbr_count);
 
     /* allocate distance matrix */
     distmatrix = (DCELL *) G_malloc(fragcount * fragcount * sizeof(DCELL));
@@ -291,7 +291,7 @@
     memset(adjmatrix, 0, fragcount * fragcount * sizeof(int));
 
     build_graph = neighborhoods[neighborhood].method;
-    build_graph(distance);
+    build_graph(distance, fragcount);
 
     /* G_message("Adjacency matrix:");
        for(row = 0; row < fragcount; row++) {
@@ -305,7 +305,7 @@
     patches = (int *)G_malloc(fragcount * sizeof(int));
     clusters = (int **)G_malloc((fragcount + 1) * sizeof(int *));
 
-    FindClusters();
+    FindClusters(fragcount);
 
     /*for(i = 0; i < clustercount; i++) {
        fprintf(stderr, "Cluster_%d:", i);
@@ -318,7 +318,7 @@
     values = (DCELL *) G_malloc(clustercount * sizeof(DCELL));
 
     calc_index = indices[index].method;
-    calc_index(values);
+    calc_index(values, fragcount);
 
     /*      fprintf(stderr, "Results:");
        for(i = 0; i < clustercount; i++) {
@@ -334,16 +334,16 @@
        ================================== */
 
     /* open the new cellfile  */
-    out_fd = G_open_raster_new(newname, map_type);
+    out_fd = Rast_open_new(newname, map_type);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* allocate result row variable */
-    d_res = G_allocate_d_raster_buf();
+    d_res = Rast_allocate_d_buf();
 
     /* write values */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(d_res, ncols);
+	Rast_set_d_null_value(d_res, ncols);
 
 	for (i = 0; i < clustercount; i++) {
 	    for (curpos = clusters[i]; curpos < clusters[i + 1]; curpos++) {
@@ -358,13 +358,13 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(row + 1, 2 * nrows, 1);
     }
 
     /* close output file */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* ================================== 
        ==========  cluster map  ========= 
@@ -372,13 +372,13 @@
 
     /* open the new cellfile  */
     sprintf(fullname, "%s_clusters", newname);
-    out_fd = G_open_raster_new(fullname, CELL_TYPE);
+    out_fd = Rast_open_new(fullname, CELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* allocate and initialize the clustermap */
     clustermap = (CELL *) G_malloc(nrows * ncols * sizeof(CELL));
-    G_set_c_null_value(clustermap, nrows * ncols);
+    Rast_set_c_null_value(clustermap, nrows * ncols);
 
     /* for each cluster */
     for (i = 0; i < clustercount; i++) {
@@ -388,13 +388,13 @@
 	for (this = clusters[i]; this < clusters[i + 1]; this++) {
 	    /* for each cell in the patch */
 	    Coords *cell;
+	    int *other;
 
 	    for (cell = fragments[*this]; cell < fragments[*this + 1]; cell++) {
 		clustermap[cell->y * ncols + cell->x] = i;
 	    }
 
 	    /* for each patch in the cluster */
-	    int *other;
 
 	    for (other = clusters[i]; other < clusters[i + 1]; other++) {
 		if (*other != *this && adjmatrix[*this * fragcount + *other]) {
@@ -411,7 +411,7 @@
 
     /* write output */
     for (row = 0; row < nrows; row++) {
-	G_put_c_raster_row(out_fd, clustermap + row * ncols);
+	Rast_put_c_row(out_fd, clustermap + row * ncols);
 
 	G_percent(nrows + row + 1, 2 * nrows, 1);
     }
@@ -419,7 +419,7 @@
     /* G_free(clustermap); */
 
     /* close output file */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* ================================== 
        ==========  convex hull  ========= 
@@ -427,19 +427,19 @@
 
     /* open the new cellfile  */
     sprintf(fullname, "%s_hull", newname);
-    out_fd = G_open_raster_new(fullname, CELL_TYPE);
+    out_fd = Rast_open_new(fullname, CELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* clear the clustermap */
-    G_set_c_null_value(clustermap, nrows * ncols);
+    Rast_set_c_null_value(clustermap, nrows * ncols);
 
     /* calculate the convex hull */
-    convex_hull(clustermap);
+    convex_hull(clustermap, nrows, ncols);
 
     /* write output */
     for (row = 0; row < nrows; row++) {
-	G_put_c_raster_row(out_fd, clustermap + row * ncols);
+	Rast_put_c_row(out_fd, clustermap + row * ncols);
 
 	G_percent(nrows + row + 1, 2 * nrows, 1);
     }
@@ -447,7 +447,7 @@
     G_free(clustermap);
 
     /* close output file */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* =====================
        ==== free memory ====

Copied: grass-addons/grass7/raster/r.pi/r.pi.graph/r.pi.graph.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.graph/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/r.pi.graph.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/r.pi.graph.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,53 @@
+<h2>DESCRIPTION</h2>
+
+Graph Theory for connectivity analysis. 
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset using class 5 (forest):
+
+Computing a graph of all patches (4 neighbourhood rule) using a maximum distance of 10 pixel, the Gabriel method and as resulting index the <em> largest patch diameter</em>:
+<div class="code"><pre>
+r.pi.graph input=landclass96 output=landclass96_graph keyval=5 distance=10 neighborhood=gabriel index=largest_patch_diameter
+</pre></div>
+
+the results are 2 files:
+landclass96_graph: the information of the index are provided (here a range of 3-589 of patch diameter)
+landclass96_graph_clusters: the generated cluster IDs are provided (here 16 clusters are identified), doing it with a distance of 5 pixel is resulting in a total of 66 cluster.
+
+
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/choice.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/choice.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/choice.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -19,7 +19,6 @@
 
 	for (i = 0; i < cluster.count; i++) {
 	    int patch_index = cluster.first_patch[i];
-
 	    int area = fragments[patch_index].count;
 
 	    if (area < min_area) {
@@ -55,7 +54,6 @@
 
 	for (i = 0; i < cluster.count; i++) {
 	    int patch_index = cluster.first_patch[i];
-
 	    int area = fragments[patch_index].count;
 
 	    if (area > max_area) {
@@ -83,7 +81,7 @@
     int end = cluster_index >= 0 ? cluster_index : cluster_count - 1;
 
     int patchcount = 0;
-    int c;
+    int r, c;
 
     for (c = begin; c <= end; c++) {
 	Cluster cluster = cluster_list[c];
@@ -91,13 +89,13 @@
 	patchcount += cluster.count;
     }
 
-    int r = rand() % patchcount;
+    r = rand() % patchcount;
 
     for (c = begin; c <= end; c++) {
-	Cluster cluster = cluster_list[c];
-
 	int i;
 
+	Cluster cluster = cluster_list[c];
+
 	for (i = 0; i < cluster.count; i++) {
 	    if (r == 0) {
 		if (cluster_index < 0) {
@@ -129,15 +127,14 @@
     int c;
 
     for (c = begin; c <= end; c++) {
-	Cluster cluster = cluster_list[c];
-
 	int i;
 
-	for (i = 0; i < cluster.count; i++) {
-	    int patch_index = cluster.first_patch[i];
+	Cluster cluster = cluster_list[c];
 
+	for (i = 0; i < cluster.count; i++) {
 	    int links = 0;
 	    int j;
+	    int patch_index = cluster.first_patch[i];
 
 	    for (j = 0; j < fragcount; j++) {
 		if (adjacency_matrix[patch_index * fragcount + j]) {
@@ -173,15 +170,14 @@
     int c;
 
     for (c = begin; c <= end; c++) {
-	Cluster cluster = cluster_list[c];
-
 	int i;
 
-	for (i = 0; i < cluster.count; i++) {
-	    int patch_index = cluster.first_patch[i];
+	Cluster cluster = cluster_list[c];
 
+	for (i = 0; i < cluster.count; i++) {
 	    int links = 0;
 	    int j;
+	    int patch_index = cluster.first_patch[i];
 
 	    for (j = 0; j < fragcount; j++) {
 		if (adjacency_matrix[patch_index * fragcount + j]) {

Deleted: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,46 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Graph Theory - successive criteria-based deletion of patches. 
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -98,17 +98,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,14 +135,14 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return curpos;
 }
 
 int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
 		   int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
     int fragcount = 0;
 
     /* find fragments */

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -17,15 +17,15 @@
     int p1, p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n1].count; p1++) {
 	Coords *c1 = frags[n1].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = 0; p2 < frags[n2].count; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		Coords *c2 = frags[n2].first_cell + p2;
 
 		if (c2->neighbors < 4) {
@@ -38,6 +38,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -47,17 +48,17 @@
     int p1, p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n1].count; p1++) {
 	Coords *c1 = frags[n1].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = 0; p2 < frags[n2].count; p2++) {
 		Coords *c2 = frags[n2].first_cell + p2;
 
-		// if cell at the border
+		/* if cell at the border */
 		if (c2->neighbors < 4) {
 		    DCELL d = dist(c1, c2);
 
@@ -70,6 +71,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -79,11 +81,11 @@
     int p;
     DCELL min = MAX_DOUBLE;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p = 0; p < frags[patch].count; p++) {
 	Coords *cell = frags[patch].first_cell + p;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (cell->neighbors < 4) {
 	    DCELL dx = loc_x - cell->x;
 	    DCELL dy = loc_y - cell->y;
@@ -94,6 +96,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -135,12 +138,15 @@
 		  int *curpos, int *flag_arr)
 {
     int i;
-    int *p;
-    int list[fragcount];
-    int *first = list;
-    int *last = list + 1;
+    int *list;
+    int *first;
+    int *last;
     int offset;
 
+    list = G_malloc(fragcount * sizeof(int));
+    first = list;
+    last = list + 1;
+
     list[0] = patch;
     flag_arr[patch] = 1;
 
@@ -163,6 +169,8 @@
 	first++;
     }
 
+    G_free(list);
+
     return curpos;
 }
 
@@ -170,15 +178,13 @@
 		  int fragcount)
 {
     int i;
-
     int count = 0;
+    int *flag_arr;
+    int *curpos = cluster_list[0].first_patch;
 
-    int flag_arr[fragcount];
-
+    flag_arr = G_malloc(fragcount * sizeof(int));
     memset(flag_arr, 0, fragcount * sizeof(int));
 
-    int *curpos = cluster_list[0].first_patch;
-
     for (i = 0; i < fragcount; i++) {
 	if (flag_arr[i] == 0) {
 	    cluster_list[count].first_patch = curpos;
@@ -202,6 +208,8 @@
        fprintf(stderr, "\n");
        } */
 
+    G_free(flag_arr);
+
     return count;
 }
 
@@ -306,12 +314,15 @@
 		     DCELL max_dist)
 {
     int i, j;
-    int parents[fragcount];
-    DCELL distances[fragcount];
+    int *parents;
+    DCELL *distances;
     int curmin;
     int nextmin = 0;
     int parent;
 
+    parents = G_malloc(fragcount * sizeof(int));
+    distances = G_malloc(fragcount * sizeof(DCELL));
+
     /* init parents and distances list */
     for (i = 0; i < fragcount; i++) {
 	parents[i] = -1;
@@ -338,13 +349,13 @@
 
 	/* find the next node for minimum spanning tree */
 	for (j = 0; j < fragcount; j++) {
+	    /* get distance to the current minimum node */
+	    DCELL dist = distmatrix[curmin * fragcount + j];
+
 	    /* skip the current minimum node */
 	    if (j == curmin)
 		continue;
 
-	    /* get distance to the current minimum node */
-	    DCELL dist = distmatrix[curmin * fragcount + j];
-
 	    /* if this distance is smaller than the stored one */
 	    /* then set a new distance and update parent list  */
 	    if (dist < distances[j]) {
@@ -359,6 +370,9 @@
 	    }
 	}
     }
+
+    G_free(parents);
+    G_free(distances);
 }
 
 /*********************************
@@ -375,7 +389,6 @@
     /* for each cluster */
     for (i = 0; i < cluster_count; i++) {
 	int n = cluster_list[i].count;
-	DCELL c = 100.0 / (n * (n - 1) * 0.5);
 	DCELL val = 0;
 
 	/* no patches are 0% connected */
@@ -457,7 +470,6 @@
 
     /* for each cluster */
     for (i = 0; i < cluster_count; i++) {
-	int n = cluster_list[i].count;
 	int total_area = 0;
 	DCELL num = 0.0;
 	DCELL denom = 0.0;
@@ -513,8 +525,7 @@
 		    DCELL * distmatrix)
 {
     int i;
-    int *p, *q;
-    Coords *cell;
+    int *p;
 
     int area_all = 0;
 
@@ -635,17 +646,17 @@
     int p1, p2;
     DCELL max = 0.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n].count; p1++) {
 	Coords *c1 = frags[n].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = p1 + 1; p2 < frags[n].count; p2++) {
 		Coords *c2 = frags[n].first_cell + p2;
 
-		// if cell at the border
+		/* if cell at the border */
 		if (c2->neighbors < 4) {
 		    DCELL d = dist(c1, c2);
 
@@ -692,15 +703,14 @@
 			  DCELL * distmatrix)
 {
     int i, j, k;
+    DCELL *pathmatrix;
 
     /* initialize path matrix */
-    DCELL pathmatrix[fragcount * fragcount * sizeof(DCELL)];
+    pathmatrix = G_malloc(fragcount * fragcount * sizeof(DCELL));
 
     for (i = 0; i < fragcount; i++) {
 	pathmatrix[i * fragcount + i] = 0.0;
 
-	int j;
-
 	for (j = i + 1; j < fragcount; j++) {
 	    int index = i * fragcount + j;
 	    int index_mirror = j * fragcount + i;
@@ -760,4 +770,6 @@
 
 	values[i] = max_dist;
     }
+
+    G_free(pathmatrix);
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -119,6 +119,5 @@
 	       DCELL * distmatrix);
 
 /* global variables */
-GLOBAL int nrows, ncols;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.graph.dec
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Graph Theory approach for connectivity analysis on patch 
  *                      level - successive removal of patches based on defined criteria
  *
@@ -84,11 +85,9 @@
 
 int main(int argc, char *argv[])
 {
-    /* result */
-    int exitres = 0;
-
     /* input */
-    char *oldname, *oldmapset, *newname, *newmapset, *idname, *idmapset;
+    char *oldname, *newname, *idname;
+    const char *oldmapset;
     char fullname[GNAME_MAX];
 
     /* in and out file pointers */
@@ -104,20 +103,31 @@
     int choice;
     DCELL distance;
 
-    /* map_type and categories */
-    RASTER_MAP_TYPE map_type;
-
     /* helpers */
     char *p;
-    int row, col, i, j, m;
+    int nrows, ncols;
+    int row, col, i;
     int n;
     f_neighborhood *build_graph;
     f_index *calc_index;
     f_choice *choose_patch;
-    int *curpos;
     CELL *result;
     DCELL *d_res;
     CELL *clustermap;
+    int seed;
+    int *flagbuf;
+    int fragcount;
+    DCELL *distmatrix;
+    int *adjmatrix;
+    int *patches;
+    int clustercount;
+    DCELL *values, *cur_values;
+    int *patch_notes;
+    int *cluster_notes;
+    int cur_pos;
+    Cluster *clusters;
+    Coords *cells;
+    Patch *fragments;
 
     struct GModule *module;
     struct
@@ -132,12 +142,10 @@
 	struct Flag *adjacent, *landscape;
     } flag;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Graph Theory - successive criteria-based deletion of patches.");
 
@@ -238,35 +246,30 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* check if the id raster file name is correct */
     idname = parm.id->answer;
     if (G_legal_filename(idname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), idname);
-    idmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), idname);
 
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
-    G_message("rows = %d, cols = %d", nrows, ncols);
+    G_debug(1, "rows = %d, cols = %d", nrows, ncols);
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
-    /* get map type */
-    map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
-
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
 
@@ -309,7 +312,7 @@
     nbr_count = flag.adjacent->answer ? 8 : 4;
 
     /* set random seed */
-    int seed = time(NULL);
+    seed = time(NULL);
 
     if (parm.seed->answer) {
 	sscanf(parm.seed->answer, "%d", &seed);
@@ -317,19 +320,19 @@
     srand(seed);
 
     /* allocate the cell buffers */
-    Coords *cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
-    Patch *fragments = (Patch *) G_malloc(nrows * ncols * sizeof(Patch));
+    cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
+    fragments = (Patch *) G_malloc(nrows * ncols * sizeof(Patch));
 
     fragments[0].first_cell = cells;
-    int *flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
+    flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
 
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
 
     G_message("Loading patches...");
 
     /* read map */
     for (row = 0; row < nrows; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
@@ -339,7 +342,7 @@
     }
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /*G_message("map");
        for(row = 0; row < nrows; row++) {
@@ -350,11 +353,11 @@
        } */
 
     /* find fragments */
-    int fragcount =
+    fragcount =
 	writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
 
     /* allocate distance matrix */
-    DCELL *distmatrix =
+    distmatrix =
 	(DCELL *) G_malloc(fragcount * fragcount * sizeof(DCELL));
     memset(distmatrix, 0, fragcount * fragcount * sizeof(DCELL));
 
@@ -370,7 +373,7 @@
        } */
 
     /* build adjacency matrix */
-    int *adjmatrix = (int *)G_malloc(fragcount * fragcount * sizeof(int));
+    adjmatrix = (int *)G_malloc(fragcount * fragcount * sizeof(int));
 
     memset(adjmatrix, 0, fragcount * fragcount * sizeof(int));
 
@@ -386,12 +389,12 @@
        } */
 
     /* find clusters */
-    int *patches = (int *)G_malloc(fragcount * sizeof(int));
-    Cluster *clusters = (Cluster *) G_malloc((fragcount) * sizeof(Cluster));
+    patches = (int *)G_malloc(fragcount * sizeof(int));
+    clusters = (Cluster *) G_malloc((fragcount) * sizeof(Cluster));
 
     clusters[0].first_patch = patches;
 
-    int clustercount = find_clusters(clusters, adjmatrix, fragcount);
+    clustercount = find_clusters(clusters, adjmatrix, fragcount);
 
     /*for(i = 0; i < clustercount; i++) {
        fprintf(stderr, "Cluster_%d:", i);
@@ -402,10 +405,10 @@
        } */
 
     /* values: Before Deletion(cluster1, cluster2, ...), After First Deletion(...), After Second Deletion(...), ... */
-    DCELL *values =
+    values =
 	(DCELL *) G_malloc((fragcount + 1) * clustercount * sizeof(DCELL));
-    int *patch_notes = (int *)G_malloc(fragcount * sizeof(int));
-    int *cluster_notes = (int *)G_malloc(fragcount * sizeof(int));
+    patch_notes = (int *)G_malloc(fragcount * sizeof(int));
+    cluster_notes = (int *)G_malloc(fragcount * sizeof(int));
 
     calc_index = indices[index].method;
     choose_patch = choices[choice].method;
@@ -419,13 +422,13 @@
 
 	/* open the new cellfile */
 	sprintf(fullname, "%s_clusters", idname);
-    out_fd = G_open_raster_new(fullname, CELL_TYPE);
-    if (out_fd < 0)
+	out_fd = Rast_open_new(fullname, CELL_TYPE);
+	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), fullname);
 
 	/* allocate and initialize the clustermap */
 	clustermap = (CELL *) G_malloc(nrows * ncols * sizeof(CELL));
-	G_set_c_null_value(clustermap, nrows * ncols);
+	Rast_set_c_null_value(clustermap, nrows * ncols);
 
 	/* for each cluster */
 	for (i = 0; i < clustercount; i++) {
@@ -436,6 +439,7 @@
 		 this < clusters[i].first_patch + clusters[i].count; this++) {
 		/* for each cell in the patch */
 		int cell_index;
+		int *other;
 
 		for (cell_index = 0; cell_index < fragments[*this].count;
 		     cell_index++) {
@@ -445,7 +449,6 @@
 		}
 
 		/* for each patch in the cluster */
-		int *other;
 
 		for (other = this + 1;
 		     other < clusters[i].first_patch + clusters[i].count;
@@ -465,33 +468,33 @@
 
 	/* write output */
 	for (row = 0; row < nrows; row++) {
-	    G_put_c_raster_row(out_fd, clustermap + row * ncols);
+	    Rast_put_c_row(out_fd, clustermap + row * ncols);
 	}
 
 	G_free(clustermap);
 
 	/* close output file */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
 	/* ================================== 
 	   ============  id raster  ============
 	   ================================== */
 
 	/* allocate result row variable */
-	d_res = G_allocate_d_raster_buf();
+	d_res = Rast_allocate_d_buf();
 
 	/* open new cellfile  */
 	sprintf(fullname, "%s_id", idname);
-    out_fd = G_open_raster_new(fullname, CELL_TYPE);
-    if (out_fd < 0)
+	out_fd = Rast_open_new(fullname, CELL_TYPE);
+	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), fullname);
 
 	/* write the output file */
 	for (row = 0; row < nrows; row++) {
-	    G_set_d_null_value(d_res, ncols);
-
 	    int patch_index;
 
+	    Rast_set_d_null_value(d_res, ncols);
+
 	    for (patch_index = 0; patch_index < fragcount; patch_index++) {
 		int cell_index;
 
@@ -506,14 +509,14 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 	}
 
 	/* free result row */
 	G_free(d_res);
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* calculate indices once before deletion */
@@ -528,8 +531,8 @@
 
     G_message("Performing iterative deletion...");
 
-    DCELL *cur_values = values + clustercount;
-    int cur_pos = 0;
+    cur_values = values + clustercount;
+    cur_pos = 0;
 
     if (flag.landscape->answer) {	/* landscape wide deletion */
 	/* for each patch */
@@ -540,17 +543,17 @@
 			     fragcount, distmatrix);
 
 	    /* find the appropriate cluster */
-	    int j;
+	    int j, k;
 	    int cluster = -1;
 	    int rel_patch;
 
 	    for (j = 0; j < clustercount; j++) {
-		int p;
+		int m;
 
-		for (p = 0; p < clusters[j].count; p++) {
-		    if (clusters[j].first_patch[p] == patch) {
+		for (m = 0; m < clusters[j].count; m++) {
+		    if (clusters[j].first_patch[m] == patch) {
 			cluster = j;
-			rel_patch = p;
+			rel_patch = m;
 			break;
 		    }
 		}
@@ -572,7 +575,6 @@
 	    clusters[cluster].count--;
 
 	    /* and from the adjacency matrix */
-	    int k;
 
 	    for (k = 0; k < fragcount; k++) {
 		adjmatrix[k * fragcount + patch] = 0;
@@ -588,7 +590,7 @@
     else {
 	/* for each cluster */
 	for (i = 0; i < clustercount; i++) {
-	    int j;
+	    int j, k;
 
 	    /* patch count times do */
 	    int count = clusters[i].count;
@@ -617,7 +619,6 @@
 		clusters[i].count--;
 
 		/* and from the adjacency matrix */
-		int k;
 
 		for (k = 0; k < fragcount; k++) {
 		    adjmatrix[k * fragcount + real_patch] = 0;
@@ -669,13 +670,12 @@
     for (i = 0; i < fragcount + 1; i++) {
 	int cluster = i > 0 ? cluster_notes[i - 1] : -1;
 	int patch = i > 0 ? patch_notes[i - 1] : -1;
+	int j;
 
 	fprintf(out_fp, "%d %d", cluster, patch);
 
-	int j;
-
 	for (j = 0; j < clustercount; j++) {
-	    fprintf(out_fp, " %lf", values[i * clustercount + j]);
+	    fprintf(out_fp, " %f", values[i * clustercount + j]);
 	}
 
 	if (i > 0 && cluster >= 0) {
@@ -687,7 +687,7 @@
 	    DCELL change_pr = change / oldval * 100.0;
 	    DCELL change_from_init = change / initval * 100.0;
 
-	    fprintf(out_fp, " %lf %lf %lf", change, change_pr,
+	    fprintf(out_fp, " %f %f %f", change, change_pr,
 		    change_from_init);
 	}
 	else {

Copied: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/r.pi.graph.dec.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.graph.dec/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/r.pi.graph.dec.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/r.pi.graph.dec.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,46 @@
+<h2>DESCRIPTION</h2>
+
+Graph Theory - successive criteria-based deletion of patches. 
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,46 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Graph Theory - iterative removal (patch relevance analysis).
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -98,17 +98,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,14 +135,14 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return curpos;
 }
 
 int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
 		   int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
     int fragcount = 0;
 
     /* find fragments */

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -17,15 +17,15 @@
     int p1, p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n1].count; p1++) {
 	Coords *c1 = frags[n1].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = 0; p2 < frags[n2].count; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		Coords *c2 = frags[n2].first_cell + p2;
 
 		if (c2->neighbors < 4) {
@@ -38,6 +38,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -47,17 +48,17 @@
     int p1, p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n1].count; p1++) {
 	Coords *c1 = frags[n1].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = 0; p2 < frags[n2].count; p2++) {
 		Coords *c2 = frags[n2].first_cell + p2;
 
-		// if cell at the border
+		/* if cell at the border */
 		if (c2->neighbors < 4) {
 		    DCELL d = dist(c1, c2);
 
@@ -70,6 +71,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -79,11 +81,11 @@
     int p;
     DCELL min = MAX_DOUBLE;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p = 0; p < frags[patch].count; p++) {
 	Coords *cell = frags[patch].first_cell + p;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (cell->neighbors < 4) {
 	    DCELL dx = loc_x - cell->x;
 	    DCELL dy = loc_y - cell->y;
@@ -94,6 +96,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -135,12 +138,15 @@
 		  int *curpos, int *flag_arr)
 {
     int i;
-    int *p;
-    int list[fragcount];
-    int *first = list;
-    int *last = list + 1;
+    int *list;
+    int *first;
+    int *last;
     int offset;
 
+    list = G_malloc(fragcount * sizeof(int));
+    first = list;
+    last = list + 1;
+
     list[0] = patch;
     flag_arr[patch] = 1;
 
@@ -163,6 +169,8 @@
 	first++;
     }
 
+    G_free(list);
+
     return curpos;
 }
 
@@ -170,15 +178,13 @@
 		  int fragcount)
 {
     int i;
-
     int count = 0;
+    int *flag_arr;
+    int *curpos = cluster_list[0].first_patch;
 
-    int flag_arr[fragcount];
-
+    flag_arr = G_malloc(fragcount * sizeof(int));
     memset(flag_arr, 0, fragcount * sizeof(int));
 
-    int *curpos = cluster_list[0].first_patch;
-
     for (i = 0; i < fragcount; i++) {
 	if (flag_arr[i] == 0) {
 	    cluster_list[count].first_patch = curpos;
@@ -202,6 +208,8 @@
        fprintf(stderr, "\n");
        } */
 
+    G_free(flag_arr);
+
     return count;
 }
 
@@ -306,12 +314,15 @@
 		     DCELL max_dist)
 {
     int i, j;
-    int parents[fragcount];
-    DCELL distances[fragcount];
+    int *parents;
+    DCELL *distances;
     int curmin;
     int nextmin = 0;
     int parent;
 
+    parents = G_malloc(fragcount * sizeof(int));
+    distances = G_malloc(fragcount * sizeof(DCELL));
+
     /* init parents and distances list */
     for (i = 0; i < fragcount; i++) {
 	parents[i] = -1;
@@ -338,13 +349,13 @@
 
 	/* find the next node for minimum spanning tree */
 	for (j = 0; j < fragcount; j++) {
+	    /* get distance to the current minimum node */
+	    DCELL dist = distmatrix[curmin * fragcount + j];
+
 	    /* skip the current minimum node */
 	    if (j == curmin)
 		continue;
 
-	    /* get distance to the current minimum node */
-	    DCELL dist = distmatrix[curmin * fragcount + j];
-
 	    /* if this distance is smaller than the stored one */
 	    /* then set a new distance and update parent list  */
 	    if (dist < distances[j]) {
@@ -359,6 +370,9 @@
 	    }
 	}
     }
+
+    G_free(parents);
+    G_free(distances);
 }
 
 /*********************************
@@ -375,7 +389,6 @@
     /* for each cluster */
     for (i = 0; i < cluster_count; i++) {
 	int n = cluster_list[i].count;
-	DCELL c = 100.0 / (n * (n - 1) * 0.5);
 	DCELL val = 0;
 
 	/* single patch is 100% connected */
@@ -451,7 +464,6 @@
 
     /* for each cluster */
     for (i = 0; i < cluster_count; i++) {
-	int n = cluster_list[i].count;
 	int total_area = 0;
 	DCELL num = 0.0;
 	DCELL denom = 0.0;
@@ -507,8 +519,7 @@
 		    DCELL * distmatrix)
 {
     int i;
-    int *p, *q;
-    Coords *cell;
+    int *p;
 
     int area_all = 0;
 
@@ -629,17 +640,17 @@
     int p1, p2;
     DCELL max = 0.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n].count; p1++) {
 	Coords *c1 = frags[n].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = p1 + 1; p2 < frags[n].count; p2++) {
 		Coords *c2 = frags[n].first_cell + p2;
 
-		// if cell at the border
+		/* if cell at the border */
 		if (c2->neighbors < 4) {
 		    DCELL d = dist(c1, c2);
 
@@ -686,15 +697,14 @@
 			  DCELL * distmatrix)
 {
     int i, j, k;
+    DCELL *pathmatrix;
 
     /* initialize path matrix */
-    DCELL pathmatrix[fragcount * fragcount * sizeof(DCELL)];
+    pathmatrix = G_malloc(fragcount * fragcount * sizeof(DCELL));
 
     for (i = 0; i < fragcount; i++) {
 	pathmatrix[i * fragcount + i] = 0.0;
 
-	int j;
-
 	for (j = i + 1; j < fragcount; j++) {
 	    int index = i * fragcount + j;
 	    int index_mirror = j * fragcount + i;
@@ -754,4 +764,6 @@
 
 	values[i] = max_dist;
     }
+
+    G_free(pathmatrix);
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -99,7 +99,4 @@
 void draw_line(int *map, int val, int x1, int y1, int x2, int y2, int sx,
 	       int sy, int width);
 
-/* global variables */
-GLOBAL int nrows, ncols;
-
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.graph.iter
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Graph Theory approach for connectivity analysis on patch 
  *                              level - iterative patch removal option (patch relevance)
  *
@@ -68,11 +69,9 @@
 
 int main(int argc, char *argv[])
 {
-    /* result */
-    int exitres = 0;
-
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset;
+    char *newname, *oldname;
+    const char *oldmapset;
     char fullname[GNAME_MAX];
 
     /* in and out file pointers */
@@ -91,7 +90,8 @@
 
     /* helpers */
     char *p;
-    int row, col, i, j, m;
+    int nrows, ncols;
+    int row, col, i;
     int n;
     f_neighborhood *build_graph;
     f_index *calc_index;
@@ -99,6 +99,17 @@
     CELL *result;
     DCELL *d_res;
     CELL *clustermap;
+    Coords *cells;
+    Patch *fragments;
+    int *flagbuf;
+    int fragcount;
+    DCELL *distmatrix;
+    int *adjmatrix;
+    int *patches;
+    Cluster *clusters;
+    int clustercount;
+    DCELL *values, *ref_values, *temp_values;
+    int *splitter_patches;
 
     struct GModule *module;
     struct
@@ -112,12 +123,10 @@
 	struct Flag *adjacent, *percent;
     } flag;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Graph Theory - iterative removal (patch relevance analysis).");
 
@@ -190,25 +199,24 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     G_message("rows = %d, cols = %d", nrows, ncols);
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* get map type */
     map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
@@ -246,19 +254,19 @@
     nbr_count = flag.adjacent->answer ? 8 : 4;
 
     /* allocate the cell buffers */
-    Coords *cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
-    Patch *fragments = (Patch *) G_malloc(nrows * ncols * sizeof(Patch));
+    cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
+    fragments = (Patch *) G_malloc(nrows * ncols * sizeof(Patch));
 
     fragments[0].first_cell = cells;
-    int *flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
+    flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
 
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
 
     G_message("Loading patches...");
 
     /* read map */
     for (row = 0; row < nrows; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
@@ -268,7 +276,7 @@
     }
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /*G_message("map");
        for(row = 0; row < nrows; row++) {
@@ -279,11 +287,11 @@
        } */
 
     /* find fragments */
-    int fragcount =
+    fragcount =
 	writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
 
     /* allocate distance matrix */
-    DCELL *distmatrix =
+    distmatrix =
 	(DCELL *) G_malloc(fragcount * fragcount * sizeof(DCELL));
     memset(distmatrix, 0, fragcount * fragcount * sizeof(DCELL));
 
@@ -299,7 +307,7 @@
        } */
 
     /* build adjacency matrix */
-    int *adjmatrix = (int *)G_malloc(fragcount * fragcount * sizeof(int));
+    adjmatrix = (int *)G_malloc(fragcount * fragcount * sizeof(int));
 
     memset(adjmatrix, 0, fragcount * fragcount * sizeof(int));
 
@@ -315,12 +323,12 @@
        } */
 
     /* find clusters */
-    int *patches = (int *)G_malloc(fragcount * sizeof(int));
-    Cluster *clusters = (Cluster *) G_malloc((fragcount) * sizeof(Cluster));
+    patches = (int *)G_malloc(fragcount * sizeof(int));
+    clusters = (Cluster *) G_malloc((fragcount) * sizeof(Cluster));
 
     clusters[0].first_patch = patches;
 
-    int clustercount = find_clusters(clusters, adjmatrix, fragcount);
+    clustercount = find_clusters(clusters, adjmatrix, fragcount);
 
     /*for(i = 0; i < clustercount; i++) {
        fprintf(stderr, "Cluster_%d:", i);
@@ -330,10 +338,10 @@
        fprintf(stderr, "\n");
        } */
 
-    DCELL *values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
+    values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
 
-    DCELL *ref_values = (DCELL *) G_malloc(clustercount * sizeof(DCELL));
-    DCELL *temp_values = (DCELL *) G_malloc(clustercount * sizeof(DCELL));
+    ref_values = (DCELL *) G_malloc(clustercount * sizeof(DCELL));
+    temp_values = (DCELL *) G_malloc(clustercount * sizeof(DCELL));
 
     calc_index = indices[index].method;
     calc_index(ref_values, clusters, clustercount, adjmatrix, fragments,
@@ -346,14 +354,23 @@
        fprintf(stderr, "\n"); */
 
     /* perform iterative deletion analysis */
-    int *splitter_patches = (int *)G_malloc(fragcount * sizeof(int));
+    splitter_patches = (int *)G_malloc(fragcount * sizeof(int));
 
     memset(splitter_patches, 0, fragcount * sizeof(int));
 
     /* for each patch */
     G_message("Performing iterative deletion...");
     for (i = 0; i < fragcount; i++) {
+	DCELL *temp_distm;
 	int temp_fragcount = fragcount - 1;
+	int p1, p2;
+	int tp1 = 0;
+	int *temp_adjm;
+	int *temp_p;
+	Cluster *temp_c;
+	int temp_cc;
+	int c;
+	int focal_cluster;
 
 	/* delete i-th patch... */
 
@@ -366,15 +383,12 @@
 	       (fragcount - i - 1) * sizeof(Patch));
 
 	/* from distance matrix */
-	DCELL *temp_distm =
+	temp_distm =
 	    (DCELL *) G_malloc(temp_fragcount * temp_fragcount *
 			       sizeof(DCELL));
 	memset(temp_distm, 0,
 	       temp_fragcount * temp_fragcount * sizeof(DCELL));
 
-	int p1, p2;
-	int tp1 = 0;
-
 	for (p1 = 0; p1 < fragcount; p1++) {
 	    if (p1 != i) {
 		int tp2 = 0;
@@ -400,7 +414,7 @@
 	}
 
 	/* build graph and see if the cluster is splitted */
-	int *temp_adjm = (int *)G_malloc(fragcount * fragcount * sizeof(int));
+	temp_adjm = (int *)G_malloc(fragcount * fragcount * sizeof(int));
 
 	memset(temp_adjm, 0, fragcount * fragcount * sizeof(int));
 
@@ -414,12 +428,12 @@
 	   fprintf(stderr, "\n");
 	   } */
 
-	int *temp_p = (int *)G_malloc(fragcount * sizeof(int));
-	Cluster *temp_c = (Cluster *) G_malloc(fragcount * sizeof(Cluster));
+	temp_p = (int *)G_malloc(fragcount * sizeof(int));
+	temp_c = (Cluster *) G_malloc(fragcount * sizeof(Cluster));
 
 	temp_c[0].first_patch = temp_p;
 
-	int temp_cc = find_clusters(temp_c, temp_adjm, temp_fragcount);
+	temp_cc = find_clusters(temp_c, temp_adjm, temp_fragcount);
 
 	/* G_message("Clustercount = %d", temp_cc); */
 
@@ -434,8 +448,6 @@
 	/* from adjacency matrix */
 	memcpy(temp_adjm, adjmatrix, fragcount * fragcount * sizeof(int));
 
-	int index;
-
 	for (index = 0; index < fragcount; index++) {
 	    temp_adjm[index * fragcount + i] = 0;
 	    temp_adjm[i * fragcount + index] = 0;
@@ -452,15 +464,15 @@
 	/* from cluster list */
 
 	/* for each cluster */
-	int c;
-	int focal_cluster = -1;
-	int *curpos = temp_p;
+	focal_cluster = -1;
+	curpos = temp_p;
 
 	for (c = 0; c < clustercount; c++) {
+	    int *patch;
+
 	    temp_c[c].first_patch = curpos;
 
 	    /* for each patch in the cluster */
-	    int *patch;
 
 	    for (patch = clusters[c].first_patch;
 		 patch < clusters[c].first_patch + clusters[c].count;
@@ -524,19 +536,19 @@
        ================================== */
 
     /* open the new cellfile  */
-    out_fd = G_open_raster_new(newname, map_type);
+    out_fd = Rast_open_new(newname, map_type);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* allocate result row variable */
-    d_res = G_allocate_d_raster_buf();
+    d_res = Rast_allocate_d_buf();
 
     /* write values */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(d_res, ncols);
-
 	int patch_index;
 
+	Rast_set_d_null_value(d_res, ncols);
+
 	for (patch_index = 0; patch_index < fragcount; patch_index++) {
 	    int cell_index;
 
@@ -550,27 +562,24 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(row + 1, 2 * nrows, 1);
     }
 
     /* close output file */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* write splitter patch map */
     /* open the new cellfile  */
     sprintf(fullname, "%s_split", newname);
-    out_fd = G_open_raster_new(fullname, CELL_TYPE);
+    out_fd = Rast_open_new(fullname, CELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), fullname);
+	G_fatal_error(_("Cannot create raster map <%s>"), fullname);
 
-    /* allocate result row variable */
-    d_res = G_allocate_d_raster_buf();
-
     /* write values */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(d_res, ncols);
+	Rast_set_d_null_value(d_res, ncols);
 
 	for (i = 0; i < clustercount; i++) {
 	    for (curpos = clusters[i].first_patch;
@@ -590,13 +599,13 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(row + 1, 2 * nrows, 1);
     }
 
     /* close output file */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* ================================== 
        ==========  cluster map  ========= 
@@ -604,13 +613,13 @@
 
     /* open the new cellfile */
     sprintf(fullname, "%s_clusters", newname);
-    out_fd = G_open_raster_new(fullname, CELL_TYPE);
+    out_fd = Rast_open_new(fullname, CELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), fullname);
+	G_fatal_error(_("Cannot create raster map <%s>"), fullname);
 
     /* allocate and initialize the clustermap */
     clustermap = (CELL *) G_malloc(nrows * ncols * sizeof(CELL));
-    G_set_c_null_value(clustermap, nrows * ncols);
+    Rast_set_c_null_value(clustermap, nrows * ncols);
 
     /* for each cluster */
     for (i = 0; i < clustercount; i++) {
@@ -621,6 +630,7 @@
 	     this < clusters[i].first_patch + clusters[i].count; this++) {
 	    /* for each cell in the patch */
 	    int cell_index;
+	    int *other;
 
 	    for (cell_index = 0; cell_index < fragments[*this].count;
 		 cell_index++) {
@@ -630,8 +640,6 @@
 	    }
 
 	    /* for each patch in the cluster */
-	    int *other;
-
 	    for (other = this + 1;
 		 other < clusters[i].first_patch + clusters[i].count;
 		 other++) {
@@ -649,7 +657,7 @@
 
     /* write output */
     for (row = 0; row < nrows; row++) {
-	G_put_c_raster_row(out_fd, clustermap + row * ncols);
+	Rast_put_c_row(out_fd, clustermap + row * ncols);
 
 	G_percent(nrows + row + 1, 2 * nrows, 1);
     }
@@ -657,7 +665,7 @@
     G_free(clustermap);
 
     /* close output file */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
 
     /* =============================

Copied: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/r.pi.graph.iter.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.graph.iter/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/r.pi.graph.iter.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/r.pi.graph.iter.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,46 @@
+<h2>DESCRIPTION</h2>
+
+Graph Theory - iterative removal (patch relevance analysis).
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.red/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.graph.red/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,46 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Graph Theory - decreasing distance threshold option. 
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.red/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -98,17 +98,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,14 +135,14 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return curpos;
 }
 
 int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
 		   int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
     int fragcount = 0;
 
     /* find fragments */

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.red/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -17,15 +17,15 @@
     int p1, p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n1].count; p1++) {
 	Coords *c1 = frags[n1].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = 0; p2 < frags[n2].count; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		Coords *c2 = frags[n2].first_cell + p2;
 
 		if (c2->neighbors < 4) {
@@ -38,6 +38,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -47,17 +48,17 @@
     int p1, p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n1].count; p1++) {
 	Coords *c1 = frags[n1].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = 0; p2 < frags[n2].count; p2++) {
 		Coords *c2 = frags[n2].first_cell + p2;
 
-		// if cell at the border
+		/* if cell at the border */
 		if (c2->neighbors < 4) {
 		    DCELL d = dist(c1, c2);
 
@@ -70,6 +71,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -79,11 +81,11 @@
     int p;
     DCELL min = MAX_DOUBLE;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p = 0; p < frags[patch].count; p++) {
 	Coords *cell = frags[patch].first_cell + p;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (cell->neighbors < 4) {
 	    DCELL dx = loc_x - cell->x;
 	    DCELL dy = loc_y - cell->y;
@@ -94,6 +96,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -135,12 +138,15 @@
 		  int *curpos, int *flag_arr)
 {
     int i;
-    int *p;
-    int list[fragcount];
-    int *first = list;
-    int *last = list + 1;
+    int *list;
+    int *first;
+    int *last;
     int offset;
 
+    list = G_malloc(fragcount * sizeof(int));
+    first = list;
+    last = list + 1;
+
     list[0] = patch;
     flag_arr[patch] = 1;
 
@@ -163,6 +169,8 @@
 	first++;
     }
 
+    G_free(list);
+
     return curpos;
 }
 
@@ -170,15 +178,13 @@
 		  int fragcount)
 {
     int i;
-
     int count = 0;
+    int *flag_arr;
+    int *curpos = cluster_list[0].first_patch;
 
-    int flag_arr[fragcount];
-
+    flag_arr = G_malloc(fragcount * sizeof(int));
     memset(flag_arr, 0, fragcount * sizeof(int));
 
-    int *curpos = cluster_list[0].first_patch;
-
     for (i = 0; i < fragcount; i++) {
 	if (flag_arr[i] == 0) {
 	    cluster_list[count].first_patch = curpos;
@@ -202,6 +208,8 @@
        fprintf(stderr, "\n");
        } */
 
+    G_free(flag_arr);
+
     return count;
 }
 
@@ -306,12 +314,15 @@
 		     DCELL max_dist)
 {
     int i, j;
-    int parents[fragcount];
-    DCELL distances[fragcount];
+    int *parents;
+    DCELL *distances;
     int curmin;
     int nextmin = 0;
     int parent;
 
+    parents = G_malloc(fragcount * sizeof(int));
+    distances = G_malloc(fragcount * sizeof(DCELL));
+
     /* init parents and distances list */
     for (i = 0; i < fragcount; i++) {
 	parents[i] = -1;
@@ -338,13 +349,13 @@
 
 	/* find the next node for minimum spanning tree */
 	for (j = 0; j < fragcount; j++) {
+	    /* get distance to the current minimum node */
+	    DCELL dist = distmatrix[curmin * fragcount + j];
+
 	    /* skip the current minimum node */
 	    if (j == curmin)
 		continue;
 
-	    /* get distance to the current minimum node */
-	    DCELL dist = distmatrix[curmin * fragcount + j];
-
 	    /* if this distance is smaller than the stored one */
 	    /* then set a new distance and update parent list  */
 	    if (dist < distances[j]) {
@@ -359,6 +370,9 @@
 	    }
 	}
     }
+
+    G_free(parents);
+    G_free(distances);
 }
 
 /*********************************
@@ -375,7 +389,6 @@
     /* for each cluster */
     for (i = 0; i < cluster_count; i++) {
 	int n = cluster_list[i].count;
-	DCELL c = 100.0 / (n * (n - 1) * 0.5);
 	DCELL val = 0;
 
 	/* single patch is 100% connected */
@@ -451,7 +464,6 @@
 
     /* for each cluster */
     for (i = 0; i < cluster_count; i++) {
-	int n = cluster_list[i].count;
 	int total_area = 0;
 	DCELL num = 0.0;
 	DCELL denom = 0.0;
@@ -507,8 +519,7 @@
 		    DCELL * distmatrix)
 {
     int i;
-    int *p, *q;
-    Coords *cell;
+    int *p;
 
     int area_all = 0;
 
@@ -629,17 +640,17 @@
     int p1, p2;
     DCELL max = 0.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = 0; p1 < frags[n].count; p1++) {
 	Coords *c1 = frags[n].first_cell + p1;
 
-	// if cell at the border
+	/* if cell at the border */
 	if (c1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = p1 + 1; p2 < frags[n].count; p2++) {
 		Coords *c2 = frags[n].first_cell + p2;
 
-		// if cell at the border
+		/* if cell at the border */
 		if (c2->neighbors < 4) {
 		    DCELL d = dist(c1, c2);
 
@@ -686,15 +697,14 @@
 			  DCELL * distmatrix)
 {
     int i, j, k;
+    DCELL *pathmatrix;
 
     /* initialize path matrix */
-    DCELL pathmatrix[fragcount * fragcount * sizeof(DCELL)];
+    pathmatrix = G_malloc(fragcount * fragcount * sizeof(DCELL));
 
     for (i = 0; i < fragcount; i++) {
 	pathmatrix[i * fragcount + i] = 0.0;
 
-	int j;
-
 	for (j = i + 1; j < fragcount; j++) {
 	    int index = i * fragcount + j;
 	    int index_mirror = j * fragcount + i;
@@ -754,4 +764,6 @@
 
 	values[i] = max_dist;
     }
+
+    G_free(pathmatrix);
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.red/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -100,7 +100,4 @@
 void draw_line(int *map, int val, int x1, int y1, int x2, int y2, int sx,
 	       int sy, int width);
 
-/* global variables */
-GLOBAL int nrows, ncols;
-
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.red/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.graph.red
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Graph Theory approach for connectivity analysis on patch 
  *                               level - decreasing distance threshold option
  *
@@ -79,22 +80,18 @@
     {std_deviat, "std_deviat", "std", "standard deviation of the values"},
     {min, "min", "min", "minimum of the values"},
     {max, "max", "max", "maximum of the values"},
-    {0, 0, 0}
+    {0, 0, 0, 0}
 };
 
 
 int main(int argc, char *argv[])
 {
-    /* result */
-    int exitres = 0;
-
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset;
-    char fullname[GNAME_MAX];
+    char *newname, *oldname;
+    const char *oldmapset;
 
     /* in and out file pointers */
     int in_fd;
-    int out_fd;
     FILE *out_fp;		/* ASCII - output */
 
     /* parameters */
@@ -107,20 +104,27 @@
     DCELL distance;
     DCELL step;
 
-    /* map_type and categories */
-    RASTER_MAP_TYPE map_type;
-
     /* helpers */
     char *p;
-    int row, col, i, j, m;
+    int nrows, ncols;
+    int row, col, i;
     int n;
     f_neighborhood *build_graph;
     f_index *calc_index;
     f_statmethod *calc_stat;
-    int *curpos;
     CELL *result;
-    DCELL *d_res;
-    CELL *clustermap;
+    Coords *cells;
+    Patch *fragments;
+    int *flagbuf;
+    int fragcount;
+    DCELL *distmatrix;
+    int *adjmatrix;
+    int *patches;
+    Cluster *clusters;
+    int val_rows;
+    DCELL *values;
+    int *cluster_counts;
+    DCELL temp_d;
 
     struct GModule *module;
     struct
@@ -134,12 +138,10 @@
 	struct Flag *adjacent;
     } flag;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Graph Theory - decreasing distance threshold option.");
 
@@ -229,29 +231,25 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     G_message("rows = %d, cols = %d", nrows, ncols);
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
-    /* get map type */
-    map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
-
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
 
@@ -306,19 +304,19 @@
     nbr_count = flag.adjacent->answer ? 8 : 4;
 
     /* allocate the cell buffers */
-    Coords *cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
-    Patch *fragments = (Patch *) G_malloc(nrows * ncols * sizeof(Patch));
+    cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
+    fragments = (Patch *) G_malloc(nrows * ncols * sizeof(Patch));
 
     fragments[0].first_cell = cells;
-    int *flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
+    flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
 
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
 
     G_message("Loading patches...");
 
     /* read map */
     for (row = 0; row < nrows; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
@@ -328,7 +326,7 @@
     }
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /*G_message("map");
        for(row = 0; row < nrows; row++) {
@@ -339,11 +337,11 @@
        } */
 
     /* find fragments */
-    int fragcount =
+    fragcount =
 	writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
 
     /* allocate distance matrix */
-    DCELL *distmatrix =
+    distmatrix =
 	(DCELL *) G_malloc(fragcount * fragcount * sizeof(DCELL));
     memset(distmatrix, 0, fragcount * fragcount * sizeof(DCELL));
 
@@ -351,11 +349,11 @@
     get_dist_matrix(distmatrix, fragments, fragcount);
 
     /* allocate adjacency matrix */
-    int *adjmatrix = (int *)G_malloc(fragcount * fragcount * sizeof(int));
+    adjmatrix = (int *)G_malloc(fragcount * fragcount * sizeof(int));
 
     /* allocate clusters */
-    int *patches = (int *)G_malloc(fragcount * sizeof(int));
-    Cluster *clusters = (Cluster *) G_malloc((fragcount) * sizeof(Cluster));
+    patches = (int *)G_malloc(fragcount * sizeof(int));
+    clusters = (Cluster *) G_malloc((fragcount) * sizeof(Cluster));
 
     clusters[0].first_patch = patches;
 
@@ -370,14 +368,14 @@
        fprintf(stderr, "\n");
        } */
 
-    int val_rows = (int)(distance / step) + 1;
+    val_rows = (int)(distance / step) + 1;
 
     /* values = (clustercount, cluster1_index1, cluster2_index1, ...), () */
-    DCELL *values =
+    values =
 	(DCELL *) G_malloc(val_rows * index_count * fragcount *
 			   sizeof(DCELL));
 
-    int *cluster_counts = (int *)G_malloc(val_rows * sizeof(int));
+    cluster_counts = (int *)G_malloc(val_rows * sizeof(int));
 
     /*      calc_index = indices[index].method;
        calc_index(ref_values, clusters, clustercount, adjmatrix, fragments, fragcount, distmatrix);
@@ -391,9 +389,12 @@
     /* perform distance reduction analysis */
     /* for each patch */
     G_message("Performing distance reduction...");
-    DCELL temp_d = distance;
+    temp_d = distance;
 
     for (i = 0; i < val_rows; i++, temp_d -= step) {
+	int idx;
+	DCELL *vals;
+
 	/* build graph with current distance */
 	memset(adjmatrix, 0, fragcount * fragcount * sizeof(int));
 	build_graph(adjmatrix, distmatrix, fragcount, temp_d);
@@ -410,8 +411,7 @@
 	cluster_counts[i] = find_clusters(clusters, adjmatrix, fragcount);
 
 	/* calculate and save indices */
-	int idx;
-	DCELL *vals = &(values[i * index_count * fragcount]);
+	vals = &(values[i * index_count * fragcount]);
 
 	for (idx = 0; idx < index_count; idx++, vals += fragcount) {
 	    int cur_index = index[idx];
@@ -425,7 +425,7 @@
     }
 
     /* test output */
-    fprintf(stderr, "Values:");
+    /*fprintf(stderr, "Values:");
     for (row = 0; row < val_rows; row++) {
 	fprintf(stderr, "\n");
 	fprintf(stderr, "Clusters: %d --- ", cluster_counts[row]);
@@ -434,7 +434,7 @@
 		    values[row * index_count * fragcount + i]);
 	}
     }
-    fprintf(stderr, "\n");
+    fprintf(stderr, "\n"); */
 
     /* write output */
     G_message("Writing output...");
@@ -464,17 +464,17 @@
     /* write values */
     temp_d = distance;
     for (i = 0; i < val_rows; i++, temp_d -= step) {
-	fprintf(out_fp, "%lf %d", temp_d, cluster_counts[i]);
-
 	int idx;
-	DCELL *vals = &(values[i * index_count * fragcount]);
+	DCELL *vals;
 
+	fprintf(out_fp, "%f %d", temp_d, cluster_counts[i]);
+
+	vals = &(values[i * index_count * fragcount]);
+
 	for (idx = 0; idx < index_count; idx++, vals += fragcount) {
-	    int cur_index = index[idx];
-
 	    DCELL val = calc_stat(vals, cluster_counts[i]);
 
-	    fprintf(out_fp, " %lf", val);
+	    fprintf(out_fp, " %f", val);
 	}
 
 	fprintf(out_fp, "\n");

Copied: grass-addons/grass7/raster/r.pi/r.pi.graph.red/r.pi.graph.red.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.graph.red/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/r.pi.graph.red.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/r.pi.graph.red.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,46 @@
+<h2>DESCRIPTION</h2>
+
+Graph Theory - decreasing distance threshold option. 
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.grow/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.grow/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.grow/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -2,8 +2,8 @@
 
 PGM = r.pi.grow
 
-LIBES = $(STATSLIB) $(GISLIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.grow/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.grow/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.grow/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,46 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Size and suitability based region growing. 
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.grow/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.grow/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.grow/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,11 +1,12 @@
 #include "local_proto.h"
 
-int gather_border(Position * res, int neighbors)
+int gather_border(Position * res, int neighbors, int *flagbuf, int nrows, int ncols)
 {
     int count = 0;
 
     /* traverse all cells */
     int row, col;
+    Position pos;
 
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -21,7 +22,8 @@
 			(row < nrows - 1 &&
 			flagbuf[(row + 1) * ncols + col] == 1)) {
 			/* add position to the list */
-			Position pos = { col, row };
+			pos.x = col;
+			pos.y = row;
 			res[count] = pos;
 			count++;
 		    }
@@ -35,7 +37,8 @@
 				flagbuf[y * ncols + x] == 1) {
 
 				/* add position to the list */
-				Position pos = { col, row };
+				pos.x = col;
+				pos.y = row;
 				res[count] = pos;
 				count++;
 				break;
@@ -64,35 +67,41 @@
     return -1;
 }
 
-int add_neighbors(Position * res, int count, int row, int col, int neighbors)
+int add_neighbors(Position * res, int count, int row, int col, 
+                  int nrows, int ncols, int neighbors, int *flagbuf)
 {
     /* look for free neighbors and add to list */
     int x, y;
+    Position pos;
 
     switch (neighbors) {
     case 4:
 	if (col > 0 && flagbuf[row * ncols + col - 1] == 0 &&
 	    find(res, count, row, col - 1) < 0) {
 	    /* add position to the list */
-	    Position pos = { col - 1, row };
+	    pos.x = col - 1;
+	    pos.y = row;
 	    res[count] = pos;
 	    count++;
 	}
 	if (col < ncols - 1 && flagbuf[row * ncols + col + 1] == 0 &&
 	    find(res, count, row, col + 1) < 0) {
-	    Position pos = { col + 1, row };
+	    pos.x = col + 1;
+	    pos.y = row;
 	    res[count] = pos;
 	    count++;
 	}
 	if (row > 0 && flagbuf[(row - 1) * ncols + col] == 0 &&
 	    find(res, count, row - 1, col) < 0) {
-	    Position pos = { col, row - 1 };
+	    pos.x = col;
+	    pos.y = row - 1;
 	    res[count] = pos;
 	    count++;
 	}
 	if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] == 0 &&
 	    find(res, count, row + 1, col) < 0) {
-	    Position pos = { col, row + 1 };
+	    pos.x = col;
+	    pos.y = row + 1;
 	    res[count] = pos;
 	    count++;
 	}
@@ -106,7 +115,8 @@
 		    flagbuf[y * ncols + x] == 0) {
 
 		    /* add position to the list */
-		    Position pos = { x, y };
+		    pos.x = x;
+		    pos.y = y;
 		    res[count] = pos;
 		    count++;
 		}
@@ -118,16 +128,19 @@
     return count;
 }
 
-int f_circular(Position * list, int count, int neighbors)
+int f_circular(Position * list, int count, int neighbors, int *flagbuf, int nrows, int ncols)
 {
+    int r;
+    Position *p;
+
     if (count == 0) {
 	return 0;
     }
 
     /* get random position */
-    int r = (int)((double)rand() / (double)RAND_MAX * (double)count);
+    r = (int)((double)rand() / (double)RAND_MAX * (double)count);
 
-    Position *p = list + r;
+    p = list + r;
 
     flagbuf[p->y * ncols + p->x] = 1;
 
@@ -138,13 +151,13 @@
     /* if border level is exceeded gather new border */
     if (count == 0) {
 	/* go to the next level border */
-	count = gather_border(list, neighbors);
+	count = gather_border(list, neighbors, flagbuf, nrows, ncols);
     }
 
     return count;
 }
 
-int f_random(Position * list, int count, int neighbors)
+int f_random(Position * list, int count, int neighbors, int *flagbuf, int nrows, int ncols)
 {
     /* get random position */
     int r = (int)((double)rand() / (double)RAND_MAX * (double)count);
@@ -158,47 +171,53 @@
     list[r] = list[count];
 
     /* add free neighbor cells */
-    count = add_neighbors(list, count, p.y, p.x, neighbors);
+    count = add_neighbors(list, count, p.y, p.x, nrows, ncols, neighbors, flagbuf);
 
     return count;
 }
 
-int f_costbased(Position * list, int count, int neighbors)
+int f_costbased(Position * list, int count, int neighbors, int *flagbuf, int nrows, int ncols)
 {
     /* build a cost array */
-    double costbuffer[count];
+    double *costbuffer;
     int i;
     double sum = 0.0;
+    double inv;
+    double r;
+    Position pb;
 
+    costbuffer = G_malloc(count * sizeof(double));
+
     for (i = 0; i < count; i++) {
+	double tmp;
 	Position *p = list + i;
 
 	costbuffer[i] = costmap[p->y * ncols + p->x];
-	double tmp = costbuffer[i];
+	tmp = costbuffer[i];
 
 	costbuffer[i] += sum;
 	sum += tmp;
 
-	//fprintf(stderr, "%0.2f ", costbuffer[i]);
+	/* fprintf(stderr, "%0.2f ", costbuffer[i]); */
     }
-    //fprintf(stderr, "\n");
+    /* fprintf(stderr, "\n"); */
 
     /* normalize */
-    double inv = 1.0 / sum;
+    inv = 1.0 / sum;
 
     for (i = 0; i < count; i++) {
 	costbuffer[i] *= inv;
     }
 
     /* get random number between 0.0 and 1.0 */
-    double r = (double)rand() / (double)RAND_MAX;
+    r = (double)rand() / (double)RAND_MAX;
 
     /* get next position */
-    Position p = list[0];
+    pb = list[0];
 
     for (i = 0; i < count; i++) {
 	if (r < costbuffer[i]) {
-	    p = list[i];
+	    pb = list[i];
 	    break;
 	}
     }
@@ -208,14 +227,16 @@
 	return 0;
     }
 
-    flagbuf[p.y * ncols + p.x] = 1;
+    flagbuf[pb.y * ncols + pb.x] = 1;
 
     /* delete border cell */
     count--;
     list[i] = list[count];
 
     /* add free neighbor cells */
-    count = add_neighbors(list, count, p.y, p.x, neighbors);
+    count = add_neighbors(list, count, pb.y, pb.x, nrows, ncols, neighbors, flagbuf);
 
+    G_free(costbuffer);
+
     return count;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.grow/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.grow/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.grow/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -22,17 +22,15 @@
     int x, y;
 } Position;
 
-typedef int (f_method) (Position *, int, int);
+typedef int (f_method) (Position *, int, int, int *, int, int);
 
 /* func.c */
-int f_circular(Position * list, int count, int neighbors);
-int f_random(Position * list, int count, int neighbors);
-int f_costbased(Position * list, int count, int neighbors);
-int gather_border(Position * res, int neighbors);
+int f_circular(Position * list, int count, int neighbors, int *flagbuf, int nrows, int ncols);
+int f_random(Position * list, int count, int neighbors, int *flagbuf, int nrows, int ncols);
+int f_costbased(Position * list, int count, int neighbors, int *flagbuf, int nrows, int ncols);
+int gather_border(Position * res, int neighbors, int *flagbuf, int nrows, int ncols);
 
 /* global variables */
-GLOBAL int nrows, ncols;
-GLOBAL int *flagbuf;
 GLOBAL DCELL *costmap;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.grow/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.grow/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.grow/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.grow
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Size and landscape suitability based region growing
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -35,8 +36,8 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset, *costname, *costmapset;
-    char fullname[GNAME_MAX];
+    char *newname, *oldname, *costname;
+    const char *oldmapset, *costmapset;
 
     /* in and out file pointers */
     int in_fd;
@@ -48,15 +49,14 @@
     f_method *method;
     int nbr_count;
 
-    /* map_type and categories */
-    RASTER_MAP_TYPE map_type;
-
     /* helpers */
     DCELL *d_res;
     int *line;
+    int *flagbuf;
 
     char *str;
     int n, i;
+    int nrows, ncols;
     int row, col;
 
     Position *border_list;
@@ -77,7 +77,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Size and suitability based region growing.");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -135,15 +135,16 @@
     /* get names of input files */
     oldname = parm.input->answer;
     costname = parm.costmap->answer;
+    costmapset = NULL;
 
     /* test input file existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* test costmap file existance */
     if (costname) {
-	if (NULL == (costmapset = G_find_cell2(costname, ""))) {
+	if (NULL == (costmapset = G_find_raster2(costname, ""))) {
 	    G_fatal_error("%s: <%s> raster file not found\n",
 			  G_program_name(), costname);
 	    exit(EXIT_FAILURE);
@@ -153,18 +154,14 @@
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
-    G_message("rows = %d, cols = %d", nrows, ncols);
+    G_debug(1, "rows = %d, cols = %d", nrows, ncols);
 
-    /* get map type */
-    map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
-
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
 
@@ -172,12 +169,18 @@
     sscanf(parm.area->answer, "%d", &area);
 
     /* get growth method */
+    method = NULL;
     for (i = 0; (str = methods[i].name) != 0; i++) {
 	if (strcmp(str, parm.method->answer) == 0) {
 	    method = methods[i].method;
 	    break;
 	}
     }
+    if (!method) {
+	G_fatal_error("<%s=%s> unknown %s", parm.method->key,
+		      parm.method->answer, parm.method->key);
+	exit(EXIT_FAILURE);
+    }
 
     /* set random seed */
     if (parm.seed->answer) {
@@ -196,21 +199,21 @@
     /* allocate the cell buffers */
     flagbuf = (int *)G_malloc(ncols * nrows * sizeof(int));
     costmap = (DCELL *) G_malloc(ncols * nrows * sizeof(DCELL));
-    line = G_allocate_c_raster_buf();
-    d_res = G_allocate_d_raster_buf();
+    line = Rast_allocate_c_buf();
+    d_res = Rast_allocate_d_buf();
 
     G_message("Loading Input file ... ");
 
     /* load map */
     /* open input file */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read patch map */
     memset(flagbuf, 0, ncols * nrows * sizeof(int));
     for (row = 0; row < nrows; row++) {
-	G_get_c_raster_row(in_fd, line, row);
+	Rast_get_c_row(in_fd, line, row);
 	for (col = 0; col < ncols; col++) {
 	    if (line[col] == keyval) {
 		flagbuf[row * ncols + col] = 1;
@@ -221,7 +224,7 @@
     }
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /*G_message("map");
        for(row = 0; row < nrows; row++) {
@@ -234,19 +237,19 @@
     /* load costmap */
     /* open input file */
     if (costname) {
-	in_fd = G_open_cell_old(costname, costmapset);
+	in_fd = Rast_open_old(costname, costmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), costname);
 
 	/* read cost map */
 	for (row = 0; row < nrows; row++) {
-	    G_get_d_raster_row(in_fd, &costmap[row * ncols], row);
+	    Rast_get_d_row(in_fd, &costmap[row * ncols], row);
 
 	    G_percent(row + 1, nrows, 1);
 	}
 
 	/* close cell file */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	for (row = 0; row < nrows; row++) {
@@ -266,7 +269,7 @@
 
     /* prepare border list */
     border_list = (Position *) G_malloc(ncols * nrows * sizeof(Position));
-    border_count = gather_border(border_list, nbr_count);
+    border_count = gather_border(border_list, nbr_count, flagbuf, nrows, ncols);
 
     /*G_message("border_count = %d", border_count); */
     
@@ -277,7 +280,7 @@
 	   }
 	   fprintf(stderr, "\n"); */
 
-	border_count = method(border_list, border_count, nbr_count);
+	border_count = method(border_list, border_count, nbr_count, flagbuf, nrows, ncols);
     }
     /*G_message("final border list:");
        for(i = 0; i < border_count; i++) {
@@ -295,26 +298,26 @@
 
     /* write output */
     /* open the new cellfile  */
-    out_fd = G_open_raster_new(newname, DCELL_TYPE);
+    out_fd = Rast_open_new(newname, DCELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* write the output file */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(d_res, ncols);
+	Rast_set_d_null_value(d_res, ncols);
 
 	for (col = 0; col < ncols; col++) {
 	    if (flagbuf[row * ncols + col] == 1) {
 		d_res[col] = 1;
 	    }
 	}
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(row + 1, nrows, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     G_free(flagbuf);
     G_free(costmap);

Copied: grass-addons/grass7/raster/r.pi/r.pi.grow/r.pi.grow.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.grow/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.grow/r.pi.grow.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.grow/r.pi.grow.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,46 @@
+<h2>DESCRIPTION</h2>
+
+Size and suitability based region growing. 
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.import/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -2,8 +2,8 @@
 
 PGM = r.pi.import
 
-LIBES = $(STATSLIB) $(GISLIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.import/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,60 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Import and generation of patch raster data based on individual patch based raster data.
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-In order to run <em>r.pi.import</em> we need an exported patch index raster:
-<div class="code"><pre>
-r.pi.index input=landclass96 output=landclass96_forestclass5_area keyval=5 method=area
-</pre></div>
-
-export this resulting map:
-<div class="code"><pre>
-r.pi.export input=landclass96_forestclass5_area output=patch_area_out values=patch_area_values id_raster=forestclass5_ID stats=average,variance,min
-</pre></div>
-
-modify it with R or just import the file again and assign the percentage coverage to each fragment. You need the <em>patch_area_values</em> file and the previously used input file <em>forestclass96</em> raster (important: the same patch coverage is mandatory otherwise patch ID in the text file and raster are not congruent!):
-
-<div class="code"><pre>
-r.pi.import input=patch_area_values raster=landclass96 output=imported_values keyval=5 id_col=1 val_col=2
-</pre></div>
-
-if you want to export the patch values to R and do e.g. a linear regression of two patch values and import them again in GRASS, do:<br>
-
-apply r.pi.export with two indices (A and B), in R do:
-
-<div class="code"><pre>
-resid.AB <- resid(lm(A[,3]~B[,3])) #write residuals of a linear regression
-df.resid.AB <- data.frame(A[,1],resid.AB) #merge patch IDs and resid into same data frame
-write.table(df.resid.AB,"resid.for.GRASS",row.names=F,col.names=F)
-</pre></div>
-
-exit R and run in GRASS:
-<div class="code"><pre>
-r.pi.import input=resid.for.GRASS raster=landclass96 output=resid.AB keyval=5 id_col=1 val_col=2
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p><i>Last changed: $Date$</i>
-

Modified: grass-addons/grass7/raster/r.pi/r.pi.import/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -98,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,17 +130,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -164,5 +152,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.import/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -22,21 +22,22 @@
 #define GLOBAL extern
 #endif
 
+typedef struct
+{
+    int x, y;
+} Position;
+
 typedef DCELL(f_statmethod) (DCELL *, int);
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* parse.c */
-void parse(DCELL * values, char *file_name, int id_col, int val_col);
+void parse(DCELL * values, char *file_name, int id_col, int val_col, int fragcount);
 
 /* global variables */
-GLOBAL int verbose;
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
-GLOBAL int sx, sy;
-
 GLOBAL int *adj_matrix;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.import/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.import
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Import of patch information based on ID patch raster 
  *                               (Reads a text-file with Patch IDs and values and creates 
  *                               a raster file with these values for patches)
@@ -22,10 +23,11 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* output */
-    char *newname, *newmapset;
+    char *newname;
 
     /* in and out file pointers */
     int in_fd;
@@ -40,24 +42,16 @@
     /* maps */
     int *map;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
+    int sx, sy;
     DCELL *d_res;
     DCELL *values;
     int *result;
-    int i, n;
-    int x, y;
+    int i;
     Coords *p;
-    char output_name[GNAME_MAX];
-    char *str;
-    DCELL val;
+    int fragcount;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -67,13 +61,13 @@
     } parm;
     struct
     {
-	struct Flag *adjacent, *quiet;
+	struct Flag *adjacent;
     } flag;
 
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Import and generation of patch raster data");
 
     parm.input = G_define_option();
@@ -125,7 +119,7 @@
     oldname = parm.raster->answer;
 
     /* test raster files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
@@ -144,18 +138,17 @@
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* allocate map buffers */
     map = (int *)G_malloc(sx * sy * sizeof(int));
     values = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
-    d_res = G_allocate_d_raster_buf();
-    result = G_allocate_c_raster_buf();
+    d_res = Rast_allocate_d_buf();
+    result = Rast_allocate_c_buf();
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     fragments[0] = cells;
@@ -163,14 +156,14 @@
     memset(map, 0, sx * sy * sizeof(int));
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map file... ");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
@@ -181,24 +174,24 @@
     G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* find fragment values */
-    writeFragments(map, sy, sx, neighb_count);
+    fragcount = writeFragments(map, sy, sx, neighb_count);
 
     /* parse input */
-    parse(values, parm.input->answer, id_col, val_col);
+    parse(values, parm.input->answer, id_col, val_col, fragcount);
 
     G_message("Writing output...");
 
     /* open new cellfile  */
-    out_fd = G_open_raster_new(newname, DCELL_TYPE);
+    out_fd = Rast_open_new(newname, DCELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* write the output file */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -208,13 +201,13 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
 
 	G_percent(row + 1, sy, 1);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* free allocated resources */
     G_free(map);

Modified: grass-addons/grass7/raster/r.pi/r.pi.import/parse.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/parse.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/parse.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -32,16 +32,15 @@
     values[id] = value;
 }
 
-void parse(DCELL * values, char *file_name, int id_col, int val_col)
+void parse(DCELL * values, char *file_name, int id_col, int val_col, int fragcount)
 {
     char buffer[GNAME_MAX];
     FILE *fp;
-    int i;
 
     fp = fopen(file_name, "r");
 
     /* fill values with NULL */
-    G_set_d_null_value(values, fragcount);
+    Rast_set_d_null_value(values, fragcount);
 
     if (fp == NULL) {
 	G_fatal_error("Couldn't open input file!");

Copied: grass-addons/grass7/raster/r.pi/r.pi.import/r.pi.import.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.import/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/r.pi.import.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/r.pi.import.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,60 @@
+<h2>DESCRIPTION</h2>
+
+Import and generation of patch raster data based on individual patch based raster data.
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+In order to run <em>r.pi.import</em> we need an exported patch index raster:
+<div class="code"><pre>
+r.pi.index input=landclass96 output=landclass96_forestclass5_area keyval=5 method=area
+</pre></div>
+
+export this resulting map:
+<div class="code"><pre>
+r.pi.export input=landclass96_forestclass5_area output=patch_area_out values=patch_area_values id_raster=forestclass5_ID stats=average,variance,min
+</pre></div>
+
+modify it with R or just import the file again and assign the percentage coverage to each fragment. You need the <em>patch_area_values</em> file and the previously used input file <em>forestclass96</em> raster (important: the same patch coverage is mandatory otherwise patch ID in the text file and raster are not congruent!):
+
+<div class="code"><pre>
+r.pi.import input=patch_area_values raster=landclass96 output=imported_values keyval=5 id_col=1 val_col=2
+</pre></div>
+
+if you want to export the patch values to R and do e.g. a linear regression of two patch values and import them again in GRASS, do:<br>
+
+apply r.pi.export with two indices (A and B), in R do:
+
+<div class="code"><pre>
+resid.AB <- resid(lm(A[,3]~B[,3])) #write residuals of a linear regression
+df.resid.AB <- data.frame(A[,1],resid.AB) #merge patch IDs and resid into same data frame
+write.table(df.resid.AB,"resid.for.GRASS",row.names=F,col.names=F)
+</pre></div>
+
+exit R and run in GRASS:
+<div class="code"><pre>
+r.pi.import input=resid.for.GRASS raster=landclass96 output=resid.AB keyval=5 id_col=1 val_col=2
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p><i>Last changed: $Date$</i>
+

Modified: grass-addons/grass7/raster/r.pi/r.pi.index/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.index/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,123 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.fragment</em> is a patch based fragmentation analysis package.
-Computation of basic fragmentation indices can be accomplished. 
-
-<p>
-Available options for the index to be computed for patches within
-a certain class are: area (area), perimeter (perim), SHAPE (shape),
-Border-Index (bor), Compactness (comp), Asymmetry (asym),
-area-perimeter ratio (apr), fractal dimension (fract),
-distance to euclidean nearest neighbour (ENN).
-
-<h2>NOTES</h2>
-
-The <em>Nearest Neighbour Index</em> (ENN) analyse the Euclidean Nearest 
-Neighbour to the first neighbouring patch. The output value is in pixel and can
-be converted to a distance values using g.region resolution information.
-<em>r.pi.enn</em> and <em>r.fragment.fnn</em> provide the same analysis concerning the
- first nearest neighbour (NN), but are extended to the n-th NN. However due to
-code construction does the <em>r.pi.index</em> distance analysis to first ENN perform faster.
-
-
-<em>Methods:</em>
-The <em>method</em> operators determine what algorithm is applied 
-on the patches.
-<em>r.pi.index</em>
-can perform the following operations:
-
-<p>
-
-<dt><b>Area</b> 
-
-<dd>The <em>Area</em> computes the area of each patch.
-
-<dt><b>Perimeter</b> 
-
-<dd>The <em>Perimeter</em> computes the perimeter of each patch.
-
-<dt><b>Area-Perimeter ratio</b> 
-
-<dd>The <em>Area-Perimeter ratio</em> divides the patch perimeter by the area.
-
-<dt><b>SHAPE Index</b> 
-
-<dd>The <em>SHAPE Index</em> divides the patch perimete by the minimum perimeter 
-possible for a maximally compact patch of the corresponding patch area.
-
-<dt><b>Border Index</b> 
-
-<dd>The <em>Border Index</em> ....
-
-<dt><b>Compactness Index</b> 
-
-<dd>The <em>Compactness Index</em> ....
-
-<dt><b>Asymmetry Index</b> 
-
-<dd>The <em>Border Index</em> ....
-
-<dt><b>Fractal Dimension Index</b> 
-
-<dd>The <em>Fractal Dimension Index</em> ....
-
-<dt><b>Nearest Neighbour Index</b> 
-
-<dd>The <em>Nearest Neighbour Index</em> computes the Euclidean distance
-to the first nearest neighbour patch.
-
-
-
-<h2>EXAMPLE</h2>
-
-Examples based on the North Carolina sample dataset are provided below. Indices are calculated for the landscape class 5 (forest).
-
-set region settings to used landcover class map:
-
-<br>
-<div class="code"><pre>
-g.region rast=landclass96
-</pre></div>
-
-
-computation of patch size (patch definition: 4-neighbourhood rule)
-<div class="code"><pre>
-r.pi.index input=landclass96 output=landclass96_forestclass5_area keyval=5 method=area
-# improve colouring of resulting map: 
-r.colors landclass96_forestclass5_area col=bgyr
-</pre></div>
-
-computation of patch size (patch definition: 8-neighbourhood rule)
-<div class="code"><pre>
-r.pi.index input=landclass96 output=landclass96_forestclass5_area keyval=5 method=area -a
-</pre></div>
-
-computation of patch isolation (euclidean distance to 1. nearest neighbour; patch definition: 4-neighbourhood rule)
-<div class="code"><pre>
-r.pi.index input=landclass96 output=landclass96_forestclass5_ENN keyval=5 method=ENN -a
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.enn.html">r.pi.enn</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-
-<h2>BUGS</h2>
-Landscapes with more than 10 000 individual patches might cause a memory
-allocation error depending on your system.
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.index/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -12,9 +12,9 @@
     int x, y;
 } Position;
 
-int getNeighbors(Position * res, int x, int y, int nx, int ny, int nbr_cnt);
+int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny, int nbr_cnt);
 
-int getNeighbors(Position * res, int x, int y, int nx, int ny, int nbr_cnt)
+int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny, int nbr_cnt)
 {
     int left, right, top, bottom;
     int i, j;
@@ -63,7 +63,7 @@
     return cnt;
 }
 
-void writeFrag(int row, int col, int nbr_cnt)
+void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols, int nbr_cnt)
 {
     int x, y, i;
     Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
@@ -100,16 +100,11 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
-	int cnt = getNeighbors(nbr_list, c, r, ncols, nrows, nbr_cnt);
+	int cnt = getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;

Modified: grass-addons/grass7/raster/r.pi/r.pi.index/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -295,6 +295,7 @@
     for (i = 0; i < count; i++) {
 	for (j = 0; j < count; j++) {
 	    if (i != j) {
+		/* ??? */
 	    }
 	}
     }

Modified: grass-addons/grass7/raster/r.pi/r.pi.index/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -9,7 +9,7 @@
 #define GLOBAL extern
 #endif
 
-extern void writeFrag(int row, int col, int nbr_cnt);
+extern void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols, int nbr_cnt);
 
 extern int f_area(DCELL * vals, Coords ** frags, int);
 extern int f_perim(DCELL * vals, Coords ** frags, int);
@@ -22,9 +22,7 @@
 extern int f_nearest_dist(DCELL *, Coords **, int);
 
 /* global variables */
-GLOBAL int nrows, ncols;
 GLOBAL Coords **fragments;
-GLOBAL int *flagbuf;
 GLOBAL Coords *actpos;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.index/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.index
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Fragmentation analysis - basic spatial indices
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -50,13 +51,14 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset;
+    char *newname, *oldname;
+    const char *oldmapset;
     char title[1024];
 
     /* in and out file pointers */
     int in_fd;
     int out_fd;
-    DCELL *result, res[30];
+    DCELL *result;
 
     /* map_type and categories */
     RASTER_MAP_TYPE map_type;
@@ -70,8 +72,8 @@
 
     char *p;
 
-    int row, col, i, j;
-    int readrow;
+    int row, col, i;
+    int nrows, ncols;
     int keyval;
     int n;
     struct Colors colr;
@@ -92,13 +94,12 @@
     DCELL *values;
     Coords *cells;
     int fragcount = 0;
+    int *flagbuf;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Basic patch based indices");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -147,22 +148,21 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
-	if (oldmapset == NULL)
+    oldmapset = G_find_raster2(oldname, "");
+    if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
         G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
@@ -195,7 +195,7 @@
     fragments = (Coords **) G_malloc(nrows * ncols * sizeof(Coords *));
     fragments[0] = cells;
     flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* get title, initialize the category and stat info */
     if (parm.title->answer)
@@ -204,7 +204,7 @@
 	sprintf(title, "Fragmentation of file: %s", oldname);
 
     /* open the new cellfile  */
-    out_fd = G_open_raster_new(newname, map_type);
+    out_fd = Rast_open_new(newname, map_type);
     if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
@@ -212,7 +212,7 @@
 
     /* find fragments */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, result, row);
+	Rast_get_d_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
@@ -225,7 +225,7 @@
 	for (col = 0; col < ncols; col++) {
 	    if (flagbuf[row * ncols + col] == 1) {
 		fragcount++;
-		writeFrag(row, col, neighb_count);
+		writeFrag(flagbuf, row, col, nrows, ncols, neighb_count);
 		fragments[fragcount] = actpos;
 	    }
 	}
@@ -241,7 +241,7 @@
     /* write the output file */
     G_message("Writing output...");
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(result, ncols);
+	Rast_set_d_null_value(result, ncols);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (actpos = fragments[i]; actpos < fragments[i + 1]; actpos++) {
@@ -251,28 +251,28 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, result);
+	Rast_put_d_row(out_fd, result);
 
 	G_percent(row, nrows, 2);
     }
 
     G_percent(nrows, nrows, 2);
 
-    G_close_cell(out_fd);
-    G_close_cell(in_fd);
+    Rast_close(out_fd);
+    Rast_close(in_fd);
 
     G_free(cells);
     G_free(fragments);
     G_free(flagbuf);
 
-    G_init_cats(0, title, &cats);
-    G_write_cats(newname, &cats);
+    Rast_init_cats(title, &cats);
+    Rast_write_cats(newname, &cats);
 
-    G_read_range(newname, newmapset, &range);
-    G_get_range_min_max(&range, &min, &max);
-    G_make_bgyr_colors(&colr, min, max);
-    G_write_colors(newname, newmapset, &colr);
-    G_free_colors(&colr);
+    Rast_read_range(newname, G_mapset(), &range);
+    Rast_get_range_min_max(&range, &min, &max);
+    Rast_make_bgyr_colors(&colr, min, max);
+    Rast_write_colors(newname, G_mapset(), &colr);
+    Rast_free_colors(&colr);
 
     exit(EXIT_SUCCESS);
 }

Copied: grass-addons/grass7/raster/r.pi/r.pi.index/r.pi.index.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.index/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/r.pi.index.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/r.pi.index.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,124 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.fragment</em> is a patch based fragmentation analysis package.
+Computation of basic fragmentation indices can be accomplished. 
+
+<p>
+Available options for the index to be computed for patches within
+a certain class are: area (area), perimeter (perim), SHAPE (shape),
+Border-Index (bor), Compactness (comp), Asymmetry (asym),
+area-perimeter ratio (apr), fractal dimension (fract),
+distance to euclidean nearest neighbour (ENN).
+
+<h2>NOTES</h2>
+
+The <em>Nearest Neighbour Index</em> (ENN) analyse the Euclidean Nearest 
+Neighbour to the first neighbouring patch. The output value is in pixel and can
+be converted to a distance values using g.region resolution information.
+<em>r.pi.enn</em> and <em>r.fragment.fnn</em> provide the same analysis concerning the
+ first nearest neighbour (NN), but are extended to the n-th NN. However due to
+code construction does the <em>r.pi.index</em> distance analysis to first ENN perform faster.
+
+
+<em>Methods:</em>
+The <em>method</em> operators determine what algorithm is applied 
+on the patches.
+<em>r.pi.index</em>
+can perform the following operations:
+
+<p>
+
+<dl>
+<dt><b>Area</b> 
+
+<dd>The <em>Area</em> computes the area of each patch.
+
+<dt><b>Perimeter</b> 
+
+<dd>The <em>Perimeter</em> computes the perimeter of each patch.
+
+<dt><b>Area-Perimeter ratio</b> 
+
+<dd>The <em>Area-Perimeter ratio</em> divides the patch perimeter by the area.
+
+<dt><b>SHAPE Index</b> 
+
+<dd>The <em>SHAPE Index</em> divides the patch perimete by the minimum perimeter 
+possible for a maximally compact patch of the corresponding patch area.
+
+<dt><b>Border Index</b> 
+
+<dd>The <em>Border Index</em> ....
+
+<dt><b>Compactness Index</b> 
+
+<dd>The <em>Compactness Index</em> ....
+
+<dt><b>Asymmetry Index</b> 
+
+<dd>The <em>Border Index</em> ....
+
+<dt><b>Fractal Dimension Index</b> 
+
+<dd>The <em>Fractal Dimension Index</em> ....
+
+<dt><b>Nearest Neighbour Index</b> 
+
+<dd>The <em>Nearest Neighbour Index</em> computes the Euclidean distance
+to the first nearest neighbour patch.
+</dl>
+
+
+<h2>EXAMPLE</h2>
+
+Examples based on the North Carolina sample dataset are provided below. Indices are calculated for the landscape class 5 (forest).
+
+set region settings to used landcover class map:
+
+<br>
+<div class="code"><pre>
+g.region rast=landclass96
+</pre></div>
+
+
+computation of patch size (patch definition: 4-neighbourhood rule)
+<div class="code"><pre>
+r.pi.index input=landclass96 output=landclass96_forestclass5_area keyval=5 method=area
+# improve colouring of resulting map: 
+r.colors landclass96_forestclass5_area col=bgyr
+</pre></div>
+
+computation of patch size (patch definition: 8-neighbourhood rule)
+<div class="code"><pre>
+r.pi.index input=landclass96 output=landclass96_forestclass5_area keyval=5 method=area -a
+</pre></div>
+
+computation of patch isolation (euclidean distance to 1. nearest neighbour; patch definition: 4-neighbourhood rule)
+<div class="code"><pre>
+r.pi.index input=landclass96 output=landclass96_forestclass5_ENN keyval=5 method=ENN -a
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.enn.html">r.pi.enn</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+
+<h2>BUGS</h2>
+Landscapes with more than 10 000 individual patches might cause a memory
+allocation error depending on your system.
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.library/draw.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.library/draw.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.library/draw.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -17,15 +17,23 @@
     if (width == 1) {
 	map[y * sx + x] = val;
     }
-    else {
-    }
+
+    /* else ? */
 }
 
 void draw_line(int *map, int val, int x1, int y1, int x2, int y2, int sx,
 	       int sy, int width)
 {
-    int steep = abs(y2 - y1) > abs(x2 - x1);
+    int steep;
+    int deltax;
+    int deltay;
+    int error;
+    int ystep;
+    int x;
+    int y;
 
+    steep = abs(y2 - y1) > abs(x2 - x1);
+
     if (steep) {
 	swap(&x1, &y1);
 	swap(&x2, &y2);
@@ -36,12 +44,11 @@
 	swap(&y1, &y2);
     }
 
-    int deltax = x2 - x1;
-    int deltay = abs(y2 - y1);
-    int error = deltax / 2;
-    int ystep = y1 < y2 ? 1 : -1;
-    int x;
-    int y = y1;
+    deltax = x2 - x1;
+    deltay = abs(y2 - y1);
+    error = deltax / 2;
+    ystep = y1 < y2 ? 1 : -1;
+    y = y1;
 
     for (x = x1; x <= x2; x++) {
 	if (steep) {

Modified: grass-addons/grass7/raster/r.pi/r.pi.library/r_pi.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.library/r_pi.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.library/r_pi.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -6,6 +6,7 @@
 #include <unistd.h>
 #include <math.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.library/stat_method.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.library/stat_method.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.library/stat_method.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -32,6 +32,7 @@
     }
 
     mean = s / (DCELL) count;
+
     return ss / count - mean * mean;
 }
 
@@ -123,17 +124,18 @@
     DCELL actval, maxval;
     int actcnt, maxcnt;
     int actpos;
-    int i;
 
     if (count <= 0)
 	return 0;
 
     quicksort(vals, 0, count - 1);
 
+    /*
     fprintf(stderr, "vals = (%0.2f", vals[0]);
     for (i = 1; i < count; i++)
 	fprintf(stderr, ",%0.2f", vals[i]);
     fprintf(stderr, ")\n\n");
+    */
 
     maxval = 0;
     maxcnt = 0;
@@ -188,12 +190,12 @@
 
 DCELL sum(DCELL * vals, int count)
 {
+    int i;
+    DCELL res = 0;
+
     if (count <= 0)
 	return 0;
 
-    int i;
-    DCELL res = 0;
-
     for (i = 0; i < count; i++)
 	res += vals[i];
 
@@ -203,6 +205,7 @@
 DCELL linear(DCELL value, DCELL propcost)
 {
     value -= propcost;
+
     return value >= 0.0 ? value : 0.0;
 }
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.lm/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.lm/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.lm/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -2,8 +2,8 @@
 
 PGM = r.pi.lm
 
-LIBES = $(STATSLIB) $(GISLIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.lm/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.lm/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.lm/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,46 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Linear regression analysis for patches. 
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.lm/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.lm/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.lm/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -17,22 +17,22 @@
 
     switch (nbr_cnt) {
     case 4:			/* von Neumann neighborhood */
-	if (x > 0 && !G_is_d_null_value(&map[y * nx + x - 1])) {
+	if (x > 0 && !Rast_is_d_null_value(&map[y * nx + x - 1])) {
 	    res[cnt].x = x - 1;
 	    res[cnt].y = y;
 	    cnt++;
 	}
-	if (y > 0 && !G_is_d_null_value(&map[(y - 1) * nx + x])) {
+	if (y > 0 && !Rast_is_d_null_value(&map[(y - 1) * nx + x])) {
 	    res[cnt].x = x;
 	    res[cnt].y = y - 1;
 	    cnt++;
 	}
-	if (x < nx - 1 && !G_is_d_null_value(&map[y * nx + x + 1])) {
+	if (x < nx - 1 && !Rast_is_d_null_value(&map[y * nx + x + 1])) {
 	    res[cnt].x = x + 1;
 	    res[cnt].y = y;
 	    cnt++;
 	}
-	if (y < ny - 1 && !G_is_d_null_value(&map[(y + 1) * nx + x])) {
+	if (y < ny - 1 && !Rast_is_d_null_value(&map[(y + 1) * nx + x])) {
 	    res[cnt].x = x;
 	    res[cnt].y = y + 1;
 	    cnt++;
@@ -47,7 +47,7 @@
 	for (i = left; i <= right; i++) {
 	    for (j = top; j <= bottom; j++) {
 		if (!(i == x && j == y) &&
-		    !G_is_d_null_value(&map[j * nx + i])) {
+		    !Rast_is_d_null_value(&map[j * nx + i])) {
 		    res[cnt].x = i;
 		    res[cnt].y = j;
 		    cnt++;
@@ -74,19 +74,21 @@
     top++;
 
     while (top > stack) {
+	int r, c, cnt;
+
 	/* pop position from stack */
 	top--;
-	int r = top->y;
-	int c = top->x;
+	r = top->y;
+	c = top->x;
 
 	/* mark cell on the flag buffer */
 	flagbuf[r * ncols + c] = flagval;
 
 	/* delete cell from map */
-	G_set_d_null_value(&map[r * ncols + c], 1);
+	Rast_set_d_null_value(&map[r * ncols + c], 1);
 
 	/* get neighbors */
-	int cnt = getNeighbors(nbr_list, map, c, r, ncols, nrows, nbr_cnt);
+	cnt = getNeighbors(nbr_list, map, c, r, ncols, nrows, nbr_cnt);
 
 	/* push neighbors on the stack */
 	for (i = 0; i < cnt; i++) {

Modified: grass-addons/grass7/raster/r.pi/r.pi.lm/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.lm/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.lm/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -11,6 +11,14 @@
     DCELL sum_xx = 0;
     DCELL sum_yy = 0;
 
+    DCELL r_n;
+    DCELL var_x;
+    DCELL var_y;
+    DCELL covar;
+    DCELL beta;
+    DCELL alpha;
+    DCELL corr;
+
     if (count <= 0)
 	return;
 
@@ -25,13 +33,13 @@
 	sum_yy += yi * yi;
     }
 
-    DCELL r_n = 1.0 / (DCELL) count;
-    DCELL var_x = (sum_xx - sum_x * sum_x * r_n) * r_n;
-    DCELL var_y = (sum_yy - sum_y * sum_y * r_n) * r_n;
-    DCELL covar = (sum_xy - sum_x * sum_y * r_n) * r_n;
-    DCELL beta = covar / var_x;
-    DCELL alpha = (sum_y - beta * sum_x) * r_n;
-    DCELL corr = beta * sqrt(var_x) / sqrt(var_y);
+    r_n = 1.0 / (DCELL) count;
+    var_x = (sum_xx - sum_x * sum_x * r_n) * r_n;
+    var_y = (sum_yy - sum_y * sum_y * r_n) * r_n;
+    covar = (sum_xy - sum_x * sum_y * r_n) * r_n;
+    beta = covar / var_x;
+    alpha = (sum_y - beta * sum_x) * r_n;
+    corr = beta * sqrt(var_x) / sqrt(var_y);
 
     *res_slope = beta;
     *res_offset = alpha;

Modified: grass-addons/grass7/raster/r.pi/r.pi.lm/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.lm/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.lm/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.lm
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Linear regression analysis for patches (not pixel based)
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -18,16 +19,14 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *newname, *oldname1, *oldname2, *newmapset, *oldmapset1, *oldmapset2;
-    char fullname[GNAME_MAX];
+    char *newname, *oldname1, *oldname2;
+    const char *oldmapset1, *oldmapset2;
 
     /* in and out file pointers */
     int in_fd;
     int out_fd;
-    FILE out_fp;
 
     /* parameters */
-    int keyval;
     int nbr_count;
     int patch_values;
 
@@ -35,10 +34,15 @@
     RASTER_MAP_TYPE map_type;
 
     /* helpers */
+    int i;
     DCELL *result;
     DCELL *map;
     int row, col;
     int nrows, ncols;
+    DCELL *x, *y;
+    int *flagbuf;
+    int value_count;
+    DCELL offset, slope, correlation, *residuals;
 
     struct GModule *module;
     struct
@@ -53,7 +57,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Linear regression analysis for patches.");
 
     parm.input1 = G_define_standard_option(G_OPT_R_INPUT);
@@ -74,29 +78,28 @@
     flag.patch_values->description = _("Set to use patch values");
 
     if (G_parser(argc, argv))
-	    exit(EXIT_FAILURE);
+	exit(EXIT_FAILURE);
 
     /* get names of input files */
     oldname1 = parm.input1->answer;
     oldname2 = parm.input2->answer;
 
     /* test input files existance */
-    oldmapset1 = G_find_cell2(oldname1, "");
-	if (oldmapset1 == NULL)
+    oldmapset1 = G_find_raster2(oldname1, "");
+    if (oldmapset1 == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname1);
-    oldmapset2 = G_find_cell2(oldname2, "");
-	if (oldmapset2 == NULL)
+    oldmapset2 = G_find_raster2(oldname2, "");
+    if (oldmapset2 == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname2);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
 	G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     /* get map type */
     map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
@@ -113,13 +116,13 @@
     G_message("Loading patches...");
 
     /* open first cell file */
-    in_fd = G_open_cell_old(oldname1, oldmapset1);
+    in_fd = Rast_open_old(oldname1, oldmapset1);
     if (in_fd < 0)
         G_fatal_error(_("Unable to open raster map <%s>"), oldname1);
 
     /* read map */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, map + row * ncols, row);
+	Rast_get_d_row(in_fd, map + row * ncols, row);
 
 	G_percent(row + 1, nrows, 1);
     }
@@ -133,35 +136,33 @@
        } */
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* open second cell file */
-    in_fd = G_open_cell_old(oldname2, oldmapset2);
+    in_fd = Rast_open_old(oldname2, oldmapset2);
     if (in_fd < 0)
         G_fatal_error(_("Unable to open raster map <%s>"), oldname2);
 
     /* gather pixel or patch values */
     /* TODO: patch values */
-    result = G_allocate_d_raster_buf();
-    DCELL *x = (DCELL *) malloc(nrows * ncols * sizeof(DCELL));
-    DCELL *y = (DCELL *) malloc(nrows * ncols * sizeof(DCELL));
-    int *flagbuf = (int *)malloc(nrows * ncols * sizeof(int));
+    result = Rast_allocate_d_buf();
+    x = (DCELL *) malloc(nrows * ncols * sizeof(DCELL));
+    y = (DCELL *) malloc(nrows * ncols * sizeof(DCELL));
+    flagbuf = (int *)malloc(nrows * ncols * sizeof(int));
 
     /* initialize flag buffer with -1 */
-    int i;
-
     for (i = 0; i < nrows * ncols; i++) {
 	flagbuf[i] = -1;
     }
-    int value_count = 0;
+    value_count = 0;
 
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, result, row);
+	Rast_get_d_row(in_fd, result, row);
 
 	for (col = 0; col < ncols; col++) {
 	    DCELL val = map[row * ncols + col];
 
-	    if (!G_is_d_null_value(&val)) {
+	    if (!Rast_is_d_null_value(&val)) {
 		x[value_count] = val;
 		y[value_count] = result[col];
 
@@ -198,8 +199,7 @@
     }
     printf("\n");
 
-    DCELL *residuals = (DCELL *) malloc(value_count * sizeof(DCELL));
-    DCELL offset, slope, correlation;
+    residuals = (DCELL *) malloc(value_count * sizeof(DCELL));
 
     /* calculate data */
     linear_regression(x, y, value_count, &offset, &slope, residuals,
@@ -210,12 +210,12 @@
     G_free(y);
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* write output */
     G_message("Writing output...");
 
-    G_message("Offset: %lf, Slope: %lf, Correlation: %lf\n", offset, slope,
+    G_message("Offset: %f, Slope: %f, Correlation: %f\n", offset, slope,
 	      correlation);
 
     /* ================================== 
@@ -223,13 +223,13 @@
        ================================== */
 
     /* open the new cellfile  */
-    out_fd = G_open_raster_new(newname, map_type);
+    out_fd = Rast_open_new(newname, map_type);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* write values */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(result, ncols);
+	Rast_set_d_null_value(result, ncols);
 
 	for (col = 0; col < ncols; col++) {
 	    int flagval = flagbuf[row * ncols + col];
@@ -239,13 +239,13 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, result);
+	Rast_put_d_row(out_fd, result);
 
 	G_percent(row + 1, nrows, 1);
     }
 
     /* close output file */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* =====================
        ==== free memory ====

Copied: grass-addons/grass7/raster/r.pi/r.pi.lm/r.pi.lm.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.lm/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.lm/r.pi.lm.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.lm/r.pi.lm.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,46 @@
+<h2>DESCRIPTION</h2>
+
+Linear regression analysis for patches. 
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.neigh/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.neigh/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,34 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Neighbourhood analysis - value of patches within a defined range. 
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.index.html">r.fragment</a>,
-<a href="r.pi.prox.html">r.fragment.dist</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.neigh/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -12,7 +12,7 @@
     int x, y;
 } Position;
 
-int getNeighbors(Position * res, int x, int y, int nx, int ny, int nbr_cnt)
+int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny, int nbr_cnt)
 {
     int left, right, top, bottom;
     int i, j;
@@ -61,7 +61,7 @@
     return cnt;
 }
 
-void writeFrag(int row, int col, int nbr_cnt)
+void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols, int nbr_cnt)
 {
     int x, y, i;
     Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
@@ -98,16 +98,11 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
-	int cnt = getNeighbors(nbr_list, c, r, ncols, nrows, nbr_cnt);
+	int cnt = getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;

Modified: grass-addons/grass7/raster/r.pi/r.pi.neigh/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -24,13 +24,13 @@
     Coords *p1, *p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = frags[n2]; p2 < frags[n2 + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -41,6 +41,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -64,7 +65,7 @@
     return distmatrix;
 }
 
-void compute_values(DCELL * vals, int min, int max, f_func stat_method)
+void compute_values(DCELL * vals, int fragcount, int min, int max, f_func stat_method)
 {
     int i, j;
     int counter;
@@ -93,7 +94,7 @@
 	   fprintf(stderr, "\n"); */
 
 	vals[i] = stat_method(patch_vals, counter);
-	// fprintf(stderr, "vals[%d] = %0.2f\n", i, vals[i]);
+	/* fprintf(stderr, "vals[%d] = %0.2f\n", i, vals[i]); */
     }
 
     G_free(distmatrix);

Modified: grass-addons/grass7/raster/r.pi/r.pi.neigh/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -16,16 +16,12 @@
 typedef DCELL(f_func) (DCELL * values, int count);
 
 /* frag.c */
-void writeFrag(int row, int col, int nbr_cnt);
+void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols, int nbr_cnt);
 
 /* func.c */
-void compute_values(DCELL * vals, int min, int max, f_func stat_method);
+void compute_values(DCELL * vals, int fragcount, int min, int max, f_func stat_method);
 
 /* global variables */
-GLOBAL int nrows, ncols;
 GLOBAL Coords **fragments;
-GLOBAL int fragcount;
-GLOBAL int *flagbuf;
 GLOBAL DCELL *valsbuf;
 GLOBAL Coords *actpos;
-GLOBAL int cnt;

Modified: grass-addons/grass7/raster/r.pi/r.pi.neigh/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.neigh
  * AUTHOR(S):    Elshad Shirinov, Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Neighbourhood analysis - value of patches within a defined range
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -35,14 +36,16 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset;
-    char *vals_name, *vals_mapset;
+    char *newname, *oldname;
+    const char *oldmapset;
+    char *vals_name;
+    const char *vals_mapset;
     char title[1024];
 
     /* in and out file pointers */
     int in_fd;
     int out_fd;
-    DCELL *result, res[30];
+    DCELL *result;
 
     /* map_type and categories */
     RASTER_MAP_TYPE map_type;
@@ -56,11 +59,13 @@
     /* neighbors count */
     int neighb_count;
 
-    int row, col, i, j;
-    int readrow;
+    int nrows, ncols;
+    int row, col, i;
     int keyval;
     int min = 0;
     int max = MAX_DOUBLE;
+    int *flagbuf;
+    int fragcount;
 
     int n;
     int copycolr;
@@ -80,12 +85,10 @@
     DCELL *values;
     Coords *cells;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Neighbourhood analysis - value of patches within a defined range.");
 
@@ -155,28 +158,27 @@
     vals_name = parm.input2->answer;
 
     /* get mapset */
-    oldmapset = G_find_cell2(oldname, "");
-    vals_mapset = G_find_cell2(vals_name, "");
+    oldmapset = G_find_raster2(oldname, "");
+    vals_mapset = G_find_raster2(vals_name, "");
 
     /* test input file existance */
-	if (oldmapset == NULL)
+    if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
-	if (vals_mapset == NULL)
+    if (vals_mapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), vals_name);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
         G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
@@ -184,7 +186,7 @@
     map_type = DCELL_TYPE;
 
     /* copy color table */
-    copycolr = (G_read_colors(oldname, oldmapset, &colr) > 0);
+    copycolr = (Rast_read_colors(oldname, oldmapset, &colr) > 0);
 
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
@@ -212,7 +214,7 @@
     fragments = (Coords **) G_malloc(nrows * ncols * sizeof(Coords *));
     fragments[0] = cells;
     flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* get min */
     if (parm.min->answer)
@@ -229,15 +231,15 @@
 	sprintf(title, "Fragmentation of file: %s", oldname);
 
     /* open the new cellfile  */
-    out_fd = G_open_raster_new(newname, map_type);
+    out_fd = Rast_open_new(newname, map_type);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     fprintf(stderr, "Percent complete ... ");
 
     /* create flag buffer */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, result, row);
+	Rast_get_d_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
@@ -245,7 +247,7 @@
     }
 
     /* close cell file */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* find fragments */
     fragcount = 0;
@@ -256,7 +258,7 @@
 	for (col = 0; col < ncols; col++) {
 	    if (flagbuf[row * ncols + col] == 1) {
 		fragcount++;
-		writeFrag(row, col, neighb_count);
+		writeFrag(flagbuf, row, col, nrows, ncols, neighb_count);
 		fragments[fragcount] = actpos;
 	    }
 	}
@@ -265,7 +267,7 @@
     G_percent(1, 1, 2);
 
     /* open patch-values file */
-    in_fd = G_open_cell_old(vals_name, vals_mapset);
+    in_fd = Rast_open_old(vals_name, vals_mapset);
     if (in_fd < 0)
         G_fatal_error(_("Unable to open raster map <%s>"), vals_name);
 
@@ -279,17 +281,17 @@
 
 	G_percent(i, fragcount, 2);
 
-	G_get_d_raster_row(in_fd, result, row);
+	Rast_get_d_row(in_fd, result, row);
 	valsbuf[i] = result[col];
     }
 
     /* perform actual function on the patches */
     values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
-    compute_values(values, min, max, stat_method);
+    compute_values(values, fragcount, min, max, stat_method);
 
     /* write the output file */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(result, ncols);
+	Rast_set_d_null_value(result, ncols);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (actpos = fragments[i]; actpos < fragments[i + 1]; actpos++) {
@@ -299,13 +301,13 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, result);
+	Rast_put_d_row(out_fd, result);
     }
 
     G_percent(row, nrows, 2);
 
-    G_close_cell(in_fd);
-    G_close_cell(out_fd);
+    Rast_close(in_fd);
+    Rast_close(out_fd);
 
     G_free(cells);
     G_free(fragments);
@@ -313,11 +315,11 @@
     G_free(values);
     G_free(valsbuf);
 
-    G_init_cats(0, title, &cats);
-    G_write_cats(newname, &cats);
+    Rast_init_cats(title, &cats);
+    Rast_write_cats(newname, &cats);
 
     if (copycolr)
-	G_write_colors(newname, newmapset, &colr);
+	Rast_write_colors(newname, G_mapset(), &colr);
 
     exit(EXIT_SUCCESS);
 }

Copied: grass-addons/grass7/raster/r.pi/r.pi.neigh/r.pi.neigh.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.neigh/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/r.pi.neigh.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/r.pi.neigh.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,34 @@
+<h2>DESCRIPTION</h2>
+
+Neighbourhood analysis - value of patches within a defined range. 
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.index.html">r.fragment</a>,
+<a href="r.pi.prox.html">r.fragment.dist</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.nlm/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,43 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Creates a random generated map with values 0 or 1" "by given landcover and agglomeration value. 
-
-<h2>NOTES</h2>
-
-Related to r.pi.nlm.circ but using fractal landscapes instead of circular growth. Per default the size of the whole region is used for generating a random landscape, this can be constraint by assigning a class in a raster map with acts as mask for the generation of the random landscape (<em>nullval</em>).
-The landcover can be set manually, randomly or be taken from the input class coverage. The agglomeration level (<em>sharpness</em>) can be set manually or randomly. If similar random landscape with differing e.g. percentage coverage should be generated, then the <em>seed</em> can be set using any number and reused for any subsequent analysis.
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-A random landscape with random percentage coverage and agglomeration factor:<br>
-<div class="code"><pre>
-r.pi.nlm output=nlm.1 landcover=50 --o
-
-</pre></div>
-
-
-A random landscape is generated using the percentage coverage of class 5. The agglomeration factor is set randomly:<br>
-<div class="code"><pre>
-r.pi.nlm input=landclass96 output=nlm.2 keyval=5 --o
-
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.nlm.html">r.nlm</a>,
-<a href="r.nlm.stats.html">r.nlm.stats</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -4,7 +4,7 @@
 {
     if ((x >= 0) && (x < size) && (y >= 0) && (y < size)) {
 	*res = map[x + y * size];
-	if (G_is_d_null_value(res)) {
+	if (Rast_is_d_null_value(res)) {
 	    double min, max;
 
 	    MinMax(map, &min, &max, size * size);
@@ -12,18 +12,18 @@
 	}
 	return 1;
     }
-    else {
-	*res = 0;
-	return 0;
-    }
+
+    *res = 0;
+
+    return 0;
 }
 
 void SetCell(double *map, int x, int y, int size, double value)
 {
-    //      fprintf(stderr, "writing value = %f to x = %d y = %d\n", value, x, y);
-    if (!G_is_d_null_value(&map[x + y * size]))
+    /*      fprintf(stderr, "writing value = %f to x = %d y = %d\n", value, x, y); */
+    if (!Rast_is_d_null_value(&map[x + y * size]))
 	map[x + y * size] = value;
-    //      fprintf(stderr, "map[%d,%d] = %f\n", x, y, map[x + y * size]);
+    /*      fprintf(stderr, "map[%d,%d] = %f\n", x, y, map[x + y * size]); */
 }
 
 double DownSample(double *map, int x, int y, int newcols, int newrows,
@@ -79,7 +79,7 @@
     double res = 0;
 
     if (map[oldx + oldy * oldcols] != 0) {
-	G_set_d_null_value(&res, 1);
+	Rast_set_d_null_value(&res, 1);
     }
     return res;
 }
@@ -88,13 +88,14 @@
 {
     int i;
 
+    *min = MAX_DOUBLE;
+    *max = MIN_DOUBLE;
+
     if (size == 0)
 	return;
 
-    *min = MAX_DOUBLE;
-    *max = MIN_DOUBLE;
     for (i = 1; i < size; i++) {
-	if (!G_is_d_null_value(&map[i])) {
+	if (!Rast_is_d_null_value(&map[i])) {
 	    if (map[i] < *min)
 		*min = map[i];
 	    if (map[i] > *max)
@@ -105,35 +106,34 @@
 
 double CutValues(double *map, double mapcover, int size)
 {
-    int values[RESOLUTION - 1];
-    double min, max, span, c;
+    int values[RESOLUTION];
+    double min, max, span;
     int pixels;
-    int i, j, index;
+    int i, index;
     int bottom, top;
     int topdif, bottomdif;
 
-    // get parameters
+    /* get parameters */
     MinMax(map, &min, &max, size);
     span = max - min;
-    c = min / span;
     pixels = Round(size * mapcover);
 
-    // classify heights
+    /* classify heights */
     memset(values, 0, RESOLUTION * sizeof(int));
     for (i = 0; i < size; i++) {
 	index = floor(RESOLUTION * (map[i] - min) / span);
 	if (index >= RESOLUTION)
 	    index = RESOLUTION - 1;
-	//              index:= RES * map[i] / span - c;
+	/*              index:= RES * map[i] / span - c; */
 	values[index]++;
     }
 
-    // accumulate top to bottom
+    /* accumulate top to bottom */
     for (i = RESOLUTION - 1; i > 0; i--) {
 	values[i - 1] += values[i];
     }
 
-    // find matching height
+    /* find matching height */
     bottom = 0;
     top = RESOLUTION - 1;
     while (bottom < top) {
@@ -147,7 +147,7 @@
     if (values[top] >= pixels)
 	top++;
 
-    // find the closest to the landcover
+    /* find the closest to the landcover */
     topdif = abs(values[top] - pixels);
     bottomdif = abs(values[bottom] - pixels);
 
@@ -167,7 +167,7 @@
     double mval;
     double r;
 
-    // get values
+    /* get values */
     int cnt = 0;
 
     if (GetCell(map, v1.x, v1.y, size, &val1))
@@ -179,15 +179,15 @@
     if (GetCell(map, v4.x, v4.y, size, &val4))
 	cnt++;
 
-    // calculate midpoints
+    /* calculate midpoints */
     mid.x = (v1.x + v2.x + v3.x + v4.x) / 4;
     mid.y = (v1.y + v2.y + v3.y + v4.y) / 4;
 
-    // calc mid values
+    /* calc mid values */
     r = (Randomf() - 0.5) * 2;
     mval = (val1 + val2 + val3 + val4) / cnt + r * d;
 
-    // set new values
+    /* set new values */
     SetCell(map, mid.x, mid.y, size, mval);
 }
 
@@ -199,17 +199,17 @@
     double actd = d;
     int xdisp;
 
-    // initialize corners
+    /* initialize corners */
     SetCell(map, 0, 0, size, 2 * (Randomf() - 0.5));
     SetCell(map, size - 1, 0, size, 2 * (Randomf() - 0.5));
     SetCell(map, 0, size - 1, size, 2 * (Randomf() - 0.5));
     SetCell(map, size - 1, size - 1, size, 2 * (Randomf() - 0.5));
 
-    // calculate starting step width
+    /* calculate starting step width */
     step = size;
 
     for (i = 0; i < n; i++) {
-	// do diamond step
+	/* do diamond step */
 	for (x = 0; x < (1 << i); x++) {
 	    for (y = 0; y < (1 << i); y++) {
 		v1.x = x * step;
@@ -224,10 +224,10 @@
 	    }
 	}
 
-	// adjust step
+	/* adjust step */
 	step >>= 1;
 
-	// do square step
+	/* do square step */
 	xdisp = 1;
 	for (y = 0; y <= (1 << (i + 1)); y++) {
 	    for (x = 0; x <= (1 << i) - xdisp; x++) {
@@ -243,7 +243,7 @@
 		FractalStep(map, v1, v2, v3, v4, actd, size);
 	    }
 
-	    // switch row offset
+	    /* switch row offset */
 	    if (xdisp == 0) {
 		xdisp = 1;
 	    }
@@ -252,7 +252,7 @@
 	    }
 	}
 
-	// adjust displacement
+	/* adjust displacement */
 	actd = actd * dmod;
     }
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm/list.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm/list.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm/list.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -131,10 +131,10 @@
     Point *list = list_array[patch].list;
     Point tmp;
 
-    //      fprintf(stderr, "shuffling:\n");
+    /*      fprintf(stderr, "shuffling:\n"); */
     for (i = 0; i < cnt - 1; i++) {
 	pos = Random(cnt - i) + i;
-	//              fprintf(stderr, " %d <-> %d ", i, pos);
+	/*              fprintf(stderr, " %d <-> %d ", i, pos); */
 	tmp = list[i];
 	list[i] = list[pos];
 	list[pos] = tmp;

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,8 +1,9 @@
 /*
  ****************************************************************************
  *
- * MODULE:       r.pi.nlm.2
+ * MODULE:       r.pi.nlm
  * AUTHOR(S):    Elshad Shirinov, Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Generation of Neutral Landscapes (fractal landscapes), similar to r.pi.nlm, but fractal landscapes instead of circular growth
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -18,10 +19,11 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* output */
-    char *newname, *newmapset;
+    char *newname;
 
     /* in and out file pointers */
     int in_fd, out_fd;
@@ -34,9 +36,6 @@
     double sharpness;
     int rand_seed;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     RASTER_MAP_TYPE map_type;
     int *buffer;
@@ -44,11 +43,9 @@
     int i, j;
     int row, col;
     int cnt;
-    Point *list;
     CELL *result;
     int size, n;
     double edge;
-    struct Cell_head ch, window;
     double min, max;
 
     struct GModule *module;
@@ -67,7 +64,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Creates a random generated map with values 0 or 1"
 	  "by given landcover and fragment count.");
@@ -130,10 +127,11 @@
 
     /* get name of input file */
     oldname = parm.input->answer;
+    oldmapset = NULL;
 
     /* test input files existance */
-    if (oldname && NULL == (oldmapset = G_find_cell2(oldname, "")))
-	    G_fatal_error(_("Raster map <%s> not found"), oldname);
+    if (oldname && NULL == (oldmapset = G_find_raster2(oldname, "")))
+	G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* if input specified get keyval */
     if (oldname) {
@@ -142,20 +140,19 @@
 	}
 	else if (!parm.landcover->answer) {
 		G_fatal_error("Specify either landcover or an input file with key value for landcover to be acquired!");
-	    }
+	}
     }
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     map_type = CELL_TYPE;
 
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     size = 1;
     n = 0;
@@ -182,7 +179,7 @@
     else {
 	if (!oldname)
 	   G_fatal_error("Specify either landcover or an input file with key value for landcover to be acquired!");
-	}
+    }
 
     /* get sharpness */
     if (parm.sharpness->answer) {
@@ -192,11 +189,10 @@
 	sharpness = Randomf();
     }
 
-
     /* allocate the cell buffer */
     buffer = (int *)G_malloc(sx * sy * sizeof(int));
     bigbuf = (double *)G_malloc(size * size * sizeof(double));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
 
     /* init buffers */
     memset(bigbuf, 0, size * size * sizeof(double));
@@ -207,13 +203,13 @@
 	pixel_count = 0;
 
 	/* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
-    if (in_fd < 0)
-        G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	in_fd = Rast_open_old(oldname, oldmapset);
+	if (in_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
 	/* init buffer with values from input and get landcover */
 	for (row = 0; row < sy; row++) {
-	    G_get_c_raster_row(in_fd, result, row);
+	    Rast_get_c_row(in_fd, result, row);
 	    for (col = 0; col < sx; col++) {
 		if (parm.nullval->answers) {
 		    for (i = 0; parm.nullval->answers[i] != NULL; i++) {
@@ -228,6 +224,7 @@
 		    pixel_count++;
 	    }
 	}
+	Rast_close(in_fd);
 
 	/* calculate landcover */
 	if (parm.keyval->answer)
@@ -249,7 +246,7 @@
     MinMax(bigbuf, &min, &max, size * size);
 
     for (i = 0; i < size * size; i++)
-	if (G_is_d_null_value(&bigbuf[i]))
+	if (Rast_is_d_null_value(&bigbuf[i]))
 	    bigbuf[i] = min;
 
     /* find edge */
@@ -272,9 +269,9 @@
 
 
     /* write output file */
-    out_fd = G_open_raster_new(newname, map_type);
+    out_fd = Rast_open_new(newname, map_type);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     for (j = 0; j < sy; j++) {
 	for (i = 0; i < sx; i++) {
@@ -284,14 +281,13 @@
 		result[i] = 1;
 	    }
 	    else {
-		G_set_c_null_value(result + i, 1);
+		Rast_set_c_null_value(result + i, 1);
 	    }
 	}
-	G_put_c_raster_row(out_fd, result);
+	Rast_put_c_row(out_fd, result);
     }
 
-    G_close_cell(in_fd);
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* print report */
     if (flag.report->answer) {
@@ -303,7 +299,7 @@
 	    if (buffer[i] == 1)
 		cnt++;
 	landcover = (double)cnt / ((double)sx * (double)sy) * 100;
-	fprintf(stdout, "landcover: %0.2lf%%\n", landcover);
+	fprintf(stdout, "landcover: %0.2f%%\n", landcover);
     }
 
     G_free(buffer);

Copied: grass-addons/grass7/raster/r.pi/r.pi.nlm/r.pi.nlm.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.nlm/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm/r.pi.nlm.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm/r.pi.nlm.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,43 @@
+<h2>DESCRIPTION</h2>
+
+Creates a random generated map with values 0 or 1" "by given landcover and agglomeration value. 
+
+<h2>NOTES</h2>
+
+Related to r.pi.nlm.circ but using fractal landscapes instead of circular growth. Per default the size of the whole region is used for generating a random landscape, this can be constraint by assigning a class in a raster map with acts as mask for the generation of the random landscape (<em>nullval</em>).
+The landcover can be set manually, randomly or be taken from the input class coverage. The agglomeration level (<em>sharpness</em>) can be set manually or randomly. If similar random landscape with differing e.g. percentage coverage should be generated, then the <em>seed</em> can be set using any number and reused for any subsequent analysis.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+A random landscape with random percentage coverage and agglomeration factor:<br>
+<div class="code"><pre>
+r.pi.nlm output=nlm.1 landcover=50 --o
+
+</pre></div>
+
+
+A random landscape is generated using the percentage coverage of class 5. The agglomeration factor is set randomly:<br>
+<div class="code"><pre>
+r.pi.nlm input=landclass96 output=nlm.2 keyval=5 --o
+
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.nlm.html">r.nlm</a>,
+<a href="r.nlm.stats.html">r.nlm.stats</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,83 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.nlm</em> is a random patch generator. It creates a random landscape
-with defined attributes. 
-
-<h2>NOTES</h2>
-
-The user must specify the names of the raster map layers to
-be used for <em>input</em> and <em>output</em>, the
-<em>landcover</em>, the
-<em>size</em>, the
-<em>count</em> used, the <em>keyval</em> 
-of the class of interest of the input raster map.
-
-
-<dt><b>Input</b> 
-
-<dd>The <em>Input</em> is potentially used for Landcover, size and count.
-
-<dt><b>keyval</b> 
-
-<dd>The <em>keyval</em> is used to compute landcover and count if not declared.
-
-<dt><b>landcover</b> 
-
-<dd>The <em>landcover</em> defines the amount of cover, if not declared,
-the landcover of keyval of input is used.
-
-<dt><b>count</b> 
-
-<dd>The <em>count</em> defines the amount of patches in the landscape,
-if not defined, the amount of patches in the input is used, if 0 is inserted,
-random amount of patches are created. Values from 1-n can be defined for
-a fixed number of patches.
-
-<dt><b>size</b> 
-
-<dd>The <em>size</em> defines the size of the artificial landscape. If
-not declared the size of the actual region is taken. 
-
-
-<dt><b>seed</b> 
-
-<dd>The <em>seed</em> defiens the seed of random points. If all settings
-and the seed is fixed, then the patches won't be random anymore, but
-fixed. The user will receive everytime the same landscape.
-
-<dt><b>xxx</b> 
-
-<dd>The <em>xxx</em> ....
-
-<dt><b>xxx</b> 
-
-<dd>The <em>xxx</em> ....
-
-</dl>
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.nlm.fractal.html">r.nlm.fractal</a>,
-<a href="r.nlm.stats.html">r.nlm.stats</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.nlm.circ
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      a simple r.nlm (neutral landscape model) module based on circular growth
  * 
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -68,7 +69,7 @@
     int top = y + 1 < sy ? y + 1 : sy - 1;
     int bottom = y > 0 ? y - 1 : 0;
 
-    int ix, iy, index, i, cell;
+    int ix, iy, index, cell;
 
     /* remove cell from border list */
     list_remove(patch, list_indexOf(patch, x, y));
@@ -140,7 +141,7 @@
 
     /* now plant new cells at random but always at the border */
     while (pixels > 0) {
-	int patch, pos, cnt;
+	int patch, pos;
 	Point p;
 	int flag;
 
@@ -190,7 +191,7 @@
 int main(int argc, char *argv[])
 {
     /* output */
-    char *newname, *newmapset;
+    char *newname;
 
     /* out file pointer */
     int out_fd;
@@ -202,16 +203,10 @@
     int patch_count;
     int rand_seed;
 
-    /* other parameters */
-    int verbose;
-    char *title;
-
     /* helper variables */
     RASTER_MAP_TYPE map_type;
     int *buffer;
     int i, j;
-    int cnt;
-    Point *list;
     CELL *result;
 
     struct GModule *module;
@@ -221,17 +216,11 @@
 	struct Option *landcover, *count;
 	struct Option *randseed, *title;
     } parm;
-    struct
-    {
-	struct Flag *quiet;
-    } flag;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Creates a random landscape with defined attributes.");
 
@@ -269,18 +258,13 @@
     parm.title->required = NO;
     parm.title->description = _("Title for resultant raster map");
 
-    flag.quiet = G_define_flag();
-    flag.quiet->key = 'q';
-    flag.quiet->description = _("Run quietly");
-
     if (G_parser(argc, argv))
 	    exit(EXIT_FAILURE);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     map_type = CELL_TYPE;
 
@@ -295,9 +279,6 @@
     /* get patchcount */
     sscanf(parm.count->answer, "%d", &patch_count);
 
-    /* get verbose */
-    verbose = !flag.quiet->answer;
-
     /* get random seed and init random */
     if (parm.randseed->answer) {
 	sscanf(parm.randseed->answer, "%d", &rand_seed);
@@ -319,7 +300,7 @@
     /* allocate the cell buffer */
     buffer = (int *)G_malloc(sx * sy * sizeof(int));
     memset(buffer, -1, sx * sy * sizeof(int));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
 
     create_patches(buffer, sx, sy, patch_count, pixel_count);
 
@@ -347,9 +328,9 @@
        } */
 
     /* write output file */
-    out_fd = G_open_raster_new(newname, map_type);
+    out_fd = Rast_open_new(newname, map_type);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     for (j = 0; j < sy; j++) {
 	for (i = 0; i < sx; i++) {
@@ -359,15 +340,12 @@
 		result[i] = 1;
 	    }
 	    else {
-		G_set_c_null_value(result + i, 1);
+		Rast_set_c_null_value(result + i, 1);
 	    }
 	}
-	G_put_c_raster_row(out_fd, result);
+	Rast_put_c_row(out_fd, result);
     }
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
-    if (verbose)
-	G_percent(100, 100, 2);
-
     exit(EXIT_SUCCESS);
 }

Copied: grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/r.pi.nlm.circ.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/r.pi.nlm.circ.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.circ/r.pi.nlm.circ.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,83 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.nlm</em> is a random patch generator. It creates a random landscape
+with defined attributes. 
+
+<h2>NOTES</h2>
+
+The user must specify the names of the raster map layers to
+be used for <em>input</em> and <em>output</em>, the
+<em>landcover</em>, the
+<em>size</em>, the
+<em>count</em> used, the <em>keyval</em> 
+of the class of interest of the input raster map.
+
+<dl>
+<dt><b>Input</b> 
+
+<dd>The <em>Input</em> is potentially used for Landcover, size and count.
+
+<dt><b>keyval</b> 
+
+<dd>The <em>keyval</em> is used to compute landcover and count if not declared.
+
+<dt><b>landcover</b> 
+
+<dd>The <em>landcover</em> defines the amount of cover, if not declared,
+the landcover of keyval of input is used.
+
+<dt><b>count</b> 
+
+<dd>The <em>count</em> defines the amount of patches in the landscape,
+if not defined, the amount of patches in the input is used, if 0 is inserted,
+random amount of patches are created. Values from 1-n can be defined for
+a fixed number of patches.
+
+<dt><b>size</b> 
+
+<dd>The <em>size</em> defines the size of the artificial landscape. If
+not declared the size of the actual region is taken. 
+
+
+<dt><b>seed</b> 
+
+<dd>The <em>seed</em> defiens the seed of random points. If all settings
+and the seed is fixed, then the patches won't be random anymore, but
+fixed. The user will receive everytime the same landscape.
+
+<dt><b>xxx</b> 
+
+<dd>The <em>xxx</em> ....
+
+<dt><b>xxx</b> 
+
+<dd>The <em>xxx</em> ....
+
+</dl>
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.nlm.fractal.html">r.nlm.fractal</a>,
+<a href="r.nlm.stats.html">r.nlm.stats</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,33 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Neutral Landscape Generator - index statistics 
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.nlm.html">r.nlm</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/fractal.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/fractal.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/fractal.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,6 +1,6 @@
 #include "local_proto.h"
 
-void create_map(int *res)
+void create_map(int *res, int size)
 {
     double *fractbuf = (double *)G_malloc(size * size * sizeof(double));
     double min, max;
@@ -16,7 +16,7 @@
     /* replace nan values with min value */
     MinMax(fractbuf, &min, &max, size * size);
     for (i = 0; i < size * size; i++)
-	if (G_is_d_null_value(&fractbuf[i]))
+	if (Rast_is_d_null_value(&fractbuf[i]))
 	    fractbuf[i] = min;
 
     /* find edge */

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -98,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,17 +130,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -164,5 +152,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -4,7 +4,7 @@
 {
     if ((x >= 0) && (x < size) && (y >= 0) && (y < size)) {
 	*res = map[x + y * size];
-	if (G_is_d_null_value(res)) {
+	if (Rast_is_d_null_value(res)) {
 	    double min, max;
 
 	    MinMax(map, &min, &max, size * size);
@@ -12,18 +12,18 @@
 	}
 	return 1;
     }
-    else {
-	*res = 0;
-	return 0;
-    }
+
+    *res = 0;
+
+    return 0;
 }
 
 void SetCell(double *map, int x, int y, int size, double value)
 {
-    //      fprintf(stderr, "writing value = %f to x = %d y = %d\n", value, x, y);
-    if (!G_is_d_null_value(&map[x + y * size]))
+    /*      fprintf(stderr, "writing value = %f to x = %d y = %d\n", value, x, y); */
+    if (!Rast_is_d_null_value(&map[x + y * size]))
 	map[x + y * size] = value;
-    //      fprintf(stderr, "map[%d,%d] = %f\n", x, y, map[x + y * size]);
+    /*      fprintf(stderr, "map[%d,%d] = %f\n", x, y, map[x + y * size]); */
 }
 
 double DownSample(double *map, int x, int y, int newcols, int newrows,
@@ -79,7 +79,7 @@
     double res = 0;
 
     if (map[oldx + oldy * oldcols] != 0) {
-	G_set_d_null_value(&res, 1);
+	Rast_set_d_null_value(&res, 1);
     }
     return res;
 }
@@ -88,13 +88,14 @@
 {
     int i;
 
+    *min = MAX_DOUBLE;
+    *max = MIN_DOUBLE;
+
     if (size == 0)
 	return;
 
-    *min = MAX_DOUBLE;
-    *max = MIN_DOUBLE;
     for (i = 1; i < size; i++) {
-	if (!G_is_d_null_value(&map[i])) {
+	if (!Rast_is_d_null_value(&map[i])) {
 	    if (map[i] < *min)
 		*min = map[i];
 	    if (map[i] > *max)
@@ -105,35 +106,34 @@
 
 double CutValues(double *map, double mapcover, int size)
 {
-    int values[RESOLUTION - 1];
-    double min, max, span, c;
+    int values[RESOLUTION];
+    double min, max, span;
     int pixels;
-    int i, j, index;
+    int i, index;
     int bottom, top;
     int topdif, bottomdif;
 
-    // get parameters
+    /* get parameters */
     MinMax(map, &min, &max, size);
     span = max - min;
-    c = min / span;
     pixels = Round(size * mapcover);
 
-    // classify heights
+    /* classify heights */
     memset(values, 0, RESOLUTION * sizeof(int));
     for (i = 0; i < size; i++) {
 	index = floor(RESOLUTION * (map[i] - min) / span);
 	if (index >= RESOLUTION)
 	    index = RESOLUTION - 1;
-	//              index:= RES * map[i] / span - c;
+	/*              index:= RES * map[i] / span - c; */
 	values[index]++;
     }
 
-    // accumulate top to bottom
+    /* accumulate top to bottom */
     for (i = RESOLUTION - 1; i > 0; i--) {
 	values[i - 1] += values[i];
     }
 
-    // find matching height
+    /* find matching height */
     bottom = 0;
     top = RESOLUTION - 1;
     while (bottom < top) {
@@ -147,7 +147,7 @@
     if (values[top] >= pixels)
 	top++;
 
-    // find the closest to the landcover
+    /* find the closest to the landcover */
     topdif = abs(values[top] - pixels);
     bottomdif = abs(values[bottom] - pixels);
 
@@ -167,7 +167,7 @@
     double mval;
     double r;
 
-    // get values
+    /* get values */
     int cnt = 0;
 
     if (GetCell(map, v1.x, v1.y, size, &val1))
@@ -179,15 +179,15 @@
     if (GetCell(map, v4.x, v4.y, size, &val4))
 	cnt++;
 
-    // calculate midpoints
+    /* calculate midpoints */
     mid.x = (v1.x + v2.x + v3.x + v4.x) / 4;
     mid.y = (v1.y + v2.y + v3.y + v4.y) / 4;
 
-    // calc mid values
+    /* calc mid values */
     r = (Randomf() - 0.5) * 2;
     mval = (val1 + val2 + val3 + val4) / cnt + r * d;
 
-    // set new values
+    /* set new values */
     SetCell(map, mid.x, mid.y, size, mval);
 }
 
@@ -199,17 +199,17 @@
     double actd = d;
     int xdisp;
 
-    // initialize corners
+    /* initialize corners */
     SetCell(map, 0, 0, size, 2 * (Randomf() - 0.5));
     SetCell(map, size - 1, 0, size, 2 * (Randomf() - 0.5));
     SetCell(map, 0, size - 1, size, 2 * (Randomf() - 0.5));
     SetCell(map, size - 1, size - 1, size, 2 * (Randomf() - 0.5));
 
-    // calculate starting step width
+    /* calculate starting step width */
     step = size;
 
     for (i = 0; i < n; i++) {
-	// do diamond step
+	/* do diamond step */
 	for (x = 0; x < (1 << i); x++) {
 	    for (y = 0; y < (1 << i); y++) {
 		v1.x = x * step;
@@ -224,10 +224,10 @@
 	    }
 	}
 
-	// adjust step
+	/* adjust step */
 	step >>= 1;
 
-	// do square step
+	/* do square step */
 	xdisp = 1;
 	for (y = 0; y <= (1 << (i + 1)); y++) {
 	    for (x = 0; x <= (1 << i) - xdisp; x++) {
@@ -243,7 +243,7 @@
 		FractalStep(map, v1, v2, v3, v4, actd, size);
 	    }
 
-	    // switch row offset
+	    /* switch row offset */
 	    if (xdisp == 0) {
 		xdisp = 1;
 	    }
@@ -252,7 +252,7 @@
 	    }
 	}
 
-	// adjust displacement
+	/* adjust displacement */
 	actd = actd * dmod;
     }
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -20,6 +20,11 @@
 typedef struct
 {
     int x, y;
+} Position;
+
+typedef struct
+{
+    int x, y;
 } Point;
 
 typedef DCELL(f_statmethod) (DCELL *, int);
@@ -45,23 +50,20 @@
 int f_frac_dim(DCELL * vals, Coords ** frags, int count);
 
 /* fractal.c */
-void create_map(int *res);
+void create_map(int *res, int size);
 
 /* frag.c */
-/* writes one fragment */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* global parameters */
-GLOBAL int verbose;
 GLOBAL int *buffer;
 GLOBAL double *bigbuf;
 GLOBAL double landcover;
 GLOBAL int sx, sy;
-GLOBAL int power, size;
+GLOBAL int power;
 GLOBAL double sharpness;
 
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.nlm.stats
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Generation of Neutral Landscapes and statistical analysis 
  *                               of fragmentation indices
  *
@@ -54,7 +55,8 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* in and out file pointers */
     int in_fd;			/* raster - input */
@@ -70,18 +72,10 @@
     int statmethods[GNAME_MAX];
     int neighb_count;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
-    RASTER_MAP_TYPE map_type;
     int i, j;
     int row, col;
-    int cnt;
     CELL *result;
-    double edge;
-    struct Cell_head ch, window;
-    double min, max;
     int pos;
 
     int *real_landscape;
@@ -89,6 +83,8 @@
     DCELL *res_values;
     int save_fragcount;
     int *fragcounts;
+    int fragcount;
+    int size;
 
     int *resmap;
 
@@ -107,13 +103,13 @@
     } parm;
     struct
     {
-	struct Flag *adjacent, *quiet;
+	struct Flag *adjacent;
     } flag;
 
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Neutral Landscape Generator - index statistics");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -214,18 +210,15 @@
     flag.adjacent->description =
 	_("Set for 8 cell-neighbors. 4 cell-neighbors are default");
 
-    flag.quiet = G_define_flag();
-    flag.quiet->key = 'q';
-    flag.quiet->description = _("Run quietly");
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
     /* get name of input file */
     oldname = parm.input->answer;
+    oldmapset = NULL;
 
     /* test input files existance */
-    if (oldname && NULL == (oldmapset = G_find_cell2(oldname, "")))
+    if (oldname && NULL == (oldmapset = G_find_raster2(oldname, "")))
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* if input specified get keyval */
@@ -235,11 +228,9 @@
 	}
     }
 
-    map_type = CELL_TYPE;
-
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     size = 1;
     power = 0;
@@ -281,9 +272,6 @@
     /* get number of cell-neighbors */
     neighb_count = flag.adjacent->answer ? 8 : 4;
 
-    /* get verbose */
-    verbose = !flag.quiet->answer;
-
     /* scan all method answers */
     for (method_count = 0; parm.method->answers[method_count] != NULL;
 	 method_count++) {
@@ -325,7 +313,7 @@
     buffer = (int *)G_malloc(sx * sy * sizeof(int));
     bigbuf = (double *)G_malloc(size * size * sizeof(double));
     resmap = (int *)G_malloc(sx * sy * sizeof(int));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     /* res_values = (method1(statmethod1(1..n))(statmethod2(1..n))) */
@@ -354,13 +342,13 @@
 	pixel_count = 0;
 
 	/* open cell files */
-	in_fd = G_open_cell_old(oldname, oldmapset);
+	in_fd = Rast_open_old(oldname, oldmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
 	/* init buffer with values from input and get landcover */
 	for (row = 0; row < sy; row++) {
-	    G_get_c_raster_row(in_fd, result, row);
+	    Rast_get_c_row(in_fd, result, row);
 	    for (col = 0; col < sx; col++) {
 		if (parm.nullval->answers) {
 		    for (i = 0; parm.nullval->answers[i] != NULL; i++) {
@@ -377,6 +365,7 @@
 		}
 	    }
 	}
+	Rast_close(in_fd);
 
 	/* test output */
 	/*              G_message("real landscape");
@@ -400,9 +389,8 @@
 	}
 
 	/* apply methods to real landscape */
+	fragcount = writeFragments(real_landscape, sy, sx, neighb_count);
 
-	writeFragments(real_landscape, sy, sx, neighb_count);
-
 	/* allocate memory for result */
 	res = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
 
@@ -441,9 +429,9 @@
 
 	G_percent(i, n, 1);
 
-	create_map(resmap);
+	create_map(resmap, size);
 
-	writeFragments(resmap, sy, sx, neighb_count);
+	fragcount = writeFragments(resmap, sy, sx, neighb_count);
 
 	/* save fragcount */
 	fragcounts[i] = fragcount;
@@ -453,7 +441,6 @@
 
 	/* calculate requested values */
 	for (m = 0; m < method_count; m++) {
-	    int cnt;
 
 	    f_func *calculate;
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/method.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/method.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/method.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -129,7 +129,7 @@
 	ax = ay = axy = 0;
 	bx = by = 0;
 	/* for all cells in a patch */
-	//              fprintf(stderr, "\npatch %d: ", i);
+	/*              fprintf(stderr, "\npatch %d: ", i); */
 	for (p = frags[i]; p < frags[i + 1]; p++, n++) {
 	    int x = p->x;
 	    int y = p->y;
@@ -140,13 +140,13 @@
 	    axy += xy;
 	    bx += x * x;
 	    by += y * y;
-	    //                      fprintf(stderr, "x_%d = %d, y_%d = %d; ", n, x, n, y);
+	    /*                      fprintf(stderr, "x_%d = %d, y_%d = %d; ", n, x, n, y); */
 	}
 	invn = 1.0 / (DCELL) n;
 	vx = ((DCELL) bx - (DCELL) ax * (DCELL) ax * invn) * invn;
 	vy = ((DCELL) by - (DCELL) ay * (DCELL) ay * invn) * invn;
 	vxy = ((DCELL) axy - (DCELL) ax * (DCELL) ay * invn) * invn;
-	//              fprintf(stderr, " axy = %d, ax = %d, ay = %d, n = %d", axy, ax, ay, n);
+	/*              fprintf(stderr, " axy = %d, ax = %d, ay = %d, n = %d", axy, ax, ay, n); */
 	vsum = vx + vy;
 	vals[i] = 2 * sqrt(0.25 * vsum * vsum + vxy * vxy - vx * vy) / vsum;
     }
@@ -210,13 +210,13 @@
     Coords *p1, *p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = frags[n2]; p2 < frags[n2 + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -227,6 +227,7 @@
 	    }
 	}
     }
+
     return min;
 }
 

Copied: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/r.pi.nlm.stats.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/r.pi.nlm.stats.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/r.pi.nlm.stats.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,33 @@
+<h2>DESCRIPTION</h2>
+
+Neutral Landscape Generator - index statistics 
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.nlm.html">r.nlm</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.odc/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.odc/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,85 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.pi.odc</em> is part of the patch based fragmentation analysis
-package r.pi.* (Patch Index). It computes omnidirectional connectivity
-analysis between patches.
-
-<h2>NOTES</h2>
-
-Several output raster are generated with the defined <em>output</em> file name and a suffix of the information provided. All files named *.FP.* are providing information concerning the focus patch. All files named *.TP.* are providing informaton about the target patches.<br>
-
-TODO: ???<p>
-
-The user must specify the names of the raster map layers to
-be used for <em>input</em> and <em>output</em>, the <em>keyval</em> the
-<em>ratio</em> (area/odd or odd/area) and <em>stats</em> used (i.e., average).
-<p>
-Within <em>r.pi.odc</em> the following setting have to be set:
-
-<h3>keyval setting:</h3>
-
-The <em>keyval</em> operator determines which category value is taken for the Patch Index analysis.
-
-<h3>Ratio setting:</h3>
-
-The <em>ratio</em> operators determine what measure is applied.
-
-<h3>Neighbourhood level:</h3>
-
-The <em>neighbor_level</em> operator determines which neighbourhood level is used. <em>0</em> produces output for the focus patch itself, <em>1</em> assigns the connectivity information of the first omnidirectional neighbours to the focus patch, hence the connectivity of the surrouding fragments. This value can be increased for analysing the more distant neighbours.
-
-<h3>Output:</h3>
-
-Various output files are autmatically created with the pattern $output.*
-
-The<br>
-
-<em>FP</em> describes attributes of the fokus patch (area and area of the odd)
-
-<em>TP</em> describes attributes of the target patch (all neighbouring patches around the FP) - separated by the statsmethod (average, median, variance, stddev)
-
-<em>ratio</em> describes which ratio is taken for all TPs.
-
-The output raster files are named accordingly:<br>
-
-*.FP.area: size of the patch<br>
-*.FP.odd: size of the isolation area<br>
-*.FP.odd_area: ratio of size of patch and size of isolaton area<br>
-
-*.TP.no: amount of neighbouring patches<br>
-*.TP.area.avg: average size of all neighbouring patches<br>
-*.TP.odd.avg: average size of all isolation areas of neighbouring patches<br>
-*.TP.odd_area.avg: average ratio of isolation area to patch size<br>
-
-*.diagram: (if flag -d active) isolation areas and border are depicted
-
-
-</dl>
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-r.pi.odc input=landclass96 output=odc keyval=5 ratio=odd_area stats=average neighbor_level=0 -d
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.fnn.html">r.pi.fnn</a>,
-<a href="r.pi.enn.html">r.pi.enn</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.odc/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -40,6 +35,7 @@
 	    cnt++;
 	}
 	break;
+
     case 8:			/* Moore neighborhood */
 	left = x > 0 ? x - 1 : 0;
 	top = y > 0 ? y - 1 : 0;
@@ -98,17 +94,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,17 +131,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -164,5 +153,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.odc/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -20,6 +20,11 @@
 typedef struct
 {
     int x, y;
+} Position;
+
+typedef struct
+{
+    int x, y;
 } Point;
 
 typedef struct
@@ -38,14 +43,14 @@
 void print_fragments();
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* voronoi.c */
-void voronoi(DCELL * values, int *map, int sx, int sy, int diag_move);
+void voronoi(DCELL * values, int *map, int sx, int sy, int diag_move, int fragcount);
 void calc_neighbors(DCELL * res, DCELL * focals, f_statmethod **methods,
 		    int stat_count, f_compensate compensate,
-		    int neighbor_level);
-void getNeighborCount(DCELL * res);
+		    int neighbor_level, int fragcount);
+void getNeighborCount(DCELL * res, int fragcount);
 
 /* compensation.c */
 DCELL none(DCELL value, int frag);
@@ -57,8 +62,6 @@
 /* global variables */
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
-GLOBAL int sx, sy;
 
 GLOBAL int *adj_matrix;
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.odc/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.odc
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      omnidirectional connectivity analysis based on polygons
  *                               (related to voronoi for points)
  *
@@ -53,26 +54,31 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
+
     /* output */
-    char *newname, *newmapset;
+    char *newname;
+
     /* mask */
-    char *maskname, *maskmapset;
+    char *maskname;
+    const char *maskmapset;
+
     /* in and out file pointers */
     int in_fd, out_fd;
     FILE *out_fp;		/* ASCII - output */
+
     /* parameters */
     int keyval;
     int stats[GNAME_MAX];
     int stat_count;
-    int ratio;
     int diag_grow;
     int compmethod;
     int neighbor_level;
+
     /* maps */
     int *map;
-    /* other parameters */
-    char *title;
+
     /* helper variables */
     int row, col;
     CELL *result;
@@ -82,6 +88,7 @@
     int neighb_count;
     int i, n;
     int x, y;
+    int sx, sy;
     Coords *p;
     char output_name[GNAME_MAX];
     char *str;
@@ -89,10 +96,8 @@
     f_statmethod **method_array;
     DCELL area;
     f_compensate *compensate;
+    int fragcount;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -108,7 +113,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Omnidirectional connectivity analysis");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -199,15 +204,16 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* get name of mask file */
     maskname = parm.mask->answer;
+    maskmapset = NULL;
 
     /* test input files existance */
-    if (maskname && (maskmapset = G_find_cell2(maskname, "")) == NULL)
+    if (maskname && (maskmapset = G_find_raster2(maskname, "")) == NULL)
         G_fatal_error(_("Raster map <%s> not found"), maskname);
 
     /* get keyval */
@@ -231,13 +237,10 @@
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
 	G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
 
-    map_type = DCELL_TYPE;
-
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     G_message("sx = %d, sy = %d", sx, sy);
 
@@ -275,21 +278,21 @@
 
     /* allocate map buffers */
     map = (int *)G_malloc(sx * sy * sizeof(int));
-    result = G_allocate_c_raster_buf();
-    d_res = G_allocate_d_raster_buf();
+    result = Rast_allocate_c_buf();
+    d_res = Rast_allocate_d_buf();
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     fragments[0] = cells;
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
@@ -308,23 +311,23 @@
        } */
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* find fragments */
-    writeFragments(map, sy, sx, neighb_count);
+    fragcount = writeFragments(map, sy, sx, neighb_count);
 
     G_message("Found %d patches", fragcount);
 
     /* apply mask */
     if (maskname) {
 	/* open mask */
-	in_fd = G_open_cell_old(maskname, maskmapset);
+	in_fd = Rast_open_old(maskname, maskmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), maskname);
 
 	/* read mask */
 	for (row = 0; row < sy; row++) {
-	    G_get_c_raster_row(in_fd, result, row);
+	    Rast_get_c_row(in_fd, result, row);
 	    for (col = 0; col < sx; col++) {
 		if (result[col] == 1) {
 		    map[row * sx + col] = TYPE_NOTHING;
@@ -337,7 +340,7 @@
 	}
 
 	/* close mask */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	for (i = 0; i < sx * sy; i++) {
@@ -362,7 +365,7 @@
 
     memset(adj_matrix, 0, fragcount * fragcount * sizeof(int));
 
-    voronoi(values, map, sx, sy, diag_grow);
+    voronoi(values, map, sx, sy, diag_grow, fragcount);
 
     /* output skipped positions */
     G_message("Positions skipped: %d", empty_count);
@@ -376,13 +379,13 @@
     strcpy(output_name, newname);
     strcat(output_name, ".FP.area");
 
-    out_fd = G_open_raster_new(output_name, map_type);
+    out_fd = Rast_open_new(output_name, DCELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
+	G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
     /* write area of focal patch */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    area = fragments[i + 1] - fragments[i];
@@ -393,23 +396,23 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* open the new cell file  */
     strcpy(output_name, newname);
     strcat(output_name, ".FP.odd");
 
-    out_fd = G_open_raster_new(output_name, map_type);
+    out_fd = Rast_open_new(output_name, DCELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
+	G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
     /* write ratio of focal patch */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -419,24 +422,24 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* open the new cell file  */
     strcpy(output_name, newname);
     strcat(output_name, ".ratioFP.");
     strcat(output_name, compmethods[compmethod].suffix);
 
-    out_fd = G_open_raster_new(output_name, map_type);
+    out_fd = Rast_open_new(output_name, DCELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
+	G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
     /* write odd of focal patch */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    area = fragments[i + 1] - fragments[i];
@@ -447,11 +450,11 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /*
        =============================== TARGET PATCHES =========================================
@@ -465,7 +468,7 @@
     }
 
     calc_neighbors(neighb_values, values, method_array, stat_count,
-		   compensate, neighbor_level);
+		   compensate, neighbor_level, fragcount);
 
     /* write areas */
     for (method = 0; method < stat_count; method++) {
@@ -474,13 +477,13 @@
 	strcat(output_name, ".TP.area.");
 	strcat(output_name, statmethods[stats[method]].suffix);
 
-	out_fd = G_open_raster_new(output_name, map_type);
+	out_fd = Rast_open_new(output_name, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
 	/* write areas of target patches with current suffix for statmethod */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -490,11 +493,11 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write odds */
@@ -504,13 +507,13 @@
 	strcat(output_name, ".TP.odd.");
 	strcat(output_name, statmethods[stats[method]].suffix);
 
-	out_fd = G_open_raster_new(output_name, map_type);
+	out_fd = Rast_open_new(output_name, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
 	/* write odd of target patches with current suffix for statmethod */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -522,11 +525,11 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write ratios */
@@ -538,13 +541,13 @@
 	strcat(output_name, ".");
 	strcat(output_name, statmethods[stats[method]].suffix);
 
-	out_fd = G_open_raster_new(output_name, map_type);
+	out_fd = Rast_open_new(output_name, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
 	/* write ratio of target patches with current suffix for statmethod */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -556,11 +559,11 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
     /*
        =============================== DIAGRAM =========================================
@@ -570,7 +573,7 @@
 	strcpy(output_name, newname);
 	strcat(output_name, ".diagram");
 
-	out_fd = G_open_raster_new(output_name, map_type);
+	out_fd = Rast_open_new(output_name, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
@@ -580,11 +583,11 @@
 		d_res[col] = map[row * sx + col];
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /*
@@ -594,16 +597,16 @@
     strcpy(output_name, newname);
     strcat(output_name, ".TP.no");
 
-    out_fd = G_open_raster_new(output_name, map_type);
+    out_fd = Rast_open_new(output_name, DCELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
+	G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
     /* get neighbor count */
-    getNeighborCount(values);
+    getNeighborCount(values, fragcount);
 
     /* write number of neighbors */
     for (row = 0; row < sy; row++) {
-	G_set_d_null_value(d_res, sx);
+	Rast_set_d_null_value(d_res, sx);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -613,11 +616,11 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, d_res);
+	Rast_put_d_row(out_fd, d_res);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /*
        =============================== DIAGRAM =========================================
@@ -627,13 +630,13 @@
 	strcpy(output_name, newname);
 	strcat(output_name, ".id");
 
-	out_fd = G_open_raster_new(output_name, map_type);
+	out_fd = Rast_open_new(output_name, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), output_name);
 
 	/* write ids of patches */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -643,11 +646,11 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
 	/* output matrix */
 	strcpy(output_name, newname);

Copied: grass-addons/grass7/raster/r.pi/r.pi.odc/r.pi.odc.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.odc/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/r.pi.odc.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/r.pi.odc.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,83 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.pi.odc</em> is part of the patch based fragmentation analysis
+package r.pi.* (Patch Index). It computes omnidirectional connectivity
+analysis between patches.
+
+<h2>NOTES</h2>
+
+Several output raster are generated with the defined <em>output</em> file name and a suffix of the information provided. All files named *.FP.* are providing information concerning the focus patch. All files named *.TP.* are providing informaton about the target patches.<br>
+
+TODO: ???<p>
+
+The user must specify the names of the raster map layers to
+be used for <em>input</em> and <em>output</em>, the <em>keyval</em> the
+<em>ratio</em> (area/odd or odd/area) and <em>stats</em> used (i.e., average).
+<p>
+Within <em>r.pi.odc</em> the following setting have to be set:
+
+<h3>keyval setting:</h3>
+
+The <em>keyval</em> operator determines which category value is taken for the Patch Index analysis.
+
+<h3>Ratio setting:</h3>
+
+The <em>ratio</em> operators determine what measure is applied.
+
+<h3>Neighbourhood level:</h3>
+
+The <em>neighbor_level</em> operator determines which neighbourhood level is used. <em>0</em> produces output for the focus patch itself, <em>1</em> assigns the connectivity information of the first omnidirectional neighbours to the focus patch, hence the connectivity of the surrouding fragments. This value can be increased for analysing the more distant neighbours.
+
+<h3>Output:</h3>
+
+Various output files are autmatically created with the pattern $output.*
+
+The<br>
+
+<em>FP</em> describes attributes of the fokus patch (area and area of the odd)
+
+<em>TP</em> describes attributes of the target patch (all neighbouring patches around the FP) - separated by the statsmethod (average, median, variance, stddev)
+
+<em>ratio</em> describes which ratio is taken for all TPs.
+
+The output raster files are named accordingly:<br>
+
+*.FP.area: size of the patch<br>
+*.FP.odd: size of the isolation area<br>
+*.FP.odd_area: ratio of size of patch and size of isolaton area<br>
+
+*.TP.no: amount of neighbouring patches<br>
+*.TP.area.avg: average size of all neighbouring patches<br>
+*.TP.odd.avg: average size of all isolation areas of neighbouring patches<br>
+*.TP.odd_area.avg: average ratio of isolation area to patch size<br>
+
+*.diagram: (if flag -d active) isolation areas and border are depicted
+
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+r.pi.odc input=landclass96 output=odc keyval=5 ratio=odd_area stats=average neighbor_level=0 -d
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.fnn.html">r.pi.fnn</a>,
+<a href="r.pi.enn.html">r.pi.enn</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.odc/voronoi.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/voronoi.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/voronoi.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -6,12 +6,11 @@
 DCELL *areas;
 Point *empty_space;
 PatchPoint *new_edge;
-int new_count;
 
 /*
    allocates memory, initializes the buffers
  */
-void init_voronoi(int *map, int sx, int sy)
+void init_voronoi(int *map, int sx, int sy, int fragcount)
 {
     int x, y;
 
@@ -33,8 +32,6 @@
 	    }
 	}
     }
-
-    new_count = 0;
 }
 
 /*
@@ -47,6 +44,7 @@
 
     memcpy(list + index, list + index + count,
 	   (size - index - count) * sizeof(Point));
+
     return size - count;
 }
 
@@ -60,6 +58,7 @@
 
     memcpy(list + index, list + index + 1,
 	   (size - index - 1) * sizeof(Point));
+
     return size - 1;
 }
 
@@ -78,7 +77,7 @@
    gathers neighbors of a pixel
  */
 int gather_neighbors(int *res, int *map, int x, int y, int sx, int sy,
-		     int diag_grow)
+		     int diag_grow, int fragcount)
 {
     int r, l, t, b;
     int nx, ny;
@@ -111,7 +110,7 @@
 	}
     }
     else {
-	if (x > 0) {		// left
+	if (x > 0) {		/* left */
 	    val = map[x - 1 + y * sx];
 	    if (val > TYPE_NOTHING && checklist[val] == 0) {
 		checklist[val] = 1;
@@ -119,7 +118,7 @@
 		count++;
 	    }
 	}
-	if (x < sx - 1) {	// right
+	if (x < sx - 1) {	/* right */
 	    val = map[x + 1 + y * sx];
 	    if (val > TYPE_NOTHING && checklist[val] == 0) {
 		checklist[val] = 1;
@@ -127,7 +126,7 @@
 		count++;
 	    }
 	}
-	if (y > 0) {		// up
+	if (y > 0) {		/* up */
 	    val = map[x + (y - 1) * sx];
 	    if (val > TYPE_NOTHING && checklist[val] == 0) {
 		checklist[val] = 1;
@@ -135,7 +134,7 @@
 		count++;
 	    }
 	}
-	if (y < sy - 1) {	// left
+	if (y < sy - 1) {	/* down */
 	    val = map[x + (y + 1) * sx];
 	    if (val > TYPE_NOTHING && checklist[val] == 0) {
 		checklist[val] = 1;
@@ -152,7 +151,7 @@
 /*
    grows patches by 1 pixel
  */
-void grow_step(int *map, int sx, int sy, int diag_grow)
+void grow_step(int *map, int sx, int sy, int diag_grow, int fragcount)
 {
     int i, j;
     int *neighbors;
@@ -160,12 +159,12 @@
     int patch;
     int neighb_cnt;
     DCELL area;
+    int new_count = 0;
 
     /* alocate memory */
     neighbors = (int *)G_malloc(fragcount * sizeof(int));
 
     /* iterate through empty space */
-    new_count = 0;
 
     for (i = empty_count - 1; i >= 0; i--) {
 	x = empty_space[i].x;
@@ -173,7 +172,7 @@
 
 	/* if at least one patch edge adjacent */
 	neighb_cnt =
-	    gather_neighbors(neighbors, map, x, y, sx, sy, diag_grow);
+	    gather_neighbors(neighbors, map, x, y, sx, sy, diag_grow, fragcount);
 
 	if (neighb_cnt > 0) {
 	    empty_count = delete_point(i, empty_space, empty_count);
@@ -202,12 +201,12 @@
 	if (patch > TYPE_NOTHING) {
 	    /* test adjacency and mark adjacent patches in the matrix */
 	    neighb_cnt =
-		gather_neighbors(neighbors, map, x, y, sx, sy, diag_grow);
+		gather_neighbors(neighbors, map, x, y, sx, sy, diag_grow, fragcount);
 	    for (j = 0; j < neighb_cnt; j++) {
 		int index1 = patch;
 		int index2 = neighbors[j];
 
-		//                              G_message(_("patches %d and %d are adjacent"), index1, index2);
+		/* G_message(_("patches %d and %d are adjacent"), index1, index2); */
 
 		if (index1 != index2) {
 		    adj_matrix[index1 + index2 * fragcount] = 1;
@@ -221,9 +220,9 @@
 /*
    Expands one patch
  */
-void expand_patch(int patch)
+void expand_patch(int patch, int fragcount)
 {
-    int i, j;
+    int i;
     int *list = (int *)G_malloc(fragcount * sizeof(int));
     int *begin = list;
     int *end = list;
@@ -241,7 +240,7 @@
 	}
     }
 
-    //      while(unleveled > 0) {
+    /* while(unleveled > 0) { */
     while (begin < end) {
 	new_count = 0;
 	/* for each patch on the list */
@@ -279,15 +278,17 @@
 	   G_message("Unleveled: %d", unleveled); */
     }
 
+    /*
     for (i = 0; i < fragcount - 1; i++) {
 	int j;
 
 	for (j = i + 1; j < fragcount; j++) {
 	    if (adj_matrix[i * fragcount + j] == 0) {
-		//G_message("Patch %d und %d sind nicht verbunden!",  i, j);
+		G_message("Patch %d und %d sind nicht verbunden!",  i, j);
 	    }
 	}
     }
+    */
 
     G_free(list);
 }
@@ -295,34 +296,33 @@
 /*
    Expands adjacency matrix by including neighbors of higher grade
  */
-void expand_matrix()
+void expand_matrix(int fragcount)
 {
     int row;
 
     for (row = 0; row < fragcount; row++) {
-	expand_patch(row);
+	expand_patch(row, fragcount);
     }
 }
 
 /*
    constucts a voronoi diagram
  */
-void voronoi(DCELL * values, int *map, int sx, int sy, int diag_grow)
+void voronoi(DCELL * values, int *map, int sx, int sy, int diag_grow, int fragcount)
 {
-    int i, j;
-    int running = 1;
+    int i;
     int max_empty;
     int last_empty = 0;
 
     /* init buffers */
-    init_voronoi(map, sx, sy);
+    init_voronoi(map, sx, sy, fragcount);
 
     /* while empty_space not empty ready grow patch buffers by 1 */
 
     max_empty = empty_count;
     while (empty_count != last_empty) {
 	last_empty = empty_count;
-	grow_step(map, sx, sy, diag_grow);
+	grow_step(map, sx, sy, diag_grow, fragcount);
 
 	G_percent(max_empty - empty_count, max_empty, 1);
     }
@@ -332,7 +332,7 @@
 	values[i] = areas[i];
     }
 
-    expand_matrix();
+    expand_matrix(fragcount);
 
     G_free(areas);
     G_free(empty_space);
@@ -349,12 +349,12 @@
  */
 void calc_neighbors(DCELL * res, DCELL * focals, f_statmethod **methods,
 		    int stat_count, f_compensate compensate,
-		    int neighbor_level)
+		    int neighbor_level, int fragcount)
 {
     int i, j, method;
     int count;
     DCELL val;
-    DCELL *areas = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
+    DCELL *areasn = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
     DCELL *odds = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
     DCELL *ratios = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
 
@@ -365,7 +365,7 @@
 	for (j = 0; j < fragcount; j++) {
 	    /* if patch i(focal) and patch j(neighbor) are adjacent */
 	    if (adj_matrix[j + i * fragcount] == neighbor_level) {
-		areas[count] = fragments[j + 1] - fragments[j];
+		areasn[count] = fragments[j + 1] - fragments[j];
 		odds[count] = focals[j];
 		ratios[count] = compensate(odds[count], count);
 		count++;
@@ -376,7 +376,7 @@
 	/* use the statistical methods to combine these */
 	for (method = 0; method < stat_count; method++) {
 	    /* write areas for neighbors of patch i */
-	    val = methods[method] (areas, count);
+	    val = methods[method] (areasn, count);
 	    res[method * fragcount + i] = val;
 
 	    /* write odds for neighbors of patch i */
@@ -395,7 +395,7 @@
     return;
 }
 
-void getNeighborCount(DCELL * res)
+void getNeighborCount(DCELL * res, int fragcount)
 {
     int i, j;
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/analysis.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/analysis.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/analysis.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,12 +1,7 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 int gather_positions(Position * res, int *map, int *mask, int x, int y,
-		     int sizex, int sizey, int patch_only)
+		     int sx, int sizex, int sizey, int patch_only)
 {
     int i, j;
     int count = 0;
@@ -26,7 +21,7 @@
     return count;
 }
 
-int perform_test(Position * positions, int count, int *map, int x, int y)
+int perform_test(Position * positions, int count, int *map, int sx)
 {
     int p1, p2;
     int x1, x2, y1, y2;
@@ -54,7 +49,7 @@
 }
 
 void perform_analysis(DCELL * values, int *map, int *mask, int n, int size,
-		      int patch_only)
+		      int patch_only, int sx, int sy)
 {
     int x, y, nx, ny, sizex, sizey, i;
     Position *pos_arr;
@@ -79,14 +74,14 @@
 	for (x = 0; x < nx; x++) {
 	    /* get relevant positions */
 	    count =
-		gather_positions(pos_arr, map, mask, x, y, sizex, sizey,
+		gather_positions(pos_arr, map, mask, x, y, sx, sizex, sizey,
 				 patch_only);
 
 	    if (count > 0) {
 		/* perform test n times */
 		value = 0;
 		for (i = 0; i < n; i++) {
-		    value += perform_test(pos_arr, count, map, x, y);
+		    value += perform_test(pos_arr, count, map, sx);
 		}
 	    }
 	    else {

Deleted: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,46 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Probability analysis of 2 random points being in the same patch. 
-
-<h2>NOTES</h2>
-
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann <br>
-Department of Remote Sensing <br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, double distance);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -82,12 +77,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, distance);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -120,17 +115,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, double distance)
+int writeFragments(int *flagbuf, int nrows, int ncols, double distance)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -144,5 +137,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -17,6 +17,11 @@
 #define GLOBAL extern
 #endif
 
+typedef struct
+{
+    int x, y;
+} Position;
+
 typedef DCELL(f_statmethod) (DCELL *, int);
 
 void print_buffer(int *buffer, int sx, int sy);
@@ -26,17 +31,13 @@
 void print_fragments();
 
 /* analysis.c */
-void perform_analysis(DCELL * values, int *map, int *mask, int n, int size, int patch_only);
+void perform_analysis(DCELL * values, int *map, int *mask, int n, int size, int patch_only, int sx, int sy);
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, double distance);
+int writeFragments(int *flagbuf, int nrows, int ncols, double distance);
 
-/* global parameters */
-GLOBAL int sx, sy;
-
 /* global variables */
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.prob.mw
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Probability analysis of 2 randomly set points to be 
  *              located within the same patch - patch-to-patch distance setting optional
  *
@@ -26,30 +27,23 @@
     char *suffix;		/* output suffix */
 };
 
-static struct statmethod statmethods[] = {
-    {average, "average", "average of values", "avg"},
-    {variance, "variance", "variance of values", "var"},
-    {std_deviat, "standard deviation", "standard deviation of values", "dev"},
-    {median, "median", "median of values", "med"},
-    {min, "min", "minimum of values", "min"},
-    {max, "max", "maximum of values", "max"},
-    {0, 0, 0, 0}
-};
-
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
+
     /* output */
-    char *newname, *newmapset;
+    char *newname;
+
     /* mask */
-    char *maskname, *maskmapset;
+    char *maskname;
+    const char *maskmapset;
+
     /* in and out file pointers */
     int in_fd, out_fd;
+
     /* parameters */
-    int stats[GNAME_MAX];
-    f_statmethod *methods;
-    int stat_count;
     int keyval;
     int n;
     int size;
@@ -60,24 +54,17 @@
     int *map;
     int *mask;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
+    int sx, sy;
     CELL *result;
     DCELL *d_res;
     DCELL *values;
-    int i, j;
+    int i;
     Coords *p;
-    char *str;
-    int method;
-    char outname[GNAME_MAX];
     int nx, ny;
+    int fragcount;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -93,7 +80,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Probability analysis of 2 random points being in the same patch.");
 
@@ -148,16 +135,17 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* get name of mask */
     maskname = parm.mask->answer;
+    maskmapset = NULL;
 
     /* test costmap existance */
-    if (maskname && (maskmapset = G_find_cell2(maskname, "")) == NULL)
-	        G_fatal_error(_("Raster map <%s> not found"), maskname);
+    if (maskname && (maskmapset = G_find_raster2(maskname, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), maskname);
 
     /* get keyval */
     sscanf(parm.keyval->answer, "%d", &keyval);
@@ -188,13 +176,10 @@
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
 	G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
 
-    map_type = DCELL_TYPE;
-
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* test output */
     /*      G_message("TEST OUTPUT :");
@@ -212,8 +197,8 @@
     mask = (int *) G_malloc(sx * sy * sizeof(int));
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
 
-    result = G_allocate_c_raster_buf();
-    d_res = G_allocate_d_raster_buf();
+    result = Rast_allocate_c_buf();
+    d_res = Rast_allocate_d_buf();
 
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     fragments[0] = cells;
@@ -223,14 +208,14 @@
     values = (DCELL *) G_malloc(nx * ny * sizeof(Coords));
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
@@ -241,7 +226,7 @@
     G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* test output */
     /*      G_message("map:\n");
@@ -250,14 +235,14 @@
     /* if mask specified, read mask */
     if (maskname) {
 	/* open mask file */
-	in_fd = G_open_cell_old(maskname, maskmapset);
+	in_fd = Rast_open_old(maskname, maskmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), maskname);
 
 	/* read mask */
 	G_message("Reading mask file:");
 	for (row = 0; row < sy; row++) {
-	    G_get_c_raster_row(in_fd, result, row);
+	    Rast_get_c_row(in_fd, result, row);
 	    for (col = 0; col < sx; col++) {
 		mask[row * sx + col] = result[col];
 	    }
@@ -267,7 +252,7 @@
 	G_percent(1, 1, 2);
 
 	/* close mask */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no costmap specified, fill mask with 1 */
@@ -281,7 +266,7 @@
        print_d_buffer(costmap, sx, sy); */
 
     /* find fragments */
-    writeFragments(map, sy, sx, distance);
+    fragcount = writeFragments(map, sy, sx, distance);
 
     /* test output */
     /*      G_message("fragcount = %d", fragcount);
@@ -299,7 +284,7 @@
 
     G_message("Performing analysis:");
 
-    perform_analysis(values, map, mask, n, size, patch_only);
+    perform_analysis(values, map, mask, n, size, patch_only, sx, sy);
 
     /* test output */
     /*G_message("Values: ");
@@ -314,13 +299,13 @@
 	G_message("Writing output...");
 
 	/* open the new cellfile  */
-	out_fd = G_open_raster_new(newname, map_type);
+	out_fd = Rast_open_new(newname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    if (row >= size / 2 && row < ny + size / 2) {
 		for (col = 0; col < nx; col++) {
@@ -329,17 +314,17 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
     }
     else {
-	fprintf(stdout, "\n\noutput = %lf\n\n", values[0]);
+	fprintf(stdout, "\n\noutput = %f\n\n", values[0]);
     }
 
     /* free allocated resources */

Copied: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/r.pi.prob.mw.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.prob.mw/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/r.pi.prob.mw.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/r.pi.prob.mw.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,46 @@
+<h2>DESCRIPTION</h2>
+
+Probability analysis of 2 random points being in the same patch. 
+
+<h2>NOTES</h2>
+
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.rectangle.html">r.pi.rectangle</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann <br>
+Department of Remote Sensing <br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.prox/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.prox/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,33 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-Calculates different proximity indices using defined buffer areas.
-
-<h2>NOTES</h2>
-...
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.index.html">r.fragment</a>,
-<a href="r.pi.neigh.html">r.pi.enn</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann<br>
-Department of Remote Sensing<br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.prox/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -12,7 +12,7 @@
     int x, y;
 } Position;
 
-int getNeighbors(Position * res, int x, int y, int nx, int ny, int nbr_cnt)
+int getNeighbors(int *flagbuf, Position * res, int x, int y, int nx, int ny, int nbr_cnt)
 {
     int left, right, top, bottom;
     int i, j;
@@ -61,7 +61,7 @@
     return cnt;
 }
 
-void writeFrag(int row, int col, int nbr_cnt)
+void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols,int nbr_cnt)
 {
     int x, y, i;
     Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
@@ -98,16 +98,11 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
-	int cnt = getNeighbors(nbr_list, c, r, ncols, nrows, nbr_cnt);
+	int cnt = getNeighbors(flagbuf, nbr_list, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -139,5 +134,6 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.prox/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/func.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/func.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -24,13 +24,13 @@
     Coords *p1, *p2;
     DCELL min = 1000000.0;
 
-    // for all cells in the first patch
+    /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
-	// if cell at the border
+	/* if cell at the border */
 	if (p1->neighbors < 4) {
-	    // for all cells in the second patch
+	    /* for all cells in the second patch */
 	    for (p2 = frags[n2]; p2 < frags[n2 + 1]; p2++) {
-		// if cell at the border
+		/* if cell at the border */
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
@@ -41,6 +41,7 @@
 	    }
 	}
     }
+
     return min;
 }
 
@@ -85,6 +86,7 @@
     }
 
     G_free(distmatrix);
+
     return 0;
 }
 
@@ -96,6 +98,7 @@
 
     for (i = 0; i < count; i++) {
 	DCELL prox = 0.0;
+	DCELL area;
 
 	for (j = 0; j < count; j++) {
 	    if (i != j) {
@@ -106,12 +109,13 @@
 		    prox += area / d;
 	    }
 	}
-	DCELL area = (DCELL) (frags[i + 1] - frags[i]);
+	area = (DCELL) (frags[i + 1] - frags[i]);
 
 	vals[i] = prox * area;
     }
 
     G_free(distmatrix);
+
     return 0;
 }
 
@@ -135,5 +139,6 @@
     }
 
     G_free(distmatrix);
+
     return 0;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.prox/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,3 +1,14 @@
+#ifndef LOCAL_PROTO_H
+#define LOCAL_PROTO_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <math.h>
+#include <time.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
 
 #ifdef MAIN
@@ -7,7 +18,7 @@
 #endif
 
 /* frag.c */
-void writeFrag(int row, int col, int nbr_cnt);
+void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols,int nbr_cnt);
 
 /* func.c */
 int f_proximity(DCELL *, Coords **, int, int, int);
@@ -16,8 +27,7 @@
 int f_neighborhood(DCELL *, Coords **, int, int, int);
 
 /* global variables */
-GLOBAL int nrows, ncols;
 GLOBAL Coords **fragments;
-GLOBAL int *flagbuf;
 GLOBAL Coords *actpos;
-GLOBAL int cnt;
+
+#endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.prox/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.prox
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Proximity analysis - values of patches within a defined range
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -48,13 +49,14 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *newname, *oldname, *newmapset, *oldmapset;
+    char *newname, *oldname;
+    const char *oldmapset;
     char title[1024];
 
     /* in and out file pointers */
     int in_fd;
     int out_fd;
-    DCELL *result, res[30];
+    DCELL *result;
 
     /* map_type and categories */
     RASTER_MAP_TYPE map_type;
@@ -68,11 +70,12 @@
     /* neighbors count */
     int neighb_count;
 
-    int row, col, i, j;
-    int readrow;
+    int row, col, i;
+    int nrows, ncols;
     int keyval;
     int min = 0;
     int max = MAX_DOUBLE;
+    int *flagbuf;
 
     int n;
     int copycolr;
@@ -93,12 +96,10 @@
     Coords *cells;
     int fragcount = 0;
 
-    struct Cell_head ch, window;
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Calculates correlation of two raster maps "
 	  "by calculating correlation function of two "
@@ -157,28 +158,27 @@
     parm.title->description = _("Title for resultant raster map");
 
     if (G_parser(argc, argv))
-	    exit(EXIT_FAILURE);
+	exit(EXIT_FAILURE);
 
     /* get names of input files */
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
-	if (oldmapset == NULL)
+    oldmapset = G_find_raster2(oldname, "");
+    if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
-	    G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
+	G_fatal_error(_("<%s> is an illegal file name"), newname);
 
     /* get size */
-    nrows = G_window_rows();
-    ncols = G_window_cols();
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
 
     /* open cell files */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
         G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
@@ -186,7 +186,7 @@
     map_type = DCELL_TYPE;	/* G_raster_map_type(oldname, oldmapset); */
 
     /* copy color table */
-    copycolr = (G_read_colors(oldname, oldmapset, &colr) > 0);
+    copycolr = (Rast_read_colors(oldname, oldmapset, &colr) > 0);
 
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
@@ -214,7 +214,7 @@
     fragments = (Coords **) G_malloc(nrows * ncols * sizeof(Coords *));
     fragments[0] = cells;
     flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
-    result = G_allocate_d_raster_buf();
+    result = Rast_allocate_d_buf();
 
     /* get min */
     if (parm.min->answer)
@@ -231,15 +231,15 @@
 	sprintf(title, "Fragmentation of file: %s", oldname);
 
     /* open the new cellfile  */
-    out_fd = G_open_raster_new(newname, map_type);
+    out_fd = Rast_open_new(newname, map_type);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     G_message(_("Percent complete ... "));
 
     /* find fragments */
     for (row = 0; row < nrows; row++) {
-	G_get_d_raster_row(in_fd, result, row);
+	Rast_get_d_row(in_fd, result, row);
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
@@ -253,11 +253,12 @@
 	for (col = 0; col < ncols; col++) {
 	    if (flagbuf[row * ncols + col] == 1) {
 		fragcount++;
-		writeFrag(row, col, neighb_count);
+		writeFrag(flagbuf, row, col, nrows, ncols, neighb_count);
 		fragments[fragcount] = actpos;
 	    }
 	}
     }
+    Rast_close(in_fd);
 
     /* perform actual function on the patches */
     values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
@@ -265,7 +266,7 @@
 
     /* write the output file */
     for (row = 0; row < nrows; row++) {
-	G_set_d_null_value(result, ncols);
+	Rast_set_d_null_value(result, ncols);
 
 	for (i = 0; i < fragcount; i++) {
 	    for (actpos = fragments[i]; actpos < fragments[i + 1]; actpos++) {
@@ -275,23 +276,22 @@
 	    }
 	}
 
-	G_put_d_raster_row(out_fd, result);
+	Rast_put_d_row(out_fd, result);
     }
 
     G_percent(row, nrows, 2);
 
-    G_close_cell(out_fd);
-    G_close_cell(in_fd);
+    Rast_close(out_fd);
 
     G_free(cells);
     G_free(fragments);
     G_free(flagbuf);
 
-    G_init_cats(0, title, &cats);
-    G_write_cats(newname, &cats);
+    Rast_init_cats(title, &cats);
+    Rast_write_cats(newname, &cats);
 
     if (copycolr)
-	G_write_colors(newname, newmapset, &colr);
+	Rast_write_colors(newname, G_mapset(), &colr);
 
     exit(EXIT_SUCCESS);
 }

Copied: grass-addons/grass7/raster/r.pi/r.pi.prox/r.pi.prox.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.prox/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/r.pi.prox.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/r.pi.prox.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,33 @@
+<h2>DESCRIPTION</h2>
+
+Calculates different proximity indices using defined buffer areas.
+
+<h2>NOTES</h2>
+...
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.index.html">r.fragment</a>,
+<a href="r.pi.neigh.html">r.pi.enn</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann<br>
+Department of Remote Sensing<br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.rectangle/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.rectangle/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.rectangle/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -2,8 +2,8 @@
 
 PGM = r.pi.rectangle
 
-LIBES = $(STATSLIB) $(GISLIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.rectangle/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.rectangle/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.rectangle/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,56 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.pi.rectangle</em> converts sampling points (e.g. GPS coordinates)
-of the corner of a sampling site into an area by generating a defined rectangle.
-
-Generates a rectangle based on a corner coordinate. 
-<p>
-This modules aims at generating sampling areas which are only known by the
-coordinate of one corner. The input are single points, while the output are
-areas representing the corresponding area for each of the single
-points/coordinates.
-
-<h2>NOTES</h2>
-
-The areas can only be generated horizontally, not diagonal. This can
-be added as wish and might be implemented in the future.
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-<div class="code"><pre>
-g.region -d
-...
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.corearea.html">r.pi.corearea</a>,
-<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
-<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
-<a href="r.pi.export.html">r.pi.export</a>,
-<a href="r.pi.graph.html">r.pi.graph</a>,
-<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
-<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
-<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
-<a href="r.pi.grow.html">r.pi.grow</a>,
-<a href="r.pi.import.html">r.pi.import</a>,
-<a href="r.pi.index.html">r.pi.index</a>,
-<a href="r.pi.lm.html">r.pi.lm</a>,
-<a href="r.pi.odc.html">r.pi.odc</a>,
-<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann <br>
-Department of Remote Sensing <br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>
-

Modified: grass-addons/grass7/raster/r.pi/r.pi.rectangle/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.rectangle/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.rectangle/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -4,12 +4,12 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <math.h>
+#include <time.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
-#include <math.h>
-#include <time.h>
 
 /* buffer.c */
 void set_buffer(CELL * buffer, int x, int y, int width, int height, int sx,

Modified: grass-addons/grass7/raster/r.pi/r.pi.rectangle/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.rectangle/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.rectangle/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.rectangle
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Delineation of rectangular study areas based on GPS location
  *                               of the respective corners
  *
@@ -35,10 +36,11 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* input */
-    char *newname, *newmapset;
+    char *newname;
 
     /* in and out file pointers */
     int in_fd;
@@ -53,17 +55,12 @@
     /* maps */
     CELL *map, *newmap;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
     CELL *result;
     char *str;
-    int n, i;
-    RASTER_MAP_TYPE map_type;
+    int n;
 
-    struct Cell_head ch, window;
     struct GModule *module;
     struct
     {
@@ -76,7 +73,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Generates a rectangle based on a corner coordinate.");
 
@@ -137,15 +134,14 @@
     oldname = parm.input->answer;
 
     /* test input files existence */
-    oldmapset = G_find_cell2(oldname, "");
-	if (oldmapset == NULL)
+    oldmapset = G_find_raster2(oldname, "");
+    if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* check if the new file name is correct */
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
 	G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
 
     /* read keyval */
     sscanf(parm.keyval->answer, "%d", &keyval);
@@ -157,8 +153,8 @@
     sscanf(parm.y->answer, "%d", &y);
 
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* find alignment */
     for (n = 0; (str = alignments[n].name); n++)
@@ -178,20 +174,20 @@
     /* allocate map buffers */
     map = (CELL *) G_malloc(sx * sy * sizeof(CELL));
     newmap = (CELL *) G_malloc(sx * sy * sizeof(CELL));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
 
     /* fill newmap with null */
-    G_set_c_null_value(newmap, sx * sy);
+    Rast_set_c_null_value(newmap, sx * sy);
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, map + row * sx, row);
+	Rast_get_c_row(in_fd, map + row * sx, row);
 
 	G_percent(row + 1, sy, 1);
     }
@@ -206,34 +202,31 @@
     }
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* write the output file */
     G_message("Writing output...");
 
-    /* open cell file */
-    if ((in_fd = G_open_cell_old(oldname, oldmapset)) < 0) {
-    }
     /* open new cell file  */
-    out_fd = G_open_raster_new(newname, CELL_TYPE);
+    out_fd = Rast_open_new(newname, CELL_TYPE);
     if (out_fd < 0)
-	    G_fatal_error(_("Cannot create raster map <%s>"), newname);
+	G_fatal_error(_("Cannot create raster map <%s>"), newname);
 
     /* write output */
     for (row = 0; row < sy; row++) {
-	G_set_c_null_value(result, sx);
+	Rast_set_c_null_value(result, sx);
 
 	for (col = 0; col < sx; col++) {
 	    result[col] = newmap[row * sx + col];
 	}
 
-	G_put_c_raster_row(out_fd, result);
+	Rast_put_c_row(out_fd, result);
 
 	G_percent(row + 1, sy, 1);
     }
 
     /* close new file */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
 
     /* free allocated resources */
     G_free(map);

Copied: grass-addons/grass7/raster/r.pi/r.pi.rectangle/r.pi.rectangle.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.rectangle/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.rectangle/r.pi.rectangle.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.rectangle/r.pi.rectangle.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,56 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.pi.rectangle</em> converts sampling points (e.g. GPS coordinates)
+of the corner of a sampling site into an area by generating a defined rectangle.
+
+Generates a rectangle based on a corner coordinate. 
+<p>
+This modules aims at generating sampling areas which are only known by the
+coordinate of one corner. The input are single points, while the output are
+areas representing the corresponding area for each of the single
+points/coordinates.
+
+<h2>NOTES</h2>
+
+The areas can only be generated horizontally, not diagonal. This can
+be added as wish and might be implemented in the future.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+<div class="code"><pre>
+g.region -d
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.corearea.html">r.pi.corearea</a>,
+<a href="r.pi.corrwin.html">r.pi.corrwin</a>,
+<a href="r.pi.csr.mw.html">r.pi.csr.mw</a>,
+<a href="r.pi.export.html">r.pi.export</a>,
+<a href="r.pi.graph.html">r.pi.graph</a>,
+<a href="r.pi.graph.dec.html">r.pi.graph.dec</a>,
+<a href="r.pi.graph.iter.html">r.pi.graph.iter</a>,
+<a href="r.pi.graph.red.html">r.pi.graph.red</a>,
+<a href="r.pi.grow.html">r.pi.grow</a>,
+<a href="r.pi.import.html">r.pi.import</a>,
+<a href="r.pi.index.html">r.pi.index</a>,
+<a href="r.pi.lm.html">r.pi.lm</a>,
+<a href="r.pi.odc.html">r.pi.odc</a>,
+<a href="r.pi.prob.mw.html">r.pi.prob.mw</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann <br>
+Department of Remote Sensing <br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>
+

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.searchtime/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,86 +0,0 @@
-Individual-based dispersal model for connectivity analysis (time-based) 
-
-<h2>DESCRIPTION</h2>
-
-This modules provides information about the isolation or connectivity of individual fragments derived of a landcover classification. Unlike <em>r.pi.energy</em> this module provides information about the time from emigration to immigration. The individual based dispersal model results are based on the step length and range, the perception distance and the attractivity to move towards patches.
-
-
-<h2>NOTES</h2>
-
-The suitability matrix impacts the step direction of individuals. If individuals are moving beyond the mapset borders the indivuals are set back to their original source patches.
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-
-The connectivity of patches of the <em>landclass96</em> class 5 are computed using the time from emigration to immigration. The step length is set to 5 pixel, the output statistics are set to <em>average</em> time and <em>variance</em> of searchtime. For each patch 1000 individuals were released and the model stopped when at least 80% of all individuals sucessfully immigrated:<br>
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000
-</pre></div>
-
-constrain the angle of forward movement to 10 degrees:
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 step_range=10
-</pre></div>
-
-setting the perception range to 10 pixel:
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 perception=10
-</pre></div>
-
-increasing the attraction to move towards patches to 10:
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 multiplicator=10
-</pre></div>
-
-limiting the amount of steps to 10:
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 maxsteps=10
-</pre></div>
-
-output of each movement location for a defined step frequency. Here every 10th step is provided as output raster:
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 out_freq=10
-</pre></div>
-
-output of a raster which immigration counts:
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 out_immi=immi_counts
-</pre></div>
-
-output of a binary immigration matrix. Each patch emigration and immigration for all patch combinations is recorded as 0 or 1:
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 binary_matrix=binary_matrix.txt
-</pre></div>
-
-output of a matrix with immigration counts for each patch:
-<div class="code"><pre>
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 immi_matrix=immi_counts.txt
-</pre></div>
-
-the previous examples assumed a homogeneous matrix, a heterogenous matrix can be included using a raster file which values are taken as costs for movement (0-100):
-<div class="code"><pre>
-# it is assumed that our species is a forest species and cannot move through water, hence a cost of 100, does not like urban areas (class: 6, cost: 10) but can disperse through shrubland (class 4, cost=1) better than through grassland (class 3, cost: 2):
-r.mapcalc "suit_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
-r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 suitability=suit_raster
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.searchtime.iter.html">r.pi.searchtime.iter</a>,
-<a href="r.pi.searchtime.mw.html">r.pi.searchtime.mw</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann <br>
-Department of Remote Sensing <br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -98,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,17 +130,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -164,5 +152,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -7,6 +7,7 @@
 #include <math.h>
 #include <time.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 #include <grass/stats.h>
 #include "../r.pi.library/r_pi.h"
@@ -20,6 +21,11 @@
 typedef struct
 {
     int x, y;
+} Position;
+
+typedef struct
+{
+    int x, y;
     double dir;
     DCELL path;
     int finished;
@@ -46,20 +52,18 @@
 void print_fragments();
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* search.c */
 void perform_search(DCELL * values, int *map, DCELL * costmap,
-		    f_statmethod **stats, int stat_count);
+		    f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy);
 
 /* indices.c */
 DCELL shannon_index(int patch);
 DCELL simpson_index(int patch);
 
 /* global parameters */
-GLOBAL int sx, sy;
 GLOBAL int keyval;
-GLOBAL int n;
 GLOBAL double percent;
 GLOBAL int maxsteps;
 GLOBAL int step_length;
@@ -72,13 +76,13 @@
 /* global variables */
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 GLOBAL Individual *indi_array;
 GLOBAL int *patch_imi;
 
-GLOBAL char *newname, *newmapset;
-GLOBAL char *iminame, *imimapset;
+GLOBAL char *newname;
+GLOBAL char *iminame;
+GLOBAL const char *imimapset;
 
 GLOBAL int *immi_matrix, *mig_matrix;
 

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.searchtime
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Individual-based dispersal model for connectivity analysis - time-based
  *
  * COPYRIGHT:    (C) 2009-2011 by the GRASS Development Team
@@ -38,10 +39,12 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* costmap */
-    char *costname, *costmapset;
+    char *costname;
+    const char *costmapset;
 
     /* in and out file pointers */
     int in_fd, out_fd;
@@ -57,12 +60,9 @@
     int *map;
     DCELL *costmap;
 
-
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
+    int sx, sy;
     CELL *result;
     DCELL *d_res;
     DCELL *values;
@@ -72,10 +72,9 @@
     char *str;
     int method;
     char outname[GNAME_MAX];
+    int fragcount;
+    int n;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -94,7 +93,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description = _("Individual-based dispersal model for connectivity analysis (time-based)");
 
     parm.input = G_define_standard_option(G_OPT_R_INPUT);
@@ -269,15 +268,18 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* get name of costmap */
     costname = parm.costmap->answer;
+    costmapset = NULL;
 
-    /* test costmap existance */    if (costname && (costmapset = G_find_cell2(costname, "")) == NULL)
-	    G_fatal_error(_("Raster map <%s> not found"), costname);    /* get keyval */
+    /* test costmap existance */
+    if (costname && (costmapset = G_find_raster2(costname, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), costname);
+    /* get keyval */
     sscanf(parm.keyval->answer, "%d", &keyval);
 
     /* get step_length */
@@ -332,7 +334,6 @@
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
 	G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
 
     /* check if the immigrants file name is correct */
     iminame = parm.out_immi->answer;
@@ -340,11 +341,9 @@
 	G_fatal_error(_("<%s> is an illegal file name"), iminame);
     imimapset = G_mapset();
 
-    map_type = DCELL_TYPE;
-
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* get maxsteps */
     if (parm.maxsteps->answer != NULL) {
@@ -399,22 +398,22 @@
 
     /* allocate map buffers */
     map = (int *)G_malloc(sx * sy * sizeof(int));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
     costmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
-    d_res = G_allocate_d_raster_buf();
+    d_res = Rast_allocate_d_buf();
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     fragments[0] = cells;
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
@@ -425,7 +424,7 @@
     G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* test output */
     /*      G_message("map:\n");
@@ -434,17 +433,14 @@
     /* if costmap specified, read costmap */
     if (costname != NULL) {
 	/* open costmap */
-	if ((in_fd = G_open_cell_old(costname, costmapset)) < 0) {
-	    G_fatal_error(_("can't open cell file <%s> in mapset %s\n"),
-			  costname, costmapset);
-	    G_usage();
-	    exit(EXIT_FAILURE);
-	}
+	in_fd = Rast_open_old(costname, costmapset);
+	if (in_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), costname);
 
 	/* read costmap */
 	G_message("Reading costmap:");
 	for (row = 0; row < sy; row++) {
-	    G_get_d_raster_row(in_fd, d_res, row);
+	    Rast_get_d_row(in_fd, d_res, row);
 	    for (col = 0; col < sx; col++) {
 		costmap[row * sx + col] = d_res[col];
 	    }
@@ -454,7 +450,7 @@
 	G_percent(1, 1, 2);
 
 	/* close costmap */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no costmap specified, fill costmap with 100 */
@@ -468,7 +464,7 @@
        print_d_buffer(costmap, sx, sy); */
 
     /* find fragments */
-    writeFragments(map, sy, sx, neighb_count);
+    fragcount = writeFragments(map, sy, sx, neighb_count);
 
     /* test output */
     /*      print_fragments(); */
@@ -498,7 +494,7 @@
 
     /* perform search */
     values = (DCELL *) G_malloc(fragcount * stat_count * sizeof(DCELL));
-    perform_search(values, map, costmap, methods, stat_count);
+    perform_search(values, map, costmap, methods, stat_count, n, fragcount, sx, sy);
 
     /* test output */
     G_message("Results:");
@@ -516,13 +512,13 @@
 
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, statmethods[stats[method]].suffix);
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -532,24 +528,24 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(method * sy + row + 1, sy * stat_count, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* open the new cellfile  */
     if (iminame) {
-	out_fd = G_open_raster_new(iminame, map_type);
+	out_fd = Rast_open_new(iminame, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), iminame);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -559,7 +555,7 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row, sy, 2);
 	}
@@ -567,7 +563,7 @@
 	G_percent(100, 100, 2);
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write immigrants matrix ASCII file */
@@ -612,12 +608,13 @@
 	for (i = 0; i < fragcount; i++) {
 	    /* calculate sum of all imigrants from patch i */
 	    int sum = 0;
+	    int threshold_count;
 
 	    for (j = 0; j < fragcount; j++) {
 		sum += immi_matrix[j * fragcount + i];
 	    }
 
-	    int threshold_count = (int)(threshold * (double)sum) / 100;
+	    threshold_count = (int)(threshold * (double)sum) / 100;
 
 	    for (j = 0; j < fragcount; j++) {
 		if (immi_matrix[i * fragcount + j] > threshold_count) {
@@ -639,182 +636,184 @@
     /* write diversity maps */
     if (flag.diversity->answer) {
 	/* calculate diversity */
-	DCELL *values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
+	DCELL *valuest = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
 
 	for (i = 0; i < fragcount; i++) {
 	    /* calculate sum of all imigrants in patch i */
 	    int sum = 0;
+	    int threshold_count;
+	    DCELL value = 0;
 
 	    for (j = 0; j < fragcount; j++) {
 		sum += immi_matrix[j * fragcount + i];
 	    }
 
 	    /* calculate threshold count */
-	    int threshold_count = (int)(threshold * (double)sum) / 100;
+	    threshold_count = (int)(threshold * (double)sum) / 100;
 
 	    /* count patches with immigrant count exceeding threshold */
-	    DCELL value = 0;
-
 	    for (j = 0; j < fragcount; j++) {
 		if (immi_matrix[j * fragcount + i] > threshold_count) {
 		    value++;
 		}
 	    }
 
-	    values[i] = value;
+	    valuest[i] = value;
 	}
 
 	/* antidiversity */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, "diversity");
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
 		    if (p->y == row) {
-			d_res[p->x] = values[i];
+			d_res[p->x] = valuest[i];
 		    }
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
 	/* antidiversity percentual */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s_percent", newname, "diversity");
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
 		    if (p->y == row) {
 			d_res[p->x] =
-			    values[i] / (DCELL) (fragcount - 1) * 100.0;
+			    valuest[i] / (DCELL) (fragcount - 1) * 100.0;
 		    }
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write antidiversity maps */
     if (flag.diversity->answer) {
 	/* calculate antidiversity */
-	DCELL *values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
+	DCELL *valuest = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
 
 	for (i = 0; i < fragcount; i++) {
 	    /* calculate sum of all imigrants from patch i */
 	    int sum = 0;
+	    int threshold_count;
+	    DCELL value = 0;
 
 	    for (j = 0; j < fragcount; j++) {
 		sum += immi_matrix[i * fragcount + j];
 	    }
 
 	    /* calculate threshold count */
-	    int threshold_count = (int)(threshold * (double)sum) / 100;
+	    threshold_count = (int)(threshold * (double)sum) / 100;
 
 	    /* count all patches with emigrant count exceeding threshold */
-	    DCELL value = 0;
-
 	    for (j = 0; j < fragcount; j++) {
 		if (immi_matrix[i * fragcount + j] > threshold_count) {
 		    value++;
 		}
 	    }
 
-	    values[i] = value;
+	    valuest[i] = value;
 	}
 
 	/* antidiversity */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, "antidiversity");
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
 		    if (p->y == row) {
-			d_res[p->x] = values[i];
+			d_res[p->x] = valuest[i];
 		    }
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
 	/* antidiversity percentual */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s_percent", newname, "antidiversity");
-	out_fd = G_open_raster_new(outname, map_type);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
 		    if (p->y == row) {
 			d_res[p->x] =
-			    values[i] / (DCELL) (fragcount - 1) * 100.0;
+			    valuest[i] / (DCELL) (fragcount - 1) * 100.0;
 		    }
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* write indices for immigrants */
     if (flag.indices->answer) {
+	DCELL *valuest;
+
 	/* SHANNON */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, "shannon");
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	/* calculate indices */
-	DCELL *values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
+	valuest = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
 
 	for (i = 0; i < fragcount; i++) {
 	    int N = 0;
@@ -829,33 +828,33 @@
 		}
 	    }
 
-	    values[i] = log((DCELL) N) - sum / (DCELL) N;
+	    valuest[i] = log((DCELL) N) - sum / (DCELL) N;
 	}
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
 		    if (p->y == row) {
-			d_res[p->x] = values[i];
+			d_res[p->x] = valuest[i];
 		    }
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
 
 	/* SIMPSON */
 	/* open the new cellfile  */
 	sprintf(outname, "%s_%s", newname, "simpson");
-	out_fd = G_open_raster_new(outname, DCELL_TYPE);
+	out_fd = Rast_open_new(outname, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
@@ -871,30 +870,30 @@
 		sum += immi * (immi - 1);
 	    }
 
-	    values[i] = (DCELL) sum / (DCELL) (N * (N - 1));
+	    valuest[i] = (DCELL) sum / (DCELL) (N * (N - 1));
 	}
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
 		    if (p->y == row) {
-			d_res[p->x] = values[i];
+			d_res[p->x] = valuest[i];
 		    }
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row + 1, sy, 1);
 	}
 
-	G_free(values);
+	G_free(valuest);
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* free allocated resources */

Copied: grass-addons/grass7/raster/r.pi/r.pi.searchtime/r.pi.searchtime.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.searchtime/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/r.pi.searchtime.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/r.pi.searchtime.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,86 @@
+Individual-based dispersal model for connectivity analysis (time-based) 
+
+<h2>DESCRIPTION</h2>
+
+This modules provides information about the isolation or connectivity of individual fragments derived of a landcover classification. Unlike <em>r.pi.energy</em> this module provides information about the time from emigration to immigration. The individual based dispersal model results are based on the step length and range, the perception distance and the attractivity to move towards patches.
+
+
+<h2>NOTES</h2>
+
+The suitability matrix impacts the step direction of individuals. If individuals are moving beyond the mapset borders the indivuals are set back to their original source patches.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+
+The connectivity of patches of the <em>landclass96</em> class 5 are computed using the time from emigration to immigration. The step length is set to 5 pixel, the output statistics are set to <em>average</em> time and <em>variance</em> of searchtime. For each patch 1000 individuals were released and the model stopped when at least 80% of all individuals sucessfully immigrated:<br>
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000
+</pre></div>
+
+constrain the angle of forward movement to 10 degrees:
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 step_range=10
+</pre></div>
+
+setting the perception range to 10 pixel:
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 perception=10
+</pre></div>
+
+increasing the attraction to move towards patches to 10:
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 multiplicator=10
+</pre></div>
+
+limiting the amount of steps to 10:
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 maxsteps=10
+</pre></div>
+
+output of each movement location for a defined step frequency. Here every 10th step is provided as output raster:
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 out_freq=10
+</pre></div>
+
+output of a raster which immigration counts:
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 out_immi=immi_counts
+</pre></div>
+
+output of a binary immigration matrix. Each patch emigration and immigration for all patch combinations is recorded as 0 or 1:
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 binary_matrix=binary_matrix.txt
+</pre></div>
+
+output of a matrix with immigration counts for each patch:
+<div class="code"><pre>
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 immi_matrix=immi_counts.txt
+</pre></div>
+
+the previous examples assumed a homogeneous matrix, a heterogenous matrix can be included using a raster file which values are taken as costs for movement (0-100):
+<div class="code"><pre>
+# it is assumed that our species is a forest species and cannot move through water, hence a cost of 100, does not like urban areas (class: 6, cost: 10) but can disperse through shrubland (class 4, cost=1) better than through grassland (class 3, cost: 2):
+r.mapcalc "suit_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
+r.pi.searchtime input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 suitability=suit_raster
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.searchtime.iter.html">r.pi.searchtime.iter</a>,
+<a href="r.pi.searchtime.mw.html">r.pi.searchtime.mw</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann <br>
+Department of Remote Sensing <br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime/search.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/search.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/search.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -12,20 +12,20 @@
 /*
    output raster with current simulation state
  */
-void test_output(int *map, int patch, int step, int n)
+void test_output(int *map, int patch, int step, int n, int sx, int sy)
 {
     int out_fd;
-    int row, col, i;
+    int row, i;
     char outname[GNAME_MAX];
     DCELL *outmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
 
     /* open the new cellfile  */
     sprintf(outname, "%s_patch%d_step%d", newname, patch, step);
 
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
@@ -42,7 +42,7 @@
 	x = indi->x;
 	y = indi->y;
 
-	//              fprintf(stderr, "indi%d: (%d, %d)\n", i, x, y);
+	/* fprintf(stderr, "indi%d: (%d, %d)\n", i, x, y); */
 
 	outmap[x + y * sx]++;
     }
@@ -62,11 +62,11 @@
 
     /* write output */
     for (row = 0; row < sy; row++) {
-	G_put_d_raster_row(out_fd, outmap + row * sx);
+	Rast_put_d_row(out_fd, outmap + row * sx);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
     G_free(outmap);
 }
 
@@ -106,7 +106,7 @@
 /*
    picks a random direction pointing outwards a patch
  */
-double pick_dir(int *map, Coords * frag)
+double pick_dir(int *map, Coords * frag, int sx, int sy)
 {
     double dirs[4];
     int i;
@@ -125,7 +125,7 @@
     if (y >= sy || map[x + (y - 1) * sx] == TYPE_NOTHING)
 	dirs[count++] = 0.75;
 
-    //      G_message("Picks for (%d, %d): %0.2f, %0.2f, %0.2f, %0.2f, cnt=%d", x, y, dirs[0], dirs[1], dirs[2], dirs[3], count);
+    /* G_message("Picks for (%d, %d): %0.2f, %0.2f, %0.2f, %0.2f, cnt=%d", x, y, dirs[0], dirs[1], dirs[2], dirs[3], count); */
 
     pick = count * Randomf();
 
@@ -136,29 +136,29 @@
 	    if (res < 0) {
 		res++;
 	    }
-	    //                      res = res < 0 ? 2 * M_PI + res : res;
-	    //                      G_message("dir = %0.2f", res);
+	    /* res = res < 0 ? 2 * M_PI + res : res; */
+	    /* G_message("dir = %0.2f", res); */
 	    return res;
 	}
     }
 
-    return -1;			// error
+    return -1;			/* error */
 }
 
 /*
    initializes all individuals for a fragment
  */
-void init_individuals(int *map, Coords * frag, int size, int n)
+void init_individuals(int *map, Coords * frag, int size, int n, int sx, int sy)
 {
     int i, border_count, index;
     Coords *cell;
 
     border_count = sort_frag(frag, size);
 
-    //      G_message("Initializing");
+    /* G_message("Initializing"); */
 
     for (i = 0; i < n; i++) {
-	//              G_message("border_count = %d", border_count);
+	/* G_message("border_count = %d", border_count); */
 
 	/* pick border cell */
 	index = Random(border_count);
@@ -166,21 +166,23 @@
 
 	indi_array[i].x = cell->x + 0.5;
 	indi_array[i].y = cell->y + 0.5;
-	indi_array[i].dir = pick_dir(map, cell);	//2 * M_PI * Randomf();
+	indi_array[i].dir = pick_dir(map, cell, sx, sy);	/* 2 * M_PI * Randomf(); */
 	indi_array[i].path = 0;
 	indi_array[i].finished = 0;
 
-	//              fprintf(stderr, "indi%d: ", i);
-	//              fprintf(stderr, "x=%0.2f, y=%0.2f, dir=%0.2f, finished=%d\n",
-	//                              indi_array[i].x, indi_array[i].y, indi_array[i].dir, indi_array[i].finished);
+	/*
+	              fprintf(stderr, "indi%d: ", i);
+	              fprintf(stderr, "x=%0.2f, y=%0.2f, dir=%0.2f, finished=%d\n",
+	                              indi_array[i].x, indi_array[i].y, indi_array[i].dir, indi_array[i].finished);
+	*/
     }
-    //      G_message("End initialization");
+    /* G_message("End initialization"); */
 }
 
 /*
    sets back an individual, when position is illegal
  */
-void set_back(int *map, int indi, int frag)
+void set_back(int *map, int indi, int frag, int sx, int sy)
 {
     int index;
     Coords *cell;
@@ -193,7 +195,7 @@
 
     indi_array[indi].x = cell->x;
     indi_array[indi].y = cell->y;
-    indi_array[indi].dir = pick_dir(map, cell);
+    indi_array[indi].dir = pick_dir(map, cell, sx, sy);
     indi_array[indi].finished = 0;
 }
 
@@ -275,7 +277,7 @@
    fills a weighted array with possible next positions
  */
 void pick_nextpos(WeightedCoords * result, int indi, int *map,
-		  DCELL * costmap, int frag)
+		  DCELL * costmap, int frag, int sx, int sy)
 {
     int i;
     double ex_step, ex_pos;
@@ -340,17 +342,17 @@
 /*
    performs a single step for an individual
  */
-void indi_step(int indi, int frag, int *map, DCELL * costmap, double step)
+void indi_step(int indi, int frag, int *map, DCELL * costmap, int fragcount, int sx, int sy)
 {
     int i;
     double sum;
     Individual *individual = indi_array + indi;
     double rnd;
-    double newx, newy, newdir;
+    double newx, newy;
     int act_cell;
 
     /* test output */
-    //      fprintf(stderr, "actpos: x = %0.2f, y = %0.2f\n", individual->x, individual->y);
+    /* fprintf(stderr, "actpos: x = %0.2f, y = %0.2f\n", individual->x, individual->y); */
 
     /* make a step in the current direction */
     int dir_index = Round(individual->dir * 8.0 * (double)step_length);
@@ -360,7 +362,7 @@
 
     /* if new position is out of limits, then set back */
     if (newx < 0 || newx >= sx || newy < 0 || newy >= sy) {
-	set_back(map, indi, frag);
+	set_back(map, indi, frag, sx, sy);
 
 	return;
     }
@@ -389,7 +391,7 @@
     }
 
     /* write an array with possible next positions */
-    pick_nextpos(pos_arr, indi, map, costmap, frag);
+    pick_nextpos(pos_arr, indi, map, costmap, frag, sx, sy);
 
     /* test output */
     /*      G_message("Nextpos array:\n");
@@ -404,7 +406,7 @@
 	sum += pos_arr[i].weight;
     }
     if (sum == 0) {
-	set_back(map, indi, frag);
+	set_back(map, indi, frag, sx, sy);
 
 	return;
     }
@@ -422,7 +424,7 @@
     individual->dir = pos_arr[i].dir;
 
     /* test output */
-    //      fprintf(stderr, "pick: x = %0.2f, y = %0.2f\n\n", newx, newy);
+    /* fprintf(stderr, "pick: x = %0.2f, y = %0.2f\n\n", newx, newy); */
 
     return;
 }
@@ -430,30 +432,29 @@
 /*
    performs a search run for a single fragment
  */
-DCELL frag_run(int *map, DCELL * costmap, int frag)
+DCELL frag_run(int *map, DCELL * costmap, int frag, int n, int fragcount, int sx, int sy)
 {
     int i;
-    DCELL res = 0;
     int step_cnt = 0;
     int finished_cnt = 0;
     int limit = ceil(n * percent / 100);
 
-    //      fprintf(stderr, "\nstarting run:\n");
-    //      fprintf(stderr, "limit = %d\n", limit); 
+    /*      fprintf(stderr, "\nstarting run:\n"); */
+    /*      fprintf(stderr, "limit = %d\n", limit); */
 
     init_individuals(map, fragments[frag],
-		     fragments[frag + 1] - fragments[frag], n);
+		     fragments[frag + 1] - fragments[frag], n, sx, sy);
 
     /* perform a step for each individual */
     finished_cnt = 0;
     while (finished_cnt < limit && step_cnt <= maxsteps) {
 	if (out_freq > 0 && (step_cnt % out_freq == 0)) {
-	    test_output(map, frag, step_cnt, n);
+	    test_output(map, frag, step_cnt, n, sx, sy);
 	}
 
 	for (i = 0; i < n; i++) {
 	    if (!indi_array[i].finished) {
-		indi_step(i, frag, map, costmap, step_length);
+		indi_step(i, frag, map, costmap, fragcount, sx, sy);
 
 		/* test if new individuum finished */
 		if (indi_array[i].finished) {
@@ -474,10 +475,11 @@
     G_percent(frag + 1, fragcount, 1);
 
     if (out_freq > 0 && (step_cnt % out_freq == 0)) {
-	test_output(map, frag, step_cnt, n);
+	test_output(map, frag, step_cnt, n, sx, sy);
     }
 
-    //      fprintf(stderr, "stepcnt = %d\n", step_cnt);
+    /*      fprintf(stderr, "stepcnt = %d\n", step_cnt); */
+
     return (DCELL) step_cnt;
 }
 
@@ -485,10 +487,9 @@
    performs a search run for each fragment
  */
 void perform_search(DCELL * values, int *map, DCELL * costmap,
-		    f_statmethod **stats, int stat_count)
+		    f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy)
 {
     int fragment, i;
-    int steps;
     f_statmethod *func;
 
     /* allocate paths array */
@@ -533,7 +534,7 @@
 
     /* perform a search run for each fragment */
     for (fragment = 0; fragment < fragcount; fragment++) {
-	steps = frag_run(map, costmap, fragment);
+	frag_run(map, costmap, fragment, n, fragcount, sx, sy);
 
 	for (i = 0; i < n; i++) {
 	    indi_paths[i] = indi_array[i].path;

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,65 +0,0 @@
-Analysis of patch relevance to maintain the landscape connectivity using individual-based dispersal model for connectivity analysis (time-based).
-
-<h2>DESCRIPTION</h2>
-
-This modules provides information about the importance of single patches for maintaining the connectivity of individual fragments derived of a landcover classification. Unlike <em>r.pi.energy.iter</em> this module provides information about the differences in time from emigration to immigration. The individual based dispersal model results are based on the step length and range, the perception distance and the attractivity to move towards patches.
-
-
-<h2>NOTES</h2>
-
-The suitability matrix impacts the step direction of individuals. If individuals are moving beyond the mapset borders the indivuals are set back to their original source patches.
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-The patch relevance concerning connectivity are based on patches of the <em>landclass96</em> raster class 5 amd the time (amount of steps) from emigration to immigration is computed. The step length is set to 5 pixel, the output statistics are set to <em>average</em> time and <em>variance</em> of searchtime. For each patch 1000 individuals were released and the model stopped when at least 80% of all individuals sucessfully immigrated:<br>
-<div class="code"><pre>
-r.pi.searchtime.iter input=landclass96 output=searchtime_iter1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average
-</pre></div>
-
-setting the perception range to 10 pixel:
-<div class="code"><pre>
-r.pi.searchtime.iter input=landclass96 output=searchtime_iter1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average perception=10
-</pre></div>
-
-increasing the attraction to move towards patches to 10:
-<div class="code"><pre>
-r.pi.searchtime.iter input=landclass96 output=searchtime_iter1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average multiplicator=10
-</pre></div>
-
-output of each movement location for a defined step frequency. Here every 10th step is provided as output raster:
-<div class="code"><pre>
-r.pi.searchtime.iter input=landclass96 output=searchtime_iter1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average out_freq=10
-</pre></div>
-
-output of a raster which immigration counts:
-<div class="code"><pre>
-r.pi.searchtime.iter input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average out_immi=immi_counts
-</pre></div>
-
-the previous examples assumed a homogeneous matrix, a heterogenous matrix can be included using a raster file which values are taken as costs for movement (0-100):
-<div class="code"><pre>
-# it is assumed that our species is a forest species and cannot move through water, hence a cost of 100, does not like urban areas (class: 6, cost: 10) but can disperse through shrubland (class 4, cost=1) better than through grassland (class 3, cost: 2):
-r.mapcalc "suit_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
-r.pi.searchtime.iter input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average suitability=suit_raster
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.searchtime.html">r.pi.searchtime</a>,
-<a href="r.pi.searchtime.mw.html">r.pi.searchtime.mw</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann <br>
-Department of Remote Sensing <br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -98,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -140,17 +130,15 @@
 
     G_free(list);
     G_free(nbr_list);
+
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -164,5 +152,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -20,6 +20,11 @@
 typedef struct
 {
     int x, y;
+} Position;
+
+typedef struct
+{
+    int x, y;
     double dir;
     DCELL path;
     int finished;
@@ -39,10 +44,6 @@
 
 typedef DCELL(f_statmethod) (DCELL *, int);
 
-/* helpers.c */
-int Round(double d);
-int Random(int max);
-double Randomf();
 void print_buffer(int *buffer, int sx, int sy);
 void print_d_buffer(DCELL * buffer, int sx, int sy);
 void print_map(double *map, int size);
@@ -50,11 +51,11 @@
 void print_fragments();
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* search.c */
 void perform_search(DCELL * values, int *map, DCELL * costmap,
-		    f_statmethod **stats, int stat_count);
+		    f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy);
 
 /* stat_method.c */
 DCELL average(DCELL * vals, int count);
@@ -65,9 +66,7 @@
 DCELL max(DCELL * vals, int count);
 
 /* global parameters */
-GLOBAL int sx, sy;
 GLOBAL int keyval;
-GLOBAL int n;
 GLOBAL double percent;
 GLOBAL int maxsteps;
 GLOBAL int step_length;
@@ -79,13 +78,13 @@
 /* global variables */
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 GLOBAL Individual *indi_array;
 GLOBAL int *patch_imi;
 GLOBAL char *deleted_arr;
 
-GLOBAL char *newname, *newmapset;
-GLOBAL char *iminame, *imimapset;
+GLOBAL char *newname;
+GLOBAL char *iminame;
+GLOBAL const char *imimapset;
 
 #endif /* LOCAL_PROTO_H */

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.searchtime.iter
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Individual-based dispersal model for connectivity analysis 
  *                              - time-based - within iterative removal of patches. Based on r.pi.searchtime
  *
@@ -39,10 +40,12 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* costmap */
-    char *costname, *costmapset;
+    char *costname;
+    const char *costmapset;
 
     /* in and out file pointers */
     int in_fd, out_fd;
@@ -59,27 +62,24 @@
     int *map;
     DCELL *costmap;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
+    int sx, sy;
     CELL *result;
     DCELL *d_res;
     DCELL *values;
     DCELL *output_values;
     DCELL *dummy;
     int neighb_count;
-    int i, j, k;
+    int i, j;
     Coords *p;
     char *str;
     int method, difmethod;
     char outname[GNAME_MAX];
     int frag, actpos;
+    int fragcount;
+    int n;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -96,7 +96,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Individual-based dispersal model for connectivity analysis (time-based) using iterative removal of patches");
 
@@ -239,7 +239,7 @@
     flag.cost->guisection = _("Required");
 
     if (G_parser(argc, argv))
-	    exit(EXIT_FAILURE);
+	exit(EXIT_FAILURE);
 
     /* initialize random generator */
     srand(time(NULL));
@@ -248,17 +248,17 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* get name of costmap */
     costname = parm.costmap->answer;
+    costmapset = NULL;
 
     /* test costmap existance */
-    if (costname && (costmapset = G_find_cell2(costname, "")) == NULL)
-	    G_fatal_error(_("Raster map <%s> not found"), costname);
-
+    if (costname && (costmapset = G_find_raster2(costname, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), costname);
     /* get keyval */
     sscanf(parm.keyval->answer, "%d", &keyval);
 
@@ -297,7 +297,6 @@
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
 	G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
 
     /* check if the immigrants file name is correct */
     iminame = parm.out_immi->answer;
@@ -305,11 +304,9 @@
 	G_fatal_error(_("<%s> is an illegal file name"), iminame);
     imimapset = G_mapset();
 
-    map_type = DCELL_TYPE;
-
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* get maxsteps */
     if (parm.maxsteps->answer != NULL) {
@@ -388,22 +385,22 @@
 
     /* allocate map buffers */
     map = (int *)G_malloc(sx * sy * sizeof(int));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
     costmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
-    d_res = G_allocate_d_raster_buf();
+    d_res = Rast_allocate_d_buf();
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     fragments[0] = cells;
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
@@ -414,7 +411,7 @@
     G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* test output */
     /*      G_message("map:\n");
@@ -423,14 +420,14 @@
     /* if costmap specified, read costmap */
     if (costname != NULL) {
 	/* open costmap */
-	in_fd = G_open_cell_old(costname, costmapset);
+	in_fd = Rast_open_old(costname, costmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), costname);
 
 	/* read costmap */
 	G_message("Reading costmap:");
 	for (row = 0; row < sy; row++) {
-	    G_get_d_raster_row(in_fd, d_res, row);
+	    Rast_get_d_row(in_fd, d_res, row);
 	    for (col = 0; col < sx; col++) {
 		costmap[row * sx + col] = d_res[col];
 	    }
@@ -440,7 +437,7 @@
 	G_percent(1, 1, 2);
 
 	/* close costmap */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no costmap specified, fill costmap with 100 */
@@ -454,7 +451,7 @@
        print_d_buffer(costmap, sx, sy); */
 
     /* find fragments */
-    writeFragments(map, sy, sx, neighb_count);
+    fragcount = writeFragments(map, sy, sx, neighb_count);
 
     /* test output */
     /*      print_fragments(); */
@@ -492,13 +489,13 @@
 			   sizeof(DCELL));
 
     /* first reference run */
-    perform_search(values, map, costmap, methods, stat_count);
+    perform_search(values, map, costmap, methods, stat_count, n, fragcount, sx, sy);
 
     /* then runs with one patch deleted */
     for (i = 0; i < fragcount; i++) {
 	deleted_arr[i] = 1;
 	perform_search(values + (i + 1) * fragcount * stat_count, map,
-		       costmap, methods, stat_count);
+		       costmap, methods, stat_count, n, fragcount, sx, sy);
 	deleted_arr[i] = 0;
 
 	/* calculate differences */
@@ -571,13 +568,13 @@
 	    sprintf(outname, "%s_%s_%s", newname,
 		    statmethods[stats[method]].suffix,
 		    statmethods[dif_stats[difmethod]].suffix);
-	    out_fd = G_open_raster_new(outname, map_type);
+	    out_fd = Rast_open_new(outname, DCELL_TYPE);
 	    if (out_fd < 0)
 		    G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	    /* write the output file */
 	    for (row = 0; row < sy; row++) {
-		G_set_d_null_value(d_res, sx);
+		Rast_set_d_null_value(d_res, sx);
 
 		for (i = 0; i < fragcount; i++) {
 		    for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -589,25 +586,25 @@
 		    }
 		}
 
-		G_put_d_raster_row(out_fd, d_res);
+		Rast_put_d_row(out_fd, d_res);
 
 	    }
 
 	    /* close output */
-	    G_close_cell(out_fd);
+	    Rast_close(out_fd);
 	}
     }
     G_percent(100, 100, 2);
 
     /* open the new cellfile  */
     if (iminame) {
-	out_fd = G_open_raster_new(iminame, map_type);
+	out_fd = Rast_open_new(iminame, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), iminame);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -617,7 +614,7 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row, sy, 2);
 	}
@@ -625,7 +622,7 @@
 	G_percent(100, 100, 2);
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* free allocated resources */

Copied: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/r.pi.searchtime.iter.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/r.pi.searchtime.iter.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/r.pi.searchtime.iter.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,65 @@
+Analysis of patch relevance to maintain the landscape connectivity using individual-based dispersal model for connectivity analysis (time-based).
+
+<h2>DESCRIPTION</h2>
+
+This modules provides information about the importance of single patches for maintaining the connectivity of individual fragments derived of a landcover classification. Unlike <em>r.pi.energy.iter</em> this module provides information about the differences in time from emigration to immigration. The individual based dispersal model results are based on the step length and range, the perception distance and the attractivity to move towards patches.
+
+
+<h2>NOTES</h2>
+
+The suitability matrix impacts the step direction of individuals. If individuals are moving beyond the mapset borders the indivuals are set back to their original source patches.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+The patch relevance concerning connectivity are based on patches of the <em>landclass96</em> raster class 5 amd the time (amount of steps) from emigration to immigration is computed. The step length is set to 5 pixel, the output statistics are set to <em>average</em> time and <em>variance</em> of searchtime. For each patch 1000 individuals were released and the model stopped when at least 80% of all individuals sucessfully immigrated:<br>
+<div class="code"><pre>
+r.pi.searchtime.iter input=landclass96 output=searchtime_iter1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average
+</pre></div>
+
+setting the perception range to 10 pixel:
+<div class="code"><pre>
+r.pi.searchtime.iter input=landclass96 output=searchtime_iter1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average perception=10
+</pre></div>
+
+increasing the attraction to move towards patches to 10:
+<div class="code"><pre>
+r.pi.searchtime.iter input=landclass96 output=searchtime_iter1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average multiplicator=10
+</pre></div>
+
+output of each movement location for a defined step frequency. Here every 10th step is provided as output raster:
+<div class="code"><pre>
+r.pi.searchtime.iter input=landclass96 output=searchtime_iter1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average out_freq=10
+</pre></div>
+
+output of a raster which immigration counts:
+<div class="code"><pre>
+r.pi.searchtime.iter input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average out_immi=immi_counts
+</pre></div>
+
+the previous examples assumed a homogeneous matrix, a heterogenous matrix can be included using a raster file which values are taken as costs for movement (0-100):
+<div class="code"><pre>
+# it is assumed that our species is a forest species and cannot move through water, hence a cost of 100, does not like urban areas (class: 6, cost: 10) but can disperse through shrubland (class 4, cost=1) better than through grassland (class 3, cost: 2):
+r.mapcalc "suit_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
+r.pi.searchtime.iter input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 dif_stats=average suitability=suit_raster
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.searchtime.html">r.pi.searchtime</a>,
+<a href="r.pi.searchtime.mw.html">r.pi.searchtime.mw</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann <br>
+Department of Remote Sensing <br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/search.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/search.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/search.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -12,20 +12,20 @@
 /*
    output raster with current simulation state
  */
-void test_output(int *map, int patch, int step, int n)
+void test_output(int *map, int patch, int step, int n, int sx, int sy)
 {
     int out_fd;
-    int row, col, i;
+    int row, i;
     char outname[GNAME_MAX];
     DCELL *outmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
 
     /* open the new cellfile  */
     sprintf(outname, "%s_patch%d_step%d", newname, patch, step);
 
-    out_fd = G_open_raster_new(outname, DCELL_TYPE);
+    out_fd = Rast_open_new(outname, DCELL_TYPE);
     if (out_fd < 0) {
 	G_fatal_error(_("can't create new cell file <%s> in mapset %s\n"),
-		      outname, newmapset);
+		      outname, G_mapset());
 	exit(EXIT_FAILURE);
     }
 
@@ -42,7 +42,7 @@
 	x = indi->x;
 	y = indi->y;
 
-	//              fprintf(stderr, "indi%d: (%d, %d)\n", i, x, y);
+	/* fprintf(stderr, "indi%d: (%d, %d)\n", i, x, y); */
 
 	outmap[x + y * sx]++;
     }
@@ -62,11 +62,11 @@
 
     /* write output */
     for (row = 0; row < sy; row++) {
-	G_put_d_raster_row(out_fd, outmap + row * sx);
+	Rast_put_d_row(out_fd, outmap + row * sx);
     }
 
     /* close output */
-    G_close_cell(out_fd);
+    Rast_close(out_fd);
     G_free(outmap);
 }
 
@@ -106,7 +106,7 @@
 /*
    picks a random direction pointing outwards a patch
  */
-double pick_dir(int *map, Coords * frag)
+double pick_dir(int *map, Coords * frag, int sx, int sy)
 {
     double dirs[4];
     int i;
@@ -116,6 +116,7 @@
     int y = frag->y;
     int count = 0;
 
+    /* ! compare to r.pi.energy.iter ! */ 
     if (x >= sx || map[x + 1 + y * sx] == TYPE_NOTHING)
 	dirs[count++] = 0.0;
     if (y <= 0 || map[x + (y + 1) * sx] == TYPE_NOTHING)
@@ -125,7 +126,7 @@
     if (y >= sy || map[x + (y - 1) * sx] == TYPE_NOTHING)
 	dirs[count++] = 0.75;
 
-    //      G_message("Picks for (%d, %d): %0.2f, %0.2f, %0.2f, %0.2f, cnt=%d", x, y, dirs[0], dirs[1], dirs[2], dirs[3], count);
+    /* G_message("Picks for (%d, %d): %0.2f, %0.2f, %0.2f, %0.2f, cnt=%d", x, y, dirs[0], dirs[1], dirs[2], dirs[3], count); */
 
     pick = count * Randomf();
 
@@ -136,29 +137,29 @@
 	    if (res < 0) {
 		res++;
 	    }
-	    //                      res = res < 0 ? 2 * M_PI + res : res;
-	    //                      G_message("dir = %0.2f", res);
+	    /* res = res < 0 ? 2 * M_PI + res : res; */
+	    /* G_message("dir = %0.2f", res); */
 	    return res;
 	}
     }
 
-    return -1;			// error
+    return -1;			/* error */
 }
 
 /*
    initializes all individuals for a fragment
  */
-void init_individuals(int *map, Coords * frag, int size, int n)
+void init_individuals(int *map, Coords * frag, int size, int n, int sx, int sy)
 {
     int i, border_count, index;
     Coords *cell;
 
     border_count = sort_frag(frag, size);
 
-    //      G_message("Initializing");
+    /* G_message("Initializing individuals"); */
 
     for (i = 0; i < n; i++) {
-	//              G_message("border_count = %d", border_count);
+	/* G_message("border_count = %d", border_count); */
 
 	/* pick border cell */
 	index = Random(border_count);
@@ -166,21 +167,23 @@
 
 	indi_array[i].x = cell->x + 0.5;
 	indi_array[i].y = cell->y + 0.5;
-	indi_array[i].dir = pick_dir(map, cell);	//2 * M_PI * Randomf();
+	indi_array[i].dir = pick_dir(map, cell, sx, sy);	/* 2 * M_PI * Randomf(); */
 	indi_array[i].path = 0;
 	indi_array[i].finished = 0;
 
-	//              fprintf(stderr, "indi%d: ", i);
-	//              fprintf(stderr, "x=%0.2f, y=%0.2f, dir=%0.2f, finished=%d\n",
-	//                              indi_array[i].x, indi_array[i].y, indi_array[i].dir, indi_array[i].finished);
+	/*
+	              fprintf(stderr, "indi%d: ", i);
+	              fprintf(stderr, "x=%0.2f, y=%0.2f, dir=%0.2f, finished=%d\n",
+	                              indi_array[i].x, indi_array[i].y, indi_array[i].dir, indi_array[i].finished);
+	*/
     }
-    //      G_message("End initialization");
+    /* G_message("End initialization"); */
 }
 
 /*
    sets back an individual, when position is illegal
  */
-void set_back(int *map, int indi, int frag)
+void set_back(int *map, int indi, int frag, int sx, int sy)
 {
     int index;
     Coords *cell;
@@ -193,7 +196,7 @@
 
     indi_array[indi].x = cell->x;
     indi_array[indi].y = cell->y;
-    indi_array[indi].dir = pick_dir(map, cell);
+    indi_array[indi].dir = pick_dir(map, cell, sx, sy);
     indi_array[indi].finished = 0;
 }
 
@@ -275,7 +278,7 @@
    fills a weighted array with possible next positions
  */
 void pick_nextpos(WeightedCoords * result, int indi, int *map,
-		  DCELL * costmap, int frag)
+		  DCELL * costmap, int frag, int sx, int sy)
 {
     int i;
     double ex_step, ex_pos;
@@ -341,7 +344,7 @@
 /*
    performs a single step for an individual
  */
-void indi_step(int indi, int frag, int *map, DCELL * costmap, double step)
+void indi_step(int indi, int frag, int *map, DCELL * costmap, int sx, int sy)
 {
     int i;
     double sum;
@@ -351,10 +354,10 @@
     int act_cell;
 
     /* test output */
-    //      fprintf(stderr, "actpos: x = %0.2f, y = %0.2f\n", individual->x, individual->y);
+    /* fprintf(stderr, "actpos: x = %0.2f, y = %0.2f\n", individual->x, individual->y); */
 
     /* write an array with possible next positions */
-    pick_nextpos(pos_arr, indi, map, costmap, frag);
+    pick_nextpos(pos_arr, indi, map, costmap, frag, sx, sy);
 
     /* test output */
     /*      G_message("Nextpos array:\n");
@@ -369,7 +372,7 @@
 	sum += pos_arr[i].weight;
     }
     if (sum == 0) {
-	set_back(map, indi, frag);
+	set_back(map, indi, frag, sx, sy);
 
 	return;
     }
@@ -389,11 +392,11 @@
     newdir = pos_arr[i].dir;
 
     /* test output */
-    //      fprintf(stderr, "pick: x = %0.2f, y = %0.2f\n\n", newx, newy);
+    /* fprintf(stderr, "pick: x = %0.2f, y = %0.2f\n\n", newx, newy); */
 
     /* if new position is out of limits, then set back */
     if (newx < 0 || newx >= sx || newy < 0 || newy >= sy) {
-	set_back(map, indi, frag);
+	set_back(map, indi, frag, sx, sy);
 
 	return;
     }
@@ -425,30 +428,29 @@
 /*
    performs a search run for a single fragment
  */
-DCELL frag_run(int *map, DCELL * costmap, int frag)
+DCELL frag_run(int *map, DCELL * costmap, int frag, int n, int fragcount, int sx, int sy)
 {
     int i;
-    DCELL res = 0;
     int step_cnt = 0;
     int finished_cnt = 0;
     int limit = ceil(n * percent / 100);
 
-    //      fprintf(stderr, "\nstarting run:\n");
-    //      fprintf(stderr, "limit = %d\n", limit); 
+    /*      fprintf(stderr, "\nstarting run:\n"); */
+    /*      fprintf(stderr, "limit = %d\n", limit); */
 
     init_individuals(map, fragments[frag],
-		     fragments[frag + 1] - fragments[frag], n);
+		     fragments[frag + 1] - fragments[frag], n, sx, sy);
 
     /* perform a step for each individual */
     finished_cnt = 0;
     while (finished_cnt < limit && step_cnt <= maxsteps) {
 	if (out_freq > 0 && (step_cnt % out_freq == 0)) {
-	    test_output(map, frag, step_cnt, n);
+	    test_output(map, frag, step_cnt, n, sx, sy);
 	}
 
 	for (i = 0; i < n; i++) {
 	    if (!indi_array[i].finished) {
-		indi_step(i, frag, map, costmap, step_length);
+		indi_step(i, frag, map, costmap, sx, sy);
 
 		/* test if new individuum finished */
 		if (indi_array[i].finished) {
@@ -468,10 +470,11 @@
     }
 
     if (out_freq > 0 && (step_cnt % out_freq == 0)) {
-	test_output(map, frag, step_cnt, n);
+	test_output(map, frag, step_cnt, n, sx, sy);
     }
 
-    //      fprintf(stderr, "stepcnt = %d\n", step_cnt);
+    /*      fprintf(stderr, "stepcnt = %d\n", step_cnt); */
+
     return (DCELL) step_cnt;
 }
 
@@ -481,10 +484,9 @@
    output in "values": ( stat1(patch1, patch2, patch3, ...), stat2(patch1, patch2, ...) )
  */
 void perform_search(DCELL * values, int *map, DCELL * costmap,
-		    f_statmethod **stats, int stat_count)
+		    f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy)
 {
     int fragment, i;
-    int steps;
     f_statmethod *func;
 
     /* allocate paths array */
@@ -524,7 +526,7 @@
 
     /* perform a search run for each fragment */
     for (fragment = 0; fragment < fragcount; fragment++) {
-	steps = frag_run(map, costmap, fragment);
+	frag_run(map, costmap, fragment, n, fragcount, sx, sy);
 
 	for (i = 0; i < n; i++) {
 	    indi_paths[i] = indi_array[i].path;

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/Makefile	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/Makefile	2017-04-06 20:56:05 UTC (rev 70845)
@@ -5,8 +5,8 @@
 LIB_NAME = grass_rpi
 RPI_LIB  = -l$(LIB_NAME)
 
-LIBES = $(STATSLIB) $(GISLIB) $(RPI_LIB)
-DEPENDENCIES = $(STATSDEP) $(GISDEP)
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
+DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Deleted: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/description.html
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/description.html	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/description.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,61 +0,0 @@
-Analysis of landscape connectivity using individual-based dispersal model inside a moving window.
-
-<h2>DESCRIPTION</h2>
-
-This modules provides information about the patch connectivity within a moving window 
-
-
-<h2>NOTES</h2>
-
-The suitability matrix impacts the step direction of individuals. If individuals are moving beyond the mapset borders the indivuals are set back to their original source patches.
-
-<h2>EXAMPLE</h2>
-
-An example for the North Carolina sample dataset:
-
-The patch relevance concerning connectivity are based on patches of the <em>landclass96</em> raster class 5 amd the time (amount of steps) from emigration to immigration is computed. The step length is set to 5 pixel, the output statistics are set to <em>average</em> time and <em>variance</em> of searchtime. For each patch 1000 individuals were released and the model stopped when at least 80% of all individuals sucessfully immigrated. The command below is computing the time for the whole landscape and the result is prompted to the screen<br>
-<div class="code"><pre>
-r.pi.searchtime.mw input=landclass96 output=searchtime_mw1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000
-</pre></div>
-
-for a graphical output a moving window size needs to be defined (here 7x7 pixel) and the amount of steps until immigration per moving window is provided in the output raster:
-<div class="code"><pre>
-r.pi.searchtime.mw input=landclass96 output=searchtime_mw1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 size=7
-</pre></div>
-
-
-setting the perception range to 10 pixel:
-<div class="code"><pre>
-r.pi.searchtime.mw input=landclass96 output=searchtime_mw1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 size=7 perception=10
-</pre></div>
-
-increasing the attraction to move towards patches to 10:
-<div class="code"><pre>
-r.pi.searchtime.mw input=landclass96 output=searchtime_mw1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 size=7 multiplicator=10
-</pre></div>
-
-the previous examples assumed a homogeneous matrix, a heterogenous matrix can be included using a raster file which values are taken as costs for movement (0-100):
-<div class="code"><pre>
-# it is assumed that our species is a forest species and cannot move through water, hence a cost of 100, does not like urban areas (class: 6, cost: 10) but can disperse through shrubland (class 4, cost=1) better than through grassland (class 3, cost: 2):
-r.mapcalc "suit_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
-r.pi.searchtime.mw input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 size=7 suitability=suit_raster
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.pi.searchtime.html">r.pi.searchtime</a>,
-<a href="r.pi.searchtime.iter.html">r.pi.searchtime.iter</a>,
-<a href="r.pi.html">r.pi</a>
-</em>
-
-<h2>AUTHORS</h2>
-Programming: Elshad Shirinov<br>
-Scientific concept: Dr. Martin Wegmann <br>
-Department of Remote Sensing <br>
-Remote Sensing and Biodiversity Unit<br>
-University of Wuerzburg, Germany
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/frag.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/frag.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -1,10 +1,5 @@
 #include "local_proto.h"
 
-typedef struct
-{
-    int x, y;
-} Position;
-
 Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
 		  int ncols, int nbr_cnt);
 int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
@@ -98,17 +93,12 @@
 	int r = first->y;
 	int c = first->x;
 
-	first++;
-
-	int left = c > 0 ? c - 1 : 0;
-	int top = r > 0 ? r - 1 : 0;
-	int right = c < ncols - 1 ? c + 1 : ncols - 1;
-	int bottom = r < nrows - 1 ? r + 1 : nrows - 1;
-
 	/* add neighbors to fifo-list */
 	int cnt =
 	    getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
 
+	first++;
+
 	for (i = 0; i < cnt; i++) {
 	    x = nbr_list[i].x;
 	    y = nbr_list[i].y;
@@ -143,14 +133,11 @@
     return actpos;
 }
 
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
 {
-    int row, col, i;
-    Coords *p;
+    int row, col;
+    int fragcount = 0;
 
-    fragcount = 0;
-    Coords *actpos = fragments[0];
-
     /* find fragments */
     for (row = 0; row < nrows; row++) {
 	for (col = 0; col < ncols; col++) {
@@ -164,5 +151,5 @@
 	}
     }
 
-    return;
+    return fragcount;
 }

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/local_proto.h	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/local_proto.h	2017-04-06 20:56:05 UTC (rev 70845)
@@ -20,6 +20,11 @@
 typedef struct
 {
     int x, y;
+} Position;
+
+typedef struct
+{
+    int x, y;
     double dir;
     DCELL path;
     int finished;
@@ -40,15 +45,13 @@
 typedef DCELL(f_statmethod) (DCELL *, int);
 
 /* frag.c */
-void writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
 
 /* search.c */
 void perform_search(DCELL * values, int *map, DCELL * costmap, int size,
-		    f_statmethod **stats, int stat_count);
+		    f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy);
 
 /* global parameters */
-GLOBAL int sx, sy;
-GLOBAL int n;
 GLOBAL double percent;
 GLOBAL int maxsteps;
 GLOBAL int step_length;
@@ -60,7 +63,6 @@
 /* global variables */
 GLOBAL Coords **fragments;
 GLOBAL Coords *cells;
-GLOBAL int fragcount;
 
 GLOBAL Individual *indi_array;
 GLOBAL int *patch_imi;

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/main.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/main.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -3,6 +3,7 @@
  *
  * MODULE:       r.pi.searchtime.mw
  * AUTHOR(S):    Elshad Shirinov, Dr. Martin Wegmann
+ *               Markus Metz (update to GRASS 7)
  * PURPOSE:      Individual-based dispersal model for connectivity analysis
  *                           - time-based - within a moving window. Based on r.pi.searchtime
  *
@@ -39,14 +40,16 @@
 int main(int argc, char *argv[])
 {
     /* input */
-    char *oldname, *oldmapset;
+    char *oldname;
+    const char *oldmapset;
 
     /* costmap */
-    char *costname, *costmapset;
+    char *costname;
+    const char *costmapset;
 
     /* output */
-    char *newname, *newmapset;
-    char *iminame, *imimapset;
+    char *newname;
+    char *iminame;
 
     /* in and out file pointers */
     int in_fd, out_fd;
@@ -62,25 +65,22 @@
     int *map;
     DCELL *costmap;
 
-    /* other parameters */
-    char *title;
-
     /* helper variables */
     int row, col;
+    int sx, sy;
     CELL *result;
     DCELL *d_res;
     DCELL *values;
     int neighb_count;
-    int i, j, k;
+    int i;
     Coords *p;
     char *str;
     int method;
     char outname[GNAME_MAX];
+    int fragcount;
+    int n;
     int nx, ny;
 
-    RASTER_MAP_TYPE map_type;
-    struct Cell_head ch, window;
-
     struct GModule *module;
     struct
     {
@@ -97,7 +97,7 @@
     G_gisinit(argv[0]);
 
     module = G_define_module();
-    module->keywords = _("raster");
+    G_add_keyword(_("raster"));
     module->description =
 	_("Individual-based dispersal model for connectivity analysis (time-based) using moving window");
 
@@ -230,17 +230,17 @@
     oldname = parm.input->answer;
 
     /* test input files existance */
-    oldmapset = G_find_cell2(oldname, "");
+    oldmapset = G_find_raster2(oldname, "");
     if (oldmapset == NULL)
         G_fatal_error(_("Raster map <%s> not found"), oldname);
 
     /* get name of costmap */
     costname = parm.costmap->answer;
+    costmapset = NULL;
 
     /* test costmap existance */
-    if (costname && (costmapset = G_find_cell2(costname, "")) == NULL)
-	    G_fatal_error(_("Raster map <%s> not found"), costname);
-
+    if (costname && (costmapset = G_find_raster2(costname, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), costname);
     /* get keyval */
     sscanf(parm.keyval->answer, "%d", &keyval);
 
@@ -287,20 +287,16 @@
     newname = parm.output->answer;
     if (G_legal_filename(newname) < 0)
 	G_fatal_error(_("<%s> is an illegal file name"), newname);
-    newmapset = G_mapset();
 
     /* check if the immigrants file name is correct */
     iminame = parm.out_immi->answer;
 
     if (iminame && G_legal_filename(iminame) < 0)
 	G_fatal_error(_("<%s> is an illegal file name"), iminame);
-    imimapset = G_mapset();
 
-    map_type = DCELL_TYPE;
-
     /* get size */
-    sx = G_window_cols();
-    sy = G_window_rows();
+    sx = Rast_window_cols();
+    sy = Rast_window_rows();
 
     /* get maxsteps */
     if (parm.maxsteps->answer != NULL) {
@@ -350,22 +346,22 @@
 
     /* allocate map buffers */
     map = (int *)G_malloc(sx * sy * sizeof(int));
-    result = G_allocate_c_raster_buf();
+    result = Rast_allocate_c_buf();
     costmap = (DCELL *) G_malloc(sx * sy * sizeof(DCELL));
-    d_res = G_allocate_d_raster_buf();
+    d_res = Rast_allocate_d_buf();
     cells = (Coords *) G_malloc(sx * sy * sizeof(Coords));
     fragments = (Coords **) G_malloc(sx * sy * sizeof(Coords *));
     fragments[0] = cells;
 
     /* open map */
-    in_fd = G_open_cell_old(oldname, oldmapset);
+    in_fd = Rast_open_old(oldname, oldmapset);
     if (in_fd < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), oldname);
+	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
     /* read map */
     G_message("Reading map:");
     for (row = 0; row < sy; row++) {
-	G_get_c_raster_row(in_fd, result, row);
+	Rast_get_c_row(in_fd, result, row);
 	for (col = 0; col < sx; col++) {
 	    if (result[col] == keyval)
 		map[row * sx + col] = 1;
@@ -376,7 +372,7 @@
     G_percent(1, 1, 2);
 
     /* close map */
-    G_close_cell(in_fd);
+    Rast_close(in_fd);
 
     /* test output */
     /*      G_message("map:\n");
@@ -385,14 +381,14 @@
     /* if costmap specified, read costmap */
     if (costname != NULL) {
 	/* open costmap */
-	in_fd = G_open_cell_old(costname, costmapset);
+	in_fd = Rast_open_old(costname, costmapset);
 	if (in_fd < 0)
 	    G_fatal_error(_("Unable to open raster map <%s>"), costname);
 
 	/* read costmap */
 	G_message("Reading costmap:");
 	for (row = 0; row < sy; row++) {
-	    G_get_d_raster_row(in_fd, d_res, row);
+	    Rast_get_d_row(in_fd, d_res, row);
 	    for (col = 0; col < sx; col++) {
 		costmap[row * sx + col] = d_res[col];
 	    }
@@ -402,7 +398,7 @@
 	G_percent(1, 1, 2);
 
 	/* close costmap */
-	G_close_cell(in_fd);
+	Rast_close(in_fd);
     }
     else {
 	/* if no costmap specified, fill costmap with 100 */
@@ -416,7 +412,7 @@
        print_d_buffer(costmap, sx, sy); */
 
     /* find fragments */
-    writeFragments(map, sy, sx, neighb_count);
+    fragcount = writeFragments(map, sy, sx, neighb_count);
 
     /* test output */
     /*      print_fragments(); */
@@ -452,7 +448,7 @@
     values = (DCELL *) G_malloc(stat_count * nx * ny * sizeof(DCELL));
 
     /* perform search */
-    perform_search(values, map, costmap, size, methods, stat_count);
+    perform_search(values, map, costmap, size, methods, stat_count, n, fragcount, sx, sy);
 
     /* free methods array */
     G_free(methods);
@@ -465,7 +461,7 @@
     G_message("Writing output...");
     if (size == 0) {
 	for (method = 0; method < stat_count; method++) {
-	    fprintf(stdout, "statmethod = %s: value = %lf\n",
+	    fprintf(stdout, "statmethod = %s: value = %f\n",
 		    statmethods[stats[method]].name, values[method]);
 	}
     }
@@ -475,13 +471,13 @@
 	    /* open the new cellfile  */
 	    sprintf(outname, "%s_%s", newname,
 		    statmethods[stats[method]].suffix);
-	    out_fd = G_open_raster_new(outname, map_type);
+	    out_fd = Rast_open_new(outname, DCELL_TYPE);
 	    if (out_fd < 0)
-		    G_fatal_error(_("Cannot create raster map <%s>"), outname);
+		G_fatal_error(_("Cannot create raster map <%s>"), outname);
 
 	    /* write the output file */
 	    for (row = 0; row < sy; row++) {
-		G_set_d_null_value(d_res, sx);
+		Rast_set_d_null_value(d_res, sx);
 
 		if (row >= size / 2 && row < ny + size / 2) {
 		    for (col = 0; col < nx; col++) {
@@ -490,26 +486,26 @@
 		    }
 		}
 
-		G_put_d_raster_row(out_fd, d_res);
+		Rast_put_d_row(out_fd, d_res);
 
 		G_percent(row + 1, sy, 1);
 	    }
 
 	    /* close output */
-	    G_close_cell(out_fd);
+	    Rast_close(out_fd);
 	}
 	G_percent(100, 100, 2);
     }
 
     /* open the new cellfile  */
     if (iminame) {
-	out_fd = G_open_raster_new(iminame, map_type);
+	out_fd = Rast_open_new(iminame, DCELL_TYPE);
 	if (out_fd < 0)
 	    G_fatal_error(_("Cannot create raster map <%s>"), iminame);
 
 	/* write the output file */
 	for (row = 0; row < sy; row++) {
-	    G_set_d_null_value(d_res, sx);
+	    Rast_set_d_null_value(d_res, sx);
 
 	    for (i = 0; i < fragcount; i++) {
 		for (p = fragments[i]; p < fragments[i + 1]; p++) {
@@ -519,7 +515,7 @@
 		}
 	    }
 
-	    G_put_d_raster_row(out_fd, d_res);
+	    Rast_put_d_row(out_fd, d_res);
 
 	    G_percent(row, sy, 2);
 	}
@@ -527,7 +523,7 @@
 	G_percent(100, 100, 2);
 
 	/* close output */
-	G_close_cell(out_fd);
+	Rast_close(out_fd);
     }
 
     /* free allocated resources */

Copied: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/r.pi.searchtime.mw.html (from rev 70844, grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/description.html)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/r.pi.searchtime.mw.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/r.pi.searchtime.mw.html	2017-04-06 20:56:05 UTC (rev 70845)
@@ -0,0 +1,61 @@
+Analysis of landscape connectivity using individual-based dispersal model inside a moving window.
+
+<h2>DESCRIPTION</h2>
+
+This modules provides information about the patch connectivity within a moving window 
+
+
+<h2>NOTES</h2>
+
+The suitability matrix impacts the step direction of individuals. If individuals are moving beyond the mapset borders the indivuals are set back to their original source patches.
+
+<h2>EXAMPLE</h2>
+
+An example for the North Carolina sample dataset:
+
+The patch relevance concerning connectivity are based on patches of the <em>landclass96</em> raster class 5 amd the time (amount of steps) from emigration to immigration is computed. The step length is set to 5 pixel, the output statistics are set to <em>average</em> time and <em>variance</em> of searchtime. For each patch 1000 individuals were released and the model stopped when at least 80% of all individuals sucessfully immigrated. The command below is computing the time for the whole landscape and the result is prompted to the screen<br>
+<div class="code"><pre>
+r.pi.searchtime.mw input=landclass96 output=searchtime_mw1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000
+</pre></div>
+
+for a graphical output a moving window size needs to be defined (here 7x7 pixel) and the amount of steps until immigration per moving window is provided in the output raster:
+<div class="code"><pre>
+r.pi.searchtime.mw input=landclass96 output=searchtime_mw1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 size=7
+</pre></div>
+
+
+setting the perception range to 10 pixel:
+<div class="code"><pre>
+r.pi.searchtime.mw input=landclass96 output=searchtime_mw1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 size=7 perception=10
+</pre></div>
+
+increasing the attraction to move towards patches to 10:
+<div class="code"><pre>
+r.pi.searchtime.mw input=landclass96 output=searchtime_mw1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 size=7 multiplicator=10
+</pre></div>
+
+the previous examples assumed a homogeneous matrix, a heterogenous matrix can be included using a raster file which values are taken as costs for movement (0-100):
+<div class="code"><pre>
+# it is assumed that our species is a forest species and cannot move through water, hence a cost of 100, does not like urban areas (class: 6, cost: 10) but can disperse through shrubland (class 4, cost=1) better than through grassland (class 3, cost: 2):
+r.mapcalc "suit_raster = if(landclass96==5,1,if(landclass96 == 1, 10, if (landclass96==3,2, if(landclass96==4,1,if(landclass96==6,100)))))"
+r.pi.searchtime.mw input=landclass96 output=searchtime1 keyval=5 step_length=5 stats=average,variance percent=80 n=1000 size=7 suitability=suit_raster
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.pi.searchtime.html">r.pi.searchtime</a>,
+<a href="r.pi.searchtime.iter.html">r.pi.searchtime.iter</a>,
+<a href="r.pi.html">r.pi</a>
+</em>
+
+<h2>AUTHORS</h2>
+Programming: Elshad Shirinov<br>
+Scientific concept: Dr. Martin Wegmann <br>
+Department of Remote Sensing <br>
+Remote Sensing and Biodiversity Unit<br>
+University of Wuerzburg, Germany
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/search.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/search.c	2017-04-06 20:48:25 UTC (rev 70844)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/search.c	2017-04-06 20:56:05 UTC (rev 70845)
@@ -16,8 +16,7 @@
 /*
    initializes all individuals for a window
  */
-void init_individuals(int x, int y, int sizex, int sizey, int *map,
-		      DCELL * costmap, int n)
+void init_individuals(int x, int y, DCELL * costmap, int n, int sx)
 {
     int i, j, index;
     Displacement *cell;
@@ -57,7 +56,7 @@
 /*
    sets back an individual, when position is illegal
  */
-void set_back(int *map, int indi)
+void set_back(int indi)
 {
     int index;
     Displacement *cell;
@@ -150,7 +149,7 @@
    fills a weighted array with possible next positions
  */
 void pick_nextpos(WeightedCoords * result, int indi, int *map,
-		  DCELL * costmap)
+		  DCELL * costmap, int sx, int sy)
 {
     int i;
     double ex_step, ex_pos;
@@ -215,7 +214,7 @@
 /*
    performs a single step for an individual
  */
-void indi_step(int indi, int *map, DCELL * costmap, double step)
+void indi_step(int indi, int *map, DCELL * costmap, int sx, int sy)
 {
     int i;
     double sum;
@@ -237,10 +236,10 @@
     }
 
     /* test output */
-    //      fprintf(stderr, "actpos: x = %0.2f, y = %0.2f\n", individual->x, individual->y);
+    /* fprintf(stderr, "actpos: x = %0.2f, y = %0.2f\n", individual->x, individual->y); */
 
     /* write an array with possible next positions */
-    pick_nextpos(pos_arr, indi, map, costmap);
+    pick_nextpos(pos_arr, indi, map, costmap, sx, sy);
 
     /* test output */
     /*      G_message("Nextpos array:\n");
@@ -255,7 +254,7 @@
 	sum += pos_arr[i].weight;
     }
     if (sum == 0) {
-	set_back(map, indi);
+	set_back(indi);
 
 	return;
     }
@@ -275,11 +274,11 @@
     newdir = pos_arr[i].dir;
 
     /* test output */
-    //      fprintf(stderr, "pick: x = %0.2f, y = %0.2f\n\n", newx, newy);
+    /* fprintf(stderr, "pick: x = %0.2f, y = %0.2f\n\n", newx, newy); */
 
     /* if new position is out of limits, then set back */
     if (newx < 0 || newx >= sx || newy < 0 || newy >= sy) {
-	set_back(map, indi);
+	set_back(indi);
 
 	return;
     }
@@ -311,24 +310,23 @@
 /*
    performs a search run for a single fragment
  */
-DCELL window_run(int x, int y, int *map, DCELL * costmap)
+DCELL window_run(int x, int y, int *map, DCELL * costmap, int n, int sx, int sy)
 {
     int i;
-    DCELL res = 0;
     int step_cnt = 0;
     int finished_cnt = 0;
     int limit = ceil(n * percent / 100);
 
-    init_individuals(x, y, sizex, sizey, map, costmap, n);
+    init_individuals(x, y, costmap, n, sx);
 
     /* perform a step for each individual */
     finished_cnt = 0;
     while (finished_cnt < limit && step_cnt <= maxsteps) {
 	for (i = 0; i < n; i++) {
 	    if (!indi_array[i].finished) {
-		indi_step(i, map, costmap, step_length);
+		indi_step(i, map, costmap, sx, sy);
 
-		/* test if new individual finished */
+		/* test if new individuum finished */
 		if (indi_array[i].finished) {
 		    finished_cnt++;
 
@@ -351,10 +349,9 @@
    performs a search run for each fragment
  */
 void perform_search(DCELL * values, int *map, DCELL * costmap, int size,
-		    f_statmethod **stats, int stat_count)
+		    f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy)
 {
-    int fragment, i;
-    int steps;
+    int i;
     f_statmethod *func;
     int x, y;
 
@@ -404,7 +401,7 @@
     /* perform a search run for each window */
     for (x = 0; x < nx; x++) {
 	for (y = 0; y < ny; y++) {
-	    steps = window_run(x, y, map, costmap);
+	    window_run(x, y, map, costmap, n, sx, sy);
 
 	    for (i = 0; i < n; i++) {
 		indi_paths[i] = indi_array[i].path;



More information about the grass-commit mailing list