GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
put_window.c
Go to the documentation of this file.
1 /*!
2  \file lib/gis/put_window.c
3 
4  \brief GIS Library - Modify window (i.e. GRASS region)
5 
6  (C) 2001-2009 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12 */
13 
14 #include <stdlib.h>
15 #include <grass/gis.h>
16 
17 #include "gis_local_proto.h"
18 
19 /*!
20  * \brief Writes the region (window)
21  *
22  * Writes the region file (WIND) in the user's current mapset
23  * or when environmental variable \c WIND_OVERRIDE is set,
24  * it writes the region to file specified by \c WIND_OVERRIDE variable.
25  *
26  * When \c WIND_OVERRIDE is set the current process and child processes
27  * are affected.
28  * Otherwise the whole GRASS session is affected.
29  *
30  * \warning When environmental variable \c WIND_OVERRIDE is not set,
31  * this routine actually changes the region.
32  * So in this case it should only be called by modules which the user knows
33  * will change the region. It is probably fair to say that only the
34  * \gmod{g.region} should call this routine unless \c WIND_OVERRIDE is set.
35  *
36  * This function does not adjust the \p window before setting the region
37  * so you should call G_adjust_Cell_head() before calling this function.
38  *
39  * \param[in,out] window pointer to Cell_head
40  *
41  * \return 1 on success
42  * \return -1 on error (no diagnostic message is printed)
43  *
44  * \sa G_get_window(), G_set_window(), python.core.use_temp_region()
45  */
46 int G_put_window(const struct Cell_head *window)
47 {
48  char *wind = getenv("WIND_OVERRIDE");
49 
50  return wind ? G_put_element_window(window, "windows", wind)
51  : G_put_element_window(window, "", "WIND");
52 }
53 
54 /*!
55  * \brief Write the region
56  *
57  * Writes the region file (WIND) in the user's current mapset
58  * from region.
59 
60  * <b>Warning:</b> Since this routine actually changes the
61  * region, it should only be called by modules which the user knows
62  * will change the region. It is probably fair to say that only the
63  * <tt>g.region</tt> should call this routine.
64  *
65  * \param[in,out] window pointer to Cell_head
66  * \param dir directory name
67  * \param name file name
68  *
69  * \return 1 on success
70  * \return -1 on error (no diagnostic message is printed)
71  *
72  * \sa G_put_window()
73  */
74 int G_put_element_window(const struct Cell_head *window, const char *dir, const char *name)
75 {
76  FILE *fd;
77 
78  if (!(fd = G_fopen_new(dir, name)))
79  return -1;
80 
81  G__write_Cell_head3(fd, window, 0);
82  fclose(fd);
83 
84  return 1;
85 }
2D/3D raster map header (used also for region)
Definition: gis.h:423
void G__write_Cell_head3(FILE *, const struct Cell_head *, int)
Write 3D cell header or window.
Definition: wr_cellhd.c:78
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
Definition: gis/open.c:220
int G_put_window(const struct Cell_head *window)
Writes the region (window)
Definition: put_window.c:46
int G_put_element_window(const struct Cell_head *window, const char *dir, const char *name)
Write the region.
Definition: put_window.c:74
const char * name
Definition: named_colr.c:7
char * getenv()