put_window.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*!
  2. \file gis/put_window.c
  3. \brief GIS Library - Modify window (i.e. GRASS region)
  4. (C) 2001-2009 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 Original author CERL
  8. */
  9. #include <stdlib.h>
  10. #include <grass/gis.h>
  11. /*!
  12. * \brief Writes the database region (window)
  13. *
  14. * Writes the database region file (WIND) in the user's current mapset
  15. * or when environmental variable \c WIND_OVERRIDE is set,
  16. * it writes the region to file specified by \c WIND_OVERRIDE variable.
  17. *
  18. * When \c WIND_OVERRIDE is set the current process and child processes
  19. * are affected.
  20. * Otherwise the whole GRASS session is affected.
  21. *
  22. * \warning When environmental variable \c WIND_OVERRIDE is not set,
  23. * this routine actually changes the database region.
  24. * So in this case it should only be called by modules which the user knows
  25. * will change the region. It is probably fair to say that only the
  26. * \gmod{g.region} should call this routine unless \c WIND_OVERRIDE is set.
  27. *
  28. * This function does not adjust the \p window before setting the region
  29. * so you should call G_adjust_Cell_head() before calling this function.
  30. *
  31. * \param[in,out] window pointer to Cell_head
  32. *
  33. * \return 1 on success
  34. * \return -1 on error (no diagnostic message is printed)
  35. *
  36. * \sa G_get_window(), G_set_window(), python.core.use_temp_region()
  37. */
  38. int G_put_window(const struct Cell_head *window)
  39. {
  40. char *wind = getenv("WIND_OVERRIDE");
  41. return wind ? G__put_window(window, "windows", wind)
  42. : G__put_window(window, "", "WIND");
  43. }
  44. /*!
  45. * \brief Write the database region
  46. *
  47. * Writes the database region file (WIND) in the user's current mapset
  48. * from region.
  49. * <b>Warning:</b> Since this routine actually changes the database
  50. * region, it should only be called by modules which the user knows
  51. * will change the region. It is probably fair to say that only the
  52. * <tt>g.region</tt> should call this routine.
  53. *
  54. * \param[in,out] window pointer to Cell_head
  55. * \param dir directory name
  56. * \param name file name
  57. *
  58. * \return 1 on success
  59. * \return -1 on error (no diagnostic message is printed)
  60. *
  61. * \sa G_put_window()
  62. */
  63. int G__put_window(const struct Cell_head *window, const char *dir, const char *name)
  64. {
  65. FILE *fd;
  66. if (!(fd = G_fopen_new(dir, name)))
  67. return -1;
  68. G__write_Cell_head3(fd, window, 0);
  69. fclose(fd);
  70. return 1;
  71. }