check.c 931 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/raster.h>
  4. #include <grass/raster3d.h>
  5. #include <grass/glocale.h>
  6. #include "local_proto.h"
  7. /*
  8. * check_stats() - Check and update statistics
  9. *
  10. * RETURN: EXIT_SUCCESS / EXIT_FAILURE
  11. */
  12. int check_stats(const char *name)
  13. {
  14. struct Categories cats;
  15. struct FPRange fprange;
  16. int cats_ok;
  17. G_message(_("Updating statistics for <%s>"), name);
  18. /* Get category status and max */
  19. cats_ok = (Rast3d_read_cats(name, "", &cats) >= 0);
  20. Rast3d_read_range(name, "", &fprange);
  21. /* Further category checks */
  22. if (!cats_ok)
  23. Rast_init_cats("", &cats);
  24. else if (cats.num != fprange.max) {
  25. cats.num = fprange.max;
  26. cats_ok = 0;
  27. }
  28. /* Update categories if needed */
  29. if (!cats_ok) {
  30. G_message(_("Updating the number of categories for <%s>"), name);
  31. Rast3d_write_cats(name, &cats);
  32. }
  33. Rast_free_cats(&cats);
  34. return 0;
  35. }