sigsetfile.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*!
  2. \file lib/imagery/sigsetfile.c
  3. \brief Imagery Library - Signature file functions (statistics for i.smap)
  4. (C) 2001-2011, 2013 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author USA CERL
  8. */
  9. #include <string.h>
  10. #include <grass/gis.h>
  11. #include <grass/imagery.h>
  12. #include <grass/glocale.h>
  13. /*!
  14. \brief Create new signiture file in given group/subgroup
  15. Note: Prints warning on error and returns NULL.
  16. \param group name of group
  17. \param subgroup name of subgroup
  18. \param name name of signiture file
  19. \return pointer to FILE
  20. \return NULL on error
  21. */
  22. FILE *I_fopen_sigset_file_new(const char *group, const char *subgroup,
  23. const char *name)
  24. {
  25. char element[GPATH_MAX];
  26. char group_name[GNAME_MAX], mapset[GMAPSET_MAX];
  27. FILE *fd;
  28. if (G_name_is_fully_qualified(group, group_name, mapset)) {
  29. if (strcmp(mapset, G_mapset()) != 0)
  30. G_warning(_("Unable to create signature file <%s> for subgroup <%s> "
  31. "of group <%s> - <%s> is not current mapset"),
  32. name, subgroup, group, mapset);
  33. }
  34. else {
  35. strcpy(group_name, group);
  36. }
  37. /* create sigset directory */
  38. sprintf(element, "%s/subgroup/%s/sigset", group_name, subgroup);
  39. G__make_mapset_element_misc("group", element);
  40. sprintf(element, "subgroup/%s/sigset/%s", subgroup, name);
  41. fd = G_fopen_new_misc("group", element, group_name);
  42. if (fd == NULL)
  43. G_warning(_("Unable to create signature file <%s> for subgroup <%s> "
  44. "of group <%s>"),
  45. name, subgroup, group);
  46. return fd;
  47. }
  48. /*!
  49. \brief Open existing signiture file
  50. \param group name of group (may be fully qualified)
  51. \param subgroup name of subgroup
  52. \param name name of signiture file
  53. \return pointer to FILE*
  54. \return NULL on error
  55. */
  56. FILE *I_fopen_sigset_file_old(const char *group, const char *subgroup,
  57. const char *name)
  58. {
  59. char element[GPATH_MAX];
  60. char group_name[GNAME_MAX], group_mapset[GMAPSET_MAX];
  61. FILE *fd;
  62. G_unqualified_name(group, NULL, group_name, group_mapset);
  63. sprintf(element, "subgroup/%s/sigset/%s", subgroup, name);
  64. fd = G_fopen_old_misc("group", element, group_name, group_mapset);
  65. return fd;
  66. }