put_window.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. **********************************************************************
  3. *
  4. * G_put_window (window)
  5. * write the current mapset window
  6. **********************************************************************
  7. *
  8. * G__put_window (window, dir, name)
  9. * write the window 'name' in 'mapset'
  10. * returns -1 error
  11. * 1 ok
  12. *********************************************************************/
  13. #include <stdlib.h>
  14. #include <grass/gis.h>
  15. /*!
  16. * \brief write the database region
  17. *
  18. * Writes the database region file (WIND) in the user's current mapset
  19. * from <b>region.</b> Returns 1 if the region is written ok. Returns -1 if not
  20. * (no diagnostic message is printed).
  21. * <b>Warning.</b> Since this routine actually changes the database region, it
  22. * should only be called by modules which the user knows will change the region.
  23. * It is probably fair to say that under GRASS 3.0 only the <i>g.region</i>,
  24. * and <i>d.zoom</i> modules should call this routine.
  25. *
  26. * \param region
  27. * \return int
  28. */
  29. int G_put_window(const struct Cell_head *window)
  30. {
  31. char *wind = getenv("WIND_OVERRIDE");
  32. return wind ? G__put_window(window, "windows", wind)
  33. : G__put_window(window, "", "WIND");
  34. }
  35. int G__put_window(const struct Cell_head *window, char *dir, char *name)
  36. {
  37. FILE *fd;
  38. if (!(fd = G_fopen_new(dir, name)))
  39. return -1;
  40. G__write_Cell_head3(fd, window, 0);
  41. fclose(fd);
  42. return 1;
  43. }