prt_hdr.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <string.h>
  2. #include <grass/raster.h>
  3. #include <grass/glocale.h>
  4. #include "kappa.h"
  5. #include "local_proto.h"
  6. void prn_header(void)
  7. {
  8. int i, len;
  9. char buf[1024], *titles, *label;
  10. char *mask;
  11. FILE *fd;
  12. if (output == NULL)
  13. fd = stdout;
  14. else if ((fd = fopen(output, "w")) == NULL) {
  15. G_fatal_error(_("Cannot open file <%s> to write header"), output);
  16. return;
  17. }
  18. /* print header */
  19. fprintf(fd, "\t\t\t%s\n", title);
  20. sprintf(buf, "LOCATION: %s\t\t\t\t%s", G_location(), G_date());
  21. fprintf(fd, "%s\n", buf);
  22. if ((mask = maskinfo()))
  23. sprintf(buf, "MASK: %s", mask);
  24. fprintf(fd, "%s\n", buf);
  25. fprintf(fd, "MAPS: ");
  26. label = "MAP";
  27. len = strlen(label);
  28. for (i = 0; i < nlayers; i++) {
  29. titles = Rast_get_cats_title(&(layers[i].labels));
  30. if (titles)
  31. G_strip(titles);
  32. if (titles == NULL || *titles == 0)
  33. titles = "(untitled)";
  34. sprintf(buf, "%*s%-*s%d = %s (%s in %s)", i * 6, "", len, label,
  35. i + 1, titles, layers[i].name, layers[i].mapset);
  36. fprintf(fd, "%s\n", buf);
  37. }
  38. if (output != NULL)
  39. fclose(fd);
  40. }