[GRASS-SVN] r42698 - in grass-addons/raster/mcda: r.mcda.electre r.mcda.fuzzy r.mcda.regime r.roughset

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 3 09:00:56 EDT 2010


Author: gianluca
Date: 2010-07-03 13:00:56 +0000 (Sat, 03 Jul 2010)
New Revision: 42698

Modified:
   grass-addons/raster/mcda/r.mcda.electre/dominance.c
   grass-addons/raster/mcda/r.mcda.electre/main.c
   grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c
   grass-addons/raster/mcda/r.mcda.fuzzy/main.c
   grass-addons/raster/mcda/r.mcda.regime/main.c
   grass-addons/raster/mcda/r.mcda.regime/regime.c
   grass-addons/raster/mcda/r.roughset/main.c
   grass-addons/raster/mcda/r.roughset/raccess.c
   grass-addons/raster/mcda/r.roughset/rbasic.c
   grass-addons/raster/mcda/r.roughset/rclass.c
   grass-addons/raster/mcda/r.roughset/rcore.c
   grass-addons/raster/mcda/r.roughset/reduct1.c
   grass-addons/raster/mcda/r.roughset/reduct2.c
   grass-addons/raster/mcda/r.roughset/rset.c
   grass-addons/raster/mcda/r.roughset/rsystem.c
   grass-addons/raster/mcda/r.roughset/rule1.c
   grass-addons/raster/mcda/r.roughset/rule2.c
   grass-addons/raster/mcda/r.roughset/rules_extr.c
Log:
indentation of code improvement

Modified: grass-addons/raster/mcda/r.mcda.electre/dominance.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/dominance.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.mcda.electre/dominance.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -1,43 +1,46 @@
 #include "local_proto.h"
 
-/* 
- * global function declaration 
+/*
+ * global function declaration
  */
 
 void build_weight_vect(int nrows, int ncols, int ncriteria,
-		       struct Option *weight, double *weight_vect);
+                       struct Option *weight, double *weight_vect);
 
 void build_dominance_matrix(int nrows, int ncols, int ncriteria,
-			    double *weight_vect, double ***decision_vol);
+                            double *weight_vect, double ***decision_vol);
 
 
 /*
- * function definitions 
+ * function definitions
  */
 
 void build_weight_vect(int nrows, int ncols, int ncriteria,
-		       struct Option *weight, double *weight_vect)
+                       struct Option *weight, double *weight_vect)
 {
 
     int i, nweight = 0;
     double weight_sum = 0;
 
-    while (weight->answers[nweight] != NULL) {
-	nweight++;
+    while (weight->answers[nweight] != NULL)
+    {
+        nweight++;
     }
 
 
     if (nweight != ncriteria)
-	G_fatal_error(_("criteria number  and weight number are different"));
+        G_fatal_error(_("criteria number  and weight number are different"));
 
 
-    for (i = 0; i < nweight; i++) {
-	weight_vect[i] = (atof(weight->answers[i]));	/*transfer  weight value  in double  array */
-	weight_sum = weight_sum + weight_vect[i];	/*calculate sum weight */
+    for (i = 0; i < nweight; i++)
+    {
+        weight_vect[i] = (atof(weight->answers[i]));	/*transfer  weight value  in double  array */
+        weight_sum = weight_sum + weight_vect[i];	/*calculate sum weight */
     }
 
-    for (i = 0; i < nweight; i++) {
-	weight_vect[i] = weight_vect[i] / weight_sum;	/*normalize vector weight */
+    for (i = 0; i < nweight; i++)
+    {
+        weight_vect[i] = weight_vect[i] / weight_sum;	/*normalize vector weight */
 
     }
 
@@ -45,7 +48,7 @@
 
 
 void build_dominance_matrix(int nrows, int ncols, int ncriteria,
-			    double *weight_vect, double ***decision_vol)
+                            double *weight_vect, double ***decision_vol)
 {
     int row1, col1, row2, col2;
     int i, j, k, cont;
@@ -55,48 +58,55 @@
     double *col_sum_disc = G_alloc_vector(nrows * ncols);
 
     k = 0;			/* make pairwise comparation and build concordance/discordance matrix */
-    for (row1 = 0; row1 < nrows; row1++) {
-	G_percent(row1, nrows, 2);
-	for (col1 = 0; col1 < ncols; col1++) {
-	    j = 0;
-	    for (row2 = 0; row2 < nrows; row2++) {
-		for (col2 = 0; col2 < ncols; col2++) {
-		    double conc = 0, disc = 0;
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        G_percent(row1, nrows, 2);
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            j = 0;
+            for (row2 = 0; row2 < nrows; row2++)
+            {
+                for (col2 = 0; col2 < ncols; col2++)
+                {
+                    double conc = 0, disc = 0;
 
-		    for (i = 0; i < ncriteria; i++) {
-			double d =
-			    decision_vol[row1][col1][i] -
-			    decision_vol[row2][col2][i];
-			if (d >= 0)
-			    conc += weight_vect[i];
-			if (d < disc)	/*WARNING: if(d>conc) */
-			     /**/ disc = -d;
-		    }
-		    row_sum_conc[k] += conc;
-		    col_sum_conc[j] += conc;
-		    row_sum_disc[k] += disc;
-		    col_sum_disc[j] += disc;
+                    for (i = 0; i < ncriteria; i++)
+                    {
+                        double d =
+                            decision_vol[row1][col1][i] -
+                            decision_vol[row2][col2][i];
+                        if (d >= 0)
+                            conc += weight_vect[i];
+                        if (d < disc)	/*WARNING: if(d>conc) */
+                            /**/ disc = -d;
+                    }
+                    row_sum_conc[k] += conc;
+                    col_sum_conc[j] += conc;
+                    row_sum_disc[k] += disc;
+                    col_sum_disc[j] += disc;
 
-		    j++;	/* increase rows index up to nrows*ncols */
-		}
-	    }
-	    k++;		/* increase columns index up to nrows*ncols */
-	}
+                    j++;	/* increase rows index up to nrows*ncols */
+                }
+            }
+            k++;		/* increase columns index up to nrows*ncols */
+        }
     }
 
     /*calculate concordance and discordance index and storage in decision_vol */
     cont = 0;			/*variabile progressiva per riga/colonna della concordance_map */
-    for (row1 = 0; row1 < nrows; row1++) {
-	G_percent(row1, nrows, 2);
-	for (col1 = 0; col1 < ncols; col1++) {
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        G_percent(row1, nrows, 2);
+        for (col1 = 0; col1 < ncols; col1++)
+        {
 
-	    /*fill matrix with concordance index for each DCELL */
-	    decision_vol[row1][col1][ncriteria] =
-		row_sum_conc[cont] - col_sum_conc[cont];
-	    /*fill matrix with discordance index for each DCELL */
-	    decision_vol[row1][col1][ncriteria + 1] =
-		row_sum_disc[cont] - col_sum_disc[cont];
-	    cont++;
-	}
+            /*fill matrix with concordance index for each DCELL */
+            decision_vol[row1][col1][ncriteria] =
+                row_sum_conc[cont] - col_sum_conc[cont];
+            /*fill matrix with discordance index for each DCELL */
+            decision_vol[row1][col1][ncriteria + 1] =
+                row_sum_disc[cont] - col_sum_disc[cont];
+            cont++;
+        }
     }
 }

Modified: grass-addons/raster/mcda/r.mcda.electre/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/main.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.mcda.electre/main.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -1,4 +1,239 @@
+<<<<<<< .mine
+/****************************************************************************
+ *
+ * MODULE:	 r.mcda.electre
+ * AUTHORS:	 Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
+ *
+ * PURPOSE:      Make a multicriterio decision  analysis based on ELECTRE algorthm
+ *
+ * COPYRIGHT:    (C) GRASS Development Team (2008)
+ *
+ *		        This program is free software under the GNU General Public
+ *   	    	License (>=v2). Read the file COPYING that comes with GRASS
+ *   	    	for details.
+ *
+ *****************************************************************************/
 
+
+#include "local_proto.h"
+
+
+/*
+ * main function
+ */
+int main(int argc, char *argv[])
+{
+    struct Cell_head cellhd;	/* it stores region information,  and header information of rasters */
+    char *result_concordance, *result_discordance;		/* outputs raster name */
+    char *mapset;		/* mapset name */
+    unsigned char *outrast_concordance, *outrast_discordance;	/* output buffer */
+    char *message;
+    int i,j, ncriteria=0;	/* index and  files number*/
+    int nrows, ncols;
+    int row1, row2, col1, col2;
+    int outfd_concordance, outfd_discordance;		/* output file descriptor */
+    double *weight_vect, ***decision_vol;/* vector and matrix */
+
+
+    struct History history;	/* holds meta-data (title, comments,..) */
+
+    struct GModule *module;	/* GRASS module for parsing arguments */
+
+    struct Option *criteria, *weight, *discordance, *concordance;	/* options */
+
+    struct input *attributes; /*storage  alla input criteria GRID files and output concordance and discordance GRID files*/
+
+
+    /* initialize GIS environment */
+    G_gisinit(argv[0]);		/* reads grass env, stores program name to G_program_name() */
+
+    /* initialize module */
+    module = G_define_module();
+    module->keywords = _("raster,MCDA");
+    module->description = _("Multicirtieria decision analysis based on ELECTRE method");
+
+    /* Define the different options as defined in gis.h */
+    criteria  = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory*/
+    criteria->key        = "criteria";
+    criteria->type       = TYPE_STRING;
+    criteria->required   = YES;
+    criteria->multiple   = YES;
+    criteria->gisprompt  = "old,cell,raster" ;
+    criteria->description = "Input geographics criteria in information system";
+
+    weight = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory*/
+    weight->key        = "weight";
+    weight->type       = TYPE_DOUBLE;
+    weight->required   = YES;
+    weight->multiple   = YES;
+    weight->description = _("Criteria weight(s) (w1,w2,..)");
+
+    concordance = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+    concordance->key = "concordance";
+    concordance->type = TYPE_STRING;
+    concordance->required = YES;
+    concordance->gisprompt = "new,cell,raster";
+    concordance->answer ="concordance";
+    concordance->description = "concordance output map";
+
+    discordance = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+    discordance->key = "discordance";
+    discordance->type = TYPE_STRING;
+    discordance->required = YES;
+    discordance->gisprompt = "new,cell,raster";
+    discordance->answer ="discordance";
+    discordance->description = "discordance output map";
+
+    /* options and flags parser */
+    if (G_parser(argc, argv))
+        exit(EXIT_FAILURE);
+
+
+    G_message("Start: %s",G_date()); /*write calculation start time*/
+
+    /* number of file (=criteria) */
+    while (criteria->answers[ncriteria]!=NULL)
+    {
+        ncriteria++;
+    }
+
+    /* process the input maps:  stores options and flags to variables */
+    /* CRITERIA grid */
+    attributes = G_malloc(ncriteria * sizeof(struct input)); /*attributes is input struct defined in top file and store alla criteria files*/
+    weight_vect=G_malloc(ncriteria * sizeof(double)); /*allocate memory fron vector weight*/
+
+
+
+    build_weight_vect(nrows,ncols,ncriteria,weight,weight_vect); /*calcolate weight vector*/
+
+
+
+    for (i = 0; i < ncriteria; i++)
+    {
+        struct input *p = &attributes[i];
+        p->name = criteria->answers[i];
+        p->mapset = G_find_cell2(p->name,""); /* G_find_cell: Looks for the raster map "name" in the database. */
+        if (p->mapset==NULL) /* returns NULL if the map was not found in any mapset,   mapset name otherwise */
+            G_fatal_error(_("Raster file <%s> not found"), p->name);
+
+        if ((p->infd = G_open_cell_old(p->name, p->mapset))<0) /* G_open_cell_old - returns file destriptor (>0) */
+            G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),p->name, p->mapset);
+
+        if (G_get_cellhd(p->name,p->mapset,&cellhd)<0)/* controlling, if we can open input raster */
+            G_fatal_error(_("Unable to read file header of <%s>"), p->name);
+
+        p->inrast = G_allocate_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL   */
+    }
+
+    result_concordance=concordance->answer; /* store outputn name in variables*/
+    result_discordance=discordance->answer;
+
+
+    if (G_legal_filename(result_concordance) < 0) /* check for legal database file names */
+        G_fatal_error(_("<%s> is an illegal file name"), result_concordance);
+
+    if (G_legal_filename(result_discordance) < 0) /* check for legal database file names */
+        G_fatal_error(_("<%s> is an illegal file name"), result_discordance);
+
+    /*values = G_malloc(ncriteria * sizeof(DCELL));*/
+
+    nrows = G_window_rows();
+    ncols = G_window_cols();
+
+    /*memory allocation for-three dimensional matrix*/
+    decision_vol=G_malloc(nrows * sizeof(double*));
+    for (i=0; i<nrows; ++i)
+    {
+        decision_vol[i]=G_malloc(ncols * sizeof(double*));
+        for (j=0; j<ncols; ++j)
+        {
+            decision_vol[i][j]=G_malloc((ncriteria+2) * sizeof(double)); /****NOTE: it's storage enven concordance and discordance index map****/
+        }
+    }
+
+    /* Allocate output buffer, use  DCELL_TYPE */
+    outrast_concordance = G_allocate_raster_buf(DCELL_TYPE); /* Allocate memory for a raster map of type DCELL_TYPE. */
+    outrast_discordance = G_allocate_raster_buf(DCELL_TYPE);
+
+    /* controlling, if we can write the raster */
+    if ((outfd_concordance = G_open_raster_new(result_concordance, DCELL_TYPE)) < 0)
+        G_fatal_error(_("Unable to create raster map <%s>"), result_concordance);
+
+    if ((outfd_discordance = G_open_raster_new(result_discordance, DCELL_TYPE)) < 0)
+        G_fatal_error(_("Unable to create raster map <%s>"), result_discordance);
+
+
+    /*build a three dimensional matrix for storage all critera maps*/
+    for (i=0;i<ncriteria;i++)
+    {
+        for (row1 = 0; row1 < nrows;row1++)
+        {
+            G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1,DCELL_TYPE);/* Reads appropriate information into the buffer buf associated with the requested row*/
+            /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row);*/
+            for (col1 = 0; col1 < ncols; col1++)
+            {
+                /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array*/
+                DCELL v1 = ((DCELL *)attributes[i].inrast)[col1];
+                decision_vol[row1][col1][i]=(double)(v1);
+
+            }
+        }
+    }
+
+
+    build_dominance_matrix(nrows,ncols,ncriteria,weight_vect,decision_vol); /*scan all DCELL, make a pairwise comparatione, buil concordance and discordance matrix and relative index*/
+
+
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            ((DCELL *) outrast_concordance)[col1] = (DCELL)decision_vol[row1][col1][ncriteria];/*write concordance map*/
+            ((DCELL *) outrast_discordance)[col1] = (DCELL)decision_vol[row1][col1][ncriteria+1];/*write discordance map*/
+        }
+        if (G_put_raster_row(outfd_concordance, outrast_concordance,  DCELL_TYPE) < 0)
+            G_fatal_error(_("Failed writing raster map <%s>"), result_concordance);
+
+        if (G_put_raster_row(outfd_discordance, outrast_discordance,  DCELL_TYPE) < 0)
+            G_fatal_error(_("Failed writing raster map <%s>"), result_discordance);
+    }
+
+
+    G_message("End: %s",G_date());
+
+    /* memory cleanup */
+    for (i = 0; i<ncriteria; i++)
+        G_free(attributes[i].inrast);
+
+    G_free(outrast_concordance);
+    G_free(outrast_discordance);
+    G_free(decision_vol);
+
+
+
+    /* closing raster maps */
+    for (i = 0; i<ncriteria; i++)
+        G_close_cell(attributes[i].infd);
+
+    G_close_cell(outfd_concordance);
+    G_close_cell(outfd_discordance);
+
+    /* add command line incantation to history concordance file */
+    G_short_history(result_concordance, "raster", &history);
+    G_command_history(&history);
+    G_write_history(result_concordance, &history);
+
+    /* add command line incantation to history discordance file */
+    G_short_history(result_discordance, "raster", &history);
+    G_command_history(&history);
+    G_write_history(result_discordance, &history);
+
+    exit(EXIT_SUCCESS);
+}
+
+
+=======
+
 /****************************************************************************
  *
  * MODULE:	 r.mcda.electre
@@ -235,3 +470,4 @@
 
     exit(EXIT_SUCCESS);
 }
+>>>>>>> .r42697

Modified: grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -1,43 +1,46 @@
 #include "local_proto.h"
 
-/* 
- * global function declaration 
+/*
+ * global function declaration
  */
 
 void build_weight_vect(int nrows, int ncols, int ncriteria,
-		       struct Option *weight, double *weight_vect);
+                       struct Option *weight, double *weight_vect);
 
 void build_fuzzy_matrix(int nrows, int ncols, int ncriteria,
-			double *weight_vect, double ***decision_vol);
+                        double *weight_vect, double ***decision_vol);
 
 
 /*
- * function definitions 
+ * function definitions
  */
 
 void build_weight_vect(int nrows, int ncols, int ncriteria,
-		       struct Option *weight, double *weight_vect)
+                       struct Option *weight, double *weight_vect)
 {
 
     int i, nweight = 0;
     double weight_sum = 0;
 
-    while (weight->answers[nweight] != NULL) {
-	nweight++;
+    while (weight->answers[nweight] != NULL)
+    {
+        nweight++;
     }
 
 
     if (nweight != ncriteria)
-	G_fatal_error(_("criteria number  and weight number are different"));
+        G_fatal_error(_("criteria number  and weight number are different"));
 
 
-    for (i = 0; i < nweight; i++) {
-	weight_vect[i] = (atof(weight->answers[i]));	/*transfer  weight value  in double  array */
-	weight_sum = weight_sum + weight_vect[i];	/*calculate sum weight */
+    for (i = 0; i < nweight; i++)
+    {
+        weight_vect[i] = (atof(weight->answers[i]));	/*transfer  weight value  in double  array */
+        weight_sum = weight_sum + weight_vect[i];	/*calculate sum weight */
     }
 
-    for (i = 0; i < nweight; i++) {
-	weight_vect[i] = weight_vect[i] / weight_sum;	/*normalize vector weight */
+    for (i = 0; i < nweight; i++)
+    {
+        weight_vect[i] = weight_vect[i] / weight_sum;	/*normalize vector weight */
 
     }
 
@@ -45,7 +48,7 @@
 
 
 void build_fuzzy_matrix(int nrows, int ncols, int ncriteria,
-			double *weight_vect, double ***decision_vol)
+                        double *weight_vect, double ***decision_vol)
 {
     int row1, col1, row2, col2;
     int i, j, k, cont;
@@ -53,60 +56,76 @@
     double value;
 
     /* apply linguistic modifier - */
-    for (row1 = 0; row1 < nrows; row1++) {
-	G_percent(row1, nrows, 2);
-	for (col1 = 0; col1 < ncols; col1++) {
-	    for (i = 0; i < ncriteria; i++) {
-		decision_vol[row1][col1][i] =
-		    pow(decision_vol[row1][col1][i], weight_vect[i]);
-	    }
-	}
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        G_percent(row1, nrows, 2);
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            for (i = 0; i < ncriteria; i++)
+            {
+                decision_vol[row1][col1][i] =
+                    pow(decision_vol[row1][col1][i], weight_vect[i]);
+            }
+        }
     }
 
     /* operate intersection - AND logic (find min value -) */
-    for (row1 = 0; row1 < nrows; row1++) {
-	G_percent(row1, nrows, 2);
-	for (col1 = 0; col1 < ncols; col1++) {
-	    value = decision_vol[row1][col1][0];	/* set value to firsth matrix i-value */
-	    for (i = 0; i < ncriteria; i++) {
-		if (decision_vol[row1][col1][i] >= value) {
-		    value = value;
-		}
-		else {
-		    value = decision_vol[row1][col1][i];
-		}
-	    }
-	    decision_vol[row1][col1][ncriteria] = value;
-	}
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        G_percent(row1, nrows, 2);
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            value = decision_vol[row1][col1][0];	/* set value to firsth matrix i-value */
+            for (i = 0; i < ncriteria; i++)
+            {
+                if (decision_vol[row1][col1][i] >= value)
+                {
+                    value = value;
+                }
+                else
+                {
+                    value = decision_vol[row1][col1][i];
+                }
+            }
+            decision_vol[row1][col1][ncriteria] = value;
+        }
     }
 
     /* operate union - OR logic (find max value -) */
-    for (row1 = 0; row1 < nrows; row1++) {
-	G_percent(row1, nrows, 2);
-	for (col1 = 0; col1 < ncols; col1++) {
-	    value = decision_vol[row1][col1][0];	/* set value to firsth matrix i-value */
-	    for (i = 0; i < ncriteria; i++) {
-		if (decision_vol[row1][col1][i] <= value) {
-		    value = value;
-		}
-		else {
-		    value = decision_vol[row1][col1][i];
-		}
-	    }
-	    decision_vol[row1][col1][ncriteria + 1] = value;
-	}
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        G_percent(row1, nrows, 2);
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            value = decision_vol[row1][col1][0];	/* set value to firsth matrix i-value */
+            for (i = 0; i < ncriteria; i++)
+            {
+                if (decision_vol[row1][col1][i] <= value)
+                {
+                    value = value;
+                }
+                else
+                {
+                    value = decision_vol[row1][col1][i];
+                }
+            }
+            decision_vol[row1][col1][ncriteria + 1] = value;
+        }
     }
 
     /* operate OWA (find average value -) */
-    for (row1 = 0; row1 < nrows; row1++) {
-	G_percent(row1, nrows, 2);
-	for (col1 = 0; col1 < ncols; col1++) {
-	    value = decision_vol[row1][col1][0];	/* set value to firsth matrix i-value */
-	    for (i = 0; i < ncriteria; i++) {
-		value = value + decision_vol[row1][col1][i];
-	    }
-	    decision_vol[row1][col1][ncriteria + 2] = value / ncriteria;
-	}
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        G_percent(row1, nrows, 2);
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            value = decision_vol[row1][col1][0];	/* set value to firsth matrix i-value */
+            for (i = 0; i < ncriteria; i++)
+            {
+                value = value + decision_vol[row1][col1][i];
+            }
+            decision_vol[row1][col1][ncriteria + 2] = value / ncriteria;
+        }
     }
 
 }

Modified: grass-addons/raster/mcda/r.mcda.fuzzy/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/main.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/main.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -50,7 +50,7 @@
     module = G_define_module();
     module->keywords = _("raster,fuzzy,MCDA");
     module->description =
-	_("Multicirtieria decision analysis based on Yager fuzzy method");
+        _("Multicirtieria decision analysis based on Yager fuzzy method");
 
     /* Define the different options as defined in gis.h */
     criteria = G_define_option();	/* Allocates memory for the Option structure and returns a pointer to this memory */
@@ -94,13 +94,14 @@
 
     /* options and flags parser */
     if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
+        exit(EXIT_FAILURE);
 
     G_message("\n\nstart: %s", G_date());	/*write calculation start time */
 
     /* number of file (=criteria) */
-    while (criteria->answers[ncriteria] != NULL) {
-	ncriteria++;
+    while (criteria->answers[ncriteria] != NULL)
+    {
+        ncriteria++;
     }
 
     /* process the input maps:  stores options and flags to variables */
@@ -112,22 +113,23 @@
 
     build_weight_vect(nrows, ncols, ncriteria, weight, weight_vect);	/*calcolate weight vector */
 
-    for (i = 0; i < ncriteria; i++) {
-	struct input *p = &attributes[i];
+    for (i = 0; i < ncriteria; i++)
+    {
+        struct input *p = &attributes[i];
 
-	p->name = criteria->answers[i];
-	p->mapset = G_find_cell2(p->name, "");	/* G_find_cell: Looks for the raster map "name" in the database. */
-	if (p->mapset == NULL)	/* returns NULL if the map was not found in any mapset,   mapset name otherwise */
-	    G_fatal_error(_("Raster file <%s> not found"), p->name);
+        p->name = criteria->answers[i];
+        p->mapset = G_find_cell2(p->name, "");	/* G_find_cell: Looks for the raster map "name" in the database. */
+        if (p->mapset == NULL)	/* returns NULL if the map was not found in any mapset,   mapset name otherwise */
+            G_fatal_error(_("Raster file <%s> not found"), p->name);
 
-	if ((p->infd = G_open_cell_old(p->name, p->mapset)) < 0)	/* G_open_cell_old - returns file destriptor (>0) */
-	    G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
-			  p->name, p->mapset);
+        if ((p->infd = G_open_cell_old(p->name, p->mapset)) < 0)	/* G_open_cell_old - returns file destriptor (>0) */
+            G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+                          p->name, p->mapset);
 
-	if (G_get_cellhd(p->name, p->mapset, &cellhd) < 0)	/* controlling, if we can open input raster */
-	    G_fatal_error(_("Unable to read file header of <%s>"), p->name);
+        if (G_get_cellhd(p->name, p->mapset, &cellhd) < 0)	/* controlling, if we can open input raster */
+            G_fatal_error(_("Unable to read file header of <%s>"), p->name);
 
-	p->inrast = G_allocate_d_raster_buf();	/* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL   */
+        p->inrast = G_allocate_d_raster_buf();	/* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL   */
     }
 
     result_and = and->answer;	/* store outputn name in variables */
@@ -136,13 +138,13 @@
 
 
     if (G_legal_filename(result_and) < 0)	/* check for legal database file names */
-	G_fatal_error(_("<%s> is an illegal file name"), result_and);
+        G_fatal_error(_("<%s> is an illegal file name"), result_and);
 
     if (G_legal_filename(result_or) < 0)	/* check for legal database file names */
-	G_fatal_error(_("<%s> is an illegal file name"), result_or);
+        G_fatal_error(_("<%s> is an illegal file name"), result_or);
 
     if (G_legal_filename(result_owa) < 0)	/* check for legal database file names */
-	G_fatal_error(_("<%s> is an illegal file name"), result_owa);
+        G_fatal_error(_("<%s> is an illegal file name"), result_owa);
 
     /*values = G_malloc(ncriteria * sizeof(DCELL)); */
 
@@ -152,12 +154,14 @@
 
     /*memory allocation for-three dimensional matrix */
     decision_vol = G_malloc(nrows * sizeof(double *));
-    for (i = 0; i < nrows; ++i) {
-	decision_vol[i] = G_malloc(ncols * sizeof(double *));
-	for (j = 0; j < ncols; ++j) {
+    for (i = 0; i < nrows; ++i)
+    {
+        decision_vol[i] = G_malloc(ncols * sizeof(double *));
+        for (j = 0; j < ncols; ++j)
+        {
 
-	    decision_vol[i][j] = G_malloc((ncriteria + 3) * sizeof(double));	     /****NOTE: it's storage enven and, or, owa map*/
-	}
+            decision_vol[i][j] = G_malloc((ncriteria + 3) * sizeof(double));	     /****NOTE: it's storage enven and, or, owa map*/
+        }
     }
 
     /* Allocate output buffer, use  DCELL_TYPE */
@@ -167,49 +171,54 @@
 
     /* controlling, if we can write the raster */
     if ((outfd_and = G_open_raster_new(result_and, DCELL_TYPE)) < 0)
-	G_fatal_error(_("Unable to create raster map <%s>"), result_and);
+        G_fatal_error(_("Unable to create raster map <%s>"), result_and);
 
     if ((outfd_or = G_open_raster_new(result_or, DCELL_TYPE)) < 0)
-	G_fatal_error(_("Unable to create raster map <%s>"), result_or);
+        G_fatal_error(_("Unable to create raster map <%s>"), result_or);
 
     if ((outfd_owa = G_open_raster_new(result_owa, DCELL_TYPE)) < 0)
-	G_fatal_error(_("Unable to create raster map <%s>"), result_owa);
+        G_fatal_error(_("Unable to create raster map <%s>"), result_owa);
 
 
     /*build a three dimensional matrix for storage all critera maps */
-    for (i = 0; i < ncriteria; i++) {
-	for (row1 = 0; row1 < nrows; row1++) {
-	    G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1, DCELL_TYPE);	/* Reads appropriate information into the buffer buf associated with the requested row */
-	    /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row); */
-	    for (col1 = 0; col1 < ncols; col1++) {
-		/* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array */
-		DCELL v1 = ((DCELL *) attributes[i].inrast)[col1];
+    for (i = 0; i < ncriteria; i++)
+    {
+        for (row1 = 0; row1 < nrows; row1++)
+        {
+            G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1, DCELL_TYPE);	/* Reads appropriate information into the buffer buf associated with the requested row */
+            /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row); */
+            for (col1 = 0; col1 < ncols; col1++)
+            {
+                /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array */
+                DCELL v1 = ((DCELL *) attributes[i].inrast)[col1];
 
-		decision_vol[row1][col1][i] = (double)(v1);
-	    }
-	}
+                decision_vol[row1][col1][i] = (double)(v1);
+            }
+        }
     }
     build_fuzzy_matrix(nrows, ncols, ncriteria, weight_vect, decision_vol);	/*scan all DCELL, make a pairwise comparatione, buil concordance and discordance matrix and relative index */
 
-    for (row1 = 0; row1 < nrows; row1++) {
-	G_percent(row1, nrows, 2);
-	for (col1 = 0; col1 < ncols; col1++) {
-	    ((DCELL *) outrast_and)[col1] =
-		(DCELL) decision_vol[row1][col1][ncriteria];
-	    ((DCELL *) outrast_or)[col1] =
-		(DCELL) decision_vol[row1][col1][ncriteria + 1];
-	    ((DCELL *) outrast_owa)[col1] =
-		(DCELL) decision_vol[row1][col1][ncriteria + 2];
-	}
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        G_percent(row1, nrows, 2);
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            ((DCELL *) outrast_and)[col1] =
+                (DCELL) decision_vol[row1][col1][ncriteria];
+            ((DCELL *) outrast_or)[col1] =
+                (DCELL) decision_vol[row1][col1][ncriteria + 1];
+            ((DCELL *) outrast_owa)[col1] =
+                (DCELL) decision_vol[row1][col1][ncriteria + 2];
+        }
 
-	if (G_put_raster_row(outfd_and, outrast_and, DCELL_TYPE) < 0)
-	    G_fatal_error(_("Failed writing raster map <%s>"), result_and);
+        if (G_put_raster_row(outfd_and, outrast_and, DCELL_TYPE) < 0)
+            G_fatal_error(_("Failed writing raster map <%s>"), result_and);
 
-	if (G_put_raster_row(outfd_or, outrast_or, DCELL_TYPE) < 0)
-	    G_fatal_error(_("Failed writing raster map <%s>"), result_or);
+        if (G_put_raster_row(outfd_or, outrast_or, DCELL_TYPE) < 0)
+            G_fatal_error(_("Failed writing raster map <%s>"), result_or);
 
-	if (G_put_raster_row(outfd_owa, outrast_owa, DCELL_TYPE) < 0)
-	    G_fatal_error(_("Failed writing raster map <%s>"), result_owa);
+        if (G_put_raster_row(outfd_owa, outrast_owa, DCELL_TYPE) < 0)
+            G_fatal_error(_("Failed writing raster map <%s>"), result_owa);
     }
 
 
@@ -217,7 +226,7 @@
 
     /* memory cleanup */
     for (i = 0; i < ncriteria; i++)
-	G_free(attributes[i].inrast);
+        G_free(attributes[i].inrast);
 
     G_free(outrast_and);
     G_free(outrast_or);
@@ -229,7 +238,7 @@
 
     /* closing raster maps */
     for (i = 0; i < ncriteria; i++)
-	G_close_cell(attributes[i].infd);
+        G_close_cell(attributes[i].infd);
 
     G_close_cell(outfd_and);
     G_close_cell(outfd_or);

Modified: grass-addons/raster/mcda/r.mcda.regime/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/main.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.mcda.regime/main.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -51,7 +51,7 @@
     module = G_define_module();
     module->keywords = _("raster,MCDA");
     module->description =
-	_("Multicirtieria decision analysis based on REGIME method");
+        _("Multicirtieria decision analysis based on REGIME method");
 
     /* Define the different options as defined in gis.h */
     criteria = G_define_option();	/* Allocates memory for the Option structure and returns a pointer to this memory */
@@ -61,7 +61,7 @@
     criteria->multiple = YES;
     criteria->gisprompt = "old,cell,raster";
     criteria->description =
-	"Input geographics criteria in information system";
+        "Input geographics criteria in information system";
 
     weight = G_define_option();	/* Allocates memory for the Option structure and returns a pointer to this memory */
     weight->key = "weight";
@@ -81,14 +81,15 @@
 
     /* options and flags parser */
     if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
+        exit(EXIT_FAILURE);
 
 
     G_message("start: %s", G_date());	/*write calculation start time */
 
     /* number of file (=criteria) */
-    while (criteria->answers[ncriteria] != NULL) {
-	ncriteria++;
+    while (criteria->answers[ncriteria] != NULL)
+    {
+        ncriteria++;
     }
 
     /* process the input maps:  stores options and flags to variables */
@@ -102,29 +103,30 @@
 
 
 
-    for (i = 0; i < ncriteria; i++) {
-	struct input *p = &attributes[i];
+    for (i = 0; i < ncriteria; i++)
+    {
+        struct input *p = &attributes[i];
 
-	p->name = criteria->answers[i];
-	p->mapset = G_find_cell2(p->name, "");	/* G_find_cell: Looks for the raster map "name" in the database. */
-	if (p->mapset == NULL)	/* returns NULL if the map was not found in any mapset,   mapset name otherwise */
-	    G_fatal_error(_("Raster file <%s> not found"), p->name);
+        p->name = criteria->answers[i];
+        p->mapset = G_find_cell2(p->name, "");	/* G_find_cell: Looks for the raster map "name" in the database. */
+        if (p->mapset == NULL)	/* returns NULL if the map was not found in any mapset,   mapset name otherwise */
+            G_fatal_error(_("Raster file <%s> not found"), p->name);
 
-	if ((p->infd = G_open_cell_old(p->name, p->mapset)) < 0)	/* G_open_cell_old - returns file destriptor (>0) */
-	    G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
-			  p->name, p->mapset);
+        if ((p->infd = G_open_cell_old(p->name, p->mapset)) < 0)	/* G_open_cell_old - returns file destriptor (>0) */
+            G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+                          p->name, p->mapset);
 
-	if (G_get_cellhd(p->name, p->mapset, &cellhd) < 0)	/* controlling, if we can open input raster */
-	    G_fatal_error(_("Unable to read file header of <%s>"), p->name);
+        if (G_get_cellhd(p->name, p->mapset, &cellhd) < 0)	/* controlling, if we can open input raster */
+            G_fatal_error(_("Unable to read file header of <%s>"), p->name);
 
-	p->inrast = G_allocate_d_raster_buf();	/* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL */
+        p->inrast = G_allocate_d_raster_buf();	/* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL */
     }
 
     result_preference = preference->answer;	/* store outputn name in variables */
 
 
     if (G_legal_filename(result_preference) < 0)	/* check for legal database file names */
-	G_fatal_error(_("<%s> is an illegal file name"), result_preference);
+        G_fatal_error(_("<%s> is an illegal file name"), result_preference);
 
     /*values = G_malloc(ncriteria * sizeof(DCELL)); */
 
@@ -133,11 +135,13 @@
 
     /*memory allocation for-three dimensional matrix */
     decision_vol = G_malloc(nrows * sizeof(double *));
-    for (i = 0; i < nrows; ++i) {
-	decision_vol[i] = G_malloc(ncols * sizeof(double *));
-	for (j = 0; j < ncols; ++j) {
-	    decision_vol[i][j] = G_malloc((ncriteria + 1) * sizeof(double));	/*NOTE: it's storage enven preference regime index map */
-	}
+    for (i = 0; i < nrows; ++i)
+    {
+        decision_vol[i] = G_malloc(ncols * sizeof(double *));
+        for (j = 0; j < ncols; ++j)
+        {
+            decision_vol[i][j] = G_malloc((ncriteria + 1) * sizeof(double));	/*NOTE: it's storage enven preference regime index map */
+        }
     }
 
     /* Allocate output buffer, use  DCELL_TYPE */
@@ -145,23 +149,26 @@
 
     /* controlling, if we can write the raster */
     if ((outfd_preference =
-	 G_open_raster_new(result_preference, DCELL_TYPE)) < 0)
-	G_fatal_error(_("Unable to create raster map <%s>"),
-		      result_preference);
+                G_open_raster_new(result_preference, DCELL_TYPE)) < 0)
+        G_fatal_error(_("Unable to create raster map <%s>"),
+                      result_preference);
 
 
     /*build a three dimensional matrix for storage all critera maps */
-    for (i = 0; i < ncriteria; i++) {
-	for (row1 = 0; row1 < nrows; row1++) {
-	    G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1, DCELL_TYPE);	/* Reads appropriate information into the buffer buf associated with the requested row */
-	    /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row); */
-	    for (col1 = 0; col1 < ncols; col1++) {
-		/* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array */
-		DCELL v1 = ((DCELL *) attributes[i].inrast)[col1];
+    for (i = 0; i < ncriteria; i++)
+    {
+        for (row1 = 0; row1 < nrows; row1++)
+        {
+            G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1, DCELL_TYPE);	/* Reads appropriate information into the buffer buf associated with the requested row */
+            /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row); */
+            for (col1 = 0; col1 < ncols; col1++)
+            {
+                /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array */
+                DCELL v1 = ((DCELL *) attributes[i].inrast)[col1];
 
-		decision_vol[row1][col1][i] = (double)(v1);
-	    }
-	}
+                decision_vol[row1][col1][i] = (double)(v1);
+            }
+        }
     }
 
     G_message("build matrix: %s", G_date());
@@ -169,28 +176,30 @@
     build_regime_matrix(nrows, ncols, ncriteria, weight_vect, decision_vol);	/*scan all DCELL, make a pairwise comparatione, buil regime index matrix */
 
 
-    for (row1 = 0; row1 < nrows; row1++) {
-	for (col1 = 0; col1 < ncols; col1++) {
-	    ((DCELL *) outrast_preference)[col1] = (DCELL) decision_vol[row1][col1][ncriteria];	/*write concordance map */
-	}
-	if (G_put_raster_row(outfd_preference, outrast_preference, DCELL_TYPE)
-	    < 0)
-	    G_fatal_error(_("Failed writing raster map <%s>"),
-			  result_preference);
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            ((DCELL *) outrast_preference)[col1] = (DCELL) decision_vol[row1][col1][ncriteria];	/*write concordance map */
+        }
+        if (G_put_raster_row(outfd_preference, outrast_preference, DCELL_TYPE)
+                < 0)
+            G_fatal_error(_("Failed writing raster map <%s>"),
+                          result_preference);
     }
 
     G_message("end: %s", G_date());
 
     /* memory cleanup */
     for (i = 0; i < ncriteria; i++)
-	G_free(attributes[i].inrast);
+        G_free(attributes[i].inrast);
 
     G_free(outrast_preference);
     G_free(decision_vol);
 
     /* closing raster maps */
     for (i = 0; i < ncriteria; i++)
-	G_close_cell(attributes[i].infd);
+        G_close_cell(attributes[i].infd);
 
     G_close_cell(outfd_preference);
 

Modified: grass-addons/raster/mcda/r.mcda.regime/regime.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/regime.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.mcda.regime/regime.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -1,42 +1,45 @@
 #include "local_proto.h"
 
-/* 
- * global function declaration 
+/*
+ * global function declaration
  */
 
 void build_weight_vect(int nrows, int ncols, int ncriteria,
-		       struct Option *weight, double *weight_vect);
+                       struct Option *weight, double *weight_vect);
 
 void build_regime_matrix(int nrows, int ncols, int ncriteria,
-			 double *weight_vect, double ***decision_vol);
+                         double *weight_vect, double ***decision_vol);
 
 
 /*
- * function definitions 
+ * function definitions
  */
 
 void build_weight_vect(int nrows, int ncols, int ncriteria,
-		       struct Option *weight, double *weight_vect)
+                       struct Option *weight, double *weight_vect)
 {
 
     int i, nweight = 0;
     double weight_sum = 0;
 
-    while (weight->answers[nweight] != NULL) {
-	nweight++;
+    while (weight->answers[nweight] != NULL)
+    {
+        nweight++;
     }
 
     if (nweight != ncriteria)
-	G_fatal_error(_("criteria number  and weight number are different"));
+        G_fatal_error(_("criteria number  and weight number are different"));
 
 
-    for (i = 0; i < nweight; i++) {
-	weight_vect[i] = (atof(weight->answers[i]));	/*transfer  weight value  in double  array */
-	weight_sum = weight_sum + weight_vect[i];	/*calculate sum weight */
+    for (i = 0; i < nweight; i++)
+    {
+        weight_vect[i] = (atof(weight->answers[i]));	/*transfer  weight value  in double  array */
+        weight_sum = weight_sum + weight_vect[i];	/*calculate sum weight */
     }
 
-    for (i = 0; i < nweight; i++) {
-	weight_vect[i] = weight_vect[i] / weight_sum;	/*normalize vector weight */
+    for (i = 0; i < nweight; i++)
+    {
+        weight_vect[i] = weight_vect[i] / weight_sum;	/*normalize vector weight */
 
     }
 
@@ -44,45 +47,52 @@
 
 
 void build_regime_matrix(int nrows, int ncols, int ncriteria,
-			 double *weight_vect, double ***decision_vol)
+                         double *weight_vect, double ***decision_vol)
 {
     int row1, col1, row2, col2;
     int i, j, k, cont;
     double *row_sum_regime = G_alloc_vector(nrows * ncols);
 
     j = 0;			/* make pairwise comparation and built regime matrix */
-    for (row1 = 0; row1 < nrows; row1++) {
-	for (col1 = 0; col1 < ncols; col1++) {
-	    for (row2 = 0; row2 < nrows; row2++) {
-		for (col2 = 0; col2 < ncols; col2++) {
-		    double reg = 0;
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            for (row2 = 0; row2 < nrows; row2++)
+            {
+                for (col2 = 0; col2 < ncols; col2++)
+                {
+                    double reg = 0;
 
-		    for (i = 0; i < ncriteria; i++) {
-			double d =
-			    decision_vol[row1][col1][i] -
-			    decision_vol[row2][col2][i];
-			if (d > 0)
-			    reg += (1 * weight_vect[i]);
-			else if (d < 0)
-			    reg += (-1 * weight_vect[i]);
-			else
-			    reg += 0;
-		    }
-		    row_sum_regime[j] += reg;
-		}
-	    }
-	    j++;		/* increase rows index up to nrows*ncols */
-	}
-	G_percent(row1, nrows, 1);
+                    for (i = 0; i < ncriteria; i++)
+                    {
+                        double d =
+                            decision_vol[row1][col1][i] -
+                            decision_vol[row2][col2][i];
+                        if (d > 0)
+                            reg += (1 * weight_vect[i]);
+                        else if (d < 0)
+                            reg += (-1 * weight_vect[i]);
+                        else
+                            reg += 0;
+                    }
+                    row_sum_regime[j] += reg;
+                }
+            }
+            j++;		/* increase rows index up to nrows*ncols */
+        }
+        G_percent(row1, nrows, 1);
     }
 
     /*calculate concordance and discordance index and storage in decision_vol */
     cont = 0;
-    for (row1 = 0; row1 < nrows; row1++) {
-	for (col1 = 0; col1 < ncols; col1++) {
-	    decision_vol[row1][col1][ncriteria] = row_sum_regime[cont] / (nrows * ncols - 1);	/*fill matrix with regime index for each DCELL */
-	    cont++;
-	}
-	G_percent(row1, nrows, 2);
+    for (row1 = 0; row1 < nrows; row1++)
+    {
+        for (col1 = 0; col1 < ncols; col1++)
+        {
+            decision_vol[row1][col1][ncriteria] = row_sum_regime[cont] / (nrows * ncols - 1);	/*fill matrix with regime index for each DCELL */
+            cont++;
+        }
+        G_percent(row1, nrows, 2);
     }
 }

Modified: grass-addons/raster/mcda/r.roughset/main.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/main.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/main.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *		 		G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *		 		G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *		 		Rough Set Library (RSL) ver. 2 original develop:
- *		 		M.Gawrys - J.Sienkiewicz 
+ *		 		M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -64,7 +64,7 @@
     attr_map->multiple = YES;
     attr_map->gisprompt = "old,cell,raster";
     attr_map->description =
-	_("Input geographics ATTRIBUTES in information system");
+        _("Input geographics ATTRIBUTES in information system");
 
     dec_map = G_define_option();
     dec_map->key = "decision";
@@ -72,7 +72,7 @@
     dec_map->required = NO;
     dec_map->gisprompt = "old,cell,raster";
     dec_map->description =
-	_("Input geographics DECISION in information system");
+        _("Input geographics DECISION in information system");
 
     genrules = G_define_option();
     genrules->key = "strgy";
@@ -88,7 +88,7 @@
     dec_txt->required = NO;
     dec_txt->gisprompt = "old_file,file,input";
     dec_txt->description =
-	_("Input text file  with  data and decision sample");
+        _("Input text file  with  data and decision sample");
 
     clssfy = G_define_option();
     clssfy->key = "clssfy";
@@ -97,7 +97,7 @@
     clssfy->options = "Classify1,Classify2,Classify3";
     clssfy->answer = "Classify1";
     clssfy->description =
-	_("Strategies for classified map (conflict resolution)");
+        _("Strategies for classified map (conflict resolution)");
 
     output_txt = G_define_option();
     output_txt->key = "outTXT";
@@ -117,22 +117,23 @@
 
     /* options and flags parser */
     if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
+        exit(EXIT_FAILURE);
 
     /* Either decision map or sample file are necesary */
     if (dec_map->answer == NULL && dec_txt->answer == NULL)
-	G_fatal_error(_("Either decision map or sample file are necessary!"));
+        G_fatal_error(_("Either decision map or sample file are necessary!"));
 
-/***********************************************************************/
+    /***********************************************************************/
 
-/********Prepare and controlling Information System files **************/
+    /********Prepare and controlling Information System files **************/
 
-/***********************************************************************/
+    /***********************************************************************/
 
     /* number of file (=attributes) */
     nattributes = 0;
-    while (attr_map->answers[nattributes] != NULL) {
-	nattributes++;
+    while (attr_map->answers[nattributes] != NULL)
+    {
+        nattributes++;
     }
 
     /* store output classified MAP name in variable */
@@ -140,58 +141,59 @@
 
     /*Convert strategy rules extraction answer in index.  strcmp return 0 if answer is the passed string */
     if (strcmp(genrules->answer, "Very fast") == 0)
-	strgy = 0;
+        strgy = 0;
     else if (strcmp(genrules->answer, "Fast") == 0)
-	strgy = 1;
+        strgy = 1;
     else if (strcmp(genrules->answer, "Medium") == 0)
-	strgy = 2;
+        strgy = 2;
     else if (strcmp(genrules->answer, "Best") == 0)
-	strgy = 3;
+        strgy = 3;
     else if (strcmp(genrules->answer, "All") == 0)
-	strgy = 4;
+        strgy = 4;
     else if (strcmp(genrules->answer, "Low") == 0)
-	strgy = 5;
+        strgy = 5;
     else if (strcmp(genrules->answer, "Upp") == 0)
-	strgy = 6;
+        strgy = 6;
     else
-	strgy = 7;
+        strgy = 7;
 
     /*Convert strategy map lassify answer in index.  strcmp return 0 if answer is the passed string */
 
     if (strcmp(clssfy->answer, "Classify1") == 0)
-	cls = 0;
+        cls = 0;
     else if (strcmp(clssfy->answer, "Classify2") == 0)
-	cls = 1;
+        cls = 1;
     else if (strcmp(clssfy->answer, "Classify3") == 0)
-	cls = 2;
+        cls = 2;
     else
-	cls = 0;
+        cls = 0;
 
 
     /* process the input maps: */
     /* ATTRIBUTES grid */
     attributes = G_malloc((nattributes + 1) * sizeof(struct input));	/*attributes is input struct defined in localproto.h */
 
-    for (i = 0; i < nattributes; i++) {
-	struct input *p = &attributes[i];
+    for (i = 0; i < nattributes; i++)
+    {
+        struct input *p = &attributes[i];
 
-	p->name = attr_map->answers[i];
-	p->mapset = G_find_cell(p->name, "");	/* G_find_cell: Looks for the raster map "name" in the database. */
+        p->name = attr_map->answers[i];
+        p->mapset = G_find_cell(p->name, "");	/* G_find_cell: Looks for the raster map "name" in the database. */
 
-	p->fd = G_open_cell_old(p->name, p->mapset);
+        p->fd = G_open_cell_old(p->name, p->mapset);
 
-	if (!p->mapset)
-	    G_fatal_error(_("Raster file <%s> not found"), p->name);
+        if (!p->mapset)
+            G_fatal_error(_("Raster file <%s> not found"), p->name);
 
-	if (p->fd < 0)
-	    G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
-			  p->name, p->mapset);
+        if (p->fd < 0)
+            G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+                          p->name, p->mapset);
 
-	if (CELL_TYPE != G_raster_map_type(p->name, p->mapset))
-	    G_fatal_error(_("Input map <%s> in mapset <%s> isn't CELL type"),
-			  p->name, p->mapset);
+        if (CELL_TYPE != G_raster_map_type(p->name, p->mapset))
+            G_fatal_error(_("Input map <%s> in mapset <%s> isn't CELL type"),
+                          p->name, p->mapset);
 
-	p->buf = G_allocate_c_raster_buf();	/* Allocate an array of CELL based on the number of columns in the current region. Return DCELL *  */
+        p->buf = G_allocate_c_raster_buf();	/* Allocate an array of CELL based on the number of columns in the current region. Return DCELL *  */
 
     }
 
@@ -205,20 +207,21 @@
 
 
     /* DECISION grid (at last column in Information System matrix) */
-    if (dec_map->answer != NULL) {
-	struct input *p = &attributes[nattributes];
+    if (dec_map->answer != NULL)
+    {
+        struct input *p = &attributes[nattributes];
 
-	p->name = dec_map->answer;
-	p->mapset = G_find_cell(p->name, "");	/* G_find_cell: Looks for the raster map "name" in the database. */
-	if (!p->mapset)
-	    G_fatal_error(_("Raster file <%s> not found"), p->name);
-	p->fd = G_open_cell_old(p->name, p->mapset);	/*opens the raster file name in mapset for reading. A nonnegative file descriptor is returned if the open is successful. */
-	if (p->fd < 0)
-	    G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
-			  p->name, p->mapset);
-	p->buf = G_allocate_raster_buf(data_type);	/* Allocate an array of DCELL based on the number of columns in the current region. 
+        p->name = dec_map->answer;
+        p->mapset = G_find_cell(p->name, "");	/* G_find_cell: Looks for the raster map "name" in the database. */
+        if (!p->mapset)
+            G_fatal_error(_("Raster file <%s> not found"), p->name);
+        p->fd = G_open_cell_old(p->name, p->mapset);	/*opens the raster file name in mapset for reading. A nonnegative file descriptor is returned if the open is successful. */
+        if (p->fd < 0)
+            G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+                          p->name, p->mapset);
+        p->buf = G_allocate_raster_buf(data_type);	/* Allocate an array of DCELL based on the number of columns in the current region.
 							   Return DCELL *  */
-	rough_set_library_out(nrows, ncols, nattributes, attributes, output_txt->answer);	/*build RSL standard file */
+        rough_set_library_out(nrows, ncols, nattributes, attributes, output_txt->answer);	/*build RSL standard file */
     }
 
 
@@ -228,35 +231,37 @@
 
     /* controlling, if we can write the raster */
     if ((outfd = G_open_raster_new(result, CELL_TYPE)) < 0)
-	G_fatal_error(_("Unable to create raster map <%s>"), result);
+        G_fatal_error(_("Unable to create raster map <%s>"), result);
 
     /* generate classified map */
     G_message("Building calssified map...");
     j = 0;			/* builder map index */
-    for (row = 0; row < nrows; row++) {
-	CELL c;
+    for (row = 0; row < nrows; row++)
+    {
+        CELL c;
 
-	G_percent(row, nrows, 2);
-	for (col = 0; col < ncols; col++) {
-	    c = ((CELL *) classify_vect[j]);
-	    ((CELL *) outrast)[col] = c;
-	    j++;
-	}
+        G_percent(row, nrows, 2);
+        for (col = 0; col < ncols; col++)
+        {
+            c = ((CELL *) classify_vect[j]);
+            ((CELL *) outrast)[col] = c;
+            j++;
+        }
 
-	if (G_put_raster_row(outfd, outrast, data_type) < 0)
-	    G_fatal_error(_("Failed writing raster map <%s>"), result);
+        if (G_put_raster_row(outfd, outrast, data_type) < 0)
+            G_fatal_error(_("Failed writing raster map <%s>"), result);
     }
 
 
     /* memory cleanup */
     for (i = 0; i <= nattributes; i++)
-	G_close_cell(attributes[i].fd);
+        G_close_cell(attributes[i].fd);
     G_close_cell(outfd);
 
     for (i = 0; i < nattributes; i++)
-	G_free(attributes[i].buf);
+        G_free(attributes[i].buf);
 
-    //G_free(outrast);      
+    //G_free(outrast);
 
     G_message("End: %s, with %d cells.", G_date(), j);
     /* add command line incantation to history file */

Modified: grass-addons/raster/mcda/r.roughset/raccess.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/raccess.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/raccess.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *			G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *			G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *			Rough Set Library (RSL) ver. 2 original develop:
- *		        M.Gawrys - J.Sienkiewicz 
+ *		        M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -15,21 +15,15 @@
  *   	    	 License (>=v2). Read the file COPYING that comes with GRASS
  *   	    	 for details.
  *
- *****************************************************************************/
+ *****************************************************************************
 
-/***                                                                       ***/
+            FUNCTION OF ACCESS TO SYSTEM TABLES
 
-/***            FUNCTION OF ACCESS TO SYSTEM TABLES                        ***/
+ part of the ROUGH system written by M.Gawrys J. Sienkiewicz
 
-/***                                                                       ***/
+****************************************************************************/
 
-/*** part of the ROUGH system written by M.Gawrys J. Sienkiewicz           ***/
 
-/***                                                                       ***/
-
-/*****************************************************************************/
-
-
 #include "rough.h"
 
 setA _table_element = NULL;
@@ -43,7 +37,7 @@
 void next_of_d(void)
 {
     if (++_table_column >= _table_row)
-	_table_column = 0, _table_row++;
+        _table_column = 0, _table_row++;
     _table_element = (_mainsys->matD) + (_mainsys->setAsize * ++_table_no);
 }
 
@@ -56,14 +50,16 @@
 void next_of_a(void)
 {
     ++_table_no;
-    if (++_table_column >= _table_row) {
-	_table_column = 0;
-	if (++_table_row >= _mainsys->objects_num) {
-	    CloseSetA(_table_element);
-	    _table_end = _table_element;
-	    _table_row = 0;
-	    return;
-	}
+    if (++_table_column >= _table_row)
+    {
+        _table_column = 0;
+        if (++_table_row >= _mainsys->objects_num)
+        {
+            CloseSetA(_table_element);
+            _table_end = _table_element;
+            _table_row = 0;
+            return;
+        }
     }
     GetDfromA(_table_element, _table_row, _table_column);
     return;
@@ -72,31 +68,34 @@
 
 int start_of_tab(int matrix_type)
 {
-    if (matrix_type == MATD) {
-	_table_no = 0;
-	_table_row = 1;
-	_table_column = 0;
-	_table_element = _mainsys->matD;
-	_table_end = _table_element + Dsize(_mainsys);
-	_current_next = next_of_d;
+    if (matrix_type == MATD)
+    {
+        _table_no = 0;
+        _table_row = 1;
+        _table_column = 0;
+        _table_element = _mainsys->matD;
+        _table_end = _table_element + Dsize(_mainsys);
+        _current_next = next_of_d;
     }
-    else if (matrix_type == MATX) {
-	START_OF_X;
-	_table_no = 0;
-	_current_next = next_of_x;
+    else if (matrix_type == MATX)
+    {
+        START_OF_X;
+        _table_no = 0;
+        _current_next = next_of_x;
     }
-    else if (matrix_type == MATA) {
-	_table_no = 0;
-	_table_row = 0;
-	_table_column = 0;
-	_table_element = InitEmptySetA();
-	_table_end = _table_element + 1;
-	_current_next = next_of_a;
-	next_of_a();
+    else if (matrix_type == MATA)
+    {
+        _table_no = 0;
+        _table_row = 0;
+        _table_column = 0;
+        _table_element = InitEmptySetA();
+        _table_end = _table_element + 1;
+        _current_next = next_of_a;
+        next_of_a();
     }
     if (_table_element == NULL)
-	ERROR(3)
-	    return (1);
+        ERROR(3)
+        return (1);
 }
 
 int end_of_tab(void)
@@ -114,13 +113,14 @@
 {
     int pom;
 
-    if (ob2 > ob1) {
-	pom = ob1;
-	ob1 = ob2;
-	ob2 = pom;
+    if (ob2 > ob1)
+    {
+        pom = ob1;
+        ob1 = ob2;
+        ob2 = pom;
     }
     return (_mainsys->matD) + ((ob1 - 1) * ob1 / 2 +
-			       ob2) * _mainsys->setAsize;
+                               ob2) * _mainsys->setAsize;
 }
 
 value_type GetA(int ob, int atr)
@@ -137,29 +137,31 @@
     cluster_type val;
     int cluster, bit;
 
-    for (cluster = 0; cluster < nby; cluster++) {
-	val = 0;
-	for (bit = 0; bit < _cluster_bits; bit++)
-	    if (A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
-		A[obj2 * atrnum + _cluster_bits * cluster + bit] &&
-		A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
-		(value_type) - 1 &&
-		A[obj2 * atrnum + _cluster_bits * cluster + bit] !=
-		(value_type) - 1)
-		val = val | _mask[bit];
-	elem[cluster] = val;
+    for (cluster = 0; cluster < nby; cluster++)
+    {
+        val = 0;
+        for (bit = 0; bit < _cluster_bits; bit++)
+            if (A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
+                    A[obj2 * atrnum + _cluster_bits * cluster + bit] &&
+                    A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
+                    (value_type) - 1 &&
+                    A[obj2 * atrnum + _cluster_bits * cluster + bit] !=
+                    (value_type) - 1)
+                val = val | _mask[bit];
+        elem[cluster] = val;
     }
-    if (nbi) {
-	val = 0;
-	for (bit = 0; bit < nbi; bit++)
-	    if (A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
-		A[obj2 * atrnum + _cluster_bits * cluster + bit] &&
-		A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
-		(value_type) - 1 &&
-		A[obj2 * atrnum + _cluster_bits * cluster + bit] !=
-		(value_type) - 1)
-		val = val | _mask[bit];
-	elem[cluster] = val;
+    if (nbi)
+    {
+        val = 0;
+        for (bit = 0; bit < nbi; bit++)
+            if (A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
+                    A[obj2 * atrnum + _cluster_bits * cluster + bit] &&
+                    A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
+                    (value_type) - 1 &&
+                    A[obj2 * atrnum + _cluster_bits * cluster + bit] !=
+                    (value_type) - 1)
+                val = val | _mask[bit];
+        elem[cluster] = val;
     }
     return 1;
 }
@@ -169,17 +171,17 @@
     int attr;
 
     for (attr = 0; attr < _mainsys->attributes_num; attr++)
-	if (ContSetA(P, attr))
-	    if ((_mainsys->matA)[ob1 * (_mainsys->attributes_num) + attr] ==
-		(value_type) - 1 ||
-		(_mainsys->matA)[ob2 * (_mainsys->attributes_num) + attr] ==
-		(value_type) - 1)
-		continue;
-	    else if ((_mainsys->matA)[ob1 * (_mainsys->attributes_num) +
-				      attr] !=
-		     (_mainsys->matA)[ob2 * (_mainsys->attributes_num) +
-				      attr])
-		return 0;
+        if (ContSetA(P, attr))
+            if ((_mainsys->matA)[ob1 * (_mainsys->attributes_num) + attr] ==
+                    (value_type) - 1 ||
+                    (_mainsys->matA)[ob2 * (_mainsys->attributes_num) + attr] ==
+                    (value_type) - 1)
+                continue;
+            else if ((_mainsys->matA)[ob1 * (_mainsys->attributes_num) +
+                                      attr] !=
+                     (_mainsys->matA)[ob2 * (_mainsys->attributes_num) +
+                                      attr])
+                return 0;
     return 1;
 }
 
@@ -189,40 +191,42 @@
     int cluster;
     setA elem;
 
-    if (ob2 > ob1) {
-	pom = ob1;
-	ob1 = ob2;
-	ob2 = pom;
+    if (ob2 > ob1)
+    {
+        pom = ob1;
+        ob1 = ob2;
+        ob2 = pom;
     }
     elem =
-	(_mainsys->matD) + ((ob1 - 1) * ob1 / 2 + ob2) * (_mainsys->setAsize);
+        (_mainsys->matD) + ((ob1 - 1) * ob1 / 2 + ob2) * (_mainsys->setAsize);
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	if (elem[cluster] & P[cluster])
-	    return 0;
+        if (elem[cluster] & P[cluster])
+            return 0;
     return 1;
 }
 
 int SingCompA(int ob1, int ob2, int atr)
 {
     return ((_mainsys->matA)[ob1 * (_mainsys->attributes_num) + atr] ==
-	    (_mainsys->matA)[ob2 * (_mainsys->attributes_num) + atr] ||
-	    (_mainsys->matA)[ob1 * (_mainsys->attributes_num) + atr] ==
-	    (value_type) - 1 ||
-	    (_mainsys->matA)[ob2 * (_mainsys->attributes_num) + atr] ==
-	    (value_type) - 1);
+            (_mainsys->matA)[ob2 * (_mainsys->attributes_num) + atr] ||
+            (_mainsys->matA)[ob1 * (_mainsys->attributes_num) + atr] ==
+            (value_type) - 1 ||
+            (_mainsys->matA)[ob2 * (_mainsys->attributes_num) + atr] ==
+            (value_type) - 1);
 }
 
 int SingCompD(int ob1, int ob2, int atr)
 {
     int pom;
 
-    if (ob2 > ob1) {
-	pom = ob1;
-	ob1 = ob2;
-	ob2 = pom;
+    if (ob2 > ob1)
+    {
+        pom = ob1;
+        ob1 = ob2;
+        ob2 = pom;
     }
     return !((_mainsys->matD)[((ob1 - 1) * ob1 / 2 + ob2)
-			      * (_mainsys->setAsize) +
-			      atr / _cluster_bits] & _mask[atr %
-							   _cluster_bits]);
+                              * (_mainsys->setAsize) +
+                              atr / _cluster_bits] & _mask[atr %
+                                                           _cluster_bits]);
 }

Modified: grass-addons/raster/mcda/r.roughset/rbasic.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rbasic.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/rbasic.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,17 +16,11 @@
  *   	    	 for details.
  *
  *****************************************************************************/
-
 /***                                                                       ***/
-
 /***               BASIC QUERIES FOR ACTIVE SYSTEM                         ***/
-
 /***                                                                       ***/
-
 /***  part of the RSL system written by M.Gawrys J.Sienkiewicz             ***/
-
 /***                                                                       ***/
-
 /*****************************************************************************/
 
 
@@ -34,13 +28,14 @@
 
 int LowAppr(setO lowappr, setO X, setA P, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return LowApprA(lowappr, X, P);
+        return LowApprA(lowappr, X, P);
     case MATD:
-	return LowApprD(lowappr, X, P);
+        return LowApprD(lowappr, X, P);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -50,22 +45,24 @@
     int ob1, ob2, disc;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     notX = InitEmptySetO();
     ClearSetO(lowappr);
     NotSetO(notX, X);
     for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
-	if (ContSetO(X, ob1)) {
-	    disc = 1;
-	    for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
-		if (ContSetO(notX, ob2))
-		    if (CompareA(ob1, ob2, P)) {
-			disc = 0;
-			break;
-		    }
-	    if (disc)
-		AddSetO(lowappr, ob1);
-	}
+        if (ContSetO(X, ob1))
+        {
+            disc = 1;
+            for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+                if (ContSetO(notX, ob2))
+                    if (CompareA(ob1, ob2, P))
+                    {
+                        disc = 0;
+                        break;
+                    }
+            if (disc)
+                AddSetO(lowappr, ob1);
+        }
     CloseSetO(notX);
     return 0;
 }
@@ -76,35 +73,38 @@
     int ob1, ob2, disc;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     notX = InitEmptySetO();
     ClearSetO(lowappr);
     NotSetO(notX, X);
     for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
-	if (ContSetO(X, ob1)) {
-	    disc = 1;
-	    for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
-		if (ContSetO(notX, ob2))
-		    if (CompareD(ob1, ob2, P)) {
-			disc = 0;
-			break;
-		    }
-	    if (disc)
-		AddSetO(lowappr, ob1);
-	}
+        if (ContSetO(X, ob1))
+        {
+            disc = 1;
+            for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+                if (ContSetO(notX, ob2))
+                    if (CompareD(ob1, ob2, P))
+                    {
+                        disc = 0;
+                        break;
+                    }
+            if (disc)
+                AddSetO(lowappr, ob1);
+        }
     CloseSetO(notX);
     return 0;
 }
 
 int UppAppr(setO uppappr, setO X, setA P, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return UppApprA(uppappr, X, P);
+        return UppApprA(uppappr, X, P);
     case MATD:
-	return UppApprD(uppappr, X, P);
+        return UppApprD(uppappr, X, P);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -114,16 +114,16 @@
     int ob1, ob2;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     CopySetO(uppappr, X);
     notX = InitEmptySetO();
     NotSetO(notX, X);
     for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
-	if (ContSetO(X, ob1))
-	    for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
-		if (ContSetO(notX, ob2))
-		    if (CompareA(ob1, ob2, P))
-			AddSetO(uppappr, ob2);
+        if (ContSetO(X, ob1))
+            for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+                if (ContSetO(notX, ob2))
+                    if (CompareA(ob1, ob2, P))
+                        AddSetO(uppappr, ob2);
     CloseSetO(notX);
     return 0;
 }
@@ -134,29 +134,30 @@
     int ob1, ob2;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     CopySetO(uppappr, X);
     notX = InitEmptySetO();
     NotSetO(notX, X);
     for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
-	if (ContSetO(X, ob1))
-	    for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
-		if (ContSetO(notX, ob2))
-		    if (CompareD(ob1, ob2, P))
-			AddSetO(uppappr, ob2);
+        if (ContSetO(X, ob1))
+            for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+                if (ContSetO(notX, ob2))
+                    if (CompareD(ob1, ob2, P))
+                        AddSetO(uppappr, ob2);
     CloseSetO(notX);
     return 0;
 }
 
 int Bound(setO bound, setO X, setA P, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return BoundA(bound, X, P);
+        return BoundA(bound, X, P);
     case MATD:
-	return BoundD(bound, X, P);
+        return BoundD(bound, X, P);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -165,7 +166,7 @@
     setO lower, upper;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     lower = InitEmptySetO();
     upper = InitEmptySetO();
     LowApprA(lower, X, P);
@@ -181,7 +182,7 @@
     setO lower, upper;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     lower = InitEmptySetO();
     upper = InitEmptySetO();
     LowApprD(lower, X, P);
@@ -194,13 +195,14 @@
 
 float AccurCoef(setO X, setA P, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return AccurCoefA(X, P);
+        return AccurCoefA(X, P);
     case MATD:
-	return AccurCoefD(X, P);
+        return AccurCoefD(X, P);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -210,7 +212,7 @@
     float coef;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     lower = InitEmptySetO();
     upper = InitEmptySetO();
     LowApprA(lower, X, P);
@@ -227,7 +229,7 @@
     float coef;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     lower = InitEmptySetO();
     upper = InitEmptySetO();
     LowApprD(lower, X, P);
@@ -240,13 +242,14 @@
 
 float ClassCoef(setO X, setA P, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return ClassCoefA(X, P);
+        return ClassCoefA(X, P);
     case MATD:
-	return ClassCoefD(X, P);
+        return ClassCoefD(X, P);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -257,17 +260,18 @@
     int ob1, ob2;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     notX = InitEmptySetO();
     pos = InitFullSetO();
     NotSetO(notX, X);
     for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
-	for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
-	    if (ContSetO(X, ob1) && ContSetO(notX, ob2) &&
-		CompareA(ob1, ob2, P)) {
-		DelSetO(pos, ob1);
-		DelSetO(pos, ob2);
-	    }
+        for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+            if (ContSetO(X, ob1) && ContSetO(notX, ob2) &&
+                    CompareA(ob1, ob2, P))
+            {
+                DelSetO(pos, ob1);
+                DelSetO(pos, ob2);
+            }
     coef = (float)CardSetO(pos) / _mainsys->objects_num;
     CloseSetO(notX);
     CloseSetO(pos);
@@ -281,17 +285,18 @@
     int ob1, ob2;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     notX = InitEmptySetO();
     pos = InitFullSetO();
     NotSetO(notX, X);
     for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
-	for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
-	    if (ContSetO(X, ob1) && ContSetO(notX, ob2) &&
-		CompareD(ob1, ob2, P)) {
-		DelSetO(pos, ob1);
-		DelSetO(pos, ob2);
-	    }
+        for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+            if (ContSetO(X, ob1) && ContSetO(notX, ob2) &&
+                    CompareD(ob1, ob2, P))
+            {
+                DelSetO(pos, ob1);
+                DelSetO(pos, ob2);
+            }
     CloseSetO(notX);
     coef = (float)CardSetO(pos) / _mainsys->objects_num;
     CloseSetO(pos);
@@ -300,13 +305,14 @@
 
 int Pos(setO pos, setA P, setA Q, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return PosA(pos, P, Q);
+        return PosA(pos, P, Q);
     case MATD:
-	return PosD(pos, P, Q);
+        return PosD(pos, P, Q);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -316,22 +322,24 @@
     setA redQ;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
-    if (IsEmptySetA(P)) {
-	ClearSetO(pos);
-	return 0;
+        ERROR(5);
+    if (IsEmptySetA(P))
+    {
+        ClearSetO(pos);
+        return 0;
     }
     redQ = InitEmptySetA();
     DifSetA(redQ, Q, P);
     FillSetO(pos);
     if (IsEmptySetA(redQ))
-	return 0;
+        return 0;
     for (i = _mainsys->objects_num - 1; i > 0; i--)
-	for (j = i - 1; j >= 0; j--)
-	    if (!CompareA(i, j, redQ) && CompareA(i, j, P)) {
-		DelSetO(pos, i);
-		DelSetO(pos, j);
-	    }
+        for (j = i - 1; j >= 0; j--)
+            if (!CompareA(i, j, redQ) && CompareA(i, j, P))
+            {
+                DelSetO(pos, i);
+                DelSetO(pos, j);
+            }
     return 0;
 }
 
@@ -341,37 +349,41 @@
     setA elem, redQ;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
-    if (IsEmptySetA(P)) {
-	ClearSetO(pos);
-	return 0;
+        ERROR(6);
+    if (IsEmptySetA(P))
+    {
+        ClearSetO(pos);
+        return 0;
     }
     redQ = InitEmptySetA();
     DifSetA(redQ, Q, P);
     FillSetO(pos);
     if (IsEmptySetA(redQ))
-	return 0;
+        return 0;
     for (i = _mainsys->objects_num - 1; i > 0; i--)
-	for (j = i - 1; j >= 0; j--) {
-	    elem = GetD(i, j);
-	    if (InterSetA(elem, redQ) && !InterSetA(elem, P)) {
-		DelSetO(pos, i);
-		DelSetO(pos, j);
-	    }
-	}
+        for (j = i - 1; j >= 0; j--)
+        {
+            elem = GetD(i, j);
+            if (InterSetA(elem, redQ) && !InterSetA(elem, P))
+            {
+                DelSetO(pos, i);
+                DelSetO(pos, j);
+            }
+        }
     CloseSetA(redQ);
     return 0;
 }
 
 float DependCoef(setA P, setA Q, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return DependCoefA(P, Q);
+        return DependCoefA(P, Q);
     case MATD:
-	return DependCoefD(P, Q);
+        return DependCoefD(P, Q);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -381,7 +393,7 @@
     float coef;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     pos = InitEmptySetO();
     PosA(pos, P, Q);
     coef = (float)CardSetO(pos) / (float)_mainsys->objects_num;
@@ -395,7 +407,7 @@
     float coef;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     pos = InitEmptySetO();
     PosD(pos, P, Q);
     coef = (float)CardSetO(pos) / (float)_mainsys->objects_num;
@@ -405,13 +417,14 @@
 
 float SignifCoef(int attr, setA P, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return SignifCoefA(attr, P);
+        return SignifCoefA(attr, P);
     case MATD:
-	return SignifCoefD(attr, P);
+        return SignifCoefD(attr, P);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -423,27 +436,29 @@
     float coef;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     if (IsEmptySetA(P) || !ContSetA(P, attr))
-	return 0;
+        return 0;
     pos1 = InitFullSetO();
     pos2 = InitFullSetO();
     Pprim = InitEmptySetA();
     CopySetA(Pprim, P);
     DelSetA(Pprim, attr);
     for (i = _mainsys->objects_num - 1; i > 0; i--)
-	for (j = i - 1; j >= 0; j--)
-	    if (CompareA(i, j, P)) {
-		DelSetO(pos1, i);
-		DelSetO(pos2, i);
-		DelSetO(pos1, j);
-		DelSetO(pos2, j);
-		continue;
-	    }
-	    else if (CompareA(i, j, Pprim)) {
-		DelSetO(pos2, i);
-		DelSetO(pos2, j);
-	    }
+        for (j = i - 1; j >= 0; j--)
+            if (CompareA(i, j, P))
+            {
+                DelSetO(pos1, i);
+                DelSetO(pos2, i);
+                DelSetO(pos1, j);
+                DelSetO(pos2, j);
+                continue;
+            }
+            else if (CompareA(i, j, Pprim))
+            {
+                DelSetO(pos2, i);
+                DelSetO(pos2, j);
+            }
     DifSetO(pos1, pos1, pos2);
     coef = (float)CardSetO(pos1) / (float)_mainsys->objects_num;
     CloseSetO(pos1);
@@ -460,29 +475,32 @@
     float coef;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     if (IsEmptySetA(P) || !ContSetA(P, attr))
-	return 0;
+        return 0;
     pos1 = InitFullSetO();
     pos2 = InitFullSetO();
     Pprim = InitEmptySetA();
     CopySetA(Pprim, P);
     DelSetA(Pprim, attr);
     for (i = _mainsys->objects_num - 1; i > 0; i--)
-	for (j = i - 1; j >= 0; j--) {
-	    elem = GetD(i, j);
-	    if (!InterSetA(elem, P)) {
-		DelSetO(pos1, i);
-		DelSetO(pos2, i);
-		DelSetO(pos1, j);
-		DelSetO(pos2, j);
-		continue;
-	    }
-	    if (!InterSetA(elem, Pprim)) {
-		DelSetO(pos2, i);
-		DelSetO(pos2, j);
-	    }
-	}
+        for (j = i - 1; j >= 0; j--)
+        {
+            elem = GetD(i, j);
+            if (!InterSetA(elem, P))
+            {
+                DelSetO(pos1, i);
+                DelSetO(pos2, i);
+                DelSetO(pos1, j);
+                DelSetO(pos2, j);
+                continue;
+            }
+            if (!InterSetA(elem, Pprim))
+            {
+                DelSetO(pos2, i);
+                DelSetO(pos2, j);
+            }
+        }
     DifSetO(pos1, pos1, pos2);
     coef = (float)CardSetO(pos1) / (float)_mainsys->objects_num;
     CloseSetO(pos1);
@@ -493,13 +511,14 @@
 
 float SignifRelCoef(int attr, setA P, setA Q, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return SignifRelCoefA(attr, P, Q);
+        return SignifRelCoefA(attr, P, Q);
     case MATD:
-	return SignifRelCoefD(attr, P, Q);
+        return SignifRelCoefD(attr, P, Q);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -511,33 +530,35 @@
     float coef;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     Pprim = InitEmptySetA();
     redQ = InitEmptySetA();
     CopySetA(Pprim, P);
     DelSetA(Pprim, attr);
     DifSetA(redQ, Q, Pprim);
     if (IsEmptySetA(P) || !ContSetA(P, attr))
-	return 0;
+        return 0;
     if (IsEmptySetA(redQ))
-	return 1;
+        return 1;
     pos1 = InitFullSetO();
     pos2 = InitFullSetO();
     for (i = _mainsys->objects_num - 1; i > 0; i--)
-	for (j = i - 1; j >= 0; j--)
-	    if (CompareA(i, j, redQ))
-		continue;
-	    else if (CompareA(i, j, P)) {
-		DelSetO(pos1, i);
-		DelSetO(pos2, i);
-		DelSetO(pos1, j);
-		DelSetO(pos2, j);
-		continue;
-	    }
-	    else if (CompareA(i, j, Pprim)) {
-		DelSetO(pos2, i);
-		DelSetO(pos2, j);
-	    }
+        for (j = i - 1; j >= 0; j--)
+            if (CompareA(i, j, redQ))
+                continue;
+            else if (CompareA(i, j, P))
+            {
+                DelSetO(pos1, i);
+                DelSetO(pos2, i);
+                DelSetO(pos1, j);
+                DelSetO(pos2, j);
+                continue;
+            }
+            else if (CompareA(i, j, Pprim))
+            {
+                DelSetO(pos2, i);
+                DelSetO(pos2, j);
+            }
     DifSetO(pos1, pos1, pos2);
     coef = (float)CardSetO(pos1) / (float)_mainsys->objects_num;
     CloseSetO(pos1);
@@ -555,35 +576,38 @@
     float coef;
 
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     Pprim = InitEmptySetA();
     redQ = InitEmptySetA();
     CopySetA(Pprim, P);
     DelSetA(Pprim, attr);
     DifSetA(redQ, Q, Pprim);
     if (IsEmptySetA(P) || !ContSetA(P, attr))
-	return 0;
+        return 0;
     if (IsEmptySetA(redQ))
-	return 1;
+        return 1;
     pos1 = InitFullSetO();
     pos2 = InitFullSetO();
     for (i = _mainsys->objects_num - 1; i > 0; i--)
-	for (j = i - 1; j >= 0; j--) {
-	    elem = GetD(i, j);
-	    if (!InterSetA(elem, redQ))
-		continue;
-	    if (!InterSetA(elem, P)) {
-		DelSetO(pos1, i);
-		DelSetO(pos2, i);
-		DelSetO(pos1, j);
-		DelSetO(pos2, j);
-		continue;
-	    }
-	    if (!InterSetA(elem, Pprim)) {
-		DelSetO(pos2, i);
-		DelSetO(pos2, j);
-	    }
-	}
+        for (j = i - 1; j >= 0; j--)
+        {
+            elem = GetD(i, j);
+            if (!InterSetA(elem, redQ))
+                continue;
+            if (!InterSetA(elem, P))
+            {
+                DelSetO(pos1, i);
+                DelSetO(pos2, i);
+                DelSetO(pos1, j);
+                DelSetO(pos2, j);
+                continue;
+            }
+            if (!InterSetA(elem, Pprim))
+            {
+                DelSetO(pos2, i);
+                DelSetO(pos2, j);
+            }
+        }
     DifSetO(pos1, pos1, pos2);
     coef = (float)CardSetO(pos1) / (float)_mainsys->objects_num;
     CloseSetO(pos1);
@@ -599,9 +623,9 @@
     int res = 0;
 
     for (start_of_tab(matrix_type); end_of_tab(); next_of_tab())
-	if (InterSetA(P, _table_element))
-	    res++;
+        if (InterSetA(P, _table_element))
+            res++;
     if (_rerror > 0)
-	return -_rerror;
+        return -_rerror;
     return res;
 }

Modified: grass-addons/raster/mcda/r.roughset/rclass.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rclass.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/rclass.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,19 +16,12 @@
  *   	    	 for details.
  *
  *****************************************************************************/
-
 /***                                                                       ***/
-
 /***               SOME MORE QUERIES FOR SYSTEM                            ***/
-
 /***                     ( CLASSIFICATION )                                ***/
-
 /***                                                                       ***/
-
 /***  part of the RSL system written by M.Gawrys J.Sienkiewicz             ***/
-
 /***                                                                       ***/
-
 /*****************************************************************************/
 
 
@@ -41,9 +34,9 @@
     int i;
 
     for (i = 0; i < _mainsys->attributes_num; i++)
-	if (ContSetA(Q, i))
-	    if (rule1[i] != rule2[i])
-		return 0;
+        if (ContSetA(Q, i))
+            if (rule1[i] != rule2[i])
+                return 0;
     return 1;
 }
 
@@ -52,16 +45,18 @@
 {
     int obj, attr, find, result = 0, size = _mainsys->attributes_num;
 
-    for (obj = 0; obj < _mainsys->objects_num; obj++) {
-	find = 1;
-	for (attr = 0; attr < size; attr++)
-	    if (rule[attr] != GetA(obj, attr))
-		if (rule[attr] != MINUS && GetA(obj, attr) != MINUS) {
-		    find = 0;
-		    break;
-		}
-	if (find)
-	    result++;
+    for (obj = 0; obj < _mainsys->objects_num; obj++)
+    {
+        find = 1;
+        for (attr = 0; attr < size; attr++)
+            if (rule[attr] != GetA(obj, attr))
+                if (rule[attr] != MINUS && GetA(obj, attr) != MINUS)
+                {
+                    find = 0;
+                    break;
+                }
+        if (find)
+            result++;
     }
     return result;
 }
@@ -72,10 +67,10 @@
     int i, size = _mainsys->attributes_num;
 
     if (N <= 0)
-	return NULL;
+        return NULL;
     result = (int *)calloc(N, sizeof(int));
     for (i = 0; i < N; i++)
-	result[i] = StrengthOfRule(rules + i * size);
+        result[i] = StrengthOfRule(rules + i * size);
     return result;
 }
 
@@ -84,16 +79,18 @@
 {
     int i, j, find, size = _mainsys->attributes_num;
 
-    for (i = 0; i < _mainsys->objects_num; i++) {
-	find = 1;
-	for (j = 0; j < size; j++)
-	    if (rule[j] != GetA(i, j))
-		if (rule[j] != MINUS && GetA(i, j) != MINUS) {
-		    find = 0;
-		    break;
-		}
-	if (find)
-	    AddSetO(set, i);
+    for (i = 0; i < _mainsys->objects_num; i++)
+    {
+        find = 1;
+        for (j = 0; j < size; j++)
+            if (rule[j] != GetA(i, j))
+                if (rule[j] != MINUS && GetA(i, j) != MINUS)
+                {
+                    find = 0;
+                    break;
+                }
+        if (find)
+            AddSetO(set, i);
     }
     return CardSetO(set);
 }
@@ -103,12 +100,13 @@
 {
     int j, result = 0, size = _mainsys->attributes_num;
 
-    for (j = 0; j < size; j++) {
-	if (!ContSetA(P, j))
-	    continue;
-	if (rule[j] != sample[j])
-	    if (rule[j] != MINUS && sample[j] != MINUS)
-		result++;
+    for (j = 0; j < size; j++)
+    {
+        if (!ContSetA(P, j))
+            continue;
+        if (rule[j] != sample[j])
+            if (rule[j] != MINUS && sample[j] != MINUS)
+                result++;
     }
     return result;
 }
@@ -120,10 +118,10 @@
     int i, size = _mainsys->attributes_num;
 
     if (N <= 0)
-	return NULL;
+        return NULL;
     result = (int *)calloc(N, sizeof(int));
     for (i = 0; i < N; i++)
-	result[i] = CompareToRule(sample, rules + i * size, P);
+        result[i] = CompareToRule(sample, rules + i * size, P);
     return result;
 }
 
@@ -131,30 +129,32 @@
 int Classify1(value_type * sample, value_type * rules, int N, setA P, setA Q)
 {
     int done = 0,
-	result = -1,
-	count = 0,
-	*diff, minDiff = _mainsys->attributes_num,
-	i, j = 0, max = 0, size = _mainsys->attributes_num;
+               result = -1,
+                        count = 0,
+                                *diff, minDiff = _mainsys->attributes_num,
+                                                 i, j = 0, max = 0, size = _mainsys->attributes_num;
     diff = CompareToRules(sample, rules, N, P);
     for (i = 0; i < N; i++)
-	if (diff[i] < minDiff)
-	    minDiff = diff[i];
-    while (!done) {		/* while there is an unprocessed rule */
-	while (diff[j] != minDiff)
-	    j++;		/* to find the rule with new decision */
-	done = 1;
-	diff[j]++;
-	count = 1;
-	for (i = j; i < N; i++)
-	    if (diff[i] == minDiff)
-		if (DecisionEQ(rules + i * size, rules + j * size, Q)) {
-		    diff[j]++;	/* to protect from next use */
-		    count++;
-		}
-		else
-		    done = 0;
-	if (count > max)
-	    max = count, result = j;
+        if (diff[i] < minDiff)
+            minDiff = diff[i];
+    while (!done)  		/* while there is an unprocessed rule */
+    {
+        while (diff[j] != minDiff)
+            j++;		/* to find the rule with new decision */
+        done = 1;
+        diff[j]++;
+        count = 1;
+        for (i = j; i < N; i++)
+            if (diff[i] == minDiff)
+                if (DecisionEQ(rules + i * size, rules + j * size, Q))
+                {
+                    diff[j]++;	/* to protect from next use */
+                    count++;
+                }
+                else
+                    done = 0;
+        if (count > max)
+            max = count, result = j;
     }
     free(diff);
     return result;
@@ -164,10 +164,10 @@
 int Classify2(value_type * sample, value_type * rules, int N, setA P, setA Q)
 {
     int i,
-	*diff,
-	first = 0, maxindex,
-	size = _mainsys->attributes_num,
-	minDiff = _mainsys->attributes_num, done = 0;
+    *diff,
+    first = 0, maxindex,
+            size = _mainsys->attributes_num,
+                   minDiff = _mainsys->attributes_num, done = 0;
     setO cover, maxcover, rulecover;
 
     cover = InitEmptySetO();
@@ -175,27 +175,30 @@
     rulecover = InitEmptySetO();
     diff = CompareToRules(sample, rules, N, P);
     for (i = 0; i < N; i++)
-	if (diff[i] < minDiff)
-	    minDiff = diff[i];
-    while (!done) {		/* while there is an unprocessed rule */
-	while (diff[first] != minDiff)
-	    first++;		/* to find the rule with new decision */
-	done = 1;
-	diff[first]++;		/* to protect from next use */
-	ObjectsForRule(cover, rules + first * size);
-	for (i = first; i < N; i++)
-	    if (diff[i] == minDiff)
-		if (DecisionEQ(rules + first * size, rules + i * size, Q)) {
-		    diff[i]++;
-		    ObjectsForRule(rulecover, rules + i * size);
-		    OrSetO(cover, cover, rulecover);
-		}
-		else
-		    done = 0;
-	if (CardSetO(maxcover) < CardSetO(cover)) {
-	    CopySetO(maxcover, cover);
-	    maxindex = first;
-	}
+        if (diff[i] < minDiff)
+            minDiff = diff[i];
+    while (!done)  		/* while there is an unprocessed rule */
+    {
+        while (diff[first] != minDiff)
+            first++;		/* to find the rule with new decision */
+        done = 1;
+        diff[first]++;		/* to protect from next use */
+        ObjectsForRule(cover, rules + first * size);
+        for (i = first; i < N; i++)
+            if (diff[i] == minDiff)
+                if (DecisionEQ(rules + first * size, rules + i * size, Q))
+                {
+                    diff[i]++;
+                    ObjectsForRule(rulecover, rules + i * size);
+                    OrSetO(cover, cover, rulecover);
+                }
+                else
+                    done = 0;
+        if (CardSetO(maxcover) < CardSetO(cover))
+        {
+            CopySetO(maxcover, cover);
+            maxindex = first;
+        }
     }
     free(diff);
     CloseSetO(cover);
@@ -205,37 +208,40 @@
 }
 
 int Classify3(value_type * sample, value_type * rules, int N,
-	      int *strength, setA P, setA Q)
+              int *strength, setA P, setA Q)
 {
     int i,
-	*diff,
-	first = 0, maxindex,
-	size = _mainsys->attributes_num,
-	minDiff = _mainsys->attributes_num, done = 0;
+    *diff,
+    first = 0, maxindex,
+            size = _mainsys->attributes_num,
+                   minDiff = _mainsys->attributes_num, done = 0;
     int cover, maxcover = 0;
 
     diff = CompareToRules(sample, rules, N, P);
     for (i = 0; i < N; i++)
-	if (diff[i] < minDiff)
-	    minDiff = diff[i];
-    while (!done) {		/* while there is an unprocessed rule */
-	while (diff[first] != minDiff)
-	    first++;		/* to find the rule with new decision */
-	done = 1;
-	diff[first]++;		/* to protect from next use */
-	cover = strength[first];
-	for (i = first; i < N; i++)
-	    if (diff[i] == minDiff)
-		if (DecisionEQ(rules + first * size, rules + i * size, Q)) {
-		    diff[i]++;
-		    cover += strength[i];
-		}
-		else
-		    done = 0;
-	if (maxcover < cover) {
-	    maxcover = cover;
-	    maxindex = first;
-	}
+        if (diff[i] < minDiff)
+            minDiff = diff[i];
+    while (!done)  		/* while there is an unprocessed rule */
+    {
+        while (diff[first] != minDiff)
+            first++;		/* to find the rule with new decision */
+        done = 1;
+        diff[first]++;		/* to protect from next use */
+        cover = strength[first];
+        for (i = first; i < N; i++)
+            if (diff[i] == minDiff)
+                if (DecisionEQ(rules + first * size, rules + i * size, Q))
+                {
+                    diff[i]++;
+                    cover += strength[i];
+                }
+                else
+                    done = 0;
+        if (maxcover < cover)
+        {
+            maxcover = cover;
+            maxindex = first;
+        }
     }
     free(diff);
     return maxindex;

Modified: grass-addons/raster/mcda/r.roughset/rcore.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rcore.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/rcore.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,19 +16,12 @@
  *   	    	 for details.
  *
  *****************************************************************************/
-
 /***                                                                       ***/
-
 /***               SOME MORE QUERIES FOR SYSTEM                            ***/
-
 /***          ( FINDING CORES AND CHECKING REDUCTS )                       ***/
-
 /***                                                                       ***/
-
 /***  part of the RSL system written by M.Gawrys J.Sienkiewicz             ***/
-
 /***                                                                       ***/
-
 /*****************************************************************************/
 
 
@@ -38,15 +31,16 @@
 
 int Core(setA core, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return CoreA(core);
+        return CoreA(core);
     case MATD:
-	return CoreDX(core, matrix_type);
+        return CoreDX(core, matrix_type);
     case MATX:
-	return CoreDX(core, matrix_type);
+        return CoreDX(core, matrix_type);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -55,22 +49,24 @@
     int ob1, ob2, attr, no1, pattr;
 
     if (_mainsys->matA == NULL)
-	ERROR(5)
-	    ClearSetA(core);
+        ERROR(5)
+        ClearSetA(core);
     for (ob1 = _mainsys->objects_num - 1; ob1 > 0; ob1--)
-	for (ob2 = ob1 - 1; ob2 >= 0; ob2--) {
-	    no1 = 0;
-	    for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
-		if (!SingCompA(ob1, ob2, attr)) {
-		    no1++;
-		    if (no1 > 1)
-			break;
-		    else
-			pattr = attr;
-		}
-	    if (no1 == 1)
-		AddSetA(core, pattr);
-	}
+        for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
+        {
+            no1 = 0;
+            for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+                if (!SingCompA(ob1, ob2, attr))
+                {
+                    no1++;
+                    if (no1 > 1)
+                        break;
+                    else
+                        pattr = attr;
+                }
+            if (no1 == 1)
+                AddSetA(core, pattr);
+        }
     return 0;
 }
 
@@ -79,48 +75,55 @@
     int cluster, bit, flag, no1, pcluster;
 
     ClearSetA(core);
-    if (matrix_type == MATD) {
-	if (_mainsys->matD == NULL)
-	    ERROR(6)
-		START_OF_D;
+    if (matrix_type == MATD)
+    {
+        if (_mainsys->matD == NULL)
+            ERROR(6)
+            START_OF_D;
     }
-    else {
-	if (_mainsys->matX == NULL)
-	    ERROR(7)
-		START_OF_X;
+    else
+    {
+        if (_mainsys->matX == NULL)
+            ERROR(7)
+            START_OF_X;
     }
-    for (; END_OF_MAT; NEXT_OF_MAT) {
-	flag = 0;
-	no1 = 0;
-	for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--) {
-	    for (bit = 0; bit < _cluster_bits; bit++)
-		if (_mask[bit] & ELEM_OF_MAT[cluster]) {
-		    no1++;
-		    if (no1 > 1) {
-			flag = 1;
-			break;
-		    }
-		    else
-			pcluster = cluster;
-		}
-	    if (flag)
-		break;
-	}
-	if (no1 == 1)
-	    core[pcluster] |= ELEM_OF_MAT[pcluster];
+    for (; END_OF_MAT; NEXT_OF_MAT)
+    {
+        flag = 0;
+        no1 = 0;
+        for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+        {
+            for (bit = 0; bit < _cluster_bits; bit++)
+                if (_mask[bit] & ELEM_OF_MAT[cluster])
+                {
+                    no1++;
+                    if (no1 > 1)
+                    {
+                        flag = 1;
+                        break;
+                    }
+                    else
+                        pcluster = cluster;
+                }
+            if (flag)
+                break;
+        }
+        if (no1 == 1)
+            core[pcluster] |= ELEM_OF_MAT[pcluster];
     }
     return 0;
 }
 
 int CoreRel(setA core, setA P, setA Q, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return CoreRelA(core, P, Q);
+        return CoreRelA(core, P, Q);
     case MATD:
-	return CoreRelD(core, P, Q);
+        return CoreRelD(core, P, Q);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -129,24 +132,26 @@
     int ob1, ob2, attr, no1, pattr;
 
     if (_mainsys->matA == NULL)
-	ERROR(5)
-	    ClearSetA(core);
+        ERROR(5)
+        ClearSetA(core);
     for (ob1 = _mainsys->objects_num - 1; ob1 > 0; ob1--)
-	for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
-	    if (!CompareA(ob1, ob2, Q)) {
-		no1 = 0;
-		for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
-		    if (ContSetA(P, attr))
-			if (!SingCompA(ob1, ob2, attr)) {
-			    no1++;
-			    if (no1 > 1)
-				break;
-			    else
-				pattr = attr;
-			}
-		if (no1 == 1)
-		    AddSetA(core, pattr);
-	    }
+        for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
+            if (!CompareA(ob1, ob2, Q))
+            {
+                no1 = 0;
+                for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+                    if (ContSetA(P, attr))
+                        if (!SingCompA(ob1, ob2, attr))
+                        {
+                            no1++;
+                            if (no1 > 1)
+                                break;
+                            else
+                                pattr = attr;
+                        }
+                if (no1 == 1)
+                    AddSetA(core, pattr);
+            }
     return 0;
 }
 
@@ -156,31 +161,35 @@
     setA elem;
 
     if (_mainsys->matD == NULL)
-	ERROR(6)
-	    ClearSetA(core);
+        ERROR(6)
+        ClearSetA(core);
     elem = InitEmptySetA();
-    for (START_OF_D; END_OF_MAT; NEXT_OF_MAT) {
-	AndSetA(elem, ELEM_OF_MAT, P);
-	flag = 0;
-	no1 = 0;
-	if (!InterSetA(Q, ELEM_OF_MAT))
-	    continue;
-	for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--) {
-	    for (bit = 0; bit < _cluster_bits; bit++)
-		if (_mask[bit] & elem[cluster]) {
-		    no1++;
-		    if (no1 > 1) {
-			flag = 1;
-			break;
-		    }
-		    else
-			pcluster = cluster;
-		}
-	    if (flag)
-		break;
-	}
-	if (no1 == 1)
-	    core[pcluster] |= elem[pcluster];
+    for (START_OF_D; END_OF_MAT; NEXT_OF_MAT)
+    {
+        AndSetA(elem, ELEM_OF_MAT, P);
+        flag = 0;
+        no1 = 0;
+        if (!InterSetA(Q, ELEM_OF_MAT))
+            continue;
+        for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+        {
+            for (bit = 0; bit < _cluster_bits; bit++)
+                if (_mask[bit] & elem[cluster])
+                {
+                    no1++;
+                    if (no1 > 1)
+                    {
+                        flag = 1;
+                        break;
+                    }
+                    else
+                        pcluster = cluster;
+                }
+            if (flag)
+                break;
+        }
+        if (no1 == 1)
+            core[pcluster] |= elem[pcluster];
     }
     CloseSetA(elem);
     return 0;
@@ -192,10 +201,11 @@
 
     and = InitEmptySetA();
     redprim = InitEmptySetA();
-    for (start_of_tab(matrix_type); end_of_tab(); next_of_tab()) {
-	AndSetA(and, _table_element, red);
-	if (CardSetA(and) == 1)
-	    OrSetA(redprim, redprim, and);
+    for (start_of_tab(matrix_type); end_of_tab(); next_of_tab())
+    {
+        AndSetA(and, _table_element, red);
+        if (CardSetA(and) == 1)
+            OrSetA(redprim, redprim, and);
     }
     CloseSetA(and);
     DifSetA(over, red, redprim);
@@ -210,12 +220,13 @@
     and = InitEmptySetA();
     redprim = InitEmptySetA();
     for (start_of_tab(matrix_type); end_of_tab(); next_of_tab())
-	if (InterSetA(_table_element, Q)) {
-	    AndSetA(and, _table_element, red);
-	    AndSetA(and, and, P);
-	    if (CardSetA(and) == 1)
-		OrSetA(redprim, redprim, and);
-	}
+        if (InterSetA(_table_element, Q))
+        {
+            AndSetA(and, _table_element, red);
+            AndSetA(and, and, P);
+            if (CardSetA(and) == 1)
+                OrSetA(redprim, redprim, and);
+        }
     CloseSetA(and);
     DifSetA(over, red, redprim);
     CloseSetA(redprim);
@@ -224,15 +235,16 @@
 
 int IsCover(setA red, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return IsCoverA(red);
+        return IsCoverA(red);
     case MATD:
-	return IsCoverDX(red, matrix_type);
+        return IsCoverDX(red, matrix_type);
     case MATX:
-	return IsCoverDX(red, matrix_type);
+        return IsCoverDX(red, matrix_type);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -243,46 +255,50 @@
 
     DifSetA(P, P, red);
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     for (ob1 = _mainsys->objects_num - 1; ob1 > 0; ob1--)
-	for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
-	    if (CompareA(ob1, ob2, red))
-		if (!CompareA(ob1, ob2, P)) {
-		    CloseSetA(P);
-		    return 0;
-		}
+        for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
+            if (CompareA(ob1, ob2, red))
+                if (!CompareA(ob1, ob2, P))
+                {
+                    CloseSetA(P);
+                    return 0;
+                }
     CloseSetA(P);
     return 1;
 }
 
 int IsCoverDX(setA red, int matrix_type)
 {
-    if (matrix_type == MATD) {
-	if (_mainsys->matD == NULL)
-	    ERROR(6)
-		START_OF_D;
+    if (matrix_type == MATD)
+    {
+        if (_mainsys->matD == NULL)
+            ERROR(6)
+            START_OF_D;
     }
-    else {
-	if (_mainsys->matX == NULL)
-	    ERROR(7)
-		START_OF_X;
+    else
+    {
+        if (_mainsys->matX == NULL)
+            ERROR(7)
+            START_OF_X;
     }
     for (; END_OF_MAT; NEXT_OF_MAT)
-	if (!IsEmptySetA(ELEM_OF_MAT))
-	    if (!InterSetA(ELEM_OF_MAT, red))
-		return 0;
+        if (!IsEmptySetA(ELEM_OF_MAT))
+            if (!InterSetA(ELEM_OF_MAT, red))
+                return 0;
     return 1;
 }
 
 int IsCoverRel(setA red, setA P, setA Q, int matrix_type)
 {
-    switch (matrix_type) {
+    switch (matrix_type)
+    {
     case MATA:
-	return IsCoverRelA(red, P, Q);
+        return IsCoverRelA(red, P, Q);
     case MATD:
-	return IsCoverRelD(red, P, Q);
+        return IsCoverRelD(red, P, Q);
     default:
-	ERROR(8)
+        ERROR(8)
     }
 }
 
@@ -292,17 +308,18 @@
     setA Pprim;
 
     if (_mainsys->matA == NULL)
-	ERROR(5);
+        ERROR(5);
     Pprim = InitEmptySetA();
     DifSetA(Pprim, P, red);
     for (ob1 = _mainsys->objects_num - 1; ob1 > 0; ob1--)
-	for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
-	    if (!CompareA(ob1, ob2, Q))
-		if (CompareA(ob1, ob2, red))
-		    if (!CompareA(ob1, ob2, Pprim)) {
-			CloseSetA(Pprim);
-			return 0;
-		    }
+        for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
+            if (!CompareA(ob1, ob2, Q))
+                if (CompareA(ob1, ob2, red))
+                    if (!CompareA(ob1, ob2, Pprim))
+                    {
+                        CloseSetA(Pprim);
+                        return 0;
+                    }
     CloseSetA(Pprim);
     return 1;
 }
@@ -310,12 +327,12 @@
 int IsCoverRelD(setA red, setA P, setA Q)
 {
     if (_mainsys->matD == NULL)
-	ERROR(6);
+        ERROR(6);
     for (START_OF_D; END_OF_MAT; NEXT_OF_MAT)
-	if (InterSetA(ELEM_OF_MAT, Q))
-	    if (!InterSetA(ELEM_OF_MAT, red))
-		if (InterSetA(ELEM_OF_MAT, P))
-		    return 0;
+        if (InterSetA(ELEM_OF_MAT, Q))
+            if (!InterSetA(ELEM_OF_MAT, red))
+                if (InterSetA(ELEM_OF_MAT, P))
+                    return 0;
     return 1;
 }
 
@@ -325,7 +342,7 @@
     setA over;
 
     if (!IsCover(red, matrix_type))
-	return 0;
+        return 0;
     over = InitEmptySetA();
     result = IsOrtho(red, over, matrix_type);
     CloseSetA(over);
@@ -339,7 +356,7 @@
     setA over;
 
     if (!IsCoverRel(red, P, Q, matrix_type))
-	return 0;
+        return 0;
     over = InitEmptySetA();
     result = IsOrthoRel(red, over, P, Q, matrix_type);
     CloseSetA(over);

Modified: grass-addons/raster/mcda/r.roughset/reduct1.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct1.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/reduct1.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,19 +16,12 @@
  *   	    	 for details.
  *
  *****************************************************************************/
-
 /***                                                                       ***/
-
 /***               SOME MORE QUERIES FOR SYSTEM                            ***/
-
 /***                   ( FINDING REDUCTS )                                 ***/
-
 /***                                                                       ***/
-
 /*** part of the RSL system written by M.Gawrys J.Sienkiewicz              ***/
-
 /***                                                                       ***/
-
 /*****************************************************************************/
 
 
@@ -39,145 +32,164 @@
 int RedRel(setA * reducts, setA P, setA Q, int matrix_type)
 {
     int MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, j, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1,	/* size of the allocated memory    */
-	newcount = 0, oldcount;	/* number of new/old reducts       */
+                    newcount = 0, oldcount;	/* number of new/old reducts       */
     int no_A = _mainsys->attributes_num;
     setA arg,			/* arguments are elements of matrix */
-      oldhead,			/* head of static list of reducts  */
-      oldtail,			/* tail ends the old reducts list  */
-      el, el1,			/* elements of this list           */
-      new_el,			/* probably new element of the list */
-      newhead,			/* begin of new reducts            */
-      newtail;			/* tail of the list of new reducts */
+    oldhead,			/* head of static list of reducts  */
+    oldtail,			/* tail ends the old reducts list  */
+    el, el1,			/* elements of this list           */
+    new_el,			/* probably new element of the list */
+    newhead,			/* begin of new reducts            */
+    newtail;			/* tail of the list of new reducts */
     setA CORE, keep;
 
     CORE = InitEmptySetA();
     _rerror = 0;
     CoreRel(CORE, P, Q, matrix_type);
-    if (_rerror != 0) {
-	CloseSetA(CORE);
-	return (-_rerror);
+    if (_rerror != 0)
+    {
+        CloseSetA(CORE);
+        return (-_rerror);
     }
-    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        CloseSetA(CORE);
+        ERROR(3);
     }
-    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	free(oldhead);
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        free(oldhead);
+        CloseSetA(CORE);
+        ERROR(3);
     }
     new_el = InitEmptySetA();
     arg = InitEmptySetA();
     oldtail = oldhead;
     newtail = newhead;
     start_of_tab(matrix_type);	/* initializing the reducts list */
-    if (!IsEmptySetA(CORE)) {
-	CopySetA(oldtail, CORE);
-	oldtail += size, oldcount = 1;
+    if (!IsEmptySetA(CORE))
+    {
+        CopySetA(oldtail, CORE);
+        oldtail += size, oldcount = 1;
     }
     else
-	do {
-	    AndSetA(arg, _table_element, P);
-	    oldcount = 0;
-	    if (InterSetA(_table_element, Q))
-		for (atr = 0; atr < no_A; atr++)
-		    if (ContSetA(arg, atr)) {
-			ClearSetA(oldtail);
-			AddSetA(oldtail, atr);
-			oldtail += size;
-			oldcount++;
-		    }
-	    next_of_tab();
-	}
-	while ((oldcount == 0) && end_of_tab());
-    for (; end_of_tab(); next_of_tab()) {	/* for each element of matD do  */
-	AndSetA(arg, _table_element, P);	/* take next element */
-	over = 0;
-	if (InterSetA(CORE, arg))
-	    continue;
-	if (!InterSetA(_table_element, Q))
-	    continue;
-	if (IsEmptySetA(arg))
-	    continue;
-	el = oldhead;
-	while (el < oldtail) {	/* compare arg to all the old reducts  */
-	    if (!InterSetA(el, arg)) {
-		for (atr = 0; atr < no_A; atr++)	/* for each atribute of arg  */
-		    if (ContSetA(arg, atr)) {
-			CopySetA(new_el, el);	/* creating potentialy new reduct */
-			AddSetA(new_el, atr);
-			over = 0;
-			el1 = oldhead;
-			while ((el1 != el) && !over) {	/* comparing new reduct to old reducts */
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			el1 = el + size;
-			while ((el1 != oldtail) && !over) {
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			if (!over) {	/* appending new reduct */
-			    newcount++;
-			    if (newcount * size * _cluster_bytes >
-				memoryN * MEMOKWANT) {
-				keep = newhead;
-				if ((newhead =
-				     (setA) realloc(keep,
-						    MEMOKWANT *
-						    (++memoryN))) == NULL) {
-				    free(oldhead);
-				    CloseSetA(new_el);
-				    CloseSetA(arg);
-				    CloseSetA(CORE);
-				    ERROR(3);
-				}
-				if (keep != newhead)
-				    newtail = newhead + (newcount - 1) * size;
-			    }
-			    CopySetA(newtail, new_el);
-			    newtail += size;
-			}
-		    }
-	    }
-	    else {		/* if reduct covers arg - rewrite it */
-		newcount++;
-		if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
-		    keep = newhead;
-		    if ((newhead =
-			 (setA) realloc(keep,
-					MEMOKWANT * (++memoryN))) == NULL) {
-			free(oldhead);
-			CloseSetA(new_el);
-			CloseSetA(arg);
-			CloseSetA(CORE);
-			ERROR(3);
-		    }
-		    if (keep != newhead)
-			newtail = newhead + (newcount - 1) * size;
-		}
-		CopySetA(newtail, el);
-		newtail += size;
-	    }
-	    el += size;
-	}
-	oldtail = newhead;	/* new reducts list becomes old */
-	newhead = oldhead;
-	oldhead = oldtail;
-	oldtail = newtail;
-	newtail = newhead;
-	oldcount = newcount;
-	newcount = 0;
-	j = memoryO;
-	memoryO = memoryN;
-	memoryN = j;
+        do
+        {
+            AndSetA(arg, _table_element, P);
+            oldcount = 0;
+            if (InterSetA(_table_element, Q))
+                for (atr = 0; atr < no_A; atr++)
+                    if (ContSetA(arg, atr))
+                    {
+                        ClearSetA(oldtail);
+                        AddSetA(oldtail, atr);
+                        oldtail += size;
+                        oldcount++;
+                    }
+            next_of_tab();
+        }
+        while ((oldcount == 0) && end_of_tab());
+    for (; end_of_tab(); next_of_tab())  	/* for each element of matD do  */
+    {
+        AndSetA(arg, _table_element, P);	/* take next element */
+        over = 0;
+        if (InterSetA(CORE, arg))
+            continue;
+        if (!InterSetA(_table_element, Q))
+            continue;
+        if (IsEmptySetA(arg))
+            continue;
+        el = oldhead;
+        while (el < oldtail)  	/* compare arg to all the old reducts  */
+        {
+            if (!InterSetA(el, arg))
+            {
+                for (atr = 0; atr < no_A; atr++)	/* for each atribute of arg  */
+                    if (ContSetA(arg, atr))
+                    {
+                        CopySetA(new_el, el);	/* creating potentialy new reduct */
+                        AddSetA(new_el, atr);
+                        over = 0;
+                        el1 = oldhead;
+                        while ((el1 != el) && !over)  	/* comparing new reduct to old reducts */
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        el1 = el + size;
+                        while ((el1 != oldtail) && !over)
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        if (!over)  	/* appending new reduct */
+                        {
+                            newcount++;
+                            if (newcount * size * _cluster_bytes >
+                                    memoryN * MEMOKWANT)
+                            {
+                                keep = newhead;
+                                if ((newhead =
+                                            (setA) realloc(keep,
+                                                           MEMOKWANT *
+                                                           (++memoryN))) == NULL)
+                                {
+                                    free(oldhead);
+                                    CloseSetA(new_el);
+                                    CloseSetA(arg);
+                                    CloseSetA(CORE);
+                                    ERROR(3);
+                                }
+                                if (keep != newhead)
+                                    newtail = newhead + (newcount - 1) * size;
+                            }
+                            CopySetA(newtail, new_el);
+                            newtail += size;
+                        }
+                    }
+            }
+            else  		/* if reduct covers arg - rewrite it */
+            {
+                newcount++;
+                if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT)
+                {
+                    keep = newhead;
+                    if ((newhead =
+                                (setA) realloc(keep,
+                                               MEMOKWANT * (++memoryN))) == NULL)
+                    {
+                        free(oldhead);
+                        CloseSetA(new_el);
+                        CloseSetA(arg);
+                        CloseSetA(CORE);
+                        ERROR(3);
+                    }
+                    if (keep != newhead)
+                        newtail = newhead + (newcount - 1) * size;
+                }
+                CopySetA(newtail, el);
+                newtail += size;
+            }
+            el += size;
+        }
+        oldtail = newhead;	/* new reducts list becomes old */
+        newhead = oldhead;
+        oldhead = oldtail;
+        oldtail = newtail;
+        newtail = newhead;
+        oldcount = newcount;
+        newcount = 0;
+        j = memoryO;
+        memoryO = memoryN;
+        memoryN = j;
     }
-    if (oldcount == 0) {
-	free(oldhead);
-	*reducts = NULL;
+    if (oldcount == 0)
+    {
+        free(oldhead);
+        *reducts = NULL;
     }
     else
-	*reducts = oldhead;
+        *reducts = oldhead;
     free(newhead);
     CloseSetA(CORE);
     CloseSetA(arg);
@@ -188,32 +200,35 @@
 int Red(setA * reducts, int matrix_type)
 {
     int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1,	/* size of the allocated memory    */
-	newcount = 0, oldcount;	/* number of new/old reducts       */
+                       newcount = 0, oldcount;	/* number of new/old reducts       */
     int no_A = _mainsys->attributes_num;
     setA oldhead,		/* head of static list of reducts  */
-      oldtail,			/* tail ends the old reducts list  */
-      el, el1,			/* elements of this list           */
-      new_el,			/* probably new element of the list */
-      newhead,			/* begin of new reducts            */
-      newtail;			/* tail of the list of new reducts */
+    oldtail,			/* tail ends the old reducts list  */
+    el, el1,			/* elements of this list           */
+    new_el,			/* probably new element of the list */
+    newhead,			/* begin of new reducts            */
+    newtail;			/* tail of the list of new reducts */
     setA CORE, keep, and, redprim;
 
     CORE = InitEmptySetA();
     _rerror = 0;
     Core(CORE, matrix_type);
-    if (_rerror != 0) {
-	CloseSetA(CORE);
-	return (-_rerror);
+    if (_rerror != 0)
+    {
+        CloseSetA(CORE);
+        return (-_rerror);
     }
-    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	CloseSetA(CORE);
-	keep = NULL;
-	ERROR(3);
+    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        CloseSetA(CORE);
+        keep = NULL;
+        ERROR(3);
     }
-    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	free(oldhead);
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        free(oldhead);
+        CloseSetA(CORE);
+        ERROR(3);
     }
     new_el = InitEmptySetA();
     and = InitEmptySetA();
@@ -221,118 +236,134 @@
     oldtail = oldhead;
     newtail = newhead;
     start_of_tab(matrix_type);
-    if (!IsEmptySetA(CORE)) {	/* initializing of the reducts list */
-	CopySetA(oldtail, CORE);
-	oldtail += size, oldcount = 1;
+    if (!IsEmptySetA(CORE))  	/* initializing of the reducts list */
+    {
+        CopySetA(oldtail, CORE);
+        oldtail += size, oldcount = 1;
     }
     else
-	do {
-	    oldcount = 0;
-	    for (atr = 0; atr < no_A; atr++)
-		if (ContSetA(_table_element, atr)) {
-		    ClearSetA(oldtail);
-		    AddSetA(oldtail, atr);
-		    oldtail += size;
-		    oldcount++;
-		}
-	    next_of_tab();
-	}
-	while ((oldcount == 0) && end_of_tab());
-    for (; end_of_tab(); next_of_tab()) {	/* for each element of matrix */
-	over = 0;
-	if (InterSetA(CORE, _table_element))
-	    continue;
-	if (IsEmptySetA(_table_element))
-	    continue;
-	el = oldhead;
-	while (el < oldtail) {	/* compare _table_element to all the old reducts  */
-	    if (!InterSetA(el, _table_element)) {	/* old reduct does not cover new element */
-		for (atr = 0; atr < no_A; atr++)	/* for each atribute of _table_element  */
-		    if (ContSetA(_table_element, atr)) {
-			CopySetA(new_el, el);	/* creating potentialy new reduct */
-			AddSetA(new_el, atr);
-			over = 0;
-			el1 = oldhead;
-			/*  if ( matrix_type==MATX && (_mainsys->matXsize<(oldtail-oldhead)))
-			   { ClearSetA( redprim );
-			   for(el1=_mainsys->matX;el1<_table_end;el1+=size)
-			   { AndSetA( and, el1, new_el );
-			   if ( CardSetA( and ) == 1 ) OrSetA( redprim, redprim, and );
-			   }
-			   over = !CompSetA( redprim, new_el );
-			   }
-			   else
-			 */
-			{
-			    while ((el1 != el) && !over) {	/* comparing new reduct to all the old reducts */
-				over = InSetA(new_el, el1);
-				el1 += size;
-			    }
-			    el1 = el + size;
-			    while ((el1 != oldtail) && !over) {
-				over = InSetA(new_el, el1);
-				el1 += size;
-			    }
-			}
-			if (!over) {	/* appending new reduct */
-			    newcount++;
-			    if (newcount * size * _cluster_bytes >
-				memoryN * MEMOKWANT) {
-				keep = newhead;
-				if ((newhead =
-				     (setA) realloc(keep,
-						    MEMOKWANT *
-						    (++memoryN))) == NULL) {
-				    free(oldhead);
-				    CloseSetA(new_el);
-				    CloseSetA(CORE);
-				    ERROR(3);
-				}
-				if (keep != newhead)
-				    newtail = newhead + (newcount - 1) * size;
-			    }
-			    CopySetA(newtail, new_el);
-			    newtail += size;
-			}
-		    }
-	    }
-	    else {		/* old reduct covers new element */
-		newcount++;
-		if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
-		    keep = newhead;
-		    if ((newhead =
-			 (setA) realloc(keep,
-					MEMOKWANT * (++memoryN))) == NULL) {
-			free(oldhead);
-			CloseSetA(new_el);
-			CloseSetA(CORE);
-			ERROR(3);
-		    }
-		    if (keep != newhead)
-			newtail = newhead + (newcount - 1) * size;
-		}
-		CopySetA(newtail, el);
-		newtail += size;
-	    }
-	    el += size;
-	}
-	oldtail = newhead;	/* new reducts list becomes old */
-	newhead = oldhead;
-	oldhead = oldtail;
-	oldtail = newtail;
-	newtail = newhead;
-	oldcount = newcount;
-	newcount = 0;
-	j = memoryO;
-	memoryO = memoryN;
-	memoryN = j;
+        do
+        {
+            oldcount = 0;
+            for (atr = 0; atr < no_A; atr++)
+                if (ContSetA(_table_element, atr))
+                {
+                    ClearSetA(oldtail);
+                    AddSetA(oldtail, atr);
+                    oldtail += size;
+                    oldcount++;
+                }
+            next_of_tab();
+        }
+        while ((oldcount == 0) && end_of_tab());
+    for (; end_of_tab(); next_of_tab())  	/* for each element of matrix */
+    {
+        over = 0;
+        if (InterSetA(CORE, _table_element))
+            continue;
+        if (IsEmptySetA(_table_element))
+            continue;
+        el = oldhead;
+        while (el < oldtail)  	/* compare _table_element to all the old reducts  */
+        {
+            if (!InterSetA(el, _table_element))  	/* old reduct does not cover new element */
+            {
+                for (atr = 0; atr < no_A; atr++)	/* for each atribute of _table_element  */
+                    if (ContSetA(_table_element, atr))
+                    {
+                        CopySetA(new_el, el);	/* creating potentialy new reduct */
+                        AddSetA(new_el, atr);
+                        over = 0;
+                        el1 = oldhead;
+                        /*  if ( matrix_type==MATX && (_mainsys->matXsize<(oldtail-oldhead)))
+                           { ClearSetA( redprim );
+                           for(el1=_mainsys->matX;el1<_table_end;el1+=size)
+                           { AndSetA( and, el1, new_el );
+                           if ( CardSetA( and ) == 1 ) OrSetA( redprim, redprim, and );
+                           }
+                           over = !CompSetA( redprim, new_el );
+                           }
+                           else
+                         */
+                        {
+                            while ((el1 != el) && !over)  	/* comparing new reduct to all the old reducts */
+                            {
+                                over = InSetA(new_el, el1);
+                                el1 += size;
+                            }
+                            el1 = el + size;
+                            while ((el1 != oldtail) && !over)
+                            {
+                                over = InSetA(new_el, el1);
+                                el1 += size;
+                            }
+                        }
+                        if (!over)  	/* appending new reduct */
+                        {
+                            newcount++;
+                            if (newcount * size * _cluster_bytes >
+                                    memoryN * MEMOKWANT)
+                            {
+                                keep = newhead;
+                                if ((newhead =
+                                            (setA) realloc(keep,
+                                                           MEMOKWANT *
+                                                           (++memoryN))) == NULL)
+                                {
+                                    free(oldhead);
+                                    CloseSetA(new_el);
+                                    CloseSetA(CORE);
+                                    ERROR(3);
+                                }
+                                if (keep != newhead)
+                                    newtail = newhead + (newcount - 1) * size;
+                            }
+                            CopySetA(newtail, new_el);
+                            newtail += size;
+                        }
+                    }
+            }
+            else  		/* old reduct covers new element */
+            {
+                newcount++;
+                if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT)
+                {
+                    keep = newhead;
+                    if ((newhead =
+                                (setA) realloc(keep,
+                                               MEMOKWANT * (++memoryN))) == NULL)
+                    {
+                        free(oldhead);
+                        CloseSetA(new_el);
+                        CloseSetA(CORE);
+                        ERROR(3);
+                    }
+                    if (keep != newhead)
+                        newtail = newhead + (newcount - 1) * size;
+                }
+                CopySetA(newtail, el);
+                newtail += size;
+            }
+            el += size;
+        }
+        oldtail = newhead;	/* new reducts list becomes old */
+        newhead = oldhead;
+        oldhead = oldtail;
+        oldtail = newtail;
+        newtail = newhead;
+        oldcount = newcount;
+        newcount = 0;
+        j = memoryO;
+        memoryO = memoryN;
+        memoryN = j;
     }
-    if (oldcount == 0) {
-	free(oldhead);
-	*reducts = NULL;
+    if (oldcount == 0)
+    {
+        free(oldhead);
+        *reducts = NULL;
     }
     else
-	*reducts = oldhead;
+        *reducts = oldhead;
     free(newhead);
     CloseSetA(CORE);
     CloseSetA(new_el);
@@ -345,152 +376,172 @@
 int RedRelLess(setA * reducts, setA P, setA Q, int N, int matrix_type)
 {
     int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1,	/* size of the allocated memory    */
-	newcount = 0, oldcount;	/* number of new/old reducts       */
+                       newcount = 0, oldcount;	/* number of new/old reducts       */
     int no_A = _mainsys->attributes_num;
     setA arg,			/* arguments are elements of matrix */
-      oldhead,			/* head of static list of reducts  */
-      oldtail,			/* tail ends the old reducts list  */
-      el, el1,			/* elements of this list           */
-      new_el,			/* probably new element of the list */
-      newhead,			/* begin of new reducts            */
-      newtail;			/* tail of the list of new reducts */
+    oldhead,			/* head of static list of reducts  */
+    oldtail,			/* tail ends the old reducts list  */
+    el, el1,			/* elements of this list           */
+    new_el,			/* probably new element of the list */
+    newhead,			/* begin of new reducts            */
+    newtail;			/* tail of the list of new reducts */
     setA CORE, keep;
 
     CORE = InitEmptySetA();
     _rerror = 0;
     CoreRel(CORE, P, Q, matrix_type);
-    if (_rerror != 0) {
-	CloseSetA(CORE);
-	return (-_rerror);
+    if (_rerror != 0)
+    {
+        CloseSetA(CORE);
+        return (-_rerror);
     }
-    if (CardSetA(CORE) > N) {
-	free(CORE);
-	return (0);
+    if (CardSetA(CORE) > N)
+    {
+        free(CORE);
+        return (0);
     }
-    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        CloseSetA(CORE);
+        ERROR(3);
     }
-    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	free(oldhead);
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        free(oldhead);
+        CloseSetA(CORE);
+        ERROR(3);
     }
     new_el = InitEmptySetA();
     arg = InitEmptySetA();
     oldtail = oldhead;
     newtail = newhead;
     start_of_tab(matrix_type);
-    if (!IsEmptySetA(CORE)) {
-	CopySetA(oldtail, CORE);
-	oldtail += size, oldcount = 1;
+    if (!IsEmptySetA(CORE))
+    {
+        CopySetA(oldtail, CORE);
+        oldtail += size, oldcount = 1;
     }
     else
-	do {
-	    AndSetA(arg, _table_element, P);
-	    oldcount = 0;
-	    if (InterSetA(_table_element, Q))
-		for (atr = 0; atr < no_A; atr++)
-		    if (ContSetA(arg, atr)) {
-			ClearSetA(oldtail);
-			AddSetA(oldtail, atr);
-			oldtail += size;
-			oldcount++;
-		    }
-	    next_of_tab();
-	}
-	while ((oldcount == 0) && end_of_tab());
-    for (; end_of_tab(); next_of_tab()) {	/* for each element of matrix do  */
-	AndSetA(arg, _table_element, P);	/* take next element */
-	over = 0;
-	if (InterSetA(CORE, arg))
-	    continue;
-	if (!InterSetA(_table_element, Q))
-	    continue;
-	if (IsEmptySetA(arg))
-	    continue;
-	el = oldhead;
-	while (el < oldtail) {	/* compare arg to all old reducts  */
-	    if (!InterSetA(el, arg)) {	/* old reduct does not cover new element */
-		if (CardSetA(el) < N)	/* shorter elements should be corected */
-		    for (atr = 0; atr < no_A; atr++)	/* for each atribute of arg  */
-			if (ContSetA(arg, atr)) {
-			    CopySetA(new_el, el);	/* creating potentialy new reduct */
-			    AddSetA(new_el, atr);
-			    over = 0;
-			    el1 = oldhead;
-			    while ((el1 != el) && !over) {	/* comparing new reduct to all the old list */
-				over = InSetA(new_el, el1);
-				el1 += size;
-			    }
-			    el1 = el + size;
-			    while ((el1 != oldtail) && !over) {
-				over = InSetA(new_el, el1);
-				el1 += size;
-			    }
-			    if (!over) {	/* appending to new list */
-				newcount++;
-				if (newcount * size * _cluster_bytes >
-				    memoryN * MEMOKWANT) {
-				    keep = newhead;
-				    if ((newhead =
-					 (setA) realloc(keep,
-							MEMOKWANT *
-							(++memoryN))) ==
-					NULL) {
-					free(oldhead);
-					CloseSetA(new_el);
-					CloseSetA(arg);
-					CloseSetA(CORE);
-					ERROR(3);
-				    }
-				    if (keep != newhead)
-					newtail =
-					    newhead + (newcount - 1) * size;
-				}
-				CopySetA(newtail, new_el);
-				newtail += size;
-			    }
-			}
-	    }
-	    else {		/* old reduct covers new element */
-		newcount++;
-		if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
-		    keep = newhead;
-		    if ((newhead =
-			 (setA) realloc(keep,
-					MEMOKWANT * (++memoryN))) == NULL) {
-			free(oldhead);
-			CloseSetA(new_el);
-			CloseSetA(arg);
-			CloseSetA(CORE);
-			ERROR(3);
-		    }
-		    if (keep != newhead)
-			newtail = newhead + (newcount - 1) * size;
-		}
-		CopySetA(newtail, el);
-		newtail += size;
-	    }
-	    el += size;
-	}
-	oldtail = newhead;	/* new list becomes old */
-	newhead = oldhead;
-	oldhead = oldtail;
-	oldtail = newtail;
-	newtail = newhead;
-	oldcount = newcount;
-	newcount = 0;
-	j = memoryO;
-	memoryO = memoryN;
-	memoryN = j;
+        do
+        {
+            AndSetA(arg, _table_element, P);
+            oldcount = 0;
+            if (InterSetA(_table_element, Q))
+                for (atr = 0; atr < no_A; atr++)
+                    if (ContSetA(arg, atr))
+                    {
+                        ClearSetA(oldtail);
+                        AddSetA(oldtail, atr);
+                        oldtail += size;
+                        oldcount++;
+                    }
+            next_of_tab();
+        }
+        while ((oldcount == 0) && end_of_tab());
+    for (; end_of_tab(); next_of_tab())  	/* for each element of matrix do  */
+    {
+        AndSetA(arg, _table_element, P);	/* take next element */
+        over = 0;
+        if (InterSetA(CORE, arg))
+            continue;
+        if (!InterSetA(_table_element, Q))
+            continue;
+        if (IsEmptySetA(arg))
+            continue;
+        el = oldhead;
+        while (el < oldtail)  	/* compare arg to all old reducts  */
+        {
+            if (!InterSetA(el, arg))  	/* old reduct does not cover new element */
+            {
+                if (CardSetA(el) < N)	/* shorter elements should be corected */
+                    for (atr = 0; atr < no_A; atr++)	/* for each atribute of arg  */
+                        if (ContSetA(arg, atr))
+                        {
+                            CopySetA(new_el, el);	/* creating potentialy new reduct */
+                            AddSetA(new_el, atr);
+                            over = 0;
+                            el1 = oldhead;
+                            while ((el1 != el) && !over)  	/* comparing new reduct to all the old list */
+                            {
+                                over = InSetA(new_el, el1);
+                                el1 += size;
+                            }
+                            el1 = el + size;
+                            while ((el1 != oldtail) && !over)
+                            {
+                                over = InSetA(new_el, el1);
+                                el1 += size;
+                            }
+                            if (!over)  	/* appending to new list */
+                            {
+                                newcount++;
+                                if (newcount * size * _cluster_bytes >
+                                        memoryN * MEMOKWANT)
+                                {
+                                    keep = newhead;
+                                    if ((newhead =
+                                                (setA) realloc(keep,
+                                                               MEMOKWANT *
+                                                               (++memoryN))) ==
+                                            NULL)
+                                    {
+                                        free(oldhead);
+                                        CloseSetA(new_el);
+                                        CloseSetA(arg);
+                                        CloseSetA(CORE);
+                                        ERROR(3);
+                                    }
+                                    if (keep != newhead)
+                                        newtail =
+                                            newhead + (newcount - 1) * size;
+                                }
+                                CopySetA(newtail, new_el);
+                                newtail += size;
+                            }
+                        }
+            }
+            else  		/* old reduct covers new element */
+            {
+                newcount++;
+                if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT)
+                {
+                    keep = newhead;
+                    if ((newhead =
+                                (setA) realloc(keep,
+                                               MEMOKWANT * (++memoryN))) == NULL)
+                    {
+                        free(oldhead);
+                        CloseSetA(new_el);
+                        CloseSetA(arg);
+                        CloseSetA(CORE);
+                        ERROR(3);
+                    }
+                    if (keep != newhead)
+                        newtail = newhead + (newcount - 1) * size;
+                }
+                CopySetA(newtail, el);
+                newtail += size;
+            }
+            el += size;
+        }
+        oldtail = newhead;	/* new list becomes old */
+        newhead = oldhead;
+        oldhead = oldtail;
+        oldtail = newtail;
+        newtail = newhead;
+        oldcount = newcount;
+        newcount = 0;
+        j = memoryO;
+        memoryO = memoryN;
+        memoryN = j;
     }
-    if (oldcount == 0) {
-	free(oldhead);
-	*reducts = NULL;
+    if (oldcount == 0)
+    {
+        free(oldhead);
+        *reducts = NULL;
     }
     else
-	*reducts = oldhead;
+        *reducts = oldhead;
     free(newhead);
     CloseSetA(CORE);
     CloseSetA(arg);
@@ -502,144 +553,164 @@
 int RedLess(setA * reducts, int N, int matrix_type)
 {
     int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1,	/* size of the allocated memory    */
-	newcount = 0, oldcount;	/* number of new/old reducts       */
+                       newcount = 0, oldcount;	/* number of new/old reducts       */
     int no_A = _mainsys->attributes_num;
     setA oldhead,		/* head of static list of reducts  */
-      oldtail,			/* tail ends the old reducts list  */
-      el, el1,			/* elements of this list           */
-      new_el,			/* probably new element of the list */
-      newhead,			/* begin of new reducts            */
-      newtail;			/* tail of the list of new reducts */
+    oldtail,			/* tail ends the old reducts list  */
+    el, el1,			/* elements of this list           */
+    new_el,			/* probably new element of the list */
+    newhead,			/* begin of new reducts            */
+    newtail;			/* tail of the list of new reducts */
     setA CORE, keep;
 
     CORE = InitEmptySetA();
     _rerror = 0;
     Core(CORE, matrix_type);
-    if (_rerror != 0) {
-	CloseSetA(CORE);
-	return (-_rerror);
+    if (_rerror != 0)
+    {
+        CloseSetA(CORE);
+        return (-_rerror);
     }
-    if (CardSetA(CORE) > N) {
-	free(CORE);
-	return (0);
+    if (CardSetA(CORE) > N)
+    {
+        free(CORE);
+        return (0);
     }
-    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        CloseSetA(CORE);
+        ERROR(3);
     }
-    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	free(oldhead);
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        free(oldhead);
+        CloseSetA(CORE);
+        ERROR(3);
     }
     new_el = InitEmptySetA();
     oldtail = oldhead;
     newtail = newhead;
     start_of_tab(matrix_type);
-    if (!IsEmptySetA(CORE)) {	/*initializing the reducts list  */
-	CopySetA(oldtail, CORE);
-	oldtail += size;
-	oldcount = 1;
+    if (!IsEmptySetA(CORE))  	/*initializing the reducts list  */
+    {
+        CopySetA(oldtail, CORE);
+        oldtail += size;
+        oldcount = 1;
     }
     else
-	do {
-	    oldcount = 0;
-	    for (atr = 0; atr < no_A; atr++)
-		if (ContSetA(_table_element, atr)) {
-		    ClearSetA(oldtail);
-		    AddSetA(oldtail, atr);
-		    oldtail += size;
-		    oldcount++;
-		}
-	    next_of_tab();
-	}
-	while ((oldcount == 0) && end_of_tab());
-    for (; end_of_tab(); next_of_tab()) {	/* for each element of matD do  */
-	over = 0;
-	if (InterSetA(_table_element, CORE))
-	    continue;
-	if (IsEmptySetA(_table_element))
-	    continue;
-	el = oldhead;
-	while (el < oldtail) {	/* compare _table_element to all the old reducts  */
-	    if (!InterSetA(el, _table_element)) {	/* old reduct does not cover new element */
-		if (CardSetA(el) < N)
-		    for (atr = 0; atr < no_A; atr++)	/* for each atribute of element */
-			if (ContSetA(_table_element, atr)) {
-			    CopySetA(new_el, el);	/* creating potentialy new reduct */
-			    AddSetA(new_el, atr);
-			    over = 0;
-			    el1 = oldhead;	/* comparing new reduct to the old reducts */
-			    while ((el1 != el) && !over) {
-				over = InSetA(new_el, el1);
-				el1 += size;
-			    }
-			    el1 = el + size;
-			    while ((el1 != oldtail) && !over) {
-				over = InSetA(new_el, el1);
-				el1 += size;
-			    }
-			    if (!over) {	/* appending new reduct to list */
-				newcount++;
-				if (newcount * size * _cluster_bytes >
-				    memoryN * MEMOKWANT) {
-				    keep = newhead;
-				    if ((newhead =
-					 (setA) realloc(keep,
-							MEMOKWANT *
-							(++memoryN))) ==
-					NULL) {
-					free(oldhead);
-					CloseSetA(new_el);
-					CloseSetA(CORE);
-					ERROR(3);
-				    }
-				    if (keep != newhead)
-					newtail =
-					    newhead + (newcount - 1) * size;
-				}
-				CopySetA(newtail, new_el);
-				newtail += size;
-			    }
-			}
-	    }
-	    else {		/* old reduct covers new element */
-		newcount++;
-		if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
-		    keep = newhead;
-		    if ((newhead =
-			 (setA) realloc(keep,
-					MEMOKWANT * (++memoryN))) == NULL) {
-			free(oldhead);
-			CloseSetA(new_el);
-			CloseSetA(CORE);
-			ERROR(3);
-		    }
-		    if (keep != newhead)
-			newtail = newhead + (newcount - 1) * size;
-		}
-		CopySetA(newtail, el);
-		newtail += size;
-	    }
-	    el += size;
-	}
-	oldtail = newhead;	/* new list becomes old */
-	newhead = oldhead;
-	oldhead = oldtail;
-	oldtail = newtail;
-	newtail = newhead;
-	oldcount = newcount;
-	newcount = 0;
-	j = memoryO;
-	memoryO = memoryN;
-	memoryN = j;
+        do
+        {
+            oldcount = 0;
+            for (atr = 0; atr < no_A; atr++)
+                if (ContSetA(_table_element, atr))
+                {
+                    ClearSetA(oldtail);
+                    AddSetA(oldtail, atr);
+                    oldtail += size;
+                    oldcount++;
+                }
+            next_of_tab();
+        }
+        while ((oldcount == 0) && end_of_tab());
+    for (; end_of_tab(); next_of_tab())  	/* for each element of matD do  */
+    {
+        over = 0;
+        if (InterSetA(_table_element, CORE))
+            continue;
+        if (IsEmptySetA(_table_element))
+            continue;
+        el = oldhead;
+        while (el < oldtail)  	/* compare _table_element to all the old reducts  */
+        {
+            if (!InterSetA(el, _table_element))  	/* old reduct does not cover new element */
+            {
+                if (CardSetA(el) < N)
+                    for (atr = 0; atr < no_A; atr++)	/* for each atribute of element */
+                        if (ContSetA(_table_element, atr))
+                        {
+                            CopySetA(new_el, el);	/* creating potentialy new reduct */
+                            AddSetA(new_el, atr);
+                            over = 0;
+                            el1 = oldhead;	/* comparing new reduct to the old reducts */
+                            while ((el1 != el) && !over)
+                            {
+                                over = InSetA(new_el, el1);
+                                el1 += size;
+                            }
+                            el1 = el + size;
+                            while ((el1 != oldtail) && !over)
+                            {
+                                over = InSetA(new_el, el1);
+                                el1 += size;
+                            }
+                            if (!over)  	/* appending new reduct to list */
+                            {
+                                newcount++;
+                                if (newcount * size * _cluster_bytes >
+                                        memoryN * MEMOKWANT)
+                                {
+                                    keep = newhead;
+                                    if ((newhead =
+                                                (setA) realloc(keep,
+                                                               MEMOKWANT *
+                                                               (++memoryN))) ==
+                                            NULL)
+                                    {
+                                        free(oldhead);
+                                        CloseSetA(new_el);
+                                        CloseSetA(CORE);
+                                        ERROR(3);
+                                    }
+                                    if (keep != newhead)
+                                        newtail =
+                                            newhead + (newcount - 1) * size;
+                                }
+                                CopySetA(newtail, new_el);
+                                newtail += size;
+                            }
+                        }
+            }
+            else  		/* old reduct covers new element */
+            {
+                newcount++;
+                if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT)
+                {
+                    keep = newhead;
+                    if ((newhead =
+                                (setA) realloc(keep,
+                                               MEMOKWANT * (++memoryN))) == NULL)
+                    {
+                        free(oldhead);
+                        CloseSetA(new_el);
+                        CloseSetA(CORE);
+                        ERROR(3);
+                    }
+                    if (keep != newhead)
+                        newtail = newhead + (newcount - 1) * size;
+                }
+                CopySetA(newtail, el);
+                newtail += size;
+            }
+            el += size;
+        }
+        oldtail = newhead;	/* new list becomes old */
+        newhead = oldhead;
+        oldhead = oldtail;
+        oldtail = newtail;
+        newtail = newhead;
+        oldcount = newcount;
+        newcount = 0;
+        j = memoryO;
+        memoryO = memoryN;
+        memoryN = j;
     }
-    if (oldcount == 0) {
-	free(oldhead);
-	*reducts = NULL;
+    if (oldcount == 0)
+    {
+        free(oldhead);
+        *reducts = NULL;
     }
     else
-	*reducts = oldhead;
+        *reducts = oldhead;
     free(newhead);
     CloseSetA(CORE);
     CloseSetA(new_el);
@@ -648,150 +719,169 @@
 
 
 int RedRelSetA(setA * reducts, setA quasicore, setA P, setA Q,
-	       int matrix_type)
+               int matrix_type)
 {
     int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1,	/* size of the allocated memory    */
-	newcount = 0, oldcount;	/* number of new/old reducts       */
+                       newcount = 0, oldcount;	/* number of new/old reducts       */
     int no_A = _mainsys->attributes_num;
     setA arg,			/* arguments are elements of matrix */
-      oldhead,			/* head of static list of reducts  */
-      oldtail,			/* tail ends the old reducts list  */
-      el, el1,			/* elements of this list           */
-      new_el,			/* probably new element of the list */
-      newhead,			/* begin of new reducts            */
-      newtail;			/* tail of the list of new reducts */
+    oldhead,			/* head of static list of reducts  */
+    oldtail,			/* tail ends the old reducts list  */
+    el, el1,			/* elements of this list           */
+    new_el,			/* probably new element of the list */
+    newhead,			/* begin of new reducts            */
+    newtail;			/* tail of the list of new reducts */
     setA CORE, keep;
 
     CORE = InitEmptySetA();
     _rerror = 0;
     CoreRel(CORE, P, Q, matrix_type);
-    if (_rerror != 0) {
-	CloseSetA(CORE);
-	return (-_rerror);
+    if (_rerror != 0)
+    {
+        CloseSetA(CORE);
+        return (-_rerror);
     }
     OrSetA(CORE, CORE, quasicore);
-    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        CloseSetA(CORE);
+        ERROR(3);
     }
-    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	free(oldhead);
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        free(oldhead);
+        CloseSetA(CORE);
+        ERROR(3);
     }
     new_el = InitEmptySetA();
     arg = InitEmptySetA();
     oldtail = oldhead;
     newtail = newhead;
     start_of_tab(matrix_type);
-    if (!IsEmptySetA(CORE)) {	/*initializing the reducts list */
-	CopySetA(oldtail, CORE);
-	oldtail += size;
-	oldcount = 1;
+    if (!IsEmptySetA(CORE))  	/*initializing the reducts list */
+    {
+        CopySetA(oldtail, CORE);
+        oldtail += size;
+        oldcount = 1;
     }
     else
-	do {
-	    AndSetA(arg, _table_element, P);
-	    oldcount = 0;
-	    if (InterSetA(_table_element, Q))
-		for (atr = 0; atr < no_A; atr++)
-		    if (ContSetA(arg, atr)) {
-			ClearSetA(oldtail);
-			AddSetA(oldtail, atr);
-			oldtail += size;
-			oldcount++;
-		    }
-	    next_of_tab();
-	}
-	while ((oldcount == 0) && end_of_tab());
-    for (; end_of_tab(); next_of_tab()) {	/* for each element of matrix do  */
-	AndSetA(arg, _table_element, P);	/* take next element */
-	over = 0;
-	if (InterSetA(CORE, arg))
-	    continue;
-	if (!InterSetA(_table_element, Q))
-	    continue;
-	if (IsEmptySetA(arg))
-	    continue;
-	el = oldhead;
-	while (el < oldtail) {	/* compare element to all the old reducts  */
-	    if (!InterSetA(el, arg)) {	/* old reduct does not cover new element */
-		for (atr = 0; atr < no_A; atr++)	/* for each atribute of element */
-		    if (ContSetA(arg, atr)) {
-			CopySetA(new_el, el);	/* creating potentialy new reduct */
-			AddSetA(new_el, atr);
-			over = 0;
-			el1 = oldhead;
-			while ((el1 != el) && !over) {	/* comparing new reduct to all the old reducts */
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			el1 = el + size;
-			while ((el1 != oldtail) && !over) {
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			if (!over) {	/* appending new reduct to list */
-			    newcount++;
-			    if (newcount * size * _cluster_bytes >
-				memoryN * MEMOKWANT) {
-				keep = newhead;
-				if ((newhead =
-				     (setA) realloc(keep,
-						    MEMOKWANT *
-						    (++memoryN))) == NULL) {
-				    free(oldhead);
-				    CloseSetA(new_el);
-				    CloseSetA(arg);
-				    CloseSetA(CORE);
-				    ERROR(3);
-				}
-				if (keep != newhead)
-				    newtail = newhead + (newcount - 1) * size;
-			    }
-			    CopySetA(newtail, new_el);
-			    newtail += size;
-			}
-		    }
-	    }
-	    else {		/* old reduct covers new elemet */
-		newcount++;
-		if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
-		    keep = newhead;
-		    if ((newhead =
-			 (setA) realloc(keep,
-					MEMOKWANT * (++memoryN))) == NULL) {
-			free(oldhead);
-			CloseSetA(new_el);
-			CloseSetA(arg);
-			CloseSetA(CORE);
-			ERROR(3);
-		    }
-		    if (keep != newhead)
-			newtail = newhead + (newcount - 1) * size;
-		}
-		CopySetA(newtail, el);
-		newtail += size;
-	    }
-	    el += size;
-	}
-	oldtail = newhead;	/*  new list becomes old */
-	newhead = oldhead;
-	oldhead = oldtail;
-	oldtail = newtail;
-	newtail = newhead;
-	oldcount = newcount;
-	newcount = 0;
-	j = memoryO;
-	memoryO = memoryN;
-	memoryN = j;
+        do
+        {
+            AndSetA(arg, _table_element, P);
+            oldcount = 0;
+            if (InterSetA(_table_element, Q))
+                for (atr = 0; atr < no_A; atr++)
+                    if (ContSetA(arg, atr))
+                    {
+                        ClearSetA(oldtail);
+                        AddSetA(oldtail, atr);
+                        oldtail += size;
+                        oldcount++;
+                    }
+            next_of_tab();
+        }
+        while ((oldcount == 0) && end_of_tab());
+    for (; end_of_tab(); next_of_tab())  	/* for each element of matrix do  */
+    {
+        AndSetA(arg, _table_element, P);	/* take next element */
+        over = 0;
+        if (InterSetA(CORE, arg))
+            continue;
+        if (!InterSetA(_table_element, Q))
+            continue;
+        if (IsEmptySetA(arg))
+            continue;
+        el = oldhead;
+        while (el < oldtail)  	/* compare element to all the old reducts  */
+        {
+            if (!InterSetA(el, arg))  	/* old reduct does not cover new element */
+            {
+                for (atr = 0; atr < no_A; atr++)	/* for each atribute of element */
+                    if (ContSetA(arg, atr))
+                    {
+                        CopySetA(new_el, el);	/* creating potentialy new reduct */
+                        AddSetA(new_el, atr);
+                        over = 0;
+                        el1 = oldhead;
+                        while ((el1 != el) && !over)  	/* comparing new reduct to all the old reducts */
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        el1 = el + size;
+                        while ((el1 != oldtail) && !over)
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        if (!over)  	/* appending new reduct to list */
+                        {
+                            newcount++;
+                            if (newcount * size * _cluster_bytes >
+                                    memoryN * MEMOKWANT)
+                            {
+                                keep = newhead;
+                                if ((newhead =
+                                            (setA) realloc(keep,
+                                                           MEMOKWANT *
+                                                           (++memoryN))) == NULL)
+                                {
+                                    free(oldhead);
+                                    CloseSetA(new_el);
+                                    CloseSetA(arg);
+                                    CloseSetA(CORE);
+                                    ERROR(3);
+                                }
+                                if (keep != newhead)
+                                    newtail = newhead + (newcount - 1) * size;
+                            }
+                            CopySetA(newtail, new_el);
+                            newtail += size;
+                        }
+                    }
+            }
+            else  		/* old reduct covers new elemet */
+            {
+                newcount++;
+                if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT)
+                {
+                    keep = newhead;
+                    if ((newhead =
+                                (setA) realloc(keep,
+                                               MEMOKWANT * (++memoryN))) == NULL)
+                    {
+                        free(oldhead);
+                        CloseSetA(new_el);
+                        CloseSetA(arg);
+                        CloseSetA(CORE);
+                        ERROR(3);
+                    }
+                    if (keep != newhead)
+                        newtail = newhead + (newcount - 1) * size;
+                }
+                CopySetA(newtail, el);
+                newtail += size;
+            }
+            el += size;
+        }
+        oldtail = newhead;	/*  new list becomes old */
+        newhead = oldhead;
+        oldhead = oldtail;
+        oldtail = newtail;
+        newtail = newhead;
+        oldcount = newcount;
+        newcount = 0;
+        j = memoryO;
+        memoryO = memoryN;
+        memoryN = j;
     }
-    if (oldcount == 0) {
-	free(oldhead);
-	*reducts = NULL;
+    if (oldcount == 0)
+    {
+        free(oldhead);
+        *reducts = NULL;
     }
     else
-	*reducts = oldhead;
+        *reducts = oldhead;
     free(newhead);
     CloseSetA(CORE);
     CloseSetA(arg);
@@ -802,137 +892,156 @@
 int RedSetA(setA * reducts, setA quasicore, int matrix_type)
 {
     int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1,	/* size of the allocated memory  */
-	newcount = 0, oldcount;	/* number of new/old reducts  */
+                       newcount = 0, oldcount;	/* number of new/old reducts  */
     int no_A = _mainsys->attributes_num;
     setA oldhead,		/* head of static list of reducts  */
-      oldtail,			/* tail ends the old reducts list  */
-      el, el1,			/* elements of this list           */
-      new_el,			/* probably new element of the list */
-      newhead,			/* begin of new reducts            */
-      newtail;			/* tail of the list of new reducts */
+    oldtail,			/* tail ends the old reducts list  */
+    el, el1,			/* elements of this list           */
+    new_el,			/* probably new element of the list */
+    newhead,			/* begin of new reducts            */
+    newtail;			/* tail of the list of new reducts */
     setA CORE, keep;
 
     CORE = InitEmptySetA();
     _rerror = 0;
     Core(CORE, matrix_type);
-    if (_rerror != 0) {
-	CloseSetA(CORE);
-	return (-_rerror);
+    if (_rerror != 0)
+    {
+        CloseSetA(CORE);
+        return (-_rerror);
     }
     OrSetA(CORE, CORE, quasicore);
-    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        CloseSetA(CORE);
+        ERROR(3);
     }
-    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
-	free(oldhead);
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((newhead = (setA) malloc(MEMOKWANT)) == NULL)
+    {
+        free(oldhead);
+        CloseSetA(CORE);
+        ERROR(3);
     }
     new_el = InitEmptySetA();
     oldtail = oldhead;
     newtail = newhead;
     start_of_tab(matrix_type);
-    if (!IsEmptySetA(CORE)) {	/*initializing  the reducts list */
-	CopySetA(oldtail, CORE);
-	oldtail += size, oldcount = 1;
+    if (!IsEmptySetA(CORE))  	/*initializing  the reducts list */
+    {
+        CopySetA(oldtail, CORE);
+        oldtail += size, oldcount = 1;
     }
     else
-	do {
-	    oldcount = 0;
-	    for (atr = 0; atr < no_A; atr++)
-		if (ContSetA(_table_element, atr)) {
-		    ClearSetA(oldtail);
-		    AddSetA(oldtail, atr);
-		    oldtail += size;
-		    oldcount++;
-		}
-	    next_of_tab();
-	}
-	while ((oldcount == 0) && end_of_tab());
-    for (; end_of_tab(); next_of_tab()) {	/* for each element of matrix do  */
-	over = 0;
-	if (InterSetA(_table_element, CORE))
-	    continue;
-	if (IsEmptySetA(_table_element))
-	    continue;
-	el = oldhead;
-	while (el < oldtail) {	/* compare elment to all the old reducts  */
-	    if (!InterSetA(el, _table_element)) {	/* old reduct does not cover element */
-		for (atr = 0; atr < no_A; atr++)	/* for each atribute of element  */
-		    if (ContSetA(_table_element, atr)) {
-			CopySetA(new_el, el);	/* creating potentialy new reduct */
-			AddSetA(new_el, atr);
-			over = 0;
-			el1 = oldhead;
-			while ((el1 != el) && !over) {	/* comparing new reduct to all the old reducts */
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			el1 = el + size;
-			while ((el1 != oldtail) && !over) {
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			if (!over) {	/* appending new reduct to list */
-			    newcount++;
-			    if (newcount * size * _cluster_bytes >
-				memoryN * MEMOKWANT) {
-				keep = newhead;
-				if ((newhead =
-				     (setA) realloc(keep,
-						    MEMOKWANT *
-						    (++memoryN))) == NULL) {
-				    free(oldhead);
-				    CloseSetA(new_el);
-				    CloseSetA(CORE);
-				    ERROR(3);
-				}
-				if (keep != newhead)
-				    newtail = newhead + (newcount - 1) * size;
-			    }
-			    CopySetA(newtail, new_el);
-			    newtail += size;
-			}
-		    }
-	    }
-	    else {		/* old reduct covers new element */
-		newcount++;
-		if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
-		    keep = newhead;
-		    if ((newhead =
-			 (setA) realloc(keep,
-					MEMOKWANT * (++memoryN))) == NULL) {
-			free(oldhead);
-			CloseSetA(new_el);
-			CloseSetA(CORE);
-			ERROR(3);
-		    }
-		    if (keep != newhead)
-			newtail = newhead + (newcount - 1) * size;
-		}
-		CopySetA(newtail, el);
-		newtail += size;
-	    }
-	    el += size;
-	}
-	oldtail = newhead;	/* new list becomes old */
-	newhead = oldhead;
-	oldhead = oldtail;
-	oldtail = newtail;
-	newtail = newhead;
-	oldcount = newcount;
-	newcount = 0;
-	j = memoryO;
-	memoryO = memoryN;
-	memoryN = j;
+        do
+        {
+            oldcount = 0;
+            for (atr = 0; atr < no_A; atr++)
+                if (ContSetA(_table_element, atr))
+                {
+                    ClearSetA(oldtail);
+                    AddSetA(oldtail, atr);
+                    oldtail += size;
+                    oldcount++;
+                }
+            next_of_tab();
+        }
+        while ((oldcount == 0) && end_of_tab());
+    for (; end_of_tab(); next_of_tab())  	/* for each element of matrix do  */
+    {
+        over = 0;
+        if (InterSetA(_table_element, CORE))
+            continue;
+        if (IsEmptySetA(_table_element))
+            continue;
+        el = oldhead;
+        while (el < oldtail)  	/* compare elment to all the old reducts  */
+        {
+            if (!InterSetA(el, _table_element))  	/* old reduct does not cover element */
+            {
+                for (atr = 0; atr < no_A; atr++)	/* for each atribute of element  */
+                    if (ContSetA(_table_element, atr))
+                    {
+                        CopySetA(new_el, el);	/* creating potentialy new reduct */
+                        AddSetA(new_el, atr);
+                        over = 0;
+                        el1 = oldhead;
+                        while ((el1 != el) && !over)  	/* comparing new reduct to all the old reducts */
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        el1 = el + size;
+                        while ((el1 != oldtail) && !over)
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        if (!over)  	/* appending new reduct to list */
+                        {
+                            newcount++;
+                            if (newcount * size * _cluster_bytes >
+                                    memoryN * MEMOKWANT)
+                            {
+                                keep = newhead;
+                                if ((newhead =
+                                            (setA) realloc(keep,
+                                                           MEMOKWANT *
+                                                           (++memoryN))) == NULL)
+                                {
+                                    free(oldhead);
+                                    CloseSetA(new_el);
+                                    CloseSetA(CORE);
+                                    ERROR(3);
+                                }
+                                if (keep != newhead)
+                                    newtail = newhead + (newcount - 1) * size;
+                            }
+                            CopySetA(newtail, new_el);
+                            newtail += size;
+                        }
+                    }
+            }
+            else  		/* old reduct covers new element */
+            {
+                newcount++;
+                if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT)
+                {
+                    keep = newhead;
+                    if ((newhead =
+                                (setA) realloc(keep,
+                                               MEMOKWANT * (++memoryN))) == NULL)
+                    {
+                        free(oldhead);
+                        CloseSetA(new_el);
+                        CloseSetA(CORE);
+                        ERROR(3);
+                    }
+                    if (keep != newhead)
+                        newtail = newhead + (newcount - 1) * size;
+                }
+                CopySetA(newtail, el);
+                newtail += size;
+            }
+            el += size;
+        }
+        oldtail = newhead;	/* new list becomes old */
+        newhead = oldhead;
+        oldhead = oldtail;
+        oldtail = newtail;
+        newtail = newhead;
+        oldcount = newcount;
+        newcount = 0;
+        j = memoryO;
+        memoryO = memoryN;
+        memoryN = j;
     }
-    if (oldcount == 0) {
-	free(oldhead);
-	*reducts = NULL;
+    if (oldcount == 0)
+    {
+        free(oldhead);
+        *reducts = NULL;
     }
     else
-	*reducts = oldhead;
+        *reducts = oldhead;
     free(newhead);
     CloseSetA(CORE);
     CloseSetA(new_el);
@@ -944,111 +1053,126 @@
     int atr, over, size = _mainsys->setAsize, newcount = 0, oldcount;	/* number of new,old reducts       */
     int no_A = _mainsys->attributes_num;
     setA arg,			/* arguments are elements of matrix */
-      oldhead,			/* head of static list of reducts  */
-      oldtail,			/* tail ends the old reducts list  */
-      el, el1,			/* elements of this list           */
-      new_el,			/* probably new element of the list */
-      newhead,			/* begin of new reducts            */
-      newtail;			/* tail of the list of new reducts */
+    oldhead,			/* head of static list of reducts  */
+    oldtail,			/* tail ends the old reducts list  */
+    el, el1,			/* elements of this list           */
+    new_el,			/* probably new element of the list */
+    newhead,			/* begin of new reducts            */
+    newtail;			/* tail of the list of new reducts */
     setA CORE;
 
     if (N == 0)
-	return 0;
+        return 0;
     CORE = InitEmptySetA();
     _rerror = 0;
     CoreRel(CORE, P, Q, matrix_type);
-    if (_rerror != 0) {
-	CloseSetA(CORE);
-	return (-_rerror);
+    if (_rerror != 0)
+    {
+        CloseSetA(CORE);
+        return (-_rerror);
     }
-    if ((oldhead = (setA) malloc(N * size * _cluster_bytes)) == NULL) {
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((oldhead = (setA) malloc(N * size * _cluster_bytes)) == NULL)
+    {
+        CloseSetA(CORE);
+        ERROR(3);
     }
-    if ((newhead = (setA) malloc(N * size * _cluster_bytes)) == NULL) {
-	free(oldhead);
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((newhead = (setA) malloc(N * size * _cluster_bytes)) == NULL)
+    {
+        free(oldhead);
+        CloseSetA(CORE);
+        ERROR(3);
     }
     new_el = InitEmptySetA();
     arg = InitEmptySetA();
     oldtail = oldhead;
     newtail = newhead;
     start_of_tab(matrix_type);
-    if (!IsEmptySetA(CORE)) {	/* initializing  the reducts list  */
-	CopySetA(oldtail, CORE);
-	oldtail += size, oldcount = 1;
+    if (!IsEmptySetA(CORE))  	/* initializing  the reducts list  */
+    {
+        CopySetA(oldtail, CORE);
+        oldtail += size, oldcount = 1;
     }
     else
-	do {
-	    AndSetA(arg, _table_element, P);
-	    oldcount = 0;
-	    if (InterSetA(_table_element, Q))
-		for (atr = 0; atr < no_A; atr++)
-		    if (ContSetA(arg, atr) && (oldcount < N)) {
-			ClearSetA(oldtail);
-			AddSetA(oldtail, atr);
-			oldtail += size;
-			oldcount++;
-		    }
-	    next_of_tab();
-	}
-	while ((oldcount == 0) && end_of_tab());
-    for (; end_of_tab(); next_of_tab()) {	/* for each element of matrix do */
-	AndSetA(arg, _table_element, P);	/* take next element */
-	over = 0;
-	if (InterSetA(CORE, arg))
-	    continue;
-	if (!InterSetA(_table_element, Q))
-	    continue;
-	if (IsEmptySetA(arg))
-	    continue;
-	el = oldhead;
-	while (el < oldtail) {	/* compare element to all the old reducts  */
-	    if (!InterSetA(el, arg)) {	/* old reduct does not cover element */
-		for (atr = 0; atr < no_A; atr++)	/* for each atribute of elememt */
-		    if (ContSetA(arg, atr) && (newcount < N)) {
-			CopySetA(new_el, el);	/* creating potentialy new reduct */
-			AddSetA(new_el, atr);
-			over = 0;
-			el1 = oldhead;
-			while ((el1 != el) && !over) {	/* comparing new reduct to all the old reducts */
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			el1 = el + size;
-			while ((el1 != oldtail) && !over) {
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			if (!over) {	/* appending new reduct to list */
-			    CopySetA(newtail, new_el);
-			    newtail += size;
-			    newcount++;
-			}
-		    }
-	    }
-	    else if (newcount < N) {
-		CopySetA(newtail, el);
-		newtail += size;
-		newcount++;
-	    }
-	    el += size;
-	}
-	oldtail = newhead;	/* new list becomes old */
-	newhead = oldhead;
-	oldhead = oldtail;
-	oldtail = newtail;
-	newtail = newhead;
-	oldcount = newcount;
-	newcount = 0;
+        do
+        {
+            AndSetA(arg, _table_element, P);
+            oldcount = 0;
+            if (InterSetA(_table_element, Q))
+                for (atr = 0; atr < no_A; atr++)
+                    if (ContSetA(arg, atr) && (oldcount < N))
+                    {
+                        ClearSetA(oldtail);
+                        AddSetA(oldtail, atr);
+                        oldtail += size;
+                        oldcount++;
+                    }
+            next_of_tab();
+        }
+        while ((oldcount == 0) && end_of_tab());
+    for (; end_of_tab(); next_of_tab())  	/* for each element of matrix do */
+    {
+        AndSetA(arg, _table_element, P);	/* take next element */
+        over = 0;
+        if (InterSetA(CORE, arg))
+            continue;
+        if (!InterSetA(_table_element, Q))
+            continue;
+        if (IsEmptySetA(arg))
+            continue;
+        el = oldhead;
+        while (el < oldtail)  	/* compare element to all the old reducts  */
+        {
+            if (!InterSetA(el, arg))  	/* old reduct does not cover element */
+            {
+                for (atr = 0; atr < no_A; atr++)	/* for each atribute of elememt */
+                    if (ContSetA(arg, atr) && (newcount < N))
+                    {
+                        CopySetA(new_el, el);	/* creating potentialy new reduct */
+                        AddSetA(new_el, atr);
+                        over = 0;
+                        el1 = oldhead;
+                        while ((el1 != el) && !over)  	/* comparing new reduct to all the old reducts */
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        el1 = el + size;
+                        while ((el1 != oldtail) && !over)
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        if (!over)  	/* appending new reduct to list */
+                        {
+                            CopySetA(newtail, new_el);
+                            newtail += size;
+                            newcount++;
+                        }
+                    }
+            }
+            else if (newcount < N)
+            {
+                CopySetA(newtail, el);
+                newtail += size;
+                newcount++;
+            }
+            el += size;
+        }
+        oldtail = newhead;	/* new list becomes old */
+        newhead = oldhead;
+        oldhead = oldtail;
+        oldtail = newtail;
+        newtail = newhead;
+        oldcount = newcount;
+        newcount = 0;
     }
-    if (oldcount == 0) {
-	free(oldhead);
-	*reducts = NULL;
+    if (oldcount == 0)
+    {
+        free(oldhead);
+        *reducts = NULL;
     }
     else
-	*reducts = oldhead;
+        *reducts = oldhead;
     free(newhead);
     CloseSetA(CORE);
     CloseSetA(arg);
@@ -1061,104 +1185,119 @@
     int atr, over, size = _mainsys->setAsize, newcount = 0, oldcount;	/* sizes of reduct lists */
     int no_A = _mainsys->attributes_num;
     setA oldhead,		/* head of static list of reducts  */
-      oldtail,			/* tail ends the old reducts list  */
-      el, el1,			/* elements of this list           */
-      new_el,			/* probably new element of the list */
-      newhead,			/* begin of new reducts            */
-      newtail;			/* tail of the list of new reducts */
+    oldtail,			/* tail ends the old reducts list  */
+    el, el1,			/* elements of this list           */
+    new_el,			/* probably new element of the list */
+    newhead,			/* begin of new reducts            */
+    newtail;			/* tail of the list of new reducts */
     setA CORE;
 
     if (N == 0)
-	return 0;
+        return 0;
     CORE = InitEmptySetA();
     _rerror = 0;
     Core(CORE, matrix_type);
-    if (_rerror != 0) {
-	CloseSetA(CORE);
-	return (-_rerror);
+    if (_rerror != 0)
+    {
+        CloseSetA(CORE);
+        return (-_rerror);
     }
-    if ((oldhead = (setA) malloc(N * size * _cluster_bytes)) == NULL) {
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((oldhead = (setA) malloc(N * size * _cluster_bytes)) == NULL)
+    {
+        CloseSetA(CORE);
+        ERROR(3);
     }
-    if ((newhead = (setA) malloc(N * size * _cluster_bytes)) == NULL) {
-	free(oldhead);
-	CloseSetA(CORE);
-	ERROR(3);
+    if ((newhead = (setA) malloc(N * size * _cluster_bytes)) == NULL)
+    {
+        free(oldhead);
+        CloseSetA(CORE);
+        ERROR(3);
     }
     new_el = InitEmptySetA();
     oldtail = oldhead;
     newtail = newhead;
     start_of_tab(matrix_type);
-    if (!IsEmptySetA(CORE)) {	/*initializing  the reducts list */
-	CopySetA(oldtail, CORE);
-	oldtail += size, oldcount = 1;
+    if (!IsEmptySetA(CORE))  	/*initializing  the reducts list */
+    {
+        CopySetA(oldtail, CORE);
+        oldtail += size, oldcount = 1;
     }
     else
-	do {
-	    oldcount = 0;
-	    for (atr = 0; atr < no_A; atr++)
-		if (ContSetA(_table_element, atr) && (oldcount < N)) {
-		    ClearSetA(oldtail);
-		    AddSetA(oldtail, atr);
-		    oldtail += size;
-		    oldcount++;
-		}
-	    next_of_tab();
-	}
-	while ((oldcount == 0) && end_of_tab());
-    for (; end_of_tab(); next_of_tab()) {	/* for each element of matrix do  */
-	over = 0;
-	if (InterSetA(_table_element, CORE))
-	    continue;
-	if (IsEmptySetA(_table_element))
-	    continue;
-	el = oldhead;
-	while (el < oldtail) {	/* compare element to all the old reducts  */
-	    if (!InterSetA(el, _table_element)) {	/* old reduct does not cover element */
-		for (atr = 0; atr < no_A; atr++)	/* for each atribute of element  */
-		    if (ContSetA(_table_element, atr) && (newcount < N)) {
-			CopySetA(new_el, el);	/* creating potentialy new element */
-			AddSetA(new_el, atr);
-			over = 0;
-			el1 = oldhead;
-			while ((el1 != el) && !over) {	/* comparing new reduct to old list */
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			el1 = el + size;
-			while ((el1 != oldtail) && !over) {
-			    over = InSetA(new_el, el1);
-			    el1 += size;
-			}
-			if (!over) {
-			    CopySetA(newtail, new_el);
-			    newtail += size;
-			    newcount++;
-			}
-		    }
-	    }
-	    else if (newcount < N) {
-		CopySetA(newtail, el);	/* rewriting reduct from old list */
-		newtail += size;
-		newcount++;
-	    }
-	    el += size;
-	}
-	oldtail = newhead;	/* new list becomes old */
-	newhead = oldhead;
-	oldhead = oldtail;
-	oldtail = newtail;
-	newtail = newhead;
-	oldcount = newcount;
-	newcount = 0;
+        do
+        {
+            oldcount = 0;
+            for (atr = 0; atr < no_A; atr++)
+                if (ContSetA(_table_element, atr) && (oldcount < N))
+                {
+                    ClearSetA(oldtail);
+                    AddSetA(oldtail, atr);
+                    oldtail += size;
+                    oldcount++;
+                }
+            next_of_tab();
+        }
+        while ((oldcount == 0) && end_of_tab());
+    for (; end_of_tab(); next_of_tab())  	/* for each element of matrix do  */
+    {
+        over = 0;
+        if (InterSetA(_table_element, CORE))
+            continue;
+        if (IsEmptySetA(_table_element))
+            continue;
+        el = oldhead;
+        while (el < oldtail)  	/* compare element to all the old reducts  */
+        {
+            if (!InterSetA(el, _table_element))  	/* old reduct does not cover element */
+            {
+                for (atr = 0; atr < no_A; atr++)	/* for each atribute of element  */
+                    if (ContSetA(_table_element, atr) && (newcount < N))
+                    {
+                        CopySetA(new_el, el);	/* creating potentialy new element */
+                        AddSetA(new_el, atr);
+                        over = 0;
+                        el1 = oldhead;
+                        while ((el1 != el) && !over)  	/* comparing new reduct to old list */
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        el1 = el + size;
+                        while ((el1 != oldtail) && !over)
+                        {
+                            over = InSetA(new_el, el1);
+                            el1 += size;
+                        }
+                        if (!over)
+                        {
+                            CopySetA(newtail, new_el);
+                            newtail += size;
+                            newcount++;
+                        }
+                    }
+            }
+            else if (newcount < N)
+            {
+                CopySetA(newtail, el);	/* rewriting reduct from old list */
+                newtail += size;
+                newcount++;
+            }
+            el += size;
+        }
+        oldtail = newhead;	/* new list becomes old */
+        newhead = oldhead;
+        oldhead = oldtail;
+        oldtail = newtail;
+        newtail = newhead;
+        oldcount = newcount;
+        newcount = 0;
     }
-    if (oldcount == 0) {
-	free(oldhead);
-	*reducts = NULL;
+    if (oldcount == 0)
+    {
+        free(oldhead);
+        *reducts = NULL;
     }
     else
-	*reducts = oldhead;
+        *reducts = oldhead;
     free(newhead);
     CloseSetA(CORE);
     CloseSetA(new_el);

Modified: grass-addons/raster/mcda/r.roughset/reduct2.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct2.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/reduct2.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,19 +16,12 @@
  *   	    	 for details.
  *
  *****************************************************************************/
-
 /***                                                                       ***/
-
 /***               SOME MORE QUERIES FOR SYSTEM                            ***/
-
 /***              ( AUXILIARY  REDUCTS ROUTINES )                          ***/
-
 /***                                                                       ***/
-
 /***  part of the RSL system written by M.Gawrys J.Sienkiewicz             ***/
-
 /***                                                                       ***/
-
 /*****************************************************************************/
 
 
@@ -44,20 +37,21 @@
     over = InitEmptySetA();
     Core(red, matrix_type);
     for (i = 0; (i < _mainsys->attributes_num) && cont; i++)
-	if (IsCover(red, matrix_type))
-	    cont = 0;
-	else
-	    AddSetA(red, i);
+        if (IsCover(red, matrix_type))
+            cont = 0;
+        else
+            AddSetA(red, i);
     cont = 1;
     while (cont)
-	if (IsOrtho(red, over, matrix_type))
-	    cont = 0;
-	else
-	    for (i = 0; i < _mainsys->attributes_num; i++)
-		if (ContSetA(over, i)) {
-		    DelSetA(red, i);
-		    break;
-		}
+        if (IsOrtho(red, over, matrix_type))
+            cont = 0;
+        else
+            for (i = 0; i < _mainsys->attributes_num; i++)
+                if (ContSetA(over, i))
+                {
+                    DelSetA(red, i);
+                    break;
+                }
     CloseSetA(over);
     return 1;
 }
@@ -70,22 +64,25 @@
 
     over = InitEmptySetA();
     CoreRel(red, P, Q, matrix_type);
-    for (i = 0; (i < _mainsys->attributes_num) && cont; i++) {
-	if (IsCoverRel(red, P, Q, matrix_type))
-	    cont = 0;
-	else
-	    AddSetA(red, i);
+    for (i = 0; (i < _mainsys->attributes_num) && cont; i++)
+    {
+        if (IsCoverRel(red, P, Q, matrix_type))
+            cont = 0;
+        else
+            AddSetA(red, i);
     }
     cont = 1;
-    while (cont) {
-	if (IsOrthoRel(red, over, P, Q, matrix_type))
-	    cont = 0;
-	else
-	    for (i = 0; i < _mainsys->attributes_num; i++)
-		if (ContSetA(over, i)) {
-		    DelSetA(red, i);
-		    break;
-		}
+    while (cont)
+    {
+        if (IsOrthoRel(red, over, P, Q, matrix_type))
+            cont = 0;
+        else
+            for (i = 0; i < _mainsys->attributes_num; i++)
+                if (ContSetA(over, i))
+                {
+                    DelSetA(red, i);
+                    break;
+                }
     }
     CloseSetA(over);
     return 1;
@@ -104,27 +101,31 @@
     Core(red, matrix_type);
     fmax = CardCoef(over, matrix_type);
     max = CardCoef(red, matrix_type);
-    while (max < fmax) {
-	for (i = 0; i < _mainsys->attributes_num; i++)
-	    if (!ContSetA(red, i)) {
-		AddSetA(red, i);
-		f = CardCoef(red, matrix_type);
-		if (f >= max)
-		    max = f, atr = i;
-		DelSetA(red, i);
-	    }
-	AddSetA(red, atr);
+    while (max < fmax)
+    {
+        for (i = 0; i < _mainsys->attributes_num; i++)
+            if (!ContSetA(red, i))
+            {
+                AddSetA(red, i);
+                f = CardCoef(red, matrix_type);
+                if (f >= max)
+                    max = f, atr = i;
+                DelSetA(red, i);
+            }
+        AddSetA(red, atr);
     }
     cont = 1;
-    while (cont) {
-	if (IsOrtho(red, over, matrix_type))
-	    cont = 0;
-	else
-	    for (i = 0; i < _mainsys->attributes_num; i++)
-		if (ContSetA(over, i)) {
-		    DelSetA(red, i);
-		    break;
-		}
+    while (cont)
+    {
+        if (IsOrtho(red, over, matrix_type))
+            cont = 0;
+        else
+            for (i = 0; i < _mainsys->attributes_num; i++)
+                if (ContSetA(over, i))
+                {
+                    DelSetA(red, i);
+                    break;
+                }
     }
     CloseSetA(over);
     return 1;
@@ -140,30 +141,34 @@
     over = InitEmptySetA();
     CoreRel(red, P, Q, matrix_type);
     fmax = DependCoef(P, Q, matrix_type);
-    while (cont) {
-	max = 0;
-	for (i = 0; i < _mainsys->attributes_num; i++)
-	    if (ContSetA(P, i) && !ContSetA(red, i)) {
-		AddSetA(red, i);
-		f = DependCoef(red, Q, matrix_type);
-		if (f >= max)
-		    max = f, atr = i;
-		DelSetA(red, i);
-	    }
-	AddSetA(red, atr);
-	if (max == fmax)
-	    cont = 0;
+    while (cont)
+    {
+        max = 0;
+        for (i = 0; i < _mainsys->attributes_num; i++)
+            if (ContSetA(P, i) && !ContSetA(red, i))
+            {
+                AddSetA(red, i);
+                f = DependCoef(red, Q, matrix_type);
+                if (f >= max)
+                    max = f, atr = i;
+                DelSetA(red, i);
+            }
+        AddSetA(red, atr);
+        if (max == fmax)
+            cont = 0;
     }
     cont = 1;
-    while (cont) {
-	if (IsOrthoRel(red, over, P, Q, matrix_type))
-	    cont = 0;
-	else
-	    for (i = 0; i < _mainsys->attributes_num; i++)
-		if (ContSetA(over, i)) {
-		    DelSetA(red, i);
-		    break;
-		}
+    while (cont)
+    {
+        if (IsOrthoRel(red, over, P, Q, matrix_type))
+            cont = 0;
+        else
+            for (i = 0; i < _mainsys->attributes_num; i++)
+                if (ContSetA(over, i))
+                {
+                    DelSetA(red, i);
+                    break;
+                }
     }
     CloseSetA(over);
     return 1;
@@ -199,8 +204,8 @@
 
     min = _mainsys->attributes_num;
     for (i = 0, START_OF_MAT(reds, N); END_OF_MAT; i++, NEXT_OF_MAT)
-	if (min > (m = CardSetA(ELEM_OF_MAT)))
-	    min = m, num = i;
+        if (min > (m = CardSetA(ELEM_OF_MAT)))
+            min = m, num = i;
     return num;
 }
 
@@ -212,18 +217,20 @@
     min = _mainsys->attributes_num + 1;
     *newreds = (cluster_type *) malloc(N * size * _cluster_bytes);
     for (START_OF_MAT(reds, N); END_OF_MAT; NEXT_OF_MAT)
-	if (min > (m = CardSetA(ELEM_OF_MAT))) {
-	    min = m;
-	    num = 0;
-	    CopySetA(*newreds + num * size, ELEM_OF_MAT);
-	}
-	else if (min == m) {
-	    num++;
-	    CopySetA(*newreds + num * size, ELEM_OF_MAT);
-	}
+        if (min > (m = CardSetA(ELEM_OF_MAT)))
+        {
+            min = m;
+            num = 0;
+            CopySetA(*newreds + num * size, ELEM_OF_MAT);
+        }
+        else if (min == m)
+        {
+            num++;
+            CopySetA(*newreds + num * size, ELEM_OF_MAT);
+        }
     *newreds =
-	(cluster_type *) realloc(*newreds, (num + 1) * size * _cluster_bytes);
+        (cluster_type *) realloc(*newreds, (num + 1) * size * _cluster_bytes);
     if (*newreds == 0)
-	num = -1;
+        num = -1;
     return num + 1;
 }

Modified: grass-addons/raster/mcda/r.roughset/rset.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rset.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/rset.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,17 +16,11 @@
  *   	    	 for details.
  *
  *****************************************************************************/
-
 /***                                                                       ***/
-
 /***       OPERATIONS ON SETS OF ATTRIBUTES AND OBJECTS                    ***/
-
 /***                                                                       ***/
-
 /***  part of the RSL system written by M.Gawrys J. Sienkiewicz            ***/
-
 /***                                                                       ***/
-
 /*****************************************************************************/
 
 
@@ -45,7 +39,7 @@
 
     set = (setA) malloc(_mainsys->setAsize * _cluster_bytes);
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	set[cluster] = 0;
+        set[cluster] = 0;
     return set;
 }
 
@@ -56,7 +50,7 @@
 
     set = (setA) malloc(_mainsys->setOsize * _cluster_bytes);
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	set[cluster] = 0;
+        set[cluster] = 0;
     return set;
 }
 
@@ -67,11 +61,11 @@
 
     set = (setA) malloc(_mainsys->setAsize * _cluster_bytes);
     for (cluster = _mainsys->setAsize - 2; cluster >= 0; cluster--)
-	set[cluster] = ~(cluster_type) 0;
+        set[cluster] = ~(cluster_type) 0;
     set[_mainsys->setAsize - 1] = 0;
     for (attr = _mainsys->attributes_num - 1;
-	 attr >= _cluster_bits * (_mainsys->setAsize - 1); attr--)
-	AddSetA(set, attr);
+            attr >= _cluster_bits * (_mainsys->setAsize - 1); attr--)
+        AddSetA(set, attr);
     return set;
 }
 
@@ -82,11 +76,11 @@
 
     set = (setA) malloc(_mainsys->setOsize * _cluster_bytes);
     for (cluster = _mainsys->setOsize - 2; cluster >= 0; cluster--)
-	set[cluster] = ~(cluster_type) 0;
+        set[cluster] = ~(cluster_type) 0;
     set[_mainsys->setOsize - 1] = 0;
     for (attr = _mainsys->objects_num - 1;
-	 attr >= _cluster_bits * (_mainsys->setOsize - 1); attr--)
-	AddSetO(set, attr);
+            attr >= _cluster_bits * (_mainsys->setOsize - 1); attr--)
+        AddSetO(set, attr);
     return set;
 }
 
@@ -96,7 +90,7 @@
 
     ClearSetA(set);
     for (atr = 0; atr < num; atr++)
-	AddSetA(set, tab[atr]);
+        AddSetA(set, tab[atr]);
 }
 
 void TabToSetO(setO set, int num, int tab[])
@@ -105,7 +99,7 @@
 
     ClearSetO(set);
     for (obj = 0; obj < num; obj++)
-	AddSetO(set, tab[obj]);
+        AddSetO(set, tab[obj]);
 }
 
 void ArgToSetA(setA set, int num, ...)
@@ -116,7 +110,7 @@
     ClearSetA(set);
     va_start(list, num);
     for (atr = 0; atr < num; atr++)
-	AddSetA(set, va_arg(list, int));
+        AddSetA(set, va_arg(list, int));
 
     va_end(list);
 }
@@ -129,7 +123,7 @@
     ClearSetO(set);
     va_start(list, num);
     for (obj = 0; obj < num; obj++)
-	AddSetO(set, va_arg(list, int));
+        AddSetO(set, va_arg(list, int));
 
     va_end(list);
 }
@@ -149,7 +143,7 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	or[cluster] = s1[cluster] | s2[cluster];
+        or[cluster] = s1[cluster] | s2[cluster];
     return;
 }
 
@@ -158,7 +152,7 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	or[cluster] = s1[cluster] | s2[cluster];
+        or[cluster] = s1[cluster] | s2[cluster];
     return;
 }
 
@@ -167,7 +161,7 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	and[cluster] = s1[cluster] & s2[cluster];
+        and[cluster] = s1[cluster] & s2[cluster];
     return;
 }
 
@@ -176,7 +170,7 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	and[cluster] = s1[cluster] & s2[cluster];
+        and[cluster] = s1[cluster] & s2[cluster];
     return;
 }
 
@@ -185,7 +179,7 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	dif[cluster] = s1[cluster] & ~s2[cluster];
+        dif[cluster] = s1[cluster] & ~s2[cluster];
     return;
 }
 
@@ -194,7 +188,7 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	dif[cluster] = s1[cluster] & ~s2[cluster];
+        dif[cluster] = s1[cluster] & ~s2[cluster];
     return;
 }
 
@@ -204,15 +198,15 @@
     int cluster, obj;
 
     for (cluster = _mainsys->setOsize - 2; cluster >= 0; cluster--)
-	not[cluster] = ~set[cluster];
+        not[cluster] = ~set[cluster];
     cluster = _mainsys->setOsize - 1;
     for (obj =
-	 _mainsys->objects_num - 1 - _cluster_bits * (_mainsys->setOsize - 1);
-	 obj >= 0; obj--)
-	if (set[cluster] & _mask[obj])
-	    not[cluster] &= ~_mask[obj];
-	else
-	    not[cluster] |= _mask[obj];
+                _mainsys->objects_num - 1 - _cluster_bits * (_mainsys->setOsize - 1);
+            obj >= 0; obj--)
+        if (set[cluster] & _mask[obj])
+            not[cluster] &= ~_mask[obj];
+        else
+            not[cluster] |= _mask[obj];
     return;
 }
 
@@ -221,16 +215,16 @@
     int cluster, attr;
 
     for (cluster = _mainsys->setAsize - 2; cluster >= 0; cluster--)
-	not[cluster] = ~set[cluster];
+        not[cluster] = ~set[cluster];
     cluster = _mainsys->setAsize - 1;
     for (attr =
-	 _mainsys->attributes_num - 1 - _cluster_bits * (_mainsys->setAsize -
-							 1); attr >= 0;
-	 attr--)
-	if (set[cluster] & _mask[attr])
-	    not[cluster] &= ~_mask[attr];
-	else
-	    not[cluster] |= _mask[attr];
+                _mainsys->attributes_num - 1 - _cluster_bits * (_mainsys->setAsize -
+                        1); attr >= 0;
+            attr--)
+        if (set[cluster] & _mask[attr])
+            not[cluster] &= ~_mask[attr];
+        else
+            not[cluster] |= _mask[attr];
     return;
 }
 
@@ -239,7 +233,7 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	set[cluster] = 0;
+        set[cluster] = 0;
     return;
 }
 
@@ -248,7 +242,7 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	set[cluster] = 0;
+        set[cluster] = 0;
     return;
 }
 
@@ -257,11 +251,11 @@
     int cluster, obj;
 
     for (cluster = _mainsys->setOsize - 2; cluster >= 0; cluster--)
-	set[cluster] = ~(cluster_type) 0;
+        set[cluster] = ~(cluster_type) 0;
     set[_mainsys->setOsize - 1] = 0;
     for (obj = _mainsys->objects_num - 1;
-	 obj >= _cluster_bits * (_mainsys->setOsize - 1); obj--)
-	AddSetO(set, obj);
+            obj >= _cluster_bits * (_mainsys->setOsize - 1); obj--)
+        AddSetO(set, obj);
     return;
 }
 
@@ -270,43 +264,43 @@
     int cluster, attr;
 
     for (cluster = _mainsys->setAsize - 2; cluster >= 0; cluster--)
-	set[cluster] = ~(cluster_type) 0;
+        set[cluster] = ~(cluster_type) 0;
     set[_mainsys->setAsize - 1] = 0;
     for (attr = _mainsys->attributes_num - 1;
-	 attr >= _cluster_bits * (_mainsys->setAsize - 1); attr--)
-	AddSetA(set, attr);
+            attr >= _cluster_bits * (_mainsys->setAsize - 1); attr--)
+        AddSetA(set, attr);
     return;
 }
 
 int AddSetO(setO set, int obj)
 {
     if (obj >= _mainsys->objects_num)
-	ERROR(9)
-	    set[obj / _cluster_bits] |= _mask[obj % _cluster_bits];
+        ERROR(9)
+        set[obj / _cluster_bits] |= _mask[obj % _cluster_bits];
     return 0;
 }
 
 int AddSetA(setA set, int attr)
 {
     if (attr >= _mainsys->attributes_num)
-	ERROR(9)
-	    set[attr / _cluster_bits] |= _mask[attr % _cluster_bits];
+        ERROR(9)
+        set[attr / _cluster_bits] |= _mask[attr % _cluster_bits];
     return 0;
 }
 
 int DelSetO(setO set, int obj)
 {
     if (obj >= _mainsys->objects_num)
-	ERROR(9)
-	    set[obj / _cluster_bits] &= ~_mask[obj % _cluster_bits];
+        ERROR(9)
+        set[obj / _cluster_bits] &= ~_mask[obj % _cluster_bits];
     return 0;
 }
 
 int DelSetA(setA set, int attr)
 {
     if (attr >= _mainsys->attributes_num)
-	ERROR(9)
-	    set[attr / _cluster_bits] &= ~_mask[attr % _cluster_bits];
+        ERROR(9)
+        set[attr / _cluster_bits] &= ~_mask[attr % _cluster_bits];
     return 0;
 }
 
@@ -315,8 +309,8 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	if (big[cluster] != (big[cluster] | small[cluster]))
-	    return 0;
+        if (big[cluster] != (big[cluster] | small[cluster]))
+            return 0;
     return 1;
 }
 
@@ -325,23 +319,23 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	if (big[cluster] != (big[cluster] | small[cluster]))
-	    return 0;
+        if (big[cluster] != (big[cluster] | small[cluster]))
+            return 0;
     return 1;
 }
 
 int ContSetA(setA set, int attr)
 {
     if (attr >= _mainsys->attributes_num)
-	ERROR(9)
-	    return (_mask[attr % _cluster_bits] & set[attr / _cluster_bits]);
+        ERROR(9)
+        return (_mask[attr % _cluster_bits] & set[attr / _cluster_bits]);
 }
 
 int ContSetO(setO set, int obj)
 {
     if (obj >= _mainsys->objects_num)
-	ERROR(9)
-	    return (_mask[obj % _cluster_bits] & set[obj / _cluster_bits]);
+        ERROR(9)
+        return (_mask[obj % _cluster_bits] & set[obj / _cluster_bits]);
 }
 
 int InterSetO(setO s1, setO s2)
@@ -349,8 +343,8 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	if (s1[cluster] & s2[cluster])
-	    return 1;
+        if (s1[cluster] & s2[cluster])
+            return 1;
     return 0;
 }
 
@@ -359,8 +353,8 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	if (s1[cluster] & s2[cluster])
-	    return 1;
+        if (s1[cluster] & s2[cluster])
+            return 1;
     return 0;
 }
 
@@ -370,8 +364,8 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	if (set[cluster])
-	    return 0;
+        if (set[cluster])
+            return 0;
     return 1;
 }
 
@@ -380,8 +374,8 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	if (set[cluster])
-	    return 0;
+        if (set[cluster])
+            return 0;
     return 1;
 }
 
@@ -390,8 +384,8 @@
     int obj, card = 0;
 
     for (obj = _mainsys->objects_num - 1; obj >= 0; obj--)
-	if (ContSetO(set, obj))
-	    card++;
+        if (ContSetO(set, obj))
+            card++;
     return card;
 }
 
@@ -400,16 +394,16 @@
     int cluster, attr, card = 0;
 
     for (cluster = _mainsys->setAsize - 2; cluster >= 0; cluster--)
-	for (attr = _cluster_bits - 1; attr >= 0; attr--)
-	    if (_mask[attr] & set[cluster])
-		card++;
+        for (attr = _cluster_bits - 1; attr >= 0; attr--)
+            if (_mask[attr] & set[cluster])
+                card++;
     cluster = _mainsys->setAsize - 1;
     for (attr =
-	 _mainsys->attributes_num - 1 - _cluster_bits * (_mainsys->setAsize -
-							 1); attr >= 0;
-	 attr--)
-	if (_mask[attr] & set[cluster])
-	    card++;
+                _mainsys->attributes_num - 1 - _cluster_bits * (_mainsys->setAsize -
+                        1); attr >= 0;
+            attr--)
+        if (_mask[attr] & set[cluster])
+            card++;
     return card;
 }
 
@@ -418,7 +412,7 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	dest[cluster] = source[cluster];
+        dest[cluster] = source[cluster];
     return;
 }
 
@@ -427,7 +421,7 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	dest[cluster] = source[cluster];
+        dest[cluster] = source[cluster];
     return;
 }
 
@@ -436,8 +430,8 @@
     int cluster;
 
     for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
-	if (set1[cluster] != set2[cluster])
-	    return 0;
+        if (set1[cluster] != set2[cluster])
+            return 0;
     return 1;
 }
 
@@ -446,8 +440,8 @@
     int cluster;
 
     for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
-	if (set1[cluster] != set2[cluster])
-	    return 0;
+        if (set1[cluster] != set2[cluster])
+            return 0;
     return 1;
 }
 
@@ -467,8 +461,8 @@
 
     ClearSetO(set);
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (val == GetA(obj, attr))
-	    AddSetO(set, obj);
+        if (val == GetA(obj, attr))
+            AddSetO(set, obj);
 }
 
 int ClassSetO(setO aclass, int obj, setA Q)
@@ -477,8 +471,8 @@
 
     ClearSetO(aclass);
     for (i = 0; i < _mainsys->objects_num; i++)
-	if (CompareA(i, obj, Q))
-	    AddSetO(aclass, i);
+        if (CompareA(i, obj, Q))
+            AddSetO(aclass, i);
     return 0;
 }
 
@@ -489,8 +483,8 @@
 
     printf("{");
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (ContSetO(set, obj))
-	    printf("%c%i", (i++ > 0 ? ',' : ' '), obj);
+        if (ContSetO(set, obj))
+            printf("%c%i", (i++ > 0 ? ',' : ' '), obj);
     printf(" }\n");
 }
 
@@ -500,7 +494,7 @@
 
     printf("{");
     for (attr = 0; attr < _mainsys->attributes_num; attr++)
-	if (ContSetA(set, attr))
-	    printf("%c%i", (i++ > 0 ? ',' : ' '), attr);
+        if (ContSetA(set, attr))
+            printf("%c%i", (i++ > 0 ? ',' : ' '), attr);
     printf(" }\n");
 }

Modified: grass-addons/raster/mcda/r.roughset/rsystem.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rsystem.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/rsystem.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -2,11 +2,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -32,435 +32,533 @@
 int      _rerror=0;
 
 SYSTEM  *InitEmptySys(void)
- { SYSTEM *sys;
-   int i;
-   cluster_type mask=1;
-   if ((sys=(SYSTEM *)malloc(sizeof(SYSTEM)))==NULL)
-     { _rerror=3; return NULL; }
-   for (i=0; i<_cluster_bits; i++)
-     { _mask[i]=mask;
+{
+    SYSTEM *sys;
+    int i;
+    cluster_type mask=1;
+    if ((sys=(SYSTEM *)malloc(sizeof(SYSTEM)))==NULL)
+    {
+        _rerror=3;
+        return NULL;
+    }
+    for (i=0; i<_cluster_bits; i++)
+    {
+        _mask[i]=mask;
         mask <<= 1;
-     }
-   sys->attributes_num=0;
-   sys->objects_num=0;
-   sys->description=NULL;
-   sys->descr_size=0;
-   sys->setAsize=0;
-   sys->setOsize=0;
-   sys->matA=NULL;
-   sys->matD=NULL;
-   sys->matX=NULL;
-   sys->matXsize=0;
-   return sys;
- }
+    }
+    sys->attributes_num=0;
+    sys->objects_num=0;
+    sys->description=NULL;
+    sys->descr_size=0;
+    sys->setAsize=0;
+    sys->setOsize=0;
+    sys->matA=NULL;
+    sys->matD=NULL;
+    sys->matX=NULL;
+    sys->matXsize=0;
+    return sys;
+}
 
 void SetParameters(SYSTEM *sys,int obj_num,int attr_num)
- { sys->attributes_num=attr_num;
-   sys->objects_num=obj_num;
-   sys->setAsize=1+(attr_num-1)/_cluster_bits;
-   sys->setOsize=1+(obj_num-1)/_cluster_bits;
- }
+{
+    sys->attributes_num=attr_num;
+    sys->objects_num=obj_num;
+    sys->setAsize=1+(attr_num-1)/_cluster_bits;
+    sys->setOsize=1+(obj_num-1)/_cluster_bits;
+}
 
 void ConnectDescr(SYSTEM *sys,void *descr,int size)
- { sys->description=descr;
-   sys->descr_size=size;
- }
+{
+    sys->description=descr;
+    sys->descr_size=size;
+}
 
 void SetName(SYSTEM *sys,char *name)
- { strncpy(sys->name,name,50); }
+{
+    strncpy(sys->name,name,50);
+}
 
 int FileToSys(SYSTEM *sys,char *filename)
- { FILE *source;
-   value_type *buf;
-   int descr_size,matAsize;
-   long len1,len2;
-   char string[50];
-   int c,n=0;
-   if(sys->matA!=NULL)
-     { free(sys->matA); sys->matA=NULL; }
-   if(sys->matD!=NULL)
-     { free(sys->matD); sys->matD=NULL; }
-   if(sys->matX!=NULL)
-     { free(sys->matX); sys->matX=NULL; }
-   if(sys->description!=NULL)
-     { free(sys->description); sys->description=NULL; }
-   if ((source=fopen(filename,"r"))==NULL)
-     ERROR(1)
-   if (!fscanf(source,"NAME%c",string))
-     ERROR(2)
-   if (string[0]!=':') ERROR(2)
-   if (!fgets(sys->name,48,source))
-     ERROR(2)
-   if (sys->name[strlen(sys->name)-1]=='\n')
-      sys->name[strlen(sys->name)-1]='\0'; 
-   else
-      while(fgetc(source)!='\n' && !feof(source));
-   if (!fscanf(source,"ATTRIBUTES:%i\n",&(sys->attributes_num)))
-     ERROR(2) 
-   if (!fscanf(source,"OBJECTS:%i\n",&(sys->objects_num)))
-     ERROR(2)
-   sys->setAsize=1+(sys->attributes_num-1)/_cluster_bits;
-   sys->setOsize=1+(sys->objects_num-1)/_cluster_bits;
-   matAsize=(sys->objects_num)*(sys->attributes_num);
-   if((buf=(value_type*)(setA)malloc(sizeof(value_type)*matAsize))==NULL)
-      ERROR(3) 
-   while (!feof(source) && n<matAsize)
-      if (fscanf(source,"%s",string)==NULL) 
-	 ERROR(2)
-      else if(string[0]=='?' || string[0]=='*')
-	  buf[n++]=(value_type)-1;
-      else if(sscanf(string,"%d",&c)==NULL) 
-	  ERROR(2)
-      else buf[n++]=(value_type)c;    
-   sys->matA=buf;
-   while(isspace(fgetc(source)));
-   if(!feof(source))
-     { len1=ftell(source)-1;
-       fseek(source,0l,SEEK_END);
-       len2=ftell(source);
-       fseek(source,len1,SEEK_SET);
-       descr_size=(int)(len2-len1);
-       buf=(value_type *)(setA)malloc(descr_size);
-       fread(buf,sizeof(char),descr_size,source);
-       sys->description=buf;
-       sys->descr_size=descr_size;
-     } 
-   fclose(source);
-   return 1;
- }
+{
+    FILE *source;
+    value_type *buf;
+    int descr_size,matAsize;
+    long len1,len2;
+    char string[50];
+    int c,n=0;
+    if (sys->matA!=NULL)
+    {
+        free(sys->matA);
+        sys->matA=NULL;
+    }
+    if (sys->matD!=NULL)
+    {
+        free(sys->matD);
+        sys->matD=NULL;
+    }
+    if (sys->matX!=NULL)
+    {
+        free(sys->matX);
+        sys->matX=NULL;
+    }
+    if (sys->description!=NULL)
+    {
+        free(sys->description);
+        sys->description=NULL;
+    }
+    if ((source=fopen(filename,"r"))==NULL)
+        ERROR(1)
+        if (!fscanf(source,"NAME%c",string))
+            ERROR(2)
+            if (string[0]!=':') ERROR(2)
+                if (!fgets(sys->name,48,source))
+                    ERROR(2)
+                    if (sys->name[strlen(sys->name)-1]=='\n')
+                        sys->name[strlen(sys->name)-1]='\0';
+                    else
+                        while (fgetc(source)!='\n' && !feof(source));
+    if (!fscanf(source,"ATTRIBUTES:%i\n",&(sys->attributes_num)))
+        ERROR(2)
+        if (!fscanf(source,"OBJECTS:%i\n",&(sys->objects_num)))
+            ERROR(2)
+            sys->setAsize=1+(sys->attributes_num-1)/_cluster_bits;
+    sys->setOsize=1+(sys->objects_num-1)/_cluster_bits;
+    matAsize=(sys->objects_num)*(sys->attributes_num);
+    if ((buf=(value_type*)(setA)malloc(sizeof(value_type)*matAsize))==NULL)
+        ERROR(3)
+        while (!feof(source) && n<matAsize)
+            if (fscanf(source,"%s",string)==NULL)
+                ERROR(2)
+                else if (string[0]=='?' || string[0]=='*')
+                    buf[n++]=(value_type)-1;
+                else if (sscanf(string,"%d",&c)==NULL)
+                    ERROR(2)
+                    else buf[n++]=(value_type)c;
+    sys->matA=buf;
+    while (isspace(fgetc(source)));
+    if (!feof(source))
+    {
+        len1=ftell(source)-1;
+        fseek(source,0l,SEEK_END);
+        len2=ftell(source);
+        fseek(source,len1,SEEK_SET);
+        descr_size=(int)(len2-len1);
+        buf=(value_type *)(setA)malloc(descr_size);
+        fread(buf,sizeof(char),descr_size,source);
+        sys->description=buf;
+        sys->descr_size=descr_size;
+    }
+    fclose(source);
+    return 1;
+}
 
 void ConnectA(SYSTEM *sys,value_type *buf)
- { sys->matA=buf; }
+{
+    sys->matA=buf;
+}
 
 void PutA(SYSTEM *sys,int obj,int atr,value_type val)
- {(sys->matA)[obj*(sys->attributes_num)+atr]=val; }
+{
+    (sys->matA)[obj*(sys->attributes_num)+atr]=val;
+}
 
 int FillAfromAscii(SYSTEM *sys,FILE *file)
- {
-  int k=0,j;
-  while (!feof(file)&&(k<Asize(sys)))
-   { if (fscanf(file,"%d",&j)==NULL) ERROR(2);
-     *(sys->matA+k++)=j;
-   }
-  return 0;
- }
+{
+    int k=0,j;
+    while (!feof(file)&&(k<Asize(sys)))
+    {
+        if (fscanf(file,"%d",&j)==NULL) ERROR(2);
+        *(sys->matA+k++)=j;
+    }
+    return 0;
+}
 
 int InitD(SYSTEM *sys)
- { cluster_type *buf;
-   int nby=(sys->attributes_num)/_cluster_bits; /* number of full clusters in element of tableD */
-   int nbi=sys->attributes_num%_cluster_bits;   /* number of bits in the last cluster */
-   int atrnum=sys->attributes_num;  		/* number of attributes */
-   int row,column,cluster,bit;
-   value_type *A=sys->matA;
-   cluster_type val,*ptr;
-   if(A==NULL) 
-      ERROR(5);
-   if ((buf=(setA)malloc(MatMemSize(sys,MATD)))==NULL)
-      ERROR(3);
-   ptr=buf;
-   for(row=1;row<sys->objects_num;row++)
-     for(column=0;column<row;column++)
-	{ for(cluster=0;cluster<nby;cluster++)
-	    { val=0;
-	      for(bit=0;bit<_cluster_bits;bit++)
-		 if(A[row*atrnum+_cluster_bits*cluster+bit]!=A[column*atrnum+_cluster_bits*cluster+bit] &&
-		    A[row*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1  && 
-		    A[column*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1  ) 
-		       val=val|_mask[bit];
-	      *ptr=val;
-	      ptr++;
-	    }
-	  if(nbi)
-	    { val=0;
-	      for(bit=0;bit<nbi;bit++)
-		 if(A[row*atrnum+_cluster_bits*cluster+bit]!=A[column*atrnum+_cluster_bits*cluster+bit] &&
-		    A[row*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1  && 
-		    A[column*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1  )
-		       val=val|_mask[bit];
-	      *ptr=val;
-	      ptr++;
-	    }
-	}
-   sys->matD=buf;
-   return MatMemSize(sys,MATD);
- }
+{
+    cluster_type *buf;
+    int nby=(sys->attributes_num)/_cluster_bits; /* number of full clusters in element of tableD */
+    int nbi=sys->attributes_num%_cluster_bits;   /* number of bits in the last cluster */
+    int atrnum=sys->attributes_num;  		/* number of attributes */
+    int row,column,cluster,bit;
+    value_type *A=sys->matA;
+    cluster_type val,*ptr;
+    if (A==NULL)
+        ERROR(5);
+    if ((buf=(setA)malloc(MatMemSize(sys,MATD)))==NULL)
+        ERROR(3);
+    ptr=buf;
+    for (row=1;row<sys->objects_num;row++)
+        for (column=0;column<row;column++)
+        {
+            for (cluster=0;cluster<nby;cluster++)
+            {
+                val=0;
+                for (bit=0;bit<_cluster_bits;bit++)
+                    if (A[row*atrnum+_cluster_bits*cluster+bit]!=A[column*atrnum+_cluster_bits*cluster+bit] &&
+                            A[row*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1  &&
+                            A[column*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1  )
+                        val=val|_mask[bit];
+                *ptr=val;
+                ptr++;
+            }
+            if (nbi)
+            {
+                val=0;
+                for (bit=0;bit<nbi;bit++)
+                    if (A[row*atrnum+_cluster_bits*cluster+bit]!=A[column*atrnum+_cluster_bits*cluster+bit] &&
+                            A[row*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1  &&
+                            A[column*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1  )
+                        val=val|_mask[bit];
+                *ptr=val;
+                ptr++;
+            }
+        }
+    sys->matD=buf;
+    return MatMemSize(sys,MATD);
+}
 
 int InitX(SYSTEM* sys,setA P,setA Q,int matrix_type)
- { setA head,tail,el,el1;
-   int  memo=1,count=0,no,dif,size,MEMOKWANT=Asize(_mainsys);
-   size=_mainsys->setAsize;
-   if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
-   tail=head;
-   el=InitEmptySetA();
-   for(start_of_tab(matrix_type);end_of_tab();next_of_tab())
-    { if ( !InterSetA(_table_element,Q) ) continue;
-      AndSetA(el,P,_table_element);
-      if ( IsEmptySetA(el) ) continue;
-      no=0;
-      dif=0;
-      for (el1=head;el1<tail;el1+=size)
-       if (InSetA(el,el1)) { no=1; break; }
-       else
-	 { if (InSetA(el1,el))  dif+=size,count--;
-	   else if (dif) CopySetA(el1-dif,el1);
-	 }
-      if (!no)
-       { if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
-	  if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
-		{ CloseSetA(el);
-		  ERROR(3);
-		}
-	 CopySetA(head+count*size,el);
-	 count++;
-	 tail=head+count*size;
-       }
+{
+    setA head,tail,el,el1;
+    int  memo=1,count=0,no,dif,size,MEMOKWANT=Asize(_mainsys);
+    size=_mainsys->setAsize;
+    if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
+    tail=head;
+    el=InitEmptySetA();
+    for (start_of_tab(matrix_type);end_of_tab();next_of_tab())
+    {
+        if ( !InterSetA(_table_element,Q) ) continue;
+        AndSetA(el,P,_table_element);
+        if ( IsEmptySetA(el) ) continue;
+        no=0;
+        dif=0;
+        for (el1=head;el1<tail;el1+=size)
+            if (InSetA(el,el1))
+            {
+                no=1;
+                break;
+            }
+            else
+            {
+                if (InSetA(el1,el))  dif+=size,count--;
+                else if (dif) CopySetA(el1-dif,el1);
+            }
+        if (!no)
+        {
+            if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
+                if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
+                {
+                    CloseSetA(el);
+                    ERROR(3);
+                }
+            CopySetA(head+count*size,el);
+            count++;
+            tail=head+count*size;
+        }
     }
-   CloseSetA(el);
-   if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
-   sys->matX=head;
-   sys->matXsize=count*size;
-   return(count);
- }
- 
+    CloseSetA(el);
+    if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
+    sys->matX=head;
+    sys->matXsize=count*size;
+    return(count);
+}
+
 int InitXforObject(SYSTEM* sys,int obj,setA P,setA Q,int matrix_type)
- {  setA head,tail,el,el1;
+{
+    setA head,tail,el,el1;
     int  memo=1,count=0,no,dif,MEMOKWANT=Asize(_mainsys);
     int size=_mainsys->setAsize;
     int obj2;
     if ((head=(setA)malloc(MEMOKWANT))==NULL)
-       ERROR(3);
+        ERROR(3);
     tail=head;
     el=InitEmptySetA();
-    for(obj2=0; obj2<_mainsys->objects_num; obj2++)
-    {  if ( obj==obj2 ) continue;
-       if ( matrix_type==MATA ) GetDfromA( el, obj, obj2 );
-       else 
-       {  _table_element=GetD( obj, obj2 );
-	  CopySetA( el, _table_element );
-       }
-       if ( !InterSetA(el,Q) ) continue;
-       AndSetA(el,P,el);
-       if ( IsEmptySetA(el) ) continue;
-       no=0;
-       dif=0;
-       for (el1=head;el1<tail;el1+=size)
-	  if (InSetA(el,el1)) { no=1; break; }
-	  else
-	  {  if (InSetA(el1,el))  dif+=size,count--;
-	     else if (dif) CopySetA(el1-dif,el1);
-	  }
-       if (!no)
-       {  if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
-	  if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
-	  {  CloseSetA(el);
-	     ERROR(3);
-	  }
-	  CopySetA(head+count*size,el);
-	  count++;
-	  tail=head+count*size;
-       }
+    for (obj2=0; obj2<_mainsys->objects_num; obj2++)
+    {
+        if ( obj==obj2 ) continue;
+        if ( matrix_type==MATA ) GetDfromA( el, obj, obj2 );
+        else
+        {
+            _table_element=GetD( obj, obj2 );
+            CopySetA( el, _table_element );
+        }
+        if ( !InterSetA(el,Q) ) continue;
+        AndSetA(el,P,el);
+        if ( IsEmptySetA(el) ) continue;
+        no=0;
+        dif=0;
+        for (el1=head;el1<tail;el1+=size)
+            if (InSetA(el,el1))
+            {
+                no=1;
+                break;
+            }
+            else
+            {
+                if (InSetA(el1,el))  dif+=size,count--;
+                else if (dif) CopySetA(el1-dif,el1);
+            }
+        if (!no)
+        {
+            if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
+                if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
+                {
+                    CloseSetA(el);
+                    ERROR(3);
+                }
+            CopySetA(head+count*size,el);
+            count++;
+            tail=head+count*size;
+        }
     }
     CloseSetA(el);
     if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL)
-       if (count>0) ERROR(3);
+        if (count>0) ERROR(3);
     sys->matX=head;
     sys->matXsize=count*size;
     return(count);
- }
+}
 
 int InitXforObjects(SYSTEM* sys,setO objects,setA P,setA Q,int matrix_type)
- {  setA head,tail,el,el1;
+{
+    setA head,tail,el,el1;
     int  memo=1,count=0,no,dif,size,MEMOKWANT=Asize(_mainsys);
     size=_mainsys->setAsize;
     if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
     tail=head;
     el=InitEmptySetA();
-    for(start_of_tab(matrix_type);end_of_tab();next_of_tab())
-    { 
-       if ( !ContSetO(objects,_table_row) &&
-	   !ContSetO(objects,_table_column) ) continue;
-       if ( !InterSetA(_table_element,Q) ) continue;
-       AndSetA(el,P,_table_element);
-       if ( IsEmptySetA(el) ) continue;
-       no=0;
-       dif=0;
-       for (el1=head;el1<tail;el1+=size)
-	  if (InSetA(el,el1)) { no=1; break; }
-	  else
-	  {  if (InSetA(el1,el))  dif+=size,count--;
-	     else if (dif) CopySetA(el1-dif,el1);
-	  }
-       if (!no)
-       {  if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
-	  if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
-	  {  CloseSetA(el);
-	     ERROR(3);
-	  }
-	  CopySetA(head+count*size,el);
-	  count++;
-	  tail=head+count*size;
-       }
+    for (start_of_tab(matrix_type);end_of_tab();next_of_tab())
+    {
+        if ( !ContSetO(objects,_table_row) &&
+                !ContSetO(objects,_table_column) ) continue;
+        if ( !InterSetA(_table_element,Q) ) continue;
+        AndSetA(el,P,_table_element);
+        if ( IsEmptySetA(el) ) continue;
+        no=0;
+        dif=0;
+        for (el1=head;el1<tail;el1+=size)
+            if (InSetA(el,el1))
+            {
+                no=1;
+                break;
+            }
+            else
+            {
+                if (InSetA(el1,el))  dif+=size,count--;
+                else if (dif) CopySetA(el1-dif,el1);
+            }
+        if (!no)
+        {
+            if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
+                if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
+                {
+                    CloseSetA(el);
+                    ERROR(3);
+                }
+            CopySetA(head+count*size,el);
+            count++;
+            tail=head+count*size;
+        }
     }
     CloseSetA(el);
     if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
     sys->matX=head;
     sys->matXsize=count*size;
     return(count);
- }
+}
 
 int InitXforObjectFromClass(SYSTEM* sys,int obj,setA P,setO aclass,int matrix_type)
- {  setA head,tail,el,el1;
+{
+    setA head,tail,el,el1;
     int  memo=1,count=0,no,dif,MEMOKWANT=Asize(_mainsys);
     int size=_mainsys->setAsize;
     int obj2;
     if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
     tail=head;
     el=InitEmptySetA();
-    for(obj2=0; obj2<_mainsys->objects_num; obj2++)
-    {  if ( ContSetO( aclass, obj2 ) ) continue;
-       if ( matrix_type==MATA ) GetDfromA( el, obj, obj2 );
-       else 
-       {  _table_element=GetD( obj, obj2 );
-	  CopySetA( el, _table_element );
-       }
-       AndSetA(el,P,el);
-       if ( IsEmptySetA(el) ) continue;
-       no=0;
-       dif=0;
-       for (el1=head;el1<tail;el1+=size)
-	  if (InSetA(el,el1)) { no=1; break; }
-	  else
-	  {  if (InSetA(el1,el))  dif+=size,count--;
-	     else if (dif) CopySetA(el1-dif,el1);
-	  }
-       if (!no)
-       {  if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
-	  if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
-	  {  CloseSetA(el);
-	     ERROR(3);
-	  }
-	  CopySetA(head+count*size,el);
-	  count++;
-	  tail=head+count*size;
-       }
+    for (obj2=0; obj2<_mainsys->objects_num; obj2++)
+    {
+        if ( ContSetO( aclass, obj2 ) ) continue;
+        if ( matrix_type==MATA ) GetDfromA( el, obj, obj2 );
+        else
+        {
+            _table_element=GetD( obj, obj2 );
+            CopySetA( el, _table_element );
+        }
+        AndSetA(el,P,el);
+        if ( IsEmptySetA(el) ) continue;
+        no=0;
+        dif=0;
+        for (el1=head;el1<tail;el1+=size)
+            if (InSetA(el,el1))
+            {
+                no=1;
+                break;
+            }
+            else
+            {
+                if (InSetA(el1,el))  dif+=size,count--;
+                else if (dif) CopySetA(el1-dif,el1);
+            }
+        if (!no)
+        {
+            if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
+                if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
+                {
+                    CloseSetA(el);
+                    ERROR(3);
+                }
+            CopySetA(head+count*size,el);
+            count++;
+            tail=head+count*size;
+        }
     }
     CloseSetA(el);
     if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
     sys->matX=head;
     sys->matXsize=count*size;
     return(count);
- }
+}
 
 
- 
+
 void UseSys(SYSTEM *sys)
- { _mainsys=sys; }
+{
+    _mainsys=sys;
+}
 
 int SysToFile(SYSTEM *sys,char *filename)
- { FILE *output;
-   int attr,obj;
-   if ((output=fopen(filename,"wb"))==NULL)
-     ERROR(1)
-   if (!fprintf(output,"NAME: %s\n",sys->name))
-     ERROR(4)
-   if (!fprintf(output,"ATTRIBUTES: %i\n",sys->attributes_num))
-     ERROR(4);
+{
+    FILE *output;
+    int attr,obj;
+    if ((output=fopen(filename,"wb"))==NULL)
+        ERROR(1)
+        if (!fprintf(output,"NAME: %s\n",sys->name))
+            ERROR(4)
+            if (!fprintf(output,"ATTRIBUTES: %i\n",sys->attributes_num))
+                ERROR(4);
     if (!fprintf(output,"OBJECTS: %i\n\n",sys->objects_num))
-     ERROR(4);
-   for(obj=0;obj<sys->objects_num;obj++)
-     { for(attr=0;attr<sys->attributes_num;attr++)
-	 if(sys->matA[obj*sys->attributes_num+attr]==(value_type)-1 )
-	  { if (!fprintf(output,"%c ",'?'))
-	     ERROR(4)
-	  }		
-         else if (!fprintf(output,"%i ",sys->matA[obj*sys->attributes_num+attr]))
-	   ERROR(4)
-       fprintf(output,"\n");
-     }
-   if(sys->descr_size!=0)
-     { fprintf(output,"\n");
-       fwrite(sys->description,sizeof(char),sys->descr_size,output); 
-     }  
-   fclose(output);
-   return 1;
- }
+        ERROR(4);
+    for (obj=0;obj<sys->objects_num;obj++)
+    {
+        for (attr=0;attr<sys->attributes_num;attr++)
+            if (sys->matA[obj*sys->attributes_num+attr]==(value_type)-1 )
+            {
+                if (!fprintf(output,"%c ",'?'))
+                    ERROR(4)
+                }
+            else if (!fprintf(output,"%i ",sys->matA[obj*sys->attributes_num+attr]))
+                ERROR(4)
+                fprintf(output,"\n");
+    }
+    if (sys->descr_size!=0)
+    {
+        fprintf(output,"\n");
+        fwrite(sys->description,sizeof(char),sys->descr_size,output);
+    }
+    fclose(output);
+    return 1;
+}
 
 void CloseSys(SYSTEM *sys)
- { if(sys->matA) free(sys->matA);
-   if(sys->matD) free(sys->matD);
-   if(sys->matX) free(sys->matX);
-   if(sys->description) free(sys->description);
-   free(sys);
- }
- 
+{
+    if (sys->matA) free(sys->matA);
+    if (sys->matD) free(sys->matD);
+    if (sys->matX) free(sys->matX);
+    if (sys->description) free(sys->description);
+    free(sys);
+}
+
 void CloseMat(SYSTEM *sys, int matrix_type)
- { switch (matrix_type)
-   { case (MATA): if(sys->matA) free(sys->matA);
-      		  sys->matA=NULL;
-      		  return;
-     case (MATD): if(sys->matD) free(sys->matD);
-	          sys->matD=NULL;
-	          return;
-     case (MATX): if(sys->matX) free(sys->matX);
-	          sys->matX=NULL;
-		  return;
-     default:	  _rerror=8;
-   }
- } 
- 
+{
+    switch (matrix_type)
+    {
+    case (MATA): if (sys->matA) free(sys->matA);
+        sys->matA=NULL;
+        return;
+    case (MATD): if (sys->matD) free(sys->matD);
+        sys->matD=NULL;
+        return;
+    case (MATX): if (sys->matX) free(sys->matX);
+        sys->matX=NULL;
+        return;
+    default:
+        _rerror=8;
+    }
+}
+
 void DisconMat(SYSTEM *sys, int matrix_type)
- { switch (matrix_type)
-   { case (MATA): sys->matA=NULL;
-      		  return;
-     case (MATD): sys->matD=NULL;
-	          return;
-     case (MATX): sys->matX=NULL;
-		  return;
-     default:	  _rerror=8;
-   }
- }
+{
+    switch (matrix_type)
+    {
+    case (MATA): sys->matA=NULL;
+        return;
+    case (MATD): sys->matD=NULL;
+        return;
+    case (MATX): sys->matX=NULL;
+        return;
+    default:
+        _rerror=8;
+    }
+}
 
 unsigned int Asize(SYSTEM *sys)
- { return  (unsigned int)(sys->attributes_num)
-	   *(unsigned int)(sys->objects_num);
- }
+{
+    return  (unsigned int)(sys->attributes_num)
+            *(unsigned int)(sys->objects_num);
+}
 
 unsigned int Dsize(SYSTEM *sys)
- { return  (unsigned int)(sys->objects_num-1)
-	  *(unsigned int)(sys->objects_num)/2
-	  *(unsigned int)(sys->setAsize);
- }
+{
+    return  (unsigned int)(sys->objects_num-1)
+            *(unsigned int)(sys->objects_num)/2
+            *(unsigned int)(sys->setAsize);
+}
 
 unsigned int Xsize(SYSTEM *sys)
- { return sys->matXsize; }
+{
+    return sys->matXsize;
+}
 
 unsigned int MatMemSize(SYSTEM *sys,int matrix_type)
- { switch (matrix_type)
-   { case (MATA): return Asize(sys)*sizeof(value_type);
-     case (MATD): return Dsize(sys)*sizeof(cluster_type);
-     case (MATX): return Xsize(sys)*sizeof(cluster_type);
-   }
-   ERROR(8)
- }
+{
+    switch (matrix_type)
+    {
+    case (MATA): return Asize(sys)*sizeof(value_type);
+    case (MATD): return Dsize(sys)*sizeof(cluster_type);
+    case (MATX): return Xsize(sys)*sizeof(cluster_type);
+    }
+    ERROR(8)
+}
 
 void *MatExist(SYSTEM *sys,int matrix_type)
- { switch (matrix_type)
-   { case (MATA): return (void *)sys->matA;
-     case (MATD): return (void *)sys->matD;
-     case (MATX): return (void *)sys->matX;
-   }
-   _rerror=8;
-   return NULL;
- } 
+{
+    switch (matrix_type)
+    {
+    case (MATA): return (void *)sys->matA;
+    case (MATD): return (void *)sys->matD;
+    case (MATX): return (void *)sys->matX;
+    }
+    _rerror=8;
+    return NULL;
+}
 
 int ObjectsNum(SYSTEM *sys)
- { return sys->objects_num ; }
+{
+    return sys->objects_num ;
+}
 
 int AttributesNum(SYSTEM *sys)
- { return sys->attributes_num; }
+{
+    return sys->attributes_num;
+}
 
 void *Description(SYSTEM *sys)
- { return sys->description; }
+{
+    return sys->description;
+}
 
 char *SysName(SYSTEM *sys)
- { return sys->name; }
+{
+    return sys->name;
+}

Modified: grass-addons/raster/mcda/r.roughset/rule1.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule1.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/rule1.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,19 +16,12 @@
  *   	    	 for details.
  *
  *****************************************************************************/
-
 /***                                                                       ***/
-
 /***               SOME MORE QUERIES FOR SYSTEM                            ***/
-
 /***                   ( MENAGING RULES )                                  ***/
-
 /***                                                                       ***/
-
 /*** part of the ROUGH system written by M.Gawrys J.Sienkiewicz            ***/
-
 /***                                                                       ***/
-
 /*****************************************************************************/
 
 
@@ -44,7 +37,7 @@
 int RuleEQ(value_type * first, value_type * second)
 {
     return !memcmp(first, second,
-		   _mainsys->attributes_num * sizeof(value_type));
+                   _mainsys->attributes_num * sizeof(value_type));
 }
 
 
@@ -54,8 +47,8 @@
     int size = _mainsys->attributes_num;
 
     for (i = 0; i < *count; i++)
-	if (RuleEQ(rules + i * size, rule))
-	    return;
+        if (RuleEQ(rules + i * size, rule))
+            return;
     RuleCopy(rules + (*count) * size, rule);
     *count += 1;
     return;

Modified: grass-addons/raster/mcda/r.roughset/rule2.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule2.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/rule2.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *					G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *				 Rough Set Library (RSL) ver. 2 original develop:
- *		         	M.Gawrys - J.Sienkiewicz 
+ *		         	M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,19 +16,12 @@
  *   	    	 for details.
  *
  *****************************************************************************/
-
 /***                                                                       ***/
-
 /***               SOME MORE QUERIES FOR SYSTEM                            ***/
-
 /***                   ( FINDING RULES )                                   ***/
-
 /***                                                                       ***/
-
 /***  part of the RSL system written by M.Gawrys J.Sienkiewicz             ***/
-
 /***                                                                       ***/
-
 /*****************************************************************************/
 
 
@@ -46,86 +39,93 @@
     value_type *rule = NULL;
 
     *rules =
-	(value_type *) malloc(memo * _mainsys->attributes_num *
-			      sizeof(value_type));
+        (value_type *) malloc(memo * _mainsys->attributes_num *
+                              sizeof(value_type));
     if (*rules == NULL)
-	ERROR(3);
+        ERROR(3);
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     rule =
-	(value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+        (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
     if (rule == NULL)
-	ERROR(3);
-    for (obj = 0; obj < _mainsys->objects_num; obj++) {
-	if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
-	    free(rule);
-	    return (-_rerror);
-	}
-	else if (!MatExist(_mainsys, MATX))
-	    continue;
-	n = Red(&reducts, MATX);
-	CloseMat(_mainsys, MATX);
-	if (memo < count + n) {
-	    memo = count + n;
-	    if ((*rules = (value_type *) realloc(*rules,
-						 memo *
-						 _mainsys->attributes_num *
-						 sizeof(value_type))) ==
-		NULL) {
-		free(reducts);
-		free(rule);
-		ERROR(3)
-	    }
-	}
-	for (red = 0; red < n; red++) {
-	    for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
-		if (ContSetA(reducts + red * size, attr) || ContSetA(Q, attr))
-		    rule[attr] = GetA(obj, attr);
-		else
-		    rule[attr] = MINUS;
-	    AddRule(*rules, &count, rule);
-	}
-	if (n > 0)
-	    free(reducts);
-	reducts = NULL;
+        ERROR(3);
+    for (obj = 0; obj < _mainsys->objects_num; obj++)
+    {
+        if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0)
+        {
+            free(rule);
+            return (-_rerror);
+        }
+        else if (!MatExist(_mainsys, MATX))
+            continue;
+        n = Red(&reducts, MATX);
+        CloseMat(_mainsys, MATX);
+        if (memo < count + n)
+        {
+            memo = count + n;
+            if ((*rules = (value_type *) realloc(*rules,
+                                                 memo *
+                                                 _mainsys->attributes_num *
+                                                 sizeof(value_type))) ==
+                    NULL)
+            {
+                free(reducts);
+                free(rule);
+                ERROR(3)
+            }
+        }
+        for (red = 0; red < n; red++)
+        {
+            for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+                if (ContSetA(reducts + red * size, attr) || ContSetA(Q, attr))
+                    rule[attr] = GetA(obj, attr);
+                else
+                    rule[attr] = MINUS;
+            AddRule(*rules, &count, rule);
+        }
+        if (n > 0)
+            free(reducts);
+        reducts = NULL;
     }
     free(rule);
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return count;
 }
 
 int AllRulesForReducts(value_type ** rules, cluster_type * reducts,
-		       int N, setA Q, int matrix_type)
+                       int N, setA Q, int matrix_type)
 {
     int red, num, i, count = 0;
     value_type *newrules = NULL;	/* rules for a single reduct */
 
     *rules = NULL;
-    for (red = 0; red < N; red++) {
-	num =
-	    AllRules(&newrules, reducts + red * _mainsys->setAsize, Q,
-		     matrix_type);
-	if ((*rules =
-	     (value_type *) realloc(*rules,
-				    (count +
-				     num) * _mainsys->attributes_num *
-				    sizeof(value_type))) == NULL) {
-	    free(newrules);
-	    ERROR(3)
-	}
-	for (i = 0; i < num; i++)
-	    AddRule(*rules, &count, newrules + i * _mainsys->attributes_num);
-	if (num > 0)
-	    free(newrules);
-	newrules = NULL;
+    for (red = 0; red < N; red++)
+    {
+        num =
+            AllRules(&newrules, reducts + red * _mainsys->setAsize, Q,
+                     matrix_type);
+        if ((*rules =
+                    (value_type *) realloc(*rules,
+                                           (count +
+                                            num) * _mainsys->attributes_num *
+                                           sizeof(value_type))) == NULL)
+        {
+            free(newrules);
+            ERROR(3)
+        }
+        for (i = 0; i < num; i++)
+            AddRule(*rules, &count, newrules + i * _mainsys->attributes_num);
+        if (num > 0)
+            free(newrules);
+        newrules = NULL;
     }
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return count;
 }
 
@@ -133,7 +133,7 @@
 int SelectRules(value_type ** rules, int *N, setO set, setA P, int option)
 {
     int i, j, obj, find, newXsize,
-	newN = 0, next = -1, size = _mainsys->attributes_num;
+    newN = 0, next = -1, size = _mainsys->attributes_num;
     setA red, newfull;
     SYSTEM *oldsys = _mainsys, *newsys = InitEmptySys();
     cluster_type *newX;
@@ -142,27 +142,31 @@
     SetParameters(newsys, *N, *N);
     newXsize = CardSetO(set) * (newsys->setAsize);
     newX = (cluster_type *) calloc(newXsize, _cluster_bytes);
-    if (newX == NULL) {
-	CloseSys(newsys);
-	ERROR(3);
+    if (newX == NULL)
+    {
+        CloseSys(newsys);
+        ERROR(3);
     }
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (ContSetO(set, obj))
-	    for (i = 0, next++; i < *N; i++) {
-		find = 1;
-		for (j = 0; j < _mainsys->attributes_num; j++) {
-		    if (!ContSetA(P, j))
-			continue;
-		    if ((*rules + i * size)[j] != GetA(obj, j))
-			if ((*rules + i * size)[j] != MINUS) {
-			    find = 0;
-			    break;
-			}
-		}
-		if (find)
-		    newX[next * newsys->setAsize + i / _cluster_bits] |=
-			_mask[i % _cluster_bits];
-	    }
+        if (ContSetO(set, obj))
+            for (i = 0, next++; i < *N; i++)
+            {
+                find = 1;
+                for (j = 0; j < _mainsys->attributes_num; j++)
+                {
+                    if (!ContSetA(P, j))
+                        continue;
+                    if ((*rules + i * size)[j] != GetA(obj, j))
+                        if ((*rules + i * size)[j] != MINUS)
+                        {
+                            find = 0;
+                            break;
+                        }
+                }
+                if (find)
+                    newX[next * newsys->setAsize + i / _cluster_bits] |=
+                        _mask[i % _cluster_bits];
+            }
     UseSys(newsys);
     newsys->matX = newX;
     newsys->matXsize = newXsize;
@@ -170,39 +174,43 @@
     InitX(newsys, newfull, newfull, MATX);
     free(newX);
     CloseSetA(newfull);
-    if (_rerror != 0) {
-	free(newsys);
-	UseSys(oldsys);
-	ERROR(3);
+    if (_rerror != 0)
+    {
+        free(newsys);
+        UseSys(oldsys);
+        ERROR(3);
     }
-    if (option == BESTOPT) {
-	i = Red(&red, MATX);
-	j = SelectOneShort(red, i);
+    if (option == BESTOPT)
+    {
+        i = Red(&red, MATX);
+        j = SelectOneShort(red, i);
     }
-    else {
-	red = InitEmptySetA();
-	RedOptim(red, MATX);
-	j = 0;
+    else
+    {
+        red = InitEmptySetA();
+        RedOptim(red, MATX);
+        j = 0;
     }
     newN = CardSetA(red + j * newsys->setAsize);
     newrules = (value_type *) malloc(newN * oldsys->attributes_num *
-				     sizeof(value_type));
-    if (newrules == NULL) {
-	CloseSys(newsys);
-	UseSys(oldsys);
-	ERROR(3);
+                                     sizeof(value_type));
+    if (newrules == NULL)
+    {
+        CloseSys(newsys);
+        UseSys(oldsys);
+        ERROR(3);
     }
     for (i = 0, obj = 0; i < *N; i++)
-	if (ContSetA(red + j * newsys->setAsize, i))
-	    memcpy(newrules + obj++ * oldsys->attributes_num,
-		   *rules + i * oldsys->attributes_num,
-		   oldsys->attributes_num * sizeof(value_type));
+        if (ContSetA(red + j * newsys->setAsize, i))
+            memcpy(newrules + obj++ * oldsys->attributes_num,
+                   *rules + i * oldsys->attributes_num,
+                   oldsys->attributes_num * sizeof(value_type));
     if (option == BESTOPT)
-	free(red);
+        free(red);
     else
-	CloseSetA(red);
+        CloseSetA(red);
     if (*N > 0)
-	free(*rules);
+        free(*rules);
     *N = newN;
     *rules = newrules;
     UseSys(oldsys);
@@ -213,104 +221,111 @@
 int BestRules(value_type ** rules, setA P, setA Q, int matrix_type)
 {
     int i, obj, num = 0,	/* total number of rules */
-	classnum = 0;		/* number of rules for class */
+                      classnum = 0;		/* number of rules for class */
     setO processed,		/* already covered objects */
-      newclass;			/* class */
+    newclass;			/* class */
     value_type *classrules = NULL;	/* rules for a single class */
 
     *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
     if (*rules == NULL)
-	ERROR(3);
+        ERROR(3);
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     processed = InitEmptySetO();
     newclass = InitEmptySetO();
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (!ContSetO(processed, obj)) {
-	    ClassSetO(newclass, obj, Q);
-	    classnum = 0;
-	    OrSetO(processed, processed, newclass);
-	    classnum =
-		BestRulesForClass(&classrules, newclass, P, Q, matrix_type);
-	    for (i = 0; i < classnum; i++)
-		AddRule(*rules, &num,
-			classrules + i * _mainsys->attributes_num);
-	    if (classnum > 0)
-		free(classrules);
-	    classrules = NULL;
-	}
+        if (!ContSetO(processed, obj))
+        {
+            ClassSetO(newclass, obj, Q);
+            classnum = 0;
+            OrSetO(processed, processed, newclass);
+            classnum =
+                BestRulesForClass(&classrules, newclass, P, Q, matrix_type);
+            for (i = 0; i < classnum; i++)
+                AddRule(*rules, &num,
+                        classrules + i * _mainsys->attributes_num);
+            if (classnum > 0)
+                free(classrules);
+            classrules = NULL;
+        }
     CloseSetO(processed);
     CloseSetO(newclass);
     if ((*rules = (value_type *) realloc(*rules,
-					 num * _mainsys->attributes_num *
-					 sizeof(value_type))) == NULL)
-	ERROR(3);
+                                         num * _mainsys->attributes_num *
+                                         sizeof(value_type))) == NULL)
+        ERROR(3);
     return num;
 }
 
 
 int BestRulesForClass(value_type ** rules, setO set, setA P, setA Q,
-		      int matrix_type)
+                      int matrix_type)
 {
     int n, attr, obj, red, num = 0;	/* total number of rules */
     int size = _mainsys->setAsize;
     setA fewred = NULL,		/* selected reducts */
-	allred = NULL;		/* all reducts */
+                  allred = NULL;		/* all reducts */
     value_type *rule = NULL;	/* single rule */
 
     *rules = NULL;
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     rule =
-	(value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+        (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
     if (rule == NULL)
-	ERROR(3);
+        ERROR(3);
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (ContSetO(set, obj)) {
-	    if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
-		free(rule);
-		return (-_rerror);
-	    }
-	    else if (!MatExist(_mainsys, MATX))
-		continue;
-	    n = Red(&allred, MATX);
-	    CloseMat(_mainsys, MATX);
-	    if (n > 0) {
-		n = SelectAllShort(&fewred, allred, n);
-		free(allred);
-	    }
-	    else {
-		free(rule);
-		return (-_rerror);
-	    }
-	    if ((*rules = (value_type *) realloc
-		 (*rules,
-		  (n +
-		   num) * _mainsys->attributes_num * sizeof(value_type))) ==
-		NULL) {
-		free(rule);
-		free(fewred);
-		return (-_rerror);
-	    }
-	    for (red = 0; red < n; red++) {
-		for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
-		    if (ContSetA(fewred + red * size, attr) ||
-			ContSetA(Q, attr))
-			rule[attr] = GetA(obj, attr);
-		    else
-			rule[attr] = MINUS;
-		AddRule(*rules, &num, rule);
-	    }
-	}
+        if (ContSetO(set, obj))
+        {
+            if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0)
+            {
+                free(rule);
+                return (-_rerror);
+            }
+            else if (!MatExist(_mainsys, MATX))
+                continue;
+            n = Red(&allred, MATX);
+            CloseMat(_mainsys, MATX);
+            if (n > 0)
+            {
+                n = SelectAllShort(&fewred, allred, n);
+                free(allred);
+            }
+            else
+            {
+                free(rule);
+                return (-_rerror);
+            }
+            if ((*rules = (value_type *) realloc
+                          (*rules,
+                           (n +
+                            num) * _mainsys->attributes_num * sizeof(value_type))) ==
+                    NULL)
+            {
+                free(rule);
+                free(fewred);
+                return (-_rerror);
+            }
+            for (red = 0; red < n; red++)
+            {
+                for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+                    if (ContSetA(fewred + red * size, attr) ||
+                            ContSetA(Q, attr))
+                        rule[attr] = GetA(obj, attr);
+                    else
+                        rule[attr] = MINUS;
+                AddRule(*rules, &num, rule);
+            }
+        }
     if (n > 0)
-	free(fewred);
+        free(fewred);
     free(rule);
     if (SelectRules(rules, &num, set, P, BESTOPT) < 0)
-	return (-_rerror);
+        return (-_rerror);
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return num;
 }
 
@@ -318,109 +333,116 @@
 int Rules(value_type ** rules, setA P, setA Q, int matrix_type)
 {
     int i, obj, num = 0,	/* total number of rules */
-	classnum = 0;		/* number of rules for class */
+                      classnum = 0;		/* number of rules for class */
     setO processed,		/* already covered objects */
-      newclass;			/* class */
+    newclass;			/* class */
     value_type *rule = NULL,	/* single rule */
-	*classrules = NULL;	/* rules for class */
+                       *classrules = NULL;	/* rules for class */
 
     *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
     if (*rules == NULL)
-	ERROR(3);
+        ERROR(3);
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     rule =
-	(value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+        (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
     if (rule == NULL)
-	ERROR(3);
+        ERROR(3);
     processed = InitEmptySetO();
     newclass = InitEmptySetO();
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (!ContSetO(processed, obj)) {
-	    ClassSetO(newclass, obj, Q);
-	    classnum = 0;
-	    OrSetO(processed, processed, newclass);
-	    classnum =
-		RulesForClass(&classrules, newclass, P, Q, matrix_type);
-	    for (i = 0; i < classnum; i++)
-		AddRule(*rules, &num,
-			classrules + i * _mainsys->attributes_num);
-	    if (classnum > 0)
-		free(classrules);
-	    classrules = NULL;
-	}
+        if (!ContSetO(processed, obj))
+        {
+            ClassSetO(newclass, obj, Q);
+            classnum = 0;
+            OrSetO(processed, processed, newclass);
+            classnum =
+                RulesForClass(&classrules, newclass, P, Q, matrix_type);
+            for (i = 0; i < classnum; i++)
+                AddRule(*rules, &num,
+                        classrules + i * _mainsys->attributes_num);
+            if (classnum > 0)
+                free(classrules);
+            classrules = NULL;
+        }
     free(rule);
     CloseSetO(processed);
     CloseSetO(newclass);
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return num;
 }
 
 
 int RulesForClass(value_type ** rules, setO set, setA P, setA Q,
-		  int matrix_type)
+                  int matrix_type)
 {
     int j, n, obj, red, num = 0;	/* total number of rules */
     int size = _mainsys->setAsize;
     setA fewred = NULL,		/* selected reducts */
-	allred = NULL;		/* all reducts */
+                  allred = NULL;		/* all reducts */
     value_type *rule = NULL;	/* single rule */
 
     *rules = NULL;
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     rule =
-	(value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+        (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
     if (rule == NULL)
-	ERROR(3);
+        ERROR(3);
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (ContSetO(set, obj)) {
-	    if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
-		free(rule);
-		return (-_rerror);
-	    }
-	    else if (!MatExist(_mainsys, MATX))
-		continue;
-	    n = Red(&allred, MATX);
-	    CloseMat(_mainsys, MATX);
-	    if (n > 0) {
-		n = SelectAllShort(&fewred, allred, n);
-		free(allred);
-	    }
-	    else {
-		free(rule);
-		return (-_rerror);
-	    }
-	    if ((*rules = (value_type *) realloc
-		 (*rules,
-		  (n +
-		   num) * _mainsys->attributes_num * sizeof(value_type))) ==
-		NULL) {
-		free(rule);
-		free(fewred);
-		return (-_rerror);
-	    }
-	    for (red = 0; red < n; red++) {
-		for (j = _mainsys->attributes_num - 1; j >= 0; j--)
-		    if (ContSetA(fewred + red * size, j) || ContSetA(Q, j))
-			rule[j] = GetA(obj, j);
-		    else
-			rule[j] = MINUS;
-		AddRule(*rules, &num, rule);
-	    }
-	}
+        if (ContSetO(set, obj))
+        {
+            if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0)
+            {
+                free(rule);
+                return (-_rerror);
+            }
+            else if (!MatExist(_mainsys, MATX))
+                continue;
+            n = Red(&allred, MATX);
+            CloseMat(_mainsys, MATX);
+            if (n > 0)
+            {
+                n = SelectAllShort(&fewred, allred, n);
+                free(allred);
+            }
+            else
+            {
+                free(rule);
+                return (-_rerror);
+            }
+            if ((*rules = (value_type *) realloc
+                          (*rules,
+                           (n +
+                            num) * _mainsys->attributes_num * sizeof(value_type))) ==
+                    NULL)
+            {
+                free(rule);
+                free(fewred);
+                return (-_rerror);
+            }
+            for (red = 0; red < n; red++)
+            {
+                for (j = _mainsys->attributes_num - 1; j >= 0; j--)
+                    if (ContSetA(fewred + red * size, j) || ContSetA(Q, j))
+                        rule[j] = GetA(obj, j);
+                    else
+                        rule[j] = MINUS;
+                AddRule(*rules, &num, rule);
+            }
+        }
     if (n > 0)
-	free(fewred);
+        free(fewred);
     free(rule);
     if (SelectRules(rules, &num, set, P, FASTOPT) < 0)
-	return (-_rerror);
+        return (-_rerror);
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return num;
 }
 
@@ -434,38 +456,40 @@
 
     *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
     if (*rules == NULL)
-	ERROR(3);
+        ERROR(3);
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     rule =
-	(value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+        (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
     if (rule == NULL)
-	ERROR(3);
-    for (obj = 0; obj < _mainsys->objects_num; obj++) {
-	if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
-	    free(rule);
-	    return (-_rerror);
-	}
-	else if (!MatExist(_mainsys, MATX))
-	    continue;
-	n = Red(&reducts, MATX);
-	CloseMat(_mainsys, MATX);
-	red = SelectOneShort(reducts, n);
-	for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
-	    if (ContSetA(reducts + red * size, attr) || ContSetA(Q, attr))
-		rule[attr] = GetA(obj, attr);
-	    else
-		rule[attr] = MINUS;
-	AddRule(*rules, &count, rule);
-	if (n > 0)
-	    free(reducts);
-	reducts = NULL;
+        ERROR(3);
+    for (obj = 0; obj < _mainsys->objects_num; obj++)
+    {
+        if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0)
+        {
+            free(rule);
+            return (-_rerror);
+        }
+        else if (!MatExist(_mainsys, MATX))
+            continue;
+        n = Red(&reducts, MATX);
+        CloseMat(_mainsys, MATX);
+        red = SelectOneShort(reducts, n);
+        for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+            if (ContSetA(reducts + red * size, attr) || ContSetA(Q, attr))
+                rule[attr] = GetA(obj, attr);
+            else
+                rule[attr] = MINUS;
+        AddRule(*rules, &count, rule);
+        if (n > 0)
+            free(reducts);
+        reducts = NULL;
     }
     free(rule);
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return count;
 }
 
@@ -478,156 +502,165 @@
 
     *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
     if (*rules == NULL)
-	ERROR(3);
+        ERROR(3);
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     rule =
-	(value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+        (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
     if (rule == NULL)
-	ERROR(3);
+        ERROR(3);
     reduct = InitEmptySetA();
-    for (obj = 0; obj < _mainsys->objects_num; obj++) {
-	if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
-	    free(rule);
-	    return (-_rerror);
-	}
-	else if (!MatExist(_mainsys, MATX))
-	    continue;
-	RedOptim(reduct, MATX);
-	CloseMat(_mainsys, MATX);
-	for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
-	    if (ContSetA(reduct, attr) || ContSetA(Q, attr))
-		rule[attr] = GetA(obj, attr);
-	    else
-		rule[attr] = MINUS;
-	AddRule(*rules, &count, rule);
+    for (obj = 0; obj < _mainsys->objects_num; obj++)
+    {
+        if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0)
+        {
+            free(rule);
+            return (-_rerror);
+        }
+        else if (!MatExist(_mainsys, MATX))
+            continue;
+        RedOptim(reduct, MATX);
+        CloseMat(_mainsys, MATX);
+        for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+            if (ContSetA(reduct, attr) || ContSetA(Q, attr))
+                rule[attr] = GetA(obj, attr);
+            else
+                rule[attr] = MINUS;
+        AddRule(*rules, &count, rule);
     }
     free(rule);
     CloseSetA(reduct);
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return count;
 }
 
 
 int ApprRules(value_type ** rules, setA P, setA Q, int option,
-	      int matrix_type)
+              int matrix_type)
 {
     int i, obj, num = 0,	/* total number of rules */
-	classnum = 0;		/* number of rules for class */
+                      classnum = 0;		/* number of rules for class */
     setO processed,		/* already covered objects */
-      newclass;			/* class */
+    newclass;			/* class */
     value_type *rule = NULL,	/* single rule */
-	*classrules = NULL;	/* rules for class */
+                       *classrules = NULL;	/* rules for class */
 
     *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
     if (*rules == NULL)
-	ERROR(3);
+        ERROR(3);
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     rule =
-	(value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+        (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
     if (rule == NULL)
-	ERROR(3);
+        ERROR(3);
     processed = InitEmptySetO();
     newclass = InitEmptySetO();
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (!ContSetO(processed, obj)) {
-	    ClassSetO(newclass, obj, Q);
-	    classnum = 0;
-	    OrSetO(processed, processed, newclass);
-	    classnum = ApprRulesForClass(&classrules, newclass, P, Q,
-					 option, matrix_type);
-	    for (i = 0; i < classnum; i++)
-		AddRule(*rules, &num,
-			classrules + i * _mainsys->attributes_num);
-	    if (classnum > 0)
-		free(classrules);
-	    classrules = NULL;
-	}
+        if (!ContSetO(processed, obj))
+        {
+            ClassSetO(newclass, obj, Q);
+            classnum = 0;
+            OrSetO(processed, processed, newclass);
+            classnum = ApprRulesForClass(&classrules, newclass, P, Q,
+                                         option, matrix_type);
+            for (i = 0; i < classnum; i++)
+                AddRule(*rules, &num,
+                        classrules + i * _mainsys->attributes_num);
+            if (classnum > 0)
+                free(classrules);
+            classrules = NULL;
+        }
     free(rule);
     CloseSetO(processed);
     CloseSetO(newclass);
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return num;
 }
 
 
 
 int ApprRulesForClass(value_type ** rules, setO set, setA P, setA Q,
-		      int option, int matrix_type)
+                      int option, int matrix_type)
 {
     int j, n, obj, red, num = 0;	/* total number of rules */
     int size = _mainsys->setAsize;
     setA fewred = NULL,		/* selected reducts */
-	allred = NULL;		/* all reducts */
+                  allred = NULL;		/* all reducts */
     value_type *rule = NULL;	/* single rule */
     setO aclass;
 
     *rules = NULL;
     if (!MatExist(_mainsys, MATA))
-	ERROR(5);
+        ERROR(5);
     rule =
-	(value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+        (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
     if (rule == NULL)
-	ERROR(3);
+        ERROR(3);
     aclass = InitEmptySetO();
     if (option == LOWER)
-	LowAppr(aclass, set, P, matrix_type);
+        LowAppr(aclass, set, P, matrix_type);
     else if (option == UPPER)
-	UppAppr(aclass, set, P, matrix_type);
+        UppAppr(aclass, set, P, matrix_type);
     else
-	CopySetO(aclass, set);
+        CopySetO(aclass, set);
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (ContSetO(aclass, obj)) {
-	    if (InitXforObjectFromClass(_mainsys, obj, P, aclass, matrix_type)
-		< 0) {
-		free(rule);
-		return (-_rerror);
-	    }
-	    else if (!MatExist(_mainsys, MATX))
-		continue;
-	    n = Red(&allred, MATX);
-	    CloseMat(_mainsys, MATX);
-	    if (n > 0) {
-		n = SelectAllShort(&fewred, allred, n);
-		free(allred);
-	    }
-	    else {
-		free(rule);
-		return (-_rerror);
-	    }
-	    if ((*rules = (value_type *) realloc
-		 (*rules,
-		  (n +
-		   num) * _mainsys->attributes_num * sizeof(value_type))) ==
-		NULL) {
-		free(rule);
-		free(fewred);
-		return (-_rerror);
-	    }
-	    for (red = 0; red < n; red++) {
-		for (j = _mainsys->attributes_num - 1; j >= 0; j--)
-		    if (ContSetA(fewred + red * size, j) || ContSetA(Q, j))
-			rule[j] = GetA(obj, j);
-		    else
-			rule[j] = MINUS;
-		AddRule(*rules, &num, rule);
-	    }
-	}
+        if (ContSetO(aclass, obj))
+        {
+            if (InitXforObjectFromClass(_mainsys, obj, P, aclass, matrix_type)
+                    < 0)
+            {
+                free(rule);
+                return (-_rerror);
+            }
+            else if (!MatExist(_mainsys, MATX))
+                continue;
+            n = Red(&allred, MATX);
+            CloseMat(_mainsys, MATX);
+            if (n > 0)
+            {
+                n = SelectAllShort(&fewred, allred, n);
+                free(allred);
+            }
+            else
+            {
+                free(rule);
+                return (-_rerror);
+            }
+            if ((*rules = (value_type *) realloc
+                          (*rules,
+                           (n +
+                            num) * _mainsys->attributes_num * sizeof(value_type))) ==
+                    NULL)
+            {
+                free(rule);
+                free(fewred);
+                return (-_rerror);
+            }
+            for (red = 0; red < n; red++)
+            {
+                for (j = _mainsys->attributes_num - 1; j >= 0; j--)
+                    if (ContSetA(fewred + red * size, j) || ContSetA(Q, j))
+                        rule[j] = GetA(obj, j);
+                    else
+                        rule[j] = MINUS;
+                AddRule(*rules, &num, rule);
+            }
+        }
     if (n > 0)
-	free(fewred);
+        free(fewred);
     free(rule);
     if (SelectRules(rules, &num, set, P, FASTOPT) < 0)
-	return (-_rerror);
+        return (-_rerror);
     if ((*rules = (value_type *) realloc
-	 (*rules,
-	  num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
-	ERROR(3);
+                  (*rules,
+                   num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+        ERROR(3);
     return num;
 }

Modified: grass-addons/raster/mcda/r.roughset/rules_extr.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rules_extr.c	2010-07-02 20:17:15 UTC (rev 42697)
+++ grass-addons/raster/mcda/r.roughset/rules_extr.c	2010-07-03 13:00:56 UTC (rev 42698)
@@ -3,11 +3,11 @@
  *
  * MODULE:       r.roughset
  * AUTHOR(S):    GRASS module authors ad Rough Set Library (RSL) maintain:
- *			G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)		
+ *			G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
  *			Rough Set Library (RSL) ver. 2 original develop:
- *		        M.Gawrys - J.Sienkiewicz 
+ *		        M.Gawrys - J.Sienkiewicz
  *
- * PURPOSE:      Geographics rough set analisys and knowledge discovery 
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery
  *
  * COPYRIGHT:    (C) A.Boggia - G.Massei (2008)
  *
@@ -16,39 +16,39 @@
  *   	    	 for details.
  *
 /************************************************************************
-** EXTRACT RULE FROM GEOGRAPHICS THEMES (Based on Rough Set Library 
-**     		written by M.Gawrys J.Sienkiewiczbrary )	  		
+** EXTRACT RULE FROM GEOGRAPHICS THEMES (Based on Rough Set Library
+**     		written by M.Gawrys J.Sienkiewiczbrary )
 **
 ** The RSL defines three types to be used in applications:
 **     setA - set of attributes,
 **     setO - set of objects and
 **     SYSTEM - information system descriptor.
-					
+
 ** The descriptor contains pointers to the information system data matrices:
 ** - MATRIX A, is the attribute-value table.
 ** - MATRIX D, is the discernibility matrix
 ** - MATRIX X, is called a reduced discernibility matrix.
-                          
+
 /***********************************************************************/
 
 #include "rough.h"
 #include "localproto.h"
 
 int rough_analysis(int nrows, int ncols, char *name, int *classify_vect,
-		   struct input *attributes, char *file_sample_txt, int strgy,
-		   int cls);
+                   struct input *attributes, char *file_sample_txt, int strgy,
+                   int cls);
 
 void rough_set_library_out(int nrows, int ncols, int nattributes,
-			   struct input *attributes, char *file_out_sys);
+                           struct input *attributes, char *file_out_sys);
 
 void output_to_txt(FILE * file_out_txt, value_type * rules, setA P, setA Q,
-		   setA core, setA beg, int n, SYSTEM * sys1, int strgy,
-		   int r, int *opr, struct input *attributes);
+                   setA core, setA beg, int n, SYSTEM * sys1, int strgy,
+                   int r, int *opr, struct input *attributes);
 
 void fPrintSetA(FILE * file, setA set);
 void fPrintSetO(FILE * file, setO set);
 void fPrintRules(FILE * file, value_type * rules, int N, int *opr, setA P,
-		 setA Q, struct input *attributes);
+                 setA Q, struct input *attributes);
 
 float MeanAttrInRule(value_type * rules, int N, setA P);
 
@@ -58,8 +58,8 @@
 
 
 int rough_analysis(int nrows, int ncols, char *name, int *classify_vect,
-		   struct input *attributes, char *file_sample_txt, int strgy,
-		   int cls)
+                   struct input *attributes, char *file_sample_txt, int strgy,
+                   int cls)
 {
     SYSTEM *sys1, *sys2;	/* Information system descriptor structures. */
 
@@ -77,31 +77,35 @@
 
     sys1 = InitEmptySys();	/* Allocates memory for a system descriptor and returns a pointer. */
 
-    if (file_sample_txt != NULL) {	/*use sample txt file if input in dec_txt->answer isn't NUL */
-	name = file_sample_txt;
-	G_message("Using %s sys file for rules generation", name);
+    if (file_sample_txt != NULL)  	/*use sample txt file if input in dec_txt->answer isn't NUL */
+    {
+        name = file_sample_txt;
+        G_message("Using %s sys file for rules generation", name);
     }				/* Imports a system from a file of the special format. */
 
 
     FileToSys(sys1, name);	/* Imports a system from a file of the special format. */
 
-    if (_rerror > 0) {
-	G_fatal_error("  Can't open data file \n");
-	return (1);
+    if (_rerror > 0)
+    {
+        G_fatal_error("  Can't open data file \n");
+        return (1);
     }
 
     strcat(name, ".out");
 
-    if (!(file_out_txt = fopen(name, "a"))) {	/*output text file */
-	G_fatal_error("  Can't open output file \n");
-	return (1);
+    if (!(file_out_txt = fopen(name, "a")))  	/*output text file */
+    {
+        G_fatal_error("  Can't open output file \n");
+        return (1);
     }
 
     UseSys(sys1);		/* Activates a system. All routines will work on this indicated system data and parameters. */
 
-    if (_rerror > 0) {
-	G_fatal_error("Can't open information system <%s>\n", sys1->name);
-	return (1);
+    if (_rerror > 0)
+    {
+        G_fatal_error("Can't open information system <%s>\n", sys1->name);
+        return (1);
     }
 
 
@@ -116,8 +120,9 @@
     nattributes = (AttributesNum(sys1) - 1);
 
     /* define attribute */
-    for (i = 0; i < nattributes; i++) {
-	AddSetA(P, i);		/* Adds a single element to a set */
+    for (i = 0; i < nattributes; i++)
+    {
+        AddSetA(P, i);		/* Adds a single element to a set */
     }
 
     /* define decision */
@@ -134,55 +139,57 @@
     CloseMat(sys1, MATX);	/* Closes a matrix. */
 
     if (n > 0)
-	free(beg);
+        free(beg);
 
-    switch (strgy) {
+    switch (strgy)
+    {
     case 0:
-	genrules = VeryFastRules;
-	break;
+        genrules = VeryFastRules;
+        break;
     case 1:
-	genrules = FastRules;
-	break;
+        genrules = FastRules;
+        break;
     case 2:
-	genrules = Rules;
-	break;
+        genrules = Rules;
+        break;
     case 3:
-	genrules = BestRules;
-	break;
+        genrules = BestRules;
+        break;
     case 4:
-	genrules = AllRules;
-	break;
+        genrules = AllRules;
+        break;
     case 5:
-	genrules = LowRules;
-	break;
+        genrules = LowRules;
+        break;
     case 6:
-	genrules = UppRules;
-	break;
+        genrules = UppRules;
+        break;
     default:
-	genrules = NormRules;
-	break;
+        genrules = NormRules;
+        break;
     }
 
     r = genrules(&rules, P, Q, MATD);	/* rules generator */
 
-    if (r > 0) {
-	opr = StrengthOfRules(rules, r);
+    if (r > 0)
+    {
+        opr = StrengthOfRules(rules, r);
     }				/* Creates a table of rules strengths */
 
 
-/**************************Output text files************************************/
+    /**************************Output text files************************************/
 
-/***********print output about sys1 in a txt file (file_out_txt)****************/
+    /***********print output about sys1 in a txt file (file_out_txt)****************/
     output_to_txt(file_out_txt, rules, P, Q, core, beg, n, sys1, strgy, r,
-		  opr, attributes);
+                  opr, attributes);
 
-/**************************close all********************************************/
+    /**************************close all********************************************/
 
     //CloseSys(sys1);   /* close sys1 */
 
-/*******************************************************************************/
+    /*******************************************************************************/
 
-/**************************Classify*********************************************/
+    /**************************Classify*********************************************/
 
     sys2 = InitEmptySys();
     SetParameters(sys2, nobjects, nattributes);	/* assigning system parameters */
@@ -191,76 +198,85 @@
     SetName(sys2, "classys");
     UseSys(sys2);		/* active system sys2 was created in application and has only MATRIX A */
 
-    if (_rerror > 0) {
-	G_fatal_error("Can't open information system <%s>\n", _mainsys->name);
-	return (1);
+    if (_rerror > 0)
+    {
+        G_fatal_error("Can't open information system <%s>\n", _mainsys->name);
+        return (1);
     }
 
     G_message("Build information system for classification ");
-    for (i = 0; i < nattributes; i++) {
-	object = 0;		/* set object numbers =0 and increase it until rows*cells for each attribute */
-	for (row = 0; row < nrows; row++) {
-	    G_percent(row, nrows, 1);
-	    /* Reads appropriate information into the buffer buf associated with the requested row */
-	    G_get_c_raster_row(attributes[i].fd, attributes[i].buf, row);
-	    for (col = 0; col < ncols; col++) {
-		value = (attributes[i].buf[col]);	/*make a cast on the DCELL output value */
-		PutA(_mainsys, object, i, value);	/* filling MATRIX A */
-		object++;
-	    }
-	}
+    for (i = 0; i < nattributes; i++)
+    {
+        object = 0;		/* set object numbers =0 and increase it until rows*cells for each attribute */
+        for (row = 0; row < nrows; row++)
+        {
+            G_percent(row, nrows, 1);
+            /* Reads appropriate information into the buffer buf associated with the requested row */
+            G_get_c_raster_row(attributes[i].fd, attributes[i].buf, row);
+            for (col = 0; col < ncols; col++)
+            {
+                value = (attributes[i].buf[col]);	/*make a cast on the DCELL output value */
+                PutA(_mainsys, object, i, value);	/* filling MATRIX A */
+                object++;
+            }
+        }
     }
 
     buf = MatExist(_mainsys, MATA);	/*Returns pointer to specified matrix if exists */
 
-    if (!buf) {
-	G_fatal_error("Error in the information system <%s>\n",
-		      _mainsys->name);
-	return (1);
+    if (!buf)
+    {
+        G_fatal_error("Error in the information system <%s>\n",
+                      _mainsys->name);
+        return (1);
     }
 
 
-    switch (cls) {
+    switch (cls)
+    {
     case 0:
-	{
-	    for (j = 0; j < _mainsys->objects_num; j++) {	/*Chooses the best rule to cover sample. Strategy no. 1 */
-		classify_vect[j] =
-		    Classify1(buf + j * _mainsys->attributes_num, rules, r, P,
-			      Q);
-		G_percent(j, _mainsys->objects_num, 1);
-	    }
-	}
-	break;
+    {
+        for (j = 0; j < _mainsys->objects_num; j++)  	/*Chooses the best rule to cover sample. Strategy no. 1 */
+        {
+            classify_vect[j] =
+                Classify1(buf + j * _mainsys->attributes_num, rules, r, P,
+                          Q);
+            G_percent(j, _mainsys->objects_num, 1);
+        }
+    }
+    break;
     case 1:
-	{
-	    for (j = 0; j < _mainsys->objects_num; j++) {	/*Chooses the best rule to cover sample. Strategy no. 2 */
-		classify_vect[j] =
-		    Classify2(buf + j * _mainsys->attributes_num, rules, r, P,
-			      Q);
-		G_percent(j, _mainsys->objects_num, 1);
-	    }
-	}
-	break;
+    {
+        for (j = 0; j < _mainsys->objects_num; j++)  	/*Chooses the best rule to cover sample. Strategy no. 2 */
+        {
+            classify_vect[j] =
+                Classify2(buf + j * _mainsys->attributes_num, rules, r, P,
+                          Q);
+            G_percent(j, _mainsys->objects_num, 1);
+        }
+    }
+    break;
     case 2:
-	{
-	    for (j = 0; j < _mainsys->objects_num; j++) {	/*Chooses the best rule to cover sample. Strategy no. 3 */
-		classify_vect[j] =
-		    Classify3(buf + j * _mainsys->attributes_num, rules, r,
-			      opr, P, Q);
-		G_percent(j, _mainsys->objects_num, 1);
-	    }
-	}
-	break;
+    {
+        for (j = 0; j < _mainsys->objects_num; j++)  	/*Chooses the best rule to cover sample. Strategy no. 3 */
+        {
+            classify_vect[j] =
+                Classify3(buf + j * _mainsys->attributes_num, rules, r,
+                          opr, P, Q);
+            G_percent(j, _mainsys->objects_num, 1);
+        }
+    }
+    break;
 
     default:
-	0;
-	break;
+        0;
+        break;
     }
 
 
     G_message("All cells classified (%d)", j);
 
-/*****************************************************************************/
+    /*****************************************************************************/
 
     free(rules);
     free(opr);
@@ -274,7 +290,7 @@
 }
 
 void rough_set_library_out(int nrows, int ncols, int nattribute,
-			   struct input *attributes, char *file_out_sys)
+                           struct input *attributes, char *file_out_sys)
 {
     int row, col, i, j;
     int value, decvalue;
@@ -284,61 +300,67 @@
 
     /* open *.sys file for writing or use stdout */
     if (NULL == (fp = fopen(file_out_sys, "w")))
-	G_fatal_error("Not able to open file [%s]", file_out_sys);
+        G_fatal_error("Not able to open file [%s]", file_out_sys);
 
     fprintf(fp, "NAME: %s\nATTRIBUTES: %d\nOBJECTS: %s\n", file_out_sys,
-	    nattribute + 1, "            ");
+            nattribute + 1, "            ");
 
-	/************** process the data *************/
+    /************** process the data *************/
 
     G_message("Build information system for rules extraction in %s",
-	      file_out_sys);
+              file_out_sys);
 
     nobject = 0;
 
-    for (row = 0; row < nrows; row++) {
-	for (i = 0; i <= nattribute; i++) {
-	    G_get_c_raster_row(attributes[i].fd, attributes[i].buf, row);	/* Reads appropriate information into the buffer buf associated with the requested row */
-	}
-	for (col = 0; col < ncols; col++) {	/*make a cast on the DCELL output value */
-	    decvalue = (int)attributes[nattribute].buf[col];
-	    if (0 < decvalue) {	/* TODO: correct form will: decval!=null */
-		for (j = 0; j < nattribute; j++) {	/*make a cast on the DCELL output value */
-		    value = (int)(attributes[j].buf[col]);
-		    sprintf(cell_buf, "%d", value);
-		    G_trim_decimal(cell_buf);
-		    fprintf(fp, "%s ", cell_buf);
-		}
-		fprintf(fp, "%d\n", decvalue);
-		nobject++;
-	    }
-	}
-	G_percent(row, nrows, 1);
+    for (row = 0; row < nrows; row++)
+    {
+        for (i = 0; i <= nattribute; i++)
+        {
+            G_get_c_raster_row(attributes[i].fd, attributes[i].buf, row);	/* Reads appropriate information into the buffer buf associated with the requested row */
+        }
+        for (col = 0; col < ncols; col++)  	/*make a cast on the DCELL output value */
+        {
+            decvalue = (int)attributes[nattribute].buf[col];
+            if (0 < decvalue)  	/* TODO: correct form will: decval!=null */
+            {
+                for (j = 0; j < nattribute; j++)  	/*make a cast on the DCELL output value */
+                {
+                    value = (int)(attributes[j].buf[col]);
+                    sprintf(cell_buf, "%d", value);
+                    G_trim_decimal(cell_buf);
+                    fprintf(fp, "%s ", cell_buf);
+                }
+                fprintf(fp, "%d\n", decvalue);
+                nobject++;
+            }
+        }
+        G_percent(row, nrows, 1);
     }
 
-	/************** write code file*************/
+    /************** write code file*************/
 
-    for (i = 0; i <= nattribute; i++) {
-	fprintf(fp, "\n%s", attributes[i].name);
+    for (i = 0; i <= nattribute; i++)
+    {
+        fprintf(fp, "\n%s", attributes[i].name);
     }
 
-	/************** write header file*************/
+    /************** write header file*************/
 
     rewind(fp);			/*move file pointer to header file */
     /* TODO: make a system to  detect errors like: G_fatal_error("Not able to write file [%s]",file_out_sys); */
 
     fprintf(fp, "NAME: %s\nATTRIBUTES: %d\nOBJECTS: %d", file_out_sys,
-	    nattribute + 1, nobject);
+            nattribute + 1, nobject);
 
-	/************** close all and exit ***********/
+    /************** close all and exit ***********/
 
     fclose(fp);
 }
 
 
 void output_to_txt(FILE * file_out_txt, value_type * rules, setA P, setA Q,
-		   setA core, setA beg, int n, SYSTEM * sys1, int strgy,
-		   int r, int *opr, struct input *attributes)
+                   setA core, setA beg, int n, SYSTEM * sys1, int strgy,
+                   int r, int *opr, struct input *attributes)
 {
     int i;
 
@@ -353,18 +375,20 @@
     fPrintSetA(file_out_txt, core);
     fprintf(file_out_txt, "\nFew reducts ( %i ):\n", n);
 
-    for (i = 0; i < n; i++) {
-	fPrintSetA(file_out_txt, beg + i * sys1->setAsize);
-	fprintf(file_out_txt, "\n");
+    for (i = 0; i < n; i++)
+    {
+        fPrintSetA(file_out_txt, beg + i * sys1->setAsize);
+        fprintf(file_out_txt, "\n");
     }
 
     fprintf(file_out_txt, "%d strategy of generating rules\n", strgy);
 
-    if (r > 0) {
-	fprintf(file_out_txt, "Rules ( %i )\n", r);
-	fPrintRules(file_out_txt, rules, r, opr, P, Q, attributes);	/*print to file generated rules */
-	fprintf(file_out_txt, "Mean number of attributes in rule = %.1f\n",
-		MeanAttrInRule(rules, r, P));
+    if (r > 0)
+    {
+        fprintf(file_out_txt, "Rules ( %i )\n", r);
+        fPrintRules(file_out_txt, rules, r, opr, P, Q, attributes);	/*print to file generated rules */
+        fprintf(file_out_txt, "Mean number of attributes in rule = %.1f\n",
+                MeanAttrInRule(rules, r, P));
     }
 }
 
@@ -377,14 +401,15 @@
 
     fprintf(f, "{");
     for (attr = 0; attr < _mainsys->attributes_num; attr++)
-	if (ContSetA(set, attr)) {
-	    fprintf(f, " %d", attr);
-	    attr++;
-	    break;
-	}
+        if (ContSetA(set, attr))
+        {
+            fprintf(f, " %d", attr);
+            attr++;
+            break;
+        }
     for (; attr < _mainsys->attributes_num; attr++)
-	if (ContSetA(set, attr))
-	    fprintf(f, ",%d", attr);
+        if (ContSetA(set, attr))
+            fprintf(f, ",%d", attr);
     fprintf(f, " }");
 }
 
@@ -394,35 +419,37 @@
 
     fprintf(f, "{");
     for (obj = 0; obj < _mainsys->objects_num; obj++)
-	if (ContSetO(set, obj)) {
-	    fprintf(f, " %d", obj);
-	    obj++;
-	    break;
-	}
+        if (ContSetO(set, obj))
+        {
+            fprintf(f, " %d", obj);
+            obj++;
+            break;
+        }
     for (; obj < _mainsys->objects_num; obj++)
-	if (ContSetO(set, obj))
-	    fprintf(f, ",%d", obj);
+        if (ContSetO(set, obj))
+            fprintf(f, ",%d", obj);
     fprintf(f, " }");
 }
 
 void fPrintRules(FILE * file, value_type * rules,
-		 int N, int *opr, setA P, setA Q, struct input *attributes)
+                 int N, int *opr, setA P, setA Q, struct input *attributes)
 {
     int n, j;
 
-    for (n = 0; n < N; n++) {
-	for (j = 0; j < _mainsys->attributes_num; j++)
-	    if (ContSetA(P, j))
-		if (rules[n * _mainsys->attributes_num + j] != MINUS)
-		    fprintf(file, "%s=%d  ", attributes[j].name,
-			    rules[n * _mainsys->attributes_num + j]);
-	fprintf(file, " => ");
-	for (j = 0; j < _mainsys->attributes_num; j++)
-	    if (ContSetA(Q, j))
-		if ((rules + n * _mainsys->attributes_num)[j] != MINUS)
-		    fprintf(file, "%s=%d  ", attributes[j].name,
-			    (rules + n * _mainsys->attributes_num)[j]);
-	fprintf(file, " ( %i objects )\n", opr[n]);
+    for (n = 0; n < N; n++)
+    {
+        for (j = 0; j < _mainsys->attributes_num; j++)
+            if (ContSetA(P, j))
+                if (rules[n * _mainsys->attributes_num + j] != MINUS)
+                    fprintf(file, "%s=%d  ", attributes[j].name,
+                            rules[n * _mainsys->attributes_num + j]);
+        fprintf(file, " => ");
+        for (j = 0; j < _mainsys->attributes_num; j++)
+            if (ContSetA(Q, j))
+                if ((rules + n * _mainsys->attributes_num)[j] != MINUS)
+                    fprintf(file, "%s=%d  ", attributes[j].name,
+                            (rules + n * _mainsys->attributes_num)[j]);
+        fprintf(file, " ( %i objects )\n", opr[n]);
     }
     return;
 }
@@ -436,10 +463,10 @@
     int size = _mainsys->attributes_num;
 
     for (i = 0; i < N; i++)
-	for (j = 0; j < size; j++)
-	    if (ContSetA(P, j))
-		if ((rules + i * size)[j] != MINUS)
-		    counter++;
+        for (j = 0; j < size; j++)
+            if (ContSetA(P, j))
+                if ((rules + i * size)[j] != MINUS)
+                    counter++;
     return (float)counter / N;
 }
 



More information about the grass-commit mailing list