[GRASS-SVN] r35675 - grass/branches/develbranch_6/raster/r.sun2

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 30 04:25:04 EST 2009


Author: neteler
Date: 2009-01-30 04:25:04 -0500 (Fri, 30 Jan 2009)
New Revision: 35675

Modified:
   grass/branches/develbranch_6/raster/r.sun2/main.c
Log:
glynn: Call G_parser() before querying GRASS environment, region, etc; use G_find_cell2()  (merge from trunk, r34734, r34581)

Modified: grass/branches/develbranch_6/raster/r.sun2/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.sun2/main.c	2009-01-30 09:24:32 UTC (rev 35674)
+++ grass/branches/develbranch_6/raster/r.sun2/main.c	2009-01-30 09:25:04 UTC (rev 35675)
@@ -70,27 +70,26 @@
 FILE *fw;
 
 
-char *elevin;
-char *aspin;
-char *slopein;
-char *civiltime = NULL;
-char *linkein = NULL;
-char *albedo = NULL;
-char *latin = NULL;
-char *coefbh = NULL;
-char *coefdh = NULL;
-char *incidout = NULL;
-char *longin = NULL;
-char *horizon = NULL;
-char *beam_rad = NULL;
-char *insol_time = NULL;
-char *diff_rad = NULL;
-char *refl_rad = NULL;
-char *glob_rad = NULL;
-char *mapset = NULL;
-char *per;
-char *shade;
-char mapname[1024];
+const char *elevin;
+const char *aspin;
+const char *slopein;
+const char *civiltime = NULL;
+const char *linkein = NULL;
+const char *albedo = NULL;
+const char *latin = NULL;
+const char *coefbh = NULL;
+const char *coefdh = NULL;
+const char *incidout = NULL;
+const char *longin = NULL;
+const char *horizon = NULL;
+const char *beam_rad = NULL;
+const char *insol_time = NULL;
+const char *diff_rad = NULL;
+const char *refl_rad = NULL;
+const char *glob_rad = NULL;
+const char *mapset = NULL;
+const char *per;
+const char *shade;
 
 struct Cell_head cellhd;
 struct pj_info iproj;
@@ -219,8 +218,8 @@
 
 
     G_gisinit(argv[0]);
+
     module = G_define_module();
-
     module->description =
 	_("Computes direct (beam), diffuse and reflected solar irradiation raster "
 	 "maps for given day, latitude, surface and atmospheric conditions. Solar "
@@ -230,21 +229,6 @@
 	 "incidence angle and/or irradiance raster maps. The shadowing effect of "
 	 "the topography is optionally incorporated.");
 
-    if (G_get_set_window(&cellhd) == -1)
-	G_fatal_error("G_get_set_window() failed");
-    gridGeom.stepx = cellhd.ew_res;
-    gridGeom.stepy = cellhd.ns_res;
-    invstepx = 1. / gridGeom.stepx;
-    invstepy = 1. / gridGeom.stepy;
-    n /*n_cols */  = cellhd.cols;
-    m /*n_rows */  = cellhd.rows;
-    xmin = cellhd.west;
-    ymin = cellhd.south;
-    xmax = cellhd.east;
-    ymax = cellhd.north;
-    gridGeom.deltx = fabs(cellhd.east - cellhd.west);
-    gridGeom.delty = fabs(cellhd.north - cellhd.south);
-
     parm.elevin = G_define_option();
     parm.elevin->key = "elevin";
     parm.elevin->type = TYPE_STRING;
@@ -509,6 +493,21 @@
 	exit(EXIT_FAILURE);
 
 
+    G_get_set_window(&cellhd);
+
+    gridGeom.stepx = cellhd.ew_res;
+    gridGeom.stepy = cellhd.ns_res;
+    invstepx = 1. / gridGeom.stepx;
+    invstepy = 1. / gridGeom.stepy;
+    n /*n_cols */  = cellhd.cols;
+    m /*n_rows */  = cellhd.rows;
+    xmin = cellhd.west;
+    ymin = cellhd.south;
+    xmax = cellhd.east;
+    ymax = cellhd.north;
+    gridGeom.deltx = fabs(cellhd.east - cellhd.west);
+    gridGeom.delty = fabs(cellhd.north - cellhd.south);
+
     setUseShadow(flag.shade->answer);
 
     /*
@@ -787,8 +786,10 @@
     }
 
 
-    if ((mapset = G_find_cell(elevin, "")) == NULL)
+    if ((mapset = G_find_cell2(elevin, "")) == NULL)
 	G_fatal_error(_("Raster map <%s> not found"),elevin);
+
+
     fd1 = G_open_cell_old(elevin, mapset);
 
     if (slopein != NULL) {
@@ -800,7 +801,7 @@
 		s[l] = (float *)G_malloc(sizeof(float) * (n));
 	    }
 	}
-	if ((mapset = G_find_cell(slopein, "")) == NULL)
+	if ((mapset = G_find_cell2(slopein, "")) == NULL)
 	       G_fatal_error(_("Raster map <%s> not found"),slopein);
 	fd3 = G_open_cell_old(slopein, mapset);
 
@@ -817,7 +818,7 @@
 	    }
 	}
 
-	if ((mapset = G_find_cell(aspin, "")) == NULL)
+	if ((mapset = G_find_cell2(aspin, "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"),aspin);
 	fd2 = G_open_cell_old(aspin, mapset);
 
@@ -831,7 +832,7 @@
 		li[l] = (float *)G_malloc(sizeof(float) * (n));
 
 	}
-	if ((mapset = G_find_cell(linkein, "")) == NULL)
+	if ((mapset = G_find_cell2(linkein, "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"),linkein);
 	fd4 = G_open_cell_old(linkein, mapset);
     }
@@ -843,7 +844,7 @@
 	    for (l = 0; l < numRows; l++)
 		a[l] = (float *)G_malloc(sizeof(float) * (n));
 	}
-	if ((mapset = G_find_cell(albedo, "")) == NULL)
+	if ((mapset = G_find_cell2(albedo, "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"),albedo);
 	fd5 = G_open_cell_old(albedo, mapset);
     }
@@ -855,7 +856,7 @@
 	    for (l = 0; l < numRows; l++)
 		la[l] = (float *)G_malloc(sizeof(float) * (n));
 	}
-	if ((mapset = G_find_cell(latin, "")) == NULL)
+	if ((mapset = G_find_cell2(latin, "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"),latin);
 	fd6 = G_open_cell_old(latin, mapset);
     }
@@ -866,7 +867,7 @@
 	for (l = 0; l < numRows; l++)
 	    longitArray[l] = (float *)G_malloc(sizeof(float) * (n));
 
-	if ((mapset = G_find_cell(longin, "")) == NULL)
+	if ((mapset = G_find_cell2(longin, "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"),longin);
 	fd7 = G_open_cell_old(longin, mapset);
     }
@@ -878,7 +879,7 @@
 	    for (l = 0; l < numRows; l++)
 		cbhr[l] = (float *)G_malloc(sizeof(float) * (n));
 	}
-	if ((mapset = G_find_cell(coefbh, "")) == NULL)
+	if ((mapset = G_find_cell2(coefbh, "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"),coefbh);
 	fr1 = G_open_cell_old(coefbh, mapset);
     }
@@ -890,7 +891,7 @@
 	    for (l = 0; l < numRows; l++)
 		cdhr[l] = (float *)G_malloc(sizeof(float) * (n));
 	}
-	if ((mapset = G_find_cell(coefdh, "")) == NULL)
+	if ((mapset = G_find_cell2(coefdh, "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"),coefdh);
 	fr2 = G_open_cell_old(coefdh, mapset);
     }
@@ -910,7 +911,7 @@
 	 * 
 	 * horizonbuf[0]=G_allocate_f_raster_buf();
 	 * sprintf(shad_filename, "%s_%02d", horizon, arrayNumInt);
-	 * if((mapset=G_find_cell(shad_filename,""))==NULL)
+	 * if((mapset=G_find_cell2(shad_filename,""))==NULL)
 	 * G_message("Horizon file no. %d not found\n", arrayNumInt);
 	 * 
 	 * fd_shad[0] = G_open_cell_old(shad_filename,mapset);
@@ -923,7 +924,7 @@
 	for (i = 0; i < arrayNumInt; i++) {
 		horizonbuf[i] = G_allocate_f_raster_buf();
 	    sprintf(shad_filename, formatString, horizon, i);
-	    if ((mapset = G_find_cell(shad_filename, "")) == NULL)
+	    if ((mapset = G_find_cell2(shad_filename, "")) == NULL)
 		G_fatal_error(_("Horizon file no. %d <%s> not found"), i, shad_filename);
 	    fd_shad[i] = G_open_cell_old(shad_filename, mapset);
 	}



More information about the grass-commit mailing list