print2.c 906 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <grass/gis.h>
  2. #include <grass/glocale.h>
  3. #include <grass/imagery.h>
  4. #include <grass/cluster.h>
  5. /* safe to call only during checkpoint(2) and after
  6. * I_cluster_exec() completes
  7. * otherwise call I_cluster_sum2() before calling this routine
  8. */
  9. int print_class_means(FILE * fd, struct Cluster *C)
  10. {
  11. int band;
  12. int c;
  13. int n;
  14. fprintf(fd, _("\nclass means/stddev for each band\n\n"));
  15. for (c = 0; c < C->nclasses; c++) {
  16. fprintf(fd, "\n");
  17. fprintf(fd, _("class %d (%d)\n"), c + 1, n = C->count[c]);
  18. fprintf(fd, _(" means "));
  19. if (n > 0)
  20. for (band = 0; band < C->nbands; band++)
  21. fprintf(fd, " %g", C->sum[band][c] / n);
  22. fprintf(fd, "\n");
  23. fprintf(fd, _(" stddev"));
  24. if (n > 1)
  25. for (band = 0; band < C->nbands; band++)
  26. fprintf(fd, " %g",
  27. I_stddev(C->sum[band][c], C->sum2[band][c], n));
  28. fprintf(fd, "\n");
  29. }
  30. fprintf(fd, "\n");
  31. return 0;
  32. }