GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
set_window.c
Go to the documentation of this file.
1 
17 #include <grass/gis.h>
18 #include <grass/glocale.h>
19 #include "G.h"
20 
30 int G_get_set_window(struct Cell_head *window)
31 {
33  G_copy((char *)window, (char *)&G__.window, sizeof(*window));
34 
35  return 1;
36 }
37 
38 
49 int G_set_window(struct Cell_head *window)
50 {
51  int i;
52  int maskfd;
53  char *err;
54 
55  /* adjust window, check for valid window */
56  /* adjust the real one, not a copy
57  G_copy (&twindow, window, sizeof(struct Cell_head));
58  window = &twindow;
59  */
60 
61  if ((err = G_adjust_Cell_head(window, 0, 0))) {
62  G_warning("G_set_window(): %s", err);
63  return -1;
64  }
65 
66  /* except for MASK, cell files open for read must have same projection
67  * and zone as new window
68  */
69  maskfd = G__.auto_mask > 0 ? G__.mask_fd : -1;
70  for (i = 0; i < G__.fileinfo_count; i++) {
71  if (G__.fileinfo[i].open_mode == OPEN_OLD) {
72  if (G__.fileinfo[i].cellhd.zone == window->zone &&
73  G__.fileinfo[i].cellhd.proj == window->proj)
74  continue;
75  if (i != maskfd) {
76  G_warning(_("G_set_window(): projection/zone differs from that of "
77  "currently open raster maps"));
78  return -1;
79  }
80  }
81  }
82 
83  /* close the mask */
84  if (G__.auto_mask > 0) {
85  G_close_cell(maskfd);
86  /* G_free (G__.mask_buf); */
87  G__.mask_fd = -1;
88  G__.auto_mask = -1; /* turn off masking */
89  }
90 
91  /* copy the window to the current window */
92  G_copy((char *)&G__.window, (char *)window, sizeof(*window));
93 
94  G__.window_set = 1;
95 
96  /* now for each possible open cell file, recreate the window mapping */
97  /*
98  * also the memory for reading and writing must be reallocated for all opened
99  * cell files
100  */
101  for (i = 0; i < G__.fileinfo_count; i++) {
102  if (G__.fileinfo[i].open_mode != OPEN_OLD &&
106  continue;
107 
108  if (G__.fileinfo[i].open_mode == OPEN_OLD)
110  /* code commented 10/1999 due to problems */
111  /* else */
112  /* opened for writing */
113  /* {
114  G_free (G__.fileinfo[i].data);
115  G__.fileinfo[i].data = (unsigned char *) G_calloc (G__.window.cols,
116  G_raster_size(G__.fileinfo[i].map_type));
117  }
118  */
119  /* allocate null bitstream buffers for reading/writing null rows */
120  /* for (j=0;j< NULL_ROWS_INMEM; j++)
121  {
122  G_free (G__.fileinfo[i].NULL_ROWS[j]);
123  G__.fileinfo[i].NULL_ROWS[j] = G__allocate_null_bits(G__.window.cols);
124  }
125  */
126 
127  /* initialize : no NULL rows in memory */
128  /* G__.fileinfo[i].min_null_row = (-1) * NULL_ROWS_INMEM;
129  if(G__.fileinfo[i].null_cur_row > 0)
130  {
131  G_warning(
132  "Calling G_set_window() in the middle of writing map %s",
133  G__.fileinfo[i].name);
134  G__.fileinfo[i].null_cur_row = 0;
135  }
136  */
137  }
138 
139  /* turn masking (back) on if necessary */
141 
142  /* reallocate/enlarge the G__. buffers for reading raster maps */
146  G__reallocate_work_buf(sizeof(DCELL));
148  /* we want the number of bytes per cell to be maximum
149  so that there is enough memory for reading and writing rows */
150 
151  return 1;
152 }
int mask_fd
Definition: G.h:80
int auto_mask
Definition: G.h:81
#define OPEN_NEW_RANDOM
Definition: G.h:103
int G_get_set_window(struct Cell_head *window)
Get the current working window.
Definition: set_window.c:30
int G_close_cell(int fd)
close a raster map
Definition: closecell.c:71
int G_copy(void *a, const void *b, int n)
Copies n bytes starting at address b into address a.
Definition: gis/copy.c:30
int G_set_window(struct Cell_head *window)
Establishes &#39;window&#39; as the current working window.
Definition: set_window.c:49
int fileinfo_count
Definition: G.h:94
const char * err
Definition: g3dcolor.c:50
int G__reallocate_null_buf(void)
Allocate/enlarge the null data buffer needed by get_map_row() and for conversion in put_row...
Definition: opencell.c:865
#define OPEN_NEW_UNCOMPRESSED
Definition: G.h:102
struct Cell_head window
Definition: G.h:78
int G__reallocate_temp_buf(void)
Allocate/enlarge the temporary buffer needed by G_get_raster_row[_nomask].
Definition: opencell.c:906
Definition: G.h:74
tuple window
Definition: tools.py:543
int open_mode
Definition: G.h:43
int window_set
Definition: G.h:79
char * G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header.
Definition: adj_cellhd.c:43
struct fileinfo * fileinfo
Definition: G.h:95
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
#define OPEN_OLD
Definition: G.h:100
struct Cell_head cellhd
Definition: G.h:44
#define XDR_DOUBLE_NBYTES
Definition: G.h:10
int G__reallocate_mask_buf(void)
Allocate/enlarge the mask buffer needed by get_map_row()
Definition: opencell.c:885
int G__create_window_mapping(int fd)
Create window mapping.
Definition: window_map.c:36
int G__reallocate_work_buf(int bytes_per_cell)
Allocate/enlarge the work data buffer needed by get_map_row and put_map_row()
Definition: opencell.c:842
int G__init_window(void)
Initialize window.
Definition: window_map.c:320
int G__check_for_auto_masking(void)
Checks for auto masking.
Definition: auto_mask.c:34
#define OPEN_NEW_COMPRESSED
Definition: G.h:101