GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 }