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 
gaussurf(char * out,double mean,double sigma)16 int gaussurf(char *out,		/* Name of raster maps to be opened.    */
17 	     double mean, double sigma	/* Distribution parameters.             */
18     )
19 {
20     int nrows, ncols;		/* Number of cell rows and columns      */
21 
22     DCELL *row_out;		/* Buffer just large enough to hold one */
23 
24     /* row of the raster map layer.         */
25 
26     int fd_out;			/* File descriptor - used to identify   */
27 
28     /* open raster maps.                    */
29     struct History history;	/* cmd line history metadata            */
30 
31     int row_count, col_count;
32 
33 	/****** INITIALISE RANDOM NUMBER GENERATOR ******/
34 
35     /* FIXME - allow seed to be specified for repeatability */
36     G_math_srand_auto();
37 
38 	/****** OPEN CELL FILES AND GET CELL DETAILS ******/
39 
40     fd_out = Rast_open_new(out, DCELL_TYPE);
41 
42     nrows = Rast_window_rows();
43     ncols = Rast_window_cols();
44 
45     row_out = Rast_allocate_d_buf();
46 
47 
48 	/****** PASS THROUGH EACH CELL ASSIGNING RANDOM VALUE ******/
49 
50     for (row_count = 0; row_count < nrows; row_count++) {
51 	G_percent(row_count, nrows, 5);
52 	for (col_count = 0; col_count < ncols; col_count++)
53 	    *(row_out + col_count) =
54 		(DCELL) (G_math_rand_gauss(sigma) + mean);
55 
56 	/* Write contents row by row */
57 	Rast_put_d_row(fd_out, (DCELL *) row_out);
58     }
59     G_percent(1, 1, 1);
60 
61 	/****** CLOSE THE CELL FILE ******/
62 
63     Rast_close(fd_out);
64     Rast_short_history(out, "raster", &history);
65     Rast_command_history(&history);
66     Rast_write_history(out, &history);
67 
68     return 0;
69 }
70