source: grass/trunk/lib/raster/set_window.c@ 69586

Last change on this file since 69586 was 63887, checked in by neteler, 10 years ago

minor doxygen header updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id
  • Property svn:mime-type set to text/x-csrc
File size: 4.0 KB
Line 
1/*!
2 * \file lib/raster/set_window.c
3 *
4 * \brief Raster Library - Set window (map 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 <grass/gis.h>
15#include <grass/raster.h>
16#include <grass/glocale.h>
17
18#include "../gis/G.h"
19#include "R.h"
20
21static void update_window_mappings(void);
22static void check_write_window(void);
23
24void Rast__init_window(void)
25{
26 if (G_is_initialized(&R__.window_set))
27 return;
28
29 G__init_window();
30
31 R__.rd_window = G__.window;
32 R__.wr_window = G__.window;
33 R__.split_window = 0;
34
35 G_initialize_done(&R__.window_set);
36}
37
38/*!
39 * \brief Establishes 'window' as the current working window.
40 *
41 * \param window window to become operative window
42 */
43void Rast_set_window(struct Cell_head *window)
44{
45 Rast__init();
46
47 if (R__.split_window)
48 G_warning(_("Rast_set_window() called while window split"));
49
50 check_write_window();
51
52 G_adjust_Cell_head(window, 0, 0);
53
54 R__.wr_window = *window;
55 R__.rd_window = *window;
56 R__.split_window = 0;
57
58 update_window_mappings();
59}
60/*!
61 \brief Unset current window
62*/
63void Rast_unset_window(void)
64{
65 G_debug(4, "Rast_unset_window()");
66
67 R__.window_set = 0;
68}
69/*!
70 * \brief Establishes 'window' as the current working window for output.
71 *
72 * \param window window to become operative window
73 */
74void Rast_set_output_window(struct Cell_head *window)
75{
76 Rast__init();
77
78 check_write_window();
79
80 G_adjust_Cell_head(window, 0, 0);
81
82 R__.wr_window = *window;
83 R__.split_window = 1;
84
85 G_set_window(window);
86}
87
88/*!
89 * \brief Establishes 'window' as the current working window for input.
90 *
91 * Any opened cell files has its file-to-window mapping reworked.
92 *
93 * \param window window to become operative window
94 */
95
96void Rast_set_input_window(struct Cell_head *window)
97{
98 Rast__init();
99
100 G_adjust_Cell_head(window, 0, 0);
101
102 R__.rd_window = *window;
103 R__.split_window = 1;
104
105 update_window_mappings();
106}
107
108static void update_window_mappings(void)
109{
110 int i;
111 int maskfd;
112
113 /* adjust window, check for valid window */
114 /* adjust the real one, not a copy
115 G_copy (&twindow, window, sizeof(struct Cell_head));
116 window = &twindow;
117 */
118
119 /* except for MASK, cell files open for read must have same projection
120 * and zone as new window
121 */
122 maskfd = R__.auto_mask > 0 ? R__.mask_fd : -1;
123 for (i = 0; i < R__.fileinfo_count; i++) {
124 struct fileinfo *fcb = &R__.fileinfo[i];
125
126 if (fcb->open_mode == OPEN_OLD) {
127 if (fcb->cellhd.zone == R__.rd_window.zone &&
128 fcb->cellhd.proj == R__.rd_window.proj)
129 continue;
130 if (i != maskfd)
131 G_fatal_error(_("Rast_set_read_window(): projection/zone differs from that of "
132 "currently open raster maps"));
133 }
134 }
135
136 /* close the mask */
137 if (R__.auto_mask > 0) {
138 Rast_close(maskfd);
139 /* G_free (R__.mask_buf); */
140 R__.mask_fd = -1;
141 R__.auto_mask = -1; /* turn off masking */
142 }
143
144 /* now for each possible open cell file, recreate the window mapping */
145 /*
146 * also the memory for reading and writing must be reallocated for all opened
147 * cell files
148 */
149 for (i = 0; i < R__.fileinfo_count; i++) {
150 struct fileinfo *fcb = &R__.fileinfo[i];
151
152 if (fcb->open_mode != OPEN_OLD &&
153 fcb->open_mode != OPEN_NEW_UNCOMPRESSED &&
154 fcb->open_mode != OPEN_NEW_COMPRESSED)
155 continue;
156
157 if (fcb->open_mode == OPEN_OLD)
158 G_fatal_error(_("Input window changed while maps are open for read. Map name <%s>"), fcb->name);
159 }
160
161 /* turn masking (back) on if necessary */
162 Rast__check_for_auto_masking();
163}
164
165static void check_write_window(void)
166{
167 int i;
168
169 for (i = 0; i < R__.fileinfo_count; i++) {
170 struct fileinfo *fcb = &R__.fileinfo[i];
171
172 if (fcb->open_mode == OPEN_NEW_UNCOMPRESSED ||
173 fcb->open_mode == OPEN_NEW_COMPRESSED)
174 G_fatal_error(_("Output window changed while maps are open for write. Map name <%s>"), fcb->name);
175 }
176}
177
Note: See TracBrowser for help on using the repository browser.