Переглянути джерело

r.geomorphon: Run grass_indent.sh on the source (#1101)

Denis Ovsienko 4 роки тому
батько
коміт
c08f63b1b6

+ 73 - 73
raster/r.geomorphon/geom.c

@@ -1,11 +1,11 @@
 #include "local_proto.h"
 /* static double dirs[NUM_DIRS] = { 0.7854, 0., 5.4978, 4.7124, 3.9270, 3.1416, 2.3562, 1.5708 };*/	/* radians */
-static double sins[NUM_DIRS] = { 0.7071067812, 0, -0.7071067812, -1, -0.7071067812, 0, 0.7071067812, 1 };	/* sinus */
-static double coss[NUM_DIRS] = { 0.7071067812, 1, 0.7071067812, 0, -0.7071067812, -1, -0.7071067812, 0 };	/* cosinus */
+static double sins[NUM_DIRS] = { 0.7071067812, 0, -0.7071067812, -1, -0.7071067812, 0, 0.7071067812, 1 };       /* sinus */
+static double coss[NUM_DIRS] = { 0.7071067812, 1, 0.7071067812, 0, -0.7071067812, -1, -0.7071067812, 0 };       /* cosinus */
 
 /* DIRS in DEGREES from NORTH: 45,0,315,270,225,180,135,90 */
 
-#define TERNARY_MAX 6561 /* 3**8 */
+#define TERNARY_MAX 6561        /* 3**8 */
 static unsigned int global_ternary_codes[TERNARY_MAX];
 
 void generate_ternary_codes()
@@ -13,7 +13,7 @@ void generate_ternary_codes()
     unsigned i;
 
     for (i = 0; i < TERNARY_MAX; ++i)
-	global_ternary_codes[i] = ternary_rotate(i);
+        global_ternary_codes[i] = ternary_rotate(i);
 }
 
 unsigned int ternary_rotate(unsigned int value)
@@ -32,25 +32,25 @@ unsigned int ternary_rotate(unsigned int value)
     int i, j, k;
 
     for (i = 0; i < NUM_DIRS; i++) {
-	pattern[i] = value % 3;
-	rev_pattern[7 - i] = value % 3;
-	value /= 3;
+        pattern[i] = value % 3;
+        rev_pattern[7 - i] = value % 3;
+        value /= 3;
     }
 
     for (j = 0; j < NUM_DIRS; j++) {
-	power = 1;
-	tmp_code = 0;
-	tmp_rev_code = 0;
-	for (i = 0; i < NUM_DIRS; i++) {
-	    k = (i - j) < 0 ? j - NUM_DIRS : j;
-	    tmp_pattern[i] = pattern[i - k];
-	    tmp_rev_pattern[i] = rev_pattern[i - k];
-	    tmp_code += tmp_pattern[i] * power;
-	    tmp_rev_code += tmp_rev_pattern[i] * power;
-	    power *= 3;
-	}
-	code = MIN(tmp_code, code);
-	rev_code = MIN(tmp_rev_code, rev_code);
+        power = 1;
+        tmp_code = 0;
+        tmp_rev_code = 0;
+        for (i = 0; i < NUM_DIRS; i++) {
+            k = (i - j) < 0 ? j - NUM_DIRS : j;
+            tmp_pattern[i] = pattern[i - k];
+            tmp_rev_pattern[i] = rev_pattern[i - k];
+            tmp_code += tmp_pattern[i] * power;
+            tmp_rev_code += tmp_rev_pattern[i] * power;
+            power *= 3;
+        }
+        code = MIN(tmp_code, code);
+        rev_code = MIN(tmp_rev_code, rev_code);
     }
     return MIN(code, rev_code);
 }
@@ -61,17 +61,17 @@ FORMS determine_form(int num_minus, int num_plus)
      * simple approach to determine form pattern */
 
     const FORMS forms[9][9] = {
-	/* minus ------------- plus ---------------- */
-	/*       0   1   2   3   4   5   6   7   8  */
-	/* 0 */ {FL, FL, FL, FS, FS, VL, VL, VL, PT},
-	/* 1 */ {FL, FL, FS, FS, FS, VL, VL, VL, __},
-	/* 2 */ {FL, SH, SL, SL, HL, HL, VL, __, __},
-	/* 3 */ {SH, SH, SL, SL, SL, HL, __, __, __},
-	/* 4 */ {SH, SH, SP, SL, SL, __, __, __, __},
-	/* 5 */ {RI, RI, SP, SP, __, __, __, __, __},
-	/* 6 */ {RI, RI, RI, __, __, __, __, __, __},
-	/* 7 */ {RI, RI, __, __, __, __, __, __, __},
-	/* 8 */ {PK, __, __, __, __, __, __, __, __},
+        /* minus ------------- plus ---------------- */
+        /*       0   1   2   3   4   5   6   7   8  */
+        /* 0 */ {FL, FL, FL, FS, FS, VL, VL, VL, PT},
+        /* 1 */ {FL, FL, FS, FS, FS, VL, VL, VL, __},
+        /* 2 */ {FL, SH, SL, SL, HL, HL, VL, __, __},
+        /* 3 */ {SH, SH, SL, SL, SL, HL, __, __, __},
+        /* 4 */ {SH, SH, SP, SL, SL, __, __, __, __},
+        /* 5 */ {RI, RI, SP, SP, __, __, __, __, __},
+        /* 6 */ {RI, RI, RI, __, __, __, __, __, __},
+        /* 7 */ {RI, RI, __, __, __, __, __, __, __},
+        /* 8 */ {PK, __, __, __, __, __, __, __, __},
     };
     /* (See the FORMS enum for the legend.) */
 
@@ -85,14 +85,14 @@ int determine_binary(int *pattern, int sign)
     unsigned char binary = 0, result = 255, test = 0;
 
     for (i = 0, n = 1; i < NUM_DIRS; i++, n *= 2)
-	binary += (pattern[i] == sign) ? n : 0;
+        binary += (pattern[i] == sign) ? n : 0;
     /* rotate */
     for (i = 0; i < NUM_DIRS; ++i) {
-	if ((i &= 7) == 0)
-	    test = binary;
-	else
-	    test = (binary << i) | (binary >> (NUM_DIRS - i));
-	result = MIN(result, test);
+        if ((i &= 7) == 0)
+            test = binary;
+        else
+            test = (binary << i) | (binary >> (NUM_DIRS - i));
+        result = MIN(result, test);
     }
     return (int)result;
 }
@@ -105,11 +105,11 @@ int rotate(unsigned char binary)
 
     /* rotate */
     for (i = 0; i < NUM_DIRS; ++i) {
-	if ((i &= 7) == 0)
-	    test = binary;
-	else
-	    test = (binary << i) | (binary >> (NUM_DIRS - i));
-	result = MIN(result, test);
+        if ((i &= 7) == 0)
+            test = binary;
+        else
+            test = (binary << i) | (binary >> (NUM_DIRS - i));
+        result = MIN(result, test);
     }
     return (int)result;
 }
@@ -121,7 +121,7 @@ int determine_ternary(int *pattern)
     int power, i;
 
     for (i = 0, power = 1; i < NUM_DIRS; ++i, power *= 3)
-	ternary_code += (pattern[i] + 1) * power;
+        ternary_code += (pattern[i] + 1) * power;
     return global_ternary_codes[ternary_code];
 }
 
@@ -132,7 +132,7 @@ float intensity(float *elevation, int pattern_size)
     int i;
 
     for (i = 0; i < NUM_DIRS; i++)
-	sum_elevation -= elevation[i];
+        sum_elevation -= elevation[i];
 
     return sum_elevation / (float)pattern_size;
 }
@@ -145,8 +145,8 @@ float exposition(float *elevation)
 
     max = elevation[0];
     for (i = 1; i < NUM_DIRS; i++)
-	if (fabs(elevation[i]) > fabs(max))
-	    max = elevation[i];
+        if (fabs(elevation[i]) > fabs(max))
+            max = elevation[i];
     return -max;
 }
 
@@ -158,8 +158,8 @@ float range(float *elevation)
 
     max = min = elevation[0];
     for (i = 1; i < NUM_DIRS; i++) {
-	max = MAX(elevation[i], max);
-	min = MIN(elevation[i], min);
+        max = MAX(elevation[i], max);
+        min = MIN(elevation[i], min);
     }
 
     return max - min;
@@ -173,11 +173,11 @@ float variance(float *elevation, int pattern_size)
     int i;
 
     for (i = 0; i < NUM_DIRS; i++)
-	sum_elevation += elevation[i];
+        sum_elevation += elevation[i];
     sum_elevation /= (float)pattern_size;
     for (i = 0; i < NUM_DIRS; i++)
-	variance +=
-	    ((sum_elevation - elevation[i]) * (sum_elevation - elevation[i]));
+        variance +=
+            ((sum_elevation - elevation[i]) * (sum_elevation - elevation[i]));
 
     return variance / (float)pattern_size;
 }
@@ -190,14 +190,14 @@ int radial2cartesian(PATTERN * pattern)
     int i;
 
     for (i = 0; i < NUM_DIRS; ++i)
-	if (pattern->distance > 0) {
-	    pattern->x[i] = pattern->distance[i] * sins[i];
-	    pattern->y[i] = pattern->distance[i] * coss[i];
-	}
-	else {
-	    pattern->x[i] = 0;
-	    pattern->y[i] = 0;
-	}
+        if (pattern->distance > 0) {
+            pattern->x[i] = pattern->distance[i] * sins[i];
+            pattern->y[i] = pattern->distance[i] * coss[i];
+        }
+        else {
+            pattern->x[i] = 0;
+            pattern->y[i] = 0;
+        }
     return 0;
 }
 
@@ -207,15 +207,15 @@ float extends(PATTERN * pattern)
     float area = 0;
 
     for (i = 0, j = 1; i < NUM_DIRS; ++i, ++j) {
-	j = j < NUM_DIRS ? j : 0;
-	area +=
-	    (pattern->x[i] * pattern->y[j] - pattern->x[j] * pattern->y[i]);
+        j = j < NUM_DIRS ? j : 0;
+        area +=
+            (pattern->x[i] * pattern->y[j] - pattern->x[j] * pattern->y[i]);
     }
     return fabs(area) / 2.;
 }
 
 int shape(PATTERN * pattern, int pattern_size, float *azimuth,
-	  float *elongation, float *width)
+          float *elongation, float *width)
 {
     /* calculates azimuth, elongation and width of geomorphon's polygon */
     int i;
@@ -228,10 +228,10 @@ int shape(PATTERN * pattern, int pattern_size, float *azimuth,
     double rxmin, rxmax, rymin, rymax;
 
     for (i = 0; i < NUM_DIRS; ++i) {
-	avg_y += pattern->y[i];
-	avg_x += pattern->x[i];
-	avg_x_square += pattern->x[i] * pattern->x[i];
-	avg_x_y += pattern->x[i] * pattern->y[i];
+        avg_y += pattern->y[i];
+        avg_x += pattern->x[i];
+        avg_x_square += pattern->x[i] * pattern->x[i];
+        avg_x_y += pattern->x[i] * pattern->y[i];
     }
     avg_y /= (float)pattern_size;
     avg_x /= (float)pattern_size;
@@ -247,12 +247,12 @@ int shape(PATTERN * pattern, int pattern_size, float *azimuth,
     rxmin = rxmax = pattern->x[0] * cosine - pattern->y[0] * sine;
     rymin = rymax = pattern->x[0] * sine + pattern->y[0] * cosine;
     for (i = 1; i < NUM_DIRS; ++i) {
-	rx = pattern->x[i] * cosine - pattern->y[i] * sine;
-	ry = pattern->x[i] * sine + pattern->y[i] * cosine;
-	rxmin = MIN(rx, rxmin);
-	rxmax = MAX(rx, rxmax);
-	rymin = MIN(ry, rymin);
-	rymax = MAX(ry, rymax);
+        rx = pattern->x[i] * cosine - pattern->y[i] * sine;
+        ry = pattern->x[i] * sine + pattern->y[i] * cosine;
+        rxmin = MIN(rx, rxmin);
+        rxmax = MAX(rx, rxmax);
+        rymin = MIN(ry, rymin);
+        rymax = MAX(ry, rymax);
     }
     rx = (rxmax - rxmin);
     ry = (rymax - rymin);

+ 17 - 17
raster/r.geomorphon/local_proto.h

@@ -15,7 +15,7 @@
 #endif
 
 
-#ifndef PI2			/* PI/2 */
+#ifndef PI2                     /* PI/2 */
 #define PI2 (2*atan(1))
 #endif
 
@@ -42,7 +42,7 @@ typedef struct
     char elevname[150];
     RASTER_MAP_TYPE raster_type;
     FCELL **elev;
-    int fd;			/* file descriptor */
+    int fd;                     /* file descriptor */
 } MAPS;
 
 typedef struct
@@ -54,24 +54,24 @@ typedef struct
     int pattern[NUM_DIRS];
     float elevation[NUM_DIRS];
     double distance[NUM_DIRS];
-    double x[NUM_DIRS], y[NUM_DIRS];		/* cartesian coordinates of geomorphon */
+    double x[NUM_DIRS], y[NUM_DIRS];    /* cartesian coordinates of geomorphon */
 } PATTERN;
 
 typedef enum
 {
-    ZERO,			/* zero cats do not accept zero category */
-    FL,				/* flat */
-    PK,				/* peak (summit) */
-    RI,				/* ridge */
-    SH,				/* shoulder */
-    SP,				/* spur (convex slope) */
-    SL,				/* slope */
-    HL,				/* hollow (concave slope) */
-    FS,				/* footslope */
-    VL,				/* valley */
-    PT,				/* pit (depression) */
-    __,				/* error (impossible) */
-    CNT				/* counter */
+    ZERO,                       /* zero cats do not accept zero category */
+    FL,                         /* flat */
+    PK,                         /* peak (summit) */
+    RI,                         /* ridge */
+    SH,                         /* shoulder */
+    SP,                         /* spur (convex slope) */
+    SL,                         /* slope */
+    HL,                         /* hollow (concave slope) */
+    FS,                         /* footslope */
+    VL,                         /* valley */
+    PT,                         /* pit (depression) */
+    __,                         /* error (impossible) */
+    CNT                         /* counter */
 } FORMS;
 
 /* main */
@@ -105,7 +105,7 @@ float exposition(float *elevation);
 float range(float *elevation);
 float variance(float *elevation, int n);
 int shape(PATTERN * pattern, int pattern_size, float *azimuth,
-	  float *elongation, float *width);
+          float *elongation, float *width);
 float extends(PATTERN * pattern);
 int radial2cartesian(PATTERN *);
 #endif

Різницю між файлами не показано, бо вона завелика
+ 482 - 480
raster/r.geomorphon/main.c


+ 65 - 62
raster/r.geomorphon/memory.c

@@ -31,56 +31,57 @@ int open_map(MAPS * rast)
     mapset = (char *)G_find_raster2(rast->elevname, "");
 
     if (mapset == NULL)
-	G_fatal_error(_("Raster map <%s> not found"), rast->elevname);
+        G_fatal_error(_("Raster map <%s> not found"), rast->elevname);
 
     rast->fd = Rast_open_old(rast->elevname, mapset);
     Rast_get_cellhd(rast->elevname, mapset, &cellhd);
     rast->raster_type = Rast_map_type(rast->elevname, mapset);
 
     if (window.ew_res + 1e-10 < cellhd.ew_res ||
-	window.ns_res + 1e-10 < cellhd.ns_res)
-	G_warning(_("Region resolution shoudn't be lesser than map %s resolution. Run g.region raster=%s to set proper resolution"),
-		  rast->elevname, rast->elevname);
+        window.ns_res + 1e-10 < cellhd.ns_res)
+        G_warning(_("Region resolution shoudn't be lesser than map %s resolution. Run g.region raster=%s to set proper resolution"),
+                  rast->elevname, rast->elevname);
 
     tmp_buf = Rast_allocate_buf(rast->raster_type);
     rast->elev = (FCELL **) G_malloc((row_buffer_size + 1) * sizeof(FCELL *));
 
     for (row = 0; row < row_buffer_size + 1; ++row) {
-	rast->elev[row] = Rast_allocate_buf(FCELL_TYPE);
-	Rast_get_row(rast->fd, tmp_buf, row, rast->raster_type);
-	for (col = 0; col < ncols; ++col)
-	    get_cell(col, rast->elev[row], tmp_buf, rast->raster_type);
-    }				/* end elev */
+        rast->elev[row] = Rast_allocate_buf(FCELL_TYPE);
+        Rast_get_row(rast->fd, tmp_buf, row, rast->raster_type);
+        for (col = 0; col < ncols; ++col)
+            get_cell(col, rast->elev[row], tmp_buf, rast->raster_type);
+    }                           /* end elev */
 
     G_free(tmp_buf);
     return 0;
 }
 
-static int get_cell(int col, float *buf_row, void *buf, RASTER_MAP_TYPE raster_type)
+static int get_cell(int col, float *buf_row, void *buf,
+                    RASTER_MAP_TYPE raster_type)
 {
 
     switch (raster_type) {
 
     case CELL_TYPE:
-	if (Rast_is_null_value(&((CELL *) buf)[col], CELL_TYPE))
-	    Rast_set_f_null_value(&buf_row[col], 1);
-	else
-	    buf_row[col] = (FCELL) ((CELL *) buf)[col];
-	break;
+        if (Rast_is_null_value(&((CELL *) buf)[col], CELL_TYPE))
+            Rast_set_f_null_value(&buf_row[col], 1);
+        else
+            buf_row[col] = (FCELL) ((CELL *) buf)[col];
+        break;
 
     case FCELL_TYPE:
-	if (Rast_is_null_value(&((FCELL *) buf)[col], FCELL_TYPE))
-	    Rast_set_f_null_value(&buf_row[col], 1);
-	else
-	    buf_row[col] = (FCELL) ((FCELL *) buf)[col];
-	break;
+        if (Rast_is_null_value(&((FCELL *) buf)[col], FCELL_TYPE))
+            Rast_set_f_null_value(&buf_row[col], 1);
+        else
+            buf_row[col] = (FCELL) ((FCELL *) buf)[col];
+        break;
 
     case DCELL_TYPE:
-	if (Rast_is_null_value(&((DCELL *) buf)[col], DCELL_TYPE))
-	    Rast_set_f_null_value(&buf_row[col], 1);
-	else
-	    buf_row[col] = (FCELL) ((DCELL *) buf)[col];
-	break;
+        if (Rast_is_null_value(&((DCELL *) buf)[col], DCELL_TYPE))
+            Rast_set_f_null_value(&buf_row[col], 1);
+        else
+            buf_row[col] = (FCELL) ((DCELL *) buf)[col];
+        break;
     }
 
     return 0;
@@ -97,15 +98,15 @@ int shift_buffers(int row)
     tmp_elev_buf = elevation.elev[0];
 
     for (i = 1; i < row_buffer_size + 1; ++i)
-	elevation.elev[i - 1] = elevation.elev[i];
+        elevation.elev[i - 1] = elevation.elev[i];
 
     elevation.elev[row_buffer_size] = tmp_elev_buf;
     Rast_get_row(elevation.fd, tmp_buf, row + row_radius_size + 1,
-		 elevation.raster_type);
+                 elevation.raster_type);
 
     for (col = 0; col < ncols; ++col)
-	get_cell(col, elevation.elev[row_buffer_size], tmp_buf,
-		 elevation.raster_type);
+        get_cell(col, elevation.elev[row_buffer_size], tmp_buf,
+                 elevation.raster_type);
 
     G_free(tmp_buf);
     return 0;
@@ -116,7 +117,7 @@ int free_map(FCELL ** map, int n)
     int i;
 
     for (i = 0; i < n; ++i)
-	G_free(map[i]);
+        G_free(map[i]);
     G_free(map);
     return 0;
 }
@@ -126,33 +127,34 @@ int write_form_cat_colors(char *raster)
     struct Colors colors;
     struct Categories cats;
     FORMS i;
-    const CATCOLORS ccolors[CNT] = {	/* colors and cats for forms */
-	{ZERO, 0, 0, 0, "forms"},
-	{FL, 220, 220, 220, "flat"},
-	{PK, 56, 0, 0, "summit"},
-	{RI, 200, 0, 0, "ridge"},
-	{SH, 255, 80, 20, "shoulder"},
-	{SP, 250, 210, 60, "spur"},
-	{SL, 255, 255, 60, "slope"},
-	{HL, 180, 230, 20, "hollow"},
-	{FS, 60, 250, 150, "footslope"},
-	{VL, 0, 0, 255, "valley"},
-	{PT, 0, 0, 56, "depression"},
-	{__, 255, 0, 255, "ERROR"}
+
+    const CATCOLORS ccolors[CNT] = {    /* colors and cats for forms */
+        {ZERO, 0, 0, 0, "forms"},
+        {FL, 220, 220, 220, "flat"},
+        {PK, 56, 0, 0, "summit"},
+        {RI, 200, 0, 0, "ridge"},
+        {SH, 255, 80, 20, "shoulder"},
+        {SP, 250, 210, 60, "spur"},
+        {SL, 255, 255, 60, "slope"},
+        {HL, 180, 230, 20, "hollow"},
+        {FS, 60, 250, 150, "footslope"},
+        {VL, 0, 0, 255, "valley"},
+        {PT, 0, 0, 56, "depression"},
+        {__, 255, 0, 255, "ERROR"}
     };
 
     Rast_init_colors(&colors);
 
     for (i = FL; i < CNT; ++i)
-	Rast_add_color_rule(&ccolors[i].cat, ccolors[i].r, ccolors[i].g,
-			    ccolors[i].b, &ccolors[i].cat, ccolors[i].r,
-			    ccolors[i].g, ccolors[i].b, &colors, CELL_TYPE);
+        Rast_add_color_rule(&ccolors[i].cat, ccolors[i].r, ccolors[i].g,
+                            ccolors[i].b, &ccolors[i].cat, ccolors[i].r,
+                            ccolors[i].g, ccolors[i].b, &colors, CELL_TYPE);
     Rast_write_colors(raster, G_mapset(), &colors);
     Rast_free_colors(&colors);
     Rast_init_cats("Forms", &cats);
     for (i = FL; i < CNT; ++i)
-	Rast_set_cat(&ccolors[i].cat, &ccolors[i].cat, ccolors[i].label,
-		     &cats, CELL_TYPE);
+        Rast_set_cat(&ccolors[i].cat, &ccolors[i].cat, ccolors[i].label,
+                     &cats, CELL_TYPE);
     Rast_write_cats(raster, &cats);
     Rast_free_cats(&cats);
     return 0;
@@ -161,28 +163,29 @@ int write_form_cat_colors(char *raster)
 int write_contrast_colors(char *raster)
 {
     struct Colors colors;
+
     /* struct Categories cats; */
 
-    FCOLORS fcolors[9] = {	/* colors for positive openness */
-	{-2500, 0, 0, 50, NULL},
-	{-100, 0, 0, 56, NULL},
-	{-15, 0, 56, 128, NULL},
-	{-3, 0, 128, 255, NULL},
-	{0, 255, 255, 255, NULL},
-	{3, 255, 128, 0, NULL},
-	{15, 128, 56, 0, NULL},
-	{100, 56, 0, 0, NULL},
-	{2500, 50, 0, 0, NULL}
+    FCOLORS fcolors[9] = {      /* colors for positive openness */
+        {-2500, 0, 0, 50, NULL},
+        {-100, 0, 0, 56, NULL},
+        {-15, 0, 56, 128, NULL},
+        {-3, 0, 128, 255, NULL},
+        {0, 255, 255, 255, NULL},
+        {3, 255, 128, 0, NULL},
+        {15, 128, 56, 0, NULL},
+        {100, 56, 0, 0, NULL},
+        {2500, 50, 0, 0, NULL}
     };
     int i;
 
     Rast_init_colors(&colors);
 
     for (i = 0; i < 8; ++i)
-	Rast_add_d_color_rule(&fcolors[i].cat, fcolors[i].r, fcolors[i].g,
-			      fcolors[i].b, &fcolors[i + 1].cat,
-			      fcolors[i + 1].r, fcolors[i + 1].g,
-			      fcolors[i + 1].b, &colors);
+        Rast_add_d_color_rule(&fcolors[i].cat, fcolors[i].r, fcolors[i].g,
+                              fcolors[i].b, &fcolors[i + 1].cat,
+                              fcolors[i + 1].r, fcolors[i + 1].g,
+                              fcolors[i + 1].b, &colors);
     Rast_write_colors(raster, G_mapset(), &colors);
     Rast_free_colors(&colors);
     /*

+ 6 - 6
raster/r.geomorphon/multires.c

@@ -8,14 +8,14 @@ int pattern_matching(int *pattern)
     int sign = -1;
 
     for (i = 0, n = 1; i < NUM_DIRS; i++, n *= 2)
-	binary += (pattern[i] == sign) ? n : 0;
+        binary += (pattern[i] == sign) ? n : 0;
     /* rotate */
     for (i = 0; i < NUM_DIRS; ++i) {
-	if ((i &= 7) == 0)
-	    test = binary;
-	else
-	    test = (binary << i) | (binary >> (NUM_DIRS - i));
-	result = MIN(result, test);
+        if ((i &= 7) == 0)
+            test = binary;
+        else
+            test = (binary << i) | (binary >> (NUM_DIRS - i));
+        result = MIN(result, test);
     }
     return ((result & source) == source) ? 1 : 0;
 

+ 104 - 104
raster/r.geomorphon/pattern.c

@@ -28,118 +28,118 @@ int calc_pattern(PATTERN * pattern, int row, int cur_row, int col)
     pattern->negatives = 0;
 
     for (i = 0; i < NUM_DIRS; ++i) {
-	/* reset patterns */
-	pattern->pattern[i] = 0;
-	pattern->elevation[i] = 0.;
-	pattern->distance[i] = 0.;
-	j = skip_cells + 1;
-	zenith_angle = -(PI2);
-	nadir_angle = PI2;
+        /* reset patterns */
+        pattern->pattern[i] = 0;
+        pattern->elevation[i] = 0.;
+        pattern->distance[i] = 0.;
+        j = skip_cells + 1;
+        zenith_angle = -(PI2);
+        nadir_angle = PI2;
 
-	if (cur_row + j * nextr[i] < 0 ||
-	    cur_row + j * nextr[i] > row_buffer_size - 1 ||
-	    col + j * nextc[i] < 0 || col + j * nextc[i] > ncols - 1)
-	    continue;		/* border: current cell is on the end of DEM */
-	if (Rast_is_f_null_value
-	    (&elevation.elev[cur_row + nextr[i]][col + nextc[i]]))
-	    continue;		/* border: next value is null, line-of-sight does not exists */
-	pattern_size++;		/* line-of-sight exists, continue calculate visibility */
+        if (cur_row + j * nextr[i] < 0 ||
+            cur_row + j * nextr[i] > row_buffer_size - 1 ||
+            col + j * nextc[i] < 0 || col + j * nextc[i] > ncols - 1)
+            continue;           /* border: current cell is on the end of DEM */
+        if (Rast_is_f_null_value
+            (&elevation.elev[cur_row + nextr[i]][col + nextc[i]]))
+            continue;           /* border: next value is null, line-of-sight does not exists */
+        pattern_size++;         /* line-of-sight exists, continue calculate visibility */
 
-	target_northing =
-	    Rast_row_to_northing(row + j * nextr[i] + 0.5, &window);
-	target_easting =
-	    Rast_col_to_easting(col + j * nextc[i] + 0.5, &window);
-	cur_distance =
-	    G_distance(cur_easting, cur_northing, target_easting,
-		       target_northing);
+        target_northing =
+            Rast_row_to_northing(row + j * nextr[i] + 0.5, &window);
+        target_easting =
+            Rast_col_to_easting(col + j * nextc[i] + 0.5, &window);
+        cur_distance =
+            G_distance(cur_easting, cur_northing, target_easting,
+                       target_northing);
 
-	while (cur_distance < search_distance) {
-	    if (cur_row + j * nextr[i] < 0 ||
-		cur_row + j * nextr[i] > row_buffer_size - 1 ||
-		col + j * nextc[i] < 0 || col + j * nextc[i] > ncols - 1)
-		break;		/* reached end of DEM (cols) or buffer (rows) */
+        while (cur_distance < search_distance) {
+            if (cur_row + j * nextr[i] < 0 ||
+                cur_row + j * nextr[i] > row_buffer_size - 1 ||
+                col + j * nextc[i] < 0 || col + j * nextc[i] > ncols - 1)
+                break;          /* reached end of DEM (cols) or buffer (rows) */
 
-	    height =
-		elevation.elev[cur_row + j * nextr[i]][col + j * nextc[i]] -
-		center_height;
-	    angle = atan2(height, cur_distance);
+            height =
+                elevation.elev[cur_row + j * nextr[i]][col + j * nextc[i]] -
+                center_height;
+            angle = atan2(height, cur_distance);
 
-	    if (angle > zenith_angle) {
-		zenith_angle = angle;
-		zenith_height = height;
-		zenith_distance = cur_distance;
-	    }
-	    if (angle < nadir_angle) {
-		nadir_angle = angle;
-		nadir_height = height;
-		nadir_distance = cur_distance;
-	    }
-	    j += cell_step;
-	    /*             j++; */ /* go to next cell */
-	    target_northing =
-		Rast_row_to_northing(row + j * nextr[i] + 0.5, &window);
-	    target_easting =
-		Rast_col_to_easting(col + j * nextc[i] + 0.5, &window);
-	    cur_distance =
-		G_distance(cur_easting, cur_northing, target_easting,
-			   target_northing);
-	}			/* end line of sight */
+            if (angle > zenith_angle) {
+                zenith_angle = angle;
+                zenith_height = height;
+                zenith_distance = cur_distance;
+            }
+            if (angle < nadir_angle) {
+                nadir_angle = angle;
+                nadir_height = height;
+                nadir_distance = cur_distance;
+            }
+            j += cell_step;
+            /*             j++; *//* go to next cell */
+            target_northing =
+                Rast_row_to_northing(row + j * nextr[i] + 0.5, &window);
+            target_easting =
+                Rast_col_to_easting(col + j * nextc[i] + 0.5, &window);
+            cur_distance =
+                G_distance(cur_easting, cur_northing, target_easting,
+                           target_northing);
+        }                       /* end line of sight */
 
-	/* original paper version */
-	/*      zenith_angle=PI2-zenith_angle;
-	   nadir_angle=PI2+nadir_angle;
-	   if(fabs(zenith_angle-nadir_angle) > flat_threshold) {
-	   if((nadir_angle-zenith_angle) > 0) {
-	   patterns->pattern[i]=1;
-	   patterns->elevation[i]=nadir_height;
-	   patterns->distance[i]=nadir_distance;
-	   patterns->num_positives++;
-	   } else {
-	   patterns->pattern[i]=-1;
-	   patterns->elevation[i]=zenith_height;
-	   patterns->distance[i]=zenith_distance;
-	   patterns->num_negatives++;
-	   }
-	   } else {
-	   patterns->distance[i]=search_distance;
-	   }
-	 */
-	/* this is used to lower flat threshold if distance exceed flat_distance parameter */
-	zenith_threshold = (flat_distance > 0 &&
-			    flat_distance <
-			    zenith_distance) ? atan2(flat_threshold_height,
-						     zenith_distance) :
-	    flat_threshold;
-	nadir_threshold = (flat_distance > 0 &&
-			   flat_distance <
-			   nadir_distance) ? atan2(flat_threshold_height,
-						   nadir_distance) :
-	    flat_threshold;
+        /* original paper version */
+        /*      zenith_angle=PI2-zenith_angle;
+           nadir_angle=PI2+nadir_angle;
+           if(fabs(zenith_angle-nadir_angle) > flat_threshold) {
+           if((nadir_angle-zenith_angle) > 0) {
+           patterns->pattern[i]=1;
+           patterns->elevation[i]=nadir_height;
+           patterns->distance[i]=nadir_distance;
+           patterns->num_positives++;
+           } else {
+           patterns->pattern[i]=-1;
+           patterns->elevation[i]=zenith_height;
+           patterns->distance[i]=zenith_distance;
+           patterns->num_negatives++;
+           }
+           } else {
+           patterns->distance[i]=search_distance;
+           }
+         */
+        /* this is used to lower flat threshold if distance exceed flat_distance parameter */
+        zenith_threshold = (flat_distance > 0 &&
+                            flat_distance <
+                            zenith_distance) ? atan2(flat_threshold_height,
+                                                     zenith_distance) :
+            flat_threshold;
+        nadir_threshold = (flat_distance > 0 &&
+                           flat_distance <
+                           nadir_distance) ? atan2(flat_threshold_height,
+                                                   nadir_distance) :
+            flat_threshold;
 
-	if (zenith_angle > zenith_threshold)
-	    pattern->positives += i;
-	if (nadir_angle < -nadir_threshold)
-	    pattern->negatives += i;
+        if (zenith_angle > zenith_threshold)
+            pattern->positives += i;
+        if (nadir_angle < -nadir_threshold)
+            pattern->negatives += i;
 
-	if (fabs(zenith_angle) > zenith_threshold ||
-	    fabs(nadir_angle) > nadir_threshold) {
-	    if (fabs(nadir_angle) < fabs(zenith_angle)) {
-		pattern->pattern[i] = 1;
-		pattern->elevation[i] = zenith_height;	/* A CHANGE! */
-		pattern->distance[i] = zenith_distance;
-		pattern->num_positives++;
-	    }
-	    if (fabs(nadir_angle) > fabs(zenith_angle)) {
-		pattern->pattern[i] = -1;
-		pattern->elevation[i] = nadir_height;	/* A CHANGE! */
-		pattern->distance[i] = nadir_distance;
-		pattern->num_negatives++;
-	    }
-	}
-	else {
-	    pattern->distance[i] = search_distance;
-	}
+        if (fabs(zenith_angle) > zenith_threshold ||
+            fabs(nadir_angle) > nadir_threshold) {
+            if (fabs(nadir_angle) < fabs(zenith_angle)) {
+                pattern->pattern[i] = 1;
+                pattern->elevation[i] = zenith_height;  /* A CHANGE! */
+                pattern->distance[i] = zenith_distance;
+                pattern->num_positives++;
+            }
+            if (fabs(nadir_angle) > fabs(zenith_angle)) {
+                pattern->pattern[i] = -1;
+                pattern->elevation[i] = nadir_height;   /* A CHANGE! */
+                pattern->distance[i] = nadir_distance;
+                pattern->num_negatives++;
+            }
+        }
+        else {
+            pattern->distance[i] = search_distance;
+        }
 
-    }				/* end for */
+    }                           /* end for */
     return pattern_size;
 }