prt_label.c 781 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <grass/raster.h>
  2. #include <grass/glocale.h>
  3. #include "kappa.h"
  4. #include "local_proto.h"
  5. void prt_label(void)
  6. {
  7. int i, j;
  8. long *cats;
  9. char *cl;
  10. FILE *fd;
  11. if (output == NULL)
  12. fd = stdout;
  13. else if ((fd = fopen(output, "a")) == NULL) {
  14. G_fatal_error(_("Can't open file <%s> to write label"), output);
  15. return;
  16. }
  17. /* print labels */
  18. for (i = 0; i < nlayers; i++) {
  19. fprintf(fd, "\n");
  20. fprintf(fd, "MAP%-d Category Description\n", i + 1);
  21. for (j = 0; j < ncat; j++) {
  22. cats = rlst;
  23. cl = Rast_get_c_cat((CELL *) &(cats[j]), &(layers[i].labels));
  24. if (cl)
  25. G_strip(cl);
  26. if (cl == NULL || *cl == 0)
  27. cl = "(no description)";
  28. fprintf(fd, "%ld: %s\n", rlst[j], cl);
  29. }
  30. }
  31. if (output != NULL)
  32. fclose(fd);
  33. }