[GRASS-SVN] r58999 - in grass/branches/releasebranch_6_4/raster/r.li: . r.li.cwed r.li.daemon r.li.dominance r.li.edgedensity r.li.mpa r.li.mps r.li.padcv r.li.padrange r.li.padsd r.li.patchdensity r.li.patchnum r.li.pielou r.li.renyi r.li.richness r.li.setup r.li.shannon r.li.shape r.li.simpson

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 11 06:09:04 PST 2014


Author: neteler
Date: 2014-02-11 06:09:03 -0800 (Tue, 11 Feb 2014)
New Revision: 58999

Added:
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection.sh
Removed:
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection
Modified:
   grass/branches/releasebranch_6_4/raster/r.li/TODO
   grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/cwed.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.h
   grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/index.h
   grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/ipc.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/list.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/list.h
   grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/worker.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/dominance.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/edgedensity.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/mpa.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/mps.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/padcv.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/padrange.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/padsd.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/main.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/main.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/pielou.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.renyi/renyi.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/richness.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/Makefile
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/area_query
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup.main
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup.procedures.tcl
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.windows.tcl
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/sample_area_vector.sh
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/square_mouse_selection.sh
   grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/square_query
   grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/shannon.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/main.c
   grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/simpson.c
Log:
r.li.*: backport of fixes from devbr6

Modified: grass/branches/releasebranch_6_4/raster/r.li/TODO
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/TODO	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/TODO	2014-02-11 14:09:03 UTC (rev 58999)
@@ -4,11 +4,21 @@
 - add relevant references
 - use English variable names in C code
 
-Please change the examples to Spearfish wherever possible:
+Please change the examples to North Carolina wherever possible:
 
+
 # Spearfish
 g.region rast=landcover.30m -p
-r.mapcalc "forests=if(landcover.30m >= 41 && landcover.30m <=43,1,null())"
+r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
+d.mon x0
+d.rast forests
+
+# r.li.setup:
+# created as described in EXAMPLES, moving window, in r.li.setup/description.html:
+echo "SAMPLINGFRAME 0|0|1|1
+SAMPLEAREA -1|-1|0.015021459227467811|0.011058451816745656
+MOVINGWINDOW" > $HOME/.r.li/history/movwindow7
+
 r.li.patchdensity forests conf=movwindow7 out=forests_p_dens7
 d.rast.leg forests_p_dens7
 
@@ -31,4 +41,8 @@
 max=19.841270
 # -> all cells are 19.841270 ?!
 
+---------
 
+Add example which results in an ASCII output file
+
+

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/cwed.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/cwed.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/cwed.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -25,11 +25,11 @@
 #define _PRES 1
 #define _ERR -1
 
-int calculate(int fd, area_des ad, Coppie * cc, long totCoppie,
+int calculate(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	      double *result);
-int calculateD(int fd, area_des ad, Coppie * cc, long totCoppie,
+int calculateD(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	       double *result);
-int calculateF(int fd, area_des ad, Coppie * cc, long totCoppie,
+int calculateF(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	       double *result);
 
 int main(int argc, char *argv[])
@@ -80,7 +80,7 @@
 }
 
 
-int contrastWeightedEdgeDensity(int fd, char **par, area_des ad,
+int contrastWeightedEdgeDensity(int fd, char **par, struct area_entry *ad,
 				double *result)
 {
     double indice = 0;		/* the result */
@@ -251,8 +251,8 @@
 	    }
 
 	}
-	else;
-	/* num = 1  ---> in the line there is only 1 token 
+	/*else
+	 *    num = 1  ---> in the line there is only 1 token 
 	 * I ignore this line
 	 */
 
@@ -298,7 +298,7 @@
 
 
 
-int calculate(int fd, area_des ad, Coppie * cc, long totCoppie,
+int calculate(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	      double *result)
 {
 
@@ -440,7 +440,7 @@
 }
 
 
-int calculateD(int fd, area_des ad, Coppie * cc, long totCoppie,
+int calculateD(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	       double *result)
 {
 
@@ -576,7 +576,7 @@
 
 
 
-int calculateF(int fd, area_des ad, Coppie * cc, long totCoppie,
+int calculateF(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	       double *result)
 {
 

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -35,14 +35,14 @@
 #include "daemon.h"
 
 
-int calculateIndex(char *file, int f(int, char **, area_des, double *),
+int calculateIndex(char *file, int f(int, char **, struct area_entry *, double *),
 		   char **parameters, char *raster, char *output)
 {
 
     char pathSetup[GPATH_MAX], out[GPATH_MAX], parsed;
     char *reportChannelName, *random_access_name;
     struct History history;
-    g_areas g;
+    struct g_area *g;
     int receiveChannel;
     int res;
     int i, mypid, doneDir, withoutJob, mv_fd, random_access;
@@ -56,15 +56,13 @@
 
     wd child[num_workers];
 
-    /*int mv_rows, mv_cols; */
-    list l;
+    /* int mv_rows, mv_cols; */
+    struct list *l;
     msg m, doneJob;
 
-    int perc=0;
-
-    g = (g_areas) G_malloc(sizeof(struct generatore));
+    g = (struct g_area *) G_malloc(sizeof(struct g_area));
     g->maskname = NULL;
-    l = (list) G_malloc(sizeof(struct lista));
+    l = (struct list*) G_malloc(sizeof(struct list));
     l->head = NULL;
     l->tail = NULL;
     l->size = 0;
@@ -145,6 +143,7 @@
 	    G_fatal_error(_("Cannot create random access file"));
     }
     else {
+	/* text file output */
 	/* check if ~/.r.li/output exists */
 	sprintf(out, "%s/.r.li/", G_home());
 
@@ -182,8 +181,9 @@
 
 	    donePid = doneJob.f.f_d.pid;
 	    result = doneJob.f.f_d.res;
-	    /*output */
+	    /* output */
 	    if (parsed != MVWIN) {
+		/* text file output */
 		print_Output(res, doneJob);
 	    }
 	    else {
@@ -195,6 +195,7 @@
 	else {
 	    donePid = doneJob.f.f_e.pid;
 	    if (parsed != MVWIN) {
+		/* text file output */
 		error_Output(res, doneJob);
 	    }
 	    else {
@@ -207,6 +208,7 @@
 
 	while (j < num_workers && donePid != child[j].pid)
 	    j++;
+
 	send(child[j].channel, &m);
 
     }
@@ -223,10 +225,11 @@
 	    donePid = doneJob.f.f_d.pid;
 	    result = doneJob.f.f_d.res;
 	    if (parsed != MVWIN) {
+		/* text file output */
 		print_Output(res, doneJob);
 	    }
 	    else {
-		/* raster */
+		/* raster output */
 		raster_Output(random_access, doneJob.f.f_d.aid, g,
 			      doneJob.f.f_d.res);
 	    }
@@ -234,6 +237,7 @@
 	else {
 	    donePid = doneJob.f.f_e.pid;
 	    if (parsed != MVWIN) {
+		/* text file output */
 		error_Output(res, doneJob);
 	    }
 	    else {
@@ -255,12 +259,10 @@
 	if (!(WIFEXITED(status)))
 	    G_warning(_("r.li.worker (pid %i) exited with abnormal status: %i"),
 		      donePid, status);
-	else {
+	else
 	    G_verbose_message(_("r.li.worker (pid %i) terminated successfully"),
 			      donePid);
-	    perc++;
-	    G_percent (perc, num_workers, 1);
-        }
+
 	/* remove pipe */
 	if (close(child[j].channel) != 0)
 	    G_message(_("Cannot close %s file (PIPE)"), child[j].pipe);
@@ -304,6 +306,9 @@
 	G_short_history(output, "raster", &history);
 	G_command_history(&history);
 	G_write_history(output, &history);
+    } else {
+	/* text file output */
+	G_message("Result written to ASCII file <%s>", out);
     }
 
     if (close(receiveChannel) != 0)
@@ -316,11 +321,11 @@
 }
 
 
-int parseSetup(char *path, list l, g_areas g, char *raster)
+int parseSetup(char *path, struct list *l, struct g_area *g, char *raster)
 {
     struct stat s;
     struct Cell_head cellhd;
-    char *buf, *token, *mapset;
+    char *buf, *token, *mapset; /* *raster_fqn, */
     int setup;
     int letti;
     double rel_x, rel_y, rel_rl, rel_cl;
@@ -353,7 +358,7 @@
 
     /* find raster map */
     mapset = G_find_cell(raster, "");
-    char * raster_ = G_fully_qualified_name(raster, mapset);
+/*    raster_fqn = G_fully_qualified_name(raster, mapset); */
    
     if (G_get_cellhd(raster, mapset, &cellhd) == -1)
 	G_fatal_error(_("Cannot read raster header file"));
@@ -385,7 +390,6 @@
 
 	    if (rel_sa_x == -1.0 && rel_sa_y == -1.0) {
 		/* runtime disposition */
-
 		int sa_rl, sa_cl;
 
 		sa_rl = (int)rint(cellhd.rows * rel_sa_rl);
@@ -422,7 +426,6 @@
 		 strcmp(token, "SAMPLEAREA") == 0);
 
 	close(setup);
-
 	return toReturn;
     }
     else if (strcmp("MASKEDSAMPLEAREA", token) == 0) {
@@ -436,6 +439,7 @@
 	    rel_sa_rl = atof(strtok(NULL, "|"));
 	    rel_sa_cl = atof(strtok(NULL, "|"));
 	    strcpy(maskname, strtok(NULL, "\n"));
+
 	    if (rel_sa_x == -1 && rel_sa_y == -1) {
 		/* runtime disposition */
 		int sa_rl, sa_cl;
@@ -467,17 +471,24 @@
 		insertNode(l, m);
 	    }
 	}
+
 	while ((token = strtok(NULL, " ")) != NULL &&
 	       strcmp(token, "MASKEDSAMPLEAREA") == 0);
+
 	close(setup);
 	return NORMAL;
     }
     else if (strcmp("MASKEDOVERLAYAREA", token) == 0) {
 	double sa_n, sa_s, sa_w, sa_e;
 	int aid = 1;
-	char maskname[GNAME_MAX] = { '\0' };
+	char maskname[GNAME_MAX] = {'\0'};
+	struct Cell_head window;
 	msg m;
 
+	/* Get the window setting. g.region rast=<input raster> */
+	/*   ? same as cellhd above ? */
+	G_get_window(&window);
+
 	do {
 	    strcpy(maskname, strtok(NULL, "|"));
 	    sa_n = atof(strtok(NULL, "|"));
@@ -487,16 +498,14 @@
 
 	    m.type = MASKEDAREA;
 
-	    struct Cell_head window;
-	    /* Get the window setting. g.region rast=<input raster> */
-	    G_get_window(&window);
 	    /* Each input overlay area from input vector are converted to raster
-	    via v.to.rast. See r.li.setup/sample_area_vector.sh. This is to used 
-	    only for reading the region (NS, EW). */
+	       via v.to.rast. See r.li.setup/sample_area_vector.sh. This is to used 
+	       only for reading the region (NS, EW). */
 
 	    /* Get start x and y position of masked overlay raster with respect 
-	    to input raster region from window. 
-	    sa_n, sa_e are read from configuration file. */
+	       to input raster region from window. 
+	       sa_n, sa_e are read from configuration file. */
+
 	    m.f.f_ma.x = (int)G_easting_to_col(sa_e, &window);
 	    m.f.f_ma.y = (int)G_northing_to_row(sa_n, &window);
 
@@ -509,16 +518,18 @@
 	    aid++;
 	    insertNode(l, m);
 	}
+
 	while ((token = strtok(NULL, " ")) != NULL &&
 	       (strcmp(token, "MASKEDOVERLAYAREA") == 0));
 
 	if (strcmp(token, "RASTERMAP") != 0)
-	    G_fatal_error(_("Irregular maskedoverlay areas definition"));
+	    G_fatal_error(_("Irregular MASKEDOVERLAY areas definition"));
 
 	token = strtok(NULL, "\n");
-	if (strcmp(token, raster_) != 0)
-	    G_fatal_error(_("The configuration file can be used only with \
-			%s rasterfile and not with %s "), token, raster_);
+/*	if (strcmp(token, raster_fqn) != 0)
+	    G_fatal_error(_("The configuration file can be used only with "
+			"rasterfile <%s> and not with <%s>"), token, raster_fqn); */
+
 	close(setup);
 	return NORMAL;
     }
@@ -529,7 +540,7 @@
     return ERROR;
 }
 
-int disposeAreas(list l, g_areas g, char *def)
+int disposeAreas(struct list *l, struct g_area *g, char *def)
 {
     char *token;
 
@@ -668,7 +679,7 @@
 }
 
 
-int next_Area(int parsed, list l, g_areas g, msg * m)
+int next_Area(int parsed, struct list *l, struct g_area *g, msg * m)
 {
     if (parsed == NORMAL) {
 	if (l->size == 0)
@@ -724,7 +735,7 @@
 }
 
 
-int raster_Output(int fd, int aid, g_areas g, double res)
+int raster_Output(int fd, int aid, struct g_area *g, double res)
 {
     double toPut = res;
     off_t offset = (off_t) aid * sizeof(double);
@@ -741,7 +752,7 @@
 }
 
 
-int write_raster(int mv_fd, int random_access, g_areas g)
+int write_raster(int mv_fd, int random_access, struct g_area *g)
 {
     int i = 0, j = 0, letti = 0;
     double *file_buf;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.h
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.h	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.h	2014-02-11 14:09:03 UTC (rev 58999)
@@ -120,11 +120,9 @@
     char *mask_name;
 };
 
-typedef struct area_entry *area_des;
 
 
 
-
 /**
  * \brief applies the f index once for every
  * area defined in setup file
@@ -134,8 +132,7 @@
  * \return 0 error occurs in calculating index
  * \return 1  otherwise
  */
-
-int calculateIndex(char *file, int f(int, char **, area_des, double *),
+int calculateIndex(char *file, int f(int, char **, struct area_entry *, double *),
 		   char **parameters, char *raster, char *output);
 
 /**
@@ -151,7 +148,7 @@
  * be written in normal way
  * \return MVWIN if a new raster file had to be created
  */
-int parseSetup(char *path, list l, g_areas g, char *raster);
+int parseSetup(char *path, struct list *l, struct g_area *g, char *raster);
 
 /**
  * \description dispose sample areas if configuration file have
@@ -165,7 +162,7 @@
  * be written in normal way
  * \return MVWIN if a new raster file had to be created
  */
-int disposeAreas(list l, g_areas g, char *def);
+int disposeAreas(struct list *l, struct g_area *g, char *def);
 
 /**
  * \brief generate the next area to analyze
@@ -176,7 +173,7 @@
  * \return 1 if the area is generated
  * \return 0 if there isn't another area
  */
-int next_Area(int parsed, list l, g_areas g, msg * m);
+int next_Area(int parsed, struct list *l, struct g_area *g, msg * m);
 
 /**
  * \brief writes output in a file
@@ -204,9 +201,8 @@
  * \param mychannel the channel where to receive the area messages
  * \param result where to put the result of index computing
  */
-void worker(char *raster, int f(int, char **, area_des, double *),
+void worker(char *raster, int f(int, char **, struct area_entry *, double *),
 	    char *server_channel, char *mychannel, char **parameters);
-
  /**
   * \brief adapts the mask at current raster file
   * \param mask name of mask raster file
@@ -224,7 +220,7 @@
   * \param res the result to be written
   * \return 0 on error, 1 if done
   */
-int raster_Output(int fd, int aid, g_areas g, double res);
+int raster_Output(int fd, int aid, struct g_area *g, double res);
 
  /**
   * \brief calculates a simple index for code debugging
@@ -234,7 +230,7 @@
   * \param result where to return result
   * \return 0 on error, 1 otherwise
   */
-int simple_index(int fd, char **par, area_des ad, double *result);
+int simple_index(int fd, char **par, struct area_entry * ad, double *result);
 
  /**
   * \brief copy the content of regular file random access 
@@ -244,7 +240,7 @@
   * \param g the mv window generator
   * \return 0 on error, 1 otherwise
   */
-int write_raster(int mv_fd, int random_access, g_areas g);
+int write_raster(int mv_fd, int random_access, struct g_area *g);
 
  /**
   * \brief get a cell raster row using the memory menager
@@ -252,7 +248,7 @@
   * \param row identifier of row to get
   * \param ad area descriptor of current sample area
   */
-CELL *RLI_get_cell_raster_row(int fd, int row, area_des ad);
+CELL *RLI_get_cell_raster_row(int fd, int row, struct area_entry * ad);
 
  /**
   * \brief get a dcell raster row using the memory menager
@@ -260,7 +256,7 @@
   * \param row identifier of row to get
   * \param ad area descriptor of current sample area
   */
-DCELL *RLI_get_dcell_raster_row(int fd, int row, area_des ad);
+DCELL *RLI_get_dcell_raster_row(int fd, int row, struct area_entry * ad);
 
  /**
   * \brief get a fcell raster row using the memory menager
@@ -268,6 +264,6 @@
   * \param row identifier of row to get
   * \param ad area descriptor of current sample area
   */
-FCELL *RLI_get_fcell_raster_row(int fd, int row, area_des ad);
+FCELL *RLI_get_fcell_raster_row(int fd, int row, struct area_entry * ad);
 
 #include "index.h"

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/index.h
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/index.h	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/index.h	2014-02-11 14:09:03 UTC (rev 58999)
@@ -26,25 +26,25 @@
   * \brief calculate patch density index on selected area
   * the abstract function is patch_density= patch_number / area
   */
-int patch_density(int fd, char **par, area_des ad, double *result);
+int patch_density(int fd, char **par, struct area_entry *ad, double *result);
 
-int patch_number(int fd, char **par, area_des ad, double *result);
-int shape_index(int fd, char **par, area_des ad, double *result);
-int shannon(int fd, char **par, area_des ad, double *result);
+int patch_number(int fd, char **par, struct area_entry *ad, double *result);
+int shape_index(int fd, char **par, struct area_entry *ad, double *result);
+int shannon(int fd, char **par, struct area_entry *ad, double *result);
 
-int pielou(int fd, char **par, area_des ad, double *result);
-int renyi(int fd, char **par, area_des ad, double *result);
+int pielou(int fd, char **par, struct area_entry *ad, double *result);
+int renyi(int fd, char **par, struct area_entry *ad, double *result);
 
-int simpson(int fd, char **par, area_des ad, double *result);
-int meanPatchSize(int fd, char **par, area_des ad, double *result);
-int meanPixelAttribute(int fd, char **par, area_des ad, double *result);
-int contrastWeightedEdgeDensity(int fd, char **par, area_des ad,
+int simpson(int fd, char **par, struct area_entry *ad, double *result);
+int meanPatchSize(int fd, char **par, struct area_entry *ad, double *result);
+int meanPixelAttribute(int fd, char **par, struct area_entry *ad, double *result);
+int contrastWeightedEdgeDensity(int fd, char **par, struct area_entry *ad,
 				double *result);
-int edgedensity(int fd, char **valore, area_des ad, double *result);
-int patchAreaDistributionCV(int fd, char **par, area_des ad, double *result);
-int patchAreaDistributionMN(int fd, char **par, area_des ad, double *result);
-int patchAreaDistributionSD(int fd, char **par, area_des ad, double *result);
-int patchAreaDistributionRANGE(int fd, char **par, area_des ad,
+int edgedensity(int fd, char **valore, struct area_entry *ad, double *result);
+int patchAreaDistributionCV(int fd, char **par, struct area_entry *ad, double *result);
+int patchAreaDistributionMN(int fd, char **par, struct area_entry *ad, double *result);
+int patchAreaDistributionSD(int fd, char **par, struct area_entry *ad, double *result);
+int patchAreaDistributionRANGE(int fd, char **par, struct area_entry *ad,
 			       double *result);
-int dominance(int fd, char **par, area_des ad, double *result);
-int richness(int fd, char **par, area_des ad, double *result);
+int dominance(int fd, char **par, struct area_entry *ad, double *result);
+int richness(int fd, char **par, struct area_entry *ad, double *result);

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/ipc.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/ipc.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/ipc.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -23,19 +23,20 @@
 #include "ipc.h"
 
 
-int send(int pipe, msg * m)
+int send(int pipe, msg *m)
 {
     int check;
 
     /* write on pipe */
     check = write(pipe, m, sizeof(msg));
+
     if (check > 0)
 	return 1;
     else
 	return 0;
 }
 
-int receive(int pipe, msg * m)
+int receive(int pipe, msg *m)
 {
     return read(pipe, m, sizeof(msg));
 }

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/list.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/list.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/list.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -25,11 +25,11 @@
  * \param l list where to insert
  * \param mess the message to insert
  */
-void insertNode(list l, msg mess)
+void insertNode(struct list *l, msg mess)
 {
-    node new;
+    struct node *new;
 
-    new = G_malloc(sizeof(struct nodoLista));
+    new = G_malloc(sizeof(struct node));
     new->m = G_malloc(sizeof(msg));
 
     if (new != NULL) {
@@ -56,20 +56,20 @@
  *\brief remove a node from list
  * \param list where to remove
  */
-void removeNode(list l)
+void removeNode(struct list *l)
 {
     if (l->head == NULL) {
 	return;
     }
     if (l->head->next == NULL) {
-	node tmp = l->head;
+	struct node *tmp = l->head;
 
 	l->head = NULL;
 	free(tmp);
 	l->size--;
     }
     else {
-	node tmp = l->head;
+	struct node *tmp = l->head;
 
 	l->head = l->head->next;
 	l->head->prev = NULL;
@@ -83,7 +83,7 @@
  * \param gen area generator to use
  * \param msg next area message
  */
-int next(g_areas gen, msg * toReturn)
+int next(struct g_area *gen, msg *toReturn)
 {
 
     if (gen->cl > gen->cols)

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/list.h
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/list.h	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/list.h	2014-02-11 14:09:03 UTC (rev 58999)
@@ -27,10 +27,10 @@
  * \member next the next item in list
  * \member m the content of list node
  */
-struct nodoLista
+struct node
 {
-    struct nodoLista *prev;
-    struct nodoLista *next;
+    struct node *prev;
+    struct node *next;
     msg *m;
 };
 
@@ -42,29 +42,26 @@
  * \member tail last item in list
  * \member size number of items in list
  */
-struct lista
+struct list
 {
-    struct nodoLista *head;
-    struct nodoLista *tail;
+    struct node *head;
+    struct node *tail;
     int size;
 };
 
-typedef struct nodoLista *node;
 
-typedef struct lista *list;
-
 /**
  * \brief insert a item in list
  * \param l list where to put items
  * \param mess the message to insert
  */
-void insertNode(list l, msg m);
+void insertNode(struct list *l, msg m);
 
 /**
  * \brief remove head item
  * \param l list where to remove
  */
-void removeNode(list l);
+void removeNode(struct list *l);
 
  /**
   * \brief struct for runtime area generation
@@ -80,7 +77,7 @@
   * \param sf_y y coordinate of sample frame
   * \param maskname name of mask for the area
   */
-struct generatore
+struct g_area
 {
     int dist;
     int add_row;
@@ -97,11 +94,9 @@
     char *maskname;
 };
 
-typedef struct generatore *g_areas;
-
 /**
  * \brief runtime area generation
  * \param gen area generator to use
  * \param msg next area message
  */
-int next(g_areas gen, msg * toReturn);
+int next(struct g_area *gen, msg *toReturn);

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/worker.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/worker.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/worker.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -37,7 +37,7 @@
 
 #define CACHESIZE 4194304
 
-void worker(char *raster, int f(int, char **, area_des, double *),
+void worker(char *raster, int f(int, char **, struct area_entry *, double *),
 	    char *server_channel, char *mychannel, char **parameters)
 {
     char *mapset;
@@ -45,7 +45,7 @@
     int rec_ch, send_ch, erease_mask = 0, data_type = 0;
     int cache_rows, used = 0;
     msg toReceive, toSend;
-    area_des ad;
+    static struct area_entry *ad;
     double result;
     int pid;
     struct Cell_head hd;
@@ -69,6 +69,7 @@
 
     /* read data type to allocate cache */
     data_type = G_raster_map_type(raster, mapset);
+
     /* calculate rows in cache */
     switch (data_type) {
     case CELL_TYPE:{
@@ -224,7 +225,7 @@
 
 char *mask_preprocessing(char *mask, char *raster, int rl, int cl)
 {
-    char *mapset, *tmp_file;
+    char *mapset, *mask_mapset, *tmp_file;
     struct Cell_head cell, oldcell;
     int mask_fd, old_fd, *buf, i, j;
     CELL *old;
@@ -237,14 +238,16 @@
 
     /* mapset is used hold the mapset of input raster */
     mapset = G_find_cell(raster, "");
+
     /* open raster */
     if (G_get_cellhd(raster, mapset, &cell) == -1)
 	return NULL;
 
-    /* mmapset is used hold the mapset where mask is saved */
-    char *mmapset = G_find_cell(mask, "");
+
+    mask_mapset = G_find_cell(mask, "");
+
     /* open raster */
-    if (G_get_cellhd(mask, mmapset, &oldcell) == -1)
+    if (G_get_cellhd(mask, mask_mapset, &oldcell) == -1)
 	return NULL;
 
     add_row = 1.0 * oldcell.rows / rl;
@@ -252,7 +255,10 @@
 
     tmp_file = G_tempfile();
     mask_fd = open(tmp_file, O_RDWR | O_CREAT, 0755);
-    old_fd = G_open_cell_old(mask, mapset);
+
+    old_fd = G_open_cell_old(mask, mask_mapset);
+
+    G_debug(1, "worker.c: mask <%s@%s>", mask, mask_mapset);
     old = G_allocate_cell_buf();
 
     for (i = 0; i < rl; i++) {
@@ -273,7 +279,7 @@
     return G_store(tmp_file);
 }
 
-CELL *RLI_get_cell_raster_row(int fd, int row, area_des ad)
+CELL *RLI_get_cell_raster_row(int fd, int row, struct area_entry *ad)
 {
     int hash;
 
@@ -288,7 +294,7 @@
 
 }
 
-DCELL *RLI_get_dcell_raster_row(int fd, int row, area_des ad)
+DCELL *RLI_get_dcell_raster_row(int fd, int row, struct area_entry *ad)
 {
     int hash;
 
@@ -303,7 +309,7 @@
 
 }
 
-FCELL *RLI_get_fcell_raster_row(int fd, int row, area_des ad)
+FCELL *RLI_get_fcell_raster_row(int fd, int row, struct area_entry *ad)
 {
     int hash;
 

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/dominance.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/dominance.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/dominance.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -6,7 +6,7 @@
  *
  *   This program is free software under the GPL (>=v2)
  *   Read the COPYING file that comes with GRASS for details.
- *       
+ *
  */
 
 #include <grass/gis.h>
@@ -21,9 +21,9 @@
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
 
-int calculate(int fd, area_des ad, double *result);
-int calculateD(int fd, area_des ad, double *result);
-int calculateF(int fd, area_des ad, double *result);
+int calculate(int fd, struct area_entry *ad, double *result);
+int calculateD(int fd, struct area_entry *ad, double *result);
+int calculateF(int fd, struct area_entry *ad, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -44,8 +44,8 @@
     conf = G_define_option();
     conf->key = "conf";
     conf->description = _("Configuration file");
-    conf->gisprompt = "old_file,file,input";
     conf->type = TYPE_STRING;
+    conf->gisprompt = "old_file,file,input";
     conf->required = YES;
 
     output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -59,37 +59,31 @@
 }
 
 
-int dominance(int fd, char **par, area_des ad, double *result)
+int dominance(int fd, char **par, struct area_entry *ad, double *result)
 {
-
     char *mapset;
-
     int ris = RLI_OK;
-
     double indice = 0;
-
     struct Cell_head hd;
 
-
     mapset = G_find_cell(ad->raster, "");
     if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
 	return RLI_ERRORE;
 
-
     switch (ad->data_type) {
     case CELL_TYPE:
 	{
-	    calculate(fd, ad, &indice);
+	    ris = calculate(fd, ad, &indice);
 	    break;
 	}
     case DCELL_TYPE:
 	{
-	    calculateD(fd, ad, &indice);
+	    ris = calculateD(fd, ad, &indice);
 	    break;
 	}
     case FCELL_TYPE:
 	{
-	    calculateF(fd, ad, &indice);
+	    ris = calculateF(fd, ad, &indice);
 	    break;
 	}
     default:
@@ -97,12 +91,12 @@
 	    G_fatal_error("data type unknown");
 	    return RLI_ERRORE;
 	}
-    }
 
-    if (ris != RLI_OK) {
-	return RLI_ERRORE;
     }
 
+    if (ris != RLI_OK)
+	   return RLI_ERRORE;
+
     *result = indice;
 
     return RLI_OK;
@@ -110,7 +104,7 @@
 }
 
 
-int calculate(int fd, area_des ad, double *result)
+int calculate(int fd, struct area_entry *ad, double *result)
 {
 
     CELL *buf;
@@ -135,12 +129,10 @@
     double t;
     double logaritmo;
 
-    generic_cell cc;
-
     avl_tree albero = NULL;
-
     AVL_table *array;
 
+    generic_cell cc;
 
     cc.t = CELL_TYPE;
 
@@ -156,15 +148,9 @@
 	masked = TRUE;
     }
 
-
     G_set_c_null_value(&precCell, 1);
 
-
-    /*for each row */
-    for (j = 0; j < ad->rl; j++) {
-	buf = RLI_get_cell_raster_row(fd, j + ad->y, ad);
-
-
+    for (j = 0; j < ad->rl; j++) {	/* for each row */
 	if (masked) {
 	    if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
 		G_fatal_error("mask read failed");
@@ -172,12 +158,12 @@
 	    }
 	}
 
-
+	buf = RLI_get_cell_raster_row(fd, j + ad->y, ad);
 	for (i = 0; i < ad->cl; i++) {	/* for each cell in the row */
 	    area++;
 	    corrCell = buf[i + ad->x];
 
-	    if (masked && mask_buf[i + ad->x] == 0) {
+	    if ((masked) && (mask_buf[i + ad->x] == 0)) {
 		G_set_c_null_value(&corrCell, 1);
 		area--;
 	    }
@@ -187,7 +173,6 @@
 		if (G_is_null_value(&precCell, cc.t)) {
 		    precCell = corrCell;
 		}
-
 		if (corrCell != precCell) {
 		    if (albero == NULL) {
 			cc.val.c = precCell;
@@ -197,6 +182,7 @@
 			    G_fatal_error("avl_make error");
 			    return RLI_ERRORE;
 			}
+			/* TODO missing?: else  - see r.li.simpson/simpson.c */
 			m++;
 		    }
 		    else {
@@ -235,10 +221,8 @@
 	}			/* end for */
     }				/* end for */
 
-
-
+    /*last closing */
     if (a != 0) {
-	/*last closing */
 	if (albero == NULL) {
 	    cc.val.c = precCell;
 	    albero = avl_make(cc, totCorr);
@@ -306,25 +290,18 @@
     else			/*if a is 0, that is all cell are null, i put index=-1 */
 	indice = (double)(-1);
 
-    *result = indice;
 
-
-    if (masked) {
+    if (masked)
 	G_free(mask_buf);
-    }
 
+    *result = indice;
+
     return RLI_OK;
 }
 
 
-
-
-
-
-
-int calculateD(int fd, area_des ad, double *result)
+int calculateD(int fd, struct area_entry *ad, double *result)
 {
-
     DCELL *buf;
     DCELL corrCell;
     DCELL precCell;
@@ -367,14 +344,9 @@
 	masked = TRUE;
     }
 
-
     G_set_d_null_value(&precCell, 1);
 
-    /*for each row */
-    for (j = 0; j < ad->rl; j++) {
-	buf = RLI_get_dcell_raster_row(fd, j + ad->y, ad);
-
-
+    for (j = 0; j < ad->rl; j++) {	/* for each row */
 	if (masked) {
 	    if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
 		G_fatal_error("mask read failed");
@@ -382,6 +354,7 @@
 	    }
 	}
 
+	buf = RLI_get_dcell_raster_row(fd, j + ad->y, ad);
 
 	for (i = 0; i < ad->cl; i++) {	/* for each dcell in the row */
 	    area++;
@@ -447,9 +420,8 @@
 	G_free(mask_buf);
     }
 
-
-    if (a != 0) {
 	/*last closing */
+    if (a != 0) {
 	if (albero == NULL) {
 	    cc.val.dc = precCell;
 	    albero = avl_make(cc, totCorr);
@@ -526,9 +498,8 @@
 }
 
 
-int calculateF(int fd, area_des ad, double *result)
+int calculateF(int fd, struct area_entry *ad, double *result)
 {
-
     FCELL *buf;
     FCELL corrCell;
     FCELL precCell;
@@ -571,15 +542,10 @@
 	masked = TRUE;
     }
 
-
     G_set_f_null_value(&precCell, 1);
 
 
-    /*for each row */
-    for (j = 0; j < ad->rl; j++) {
-	buf = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
-
-
+    for (j = 0; j < ad->rl; j++) {	/* for each row */
 	if (masked) {
 	    if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
 		G_fatal_error("mask read failed");
@@ -587,10 +553,13 @@
 	    }
 	}
 
+	buf = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
 
 	for (i = 0; i < ad->cl; i++) {	/* for each fcell in the row */
+
 	    area++;
 	    corrCell = buf[i + ad->x];
+
 	    if (masked && mask_buf[i + ad->x] == 0) {
 		G_set_f_null_value(&corrCell, 1);
 		area--;
@@ -648,7 +617,6 @@
 	}
     }
 
-
     /*last closing */
     if (a != 0) {
 	if (albero == NULL) {
@@ -715,18 +683,15 @@
 
 	G_free(array);
     }
-
-
     else			/*if a is 0, that is all cell are null, i put index=-1 */
-	indice = (double)(-1);
+	  indice = (double)(-1);
 
 
-    *result = indice;
-
-
-
     if (masked) {
 	G_free(mask_buf);
     }
+
+    *result = indice;
+
     return RLI_OK;
 }

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/edgedensity.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/edgedensity.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/edgedensity.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -20,9 +20,9 @@
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
 
-int calculate(int fd, area_des ad, char **valore, double *result);
-int calculateD(int fd, area_des ad, char **valore, double *result);
-int calculateF(int fd, area_des ad, char **valore, double *result);
+int calculate(int fd, struct area_entry *ad, char **valore, double *result);
+int calculateD(int fd, struct area_entry *ad, char **valore, double *result);
+int calculateF(int fd, struct area_entry *ad, char **valore, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -54,10 +54,10 @@
     class->type = TYPE_STRING;
     class->required = NO;
     class->multiple = NO;
-    class->description =
-	"The value of the patch type, it can be integer, double or float; it will be changed in function of map type";
+    class->label = _("The value of the patch type");
+    class->description = _("It can be integer, double or float; "
+			   "it will be changed in function of map type");
 
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -73,7 +73,7 @@
 }
 
 
-int edgedensity(int fd, char **valore, area_des ad, double *result)
+int edgedensity(int fd, char **valore, struct area_entry *ad, double *result)
 {
     struct Cell_head hd;
 
@@ -121,40 +121,34 @@
 }
 
 
-int calculate(int fd, area_des ad, char **valore, double *result)
+int calculate(int fd, struct area_entry *ad, char **valore, double *result)
 {
     double indice = 0;
     double e = 0;
     double somma = 0;
     double area = 0;
-
     CELL *buf_corr, *buf_sup, *buf_inf;
     CELL prevCell, corrCell, supCell, infCell, nextCell;
-
     AVL_table *array;
-
-    buf_sup = NULL;
-
     long tot = 0;
     long zero = 0;
     long m = 0;
     long bordoCorr = 0;
-
     avl_tree albero = NULL;
-
     int i, j;
     int mask_fd = -1, *mask_corr, *mask_sup, *mask_inf;
     int masked = FALSE;
     int ris;
-
     generic_cell c1;
 
+    buf_sup = NULL;
     c1.t = CELL_TYPE;
+
     /* open mask if needed */
     if (ad->mask == 1) {
 	if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
-	    G_fatal_error("can't  open mask %s", ad->mask_name);
-	    return RLI_ERRORE;
+	    G_fatal_error("Cannot open mask file <%s>", ad->mask_name);
+	    return RLI_ERRORE;  /* FIXME: can not return from a fatal error */
 	}
 
 	mask_corr = G_malloc(ad->cl * sizeof(int));
@@ -178,11 +172,14 @@
 	return RLI_ERRORE;
     }
 
-    G_set_c_null_value(buf_sup + ad->x, ad->cl);	/*the first time buf_sup is all null */
+    /* the first time buf_sup is all null */
+    G_set_c_null_value(buf_sup + ad->x, ad->cl);
 
-    for (j = 0; j < ad->rl; j++) {	/* for each raster row */
+    /* for each raster row */
+    for (j = 0; j < ad->rl; j++) {
 
-	buf_corr = RLI_get_cell_raster_row(fd, j + ad->y, ad);	/* read row of raster */
+	/* read row of raster */
+	buf_corr = RLI_get_cell_raster_row(fd, j + ad->y, ad);
 
 	if (j > 0)		/* not first row */
 	    buf_sup = RLI_get_cell_raster_row(fd, j - 1 + ad->y, ad);
@@ -369,12 +366,13 @@
 	G_free(mask_inf);
 	G_free(mask_corr);
     }
-    /* G_free(buf_sup); */
+
+    /* G_free(buf_sup); */   /* <-- why not free it? */
     return RLI_OK;
 }
 
 
-int calculateD(int fd, area_des ad, char **valore, double *result)
+int calculateD(int fd, struct area_entry *ad, char **valore, double *result)
 {
     double indice = 0;
     double e = 0;
@@ -405,8 +403,8 @@
     /* open mask if needed */
     if (ad->mask == 1) {
 	if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
-	    G_fatal_error("can't  open mask");
-	    return RLI_ERRORE;
+	    G_fatal_error("Cannot open mask file");
+	    return RLI_ERRORE;  /* FIXME: can not return from a fatal error */
 	}
 
 	mask_corr = G_malloc(ad->cl * sizeof(int));
@@ -626,7 +624,7 @@
     return RLI_OK;
 }
 
-int calculateF(int fd, area_des ad, char **valore, double *result)
+int calculateF(int fd, struct area_entry *ad, char **valore, double *result)
 {
     double indice = 0;
     double e = 0;
@@ -656,8 +654,8 @@
     /* open mask if needed */
     if (ad->mask == 1) {
 	if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
-	    G_fatal_error("can't  open mask");
-	    return RLI_ERRORE;
+	    G_fatal_error("Cannot open mask file");
+	    return RLI_ERRORE;  /* FIXME: can not return from a fatal error */
 	}
 
 	mask_corr = G_malloc(ad->cl * sizeof(int));
@@ -681,16 +679,19 @@
 	return RLI_ERRORE;
     }
 
-    G_set_f_null_value(buf_sup + ad->x, ad->cl);	/*the first time buf_sup is all null */
+    /* the first time buf_sup is all null */
+    G_set_f_null_value(buf_sup + ad->x, ad->cl);
 
-    for (j = 0; j < ad->rl; j++) {	/* for each raster row */
+    /* for each raster row */
+    for (j = 0; j < ad->rl; j++) {
 
-	buf_corr = RLI_get_fcell_raster_row(fd, j + ad->y, ad);	/* read row of raster */
+	/* read row of raster */
+	buf_corr = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
 
 	if (j > 0)		/* not first row */
 	    buf_sup = RLI_get_fcell_raster_row(fd, j - 1 + ad->y, ad);
 
-	if ((j + 1) < ad->rl) {	/*not last row */
+	if ((j + 1) < ad->rl) {	/* not last row */
 
 	    buf_inf = RLI_get_fcell_raster_row(fd, 1 + j + ad->y, ad);
 	}

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/mpa.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/mpa.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/mpa.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -22,9 +22,9 @@
 #include "../r.li.daemon/daemon.h"
 
 
-int calculate(int fd, area_des ad, double *result);
-int calculateD(int fd, area_des ad, double *result);
-int calculateF(int fd, area_des ad, double *result);
+int calculate(int fd, struct area_entry *ad, double *result);
+int calculateD(int fd, struct area_entry *ad, double *result);
+int calculateF(int fd, struct area_entry *ad, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -60,7 +60,7 @@
 }
 
 
-int meanPixelAttribute(int fd, char **par, area_des ad, double *result)
+int meanPixelAttribute(int fd, char **par, struct area_entry *ad, double *result)
 {
     char *mapset;
 
@@ -110,7 +110,7 @@
 
 
 
-int calculate(int fd, area_des ad, double *result)
+int calculate(int fd, struct area_entry *ad, double *result)
 {
     CELL *buf;
 
@@ -174,7 +174,7 @@
     return RLI_OK;
 }
 
-int calculateD(int fd, area_des ad, double *result)
+int calculateD(int fd, struct area_entry *ad, double *result)
 {
     DCELL *buf;
 
@@ -239,7 +239,7 @@
     return RLI_OK;
 }
 
-int calculateF(int fd, area_des ad, double *result)
+int calculateF(int fd, struct area_entry *ad, double *result)
 {
     FCELL *buf;
 

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/mps.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/mps.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/mps.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -9,25 +9,23 @@
  *
  */
 
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
 #include <stdlib.h>
 #include <fcntl.h>
 #include <math.h>
 
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
 #include "../r.li.daemon/defs.h"
 #include "../r.li.daemon/avlDefs.h"
 #include "../r.li.daemon/avlID.h"
 #include "../r.li.daemon/daemon.h"
 
 
-int calculate(int fd, area_des ad, struct Cell_head hd, double *result);
-int calculateD(int fd, area_des ad, struct Cell_head hd, double *result);
-int calculateF(int fd, area_des ad, struct Cell_head hd, double *result);
+int calculate(int fd, struct area_entry *ad, struct Cell_head hd, double *result);
+int calculateD(int fd, struct area_entry *ad, struct Cell_head hd, double *result);
+int calculateF(int fd, struct area_entry *ad, struct Cell_head hd, double *result);
 
-
 int main(int argc, char *argv[])
 {
     struct Option *raster, *conf, *output;
@@ -60,26 +58,17 @@
 }
 
 
-
-int meanPatchSize(int fd, char **par, area_des ad, double *result)
+int meanPatchSize(int fd, char **par, struct area_entry *ad, double *result)
 {
-
     char *mapset;
-
     int ris = 0;
-
     double indice = 0;
-
     struct Cell_head hd;
 
-
-
     mapset = G_find_cell(ad->raster, "");
     if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
 	return RLI_ERRORE;
 
-
-
     switch (ad->data_type) {
     case CELL_TYPE:
 	{
@@ -101,18 +90,18 @@
 	    G_fatal_error("data type unknown");
 	    return RLI_ERRORE;
 	}
+
     }
-    if (ris != RLI_OK) {
-	return RLI_ERRORE;
-    }
+    if (ris != RLI_OK)
+	  return RLI_ERRORE;
 
     *result = indice;
-    return RLI_OK;
 
+    return RLI_OK;
 }
 
 
-int calculate(int fd, area_des ad, struct Cell_head hd, double *result)
+int calculate(int fd, struct area_entry *ad, struct Cell_head hd, double *result)
 {
     CELL *buf;
     CELL *buf_sup;
@@ -143,11 +132,8 @@
     double EW_DIST1, EW_DIST2, NS_DIST1, NS_DIST2;
 
     avlID_tree albero = NULL;
-
     avlID_table *array;
 
-
-
     /* open mask if needed */
     if (ad->mask == 1) {
 	if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0)
@@ -479,25 +465,22 @@
 
     G_free(mask_patch_corr);
 
-    G_free(buf_sup);
+    /* G_free(buf_sup); */   /* <-- why not free it? */
     return RLI_OK;
 }
 
 
-int calculateD(int fd, area_des ad, struct Cell_head hd, double *result)
+int calculateD(int fd, struct area_entry *ad, struct Cell_head hd, double *result)
 {
     DCELL *buf;
     DCELL *buf_sup;
-
     DCELL corrCell;
     DCELL precCell;
     DCELL supCell;
-
     int i, j;
     int mask_fd = -1, *mask_buf;
     int ris = 0;
     int masked = FALSE;
-
     long npatch = 0;
     long tot = 0;
     long zero = 0;
@@ -507,7 +490,6 @@
     long doppi = 0;
     long *mask_patch_sup;
     long *mask_patch_corr;
-
     double indice = 0;
     double area = 0;		/*if all cells are null area=0 */
     double areaCorrect = 0;
@@ -853,7 +835,7 @@
 }
 
 
-int calculateF(int fd, area_des ad, struct Cell_head hd, double *result)
+int calculateF(int fd, struct area_entry *ad, struct Cell_head hd, double *result)
 {
     FCELL *buf;
     FCELL *buf_sup;
@@ -1168,7 +1150,6 @@
 	    }
 	}
 
-
 	array = G_malloc(npatch * sizeof(avlID_tableRow));
 	if (array == NULL) {
 	    G_fatal_error("malloc array failed");
@@ -1213,8 +1194,8 @@
 
 
     if (masked)
-	G_free(mask_buf);
-
+	  G_free(mask_buf);
+/* TODO: fix if? */
     G_free(mask_patch_corr);
 
     return RLI_OK;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/padcv.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/padcv.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/padcv.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -9,22 +9,22 @@
  *
  */
 
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
 #include <stdlib.h>
 #include <fcntl.h>
 #include <math.h>
 
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
 #include "../r.li.daemon/defs.h"
 #include "../r.li.daemon/avlDefs.h"
 #include "../r.li.daemon/avlID.h"
 #include "../r.li.daemon/GenericCell.h"
 #include "../r.li.daemon/daemon.h"
 
-int calculate(int fd, area_des ad, double *result);
-int calculateD(int fd, area_des ad, double *result);
-int calculateF(int fd, area_des ad, double *result);
+int calculate(int fd, struct area_entry *ad, double *result);
+int calculateD(int fd, struct area_entry *ad, double *result);
+int calculateF(int fd, struct area_entry *ad, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -39,20 +39,24 @@
 
     /* define options */
     raster = G_define_standard_option(G_OPT_R_MAP);
+
     conf = G_define_option();
     conf->key = "conf";
     conf->description = _("Configuration file");
     conf->gisprompt = "old_file,file,input";
     conf->type = TYPE_STRING;
     conf->required = YES;
+
     output = G_define_standard_option(G_OPT_R_OUTPUT);
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
+
     return calculateIndex(conf->answer, patchAreaDistributionCV, NULL,
 			  raster->answer, output->answer);
 }
 
-int patchAreaDistributionCV(int fd, char **par, area_des ad, double *result)
+int patchAreaDistributionCV(int fd, char **par, struct area_entry *ad, double *result)
 {
     char *mapset;
     double indice = 0;
@@ -64,39 +68,38 @@
 	return RLI_ERRORE;
     switch (ad->data_type) {
     case CELL_TYPE:
-
 	{
 	    ris = calculate(fd, ad, &indice);
 	    break;
 	}
     case DCELL_TYPE:
-
 	{
 	    ris = calculateD(fd, ad, &indice);
 	    break;
 	}
     case FCELL_TYPE:
-
 	{
 	    ris = calculateF(fd, ad, &indice);
 	    break;
 	}
     default:
-
 	{
 	    G_fatal_error("data type unknown");
 	    return RLI_ERRORE;
 	}
+
     }
     if (ris != RLI_OK) {
 	*result = -1;
 	return RLI_ERRORE;
     }
+
     *result = indice;
+
     return RLI_OK;
 }
 
-int calculate(int fd, area_des ad, double *result)
+int calculate(int fd, struct area_entry *ad, double *result)
 {
     CELL *buf;
     CELL *buf_sup;
@@ -236,24 +239,20 @@
 				ris = avlID_add(&albero, idCorr, totCorr);
 				switch (ris) {
 				case AVL_ERR:
-
 				    {
 					G_fatal_error("avlID_add error");
 					return RLI_ERRORE;
 				    }
 				case AVL_ADD:
-
 				    {
 					npatch++;
 					break;
 				    }
 				case AVL_PRES:
-
 				    {
 					break;
 				    }
 				default:
-
 				    {
 					G_fatal_error
 					    ("avlID_add unknown error");
@@ -421,24 +420,20 @@
 	    ris = avlID_add(&albero, idCorr, totCorr);
 	    switch (ris) {
 	    case AVL_ERR:
-
 		{
 		    G_fatal_error("avlID_add error");
 		    return RLI_ERRORE;
 		}
 	    case AVL_ADD:
-
 		{
 		    npatch++;
 		    break;
 		}
 	    case AVL_PRES:
-
 		{
 		    break;
 		}
 	    default:
-
 		{
 		    G_fatal_error("avlID_add unknown error");
 		    return RLI_ERRORE;
@@ -490,11 +485,11 @@
     G_free(mask_patch_sup);
     *result = indice;
 
-    G_free(buf_sup);
+    /* G_free(buf_sup); */   /* <-- why not free it? */
     return RLI_OK;
 }
 
-int calculateD(int fd, area_des ad, double *result)
+int calculateD(int fd, struct area_entry *ad, double *result)
 {
     DCELL *buf;
     DCELL *buf_sup;
@@ -633,24 +628,20 @@
 				ris = avlID_add(&albero, idCorr, totCorr);
 				switch (ris) {
 				case AVL_ERR:
-
 				    {
 					G_fatal_error("avlID_add error");
 					return RLI_ERRORE;
 				    }
 				case AVL_ADD:
-
 				    {
 					npatch++;
 					break;
 				    }
 				case AVL_PRES:
-
 				    {
 					break;
 				    }
 				default:
-
 				    {
 					G_fatal_error
 					    ("avlID_add unknown error");
@@ -817,24 +808,20 @@
 	    ris = avlID_add(&albero, idCorr, totCorr);
 	    switch (ris) {
 	    case AVL_ERR:
-
 		{
 		    G_fatal_error("avlID_add error");
 		    return RLI_ERRORE;
 		}
 	    case AVL_ADD:
-
 		{
 		    npatch++;
 		    break;
 		}
 	    case AVL_PRES:
-
 		{
 		    break;
 		}
 	    default:
-
 		{
 		    G_fatal_error("avlID_add unknown error");
 		    return RLI_ERRORE;
@@ -888,7 +875,7 @@
     return RLI_OK;
 }
 
-int calculateF(int fd, area_des ad, double *result)
+int calculateF(int fd, struct area_entry *ad, double *result)
 {
     FCELL *buf;
     FCELL *buf_sup;
@@ -1029,24 +1016,20 @@
 				ris = avlID_add(&albero, idCorr, totCorr);
 				switch (ris) {
 				case AVL_ERR:
-
 				    {
 					G_fatal_error("avlID_add error");
 					return RLI_ERRORE;
 				    }
 				case AVL_ADD:
-
 				    {
 					npatch++;
 					break;
 				    }
 				case AVL_PRES:
-
 				    {
 					break;
 				    }
 				default:
-
 				    {
 					G_fatal_error
 					    ("avlID_add unknown error");
@@ -1214,24 +1197,20 @@
 	    ris = avlID_add(&albero, idCorr, totCorr);
 	    switch (ris) {
 	    case AVL_ERR:
-
 		{
 		    G_fatal_error("avlID_add error");
 		    return RLI_ERRORE;
 		}
 	    case AVL_ADD:
-
 		{
 		    npatch++;
 		    break;
 		}
 	    case AVL_PRES:
-
 		{
 		    break;
 		}
 	    default:
-
 		{
 		    G_fatal_error("avlID_add unknown error");
 		    return RLI_ERRORE;
@@ -1279,8 +1258,10 @@
     else
 	indice = (double)(-1);
     if (masked)
-	G_free(mask_buf);
+	  G_free(mask_buf);
+/* TODO: fix if? */
     G_free(mask_patch_sup);
+
     *result = indice;
     return RLI_OK;
 }

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/padrange.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/padrange.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/padrange.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -22,9 +22,9 @@
 #include "../r.li.daemon/GenericCell.h"
 #include "../r.li.daemon/daemon.h"
 
-int calculate(int fd, area_des ad, double *result);
-int calculateD(int fd, area_des ad, double *result);
-int calculateF(int fd, area_des ad, double *result);
+int calculate(int fd, struct area_entry *ad, double *result);
+int calculateD(int fd, struct area_entry *ad, double *result);
+int calculateF(int fd, struct area_entry *ad, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -52,7 +52,7 @@
 			  raster->answer, output->answer);
 }
 
-int patchAreaDistributionRANGE(int fd, char **par, area_des ad,
+int patchAreaDistributionRANGE(int fd, char **par, struct area_entry *ad,
 			       double *result)
 {
     char *mapset;
@@ -97,7 +97,7 @@
 }
 
 
-int calculate(int fd, area_des ad, double *result)
+int calculate(int fd, struct area_entry *ad, double *result)
 {
 
     CELL *buf;
@@ -507,7 +507,7 @@
 
 
 
-int calculateD(int fd, area_des ad, double *result)
+int calculateD(int fd, struct area_entry *ad, double *result)
 {
     DCELL *buf;
     DCELL *buf_sup;
@@ -890,7 +890,7 @@
 
 
 
-int calculateF(int fd, area_des ad, double *result)
+int calculateF(int fd, struct area_entry *ad, double *result)
 {
     FCELL *buf;
     FCELL *buf_sup;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/padsd.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/padsd.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/padsd.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -21,9 +21,9 @@
 #include "../r.li.daemon/avlID.h"
 #include "../r.li.daemon/GenericCell.h"
 #include "../r.li.daemon/daemon.h"
-int calculate(int fd, area_des ad, double *result);
-int calculateD(int fd, area_des ad, double *result);
-int calculateF(int fd, area_des ad, double *result);
+int calculate(int fd, struct area_entry *ad, double *result);
+int calculateD(int fd, struct area_entry *ad, double *result);
+int calculateF(int fd, struct area_entry *ad, double *result);
 int main(int argc, char *argv[])
 {
     struct Option *raster, *conf, *output;
@@ -50,7 +50,7 @@
 			  raster->answer, output->answer);
 }
 
-int patchAreaDistributionSD(int fd, char **par, area_des ad, double *result)
+int patchAreaDistributionSD(int fd, char **par, struct area_entry *ad, double *result)
 {
     char *mapset;
     double indice = 0;
@@ -94,7 +94,7 @@
     return RLI_OK;
 }
 
-int calculate(int fd, area_des ad, double *result)
+int calculate(int fd, struct area_entry *ad, double *result)
 {
     CELL *buf;
     CELL *buf_sup;
@@ -493,7 +493,7 @@
 
 
 
-int calculateD(int fd, area_des ad, double *result)
+int calculateD(int fd, struct area_entry *ad, double *result)
 {
     DCELL *buf;
     DCELL *buf_sup;
@@ -885,7 +885,7 @@
     return RLI_OK;
 }
 
-int calculateF(int fd, area_des ad, double *result)
+int calculateF(int fd, struct area_entry *ad, double *result)
 {
     FCELL *buf;
     FCELL *buf_sup;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/main.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/main.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -56,7 +56,7 @@
 }
 
 
-int patch_density(int fd, char **par, area_des ad, double *result)
+int patch_density(int fd, char **par, struct area_entry *ad, double *result)
 {
     CELL *buf, *sup;
     int count = 0, i, j, connected = 0, complete_line = 1, other_above = 0;
@@ -67,21 +67,25 @@
     double EW_DIST1, EW_DIST2, NS_DIST1, NS_DIST2;
     int mask_fd = -1, *mask_buf, *mask_sup, null_count = 0;
 
+    G_debug(1, "begin patch_density() index");
+
     G_set_c_null_value(&complete_value, 1);
     mapset = G_find_cell(ad->raster, "");
     if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
 	return 0;
-    sup = G_allocate_cell_buf();
 
     /* open mask if needed */
     if (ad->mask == 1) {
 	if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0)
 	    return 0;
+
 	mask_buf = malloc(ad->cl * sizeof(int));
 	mask_sup = malloc(ad->cl * sizeof(int));
     }
 
-    /*calculate distance */
+    sup = G_allocate_cell_buf();
+
+    /* calculate distance */
     G_begin_distance_calculations();
     /* EW Dist at North edge */
     EW_DIST1 = G_distance(hd.east, hd.north, hd.west, hd.north);
@@ -93,15 +97,15 @@
     NS_DIST2 = G_distance(hd.west, hd.north, hd.west, hd.south);
 
 
+    /* calculate number of patch */
 
-
-    /*calculate number of patch */
-
     for (i = 0; i < ad->rl; i++) {
 	buf = RLI_get_cell_raster_row(fd, i + ad->y, ad);
+
 	if (i > 0) {
 	    sup = RLI_get_cell_raster_row(fd, i - 1 + ad->y, ad);
 	}
+
 	/* mask values */
 	if (ad->mask == 1) {
 	    int k;
@@ -192,13 +196,14 @@
 
     area = (((EW_DIST1 + EW_DIST2) / 2) / hd.cols) *
 	(((NS_DIST1 + NS_DIST2) / 2) / hd.rows) *
-	(ad->rl * ad->cl - null_count);
+	(ad->rl *ad->cl - null_count);
 
     if (area != 0)
 	*result = (count / area) * 1000000;
     else
 	*result = -1;
 
-    /* G_free(sup);  */
+    G_free(sup);
+
     return RLI_OK;
 }

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/main.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/main.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -56,7 +56,7 @@
 
 }
 
-int patch_number(int fd, char **par, area_des ad, double *result)
+int patch_number(int fd, char **par, struct area_entry *ad, double *result)
 {
     CELL *buf, *sup;
     int count = 0, i, j, connected = 0, complete_line = 1, other_above = 0;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/pielou.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/pielou.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/pielou.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -26,11 +26,11 @@
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
 
-int calculate(int fd, area_des ad, double *result);
+int calculate(int fd, struct area_entry *ad, double *result);
 
-int calculateD(int fd, area_des ad, double *result);
+int calculateD(int fd, struct area_entry *ad, double *result);
 
-int calculateF(int fd, area_des ad, double *result);
+int calculateF(int fd, struct area_entry *ad, double *result);
 
 /*This function is used to sort the values in the moving window */
 static int cmp(const void *pa, const void *pb)
@@ -79,7 +79,7 @@
 
 }
 
-int pielou(int fd, char **par, area_des ad, double *result)
+int pielou(int fd, char **par, struct area_entry *ad, double *result)
 {
 
     char *mapset;
@@ -127,7 +127,7 @@
 }
 
 
-int calculate(int fd, area_des ad, double *result)
+int calculate(int fd, struct area_entry *ad, double *result)
 {
 
     CELL *buf;
@@ -357,7 +357,7 @@
 
 
 
-int calculateD(int fd, area_des ad, double *result)
+int calculateD(int fd, struct area_entry *ad, double *result)
 {
 
     DCELL *buf;
@@ -583,7 +583,7 @@
 }
 
 
-int calculateF(int fd, area_des ad, double *result)
+int calculateF(int fd, struct area_entry *ad, double *result)
 {
 
     FCELL *buf;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.renyi/renyi.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.renyi/renyi.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.renyi/renyi.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -26,11 +26,11 @@
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
 
-double calculate(area_des ad, int fd, char **par, double *result);
+double calculate(struct area_entry *ad, int fd, char **par, double *result);
 
-double calculateD(area_des ad, int fd, char **par, double *result);
+double calculateD(struct area_entry *ad, int fd, char **par, double *result);
 
-double calculateF(area_des ad, int fd, char **par, double *result);
+double calculateF(struct area_entry *ad, int fd, char **par, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -86,7 +86,7 @@
 
 }
 
-int renyi(int fd, char **par, area_des ad, double *result)
+int renyi(int fd, char **par, struct area_entry *ad, double *result)
 {
     char *mapset;
     int ris = RLI_OK;
@@ -132,7 +132,7 @@
 
 
 
-double calculate(area_des ad, int fd, char **par, double *result)
+double calculate(struct area_entry *ad, int fd, char **par, double *result)
 {
     CELL *buf;
     CELL corrCell;
@@ -324,7 +324,7 @@
 }
 
 
-double calculateD(area_des ad, int fd, char **par, double *result)
+double calculateD(struct area_entry *ad, int fd, char **par, double *result)
 {
     DCELL *buf;
     DCELL corrCell;
@@ -519,7 +519,7 @@
 
 
 
-double calculateF(area_des ad, int fd, char **par, double *result)
+double calculateF(struct area_entry *ad, int fd, char **par, double *result)
 {
     FCELL *buf;
     FCELL corrCell;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/richness.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/richness.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/richness.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -22,9 +22,9 @@
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
 
-double calculate(area_des ad, int fd, double *result);
-double calculateD(area_des ad, int fd, double *result);
-double calculateF(area_des ad, int fd, double *result);
+double calculate(struct area_entry *ad, int fd, double *result);
+double calculateD(struct area_entry *ad, int fd, double *result);
+double calculateF(struct area_entry *ad, int fd, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -59,7 +59,7 @@
 
 }
 
-int dominance(int fd, char **par, area_des ad, double *result)
+int dominance(int fd, char **par, struct area_entry *ad, double *result)
 {
     char *mapset;
 
@@ -110,7 +110,7 @@
 
 
 
-double calculate(area_des ad, int fd, double *result)
+double calculate(struct area_entry *ad, int fd, double *result)
 {
     CELL *buf;
     CELL corrCell;
@@ -269,7 +269,7 @@
 }
 
 
-double calculateD(area_des ad, int fd, double *result)
+double calculateD(struct area_entry *ad, int fd, double *result)
 {
     DCELL *buf;
     DCELL corrCell;
@@ -431,7 +431,7 @@
 
 
 
-double calculateF(area_des ad, int fd, double *result)
+double calculateF(struct area_entry *ad, int fd, double *result)
 {
     FCELL *buf;
     FCELL corrCell;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/Makefile
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/Makefile	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/Makefile	2014-02-11 14:09:03 UTC (rev 58999)
@@ -9,7 +9,7 @@
 default: script
 	$(MKDIR) $(TARGET)
 	$(INSTALL) area_query $(TARGET)/area_query
-	$(INSTALL) masked_area_selection $(TARGET)/masked_area_selection
+	$(INSTALL) masked_area_selection.sh $(TARGET)/masked_area_selection.sh
 	$(INSTALL) r.li.setup.main $(TARGET)/r.li.setup.main
 	$(INSTALL) r.li.setup.procedures.tcl $(TARGET)/r.li.setup.procedures.tcl
 	$(INSTALL) r.li.windows.tcl $(TARGET)/r.li.windows.tcl

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/area_query
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/area_query	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/area_query	2014-02-11 14:09:03 UTC (rev 58999)
@@ -4,21 +4,22 @@
 
 
 # Simply ask if the selected area is ok or not and save the
-# answer in the environment variable "env(name)"
+# answer in the filename given by the environment variable "env(name)"
 
     wm title . "Select this area"
     wm minsize . 250 100
-    label .label -text "Is this area ok?"
+
+    label .label -text "\nIs this area ok?"
     pack .label 
     frame .buttons
     pack .buttons
-    set val ""
+    set val "$env(input_vector)_$env(CAT)"
     button .buttons.ok -text "Ok" -command {
 	frame .name
 	pack .name
 	frame .name.e
 	pack .name.e
-	label .name.e.n -text "Insert area name"
+	label .name.e.n -text "Enter area name\n(raster map mask name)"
 	entry .name.e.val -textvariable val -width 20
 	grid .name.e.n .name.e.val
 	frame .name.buttons
@@ -27,7 +28,7 @@
 	    if {$val != ""} then {
 		    exec echo 1 $val > $env(name)
 		    destroy .
-		}
+	    }
 	}
 	pack  .name.buttons.b
     }
@@ -35,4 +36,11 @@
 	exec echo 0 > $env(name)
 	destroy .
     }
-    grid .buttons.ok .buttons.no
+    # what to call it: "stop"? "abort"? "quit"?
+    button .buttons.abort -text "Done" -command {
+	exec echo -1 > $env(name)
+	destroy .
+    }
+
+    grid .buttons.ok .buttons.no .buttons.abort -padx 2 -pady 2
+

Deleted: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection	2014-02-11 14:09:03 UTC (rev 58999)
@@ -1,166 +0,0 @@
-#!/bin/sh
-#%Module 
-#%description: Select a circular or polygonal area
-#%End
-#%option
-#% key: raster
-#% type: string
-#% description: raster map to to analyse
-#% required: yes
-#%end
-#%option
-#% key: vector
-#% type: string
-#% description: vector to overlay
-#% required: no
-#%end
-#%option
-#% key: site
-#% type: string
-#% description: site to overlay
-#% required: no
-#%end
-#%option
-#% key: conf
-#% type: string
-#% description: name of configuration file where insert areas
-#% required: yes
-#%end
-#%option
-#% key: north
-#% type: string
-#% description: nothern edge (use only with f flag)
-#% required: no
-#%end
-#%option
-#% key: south
-#% type: string
-#% description:south edge (use only with f flag)
-#% required: no
-#%end
-#%option
-#% key: east
-#% type: string
-#% description: east edge(use only with f flag)
-#% required: no
-#%end
-#%option
-#% key: west 
-#% type: string
-#% description: west edge(use only with f flag)
-#% required: no
-#%end
-#%flag
-#% key: f
-#% description: sample frame yet selected 
-#%end
-#%flag
-#% key: c
-#% description: take a circular area
-#%end
-
-# Where to find the others scripts
-f_path="$GISBASE/etc/r.li.setup"
-
-# Check if we have grass
-if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
-fi
-
-if [ "$1" != "@ARGS_PARSED@" ] ; then
-  exec g.parser "$0" "$@"
-fi
-
-#### set temporary files
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
-    echo "ERROR: unable to create temporary files" 1>&2
-    exit 1
-fi
-
-
-#### environment variables
-g.gisenv LOCATION_NAME > $TMP.var
-read LOCATION < $TMP.var
-g.gisenv GISDBASE > $TMP.var
-read GISDBASE < $TMP.var
-g.gisenv MAPSET > $TMP.var
-read MAPSET < $TMP.var
-# show the sampling frame
-
-if [ $GIS_FLAG_f -eq 1 ] ; then
-    g.region n=$GIS_OPT_north s=$GIS_OPT_south e=$GIS_OPT_east w=$GIS_OPT_west
-else
-    g.region rast=$GIS_OPT_raster
-fi
-# open x1 monitor
-d.mon stop=x1
-d.mon start=x1
-
-d.rast -o map=$GIS_OPT_raster
-if [ -n "$GIS_OPT_vector" ] ; then
-    d.vect map=$GIS_OPT_vector
-fi
-if [ -n "$GIS_OPT_site" ] ; then 
-    d.vect  map=$GIS_OPT_site
-fi
-#let draw area
-if [ $GIS_FLAG_c -eq 1 ] ; then
-    cp $f_path/circle.txt $$.txt 
-else
-    cp $f_path/polygon.txt  $$.txt 
-fi
- 
-r.digit output="$$" < "$$.txt"
-
-#show the selected area
-d.rast -o map=$$ 
-export name=$$.val
-$GRASS_WISH $f_path/area_query 
-    cat $name | cut -f1 -d ' ' > $name.var
-    read ok < $name.var
-    cat $name | cut -f2 -d' ' > $name.var
-    r_name=""
-    read r_name < $name.var
-    if [ $ok -eq 1 ] ; then
-	r.to.vect input="$$" output="v$$" feature=area
-	g.region vect="v$$"
-	v.to.rast input="v$$" output=$r_name value=1 use=val
-	#write info in configuration file
-	g.region -g| grep "n=" | cut -f2 -d'='> $name.var
-	read north < $name.var
-	g.region -g| grep "s=" | cut -f2 -d'='  > $name.var
-	read south < $name.var
-	g.region -g| grep "e=" | cut -f2 -d'=' > $name.var
-	read east < $name.var
-	g.region -g| grep "w=" | cut -f2 -d'=' > $name.var
-	read west < $name.var
-	echo "SAMPLEAREAMASKED $r_name $north|$south|$east|$west" >>\
-	    $GIS_OPT_conf
-	#remove tmp raster and vector
-	g.remove rast=$$
-	g.remove vect=v$$
-        #rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/cats/"$$" 
-	#rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/cell/"$$" 
-	#rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/cellhd/"$$" 
-	#rm -fR "$GISDBASE"/"$LOCATION"/"$MAPSET"/cell_misc/"$$" 
-	#rm -f  "$GISDBASE"/"$LOCATION"/"$MAPSET"/colr/"$$" 
-	#rm -f "$GISDBASE"/"$LOCATION"/"$MAPSET"/hist/"$$" 
-	#rm -fR "$GISDBASE"/"$LOCATION"/"$MAPSET"/vector/"v$$"
-	echo DROP TABLE "v$$" | db.execute
-	
-	if [ $GIS_FLAG_f -eq 1 ] ; then
-	    g.region n=$GIS_OPT_north s=$GIS_OPT_south e=$GIS_OPT_east w=$GIS_OPT_west
-	else
-	    g.region rast=$GIS_OPT_raster
-	fi
-
-    else
-	echo 0 >> $GIS_OPT_conf
-    fi
-
-d.mon stop=x1
-#clean tmp files
-rm -f $$*
-rm -f $TMP*

Copied: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection.sh (from rev 58981, grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection)
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection.sh	                        (rev 0)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection.sh	2014-02-11 14:09:03 UTC (rev 58999)
@@ -0,0 +1,212 @@
+#!/bin/sh
+#
+# Masked area selection using r.digit
+#
+
+#%Module
+#%description: Select a circular or polygonal area
+#%End
+#%option
+#% key: raster
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Raster map to to analyse
+#% required: yes
+#%end
+#%option
+#% key: vector
+#% type: string
+#% gisprompt: old,vector,vector
+#% key_desc: name
+#% description: Vector map to overlay
+#% required: no
+#%end
+#%option
+#% key: site
+#% type: string
+#% gisprompt: old,vector,vector
+#% key_desc: name
+#% description: Vector points map to overlay
+#% required: no
+#%end
+#%option
+#% key: conf
+#% type: string
+#% gisprompt: new_file,file,output
+#% key_desc: filename
+#% description: Name of configuration file where areas are to be saved
+#% required: yes
+#%end
+#%option
+#% key: north
+#% type: string
+#% description: Northern edge (use only with the 'f' flag)
+#% required: no
+#%end
+#%option
+#% key: south
+#% type: string
+#% description: Southern edge (use only with the 'f' flag)
+#% required: no
+#%end
+#%option
+#% key: east
+#% type: string
+#% description: Eastern edge (use only with the 'f' flag)
+#% required: no
+#%end
+#%option
+#% key: west
+#% type: string
+#% description: Western edge (use only with the 'f' flag)
+#% required: no
+#%end
+#%flag
+#% key: f
+#% description: Sample frame not yet selected, set from module options
+#%end
+#%flag
+#% key: c
+#% description: Take a circular area
+#%end
+
+# Where to find the others scripts
+f_path="$GISBASE/etc/r.li.setup"
+
+# Check if we are in a GRASS session
+if test "$GISBASE" = ""; then
+   echo "You must be in GRASS GIS to run this program." 1>&2
+   exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+   exec g.parser "$0" "$@"
+fi
+
+
+#### environment variables
+GISDBASE=`g.gisenv get=GISDBASE`
+LOCATION=`g.gisenv get=LOCATION_NAME`
+MAPSET=`g.gisenv get=MAPSET`
+: ${GISDBASE?} ${LOCATION?} ${MAPSET?}
+
+
+#### set temporary files
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+    echo "ERROR: unable to create temporary files" 1>&2
+    exit 1
+fi
+
+cleanup()
+{
+   # remove temporary region
+   eval `g.findfile elem=windows file="tmp_rli_selmsk.$$" | grep '^name='`
+   if [ -n "$name" ] ; then
+      g.region region="tmp_rli_selmsk.$$"
+      g.remove region="tmp_rli_selmsk.$$" --quiet
+   fi
+
+   rm -f "$TMP" "$TMP".val
+}
+trap "cleanup" 2 3 15
+
+
+# setup internal region
+#  (WIND_OVERRIDE is already present by the main r.li.setup script)
+g.region save="tmp_rli_selmsk.$$"
+
+# ?show the sampling frame
+if [ "$GIS_FLAG_f" -eq 1 ] ; then
+    g.region n="$GIS_OPT_north" s="$GIS_OPT_south" \
+	     e="$GIS_OPT_east" w="$GIS_OPT_west"
+else
+    g.region rast="$GIS_OPT_raster"
+fi
+
+# find a free Xmonitor
+XMON=x1
+for i in 1 2 3 4 5 6 7 ; do
+   result=`d.mon -L | grep -w "^x$i"`
+   if [ `echo "$result" | grep -c 'not'` -eq 1 ] ; then
+      XMON="x$i"
+      break
+   fi
+done
+
+d.mon start="$XMON" --quiet
+
+d.rast -o map="$GIS_OPT_raster" --quiet
+
+if [ -n "$GIS_OPT_vector" ] ; then
+    d.vect map="$GIS_OPT_vector" type=area fcolor=none width=2
+fi
+if [ -n "$GIS_OPT_site" ] ; then
+    d.vect map="$GIS_OPT_site" color=black fcolor=black size=9 icon=basic/circle
+    d.vect map="$GIS_OPT_site" color=red fcolor=red size=5 icon=basic/circle
+fi
+
+# setup for drawing area
+if [ "$GIS_FLAG_c" -eq 1 ] ; then
+   RDIG_INSTR="$f_path/circle.txt"
+   STYLE="circle"
+else
+   RDIG_INSTR="$f_path/polygon.txt"
+   STYLE="polygon"
+fi
+
+# feed options to r.digit
+r.digit output="tmp_rli_mask.$$" --quiet < "$RDIG_INSTR"
+
+
+# show the selected area
+d.rast -o map="tmp_rli_mask.$$" --quiet
+
+name="$TMP.val"
+export name
+
+# ask if it's ok, save 0,1 to "$name" temp file
+"$GRASS_WISH" "$f_path/area_query"
+
+ok=`cat "$name" | cut -f1 -d ' '`
+r_name=`cat "$name" | cut -f2 -d' '`
+
+
+if [ "$ok" -eq 1 ] ; then
+    mask_name="rli_samp_${STYLE}_${r_name}"
+    # r.mask + 'g.region zoom= align=' + 'r.mapcalc cropmap=map' would be cleaner?
+    r.to.vect input="tmp_rli_mask.$$" output="tmp_rli_mask_v$$" feature=area --quiet
+    g.region vect="tmp_rli_mask_v$$"
+    v.to.rast input="tmp_rli_mask_v$$" output="$mask_name" use=val value=1  --quiet
+
+    # write info in configuration file
+    eval `g.region -g`
+    north="$n"
+    south="$s"
+    east="$e"
+    west="$w"
+
+    echo "SAMPLEAREAMASKED $mask_name $north|$south|$east|$west" >> \
+	    "$GIS_OPT_conf"
+
+    # remove tmp raster and vector
+    g.remove rast="tmp_rli_mask.$$" --quiet
+    g.remove vect="tmp_rli_mask_v$$" --quiet
+
+    if [ "$GIS_FLAG_f" -eq 1 ] ; then
+    	g.region n="$GIS_OPT_north" s="$GIS_OPT_south" \
+    		    e="$GIS_OPT_east" w="$GIS_OPT_west"
+    else
+    	g.region rast="$GIS_OPT_raster"
+    fi
+
+else
+    echo 0 >> "$GIS_OPT_conf"
+fi
+
+
+d.mon stop="$XMON" --quiet
+
+# clean tmp files
+cleanup


Property changes on: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/masked_area_selection.sh
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup	2014-02-11 14:09:03 UTC (rev 58999)
@@ -5,31 +5,53 @@
 # MODULE:       r.li.setup
 #
 # AUTHOR(S):    Spano Lucio Davide & Claudio Porta
-#          
+#               shell scripts rewrite by Hamish Bowman
 #
-# PURPOSE:     Configuration editor for r.li.<index>. It sets sampling frame and 
-#              sample areas to analyze, the configuration is raster map indipendent.
+# PURPOSE:      Configuration editor for r.li.<index>. It sets sampling
+#               frame and sample areas to analyze, the configuration is
+#               raster map indipendent.
 #
-# This program is free software under the GPL (>=v2)
-# Read the COPYING file that comes with GRASS for details.
+#   This program is free software under the GPL (>=v2)
+#   Read the COPYING file that comes with GRASS for details.
 #
 #############################################################################
+
 #%Module
 #%  description: Configuration editor for r.li.'index'
 #%  keywords: raster, landscape structure analysis
 #%End
 
 if  [ -z "$GISBASE" ] ; then
-   echo "You must be in GRASS GIS to run this program."
+   echo "You must be in GRASS GIS to run this program." 1>&2
    exit 1
 fi
 
+
+cleanup()
+{
+   # remove temporary region
+   eval `g.findfile elem=windows file="tmp_rlisetup.$$" | grep '^name='`
+   if [ -n "$name" ] ; then
+      unset WIND_OVERRIDE
+      g.remove region="tmp_rlisetup.$$" --quiet
+   fi
+}
+trap "cleanup" 2 3 15
+
+
 if [ $# -eq 0 ] ; then
-   $GISBASE/etc/r.li.setup/r.li.setup.main
+   # setup internal region
+   g.region save="tmp_rlisetup.$$"
+   WIND_OVERRIDE="tmp_rlisetup.$$"
+   export WIND_OVERRIDE
+
+   "$GISBASE"/etc/r.li.setup/r.li.setup.main
+
+   cleanup
    exit 0
 fi
 
+
 if [ "$1" != "@ARGS_PARSED@" ] ; then
-  exec g.parser "$0" "$@"
+   exec g.parser "$0" "$@"
 fi
-

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup.main
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup.main	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup.main	2014-02-11 14:09:03 UTC (rev 58999)
@@ -89,13 +89,13 @@
 	pack $widget.samplingArea.choice
 	set selection ""
 	radiobutton $widget.samplingArea.choice.whole -text "Whole map layer" -relief flat -variable selection -value whole -width 40 -anchor w 
-	radiobutton $widget.samplingArea.choice.regions -text "Regions" -relief flat -variable selection -value regions -width 40 -anchor w
-	radiobutton $widget.samplingArea.choice.units -text "Sample units" -relief flat -variable selection -value units -width 40 -anchor w
+	radiobutton $widget.samplingArea.choice.regions -text "Regions (digitize polygons with mouse)" -relief flat -variable selection -value regions -width 40 -anchor w
+	radiobutton $widget.samplingArea.choice.units -text "Sample units (digitize box or circular areas\nwith mouse or define using keyboard)" -relief flat -variable selection -value units -width 40 -anchor w
 	radiobutton $widget.samplingArea.choice.window -text "Moving window" -relief flat -variable selection -value window -width 40 -anchor w
 	set vectorAreas [exec cat $env(TMP).set | grep "SAMPLINGFRAME" | tail -n 1 | cut -f2 -d " "]
 	if { $vectorAreas == "0|0|1|1"} then {
-		#inserting select areas from the overlayed vector map
-		radiobutton $widget.samplingArea.choice.vector -text "Select areas from the overlayed vector map" -relief flat -variable selection -value vector -width 40 -anchor w
+		#inserting select areas from the overlaid vector map
+		radiobutton $widget.samplingArea.choice.vector -text "Select areas from the overlaid vector map" -relief flat -variable selection -value vector -width 40 -anchor w
 		pack $widget.samplingArea.choice.whole $widget.samplingArea.choice.regions $widget.samplingArea.choice.units $widget.samplingArea.choice.window $widget.samplingArea.choice.vector
 	} else {
 		pack $widget.samplingArea.choice.whole $widget.samplingArea.choice.regions $widget.samplingArea.choice.units $widget.samplingArea.choice.window
@@ -172,8 +172,8 @@
 	frame .newConf.frame -relief flat
 	pack .newConf.frame -side top -fill y -anchor center
 
-	set names {{} {Configuration file name:} {Raster map to use to select areas:} {[Vector map to overlay:]}\
-	 {[Site file to overlay:]} }
+	set names {{} {Configuration file name:} {Raster map to use to select areas:} {[Vector areas map to overlay:]}\
+	 {[Vector points map to overlay:]} }
 	label .newConf.frame.label1 -text [lindex $names 1] -anchor e
 	entry .newConf.frame.entry1 -width 35 -textvariable env(CONF)
 	grid .newConf.frame.label1 .newConf.frame.entry1 -sticky ew -pady 2 -padx 1
@@ -203,15 +203,15 @@
 	# insert buttons
 	frame .newConf.buttons -relief flat
 	pack .newConf.buttons -side bottom -anchor center -pady 2
-	button .newConf.buttons.save -text "Save settings" -state disabled -command {
+	button .newConf.buttons.save -text "3. Save settings" -state disabled -command {
 		saveSettings .newConf
 		}
-	button .newConf.buttons.s_area -text "Setup sampling areas" -state disabled -command {
+	button .newConf.buttons.s_area -text "2. Setup sampling areas" -state disabled -command {
 		setupSamplingArea .newConf
 		.newConf.buttons.save configure -state active
 		.newConf.buttons.s_area configure -state disabled
 	}
-	button .newConf.buttons.s_frame -text "Setup sampling frame" -command {
+	button .newConf.buttons.s_frame -text "1. Setup sampling frame" -command {
 		setupSamplingFrame .newConf
 		.newConf.buttons.s_frame configure -state disabled
 	} 
@@ -239,7 +239,7 @@
 	frame $widget.newUni.button
 	pack $widget.newUni.button -side left -anchor w 
 	#buttons
-	button $widget.newUni.button.b2 -text " Use keyboard to enter sampling units dimension " -width 50 -command {
+	button $widget.newUni.button.b2 -text " Use keyboard to define sampling units dimension " -width 50 -command {
 		 setKeyboardUnit 
 		 $setSampleUnits.newUni.button.b2 configure -state disabled
 		 $setSampleUnits.newUni.button.b3 configure -state disabled
@@ -273,7 +273,7 @@
 	frame $widget.newWin.button
 	pack $widget.newWin.button -side left -anchor w 
 	#buttons
-	button $widget.newWin.button.b2 -text " Use keyboard to enter moving window dimension " -width 50 -command {
+	button $widget.newWin.button.b2 -text " Use keyboard to define moving window dimension " -width 50 -command {
 		 setKeyboardWindow 
 		 $setMovWindow.newWin.button.b2 configure -state disabled
 		 $setMovWindow.newWin.button.b3 configure -state disabled
@@ -367,8 +367,8 @@
 	wm title .removeconf "\[r.li.setup\] Remove Window"
 	
 	# new top label
-	label .removeconf.topLabel -text "Are You sure to remove the ' $selection ' file ?"
-        pack .removeconf.topLabel -side top
+	label .removeconf.topLabel -text "Are you sure you want to remove\nthe '$selection' configuration file ?"
+        pack .removeconf.topLabel -side top -pady 10 -padx 10
 	
 	# create new frame
 	frame .removeconf.buttons -relief flat
@@ -378,8 +378,7 @@
 	button .removeconf.buttons.y -text "Yes" -width 8 -command { 
 	      if { [ catch { exec rm $env(HOME)/.r.li/history/$selection } ] } then { 
 		tk_messageBox -message "'$selection' Not deleted" -type ok -icon error} else {
-		#annoying "deleted" messageBox
-		#tk_messageBox -message "$selection  deleted" -type ok
+		tk_messageBox -message "'$selection' deleted." -type ok
 		openDir .files "~/.r.li/history"
 		destroy .removeconf}
 	}
@@ -387,7 +386,7 @@
 	# create no button
 	button .removeconf.buttons.n -text "No" -width 8 -command { destroy .removeconf
 	openDir .files "~/.r.li/history"}
-	grid .removeconf.buttons.y  .removeconf.buttons.n
+	grid .removeconf.buttons.y  .removeconf.buttons.n -padx 2 -pady 10
 	}
 }
 

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup.procedures.tcl
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup.procedures.tcl	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.setup.procedures.tcl	2014-02-11 14:09:03 UTC (rev 58999)
@@ -7,8 +7,8 @@
  #update sample frame environment variables
  proc updateSF_Environment { } {
  	global env
- 	exec g.region rast=$env(RASTER) 
-	exec g.region -g > $env(TMP).tmp 
+ 	exec g.region rast=$env(RASTER)
+	exec g.region -g > $env(TMP).tmp
 	set n [ exec cat $env(TMP).tmp | grep "n=" | cut -f2 -d= ]
 	set s [ exec cat $env(TMP).tmp | grep "s=" | head -n 1 | cut -f2 -d= ]
 	set w [ exec cat $env(TMP).tmp | grep "w=" | cut -f2 -d= ]
@@ -26,18 +26,18 @@
 	file delete $env(TMP).tmp
 	#debug line
 	#tk_messageBox -message "$env(SF_N)|$env(SF_S)|$env(SF_W)|$env(SF_E)|$env(SF_NSRES)|$env(SF_EWRES)|"
-	
+
  }
- 
- 
- #shows the instruction for drawing squares 
+
+
+ #shows the instruction for drawing squares
  proc squareInstruction {} {
  	toplevel .instruction
 	wm title .instruction "\[r.li.setup\] Commands"
 	#wm maxsize .instruction 300 200
 	frame .instruction.txt
-	pack .instruction.txt 
-	text .instruction.txt.t -font Helvetica -height 12 
+	pack .instruction.txt
+	text .instruction.txt.t -font Helvetica -height 12
 	.instruction.txt.t tag configure big -font {Helvetica 16 bold}
 	.instruction.txt.t tag configure normal -font {Helvetica 14}
 	.instruction.txt.t insert end "Mouse buttons functions \n \n" big
@@ -55,14 +55,14 @@
 	#.instruction.txt configure -state disabled
 	return .instruction
  }
- 
+
  proc vectorInstruction {} {
  	toplevel .instruction
 	wm title .instruction "\[r.li.setup\] Commands"
 	#wm maxsize .instruction 300 200
 	frame .instruction.txt
-	pack .instruction.txt 
-	text .instruction.txt.t -font Helvetica -height 12 
+	pack .instruction.txt
+	text .instruction.txt.t -font Helvetica -height 12
 	.instruction.txt.t tag configure big -font {Helvetica 16 bold}
 	.instruction.txt.t tag configure normal -font {Helvetica 14}
 	.instruction.txt.t insert end "Mouse buttons functions \n \n" big
@@ -80,14 +80,14 @@
 	#.instruction.txt configure -state disabled
 	return .instruction
  }
- 
+
  proc circleInstruction {} {
  	toplevel .instruction
 	wm title .instruction "\[r.li.setup\] Commands"
 	#wm maxsize .instruction 300 200
 	frame .instruction.txt
-	pack .instruction.txt 
-	text .instruction.txt.t -font Helvetica -height 12 
+	pack .instruction.txt
+	text .instruction.txt.t -font Helvetica -height 12
 	.instruction.txt.t tag configure big -font {Helvetica 16 bold}
 	.instruction.txt.t tag configure normal -font {Helvetica 14}
 	.instruction.txt.t insert end "Mouse buttons functions \n \n" big
@@ -116,15 +116,15 @@
 	pack .fileBrowser.top -side top -fill y -anchor center
 	listbox .fileBrowser.top.listbox -selectmode single
 	openDir .fileBrowser.top.listbox $path
-	pack .fileBrowser.top.listbox -expand 1 -fill both -padx 7 -pady 7 
+	pack .fileBrowser.top.listbox -expand 1 -fill both -padx 7 -pady 7
 	#browser buttons
 	frame .fileBrowser.buttons
 	pack .fileBrowser.buttons -side bottom -pady 2 -anchor center
 	button .fileBrowser.buttons.open -text "Open" -command {set selection [fileSelect .fileBrowser .fileBrowser.top.listbox $p_entry]}
 	pack .fileBrowser.buttons.open
- 
+
  }
- 
+
  proc fileSelect {widget listbox entry} {
  set selection [$listbox get [$listbox curselection]]
 		switch [file type $selection] {
@@ -137,10 +137,10 @@
 		}
 	}
 }
- 
- 
- 
- #Open the specified directory 
+
+
+
+ #Open the specified directory
  proc openDir {listbox newpath} {
     catch {cd $newpath}
     $listbox delete 0 end
@@ -174,12 +174,12 @@
 	} else {
 		set ins [squareInstruction]
 		tkwait window $ins
-		catch { exec $env(F_PATH)/square_mouse_selection.sh raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$tmp.tmp } 
+		catch { exec $env(F_PATH)/square_mouse_selection.sh raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$tmp.tmp >@stdout 2>@stderr }
 		set ok ""
 		catch {set ok [exec cat $tmp.tmp | grep "SQUAREAREA" | cut -f1 -d\ ]}
 		if { $ok == "SQUAREAREA" } then {
 			#sampling frame accepted
-			set start [exec cat $tmp.tmp | grep "START" | cut -f2 -d\ ] 
+			set start [exec cat $tmp.tmp | grep "START" | cut -f2 -d\ ]
 			scan $start %f|%f|%f|%f|%f|%f s_n s_s s_e s_w s_nres s_sres
 			set square [exec cat $tmp.tmp | grep "SQUAREAREA" | cut -f2 -d\ ]
 			#resolution north-south
@@ -191,11 +191,11 @@
 			set env(SF_S) $s
 			set env(SF_E) $e
 			set env(SF_W) $w
-			set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+			set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 			set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\|  ]
 			# calulating area coordinates
-			set env(SF_Y) [expr abs(round(($s_n - $n) / $nres)) ] 
-			set env(SF_X) [expr abs(round(($s_w - $w) / $sres)) ] 
+			set env(SF_Y) [expr abs(round(($s_n - $n) / $nres)) ]
+			set env(SF_X) [expr abs(round(($s_w - $w) / $sres)) ]
 			set env(SF_RL) [expr abs(round(($n - $s) / $nres)) ]
 			set env(SF_CL) [expr abs(round(($e - $w) / $sres)) ]
 			set env(SF_NSRES) $nres
@@ -206,12 +206,12 @@
 			set cl [ expr double($env(SF_CL)) / double($cols) ]
 			#debug line
 			#tk_messageBox -message "$x|$y|$rl|$cl"
-			exec echo "SAMPLINGFRAME $x|$y|$rl|$cl" >> $tmp.set 
+			exec echo "SAMPLINGFRAME $x|$y|$rl|$cl" >> $tmp.set
 			tk_messageBox -message "Selected area set as sampling frame" -type ok
 			file delete $tmp.tmp
 			$button configure -state disabled
 		} else {
-			tk_messageBox -message "Warning sampling frame not set" -type ok -icon warning
+			tk_messageBox -message "Warning: sampling frame not set" -type ok -icon warning
 		}
 	}
 	}
@@ -225,7 +225,7 @@
 set tmp $env(TMP)
 switch $selection {
 	whole {
-		set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+		set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 		set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 		set x [expr double($env(SF_X)) / double($cols) ]
 		set y [expr double($env(SF_Y)) / double($rows) ]
@@ -246,8 +246,8 @@
 	vector {
 		tk_messageBox -message "WARNING: this configuration file will work only on $env(RASTER) raster map" -type ok -icon warning
 		#TODO change here
-		if { $env(RASTER) != "" && $env(VECTOR) != "" && $env(CONF) != "" } then { 
-			catch { exec  $env(F_PATH)/sample_area_vector.sh  raster=$env(RASTER) vector=$env(VECTOR) conf=$env(TMP).set } 
+		if { $env(RASTER) != "" && $env(VECTOR) != "" && $env(CONF) != "" } then {
+			catch { exec  $env(F_PATH)/sample_area_vector.sh  raster=$env(RASTER) vector=$env(VECTOR) sites=$env(SITE) conf=$env(TMP).set >@stdout 2>@stderr }
 		} else {
 			tk_messageBox -message "Please set configuration file name, raster map and vector file to overlay" -type ok -icon error
 		}
@@ -259,84 +259,84 @@
 # defines sampling units distribuition
 proc defineSamplingUnits {selec rl cl maskname} {
 	global env
-	set tmp $env(TMP) 
+	set tmp $env(TMP)
 	#da modificare qua per le proiezioni
 	switch $selec {
-	
+
 		nonoverlapping {
-			toplevel .dialog 
+			toplevel .dialog
 			wm title .dialog " Random Nonoverlapping "
-			wm minsize .dialog 300 150
-		
+			wm minsize .dialog 300 100
+
 			frame .dialog.scale
 			pack .dialog.scale
-			label .dialog.scale.label1 -text " What number of Sampling Units to use?"
+			label .dialog.scale.label1 -text "\n How many Sampling Units to use?"
 			entry .dialog.scale.e1 -width 5 -textvariable number1
-			grid .dialog.scale.label1 .dialog.scale.e1   -padx 3
-			
+			grid .dialog.scale.label1 .dialog.scale.e1  -padx 3
+
 			button .dialog.button -text " Ok " -command {
 				if  { $number1!="" && ![catch { exec printf %i $number1 }]} then {
 					exec echo "RANDOMNONOVERLAPPING $number1" >> $env(TMP).set
-					tk_messageBox -message "Sampling units distribuition set as Random Nonoverlapping" -type ok
+					tk_messageBox -message "Sampling units distribuition set to Random Nonoverlapping" -type ok
 					set number1 ""
 					destroy .dialog
 				} else {
 					tk_messageBox -message "Please type integer value" -type ok -icon error
-				} 
+				}
 			}
-			pack .dialog.button
+			pack .dialog.button -pady 3
 		}
-		
-		contiguous { 
+
+		contiguous {
 			exec echo "SYSTEMATICCONTIGUOUS " >> $env(TMP).set
-			tk_messageBox -message "Sampling units distribuition set as Systematic Contiguous" -type ok
+			tk_messageBox -message "Sampling units distribuition set to Systematic Contiguous" -type ok
 		}
-		
-		noncontiguous { 
-			toplevel .dialog 
+
+		noncontiguous {
+			toplevel .dialog
 			wm title .dialog " Systematic non contiguous "
 			wm minsize .dialog 300 150
-		
+
 			frame .dialog.scale
 			pack .dialog.scale
 			label .dialog.scale.label1 -text " Insert distance between units"
 			entry .dialog.scale.e1 -width 5 -textvariable number1
 			grid .dialog.scale.label1 .dialog.scale.e1   -padx 3
-		
+
 	       		button .dialog.button -text " Ok " -command {
 			if  { $number1!="" && ![catch { exec printf %i $number1 }]} then {
 				exec echo "SYSTEMATICNONCONTIGUOUS $number1" >> $env(TMP).set
-				tk_messageBox -message "Sampling units distribuition set as Systematic Non Contiguous" -type ok
+				tk_messageBox -message "Sampling units distribuition set to Systematic Non Contiguous" -type ok
 				set number1 ""
 				destroy .dialog
 			} else {
 				tk_messageBox -message "Please type integer value" -type ok -icon error
 			}
 		}
-		pack .dialog.button	
+		pack .dialog.button
 		}
-		
-		random { 
-			toplevel .dialog 
+
+		random {
+			toplevel .dialog
 			wm title .dialog " Stratified Random "
 			wm minsize .dialog 300 150
-		
+
 			frame .dialog.scale
 			pack .dialog.scale
 			label .dialog.scale.label1 -text " Insert number of row strates "
 			entry .dialog.scale.e1 -width 5 -textvariable number1
 			grid .dialog.scale.label1 .dialog.scale.e1   -padx 3
-			
+
 			frame .dialog.scale2
 			pack .dialog.scale2
 			label .dialog.scale2.label2 -text " Insert number of column strates "
 			entry .dialog.scale2.e2 -width 5 -textvariable number2
 			grid .dialog.scale2.label2 .dialog.scale2.e2   -padx 3
-		
+
 	       		button .dialog.button -text " Ok " -command {
 			if  { $number1!="" && $number2!="" && ![catch { exec printf %i%i $number1 $number2 }]} then {
 				exec echo "STRATIFIEDRANDOM $number1|$number2" >> $env(TMP).set
-				tk_messageBox -message "Sampling units distribuition set as Stratified random" -type ok
+				tk_messageBox -message "Sampling units distribuition set to Stratified random" -type ok
 				set number1 ""
 				destroy .dialog
 			} else {
@@ -345,8 +345,8 @@
 		}
 		pack .dialog.button
 		}
-		
-		sites { 
+
+		sites {
 			if { $env(RASTER) == "" || $env(SITE) == "" } then {
 				tk_messageBox -message "Please set raster and site file names first" -icon error
 			} else {
@@ -367,7 +367,7 @@
 			#check if we have integers
 			tk_messageBox -message "Type integer values" -type ok -icon error
 			} else {
-				set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+				set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 				set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 				set rl [expr double($number2) / double($rows) ]
 				set cl [expr double($number1) /double($cols) ]
@@ -380,14 +380,14 @@
 			tk_messageBox -message "Set all entries first" -type ok -icon error
 			}
 		}
-		circle { 
+		circle {
 			if  { $number3 != "" } then {
 				if { [catch { exec printf %i $number3 }]  } then {
 				#check if we have integers
 				tk_messageBox -message "Type integer values" -type ok -icon error
 			} else {
 				circleMask $number3 $maskname
-				set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+				set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 				set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\|  ]
 				set rl [expr double($env(CIR_RL)) /double($rows)]
 				set cl [expr double($env(CIR_CL)) /double($cols)]
@@ -413,19 +413,19 @@
 		set ins [vectorInstruction]
 		tkwait window $ins
 		while { $i < $number } {
-		 	catch { exec $env(F_PATH)/masked_area_selection -f north=$env(SF_N) south=$env(SF_S) west=$env(SF_W) east=$env(SF_E) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp }
+		 	catch { exec $env(F_PATH)/masked_area_selection.sh -f north=$env(SF_N) south=$env(SF_S) west=$env(SF_W) east=$env(SF_E) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp >@stdout 2>@stderr }
 			set ok ""
 			catch {set ok [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f1 -d\ ]}
 			if { $ok == "SAMPLEAREAMASKED" } then {
-				#region accepted 
+				#region accepted
 				incr i
 				set r_name [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f2 -d\ ]
 				set square [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f3 -d\ ]
 				scan $square %f|%f|%f|%f n s e w
-				set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+				set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 				set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\|  ]
-				set abs_y [expr $env(SF_Y) + abs(round(($env(SF_N) - $n) / $env(SF_NSRES))) ] 
-				set abs_x [expr $env(SF_X)+ abs(round(($env(SF_W) - $w) / $env(SF_EWRES))) ] 
+				set abs_y [expr $env(SF_Y) + abs(round(($env(SF_N) - $n) / $env(SF_NSRES))) ]
+				set abs_x [expr $env(SF_X)+ abs(round(($env(SF_W) - $w) / $env(SF_EWRES))) ]
 				set abs_rl [expr abs(round(($n - $s) / $env(SF_NSRES))) ]
 				set abs_cl [expr abs(round(($e - $w) / $env(SF_EWRES))) ]
 				#debug line
@@ -436,16 +436,16 @@
 				set cl [ expr double($abs_cl) / double($cols) ]
 				#debug line
 				#tk_messageBox -message "$x|$y|$rl|$cl"
-				exec echo "MASKEDSAMPLEAREA $x|$y|$rl|$cl|$r_name" >> $env(TMP).set 
+				exec echo "MASKEDSAMPLEAREA $x|$y|$rl|$cl|$r_name" >> $env(TMP).set
 				tk_messageBox -message "Selected region saved as sampling area" -type ok
 				file delete $env(TMP).tmp
 			} else {
 				tk_messageBox -message "Please redraw region number $i" -type ok -icon warning
 			}
 		}
-		  
-		 
-		
+
+
+
 	}
 }
 
@@ -463,13 +463,13 @@
 				tk_messageBox -message "Please enter a raster map and a configuration file name first" -type ok -icon error
 			} else {
 				while { $i < $num } {
-					catch { exec $env(F_PATH)/square_mouse_selection.sh -f north=$env(SF_N) south=$env(SF_S) east=$env(SF_E) west=$env(SF_W) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp } 
+					catch { exec $env(F_PATH)/square_mouse_selection.sh -f north=$env(SF_N) south=$env(SF_S) east=$env(SF_E) west=$env(SF_W) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp >@stdout 2>@stderr }
 					set ok ""
 					catch {set ok [exec cat $env(TMP).tmp | grep "SQUAREAREA" | cut -f1 -d\ ]}
 					if { $ok == "SQUAREAREA" } then {
 						#sampling area accepted
 						incr i
-						set start [exec cat $env(TMP).tmp | grep "START" | cut -f2 -d\ ] 
+						set start [exec cat $env(TMP).tmp | grep "START" | cut -f2 -d\ ]
 						scan $start %f|%f|%f|%f|%f|%f s_n s_s s_e s_w s_nres s_sres
 						set square [exec cat $env(TMP).tmp | grep "SQUAREAREA" | cut -f2 -d\ ]
 						#resolution north-south
@@ -477,11 +477,11 @@
 						#resolution east-west
 						set sres ""
 						scan $square %f|%f|%f|%f|%f|%f n s e w nres sres
-						set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+						set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 						set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\|  ]
 						# calulating area coordinates
-						set abs_y [expr abs(round(($s_n - $n) / $nres)) ] 
-						set abs_x [expr abs(round(($s_w - $w) / $sres)) ] 
+						set abs_y [expr abs(round(($s_n - $n) / $nres)) ]
+						set abs_x [expr abs(round(($s_w - $w) / $sres)) ]
 						set abs_rl [expr abs(round(($n - $s) / $nres)) ]
 						set abs_cl [expr abs(round(($e - $w) / $sres)) ]
 						#debug line
@@ -492,12 +492,12 @@
 						set cl [ expr double($abs_cl) / double($cols) ]
 						#debug line
 						#tk_messageBox -message "$x|$y|$rl|$cl"
-						exec echo "SAMPLEAREA $x|$y|$rl|$cl" >> $env(TMP).set 
+						exec echo "SAMPLEAREA $x|$y|$rl|$cl" >> $env(TMP).set
 						tk_messageBox -message "Selected area saved as sample area" -type ok
 						file delete $env(TMP).tmp
 					} else {
-						tk_messageBox -message "Warning sampling area not set" -type ok -icon warning
-					}	
+						tk_messageBox -message "Warning: sampling area not set" -type ok -icon warning
+					}
 				}
 			}
 		}
@@ -507,19 +507,19 @@
 			set ins [circleInstruction]
 			tkwait window $ins
 			while { $i < $num } {
-		 		catch { exec $env(F_PATH)/masked_area_selection -f -c north=$env(SF_N) south=$env(SF_S) west=$env(SF_W) east=$env(SF_E) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp }
+		 		catch { exec $env(F_PATH)/masked_area_selection.sh -f -c north=$env(SF_N) south=$env(SF_S) west=$env(SF_W) east=$env(SF_E) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp >@stdout 2>@stderr }
 				set ok ""
 				catch {set ok [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f1 -d\ ]}
 				if { $ok == "SAMPLEAREAMASKED" } then {
-					#region accepted 
+					#region accepted
 					incr i
 					set r_name [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f2 -d\ ]
 					set square [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f3 -d\ ]
 					scan $square %f|%f|%f|%f n s e w
-					set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+					set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 					set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\|  ]
-					set abs_y [expr $env(SF_Y) + abs(round(($env(SF_N) - $n) / $env(SF_NSRES))) ] 
-					set abs_x [expr $env(SF_X)+ abs(round(($env(SF_W) - $w) / $env(SF_EWRES))) ] 
+					set abs_y [expr $env(SF_Y) + abs(round(($env(SF_N) - $n) / $env(SF_NSRES))) ]
+					set abs_x [expr $env(SF_X)+ abs(round(($env(SF_W) - $w) / $env(SF_EWRES))) ]
 					set abs_rl [expr abs(round(($n - $s) / $env(SF_NSRES))) ]
 					set abs_cl [expr abs(round(($e - $w) / $env(SF_EWRES))) ]
 					#debug line
@@ -530,7 +530,7 @@
 					set cl [ expr double($abs_cl) / double($cols) ]
 					#debug line
 					#tk_messageBox -message "$x|$y|$rl|$cl"
-					exec echo "MASKEDSAMPLEAREA $x|$y|$rl|$cl|$r_name" >> $env(TMP).set 
+					exec echo "MASKEDSAMPLEAREA $x|$y|$rl|$cl|$r_name" >> $env(TMP).set
 					tk_messageBox -message "Selection saved as sampling area" -type ok
 					file delete $env(TMP).tmp
 				} else {
@@ -539,12 +539,12 @@
 			}
 		}
 	}
-	
+
 }
 
 #draw moving window with mouse
 proc drawMouseWindow { sel } {
-	global env 
+	global env
 	#rectangular or circular window
 	switch $sel {
 		rectangle {
@@ -555,13 +555,13 @@
 				tk_messageBox -message "Please enter a raster map and a configuration file name first" -type ok -icon error
 			} else {
 				while { $i == 0 } {
-					catch { exec $env(F_PATH)/square_mouse_selection.sh -f north=$env(SF_N) south=$env(SF_S) east=$env(SF_E) west=$env(SF_W) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp } 
+					catch { exec $env(F_PATH)/square_mouse_selection.sh -f north=$env(SF_N) south=$env(SF_S) east=$env(SF_E) west=$env(SF_W) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp >@stdout 2>@stderr }
 					set ok ""
 					catch {set ok [exec cat $env(TMP).tmp | grep "SQUAREAREA" | cut -f1 -d\ ]}
 					if { $ok == "SQUAREAREA" } then {
 						#moving window accepted
 						incr i
-						set start [exec cat $env(TMP).tmp | grep "START" | cut -f2 -d\ ] 
+						set start [exec cat $env(TMP).tmp | grep "START" | cut -f2 -d\ ]
 						scan $start %f|%f|%f|%f|%f|%f s_n s_s s_e s_w s_nres s_sres
 						set square [exec cat $env(TMP).tmp | grep "SQUAREAREA" | cut -f2 -d\ ]
 						#resolution north-south
@@ -569,7 +569,7 @@
 						#resolution east-west
 						set sres ""
 						scan $square %f|%f|%f|%f|%f|%f n s e w nres sres
-						set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+						set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 						set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\|  ]
 						#calculating moving window width and length
 						set abs_rl [expr abs(round(($n - $s) / $nres)) ]
@@ -581,14 +581,14 @@
 						#debug line
 						#tk_messageBox -message "$x|$y|$rl|$cl"
 						exec echo "MOVINGWINDOW" >> $env(TMP).set
-						exec echo "SAMPLEAREA -1|-1|$rl|$cl" >> $env(TMP).set 
+						exec echo "SAMPLEAREA -1|-1|$rl|$cl" >> $env(TMP).set
 						tk_messageBox -message "Moving window set" -type ok
 						file delete $env(TMP).tmp
 					} else {
 						tk_messageBox -message "Moving window not set" -type ok -icon warning
-					}	
+					}
 				}
-			}	
+			}
 		}
 		circle {
 			#circulars areas
@@ -596,16 +596,16 @@
 			set ins [circleInstruction]
 			tkwait window $ins
 			while { $i == 0 } {
-		 		catch { exec $env(F_PATH)/masked_area_selection -f -c north=$env(SF_N) south=$env(SF_S) west=$env(SF_W) east=$env(SF_E) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp }
+		 		catch { exec $env(F_PATH)/masked_area_selection.sh -f -c north=$env(SF_N) south=$env(SF_S) west=$env(SF_W) east=$env(SF_E) raster=$env(RASTER) vector=$env(VECTOR) site=$env(SITE) conf=$env(TMP).tmp >@stdout 2>@stderr }
 				set ok ""
 				catch {set ok [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f1 -d\ ]}
 				if { $ok == "SAMPLEAREAMASKED" } then {
-					#region accepted 
+					#region accepted
 					incr i
 					set r_name [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f2 -d\ ]
 					set square [exec cat $env(TMP).tmp | grep "SAMPLEAREAMASKED" | cut -f3 -d\ ]
 					scan $square %f|%f|%f|%f n s e w
-					set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+					set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 					set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\|  ]
 					set abs_rl [expr abs(round(($n - $s) / $env(SF_NSRES))) ]
 					set abs_cl [expr abs(round(($e - $w) / $env(SF_EWRES))) ]
@@ -616,20 +616,20 @@
 					#debug line
 					#tk_messageBox -message "$x|$y|$rl|$cl"
 					exec echo "MOVINGWINDOW" >> $env(TMP).set
-					exec echo "MASKEDSAMPLEAREA -1|-1|$rl|$cl|$r_name" >> $env(TMP).set 
+					exec echo "MASKEDSAMPLEAREA -1|-1|$rl|$cl|$r_name" >> $env(TMP).set
 					tk_messageBox -message "Moving window set" -type ok
 					file delete $env(TMP).tmp
 				} else {
 					tk_messageBox -message "Moving window not set" -type ok -icon warning
 				}
 			}
-		}	
+		}
 	}
 }
 
 #create a circle mask for the keyboard circle selection
 proc circleMask { radius name} {
-	global env 
+	global env
 	exec g.region rast=$env(RASTER)
 	exec g.region -m > $env(TMP).tmp
 	set nsres [ exec cat $env(TMP).tmp | grep "nsres=" | cut -f2 -d= ]
@@ -638,7 +638,7 @@
 	set xcell [expr round((2 * $radius) / $ewres) ]
 	set ycell [expr round((2 * $radius) / $nsres) ]
 	#to create a good raster circle the center of the circle have to be
-	#in the center of a cell, then we need an odd number of cells... 
+	#in the center of a cell, then we need an odd number of cells...
 	if { [ expr $xcell % 2 ] == 0 } then {
 		incr xcell
 	}
@@ -653,33 +653,33 @@
 	set southEdge [expr double($env(SF_N) - ($ycell * $env(SF_NSRES)))]
 	#restrict region
 	exec g.region n=$env(SF_N) s=$southEdge e=$easthEdge w=$env(SF_W)
-	set xcenter [exec g.region -c | grep "region center easting:" | cut -f2 -d: | tr -d " "]
-	set ycenter [exec g.region -c | grep "region center northing:" | cut -f2 -d: | tr -d " "]
+	set xcenter [exec g.region -c | grep "center easting:" | cut -f2 -d: | tr -d " "]
+	set ycenter [exec g.region -c | grep "center northing:" | cut -f2 -d: | tr -d " "]
 	#debug line
 	#tk_messageBox -message "$xcenter , $ycenter $env(SF_N) $southEdge $env(SF_W) $easthEdge"
 	#creating circle
 	catch {exec r.circle -b output=$name coordinate=$xcenter,$ycenter max=$radius }
 	file delete $env(TMP).tmp
-} 
+}
 
-#set sample units from a site file 
+#set sample units from a site file
 
 proc centerOverSites { rl cl name} {
-	global env 
+	global env
 	if { $env(SITE) == "" || $env(RASTER) == "" } then {
 		tk_messageBox -message "Please set raster and site file name first" -type ok -icon error
 	} else {
 		#raster boundaries
-		exec g.region rast=$env(RASTER) 
-		exec g.region -g > $env(TMP).tmp 
-		set rows [exec  r.info map=$env(RASTER) | grep "Rows" | tr -d " " |   cut -f 2 -d: | cut -f 1 -d\| ]
+		exec g.region rast=$env(RASTER)
+		exec g.region -g > $env(TMP).tmp
+		set rows [exec r.info map=$env(RASTER) | grep "Rows" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
 		set cols [exec r.info map=$env(RASTER) | grep "Columns" | tr -d " " | cut -f 2 -d: | cut -f 1 -d\| ]
-		#create ascii site file 
+		#create ascii site file
 		exec v.out.ascii input=$env(SITE) output=$env(TMP).asc format=point
-		#counting points 
+		#counting points
 		set num [exec cat $env(TMP).asc | grep -c "" ]
 		set i 0
-		
+
 		# inserting point if they are into sample frame
 		while { $i < $num } {
 			incr i
@@ -696,7 +696,7 @@
 			}
 			if { $ok == "TRUE" } then {
 				#the point is into sample frame
-				#calculating what cell contains this point 
+				#calculating what cell contains this point
 				set p_c [expr int( abs($x - $env(SF_W)) / $env(SF_EWRES))]
 				set p_r [expr int( abs($y - $env(SF_N)) / $env(SF_NSRES))]
 				#debug line
@@ -704,7 +704,7 @@
 				#the point is the center of the rectangle, we have to see if the rectangle is into sample frame
 				set rl_delta [expr int( $rl/2)]
 				set cl_delta [expr int( $cl/2)]
-				set n_diff [expr ($p_r - $rl_delta) - $env(SF_Y)] 
+				set n_diff [expr ($p_r - $rl_delta) - $env(SF_Y)]
 				set s_diff [expr ($env(SF_Y) + $env(SF_RL)) - ($p_r + $rl_delta +1) ]
 				set e_diff [expr ($env(SF_X) + $env(SF_CL)) - ($p_c + $cl_delta + 1) ]
 				set w_diff [expr ($p_c - $cl_delta) - $env(SF_X)]
@@ -723,33 +723,33 @@
 					}
 				}
 			}
-				
+
 		}
-	file delete $env(TMP).tmp $env(TMP).line $env(TMP).asc 
-	
-	} 
+	file delete $env(TMP).tmp $env(TMP).line $env(TMP).asc
+
+	}
 }
 
 proc saveSettings { widget } {
 	global env
-	
+
 	#write the sample frame
-	exec cat $env(TMP).set | grep "SAMPLINGFRAME " | tail -n 1 > $env(CONF) 
+	exec cat $env(TMP).set | grep "SAMPLINGFRAME " | tail -n 1 > $env(CONF)
 	#write sampling areas
-	catch  { exec cat $env(TMP).set | grep "SAMPLEAREA " >> $env(CONF) } 
+	catch  { exec cat $env(TMP).set | grep "SAMPLEAREA " >> $env(CONF) }
 	catch { exec cat $env(TMP).set | grep "MASKEDSAMPLEAREA " >> $env(CONF) }
 	set overlay 0
 	catch { set overlay [ exec cat $env(TMP).set | grep "MASKEDOVERLAYAREA " -c ] }
 	if { $overlay != 0 } then {
-		exec cat $env(TMP).set | grep "MASKEDOVERLAYAREA " >> $env(CONF) 
+		exec cat $env(TMP).set | grep "MASKEDOVERLAYAREA " >> $env(CONF)
 		exec echo "RASTERMAP $env(RASTER)" >> $env(CONF)
 		exec echo "VECTORMAP $env(VECTOR)" >> $env(CONF)
 	}
 	#write disposition line
-	catch { exec cat $env(TMP).set | grep "MOVINGWINDOW" >> $env(CONF) } 
-	catch { exec cat $env(TMP).set | grep "RANDOMNONOVERLAPPING " >> $env(CONF) } 
+	catch { exec cat $env(TMP).set | grep "MOVINGWINDOW" >> $env(CONF) }
+	catch { exec cat $env(TMP).set | grep "RANDOMNONOVERLAPPING " >> $env(CONF) }
 	catch { exec cat $env(TMP).set | grep "SYSTEMATICCONTIGUOUS " >> $env(CONF) }
-	catch { exec cat $env(TMP).set | grep "SYSTEMATICNONCONTIGUOUS " >> $env(CONF) } 
+	catch { exec cat $env(TMP).set | grep "SYSTEMATICNONCONTIGUOUS " >> $env(CONF) }
 	catch { exec cat $env(TMP).set | grep "STRATIFIEDRANDOM " >> $env(CONF)  }
 	file delete $env(TMP).set
 	destroy $widget

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.windows.tcl
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.windows.tcl	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/r.li.windows.tcl	2014-02-11 14:09:03 UTC (rev 58999)
@@ -153,7 +153,7 @@
 	label .kUni.scale.label4 -text " What radius size (in meters) for each sampling unit?" -state disabled
 	entry .kUni.scale.e4 -width 5 -textvariable number4 -state disabled
 	grid .kUni.scale.label4 .kUni.scale.e4 -pady 20 -padx 3
-	label .kUni.scale.label5 -text " Name for the circle mask" -state disabled
+	label .kUni.scale.label5 -text " Name for the circle mask raster map" -state disabled
 	entry .kUni.scale.e5 -width 15 -textvariable maskname -state disabled 
 	grid .kUni.scale.label5 .kUni.scale.e5  -padx 3
 	
@@ -196,6 +196,7 @@
 				#check if we have integers
 				tk_messageBox -message "Type integer values or set raster map name" -type ok -icon error
 			} else {
+				set maskname "rli_circlemask_$maskname"
 				circleMask $number4 $maskname
 				defineSamplingUnits $selec $env(CIR_RL) $env(CIR_RL) $maskname
 				if { $selec != "sites" } then {
@@ -393,7 +394,7 @@
 		label .load.info.l1 -text "The sampling areas are defined only for $rname file"
 		pack .load.info.l1
 		set vname [exec cat $filename | grep "VECTORMAP " | cut -f2 -d\ ]
-		label .load.info.l2 -text "The overlayed vector file is $vname"
+		label .load.info.l2 -text "The overlaid vector file is $vname"
 		pack .load.info.l2
 	} else {
 		#extract sample areas

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/sample_area_vector.sh
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/sample_area_vector.sh	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/sample_area_vector.sh	2014-02-11 14:09:03 UTC (rev 58999)
@@ -1,132 +1,201 @@
-#!/bin/bash
+#!/bin/sh
 #
 # This program is free software under the GPL (>=v2)
 # Read the COPYING file that comes with GRASS for details.
+#
 
-#%Module 
-#% description: Create sample area from a vector map 
+#%Module
+#% description: Create sample area from a vector map
 #%End
 #%option
 #% key: raster
 #% type: string
-#% description: raster map to to analyse
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Raster map to to analyse
 #% required: yes
 #%end
 #%option
 #% key: vector
 #% type: string
-#% description: vector map where areas are defined
+#% gisprompt: old,vector,vector
+#% key_desc: name
+#% description: Vector map containing areas
 #% required: yes
 #%end
 #%option
+#% key: sites
+#% type: string
+#% description: Vector points map to overlay
+#% required: no
+#%end
+#%option
 #% key: conf
 #% type: string
-#% description: name of configuration file where insert areas
+#% key_desc: name
+#% gisprompt: new_file,file,output
+#% description: Name of configuration file where areas are to be saved
 #% required: yes
 #%end
 
 
-# Check if we have grass
-if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
- fi
+# Check if we are in a GRASS session
+if [ -z "$GISBASE" ] ; then
+   echo "You must be in GRASS GIS to run this program." 1>&2
+   exit 1
+fi
+
 if [ "$1" != "@ARGS_PARSED@" ] ; then
-  exec g.parser "$0" "$@"
+   exec g.parser "$0" "$@"
 fi
+
+
+#### environment variables
+GISDBASE=`g.gisenv get=GISDBASE`
+LOCATION=`g.gisenv get=LOCATION_NAME`
+MAPSET=`g.gisenv get=MAPSET`
+: ${GISDBASE?} ${LOCATION?} ${MAPSET?}
+
+
 #### set temporary files
 TMP="`g.tempfile pid=$$`"
 if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
-    echo "ERROR: unable to create temporary files" 1>&2
-    exit 1
+   echo "ERROR: unable to create temporary files" 1>&2
+   exit 1
 fi
-#### environment variables
-g.gisenv LOCATION_NAME > $TMP.var
-read LOCATION < $TMP.var
-g.gisenv GISDBASE > $TMP.var
-read GISDBASE < $TMP.var
-g.gisenv MAPSET > $TMP.var
-read MAPSET < $TMP.var
 
+
+cleanup()
+{
+   # remove temporary region
+   eval `g.findfile elem=windows file="tmp_rli_sampvect.$$" | grep '^name='`
+   if [ -n "$name" ] ; then
+      g.region region="tmp_rli_sampvect.$$"
+      g.remove region="tmp_rli_sampvect.$$" --quiet
+   fi
+
+   rm -f "$TMP"*
+}
+trap "cleanup" 2 3 15
+
+
+# setup internal region
+#  (WIND_OVERRIDE is already present by the main r.li.setup script)
+g.region save="tmp_rli_sampvect.$$"
+
+
+# find a free Xmonitor
+XMON=x1
+for i in 1 2 3 4 5 6 7 ; do
+   result=`d.mon -L | grep -w "^x$i"`
+   if [ `echo "$result" | grep -c 'not'` -eq 1 ] ; then
+      XMON="x$i"
+      break
+   fi
+done
+
+#d.mon stop="$XMON" --quiet
+d.mon start="$XMON" --quiet
+
+# TODO: pause to offer a "resize xmon now" window since it will
+#  be locked during the interactive selection.
+
 f_path="$GISBASE/etc/r.li.setup"
 
 ##############################################################
-#read categories from input vector, extract,
-#convert to raster and save the bounds to configuration file
+# read categories from input vector, extract,
+# convert to raster and save the bounds to configuration file
 ##############################################################
 
-#using v.category instead of v.build with cdump
-v.category input=$GIS_OPT_vector option=print | sort | uniq > $TMP.cat
+# using v.category instead of v.build with cdump because v.build
+#  needs fully qualified map name and is harder to parse.
 
-#get input vector name
-GIS_OPT_input_vector=`echo $GIS_OPT_vector| cut -d'@' -f 1`
+v.category input="$GIS_OPT_vector" type=centroid option=print | \
+  sort -n | uniq > "$TMP.cat"
 
-#get input vector mapset
-GIS_OPT_input_mapset=`echo $GIS_OPT_vector| cut -d'@' -f 2`
+NUM_CATS=`wc -l < "$TMP.cat"`
 
-#read input vector categories into CAT_LIST array
-IFS=$'\r\n' CAT_LIST=($(cat $TMP.cat))
+if [ "$NUM_CATS" -gt 30 ] ; then
+    g.message -w "<$GIS_OPT_vector> contains $NUM_CATS areas. Manual selection may be time consuming."
+    # TODO: d.menu [Continue][Abort] on screen display
+elif [ "$NUM_CATS" -eq 0 ] ; then
+    g.message -w "<$GIS_OPT_vector> doesn't contain any areas. Aborting selection."
+    # TODO: d.menu [Ok] on screen display
+fi
 
-TMP_REGION="reg`g.tempfile pid=$$`"
-#save the current region settings temporarily to avoid surpirses later.
-g.region save=$TMP_REGION
+# crop away @mapset part, if present
+input_vector=`echo "$GIS_OPT_vector" | cut -d'@' -f 1`
 
-#process each feature in the vector having category values in the CAT_LIST array
-for CAT in "${CAT_LIST[@]}" 
-do
-    #vector to store a feature fro $GIS_OPT_vector with category value $CAT.
-    #This temporary vector will be removed at the end. 
-    EXTRACT=$GIS_OPT_input_vector"_"$CAT"_part@"$GIS_OPT_input_mapset
-    
-    #extract only a part of $GIS_OPT_vector where category = $CAT and store in $EXTRACT
-    v.extract input=$GIS_OPT_vector output=$EXTRACT type=point,line,boundary,centroid,area,face new=-1 -d where='CAT='$CAT
-    
-    #TODO: anyway to check if x1 is in use?
-    #opening monitor x1
-    d.mon stop=x1
-    d.mon start=x1
-    #setting region with raster resolution
-    g.region vect=$EXTRACT align=$GIS_OPT_raster
-    d.rast -o $GIS_OPT_raster    
-    #render extracted vector map
-    d.vect $EXTRACT
-    #ask the user if he wants to analyse this vector and a name for raster
-    #in graphical mode using wish
-    export name=$TMP.val # where find the answer
-    $GRASS_WISH $f_path/area_query 
-    cat $name | cut -f1 -d ' ' > $name.var
-    read ok < $name.var
-    cat $name | cut -f2 -d' ' > $name.var
-    r_name=""
-    read r_name < $name.var
-    echo $r_name
 
-    if [ $ok -eq 1 ] ; then
+# process each feature in the vector that has a cat
+i=0
+while read CAT ; do
+   # skip blank lines.. (shouldn't be any)
+    if [ -z "$CAT" ] ; then
+       continue
+    fi
+
+    i=`expr $i + 1`
+
+    # Temporary vector map to store an individual feature from the input vector
+    #  It will be removed at the end of the iteration.
+    EXTRACT="tmp_$$_${input_vector}_${CAT}"
+
+    v.extract input="$GIS_OPT_vector" output="$EXTRACT" \
+       type=area new=-1 -d list="$CAT" --quiet
+
+    # set region with raster resolution
+    g.region vect="$EXTRACT" align="$GIS_OPT_raster"
+
+    d.erase
+    d.rast -o "$GIS_OPT_raster" --quiet
+
+    # render extracted vector map  (prehaps fcolor=none for areas?)
+    d.vect "$EXTRACT" type=boundary width=2
+
+    if [ -n "$GIS_OPT_SITES" ] ; then
+	d.vect map="$GIS_OPT_SITES" color=black fcolor=black size=9 icon=basic/circle
+	d.vect map="$GIS_OPT_SITES" color=red fcolor=red size=5 icon=basic/circle
+    fi
+
+    echo " Area $i of $NUM_CATS (category $CAT)" | \
+       d.text color=black size=2.5
+
+    # ask the user to analyse this vector and a name for raster in a Tcl GUI
+    name="$TMP.val" # where find the answer
+    export name input_vector CAT
+
+    # ask if it's ok, save 0,1 to "$name" temp file
+    "$GRASS_WISH" "$f_path/area_query"
+
+    ok=`cat "$name" | cut -f1 -d ' '`
+    r_name=`cat "$name" | cut -f2 -d' '`
+
+    # debug or needed?
+    g.message -d message="area_query map name (exit code 1) or exit code: $r_name"
+
+    if [ "$ok" -eq 1 ] ; then
 	#area selected, create mask
-	v.to.rast input=$EXTRACT output=$r_name use=cat value=1 rows=4096
-	#read the region settings to save to configuration file
-	g.region -g| grep "n=" | cut -f2 -d'='> $name.var
-	read north < $name.var
-	g.region -g| grep "s=" | cut -f2 -d'='  > $name.var
-	read south < $name.var
-	g.region -g| grep "e=" | cut -f2 -d'=' > $name.var
-	read east < $name.var
-	g.region -g| grep "w=" | cut -f2 -d'=' > $name.var
-	read west < $name.var
-	#write info in configuration file
-	echo "MASKEDOVERLAYAREA $r_name|$north|$south|$east|$west" >> $GIS_OPT_conf
+	mask_name="rli_samp_${r_name}"
+	v.to.rast input="$EXTRACT" output="$mask_name" use=cat --quiet
+
+	# save the region settings into the configuration file
+	eval `g.region -g`
+	echo "MASKEDOVERLAYAREA $mask_name|$n|$s|$e|$w" >> "$GIS_OPT_conf"
+
+    elif [ "$ok" -eq -1 ] ; then
+	g.remove vect="$EXTRACT" --quiet
+	break
     fi
+
     #remove temporary vector map created from v.extract
-    g.remove vect=$EXTRACT
-    #rm -fR "$GISDBASE"/"$LOCATION"/"$MAPSET"/vector/$GIS_OPT_vector"part"$I
-    #echo DROP TABLE $GIS_OPT_vector"part"$I | db.execute 
-done
-d.mon stop=x1
-#restore user region
-g.region region=$TMP_REGION
-#remove temporary region, $TMP_REGION
-g.remove region=$TMP_REGION
-# clean tmp files
-rm -f $TMP*
+    g.remove vect="$EXTRACT" --quiet
 
+done < "$TMP.cat"
 
+
+d.mon stop="$XMON" --quiet
+
+
+# clean tmp files and restore region
+cleanup

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/square_mouse_selection.sh
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/square_mouse_selection.sh	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/square_mouse_selection.sh	2014-02-11 14:09:03 UTC (rev 58999)
@@ -1,154 +1,190 @@
-#! /bin/sh 
-
+#!/bin/sh
+#
+# This script selects a square area using the mouse
+#
 # This program is free software under the GPL (>=v2)
 # Read the COPYING file that comes with GRASS for details.
+#
 
-#this script select a square area using mouse
-
-#%Module 
+#%Module
 #% description: Select a rectangular area
 #%End
 #%option
 #% key: raster
 #% type: string
-#% description: raster map to to analyse
+#% gisprompt: old,cell,raster
+#% description: Raster map to to analyse
 #% required: yes
 #%end
 #%option
 #% key: vector
 #% type: string
-#% description: vector to overlay
+#% gisprompt: old,vector,vector
+#% description: Vector map to overlay
 #% required: no
 #%end
 #%option
 #% key: site
 #% type: string
-#% description: site to overlay
+#% description: Vector points map to overlay
 #% required: no
 #%end
 #%option
 #% key: conf
 #% type: string
-#% description: name of configuration file where insert areas
+#% gisprompt: new,file,file
+#% description: Name of configuration file where inserted areas will be stored
 #% required: yes
 #%end
 #%option
 #% key: north
 #% type: string
-#% description: nothern edge (use only with f flag)
+#% description: Northern edge (use only with the 'f' flag)
 #% required: no
 #%end
 #%option
 #% key: south
 #% type: string
-#% description:south edge (use only with f flag)
+#% description: Southern edge (use only with the 'f' flag)
 #% required: no
 #%end
 #%option
 #% key: east
 #% type: string
-#% description: east edge(use only with f flag)
+#% description: Eastern edge (use only with the 'f' flag)
 #% required: no
 #%end
 #%option
-#% key: west 
+#% key: west
 #% type: string
-#% description: west edge(use only with f flag)
+#% description: Western edge (use only with the 'f' flag)
 #% required: no
 #%end
 #%flag
 #% key: f
-#% description: sample frame yet selected 
+#% description: Sample frame selected by module options
 #%end
 
 f_path="$GISBASE/etc/r.li.setup"
 
-# Check if we have grass
+# Check if we are in a GRASS session
 if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
+   echo "You must be in GRASS GIS to run this program." 1>&2
+   exit 1
 fi
+
 if [ "$1" != "@ARGS_PARSED@" ] ; then
-  exec g.parser "$0" "$@"
+   exec g.parser "$0" "$@"
 fi
 
+#### create temporary file
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+    echo "ERROR: unable to create temporary file" 1>&2
+    exit 1
+fi
 
+cleanup()
+{
+   # remove temporary region
+   eval `g.findfile elem=windows file="tmp_rli_sq.$$" | grep '^name='`
+   if [ -n "$name" ] ; then
+      g.region region="tmp_rli_sq.$$"
+      g.remove region="tmp_rli_sq.$$" --quiet
+   fi
 
-# open x1 monitor
-d.mon stop=x1
-d.mon start=x1
+   rm -f "$TMP" "$TMP.var"
+}
+trap "cleanup" 2 3 15
 
 
-g.region rast=$GIS_OPT_raster
+# find a free Xmonitor
+XMON=x1
+for i in 1 2 3 4 5 6 7 ; do
+   result=`d.mon -L | grep -w "^x$i"`
+   if [ `echo "$result" | grep -c 'not'` -eq 1 ] ; then
+      XMON="x$i"
+      break
+   fi
+done
 
-#### set temporary files
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
-    echo "ERROR: unable to create temporary files" 1>&2
-    exit 1
-fi
+d.mon start="$XMON" --quiet
 
-#saving starting values
-g.region -g | grep "n=" | cut -f2 -d'=' > $TMP.var
-read s_n < $TMP.var
-g.region -g | grep "s=" | cut -f2 -d'=' > $TMP.var
-read s_s < $TMP.var
-g.region -g | grep "e=" | cut -f2 -d'=' > $TMP.var
-read s_e < $TMP.var
-g.region -g | grep "w=" | cut -f2 -d'=' > $TMP.var
-read s_w < $TMP.var
-g.region -g | grep "nsres=" | cut -f2 -d'=' > $TMP.var
-read s_nsres < $TMP.var
-g.region -g | grep "ewres=" | cut -f2 -d'=' > $TMP.var
-read s_ewres < $TMP.var
-echo "START $s_n|$s_s|$s_e|$s_w|$s_nsres|$s_ewres" >> $GIS_OPT_conf
 
+# setup internal region
+#  (WIND_OVERRIDE is already present by the main r.li.setup script)
+g.region save="tmp_rli_sq.$$"
+g.region rast="$GIS_OPT_raster"
+
+# store starting values
+eval `g.region -g`
+s_n="$n"
+s_s="$s"
+s_e="$e"
+s_w="$w"
+s_nsres="$nsres"
+s_ewres="$ewres"
+
+echo "START $s_n|$s_s|$s_e|$s_w|$s_nsres|$s_ewres" >> "$GIS_OPT_conf"
+
 # show the sampling frame
-if [ $GIS_FLAG_f -eq 1 ] ; then
-    g.region n=$GIS_OPT_north s=$GIS_OPT_south e=$GIS_OPT_east w=$GIS_OPT_west
+if [ "$GIS_FLAG_f" -eq 1 ] ; then
+    g.region n="$GIS_OPT_north" s="$GIS_OPT_south" \
+	     e="$GIS_OPT_east" w="$GIS_OPT_west"
 fi
 
-d.rast -o map=$GIS_OPT_raster
+d.rast -o map="$GIS_OPT_raster" --quiet
+
 if [ -n "$GIS_OPT_vector" ] ; then
-    d.vect  map=$GIS_OPT_vector
+    d.vect map="$GIS_OPT_vector" type=area fcolor=none width=2
 fi
-if [ -n "$GIS_OPT_site" ] ; then 
-    d.vect  map=$GIS_OPT_site
+if [ -n "$GIS_OPT_site" ] ; then
+    d.vect map="$GIS_OPT_site" color=black fcolor=black size=9 icon=basic/circle
+    d.vect map="$GIS_OPT_site" color=red fcolor=red size=5 icon=basic/circle
 fi
 
-#let draw area
+# have the user selected the area of interest with the mouse
+
+# TODO: popup message? (d.menu: "Draw box now: [ok]")
+######
+#d.menu bcolor=aqua tcolor=black << EOF
+#.T 20
+#.L 20
+#Next select area with mouse
+#          [ Ok ]
+#EOF
+######
+
+# note if user right clicks to quit without zooming the whole frame is used.
 d.zoom
 
-#ask if the selected area is right
-export name=$TMP #where write the answer
-$GRASS_WISH $f_path/square_query
-read ok < $TMP.var
-if [ $ok -eq 0 ] ; then
-    echo "NO" >> $GIS_OPT_conf
-fi
 
-if [ $ok -eq 1 ] ; then
-    #write the square boundaries
-    g.region -g | grep "n=" | cut -f2 -d'=' > $TMP.var
-    read n < $TMP.var
-    g.region -g | grep "s=" | cut -f2 -d'=' > $TMP.var
-    read s < $TMP.var
-    g.region -g | grep "e=" | cut -f2 -d'=' > $TMP.var
-    read e < $TMP.var
-    g.region -g | grep "w=" | cut -f2 -d'=' > $TMP.var
-    read w < $TMP.var
-    g.region -g | grep "nsres=" | cut -f2 -d'=' > $TMP.var
-    read nsres < $TMP.var
-    g.region -g | grep "ewres=" | cut -f2 -d'=' > $TMP.var
-    read ewres < $TMP.var
-    echo "SQUAREAREA $n|$s|$e|$w|$nsres|$ewres" >> $GIS_OPT_conf
-fi
+# ask if the selected area is right
+name="$TMP.var"  # temp file where the answer is written to by the tcl pop-up
+export name
 
-#close monitor
-d.mon stop=x1
-# clean tmp files
-rm -f $TMP*
+# ask if it's ok, save 0,1 to the "$name" tmp file
+"$GRASS_WISH" "$f_path/square_query"
 
+if [ -e "$name" ] ; then
+   read ok < "$name"
+else
+   ok="-999"
+fi
 
+if [ "$ok" -eq 0 ] ; then
+    echo "NO" >> "$GIS_OPT_conf"
+elif [ "$ok" -eq 1 ] ; then
+    # write the square boundaries
+    # TODO: is range (0-1, 0-1) valid or a bug?
+    eval `g.region -g`
+    echo "SQUAREAREA $n|$s|$e|$w|$nsres|$ewres" >> "$GIS_OPT_conf"
+else
+    g.message -e "Unable to ascertain if the selected area was ok or not"
+fi
 
+# close the Xmonitor
+d.mon stop="$XMON" --quiet
 
+# clean tmp files and temporary region
+cleanup

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/square_query
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/square_query	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.setup/square_query	2014-02-11 14:09:03 UTC (rev 58999)
@@ -12,17 +12,17 @@
     global env
     wm title . "Select this area"
     wm minsize . 250 100
-    label .label -text "Is this area ok?"
+    label .label -text "\nIs this area ok?"
     pack .label 
     frame .buttons
     pack .buttons
     set val ""
     button .buttons.ok -text "Ok" -command {
-	exec echo 1 > $env(name).var
+	exec echo 1 > $env(name)
 	destroy .
     }
     button .buttons.no -text "No" -command {
-	exec echo 0 > $env(name).var
+	exec echo 0 > $env(name)
 	destroy .
     }
-    grid .buttons.ok .buttons.no
+    grid .buttons.ok .buttons.no -padx 3 -pady 3

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/shannon.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/shannon.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/shannon.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -21,9 +21,9 @@
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
 
-int calculate(int fd, area_des ad, double *result);
-int calculateD(int fd, area_des ad, double *result);
-int calculateF(int fd, area_des ad, double *result);
+int calculate(int fd, struct area_entry *ad, double *result);
+int calculateD(int fd, struct area_entry *ad, double *result);
+int calculateF(int fd, struct area_entry *ad, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -59,7 +59,7 @@
 }
 
 
-int shannon(int fd, char **par, area_des ad, double *result)
+int shannon(int fd, char **par, struct area_entry * ad, double *result)
 {
 
     char *mapset;
@@ -110,7 +110,7 @@
 }
 
 
-int calculate(int fd, area_des ad, double *result)
+int calculate(int fd, struct area_entry *ad, double *result)
 {
 
     CELL *buf;
@@ -314,7 +314,7 @@
 
 
 
-int calculateD(int fd, area_des ad, double *result)
+int calculateD(int fd, struct area_entry *ad, double *result)
 {
 
     DCELL *buf;
@@ -517,7 +517,7 @@
 }
 
 
-int calculateF(int fd, area_des ad, double *result)
+int calculateF(int fd, struct area_entry *ad, double *result)
 {
 
     FCELL *buf;

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/main.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/main.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -55,7 +55,7 @@
 
 }
 
-int shape_index(int fd, char **par, area_des ad, double *result)
+int shape_index(int fd, char **par, struct area_entry *ad, double *result)
 {
 
 
@@ -89,6 +89,7 @@
 		}
 	    }
 	}
+	/* todo? free(mask_buf); */
     }
 
     /* calculate distance */

Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/simpson.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/simpson.c	2014-02-11 14:07:21 UTC (rev 58998)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/simpson.c	2014-02-11 14:09:03 UTC (rev 58999)
@@ -22,9 +22,9 @@
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
 
-double calculate(area_des ad, int fd, double *result);
-double calculateD(area_des ad, int fd, double *result);
-double calculateF(area_des ad, int fd, double *result);
+double calculate(struct area_entry *ad, int fd, double *result);
+double calculateD(struct area_entry *ad, int fd, double *result);
+double calculateF(struct area_entry *ad, int fd, double *result);
 
 int main(int argc, char *argv[])
 {
@@ -59,18 +59,13 @@
 
 }
 
-int simpson(int fd, char **par, area_des ad, double *result)
+int simpson(int fd, char **par, struct area_entry *ad, double *result)
 {
     char *mapset;
-
     int ris = RLI_OK;
-
     double indice = 0;
-
     struct Cell_head hd;
 
-
-
     mapset = G_find_cell(ad->raster, "");
     if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
 	return RLI_ERRORE;
@@ -110,7 +105,7 @@
 
 
 
-double calculate(area_des ad, int fd, double *result)
+double calculate(struct area_entry *ad, int fd, double *result)
 {
     CELL *buf;
     CELL corrCell;
@@ -134,12 +129,10 @@
     double t;
 
     avl_tree albero = NULL;
-
     AVL_table *array;
 
     generic_cell uc;
 
-
     uc.t = CELL_TYPE;
 
     /* open mask if needed */
@@ -276,7 +269,7 @@
 	return RLI_ERRORE;
     }
 
-    /* claculate index summary */
+    /* calculate index summary */
     for (i = 0; i < m; i++) {
 	t = (double)(array[i]->tot);
 	p = t / area;
@@ -300,7 +293,7 @@
 }
 
 
-double calculateD(area_des ad, int fd, double *result)
+double calculateD(struct area_entry *ad, int fd, double *result)
 {
     DCELL *buf;
     DCELL corrCell;
@@ -488,8 +481,7 @@
 }
 
 
-
-double calculateF(area_des ad, int fd, double *result)
+double calculateF(struct area_entry *ad, int fd, double *result)
 {
     FCELL *buf;
     FCELL corrCell;
@@ -545,7 +537,6 @@
 
 	buf = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
 
-
 	for (i = 0; i < ad->cl; i++) {	/* for each fcell in the row */
 
 	    area++;
@@ -605,7 +596,6 @@
 		precCell = corrCell;
 	    }
 
-
 	}
     }
 



More information about the grass-commit mailing list