[GRASS-SVN] r38675 - grass/branches/develbranch_6/raster/r.sun2
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 11 03:02:20 EDT 2009
Author: hamish
Date: 2009-08-11 03:02:20 -0400 (Tue, 11 Aug 2009)
New Revision: 38675
Modified:
grass/branches/develbranch_6/raster/r.sun2/main.c
Log:
sanitize some inputs; minor clean/comments
Modified: grass/branches/develbranch_6/raster/r.sun2/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.sun2/main.c 2009-08-11 03:15:39 UTC (rev 38674)
+++ grass/branches/develbranch_6/raster/r.sun2/main.c 2009-08-11 07:02:20 UTC (rev 38675)
@@ -40,6 +40,7 @@
#include "local_proto.h"
#include "rsunglobals.h"
+/* default values */
#define NUM_PARTITIONS "1"
#define SKIP "1"
#define BIG 1.e20
@@ -164,7 +165,7 @@
*/
double horizonStep;
double ltime, tim, timo;
-double declination; /* Contains the negative of the declination at the chosen day */
+double declination; /* Contains the negative of the declination at the chosen day */
/*
* double lum_C31_l, lum_C33_l;
@@ -173,12 +174,14 @@
double cbh, cdh;
double TOLER;
-
+/* 1852m/nm * 60nm/degree = 111120 m/deg */
#define DEGREEINMETERS 111120.
-int ll_correction = 0;
+int ll_correction = FALSE;
double coslatsq;
+/* why not use G_distance() here which switches to geodesic/great
+ circle distace as needed? */
double distance(double x1, double x2, double y1, double y2)
{
if (ll_correction) {
@@ -434,12 +437,12 @@
_("Output global (total) irradiance/irradiation [W.m-2] (mode 1) or irradiance/irradiation raster map [Wh.m-2.day-1] (mode 2)");
parm.glob_rad->guisection = _("Output_options");
-
parm.day = G_define_option();
parm.day->key = "day";
parm.day->type = TYPE_INTEGER;
parm.day->required = YES;
parm.day->description = _("No. of day of the year (1-365)");
+ parm.day->options = "1-365";
parm.step = G_define_option();
parm.step->key = "step";
@@ -543,7 +546,6 @@
saveMemory = flag.saveMemory->answer;
civiltime = parm.civilTime->answer;
-
elevin = parm.elevin->answer;
aspin = parm.aspin->answer;
slopein = parm.slopein->answer;
@@ -553,30 +555,30 @@
if (civiltime != NULL) {
- setUseCivilTime(1);
+ setUseCivilTime(TRUE);
longin = parm.longin->answer;
if (longin == NULL) {
G_fatal_error(_("You must give the longitude raster if you use civil time"));
}
- sscanf(parm.civilTime->answer, "%lf", &civilTime);
+ if (sscanf(parm.civilTime->answer, "%lf", &civilTime) != 1)
+ G_fatal_error(_("Error reading civil time zone value"));
+ if (civilTime < -24. || civilTime > 24.)
+ G_fatal_error(_("Invalid civil time zone value"));
+
/* Normalize if somebody should be weird enough to give more than +- 12
* hours offset. */
-
- civilTime -= 24 * ((int)(civilTime / 24.));
- if (civilTime < -12.) {
+ if (civilTime < -12.)
civilTime += 24.;
- }
- else if (civilTime > 12.) {
+ else if (civilTime > 12.)
civilTime -= 24;
- }
-
}
else {
- setUseCivilTime(0);
+ setUseCivilTime(FALSE);
}
+
coefbh = parm.coefbh->answer;
coefdh = parm.coefdh->answer;
incidout = parm.incidout->answer;
@@ -592,12 +594,12 @@
G_fatal_error(_("insol_time and incidout are incompatible options"));
sscanf(parm.day->answer, "%d", &day);
- sscanf(parm.step->answer, "%lf", &step);
- if (parm.step->answer != NULL) {
- if (sscanf(parm.step->answer, "%lf", &step) != 1)
- G_fatal_error(_("Error reading time step size"));
- }
+ if (sscanf(parm.step->answer, "%lf", &step) != 1)
+ G_fatal_error(_("Error reading time step size"));
+ if (step <= 0.0 || step > 24.0)
+ G_fatal_error(_("Invalid time step size"));
+
if (parm.horizonstep->answer != NULL) {
if (sscanf(parm.horizonstep->answer, "%lf", &horizonStep) != 1)
G_fatal_error(_("Error reading horizon step size"));
@@ -758,13 +760,12 @@
/**********end of parser - ******************************/
- if ((G_projection() == PROJECTION_LL)) {
- ll_correction = 1;
- }
+ if ((G_projection() == PROJECTION_LL))
+ ll_correction = TRUE;
- G_debug(3, "calculate starts...");
+ G_debug(3, "calculate() starts...");
calculate(singleSlope, singleAspect, singleAlbedo, singleLinke, gridGeom);
- G_debug(3, "OUTGR starts...");
+ G_debug(3, "OUTGR() starts...");
OUTGR();
exit(EXIT_SUCCESS);
@@ -2075,6 +2076,9 @@
{
double d1, decl;
+ /* stretch day number in the following calculation for siderial effect? */
+ /* ? double siderial_day = no_of_day + ((no_of_day * 0.25) / 365.) ? */
+ /* or just change d1 to : d1 = pi2 * no_of_day / 365.0; ? */
d1 = pi2 * no_of_day / 365.25;
decl = asin(0.3978 * sin(d1 - 1.4 + 0.0355 * sin(d1 - 0.0489)));
decl = -decl;
More information about the grass-commit
mailing list