[GRASS-SVN] r32908 - in grass-addons/gipe: i.albedo i.biomass i.vi

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Aug 19 19:06:30 EDT 2008


Author: ychemin
Date: 2008-08-19 19:06:29 -0400 (Tue, 19 Aug 2008)
New Revision: 32908

Modified:
   grass-addons/gipe/i.albedo/main.c
   grass-addons/gipe/i.biomass/main.c
   grass-addons/gipe/i.vi/main.c
Log:
Clean up, code standardization

Modified: grass-addons/gipe/i.albedo/main.c
===================================================================
--- grass-addons/gipe/i.albedo/main.c	2008-08-19 22:39:15 UTC (rev 32907)
+++ grass-addons/gipe/i.albedo/main.c	2008-08-19 23:06:29 UTC (rev 32908)
@@ -1,11 +1,11 @@
 /****************************************************************************
  *
  * MODULE:       i.albedo
- * AUTHOR(S):    Yann Chemin - ychemin at gmail.com
+ * AUTHOR(S):    Yann Chemin - yann.chemin at gmail.com
  * PURPOSE:      Calculate Broadband Albedo (0.3-3 Micrometers)
  *               from Surface Reflectance (Modis, AVHRR, Landsat, Aster).
  *
- * COPYRIGHT:    (C) 2004-2006 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2004-2008 by the GRASS Development Team
  *
  *               This program is free software under the GNU Lesser General Public
  *   	    	 License. Read the file COPYING that comes with GRASS for details.
@@ -29,8 +29,8 @@
 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;
 
@@ -39,13 +39,13 @@
 	
 	struct Flag *flag1, *flag2, *flag3;
 	struct Flag *flag4, *flag5, *flag6;
-	struct History history; //metadata
-	struct Colors colors; //Color rules
+	struct History history; /*metadata*/
+	struct Colors colors; /*Color rules*/
 	/************************************/
 	/* FMEO Declarations*****************/
-	char *name; //input raster name
-	char *result; //output raster name
-	//File Descriptors
+	char *name; /*input raster name*/
+	char *result; /*output raster name*/
+	/*File Descriptors*/
 	int nfiles;
 	int infd[MAXFILES];
 	int outfd;
@@ -64,10 +64,6 @@
 	RASTER_MAP_TYPE in_data_type[MAXFILES]; /* 0=numbers  1=text */
 	RASTER_MAP_TYPE out_data_type = DCELL_TYPE;
 
-	char *fileName;
-#define fileNameLe 8
-#define fileNamePosition 3
-
 	/************************************/
 	/************************************/
 	int		histogram[100];
@@ -353,7 +349,7 @@
 			b=0.05-a*(i_bottom1a/100.0);
 			G_message("a= %f\tb= %f\n",a,b);
 		}
-	}//END OF FLAG1
+	}/*END OF FLAG1*/
 	/* End of processing histogram*/
 	/*******************/
 	/* Process pixels */
@@ -397,7 +393,7 @@
 				de = bb_alb_aster(d[1],d[2],d[3],d[4],d[5],d[6]);
 			}
 			if(flag5->answer||flag6->answer){
-				// Post-Process Albedo
+				/* Post-Process Albedo */
 				de	= a*de+b;
 			}
 			((DCELL *) outrast)[col] = de;

Modified: grass-addons/gipe/i.biomass/main.c
===================================================================
--- grass-addons/gipe/i.biomass/main.c	2008-08-19 22:39:15 UTC (rev 32907)
+++ grass-addons/gipe/i.biomass/main.c	2008-08-19 23:06:29 UTC (rev 32908)
@@ -1,11 +1,11 @@
 /****************************************************************************
  *
  * MODULE:       i.biomass
- * AUTHOR(S):    Yann Chemin - ychemin at gmail.com
+ * AUTHOR(S):    Yann Chemin - yann.chemin at gmail.com
  * PURPOSE:      Creates a map of biomass growth
  *               
  *
- * COPYRIGHT:    (C) 2002-2006 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
@@ -24,8 +24,8 @@
 
 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;
 
@@ -34,14 +34,14 @@
 	struct Option *output1;
 	
 	struct Flag *flag1;	
-	struct History history; //metadata
+	struct History history; /*metadata*/
 	struct Colors colors;
 	
 	/************************************/
 	/* FMEO Declarations*****************/
-	char *name;   // input raster name
-	char *result1,*result2; //output raster name
-	//File Descriptors
+	char *name;   /* input raster name*/
+	char *result1,*result2; /*output raster name*/
+	/*File Descriptors*/
 	int infd_fpar, infd_lightuseff, infd_lat, infd_doy, infd_tsw, infd_wat_avail;
 	int outfd1;
 	
@@ -49,7 +49,7 @@
 	int i=0,j=0;
 	
 	void *inrast_fpar, *inrast_lightuseff, *inrast_lat, *inrast_doy, *inrast_tsw, *inrast_wat_avail;
-	unsigned char *outrast1;
+	DCELL *outrast1;
 	RASTER_MAP_TYPE data_type_output=DCELL_TYPE;
 	RASTER_MAP_TYPE data_type_fpar;
 	RASTER_MAP_TYPE data_type_lightuseff;
@@ -215,28 +215,83 @@
 		/*process the data */
 		for (col=0; col < ncols; col++)
 		{
-			d_fpar = ((DCELL *) inrast_fpar)[col];
-			d_lightuseff = ((DCELL *) inrast_lightuseff)[col];
-			d_lat = ((DCELL *) inrast_lat)[col];
-			d_doy = ((DCELL *) inrast_doy)[col];
-			d_tsw = ((DCELL *) inrast_tsw)[col];
-			d_wat_avail = ((DCELL *) inrast_wat_avail)[col];
-			if(G_is_d_null_value(&d_fpar)){
-				((DCELL *) outrast1)[col] = -999.99;
-			}else if(G_is_d_null_value(&d_lightuseff)){
-				((DCELL *) outrast1)[col] = -999.99;
-			}else if(G_is_d_null_value(&d_lat)){
-				((DCELL *) outrast1)[col] = -999.99;
-			}else if(G_is_d_null_value(&d_doy)){
-				((DCELL *) outrast1)[col] = -999.99;
-			}else if(G_is_d_null_value(&d_tsw)){
-				((DCELL *) outrast1)[col] = -999.99;
-			}else if(G_is_d_null_value(&d_wat_avail)){
-				((DCELL *) outrast1)[col] = -999.99;
+			switch(data_type_fpar){
+				case CELL_TYPE:
+					d_fpar = (double) ((CELL *) inrast_fpar)[col];
+					break;
+				case FCELL_TYPE:
+					d_fpar = (double) ((FCELL *) inrast_fpar)[col];
+					break;
+				case DCELL_TYPE:
+					d_fpar = ((DCELL *) inrast_fpar)[col];
+					break;
+			}
+			switch(data_type_lightuseff){
+				case CELL_TYPE:
+					d_lightuseff = (double) ((CELL *) inrast_lightuseff)[col];
+					break;
+				case FCELL_TYPE:
+					d_lightuseff= (double) ((FCELL *) inrast_lightuseff)[col];
+					break;
+				case DCELL_TYPE:
+					d_lightuseff = ((DCELL *) inrast_lightuseff)[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;
+			}
+			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_tsw){
+				case CELL_TYPE:
+					d_tsw = (double) ((CELL *) inrast_tsw)[col];
+					break;
+				case FCELL_TYPE:
+					d_tsw = (double) ((FCELL *) inrast_tsw)[col];
+					break;
+				case DCELL_TYPE:
+					d_tsw = ((DCELL *) inrast_tsw)[col];
+					break;
+			}
+			switch(data_type_wat_avail){
+				case CELL_TYPE:
+					d_wat_avail = (double) ((CELL *) inrast_wat_avail)[col];
+					break;
+				case FCELL_TYPE:
+					d_wat_avail = (double) ((FCELL *) inrast_wat_avail)[col];
+					break;
+				case DCELL_TYPE:
+					d_wat_avail = ((DCELL *) inrast_wat_avail)[col];
+					break;
+			}
+			if(G_is_d_null_value(&d_fpar)||
+			G_is_d_null_value(&d_lightuseff)||
+			G_is_d_null_value(&d_lat)||
+			G_is_d_null_value(&d_doy)||
+			G_is_d_null_value(&d_tsw)||
+			G_is_d_null_value(&d_wat_avail)){
+				G_set_d_null_value(&outrast1[col],1);
 			}else {
 				d_solar = solar_day(d_lat, d_doy, d_tsw );
 				d = biomass(d_fpar,d_solar,d_wat_avail,d_lightuseff);
-				((DCELL *) outrast1)[col] = d;
+				outrast1[col] = d;
 			}
 		}
 		if (G_put_raster_row (outfd1, outrast1, data_type_output) < 0)

Modified: grass-addons/gipe/i.vi/main.c
===================================================================
--- grass-addons/gipe/i.vi/main.c	2008-08-19 22:39:15 UTC (rev 32907)
+++ grass-addons/gipe/i.vi/main.c	2008-08-19 23:06:29 UTC (rev 32908)
@@ -46,32 +46,34 @@
 
 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;
 
-	char *viflag;// Switch for particular index
+	char *viflag;/*Switch for particular index*/
 	
 	struct GModule *module;
 	struct Option *input1, *input2,*input3,*input4,*input5,*input6,*input7, *output;
 	
 	struct Flag *flag1;	
-	struct History history; //metadata
-	struct Colors colors; //Color rules	
+	struct History history; /*metadata*/
+	struct Colors colors; /*Color rules*/	
 	/************************************/
 	/* FMEO Declarations*****************/
-	char *name;   // input raster name
-	char *result; //output raster name
-	//File Descriptors
-	int infd_redchan, infd_nirchan, infd_greenchan, infd_bluechan, infd_chan5chan, infd_chan7chan;
+	char *name;   /*input raster name*/
+	char *result; /*output raster name*/
+	/*File Descriptors*/
+	int infd_redchan, infd_nirchan, infd_greenchan;
+	int infd_bluechan, infd_chan5chan, infd_chan7chan;
 	int outfd;
 	
 	char  *bluechan, *greenchan,*redchan, *nirchan, *chan5chan, *chan7chan;
 	
 	int i=0,j=0;
 	
-	void *inrast_redchan, *inrast_nirchan, *inrast_greenchan, *inrast_bluechan, *inrast_chan5chan, *inrast_chan7chan;
+	void *inrast_redchan, *inrast_nirchan, *inrast_greenchan;
+	void *inrast_bluechan, *inrast_chan5chan, *inrast_chan7chan;
 	DCELL *outrast;
 	RASTER_MAP_TYPE data_type_output=DCELL_TYPE;
 	RASTER_MAP_TYPE data_type_redchan;
@@ -97,59 +99,39 @@
 	input1->description=_("Name of VI: sr,ndvi,ipvi,dvi,evi,pvi,wdvi,savi,msavi,msavi2,gemi,arvi,gvi,gari.");
 	input1->answer     =_("ndvi");
 
-	input2 = G_define_option() ;
+	input2 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input2->key	   = _("red");
-	input2->type       = TYPE_STRING;
-	input2->required   = YES;
-	input2->gisprompt  =_("old,cell,raster") ;
 	input2->description=_("Name of the RED Channel surface reflectance map [0.0;1.0]");
 	input2->answer     =_("redchan");
 
-	input3 = G_define_option() ;
+	input3 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input3->key        =_("nir");
-	input3->type       = TYPE_STRING;
-	input3->required   = YES;
-	input3->gisprompt  =_("old,cell,raster");
 	input3->description=_("Name of the NIR Channel surface reflectance map [0.0;1.0]");
 	input3->answer     =_("nirchan");
 
-	input4 = G_define_option() ;
+	input4 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input4->key        =_("green");
-	input4->type       = TYPE_STRING;
 	input4->required   = NO;
-	input4->gisprompt  =_("old,cell,raster");
 	input4->description=_("Name of the GREEN Channel surface reflectance map [0.0;1.0]");
-//	input4->answer     =_("greenchan");
 
-	input5 = G_define_option() ;
+	input5 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input5->key        =_("blue");
-	input5->type       = TYPE_STRING;
 	input5->required   = NO;
-	input5->gisprompt  =_("old,cell,raster");
 	input5->description=_("Name of the BLUE Channel surface reflectance map [0.0;1.0]");
-//	input5->answer     =_("bluechan");
 
-	input6 = G_define_option() ;
+	input6 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input6->key        =_("chan5");
-	input6->type       = TYPE_STRING;
 	input6->required   = NO;
-	input6->gisprompt  =_("old,cell,raster");
 	input6->description=_("Name of the CHAN5 Channel surface reflectance map [0.0;1.0]");
-//	input6->answer     =_("chan5chan");
 
-	input7 = G_define_option() ;
+	input7 = G_define_standard_option(G_OPT_R_INPUT) ;
 	input7->key        =_("chan7");
-	input7->type       = TYPE_STRING;
 	input7->required   = NO;
-	input7->gisprompt  =_("old,cell,raster");
 	input7->description=_("Name of the CHAN7 Channel surface reflectance map [0.0;1.0]");
-//	input7->answer     =_("chan7chan");
 
-	output= G_define_option() ;
+	output= G_define_standard_option(G_OPT_R_OUTPUT) ;
 	output->key        =_("vi");
-	output->type       = TYPE_STRING;
 	output->required   = YES;
-	output->gisprompt  =_("new,cell,raster");
 	output->description=_("Name of the output vi layer");
 	output->answer     =_("vi");
 
@@ -259,7 +241,6 @@
 		DCELL d_chan5chan;
 		DCELL d_chan7chan;
 		G_percent(row,nrows,2);
-//		printf("row = %i/%i\n",row,nrows);
 		if(G_get_raster_row(infd_redchan,inrast_redchan,row,data_type_redchan)<0)
 			G_fatal_error(_("Could not read from <%s>"),redchan);
 		if(G_get_raster_row(infd_nirchan,inrast_nirchan,row,data_type_nirchan)<0)
@@ -357,8 +338,6 @@
 						break;
 				}
 			}
-			//	printf("col=%i/%i ",col,ncols);
-		// to change to multiple to output files.
 			if(G_is_d_null_value(&d_redchan)||
 			G_is_d_null_value(&d_nirchan)||
 			((greenchan)&&G_is_d_null_value(&d_greenchan))||



More information about the grass-commit mailing list