target.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <stdio.h>
  2. #include <grass/gis.h>
  3. #include <grass/imagery.h>
  4. #include <grass/glocale.h>
  5. /*!
  6. * \brief read target information
  7. *
  8. * Reads the target <b>location</b> and <b>mapset</b>
  9. * from the TARGET file for the specified group. Returns 1 if successful; 0
  10. * otherwise (and prints a diagnostic error). This routine is used by
  11. * <i>g.gui.gcp</i> and <i>i.rectify</i> and probably should not be used by
  12. * other programs.
  13. * <b>Note.</b> This routine does <b>not</b> validate the target information.
  14. *
  15. * \param group
  16. * \param location
  17. * \param mapset
  18. * \return int
  19. */
  20. int I_get_target(const char *group, char *location, char *mapset)
  21. {
  22. FILE *fd;
  23. int ok;
  24. *location = *mapset = 0;
  25. G_suppress_warnings(1);
  26. fd = I_fopen_group_file_old(group, "TARGET");
  27. G_suppress_warnings(0);
  28. if (fd == NULL)
  29. return 0;
  30. ok = (fscanf(fd, "%s %s", location, mapset) == 2);
  31. fclose(fd);
  32. if (!ok) {
  33. *location = *mapset = 0;
  34. G_warning(_("Unable to read target file for group [%s]"), group);
  35. }
  36. return ok;
  37. }
  38. /*!
  39. * \brief write target information
  40. *
  41. * Writes the target <b>location</b> and <b>mapset</b> to
  42. * the TARGET file for the specified <b>group.</b> Returns 1 if successful; 0
  43. * otherwise (but no error messages are printed).
  44. * This routine is used by <i>i.target</i> and probably should not be used by
  45. * other programs.
  46. * <b>Note.</b> This routine does <b>not</b> validate the target
  47. * information.
  48. *
  49. * \param group
  50. * \param location
  51. * \param mapset
  52. * \return int
  53. */
  54. int I_put_target(const char *group, const char *location, const char *mapset)
  55. {
  56. FILE *fd;
  57. fd = I_fopen_group_file_new(group, "TARGET");
  58. if (fd == NULL)
  59. return 0;
  60. fprintf(fd, "%s\n%s\n", location, mapset);
  61. fclose(fd);
  62. return 1;
  63. }