Debian Codegraph @

raster/r.surf.gauss/gaussurf.c

raw
1 /* updated to FP support 11/99 Markus Neteler */
2
3 /*****************/
4
5 /** gaussurf() **/
6
7 /*****************/
8
9 #include <unistd.h>
10 #include <math.h>
11 #include <grass/gis.h>
12 #include <grass/raster.h>
13 #include <grass/gmath.h>
14
15 int gaussurf(char *out, /* Name of raster maps to be opened. */
16 double mean, double sigma /* Distribution parameters. */
17 )
18 {
19 int nrows, ncols; /* Number of cell rows and columns */
20
21 DCELL *row_out; /* Buffer just large enough to hold one */
22
23 /* row of the raster map layer. */
24
25 int fd_out; /* File descriptor - used to identify */
26
27 /* open raster maps. */
28 struct History history; /* cmd line history metadata */
29
30 int row_count, col_count;
31
32 /****** OPEN CELL FILES AND GET CELL DETAILS ******/
33
34 fd_out = Rast_open_new(out, DCELL_TYPE);
35
36 nrows = Rast_window_rows();
37 ncols = Rast_window_cols();
38
39 row_out = Rast_allocate_d_buf();
40
41 /****** PASS THROUGH EACH CELL ASSIGNING RANDOM VALUE ******/
42
43 for (row_count = 0; row_count < nrows; row_count++) {
44 G_percent(row_count, nrows, 5);
45 for (col_count = 0; col_count < ncols; col_count++)
46 *(row_out + col_count) = (DCELL)(G_math_rand_gauss(sigma) + mean);
47
48 /* Write contents row by row */
49 Rast_put_d_row(fd_out, (DCELL *)row_out);
50 }
51 G_percent(1, 1, 1);
52
53 /****** CLOSE THE CELL FILE ******/
54
55 Rast_close(fd_out);
56 Rast_short_history(out, "raster", &history);
57 Rast_command_history(&history);
58 Rast_write_history(out, &history);
59
60 return 0;
61 }