Переглянути джерело

Initialize raster library automatically

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@38429 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 16 роки тому
батько
коміт
2ce51108a0

+ 1 - 0
include/rasterdefs.h

@@ -343,6 +343,7 @@ int Rast_command_history(struct History *);
 void Rast_init(void);
 void Rast__check_init(void);
 void Rast_init_all(void);
+void Rast__init(void);
 
 /* interp.c */
 DCELL Rast_interp_linear(double, DCELL, DCELL);

+ 6 - 0
lib/raster/auto_mask.c

@@ -38,6 +38,8 @@ int Rast__check_for_auto_masking(void)
 {
     struct Cell_head cellhd;
 
+    Rast__init();
+
     /* if mask is switched off (-2) return -2
        if R__.auto_mask is not set (-1) or set (>=0) recheck the MASK */
 
@@ -84,6 +86,8 @@ int Rast__check_for_auto_masking(void)
 
 void Rast_suppress_masking(void)
 {
+    Rast__init();
+
     if (R__.auto_mask > 0) {
 	Rast_close(R__.mask_fd);
 	/* G_free (R__.mask_buf); */
@@ -101,6 +105,8 @@ void Rast_suppress_masking(void)
 
 void Rast_unsuppress_masking(void)
 {
+    Rast__init();
+
     if (R__.auto_mask < -1) {
 	R__.mask_fd = -1;
 	Rast__check_for_auto_masking();

+ 1 - 0
lib/raster/gdal.c

@@ -355,6 +355,7 @@ struct GDAL_link *Rast_create_gdal_link(const char *name,
     struct Key_Value *key_val;
     char buf[32];
 
+    Rast__init();
 
     Rast_init_gdal();
 

+ 10 - 4
lib/raster/init.c

@@ -44,10 +44,7 @@ static int init(void);
 
 void Rast_init(void)
 {
-    if (initialized)
-	return;
-
-    init();
+    Rast__init();
 }
 
 
@@ -66,6 +63,14 @@ void Rast__check_init(void)
 }
 
 
+void Rast__init(void)
+{
+    if (G_is_initialized(&initialized))
+	return;
+    init();
+    G_initialize_done(&initialized);
+}
+
 static int init(void)
 {
     /* no histograms */
@@ -87,6 +92,7 @@ static int init(void)
 
 void Rast_init_all(void)
 {
+    Rast__init();
     Rast__check_for_auto_masking();
     Rast_init_gdal();
 }

+ 6 - 0
lib/raster/opencell.c

@@ -168,6 +168,8 @@ int Rast__open_old(const char *name, const char *mapset)
     char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
     struct GDAL_link *gdal;
 
+    Rast__init();
+
     /* make sure window is set    */
     Rast__init_window();
 
@@ -564,6 +566,8 @@ static int G__open_raster_new(const char *name, int open_mode,
     const char *cell_dir;
     int nbytes;
 
+    Rast__init();
+
     switch (map_type) {
     case CELL_TYPE:
 	cell_dir = "cell";
@@ -729,6 +733,8 @@ static int G__open_raster_new(const char *name, int open_mode,
  */
 int Rast_set_fp_type(RASTER_MAP_TYPE map_type)
 {
+    Rast__init();
+
     switch (map_type) {
     case FCELL_TYPE:
     case DCELL_TYPE:

+ 2 - 0
lib/raster/set_window.c

@@ -33,6 +33,8 @@ int Rast_set_window(struct Cell_head *window)
     int maskfd;
     const char *err;
 
+    Rast__init();
+
     /* adjust window, check for valid window */
     /* adjust the real one, not a copy
        G_copy (&twindow, window, sizeof(struct Cell_head));

+ 2 - 0
lib/raster/window_map.c

@@ -115,6 +115,8 @@ void Rast__create_window_mapping(int fd)
  */
 void Rast__init_window(void)
 {
+    Rast__init();
+
     if (G_is_initialized(&R__.window_set))
 	return;