gaussurf.c 1.7 KB

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