get_stats.c 712 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/raster.h>
  4. #include <grass/glocale.h>
  5. #include "local_proto.h"
  6. int get_stats(const char *name, struct Cell_stats *statf)
  7. {
  8. int fd;
  9. CELL *cell;
  10. int row, nrows, ncols;
  11. fd = Rast_open_old(name, "");
  12. nrows = Rast_window_rows();
  13. ncols = Rast_window_cols();
  14. cell = Rast_allocate_c_buf();
  15. Rast_init_cell_stats(statf);
  16. G_message(_("Reading %s ..."), name);
  17. for (row = 0; row < nrows; row++) {
  18. G_percent(row, nrows, 2);
  19. Rast_get_c_row(fd, cell, row);
  20. Rast_update_cell_stats(cell, ncols, statf);
  21. }
  22. if (row < nrows)
  23. exit(1);
  24. Rast_close(fd);
  25. G_free(cell);
  26. G_percent(row, nrows, 2);
  27. return 0;
  28. }