[GRASS-SVN] r33933 - grass-addons/gipe/i.sunhours

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 20 07:16:04 EDT 2008


Author: ychemin
Date: 2008-10-20 07:16:03 -0400 (Mon, 20 Oct 2008)
New Revision: 33933

Added:
   grass-addons/gipe/i.sunhours/i.sunhours.html
Removed:
   grass-addons/gipe/i.sunhours/description.html
Modified:
   grass-addons/gipe/i.sunhours/main.c
Log:
bug fix + prepare for main SVN

Deleted: grass-addons/gipe/i.sunhours/description.html
===================================================================
--- grass-addons/gipe/i.sunhours/description.html	2008-10-20 10:25:23 UTC (rev 33932)
+++ grass-addons/gipe/i.sunhours/description.html	2008-10-20 11:16:03 UTC (rev 33933)
@@ -1,24 +0,0 @@
-<H2>DESCRIPTION</H2>
-
-<EM>i.sunhours</EM> creates a sunshine hours map from any map, it considers a perfect clear day. This method follows Iqbal (1983) as found in the AHAS manual (Parodi, 2000).
-<H2>NOTES</H2>
-Iqbal, M., 1983. An Introduction to Solar Radiation. Iqbal, M., Editorial: Academic Press. Toronto, Canada.
-Parodi, G., 2000. AVHRR Hydrological Analysis System. Algorithms and Theory, Version 1.0. WRES - ITC, The Netherlands.
-<H2>TODO</H2>
-
-
-<H2>SEE ALSO</H2>
-
-<em>
-<A HREF="i.evapo.TSA.html">i.evapo.TSA</A><br>
-<A HREF="i.latitude.html">i.latitude</A><br>
-</em>
-
-
-<H2>AUTHORS</H2>
-
-Yann Chemin, GRASS Development Team<BR>
-
-
-<p>
-<i>Last changed: $Date: 2007/02/19 10:19:59 $</i>

Copied: grass-addons/gipe/i.sunhours/i.sunhours.html (from rev 33842, grass-addons/gipe/i.sunhours/description.html)
===================================================================
--- grass-addons/gipe/i.sunhours/i.sunhours.html	                        (rev 0)
+++ grass-addons/gipe/i.sunhours/i.sunhours.html	2008-10-20 11:16:03 UTC (rev 33933)
@@ -0,0 +1,24 @@
+<H2>DESCRIPTION</H2>
+
+<EM>i.sunhours</EM> creates a sunshine hours map from any map, it considers a perfect clear day. This method follows Iqbal (1983) as found in the AHAS manual (Parodi, 2000).
+<H2>NOTES</H2>
+Iqbal, M., 1983. An Introduction to Solar Radiation. Iqbal, M., Editorial: Academic Press. Toronto, Canada.
+Parodi, G., 2000. AVHRR Hydrological Analysis System. Algorithms and Theory, Version 1.0. WRES - ITC, The Netherlands.
+<H2>TODO</H2>
+
+
+<H2>SEE ALSO</H2>
+
+<em>
+<A HREF="i.evapo.TSA.html">i.evapo.TSA</A><br>
+<A HREF="i.latitude.html">i.latitude</A><br>
+</em>
+
+
+<H2>AUTHORS</H2>
+
+Yann Chemin, GRASS Development Team<BR>
+
+
+<p>
+<i>Last changed: $Date: 2007/02/19 10:19:59 $</i>


Property changes on: grass-addons/gipe/i.sunhours/i.sunhours.html
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: grass-addons/gipe/i.sunhours/main.c
===================================================================
--- grass-addons/gipe/i.sunhours/main.c	2008-10-20 10:25:23 UTC (rev 33932)
+++ grass-addons/gipe/i.sunhours/main.c	2008-10-20 11:16:03 UTC (rev 33933)
@@ -1,4 +1,3 @@
-
 /****************************************************************************
  *
  * MODULE:       i.sunhours
@@ -7,14 +6,13 @@
  * 		 under a perfect clear sky condition.
  * 		 Called generally "N" in meteorology. 
  *
- * COPYRIGHT:    (C) 2002-2007 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2002-2008 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
  *   	    	 License (>=v2). Read the file COPYING that comes with GRASS
  *   	    	 for details.
  *
  *****************************************************************************/
-     
     
 #include <stdio.h>
 #include <stdlib.h>
@@ -24,111 +22,70 @@
 #include <grass/glocale.h>
     
 #define PI 3.1415927
+
 int main(int argc, char *argv[]) 
 {
-    struct Cell_head cellhd;	/*region+header info */
-
-    char *mapset;		/*mapset name */
-
     int nrows, ncols;
-
     int row, col;
-
     struct GModule *module;
-
     struct Option *input1, *input2, *output1;
-
-    struct Flag *flag1;
-
     struct History history;	/*metadata */
 
-    
-
-	/************************************/ 
-	/* FMEO Declarations**************** */ 
+    /************************************/ 
     char *name;			/*input raster name */
-
     char *result1;		/*output raster name */
-
-    
-	/*File Descriptors */ 
-    int infd_lat, infd_doy;
-
+    int infd_lat, infd_doy;    /*File Descriptors */ 
     int outfd1;
-
     char *lat, *doy;
-
-    int i = 0, j = 0;
-
     void *inrast_lat, *inrast_doy;
-
     DCELL * outrast1;
-    RASTER_MAP_TYPE data_type_output = DCELL_TYPE;
-    RASTER_MAP_TYPE data_type_lat;
-    RASTER_MAP_TYPE data_type_doy;
-    
 
-	/************************************/ 
-	G_gisinit(argv[0]);
+    /************************************/ 
+    G_gisinit(argv[0]);
     module = G_define_module();
     module->keywords = _("sunshine, hours, daytime");
     module->description = _("creates a sunshine hours map");
     
-	/* Define the different options */ 
-	input1 = G_define_standard_option(G_OPT_R_INPUT);
+    /* Define the different options */ 
+    input1 = G_define_standard_option(G_OPT_R_INPUT);
     input1->key = _("doy");
-    input1->description = _("Name of the latitude input map");
+    input1->description = _("Name of the doy input map");
+
     input2 = G_define_standard_option(G_OPT_R_INPUT);
     input2->key = _("lat");
     input2->description = _("Name of the latitude input map");
+
     output1 = G_define_standard_option(G_OPT_R_OUTPUT);
-    output1->description = _("Name of the output sunshine hours layer");
-    
+    output1->description = _("Name of the output sunshine hours map");
 
-	/********************/ 
-	if (G_parser(argc, argv))
+    /********************/ 
+    if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
-    lat = input1->answer;
-    doy = input2->answer;
+
+    doy = input1->answer;
+    lat = input2->answer;
     result1 = output1->answer;
-    
 
-	/***************************************************/ 
-	mapset = G_find_cell2(doy, "");
-    if (mapset == NULL) {
-	G_fatal_error(_("cell file [%s] not found"), doy);
-    }
-    data_type_doy = G_raster_map_type(doy, mapset);
-    if ((infd_doy = G_open_cell_old(doy, mapset)) < 0)
+    /***************************************************/ 
+    if ((infd_doy = G_open_cell_old(doy, "")) < 0)
 	G_fatal_error(_("Cannot open cell file [%s]"), doy);
-    if (G_get_cellhd(doy, mapset, &cellhd) < 0)
-	G_fatal_error(_("Cannot read file header of [%s])"), doy);
-    inrast_doy = G_allocate_raster_buf(data_type_doy);
-    
+    inrast_doy = G_allocate_d_raster_buf();
 
-	/***************************************************/ 
-	mapset = G_find_cell2(lat, "");
-    if (mapset == NULL) {
-	G_fatal_error(_("cell file [%s] not found"), lat);
-    }
-    data_type_lat = G_raster_map_type(lat, mapset);
-    if ((infd_lat = G_open_cell_old(lat, mapset)) < 0)
+    /***************************************************/ 
+    if ((infd_lat = G_open_cell_old(lat, "")) < 0)
 	G_fatal_error(_("Cannot open cell file [%s]"), lat);
-    if (G_get_cellhd(lat, mapset, &cellhd) < 0)
-	G_fatal_error(_("Cannot read file header of [%s])"), lat);
     inrast_lat = G_allocate_raster_buf(data_type_lat);
-    
 
-	/***************************************************/ 
-	G_debug(3, "number of rows %d", cellhd.rows);
-    G_debug(3, "number of rows %d", cellhd.rows);
+    /***************************************************/ 
     nrows = G_window_rows();
     ncols = G_window_cols();
-    outrast1 = G_allocate_raster_buf(data_type_output);
-    if ((outfd1 = G_open_raster_new(result1, data_type_output)) < 0)
+
+    outrast1 = G_allocate_d_raster_buf();
+    if ((outfd1 = G_open_raster_new(result1, DCELL_TYPE)) < 0)
 	G_fatal_error(_("Could not open <%s>"), result1);
+
     for (row = 0; row < nrows; row++)
-	 {
+    {
 	DCELL d;
 	DCELL d_da;
 	DCELL d_delta;
@@ -137,55 +94,40 @@
 	DCELL d_lat;
 	DCELL d_doy;
 	G_percent(row, nrows, 2);
-	if (G_get_raster_row(infd_doy, inrast_doy, row, data_type_doy) < 0)
+
+	if (G_get_raster_row(infd_doy, inrast_doy, row, DCELL_TYPE) < 0)
 	    G_fatal_error(_("Could not read from <%s>"), doy);
-	if (G_get_raster_row(infd_lat, inrast_lat, row, data_type_lat) < 0)
+	if (G_get_raster_row(infd_lat, inrast_lat, row, DCELL_TYPE) < 0)
 	    G_fatal_error(_("Could not read from <%s>"), lat);
+
 	for (col = 0; col < ncols; col++)
-	     {
-	    switch (data_type_doy) {
-	    case CELL_TYPE:
-		d_doy = (double)((CELL *) inrast_doy)[col];
-		break;
-	    case FCELL_TYPE:
-		d_doy = (double)((FCELL *) inrast_doy)[col];
-		break;
-	    case DCELL_TYPE:
-		d_doy = ((DCELL *) inrast_doy)[col];
-		break;
-	    }
-	    switch (data_type_lat) {
-	    case CELL_TYPE:
-		d_lat = (double)((CELL *) inrast_lat)[col];
-		break;
-	    case FCELL_TYPE:
-		d_lat = (double)((FCELL *) inrast_lat)[col];
-		break;
-	    case DCELL_TYPE:
-		d_lat = ((DCELL *) inrast_lat)[col];
-		break;
-	    }
+        {
+            d_doy = ((DCELL *) inrast_doy)[col];
+            d_lat = ((DCELL *) inrast_lat)[col];
+
 	    d_da = 2 * PI * (d_doy - 1) / 365.0;
-	    d_delta =
+	    d_delta = 
 		0.006918 - 0.399912 * cos(d_da) + 0.070257 * sin(d_da) -
 		0.006758 * cos(2 * d_da) + 0.000907 * sin(2 * d_da) -
 		0.002697 * cos(3 * d_da) + 0.00148 * sin(3 * d_da);
 	    d_Ws = acos(-tan(d_lat * PI / 180) * tan(d_delta));
 	    d_N = (360.0 / (15.0 * PI)) * d_Ws;
 	    ((DCELL *) outrast1)[col] = d_N;
-	    }
-	if (G_put_raster_row(outfd1, outrast1, data_type_output) < 0)
+        }
+	if (G_put_raster_row(outfd1, outrast1, DCELL_TYPE) < 0)
 	    G_fatal_error(_("Cannot write to output raster file"));
-	}
+    }
     G_free(inrast_lat);
     G_free(inrast_doy);
     G_close_cell(infd_lat);
     G_close_cell(infd_doy);
     G_free(outrast1);
     G_close_cell(outfd1);
+
     G_short_history(result1, "raster", &history);
     G_command_history(&history);
     G_write_history(result1, &history);
+
     exit(EXIT_SUCCESS);
 }
 



More information about the grass-commit mailing list