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