[GRASS-SVN] r34542 - in grass/trunk: db db/db.columns db/db.connect db/db.copy db/db.createdb db/db.databases db/db.describe db/db.drivers db/db.dropdb db/db.droptable db/db.execute db/db.select db/db.tables general/g.copy general/g.list general/g.remove general/g.rename raster raster/r.ros raster/r.spread raster/r.spreadpath raster/wildfire raster3d raster3d/base raster3d/r3.info raster3d/r3.timestamp

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 27 13:51:45 EST 2008


Author: glynn
Date: 2008-11-27 13:51:44 -0500 (Thu, 27 Nov 2008)
New Revision: 34542

Added:
   grass/trunk/db/db.columns/
   grass/trunk/db/db.columns/Makefile
   grass/trunk/db/db.columns/columns.c
   grass/trunk/db/db.columns/db.columns.html
   grass/trunk/db/db.connect/
   grass/trunk/db/db.connect/Makefile
   grass/trunk/db/db.connect/connect.c
   grass/trunk/db/db.connect/db.connect.html
   grass/trunk/db/db.copy/
   grass/trunk/db/db.copy/Makefile
   grass/trunk/db/db.copy/copy.c
   grass/trunk/db/db.copy/db.copy.html
   grass/trunk/db/db.createdb/
   grass/trunk/db/db.createdb/Makefile
   grass/trunk/db/db.createdb/createdb.c
   grass/trunk/db/db.createdb/db.createdb.html
   grass/trunk/db/db.databases/
   grass/trunk/db/db.databases/Makefile
   grass/trunk/db/db.databases/databases.c
   grass/trunk/db/db.databases/db.databases.html
   grass/trunk/db/db.describe/
   grass/trunk/db/db.describe/Makefile
   grass/trunk/db/db.describe/db.describe.html
   grass/trunk/db/db.describe/describe.c
   grass/trunk/db/db.describe/local_proto.h
   grass/trunk/db/db.describe/printtab.c
   grass/trunk/db/db.drivers/
   grass/trunk/db/db.drivers/Makefile
   grass/trunk/db/db.drivers/db.drivers.html
   grass/trunk/db/db.drivers/drivers.c
   grass/trunk/db/db.dropdb/
   grass/trunk/db/db.dropdb/Makefile
   grass/trunk/db/db.dropdb/db.dropdb.html
   grass/trunk/db/db.dropdb/dropdb.c
   grass/trunk/db/db.droptable/
   grass/trunk/db/db.droptable/Makefile
   grass/trunk/db/db.droptable/db.droptable.html
   grass/trunk/db/db.droptable/droptable.c
   grass/trunk/db/db.execute/
   grass/trunk/db/db.execute/Makefile
   grass/trunk/db/db.execute/db.execute.html
   grass/trunk/db/db.execute/execute.c
   grass/trunk/db/db.select/
   grass/trunk/db/db.select/Makefile
   grass/trunk/db/db.select/db.select.html
   grass/trunk/db/db.select/local_proto.h
   grass/trunk/db/db.select/printtab.c
   grass/trunk/db/db.select/select.c
   grass/trunk/db/db.tables/
   grass/trunk/db/db.tables/Makefile
   grass/trunk/db/db.tables/db.tables.html
   grass/trunk/db/db.tables/tables.c
   grass/trunk/general/g.copy/main.c
   grass/trunk/general/g.list/main.c
   grass/trunk/general/g.remove/main.c
   grass/trunk/general/g.rename/main.c
   grass/trunk/raster/r.ros/
   grass/trunk/raster/r.ros/Makefile
   grass/trunk/raster/r.ros/local_proto.h
   grass/trunk/raster/r.ros/main.c
   grass/trunk/raster/r.ros/r.ros.html
   grass/trunk/raster/r.ros/spot_dist.c
   grass/trunk/raster/r.spread/
   grass/trunk/raster/r.spread/Makefile
   grass/trunk/raster/r.spread/cell_ptrHa.h
   grass/trunk/raster/r.spread/cmd_line.h
   grass/trunk/raster/r.spread/collect_ori.c
   grass/trunk/raster/r.spread/costHa.h
   grass/trunk/raster/r.spread/deleteHa.c
   grass/trunk/raster/r.spread/display.c
   grass/trunk/raster/r.spread/fixHa.c
   grass/trunk/raster/r.spread/get_minHa.c
   grass/trunk/raster/r.spread/insert2Ha.c
   grass/trunk/raster/r.spread/insertHa.c
   grass/trunk/raster/r.spread/local_proto.h
   grass/trunk/raster/r.spread/main.c
   grass/trunk/raster/r.spread/pick_dist.c
   grass/trunk/raster/r.spread/pick_ignite.c
   grass/trunk/raster/r.spread/r.spread.html
   grass/trunk/raster/r.spread/ram2out.c
   grass/trunk/raster/r.spread/replaceHa.c
   grass/trunk/raster/r.spread/select_linksB.c
   grass/trunk/raster/r.spread/spot.c
   grass/trunk/raster/r.spread/spread.c
   grass/trunk/raster/r.spreadpath/
   grass/trunk/raster/r.spreadpath/Makefile
   grass/trunk/raster/r.spreadpath/drawline.c
   grass/trunk/raster/r.spreadpath/insert.c
   grass/trunk/raster/r.spreadpath/local_proto.h
   grass/trunk/raster/r.spreadpath/main.c
   grass/trunk/raster/r.spreadpath/path_finder.c
   grass/trunk/raster/r.spreadpath/point.h
   grass/trunk/raster/r.spreadpath/r.spreadpath.html
   grass/trunk/raster/r.spreadpath/stash.h
   grass/trunk/raster3d/r3.info/
   grass/trunk/raster3d/r3.info/Makefile
   grass/trunk/raster3d/r3.info/r3.info.html
   grass/trunk/raster3d/r3.info/r3.info.main.c
   grass/trunk/raster3d/r3.timestamp/
   grass/trunk/raster3d/r3.timestamp/Makefile
   grass/trunk/raster3d/r3.timestamp/r3.timestamp.html
   grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c
Removed:
   grass/trunk/db/base/
   grass/trunk/general/g.copy/copy.c
   grass/trunk/general/g.list/list.c
   grass/trunk/general/g.remove/remove.c
   grass/trunk/general/g.rename/rename.c
   grass/trunk/raster/wildfire/r.ros/
   grass/trunk/raster/wildfire/r.spread/
   grass/trunk/raster/wildfire/r.spreadpath/
   grass/trunk/raster3d/base/r3.info.html
   grass/trunk/raster3d/base/r3.info.main.c
   grass/trunk/raster3d/base/r3.timestamp.html
   grass/trunk/raster3d/base/r3.timestamp.main.c
Modified:
   grass/trunk/db/Makefile
   grass/trunk/raster/Makefile
   grass/trunk/raster3d/Makefile
   grass/trunk/raster3d/base/Makefile
Log:
Improve adherence to consistent directory structure


Modified: grass/trunk/db/Makefile
===================================================================
--- grass/trunk/db/Makefile	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/db/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -3,8 +3,19 @@
 
 SUBDIRS = \
 	drivers \
-	base \
-	db.login
+	db.columns \
+	db.connect \
+	db.copy \
+	db.createdb \
+	db.databases \
+	db.describe \
+	db.drivers \
+	db.dropdb \
+	db.droptable \
+	db.execute \
+	db.login \
+	db.select \
+	db.tables
 
 PGM = databaseintro
 


Property changes on: grass/trunk/db/db.columns
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.columns/Makefile
===================================================================
--- grass/trunk/db/db.columns/Makefile	                        (rev 0)
+++ grass/trunk/db/db.columns/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.columns
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.columns/columns.c (from rev 34541, grass/trunk/db/base/columns.c)
===================================================================
--- grass/trunk/db/db.columns/columns.c	                        (rev 0)
+++ grass/trunk/db/db.columns/columns.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,101 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.columns
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
+ * PURPOSE:      list the column names for a table
+ * COPYRIGHT:    (C) 2002-2006 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 <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/codes.h>
+#include <stdlib.h>
+#include <grass/glocale.h>
+
+
+struct
+{
+    char *driver, *database, *table;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+
+
+int main(int argc, char **argv)
+{
+    dbDriver *driver;
+    dbHandle handle;
+    dbTable *table;
+    dbString table_name;
+    int col, ncols;
+
+    parse_command_line(argc, argv);
+
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL)
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+
+    db_init_handle(&handle);
+    db_set_handle(&handle, parms.database, NULL);
+    if (db_open_database(driver, &handle) != DB_OK)
+	exit(EXIT_FAILURE);
+
+    db_init_string(&table_name);
+    db_set_string(&table_name, parms.table);
+    if (db_describe_table(driver, &table_name, &table) != DB_OK)
+	exit(EXIT_FAILURE);
+
+    db_close_database(driver);
+    db_shutdown_driver(driver);
+
+    ncols = db_get_table_number_of_columns(table);
+    for (col = 0; col < ncols; col++)
+	fprintf(stdout, "%s\n",
+		db_get_column_name(db_get_table_column(table, col)));
+
+    exit(EXIT_SUCCESS);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *database, *table;
+    struct GModule *module;
+    const char *drv, *db;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    table = G_define_standard_option(G_OPT_DB_TABLE);
+    table->required = YES;
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+    if ((drv = db_get_default_driver_name()))
+	driver->answer = (char *) drv;
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    if ((db = db_get_default_database_name()))
+	database->answer = (char *) db;
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, attribute table");
+    module->description = _("List all columns for a given table.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    parms.driver = driver->answer;
+    parms.database = database->answer;
+    parms.table = table->answer;
+}


Property changes on: grass/trunk/db/db.columns/columns.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.columns/db.columns.html (from rev 34541, grass/trunk/db/base/db.columns.html)
===================================================================
--- grass/trunk/db/db.columns/db.columns.html	                        (rev 0)
+++ grass/trunk/db/db.columns/db.columns.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,47 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.columns</em> lists all columns for a give table. Connection to 
+databases are supported through dbf, shp, odbc and pg drivers.  
+
+<h2>NOTE</h2>
+
+If parameters for database connection are already set with 
+<a HREF="db.connect.html">db.connect</a>, they are taken as default values and
+do not need to be spcified each time.
+
+<h2>EXAMPLE</h2>
+
+<em>List columns from PostgreSQL attribute table</em><br>
+<div class="code"><pre>
+db.columns table=markveggy driver=pg database=grass60test
+</pre></div>
+
+<p>
+
+<em>If database parameters are already set</em><br>
+<div class="code"><pre>
+db.columns table=markveggy
+</pre></div>
+
+<p>
+
+<em>List columns from Shape file with DBF attribute table</em><br>
+<div class="code"><pre>
+db.columns table=network driver=dbf database=/daten/grassdata/fire/PERMANENT/dbf/
+</pre></div>
+
+<h2>SEE ALSO</h2>
+<em><a HREF="db.connect.html">db.connect</a>,
+<a HREF="db.describe.html">db.describe</a>,
+<a HREF="db.drivers.html">db.drivers</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.columns/db.columns.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.connect
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.connect/Makefile
===================================================================
--- grass/trunk/db/db.connect/Makefile	                        (rev 0)
+++ grass/trunk/db/db.connect/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.connect
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.connect/connect.c (from rev 34541, grass/trunk/db/base/connect.c)
===================================================================
--- grass/trunk/db/db.connect/connect.c	                        (rev 0)
+++ grass/trunk/db/db.connect/connect.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,174 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.connect
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Alex Shevlakov <sixote yahoo.com>, 
+ *               Glynn Clements <glynn gclements.plus.com>,
+ *               Markus Neteler <neteler itc.it>,
+ *               Hamish Bowman <hamish_b yahoo com>
+ * PURPOSE:      set parameters for connection to database
+ * 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>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+
+/* database for DBF can be written with variables:
+ *   database=$GISDBASE/$LOCATION_NAME/$MAPSET/dbf
+ */
+
+int main(int argc, char *argv[])
+{
+    dbConnection conn;
+    struct Flag *print, *check_set_default;
+
+    /*    struct Option *driver, *database, *user, *password, *keycol; */
+    struct Option *driver, *database, *schema, *group;
+    struct GModule *module;
+
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, attribute table");
+    module->description =
+	_("Prints/sets general DB connection for current mapset and exits.");
+
+
+    print = G_define_flag();
+    print->key = 'p';
+    print->description = _("Print current connection parameters and exit");
+
+    check_set_default = G_define_flag();
+    check_set_default->key = 'c';
+    check_set_default->description =
+	_("Check connection parameters, set if uninitialized, and exit");
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+    driver->answer = (char *) db_get_default_driver_name();
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    database->answer = (char *) db_get_default_database_name();
+
+    schema = G_define_option();
+    schema->key = "schema";
+    schema->type = TYPE_STRING;
+    schema->required = NO;
+    schema->multiple = NO;
+    schema->answer = (char *) db_get_default_schema_name();
+    schema->label = _("Database schema");
+    schema->description = _("Do not use this option if schemas "
+			    "are not supported by driver/database server");
+
+    group = G_define_option();
+    group->key = "group";
+    group->type = TYPE_STRING;
+    group->required = NO;
+    group->multiple = NO;
+    group->answer = (char*) db_get_default_group_name();
+    group->description = _("Default group of database users to which "
+			   "select privilege is granted");
+
+    /* commented due to new mechanism:
+       user = G_define_option() ;
+       user->key        = "user" ;
+       user->type       = TYPE_STRING ;
+       user->required   = NO  ;
+       user->multiple   = NO ;
+       user->description= "User:" ;    
+
+       password = G_define_option() ;
+       password->key        = "password" ;
+       password->type       = TYPE_STRING ;
+       password->required   = NO  ;
+       password->multiple   = NO ;
+       password->description= "Password:" ;
+     */
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
+    if (print->answer) {
+	/* get and print connection */
+	if (db_get_connection(&conn) == DB_OK) {
+	    fprintf(stdout, "driver:%s\n",
+		    conn.driverName ? conn.driverName : "");
+	    fprintf(stdout, "database:%s\n",
+		    conn.databaseName ? conn.databaseName : "");
+	    fprintf(stdout, "schema:%s\n",
+		    conn.schemaName ? conn.schemaName : "");
+	    fprintf(stdout, "group:%s\n", conn.group ? conn.group : "");
+	}
+	else
+	    G_fatal_error(_("Database connection not defined. "
+			    "Run db.connect."));
+
+	exit(EXIT_SUCCESS);
+    }
+
+
+    if (check_set_default->answer) {
+	/* check connection and set to system-wide default in required */
+	/*
+	 * TODO: improve db_{get,set}_connection() to not return DB_OK on error
+	 *       (thus currently there is no point in checking for that here)
+	 */
+	db_get_connection(&conn);
+
+	if (!conn.driverName && !conn.databaseName) {
+
+	    db_set_default_connection();
+	    db_get_connection(&conn);
+
+	    G_message(_("Default driver / database set to:\n"
+			"driver: %s\ndatabase: %s"), conn.driverName,
+		      conn.databaseName);
+	}
+	/* they must be a matched pair, so if one is set but not the other
+	   then give up and let the user figure it out */
+	else if (!conn.driverName) {
+	    G_fatal_error(_("Default driver is not set"));
+	}
+	else if (!conn.databaseName) {
+	    G_fatal_error(_("Default database is not set"));
+	}
+
+	/* connection either already existed or now exists */
+	exit(EXIT_SUCCESS);
+    }
+
+
+    /* set connection */
+    db_get_connection(&conn);	/* read current */
+
+    if (driver->answer)
+	conn.driverName = driver->answer;
+
+    if (database->answer)
+	conn.databaseName = database->answer;
+
+    if (schema->answer)
+	conn.schemaName = schema->answer;
+
+    if (group->answer)
+	conn.group = group->answer;
+
+    db_set_connection(&conn);
+
+
+    exit(EXIT_SUCCESS);
+}


Property changes on: grass/trunk/db/db.connect/connect.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.connect/db.connect.html (from rev 34541, grass/trunk/db/base/db.connect.html)
===================================================================
--- grass/trunk/db/db.connect/db.connect.html	                        (rev 0)
+++ grass/trunk/db/db.connect/db.connect.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,126 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.connect</em> allows the user to set database connection parameters.
+These parameters are then taken as default values by modules so that the
+user does not need to enter the parameters each time.
+
+
+<H2>NOTES</H2>
+
+Values are stored in the mapset's <tt>VAR</tt> file;
+the connection is not tested for validity.
+<P>
+The <b>-p</b> flag will display the current connection parameters. 
+<P>
+The <b>-c</b> flag will silently check if the connection parameters have
+been set, and if not will set them to use GRASS's default values.
+(useful in scripts before you attempt to create a new database table)
+<P>
+To connect a vector map to a database table, use <em>v.db.connect</em>
+or <em>v.db.addtable</em>.
+
+
+<h2>EXAMPLES</h2>
+
+<h3>DBF</h3>
+
+Local storage (the dbf/ subdirectory in the mapset must exist or must be
+created by the user):
+<br>
+<div class="code"><pre>
+db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
+db.tables -p
+</pre></div>
+
+
+<h3>SQLite</h3>
+
+Local storage:
+<br>
+<div class="code"><pre>
+db.connect driver=sqlite database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db'
+db.connect -p
+db.tables -p
+</pre></div>
+<P>
+The SQLite database is created automatically when used the first time.
+
+
+<h3>ODBC</h3>
+
+Network storage: (may require the use of <a href=db.login.html>db.login</a>):
+<br> 
+<div class="code"><pre>
+db.connect driver=odbc database=gtest
+db.login user=myname [pass=secret]
+db.connect -p
+db.tables -p
+</pre></div>
+
+
+<h3>PostgreSQL</h3>
+
+Network storage: (may require the use of <a href=db.login.html>db.login</a>):
+<br>
+<div class="code"><pre>
+db.connect driver=pg database="host=myserver.itc.it,dbname=mydb"
+db.login user=myname [pass=secret]
+db.connect -p
+db.tables -p
+</pre></div>
+
+
+<h3>PostgreSQL with different port</h3>
+
+Network storage: (may require the use of <a href=db.login.html>db.login</a>):
+<br>
+<div class="code"><pre>
+db.connect driver=pg database="host=myserver.itc.it,dbname=mydb,port=6666"
+db.login user=myname [pass=secret]
+db.connect -p
+db.tables -p
+</pre></div>
+
+
+<h3>MySQL (local)</h3>
+
+Local storage (<a href=db.login.html>db.login</a> may not be needed):
+<br>
+<div class="code"><pre>
+db.connect driver=mysql database=mydb
+db.login user=myname [pass=secret]
+db.connect -p
+db.tables -p
+</pre></div>
+
+
+<h3>MySQL (external server)</h3>
+
+Network storage: (may require the use of <a href=db.login.html>db.login</a>):
+<br>
+<div class="code"><pre>
+db.connect driver=mysql database="host=myserver.itc.it,dbname=mydb"
+db.login user=myname [pass=secret]
+db.connect -p
+db.tables -p
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a HREF="db.columns.html">db.columns</a>,
+<a HREF="db.drivers.html">db.drivers</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="v.db.addtable.html">v.db.addtable</a>,
+<a HREF="v.db.connect.html">v.db.connect</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.connect/db.connect.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.copy
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.copy/Makefile
===================================================================
--- grass/trunk/db/db.copy/Makefile	                        (rev 0)
+++ grass/trunk/db/db.copy/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.copy
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.copy/copy.c (from rev 34541, grass/trunk/db/base/copy.c)
===================================================================
--- grass/trunk/db/db.copy/copy.c	                        (rev 0)
+++ grass/trunk/db/db.copy/copy.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,129 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.copy
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
+ * PURPOSE:      copy a table
+ * COPYRIGHT:    (C) 2003-2006 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 <stdlib.h>
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+
+
+int main(int argc, char **argv)
+{
+    int ret;
+    struct Option *from_driver, *from_database, *from_table;
+    struct Option *to_driver, *to_database, *to_table;
+    struct Option *where, *select;
+    struct GModule *module;
+    const char *drv, *db;
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, attribute table, SQL");
+    module->label = _("Copy a table.");
+    module->description =
+	_("Either 'from_table' (optionally with 'where') can be used "
+	  "or 'select' option, but not 'from_table' and 'select' at the same time.");
+    
+    from_driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    from_driver->key = "from_driver";
+    from_driver->options = db_list_drivers();
+    from_driver->description = _("Input driver name");
+    if ((drv = db_get_default_driver_name()))
+      from_driver->answer = (char *) drv;
+
+    from_database = G_define_standard_option(G_OPT_DB_DATABASE);
+    from_database->key = "from_database";
+    from_database->description = _("Input database name");
+    if ((db = db_get_default_database_name()))
+      from_database->answer = (char *) db;
+
+    from_table = G_define_standard_option(G_OPT_DB_TABLE);
+    from_table->key = "from_table";
+    from_table->description =
+	_("Input table name (only, if 'select' is not used)");
+
+    to_driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    to_driver->key = "to_driver";
+    to_driver->options = db_list_drivers();
+    to_driver->required = NO;
+    to_driver->description = _("Output driver name");
+    if ((drv = db_get_default_driver_name()))
+      to_driver->answer = (char *) drv;
+
+    to_database = G_define_standard_option(G_OPT_DB_DATABASE);
+    to_database->key = "to_database";
+    to_database->description = _("Output database name");
+    if ((db = db_get_default_database_name()))
+      to_database->answer = (char *) db;
+
+    to_table = G_define_standard_option(G_OPT_DB_TABLE);
+    to_table->key = "to_table";
+    to_table->required = YES;
+    to_table->description = _("Output table name");
+    to_table->gisprompt = "new,dbtable,dbtable";
+
+    where = G_define_standard_option(G_OPT_DB_WHERE);
+
+    select = G_define_option();
+    select->key = "select";
+    select->type = TYPE_STRING;
+    select->required = NO;
+    select->label = _("Full select statement (only, if 'from_table' and 'where' is not used)");
+    select->description = _("E.g.: SELECT dedek FROM starobince WHERE obec = 'Frimburg'");
+    
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    /* Check options and copy tables */
+    if (from_table->answer) {
+	if (select->answer)
+	    G_fatal_error(_("Cannot combine 'from_table' and 'select' options"));
+
+	if (where->answer) {
+	    ret =
+		db_copy_table_where(from_driver->answer,
+				    from_database->answer, from_table->answer,
+				    to_driver->answer, to_database->answer,
+				    to_table->answer, where->answer);
+	}
+	else {
+	    ret =
+		db_copy_table(from_driver->answer, from_database->answer,
+			      from_table->answer, to_driver->answer,
+			      to_database->answer, to_table->answer);
+	}
+    }
+    else {
+	if (!select->answer)
+	    G_fatal_error(_("Either 'from_table' or 'select' option must be given."));
+
+	if (where->answer)
+	    G_fatal_error(_("Cannot combine 'select' and 'where' options"));
+
+	ret =
+	    db_copy_table_select(from_driver->answer, from_database->answer,
+				 from_table->answer, to_driver->answer,
+				 to_database->answer, to_table->answer,
+				 select->answer);
+    }
+
+    if (ret == DB_FAILED) {
+	G_warning(_("Copy table failed"));
+	exit(EXIT_FAILURE);
+    }
+
+    exit(EXIT_SUCCESS);
+}


Property changes on: grass/trunk/db/db.copy/copy.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.copy/db.copy.html (from rev 34541, grass/trunk/db/base/db.copy.html)
===================================================================
--- grass/trunk/db/db.copy/db.copy.html	                        (rev 0)
+++ grass/trunk/db/db.copy/db.copy.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,75 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.copy</em> allows the user to copy a table between two databases.
+Databases can be connected through different drivers (see example).
+
+<h2>NOTES</h2>
+
+Attribute tables can be copied manually using db.copy and 
+<em><a HREF="v.db.connect.html">v.db.connect</a></em>. Current connection 
+settings are saved in <em>$LOCATION/vector_map/dbln</em>.  
+
+<h2>EXAMPLES</h2>
+
+<h3>DBF -> PG</h3>
+
+<em>Storing table 'markveggy.dbf' (in current directory) into PostgreSQL
+through ODBC:</em><br>
+
+<div class="code"><pre>
+db.copy from_driver=dbf from_database=$HOME/grassdata/spearfish60/user1/dbf \
+  from_table=markveggy to_driver=pg to_database="host=pgserver,dbname=grass6test" \
+  to_table=markveggy 
+</pre></div>
+
+
+<h3>PG -> DBF</h3>
+
+<div class="code"><pre>
+db.copy from_driver=pg  from_database="host=pgserver.itc.it,dbname=testdb" \
+  from_table=origtable to_driver=dbf \
+  to_database=$HOME/grassdata/spearfish60/user1/dbf to_table=origtable
+</pre></div>
+
+
+<h3>PG -> PG with condition</h3>
+
+<div class="code"><pre>
+db.copy from_driver=pg  from_database="host=localhost,dbname=meteo" \
+  from_table=ukraine to_driver=pg to_database="host=localhost,dbname=meteo" \
+  to_table=selection where="cat < 500" 
+</pre></div>
+
+<h3>DBF -> SQLite</h3>
+
+<div class="code"><pre>
+db.copy from_driver=dbf from_database=$HOME/grassdata/spearfish60/user1/dbf \
+   from_table=ammprv to_driver=sqlite \
+   to_database=$HOME/grassdata/spearfish60/user1/mysqlite.db to_table=ammprv
+
+# convenient viewer:
+sqlitebrowser $HOME/grassdata/spearfish60/user1/mysqlite.db
+</pre></div>
+
+<h3>SQLite -> DBF</h3>
+<div class="code"><pre>
+db.copy from_driver=sqlite from_database=$HOME/grassdata/spearfish60/user1/mysqlite.db \
+   from_table=ammprv to_driver=dbf to_database=$HOME/grassdata/spearfish60/user1/dbf \
+   to_table=ammprv
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em><a HREF="v.db.connect.html">v.db.connect</a>,
+<a HREF="db.drivers.html">db.drivers</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="v.clean.html">v.clean</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-irst, Trento, Italy
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.copy/db.copy.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.createdb
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.createdb/Makefile
===================================================================
--- grass/trunk/db/db.createdb/Makefile	                        (rev 0)
+++ grass/trunk/db/db.createdb/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.createdb
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.createdb/createdb.c (from rev 34541, grass/trunk/db/base/createdb.c)
===================================================================
--- grass/trunk/db/db.createdb/createdb.c	                        (rev 0)
+++ grass/trunk/db/db.createdb/createdb.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,79 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.createdb
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
+ * PURPOSE:      create a new empty database
+ * COPYRIGHT:    (C) 2002-2006 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 <stdlib.h>
+#include <grass/dbmi.h>
+#include <grass/gis.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+
+
+struct
+{
+    char *driver, *database;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+
+
+int main(int argc, char **argv)
+{
+    dbDriver *driver;
+    dbHandle handle;
+    int stat;
+
+    parse_command_line(argc, argv);
+
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL)
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+
+    db_init_handle(&handle);
+    db_set_handle(&handle, parms.database, NULL);
+    stat = db_create_database(driver, &handle);
+    db_shutdown_driver(driver);
+
+    exit(stat == DB_OK ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *database;
+    struct GModule *module;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+    driver->required = YES;
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    database->required = YES;
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, SQL");
+    module->description = _("Creates an empty database.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    parms.driver = driver->answer;
+    parms.database = database->answer;
+}


Property changes on: grass/trunk/db/db.createdb/createdb.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.createdb/db.createdb.html (from rev 34541, grass/trunk/db/base/db.createdb.html)
===================================================================
--- grass/trunk/db/db.createdb/db.createdb.html	                        (rev 0)
+++ grass/trunk/db/db.createdb/db.createdb.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,39 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.createdb</em> allows the user to create a new empty database through
+different drivers. A working database connection needs to be established.  
+
+<h2>EXAMPLE</h2>
+
+<em>Create a new PostgreSQL database (if PostgreSQL connection is established
+through odbc driver)</em><br>
+
+<div class="code"><pre>
+db.createdb driver=odbc database=grass60test
+</pre></div>
+
+<p>
+
+<em>Create a new PostgreSQL database (if PostgreSQL connection is established
+through pg driver)</em><br>
+<div class="code"><pre>
+db.createdb driver=pg database='host=pgserver.itc.it,dbname=grass60test'
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a HREF="db.columns.html">db.columns</a>,
+<a HREF="db.describe.html">db.describe</a>,
+<a HREF="db.drivers.html">db.drivers</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.createdb/db.createdb.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.databases
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.databases/Makefile
===================================================================
--- grass/trunk/db/db.databases/Makefile	                        (rev 0)
+++ grass/trunk/db/db.databases/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.databases
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.databases/databases.c (from rev 34541, grass/trunk/db/base/databases.c)
===================================================================
--- grass/trunk/db/db.databases/databases.c	                        (rev 0)
+++ grass/trunk/db/db.databases/databases.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,99 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.databases
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
+ * PURPOSE:      lists all databases for a given driver
+ * COPYRIGHT:    (C) 2002-2006 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 <stdlib.h>
+#include <grass/dbmi.h>
+#include <grass/gis.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+
+
+struct
+{
+    char *driver;
+    char *location;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+
+
+int main(int argc, char **argv)
+{
+    dbDriver *driver;
+    dbHandle *handles;
+    dbString locations;
+    int nlocs = 0;
+    int count, i;
+
+    db_init_string(&locations);
+    parse_command_line(argc, argv);
+
+    if (parms.location) {
+	db_set_string(&locations, parms.location);
+	nlocs = 1;
+    }
+
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL)
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+
+    if (db_list_databases(driver, &locations, nlocs, &handles, &count) !=
+	DB_OK)
+	G_fatal_error(_("Unable to list databases"));
+
+    db_shutdown_driver(driver);
+
+    for (i = 0; i < count; i++) {
+	fprintf(stdout, "%s", db_get_handle_dbname(&handles[i]));
+	fprintf(stdout, "\n");
+    }
+
+    exit(EXIT_SUCCESS);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *location;
+    struct GModule *module;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+
+    location = G_define_option();
+    location->key = "location";
+    location->type = TYPE_STRING;
+    location->required = NO;
+    location->multiple = YES;
+    location->description = _("Location name");
+
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, SQL");
+    module->description =
+	_("List all databases for a given driver and location.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    parms.driver = driver->answer;
+    parms.location = location->answer;
+}


Property changes on: grass/trunk/db/db.databases/databases.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.databases/db.databases.html (from rev 34541, grass/trunk/db/base/db.databases.html)
===================================================================
--- grass/trunk/db/db.databases/db.databases.html	                        (rev 0)
+++ grass/trunk/db/db.databases/db.databases.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,20 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.databases</em> lists all databases for a given driver. Supported drivers
+are dbf, shp, odbc and pg.
+
+<h2>SEE ALSO</h2>
+
+<em><a HREF="db.columns.html">db.columns</a>,
+<a HREF="db.describe.html">db.describe</a>,
+<a HREF="db.drivers.html">db.drivers</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.databases/db.databases.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.describe
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.describe/Makefile
===================================================================
--- grass/trunk/db/db.describe/Makefile	                        (rev 0)
+++ grass/trunk/db/db.describe/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.describe
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.describe/db.describe.html (from rev 34541, grass/trunk/db/base/db.describe.html)
===================================================================
--- grass/trunk/db/db.describe/db.describe.html	                        (rev 0)
+++ grass/trunk/db/db.describe/db.describe.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,58 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.describe</em> displays table information. If parameter <b>-c</b> is used 
+ only column names instead of full column descriptions is given. 
+
+<h2>NOTE</h2>
+
+If parameters for database connection are already set with 
+<a HREF="db.connect.html">db.connect</a>, they are taken as default values and
+do not need to be spcified each time.
+ 
+<h2>EXAMPLE</h2>
+
+<div class="code"><pre>
+db.describe -c table=roads database='$GISDBASE/$LOCATION_NAME/PERMANENT/dbf/' \
+            driver=dbf
+ncols:2
+Column 1:cat:INTEGER:11
+Column 2:label:CHARACTER:43
+</pre></div>
+
+<div class="code"><pre>
+db.describe table=roads database='$GISDBASE/$LOCATION_NAME/PERMANENT/dbf/' \
+            driver=dbf
+table:roads
+description:
+insert:yes
+delete:yes
+ncols:2
+
+column:cat
+description:
+type:INTEGER
+len:11
+scale:0
+precision:10
+default:
+nullok:yes
+select:yes
+update:yes
+[...]
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a HREF="db.columns.html">db.columns</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.describe/db.describe.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.describe/describe.c (from rev 34541, grass/trunk/db/base/describe.c)
===================================================================
--- grass/trunk/db/db.describe/describe.c	                        (rev 0)
+++ grass/trunk/db/db.describe/describe.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,135 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.describe
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>,
+ *               Markus Neteler <neteler itc.it>,
+ *               Stephan Holl
+ * PURPOSE:      Displays table information
+ * 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 <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+
+struct
+{
+    char *driver, *database, *table;
+    int printcolnames;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+
+
+int main(int argc, char **argv)
+{
+    dbDriver *driver;
+    dbHandle handle;
+    dbTable *table;
+    dbString table_name;
+    int col, ncols, nrows;
+    dbColumn *column;
+    char buf[1024];
+    dbString stmt;
+
+    parse_command_line(argc, argv);
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL)
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+
+    db_init_handle(&handle);
+    db_set_handle(&handle, parms.database, NULL);
+    if (db_open_database(driver, &handle) != DB_OK)
+	G_fatal_error(_("Unable to open database <%s>"), parms.database);
+
+    db_init_string(&table_name);
+    db_set_string(&table_name, parms.table);
+
+    if (db_describe_table(driver, &table_name, &table) != DB_OK)
+	G_fatal_error(_("Unable to describe table <%s>"), table_name);
+
+    if (!parms.printcolnames)
+	print_table_definition(driver, table);
+    else {
+	ncols = db_get_table_number_of_columns(table);
+
+	db_init_string(&stmt);
+	sprintf(buf, "select * from %s", db_get_table_name(table));
+	db_set_string(&stmt, buf);
+	nrows = db_get_table_number_of_rows(driver, &stmt);
+	fprintf(stdout, "ncols: %d\n", ncols);
+	fprintf(stdout, "nrows: %d\n", nrows);
+	for (col = 0; col < ncols; col++) {
+	    column = db_get_table_column(table, col);
+	    fprintf(stdout, "Column %d: %s:%s:%d\n", (col + 1),
+		    db_get_column_name(column),
+		    db_sqltype_name(db_get_column_sqltype(column)),
+		    db_get_column_length(column));
+	}
+    }
+
+    db_close_database(driver);
+    db_shutdown_driver(driver);
+
+    exit(EXIT_SUCCESS);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *database, *table;
+    struct Flag *cols, *tdesc;
+    struct GModule *module;
+    const char *drv, *db;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    cols = G_define_flag();
+    cols->key = 'c';
+    cols->description = _("Print column names only instead "
+			  "of full column descriptions");
+
+    tdesc = G_define_flag();
+    tdesc->key = 't';
+    tdesc->description = _("Print table structure");
+
+    table = G_define_standard_option(G_OPT_DB_TABLE);
+    table->required = YES;
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+    if ((drv = db_get_default_driver_name()))
+      driver->answer = (char *) drv;
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    if ((db = db_get_default_database_name()))
+	database->answer = (char *) db;
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, attribute table");
+    module->description = _("Describes a table in detail.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    parms.driver = driver->answer;
+    parms.database = database->answer;
+    parms.table = table->answer;
+    parms.printcolnames = cols->answer;
+}


Property changes on: grass/trunk/db/db.describe/describe.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.describe/local_proto.h (from rev 34541, grass/trunk/db/base/local_proto.h)
===================================================================
--- grass/trunk/db/db.describe/local_proto.h	                        (rev 0)
+++ grass/trunk/db/db.describe/local_proto.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,8 @@
+#ifndef __LOCAL_PROTO_H__
+#define __LOCAL_PROTO_H__
+
+int print_priv(char *, int);
+int print_column_definition(dbColumn *);
+int print_table_definition(dbDriver *, dbTable *);
+
+#endif /* __LOCAL_PROTO_H__ */


Property changes on: grass/trunk/db/db.describe/local_proto.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.describe/printtab.c (from rev 34541, grass/trunk/db/base/printtab.c)
===================================================================
--- grass/trunk/db/db.describe/printtab.c	                        (rev 0)
+++ grass/trunk/db/db.describe/printtab.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,78 @@
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include "local_proto.h"
+#include <grass/glocale.h>
+
+int print_table_definition(dbDriver * driver, dbTable * table)
+{
+    int ncols, col, nrows;
+    dbColumn *column;
+    char buf[1024];
+    dbString stmt;
+
+    fprintf(stdout, "table:%s\n", db_get_table_name(table));
+    fprintf(stdout, "description:%s\n", db_get_table_description(table));
+    print_priv("insert", db_get_table_insert_priv(table));
+    print_priv("delete", db_get_table_delete_priv(table));
+
+    ncols = db_get_table_number_of_columns(table);
+
+    db_init_string(&stmt);
+    sprintf(buf, "select * from %s", db_get_table_name(table));
+    db_set_string(&stmt, buf);
+    nrows = db_get_table_number_of_rows(driver, &stmt);
+    fprintf(stdout, "ncols:%d\n", ncols);
+    fprintf(stdout, "nrows:%d\n", nrows);
+    for (col = 0; col < ncols; col++) {
+	column = db_get_table_column(table, col);
+	fprintf(stdout, "\n");
+	print_column_definition(column);
+    }
+
+    return 0;
+}
+
+int print_column_definition(dbColumn * column)
+{
+    dbString value_string;
+
+    fprintf(stdout, "column:%s\n", db_get_column_name(column));
+    fprintf(stdout, "description:%s\n", db_get_column_description(column));
+    fprintf(stdout, "type:%s\n",
+	    db_sqltype_name(db_get_column_sqltype(column)));
+    fprintf(stdout, "len:%d\n", db_get_column_length(column));
+    fprintf(stdout, "scale:%d\n", db_get_column_scale(column));
+    fprintf(stdout, "precision:%d\n", db_get_column_precision(column));
+    fprintf(stdout, "default:");
+    if (db_test_column_has_default_value(column)) {
+	db_init_string(&value_string);
+	db_convert_column_default_value_to_string(column, &value_string);
+	fprintf(stdout, "%s", db_get_string(&value_string));
+    }
+    fprintf(stdout, "\n");
+    fprintf(stdout, "nullok:%s\n",
+	    db_test_column_null_allowed(column) ? "yes" : "no");
+    print_priv("select", db_get_column_select_priv(column));
+    print_priv("update", db_get_column_update_priv(column));
+
+    return 0;
+}
+
+int print_priv(char *label, int priv)
+{
+    fprintf(stdout, "%s:", label);
+    switch (priv) {
+    case DB_GRANTED:
+	fprintf(stdout, "yes");
+	break;
+    case DB_NOT_GRANTED:
+	fprintf(stdout, "no");
+	break;
+    default:
+	fprintf(stdout, "?");
+	break;
+    }
+    fprintf(stdout, "\n");
+
+    return 0;
+}


Property changes on: grass/trunk/db/db.describe/printtab.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.drivers
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.drivers/Makefile
===================================================================
--- grass/trunk/db/db.drivers/Makefile	                        (rev 0)
+++ grass/trunk/db/db.drivers/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.drivers
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.drivers/db.drivers.html (from rev 34541, grass/trunk/db/base/db.drivers.html)
===================================================================
--- grass/trunk/db/db.drivers/db.drivers.html	                        (rev 0)
+++ grass/trunk/db/db.drivers/db.drivers.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,19 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.drivers</em> lists all database drivers. 
+
+<h2>SEE ALSO</h2>
+<em><a HREF="db.connect.html">db.connect</a>,
+<a HREF="db.describe.html">db.describe</a>,
+<a HREF="db.drivers.html">db.drivers</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.drivers/db.drivers.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.drivers/drivers.c (from rev 34541, grass/trunk/db/base/drivers.c)
===================================================================
--- grass/trunk/db/db.drivers/drivers.c	                        (rev 0)
+++ grass/trunk/db/db.drivers/drivers.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,81 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.drivers
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>, Stephan Holl
+ * PURPOSE:      lists all database drivers
+ * COPYRIGHT:    (C) 2002-2006 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 <stdlib.h>
+#include <grass/codes.h>
+#include <grass/dbmi.h>
+#include <grass/codes.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+
+struct
+{
+    int f;
+} parms;
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+
+
+int main(int argc, char **argv)
+{
+    dbDbmscap *list, *p;
+
+    parse_command_line(argc, argv);
+
+    list = db_read_dbmscap();
+    if (list == NULL) {
+	G_message(_("Error trying to read dbmscap file\n"));
+	exit(EXIT_FAILURE);
+    }
+
+    for (p = list; p; p = p->next) {
+	fprintf(stdout, "%s", p->driverName);
+	if (parms.f)
+	    fprintf(stdout, ":%s", p->comment);
+	fprintf(stdout, "\n");
+    }
+
+    exit(EXIT_SUCCESS);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Flag *full, *print;
+    struct GModule *module;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    full = G_define_flag();
+    full->key = 'f';
+    full->description = _("Full output");
+
+    print = G_define_flag();
+    print->key = 'p';
+    print->description = _("print drivers and exit");
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, attribute table");
+    module->description = _("List all database drivers.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    parms.f = full->answer;
+}


Property changes on: grass/trunk/db/db.drivers/drivers.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.dropdb
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.dropdb/Makefile
===================================================================
--- grass/trunk/db/db.dropdb/Makefile	                        (rev 0)
+++ grass/trunk/db/db.dropdb/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.dropdb
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.dropdb/db.dropdb.html (from rev 34541, grass/trunk/db/base/db.dropdb.html)
===================================================================
--- grass/trunk/db/db.dropdb/db.dropdb.html	                        (rev 0)
+++ grass/trunk/db/db.dropdb/db.dropdb.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,23 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.dropdb</em> removes an existing database. 
+
+<h2>EXAMPLE</h2>
+
+<em>Remove an existing database connected through odbc</em><br>
+<b>db.dropdb driver=</b><em>odbc</em> <b>database=</b><em>g51test</em>
+
+<h2>SEE ALSO</h2>
+<em>
+<a HREF="db.describe.html">db.describe</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.dropdb/db.dropdb.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.dropdb/dropdb.c (from rev 34541, grass/trunk/db/base/dropdb.c)
===================================================================
--- grass/trunk/db/db.dropdb/dropdb.c	                        (rev 0)
+++ grass/trunk/db/db.dropdb/dropdb.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,79 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.dropdb
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>, Stephan Holl
+ * PURPOSE:      removes an existing database
+ * COPYRIGHT:    (C) 2002-2006 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 <stdlib.h>
+#include <grass/dbmi.h>
+#include <grass/gis.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+
+
+struct
+{
+    char *driver, *database;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+
+
+int main(int argc, char **argv)
+{
+    dbDriver *driver;
+    dbHandle handle;
+    int stat;
+
+    parse_command_line(argc, argv);
+
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL)
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+
+    db_init_handle(&handle);
+    db_set_handle(&handle, parms.database, NULL);
+    stat = db_delete_database(driver, &handle);
+    db_shutdown_driver(driver);
+
+    exit(stat == DB_OK ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *database;
+    struct GModule *module;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+    driver->required = YES;
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    database->required = YES;
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, SQL");
+    module->description = _("Removes a database.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    parms.driver = driver->answer;
+    parms.database = database->answer;
+}


Property changes on: grass/trunk/db/db.dropdb/dropdb.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.droptable
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.droptable/Makefile
===================================================================
--- grass/trunk/db/db.droptable/Makefile	                        (rev 0)
+++ grass/trunk/db/db.droptable/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.droptable
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.droptable/db.droptable.html (from rev 34541, grass/trunk/db/base/db.droptable.html)
===================================================================
--- grass/trunk/db/db.droptable/db.droptable.html	                        (rev 0)
+++ grass/trunk/db/db.droptable/db.droptable.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,39 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.droptable</em> removes an existing database table. 
+
+<h2>NOTE</h2>
+
+If parameters for database connection are already set with 
+<a HREF="db.connect.html">db.connect</a>, they are taken as default values and
+do not need to be spcified each time.
+
+<h2>EXAMPLE</h2>
+
+<em>Remove an existing attribute table connected through odbc</em><br>
+<div class="code"><pre>
+db.droptable table=test driver=odbc database=g60test
+</pre></div>
+
+<p>
+
+<em>Remove attribute table with if database connection is set with db.connect</em><br>
+<div class="code"><pre>
+db.droptable table=test
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a HREF="db.describe.html">db.describe</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.droptable/db.droptable.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.droptable/droptable.c (from rev 34541, grass/trunk/db/base/droptable.c)
===================================================================
--- grass/trunk/db/db.droptable/droptable.c	                        (rev 0)
+++ grass/trunk/db/db.droptable/droptable.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,87 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.droptable
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>, Stephan Holl
+ * PURPOSE:      removes an existing database table
+ * COPYRIGHT:    (C) 2002-2006 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 <stdlib.h>
+#include <grass/dbmi.h>
+#include <grass/gis.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+
+
+struct
+{
+    char *driver, *database, *table;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+
+
+int main(int argc, char **argv)
+{
+    dbDriver *driver;
+    dbHandle handle;
+    dbString table;
+    int stat;
+
+    parse_command_line(argc, argv);
+
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL)
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+
+    db_init_handle(&handle);
+    db_set_handle(&handle, parms.database, NULL);
+
+    db_init_string(&table);
+    db_set_string(&table, parms.table);
+    stat = db_open_database(driver, &handle);
+    if (stat == DB_OK)
+	stat = db_drop_table(driver, &table);
+    db_shutdown_driver(driver);
+
+    exit(stat == DB_OK ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *database, *table;
+    struct GModule *module;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    table = G_define_standard_option(G_OPT_DB_DRIVER);
+    table->required = YES;
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, SQL");
+    module->description = _("Removes a table from database.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    parms.driver = driver->answer;
+    parms.database = database->answer;
+    parms.table = table->answer;
+}


Property changes on: grass/trunk/db/db.droptable/droptable.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.execute
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.execute/Makefile
===================================================================
--- grass/trunk/db/db.execute/Makefile	                        (rev 0)
+++ grass/trunk/db/db.execute/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.execute
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.execute/db.execute.html (from rev 34541, grass/trunk/db/base/db.execute.html)
===================================================================
--- grass/trunk/db/db.execute/db.execute.html	                        (rev 0)
+++ grass/trunk/db/db.execute/db.execute.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,115 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.execute</em> allows the user to execute SQL statements.  
+
+<h2>NOTES</h2>
+
+<em>db.execute</em> only executes SQL statements and does not return 
+any data. If you need data returned from the database, use <em>db.select</em>.
+<P>
+If parameters for database connection are already set with 
+<a HREF="db.connect.html">db.connect</a>, they are taken as default values and
+do not need to be specified each time.
+<P>
+If you have a large number of SQL commands to process, it is much much faster
+to place all the SQL statements into a text file and use <em>db.execute</em>'s
+<b>input</b> file parameter than it is to process each statement individually
+in a loop. If multiple instruction lines are given, each SQL line must end
+with a semicolon.
+<p>
+Please see the individual <a href="sql.html">sql driver</a> pages for how to create
+a new database.
+
+<h2>EXAMPLES</h2>
+
+<em>Create a new table with columns 'cat' and 'soiltype':</em><br>
+<div class="code"><pre>
+echo 'create table soils (cat integer, soiltype varchar(10) )' | db.execute
+</pre></div>
+
+<p>
+<em>Create a new table using a file with SQL statements:</em><br>
+<div class="code"><pre>
+db.execute driver=odbc database=g60test input=file.sql
+</pre></div>
+
+<P>
+<em>Insert new row into attribute table:</em><br>
+<div class="code"><pre>
+echo "INSERT INTO nobugs (id,name,east_gb,north_gb) values (30,'Ala',1657340,5072301)" | db.execute
+</pre></div>
+
+<P>
+<em>Update attribute entries to new value based on SQL rule:</em><br>
+<div class="code"><pre>
+echo "UPDATE roads SET travelcost=5 WHERE cat=1" | db.execute
+</pre></div>
+
+<P>
+<em>Update attribute entries to new value based on SQL rule:</em><br>
+<div class="code"><pre>
+echo "UPDATE dourokukan SET testc=50 WHERE testc is NULL" | db.execute
+</pre></div>
+
+<P>
+<em>Delete selected rows from attribute table:</em><br>
+<div class="code"><pre>
+echo "DELETE FROM gsod_stationlist WHERE latitude < -91" | db.execute
+</pre></div>
+
+<P>
+<em>Add new column to attribute table:</em><br>
+<div class="code"><pre>
+echo "ALTER TABLE roads ADD COLUMN length double" | db.execute
+</pre></div>
+
+<P>
+<em>Column type conversion - update new column from existing column (all drivers except for DBF):</em><br>
+<div class="code"><pre>
+# 'z_value' is varchar and 'z' is double precision:
+echo "update geodetic_pts SET z = CAST(z_value AS numeric)" | db.execute
+</pre></div>
+
+<P>
+<em>Drop column from attribute table:</em><br>
+<div class="code"><pre>
+echo "ALTER TABLE roads DROP COLUMN length" | db.execute
+</pre></div>
+
+<P>
+<em>Drop table (not supported by all drivers)</em><br>
+<div class="code"><pre>
+echo "DROP TABLE fmacopy" | db.execute
+</pre></div>
+
+<p>
+<em>Update attribute with multiple SQL instructions in file (e.g., file.sql,
+    instruction line must end with a semicolon):</em><br>
+<div class="code"><pre>
+UPDATE roads SET travelcost=5 WHERE cat=1;
+UPDATE roads SET travelcost=2 WHERE cat=2;
+ 
+cat file.sql | db.execute
+</pre></div>
+
+<P>
+<em>Join table 'myroads' into table 'extratab' based on common 'cat' column values (not supported by DBF driver):<br>
+<div class="code"><pre>
+echo "UPDATE extratab SET names=(SELECT label FROM myroads WHERE extratab.cat=myroads.cat);" | db.execute
+</pre></div>
+
+<h2>SEE ALSO</h2>
+<em><a HREF="db.columns.html">db.columns</a>,
+<a HREF="db.describe.html">db.describe</a>,
+<a HREF="db.drivers.html">db.drivers</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.select.html">db.select</a>,
+<a HREF="db.tables.html">db.tables</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+CERL
+
+<p><i>Last changed: $Date$</i></p>


Property changes on: grass/trunk/db/db.execute/db.execute.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.execute/execute.c (from rev 34541, grass/trunk/db/base/execute.c)
===================================================================
--- grass/trunk/db/db.execute/execute.c	                        (rev 0)
+++ grass/trunk/db/db.execute/execute.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,176 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.execute
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Huidae Cho <grass4u gmail.com>, Glynn Clements <glynn gclements.plus.com>, Hamish Bowman <hamish_nospam yahoo.com>, Markus Neteler <neteler itc.it>, Stephan Holl
+ * PURPOSE:      process one non-select sql statement
+ * COPYRIGHT:    (C) 2002-2006 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 <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+
+
+struct
+{
+    char *driver, *database, *input;
+    int i;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+static int get_stmt(FILE *, dbString *);
+static int stmt_is_empty(dbString *);
+
+
+int main(int argc, char **argv)
+{
+    dbString stmt;
+    dbDriver *driver;
+    dbHandle handle;
+    int ret;
+    FILE *fd;
+    int error = 0;
+
+    parse_command_line(argc, argv);
+
+    if (parms.input) {
+	fd = fopen(parms.input, "r");
+	if (fd == NULL) {
+	    perror(parms.input);
+	    exit(EXIT_FAILURE);
+	}
+    }
+    else
+	fd = stdin;
+
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL) {
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+    }
+
+    db_init_handle(&handle);
+    db_set_handle(&handle, parms.database, NULL);
+    if (db_open_database(driver, &handle) != DB_OK)
+	G_fatal_error(_("Unable to open database <%s>"), parms.database);
+
+    while (get_stmt(fd, &stmt)) {
+	if (!stmt_is_empty(&stmt)) {
+	    G_debug(3, "sql: %s", db_get_string(&stmt));
+
+	    ret = db_execute_immediate(driver, &stmt);
+
+	    if (ret != DB_OK) {
+		if (parms.i) {	/* ignore SQL errors */
+		    G_warning(_("Error while executing: '%s'"),
+			      db_get_string(&stmt));
+		    error++;
+		}
+		else
+		    G_fatal_error(_("Error while executing: '%s'"),
+				  db_get_string(&stmt));
+	    }
+	}
+    }
+
+    db_close_database(driver);
+    db_shutdown_driver(driver);
+
+    exit(error ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *database, *input;
+    struct Flag *i;
+    struct GModule *module;
+    const char *drv, *db;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, attribute table, SQL");
+    module->description = _("Executes any SQL statement.");
+
+    input = G_define_standard_option(G_OPT_F_INPUT);
+    input->required = NO;
+    input->description = _("Name of file containing SQL statements");
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+    if ((drv = db_get_default_driver_name()))
+	driver->answer = (char *) drv;
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    if ((db = db_get_default_database_name()))
+	database->answer = (char *) db;
+
+    i = G_define_flag();
+    i->key = 'i';
+    i->description = _("Ignore SQL errors and continue");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_SUCCESS);
+
+    parms.driver = driver->answer;
+    parms.database = database->answer;
+    parms.input = input->answer;
+    parms.i = i->answer;
+}
+
+
+static int get_stmt(FILE * fd, dbString * stmt)
+{
+    char buf[4000], buf2[4000], buf3[7];
+    int len, row = 0;
+
+    db_init_string(stmt);
+
+    while (fgets(buf, 4000, fd) != NULL) {
+	strcpy(buf2, buf);
+	G_chop(buf2);
+	len = strlen(buf2);
+
+	strncpy(buf3, buf2, 6);
+	if (G_strcasecmp(buf3, "select") == 0)
+	    G_fatal_error(_("Use db.select for SELECT SQL statements"));
+
+	len = strlen(buf2);
+	if (buf2[len - 1] == ';') {	/* end of statement */
+	    buf2[len - 1] = 0;	/* truncate ';' */
+	    db_append_string(stmt, buf2);	/* append truncated */
+	    return 1;
+	}
+	else {
+	    db_append_string(stmt, buf);	/* append not truncated string (\n may be part of value) */
+	}
+	row++;
+    }
+
+    if (row > 0)
+	return 1;
+
+    return 0;
+}
+
+
+static int stmt_is_empty(dbString * stmt)
+{
+    char dummy[2];
+
+    return (sscanf(db_get_string(stmt), "%1s", dummy) != 1);
+}


Property changes on: grass/trunk/db/db.execute/execute.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.select
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.select/Makefile
===================================================================
--- grass/trunk/db/db.select/Makefile	                        (rev 0)
+++ grass/trunk/db/db.select/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.select
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.select/db.select.html (from rev 34541, grass/trunk/db/base/db.select.html)
===================================================================
--- grass/trunk/db/db.select/db.select.html	                        (rev 0)
+++ grass/trunk/db/db.select/db.select.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,69 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.select</em> prints result of selection from database 
+based on SQL statement read from input file or from standard input 
+to standard output.
+
+<h2>NOTE</h2>
+
+If parameters for database connection are already set with 
+<a HREF="db.connect.html">db.connect</a>, they are taken as default values and
+do not need to be spcified each time. Output will be displayed to stdout or can
+be directed to a file.
+
+<h2>EXAMPLES</h2>
+
+<div class="code"><pre>
+echo "select * from roads" | db.select 
+or
+ cat file.sql | db.select 
+or
+ db.select input=file.sql
+</pre></div>
+
+<p>
+
+<em>Select all from table roads</em><br>
+<div class="code"><pre>
+db.select -c driver=odbc database=g51test table=roads input=file.sql > result.csv
+</pre></div>
+
+<P>
+
+<em>Select some string attribute, exclude others:</em><br>
+<div class="code"><pre>
+echo "SELECT * FROM archsites WHERE str1 &lt;&gt; 'No Name'" | db.select
+</pre></div>
+
+<P>
+
+<em>Select some string attribute with ZERO length:</em><br>
+<div class="code"><pre>
+echo "SELECT * FROM archsites WHERE str1 IS NULL" | db.select
+</pre></div>
+
+<P>
+
+<em>Select coordinates from PostGIS table:</em><br>
+<div class="code"><pre>
+echo "SELECT x(geo),y(geo) FROM localizzazione" | db.select
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em><a HREF="sql.html">GRASS SQL interface</a>,
+<a HREF="db.connect.html">db.connect</a>,
+<a HREF="db.describe.html">db.describe</a>,
+<a HREF="db.drivers.html">db.drivers</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.tables.html">db.tables</a></em>
+
+
+<h2>AUTHOR</h2>
+?<br>
+Modifications: Radim Blazek, ITC-Irst, Trento, Italy
+
+<p><i>Last changed: $Date$</i>
+


Property changes on: grass/trunk/db/db.select/db.select.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.select/local_proto.h (from rev 34541, grass/trunk/db/base/local_proto.h)
===================================================================
--- grass/trunk/db/db.select/local_proto.h	                        (rev 0)
+++ grass/trunk/db/db.select/local_proto.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,8 @@
+#ifndef __LOCAL_PROTO_H__
+#define __LOCAL_PROTO_H__
+
+int print_priv(char *, int);
+int print_column_definition(dbColumn *);
+int print_table_definition(dbDriver *, dbTable *);
+
+#endif /* __LOCAL_PROTO_H__ */


Property changes on: grass/trunk/db/db.select/local_proto.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.select/printtab.c (from rev 34541, grass/trunk/db/base/printtab.c)
===================================================================
--- grass/trunk/db/db.select/printtab.c	                        (rev 0)
+++ grass/trunk/db/db.select/printtab.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,78 @@
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include "local_proto.h"
+#include <grass/glocale.h>
+
+int print_table_definition(dbDriver * driver, dbTable * table)
+{
+    int ncols, col, nrows;
+    dbColumn *column;
+    char buf[1024];
+    dbString stmt;
+
+    fprintf(stdout, "table:%s\n", db_get_table_name(table));
+    fprintf(stdout, "description:%s\n", db_get_table_description(table));
+    print_priv("insert", db_get_table_insert_priv(table));
+    print_priv("delete", db_get_table_delete_priv(table));
+
+    ncols = db_get_table_number_of_columns(table);
+
+    db_init_string(&stmt);
+    sprintf(buf, "select * from %s", db_get_table_name(table));
+    db_set_string(&stmt, buf);
+    nrows = db_get_table_number_of_rows(driver, &stmt);
+    fprintf(stdout, "ncols:%d\n", ncols);
+    fprintf(stdout, "nrows:%d\n", nrows);
+    for (col = 0; col < ncols; col++) {
+	column = db_get_table_column(table, col);
+	fprintf(stdout, "\n");
+	print_column_definition(column);
+    }
+
+    return 0;
+}
+
+int print_column_definition(dbColumn * column)
+{
+    dbString value_string;
+
+    fprintf(stdout, "column:%s\n", db_get_column_name(column));
+    fprintf(stdout, "description:%s\n", db_get_column_description(column));
+    fprintf(stdout, "type:%s\n",
+	    db_sqltype_name(db_get_column_sqltype(column)));
+    fprintf(stdout, "len:%d\n", db_get_column_length(column));
+    fprintf(stdout, "scale:%d\n", db_get_column_scale(column));
+    fprintf(stdout, "precision:%d\n", db_get_column_precision(column));
+    fprintf(stdout, "default:");
+    if (db_test_column_has_default_value(column)) {
+	db_init_string(&value_string);
+	db_convert_column_default_value_to_string(column, &value_string);
+	fprintf(stdout, "%s", db_get_string(&value_string));
+    }
+    fprintf(stdout, "\n");
+    fprintf(stdout, "nullok:%s\n",
+	    db_test_column_null_allowed(column) ? "yes" : "no");
+    print_priv("select", db_get_column_select_priv(column));
+    print_priv("update", db_get_column_update_priv(column));
+
+    return 0;
+}
+
+int print_priv(char *label, int priv)
+{
+    fprintf(stdout, "%s:", label);
+    switch (priv) {
+    case DB_GRANTED:
+	fprintf(stdout, "yes");
+	break;
+    case DB_NOT_GRANTED:
+	fprintf(stdout, "no");
+	break;
+    default:
+	fprintf(stdout, "?");
+	break;
+    }
+    fprintf(stdout, "\n");
+
+    return 0;
+}


Property changes on: grass/trunk/db/db.select/printtab.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.select/select.c (from rev 34541, grass/trunk/db/base/select.c)
===================================================================
--- grass/trunk/db/db.select/select.c	                        (rev 0)
+++ grass/trunk/db/db.select/select.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,291 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.select
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Huidae Cho <grass4u gmail.com>, Glynn Clements <glynn gclements.plus.com>, Jachym Cepicky <jachym les-ejk.cz>, Markus Neteler <neteler itc.it>, Stephan Holl
+ * PURPOSE:      process one sql select statement
+ * COPYRIGHT:    (C) 2002-2007 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 <stdlib.h>
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+
+struct
+{
+    char *driver, *database, *table, *sql, *fs, *vs, *nv, *input;
+    int c, d, h, test_only;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+static int sel(dbDriver *, dbString *);
+static int get_stmt(FILE *, dbString *);
+static int stmt_is_empty(dbString *);
+
+
+int main(int argc, char **argv)
+{
+    dbString stmt;
+    dbDriver *driver;
+    dbHandle handle;
+    int stat;
+    FILE *fd;
+
+    parse_command_line(argc, argv);
+
+    if (parms.input) {
+	fd = fopen(parms.input, "r");
+	if (fd == NULL) {
+	    perror(parms.input);
+	    exit(ERROR);
+	}
+    }
+    else
+	fd = stdin;
+
+    db_init_string(&stmt);
+
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL) {
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+    }
+
+    db_init_handle(&handle);
+    db_set_handle(&handle, parms.database, NULL);
+    if (db_open_database(driver, &handle) != DB_OK)
+	G_fatal_error(_("Unable to open database <%s>"), parms.database);
+
+    if (parms.sql) {
+	db_set_string(&stmt, parms.sql);
+	stat = sel(driver, &stmt);
+    }
+    else if (parms.table) {
+	db_set_string(&stmt, "select * from ");
+	db_append_string(&stmt, parms.table);
+	stat = sel(driver, &stmt);
+    }
+    else {			/* read stdin */
+	stat = OK;
+	while (stat == OK && get_stmt(fd, &stmt)) {
+	    if (!stmt_is_empty(&stmt))
+		stat = sel(driver, &stmt);
+	}
+    }
+
+    db_close_database(driver);
+    db_shutdown_driver(driver);
+
+    exit(stat);
+}
+
+
+static int sel(dbDriver * driver, dbString * stmt)
+{
+    dbCursor cursor;
+    dbTable *table;
+    dbColumn *column;
+    dbValue *value;
+    dbString value_string;
+    int col, ncols;
+    int more;
+
+    if (db_open_select_cursor(driver, stmt, &cursor, DB_SEQUENTIAL) != DB_OK)
+	return ERROR;
+    if (parms.test_only)
+	return OK;
+
+    table = db_get_cursor_table(&cursor);
+    ncols = db_get_table_number_of_columns(table);
+    if (parms.d) {
+	for (col = 0; col < ncols; col++) {
+	    column = db_get_table_column(table, col);
+	    print_column_definition(column);
+	}
+
+	return OK;
+    }
+
+    db_init_string(&value_string);
+
+    /* column names if horizontal output */
+    if (parms.h && parms.c) {
+	for (col = 0; col < ncols; col++) {
+	    column = db_get_table_column(table, col);
+	    if (col)
+		fprintf(stdout, "%s", parms.fs);
+	    fprintf(stdout, "%s", db_get_column_name(column));
+	}
+	fprintf(stdout, "\n");
+    }
+
+    /* fetch the data */
+    while (1) {
+	if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK)
+	    return ERROR;
+	if (!more)
+	    break;
+
+	for (col = 0; col < ncols; col++) {
+	    column = db_get_table_column(table, col);
+	    value = db_get_column_value(column);
+	    db_convert_column_value_to_string(column, &value_string);
+	    if (parms.c && !parms.h)
+		fprintf(stdout, "%s%s", db_get_column_name(column), parms.fs);
+	    if (col && parms.h)
+		fprintf(stdout, "%s", parms.fs);
+	    if (parms.nv && db_test_value_isnull(value))
+		fprintf(stdout, "%s", parms.nv);
+	    else
+		fprintf(stdout, "%s", db_get_string(&value_string));
+	    if (!parms.h)
+		fprintf(stdout, "\n");
+	}
+	if (parms.h)
+	    fprintf(stdout, "\n");
+	else if (parms.vs)
+	    fprintf(stdout, "%s\n", parms.vs);
+    }
+
+    return OK;
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *database, *table, *sql, *fs, *vs, *nv, *input;
+    struct Flag *c, *d, *v, *flag_test;
+    struct GModule *module;
+    const char *drv, *db;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    table = G_define_standard_option(G_OPT_DB_TABLE);
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    if ((db = db_get_default_database_name()))
+	database->answer = (char *) db;
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+    if ((drv = db_get_default_driver_name()))
+	driver->answer = (char *) drv;
+
+    sql = G_define_option();
+    sql->key = "sql";
+    sql->type = TYPE_STRING;
+    sql->required = NO;
+    sql->label = _("SQL select statement");
+    sql->description =
+	_("For example: 'select * from rybniky where kapri = 'hodne'");
+
+    fs = G_define_standard_option(G_OPT_F_SEP);
+    fs->description = _("Output field separator");
+
+    vs = G_define_standard_option(G_OPT_F_SEP);
+    vs->key = "vs";
+    vs->description = _("Output vertical record separator");
+    vs->answer = NULL;
+
+    nv = G_define_option();
+    nv->key = "nv";
+    nv->type = TYPE_STRING;
+    nv->required = NO;
+    nv->description = _("Null value indicator");
+
+    input = G_define_standard_option(G_OPT_F_INPUT);
+    input->required = NO;
+    input->description = _("Name of file with sql statement");
+
+    c = G_define_flag();
+    c->key = 'c';
+    c->description = _("Do not include column names in output");
+
+    d = G_define_flag();
+    d->key = 'd';
+    d->description = _("Describe query only (don't run it)");
+
+    v = G_define_flag();
+    v->key = 'v';
+    v->description = _("Vertical output (instead of horizontal)");
+
+    flag_test = G_define_flag();
+    flag_test->key = 't';
+    flag_test->description = _("Only test query, do not execute");
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, attribute table, SQL");
+    module->description = _("Selects data from table.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_SUCCESS);
+
+    parms.driver = driver->answer;
+    parms.database = database->answer;
+    parms.table = table->answer;
+    parms.sql = sql->answer;
+    parms.fs = fs->answer;
+    parms.vs = vs->answer;
+    parms.nv = nv->answer;
+    parms.input = input->answer;
+    if (!c->answer)
+	parms.c = 1;
+    else
+	parms.c = 0;
+    parms.d = d->answer;
+    if (!v->answer)
+	parms.h = 1;
+    else
+	parms.h = 0;
+    parms.test_only = flag_test->answer;
+
+    if (!parms.fs)
+	parms.fs = "";
+    if (parms.input && *parms.input == 0) {
+	G_usage();
+	exit(EXIT_FAILURE);
+    }
+}
+
+
+static int get_stmt(FILE * fd, dbString * stmt)
+{
+    char buf[1024];
+    int n;
+    static int first = 1;
+
+    db_zero_string(stmt);
+
+    /* this is until get_stmt is smart enough to handle multiple stmts */
+    if (!first)
+	return 0;
+    first = 0;
+
+    while ((n = fread(buf, 1, sizeof(buf) - 1, fd)) > 0) {
+	buf[n] = 0;
+	db_append_string(stmt, buf);
+    }
+
+    return 1;
+}
+
+
+static int stmt_is_empty(dbString * stmt)
+{
+    char dummy[2];
+
+    return (sscanf(db_get_string(stmt), "%1s", dummy) != 1);
+}


Property changes on: grass/trunk/db/db.select/select.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/db/db.tables
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/db/db.tables/Makefile
===================================================================
--- grass/trunk/db/db.tables/Makefile	                        (rev 0)
+++ grass/trunk/db/db.tables/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(DBMILIB) $(GISLIB) $(DATETIMELIB)
+DEPENDENCIES = $(GISDEP) $(DBMIDEP)
+
+PGM = db.tables
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Copied: grass/trunk/db/db.tables/db.tables.html (from rev 34541, grass/trunk/db/base/db.tables.html)
===================================================================
--- grass/trunk/db/db.tables/db.tables.html	                        (rev 0)
+++ grass/trunk/db/db.tables/db.tables.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,35 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.tables</em> lists all tables for a given database. 
+
+<h2>NOTE</h2>
+
+If parameters for database connection are already set with 
+<a HREF="db.connect.html">db.connect</a>, they are taken as default values and
+do not need to be spcified each time.
+
+<h2>EXAMPLES</h2>
+
+<em>List all tables if database connection is already set</em><br>
+<div class="code"><pre>
+db.tables -p
+</pre></div>
+
+<p>
+
+<em>List all tables of existing dbf database</em><br>
+<div class="code"><pre>
+db.tables driver=dbf database=/home/user/grassdata/fire/PERMANENT/dbf
+</pre></div>
+
+<h2>SEE ALSO</h2>
+<em><a HREF="db.columns.html">db.columns</a>,
+<a HREF="db.droptable.html">db.droptable</a>,
+<a HREF="db.login.html">db.login</a>,
+<a HREF="db.execute.html">db.execute</a>,
+<a HREF="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+?
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/db/db.tables/db.tables.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/db/db.tables/tables.c (from rev 34541, grass/trunk/db/base/tables.c)
===================================================================
--- grass/trunk/db/db.tables/tables.c	                        (rev 0)
+++ grass/trunk/db/db.tables/tables.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,104 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.tables
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>, Stephan Holl
+ * PURPOSE:      lists all tables for a given database
+ * COPYRIGHT:    (C) 2002-2006 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 <stdlib.h>
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/codes.h>
+#include <grass/glocale.h>
+
+
+struct
+{
+    char *driver, *database;
+    int s;
+} parms;
+
+
+/* function prototypes */
+static void parse_command_line(int, char **);
+
+
+int main(int argc, char **argv)
+{
+    dbDriver *driver;
+    dbHandle handle;
+    dbString *names;
+    int i, count;
+    int system_tables;
+
+    parse_command_line(argc, argv);
+
+    driver = db_start_driver(parms.driver);
+    if (driver == NULL)
+	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
+
+    db_init_handle(&handle);
+    db_set_handle(&handle, parms.database, NULL);
+    if (db_open_database(driver, &handle) != DB_OK)
+	G_fatal_error(_("Unable to open database <%s>"), parms.database);
+
+    system_tables = parms.s;
+    if (db_list_tables(driver, &names, &count, system_tables) != DB_OK)
+	exit(ERROR);
+    for (i = 0; i < count; i++)
+	fprintf(stdout, "%s\n", db_get_string(&names[i]));
+
+    db_close_database(driver);
+    db_shutdown_driver(driver);
+
+    exit(EXIT_SUCCESS);
+}
+
+
+static void parse_command_line(int argc, char **argv)
+{
+    struct Option *driver, *database;
+    struct Flag *p, *s;
+    struct GModule *module;
+    const char *drv, *db;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = db_list_drivers();
+    if ((drv = db_get_default_driver_name()))
+	driver->answer = (char *) drv;
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    if ((db = db_get_default_database_name()))
+	database->answer = (char *) db;
+
+    p = G_define_flag();
+    p->key = 'p';
+    p->description = _("Print tables and exit");
+
+    s = G_define_flag();
+    s->key = 's';
+    s->description = _("System tables instead of user tables");
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("database, attribute table");
+    module->description = _("Lists all tables for a given database.");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_SUCCESS);
+
+    parms.driver = driver->answer;
+    parms.database = database->answer;
+    parms.s = s->answer;
+}


Property changes on: grass/trunk/db/db.tables/tables.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Deleted: grass/trunk/general/g.copy/copy.c
===================================================================
--- grass/trunk/general/g.copy/copy.c	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/general/g.copy/copy.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -1,100 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       cmd
- * AUTHOR(S):    CERL (original contributor)
- *               Radim Blazek <radim.blazek gmail.com>, 
- *               Cedric Shock <cedricgrass shockfamily.net>, 
- *               Huidae Cho <grass4u gmail.com>, 
- *               Glynn Clements <glynn gclements.plus.com>, 
- *               Markus Neteler <neteler itc.it>, 
- *               Martin Landa <landa.martin gmail.com>
- * PURPOSE:      lets users copy database files 
- * COPYRIGHT:    (C) 2003-2007 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 <stdlib.h>
-#include <string.h>
-#include <grass/glocale.h>
-#include <grass/list.h>
-
-int main(int argc, char *argv[])
-{
-    int i, n;
-    const char *mapset;
-    struct GModule *module;
-    struct Option **parm, *p;
-    char *from, *to;
-    int result = EXIT_SUCCESS;
-
-    G_gisinit(argv[0]);
-
-    read_list(0);
-
-    module = G_define_module();
-    module->keywords = _("general, map management");
-    module->description =
-	_("Copies available data files in the user's current mapset "
-	  "search path and location to the appropriate element "
-	  "directories under the user's current mapset.");
-
-    parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
-
-    for (n = 0; n < nlist; n++) {
-	char *str;
-
-	p = parm[n] = G_define_option();
-	p->key = list[n].alias;
-	p->key_desc = "from,to";
-	p->type = TYPE_STRING;
-	p->required = NO;
-	p->multiple = NO;
-	G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
-	p->gisprompt = str;
-	G_asprintf(&str, _("%s file(s) to be copied"), list[n].alias);
-	p->description = str;
-    }
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    for (n = 0; n < nlist; n++) {
-	if (parm[n]->answers == NULL)
-	    continue;
-	i = 0;
-	while (parm[n]->answers[i]) {
-	    from = parm[n]->answers[i++];
-	    to = parm[n]->answers[i++];
-	    mapset = find(n, from, "");
-	    if (!mapset) {
-		G_warning(_("<%s> not found"), from);
-		continue;
-	    }
-	    if (G_strcasecmp(mapset, G_mapset()) == 0 &&
-		G_strcasecmp(from, to) == 0) {
-		G_warning(_("%s=%s,%s: files are the same, no copy required"),
-			  parm[n]->key, from, to);
-		continue;
-	    }
-	    if (find(n, to, G_mapset()) && !(module->overwrite)) {
-		G_warning(_("<%s> already exists"), to);
-		continue;
-	    }
-	    if (G_legal_filename(to) < 0) {
-		G_warning(_("<%s> is an illegal file name"), to);
-		continue;
-	    }
-	    if (do_copy(n, from, mapset, to) == 1) {
-		result = EXIT_FAILURE;
-	    }
-	    G_remove_misc("cell_misc", "reclassed_to", to);
-	}
-    }
-
-    exit(result);
-}

Copied: grass/trunk/general/g.copy/main.c (from rev 34541, grass/trunk/general/g.copy/copy.c)
===================================================================
--- grass/trunk/general/g.copy/main.c	                        (rev 0)
+++ grass/trunk/general/g.copy/main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,100 @@
+
+/****************************************************************************
+ *
+ * MODULE:       cmd
+ * AUTHOR(S):    CERL (original contributor)
+ *               Radim Blazek <radim.blazek gmail.com>, 
+ *               Cedric Shock <cedricgrass shockfamily.net>, 
+ *               Huidae Cho <grass4u gmail.com>, 
+ *               Glynn Clements <glynn gclements.plus.com>, 
+ *               Markus Neteler <neteler itc.it>, 
+ *               Martin Landa <landa.martin gmail.com>
+ * PURPOSE:      lets users copy database files 
+ * COPYRIGHT:    (C) 2003-2007 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 <stdlib.h>
+#include <string.h>
+#include <grass/glocale.h>
+#include <grass/list.h>
+
+int main(int argc, char *argv[])
+{
+    int i, n;
+    const char *mapset;
+    struct GModule *module;
+    struct Option **parm, *p;
+    char *from, *to;
+    int result = EXIT_SUCCESS;
+
+    G_gisinit(argv[0]);
+
+    read_list(0);
+
+    module = G_define_module();
+    module->keywords = _("general, map management");
+    module->description =
+	_("Copies available data files in the user's current mapset "
+	  "search path and location to the appropriate element "
+	  "directories under the user's current mapset.");
+
+    parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
+
+    for (n = 0; n < nlist; n++) {
+	char *str;
+
+	p = parm[n] = G_define_option();
+	p->key = list[n].alias;
+	p->key_desc = "from,to";
+	p->type = TYPE_STRING;
+	p->required = NO;
+	p->multiple = NO;
+	G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
+	p->gisprompt = str;
+	G_asprintf(&str, _("%s file(s) to be copied"), list[n].alias);
+	p->description = str;
+    }
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    for (n = 0; n < nlist; n++) {
+	if (parm[n]->answers == NULL)
+	    continue;
+	i = 0;
+	while (parm[n]->answers[i]) {
+	    from = parm[n]->answers[i++];
+	    to = parm[n]->answers[i++];
+	    mapset = find(n, from, "");
+	    if (!mapset) {
+		G_warning(_("<%s> not found"), from);
+		continue;
+	    }
+	    if (G_strcasecmp(mapset, G_mapset()) == 0 &&
+		G_strcasecmp(from, to) == 0) {
+		G_warning(_("%s=%s,%s: files are the same, no copy required"),
+			  parm[n]->key, from, to);
+		continue;
+	    }
+	    if (find(n, to, G_mapset()) && !(module->overwrite)) {
+		G_warning(_("<%s> already exists"), to);
+		continue;
+	    }
+	    if (G_legal_filename(to) < 0) {
+		G_warning(_("<%s> is an illegal file name"), to);
+		continue;
+	    }
+	    if (do_copy(n, from, mapset, to) == 1) {
+		result = EXIT_FAILURE;
+	    }
+	    G_remove_misc("cell_misc", "reclassed_to", to);
+	}
+    }
+
+    exit(result);
+}

Deleted: grass/trunk/general/g.list/list.c
===================================================================
--- grass/trunk/general/g.list/list.c	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/general/g.list/list.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -1,127 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       g.list
- *               
- * AUTHOR(S):    Michael Shapiro,
- *               U.S.Army Construction Engineering Research Laboratory
- *               
- * PURPOSE:      Lists available GRASS data base files of the
- *               user-specified data type to standard output
- *
- * COPYRIGHT:    (C) 1999-2007 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 <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <grass/spawn.h>
-#include <grass/list.h>
-
-struct Option *element;
-
-int parse(const char *data_type);
-
-int main(int argc, char *argv[])
-{
-    int i, n, len;
-    struct GModule *module;
-    struct Option *mapset_opt;
-    struct Flag *full;
-    const char *mapset;
-    char *str;
-
-    G_gisinit(argv[0]);
-
-    read_list(0);
-
-    module = G_define_module();
-    module->keywords = _("general, map management");
-    module->description =
-	_("Lists available GRASS data base files "
-	  "of the user-specified data type to standard output.");
-
-    element = G_define_option();
-    element->key = "type";
-    element->key_desc = "datatype";
-    element->type = TYPE_STRING;
-    element->required = YES;
-    element->multiple = YES;
-    element->description = "Data type";
-
-    for (len = 0, n = 0; n < nlist; n++)
-	len += strlen(list[n].alias) + 1;
-    str = G_malloc(len);
-
-    for (n = 0; n < nlist; n++) {
-	if (n) {
-	    strcat(str, ",");
-	    strcat(str, list[n].alias);
-	}
-	else
-	    strcpy(str, list[n].alias);
-    }
-    element->options = str;
-
-    mapset_opt = G_define_option();
-    mapset_opt->key = "mapset";
-    mapset_opt->type = TYPE_STRING;
-    mapset_opt->required = NO;
-    mapset_opt->multiple = NO;
-    mapset_opt->description = _("Mapset to list (default: current search path)");
-
-    full = G_define_flag();
-    full->key = 'f';
-    full->description = _("Verbose listing (also list map titles)");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    mapset = mapset_opt->answer;
-    if (!mapset)
-	mapset = "";
-
-    if (G_strcasecmp(mapset, ".") == 0)
-	mapset = G_mapset();
-
-    i = 0;
-    while (element->answers[i]) {
-	n = parse(element->answers[i]);
-
-	if (full->answer) {
-	    char lister[GPATH_MAX];
-
-	    sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
-		    list[n].element[0]);
-	    G_debug(3, "lister CMD: %s", lister);
-	    if (access(lister, 1) == 0)	/* execute permission? */
-		G_spawn(lister, lister, mapset, NULL);
-	    else
-		do_list(n, mapset);
-	}
-	else {
-	    do_list(n, mapset);
-	}
-
-	i++;
-    }
-
-    exit(EXIT_SUCCESS);
-}
-
-int parse(const char *data_type)
-{
-    int n;
-
-    for (n = 0; n < nlist; n++) {
-	if (G_strcasecmp(list[n].alias, data_type) == 0)
-	    break;
-    }
-
-    return n;
-}

Copied: grass/trunk/general/g.list/main.c (from rev 34541, grass/trunk/general/g.list/list.c)
===================================================================
--- grass/trunk/general/g.list/main.c	                        (rev 0)
+++ grass/trunk/general/g.list/main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,127 @@
+
+/****************************************************************************
+ *
+ * MODULE:       g.list
+ *               
+ * AUTHOR(S):    Michael Shapiro,
+ *               U.S.Army Construction Engineering Research Laboratory
+ *               
+ * PURPOSE:      Lists available GRASS data base files of the
+ *               user-specified data type to standard output
+ *
+ * COPYRIGHT:    (C) 1999-2007 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 <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <grass/spawn.h>
+#include <grass/list.h>
+
+struct Option *element;
+
+int parse(const char *data_type);
+
+int main(int argc, char *argv[])
+{
+    int i, n, len;
+    struct GModule *module;
+    struct Option *mapset_opt;
+    struct Flag *full;
+    const char *mapset;
+    char *str;
+
+    G_gisinit(argv[0]);
+
+    read_list(0);
+
+    module = G_define_module();
+    module->keywords = _("general, map management");
+    module->description =
+	_("Lists available GRASS data base files "
+	  "of the user-specified data type to standard output.");
+
+    element = G_define_option();
+    element->key = "type";
+    element->key_desc = "datatype";
+    element->type = TYPE_STRING;
+    element->required = YES;
+    element->multiple = YES;
+    element->description = "Data type";
+
+    for (len = 0, n = 0; n < nlist; n++)
+	len += strlen(list[n].alias) + 1;
+    str = G_malloc(len);
+
+    for (n = 0; n < nlist; n++) {
+	if (n) {
+	    strcat(str, ",");
+	    strcat(str, list[n].alias);
+	}
+	else
+	    strcpy(str, list[n].alias);
+    }
+    element->options = str;
+
+    mapset_opt = G_define_option();
+    mapset_opt->key = "mapset";
+    mapset_opt->type = TYPE_STRING;
+    mapset_opt->required = NO;
+    mapset_opt->multiple = NO;
+    mapset_opt->description = _("Mapset to list (default: current search path)");
+
+    full = G_define_flag();
+    full->key = 'f';
+    full->description = _("Verbose listing (also list map titles)");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    mapset = mapset_opt->answer;
+    if (!mapset)
+	mapset = "";
+
+    if (G_strcasecmp(mapset, ".") == 0)
+	mapset = G_mapset();
+
+    i = 0;
+    while (element->answers[i]) {
+	n = parse(element->answers[i]);
+
+	if (full->answer) {
+	    char lister[GPATH_MAX];
+
+	    sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
+		    list[n].element[0]);
+	    G_debug(3, "lister CMD: %s", lister);
+	    if (access(lister, 1) == 0)	/* execute permission? */
+		G_spawn(lister, lister, mapset, NULL);
+	    else
+		do_list(n, mapset);
+	}
+	else {
+	    do_list(n, mapset);
+	}
+
+	i++;
+    }
+
+    exit(EXIT_SUCCESS);
+}
+
+int parse(const char *data_type)
+{
+    int n;
+
+    for (n = 0; n < nlist; n++) {
+	if (G_strcasecmp(list[n].alias, data_type) == 0)
+	    break;
+    }
+
+    return n;
+}

Copied: grass/trunk/general/g.remove/main.c (from rev 34541, grass/trunk/general/g.remove/remove.c)
===================================================================
--- grass/trunk/general/g.remove/main.c	                        (rev 0)
+++ grass/trunk/general/g.remove/main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,146 @@
+
+/****************************************************************************
+ *
+ * MODULE:       cmd
+ * AUTHOR(S):    CERL (original contributor)
+ *               Radim Blazek <radim.blazek gmail.com>, 
+ *               Cedric Shock <cedricgrass shockfamily.net>, 
+ *               Huidae Cho <grass4u gmail.com>, 
+ *               Glynn Clements <glynn gclements.plus.com>, 
+ *               Jachym Cepicky <jachym les-ejk.cz>, 
+ *               Markus Neteler <neteler itc.it>, 
+ *               Martin Landa <landa.martin gmail.com>
+ * PURPOSE:      lets users remove GRASS database files
+ * COPYRIGHT:    (C) 1999-2007 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 <stdlib.h>
+#include <string.h>
+#include <grass/glocale.h>
+#include <grass/list.h>
+
+static int check_reclass(const char *name, const char *mapset, int force)
+{
+    char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
+    char **rmaps;
+    int nrmaps;
+
+    if (G_is_reclassed_to(name, mapset, &nrmaps, &rmaps) > 0) {
+	for (; *rmaps; rmaps++) {
+	    /* force remove */
+	    if (force)
+		G_warning(_("[%s@%s] is a base map for [%s]. Remove forced."),
+			  name, mapset, *rmaps);
+	    else
+		G_warning(_("[%s@%s] is a base map. Remove reclassed map first: %s"),
+			  name, mapset, *rmaps);
+	}
+
+	if (!force)
+	    return 1;
+    }
+
+    if (G_is_reclass(name, mapset, rname, rmapset) > 0 &&
+	G_is_reclassed_to(rname, rmapset, &nrmaps, &rmaps) > 0) {
+	char path[GPATH_MAX];
+	char *p = strchr(rname, '@');
+	char *qname = G_fully_qualified_name(name, mapset);
+
+	if (p)
+	    *p = '\0';
+
+	G__file_name_misc(path, "cell_misc", "reclassed_to", rname, rmapset);
+
+	if (nrmaps == 1 && !G_strcasecmp(rmaps[0], qname)) {
+
+	    if (remove(path) < 0)
+		G_warning(_("Removing information about reclassed map from [%s@%s] failed"),
+			  rname, rmapset);
+	}
+	else {
+	    FILE *fp = fopen(path, "w");
+
+	    if (fp) {
+		for (; *rmaps; rmaps++)
+		    if (G_strcasecmp(*rmaps, qname))
+			fprintf(fp, "%s\n", *rmaps);
+		fclose(fp);
+	    }
+	    else
+		G_warning(_("Removing information about reclassed map from [%s@%s] failed"),
+			  rname, rmapset);
+
+	}
+    }
+
+    return 0;
+}
+
+int main(int argc, char *argv[])
+{
+    int i, n;
+    struct GModule *module;
+    struct Option **parm, *p;
+    struct Flag *force_flag;
+    const char *name, *mapset;
+    const char *location_path;
+    int result = EXIT_SUCCESS;
+    int force = 0;
+
+    G_gisinit(argv[0]);
+
+    read_list(0);
+
+    module = G_define_module();
+    module->keywords = _("general, map management");
+    module->description =
+	_("Removes data base element files from "
+	  "the user's current mapset.");
+
+    force_flag = G_define_flag();
+    force_flag->key = 'f';
+    force_flag->description = _("Force remove");
+
+    parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
+
+    for (n = 0; n < nlist; n++) {
+	char *str;
+
+	p = parm[n] = G_define_option();
+	p->key = list[n].alias;
+	p->type = TYPE_STRING;
+	p->required = NO;
+	p->multiple = YES;
+	G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
+	p->gisprompt = str;
+	G_asprintf(&str, _("%s file(s) to be removed"), list[n].alias);
+	p->description = str;
+    }
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    location_path = G_location_path();
+    mapset = G_mapset();
+
+    if (force_flag->answer)
+	force = 1;
+
+    for (n = 0; n < nlist; n++) {
+	if (parm[n]->answers)
+	    for (i = 0; (name = parm[n]->answers[i]); i++) {
+		if (G_strcasecmp(list[n].alias, "rast") == 0 &&
+		    check_reclass(name, mapset, force))
+		    continue;
+
+		if (do_remove(n, name) == 1) {
+		    result = EXIT_FAILURE;
+		}
+	    }
+    }
+    exit(result);
+}

Deleted: grass/trunk/general/g.remove/remove.c
===================================================================
--- grass/trunk/general/g.remove/remove.c	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/general/g.remove/remove.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -1,146 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       cmd
- * AUTHOR(S):    CERL (original contributor)
- *               Radim Blazek <radim.blazek gmail.com>, 
- *               Cedric Shock <cedricgrass shockfamily.net>, 
- *               Huidae Cho <grass4u gmail.com>, 
- *               Glynn Clements <glynn gclements.plus.com>, 
- *               Jachym Cepicky <jachym les-ejk.cz>, 
- *               Markus Neteler <neteler itc.it>, 
- *               Martin Landa <landa.martin gmail.com>
- * PURPOSE:      lets users remove GRASS database files
- * COPYRIGHT:    (C) 1999-2007 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 <stdlib.h>
-#include <string.h>
-#include <grass/glocale.h>
-#include <grass/list.h>
-
-static int check_reclass(const char *name, const char *mapset, int force)
-{
-    char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
-    char **rmaps;
-    int nrmaps;
-
-    if (G_is_reclassed_to(name, mapset, &nrmaps, &rmaps) > 0) {
-	for (; *rmaps; rmaps++) {
-	    /* force remove */
-	    if (force)
-		G_warning(_("[%s@%s] is a base map for [%s]. Remove forced."),
-			  name, mapset, *rmaps);
-	    else
-		G_warning(_("[%s@%s] is a base map. Remove reclassed map first: %s"),
-			  name, mapset, *rmaps);
-	}
-
-	if (!force)
-	    return 1;
-    }
-
-    if (G_is_reclass(name, mapset, rname, rmapset) > 0 &&
-	G_is_reclassed_to(rname, rmapset, &nrmaps, &rmaps) > 0) {
-	char path[GPATH_MAX];
-	char *p = strchr(rname, '@');
-	char *qname = G_fully_qualified_name(name, mapset);
-
-	if (p)
-	    *p = '\0';
-
-	G__file_name_misc(path, "cell_misc", "reclassed_to", rname, rmapset);
-
-	if (nrmaps == 1 && !G_strcasecmp(rmaps[0], qname)) {
-
-	    if (remove(path) < 0)
-		G_warning(_("Removing information about reclassed map from [%s@%s] failed"),
-			  rname, rmapset);
-	}
-	else {
-	    FILE *fp = fopen(path, "w");
-
-	    if (fp) {
-		for (; *rmaps; rmaps++)
-		    if (G_strcasecmp(*rmaps, qname))
-			fprintf(fp, "%s\n", *rmaps);
-		fclose(fp);
-	    }
-	    else
-		G_warning(_("Removing information about reclassed map from [%s@%s] failed"),
-			  rname, rmapset);
-
-	}
-    }
-
-    return 0;
-}
-
-int main(int argc, char *argv[])
-{
-    int i, n;
-    struct GModule *module;
-    struct Option **parm, *p;
-    struct Flag *force_flag;
-    const char *name, *mapset;
-    const char *location_path;
-    int result = EXIT_SUCCESS;
-    int force = 0;
-
-    G_gisinit(argv[0]);
-
-    read_list(0);
-
-    module = G_define_module();
-    module->keywords = _("general, map management");
-    module->description =
-	_("Removes data base element files from "
-	  "the user's current mapset.");
-
-    force_flag = G_define_flag();
-    force_flag->key = 'f';
-    force_flag->description = _("Force remove");
-
-    parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
-
-    for (n = 0; n < nlist; n++) {
-	char *str;
-
-	p = parm[n] = G_define_option();
-	p->key = list[n].alias;
-	p->type = TYPE_STRING;
-	p->required = NO;
-	p->multiple = YES;
-	G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
-	p->gisprompt = str;
-	G_asprintf(&str, _("%s file(s) to be removed"), list[n].alias);
-	p->description = str;
-    }
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    location_path = G_location_path();
-    mapset = G_mapset();
-
-    if (force_flag->answer)
-	force = 1;
-
-    for (n = 0; n < nlist; n++) {
-	if (parm[n]->answers)
-	    for (i = 0; (name = parm[n]->answers[i]); i++) {
-		if (G_strcasecmp(list[n].alias, "rast") == 0 &&
-		    check_reclass(name, mapset, force))
-		    continue;
-
-		if (do_remove(n, name) == 1) {
-		    result = EXIT_FAILURE;
-		}
-	    }
-    }
-    exit(result);
-}

Copied: grass/trunk/general/g.rename/main.c (from rev 34541, grass/trunk/general/g.rename/rename.c)
===================================================================
--- grass/trunk/general/g.rename/main.c	                        (rev 0)
+++ grass/trunk/general/g.rename/main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,147 @@
+
+/****************************************************************************
+ *
+ * MODULE:       g.rename cmd
+ * AUTHOR(S):    CERL (original contributor)
+ *               Radim Blazek <radim.blazek gmail.com>, 
+ *               Cedric Shock <cedricgrass shockfamily.net>, 
+ *               Glynn Clements <glynn gclements.plus.com>, 
+ *               Markus Neteler <neteler itc.it>, 
+ *               Martin Landa <landa.martin gmail.com>
+ * PURPOSE:      
+ * COPYRIGHT:    (C) 1994-2007 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 <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/list.h>
+
+int main(int argc, char *argv[])
+{
+    int i, n;
+    struct GModule *module;
+    struct Option **parm, *p;
+    char *old, *new;
+    int nrmaps;
+    const char *mapset, *location_path;
+    char **rmaps;
+    int result = EXIT_SUCCESS;
+
+    G_gisinit(argv[0]);
+
+    read_list(0);
+
+    module = G_define_module();
+    module->keywords = _("general, map management");
+    module->description =
+	_("Renames data base element files in the user's current mapset.");
+
+    parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
+
+    for (n = 0; n < nlist; n++) {
+	char *str;
+
+	p = parm[n] = G_define_option();
+	p->key = list[n].alias;
+	p->key_desc = "old,new";
+	p->type = TYPE_STRING;
+	p->required = NO;
+	p->multiple = NO;
+	G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
+	p->gisprompt = str;
+	G_asprintf(&str, _("%s file(s) to be renamed"), list[n].alias);
+	p->description = str;
+    }
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    location_path = G__location_path();
+    mapset = G_mapset();
+
+    for (n = 0; n < nlist; n++) {
+	if (parm[n]->answers == NULL)
+	    continue;
+	i = 0;
+	while (parm[n]->answers[i]) {
+	    old = parm[n]->answers[i++];
+	    new = parm[n]->answers[i++];
+	    if (!find(n, old, mapset)) {
+		G_warning(_("%s <%s> not found"), list[n].maindesc, old);
+		continue;
+	    }
+	    if (find(n, new, "") && !(module->overwrite)) {
+		G_warning(_("<%s> already exists in mapset <%s>"), new,
+			  find(n, new, ""));
+		continue;
+	    }
+	    if (G_legal_filename(new) < 0) {
+		G_warning(_("<%s> is an illegal file name"), new);
+		continue;
+	    }
+	    if (strcmp(old, new) == 0) {
+		G_warning(_("%s=%s,%s: files are the same, no rename required"),
+			  parm[n]->key, old, new);
+		continue;
+	    }
+
+	    if (G_is_reclassed_to(old, mapset, &nrmaps, &rmaps) > 0) {
+		int ptr, l;
+		char buf1[256], buf2[256], buf3[256], *str;
+		FILE *fp;
+
+		G_message(_("Renaming reclass maps"));
+
+		for (; *rmaps; rmaps++) {
+		    G_message(" %s", *rmaps);
+		    sprintf(buf3, "%s", *rmaps);
+		    if ((str = strchr(buf3, '@'))) {
+			*str = 0;
+			sprintf(buf2, "%s", str + 1);
+		    }
+		    else {
+			sprintf(buf2, "%s", mapset);
+		    }
+		    sprintf(buf1, "%s/%s/cellhd/%s", location_path, buf2,
+			    buf3);
+
+		    fp = fopen(buf1, "r");
+		    if (fp == NULL)
+			continue;
+
+		    fgets(buf2, 255, fp);
+		    fgets(buf2, 255, fp);
+		    fgets(buf2, 255, fp);
+
+		    ptr = ftell(fp);
+		    fseek(fp, 0L, SEEK_END);
+		    l = ftell(fp) - ptr;
+
+		    str = (char *)G_malloc(l);
+		    fseek(fp, ptr, SEEK_SET);
+		    fread(str, l, 1, fp);
+		    fclose(fp);
+
+		    fp = fopen(buf1, "w");
+		    fprintf(fp, "reclass\n");
+		    fprintf(fp, "name: %s\n", new);
+		    fprintf(fp, "mapset: %s\n", mapset);
+		    fwrite(str, l, 1, fp);
+		    G_free(str);
+		    fclose(fp);
+		}
+	    }
+	    if (do_rename(n, old, new) == 1) {
+		result = EXIT_FAILURE;
+	    }
+	}
+    }
+    exit(result);
+}

Deleted: grass/trunk/general/g.rename/rename.c
===================================================================
--- grass/trunk/general/g.rename/rename.c	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/general/g.rename/rename.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -1,147 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       g.rename cmd
- * AUTHOR(S):    CERL (original contributor)
- *               Radim Blazek <radim.blazek gmail.com>, 
- *               Cedric Shock <cedricgrass shockfamily.net>, 
- *               Glynn Clements <glynn gclements.plus.com>, 
- *               Markus Neteler <neteler itc.it>, 
- *               Martin Landa <landa.martin gmail.com>
- * PURPOSE:      
- * COPYRIGHT:    (C) 1994-2007 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 <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/list.h>
-
-int main(int argc, char *argv[])
-{
-    int i, n;
-    struct GModule *module;
-    struct Option **parm, *p;
-    char *old, *new;
-    int nrmaps;
-    const char *mapset, *location_path;
-    char **rmaps;
-    int result = EXIT_SUCCESS;
-
-    G_gisinit(argv[0]);
-
-    read_list(0);
-
-    module = G_define_module();
-    module->keywords = _("general, map management");
-    module->description =
-	_("Renames data base element files in the user's current mapset.");
-
-    parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
-
-    for (n = 0; n < nlist; n++) {
-	char *str;
-
-	p = parm[n] = G_define_option();
-	p->key = list[n].alias;
-	p->key_desc = "old,new";
-	p->type = TYPE_STRING;
-	p->required = NO;
-	p->multiple = NO;
-	G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
-	p->gisprompt = str;
-	G_asprintf(&str, _("%s file(s) to be renamed"), list[n].alias);
-	p->description = str;
-    }
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    location_path = G__location_path();
-    mapset = G_mapset();
-
-    for (n = 0; n < nlist; n++) {
-	if (parm[n]->answers == NULL)
-	    continue;
-	i = 0;
-	while (parm[n]->answers[i]) {
-	    old = parm[n]->answers[i++];
-	    new = parm[n]->answers[i++];
-	    if (!find(n, old, mapset)) {
-		G_warning(_("%s <%s> not found"), list[n].maindesc, old);
-		continue;
-	    }
-	    if (find(n, new, "") && !(module->overwrite)) {
-		G_warning(_("<%s> already exists in mapset <%s>"), new,
-			  find(n, new, ""));
-		continue;
-	    }
-	    if (G_legal_filename(new) < 0) {
-		G_warning(_("<%s> is an illegal file name"), new);
-		continue;
-	    }
-	    if (strcmp(old, new) == 0) {
-		G_warning(_("%s=%s,%s: files are the same, no rename required"),
-			  parm[n]->key, old, new);
-		continue;
-	    }
-
-	    if (G_is_reclassed_to(old, mapset, &nrmaps, &rmaps) > 0) {
-		int ptr, l;
-		char buf1[256], buf2[256], buf3[256], *str;
-		FILE *fp;
-
-		G_message(_("Renaming reclass maps"));
-
-		for (; *rmaps; rmaps++) {
-		    G_message(" %s", *rmaps);
-		    sprintf(buf3, "%s", *rmaps);
-		    if ((str = strchr(buf3, '@'))) {
-			*str = 0;
-			sprintf(buf2, "%s", str + 1);
-		    }
-		    else {
-			sprintf(buf2, "%s", mapset);
-		    }
-		    sprintf(buf1, "%s/%s/cellhd/%s", location_path, buf2,
-			    buf3);
-
-		    fp = fopen(buf1, "r");
-		    if (fp == NULL)
-			continue;
-
-		    fgets(buf2, 255, fp);
-		    fgets(buf2, 255, fp);
-		    fgets(buf2, 255, fp);
-
-		    ptr = ftell(fp);
-		    fseek(fp, 0L, SEEK_END);
-		    l = ftell(fp) - ptr;
-
-		    str = (char *)G_malloc(l);
-		    fseek(fp, ptr, SEEK_SET);
-		    fread(str, l, 1, fp);
-		    fclose(fp);
-
-		    fp = fopen(buf1, "w");
-		    fprintf(fp, "reclass\n");
-		    fprintf(fp, "name: %s\n", new);
-		    fprintf(fp, "mapset: %s\n", mapset);
-		    fwrite(str, l, 1, fp);
-		    G_free(str);
-		    fclose(fp);
-		}
-	    }
-	    if (do_rename(n, old, new) == 1) {
-		result = EXIT_FAILURE;
-	    }
-	}
-    }
-    exit(result);
-}

Modified: grass/trunk/raster/Makefile
===================================================================
--- grass/trunk/raster/Makefile	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/raster/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -29,11 +29,12 @@
 	r.in.arc \
 	r.in.ascii \
 	r.in.bin \
-	r.info \
+	r.in.gdal \
 	r.in.gridatb \
 	r.in.mat \
 	r.in.poly \
 	r.in.xyz \
+	r.info \
 	r.kappa \
 	r.lake \
 	r.li \
@@ -46,12 +47,15 @@
 	r.out.arc \
 	r.out.ascii \
 	r.out.bin \
+	r.out.gdal \
 	r.out.gridatb \
 	r.out.mat \
 	r.out.mpeg \
+	r.out.png \
 	r.out.pov \
 	r.out.ppm \
 	r.out.ppm3 \
+	r.out.tiff \
 	r.out.vrml \
 	r.out.vtk \
 	r.param.scale \
@@ -67,14 +71,17 @@
 	r.recode \
 	r.region \
 	r.report \
-	r.resample \
 	r.resamp.interp \
 	r.resamp.rst \
 	r.resamp.stats \
+	r.resample \
 	r.rescale \
 	r.rescale.eq \
+	r.ros \
 	r.series \
 	r.slope.aspect \
+	r.spread \
+	r.spreadpath \
 	r.statistics \
 	r.statistics2 \
 	r.statistics3 \
@@ -85,10 +92,12 @@
 	r.support.stats \
 	r.surf.area \
 	r.surf.contour \
+	r.surf.fractal \
+	r.surf.gauss \
 	r.surf.idw \
 	r.surf.idw2 \
 	r.surf.random \
-	r.surf.gauss \
+	r.terraflow \
 	r.texture \
 	r.thin \
 	r.timestamp \
@@ -106,14 +115,7 @@
 	r.water.outlet \
 	r.watershed \
 	r.what \
-	r.what.color \
-	wildfire \
-	r.in.gdal \
-	r.out.gdal \
-	r.surf.fractal \
-	r.out.png \
-	r.terraflow \
-	r.out.tiff
+	r.what.color
 
 #	r.le \
 


Property changes on: grass/trunk/raster/r.ros
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Copied: grass/trunk/raster/r.ros/Makefile (from rev 34541, grass/trunk/raster/wildfire/r.ros/Makefile)
===================================================================
--- grass/trunk/raster/r.ros/Makefile	                        (rev 0)
+++ grass/trunk/raster/r.ros/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.ros
+
+LIBES = $(GISLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass/trunk/raster/r.ros/Makefile
___________________________________________________________________
Name: svn:mime-type
   + text/x-sh
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.ros/local_proto.h (from rev 34541, grass/trunk/raster/wildfire/r.ros/local_proto.h)
===================================================================
--- grass/trunk/raster/r.ros/local_proto.h	                        (rev 0)
+++ grass/trunk/raster/r.ros/local_proto.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,8 @@
+#ifndef __LOCAL_PROTO_H__
+#define __LOCAL_PROTO_H__
+
+/* spot_dist.c */
+int spot_dist(int fuel, float maxros, int speed, float angle, int row0,
+	      int col0);
+
+#endif


Property changes on: grass/trunk/raster/r.ros/local_proto.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.ros/main.c (from rev 34541, grass/trunk/raster/wildfire/r.ros/main.c)
===================================================================
--- grass/trunk/raster/r.ros/main.c	                        (rev 0)
+++ grass/trunk/raster/r.ros/main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,923 @@
+
+/****************************************************************************
+ *
+ * MODULE:       r.ros
+ * AUTHOR(S):    Jianping Xu, Rutgers University, 1993
+ *               Markus Neteler <neteler itc.it>
+ *               Roberto Flor <flor itc.it>, Brad Douglas <rez touchofmadness.com>,
+ *               Glynn Clements <glynn gclements.plus.com>, Jachym Cepicky <jachym les-ejk.cz>
+ * PURPOSE:
+ *
+ * This raster module creates three raster map layers:
+ *	1. Base (perpendicular) rate of spread (ROS);
+ *	2. Maximum (forward) ROS; and
+ * 	3. Direction of the Maximum ROS.
+ * The calculation of the two ROS values for each raster
+ * cell is based on the Fortran code by Pat Andrews (1983)
+ * of the Northern Forest Fire Laboratory, USDA Forest
+ * Service. These three raster map layers are expected to
+ * be the inputs for a seperate GRASS raster module 
+ * 'r.spread'.
+ * 
+ * 'r.ros' can be run in two standard GRASS modes:
+ * interactive and command line. For an interactive run,
+ * type in 
+ *	r.ros 
+ * and follow the prompts; for a command line mode, 
+ * type in 
+ * 	r.ros [-v] model=name [moisture_1h=name] 
+ *			[moisture_10h=name] 
+ *			[moisture_100h=name] 
+ *			moisture_live=name [velocity=name]
+ * 			[direction=name] [slope=name] 
+ *			[aspect=name] output=name
+ * where:
+ *   Flag:
+ *   Raster Maps:
+ *      model   	1-13: the standard fuel models,
+ *			all other numbers: same as barriers;
+ *  	moisture_1h   	100*moisture_content;
+ *	moisture_10h  	100*moisture_content;
+ *	moisture_100h   100*moisture_content;
+ *	moisture_live   100*moisture_content;
+ *	velocity   	ft/minute;
+ *	direction   	degree;
+ *	slope   	degree;
+ * 	aspect   	degree starting from East, anti-clockwise;
+ *	output 
+ *	  for Base ROS	cm/min (technically not ft/min);
+ *  	  for Max ROS	cm/min (technically not ft/min);
+ *	  for Direction	degree.
+ *
+ * Note that the name given as output will be used as 
+ * PREFIX for several actual raster maps. For example, if 
+ * my_ros is given as the output name, 'r.ros' will 
+ * actually produce three raster maps named my_ros.base, 
+ * my_ros.max, and my_ros.maxdir, or even my_ros.spotdist
+ * respectively. 
+ *   
+ * COPYRIGHT:    (C) 2000-2006 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 <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+
+#define DATA(map, r, c)         (map)[(r) * ncols + (c)]
+#define DEBUG
+
+
+/*measurements of the 13 fuel models, input of Rothermel equation (1972) */
+float WO[4][14] =
+    { {0, 0.034, 0.092, 0.138, 0.230, 0.046, 0.069, 0.052, 0.069, 0.134,
+       0.138, 0.069, 0.184, 0.322},
+{0, 0, 0.046, 0, 0.184, 0.023, 0.115, 0.086, 0.046, 0.019, 0.092, 0.207,
+ 0.644, 1.058},
+{0, 0, 0.023, 0, 0.092, 0, 0.092, 0.069, 0.115, 0.007, 0.230, 0.253, 0.759,
+ 1.288},
+{0, 0, 0.023, 0, 0.230, 0.092, 0, 0.017, 0, 0, 0.092, 0, 0}
+};
+
+					    /*ovendry fuel loading, lb./ft.^2 */
+float DELTA[] = { 0, 1.0, 1.0, 2.5, 6.0, 2.0, 2.5, 2.5,
+    0.2, 0.2, 1.0, 1.0, 2.3, 3.0
+};				/*fuel depth, ft. */
+float SIGMA[4][14] =
+    { {0, 3500, 3000, 1500, 2000, 2000, 1750, 1750, 2000, 2500, 2000, 1500,
+       1500, 1500},
+{0, 0, 109, 0, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109},
+{0, 0, 30, 0, 30, 0, 30, 30, 30, 30, 30, 30, 30, 30},
+{0, 0, 1500, 0, 1500, 1500, 0, 1500, 0, 0, 1500, 0, 0, 0}
+};
+
+			 /*fuel particale surface-area-to-volume ratio, 1/ft. */
+float MX[] = { 0, 0.12, 0.15, 0.25, 0.20, 0.20, 0.25, 0.40,
+    0.30, 0.25, 0.25, 0.15, 0.20, 0.25
+};				/*moisture content of extinction */
+
+CELL *map_elev;			/*full array for elevation map layer (for spotting) */
+int nrows, ncols;
+struct Cell_head window;
+
+
+int main(int argc, char *argv[])
+{
+
+	/***input of Rothermel equation (1972)***/
+    float h = 8000.0,		/*heat of combustion, BTU/lb. */
+	rhop = 32,		/*ovendry fuel density, lb./ft.^3 */
+	ST = 0.0555;		/*fuel total mineral content, lb. minerals/lb. ovendry */
+
+    float sigma[14];
+
+	/***derived parameters of Rothermel equation (1972)***/
+    float R,			/*rate of spread, ft./min.
+				   R = IR*xi*(1+phiw+phis)/(rhob*epsilon*Qig)  */
+      IR,			/*reaction intensity, BTU/ft.^2/min.
+				   IR = gamma*wn*h*etaM*etas  */
+      gamma,			/*optimum reation velosity, 1/min.
+				   gamma = gammamax*(beta/betaop)^A*
+				   exp(A(1-beta/betaop))  */
+      gammamax,			/*maximum reation velosity, 1/min.
+				   gammamax = sigma^1.5/(495+0.0594*sigma^1.5)  */
+      betaop,			/*optimum packing ratio 
+				   betaop = 3.348/(sigma^0.8189)  */
+      A,			/*A = 1/(4.77*sigma^0.1-7.27)  */
+      etas = 0.174 / pow(0.01, 0.19),	/*mineral damping coefficient */
+	xi,			/*propagating flux ratio,
+				   xi = exp((0.792+0.681*sigma^0.5)(beta+0.1))/
+				   (192+0.2595*sigma)  */
+	phiw,			/*wind coefficient,  phiw = C*U^B/(beta/betaop)^E */
+	C,			/*C = 7.47/exp(0.133*sigma^0.55)  */
+	B,			/*B = 0.02526*sigma^.054   */
+	E,			/*E = 0.715/exp(0.000359*sigma)  */
+	phis,			/*slope coefficient,phis = 5.275/beta^0.3*(tan(theta)^2) */
+	rhob,			/*ovendry bulk density, lb./ft.^3, rohb = wo/delta */
+	epsilon[4][14],		/*effective heating number, epsilon = 1/exp(138/sigma) */
+	Qig[14],		/*heat of preignition, BTU/lb.  Qig = 250+1116*Mf */
+	beta;			/*packing ratio,  beta = rhob/rhop  */
+
+	/***intermediate variables***/
+    float R0,			/*base ROS (w/out wind/slope) */
+      Rdir, sin_fac, cos_fac, Ffactor_all[4][14],	/*in all fuel subclasses by sigma/WO */
+      Ffactor_in_dead[3][14],	/*in dead fuel subclasses by sigma/WO */
+      Ffactor_dead[14],		/*dead fuel weight by sigma/WO */
+      Ffactor_live[14],		/*live fuel weight by sigma/WO */
+      Gfactor_in_dead[3][14],	/*in dead fuel by the 6 classes */
+      G1, G2, G3, G4, G5, wo_dead[14],	/*dead fuel total load */
+      wn_dead,			/*net dead fuel total load */
+      wn_live,			/*net live fuel (total) load */
+      class_sum, moisture[4],	/*moistures of 1-h,10-h,100-h,live fuels */
+      Mf_dead,			/*total moisture of dead fuels */
+      etaM_dead,		/*dead fuel misture damping coefficent */
+      etaM_live,		/*live fuel misture damping coefficent */
+      xmext,			/*live fuel moisture of extinction */
+      phi_ws,			/*wind and slope conbined coefficient */
+      wmfd, fdmois, fined, finel;
+
+    /*other local variables */
+    int col, row,
+	spotting,
+	model, class,
+	fuel_fd = 0,
+	mois_1h_fd = 0, mois_10h_fd = 0, mois_100h_fd = 0, mois_live_fd = 0,
+	vel_fd = 0, dir_fd = 0,
+	elev_fd = 0, slope_fd = 0, aspect_fd = 0,
+	base_fd = 0, max_fd = 0, maxdir_fd = 0, spotdist_fd = 0;
+
+    char name_base[60], name_max[60], name_maxdir[60], name_spotdist[60];
+
+    CELL *fuel,			/*cell buffer for fuel model map layer */
+     *mois_1h,			/*cell buffer for 1-hour fuel moisture map layer */
+     *mois_10h,			/*cell buffer for 10-hour fuel moisture map layer */
+     *mois_100h,		/*cell buffer for 100-hour fuel moisture map layer */
+     *mois_live,		/*cell buffer for live fuel moisture map layer */
+     *vel,			/*cell buffer for wind velocity map layer */
+     *dir,			/*cell buffer for wind direction map layer */
+     *elev = NULL,		/*cell buffer for elevation map layer (for spotting) */
+	*slope,			/*cell buffer for slope map layer */
+	*aspect,		/*cell buffer for aspect map layer */
+	*base,			/*cell buffer for base ROS map layer */
+	*max,			/*cell buffer for max ROS map layer */
+	*maxdir,		/*cell buffer for max ROS direction map layer */
+	*spotdist = NULL;	/*cell buffer for max spotting distance map layer */
+
+    extern struct Cell_head window;
+
+    struct
+    {
+	struct Option *model,
+	    *mois_1h, *mois_10h, *mois_100h, *mois_live,
+	    *vel, *dir, *elev, *slope, *aspect, *output;
+    } parm;
+
+    /* please, remove before GRASS 7 released */
+    struct Flag *flag1, *flag2;
+    struct GModule *module;
+
+    /* initialize access to database and create temporary files */
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("raster");
+    module->description =
+	_("Generates three, or four raster map layers showing 1) the base "
+	  "(perpendicular) rate of spread (ROS), 2) the maximum (forward) ROS, "
+	  "3) the direction of the maximum ROS, and optionally 4) the "
+	  "maximum potential spotting distance.");
+
+    parm.model = G_define_option();
+    parm.model->key = "model";
+    parm.model->type = TYPE_STRING;
+    parm.model->required = YES;
+    parm.model->gisprompt = "old,cell,raster";
+    parm.model->description = _("Name of raster map containing fuel MODELs");
+
+    parm.mois_1h = G_define_option();
+    parm.mois_1h->key = "moisture_1h";
+    parm.mois_1h->type = TYPE_STRING;
+    parm.mois_1h->gisprompt = "old,cell,raster";
+    parm.mois_1h->description =
+	_("Name of raster map containing the 1-HOUR fuel MOISTURE (%)");
+
+    parm.mois_10h = G_define_option();
+    parm.mois_10h->key = "moisture_10h";
+    parm.mois_10h->type = TYPE_STRING;
+    parm.mois_10h->gisprompt = "old,cell,raster";
+    parm.mois_10h->description =
+	_("Name of raster map containing the 10-HOUR fuel MOISTURE (%)");
+
+    parm.mois_100h = G_define_option();
+    parm.mois_100h->key = "moisture_100h";
+    parm.mois_100h->type = TYPE_STRING;
+    parm.mois_100h->gisprompt = "old,cell,raster";
+    parm.mois_100h->description =
+	_("Name of raster map containing the 100-HOUR fuel MOISTURE (%)");
+
+    parm.mois_live = G_define_option();
+    parm.mois_live->key = "moisture_live";
+    parm.mois_live->type = TYPE_STRING;
+    parm.mois_live->required = YES;
+    parm.mois_live->gisprompt = "old,cell,raster";
+    parm.mois_live->description =
+	_("Name of raster map containing LIVE fuel MOISTURE (%)");
+
+    parm.vel = G_define_option();
+    parm.vel->key = "velocity";
+    parm.vel->type = TYPE_STRING;
+    parm.vel->gisprompt = "old,cell,raster";
+    parm.vel->description =
+	_("Name of raster map containing midflame wind VELOCITYs (ft/min)");
+
+    parm.dir = G_define_option();
+    parm.dir->key = "direction";
+    parm.dir->type = TYPE_STRING;
+    parm.dir->gisprompt = "old,cell,raster";
+    parm.dir->description =
+	_("Name of raster map containing wind DIRECTIONs (degree)");
+
+    parm.slope = G_define_option();
+    parm.slope->key = "slope";
+    parm.slope->type = TYPE_STRING;
+    parm.slope->gisprompt = "old,cell,raster";
+    parm.slope->description =
+	_("Name of raster map containing SLOPE (degree)");
+
+    parm.aspect = G_define_option();
+    parm.aspect->key = "aspect";
+    parm.aspect->type = TYPE_STRING;
+    parm.aspect->gisprompt = "old,cell,raster";
+    parm.aspect->description =
+	_("Name of raster map containing ASPECT (degree, anti-clockwise from E)");
+
+    parm.elev = G_define_option();
+    parm.elev->key = "elevation";
+    parm.elev->type = TYPE_STRING;
+    parm.elev->gisprompt = "old,cell,raster";
+    parm.elev->description =
+	_("Name of raster map containing ELEVATION (m) (required w/ -s)");
+
+    parm.output = G_define_option();
+    parm.output->key = "output";
+    parm.output->type = TYPE_STRING;
+    parm.output->required = YES;
+    parm.output->gisprompt = "new,cell,raster";
+    parm.output->description =
+	_("Name of raster map to contain results (several new layers)");
+
+    /* please, remove before GRASS 7 released */
+    flag1 = G_define_flag();
+    flag1->key = 'v';
+    flag1->description = _("Run verbosely");
+
+    flag2 = G_define_flag();
+    flag2->key = 's';
+    flag2->description = _("Also produce maximum SPOTTING distance");
+
+    /*   Parse command line */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    /* please, remove before GRASS 7 released */
+    if (flag1->answer) {
+	putenv("GRASS_VERBOSE=3");
+	G_warning(_("The '-v' flag is superseded and will be removed "
+		    "in future. Please use '--verbose' instead."));
+    }
+
+    spotting = flag2->answer;
+
+    /*  Check if input layers exists in data base  */
+    if (G_find_cell2(parm.model->answer, "") == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), parm.model->answer);
+
+    if (!
+	(parm.mois_1h->answer || parm.mois_10h->answer ||
+	 parm.mois_100h->answer)) {
+	G_warning
+	    ("no dead fuel moisture is given. At least one of the 1-h, 10-h, 100-h moisture layers is required.");
+	G_usage();
+	exit(EXIT_FAILURE);
+    }
+
+    if (parm.mois_1h->answer) {
+	if (G_find_cell2(parm.mois_1h->answer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"),
+			  parm.mois_1h->answer);
+    }
+    if (parm.mois_10h->answer) {
+	if (G_find_cell2(parm.mois_10h->answer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"),
+			  parm.mois_10h->answer);
+    }
+    if (parm.mois_100h->answer) {
+	if (G_find_cell2(parm.mois_100h->answer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"),
+			  parm.mois_100h->answer);
+    }
+
+    if (G_find_cell2(parm.mois_live->answer, "") == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), parm.mois_live->answer);
+
+    if (parm.vel->answer && !(parm.dir->answer)) {
+	G_warning
+	    ("a wind direction layer should be given if the wind velocity layer--%s-- has been given\n",
+	     parm.vel->answer);
+	G_usage();
+	exit(EXIT_FAILURE);
+    }
+    if (!(parm.vel->answer) && parm.dir->answer) {
+	G_warning
+	    ("a wind velocity layer should be given if the wind direction layer--%s-- has been given\n",
+	     parm.dir->answer);
+	G_usage();
+	exit(EXIT_FAILURE);
+    }
+    if (parm.vel->answer) {
+	if (G_find_cell2(parm.vel->answer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"), parm.vel->answer);
+    }
+    if (parm.dir->answer) {
+	if (G_find_cell2(parm.dir->answer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"), parm.dir->answer);
+    }
+
+    if (parm.slope->answer && !(parm.aspect->answer)) {
+	G_warning
+	    ("an aspect layer should be given if the slope layer--%s-- has been given\n",
+	     parm.slope->answer);
+	G_usage();
+	exit(EXIT_FAILURE);
+    }
+    if (!(parm.slope->answer) && parm.aspect->answer) {
+	G_warning
+	    ("a slope layer should be given if the aspect layer--%s-- has been given\n",
+	     parm.aspect->answer);
+	G_usage();
+	exit(EXIT_FAILURE);
+    }
+    if (parm.slope->answer) {
+	if (G_find_cell2(parm.slope->answer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"), parm.slope->answer);
+    }
+    if (parm.aspect->answer) {
+	if (G_find_cell2(parm.aspect->answer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"),
+			  parm.aspect->answer);
+    }
+
+    if (spotting) {
+	if (!(parm.elev->answer)) {
+	    G_warning
+		("an elevation layer should be given if considering spotting\n");
+	    G_usage();
+	    exit(EXIT_FAILURE);
+	}
+	else {
+	    if (G_find_cell2(parm.elev->answer, "") == NULL)
+		G_fatal_error(_("Raster map <%s> not found"),
+			      parm.elev->answer);
+	}
+    }
+
+    /*assign names of the three output ROS layers */
+    sprintf(name_base, "%s.base", parm.output->answer);
+    sprintf(name_max, "%s.max", parm.output->answer);
+    sprintf(name_maxdir, "%s.maxdir", parm.output->answer);
+
+    /*check if the output layer names EXIST */
+    if (G_find_cell2(name_base, G_mapset()))
+	G_fatal_error(_("Raster map <%s> already exists in mapset <%s>, select another name"),
+		      name_base, G_mapset());
+
+    if (G_find_cell2(name_max, G_mapset()))
+	G_fatal_error(_("Raster map <%s> already exists in mapset <%s>, select another name"),
+		      name_max, G_mapset());
+
+    if (G_find_cell2(name_maxdir, G_mapset()))
+	G_fatal_error(_("Raster map <%s> already exists in mapset <%s>, select another name"),
+		      name_maxdir, G_mapset());
+
+    /*assign a name to output SPOTTING distance layer */
+    if (spotting) {
+	sprintf(name_spotdist, "%s.spotdist", parm.output->answer);
+	if (G_find_cell2(name_spotdist, G_mapset()))
+	    G_fatal_error(_("Raster map <%s> already exists in mapset <%s>, select another name"),
+			  name_spotdist, G_mapset());
+    }
+
+    /*  Get database window parameters  */
+    G_get_window(&window);
+
+    /*  find number of rows and columns in window    */
+    nrows = G_window_rows();
+    ncols = G_window_cols();
+
+    fuel = G_allocate_cell_buf();
+    mois_1h = G_allocate_cell_buf();
+    mois_10h = G_allocate_cell_buf();
+    mois_100h = G_allocate_cell_buf();
+    mois_live = G_allocate_cell_buf();
+    vel = G_allocate_cell_buf();
+    dir = G_allocate_cell_buf();
+    slope = G_allocate_cell_buf();
+    aspect = G_allocate_cell_buf();
+    base = G_allocate_cell_buf();
+    max = G_allocate_cell_buf();
+    maxdir = G_allocate_cell_buf();
+    if (spotting) {
+	spotdist = G_allocate_cell_buf();
+	elev = G_allocate_cell_buf();
+	map_elev = (CELL *) G_calloc(nrows * ncols, sizeof(CELL));
+    }
+
+    /*  Open input cell layers for reading  */
+
+    fuel_fd =
+	G_open_cell_old(parm.model->answer,
+			G_find_cell2(parm.model->answer, ""));
+    if (fuel_fd < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"),
+		      parm.model->answer);
+
+    if (parm.mois_1h->answer) {
+	mois_1h_fd =
+	    G_open_cell_old(parm.mois_1h->answer,
+			    G_find_cell2(parm.mois_1h->answer, ""));
+	if (mois_1h_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"),
+			  parm.mois_1h->answer);
+    }
+    if (parm.mois_10h->answer) {
+	mois_10h_fd =
+	    G_open_cell_old(parm.mois_10h->answer,
+			    G_find_cell2(parm.mois_10h->answer, ""));
+	if (mois_10h_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"),
+			  parm.mois_10h->answer);
+    }
+    if (parm.mois_100h->answer) {
+	mois_100h_fd =
+	    G_open_cell_old(parm.mois_100h->answer,
+			    G_find_cell2(parm.mois_100h->answer, ""));
+	if (mois_100h_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"),
+			  parm.mois_100h->answer);
+    }
+
+    mois_live_fd =
+	G_open_cell_old(parm.mois_live->answer,
+			G_find_cell2(parm.mois_live->answer, ""));
+    if (mois_live_fd < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"),
+		      parm.mois_live->answer);
+
+    if (parm.vel->answer) {
+	vel_fd =
+	    G_open_cell_old(parm.vel->answer,
+			    G_find_cell2(parm.vel->answer, ""));
+	if (vel_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"),
+			  parm.vel->answer);
+    }
+    if (parm.dir->answer) {
+	dir_fd =
+	    G_open_cell_old(parm.dir->answer,
+			    G_find_cell2(parm.dir->answer, ""));
+	if (dir_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"),
+			  parm.dir->answer);
+    }
+
+    if (parm.slope->answer) {
+	slope_fd =
+	    G_open_cell_old(parm.slope->answer,
+			    G_find_cell2(parm.slope->answer, ""));
+	if (slope_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"),
+			  parm.slope->answer);
+    }
+    if (parm.aspect->answer) {
+	aspect_fd =
+	    G_open_cell_old(parm.aspect->answer,
+			    G_find_cell2(parm.aspect->answer, ""));
+	if (aspect_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"),
+			  parm.aspect->answer);
+    }
+
+    if (spotting) {
+	elev_fd =
+	    G_open_cell_old(parm.elev->answer,
+			    G_find_cell2(parm.elev->answer, ""));
+	if (elev_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"),
+			  parm.elev->answer);
+    }
+
+    base_fd = G_open_cell_new(name_base);
+    max_fd = G_open_cell_new(name_max);
+    maxdir_fd = G_open_cell_new(name_maxdir);
+    if (spotting)
+	spotdist_fd = G_open_cell_new(name_spotdist);
+
+    /*compute weights, combined wo, and combined sigma */
+    /*wo[model] -- simple sum of WO[class][model] by all fuel subCLASS */
+    /*sigma[model] -- weighted sum of SIGMA[class][model] by all fuel subCLASS       *epsilon[class][model] */
+    for (model = 1; model <= 13; model++) {
+	class_sum = 0.0;
+	wo_dead[model] = 0.0;
+	sigma[model] = 0.0;
+	for (class = 0; class <= 3; class++) {
+	    class_sum = class_sum + WO[class][model] * SIGMA[class][model];
+	    if (SIGMA[class][model] > 0.0) {
+		epsilon[class][model] = exp(-138.0 / SIGMA[class][model]);
+	    }
+	    else {
+		epsilon[class][model] = 0.0;
+	    }
+	}
+	for (class = 0; class <= 3; class++) {
+	    Ffactor_all[class][model] =
+		WO[class][model] * SIGMA[class][model] / class_sum;
+	    sigma[model] =
+		sigma[model] +
+		SIGMA[class][model] * Ffactor_all[class][model];
+	}
+	class_sum = 0.0;
+	for (class = 0; class <= 2; class++) {
+	    wo_dead[model] = wo_dead[model] + WO[class][model];
+	    class_sum = class_sum + WO[class][model] * SIGMA[class][model];
+	}
+	for (class = 0; class <= 2; class++) {
+	    Ffactor_in_dead[class][model] =
+		WO[class][model] * SIGMA[class][model] / class_sum;
+	}
+
+	/* compute G factor for each of the 6 subclasses */
+	G1 = 0.0;
+	G2 = 0.0;
+	G3 = 0.0;
+	G4 = 0.0;
+	G5 = 0.0;
+	for (class = 0; class <= 2; class++) {
+	    if (SIGMA[class][model] >= 1200)
+		G1 = G1 + Ffactor_in_dead[class][model];
+	    if (SIGMA[class][model] < 1200 && SIGMA[class][model] >= 192)
+		G2 = G2 + Ffactor_in_dead[class][model];
+	    if (SIGMA[class][model] < 192 && SIGMA[class][model] >= 96)
+		G3 = G3 + Ffactor_in_dead[class][model];
+	    if (SIGMA[class][model] < 96 && SIGMA[class][model] >= 48)
+		G4 = G4 + Ffactor_in_dead[class][model];
+	    if (SIGMA[class][model] < 48 && SIGMA[class][model] >= 16)
+		G5 = G5 + Ffactor_in_dead[class][model];
+	}
+	for (class = 0; class <= 2; class++) {
+	    if (SIGMA[class][model] >= 1200)
+		Gfactor_in_dead[class][model] = G1;
+	    if (SIGMA[class][model] < 1200 && SIGMA[class][model] >= 192)
+		Gfactor_in_dead[class][model] = G2;
+	    if (SIGMA[class][model] < 192 && SIGMA[class][model] >= 96)
+		Gfactor_in_dead[class][model] = G3;
+	    if (SIGMA[class][model] < 96 && SIGMA[class][model] >= 48)
+		Gfactor_in_dead[class][model] = G4;
+	    if (SIGMA[class][model] < 48 && SIGMA[class][model] >= 16)
+		Gfactor_in_dead[class][model] = G5;
+	    if (SIGMA[class][model] < 16)
+		Gfactor_in_dead[class][model] = 0.0;
+	}
+
+	Ffactor_dead[model] =
+	    class_sum / (class_sum + WO[3][model] * SIGMA[3][model]);
+	Ffactor_live[model] = 1 - Ffactor_dead[model];
+    }
+
+    /*if considering spotting, read elevation map into an array */
+    if (spotting)
+	for (row = 0; row < nrows; row++) {
+	    if (G_get_map_row(elev_fd, elev, row) < 0)
+		G_fatal_error("cannot get map row!");
+	    for (col = 0; col < ncols; col++)
+		DATA(map_elev, row, col) = elev[col];
+	}
+
+    /*major computation: compute ROSs one cell a time */
+    G_message(_("Percent Completed ... "));
+
+    for (row = 0; row < nrows; row++) {
+	G_percent(row, nrows, 2);
+	if (G_get_map_row(fuel_fd, fuel, row) < 0)
+	    G_fatal_error("cannot get map row: %d!", row);
+	if (parm.mois_1h->answer)
+	    if (G_get_map_row(mois_1h_fd, mois_1h, row) < 0)
+		G_fatal_error("cannot get map row: %d!", row);
+	if (parm.mois_10h->answer)
+	    if (G_get_map_row(mois_10h_fd, mois_10h, row) < 0)
+		G_fatal_error("cannot get map row: %d!", row);
+	if (parm.mois_100h->answer)
+	    if (G_get_map_row(mois_100h_fd, mois_100h, row) < 0)
+		G_fatal_error("cannot get map row: %d!", row);
+	if (G_get_map_row(mois_live_fd, mois_live, row) < 0)
+	    G_fatal_error("cannot get map row: %d!", row);
+	if (parm.vel->answer)
+	    if (G_get_map_row(vel_fd, vel, row) < 0)
+		G_fatal_error("cannot get map row: %d!", row);
+	if (parm.dir->answer)
+	    if (G_get_map_row(dir_fd, dir, row) < 0)
+		G_fatal_error("cannot get map row: %d!", row);
+	if (parm.slope->answer)
+	    if (G_get_map_row(slope_fd, slope, row) < 0)
+		G_fatal_error("cannot get map row: %d!", row);
+	if (parm.aspect->answer)
+	    if (G_get_map_row(aspect_fd, aspect, row) < 0)
+		G_fatal_error("cannot get map row: %d!", row);
+
+	/*initialize cell buffers for output map layers */
+	for (col = 0; col < ncols; col++) {
+	    base[col] = max[col] = maxdir[col] = 0;
+	    if (spotting)
+		spotdist[col] = 0;
+	}
+
+	for (col = 0; col < ncols; col++) {
+	    /*check if a fuel is within the 13 models,
+	     *if not, no processing; useful when no data presents*/
+	    if (fuel[col] < 1 || fuel[col] > 13)
+		continue;
+	    if (parm.mois_1h->answer)
+		moisture[0] = 0.01 * mois_1h[col];
+	    if (parm.mois_10h->answer)
+		moisture[1] = 0.01 * mois_10h[col];
+	    if (parm.mois_100h->answer)
+		moisture[2] = 0.01 * mois_100h[col];
+	    moisture[3] = 0.01 * mois_live[col];
+	    if (parm.aspect->answer)
+		aspect[col] = (630 - aspect[col]) % 360;
+
+	    /* assign some dead fuel moisture if not completely 
+	     *     given based on emperical relationship*/
+	    if (!(parm.mois_10h->answer || parm.mois_100h->answer)) {
+		moisture[1] = moisture[0] + 0.01;
+		moisture[2] = moisture[0] + 0.02;
+	    }
+	    if (!(parm.mois_1h->answer || parm.mois_100h->answer)) {
+		moisture[0] = moisture[1] - 0.01;
+		moisture[2] = moisture[1] + 0.01;
+	    }
+	    if (!(parm.mois_1h->answer || parm.mois_10h->answer)) {
+		moisture[0] = moisture[2] - 0.02;
+		moisture[1] = moisture[2] - 0.01;
+	    }
+	    if (!(parm.mois_1h->answer) && parm.mois_10h->answer &&
+		parm.mois_100h->answer)
+		moisture[0] = moisture[1] - 0.01;
+	    if (!(parm.mois_10h->answer) && parm.mois_1h->answer &&
+		parm.mois_100h->answer)
+		moisture[1] = moisture[0] + 0.01;
+	    if (!(parm.mois_100h->answer) && parm.mois_1h->answer &&
+		parm.mois_10h->answer)
+		moisture[2] = moisture[1] + 0.01;
+
+	    /*compute xmext, moisture of extinction of live fuels */
+	    wmfd = 0.0;
+	    fined = 0.0;
+	    if (SIGMA[3][fuel[col]] > 0.0) {
+		for (class = 0; class <= 2; class++) {
+		    if (SIGMA[class][fuel[col]] == 0.0)
+			continue;
+		    fined =
+			fined +
+			WO[class][fuel[col]] * exp(-138.0 /
+						   SIGMA[class][fuel[col]]);
+		    wmfd =
+			wmfd +
+			WO[class][fuel[col]] * exp(-138.0 /
+						   SIGMA[class][fuel[col]]) *
+			moisture[class];
+		}
+		fdmois = wmfd / fined;
+		finel = WO[3][fuel[col]] * exp(-500.0 / SIGMA[3][fuel[col]]);
+		xmext =
+		    2.9 * (fined / finel) * (1 - fdmois / MX[fuel[col]]) -
+		    0.226;
+	    }
+	    else
+		xmext = MX[fuel[col]];
+	    if (xmext < MX[fuel[col]])
+		xmext = MX[fuel[col]];
+
+	    /*compute other intermediate values */
+	    Mf_dead = 0.0;
+	    wn_dead = 0.0;
+	    class_sum = 0.0;
+	    for (class = 0; class <= 2; class++) {
+		Mf_dead =
+		    Mf_dead +
+		    moisture[class] * Ffactor_in_dead[class][fuel[col]];
+		wn_dead =
+		    wn_dead +
+		    WO[class][fuel[col]] * Gfactor_in_dead[class][fuel[col]] *
+		    (1 - ST);
+		Qig[class] = 250 + 1116 * moisture[class];
+		class_sum =
+		    class_sum +
+		    Ffactor_all[class][fuel[col]] *
+		    epsilon[class][fuel[col]] * Qig[class];
+	    }
+	    etaM_dead =
+		1.0 - 2.59 * (Mf_dead / MX[fuel[col]]) +
+		5.11 * (Mf_dead / MX[fuel[col]]) * (Mf_dead / MX[fuel[col]]) -
+		3.52 * (Mf_dead / MX[fuel[col]]) * (Mf_dead / MX[fuel[col]]) *
+		(Mf_dead / MX[fuel[col]]);
+	    if (Mf_dead >= MX[fuel[col]])
+		etaM_dead = 0.0;
+	    etaM_live =
+		1.0 - 2.59 * (moisture[3] / xmext) +
+		5.11 * (moisture[3] / xmext) * (moisture[3] / xmext) -
+		3.52 * (moisture[3] / xmext) * (moisture[3] / xmext) *
+		(moisture[3] / xmext);
+	    if (moisture[3] >= xmext)
+		etaM_live = 0.0;
+	    wn_live = WO[3][fuel[col]] * (1 - ST);
+	    Qig[3] = 250 + 1116 * moisture[3];
+	    class_sum =
+		class_sum +
+		Ffactor_all[3][fuel[col]] * epsilon[3][fuel[col]] * Qig[3];
+
+	    /*final computations */
+	    rhob = (wo_dead[fuel[col]] + WO[3][fuel[col]]) / DELTA[fuel[col]];
+	    beta = rhob / rhop;
+	    betaop = 3.348 / pow(sigma[fuel[col]], 0.8189);
+	    A = 133 / pow(sigma[fuel[col]], 0.7913);
+	    gammamax =
+		pow(sigma[fuel[col]],
+		    1.5) / (495 + 0.0594 * pow(sigma[fuel[col]], 1.5));
+	    gamma =
+		gammamax * pow(beta / betaop,
+			       A) * exp(A * (1 - beta / betaop));
+	    xi = exp((0.792 + 0.681 * pow(sigma[fuel[col]], 0.5)) * (beta +
+								     0.1)) /
+		(192 + 0.2595 * sigma[fuel[col]]);
+	    IR = gamma * h * (wn_dead * etaM_dead +
+			      wn_live * etaM_live) * etas;
+
+	    R0 = IR * xi / (rhob * class_sum);
+
+	    if (parm.vel->answer && parm.dir->answer) {
+		C = 7.47 * exp(-0.133 * pow(sigma[fuel[col]], 0.55));
+		B = 0.02526 * pow(sigma[fuel[col]], 0.54);
+		E = 0.715 * exp(-0.000359 * sigma[fuel[col]]);
+		phiw = C * pow((double)vel[col], B) / pow(beta / betaop, E);
+	    }
+	    else
+		phiw = 0.0;
+
+	    if (parm.slope->answer && parm.aspect->answer) {
+		phis =
+		    5.275 * pow(beta,
+				-0.3) * tan(0.01745 * slope[col]) *
+		    tan(0.01745 * slope[col]);
+	    }
+	    else
+		phis = 0.0;
+
+	    /*compute the maximum ROS R and its direction, 
+	     *vector adding for the effect of wind and slope*/
+	    if (parm.dir->answer && parm.aspect->answer) {
+		sin_fac =
+		    phiw * sin(0.01745 * dir[col]) +
+		    phis * sin(0.01745 * aspect[col]);
+		cos_fac =
+		    phiw * cos(0.01745 * dir[col]) +
+		    phis * cos(0.01745 * aspect[col]);
+		phi_ws = sqrt(sin_fac * sin_fac + cos_fac * cos_fac);
+		Rdir = atan2(sin_fac, cos_fac) / 0.01745;
+	    }
+	    else if (parm.dir->answer && !(parm.aspect->answer)) {
+		phi_ws = phiw;
+		Rdir = dir[col];
+	    }
+	    else if (!(parm.dir->answer) && parm.aspect->answer) {
+		phi_ws = phis;
+		Rdir = (float)aspect[col];
+	    }
+	    else {
+		phi_ws = 0.0;
+		Rdir = 0.0;
+	    }
+	    R = R0 * (1 + phi_ws);
+	    if (Rdir < 0.0)
+		Rdir = Rdir + 360;
+	    /*printf("\nparm.dir->aanswer=%s, parm.aspect->aanswer=%s, phis=%f, phi_ws=%f, aspect[col]=%d,Rdir=%f",parm.dir->answer,parm.aspect->answer,phis,phi_ws,aspect[col],Rdir); */
+
+	    /*maximum spotting distance */
+	    if (spotting)
+		spotdist[col] =
+		    spot_dist(fuel[col], R, vel[col], Rdir, row, col);
+
+	    /*to avoid 0 R, convert ft./min to cm/min */
+	    R0 = 30.5 * R0;
+	    R = 30.5 * R;
+	    /*4debugging            R0 = R0/30.5/1.1; R = R/30.5/1.1; */
+
+	    base[col] = (int)R0;
+	    max[col] = (int)R;
+	    maxdir[col] = (int)Rdir;
+	    /*printf("(%d, %d)\nR0=%.2f, vel=%d, dir=%d, phiw=%.2f, s=%d, as=%d, phis=%.2f, R=%.1f, Rdir=%.0f\n", row, col, R0, vel[col], dir[col], phiw, slope[col], aspect[col], phis, R, Rdir); */
+	}
+	G_put_raster_row(base_fd, base, CELL_TYPE);
+	G_put_raster_row(max_fd, max, CELL_TYPE);
+	G_put_raster_row(maxdir_fd, maxdir, CELL_TYPE);
+	if (spotting)
+	    G_put_raster_row(spotdist_fd, spotdist, CELL_TYPE);
+    }
+    G_percent(row, nrows, 2);
+
+    G_close_cell(fuel_fd);
+    if (parm.mois_1h->answer)
+	G_close_cell(mois_1h_fd);
+    if (parm.mois_10h->answer)
+	G_close_cell(mois_10h_fd);
+    if (parm.mois_100h->answer)
+	G_close_cell(mois_100h_fd);
+    G_close_cell(mois_live_fd);
+    if (parm.vel->answer)
+	G_close_cell(vel_fd);
+    if (parm.dir->answer)
+	G_close_cell(dir_fd);
+    if (parm.slope->answer)
+	G_close_cell(slope_fd);
+    if (parm.aspect->answer)
+	G_close_cell(aspect_fd);
+    G_close_cell(base_fd);
+    G_close_cell(max_fd);
+    G_close_cell(maxdir_fd);
+    if (spotting) {
+	G_close_cell(spotdist_fd);
+	G_close_cell(spotdist_fd);
+	G_free(map_elev);
+    }
+
+    /*      
+       for (model = 1; model <= 13; model++) {
+       if (model == 1)
+       printf("\n           Grass and Grass-dominated\n");
+       else if (model == 4)
+       printf("             Chaparral and Shrubfields\n");
+       else if (model == 8)
+       printf("                   Timber Litter\n");
+       else if (model == 11)
+       printf("                   Logging Slash\n");
+       printf("Model %2d   ", model);
+       for (class = 0; class <= 3; class++) 
+       printf("%4.0f/%.3f ", SIGMA[class][model], WO[class][model]);
+       printf("  %.1f  %.2f\n", DELTA[model], MX[model]);
+       } 
+
+       printf("\nWeight in All Fuel Subclasses:\n");
+       for (model = 1; model <= 13; model++) {
+       printf("model %2d  ", model);
+       for (class = 0; class <= 3; class++) 
+       printf("%.2f  ", Ffactor_all[class][model]);
+       printf("%4.0f/%.3f=%6.0f  model %2d\n", sigma[model], wo_dead[model]+WO[3][model], sigma[model]/(wo_dead[model]+WO[3][model]), model);
+       } 
+       printf("\nWeight in Dead Fuel Subclasses, Dead Weight/Live Weight:\n");for (model = 1; model <= 13; model++) {
+       printf("model %2d  ", model);
+       for (class = 0; class <= 2; class++) 
+       printf("%.2f  ", Ffactor_in_dead[class][model]);
+       printf("%.2f/%.2f  model %2d\n", Ffactor_dead[model], Ffactor_live[model], model);
+       } 
+     */
+
+    exit(EXIT_SUCCESS);
+}


Property changes on: grass/trunk/raster/r.ros/main.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.ros/r.ros.html (from rev 34541, grass/trunk/raster/wildfire/r.ros/r.ros.html)
===================================================================
--- grass/trunk/raster/r.ros/r.ros.html	                        (rev 0)
+++ grass/trunk/raster/r.ros/r.ros.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,161 @@
+<H2>DESCRIPTION</H2>
+
+<P><I>r.ros</I> generates the base ROS value, maximum ROS value, direction
+of the maximum ROS, and optionally the maximum potential spotting distance
+of a wildfire for each raster cell in the current geographic region. The
+calculation of the two ROS values for each raster cell is based on the
+Fortran code by Pat Andrews (1983) of the Northern Forest Fire Laboratory,
+USDA Forest Service. The direction of the maximum ROS results from the
+vector addition of the forward ROS in wind direction and that in upslope
+direction. The spotting distance, if required, will be calculated by a
+separate function, spot_dist(), which is based on Lathrop and Xu (in preparation),
+Chase (1984) and Rothermel (1991). These three or four raster map layers
+serve as inputs for another GRASS raster program r.spread. More information
+on r.ros and r.spread can be found in Xu (1994).
+
+<H2>Parameters:</H2>
+<DL>
+<DT><B>model=</B>name
+<DD> Name of an
+existing raster map layer in the user's current mapset search path containing
+the standard fuel models defined by the USDA Forest Service. Valid values
+are 1-13; other numbers are recognized as barriers by r.ros.
+
+<DT><B>moisture_1h=</B>name
+<DD> Name of an existing raster map layer in
+the user's current mapset search path containing the 1-hour (&lt;.25")
+fuel moisture (percentage content multiplied by 100).
+
+<DT><B>moisture_10h=</B>name 
+<DD>Name of an existing raster map layer in the
+user's current mapset search path containing the 10-hour (.25-1") fuel
+moisture (percentage content multiplied by 100).
+
+<DT><B>moisture_100h=</B>name
+<DD>Name of an existing raster map layer in the
+user's current mapset search path containing the 100-hour (1-3") fuel moisture
+(percentage content multiplied by 100).
+
+<DT><B>moisture_live=</B>name
+<DD>Name of an existing raster map layer in the
+user's current mapset search path containing live (herbaceous) fuel fuel
+moisture (percentage content multiplied by 100).
+
+<DT><B>velocity=</B>name
+<DD>Name of an existing raster map layer in the user's
+current mapset search path containing wind velocities at half of the average
+flame height (feet/minute).
+
+<DT><B>direction=</B>name
+<DD>Name of an existing raster map
+layer in the user's current mapset search path containing wind direction,
+clockwise from north (degree).
+
+<DT><B>slope=</B>name
+<DD>Name of
+an existing raster map layer in the user's current mapset search path containing
+topographic slope (degree).
+
+<DT><B>aspect=</B>name
+<DD>Name of an existing
+raster map layer in the user's current mapset search path containing
+topographic aspect, counter-clockwise from east (GRASS convention)
+(degree).
+
+<DT><B>elevation=</B>name
+<DD>Name of an existing raster map
+layer in the user's current mapset search path containing elevation (meters).
+
+<DT><B>output=</B>name Prefix of new
+raster map layers in the user's current mapset to contain
+<BR> 1) the base (perpendicular) ROS
+(cm/minute);
+<BR> 2) the maximum (forward) ROS (cm/minute),
+<BR> 3) the direction of the maximum
+ROS, clockwise from north (degree), and optionally
+<BR> 4) the maximum potential
+spotting distance (meters).
+<BR>If 'my_ros' is given as the output name, then r.ros automatically
+assigns 'my_ros.base', 'my_ros.max', 'my_ros.maxdir', and optionally,
+'my_ros.spotdist' as the names for the actual output map layers.
+</DL>
+
+<H2>OPTIONS</H2>
+
+r.ros can be run either non-interactively or interactively. The program
+is run interactively if the user types r.ros without specifying flag settings
+and parameter values on the command line. In this case, the user will be
+prompted for input. The program will be run non-interactively if the user
+specifies the names of raster map layers and any desired options on the
+command line, using the form:
+<BR> r.ros [-vs] model=name [moisture_1h=name]
+[moisture_10h=name] [moisture_100h=name]
+moisture_live=name [velocity=name] [direction=name]
+[slope=name] [aspect=name] [elevation=name] output=name
+
+<P>If the options <B>moisture_1h=</B>name, <B>moisture_10h=</B>name, and
+<B>moisture_100h=</B>name are partially given, the program will assign
+values to the missing option using the formula:
+
+<P>
+moisture_100h = moisture_10h + 1 = moisture_1h + 2.
+
+<P>However at least one of them should be given. Options <B>velocity=</B>name
+and <B>direction=</B>name must be in pair, whether given or not. If none
+is given, the program will assume a no-wind condition. Options <B>slope=</B>name
+and <B>aspect=</B>name must be in pair, whether given or not. If none is
+given, the program will assume a topographically flat condition. Option
+<B>elevation=</B>name must be given if -s option is used.
+
+<H2>EXAMPLE</H2>
+Assume we have inputs, the following generates ROSes and spotting distances:
+
+<P>r.ros -vs model=fire_model moisture_1h=1hour_moisture moisture_live=live_moisture
+velocity=wind_speed direction=wind_direction
+slope=slope aspect=aspect elevation=elevation output=my_ros
+
+<H2>NOTES</H2>
+1. r.ros is supposed to be run before running another GRASS program r.spread.
+The combination of the two forms a simulation of the spread of wildfires.
+<BR>2. The inputs to r.ros should be in proper units.
+<BR>3. The output units for the base and maximum ROSes are in cm/minute
+rather than ft/minute, which is due to that a possible zero ft/minute base
+ROS value and a positive integer ft/minute maximum ROS would result in
+calculation failure in the r.spread program.
+<BR>4. The user needs to provide only ONE output name even the program
+actually generates THREE or FOUR map layers.
+<BR>5. The rules for optional parameters must be followed.
+
+<H2>SEE ALSO</H2>
+
+<EM><A HREF="g.region.html">g.region</A>,
+<!-- <A HREF="r.mask.html"> r.mask,</A> -->
+<A HREF="r.slope.aspect.html">r.slope.aspect</A>,
+ <A HREF="r.spread.html">r.spread</A></EM>
+
+<H2>REFERENCES</H2>
+<B>Albini,</B> F. A., 1976, Computer-based models of wildland fire behavior:
+a user's manual, USDA Forest Service, Intermountain Forest and Range Experiment
+Station, Ogden, Utah.
+<BR><B>Andrews</B>, P. L., 1986, BEHAVE: fire behavior prediction and fuel
+modeling system -- BURN subsystem, Part 1, USDA Forest Service, Intermountain
+Research Station, Gen. Tech. Rep. INT-194, Ogden, Utah.
+<BR><B>Chase</B>, Carolyn, H., 1984, Spotting distance from wind-driven
+surface fires -- extensions of equations for pocket calculators, US Forest
+Service, Res. Note INT-346, Ogden, Utah.
+<BR><B>Lathrop</B>, Richard G. and Jianping Xu, A geographic information
+system-based approach for calculating spotting distance. (in preparation)
+<BR><B>Rothermel</B>, R. E., 1972, A mathematical model for predicting
+fire spread in wildland fuels, USDA Forest Service, Intermountain Forest
+and Range Experiment Station, Res. Pap. INT-115, Ogden, Utah.
+<BR><B>Rothermel</B>, Richard, 1991, Predicting behavior and size of crown
+fires in the northern Rocky Mountains, US Forest Service, Res. Paper INT-438,
+Ogden, Utah.
+<BR><B>Xu</B>, Jianping, 1994, Simulating the spread of wildfires using
+a geographic information system and remote sensing, Ph. D. Dissertation,
+Rutgers University, New Brunswick, New Jersey.
+
+<H2> AUTHOR</H2>
+Jianping Xu, Center for Remote Sensing and Spatial Analysis, Rutgers University.
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/raster/r.ros/r.ros.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.ros/spot_dist.c (from rev 34541, grass/trunk/raster/wildfire/r.ros/spot_dist.c)
===================================================================
--- grass/trunk/raster/r.ros/spot_dist.c	                        (rev 0)
+++ grass/trunk/raster/r.ros/spot_dist.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,152 @@
+
+/******************************************************************************
+ *	spot_dist.c 		in ~/r.ros
+ *	
+ *  	Returns the maximum spotting distance (in meters) based on:
+ * 1) Lathrop, Richard G. and Jianping Xu, 1994, A geographic information
+ *	system method to assist evaluating spotting distance in any 
+ * 	terrain conditions. (in preparation) 
+ *
+ *	|
+ *	|
+ *	|***    z0 = e0 + h0	
+ *	|     *
+ *	|       *   firebrand trajetory z: z = z0 - (X/(1.3U))^2 
+ *	|	 * 			   simplified from Chase (1984)
+ *	|	  *
+ *	|	   *
+ *	| 	    *
+ *	|\ e0	     *
+ *	| \___    __  *   /\
+ *	|     \__/  \__*_/  \   surface e: from DEM 	
+ *	.		     \
+ *	.
+ *	
+ *	|___________________________________ X
+ *
+ * 2) Chase, Carolyn, H., 1984, Spotting distance from wind-driven surface 
+ *	fires -- ententions of equations for pocket calculators, US Forest 
+ *	Service, Res. Note INT-346 , Ogden, Uhta, 21 p.
+ * 3) Rothermel, Richard, 1991, Predicting behavior and size of crown fires 
+ *	in the northern Rocky Mountains, US Forest Service, Res. Paper 
+ *	INT-438, 46 p.
+ ******************************************************************************/
+
+#include <grass/gis.h>
+#include <math.h>
+
+
+#define DATA(map, r, c) (map)[(r) * ncols + (c)]
+#define	DEG2RAD		0.017453292
+/*#define DEBUG */
+
+
+/* Ovendry loading for all sizes (lb/ft^2) */
+float w[14] = { 0, 0.034, 0.184, 0.138, 0.736, 0.161, 0.276,
+    0.224, 0.230, 0.160, 0.552, 0.529, 1.587, 2.668
+};
+
+/* Mean average cover height (assumed the same as current fuel depth (ft) */
+float hbar[] = { 0, 1.0, 1.0, 2.5, 6.0, 2.0, 2.5,
+    2.5, 0.2, 0.2, 1.0, 1.0, 2.3, 3.0
+};
+
+/* A Coeficients in E = IA(.474U)^B (s), where U is wind at 20 ft (mi/h) */
+double A[14] = { 0, 545, 709, 429, 301, 235, 242,
+    199, 0, 1121, 224, 179, 163, 170
+};
+
+/* B Coeficients in E = IA(.474U)^B (s), where U is wind at 20 ft (mi/h) */
+double B[14] = { 0, -1.21, -1.32, -1.19, -1.05, -0.92, -0.94,
+    0.83, 0, -1.51, -0.89, -0.81, -0.78, -0.79
+};
+
+int spot_dist(int fuel, float maxros, int speed, float angle, int row0,
+	      int col0)
+{
+    /* variables in Chase (1984) (use h0 for z0 which for e0 + h0) */
+    double h0;			/* initial firebrand height (m) */
+    double E;			/* thermal strength (Btu/ft) */
+    double I;			/* mean fire intensity (Btu/ft/s) */
+    double U;			/* mean windspeed at 6 meter (km/h) */
+
+    /* variables in Rothermel (1991) */
+    float R;			/* forward rate of spread (ROS) (ft/s) */
+
+    /* other variables */
+    extern CELL *map_elev;	/* elevation map array */
+    extern int nrows, ncols;
+    extern struct Cell_head window;
+    double z0;			/* initial firebrand elevation (m) */
+    double z;			/* firebrand height (m) */
+    int row, col;		/* a cell under a spotting trajatory */
+    int S;			/* spotting distance on an terrain (m) */
+    double sqrd;		/* distance from cell0 to cell */
+    double sin_a, cos_a;	/* of the wind angle */
+    double sqr_ns, sqr_ew;	/* square resolutions for speed */
+    int i;			/* for advance a step */
+
+    if (fuel == 8)		/* no spotting from closed timber litter */
+	return (0);
+
+    /* get I from Byram's equation, I = R*w*h, cited in Rothermel (1991) */
+    R = maxros / 60.0;
+    I = R * w[fuel] * 8000;
+
+    /* get h0 (originally z0) and z0 (e0 + h0) from Chase (1984) */
+    U = 2 * speed / 88.0;
+    if (U == 0.0)
+	E = 0.0;		/* to avoid domain error in pow() */
+    else
+	E = I * A[fuel] * pow(0.474 * U, B[fuel]);
+    h0 = 0.3048 * (1.055 * sqrt(E));
+    U *= 1.609;			/* change units to metric */
+    z0 = DATA(map_elev, row0, col0) + h0;
+
+    sin_a = sin(angle * DEG2RAD), cos_a = cos(angle * DEG2RAD);
+    sqr_ns = window.ns_res * window.ns_res;
+    sqr_ew = window.ew_res * window.ew_res;
+
+    /* vertical change using F=1.3*U*(dz)^.5, simplified from Chase (1984) */
+    S = 0;
+    row = row0 - cos_a + 0.5, col = col0 + sin_a + 0.5;
+    if (row < 0 || row >= nrows || col < 0 || col >= ncols)	/* outside */
+	return (S);
+
+    i = 1;
+    while (1) {
+	if (row < 0 || row >= nrows)	/* outside the region */
+	    break;
+	if (col < 0 || col >= ncols)	/* outside the region */
+	    break;
+	sqrd = (row - row0) * (row - row0) * sqr_ns
+	    + (col - col0) * (col - col0) * sqr_ew;
+	z = z0 - sqrd / (1.69 * U * U);
+
+	if (DATA(map_elev, row, col) > z) {
+#ifdef DEBUG
+	    printf
+		("\nA return: m%d U=%d(m/h) h0=%d(m) e0(%d,%d)=%d z=%d(m) e(%d,%d)=%d s=%d(m)",
+		 (int)fuel, (int)U, (int)h0, row0, col0, DATA(map_elev, row0,
+							      col0), (int)z,
+		 row, col, DATA(map_elev, row, col), S);
+#endif
+	    return (S);
+	}
+	/* advance a step */
+	S = sqrt((double)sqrd);
+#ifdef DEBUG
+	printf
+	    ("\nm%d U=%d(m/h) h0=%d(m) e0(%d,%d)=%d z=%d(m) e(%d,%d)=%d s=%d(m)",
+	     (int)fuel, (int)U, (int)h0, row0, col0, DATA(map_elev, row0,
+							  col0), (int)z, row,
+	     col, DATA(map_elev, row, col), S);
+#endif
+	i++;
+	row = row0 - i * cos_a + 0.5, col = col0 + i * sin_a + 0.5;
+	if (row < 0 || row >= nrows || col < 0 || col >= ncols)
+	    return (S);		/* outside the region */
+    }
+
+    return S;
+}


Property changes on: grass/trunk/raster/r.ros/spot_dist.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/raster/r.spread
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Copied: grass/trunk/raster/r.spread/Makefile (from rev 34541, grass/trunk/raster/wildfire/r.spread/Makefile)
===================================================================
--- grass/trunk/raster/r.spread/Makefile	                        (rev 0)
+++ grass/trunk/raster/r.spread/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,16 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.spread
+
+include $(MODULE_TOPDIR)/include/Make/Vars.make
+
+MOD_OBJS := $(filter-out display.o,$(AUTO_OBJS))
+
+# LIBES = $(DISPLAYLIB) $(RASTERLIB) $(GISLIB)
+# DEPENDENCIES = $(DISPLAYDEP) $(RASTERDEP) $(GISDEP)
+LIBES = $(GISLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass/trunk/raster/r.spread/Makefile
___________________________________________________________________
Name: svn:mime-type
   + text/x-sh
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/cell_ptrHa.h (from rev 34541, grass/trunk/raster/wildfire/r.spread/cell_ptrHa.h)
===================================================================
--- grass/trunk/raster/r.spread/cell_ptrHa.h	                        (rev 0)
+++ grass/trunk/raster/r.spread/cell_ptrHa.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,9 @@
+#ifndef CELL_PTRHA_H
+#define CELL_PTRHA_H
+struct cell_ptrHa
+{
+    float angle;
+    int row, col;
+    struct cell_ptrHa *next;
+};
+#endif


Property changes on: grass/trunk/raster/r.spread/cell_ptrHa.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/cmd_line.h (from rev 34541, grass/trunk/raster/wildfire/r.spread/cmd_line.h)
===================================================================
--- grass/trunk/raster/r.spread/cmd_line.h	                        (rev 0)
+++ grass/trunk/raster/r.spread/cmd_line.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,33 @@
+
+/****************************************************************/
+/*                                                              */
+/*      This header file declares the global variables and the  */
+/*      structures that are to be used for command line         */
+/*      processing                                              */
+/*                                                              */
+
+/****************************************************************/
+
+#ifndef CMD_LINE_H
+#define CMD_LINE_H
+extern char *backdrop_layer;
+extern char *base_layer;
+extern char *dir_layer;
+extern char *max_layer;
+extern char *spotdist_layer;
+extern char *mois_layer;
+extern char *out_layer;
+extern char *start_layer;
+extern char *velocity_layer;
+extern char *x_out_layer;
+extern char *y_out_layer;
+
+extern float comp_dens;
+extern int display;
+extern int init_time;
+extern int least;
+extern int spotting;
+extern int time_lag;
+extern int x_out;
+extern int y_out;
+#endif /* CMD_LINE_H */


Property changes on: grass/trunk/raster/r.spread/cmd_line.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/collect_ori.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/collect_ori.c)
===================================================================
--- grass/trunk/raster/r.spread/collect_ori.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/collect_ori.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,106 @@
+
+/*********************************************************************
+ *
+ *	collect_ori.c	in ~/r.spread2
+ *
+ *	functin to collect the spread origins from the source map and
+ *	put them into a min-heap; also marks the origin locations and
+ *	the other locations to avoid redundant computation and to be
+ *	able to terminate.
+ *********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <grass/gis.h>
+#include "cmd_line.h"
+#include "costHa.h"
+#include "local_proto.h"
+
+#define DATA(map, r, c)		(map)[(r) * ncols + (c)]
+
+/*#define DEBUG */
+
+/* Globals from cmd_line */
+char *backdrop_layer;
+char *base_layer;
+char *dir_layer;
+char *max_layer;
+char *spotdist_layer;
+char *mois_layer;
+char *out_layer;
+char *start_layer;
+char *velocity_layer;
+char *x_out_layer;
+char *y_out_layer;
+
+float comp_dens;
+int display;
+int init_time;
+int least;
+int spotting;
+int time_lag;
+int x_out;
+int y_out;
+
+void collect_ori(int start_fd)
+{
+    extern CELL *cell;
+    extern CELL *map_base, *map_x_out, *map_y_out, *map_visit;
+    extern float *map_out;
+    extern char buf[];
+    extern float neg, zero;
+    extern int BARRIER;
+    extern int nrows, ncols;
+    extern long heap_len;
+    extern struct costHa *heap;
+    int row, col;
+
+    for (row = 0; row < nrows; row++) {
+	G_percent(row, nrows, 2);
+
+	if (G_get_map_row(start_fd, cell, row) < 0)
+	    exit(1);
+
+	for (col = 0; col < ncols; col++) {
+	    if (*(cell + col) > 0) {
+		/*Check if starting sources legally ? */
+		if (DATA(map_base, row, col) <= 0) {
+		    G_warning("Can't start from a BARRIER at cell (%d,%d), request ignored",
+			    col, row);
+		    continue;
+		}
+
+		DATA(map_out, row, col) = (float)init_time;
+		insertHa((float)init_time, zero, row, col, heap, &heap_len);
+		/*mark it to avoid redundant computing */
+		DATA(map_visit, row, col) = 1;
+
+		if (x_out)
+		    DATA(map_x_out, row, col) = col;
+		if (y_out)
+		    DATA(map_y_out, row, col) = row;
+		G_debug(4, "origin: row=%d col=%d", row, col);
+#if 0
+		if (display)
+		    draw_a_burning_cell(row, col);
+#endif
+	    }
+	    else {
+		DATA(map_out, row, col) = neg;
+		DATA(map_visit, row, col) = BARRIER;
+	    }
+	}
+    }
+
+    G_percent(row, nrows, 2);
+
+#ifdef DEBUG
+    {
+	int i;
+
+	printf("\nheap_len=%d  ", heap_len);
+	for (i = 1; i <= heap_len; i++)
+	    printf("(%d,%d) ", heap[i].row, heap[i].col);
+    }
+#endif
+}


Property changes on: grass/trunk/raster/r.spread/collect_ori.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/costHa.h (from rev 34541, grass/trunk/raster/wildfire/r.spread/costHa.h)
===================================================================
--- grass/trunk/raster/r.spread/costHa.h	                        (rev 0)
+++ grass/trunk/raster/r.spread/costHa.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,17 @@
+
+/*************************************************
+ *
+ *   costHa.h - Data structure for costHa (spread)
+ *
+ *   It is used for (heap) sorting the
+ *   cumulative time, it's a contiguous structure.
+ *
+ *************************************************/
+#ifndef COSTHA_H
+#define COSTHA_H 1
+struct costHa
+{
+    float min_cost, angle;
+    int row, col;
+};
+#endif


Property changes on: grass/trunk/raster/r.spread/costHa.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/deleteHa.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/deleteHa.c)
===================================================================
--- grass/trunk/raster/r.spread/deleteHa.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/deleteHa.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,44 @@
+
+/***********************************************************
+ *
+ *                 deleteHa.c (for spread)
+ *  This routine is to delete a cell in a heap. 
+ *  It 1) searches the cell backward and sequentially from 
+ *        the heap (if not found, returns a error message), 
+ *     2) overwrites that cell and calls fixH routine to 
+ *        restore a heap order.
+ *
+ ************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "costHa.h"
+#include "local_proto.h"
+
+void
+deleteHa(float old_min_cost, int row, int col,
+	 struct costHa *heap, long *heap_len)
+{
+    /* struct costHa  *fixHa(); */
+    long i;
+
+    if (*heap_len < 1) {
+	printf("programming ERROR: can't delete a cell from an ampty list");
+	exit(1);
+    }
+    /* search the old_cell from the heap */
+    for (i = 0; i <= *heap_len; i++) {
+	if (heap[i].min_cost == old_min_cost &&
+	    heap[i].row == row && heap[i].col == col)
+	    break;
+    }
+    if (i == 0) {
+	printf("programming ERROR: can't find the old_cell from the list");
+	exit(1);
+    }
+    /* overwrite that cell, fix the heap */
+    fixHa(i, heap, *heap_len);
+    *heap_len = *heap_len - 1;
+
+    return;
+}


Property changes on: grass/trunk/raster/r.spread/deleteHa.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/display.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/display.c)
===================================================================
--- grass/trunk/raster/r.spread/display.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/display.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,199 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <grass/gis.h>
+#include <grass/display.h>
+#include <grass/raster.h>
+#include "cmd_line.h"
+#include "local_proto.h"
+
+#define SIZE 80
+
+static char buf[SIZE], old_time[SIZE], cur_time[SIZE];
+static double f2s_x, f2s_y;	/*file-to-screen factors */
+static int old_value = 0;
+static int xoffset, yoffset;	/*screen coors of u-l corner of file */
+static int x1, y1, x2, y2;	/*diagonal pts of a box */
+static int x1_st, y1_st, x2_st, y2_st;	/*pts of the elapsed Spread Time box */
+static int x1_ct, y1_ct, x2_ct, y2_ct;	/*pts of the Current Time box */
+static struct Colors colors;
+static struct tm *t_time;
+static time_t c_time;
+
+void display_init(void)
+{
+    extern struct Cell_head window;
+    extern int nrows, ncols;	/*numbers of rows and columns in file */
+    double t, b, l, r;		/*top, bottom, left and right of frame */
+    int width, height;
+
+
+    /*set time zone for tracing local time */
+    tzset();
+
+    if (R_open_driver() != 0) {
+	G_fatal_error("couldn't open display");
+    }
+    D_setup(1);
+    D_get_screen_window(&t, &b, &l, &r);
+    /*printf("\nt,b,l,r: %d, %d, %d, %d", t, b, l, r);
+     */
+    /*setup some graphics boxes */
+    R_standard_color(D_translate_color("grey"));
+    R_move_abs(l, t + (b - t) / 20);
+    R_cont_abs(r, t + (b - t) / 20);
+    R_move_abs(r, t + (b - t) / 10);
+    R_cont_abs(l, t + (b - t) / 10);
+    R_move_abs(l + (r - l) / 2, t);
+    R_cont_abs(l + (r - l) / 2, t + (b - t) / 10);
+
+    /*logo box */
+    x1 = l;
+    y1 = t;
+    x2 = l + 0.5 * (r - l);
+    y2 = t + 0.05 * (b - t);
+    R_standard_color(5);
+    R_box_abs(x1, y1, x2 - 1, y2 - 1);
+    R_text_size((int)(0.055 * (x2 - x1)), (int)(0.7 * (y2 - y1)));
+    R_move_abs((int)(x1 + 0.03 * (x2 - x1)), (int)(y1 + 0.825 * (y2 - y1)));
+    R_standard_color(8);
+    R_text("Live SPREAD Simulation");
+
+    /*elapsed spread time box */
+    x1_st = l + 0.5 * (r - l);
+    y1_st = t;
+    x2_st = r;
+    y2_st = t + 0.05 * (b - t);
+    /*printf("\ny1-st y2-st x1st, x2st: %d, %d, %d, %d", y1_st,y2_st,x1_st,x2_st);
+     */ R_standard_color(9);
+    R_box_abs(x1_st + 1, y1_st, x2_st, y2_st - 1);
+    R_text_size((int)(0.049 * (x2_st - x1_st)), (int)(0.5 * (y2_st - y1_st)));
+    R_move_abs((int)(x1_st + 0.03 * (x2_st - x1_st)),
+	       (int)(y1_st + 0.75 * (y2_st - y1_st)));
+    R_standard_color(1);
+    R_text("Elapsed Spread Time 00:00");
+
+    /*starting watch-time box */
+    x1 = l;
+    y1 = t + 0.05 * (b - t);
+    x2 = l + 0.5 * (r - l);
+    y2 = t + 0.1 * (b - t);
+    R_standard_color(9);
+    R_box_abs(x1, y1 + 1, x2 - 1, y2 - 1);
+    R_text_size((int)(0.05 * (x2 - x1)), (int)(0.5 * (y2 - y1)));
+    R_move_abs((int)(x1 + 0.03 * (x2 - x1)), (int)(y1 + 0.75 * (y2 - y1)));
+    time(&c_time);
+    t_time = localtime(&c_time);
+    strftime(cur_time, SIZE, "%H:%M", t_time);
+    sprintf(buf, "   Started  At  %s", cur_time);
+    R_standard_color(8);
+    R_text(buf);
+
+    /*current watch-time box */
+    x1_ct = l + 0.5 * (r - l);
+    y1_ct = t + 0.05 * (b - t);
+    x2_ct = r;
+    y2_ct = t + 0.1 * (b - t);
+    R_standard_color(9);
+    R_box_abs(x1_ct + 1, y1_ct + 1, x2_ct, y2_ct - 1);
+    R_text_size((int)(0.05 * (x2_ct - x1_ct)), (int)(0.5 * (y2_ct - y1_ct)));
+    R_move_abs((int)(x1_ct + 0.03 * (x2_ct - x1_ct)),
+	       (int)(y1_ct + 0.75 * (y2_ct - y1_ct)));
+    R_standard_color(8);
+    sprintf(buf, "  Current  Time  %s", cur_time);
+    R_text(buf);
+
+    /*live image display box */
+    D_reset_screen_window(t + (b - t) / 10 + 2, b, l, r);
+    R_close_driver();
+
+    /*Set a graster map as a background image */
+    if (backdrop_layer) {
+	sprintf(buf, "d.rast -o %s", backdrop_layer);
+	system(buf);
+    }
+
+    /*figure scaling factors of a file cell to a screen unit */
+    R_open_driver();
+    G_make_grey_scale_colors(&colors, 0, 59);
+    width = r - l;
+    height = 0.9 * (b - t) - 1;
+    if (width * nrows > height * ncols) {
+	f2s_y = height / (float)nrows;
+	f2s_x = (window.ew_res / window.ns_res) * f2s_y;
+	yoffset = t + 0.1 * (b - t) + 3;
+	xoffset = l + (width - f2s_x * ncols) / 2 + 1;
+    }
+    else {
+	f2s_x = width / (float)ncols;
+	f2s_y = (window.ns_res / window.ew_res) * f2s_x;
+	xoffset = l + 1;
+	yoffset = t + 0.1 * (b - t) + (height - f2s_y * nrows) / 2 + 3;
+    }
+
+    D_reset_screen_window(t, b, l, r);
+}
+
+
+void draw_a_cell(int row, int col, int cell_value)
+{
+    x1 = xoffset + f2s_x * col;
+    y1 = yoffset + f2s_y * row;
+    x2 = x1 + f2s_x + 0.999;	/*tradeoff:allowing overlaps to avoid gaps */
+    y2 = y1 + f2s_y + 0.999;	/*tradeoff:allowing overlaps to avoid gaps */
+    D_color(cell_value % 60, &colors);
+    R_box_abs(x1, y1, x2, y2);
+    R_flush();
+
+    /* if cell_value changes, update it in the elasped-spread-time box, 
+     * also update the current watch-time if it changes*/
+    if (cell_value > old_value) {
+	old_value = cell_value;
+	R_standard_color(9);
+	R_box_abs(x1_st + 1, y1_st, x2_st, y2_st - 1);
+	R_text_size((int)(0.049 * (x2_st - x1_st)),
+		    (int)(0.5 * (y2_st - y1_st)));
+	R_move_abs((int)(x1_st + 0.03 * (x2_st - x1_st)),
+		   (int)(y1_st + 0.75 * (y2_st - y1_st)));
+	R_standard_color(1);
+	sprintf(buf, "Elapsed Spread Time %d%d:%d%d", (cell_value / 600),
+		(cell_value / 60 - cell_value / 600 * 10),
+		((cell_value - cell_value / 60 * 60) / 10),
+		((cell_value - cell_value / 60 * 60) -
+		 (cell_value - cell_value / 60 * 60) / 10 * 10));
+	R_text(buf);
+
+	time(&c_time);
+	t_time = localtime(&c_time);
+	strftime(cur_time, SIZE, "%H:%M", t_time);
+	if (strcmp(cur_time, old_time) != 0) {
+	    strcpy(old_time, cur_time);
+	    R_standard_color(9);
+	    R_box_abs(x1_ct + 1, y1_ct + 1, x2_ct, y2_ct);
+	    R_text_size((int)(0.05 * (x2_ct - x1_ct)),
+			(int)(0.5 * (y2_ct - y1_ct)));
+	    R_move_abs((int)(x1_ct + 0.03 * (x2_ct - x1_ct)),
+		       (int)(y1_ct + 0.75 * (y2_ct - y1_ct)));
+	    R_standard_color(8);
+	    sprintf(buf, "  Current  Time  %s", cur_time);
+	    R_text(buf);
+	}
+    }
+}
+
+void draw_a_burning_cell(int row, int col)
+{
+    x1 = xoffset + f2s_x * col;
+    y1 = yoffset + f2s_y * row;
+    x2 = x1 + f2s_x + 0.999;	/*tradeoff:allowing overlaps to avoid gaps */
+    y2 = y1 + f2s_y + 0.999;	/*tradeoff:allowing overlaps to avoid gaps */
+    R_standard_color(D_translate_color("red"));
+    R_box_abs(x1, y1, x2, y2);
+    R_flush();
+}
+
+void display_close(void)
+{
+    R_close_driver();
+}


Property changes on: grass/trunk/raster/r.spread/display.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/fixHa.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/fixHa.c)
===================================================================
--- grass/trunk/raster/r.spread/fixHa.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/fixHa.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,43 @@
+
+/**************************************************
+ *
+ *               fixHa.c (for spread)
+ *  This routine is to restore a 'heap' order upon
+ *  removing a cell from the heap, which is ordered
+ *  by the min_cost of a cell.
+ *
+ **************************************************/
+#include <stdlib.h>
+#include "costHa.h"
+#include "local_proto.h"
+
+struct costHa *fixHa(long go_pos, struct costHa *heap, long heap_len)
+{
+    long vacant, smaller_child;
+
+    if (heap_len == 0)
+	return NULL;
+
+    vacant = go_pos;
+    while (2 * vacant <= heap_len) {
+	smaller_child = 2 * vacant;
+	if ((2 * vacant < heap_len) &&
+	    (heap[2 * vacant + 1].min_cost < heap[2 * vacant].min_cost))
+	    smaller_child++;
+	if (heap[heap_len].min_cost > heap[smaller_child].min_cost) {
+	    heap[vacant].min_cost = heap[smaller_child].min_cost;
+	    heap[vacant].angle = heap[smaller_child].angle;
+	    heap[vacant].row = heap[smaller_child].row;
+	    heap[vacant].col = heap[smaller_child].col;
+	    vacant = smaller_child;
+	}
+	else
+	    break;
+    }
+    heap[vacant].min_cost = heap[heap_len].min_cost;
+    heap[vacant].angle = heap[heap_len].angle;
+    heap[vacant].row = heap[heap_len].row;
+    heap[vacant].col = heap[heap_len].col;
+
+    return heap;
+}


Property changes on: grass/trunk/raster/r.spread/fixHa.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/get_minHa.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/get_minHa.c)
===================================================================
--- grass/trunk/raster/r.spread/get_minHa.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/get_minHa.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,27 @@
+
+/************************************************************
+ *
+ *                 get_minHa.c (for spread)
+ *  This routine is to get the cell with the SMALLEST min_
+ *  cost. This cell is the root of the (min) heap. After 
+ *  removing the root, it calls fixHa routine to restore a
+ *  heap order.
+ *
+ ************************************************************/
+
+#include "costHa.h"
+#include "local_proto.h"
+
+void get_minHa(struct costHa *heap, struct costHa *pres_cell, long heap_len)
+{
+    /* struct costHa  *fixHa(); */
+    if (heap_len == 0)
+	return;
+    pres_cell->min_cost = heap[1].min_cost;
+    pres_cell->angle = heap[1].angle;
+    pres_cell->row = heap[1].row;
+    pres_cell->col = heap[1].col;
+    fixHa(1, heap, heap_len);
+
+    return;
+}


Property changes on: grass/trunk/raster/r.spread/get_minHa.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/insert2Ha.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/insert2Ha.c)
===================================================================
--- grass/trunk/raster/r.spread/insert2Ha.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/insert2Ha.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,44 @@
+
+/***************************************************************/
+/*                                                             */
+/*      insert2Ha.c           in         ~/rsc.src/spread      */
+/*                                                             */
+/*    This routine creates a queue (linked list) of cell_ptr   */
+/*    data structures. It allocates memory for the cell to     */
+/*    be inserted, assigns given coordinates to the structure  */
+/*    attributes, then it insert the new cell into the list.   */
+/*                                                             */
+
+/***************************************************************/
+
+#include <grass/gis.h>
+#include "cell_ptrHa.h"
+#include "local_proto.h"
+
+void
+insert2Ha(struct cell_ptrHa **front_cell,
+	  struct cell_ptrHa **rear_cell, float angle, int row, int col)
+{
+    struct cell_ptrHa *temp_cell, *temp_cell2;
+
+    temp_cell = (struct cell_ptrHa *)(G_malloc(sizeof(struct cell_ptrHa)));
+
+    temp_cell->angle = angle;
+    temp_cell->row = row;
+    temp_cell->col = col;
+
+    if (*front_cell == NULL) {
+	*front_cell = temp_cell;
+	*rear_cell = temp_cell;
+	temp_cell->next = NULL;
+    }
+    else {
+	temp_cell2 = *rear_cell;
+	temp_cell2->next = temp_cell;
+	*rear_cell = temp_cell;
+	temp_cell->next = NULL;
+    }
+    return;
+}
+
+/**************** END OF FUNCTION "INSERT2HA" *********************/


Property changes on: grass/trunk/raster/r.spread/insert2Ha.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/insertHa.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/insertHa.c)
===================================================================
--- grass/trunk/raster/r.spread/insertHa.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/insertHa.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,33 @@
+
+/***********************************************************
+ *
+ *                 insertHa.c (for spread)
+ *  This routine is to insert a new cell into a heap. It is
+ *  a min_heap, the heap order is by the min_cost of cells,
+ *  and the min_cost of the heap root is always the SMALLEST.
+ *
+ ************************************************************/
+
+#include "costHa.h"
+#include "local_proto.h"
+
+void
+insertHa(float new_min_cost, float angle, int row, int col,
+	 struct costHa *heap, long *heap_len)
+{
+    long vacant;
+
+    vacant = ++*heap_len;
+    while (vacant > 1 && new_min_cost < heap[vacant / 2].min_cost) {
+	heap[vacant].min_cost = heap[vacant / 2].min_cost;
+	heap[vacant].angle = heap[vacant / 2].angle;
+	heap[vacant].row = heap[vacant / 2].row;
+	heap[vacant].col = heap[vacant / 2].col;
+	vacant = vacant / 2;
+    }
+    heap[vacant].min_cost = new_min_cost;
+    heap[vacant].angle = angle;
+    heap[vacant].row = row;
+    heap[vacant].col = col;
+    return;
+}


Property changes on: grass/trunk/raster/r.spread/insertHa.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/local_proto.h (from rev 34541, grass/trunk/raster/wildfire/r.spread/local_proto.h)
===================================================================
--- grass/trunk/raster/r.spread/local_proto.h	                        (rev 0)
+++ grass/trunk/raster/r.spread/local_proto.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,48 @@
+#include "cell_ptrHa.h"
+#include "costHa.h"
+/* collect_ori.c */
+void collect_ori(int);
+
+/* deleteHa.c */
+void deleteHa(float, int, int, struct costHa *, long *);
+
+/* display.c */
+void display_init(void);
+void draw_a_cell(int, int, int);
+void draw_a_burning_cell(int, int);
+void display_close(void);
+
+/* fixHa.c */
+struct costHa *fixHa(long, struct costHa *, long);
+
+/* get_minHa.c */
+void get_minHa(struct costHa *, struct costHa *, long);
+
+/* insert2Ha.c */
+void insert2Ha(struct cell_ptrHa **, struct cell_ptrHa **, float, int, int);
+
+/* insertHa.c */
+void insertHa(float, float, int, int, struct costHa *, long *);
+
+/* pick_dist.c */
+int pick_dist(int);
+
+/* pick_ignite.c */
+int pick_ignite(int);
+
+/* ram2out.c */
+void ram2out(void);
+
+/* replaceHa.c */
+void replaceHa(float, float, int, int, struct costHa *, long *);
+
+/* select_linksB.c */
+void select_linksB(struct costHa *, int, float);
+
+/* spot.c */
+void spot(struct costHa *, int);
+
+/* spread.c */
+void spread(void);
+int cumulative(struct costHa *, struct cell_ptrHa *, int, int, int, float *);
+void update(struct costHa *, int, int, double, float);


Property changes on: grass/trunk/raster/r.spread/local_proto.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/main.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/main.c)
===================================================================
--- grass/trunk/raster/r.spread/main.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,545 @@
+
+/****************************************************************************
+ *
+ * MODULE:       r.spread
+ * AUTHOR(S):    Jianping Xu, 1995 (original contributor)
+ *                 Center for Remote Sensing and Spatial Analysis (CRSSA)
+ *                 Rutgers University.
+ *               Andreas.Lange <andreas.lange rhein-main.de>, Eric G. Miller <egm2 jps.net>,
+ *               Markus Neteler <neteler itc.it>, Roberto Flor <flor itc.it>,
+ *               Brad Douglas <rez touchofmadness.com>,
+ *               Glynn Clements <glynn gclements.plus.com>, Jachym Cepicky <jachym les-ejk.cz>
+ * PURPOSE:      
+ *      This is the main program for simulating elliptical spread.
+ *                  
+ *      It
+ *      1) determines the earliest time a phenomenon REACHES to a
+ *         map cell, NOT the time that cell is EXHAUSTED.
+ *      3) If a cell is spread barrier, a no-data value is assigned
+ *         to it.
+ * COPYRIGHT:    (C) 2000-2006 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>
+#include <math.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "cmd_line.h"
+#include "costHa.h"
+#include "cell_ptrHa.h"
+#include "local_proto.h"
+
+#define DATA(map, r, c)		(map)[(r) * ncols + (c)]
+
+CELL range_min, range_max;
+CELL *cell;
+CELL *x_cell;
+CELL *y_cell;
+
+CELL *map_max;
+CELL *map_dir;
+CELL *map_base;
+CELL *map_spotdist;
+CELL *map_velocity;
+CELL *map_mois;
+float *map_out;
+CELL *map_x_out;
+CELL *map_y_out;
+CELL *map_visit;
+
+char buf[400];
+
+float zero = 0.0;
+float neg = -2.0;
+
+int BARRIER = 0;
+int max_fd, dir_fd, base_fd, start_fd;
+int spotdist_fd, velocity_fd, mois_fd;
+int cum_fd, x_fd, y_fd;
+int nrows, ncols;
+
+long heap_len;
+
+struct Cell_head window;
+struct Range range;
+
+struct costHa *heap;
+
+
+int main(int argc, char *argv[])
+{
+    int col, row;
+
+    struct
+    {
+	struct Option *max, *dir, *base, *start,
+	    *spotdist, *velocity, *mois,
+	    *least, *comp_dens, *init_time,
+	    *time_lag, *backdrop, *out, *x_out, *y_out;
+    } parm;
+    struct
+    {
+	/* please, remove before GRASS 7 released */
+	struct Flag *display, *spotting;
+    } flag;
+    struct GModule *module;
+
+    /* initialize access to database and create temporary files */
+
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("raster");
+    module->label =
+	_("Simulates elliptically anisotropic spread on a graphics window and "
+	 "generates a raster map of the cumulative time of spread, "
+	 "given raster maps containing the rates of spread (ROS), the ROS "
+	 "directions and the spread origins.");
+    module->description =
+	_("It optionally produces raster maps to contain backlink UTM "
+	  "coordinates for tracing spread paths.");
+
+    parm.max = G_define_option();
+    parm.max->key = "max";
+    parm.max->type = TYPE_STRING;
+    parm.max->required = YES;
+    parm.max->gisprompt = "old,cell,raster";
+    parm.max->guisection = _("Input_maps");
+    parm.max->description =
+	_("Name of raster map containing MAX rate of spread (ROS) (cm/min)");
+
+    parm.dir = G_define_option();
+    parm.dir->key = "dir";
+    parm.dir->type = TYPE_STRING;
+    parm.dir->required = YES;
+    parm.dir->gisprompt = "old,cell,raster";
+    parm.dir->guisection = _("Input_maps");
+    parm.dir->description =
+	_("Name of raster map containing DIRections of max ROS (degree)");
+
+    parm.base = G_define_option();
+    parm.base->key = "base";
+    parm.base->type = TYPE_STRING;
+    parm.base->required = YES;
+    parm.base->gisprompt = "old,cell,raster";
+    parm.base->guisection = _("Input_maps");
+    parm.base->description =
+	_("Name of raster map containing BASE ROS (cm/min)");
+
+    parm.start = G_define_option();
+    parm.start->key = "start";
+    parm.start->type = TYPE_STRING;
+    parm.start->required = YES;
+    parm.start->gisprompt = "old,cell,raster";
+    parm.start->guisection = _("Input_maps");
+    parm.start->description =
+	_("Name of raster map containing STARTing sources");
+
+    parm.spotdist = G_define_option();
+    parm.spotdist->key = "spot_dist";
+    parm.spotdist->type = TYPE_STRING;
+    parm.spotdist->gisprompt = "old,cell,raster";
+    parm.spotdist->guisection = _("Input_maps");
+    parm.spotdist->description =
+	_("Name of raster map containing max SPOTting DISTance (m) (required w/ -s)");
+
+    parm.velocity = G_define_option();
+    parm.velocity->key = "w_speed";
+    parm.velocity->type = TYPE_STRING;
+    parm.velocity->gisprompt = "old,cell,raster";
+    parm.velocity->guisection = _("Input_maps");
+    parm.velocity->description =
+	_("Name of raster map containing midflame Wind SPEED (ft/min) (required w/ -s)");
+
+    parm.mois = G_define_option();
+    parm.mois->key = "f_mois";
+    parm.mois->type = TYPE_STRING;
+    parm.mois->gisprompt = "old,cell,raster";
+    parm.mois->guisection = _("Input_maps");
+    parm.mois->description =
+	_("Name of raster map containing fine Fuel MOISture of the cell receiving a spotting firebrand (%) (required w/ -s)");
+
+    parm.least = G_define_option();
+    parm.least->key = "least_size";
+    parm.least->type = TYPE_STRING;
+    parm.least->key_desc = "odd int";
+    parm.least->options = "3,5,7,9,11,13,15";
+    parm.least->description =
+	_("Basic sampling window SIZE needed to meet certain accuracy (3)");
+
+    parm.comp_dens = G_define_option();
+    parm.comp_dens->key = "comp_dens";
+    parm.comp_dens->type = TYPE_STRING;
+    parm.comp_dens->key_desc = "decimal";
+    parm.comp_dens->description =
+	_("Sampling DENSity for additional COMPutin (range: 0.0 - 1.0 (0.5))");
+
+    parm.init_time = G_define_option();
+    parm.init_time->key = "init_time";
+    parm.init_time->type = TYPE_STRING;
+    parm.init_time->key_desc = "int (>= 0)";
+    parm.init_time->description =
+	_("INITial TIME for current simulation (0) (min)");
+
+    parm.time_lag = G_define_option();
+    parm.time_lag->key = "lag";
+    parm.time_lag->type = TYPE_STRING;
+    parm.time_lag->key_desc = "int (>= 0)";
+    parm.time_lag->description =
+	_("Simulating time duration LAG (fill the region) (min)");
+
+    parm.backdrop = G_define_option();
+    parm.backdrop->key = "backdrop";
+    parm.backdrop->type = TYPE_STRING;
+    parm.backdrop->gisprompt = "old,cell,raster";
+    parm.backdrop->description =
+	_("Name of raster map as a display backdrop");
+
+    parm.out = G_define_option();
+    parm.out->key = "output";
+    parm.out->type = TYPE_STRING;
+    parm.out->required = YES;
+    parm.out->gisprompt = "new,cell,raster";
+    parm.out->guisection = _("Output_maps");
+    parm.out->description =
+	_("Name of raster map to contain OUTPUT spread time (min)");
+
+    parm.x_out = G_define_option();
+    parm.x_out->key = "x_output";
+    parm.x_out->type = TYPE_STRING;
+    parm.x_out->gisprompt = "new,cell,raster";
+    parm.x_out->guisection = _("Output_maps");
+    parm.x_out->description =
+	_("Name of raster map to contain X_BACK coordinates");
+
+    parm.y_out = G_define_option();
+    parm.y_out->key = "y_output";
+    parm.y_out->type = TYPE_STRING;
+    parm.y_out->gisprompt = "new,cell,raster";
+    parm.y_out->guisection = _("Output_maps");
+    parm.y_out->description =
+	_("Name of raster map to contain Y_BACK coordinates");
+
+    flag.display = G_define_flag();
+    flag.display->key = 'd';
+#if 0
+    flag.display->description = _("DISPLAY 'live' spread process on screen");
+#else
+    flag.display->description = _("Live display - currently DISABLED");
+#endif
+
+    flag.spotting = G_define_flag();
+    flag.spotting->key = 's';
+    flag.spotting->description = _("For wildfires: consider SPOTTING effect");
+
+    /*   Parse command line */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
+    srand(getpid());
+
+    display = flag.display->answer;
+#if 1
+    if (display)
+	G_fatal_error(_("The display feature is disabled"));
+#endif
+    spotting = flag.spotting->answer;
+
+    max_layer = parm.max->answer;
+    dir_layer = parm.dir->answer;
+    base_layer = parm.base->answer;
+    start_layer = parm.start->answer;
+    backdrop_layer = parm.backdrop->answer;
+    out_layer = parm.out->answer;
+    if (parm.x_out->answer) {
+	x_out = 1;
+	x_out_layer = parm.x_out->answer;
+    }
+    if (parm.y_out->answer) {
+	y_out = 1;
+	y_out_layer = parm.y_out->answer;
+    }
+    if (spotting) {
+	if (!
+	    (parm.spotdist->answer && parm.velocity->answer &&
+	     parm.mois->answer)) {
+	    G_warning
+		("SPOTTING DISTANCE, fuel MOISTURE, or wind VELOCITY map not given w/ -s");
+	    G_usage();
+	    exit(EXIT_FAILURE);
+	}
+	else {
+	    spotdist_layer = parm.spotdist->answer;
+	    velocity_layer = parm.velocity->answer;
+	    mois_layer = parm.mois->answer;
+	}
+    }
+    /*Check the given the least sampling size, assign the default if needed */
+    if (parm.least->answer)
+	least = atoi(parm.least->answer);
+    else
+	least = 3;
+    /*Check the given computing density, assign the default if needed */
+    if (parm.comp_dens->answer) {
+	comp_dens = atof(parm.comp_dens->answer);
+	if (comp_dens < 0.0 || comp_dens > 1.0) {
+	    G_warning("Illegal computing density <%s>",
+		      parm.comp_dens->answer);
+	    G_usage();
+	    exit(EXIT_FAILURE);
+	}
+    }
+    else {
+	comp_dens = 0.5;
+    }
+    /*Check the given initial time and simulation time lag, assign the default if needed */
+    if (parm.init_time->answer) {
+	init_time = atoi(parm.init_time->answer);
+	if (init_time < 0) {
+	    G_warning("Illegal initial time <%s>", parm.init_time->answer);
+	    G_usage();
+	    exit(EXIT_FAILURE);
+	}
+    }
+    else {
+	time_lag = 0;
+    }
+    if (parm.time_lag->answer) {
+	time_lag = atoi(parm.time_lag->answer);
+	if (time_lag < 0) {
+	    G_warning("Illegal simulating time lag <%s>",
+		      parm.time_lag->answer);
+	    G_usage();
+	    exit(EXIT_FAILURE);
+	}
+    }
+    else {
+	time_lag = 99999;
+    }
+
+    /*  Get database window parameters  */
+
+    G_get_window(&window);
+
+    /*  find number of rows and columns in window    */
+
+    nrows = G_window_rows();
+    ncols = G_window_cols();
+
+    /*transfor measurement unit from meters to centimeters due to ROS unit
+     *if the input ROSs are in m/min units, cancell the following*/
+    window.ns_res = 100 * window.ns_res;
+    window.ew_res = 100 * window.ew_res;
+
+    /* Initialize display screens */
+#if 0
+    if (display)
+	display_init();
+#endif
+
+    /*  Check if input layers exists in data base  */
+
+    if (G_find_cell2(max_layer, "") == NULL)
+	G_fatal_error("Raster map <%s> not found", max_layer);
+
+    if (G_find_cell2(dir_layer, "") == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), dir_layer);
+
+    if (G_find_cell2(base_layer, "") == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), base_layer);
+
+    if (G_find_cell2(start_layer, "") == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), start_layer);
+
+    if (spotting) {
+	if (G_find_cell2(spotdist_layer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"), spotdist_layer);
+
+	if (G_find_cell2(velocity_layer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"), velocity_layer);
+
+	if (G_find_cell2(mois_layer, "") == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"), mois_layer);
+    }
+
+    /*  Open input cell layers for reading  */
+
+    max_fd = G_open_cell_old(max_layer, G_find_cell2(max_layer, ""));
+    if (max_fd < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), max_layer);
+
+    dir_fd = G_open_cell_old(dir_layer, G_find_cell2(dir_layer, ""));
+    if (dir_fd < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), dir_layer);
+
+    base_fd = G_open_cell_old(base_layer, G_find_cell2(base_layer, ""));
+    if (base_fd < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), base_layer);
+
+    if (spotting) {
+	spotdist_fd =
+	    G_open_cell_old(spotdist_layer, G_find_cell2(spotdist_layer, ""));
+	if (spotdist_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), spotdist_layer);
+
+	velocity_fd =
+	    G_open_cell_old(velocity_layer, G_find_cell2(velocity_layer, ""));
+	if (velocity_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), velocity_layer);
+
+	mois_fd = G_open_cell_old(mois_layer, G_find_cell2(mois_layer, ""));
+	if (mois_fd < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), mois_layer);
+    }
+
+    /*  Allocate memories for a row  */
+    cell = G_allocate_cell_buf();
+    if (x_out)
+	x_cell = G_allocate_cell_buf();
+    if (y_out)
+	y_cell = G_allocate_cell_buf();
+
+    /*  Allocate memories for a map  */
+    map_max = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+    map_dir = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+    map_base = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+    map_visit = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+    map_out = (float *)G_calloc(nrows * ncols + 1, sizeof(float));
+    if (spotting) {
+	map_spotdist = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+	map_velocity = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+	map_mois = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+    }
+    if (x_out)
+	map_x_out = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+    if (y_out)
+	map_y_out = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
+
+
+    /*   Write the input layers in the map "arrays"  */
+
+    G_message(_("Reading inputs..."));
+
+    for (row = 0; row < nrows; row++) {
+	G_percent(row, nrows, 2);
+	if (G_get_map_row(max_fd, cell, row) < 0)
+	    exit(EXIT_FAILURE);
+	for (col = 0; col < ncols; col++)
+	    DATA(map_max, row, col) = cell[col];
+	if (G_get_map_row(dir_fd, cell, row) < 0)
+	    exit(EXIT_FAILURE);
+	for (col = 0; col < ncols; col++)
+	    DATA(map_dir, row, col) = cell[col];
+	if (G_get_map_row(base_fd, cell, row) < 0)
+	    exit(EXIT_FAILURE);
+	for (col = 0; col < ncols; col++)
+	    DATA(map_base, row, col) = cell[col];
+	if (spotting) {
+	    if (G_get_map_row(spotdist_fd, cell, row) < 0)
+		exit(EXIT_FAILURE);
+	    for (col = 0; col < ncols; col++)
+		DATA(map_spotdist, row, col) = cell[col];
+	    if (G_get_map_row(velocity_fd, cell, row) < 0)
+		exit(EXIT_FAILURE);
+	    for (col = 0; col < ncols; col++)
+		DATA(map_velocity, row, col) = cell[col];
+	    if (G_get_map_row(mois_fd, cell, row) < 0)
+		exit(EXIT_FAILURE);
+	    for (col = 0; col < ncols; col++)
+		DATA(map_mois, row, col) = cell[col];
+	}
+    }
+    G_percent(row, nrows, 2);
+
+
+    /*   Scan the START layer searching for starting points.
+     *   Create an array of starting points (min_heap) ordered by costs.
+     */
+
+    start_fd = G_open_cell_old(start_layer, G_find_cell2(start_layer, ""));
+    if (start_fd < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), start_layer);
+
+    G_read_range(start_layer, G_find_file("cell", start_layer, ""), &range);
+    G_get_range_min_max(&range, &range_min, &range_max);
+
+    /*  Initialize the heap  */
+    heap =
+	(struct costHa *)G_calloc(nrows * ncols + 1, sizeof(struct costHa));
+    heap_len = 0;
+
+    G_message(_("Reading %s..."), start_layer);
+    G_debug(1, "Collecting origins...");
+    collect_ori(start_fd);
+    G_debug(1, "Done");
+
+
+    /* Major computation of spread time */
+    G_debug(1, "Spreading...");
+    spread();
+    G_debug(1, "Done");
+
+
+    /*  Open cumulative cost layer (and x, y direction layers) for writing */
+
+    cum_fd = G_open_cell_new(out_layer);
+    if (x_out)
+	x_fd = G_open_cell_new(x_out_layer);
+    if (y_out)
+	y_fd = G_open_cell_new(y_out_layer);
+
+    /* prepare output -- adjust from cm to m */
+    window.ew_res = window.ew_res / 100;
+    window.ns_res = window.ns_res / 100;
+
+    /* copy maps in ram to output maps */
+    ram2out();
+
+    G_free(map_max);
+    G_free(map_dir);
+    G_free(map_base);
+    G_free(map_out);
+    G_free(map_visit);
+    if (x_out)
+	G_free(map_x_out);
+    if (y_out)
+	G_free(map_y_out);
+    if (spotting) {
+	G_free(map_spotdist);
+	G_free(map_mois);
+	G_free(map_velocity);
+    }
+
+    G_close_cell(max_fd);
+    G_close_cell(dir_fd);
+    G_close_cell(base_fd);
+    G_close_cell(start_fd);
+    G_close_cell(cum_fd);
+    if (x_out)
+	G_close_cell(x_fd);
+    if (y_out)
+	G_close_cell(y_fd);
+    if (spotting) {
+	G_close_cell(spotdist_fd);
+	G_close_cell(velocity_fd);
+	G_close_cell(mois_fd);
+    }
+
+    /* close graphics */
+#if 0
+    if (display)
+	display_close();
+#endif
+
+    exit(EXIT_SUCCESS);
+}


Property changes on: grass/trunk/raster/r.spread/main.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/pick_dist.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/pick_dist.c)
===================================================================
--- grass/trunk/raster/r.spread/pick_dist.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/pick_dist.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,30 @@
+
+/******************************************************************************
+ *
+ *	pick_dist.c  inverse square distance distributed probability generator
+ *	
+ * Usage: pick_dist (maxnumber)
+ *
+ * Notes: prob_invsqr() generates a decreasing probability distribution 
+ * outward in an inverse square rate. It use three consecutive random number
+ * generator: 
+ *	applying it once gets an UNIFORM distribution in the range of 0-max_num;
+ *	doing it twice gets a SIMPLE INVERSE distribuion in that range;
+ *	doing three times gets a INVERSE SQUARE distribution.
+ * 
+ * Author: Jianping Xu, Rutgers University
+ * Date: 06/11/1994
+ ******************************************************************************/
+#include <stdlib.h>
+#include <limits.h>
+#include <math.h>
+#include "local_proto.h"
+
+int pick_dist(int u)
+{
+    int v;
+
+    v = (int)((u + 0.99999999999) * rand() / INT_MAX);
+    u = (int)((v + 0.99999999999) * rand() / INT_MAX);
+    return ((int)((u + 0.99999999999) * rand() / INT_MAX));	/*4th for a test */
+}


Property changes on: grass/trunk/raster/r.spread/pick_dist.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/pick_ignite.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/pick_ignite.c)
===================================================================
--- grass/trunk/raster/r.spread/pick_ignite.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/pick_ignite.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,25 @@
+
+/******************************************************************************
+ *
+ *	pick_ignite.c 	pick an ignition based on probability
+ *	
+ * Usage: pick_ignite (fuelmoisture)
+ *
+ * Notes: pick_ignite() pick an ignition idetermined by fine fuel moisture
+ * based on the probability simplified from Rothermel (1983): Predicting
+ * ?????????????????? 
+ * Author: Jianping Xu, Rutgers University
+ * Date: 06/11/1994
+ ******************************************************************************/
+#include <stdlib.h>
+#include <limits.h>
+#include "local_proto.h"
+
+int p[18] = { 100, 100, 100, 90, 80, 70, 60, 50, 40,	/*adapt the "average" */
+    40, 30, 30, 20, 20, 20, 10, 10, 10
+};				/*10-50 shading, 80-89F */
+
+int pick_ignite(int i)
+{
+    return ((100.0 * rand() / INT_MAX) <= p[i]);
+}


Property changes on: grass/trunk/raster/r.spread/pick_ignite.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/r.spread.html (from rev 34541, grass/trunk/raster/wildfire/r.spread/r.spread.html)
===================================================================
--- grass/trunk/raster/r.spread/r.spread.html	                        (rev 0)
+++ grass/trunk/raster/r.spread/r.spread.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,219 @@
+<H2>DESCRIPTION</H2>
+
+Spread phenomena usually show uneven movement over space. Such unevenness
+is due to two reasons:
+<BR>1) the uneven conditions from location to location, which can be called
+SPATIAL HETEROGENEITY, and
+<BR>2) the uneven conditions in different directions, which can be called
+ANISOTROPY.
+<BR>The anisotropy of spread occurs when any of the determining factors
+have directional components. For example, wind and topography cause anisotropic
+spread of wildfires.
+
+<P>One of the simplest spatial heterogeneous and anisotropic spread
+is elliptical spread, in which, each local spread shape can be thought
+as an ellipse. In a raster setting, cell centers are foci of the spread
+ellipses, and the spread phenomenon moves fastest toward apogees and slowest
+to perigees. The sizes and shapes of spread ellipses may vary cell by cell.
+So the overall spread shape is commonly not an ellipse.
+
+<P><I>r.spread </I>simulates elliptically anisotropic spread phenomena,
+given three raster map layers about ROS (base ROS, maximum ROS and direction
+of the maximum ROS) plus a raster map layer showing the starting sources.
+These ROS layers define unique ellipses for all cell locations in the current
+geographic region as if each cell center was a potential spread origin.
+For some wildfire spread, these ROS layers can be generated by another
+GRASS raster program r.ros. The actual locations reached by a spread event
+are constrained by the actual spread origins and the elapsed spread time.
+
+<P><I>r.spread </I>optionally produces raster maps to contain backlink
+UTM coordinates for each raster cell of the spread time map. The spread
+paths can be accurately traced based on the backlink information by another
+GRASS raster program r.spreadpath.
+
+<P>Part of the spotting function in r.spread is based on Chase (1984)
+and Rothermel (1983). More information on <I>r.spread</I>, <I><A HREF="r.ros.html">r.ros</A></I>
+and <I><A HREF="r.spreadpath.html">r.spreadpath</A></I> can be found in
+Xu (1994).
+
+<H2>Flags:</H2>
+<DL>
+
+<DT>-d
+<DD> Display the "live" simulation on screen. A graphics window
+must be opened and selected before using this option.
+
+<DT>-s
+<DD> For wildfires, also consider spotting.
+</DL>
+
+<H2>Parameters</H2>
+<DL>
+ 
+<DT><B>max=</B>name
+<DD>Name of an existing raster map layer in the user's current
+mapset search path containing the maximum ROS values (cm/minute).
+
+<DT><B>dir=</B>name 
+<DD>Name of an existing raster map layer in the user's
+current mapset search path containing directions of the maximum ROSes,
+clockwise from north (degree).
+
+<DT><B>base=</B>name 
+<DD>Name of an existing raster map layer in the user's
+current mapset search path containing the ROS values in the directions
+perpendicular to maximum ROSes' (cm/minute). These ROSes are also the ones
+without the effect of directional factors.
+
+<DT><B>start=</B>name 
+<DD>Name of an existing raster map layer in the
+user's current mapset search path containing starting locations of the
+spread phenomenon. Any positive integers in this map are recognized as
+starting sources.
+
+<DT><B>spot_dist=</B>name 
+<DD>Name of an existing raster map layer in
+the user's current mapset search path containing the maximum potential
+spotting distances (meters).
+
+<DT><B>w_speed=</B>name 
+<DD>Name of an existing raster map layer in the
+user's current mapset search path containing wind velocities at half of
+the average flame height (feet/minute).
+
+<DT><B>f_mois</B>=name 
+<DD>Name of an existing raster map layer in the
+user's current mapset search path containing the 1-hour (&lt;.25") fuel
+moisture (percentage content multiplied by 100).
+
+<DT><B>least_size=</B>odd int An odd integer ranging 3 - 15 indicating
+the basic sampling window size within which all cells will be considered
+to see whether they will be reached by the current spread cell. The default
+number is 3 which means a 3x3 window.
+
+<DT><B>comp_dens=</B>decimal A decimal number ranging 0.0 - 1.0 indicating
+additional sampling cells will be considered to see whether they will be
+reached by the current spread cell. The closer to 1.0 the decimal number
+is, the longer the program will run and the higher the simulation accuracy
+will be. The default number is 0.5.
+
+<DT><B>init_time=</B>int A non-negative number specifying the initial
+time for the current spread simulation (minutes). This is useful when multiple
+phase simulation is conducted. The default time is 0.
+
+<DT><B>lag=</B>int A non-negative integer specifying the simulating
+duration time lag (minutes). The default is infinite, but the program will
+terminate when the current geographic region/mask has been filled. It also
+controls the computational time, the shorter the time lag, the faster the
+program will run.
+
+<DT><B>backdrop=</B>name 
+<DD>Name of an existing raster map layer in the
+user's current mapset search path to be used as the background on which
+the "live" movement will be shown.
+
+<DT><B>output=</B>name 
+<DD>Name of the new raster map layer to contain
+the results of the cumulative spread time needed for a phenomenon to reach
+each cell from the starting sources (minutes).
+
+<DT><B>x_output=</B>name 
+<DD>Name of the new raster map layer to contain
+the results of backlink information in UTM easting coordinates for each
+cell.
+
+<DT><B>y_output</B>=name 
+<DD>Name of the new raster map layer to contain
+the results of backlink information in UTM northing coordinates for each
+cell.
+</DL>
+
+<H2>OPTIONS</H2>
+The user can run r.spread either interactively or non- interactively. The
+program is run interactively if the user types <I>r.spread</I> without
+specifying flag settings and parameter values on the command line. In this
+case, the user will be prompted for input.
+
+<P>Alternately, the user can run r.spread non-interactively, by specifying
+the names of raster map layers and desired options on the command line,
+using the form:
+
+<P>r.spread [-vds] max=name dir=name base=name start=name [spot_dist=name]
+[w_speed=name] [f_mois=name] [least_size=odds int] [comp_dens=decimal]
+[init_time=int (&gt;=0)] [lag=int (&gt;= 0)] [backdrop=name] output=name [x_output=name]
+[y_output=name] The -d option can only be used after a graphics window
+is opened and selected.
+
+<P>Options spot_dist=name, w_speed=name and f_mois=name must all
+be given if the -s option is used.
+
+
+<H2>EXAMPLE</H2>
+Assume we have inputs, the following simulates a spotting- involved wildfire
+on the graphics window and generates three raster maps to contain spread
+time, backlink information in UTM northing and easting coordinates:
+
+<P>r.spread -ds max=my_ros.max dir=my_ros.maxdir base=my_ros.base
+start=fire_origin spot_dist=my_ros.spotdist w_speed=wind_speed f_mois=1hour_moisture
+backdrop=image_burned output=my_spread x_output=my_spread.x y_output=my_spread.y
+
+<H2>NOTES</H2>
+1. r.spread is a specific implementation of the shortest path algorithm.
+r.cost GRASS program served as the starting point for the development of
+r.spread. One of the major differences between the two programs is that
+r.cost only simulates ISOTROPIC spread while r.spread can simulate ELLIPTICALLY
+ANISOTROPIC spread, including isotropic spread as a special case.
+
+<P>2. Before running r.spread, the user should prepare the ROS (base,
+max and direction) maps using appropriate models. For some wildfire spread,
+a separate GRASS program r.ros based on Rothermel's fire equation does
+such work. The combination of the two forms a simulation of wildfire spread.
+
+<P>3. The relationship of the start map and ROS maps should be logically
+correct, i.e. a starting source (a positive value in the start map) should
+not be located in a spread BARRIER (zero value in the ROS maps). Otherwise
+the program refuses to run.
+
+<P>4. r.spread uses the current geographic region settings. The output
+map layer will not go outside the boundaries set in the region, and will
+not be influenced by starting sources outside. So any change of the current
+region may influence the output. The recommendation is to use slightly
+larger region than needed. Refer to g.region to set an appropriate geographic
+region.
+
+<P>5. The inputs to r.spread should be in proper units.
+
+<P>6. r.spread is a computationally intensive program. The user may
+need to choose appropriate size of the geographic region and resolution.
+
+<P>7. A low and medium (i.e. &lt;= 0.5) sampling density can improve
+accuracy for elliptical simulation significantly, without adding significantly
+extra running time. Further increasing the sample density will not gain
+much accuracy while requiring greatly additional running time.
+
+<H2>SEE ALSO</H2>
+
+<EM><A HREF="g.region.html">g.region</A></EM>,
+<EM><A HREF="r.cost.html">r.cost</A></EM>,
+<!-- <EM><A HREF="r.mask.html">r.mask</A></EM>, -->
+<EM><A HREF="r.spreadpath.html">r.spreadpath</A></EM>,
+<EM><A HREF="r.ros.html">r.ros</A></EM>
+
+<H2>REFERENCES</H2>
+Chase, Carolyn, H., 1984, Spotting distance from wind-driven surface fires
+-- extensions of equations for pocket calculators, US Forest Service, Res.
+Note INT-346, Ogden, Utah.
+
+<P>Rothermel, R. C., 1983, How to predict the spread and intensity
+of forest and range fires. US Forest Service, Gen. Tech. Rep. INT-143.
+Ogden, Utah.
+
+<P>Xu, Jianping, 1994, Simulating the spread of wildfires using a
+geographic information system and remote sensing, Ph. D. Dissertation,
+Rutgers University, New Brunswick, New Jersey.
+
+<H2>AUTHOR</H2>
+Jianping Xu and Richard G. Lathrop, Jr., Center for Remote Sensing and
+Spatial Analysis, Rutgers University.
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/raster/r.spread/r.spread.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/ram2out.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/ram2out.c)
===================================================================
--- grass/trunk/raster/r.spread/ram2out.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/ram2out.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <grass/gis.h>
+#include "cmd_line.h"
+#include "costHa.h"
+#include "local_proto.h"
+
+#define DATA(map, r, c)		(map)[(r) * ncols + (c)]
+
+void ram2out(void)
+{
+    extern CELL *cell, *x_cell, *y_cell;
+    extern CELL *map_x_out, *map_y_out;
+    extern float *map_out;
+    extern int cum_fd, x_fd, y_fd;
+    extern int nrows, ncols;
+    extern struct Cell_head window;
+    double north, west;
+    double G_row_to_northing(), G_col_to_easting();
+    int row, col;
+
+    north = G_row_to_northing(0.5, &window);
+    west = G_col_to_easting(0.5, &window);
+    /*  Copy maps in ram to output maps, casting into integers */
+    G_message("Writing output: %s, x_output: %s, y_output: %s ... ",
+	      out_layer, x_out_layer, y_out_layer);
+    for (row = 0; row < nrows; row++) {
+	for (col = 0; col < ncols; col++) {
+	    G_percent(row, nrows, 2);
+	    *(cell + col) = (int)DATA(map_out, row, col);
+	    if (x_out) {
+		if (DATA(map_x_out, row, col) == 0)
+		    *(x_cell + col) = 0;
+		else
+		    *(x_cell + col) =
+			(int)(west +
+			      window.ew_res * DATA(map_x_out, row, col));
+	    }
+	    if (y_out) {
+		if (DATA(map_y_out, row, col) == 0)
+		    *(y_cell + col) = 0;
+		else
+		    *(y_cell + col) =
+			(int)(north -
+			      window.ns_res * DATA(map_y_out, row, col));
+	    }
+	}
+	G_put_raster_row(cum_fd, cell, CELL_TYPE);
+	if (x_out)
+	    G_put_raster_row(x_fd, x_cell, CELL_TYPE);
+	if (y_out)
+	    G_put_raster_row(y_fd, y_cell, CELL_TYPE);
+    }
+    G_percent(row, nrows, 2);
+}


Property changes on: grass/trunk/raster/r.spread/ram2out.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/replaceHa.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/replaceHa.c)
===================================================================
--- grass/trunk/raster/r.spread/replaceHa.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/replaceHa.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,86 @@
+
+/***********************************************************
+ *
+ *                 replaceHa.c (for spread)
+ *  This routine is to delete a cell in a heap. 
+ *  It 1) searches the cell backward and sequentially from 
+ *        the heap (if not found, returns a error message), 
+ *     2) repalce that cell with the new min_cost and
+ *        restore a heap order.
+ *
+ ************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <grass/gis.h>
+#include "costHa.h"
+#include "local_proto.h"
+
+void
+replaceHa(float new_min_cost, float angle, int row, int col,
+	  struct costHa *heap, long *heap_len)
+{
+    long i, smaller_child = 0;
+
+    G_debug(4, "in replaceHa()");
+
+    if (*heap_len < 1)
+	G_fatal_error("Programming ERROR: can't delete a cell from an empty list");
+
+    /* search the cell with row and col from the heap */
+    for (i = *heap_len; i >= 0; i--) {
+	if (heap[i].row == row && heap[i].col == col)
+	    break;
+    }
+    if (i == 0)
+	G_fatal_error("Programming ERROR: can't find the old_cell from the list");
+
+    /* replace this cell, fix the heap */
+    /*take care upward */
+
+    G_debug(4, "in replaceHa() before first while");
+    while (i > 1 && new_min_cost < heap[i / 2].min_cost) {
+	heap[i].min_cost = heap[i / 2].min_cost;
+	heap[i].angle = heap[i / 2].angle;
+	heap[i].row = heap[i / 2].row;
+	heap[i].col = heap[i / 2].col;
+	i = i / 2;
+    }
+
+    /*take care downward */
+    if (2 * i <= *heap_len)
+	smaller_child = 2 * i;
+
+    if ((2 * i < *heap_len) &&
+	(heap[2 * i].min_cost > heap[2 * i + 1].min_cost))
+	smaller_child++;
+
+
+    G_debug(4, "in replaceHa() before second while. smaller_child=%ld",
+	smaller_child);
+
+    while ( (smaller_child <= *heap_len) && (smaller_child > 0) &&
+	   (new_min_cost > heap[smaller_child].min_cost)) {
+
+	heap[i].min_cost = heap[smaller_child].min_cost;
+	heap[i].angle = heap[smaller_child].angle;
+	heap[i].row = heap[smaller_child].row;
+	heap[i].col = heap[smaller_child].col;
+
+	i = smaller_child;
+	smaller_child = 2 * i;
+
+	if ((2 * i < *heap_len) &&
+	    (heap[2 * i].min_cost > heap[2 * i + 1].min_cost))
+	    smaller_child++;
+    }
+
+    /*now i is the right position */
+    heap[i].min_cost = new_min_cost;
+    heap[i].angle = angle;
+    heap[i].row = row;
+    heap[i].col = col;
+
+    G_debug(4, "replaceHa() done");
+
+    return;
+}


Property changes on: grass/trunk/raster/r.spread/replaceHa.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/select_linksB.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/select_linksB.c)
===================================================================
--- grass/trunk/raster/r.spread/select_linksB.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/select_linksB.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,180 @@
+
+/************************************************************************
+ *
+ *	select_linksB.c		in ~/r.spread
+ *
+ *	function to select cell links for elliptical spread and to put 
+ *	the destinated cell of a link in a simple linked list of type
+ *	cell_ptrHa. 
+ *
+ *	The selection rule is: cells in an enlarged spread ellipse 
+ *	centered at the current spread cell. The apogee is 1 cell plus 
+ *	the integer number of cells of the ratio of the maximum rate 
+ *	of spread (ROS) to the base (perpendicular to the max) ROS.
+ *	
+ *	By Jianping Xu, Rutgers University.
+ *	06/22/93
+ *
+ *************************************************************************/
+
+#include <stdio.h>
+#include <math.h>
+#include <grass/gis.h>
+#include "costHa.h"
+#include "cell_ptrHa.h"
+#include "local_proto.h"
+
+#ifndef PI
+#define PI M_PI
+#endif
+
+#define DATA(map, r, c)		(map)[(r) * ncols + (c)]
+
+/*#define DEBUG */
+
+void select_linksB(struct costHa *pres_cell, int least, float comp_dens)
+{
+    extern CELL *map_max, *map_dir, *map_base;	/*for ellipse */
+    extern CELL *map_visit;	/*for avoiding redundancy */
+    extern int BARRIER;
+    extern int nrows, ncols;
+    extern struct cell_ptrHa *front_cell, *rear_cell;
+    float angle;		/*that of a link cell to spread cell */
+    float dir_angle;		/*that of the maximum ROS */
+    float cos_dir_angle, sin_dir_angle;
+    float polar_len;		/*polar distance of the ellipse */
+    float distance;
+    int n = 0, s = 0, e = 0, w = 0;	/*parameters defining a rectangule */
+    int ros_max, ros_base, dir;	/*3 params defining an elps */
+    int row, col;
+
+#ifdef DEBUG
+    printf("\nin select pres(%d,%d) ", pres_cell->row, pres_cell->col);
+#endif
+#ifdef DEBUG
+    for (row = 0; row < nrows; row++) {
+	printf("\nrow %d: ", row);
+	for (col = 0; col < ncols; col++)
+	    printf("%d ", DATA(map_base, row, col));
+    }
+#endif
+
+    ros_max = DATA(map_max, pres_cell->row, pres_cell->col);
+    ros_base = DATA(map_base, pres_cell->row, pres_cell->col);
+    dir = DATA(map_dir, pres_cell->row, pres_cell->col);
+
+    dir_angle = dir % 360 * PI / 180;
+    sin_dir_angle = sin(dir_angle);
+    cos_dir_angle = cos(dir_angle);
+
+    /* identifies a rectangular just enclosing the ellipse,
+     * thus avoiding redundant work in selection */
+
+    if (dir_angle >= 7 * PI / 4 || dir_angle < PI / 4) {	/*down mainly N */
+	n = (ros_max / ros_base - 1) * comp_dens + least;
+	s = least;
+	w = (ros_max / ros_base - 1) * comp_dens + least;
+	e = (ros_max / ros_base - 1) * comp_dens + least;
+    }
+    if (dir_angle >= PI / 4 && dir_angle < 3 * PI / 4) {	/*down mainly E */
+	n = (ros_max / ros_base - 1) * comp_dens + least;
+	s = (ros_max / ros_base - 1) * comp_dens + least;
+	w = least;
+	e = (ros_max / ros_base - 1) * comp_dens + least;
+    }
+    if (dir_angle >= 3 * PI / 4 && dir_angle < 5 * PI / 4) {	/*down mainly S */
+	n = least;
+	s = (ros_max / ros_base - 1) * comp_dens + least;
+	w = (ros_max / ros_base - 1) * comp_dens + least;
+	e = (ros_max / ros_base - 1) * comp_dens + least;
+    }
+    if (dir_angle >= 5 * PI / 4 && dir_angle < 7 * PI / 4) {	/*down mainly W */
+	n = (ros_max / ros_base - 1) * comp_dens + least;
+	s = (ros_max / ros_base - 1) * comp_dens + least;
+	w = (ros_max / ros_base - 1) * comp_dens + least;
+	e = least;
+    }
+
+    if (n > least)
+	n--;
+    if (n > least)
+	n--;
+    if (s > least)
+	s--;
+    if (s > least)
+	s--;
+    if (e > least)
+	e--;
+    if (e > least)
+	e--;
+    if (w > least)
+	w--;
+    if (w > least)
+	w--;
+
+    /* collect cells in the elliptical templet, put into a list */
+    for (row = pres_cell->row - n; row <= pres_cell->row + s; row++) {
+	if (row < 0 || row >= nrows)	/*outside n,s */
+	    continue;
+
+	for (col = pres_cell->col - w; col <= pres_cell->col + e; col++) {
+
+	    G_debug(4,
+		"(%d, %d) max=%d base=%d dir=%d least=%d n=%d s=%d e=%d w=%d base=%d BARRIER=%d",
+		 row, col, ros_max, ros_base, dir, least, n, s, e, w,
+		 DATA(map_base, row, col), BARRIER);
+
+	    if (col < 0 || col >= ncols)	/*outside e,w */
+		continue;
+
+	    G_debug(4,
+		"(%d, %d) max=%d base=%d dir=%d least=%d n=%d s=%d e=%d w=%d base=%d BARRIER=%d",
+		 row, col, ros_max, ros_base, dir, least, n, s, e, w,
+		 DATA(map_base, row, col), BARRIER);
+
+	    if (row == pres_cell->row && col == pres_cell->col)
+		continue;	/*spread cell */
+
+	    G_debug(4,
+		"(%d, %d) max=%d base=%d dir=%d least=%d n=%d s=%d e=%d w=%d base=%d BARRIER=%d",
+		 row, col, ros_max, ros_base, dir, least, n, s, e, w,
+		 DATA(map_base, row, col), BARRIER);
+
+	    if (DATA(map_visit, row, col))	/*visited? */
+		continue;
+
+	    G_debug(4,
+		"(%d, %d) max=%d base=%d dir=%d least=%d n=%d s=%d e=%d w=%d base=%d BARRIER=%d",
+		 row, col, ros_max, ros_base, dir, least, n, s, e, w,
+		 DATA(map_base, row, col), BARRIER);
+
+	    if (DATA(map_base, row, col) == BARRIER)	/*barriers */
+		continue;
+
+	     G_debug(4,
+		"(%d, %d) max=%d base=%d dir=%d least=%d n=%d s=%d e=%d w=%d",
+		 row, col, ros_max, ros_base, dir, least, n, s, e, w);
+	    angle =
+		atan2((double)(col - pres_cell->col),
+		      (double)(pres_cell->row - row));
+
+	    /*the polar (square) distance of enlarged ellipse */
+	    polar_len =
+		(1 / (1 - (1 - ros_base / (float)ros_max)
+			* cos(angle - dir_angle))) *
+			(1 / (1 - (1 - ros_base / (float)ros_max) *
+			cos(angle - dir_angle))) + 2 * least * least;
+
+	    /*the (square) distance to this cell */
+	    distance =
+		(float)(row - pres_cell->row) * (row - pres_cell->row) +
+		(col - pres_cell->col) * (col - pres_cell->col);
+
+	    /*applies the selection rule */
+	    if (distance > polar_len)
+		continue;
+
+	    insert2Ha(&front_cell, &rear_cell, (float)angle, row, col);
+	}
+    }
+}


Property changes on: grass/trunk/raster/r.spread/select_linksB.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/spot.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/spot.c)
===================================================================
--- grass/trunk/raster/r.spread/spot.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/spot.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,130 @@
+
+/******************************************************************************
+ *	spot.c 		in ~/r.spread.fast
+ *	
+ *  	This function is for wildfire spread simulation only.
+ *	It 1) is an inverse square distance randomization of the maximum 
+ * 	   spotting distance;
+ *
+ *		| p(X)
+ *		|
+ *		|*
+ *		|*
+ *		| 
+ *		| *
+ *		|  			1
+ *		|   *		p(X) = ---	(0 <= X <= max_dist)
+ *		|    *		       X^2
+ *		|      *
+ *		|	 *
+ *		|	   *
+ *		|	      *
+ *		|		 *
+ *		|		     *
+ *		|			  *
+ *		|______________________________********_______  X
+ *						      ^
+ *						     max_dist
+ *
+ * 	2) the maximum spotting distance is derived from simplification of 
+ *	   Chase (1984);
+ *	3) the landing firebrand may ignite spread based on fine fuel
+ *	   moisture dictated probability simplified from Rothermel (1983);
+ *	4) spotting travel time is proportional to but slower than windspeed;
+ *	5) there is an elapsed time to reach equilibium rate of spread (ROS).
+ *	   This elapsed time is proportional to the ROS. 
+ * Refs:
+ * Chase, C. H., 1984, Spotting distance from wind-driven surface fires --
+ * 	ententions of equations for pocket calculators, US Forest Service, Res. 
+ *	Note INT-346, Ogden, Uhta, 27 p.
+ * Rothermel, R. C., 1983, How to predict the spread and intensity of forest 
+ *	and range fires. US Forest Service, Gen. Tech. Rep. INT-143. Ogden, 
+ *	Utha, 161 p.
+ ******************************************************************************/
+#include <stdio.h>
+#include <math.h>
+#include <grass/gis.h>
+#include "cmd_line.h"
+#include "costHa.h"
+#include "cell_ptrHa.h"
+#include "local_proto.h"
+
+#ifndef PI
+#define PI M_PI
+#endif
+
+#define DATA(map, r, c)		(map)[(r) * ncols + (c)]
+
+void spot(struct costHa *pres_cell, int dir /* direction of forward ROS */ )
+{
+    extern CELL *map_max;	/* max ROS (cm/min) */
+    extern CELL *map_spotdist;	/* max spotting distance (m) */
+    extern CELL *map_velocity;	/* midflame windspeed (ft/min) */
+    extern CELL *map_mois;	/* fuel moisture (%) */
+
+    /*      extern float    PI; */
+    extern int nrows, ncols;
+    extern struct Cell_head window;
+    float spot_cost;		/* spotting travel time (min) */
+    float min_cost;		/* min cumulative time (min) */
+    float U;			/* wind speed at 6m (m/min) */
+    float Te;			/* time to reach max ROS (min) */
+    int land_dist;		/* stochastic landing dist (m) */
+    int land_distc;		/* land_dist in cell counts */
+    int row, col;
+
+    /* Find the (cell) location spotting might reach */
+
+    land_dist = pick_dist(DATA(map_spotdist, pres_cell->row, pres_cell->col));
+
+    G_debug(1, "pres_cell(%d, %d): land_dist=%d", pres_cell->row,
+	   pres_cell->col, land_dist);
+
+    land_distc = land_dist / (window.ns_res / 100);	/* 100 fac due to cm */
+
+    if (land_distc < 2)		/* no need for adjacent cells */
+	return;
+    row = pres_cell->row - land_distc * cos((dir % 360) * PI / 180) + 0.5;
+    col = pres_cell->col + land_distc * sin((dir % 360) * PI / 180) + 0.5;
+    if (row < 0 || row >= nrows)	/* outside the region */
+	return;
+    if (col < 0 || col >= ncols)	/* outside the region */
+	return;
+    if (DATA(map_max, row, col) <= 0)	/* a barrier */
+	return;
+
+    /* check if ignitable based on probs. modified from Rothermel (1983) */
+
+    if (DATA(map_mois, row, col) > 17)	/* too wet */
+	return;
+
+    G_debug(1,
+      "	pre pick_ignite(): land_distc(%d, %d)=%d dir=%d PI=%.2f (dir%%360)*PI/180=%.2f",
+	  row, col, land_distc, dir, PI, (dir % 360) * PI / 180);
+
+    if (pick_ignite(DATA(map_mois, row, col)) == 0)	/* not success */
+	return;
+
+    G_debug(1, "	post pick_ignite(): land_distc(%d, %d)=%d ",
+	   row, col, land_distc);
+
+    /* travel time by spotting */
+
+    U = 0.305 * DATA(map_velocity, pres_cell->row, pres_cell->col);
+    /*NOTE: use value at midflame */
+    spot_cost = land_dist / U;
+
+    /* elapsed time to reach the max ROS, proportional to ROS */
+
+    Te = DATA(map_max, pres_cell->row, pres_cell->col) / 1000 + 1;
+
+    /* cumulative travel time since start */
+
+    min_cost = pres_cell->min_cost + spot_cost + Te;
+
+    /* update it to the to_cell */
+    G_debug(1, "		min_cost=%.2f: pres=%.2f spot=%.2f Te=%.2f",
+	   min_cost, pres_cell->min_cost, spot_cost, Te);
+
+    update(pres_cell, row, col, (double)dir, min_cost);
+}


Property changes on: grass/trunk/raster/r.spread/spot.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spread/spread.c (from rev 34541, grass/trunk/raster/wildfire/r.spread/spread.c)
===================================================================
--- grass/trunk/raster/r.spread/spread.c	                        (rev 0)
+++ grass/trunk/raster/r.spread/spread.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,285 @@
+
+/***********************************************************************
+ *
+ *	spread.c	in ../r.spread
+ *
+ *	This is a raster version of Dijkstra's shortest path algorithm
+ *	that is suited for simulating elliptical spread phenomena. It 
+ *		1) starts from each spread origin (stored in 
+ *		   a linked list of type costHa) - spread();
+ *		2) selects appropriate cells as links for the current
+ *		   spread cell and stored in a linked list of type 
+ *		   cell_ptrHa - select() ;
+ *		   	A) caculates the cumulative cost (time) of the 
+ *			   end cell of each link - calculate();
+ *			B) compares this new cumulative cost (time) with 
+ *			   the previously computed cumulative time/cost, 
+ *			   if there is any, of the same cell - update();
+ *			C) puts this cell into a min-heap and puts the 
+ *			   new cumulative cost (time) together with UTM 
+ *			   coordinates in the cumulative cost (time) 
+ *			   map, x (East) map and y (North) map if 
+ *			   there is no previous cumulative cost (time);
+ *			   otherwise, if the new cumulative cost (time)
+ *			   is less, replaces with it both in the heap
+ *			   and the output maps - update().
+ *		3) gets the first cell in the min-heap, which is the 
+ *		   cell with the least cumulative cost (time), and 
+ *		   repeats Step 2 until the heap is empty or desired 
+ *		   simulated cumulative cost (time) is reached - spread().
+ *
+ ***********************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <grass/gis.h>
+#include "cmd_line.h"
+#include "costHa.h"
+#include "cell_ptrHa.h"
+#include "local_proto.h"
+
+#ifndef PI
+#define PI M_PI
+#endif
+#define DATA(map, r, c)		(map)[(r) * ncols + (c)]
+
+/*#define DEBUG */
+
+extern CELL *map_max, *map_base, *map_dir, *map_visit;
+extern CELL *map_x_out, *map_y_out;
+extern float *map_out;
+extern int BARRIER;
+extern int nrows, ncols;
+
+/* extern float         PI; */
+extern long heap_len;
+extern struct costHa *heap;
+extern struct Cell_head window;
+
+struct cell_ptrHa *front_cell = NULL, *rear_cell = NULL;
+
+void spread(void)
+{
+    float min_cost;
+    int ros_max, ros_base, dir;
+    int row, col;
+    int cell_count = 0, ncells = 0;
+    struct cell_ptrHa *to_cell, *old_to_cell;
+    struct costHa *pres_cell;
+
+    ncells = nrows * ncols;
+    G_message
+	("Finding spread time - number of cells visited in percentage ...  %3d%%",
+	 0);
+    pres_cell = (struct costHa *)G_malloc(sizeof(struct costHa));
+    get_minHa(heap, pres_cell, heap_len);
+    G_debug(2, "begin spread: cost(%d,%d)=%f", pres_cell->row, pres_cell->col,
+	    pres_cell->min_cost);
+    G_debug(2,
+	    "              heap_len=%ld pres_cell->min_cost=%f time_lag=%d",
+	    heap_len, pres_cell->min_cost, time_lag);
+    while (heap_len-- > 0 && pres_cell->min_cost < init_time + time_lag + 1.0) {
+	ros_max = DATA(map_max, pres_cell->row, pres_cell->col);
+	ros_base = DATA(map_base, pres_cell->row, pres_cell->col);
+	dir = DATA(map_dir, pres_cell->row, pres_cell->col);
+
+	/*Select end cells of links of the present cell */
+	select_linksB(pres_cell, least / 2, comp_dens);
+
+#ifdef DEBUG
+	to_cell = front_cell;
+	while (to_cell != NULL) {
+	    printf("(%d,%d) ", to_cell->row, to_cell->col);
+	    to_cell = to_cell->next;
+	}
+#endif
+	/*Get a cell in the list each time, and compute culmulative costs
+	 *via the current spread cell*/
+	to_cell = front_cell;
+	while (to_cell != NULL) {
+	    /*calculate cumulative costs,
+	     *function returns -1 if detected a barrier */
+	    if (cumulative
+		(pres_cell, to_cell, ros_max, ros_base, dir,
+		 &min_cost) == -1) {
+		old_to_cell = to_cell;
+		to_cell = to_cell->next;
+		front_cell = to_cell;
+		G_free(old_to_cell);
+		continue;
+	    }
+
+	    G_debug(2, "	finish a link: cost(%d,%d)->(%d,%d)=%f",
+		    pres_cell->row, pres_cell->col, to_cell->row,
+		    to_cell->col, min_cost);
+	    /*update the cumulative time/cost */
+	    update(pres_cell, to_cell->row, to_cell->col, to_cell->angle,
+		   min_cost);
+	    old_to_cell = to_cell;
+	    to_cell = to_cell->next;
+	    front_cell = to_cell;
+	    G_free(old_to_cell);
+	}
+
+	/*compute spotting fires */
+	if (spotting)
+	    spot(pres_cell, dir);
+
+	/*mark a visited cell */
+	DATA(map_visit, pres_cell->row, pres_cell->col) = YES;
+#if 0
+	if (display)
+	    draw_a_cell(pres_cell->row, pres_cell->col,
+			(int)pres_cell->min_cost);
+#endif
+
+	cell_count++;
+	if ((100 * cell_count / ncells) % 2 == 0 &&
+	    (100 * (cell_count + (int)(0.009 * ncells)) / ncells) % 2 == 0) {
+	    G_percent(cell_count, ncells, 2);
+	}
+
+	get_minHa(heap, pres_cell, heap_len);
+	G_debug(2,
+		"in while:     heap_len=%ld pres_cell->min_cost=%f time_lag=%d",
+		heap_len, pres_cell->min_cost, time_lag);
+    }				/*end 'while (heap_len-- >0)' */
+    G_free(pres_cell);
+
+    /*Assign min_cost values to un-reached area */
+    for (row = 0; row < nrows; row++) {
+	for (col = 0; col < ncols; col++) {
+	    if (!DATA(map_visit, row, col)) {
+		DATA(map_out, row, col) = (float)BARRIER;
+		if (x_out)
+		    DATA(map_x_out, row, col) = 0;
+		if (y_out)
+		    DATA(map_y_out, row, col) = 0;
+	    }
+	}
+    }
+    G_debug(2, "end spread");
+}				/*end spread () */
+
+
+/******* function computing cumulative spread time/cost, ***************
+ ******* good for both adjacent cell links and non-adjacent cell links */
+
+int
+cumulative(struct costHa *pres_cell, struct cell_ptrHa *to_cell,
+	   int ros_max, int ros_base, int dir, float *min_cost)
+{
+    float ros, xros, cost;
+    float xstep_len;
+    float cos_angle, sin_angle;
+    int xrow, xcol, xsteps, count;
+
+    /*most of the actions below calculate the cumulative time/cost,
+     *from the current spread cell, of the end cell of one link*/
+
+    sin_angle = sin(to_cell->angle);
+    cos_angle = cos(to_cell->angle);
+
+    if (abs(pres_cell->row - to_cell->row) >
+	abs(pres_cell->col - to_cell->col)) {
+	xsteps = abs(pres_cell->row - to_cell->row);
+	xstep_len = 1 / cos_angle;
+	if (xstep_len < 0.0)
+	    xstep_len = -xstep_len;
+    }
+    else {
+	xsteps = abs(pres_cell->col - to_cell->col);
+	xstep_len = 1 / sin_angle;
+	if (xstep_len < 0.0)
+	    xstep_len = -xstep_len;
+    }
+
+    /*ROS value based on a 'from_cell', (elliptical cases) */
+    ros =
+	ros_base / (1 -
+		    (1 - ros_base / (float)ros_max) * cos(to_cell->angle -
+							  dir % 360 * PI /
+							  180));
+
+    /*the next cell */
+    xrow = pres_cell->row - xstep_len * cos_angle + 0.5;
+    xcol = pres_cell->col + xstep_len * sin_angle + 0.5;
+
+    cost = 0.0;
+    count = 1;
+    while (count <= xsteps) {
+	/*Can't go through a barrer in a path */
+	if (DATA(map_base, xrow, xcol) <= 0)
+	    return -1;
+
+	/*ROS value based on current 'to_cell', (elliptical cases) */
+	xros =
+	    DATA(map_base, xrow,
+		 xcol) / (1 - (1 -
+			       DATA(map_base, xrow,
+				    xcol) / (float)DATA(map_max, xrow,
+							xcol)) *
+			  cos(to_cell->angle -
+			      DATA(map_dir, xrow, xcol) % 360 * PI / 180));
+	/*Calculate cost to this cell */
+	cost =
+	    cost + 0.5 * (xstep_len * window.ns_res / ros +
+			  xstep_len * window.ns_res / xros);
+
+	/*Update temp cell along the path, and counter */
+	ros = xros;
+	xrow = pres_cell->row - count * xstep_len * cos_angle + 0.5;
+	xcol = pres_cell->col + count * xstep_len * sin_angle + 0.5;
+	count++;
+    }				/*end'while (count<= ..)' */
+    G_debug(2, "		in cumulatvie() cost=%.2f pre min_cost=%.2f",
+	    cost, *min_cost);
+    /*from the origin, cumulative time/cost of the end cell of one link */
+    *min_cost = pres_cell->min_cost + cost;
+    G_debug(2, "		in cumulatvie() 	 post min_cost=%.2f",
+	    *min_cost);
+
+    return 0;
+}
+
+
+/****** function for updating the cumulative cost/time, possibaly     ********
+ ****** back path x,y coordinates, both in the output(s) and the heap ********/
+
+void
+update(struct costHa *pres_cell, int row, int col, double angle,
+       float min_cost)
+{
+    if (DATA(map_out, row, col) < -1.0) {
+	G_debug(2, "	insert: out(%d,%d)=%f min_cost=%f", row, col,
+		DATA(map_out, row, col), min_cost);
+	DATA(map_out, row, col) = min_cost;
+	if (x_out)
+	    DATA(map_x_out, row, col) = pres_cell->col;
+	if (y_out)
+	    DATA(map_y_out, row, col) = pres_cell->row;
+
+	insertHa(min_cost, angle, row, col, heap, &heap_len);
+#if 0
+	if (display && min_cost < init_time + time_lag + 1.0)
+	    draw_a_burning_cell(row, col);
+#endif
+    }
+    else {
+	if (DATA(map_out, row, col) > min_cost + 0.001) {
+	    G_debug(2, "	replace: out(%d,%d)=%f min_cost=%f", row, col,
+		    DATA(map_out, row, col), min_cost);
+	    DATA(map_out, row, col) = min_cost;
+	    if (x_out)
+		DATA(map_x_out, row, col) = pres_cell->col;
+	    if (y_out)
+		DATA(map_y_out, row, col) = pres_cell->row;
+
+	    replaceHa(min_cost, angle, row, col, heap, &heap_len);
+#if 0
+	    if (display && min_cost < init_time + time_lag + 1.0)
+		draw_a_burning_cell(row, col);
+#endif
+	}
+    }
+}


Property changes on: grass/trunk/raster/r.spread/spread.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/raster/r.spreadpath
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Copied: grass/trunk/raster/r.spreadpath/Makefile (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/Makefile)
===================================================================
--- grass/trunk/raster/r.spreadpath/Makefile	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.spreadpath
+
+LIBES = $(SEGMENTLIB) $(GISLIB)
+DEPENDENCIES = $(SEGMENTDEP) $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass/trunk/raster/r.spreadpath/Makefile
___________________________________________________________________
Name: svn:mime-type
   + text/x-sh
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spreadpath/drawline.c (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/drawline.c)
===================================================================
--- grass/trunk/raster/r.spreadpath/drawline.c	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/drawline.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,79 @@
+
+/****** drawline.c *****************************************************
+
+	Function to draw a line segment defined by points (row, col) 
+	and (backrow, backcol) using Bresenham's Algorithm.
+	Note: 	do not draw the end point (backrow, backcol) 
+		except when it is the same as the beginning point 
+		(row, col) in order to be able utilize path segments
+		drawn before the current path segment.
+		 
+ ***********************************************************************/
+#include <grass/segment.h>
+
+
+void drawline(int x1, int y1, int x2, int y2)
+{
+    extern char *value;
+    extern SEGMENT out_seg;
+
+    int dx, dy, i, e;
+    int incx, incy, inc1, inc2;
+    int x, y;
+    int data = 1;
+
+    /*debug: printf("\n(%d,%d)->(%d,%d): ", x1,y1,x2,y2); */
+    dx = x2 - x1;
+    dy = y2 - y1;
+    incx = 1;
+    incy = 1;
+    if (dx < 0) {
+	dx = -dx;
+	incx = -1;
+    }
+    if (dy < 0) {
+	dy = -dy;
+	incy = -1;
+    }
+    x = x1;
+    y = y1;
+
+    value = (char *)&data;
+
+    if (dx > dy) {
+	segment_put(&out_seg, value, x, y);
+	/*debug: printf("put1-(%d,%d) ",x,y); */
+	e = 2 * dy - dx;
+	inc1 = 2 * (dy - dx);
+	inc2 = 2 * dy;
+	for (i = 0; i < dx - 1; i++) {
+	    if (e >= 0) {
+		y += incy;
+		e += inc1;
+	    }
+	    else
+		e += inc2;
+	    x += incx;
+	    segment_put(&out_seg, value, x, y);
+	    /*debug:printf("put2-(%d,%d) ",x,y); */
+	}
+    }
+    else {
+	segment_put(&out_seg, value, x, y);
+	/*debug:printf("put3-(%d,%d) ",x,y); */
+	e = 2 * dx - dy;
+	inc1 = 2 * (dx - dy);
+	inc2 = 2 * dx;
+	for (i = 0; i < dy - 1; i++) {
+	    if (e >= 0) {
+		x += incx;
+		e += inc1;
+	    }
+	    else
+		e += inc2;
+	    y += incy;
+	    segment_put(&out_seg, value, x, y);
+	    /*debug:rintf("put4-(%d,%d) ",x,y); */
+	}
+    }
+}


Property changes on: grass/trunk/raster/r.spreadpath/drawline.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spreadpath/insert.c (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/insert.c)
===================================================================
--- grass/trunk/raster/r.spreadpath/insert.c	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/insert.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,27 @@
+#include <grass/gis.h>
+#include <grass/segment.h>
+#include "point.h"
+
+
+void insert(POINT ** pres_pt, int row, int col, int backrow, int backcol)
+{
+    extern POINT *head_start_pt;
+    POINT *new_pt;
+
+    new_pt = (struct point *)G_malloc(sizeof(struct point));
+
+    new_pt->row = row;
+    new_pt->col = col;
+    new_pt->backrow = backrow;
+    new_pt->backcol = backcol;
+    new_pt->next = NULL;
+
+    if (head_start_pt == NULL) {
+	head_start_pt = new_pt;
+	*pres_pt = head_start_pt;
+    }
+    else {
+	(*pres_pt)->next = new_pt;
+	*pres_pt = (*pres_pt)->next;
+    }
+}


Property changes on: grass/trunk/raster/r.spreadpath/insert.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spreadpath/local_proto.h (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/local_proto.h)
===================================================================
--- grass/trunk/raster/r.spreadpath/local_proto.h	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/local_proto.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,16 @@
+#ifndef __LOCAL_PROTO_H__
+#define __LOCAL_PROTO_H__
+
+#include "point.h"
+
+
+/* drawline.c */
+void drawline(int x1, int y1, int x2, int y2);
+
+/* insert.c */
+void insert(POINT ** pres_pt, int row, int col, int backrow, int backcol);
+
+/* path_finder.c */
+void path_finder(int row, int col, int backrow, int backcol);
+
+#endif


Property changes on: grass/trunk/raster/r.spreadpath/local_proto.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spreadpath/main.c (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/main.c)
===================================================================
--- grass/trunk/raster/r.spreadpath/main.c	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,357 @@
+
+/****************************************************************************
+ *
+ * MODULE:       r.spreadpath
+ * AUTHOR(S):    Jianping Xu 1995: WIldfire SPread Simulation, WiSpS (original contributor)
+ *               Markus Neteler <neteler itc.it>
+ *               Roberto Flor <flor itc.it>, Brad Douglas <rez touchofmadness.com>,
+ *               Glynn Clements <glynn gclements.plus.com>, Jachym Cepicky <jachym les-ejk.cz>
+ * PURPOSE:      This is the main program for tracing out the shortest path(s)
+ *               based on the raster map showing back path cells from which the   
+ *               cumulative costs were determined.
+ * COPYRIGHT:    (C) 2000-2006 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.
+ *
+ *****************************************************************************/
+
+/**********************************************************************/
+/*                                                                    */
+/*      This is the main program for tracing out the shortest path(s) */
+/*      based on the raster map showing back path cells from which the */
+/*      cumulative costs were determined.                             */
+/*                                                                    */
+
+/**********************************************************************/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <grass/segment.h>
+#include <grass/gis.h>
+
+#include "stash.h"
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+
+struct variables
+{
+    char *alias;
+    int position;
+} variables[] = {
+    {"x_input", BACKCOL_LAYER},
+    {"y_input", BACKROW_LAYER},
+    {"coor", START_PT},
+    {"output", PATH_LAYER}
+};
+
+char path_layer[64];
+char backrow_layer[64];
+char backcol_layer[64];
+struct point *head_start_pt = NULL;
+
+char *value;
+int nrows, ncols;
+SEGMENT in_row_seg, in_col_seg, out_seg;
+
+
+int main(int argc, char **argv)
+{
+    int n, verbose = 1,
+	backrow, backcol,
+	col, row,
+	len, flag,
+	srows, scols,
+	backrow_fd, backcol_fd, path_fd, in_row_fd, in_col_fd, out_fd;
+    const char *current_mapset,
+	*search_mapset,
+	*path_mapset,
+	*backrow_mapset,
+	*backcol_mapset, *in_row_file, *in_col_file, *out_file;
+    CELL *cell;
+    POINT *PRES_PT, *PRESENT_PT, *OLD_PT;
+    struct Cell_head window;
+    double east, north;
+    struct Option *opt1, *opt2, *opt3, *opt4;
+    struct Flag *flag1;
+    struct GModule *module;
+
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("raster");
+    module->description =
+	_("Recursively traces the least cost path backwards to "
+	  "cells from which the cumulative cost was determined.");
+
+    opt1 = G_define_option();
+    opt1->key = "x_input";
+    opt1->type = TYPE_STRING;
+    opt1->required = YES;
+    opt1->gisprompt = "old,cell,raster";
+    opt1->description =
+	_("Name of raster map containing back-path easting information");
+
+    opt2 = G_define_option();
+    opt2->key = "y_input";
+    opt2->type = TYPE_STRING;
+    opt2->required = YES;
+    opt2->gisprompt = "old,cell,raster";
+    opt2->description =
+	_("Name of raster map containing back-path northing information");
+
+    opt3 = G_define_option();
+    opt3->key = "coordinate";
+    opt3->type = TYPE_STRING;
+    opt3->multiple = YES;
+    opt3->key_desc = "x,y";
+    opt3->description =
+	_("The map E and N grid coordinates of starting points");
+
+    opt4 = G_define_option();
+    opt4->key = "output";
+    opt4->type = TYPE_STRING;
+    opt4->required = YES;
+    opt4->gisprompt = "new,cell,raster";
+    opt4->description = _("Name of spread path raster map");
+
+    flag1 = G_define_flag();
+    flag1->key = 'v';
+    flag1->description = _("Run verbosely");
+
+    /*   Do command line parsing    */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    current_mapset = G_mapset();
+    in_row_file = G_tempfile();
+    in_col_file = G_tempfile();
+    out_file = G_tempfile();
+
+    /*  Get database window parameters      */
+    G_get_window(&window);
+
+    verbose = flag1->answer;
+
+    /*  Check if backrow layer exists in data base  */
+    search_mapset = "";
+
+    strcpy(backrow_layer, opt2->answer);
+    strcpy(backcol_layer, opt1->answer);
+
+    backrow_mapset = G_find_cell(backrow_layer, search_mapset);
+    backcol_mapset = G_find_cell(backcol_layer, search_mapset);
+
+    if (backrow_mapset == NULL)
+	G_fatal_error("%s - not found", backrow_layer);
+
+    if (backcol_mapset == NULL)
+	G_fatal_error("%s - not found", backcol_layer);
+
+    search_mapset = "";
+
+    strcpy(path_layer, opt4->answer);
+
+    path_mapset = G_find_cell(path_layer, search_mapset);
+
+    /*  find number of rows and cols in window    */
+    nrows = G_window_rows();
+    ncols = G_window_cols();
+
+    cell = G_allocate_cell_buf();
+
+    /*  Open back cell layers for reading  */
+    backrow_fd = G_open_cell_old(backrow_layer, backrow_mapset);
+    if (backrow_fd < 0)
+	G_fatal_error("%s - can't open raster map", backrow_layer);
+
+    backcol_fd = G_open_cell_old(backcol_layer, backcol_mapset);
+    if (backcol_fd < 0)
+	G_fatal_error("%s - can't open raster map", backcol_layer);
+
+    /*   Parameters for map submatrices   */
+    len = sizeof(CELL);
+
+    srows = nrows / 4 + 1;
+    scols = ncols / 4 + 1;
+
+    if (verbose)
+	G_message
+	    ("\nReading the input map -%s- and -%s- and creating some temporary files...",
+	     backrow_layer, backcol_layer);
+
+    /* Create segmented files for back cell and output layers  */
+    in_row_fd = creat(in_row_file, 0666);
+    segment_format(in_row_fd, nrows, ncols, srows, scols, len);
+    close(in_row_fd);
+    in_col_fd = creat(in_col_file, 0666);
+    segment_format(in_col_fd, nrows, ncols, srows, scols, len);
+    close(in_col_fd);
+
+    out_fd = creat(out_file, 0666);
+    segment_format(out_fd, nrows, ncols, srows, scols, len);
+    close(out_fd);
+
+    /*   Open initialize and segment all files  */
+    in_row_fd = open(in_row_file, 2);
+    segment_init(&in_row_seg, in_row_fd, 4);
+    in_col_fd = open(in_col_file, 2);
+    segment_init(&in_col_seg, in_col_fd, 4);
+
+    out_fd = open(out_file, 2);
+    segment_init(&out_seg, out_fd, 4);
+
+    /*   Write the back cell layers in the segmented files, and  
+     *   Change UTM coordinates to ROWs and COLUMNs */
+    for (row = 0; row < nrows; row++) {
+	if (G_get_map_row(backrow_fd, cell, row) < 0)
+	    G_fatal_error("unable to get map row %d", row);
+
+	for (col = 0; col < ncols; col++)
+	    if (cell[col] > 0)
+		cell[col] =
+		    (window.north - cell[col]) / window.ns_res /* - 0.5 */ ;
+	    else
+		cell[col] = -1;
+	segment_put_row(&in_row_seg, cell, row);
+	if (G_get_map_row(backcol_fd, cell, row) < 0)
+	    G_fatal_error("unable to get map row %d", row);
+
+	for (col = 0; col < ncols; col++)
+	    if (cell[col] > 0)
+		cell[col] =
+		    (cell[col] - window.west) / window.ew_res /* - 0.5 */ ;
+	segment_put_row(&in_col_seg, cell, row);
+    }
+
+    /* Convert easting and northing from the command line to row and col */
+    if (opt3->answer) {
+	for (n = 0; opt3->answers[n] != NULL; n += 2) {
+	    G_scan_easting(opt3->answers[n], &east, G_projection());
+	    G_scan_northing(opt3->answers[n + 1], &north, G_projection());
+	    row = (window.north - north) / window.ns_res;
+	    col = (east - window.west) / window.ew_res;
+	    /* ignore pt outside window */
+	    if (east < window.west || east > window.east ||
+		north < window.south || north > window.north) {
+		G_warning("Ignoring point outside window: ");
+		G_warning("   %.4f,%.4f", east, north);
+		continue;
+	    }
+
+	    value = (char *)&backrow;
+	    segment_get(&in_row_seg, value, row, col);
+	    /* ignore pt in no-data area */
+	    if (backrow < 0) {
+		G_warning("Ignoring point in NO-DATA area :");
+		G_warning("   %.4f,%.4f", east, north);
+		continue;
+	    }
+	    value = (char *)&backcol;
+	    segment_get(&in_col_seg, value, row, col);
+
+	    insert(&PRESENT_PT, row, col, backrow, backcol);
+	}
+    }
+
+    /*  Set flag according to input */
+    if (path_mapset != NULL) {
+	if (head_start_pt == NULL)
+	    /*output layer exists and start pts are not given on cmd line */
+	    flag = 1;
+
+	/* output layer exists and starting pts are given on cmd line */
+	else
+	    flag = 2;
+    }
+    else
+	flag = 3;		/* output layer does not previously exist */
+
+    /* If the output layer containing the starting positions */
+    /* create a linked list of of them  */
+    if (flag == 1) {
+	path_fd = G_open_cell_old(path_layer, path_mapset);
+	if (path_fd < 0)
+	    G_fatal_error("%s -can't open raster map", path_layer);
+
+	/*  Search for the marked starting pts and make list    */
+	for (row = 0; row < nrows; row++) {
+	    if (G_get_map_row(path_fd, cell, row) < 0)
+		G_fatal_error("unable to get map row %d", row);
+
+	    for (col = 0; col < ncols; col++) {
+		if (cell[col] > 0) {
+		    value = (char *)&backrow;
+		    segment_get(&in_row_seg, value, row, col);
+		    /* ignore pt in no-data area */
+		    if (backrow < 0) {
+			G_warning("Ignoring point in NO-DATA area:");
+			G_warning("   %.4f,%.4f\n",
+				  window.west + window.ew_res * (col + 0.5),
+				  window.north - window.ns_res * (row + 0.5));
+			continue;
+		    }
+		    value = (char *)&backcol;
+		    segment_get(&in_col_seg, value, row, col);
+		    insert(&PRESENT_PT, row, col, backrow, backcol);
+		}
+	    }			/* loop over cols */
+	}			/* loop over rows */
+
+	G_close_cell(path_fd);
+    }
+
+    /* loop over the starting points to find the least cost paths */
+    if (verbose)
+	G_message("\nFinding the least cost paths ...");
+
+    PRES_PT = head_start_pt;
+    while (PRES_PT != NULL) {
+	path_finder(PRES_PT->row, PRES_PT->col, PRES_PT->backrow,
+		    PRES_PT->backcol);
+
+	OLD_PT = PRES_PT;
+	PRES_PT = NEXT_PT;
+	G_free(OLD_PT);
+    }
+
+    /* Write pending updates by segment_put() to outputmap */
+    segment_flush(&out_seg);
+
+    if (verbose)
+	G_message("\nWriting the output map  -%s-...", path_layer);
+
+    path_fd = G_open_cell_new(path_layer);
+    for (row = 0; row < nrows; row++) {
+	segment_get_row(&out_seg, cell, row);
+	if (G_put_raster_row(path_fd, cell, CELL_TYPE) < 0)
+	    G_fatal_error("unable to write map row %d", row);
+    }
+
+    if (verbose)
+	G_message("finished.");
+
+    segment_release(&in_row_seg);	/* release memory  */
+    segment_release(&in_col_seg);
+    segment_release(&out_seg);
+
+    close(in_row_fd);		/* close all files */
+    close(in_col_fd);
+    close(out_fd);
+
+    G_close_cell(path_fd);
+    G_close_cell(backrow_fd);
+    G_close_cell(backcol_fd);
+
+    unlink(in_row_file);	/* remove submatrix files  */
+    unlink(in_col_file);
+    unlink(out_file);
+
+    exit(EXIT_SUCCESS);
+}


Property changes on: grass/trunk/raster/r.spreadpath/main.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spreadpath/path_finder.c (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/path_finder.c)
===================================================================
--- grass/trunk/raster/r.spreadpath/path_finder.c	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/path_finder.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,46 @@
+
+/****** path_finder.c ***********************************************
+	
+	This recursive function traces the least cost path backwards
+	to cells from which the cumulative cost was determined 
+
+*********************************************************************/
+#include <grass/segment.h>
+#include "local_proto.h"
+
+
+void path_finder(int row, int col, int backrow, int backcol)
+{
+    int data, new_backrow, new_backcol;
+    extern char *value;
+    extern int nrows, ncols;
+    extern SEGMENT in_row_seg, in_col_seg, out_seg;
+
+    if (row < 0 || row >= nrows || col < 0 || col >= ncols)
+	return;			/* outside the window */
+
+    /* if the pt has already been traversed, return */
+    value = (char *)&data;
+    segment_get(&out_seg, value, row, col);
+    if (data == 1)
+	return;			/* already traversed */
+
+    /* otherwise, draw a line on output */
+    drawline(row, col, backrow, backcol);
+    /*DEBUG
+       printf("\nrow=%d, col=%d, backrow=%d, backcol=%d", row, col, backrow, backcol);
+     */
+    /* update path position */
+    if (row == backrow && col == backcol) {
+	printf("\n");
+	return;
+    }				/* reach an origin */
+
+    value = (char *)&new_backrow;
+    segment_get(&in_row_seg, value, backrow, backcol);
+    value = (char *)&new_backcol;
+    segment_get(&in_col_seg, value, backrow, backcol);
+
+    path_finder(backrow, backcol, new_backrow, new_backcol);
+    return;
+}


Property changes on: grass/trunk/raster/r.spreadpath/path_finder.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spreadpath/point.h (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/point.h)
===================================================================
--- grass/trunk/raster/r.spreadpath/point.h	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/point.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,33 @@
+#ifndef __POINT_H__
+#define __POINT_H__
+
+/***************************************************************/
+/*                                                             */
+/*      point.h    in   r.spreadpath                           */
+/*                                                             */
+/*      This header file defines the point data structure      */
+/*      and variables related to this structure.               */
+/*                                                             */
+
+/***************************************************************/
+
+struct point
+{
+    int row, col, backrow, backcol;
+    struct point *next;
+};
+
+#define POINT           struct point
+#define PRES_PT_BACKROW PRES_PT->backrow
+#define PRES_PT_BACKCOL PRES_PT->backcol
+#define PRES_PT_ROW     PRES_PT->row
+#define PRES_PT_COL     PRES_PT->col
+#define NEXT_PT         PRES_PT->next
+#define NEW_BACKROW     NEW_START_PT->backrow
+#define NEW_BACKCOL     NEW_START_PT->backcol
+#define NEW_ROW         NEW_START_PT->row
+#define NEW_COL         NEW_START_PT->col
+#define NEW_NEXT        NEW_START_PT->next
+#define NEXT_START_PT   PRESENT_PT->next
+
+#endif


Property changes on: grass/trunk/raster/r.spreadpath/point.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spreadpath/r.spreadpath.html (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/r.spreadpath.html)
===================================================================
--- grass/trunk/raster/r.spreadpath/r.spreadpath.html	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/r.spreadpath.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,48 @@
+<H2>DESCRIPTION</H2>
+
+<EM>r.spreadpath</EM> recursively traces the least cost path backwards to
+the origin, given backlink information input map layers and target locations
+from where paths are to be traced. The backlink information map layers
+record each cell's backlink UTM northing (the y_input) and easting (the
+x_input) coordinates from which the cell's cumulative cost was determined.
+
+<P>
+
+The backlink inputs can be generated from another GRASS raster program
+<EM>r.spread</EM>. One of the major applications of <EM>r.spreadpath</EM>
+along with <EM>r.spread</EM> is to accurately find the least cost corridors
+and/or paths on a raster setting. More information on <EM>r.spread</EM> and
+<EM>r.spreadpath</EM> can be found in Xu (1994).
+
+<H2>Parameters:</H2>
+<DL>
+<DT><B>x_input=</B><EM>name</EM>
+<DD>Name of input raster map layer containing backlink UTM easting
+coordinates.
+
+<DT><B>y_input=</B><EM>name</EM>
+<DD>Name of input raster map layer containing backlink UTM northing coordinates.
+
+<DT><B>coordinate=</B><EM>x,y[,x,y,x,y, ...]</EM>
+<DD>Each x,y coordinate pair gives the easting and northing (respectively) geographic coordinates of a target point from which to backwards trace the least cost path. As many
+points as desired can be entered by the user.
+
+<DT><B>output=</B><EM>name</EM>
+<DD>Name of raster map layer to contain output. Also can be used as the map layer of the input target points. If so used, the input target point map will be overwritten by the output.
+</DL>
+
+<H2>SEE ALSO</H2>
+<EM><A HREF="r.spread.html">r.spread</A></EM>,
+<EM><A HREF="r.ros.html">r.ros</A></EM>
+
+
+<H2>REFERENCES</H2>
+Xu, Jianping, 1994, Simulating the spread of wildfires using a geographic
+information system and remote sensing, Ph. D. Dissertation, Rutgers University,
+New Brunswick, New Jersey.
+
+<H2>AUTHOR</H2>
+Jianping Xu and Richard G. Lathrop, Jr., Center for Remote Sensing and
+Spatial Analysis, Rutgers University.
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/raster/r.spreadpath/r.spreadpath.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster/r.spreadpath/stash.h (from rev 34541, grass/trunk/raster/wildfire/r.spreadpath/stash.h)
===================================================================
--- grass/trunk/raster/r.spreadpath/stash.h	                        (rev 0)
+++ grass/trunk/raster/r.spreadpath/stash.h	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,26 @@
+
+/***************************************************************/
+/*                                                             */
+/*      stash.h         in r.spreadpath                        */
+/*                                                             */
+/*       This header file declares the global variables and    */
+/*       the structures that are to be used for command        */
+/*       line processing.                                      */
+/*                                                             */
+
+/***************************************************************/
+
+#include <stdio.h>
+#define      BACKCOL_LAYER      1
+#define      BACKROW_LAYER      2
+#define      START_PT           3
+#define      PATH_LAYER         4
+
+#include "point.h"
+
+extern char path_layer[];
+extern char backrow_layer[];
+extern char backcol_layer[];
+extern struct point *head_start_pt;
+
+/****************END OF "GDRAIN_CMD_LINE.H"**********************/


Property changes on: grass/trunk/raster/r.spreadpath/stash.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chdr
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Modified: grass/trunk/raster3d/Makefile
===================================================================
--- grass/trunk/raster3d/Makefile	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/raster3d/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -2,14 +2,16 @@
 
 SUBDIRS = \
 	r3.cross.rast \
+	r3.gwflow \
 	r3.in.ascii \
 	r3.in.v5d \
-	r3.gwflow \
+	r3.info \
 	r3.mkdspf \
 	r3.out.ascii \
 	r3.out.v5d \
 	r3.out.vtk \
 	r3.stats \
+	r3.timestamp \
 	r3.to.rast \
 	base
 

Modified: grass/trunk/raster3d/base/Makefile
===================================================================
--- grass/trunk/raster3d/base/Makefile	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/raster3d/base/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -4,12 +4,10 @@
 LIBES = $(G3DLIB) $(GISLIB)
 DEPENDENCIES = $(G3DDEP) $(GISDEP)
 
-PROGRAMS = r3.info r3.mask r3.null r3.timestamp
+PROGRAMS = r3.mask r3.null
 
 r3_mask_OBJS = r3.mask.main.o mask_functions.o
 r3_null_OBJS = r3.null.main.o mask_functions.o
-r3_info_OBJS = r3.info.main.o
-r3_timestamp_OBJS = r3.timestamp.main.o
 
 include $(MODULE_TOPDIR)/include/Make/Multi.make
 

Deleted: grass/trunk/raster3d/base/r3.info.html
===================================================================
--- grass/trunk/raster3d/base/r3.info.html	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/raster3d/base/r3.info.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -1,13 +0,0 @@
-<H2>DESCRIPTION</H2>
-
-<EM>r3.info</EM> reports metadata and range of 3D voxel maps.
-
-<H2>SEE ALSO</H2>
-
-<EM><A HREF="r.info.html">r.info</A></EM><br>
-
-<H2>AUTHORS</H2>
-Roman Waupotitsch, Michael Shapiro, 
-Helena Mitasova, Bill Brown, Lubos Mitas,
-Jaro Hofierka
-<p><i>Last changed: $Date$</i>

Deleted: grass/trunk/raster3d/base/r3.info.main.c
===================================================================
--- grass/trunk/raster3d/base/r3.info.main.c	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/raster3d/base/r3.info.main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -1,438 +0,0 @@
-
-/***************************************************************************
-*
-* MODULE:       r3.info
-*
-* AUTHOR(S):    Roman Waupotitsch, Michael Shapiro, Helena Mitasova, Bill Brown,
-*               Lubos Mitas, Jaro Hofierka
-*
-* PURPOSE:      Outputs basic information about a user-specified 3D raster map layer.
-*
-* COPYRIGHT:    (C) 2005 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.
-*
-*****************************************************************************/
-
-/* \todo
- *    History support still not full implemented.
- *    Only parts of the timestep functionality are implemented, the timzone is missed ;).
- */
-
-/*local prototype */
-int format_double(double value, char *buf);
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/G3d.h>
-#include <grass/glocale.h>
-
-#define printline(x) fprintf (out," | %-74.74s |\n",x)
-#define divider(x) \
-    fprintf (out," %c",x);\
-    for (i = 0; i < 76; i++)\
-        fprintf(out,"-");\
-    fprintf (out,"%c\n",x)
-
-#define TMP_LENGTH 100
-
-static char *name;
-
-/**************************************************************************/
-int main(int argc, char *argv[])
-{
-    char *mapset;
-    char *line = NULL;
-    char tmp1[TMP_LENGTH], tmp2[TMP_LENGTH], tmp3[TMP_LENGTH];
-    char timebuff[256];
-    int i;
-    FILE *out;
-    G3D_Region cellhd;
-    void *g3map;
-    struct Categories cats;
-    struct History hist;
-    struct TimeStamp ts;
-    int head_ok;
-    int cats_ok;
-    int hist_ok;
-    int time_ok = 0, first_time_ok = 0, second_time_ok = 0;
-    struct Option *opt1;
-    struct Flag *rflag;
-    struct Flag *sflag;
-    struct Flag *tflag;
-    struct Flag *timestampflag;
-    struct Flag *gflag;
-    struct Flag *hflag;
-    int data_type;
-
-    struct GModule *module;
-    double dmin, dmax;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("raster3d, voxel");
-    module->description =
-	_("Outputs basic information about a user-specified 3D raster map layer.");
-
-    opt1 = G_define_option();
-    opt1->key = "map";
-    opt1->type = TYPE_STRING;
-    opt1->required = YES;
-    opt1->gisprompt = "old,grid3,3d raster";
-    opt1->description = _("Name of input 3D raster map");
-
-    rflag = G_define_flag();
-    rflag->key = 'r';
-    rflag->description = _("Print range only");
-
-    sflag = G_define_flag();
-    sflag->key = 's';
-    sflag->description =
-	_("Print 3D raster map resolution (NS-res, EW-res, TB-res) only");
-
-    tflag = G_define_flag();
-    tflag->key = 't';
-    tflag->description = _("Print 3D raster map type (float/double) only");
-
-    gflag = G_define_flag();
-    gflag->key = 'g';
-    gflag->description = _("Print 3D raster map region only");
-
-    hflag = G_define_flag();
-    hflag->key = 'h';
-    hflag->description = _("Print 3D raster history instead of info");
-
-    timestampflag = G_define_flag();
-    timestampflag->key = 'p';
-    timestampflag->description =
-	_("Print 3D raster map timestamp (day.month.year hour:minute:seconds) only");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    name = G_store(opt1->answer);
-
-    if ((mapset = G_find_grid3(name, "")) == NULL)
-	G_fatal_error(_("Raster map <%s> not found"), name);
-
-    /*We need to open the map */
-    g3map =
-	G3d_openCellOld(name, mapset, G3D_DEFAULT_WINDOW,
-			G3D_TILE_SAME_AS_FILE, G3D_NO_CACHE);
-    if (NULL == g3map)
-	G_fatal_error(_("Error opening grid3 file [%s]"), name);
-
-    /*Get the maptype */
-    data_type = G3d_fileTypeMap(g3map);
-    head_ok = G3d_readRegionMap(name, mapset, &cellhd) >= 0;
-    hist_ok = G3d_readHistory(name, mapset, &hist) >= 0;
-    cats_ok = G3d_readCats(name, mapset, &cats) >= 0;
-    /*Check the Timestamp */
-    time_ok = G_read_grid3_timestamp(name, mapset, &ts) > 0;
-
-    /*Check for valid entries, show none if no entire available! */
-    if (time_ok) {
-	if (ts.count > 0)
-	    first_time_ok = 1;
-	if (ts.count > 1)
-	    second_time_ok = 1;
-    }
-
-    out = stdout;
-
-    /*Show the info if no flag is set */
-    if (!rflag->answer && !sflag->answer && !tflag->answer && !gflag->answer
-	&& !timestampflag->answer && !hflag->answer) {
-	divider('+');
-
-	if (G_asprintf
-	    (&line, "Layer:    %-29.29s  Date: %s", name,
-	     hist_ok ? hist.mapid : "??") > 0)
-	    printline(line);
-	else
-	    G_fatal_error(_("Cannot allocate memory for string"));
-
-
-	if (G_asprintf
-	    (&line, "Mapset:   %-29.29s  Login of Creator: %s", mapset,
-	     hist_ok ? hist.creator : "??") > 0)
-	    printline(line);
-	else
-	    G_fatal_error(_("Cannot allocate memory for string"));
-
-
-	if (G_asprintf(&line, "Location: %s", G_location()) > 0)
-	    printline(line);
-	else
-	    G_fatal_error(_("Cannot allocate memory for string"));
-
-	if (G_asprintf(&line, "DataBase: %s", G_gisdbase()) > 0)
-	    printline(line);
-	else
-	    G_fatal_error(_("Cannot allocate memory for string"));
-
-	if (G_asprintf
-	    (&line, "Title:    %s ( %s )", cats_ok ? cats.title : "??",
-	     hist_ok ? hist.title : "??") > 0)
-	    printline(line);
-	else
-	    G_fatal_error(_("Cannot allocate memory for string"));
-
-	/*This shows the TimeStamp */
-	if (time_ok && (first_time_ok || second_time_ok)) {
-
-	    G_format_timestamp(&ts, timebuff);
-
-	    /*Create the r.info timestamp string */
-	    if (G_asprintf(&line, "Timestamp: %s", timebuff) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-	}
-	else {
-	    if (G_asprintf(&line, "Timestamp: none") > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-	}
-
-
-	divider('|');
-	printline("");
-
-	if (cats_ok) {
-	    format_double((double)cats.num, tmp1);
-	}
-
-	if (G_asprintf
-	    (&line, "  Type of Map:  %-20.20s Number of Categories: %-9s",
-	     "3d cell", cats_ok ? tmp1 : "??") > 0)
-	    printline(line);
-	else
-	    G_fatal_error(_("Cannot allocate memory for string"));
-
-	if (G_asprintf(&line, "  Data Type:    %s",
-		       (data_type == FCELL_TYPE ? "float" :
-			(data_type == DCELL_TYPE ? "double" : "??"))) > 0)
-	    printline(line);
-	else
-	    G_fatal_error(_("Cannot allocate memory for string"));
-
-
-	if (head_ok) {
-	    if (G_asprintf(&line, "  Rows:         %d", cellhd.rows) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    if (G_asprintf(&line, "  Columns:      %d", cellhd.cols) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    if (G_asprintf(&line, "  Depths:       %d", cellhd.depths) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    if (G_asprintf
-		(&line, "  Total Cells:  %ld",
-		 (long)cellhd.rows * cellhd.cols * cellhd.depths) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    if (G_asprintf
-		(&line, "       Projection: %s (zone %d)",
-		 G_database_projection_name(), G_zone()) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    G_format_northing(cellhd.north, tmp1, cellhd.proj);
-	    G_format_northing(cellhd.south, tmp2, cellhd.proj);
-	    G_format_resolution(cellhd.ns_res, tmp3, cellhd.proj);
-	    if (G_asprintf
-		(&line, "           N: %10s    S: %10s   Res: %5s", tmp1,
-		 tmp2, tmp3) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    G_format_easting(cellhd.east, tmp1, cellhd.proj);
-	    G_format_easting(cellhd.west, tmp2, cellhd.proj);
-	    G_format_resolution(cellhd.ew_res, tmp3, cellhd.proj);
-	    if (G_asprintf
-		(&line, "           E: %10s    W: %10s   Res: %5s", tmp1,
-		 tmp2, tmp3) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    format_double(cellhd.top, tmp1);
-	    format_double(cellhd.bottom, tmp2);
-	    format_double(cellhd.tb_res, tmp3);
-	    if (G_asprintf
-		(&line, "           T: %10s    B: %10s   Res: %5s", tmp1,
-		 tmp2, tmp3) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-	    if (0 == G3d_range_load(g3map))
-		G_fatal_error(_("Error reading range for [%s]"), name);
-
-	    G3d_range_min_max(g3map, &dmin, &dmax);
-	    format_double(dmin, tmp1);
-	    format_double(dmax, tmp2);
-
-	    if (G_asprintf
-		(&line, "  Range of data:   min = %10s max = %10s", tmp1,
-		 tmp2) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-	}
-
-	printline("");
-
-	if (hist_ok) {
-	    printline("  Data Source:");
-	    if (G_asprintf(&line, "   %s", hist.datsrc_1) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    if (G_asprintf(&line, "   %s", hist.datsrc_2) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    printline("");
-
-	    printline("  Data Description:");
-	    if (G_asprintf(&line, "   %s", hist.keywrd) > 0)
-		printline(line);
-	    else
-		G_fatal_error(_("Cannot allocate memory for string"));
-
-	    printline("");
-	    if (hist.edlinecnt) {
-		printline("  Comments:  ");
-
-		for (i = 0; i < hist.edlinecnt; i++)
-
-	    /**************************************/
-		{
-		    if (G_asprintf(&line, "   %s", hist.edhist[i]) > 0)
-			printline(line);
-		    else
-			G_fatal_error(_("Cannot allocate memory for string"));
-
-		}
-	    }
-
-	    printline("");
-	}
-
-	divider('+');
-
-	fprintf(out, "\n");
-    }
-    else {			/* Range */
-	if (rflag->answer) {
-	    if (0 == G3d_range_load(g3map))
-		G_fatal_error(_("Error reading range for [%s]"), name);
-
-	    G3d_range_min_max(g3map, &dmin, &dmax);
-	    fprintf(out, "min=%f\n", dmin);
-	    fprintf(out, "max=%f\n", dmax);
-
-	}			/*Region */
-	else if (gflag->answer) {
-	    sprintf(tmp1, "%f", cellhd.north);
-	    sprintf(tmp2, "%f", cellhd.south);
-	    G_trim_decimal(tmp1);
-	    G_trim_decimal(tmp2);
-	    fprintf(out, "north=%s\n", tmp1);
-	    fprintf(out, "south=%s\n", tmp2);
-
-	    sprintf(tmp1, "%f", cellhd.east);
-	    sprintf(tmp2, "%f", cellhd.west);
-	    G_trim_decimal(tmp1);
-	    G_trim_decimal(tmp2);
-	    fprintf(out, "east=%s\n", tmp1);
-	    fprintf(out, "west=%s\n", tmp2);
-
-	    fprintf(out, "bottom=%g\n", cellhd.bottom);
-	    fprintf(out, "top=%g\n", cellhd.top);
-	}			/*Resolution */
-	else if (sflag->answer) {
-	    G_format_resolution(cellhd.ns_res, tmp3, cellhd.proj);
-	    fprintf(out, "nsres=%s\n", tmp3);
-
-	    G_format_resolution(cellhd.ew_res, tmp3, cellhd.proj);
-	    fprintf(out, "ewres=%s\n", tmp3);
-
-	    fprintf(out, "tbres=%g\n", cellhd.tb_res);
-	}			/*Datatype */
-	else if (tflag->answer) {
-	    fprintf(out, "datatype=\"%s\"\n",
-		    (data_type ==
-		     FCELL_TYPE ? "float" : (data_type ==
-					     DCELL_TYPE ? "double" : "??")));
-
-	}			/*History output */
-	else if (hflag->answer) {
-	    if (hist_ok) {
-		fprintf(out, "Data Source:\n");
-		fprintf(out, "   %s\n", hist.datsrc_1);
-		fprintf(out, "   %s\n", hist.datsrc_2);
-		fprintf(out, "Data Description:\n");
-		fprintf(out, "   %s\n", hist.keywrd);
-		if (hist.edlinecnt) {
-		    fprintf(out, "Comments:\n");
-		    for (i = 0; i < hist.edlinecnt; i++)
-			fprintf(out, "   %s\n", hist.edhist[i]);
-		}
-	    }
-	    else {
-		G_fatal_error(_("Error while reading history file"));
-	    }
-	}			/*Timestamp */
-	else if (timestampflag->answer) {
-	    if (time_ok && (first_time_ok || second_time_ok)) {
-
-		G_format_timestamp(&ts, timebuff);
-
-		/*Create the r.info timestamp string */
-		fprintf(out, "Timestamp=\"%s\"", timebuff);
-
-	    }
-	    else {
-		fprintf(out, "Timestamp=\"none\"\n");
-	    }
-	}
-
-    }
-
-    /*Close the opened map */
-    if (!G3d_closeCell(g3map))
-	G_fatal_error(_("Error closing 3d raster map"));
-
-
-    return 0;
-}
-
-/**************************************************************************/
-int format_double(double value, char *buf)
-{
-
-    sprintf(buf, "%.8lf", value);
-    G_trim_decimal(buf);
-    return 0;
-}

Deleted: grass/trunk/raster3d/base/r3.timestamp.html
===================================================================
--- grass/trunk/raster3d/base/r3.timestamp.html	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/raster3d/base/r3.timestamp.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -1,106 +0,0 @@
-<H2>DESCRIPTION</H2>
-
-
-This command has 2 modes of operation. If no date argument
-     is supplied, then the current timestamp for the grid3d map
-     is printed. If a date argument is specified, then the
-     timestamp for the grid3d map is set to the specified
-     date(s).  See EXAMPLES below.
-
-
-
-<H2>EXAMPLES</H2>
-
- <b>r3.timestamp map=soils</b><br>
-	  Prints the timestamp for the "soils" grid3d map. If
-	  there is no timestamp for soils, nothing is printed. If
-	  there is a timestamp, one or two lines are printed,
-	  depending on if the timestamp for the map consists of a
-	  single date or two dates (ie start and end dates).
-<p>
-<b>     r3.timestamp map=soils date='15 sep 1987'</b><br>
-	  Sets the timestamp for "soils" to the single date<br>
-	  "15 sep 1987"
-<p>
-<b>     r3.timestamp map=soils date='15 sep 1987/20 feb 1988'</b><br>
-	  Sets the timestamp for "soils" to have the start date<br>
-	  "15 sep 1987" and the end date "20 feb 1988"
-<p>
-<b>     r3.timestamp map=soils date='18 feb 2005 10:30:00/20 jul 2007 20:30:00'</b><br>
-	  Sets the timestamp for "soils" to have the start date<br>
-	  "18 aug 2005 10:30:00" and the end date "20 jul 2007 20:30:00"
-<p>
-
-<b>     r3.timestamp map=soils date=none</b><br>
-	  Removes the timestamp for the "soils" grid3d map
-
-<H2>TIMESTAMP FORMAT</H2>
-     The timestamp values must use the format as described in the
-     GRASS datetime library.  The source tree for this library
-     should have a description of the format. For convience, the
-     formats as of Feb, 1996 are reproduced here:
-<p>
-     There are two types of datetime values: absolute and
-     relative. Absolute values specify exact dates and/or times.
-     Relative values specify a span of time. Some examples will
-     help clarify:
-<p>
-   <b>  Absolute</b><p>
-	  The general format for absolute values is
-<p><tt>
-	     day month year [bc] hour:minute:seconds timezone
-<br>
-	     day is 1-31<br>
-	     month is jan,feb,...,dec<br>
-	     year is 4 digit year<br>
-	     [bc] if present, indicates dates is BC<br>
-	     hour is 0-23 (24 hour clock)<br>
-	     mintue is 0-59<br>
-	     second is 0-59.9999 (fractions of second allowed)<br>
-	     timezone is +hhmm or -hhmm (eg, -0600)<br>
-<br>
-	  parts can be missing
-<br>
-	     1994 [bc]<br>
-	     Jan 1994 [bc]<br>
-	     15 jan 1000 [bc]<br>
-	     15 jan 1994 [bc] 10 [+0000]<br>
-	     15 jan 1994 [bc] 10:00 [+0100]<br>
-	     15 jan 1994 [bc] 10:00:23.34 [-0500]<br>
-<br>
-</tt>
-    <b> Relative</b>
-	  There are two types of relative datetime values, year-
-	  month and day-second.	 The formats are:
-<p><tt>
-	     [-] # years # months<br>
-	     [-] # days # hours # minutes # seconds
-</tt><p>
-	  The words years, months, days, hours, minutes, seconds
-	  are literal words, and the # are the numeric values.<br>
-	  Examples:<p>
-<tt>
-	     2 years<br>
-	     5 months<br>
-	     2 years 5 months<br>
-	     100 days<br>
-	     15 hours 25 minutes 35.34 seconds<br>
-	     100 days 25 minutes<br>
-	     1000 hours 35.34 seconds
-</tt><p>
-	  The following are <i>illegal</i> because it mixes year-month
-	  and day-second (because the number of days in a month
-	  or in a year vary):<p>
-<tt>
-	     3 months 15 days<br>
-	     3 years 10 days
-</tt>
-<H2>BUGS</H2>
-Spaces in the timestamp value are required.
-
-<H2>AUTHOR</H2>
-Michael Pelizzari<br>
-Lockheed Martin Space Systems<br>
-based on r.timestamp by Michael Shapiro, <br>
-U.S.Army Construction Engineering Research Laboratory
-<p><i>Last changed: $Date$</i>

Deleted: grass/trunk/raster3d/base/r3.timestamp.main.c
===================================================================
--- grass/trunk/raster3d/base/r3.timestamp.main.c	2008-11-27 17:17:06 UTC (rev 34541)
+++ grass/trunk/raster3d/base/r3.timestamp.main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -1,95 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       r3.timestamp
- * AUTHOR(S):    Michael Pelizzari <michael.pelizzari lmco.com> 
- *                     (original contributor)
- *               Glynn Clements <glynn gclements.plus.com> Markus Neteler <neteler itc.it>
- * PURPOSE:      Stamps grid3 files with date and time.  
- * COPYRIGHT:    (C) 2001-2006 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.
- *
- *****************************************************************************/
-
-/* based on r.timestamp by Michael Shapiro and v.timestamp by Markus Neteler:
- * 
- * Stamps grid3 files with date and time.  This main.c is linked to functions 
- * currently residing in lib/gis/timestamp.c
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/G3d.h>
-#include <grass/glocale.h>
-
-int main(int argc, char *argv[])
-{
-    struct Option *map, *date;
-    struct TimeStamp ts;
-    char *name;
-    char *mapset;
-    int modify;
-    struct GModule *module;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("raster3d, voxel");
-    module->description =
-	_("Print/add/remove a timestamp for a 3D raster map");
-
-    map = G_define_option();
-    map->key = "map";
-    map->required = YES;
-    map->type = TYPE_STRING;
-    map->gisprompt = "old,grid3,3d raster";
-    map->description = _("Input grid3 filename");
-
-    date = G_define_option();
-    date->key = "date";
-    date->key_desc = "timestamp";
-    date->required = NO;
-    date->type = TYPE_STRING;
-    date->description = _("Datetime, datetime1/datetime2, or none");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    name = map->answer;
-
-    modify = date->answer != NULL;
-
-    if (modify)
-	mapset = G_find_grid3(name, G_mapset());
-    else
-	mapset = G_find_grid3(name, "");
-
-    if (mapset == NULL) {
-	G_fatal_error(_("Grid3 <%s> not found %s"), name,
-		      modify ? "in current mapset" : "");
-	exit(EXIT_FAILURE);
-    }
-
-    if (!modify) {
-	if (G_read_grid3_timestamp(name, mapset, &ts) == 1) {
-	    G__write_timestamp(stdout, &ts);
-	    exit(EXIT_SUCCESS);
-	}
-	else
-	    exit(EXIT_FAILURE);
-    }
-    if (strcmp(date->answer, "none") == 0) {
-	G_remove_grid3_timestamp(name);
-	exit(EXIT_SUCCESS);
-    }
-
-    G_scan_timestamp(&ts, date->answer);
-    G_write_grid3_timestamp(name, &ts);
-    exit(EXIT_SUCCESS);
-}


Property changes on: grass/trunk/raster3d/r3.info
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/raster3d/r3.info/Makefile
===================================================================
--- grass/trunk/raster3d/r3.info/Makefile	                        (rev 0)
+++ grass/trunk/raster3d/r3.info/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM=r3.info
+
+LIBES = $(G3DLIB) $(GISLIB)
+DEPENDENCIES = $(G3DDEP) $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd

Copied: grass/trunk/raster3d/r3.info/r3.info.html (from rev 34541, grass/trunk/raster3d/base/r3.info.html)
===================================================================
--- grass/trunk/raster3d/r3.info/r3.info.html	                        (rev 0)
+++ grass/trunk/raster3d/r3.info/r3.info.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,13 @@
+<H2>DESCRIPTION</H2>
+
+<EM>r3.info</EM> reports metadata and range of 3D voxel maps.
+
+<H2>SEE ALSO</H2>
+
+<EM><A HREF="r.info.html">r.info</A></EM><br>
+
+<H2>AUTHORS</H2>
+Roman Waupotitsch, Michael Shapiro, 
+Helena Mitasova, Bill Brown, Lubos Mitas,
+Jaro Hofierka
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/raster3d/r3.info/r3.info.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster3d/r3.info/r3.info.main.c (from rev 34541, grass/trunk/raster3d/base/r3.info.main.c)
===================================================================
--- grass/trunk/raster3d/r3.info/r3.info.main.c	                        (rev 0)
+++ grass/trunk/raster3d/r3.info/r3.info.main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,438 @@
+
+/***************************************************************************
+*
+* MODULE:       r3.info
+*
+* AUTHOR(S):    Roman Waupotitsch, Michael Shapiro, Helena Mitasova, Bill Brown,
+*               Lubos Mitas, Jaro Hofierka
+*
+* PURPOSE:      Outputs basic information about a user-specified 3D raster map layer.
+*
+* COPYRIGHT:    (C) 2005 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.
+*
+*****************************************************************************/
+
+/* \todo
+ *    History support still not full implemented.
+ *    Only parts of the timestep functionality are implemented, the timzone is missed ;).
+ */
+
+/*local prototype */
+int format_double(double value, char *buf);
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/G3d.h>
+#include <grass/glocale.h>
+
+#define printline(x) fprintf (out," | %-74.74s |\n",x)
+#define divider(x) \
+    fprintf (out," %c",x);\
+    for (i = 0; i < 76; i++)\
+        fprintf(out,"-");\
+    fprintf (out,"%c\n",x)
+
+#define TMP_LENGTH 100
+
+static char *name;
+
+/**************************************************************************/
+int main(int argc, char *argv[])
+{
+    char *mapset;
+    char *line = NULL;
+    char tmp1[TMP_LENGTH], tmp2[TMP_LENGTH], tmp3[TMP_LENGTH];
+    char timebuff[256];
+    int i;
+    FILE *out;
+    G3D_Region cellhd;
+    void *g3map;
+    struct Categories cats;
+    struct History hist;
+    struct TimeStamp ts;
+    int head_ok;
+    int cats_ok;
+    int hist_ok;
+    int time_ok = 0, first_time_ok = 0, second_time_ok = 0;
+    struct Option *opt1;
+    struct Flag *rflag;
+    struct Flag *sflag;
+    struct Flag *tflag;
+    struct Flag *timestampflag;
+    struct Flag *gflag;
+    struct Flag *hflag;
+    int data_type;
+
+    struct GModule *module;
+    double dmin, dmax;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("raster3d, voxel");
+    module->description =
+	_("Outputs basic information about a user-specified 3D raster map layer.");
+
+    opt1 = G_define_option();
+    opt1->key = "map";
+    opt1->type = TYPE_STRING;
+    opt1->required = YES;
+    opt1->gisprompt = "old,grid3,3d raster";
+    opt1->description = _("Name of input 3D raster map");
+
+    rflag = G_define_flag();
+    rflag->key = 'r';
+    rflag->description = _("Print range only");
+
+    sflag = G_define_flag();
+    sflag->key = 's';
+    sflag->description =
+	_("Print 3D raster map resolution (NS-res, EW-res, TB-res) only");
+
+    tflag = G_define_flag();
+    tflag->key = 't';
+    tflag->description = _("Print 3D raster map type (float/double) only");
+
+    gflag = G_define_flag();
+    gflag->key = 'g';
+    gflag->description = _("Print 3D raster map region only");
+
+    hflag = G_define_flag();
+    hflag->key = 'h';
+    hflag->description = _("Print 3D raster history instead of info");
+
+    timestampflag = G_define_flag();
+    timestampflag->key = 'p';
+    timestampflag->description =
+	_("Print 3D raster map timestamp (day.month.year hour:minute:seconds) only");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    name = G_store(opt1->answer);
+
+    if ((mapset = G_find_grid3(name, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), name);
+
+    /*We need to open the map */
+    g3map =
+	G3d_openCellOld(name, mapset, G3D_DEFAULT_WINDOW,
+			G3D_TILE_SAME_AS_FILE, G3D_NO_CACHE);
+    if (NULL == g3map)
+	G_fatal_error(_("Error opening grid3 file [%s]"), name);
+
+    /*Get the maptype */
+    data_type = G3d_fileTypeMap(g3map);
+    head_ok = G3d_readRegionMap(name, mapset, &cellhd) >= 0;
+    hist_ok = G3d_readHistory(name, mapset, &hist) >= 0;
+    cats_ok = G3d_readCats(name, mapset, &cats) >= 0;
+    /*Check the Timestamp */
+    time_ok = G_read_grid3_timestamp(name, mapset, &ts) > 0;
+
+    /*Check for valid entries, show none if no entire available! */
+    if (time_ok) {
+	if (ts.count > 0)
+	    first_time_ok = 1;
+	if (ts.count > 1)
+	    second_time_ok = 1;
+    }
+
+    out = stdout;
+
+    /*Show the info if no flag is set */
+    if (!rflag->answer && !sflag->answer && !tflag->answer && !gflag->answer
+	&& !timestampflag->answer && !hflag->answer) {
+	divider('+');
+
+	if (G_asprintf
+	    (&line, "Layer:    %-29.29s  Date: %s", name,
+	     hist_ok ? hist.mapid : "??") > 0)
+	    printline(line);
+	else
+	    G_fatal_error(_("Cannot allocate memory for string"));
+
+
+	if (G_asprintf
+	    (&line, "Mapset:   %-29.29s  Login of Creator: %s", mapset,
+	     hist_ok ? hist.creator : "??") > 0)
+	    printline(line);
+	else
+	    G_fatal_error(_("Cannot allocate memory for string"));
+
+
+	if (G_asprintf(&line, "Location: %s", G_location()) > 0)
+	    printline(line);
+	else
+	    G_fatal_error(_("Cannot allocate memory for string"));
+
+	if (G_asprintf(&line, "DataBase: %s", G_gisdbase()) > 0)
+	    printline(line);
+	else
+	    G_fatal_error(_("Cannot allocate memory for string"));
+
+	if (G_asprintf
+	    (&line, "Title:    %s ( %s )", cats_ok ? cats.title : "??",
+	     hist_ok ? hist.title : "??") > 0)
+	    printline(line);
+	else
+	    G_fatal_error(_("Cannot allocate memory for string"));
+
+	/*This shows the TimeStamp */
+	if (time_ok && (first_time_ok || second_time_ok)) {
+
+	    G_format_timestamp(&ts, timebuff);
+
+	    /*Create the r.info timestamp string */
+	    if (G_asprintf(&line, "Timestamp: %s", timebuff) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+	}
+	else {
+	    if (G_asprintf(&line, "Timestamp: none") > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+	}
+
+
+	divider('|');
+	printline("");
+
+	if (cats_ok) {
+	    format_double((double)cats.num, tmp1);
+	}
+
+	if (G_asprintf
+	    (&line, "  Type of Map:  %-20.20s Number of Categories: %-9s",
+	     "3d cell", cats_ok ? tmp1 : "??") > 0)
+	    printline(line);
+	else
+	    G_fatal_error(_("Cannot allocate memory for string"));
+
+	if (G_asprintf(&line, "  Data Type:    %s",
+		       (data_type == FCELL_TYPE ? "float" :
+			(data_type == DCELL_TYPE ? "double" : "??"))) > 0)
+	    printline(line);
+	else
+	    G_fatal_error(_("Cannot allocate memory for string"));
+
+
+	if (head_ok) {
+	    if (G_asprintf(&line, "  Rows:         %d", cellhd.rows) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    if (G_asprintf(&line, "  Columns:      %d", cellhd.cols) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    if (G_asprintf(&line, "  Depths:       %d", cellhd.depths) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    if (G_asprintf
+		(&line, "  Total Cells:  %ld",
+		 (long)cellhd.rows * cellhd.cols * cellhd.depths) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    if (G_asprintf
+		(&line, "       Projection: %s (zone %d)",
+		 G_database_projection_name(), G_zone()) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    G_format_northing(cellhd.north, tmp1, cellhd.proj);
+	    G_format_northing(cellhd.south, tmp2, cellhd.proj);
+	    G_format_resolution(cellhd.ns_res, tmp3, cellhd.proj);
+	    if (G_asprintf
+		(&line, "           N: %10s    S: %10s   Res: %5s", tmp1,
+		 tmp2, tmp3) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    G_format_easting(cellhd.east, tmp1, cellhd.proj);
+	    G_format_easting(cellhd.west, tmp2, cellhd.proj);
+	    G_format_resolution(cellhd.ew_res, tmp3, cellhd.proj);
+	    if (G_asprintf
+		(&line, "           E: %10s    W: %10s   Res: %5s", tmp1,
+		 tmp2, tmp3) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    format_double(cellhd.top, tmp1);
+	    format_double(cellhd.bottom, tmp2);
+	    format_double(cellhd.tb_res, tmp3);
+	    if (G_asprintf
+		(&line, "           T: %10s    B: %10s   Res: %5s", tmp1,
+		 tmp2, tmp3) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+	    if (0 == G3d_range_load(g3map))
+		G_fatal_error(_("Error reading range for [%s]"), name);
+
+	    G3d_range_min_max(g3map, &dmin, &dmax);
+	    format_double(dmin, tmp1);
+	    format_double(dmax, tmp2);
+
+	    if (G_asprintf
+		(&line, "  Range of data:   min = %10s max = %10s", tmp1,
+		 tmp2) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+	}
+
+	printline("");
+
+	if (hist_ok) {
+	    printline("  Data Source:");
+	    if (G_asprintf(&line, "   %s", hist.datsrc_1) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    if (G_asprintf(&line, "   %s", hist.datsrc_2) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    printline("");
+
+	    printline("  Data Description:");
+	    if (G_asprintf(&line, "   %s", hist.keywrd) > 0)
+		printline(line);
+	    else
+		G_fatal_error(_("Cannot allocate memory for string"));
+
+	    printline("");
+	    if (hist.edlinecnt) {
+		printline("  Comments:  ");
+
+		for (i = 0; i < hist.edlinecnt; i++)
+
+	    /**************************************/
+		{
+		    if (G_asprintf(&line, "   %s", hist.edhist[i]) > 0)
+			printline(line);
+		    else
+			G_fatal_error(_("Cannot allocate memory for string"));
+
+		}
+	    }
+
+	    printline("");
+	}
+
+	divider('+');
+
+	fprintf(out, "\n");
+    }
+    else {			/* Range */
+	if (rflag->answer) {
+	    if (0 == G3d_range_load(g3map))
+		G_fatal_error(_("Error reading range for [%s]"), name);
+
+	    G3d_range_min_max(g3map, &dmin, &dmax);
+	    fprintf(out, "min=%f\n", dmin);
+	    fprintf(out, "max=%f\n", dmax);
+
+	}			/*Region */
+	else if (gflag->answer) {
+	    sprintf(tmp1, "%f", cellhd.north);
+	    sprintf(tmp2, "%f", cellhd.south);
+	    G_trim_decimal(tmp1);
+	    G_trim_decimal(tmp2);
+	    fprintf(out, "north=%s\n", tmp1);
+	    fprintf(out, "south=%s\n", tmp2);
+
+	    sprintf(tmp1, "%f", cellhd.east);
+	    sprintf(tmp2, "%f", cellhd.west);
+	    G_trim_decimal(tmp1);
+	    G_trim_decimal(tmp2);
+	    fprintf(out, "east=%s\n", tmp1);
+	    fprintf(out, "west=%s\n", tmp2);
+
+	    fprintf(out, "bottom=%g\n", cellhd.bottom);
+	    fprintf(out, "top=%g\n", cellhd.top);
+	}			/*Resolution */
+	else if (sflag->answer) {
+	    G_format_resolution(cellhd.ns_res, tmp3, cellhd.proj);
+	    fprintf(out, "nsres=%s\n", tmp3);
+
+	    G_format_resolution(cellhd.ew_res, tmp3, cellhd.proj);
+	    fprintf(out, "ewres=%s\n", tmp3);
+
+	    fprintf(out, "tbres=%g\n", cellhd.tb_res);
+	}			/*Datatype */
+	else if (tflag->answer) {
+	    fprintf(out, "datatype=\"%s\"\n",
+		    (data_type ==
+		     FCELL_TYPE ? "float" : (data_type ==
+					     DCELL_TYPE ? "double" : "??")));
+
+	}			/*History output */
+	else if (hflag->answer) {
+	    if (hist_ok) {
+		fprintf(out, "Data Source:\n");
+		fprintf(out, "   %s\n", hist.datsrc_1);
+		fprintf(out, "   %s\n", hist.datsrc_2);
+		fprintf(out, "Data Description:\n");
+		fprintf(out, "   %s\n", hist.keywrd);
+		if (hist.edlinecnt) {
+		    fprintf(out, "Comments:\n");
+		    for (i = 0; i < hist.edlinecnt; i++)
+			fprintf(out, "   %s\n", hist.edhist[i]);
+		}
+	    }
+	    else {
+		G_fatal_error(_("Error while reading history file"));
+	    }
+	}			/*Timestamp */
+	else if (timestampflag->answer) {
+	    if (time_ok && (first_time_ok || second_time_ok)) {
+
+		G_format_timestamp(&ts, timebuff);
+
+		/*Create the r.info timestamp string */
+		fprintf(out, "Timestamp=\"%s\"", timebuff);
+
+	    }
+	    else {
+		fprintf(out, "Timestamp=\"none\"\n");
+	    }
+	}
+
+    }
+
+    /*Close the opened map */
+    if (!G3d_closeCell(g3map))
+	G_fatal_error(_("Error closing 3d raster map"));
+
+
+    return 0;
+}
+
+/**************************************************************************/
+int format_double(double value, char *buf)
+{
+
+    sprintf(buf, "%.8lf", value);
+    G_trim_decimal(buf);
+    return 0;
+}


Property changes on: grass/trunk/raster3d/r3.info/r3.info.main.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native


Property changes on: grass/trunk/raster3d/r3.timestamp
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Added: grass/trunk/raster3d/r3.timestamp/Makefile
===================================================================
--- grass/trunk/raster3d/r3.timestamp/Makefile	                        (rev 0)
+++ grass/trunk/raster3d/r3.timestamp/Makefile	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM=r3.timestamp
+
+LIBES = $(G3DLIB) $(GISLIB)
+DEPENDENCIES = $(G3DDEP) $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd

Copied: grass/trunk/raster3d/r3.timestamp/r3.timestamp.html (from rev 34541, grass/trunk/raster3d/base/r3.timestamp.html)
===================================================================
--- grass/trunk/raster3d/r3.timestamp/r3.timestamp.html	                        (rev 0)
+++ grass/trunk/raster3d/r3.timestamp/r3.timestamp.html	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,106 @@
+<H2>DESCRIPTION</H2>
+
+
+This command has 2 modes of operation. If no date argument
+     is supplied, then the current timestamp for the grid3d map
+     is printed. If a date argument is specified, then the
+     timestamp for the grid3d map is set to the specified
+     date(s).  See EXAMPLES below.
+
+
+
+<H2>EXAMPLES</H2>
+
+ <b>r3.timestamp map=soils</b><br>
+	  Prints the timestamp for the "soils" grid3d map. If
+	  there is no timestamp for soils, nothing is printed. If
+	  there is a timestamp, one or two lines are printed,
+	  depending on if the timestamp for the map consists of a
+	  single date or two dates (ie start and end dates).
+<p>
+<b>     r3.timestamp map=soils date='15 sep 1987'</b><br>
+	  Sets the timestamp for "soils" to the single date<br>
+	  "15 sep 1987"
+<p>
+<b>     r3.timestamp map=soils date='15 sep 1987/20 feb 1988'</b><br>
+	  Sets the timestamp for "soils" to have the start date<br>
+	  "15 sep 1987" and the end date "20 feb 1988"
+<p>
+<b>     r3.timestamp map=soils date='18 feb 2005 10:30:00/20 jul 2007 20:30:00'</b><br>
+	  Sets the timestamp for "soils" to have the start date<br>
+	  "18 aug 2005 10:30:00" and the end date "20 jul 2007 20:30:00"
+<p>
+
+<b>     r3.timestamp map=soils date=none</b><br>
+	  Removes the timestamp for the "soils" grid3d map
+
+<H2>TIMESTAMP FORMAT</H2>
+     The timestamp values must use the format as described in the
+     GRASS datetime library.  The source tree for this library
+     should have a description of the format. For convience, the
+     formats as of Feb, 1996 are reproduced here:
+<p>
+     There are two types of datetime values: absolute and
+     relative. Absolute values specify exact dates and/or times.
+     Relative values specify a span of time. Some examples will
+     help clarify:
+<p>
+   <b>  Absolute</b><p>
+	  The general format for absolute values is
+<p><tt>
+	     day month year [bc] hour:minute:seconds timezone
+<br>
+	     day is 1-31<br>
+	     month is jan,feb,...,dec<br>
+	     year is 4 digit year<br>
+	     [bc] if present, indicates dates is BC<br>
+	     hour is 0-23 (24 hour clock)<br>
+	     mintue is 0-59<br>
+	     second is 0-59.9999 (fractions of second allowed)<br>
+	     timezone is +hhmm or -hhmm (eg, -0600)<br>
+<br>
+	  parts can be missing
+<br>
+	     1994 [bc]<br>
+	     Jan 1994 [bc]<br>
+	     15 jan 1000 [bc]<br>
+	     15 jan 1994 [bc] 10 [+0000]<br>
+	     15 jan 1994 [bc] 10:00 [+0100]<br>
+	     15 jan 1994 [bc] 10:00:23.34 [-0500]<br>
+<br>
+</tt>
+    <b> Relative</b>
+	  There are two types of relative datetime values, year-
+	  month and day-second.	 The formats are:
+<p><tt>
+	     [-] # years # months<br>
+	     [-] # days # hours # minutes # seconds
+</tt><p>
+	  The words years, months, days, hours, minutes, seconds
+	  are literal words, and the # are the numeric values.<br>
+	  Examples:<p>
+<tt>
+	     2 years<br>
+	     5 months<br>
+	     2 years 5 months<br>
+	     100 days<br>
+	     15 hours 25 minutes 35.34 seconds<br>
+	     100 days 25 minutes<br>
+	     1000 hours 35.34 seconds
+</tt><p>
+	  The following are <i>illegal</i> because it mixes year-month
+	  and day-second (because the number of days in a month
+	  or in a year vary):<p>
+<tt>
+	     3 months 15 days<br>
+	     3 years 10 days
+</tt>
+<H2>BUGS</H2>
+Spaces in the timestamp value are required.
+
+<H2>AUTHOR</H2>
+Michael Pelizzari<br>
+Lockheed Martin Space Systems<br>
+based on r.timestamp by Michael Shapiro, <br>
+U.S.Army Construction Engineering Research Laboratory
+<p><i>Last changed: $Date$</i>


Property changes on: grass/trunk/raster3d/r3.timestamp/r3.timestamp.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c (from rev 34541, grass/trunk/raster3d/base/r3.timestamp.main.c)
===================================================================
--- grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c	                        (rev 0)
+++ grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c	2008-11-27 18:51:44 UTC (rev 34542)
@@ -0,0 +1,95 @@
+
+/****************************************************************************
+ *
+ * MODULE:       r3.timestamp
+ * AUTHOR(S):    Michael Pelizzari <michael.pelizzari lmco.com> 
+ *                     (original contributor)
+ *               Glynn Clements <glynn gclements.plus.com> Markus Neteler <neteler itc.it>
+ * PURPOSE:      Stamps grid3 files with date and time.  
+ * COPYRIGHT:    (C) 2001-2006 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.
+ *
+ *****************************************************************************/
+
+/* based on r.timestamp by Michael Shapiro and v.timestamp by Markus Neteler:
+ * 
+ * Stamps grid3 files with date and time.  This main.c is linked to functions 
+ * currently residing in lib/gis/timestamp.c
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/G3d.h>
+#include <grass/glocale.h>
+
+int main(int argc, char *argv[])
+{
+    struct Option *map, *date;
+    struct TimeStamp ts;
+    char *name;
+    char *mapset;
+    int modify;
+    struct GModule *module;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("raster3d, voxel");
+    module->description =
+	_("Print/add/remove a timestamp for a 3D raster map");
+
+    map = G_define_option();
+    map->key = "map";
+    map->required = YES;
+    map->type = TYPE_STRING;
+    map->gisprompt = "old,grid3,3d raster";
+    map->description = _("Input grid3 filename");
+
+    date = G_define_option();
+    date->key = "date";
+    date->key_desc = "timestamp";
+    date->required = NO;
+    date->type = TYPE_STRING;
+    date->description = _("Datetime, datetime1/datetime2, or none");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    name = map->answer;
+
+    modify = date->answer != NULL;
+
+    if (modify)
+	mapset = G_find_grid3(name, G_mapset());
+    else
+	mapset = G_find_grid3(name, "");
+
+    if (mapset == NULL) {
+	G_fatal_error(_("Grid3 <%s> not found %s"), name,
+		      modify ? "in current mapset" : "");
+	exit(EXIT_FAILURE);
+    }
+
+    if (!modify) {
+	if (G_read_grid3_timestamp(name, mapset, &ts) == 1) {
+	    G__write_timestamp(stdout, &ts);
+	    exit(EXIT_SUCCESS);
+	}
+	else
+	    exit(EXIT_FAILURE);
+    }
+    if (strcmp(date->answer, "none") == 0) {
+	G_remove_grid3_timestamp(name);
+	exit(EXIT_SUCCESS);
+    }
+
+    G_scan_timestamp(&ts, date->answer);
+    G_write_grid3_timestamp(name, &ts);
+    exit(EXIT_SUCCESS);
+}


Property changes on: grass/trunk/raster3d/r3.timestamp/r3.timestamp.main.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native



More information about the grass-commit mailing list