GRASS Programmer's Manual  6.4.2(2012)
auto_mask.c
Go to the documentation of this file.
00001 
00017 #include <stdlib.h>
00018 #include <grass/gis.h>
00019 #include <grass/glocale.h>
00020 #include "G.h"
00021 
00022 
00034 int G__check_for_auto_masking(void)
00035 {
00036     struct Cell_head cellhd;
00037 
00038     /* if mask is switched off (-2) return -2
00039        if G__.auto_mask is not set (-1) or set (>=0) recheck the MASK */
00040 
00041     if (G__.auto_mask < -1)
00042         return G__.auto_mask;
00043 
00044     /* if(G__.mask_fd > 0) G_free (G__.mask_buf); */
00045 
00046     /* look for the existence of the MASK file */
00047     G__.auto_mask = (G_find_cell("MASK", G_mapset()) != 0);
00048 
00049     if (G__.auto_mask <= 0)
00050         return 0;
00051 
00052     /* check MASK projection/zone against current region */
00053     if (G_get_cellhd("MASK", G_mapset(), &cellhd) >= 0) {
00054         if (cellhd.zone != G_zone() || cellhd.proj != G_projection()) {
00055             G__.auto_mask = 0;
00056             return 0;
00057         }
00058     }
00059 
00060     G_unopen_cell(G__.mask_fd);
00061     G__.mask_fd = G__open_cell_old("MASK", G_mapset());
00062     if (G__.mask_fd < 0) {
00063         G__.auto_mask = 0;
00064         G_warning(_("Unable to open automatic MASK file"));
00065         return 0;
00066     }
00067 
00068     /*    G__.mask_buf = G_allocate_cell_buf(); */
00069 
00070     G__.auto_mask = 1;
00071 
00072     return 1;
00073 }
00074 
00075 
00082 int G_suppress_masking(void)
00083 {
00084     if (G__.auto_mask > 0) {
00085         G_close_cell(G__.mask_fd);
00086         /* G_free (G__.mask_buf); */
00087         G__.mask_fd = -1;
00088     }
00089     G__.auto_mask = -2;
00090 
00091     return 0;
00092 }
00093 
00094 
00101 int G_unsuppress_masking(void)
00102 {
00103     if (G__.auto_mask < -1) {
00104         G__.mask_fd = -1;
00105         G__check_for_auto_masking();
00106     }
00107 
00108     return 0;
00109 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines