auto_mask.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "gis.h"
00003 #include "glocale.h"
00004 /*
00005  **********************************************************************
00006  *
00007  *   G__check_for_auto_masking()
00008  *
00009  *   On first call, opens the mask file if declared and available
00010  *      and allocates buffer for reading mask rows.  Returns 0 for
00011  *      mask unset or unavailable and 1 for set and available.
00012  *   On second call, returns 0 or 1 as above.
00013  *
00014  *   returns:
00015  *      0  mask unset or unavailable
00016  *      1  mask set and available and ready to use
00017  **********************************************************************/
00018 
00019 #include "G.h"
00020 
00021 int G__check_for_auto_masking (void)
00022 {
00023     struct Cell_head cellhd;
00024 
00025     /* if mask is switched off (-2) return -2
00026        if G__.auto_mask is not set (-1) or set (>=0) recheck the MASK */
00027     if (G__.auto_mask < -1)
00028         return G__.auto_mask ;  
00029 
00030     /* if(G__.mask_fd > 0) free(G__.mask_buf);*/
00031 
00032 /* look for the existence of the MASK file */
00033     G__.auto_mask = (G_find_cell ("MASK", G_mapset()) != 0);
00034 
00035     if (G__.auto_mask <= 0)
00036         return 0;
00037 
00038 /* check MASK projection/zone against current region */
00039     if (G_get_cellhd ("MASK", G_mapset(), &cellhd) >= 0)
00040     {
00041         if (cellhd.zone != G_zone() || cellhd.proj != G_projection())
00042         {
00043             G__.auto_mask = 0;
00044             return 0;
00045         }
00046     }
00047 
00048     G_unopen_cell(G__.mask_fd );
00049     G__.mask_fd = G__open_cell_old ("MASK", G_mapset());
00050     if (G__.mask_fd < 0)
00051     {
00052         G__.auto_mask = 0;
00053         G_warning (_("Unable to open automatic MASK file"));
00054         return 0;
00055     }
00056 
00057 /*    G__.mask_buf = G_allocate_cell_buf();*/
00058 
00059     G__.auto_mask = 1;
00060 
00061     return 1;
00062 }
00063 
00064 int G_suppress_masking (void)
00065 {
00066     if (G__.auto_mask > 0)
00067     {
00068         G_close_cell (G__.mask_fd);
00069         /* free (G__.mask_buf); */
00070         G__.mask_fd = -1;
00071     }
00072     G__.auto_mask = -2;
00073 
00074     return 0;
00075 }
00076 
00077 int G_unsuppress_masking (void)
00078 {
00079     if (G__.auto_mask < -1)
00080     {
00081         G__.mask_fd = -1;
00082         G__check_for_auto_masking ();
00083     }
00084 
00085     return 0;
00086 }

Generated on Wed Aug 23 17:49:21 2006 for GRASS by  doxygen 1.4.7