[GRASS-SVN] r44157 - grass/trunk/raster/r.sunmask

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 1 19:30:53 EDT 2010


Author: martinl
Date: 2010-11-01 16:30:53 -0700 (Mon, 01 Nov 2010)
New Revision: 44157

Modified:
   grass/trunk/raster/r.sunmask/g_solposition.c
   grass/trunk/raster/r.sunmask/global.h
   grass/trunk/raster/r.sunmask/main.c
Log:
r.sunmask: messages clean up (use G_debug)
(merge r44156 from devbr6)


Modified: grass/trunk/raster/r.sunmask/g_solposition.c
===================================================================
--- grass/trunk/raster/r.sunmask/g_solposition.c	2010-11-01 23:26:16 UTC (rev 44156)
+++ grass/trunk/raster/r.sunmask/g_solposition.c	2010-11-01 23:30:53 UTC (rev 44157)
@@ -25,21 +25,21 @@
  *----------------------------------------------------------------------------*/
 
 /* uncomment to get debug output */
-/*#define DEBUG */
 
 #include <math.h>
 #include <string.h>
 #include <stdio.h>
 #include <grass/gis.h>
+#include <grass/glocale.h>
 #include <grass/gprojects.h>
 #include "solpos00.h"
 
 struct posdata pd, *pdat;	/* declare solpos data struct and a pointer for it */
 
 
-long G_calc_solar_position(double longitude, double latitude, double timezone,
-			   int year, int month, int day, int hour, int minute,
-			   int second)
+long calc_solar_position(double longitude, double latitude, double timezone,
+			 int year, int month, int day, int hour, int minute,
+			 int second)
 {
 
     /* Note: this code is valid from year 1950 to 2050 (solpos restriction)
@@ -63,8 +63,8 @@
 
     /* we don't like to run G_calc_solar_position in xy locations */
     if (window.proj == 0)
-	G_fatal_error
-	    ("Can't calculate sun position in xy locations. Specify sunposition directly.");
+	G_fatal_error(_("Unable to calculate sun position in un-projected locations. "
+			"Specify sunposition directly."));
 
     pdat = &pd;			/* point to the structure for convenience */
 
@@ -75,58 +75,45 @@
     S_init(pdat);
 
     /* check if given point is in current window */
-#ifdef DEBUG
-    fprintf(stderr, "window.north: %f, window.south: %f\n", window.north,
+    G_debug(1, "window.north: %f, window.south: %f\n", window.north,
 	    window.south);
-    fprintf(stderr, "window.west:  %f, window.east : %f\n", window.west,
+    G_debug(1, "window.west:  %f, window.east : %f\n", window.west,
 	    window.east);
-#endif
+    
     inside = 0;
     if (latitude >= window.south && latitude <= window.north &&
 	longitude >= window.west && longitude <= window.east)
 	inside = 1;
     if (!inside)
-	G_warning
-	    ("Specified point %f, %f outside of current region, is that intended? Anyway, it will be used.\n",
-	     longitude, latitude);
+	G_warning(_("Specified point %f, %f outside of current region, "
+		    "is that intended? Anyway, it will be used."),
+		  longitude, latitude);
 
     /* if coordinates are not in lat/long format, transform them: */
     if ((G_projection() != PROJECTION_LL) && window.proj != 0) {
-#ifdef DEBUG
-	fprintf(stderr,
-		"Transforming input coordinates to lat/long (req. for solar position)\n");
-#endif
-
+	G_debug(1, "Transforming input coordinates to lat/long (req. for solar position)");
+	
 	/* read current projection info */
 	if ((in_proj_info = G_get_projinfo()) == NULL)
-	    G_fatal_error("Can't get projection info of current location");
+	    G_fatal_error(_("Unable to get projection info of current location"));
 
 	if ((in_unit_info = G_get_projunits()) == NULL)
-	    G_fatal_error("Can't get projection units of current location");
+	    G_fatal_error(_("Unable to get projection units of current location"));
 
 	if (pj_get_kv(&iproj, in_proj_info, in_unit_info) < 0)
-	    G_fatal_error
-		("Can't get projection key values of current location");
-
+	    G_fatal_error(_("Unable to get projection key values of current location"));
+	
 	G_free_key_value(in_proj_info);
 	G_free_key_value(in_unit_info);
 
-#ifdef DEBUG
 	/* Try using pj_print_proj_params() instead of all this */
-	fprintf(stderr, "Projection found in location:\n");
-	fprintf(stderr, "IN: meter: %f zone: %i proj: %s (iproj struct)\n",
+	G_debug(1, "Projection found in location:");
+	G_debug(1, "IN: meter: %f zone: %i proj: %s (iproj struct)",
 		iproj.meters, iproj.zone, iproj.proj);
-	fprintf(stderr, "IN: ellps: a: %f  es: %f\n", iproj.pj->a,
-		iproj.pj->es);
-	fprintf(stderr, "IN: x0: %f y0: %f\n", iproj.pj->x0, iproj.pj->y0);
-	fprintf(stderr, "IN: lam0: %f phi0: %f\n", iproj.pj->lam0,
-		iproj.pj->phi0);
-	fprintf(stderr, "IN: k0: %f\n", iproj.pj->k0);
-	fprintf(stderr, "IN coord: longitude: %f, latitude: %f\n", longitude,
+	G_debug(1, "IN coord: longitude: %f, latitude: %f", longitude,
 		latitude);
 	/* see src/include/projects.h, struct PJconsts */
-#endif
-
+	
 	/* set output projection to lat/long for solpos */
 	oproj.zone = 0;
 	oproj.meters = 1.;
@@ -137,18 +124,13 @@
 	/* XX do the transform 
 	 *               outx        outy    in_info  out_info */
 	if (pj_do_proj(&longitude, &latitude, &iproj, &oproj) < 0) {
-	    fprintf(stderr,
-		    "Error in pj_do_proj (projection of input coordinate pair)\n");
-	    exit(0);
+	    G_fatal_error(_("Error in pj_do_proj (projection of input coordinate pair)"));
 	}
 
-#ifdef DEBUG
-	fprintf(stderr, "Transformation to lat/long:\n");
-	fprintf(stderr, "OUT: longitude: %f, latitude: %f\n", longitude,
+	G_debug(1, "Transformation to lat/long:");
+	G_debug(1, "OUT: longitude: %f, latitude: %f", longitude,
 		latitude);
-#endif
 
-
     }				/* transform if not LL */
 
     pdat->longitude = longitude;	/* Note that latitude and longitude are  */

Modified: grass/trunk/raster/r.sunmask/global.h
===================================================================
--- grass/trunk/raster/r.sunmask/global.h	2010-11-01 23:26:16 UTC (rev 44156)
+++ grass/trunk/raster/r.sunmask/global.h	2010-11-01 23:30:53 UTC (rev 44157)
@@ -2,5 +2,5 @@
 extern int sunset;
 
 /* proto */
-long G_calc_solar_position(double, double, double, int, int, int, int, int,
-			   int);
+long calc_solar_position(double, double, double, int, int, int, int, int,
+			 int);

Modified: grass/trunk/raster/r.sunmask/main.c
===================================================================
--- grass/trunk/raster/r.sunmask/main.c	2010-11-01 23:26:16 UTC (rev 44156)
+++ grass/trunk/raster/r.sunmask/main.c	2010-11-01 23:30:53 UTC (rev 44157)
@@ -39,16 +39,17 @@
  *                    but it's somewhat slow with non-CELL maps
  *********************************************************************/
 
-#include "global.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
-#include "solpos00.h"
 #include <grass/glocale.h>
 
+#include "global.h"
+#include "solpos00.h"
+
 float asol, phi0, sun_zenith, sun_azimuth;	/* from nadir, from north */
 int sunset;
 
@@ -60,12 +61,6 @@
 					   allocated dynamically with G_malloc) */
 struct Cell_head window;
 
-
-/*
-   #define      RASTER_VALUE_FUNC
- */
-
-
 union RASTER_PTR
 {
     void *v;
@@ -74,15 +69,10 @@
     DCELL *d;
 };
 
-
 #ifdef	RASTER_VALUE_FUNC
-
 double raster_value(union RASTER_PTR buf, int data_type, int col);
-
 #else
-
 #define	raster_value(buf, data_type, col)	((double)(data_type == CELL_TYPE ? buf.c[col] : (data_type == FCELL_TYPE ? buf.f[col] : buf.d[col])))
-
 #endif
 
 int main(int argc, char *argv[])
@@ -102,7 +92,7 @@
 	struct Option *opt1, *opt2, *opt3, *opt4, *north, *east, *year,
 	    *month, *day, *hour, *minutes, *seconds, *timezone;
     } parm;
-    struct Flag *flag1, *flag2, *flag3, *flag4;
+    struct Flag *flag1, *flag3, *flag4;
     struct GModule *module;
     char *name, *outname;
     double dazi, dalti;
@@ -251,16 +241,16 @@
     if (!parm.north->answer || !parm.east->answer) {
 	north = (window.north - window.south) / 2. + window.south;
 	east = (window.west - window.east) / 2. + window.east;
-	G_message(_("Using map center coordinates: %f %f"), east, north);
+	G_verbose_message(_("Using map center coordinates: %f %f"), east, north);
     }
     else {			/* user defined east, north: */
 
 	sscanf(parm.north->answer, "%lf", &north);
 	sscanf(parm.east->answer, "%lf", &east);
 	if (strlen(parm.east->answer) == 0)
-	    G_fatal_error(_("Empty east coordinate specified!"));
+	    G_fatal_error(_("Empty east coordinate specified"));
 	if (strlen(parm.north->answer) == 0)
-	    G_fatal_error(_("Empty north coordinate specified!"));
+	    G_fatal_error(_("Empty north coordinate specified"));
     }
 
     /* check which method to use for sun position:
@@ -279,19 +269,19 @@
 	locparms = 0;
 
     if (solparms && locparms)	/* both defined */
-	G_fatal_error(_("Either define sun position or location/date/time parameters."));
+	G_fatal_error(_("Either define sun position or location/date/time parameters"));
 
     if (!solparms && !locparms)	/* nothing defined */
-	G_fatal_error(_("Neither sun position nor east/north, date/time/timezone definition are complete."));
+	G_fatal_error(_("Neither sun position nor east/north, date/time/timezone definition are complete"));
 
     /* if here, one definition was complete */
     if (locparms) {
-	G_message(_("Calculating sun position... (using solpos (V. %s) from NREL)\n"),
+	G_message(_("Calculating sun position... (using solpos (V. %s) from NREL)"),
 		  SOLPOSVERSION);
 	use_solpos = 1;
     }
     else {
-	G_message(_("Using user defined sun azimuth, altitude settings (ignoring eventual other values)\n"));
+	G_message(_("Using user defined sun azimuth, altitude settings (ignoring eventual other values)"));
 	use_solpos = 0;
     }
 
@@ -327,8 +317,8 @@
     if (use_solpos) {
 	G_debug(3, "\nlat:%f  long:%f", north, east);
 	retval =
-	    G_calc_solar_position(east, north, timezone, year, month, day,
-				  hour, minutes, seconds);
+	    calc_solar_position(east, north, timezone, year, month, day,
+				hour, minutes, seconds);
 
 	/* Remove +0.5 above if you want round-down instead of round-to-nearest */
 	sretr = (int)floor(pdat->sretr);	/* sunrise */
@@ -346,7 +336,7 @@
 
 	/* print the results */
 	if (retval == 0) {	/* error check */
-	    if (flag2->answer || (flag3->answer && !flag2->answer)) {
+	    if (flag3->answer) {
 		if (flag4->answer) {
 		    fprintf(stdout, "date=%d.%02d.%02d\n", pdat->year,
 			    pdat->month, pdat->day);
@@ -372,23 +362,23 @@
 		    }
 		}
 		else {
-		    G_message(_(" %d.%02d.%02d, daynum %d, time: %02i:%02i:%02i (decimal time: %f)\n"),
+		    G_message(_("%d.%02d.%02d, daynum %d, time: %02i:%02i:%02i (decimal time: %f)"),
 			      pdat->year, pdat->month, pdat->day,
 			      pdat->daynum, pdat->hour, pdat->minute,
 			      pdat->second,
 			      pdat->hour + (pdat->minute * 100.0 / 60.0 +
 					    pdat->second * 100.0 / 3600.0) /
 			      100.);
-		    G_message(_(" long: %f, lat: %f, timezone: %f\n"),
+		    G_message(_("long: %f, lat: %f, timezone: %f"),
 			      pdat->longitude, pdat->latitude,
 			      pdat->timezone);
-		    G_message(_(" Solar position: sun azimuth: %f,\n   sun angle above horz.(refraction corrected): %f\n"),
+		    G_message(_("Solar position: sun azimuth: %f, sun angle above horz.(refraction corrected): %f"),
 			      pdat->azim, pdat->elevref);
 
 		    if (sretr / 60 <= 24.0) {
-			G_message(_(" Sunrise time (without refraction): %02d:%02d:%02d\n"),
+			G_message(_("Sunrise time (without refraction): %02d:%02d:%02d\n"),
 				  sretr / 60, sretr % 60, sretr_sec);
-			G_message(_(" Sunset time  (without refraction): %02d:%02d:%02d\n"),
+			G_message(_("Sunset time  (without refraction): %02d:%02d:%02d\n"),
 				  ssetr / 60, ssetr % 60, ssetr_sec);
 		    }
 		}
@@ -413,34 +403,34 @@
 	G_debug(3, "current_time:%f sunrise:%f", current_time, sunrise);
 	if ((current_time < sunrise)) {
 	    if (sretr / 60 <= 24.0)
-		G_message(_("Time (%02i:%02i:%02i) is before sunrise (%02d:%02d:%02d)!\n"),
+		G_message(_("Time (%02i:%02i:%02i) is before sunrise (%02d:%02d:%02d)"),
 			  pdat->hour, pdat->minute, pdat->second, sretr / 60,
 			  sretr % 60, sretr_sec);
 	    else
-		G_message(_("Time (%02i:%02i:%02i) is before sunrise!\n"),
+		G_message(_("Time (%02i:%02i:%02i) is before sunrise"),
 			  pdat->hour, pdat->minute, pdat->second);
 
 	    G_warning(_("Nothing to calculate. Please verify settings."));
 	}
 	if ((current_time > sunset)) {
 	    if (sretr / 60 <= 24.0)
-		G_message(_("Time (%02i:%02i:%02i) is after sunset (%02d:%02d:%02d)!\n"),
+		G_message(_("Time (%02i:%02i:%02i) is after sunset (%02d:%02d:%02d)"),
 			  pdat->hour, pdat->minute, pdat->second, ssetr / 60,
 			  ssetr % 60, ssetr_sec);
 	    else
-		G_message(_("Time (%02i:%02i:%02i) is after sunset!\n"),
+		G_message(_("Time (%02i:%02i:%02i) is after sunset"),
 			  pdat->hour, pdat->minute, pdat->second);
 	    G_warning(_("Nothing to calculate. Please verify settings."));
 	}
     }
 
     if (flag3->answer && (use_solpos == 1)) {	/* we only want the sun position */
-	G_message(_("No map calculation requested. Finished.\n"));
+	G_message(_("No map calculation requested. Finished."));
 	exit(EXIT_SUCCESS);
     }
     else if (flag3->answer && (use_solpos == 0)) {
 	/* are you joking ? */
-	G_message(_("You already know the sun position.\n"));
+	G_message(_("You already know the sun position"));
 	exit(EXIT_SUCCESS);
     }
 
@@ -454,7 +444,7 @@
 
     if (data_type == CELL_TYPE) {
 	if ((Rast_read_range(name, "", &range)) < 0)
-	    G_fatal_error(_("Can't open range file for %s"), name);
+	    G_fatal_error(_("Unable to open range file for raster map <%s>"), name);
 	Rast_get_range_min_max(&range, &min, &max);
 	dmin = (double)min;
 	dmax = (double)max;
@@ -477,7 +467,7 @@
 	col1 = 0;
 	drow = -1;
 	Rast_get_row(elev_fd, elevbuf.v, row1, data_type);
-
+	
 	while (col1 < window.cols) {
 	    dvalue = raster_value(elevbuf, data_type, col1);
 	    /*              outbuf.c[col1]=1; */
@@ -535,7 +525,6 @@
     Rast_set_history(&hist, HIST_DATSRC_2, G_recreate_command());
     Rast_write_history(outname, &hist);
 
-    G_done_msg(" ");
     exit(EXIT_SUCCESS);
 }
 



More information about the grass-commit mailing list