[GRASS-SVN] r32973 - in grass-addons/gipe: i.sattime i.sunhours

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 21 10:03:19 EDT 2008


Author: ychemin
Date: 2008-08-21 10:03:19 -0400 (Thu, 21 Aug 2008)
New Revision: 32973

Modified:
   grass-addons/gipe/i.sattime/main.c
   grass-addons/gipe/i.sunhours/main.c
Log:
code cleaning, upgrade, standardization

Modified: grass-addons/gipe/i.sattime/main.c
===================================================================
--- grass-addons/gipe/i.sattime/main.c	2008-08-21 13:50:39 UTC (rev 32972)
+++ grass-addons/gipe/i.sattime/main.c	2008-08-21 14:03:19 UTC (rev 32973)
@@ -5,7 +5,7 @@
  * PURPOSE:      Calculates the time of satellite overpass
  * 		 using sun elevation angle, latitude and DOY.
  *
- * COPYRIGHT:    (C) 2007 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2007-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
@@ -24,23 +24,22 @@
 
 int main(int argc, char *argv[])
 {
-	struct Cell_head cellhd; //region+header info
-	char *mapset; // mapset name
+	struct Cell_head cellhd; /*region+header info*/
+	char *mapset; /*mapset name*/
 	int nrows, ncols;
 	int row,col;
 
-	int verbose=1;
 	struct GModule *module;
 	struct Option *input1, *input2, *input3, *input4, *output1;
 	
 	struct Flag *flag1;	
-	struct History history; //metadata
+	struct History history; /*metadata*/
 	
 	/************************************/
 	/* FMEO Declarations*****************/
-	char *name;   // input raster name
-	char *result1; //output raster name
-	//File Descriptors
+	char *name;   /*input raster name*/
+	char *result1; /*output raster name*/
+	/*File Descriptors*/
 	int infd_lat, infd_lon, infd_doy, infd_phi;
 	int outfd1;
 	
@@ -48,7 +47,7 @@
 	int i=0,j=0;
 
 	void *inrast_lat, *inrast_lon, *inrast_doy, *inrast_phi;
-	unsigned char *outrast1;
+	DCELL *outrast1;
 	RASTER_MAP_TYPE data_type_output=DCELL_TYPE;
 	RASTER_MAP_TYPE data_type_lat;
 	RASTER_MAP_TYPE data_type_lon;
@@ -62,51 +61,25 @@
 	module->description = _("creates a satellite overpass time map");
 
 	/* Define the different options */
-	input1 = G_define_option() ;
+	input1 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input1->key	   = _("doy");
-	input1->type       = TYPE_STRING;
-	input1->required   = YES;
-	input1->gisprompt  =_("old,cell,raster") ;
 	input1->description=_("Name of the DOY input map");
-	input1->answer     =_("doy");
 
-	input2 = G_define_option() ;
+	input2 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input2->key	   = _("lat");
-	input2->type       = TYPE_STRING;
-	input2->required   = YES;
-	input2->gisprompt  =_("old,cell,raster") ;
 	input2->description=_("Name of the latitude input map");
-	input2->answer     =_("latitude");
 
-	input3 = G_define_option() ;
+	input3 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input3->key	   = _("long");
-	input3->type       = TYPE_STRING;
-	input3->required   = YES;
-	input3->gisprompt  =_("old,cell,raster") ;
 	input3->description=_("Name of the longitude input map");
-	input3->answer     =_("longitude");
 
-	input4 = G_define_option() ;
+	input4 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input4->key	   = _("sun_elev");
-	input4->type       = TYPE_STRING;
-	input4->required   = YES;
-	input4->gisprompt  =_("old,cell,raster") ;
 	input4->description=_("Name of the sun elevation angle input map");
-	input4->answer     =_("phi");
 
-	output1 = G_define_option() ;
-	output1->key        =_("sath");
-	output1->type       = TYPE_STRING;
-	output1->required   = YES;
-	output1->gisprompt  =_("new,cell,raster");
+	output1 = G_define_standard_option(G_OPT_R_OUTPUT) ;
 	output1->description=_("Name of the output satellite overpass time layer");
-	output1->answer     =_("sath");
 
-	
-	flag1 = G_define_flag();
-	flag1->key = 'q';
-	flag1->description = _("Quiet");
-
 	/********************/
 	if (G_parser(argc, argv))
 		exit (EXIT_FAILURE);
@@ -117,7 +90,6 @@
 	phi	 	= input4->answer;
 		
 	result1  	= output1->answer;
-	verbose 	= (!flag1->answer);
 	/***************************************************/
 	mapset = G_find_cell2(doy, "");
 	if (mapset == NULL) {
@@ -164,7 +136,6 @@
 	inrast_phi = G_allocate_raster_buf(data_type_phi);
 	/***************************************************/
 	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();
@@ -186,8 +157,7 @@
 		DCELL d_lon;
 		DCELL d_doy;
 		DCELL d_phi;
-		if(verbose)
-			G_percent(row,nrows,2);
+		G_percent(row,nrows,2);
 		if(G_get_raster_row(infd_doy,inrast_doy,row,data_type_doy)<0)
 			G_fatal_error(_("Could not read from <%s>"),doy);
 		if(G_get_raster_row(infd_lat,inrast_lat,row,data_type_lat)<0)
@@ -242,9 +212,6 @@
 					d_phi	= ((DCELL *) inrast_phi)[col];
 					break;
 			}
-			//d_da = 2 * PI * ( d_doy - 1 ) / 365.0;
-			//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_delta = 0.4093*sin((2.0*PI/365.0)*d_doy-1.39);
 			d_frac_year = (360.0/365.25) * d_doy;
 			d_delta = 0.396372-22.91327*cos(d_frac_year*PI/180.0)+4.02543*sin(d_frac_year*PI/180.0)-0.387205*cos(2*d_frac_year*PI/180.0)+0.051967*sin(2*d_frac_year*PI/180.0)-0.154527*cos(3*d_frac_year*PI/180.0)+0.084798*sin(3*d_frac_year*PI/180.0);
 			d_tc_wa = 0.004297+0.107029*cos(d_frac_year*PI/180.0)-1.837877*sin(d_frac_year*PI/180.0)-0.837378*cos(2*d_frac_year*PI/180.0)-2.340475*sin(2*d_frac_year*PI/180.0);
@@ -252,8 +219,7 @@
 			d_Wa2=cos(d_delta*PI/180.0)*cos(d_lat*PI/180.0);
 			d_Wa=acos(d_Wa1/d_Wa2);
 			d_time = ((d_Wa-(d_lon*PI/180.0)-d_tc_wa)/15.0)+12.0;
-			//d_time = 12.0*(d_Wa+1.0)/PI + d_lon*(24.0/360.0);
-			((DCELL *) outrast1)[col] = d_time;
+			outrast1[col] = d_time;
 		}
 		if (G_put_raster_row (outfd1, outrast1, data_type_output) < 0)
 			G_fatal_error(_("Cannot write to output raster file"));

Modified: grass-addons/gipe/i.sunhours/main.c
===================================================================
--- grass-addons/gipe/i.sunhours/main.c	2008-08-21 13:50:39 UTC (rev 32972)
+++ grass-addons/gipe/i.sunhours/main.c	2008-08-21 14:03:19 UTC (rev 32973)
@@ -25,23 +25,22 @@
 
 int main(int argc, char *argv[])
 {
-	struct Cell_head cellhd; //region+header info
-	char *mapset; // mapset name
+	struct Cell_head cellhd; /*region+header info*/
+	char *mapset; /*mapset name*/
 	int nrows, ncols;
 	int row,col;
 
-	int verbose=1;
 	struct GModule *module;
 	struct Option *input1, *input2, *output1;
 	
 	struct Flag *flag1;	
-	struct History history; //metadata
+	struct History history; /*metadata*/
 	
 	/************************************/
 	/* FMEO Declarations*****************/
-	char *name;   // input raster name
-	char *result1; //output raster name
-	//File Descriptors
+	char *name;   /*input raster name*/
+	char *result1; /*output raster name*/
+	/*File Descriptors*/
 	int infd_lat, infd_doy;
 	int outfd1;
 	
@@ -49,7 +48,7 @@
 	int i=0,j=0;
 
 	void *inrast_lat, *inrast_doy;
-	unsigned char *outrast1;
+	DCELL *outrast1;
 	RASTER_MAP_TYPE data_type_output=DCELL_TYPE;
 	RASTER_MAP_TYPE data_type_lat;
 	RASTER_MAP_TYPE data_type_doy;
@@ -61,35 +60,16 @@
 	module->description = _("creates a sunshine hours map");
 
 	/* Define the different options */
-	input1 = G_define_option() ;
+	input1 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input1->key	   = _("doy");
-	input1->type       = TYPE_STRING;
-	input1->required   = YES;
-	input1->gisprompt  =_("old,cell,raster") ;
 	input1->description=_("Name of the latitude input map");
-	input1->answer     =_("doy");
 
-	input2 = G_define_option() ;
+	input2 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input2->key	   = _("lat");
-	input2->type       = TYPE_STRING;
-	input2->required   = YES;
-	input2->gisprompt  =_("old,cell,raster") ;
 	input2->description=_("Name of the latitude input map");
-	input2->answer     =_("latitude");
 
-	output1 = G_define_option() ;
-	output1->key        =_("sunh");
-	output1->type       = TYPE_STRING;
-	output1->required   = YES;
-	output1->gisprompt  =_("new,cell,raster");
+	output1 = G_define_standard_option(G_OPT_R_OUTPUT) ;
 	output1->description=_("Name of the output sunshine hours layer");
-	output1->answer     =_("sunh");
-
-	
-	flag1 = G_define_flag();
-	flag1->key = 'q';
-	flag1->description = _("Quiet");
-
 	/********************/
 	if (G_parser(argc, argv))
 		exit (EXIT_FAILURE);
@@ -98,7 +78,6 @@
 	doy	 	= input2->answer;
 		
 	result1  = output1->answer;
-	verbose = (!flag1->answer);
 	/***************************************************/
 	mapset = G_find_cell2(doy, "");
 	if (mapset == NULL) {
@@ -140,17 +119,13 @@
 		DCELL d_N;
 		DCELL d_lat;
 		DCELL d_doy;
-		if(verbose)
-			G_percent(row,nrows,2);
+		G_percent(row,nrows,2);
 		if(G_get_raster_row(infd_doy,inrast_doy,row,data_type_doy)<0)
 			G_fatal_error(_("Could not read from <%s>"),doy);
 		if(G_get_raster_row(infd_lat,inrast_lat,row,data_type_lat)<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];



More information about the grass-commit mailing list