cell_title.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**************************************************************
  2. * char *Rast_get_cell_title (name, mapset)
  3. * char *name name of map file
  4. * char *mapset mapset containing name
  5. *
  6. * returns pointer to string containing cell title. (from cats file)
  7. *************************************************************/
  8. #include <grass/gis.h>
  9. /*!
  10. * \brief get raster map title
  11. *
  12. * If only the map layer title is needed, it is not necessary to read the
  13. * entire category file into memory. This routine gets the title for raster map
  14. * <b>name</b> in <b>mapset</b> directly from the category file, and returns
  15. * a pointer to the title. A legal pointer is always returned. If the map layer
  16. * does not have a title, then a pointer to the empty string "" is returned.
  17. *
  18. * \param name
  19. * \param mapset
  20. * \return char *
  21. */
  22. char *Rast_get_cell_title(const char *name, const char *mapset)
  23. {
  24. FILE *fd;
  25. int stat;
  26. char title[1024];
  27. stat = -1;
  28. fd = G_fopen_old("cats", name, mapset);
  29. if (fd) {
  30. stat = 1;
  31. if (!fgets(title, sizeof title, fd)) /* skip number of cats */
  32. stat = -1;
  33. else if (!G_getl(title, sizeof title, fd)) /* read title */
  34. stat = -1;
  35. fclose(fd);
  36. }
  37. if (stat < 0)
  38. *title = 0;
  39. else
  40. G_strip(title);
  41. return G_store(title);
  42. }