put_window.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 Write the database region
  13. *
  14. * Writes the database region file (WIND) in the user's current mapset
  15. * from region.
  16. * <b>Warning:</b> Since this routine actually changes the database
  17. * region, it should only be called by modules which the user knows
  18. * will change the region. It is probably fair to say that only the
  19. * <tt>g.region</tt>.
  20. *
  21. * \param[in,out] window pointer to Cell_head
  22. *
  23. * \return 1 on success
  24. * \return -1 on error (no diagnostic message is printed)
  25. */
  26. int G_put_window(const struct Cell_head *window)
  27. {
  28. char *wind = getenv("WIND_OVERRIDE");
  29. return wind ? G__put_window(window, "windows", wind)
  30. : G__put_window(window, "", "WIND");
  31. }
  32. /*!
  33. * \brief Write the database region
  34. *
  35. * Writes the database region file (WIND) in the user's current mapset
  36. * from region.
  37. * <b>Warning:</b> Since this routine actually changes the database
  38. * region, it should only be called by modules which the user knows
  39. * will change the region. It is probably fair to say that only the
  40. * <tt>g.region</tt>.
  41. *
  42. * \param[in,out] window pointer to Cell_head
  43. * \param dir directory name
  44. * \param name file name
  45. *
  46. * \return 1 on success
  47. * \return -1 on error (no diagnostic message is printed)
  48. */
  49. int G__put_window(const struct Cell_head *window, const char *dir, const char *name)
  50. {
  51. FILE *fd;
  52. if (!(fd = G_fopen_new(dir, name)))
  53. return -1;
  54. G__write_Cell_head3(fd, window, 0);
  55. fclose(fd);
  56. return 1;
  57. }