[GRASS-SVN] r67439 - in grass-addons/grass7/imagery: . i.eb.z0m0

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 30 13:08:03 PST 2015


Author: ychemin
Date: 2015-12-30 13:08:03 -0800 (Wed, 30 Dec 2015)
New Revision: 67439

Added:
   grass-addons/grass7/imagery/i.eb.z0m0/
   grass-addons/grass7/imagery/i.eb.z0m0/i.eb.z0m0.html
Removed:
   grass-addons/grass7/imagery/i.eb.z0m0/description.html
Modified:
   grass-addons/grass7/imagery/Makefile
   grass-addons/grass7/imagery/i.eb.z0m0/Makefile
   grass-addons/grass7/imagery/i.eb.z0m0/main.c
Log:
upgraded i.eb.z0m0 to grass v7

Modified: grass-addons/grass7/imagery/Makefile
===================================================================
--- grass-addons/grass7/imagery/Makefile	2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/Makefile	2015-12-30 21:08:03 UTC (rev 67439)
@@ -5,8 +5,10 @@
 SUBDIRS = \
 	i.alti \
 	i.destripe \
+	i.eb.deltat \
 	i.eb.hsebal95 \
 	i.eb.z0m \
+	i.eb.z0m0 \
 	i.edge \
 	i.evapo.potrad \
 	i.evapo.senay \

Modified: grass-addons/grass7/imagery/i.eb.z0m0/Makefile
===================================================================
--- grass-addons/grass6/imagery/gipe/i.eb.z0m0/Makefile	2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.eb.z0m0/Makefile	2015-12-30 21:08:03 UTC (rev 67439)
@@ -2,13 +2,9 @@
 
 PGM = i.eb.z0m0
 
-LIBES = $(GISLIB)
-DEPENDENCIES = $(GISDEP)
+LIBES = $(GISLIB) $(RASTERLIB)
+DEPENDENCIES = $(GISDEP) $(RASTERDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 
-ifneq ($(USE_LARGEFILES),)
-	EXTRA_CFLAGS = -D_FILE_OFFSET_BITS=64
-endif
-
 default: cmd

Deleted: grass-addons/grass7/imagery/i.eb.z0m0/description.html
===================================================================
--- grass-addons/grass6/imagery/gipe/i.eb.z0m0/description.html	2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.eb.z0m0/description.html	2015-12-30 21:08:03 UTC (rev 67439)
@@ -1,32 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>i.eb.z0m0</em> calculates the momentum roughness length (z0m) and optionally the surface roughness for heat transport (z0h) as per SEBAL requirements from bastiaanssen (1995).
-This version is calculating from a NDVI with an deterministic equation, as seen in Bastiaanssen (1995).
-This is a typical input to sensible heat flux computations of any energy balance modeling.
-<h2>NOTES</h2>
-
-The NDVI map input and the ndvi_max operation set, is only to get a linear relationship from NDVI to vegetation height. The latter being related to z0m by a factor 7. 
-
-If you happen to have a vegetation height (hv) map, then z0m=hv/7 and z0h=0.1*z0m. There, fixed.
-
-
-<h2>TODO</h2>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="i.eb.h0.html">i.eb.h0</a><br>
-<a href="i.eb.h_SEBAL95.html">i.eb.h_SEBAL95</a><br>
-<a href="i.eb.h_iter.html">i.eb.h_iter</a><br>
-<a href="i.eb.z0m.html">i.eb.z0m</a><br>
-</em>
-
-
-<h2>AUTHORS</h2>
-
-Yann Chemin, International Rice Research Institute, The Philippines<br>
-
-
-<p>
-<i>Last changed: $Date$</i>

Copied: grass-addons/grass7/imagery/i.eb.z0m0/i.eb.z0m0.html (from rev 67438, grass-addons/grass6/imagery/gipe/i.eb.z0m0/description.html)
===================================================================
--- grass-addons/grass7/imagery/i.eb.z0m0/i.eb.z0m0.html	                        (rev 0)
+++ grass-addons/grass7/imagery/i.eb.z0m0/i.eb.z0m0.html	2015-12-30 21:08:03 UTC (rev 67439)
@@ -0,0 +1,32 @@
+<h2>DESCRIPTION</h2>
+
+<em>i.eb.z0m0</em> calculates the momentum roughness length (z0m) and optionally the surface roughness for heat transport (z0h) as per SEBAL requirements from bastiaanssen (1995).
+This version is calculating from a NDVI with an deterministic equation, as seen in Bastiaanssen (1995).
+This is a typical input to sensible heat flux computations of any energy balance modeling.
+<h2>NOTES</h2>
+
+The NDVI map input and the ndvi_max operation set, is only to get a linear relationship from NDVI to vegetation height. The latter being related to z0m by a factor 7. 
+
+If you happen to have a vegetation height (hv) map, then z0m=hv/7 and z0h=0.1*z0m. There, fixed.
+
+
+<h2>TODO</h2>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="i.eb.h0.html">i.eb.h0</a><br>
+<a href="i.eb.h_SEBAL95.html">i.eb.h_SEBAL95</a><br>
+<a href="i.eb.h_iter.html">i.eb.h_iter</a><br>
+<a href="i.eb.z0m.html">i.eb.z0m</a><br>
+</em>
+
+
+<h2>AUTHORS</h2>
+
+Yann Chemin, International Rice Research Institute, The Philippines<br>
+
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass-addons/grass7/imagery/i.eb.z0m0/main.c
===================================================================
--- grass-addons/grass6/imagery/gipe/i.eb.z0m0/main.c	2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.eb.z0m0/main.c	2015-12-30 21:08:03 UTC (rev 67439)
@@ -6,7 +6,7 @@
  * PURPOSE:      Calculates the momentum roughness length
  *               as seen in Bastiaanssen (1995) 
  *
- * COPYRIGHT:    (C) 2002-2008 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2002-2016 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
@@ -19,69 +19,47 @@
 #include <stdlib.h>
 #include <string.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 double zom_0(double ndvi, double ndvi_max, double hv_ndvimax,
 	      double hv_desert);
 int main(int argc, char *argv[]) 
 {
     struct Cell_head cellhd;	/*region+header info */
-
     char *mapset;		/*mapset name */
-
     int nrows, ncols;
-
     int row, col;
-
     int heat = 0;		/*Flag for surf. roughness for heat transport output */
-
     struct GModule *module;
-
     struct Option *input1, *input2, *input3, *input4;
-
     struct Option *output1, *output2;
-
     struct Flag *flag1, *flag2;
-
     struct History history;	/*metadata */
-
-    
-
-	/************************************/ 
-	/* FMEO Declarations**************** */ 
     char *name;			/*input raster name */
-
     char *result1, *result2;	/*output raster name */
-
-    
-	/*File Descriptors */ 
     int infd_ndvi;
-
     int outfd1, outfd2;
-
     char *ndvi;
-
     char *z0m, *z0h;
-
     double coef_z0h, hv_max, hmr;
-
     int i = 0, j = 0;
-
     void *inrast_ndvi;
-
     DCELL * outrast1, *outrast2;
     RASTER_MAP_TYPE data_type_output = DCELL_TYPE;
     RASTER_MAP_TYPE data_type_ndvi;
-    
-
-	/************************************/ 
-	G_gisinit(argv[0]);
+    /************************************/ 
+    G_gisinit(argv[0]);
     module = G_define_module();
-    module->keywords = _("roughness length, energy balance, SEBAL");
+    G_add_keyword(_("imagery"));
+    G_add_keyword(_("energy balance"));
+    G_add_keyword(_("SEBAL"));
+    G_add_keyword(_("SEBS"));
+    G_add_keyword(_("roughness length"));
     module->description =
 	_("Momentum roughness length (z0m) and surface roughness for heat transport (z0h) as seen in Bastiaanssen (2004)");
     
-	/* 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 = _("ndvi");
     input1->description = _("Name of the NDVI map [-1.0;1.0]");
     input2 = G_define_option();
@@ -118,9 +96,8 @@
     flag1->key = 'h';
     flag1->description = _("z0h output (You have to input a coef value)");
     
-
-	/********************/ 
-	if (G_parser(argc, argv))
+    /********************/ 
+    if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
     ndvi = input1->answer;
     if (input2->answer)
@@ -132,47 +109,36 @@
 	result2 = output2->answer;
     if (flag1->answer)
 	heat = flag1->answer;
-    
 
-	/***************************************************/ 
-	mapset = G_find_cell2(ndvi, "");
-    if (mapset == NULL) {
-	G_fatal_error(_("cell file [%s] not found"), ndvi);
-    }
-    data_type_ndvi = G_raster_map_type(ndvi, mapset);
-    if ((infd_ndvi = G_open_cell_old(ndvi, mapset)) < 0)
+    /***************************************************/ 
+    data_type_ndvi = Rast_map_type(ndvi, mapset);
+    if ((infd_ndvi = Rast_open_old(ndvi, mapset)) < 0)
 	G_fatal_error(_("Cannot open cell file [%s]"), ndvi);
-    if (G_get_cellhd(ndvi, mapset, &cellhd) < 0)
-	G_fatal_error(_("Cannot read file header of [%s])"), ndvi);
-    inrast_ndvi = G_allocate_raster_buf(data_type_ndvi);
+    Rast_get_cellhd(ndvi, mapset, &cellhd);
+    inrast_ndvi = Rast_allocate_buf(data_type_ndvi);
     
-
-	/***************************************************/ 
-	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);
+    /***************************************************/ 
+    G_debug(3, "number of rows %d", cellhd.rows);
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
+    outrast1 = Rast_allocate_buf(data_type_output);
     if (input2->answer && output2->answer) {
-	outrast2 = G_allocate_raster_buf(data_type_output);
+	outrast2 = Rast_allocate_buf(data_type_output);
     }
     
-	/* Create New raster files */ 
-	if ((outfd1 = G_open_raster_new(result1, data_type_output)) < 0)
-	G_fatal_error(_("Could not open <%s>"), result1);
+    /* Create New raster files */ 
+    outfd1 = Rast_open_new(result1, data_type_output);
     if (input2->answer && output2->answer) {
-	if ((outfd2 = G_open_raster_new(result2, data_type_output)) < 0)
-	    G_fatal_error(_("Could not open <%s>"), result2);
+	outfd2 = Rast_open_new(result2, data_type_output);
     }
     DCELL d_ndvi;		/* Input raster */
     DCELL d_ndvi_max = 0.0;	/* Generated here */
     
-	/* THREAD 1 */ 
-	/* NDVI Max */ 
-	for (row = 0; row < nrows; row++)
-	 {
+    /* NDVI Max */ 
+    for (row = 0; row < nrows; row++)
+    {
 	G_percent(row, nrows, 2);
-	if (G_get_d_raster_row(infd_ndvi, inrast_ndvi, row) < 0)
-	    G_fatal_error(_("Could not read from <%s>"), ndvi);
+	Rast_get_d_row(infd_ndvi, inrast_ndvi, row);
 	for (col = 0; col < ncols; col++)
 	     {
 	    switch (data_type_ndvi) {
@@ -186,32 +152,26 @@
 		d_ndvi = (double)((DCELL *) inrast_ndvi)[col];
 		break;
 	    }
-	    if (G_is_d_null_value(&d_ndvi)) {
-		
+	    if (Rast_is_d_null_value(&d_ndvi)) {		
 		    /* do nothing */ 
 	    }
 	    else if ((d_ndvi) > d_ndvi_max && (d_ndvi) < 0.98) {
 		d_ndvi_max = d_ndvi;
 	    }
-	    }
 	}
+    }
     G_message("ndvi_max=%f\n", d_ndvi_max);
-    
 	/* Process pixels */ 
 	for (row = 0; row < nrows; row++)
-	 {
+	{
 	DCELL d;
 	DCELL d_z0h;
 	G_percent(row, nrows, 2);
-	
 	    /* read input maps */ 
-	    if (G_get_raster_row(infd_ndvi, inrast_ndvi, row, data_type_ndvi)
-		< 0)
-	    G_fatal_error(_("Could not read from <%s>"), ndvi);
-	
+	    Rast_get_row(infd_ndvi, inrast_ndvi, row, data_type_ndvi);
 	    /*process the data */ 
 	    for (col = 0; col < ncols; col++)
-	     {
+	    {
 	    switch (data_type_ndvi) {
 	    case CELL_TYPE:
 		d_ndvi = (double)((CELL *) inrast_ndvi)[col];
@@ -223,47 +183,43 @@
 		d_ndvi = (double)((DCELL *) inrast_ndvi)[col];
 		break;
 	    }
-	    if (G_is_d_null_value(&d_ndvi)) {
-		G_set_d_null_value(&outrast1[col], 1);
+	    if (Rast_is_d_null_value(&d_ndvi)) {
+		Rast_set_d_null_value(&outrast1[col], 1);
 		if (input2->answer && output2->answer) {
-		    G_set_d_null_value(&outrast2[col], 1);
+		    Rast_set_d_null_value(&outrast2[col], 1);
 		}
 	    }
 	    else {
-		
-
-				/****************************/ 
-		    /* calculate z0m            */ 
-		    d = zom_0(d_ndvi, d_ndvi_max, hv_max, hmr);
+                /****************************/ 
+                /* calculate z0m            */ 
+                d = zom_0(d_ndvi, d_ndvi_max, hv_max, hmr);
 		outrast1[col] = d;
 		if (input2->answer && output2->answer) {
 		    d_z0h = d * coef_z0h;
 		    outrast2[col] = d_z0h;
 		}
 	    }
-	    }
-	if (G_put_raster_row(outfd1, outrast1, data_type_output) < 0)
-	    G_fatal_error(_("Cannot write to output z0m raster file"));
+	}
+	Rast_put_row(outfd1, outrast1, data_type_output);
 	if (input2->answer && output2->answer) {
-	    if (G_put_raster_row(outfd2, outrast2, data_type_output) < 0)
-		G_fatal_error(_("Cannot write to output z0h raster file"));
+	    Rast_put_row(outfd2, outrast2, data_type_output);
 	}
-	}
-    G_free(inrast_ndvi);
-    G_close_cell(infd_ndvi);
-    G_free(outrast1);
-    G_close_cell(outfd1);
+    }
+    free(inrast_ndvi);
+    Rast_close(infd_ndvi);
+    free(outrast1);
+    Rast_close(outfd1);
     if (input2->answer && output2->answer) {
-	G_free(outrast2);
-	G_close_cell(outfd2);
+	free(outrast2);
+	Rast_close(outfd2);
     }
-    G_short_history(result1, "raster", &history);
-    G_command_history(&history);
-    G_write_history(result1, &history);
+    Rast_short_history(result1, "raster", &history);
+    Rast_command_history(&history);
+    Rast_write_history(result1, &history);
     if (input2->answer && output2->answer) {
-	G_short_history(result2, "raster", &history);
-	G_command_history(&history);
-	G_write_history(result2, &history);
+	Rast_short_history(result2, "raster", &history);
+	Rast_command_history(&history);
+	Rast_write_history(result2, &history);
     }
     exit(EXIT_SUCCESS);
 }



More information about the grass-commit mailing list