GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
int mask_fd
Definition: G.h:80
int auto_mask
Definition: G.h:81
int G_get_cellhd(const char *name, const char *mapset, struct Cell_head *cellhd)
Read the raster header.
Definition: get_cellhd.c:45
int G_suppress_masking(void)
Suppresses masking.
Definition: auto_mask.c:82
int G_close_cell(int fd)
close a raster map
Definition: closecell.c:71
int G_unsuppress_masking(void)
Unsuppresses masking.
Definition: auto_mask.c:101
Definition: G.h:74
char * G_find_cell(char *name, const char *mapset)
find a raster map
Definition: find_cell.c:63
int G_unopen_cell(int fd)
unopen a raster map
Definition: closecell.c:104
int G_zone(void)
Query cartographic zone.
Definition: zone.c:28
int G__open_cell_old(const char *name, const char *mapset)
Lower level function, open cell files, supercell files, and the MASK file.
Definition: opencell.c:149
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_projection(void)
query cartographic projection
Definition: proj1.c:33
int G__check_for_auto_masking(void)
Checks for auto masking.
Definition: auto_mask.c:34