GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
auto_mask.c
Go to the documentation of this file.
1 
17 #include <stdlib.h>
18 #include <grass/gis.h>
19 #include <grass/glocale.h>
20 #include "G.h"
21 
22 
35 {
36  struct Cell_head cellhd;
37 
38  /* if mask is switched off (-2) return -2
39  if G__.auto_mask is not set (-1) or set (>=0) recheck the MASK */
40 
41  if (G__.auto_mask < -1)
42  return G__.auto_mask;
43 
44  /* if(G__.mask_fd > 0) G_free (G__.mask_buf); */
45 
46  /* look for the existence of the MASK file */
47  G__.auto_mask = (G_find_cell("MASK", G_mapset()) != 0);
48 
49  if (G__.auto_mask <= 0)
50  return 0;
51 
52  /* check MASK projection/zone against current region */
53  if (G_get_cellhd("MASK", G_mapset(), &cellhd) >= 0) {
54  if (cellhd.zone != G_zone() || cellhd.proj != G_projection()) {
55  G__.auto_mask = 0;
56  return 0;
57  }
58  }
59 
61  G__.mask_fd = G__open_cell_old("MASK", G_mapset());
62  if (G__.mask_fd < 0) {
63  G__.auto_mask = 0;
64  G_warning(_("Unable to open automatic MASK file"));
65  return 0;
66  }
67 
68  /* G__.mask_buf = G_allocate_cell_buf(); */
69 
70  G__.auto_mask = 1;
71 
72  return 1;
73 }
74 
75 
83 {
84  if (G__.auto_mask > 0) {
86  /* G_free (G__.mask_buf); */
87  G__.mask_fd = -1;
88  }
89  G__.auto_mask = -2;
90 
91  return 0;
92 }
93 
94 
102 {
103  if (G__.auto_mask < -1) {
104  G__.mask_fd = -1;
106  }
107 
108  return 0;
109 }