[GRASS-SVN] r32810 - in grass/trunk: display/d.linegraph display/d.rast.arrow display/d.rast.num general/g.mapsets imagery/i.fft imagery/i.his.rgb imagery/i.ifft imagery/i.ortho.photo/menu imagery/i.rgb.his raster/r.circle raster/r.flow raster/r.null raster/r.out.png raster/r.out.tiff raster/r.support vector/v.in.ascii vector/v.out.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 16 05:46:06 EDT 2008


Author: glynn
Date: 2008-08-16 05:46:03 -0400 (Sat, 16 Aug 2008)
New Revision: 32810

Added:
   grass/trunk/display/d.linegraph/main.c
   grass/trunk/display/d.rast.arrow/main.c
   grass/trunk/display/d.rast.num/main.c
   grass/trunk/general/g.mapsets/main.c
   grass/trunk/imagery/i.fft/main.c
   grass/trunk/imagery/i.his.rgb/main.c
   grass/trunk/imagery/i.ifft/main.c
   grass/trunk/imagery/i.ortho.photo/menu/main.c
   grass/trunk/imagery/i.rgb.his/main.c
   grass/trunk/raster/r.circle/main.c
   grass/trunk/raster/r.flow/main.c
   grass/trunk/raster/r.null/main.c
   grass/trunk/raster/r.out.png/main.c
   grass/trunk/raster/r.out.tiff/main.c
   grass/trunk/raster/r.support/main.c
   grass/trunk/vector/v.in.ascii/main.c
   grass/trunk/vector/v.out.ascii/main.c
Removed:
   grass/trunk/display/d.linegraph/linegraph.c
   grass/trunk/display/d.rast.arrow/arrow.c
   grass/trunk/display/d.rast.num/number.c
   grass/trunk/general/g.mapsets/get_path.c
   grass/trunk/general/g.mapsets/main_cmd.c
   grass/trunk/general/g.mapsets/main_inter.c
   grass/trunk/general/g.mapsets/scan_int.c
   grass/trunk/general/g.mapsets/set_path.c
   grass/trunk/imagery/i.fft/fftmain.c
   grass/trunk/imagery/i.his.rgb/h2rmain.c
   grass/trunk/imagery/i.ifft/ifftmain.c
   grass/trunk/imagery/i.ortho.photo/menu/menu.c
   grass/trunk/imagery/i.rgb.his/r2hmain.c
   grass/trunk/raster/r.circle/dist.c
   grass/trunk/raster/r.flow/calc.c
   grass/trunk/raster/r.null/null.c
   grass/trunk/raster/r.out.png/r.out.png.c
   grass/trunk/raster/r.out.tiff/r.out.tiff.c
   grass/trunk/raster/r.support/front.c
   grass/trunk/vector/v.in.ascii/in.c
   grass/trunk/vector/v.out.ascii/out.c
Modified:
   grass/trunk/general/g.mapsets/Makefile
Log:
main() should be in a file named main.c
Remove unused files


Deleted: grass/trunk/display/d.linegraph/linegraph.c
===================================================================
--- grass/trunk/display/d.linegraph/linegraph.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/display/d.linegraph/linegraph.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,576 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       d.linegraph
- * AUTHOR(S):    Chris Rewerts, Agricultural Engineering, Purdue University (original contributor)
- *               Markus Neteler <neteler itc.it>
- *               Roberto Flor <flor itc.it>, Bernhard Reiter <bernhard intevation.de>, 
- *               Huidae Cho <grass4u gmail.com>, Glynn Clements <glynn gclements.plus.com>, 
- *               Hamish Bowman <hamish_nospam yahoo.com>
- * PURPOSE:      
- * 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.
- *
- *****************************************************************************/
-/* Chris Rewerts
-   rewerts at ecn.purdue.edu
-   Agricultural Engineering, Purdue University
-   February 1992
-   program: d.linegraph
-
-   This program is based on Raghaven Srinivasan's modification  
-   of the programs written by Dave Johnson for d.histogram. 
-
-   Will read files containing a column of numbers and create line
-   graphs. One file can be used for the X axis, up to 10 for the 
-   Y axis. Each numerical x,y file should be a single column of
-   numbers.    
- */
-
-#include <stdlib.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/display.h>
-#include <grass/colors.h>
-#include <grass/glocale.h>
-#include "linegraph.h"
-
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-
-/* the default order of precedence of colors to use for Y lines */
-int default_y_colors[] = {
-    0,
-    RED, GREEN, VIOLET, BLUE, ORANGE,
-    GRAY, BROWN, MAGENTA, WHITE, INDIGO
-};
-
-int main(int argc, char **argv)
-{
-    int xoffset;		/* offset for x-axis */
-    int yoffset;		/* offset for y-axis */
-    int text_height;
-    int text_width;
-    int i;
-    int j;
-    int c;
-    int tic_every;
-    int max_tics;
-    int title_color;
-    int num_y_files;
-    int tic_unit;
-    double t, b, l, r;
-    double tt, tb, tl, tr;
-    int prev_x, prev_y[11];
-    int new_x, new_y[11];
-    int line;
-    double x_line[3];
-    double y_line[3];
-    int err;
-
-    struct in_file
-    {
-	int num_pnts;		/* number of lines in file  */
-	int color;		/* color to use for y lines */
-	float max;		/* maximum value in file    */
-	float min;		/* minimum value in file    */
-	float value;		/* current value read in    */
-	char name[1024];	/* name of file      */
-	char full_name[1024];	/* path/name of file    */
-	FILE *fp;		/* pointer to file        */
-    };
-
-    struct in_file in[12];
-    struct GModule *module;
-
-    float max_y;
-    float min_y;
-    float height, width;
-    float xscale;
-    float yscale;
-
-    char txt[1024], xlabel[512];
-    char tic_name[1024];
-    char *name;
-    char color_name[20];
-
-    FILE *fopen();
-
-    struct Option *dir_opt, *x_opt, *y_opt;
-    struct Option *y_color_opt;
-    struct Option *title[3];
-    struct Option *t_color_opt;
-
-    /* Initialize the GIS calls */
-    G_gisinit(argv[0]);
-
-    /* Set description */
-    module = G_define_module();
-    module->keywords = _("display");
-    module->description =
-	_("Generates and displays simple line graphs in the active graphics monitor display frame.");
-
-    x_opt = G_define_option();
-    x_opt->key = "x_file";
-    x_opt->description = _("Name of data file for X axis of graph");
-    x_opt->type = TYPE_STRING;
-    x_opt->required = YES;
-
-    y_opt = G_define_option();
-    y_opt->key = "y_file";
-    y_opt->description = _("Name of data file(s) for Y axis of graph");
-    y_opt->type = TYPE_STRING;
-    y_opt->required = YES;
-    y_opt->multiple = YES;
-
-    dir_opt = G_define_option();
-    dir_opt->key = "directory";
-    dir_opt->description = _("Path to file location");
-    dir_opt->type = TYPE_STRING;
-    dir_opt->required = NO;
-    dir_opt->answer = ".";
-
-    y_color_opt = G_define_option();
-    y_color_opt->key = "y_color";
-    y_color_opt->description = _("Color for Y data");
-    y_color_opt->type = TYPE_STRING;
-    y_color_opt->required = NO;
-    y_color_opt->multiple = YES;
-    y_color_opt->answers = NULL;
-    y_color_opt->options = D_COLOR_LIST;
-
-    t_color_opt = G_define_option();
-    t_color_opt->key = "title_color";
-    t_color_opt->description = _("Color for axis, tics, numbers, and title");
-    t_color_opt->type = TYPE_STRING;
-    t_color_opt->required = NO;
-    t_color_opt->answer = DEFAULT_FG_COLOR;
-    t_color_opt->options = D_COLOR_LIST;
-
-    title[0] = G_define_option();
-    title[0]->key = "x_title";
-    title[0]->description = _("Title for X data");
-    title[0]->type = TYPE_STRING;
-    title[0]->required = NO;
-    title[0]->answer = "";
-
-    title[1] = G_define_option();
-    title[1]->key = "y_title";
-    title[1]->description = _("Title for Y data");
-    title[1]->type = TYPE_STRING;
-    title[1]->required = NO;
-    title[1]->answer = "";
-
-    title[2] = G_define_option();
-    title[2]->key = "title";
-    title[2]->description = _("Title for Graph");
-    title[2]->type = TYPE_STRING;
-    title[2]->required = NO;
-    title[2]->answer = "";
-
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    for (i = 0; i < 3; i++) {
-	for (j = 0; j < strlen(title[i]->answer); j++)
-	    if (title[i]->answer[j] == '_')
-		title[i]->answer[j] = ' ';
-    }
-
-    /* build path to X data file and open for reading
-       notice that in[0] will be the X file, and in[1-10]
-       will be the Y file(s) */
-
-    sprintf(in[0].full_name, "%s/%s", dir_opt->answer, x_opt->answer);
-    sprintf(in[0].name, "%s", x_opt->answer);
-
-    if ((in[0].fp = fopen(in[0].full_name, "r")) == NULL)
-	G_fatal_error(_("Unable to open input file <%s>"), in[0].full_name);
-
-    num_y_files = 0;
-
-    /* open all Y data files */
-
-    for (i = 0, j = 1; (name = y_opt->answers[i]); i++, j++) {
-	sprintf(in[j].full_name, "%s/%s", dir_opt->answer, name);
-	sprintf(in[j].name, "%s", name);
-
-	if ((in[j].fp = fopen(in[j].full_name, "r")) == NULL)
-	    G_fatal_error(_("Unable to open input file <%s>"),
-			  in[j].full_name);
-
-	num_y_files++;
-	if (num_y_files > 10)
-	    G_fatal_error(_("Maximum of 10 Y data files exceeded"));
-    }
-
-    /* set colors  */
-
-    title_color = D_translate_color(t_color_opt->answer);
-
-    /* I had an argument with the parser, and couldn't get a neat list of
-       the input colors as I thought I should. I did a quick hack to get
-       my list from the answer var, which gives us the colors input
-       separated by commas. at least we know that they have been checked against
-       the list of possibles */
-    c = 0;
-    j = 1;
-    if (y_color_opt->answer != NULL) {
-	for (i = 0; i <= (strlen(y_color_opt->answer)); i++) {
-	    if ((y_color_opt->answer[i] == ',') ||
-		(i == (strlen(y_color_opt->answer)))) {
-		color_name[c] = '\0';
-		in[j].color = D_translate_color(color_name);
-		j++;
-		c = 0;
-	    }
-	    else {
-		color_name[c++] = y_color_opt->answer[i];
-	    }
-	}
-	/* this is lame. I could come up with a color or prompt for one or something */
-	if (j < num_y_files)
-	    G_fatal_error(_("Only <%d> colors given for <%d> lines"), j,
-			  num_y_files);
-    }
-    else
-	/* no colors given on command line, use default list */
-    {
-	for (i = 1; i <= num_y_files; i++) {
-	    in[i].color = default_y_colors[i];
-	}
-    }
-
-    /* get coordinates of current screen window, in pixels */
-    if (R_open_driver() != 0)
-	G_fatal_error(_("No graphics device selected"));
-    D_get_screen_window(&t, &b, &l, &r);
-    R_set_window(t, b, l, r);
-
-    /* create axis lines, to be drawn later */
-    height = b - t;
-    width = r - l;
-    x_line[0] = x_line[1] = l + (int)(ORIGIN_X * width);
-    x_line[2] = l + (int)(XAXIS_END * width);
-    y_line[0] = b - (int)(YAXIS_END * height);
-    y_line[1] = y_line[2] = b - (int)(ORIGIN_Y * height);
-    text_height = (int)(b - t) * TEXT_HEIGHT;
-    text_width = (int)(r - l) * TEXT_WIDTH;
-    R_text_size(text_width, text_height);
-
-    /* read thru each data file in turn, find max and min values for
-       each, count lines, find x min and max, find overall y min and
-       max */
-
-    max_y = -99999.9;
-    min_y = 99999.9;
-
-    for (i = 0; i <= num_y_files; i++) {
-
-	in[i].min = 99999.9;
-	in[i].max = -99999.9;
-	in[i].value = 0.0;
-	in[i].num_pnts = 0;
-
-	while ((err = fscanf(in[i].fp, "%f", &in[i].value)) != EOF) {
-	    in[i].num_pnts++;
-	    in[i].max = MAX(in[i].max, in[i].value);
-	    in[i].min = MIN(in[i].min, in[i].value);
-	    if (i > 0) {	/* if we have a y file */
-		min_y = MIN(min_y, in[i].value);
-		max_y = MAX(max_y, in[i].value);
-	    }
-	}
-	if ((i > 0) && (in[0].num_pnts != in[i].num_pnts)) {
-	    G_warning(_("Y input file <%s> contains %s data points than the X input file"),
-		      in[i].name,
-		      ((in[i].num_pnts < in[0].num_pnts) ? "fewer" : "more"));
-
-	    if (in[i].num_pnts > in[0].num_pnts)
-		G_message(_("The last %d point(s) will be ignored"),
-			  (in[i].num_pnts - in[0].num_pnts));
-	}
-    }
-
-    /* close all files */
-
-    for (i = 0; i <= num_y_files; i++)
-	fclose(in[i].fp);
-
-    /* figure scaling factors and offsets */
-
-    xscale = ((double)(x_line[2] - x_line[1]) / (double)(in[0].num_pnts));
-    yscale = ((double)(y_line[1] - y_line[0]) / (max_y - min_y));
-    yoffset = (double)(y_line[1]);
-    xoffset = (double)(x_line[1]);
-
-    /* figure tic_every and tic_units for the x-axis of the bar-chart.
-       tic_every tells how often to place a tic-number.  tic_unit tells
-       the unit to use in expressing tic-numbers. */
-
-    if (xscale < XTIC_DIST) {
-	max_tics = (x_line[2] - x_line[1]) / XTIC_DIST;
-	i = 1;
-	while (((in[0].max - in[0].min) / tics[i].every) > max_tics)
-	    i++;
-	tic_every = tics[i].every;
-	tic_unit = tics[i].unit;
-	strcpy(tic_name, tics[i].name);
-    }
-    else {
-	tic_every = 1;
-	tic_unit = 1;
-	strcpy(tic_name, "");
-    }
-
-
-    /* open all the data files again */
-
-    for (i = 0; i <= num_y_files; i++) {
-	if ((in[i].fp = fopen(in[i].full_name, "r")) == NULL) {
-	    sprintf(txt, "Could not open input file <%s>.", in[i].full_name);
-	    death(txt);
-	}
-    }
-
-    /* loop through number of lines in x data file, 
-       then loop thru for each y file, drawing a piece of each line and a
-       legend bar on each iteration evenly divisible, a tic-mark
-       on those evenly divisible by tic_unit, and a tic_mark
-       number on those evenly divisible by tic_every   */
-
-    /* read the info from the inputs */
-
-    for (line = 0; line < in[0].num_pnts; line++) {
-	/* scan in an X value */
-	err = fscanf(in[0].fp, "%f", &in[0].value);
-
-	/* didn't find a number or hit EOF before our time */
-	if ((err != 1) || (err == EOF)) {
-	    sprintf(txt, _("Problem reading X data file at line %d"), line);
-	    death(txt);
-	}
-
-	/* for each Y data file, get a value and compute where to draw it */
-	for (i = 1; i <= num_y_files; i++) {
-	    /* check to see that we do indeed have data for this point */
-	    if (line < in[i].num_pnts) {
-		err = fscanf(in[i].fp, "%f", &in[i].value);
-		if ((in[i].num_pnts >= line) && (err != 1)) {
-		    sprintf(txt,
-			    _("Problem reading <%s> data file at line %d"),
-			    in[i].name, line);
-		    death(txt);
-		}
-
-		/* in case the Y file has fewer lines than the X file, we will skip
-		   trying to draw when we run out of data */
-
-		/* draw increment of each Y file's data */
-
-		R_standard_color(in[i].color);
-
-		/* find out position of where Y should be drawn. */
-		/* if our minimum value of y is not negative, this is easy */
-
-		if (min_y >= 0)
-		    new_y[i] =
-			(int)(yoffset - yscale * (in[i].value - min_y));
-
-		/* if our minimum value of y is negative, then we have two
-		   cases:  our current value to plot is pos or neg */
-
-		else {
-		    if (in[i].value < 0)
-			new_y[i] = (int)(yoffset - yscale * (-1 *
-							     (min_y -
-							      in[i].value)));
-		    else
-			new_y[i] = (int)(yoffset - yscale * (in[i].value +
-							     (min_y * -1)));
-		}
-
-		new_x = xoffset + (line * xscale);
-		if (line == 0) {
-		    prev_x = xoffset;
-		    prev_y[i] = yoffset;
-		}
-		R_move_abs(prev_x, prev_y[i]);
-		R_cont_abs(new_x, new_y[i]);
-		prev_y[i] = new_y[i];
-	    }
-	}
-	prev_x = new_x;
-
-	/* draw x-axis tic-marks and numbers */
-
-	if (rem((long int)in[0].value, tic_every) == (float)0) {
-
-	    /* draw a numbered tic-mark */
-
-	    R_standard_color(title_color);
-	    R_move_abs((int)(xoffset + line * xscale),
-		       (int)(b - ORIGIN_Y * (b - t)));
-	    R_cont_rel((int)0, (int)(BIG_TIC * (b - t)));
-	    if ((in[0].value >= 1) || (in[0].value <= -1) ||
-		(in[0].value == 0))
-		sprintf(txt, "%.0f", (in[0].value / tic_unit));
-	    else
-		sprintf(txt, "%.2f", (in[0].value));
-	    text_height = (b - t) * TEXT_HEIGHT;
-	    text_width = (r - l) * TEXT_WIDTH;
-	    R_text_size(text_width, text_height);
-	    R_get_text_box(txt, &tt, &tb, &tl, &tr);
-	    while ((tr - tl) > XTIC_DIST) {
-		text_width *= 0.75;
-		text_height *= 0.75;
-		R_text_size(text_width, text_height);
-		R_get_text_box(txt, &tt, &tb, &tl, &tr);
-	    }
-	    R_move_abs((int)(xoffset + (line * xscale - (tr - tl) / 2)),
-		       (int)(b - XNUMS_Y * (b - t)));
-	    R_text(txt);
-	}
-	else if (rem(line, tic_unit) == (float)0) {
-
-	    /* draw a tic-mark */
-
-	    R_standard_color(title_color);
-	    R_move_abs((int)(xoffset + line * xscale),
-		       (int)(b - ORIGIN_Y * (b - t)));
-	    R_cont_rel((int)0, (int)(SMALL_TIC * (b - t)));
-	}
-    }
-
-    /* close all input files */
-    for (i = 0; i <= num_y_files; i++) {
-	fclose(in[i].fp);
-    }
-
-    /* draw the x-axis label */
-    if ((strcmp(title[0]->answer, "") == 0) && (strcmp(tic_name, "") == 0))
-	*xlabel = '\0';
-    else
-	sprintf(xlabel, "X: %s %s", title[0]->answer, tic_name);
-    text_height = (b - t) * TEXT_HEIGHT;
-    text_width = (r - l) * TEXT_WIDTH * 1.5;
-    R_text_size(text_width, text_height);
-    R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
-    R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
-	       (int)(b - LABEL_1 * (b - t)));
-    R_standard_color(title_color);
-    R_text(xlabel);
-
-    /* DRAW Y-AXIS TIC-MARKS AND NUMBERS
-       first, figure tic_every and tic_units for the x-axis of the bar-chart.
-       tic_every tells how often to place a tic-number.  tic_unit tells
-       the unit to use in expressing tic-numbers. */
-
-    if (yscale < YTIC_DIST) {
-	max_tics = (y_line[1] - y_line[0]) / YTIC_DIST;
-	i = 1;
-	while (((max_y - min_y) / tics[i].every) > max_tics)
-	    i++;
-	tic_every = tics[i].every;
-	tic_unit = tics[i].unit;
-	strcpy(tic_name, tics[i].name);
-    }
-    else {
-	tic_every = 1;
-	tic_unit = 1;
-	strcpy(tic_name, "");
-    }
-
-    /* Y-AXIS LOOP */
-
-    for (i = (int)min_y; i <= (int)max_y; i += tic_unit) {
-	if (rem(i, tic_every) == (float)0) {
-	    /* draw a tic-mark */
-
-	    R_move_abs((int)x_line[0], (int)(yoffset - yscale * (i - min_y)));
-	    R_cont_rel((int)(-(r - l) * BIG_TIC), (int)0);
-
-	    /* draw a tic-mark number */
-
-	    sprintf(txt, "%d", (i / tic_unit));
-	    text_height = (b - t) * TEXT_HEIGHT;
-	    text_width = (r - l) * TEXT_WIDTH;
-	    R_text_size(text_width, text_height);
-	    R_get_text_box(txt, &tt, &tb, &tl, &tr);
-	    while ((tt - tb) > YTIC_DIST) {
-		text_width *= 0.75;
-		text_height *= 0.75;
-		R_text_size(text_width, text_height);
-		R_get_text_box(txt, &tt, &tb, &tl, &tr);
-	    }
-	    R_move_abs((int)(l + (r - l) * YNUMS_X - (tr - tl) / 2),
-		       (int)(yoffset -
-			     (yscale * (i - min_y) + 0.5 * (tt - tb))));
-	    R_text(txt);
-	}
-	else if (rem(i, tic_unit) == (float)0) {
-	    /* draw a tic-mark */
-
-	    R_move_abs((int)x_line[0], (int)(yoffset - yscale * (i - min_y)));
-	    R_cont_rel((int)(-(r - l) * SMALL_TIC), (int)0);
-	}
-    }
-
-    /* draw the y-axis label */
-    if ((strcmp(title[1]->answer, "") == 0) && (strcmp(tic_name, "") == 0))
-	*xlabel = '\0';
-    else
-	sprintf(xlabel, "Y: %s %s", title[1]->answer, tic_name);
-    text_height = (b - t) * TEXT_HEIGHT;
-    text_width = (r - l) * TEXT_WIDTH * 1.5;
-    R_text_size(text_width, text_height);
-    R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
-    R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
-	       (int)(b - LABEL_2 * (b - t)));
-    R_standard_color(title_color);
-    R_text(xlabel);
-
-    /* top label */
-    sprintf(xlabel, title[2]->answer);
-    text_height = (b - t) * TEXT_HEIGHT;
-    text_width = (r - l) * TEXT_WIDTH * 2.0;
-    R_text_size(text_width, text_height);
-    R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
-    /*
-       R_move_abs((int)(((r-l)/2)-(tr-tl)/2),
-       (int) (t+ (b-t)*.07) );
-     */
-    R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
-	       (int)(t + (b - t) * .07));
-    R_standard_color(title_color);
-    R_text(xlabel);
-
-    /* draw x and y axis lines */
-    R_standard_color(title_color);
-    R_polyline_abs(x_line, y_line, 3);
-
-    R_flush();
-    R_close_driver();
-    exit(EXIT_SUCCESS);
-}
-
-float rem(long int x, long int y)
-{
-    long int d = x / y;
-
-    return ((float)(x - y * d));
-}
-
-
-/* a function for making an exit after the R_driver is open */
-int death(char *gasp)
-{
-    R_flush();
-    R_close_driver();
-    G_fatal_error("%s", gasp);
-}

Copied: grass/trunk/display/d.linegraph/main.c (from rev 32801, grass/trunk/display/d.linegraph/linegraph.c)
===================================================================
--- grass/trunk/display/d.linegraph/main.c	                        (rev 0)
+++ grass/trunk/display/d.linegraph/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,576 @@
+
+/****************************************************************************
+ *
+ * MODULE:       d.linegraph
+ * AUTHOR(S):    Chris Rewerts, Agricultural Engineering, Purdue University (original contributor)
+ *               Markus Neteler <neteler itc.it>
+ *               Roberto Flor <flor itc.it>, Bernhard Reiter <bernhard intevation.de>, 
+ *               Huidae Cho <grass4u gmail.com>, Glynn Clements <glynn gclements.plus.com>, 
+ *               Hamish Bowman <hamish_nospam yahoo.com>
+ * PURPOSE:      
+ * 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.
+ *
+ *****************************************************************************/
+/* Chris Rewerts
+   rewerts at ecn.purdue.edu
+   Agricultural Engineering, Purdue University
+   February 1992
+   program: d.linegraph
+
+   This program is based on Raghaven Srinivasan's modification  
+   of the programs written by Dave Johnson for d.histogram. 
+
+   Will read files containing a column of numbers and create line
+   graphs. One file can be used for the X axis, up to 10 for the 
+   Y axis. Each numerical x,y file should be a single column of
+   numbers.    
+ */
+
+#include <stdlib.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/display.h>
+#include <grass/colors.h>
+#include <grass/glocale.h>
+#include "linegraph.h"
+
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+#define MIN(x,y) ((x) < (y) ? (x) : (y))
+
+/* the default order of precedence of colors to use for Y lines */
+int default_y_colors[] = {
+    0,
+    RED, GREEN, VIOLET, BLUE, ORANGE,
+    GRAY, BROWN, MAGENTA, WHITE, INDIGO
+};
+
+int main(int argc, char **argv)
+{
+    int xoffset;		/* offset for x-axis */
+    int yoffset;		/* offset for y-axis */
+    int text_height;
+    int text_width;
+    int i;
+    int j;
+    int c;
+    int tic_every;
+    int max_tics;
+    int title_color;
+    int num_y_files;
+    int tic_unit;
+    double t, b, l, r;
+    double tt, tb, tl, tr;
+    int prev_x, prev_y[11];
+    int new_x, new_y[11];
+    int line;
+    double x_line[3];
+    double y_line[3];
+    int err;
+
+    struct in_file
+    {
+	int num_pnts;		/* number of lines in file  */
+	int color;		/* color to use for y lines */
+	float max;		/* maximum value in file    */
+	float min;		/* minimum value in file    */
+	float value;		/* current value read in    */
+	char name[1024];	/* name of file      */
+	char full_name[1024];	/* path/name of file    */
+	FILE *fp;		/* pointer to file        */
+    };
+
+    struct in_file in[12];
+    struct GModule *module;
+
+    float max_y;
+    float min_y;
+    float height, width;
+    float xscale;
+    float yscale;
+
+    char txt[1024], xlabel[512];
+    char tic_name[1024];
+    char *name;
+    char color_name[20];
+
+    FILE *fopen();
+
+    struct Option *dir_opt, *x_opt, *y_opt;
+    struct Option *y_color_opt;
+    struct Option *title[3];
+    struct Option *t_color_opt;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("display");
+    module->description =
+	_("Generates and displays simple line graphs in the active graphics monitor display frame.");
+
+    x_opt = G_define_option();
+    x_opt->key = "x_file";
+    x_opt->description = _("Name of data file for X axis of graph");
+    x_opt->type = TYPE_STRING;
+    x_opt->required = YES;
+
+    y_opt = G_define_option();
+    y_opt->key = "y_file";
+    y_opt->description = _("Name of data file(s) for Y axis of graph");
+    y_opt->type = TYPE_STRING;
+    y_opt->required = YES;
+    y_opt->multiple = YES;
+
+    dir_opt = G_define_option();
+    dir_opt->key = "directory";
+    dir_opt->description = _("Path to file location");
+    dir_opt->type = TYPE_STRING;
+    dir_opt->required = NO;
+    dir_opt->answer = ".";
+
+    y_color_opt = G_define_option();
+    y_color_opt->key = "y_color";
+    y_color_opt->description = _("Color for Y data");
+    y_color_opt->type = TYPE_STRING;
+    y_color_opt->required = NO;
+    y_color_opt->multiple = YES;
+    y_color_opt->answers = NULL;
+    y_color_opt->options = D_COLOR_LIST;
+
+    t_color_opt = G_define_option();
+    t_color_opt->key = "title_color";
+    t_color_opt->description = _("Color for axis, tics, numbers, and title");
+    t_color_opt->type = TYPE_STRING;
+    t_color_opt->required = NO;
+    t_color_opt->answer = DEFAULT_FG_COLOR;
+    t_color_opt->options = D_COLOR_LIST;
+
+    title[0] = G_define_option();
+    title[0]->key = "x_title";
+    title[0]->description = _("Title for X data");
+    title[0]->type = TYPE_STRING;
+    title[0]->required = NO;
+    title[0]->answer = "";
+
+    title[1] = G_define_option();
+    title[1]->key = "y_title";
+    title[1]->description = _("Title for Y data");
+    title[1]->type = TYPE_STRING;
+    title[1]->required = NO;
+    title[1]->answer = "";
+
+    title[2] = G_define_option();
+    title[2]->key = "title";
+    title[2]->description = _("Title for Graph");
+    title[2]->type = TYPE_STRING;
+    title[2]->required = NO;
+    title[2]->answer = "";
+
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    for (i = 0; i < 3; i++) {
+	for (j = 0; j < strlen(title[i]->answer); j++)
+	    if (title[i]->answer[j] == '_')
+		title[i]->answer[j] = ' ';
+    }
+
+    /* build path to X data file and open for reading
+       notice that in[0] will be the X file, and in[1-10]
+       will be the Y file(s) */
+
+    sprintf(in[0].full_name, "%s/%s", dir_opt->answer, x_opt->answer);
+    sprintf(in[0].name, "%s", x_opt->answer);
+
+    if ((in[0].fp = fopen(in[0].full_name, "r")) == NULL)
+	G_fatal_error(_("Unable to open input file <%s>"), in[0].full_name);
+
+    num_y_files = 0;
+
+    /* open all Y data files */
+
+    for (i = 0, j = 1; (name = y_opt->answers[i]); i++, j++) {
+	sprintf(in[j].full_name, "%s/%s", dir_opt->answer, name);
+	sprintf(in[j].name, "%s", name);
+
+	if ((in[j].fp = fopen(in[j].full_name, "r")) == NULL)
+	    G_fatal_error(_("Unable to open input file <%s>"),
+			  in[j].full_name);
+
+	num_y_files++;
+	if (num_y_files > 10)
+	    G_fatal_error(_("Maximum of 10 Y data files exceeded"));
+    }
+
+    /* set colors  */
+
+    title_color = D_translate_color(t_color_opt->answer);
+
+    /* I had an argument with the parser, and couldn't get a neat list of
+       the input colors as I thought I should. I did a quick hack to get
+       my list from the answer var, which gives us the colors input
+       separated by commas. at least we know that they have been checked against
+       the list of possibles */
+    c = 0;
+    j = 1;
+    if (y_color_opt->answer != NULL) {
+	for (i = 0; i <= (strlen(y_color_opt->answer)); i++) {
+	    if ((y_color_opt->answer[i] == ',') ||
+		(i == (strlen(y_color_opt->answer)))) {
+		color_name[c] = '\0';
+		in[j].color = D_translate_color(color_name);
+		j++;
+		c = 0;
+	    }
+	    else {
+		color_name[c++] = y_color_opt->answer[i];
+	    }
+	}
+	/* this is lame. I could come up with a color or prompt for one or something */
+	if (j < num_y_files)
+	    G_fatal_error(_("Only <%d> colors given for <%d> lines"), j,
+			  num_y_files);
+    }
+    else
+	/* no colors given on command line, use default list */
+    {
+	for (i = 1; i <= num_y_files; i++) {
+	    in[i].color = default_y_colors[i];
+	}
+    }
+
+    /* get coordinates of current screen window, in pixels */
+    if (R_open_driver() != 0)
+	G_fatal_error(_("No graphics device selected"));
+    D_get_screen_window(&t, &b, &l, &r);
+    R_set_window(t, b, l, r);
+
+    /* create axis lines, to be drawn later */
+    height = b - t;
+    width = r - l;
+    x_line[0] = x_line[1] = l + (int)(ORIGIN_X * width);
+    x_line[2] = l + (int)(XAXIS_END * width);
+    y_line[0] = b - (int)(YAXIS_END * height);
+    y_line[1] = y_line[2] = b - (int)(ORIGIN_Y * height);
+    text_height = (int)(b - t) * TEXT_HEIGHT;
+    text_width = (int)(r - l) * TEXT_WIDTH;
+    R_text_size(text_width, text_height);
+
+    /* read thru each data file in turn, find max and min values for
+       each, count lines, find x min and max, find overall y min and
+       max */
+
+    max_y = -99999.9;
+    min_y = 99999.9;
+
+    for (i = 0; i <= num_y_files; i++) {
+
+	in[i].min = 99999.9;
+	in[i].max = -99999.9;
+	in[i].value = 0.0;
+	in[i].num_pnts = 0;
+
+	while ((err = fscanf(in[i].fp, "%f", &in[i].value)) != EOF) {
+	    in[i].num_pnts++;
+	    in[i].max = MAX(in[i].max, in[i].value);
+	    in[i].min = MIN(in[i].min, in[i].value);
+	    if (i > 0) {	/* if we have a y file */
+		min_y = MIN(min_y, in[i].value);
+		max_y = MAX(max_y, in[i].value);
+	    }
+	}
+	if ((i > 0) && (in[0].num_pnts != in[i].num_pnts)) {
+	    G_warning(_("Y input file <%s> contains %s data points than the X input file"),
+		      in[i].name,
+		      ((in[i].num_pnts < in[0].num_pnts) ? "fewer" : "more"));
+
+	    if (in[i].num_pnts > in[0].num_pnts)
+		G_message(_("The last %d point(s) will be ignored"),
+			  (in[i].num_pnts - in[0].num_pnts));
+	}
+    }
+
+    /* close all files */
+
+    for (i = 0; i <= num_y_files; i++)
+	fclose(in[i].fp);
+
+    /* figure scaling factors and offsets */
+
+    xscale = ((double)(x_line[2] - x_line[1]) / (double)(in[0].num_pnts));
+    yscale = ((double)(y_line[1] - y_line[0]) / (max_y - min_y));
+    yoffset = (double)(y_line[1]);
+    xoffset = (double)(x_line[1]);
+
+    /* figure tic_every and tic_units for the x-axis of the bar-chart.
+       tic_every tells how often to place a tic-number.  tic_unit tells
+       the unit to use in expressing tic-numbers. */
+
+    if (xscale < XTIC_DIST) {
+	max_tics = (x_line[2] - x_line[1]) / XTIC_DIST;
+	i = 1;
+	while (((in[0].max - in[0].min) / tics[i].every) > max_tics)
+	    i++;
+	tic_every = tics[i].every;
+	tic_unit = tics[i].unit;
+	strcpy(tic_name, tics[i].name);
+    }
+    else {
+	tic_every = 1;
+	tic_unit = 1;
+	strcpy(tic_name, "");
+    }
+
+
+    /* open all the data files again */
+
+    for (i = 0; i <= num_y_files; i++) {
+	if ((in[i].fp = fopen(in[i].full_name, "r")) == NULL) {
+	    sprintf(txt, "Could not open input file <%s>.", in[i].full_name);
+	    death(txt);
+	}
+    }
+
+    /* loop through number of lines in x data file, 
+       then loop thru for each y file, drawing a piece of each line and a
+       legend bar on each iteration evenly divisible, a tic-mark
+       on those evenly divisible by tic_unit, and a tic_mark
+       number on those evenly divisible by tic_every   */
+
+    /* read the info from the inputs */
+
+    for (line = 0; line < in[0].num_pnts; line++) {
+	/* scan in an X value */
+	err = fscanf(in[0].fp, "%f", &in[0].value);
+
+	/* didn't find a number or hit EOF before our time */
+	if ((err != 1) || (err == EOF)) {
+	    sprintf(txt, _("Problem reading X data file at line %d"), line);
+	    death(txt);
+	}
+
+	/* for each Y data file, get a value and compute where to draw it */
+	for (i = 1; i <= num_y_files; i++) {
+	    /* check to see that we do indeed have data for this point */
+	    if (line < in[i].num_pnts) {
+		err = fscanf(in[i].fp, "%f", &in[i].value);
+		if ((in[i].num_pnts >= line) && (err != 1)) {
+		    sprintf(txt,
+			    _("Problem reading <%s> data file at line %d"),
+			    in[i].name, line);
+		    death(txt);
+		}
+
+		/* in case the Y file has fewer lines than the X file, we will skip
+		   trying to draw when we run out of data */
+
+		/* draw increment of each Y file's data */
+
+		R_standard_color(in[i].color);
+
+		/* find out position of where Y should be drawn. */
+		/* if our minimum value of y is not negative, this is easy */
+
+		if (min_y >= 0)
+		    new_y[i] =
+			(int)(yoffset - yscale * (in[i].value - min_y));
+
+		/* if our minimum value of y is negative, then we have two
+		   cases:  our current value to plot is pos or neg */
+
+		else {
+		    if (in[i].value < 0)
+			new_y[i] = (int)(yoffset - yscale * (-1 *
+							     (min_y -
+							      in[i].value)));
+		    else
+			new_y[i] = (int)(yoffset - yscale * (in[i].value +
+							     (min_y * -1)));
+		}
+
+		new_x = xoffset + (line * xscale);
+		if (line == 0) {
+		    prev_x = xoffset;
+		    prev_y[i] = yoffset;
+		}
+		R_move_abs(prev_x, prev_y[i]);
+		R_cont_abs(new_x, new_y[i]);
+		prev_y[i] = new_y[i];
+	    }
+	}
+	prev_x = new_x;
+
+	/* draw x-axis tic-marks and numbers */
+
+	if (rem((long int)in[0].value, tic_every) == (float)0) {
+
+	    /* draw a numbered tic-mark */
+
+	    R_standard_color(title_color);
+	    R_move_abs((int)(xoffset + line * xscale),
+		       (int)(b - ORIGIN_Y * (b - t)));
+	    R_cont_rel((int)0, (int)(BIG_TIC * (b - t)));
+	    if ((in[0].value >= 1) || (in[0].value <= -1) ||
+		(in[0].value == 0))
+		sprintf(txt, "%.0f", (in[0].value / tic_unit));
+	    else
+		sprintf(txt, "%.2f", (in[0].value));
+	    text_height = (b - t) * TEXT_HEIGHT;
+	    text_width = (r - l) * TEXT_WIDTH;
+	    R_text_size(text_width, text_height);
+	    R_get_text_box(txt, &tt, &tb, &tl, &tr);
+	    while ((tr - tl) > XTIC_DIST) {
+		text_width *= 0.75;
+		text_height *= 0.75;
+		R_text_size(text_width, text_height);
+		R_get_text_box(txt, &tt, &tb, &tl, &tr);
+	    }
+	    R_move_abs((int)(xoffset + (line * xscale - (tr - tl) / 2)),
+		       (int)(b - XNUMS_Y * (b - t)));
+	    R_text(txt);
+	}
+	else if (rem(line, tic_unit) == (float)0) {
+
+	    /* draw a tic-mark */
+
+	    R_standard_color(title_color);
+	    R_move_abs((int)(xoffset + line * xscale),
+		       (int)(b - ORIGIN_Y * (b - t)));
+	    R_cont_rel((int)0, (int)(SMALL_TIC * (b - t)));
+	}
+    }
+
+    /* close all input files */
+    for (i = 0; i <= num_y_files; i++) {
+	fclose(in[i].fp);
+    }
+
+    /* draw the x-axis label */
+    if ((strcmp(title[0]->answer, "") == 0) && (strcmp(tic_name, "") == 0))
+	*xlabel = '\0';
+    else
+	sprintf(xlabel, "X: %s %s", title[0]->answer, tic_name);
+    text_height = (b - t) * TEXT_HEIGHT;
+    text_width = (r - l) * TEXT_WIDTH * 1.5;
+    R_text_size(text_width, text_height);
+    R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
+    R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
+	       (int)(b - LABEL_1 * (b - t)));
+    R_standard_color(title_color);
+    R_text(xlabel);
+
+    /* DRAW Y-AXIS TIC-MARKS AND NUMBERS
+       first, figure tic_every and tic_units for the x-axis of the bar-chart.
+       tic_every tells how often to place a tic-number.  tic_unit tells
+       the unit to use in expressing tic-numbers. */
+
+    if (yscale < YTIC_DIST) {
+	max_tics = (y_line[1] - y_line[0]) / YTIC_DIST;
+	i = 1;
+	while (((max_y - min_y) / tics[i].every) > max_tics)
+	    i++;
+	tic_every = tics[i].every;
+	tic_unit = tics[i].unit;
+	strcpy(tic_name, tics[i].name);
+    }
+    else {
+	tic_every = 1;
+	tic_unit = 1;
+	strcpy(tic_name, "");
+    }
+
+    /* Y-AXIS LOOP */
+
+    for (i = (int)min_y; i <= (int)max_y; i += tic_unit) {
+	if (rem(i, tic_every) == (float)0) {
+	    /* draw a tic-mark */
+
+	    R_move_abs((int)x_line[0], (int)(yoffset - yscale * (i - min_y)));
+	    R_cont_rel((int)(-(r - l) * BIG_TIC), (int)0);
+
+	    /* draw a tic-mark number */
+
+	    sprintf(txt, "%d", (i / tic_unit));
+	    text_height = (b - t) * TEXT_HEIGHT;
+	    text_width = (r - l) * TEXT_WIDTH;
+	    R_text_size(text_width, text_height);
+	    R_get_text_box(txt, &tt, &tb, &tl, &tr);
+	    while ((tt - tb) > YTIC_DIST) {
+		text_width *= 0.75;
+		text_height *= 0.75;
+		R_text_size(text_width, text_height);
+		R_get_text_box(txt, &tt, &tb, &tl, &tr);
+	    }
+	    R_move_abs((int)(l + (r - l) * YNUMS_X - (tr - tl) / 2),
+		       (int)(yoffset -
+			     (yscale * (i - min_y) + 0.5 * (tt - tb))));
+	    R_text(txt);
+	}
+	else if (rem(i, tic_unit) == (float)0) {
+	    /* draw a tic-mark */
+
+	    R_move_abs((int)x_line[0], (int)(yoffset - yscale * (i - min_y)));
+	    R_cont_rel((int)(-(r - l) * SMALL_TIC), (int)0);
+	}
+    }
+
+    /* draw the y-axis label */
+    if ((strcmp(title[1]->answer, "") == 0) && (strcmp(tic_name, "") == 0))
+	*xlabel = '\0';
+    else
+	sprintf(xlabel, "Y: %s %s", title[1]->answer, tic_name);
+    text_height = (b - t) * TEXT_HEIGHT;
+    text_width = (r - l) * TEXT_WIDTH * 1.5;
+    R_text_size(text_width, text_height);
+    R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
+    R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
+	       (int)(b - LABEL_2 * (b - t)));
+    R_standard_color(title_color);
+    R_text(xlabel);
+
+    /* top label */
+    sprintf(xlabel, title[2]->answer);
+    text_height = (b - t) * TEXT_HEIGHT;
+    text_width = (r - l) * TEXT_WIDTH * 2.0;
+    R_text_size(text_width, text_height);
+    R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
+    /*
+       R_move_abs((int)(((r-l)/2)-(tr-tl)/2),
+       (int) (t+ (b-t)*.07) );
+     */
+    R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
+	       (int)(t + (b - t) * .07));
+    R_standard_color(title_color);
+    R_text(xlabel);
+
+    /* draw x and y axis lines */
+    R_standard_color(title_color);
+    R_polyline_abs(x_line, y_line, 3);
+
+    R_flush();
+    R_close_driver();
+    exit(EXIT_SUCCESS);
+}
+
+float rem(long int x, long int y)
+{
+    long int d = x / y;
+
+    return ((float)(x - y * d));
+}
+
+
+/* a function for making an exit after the R_driver is open */
+int death(char *gasp)
+{
+    R_flush();
+    R_close_driver();
+    G_fatal_error("%s", gasp);
+}

Deleted: grass/trunk/display/d.rast.arrow/arrow.c
===================================================================
--- grass/trunk/display/d.rast.arrow/arrow.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/display/d.rast.arrow/arrow.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,819 +0,0 @@
-/*
- ****************************************************************************
- *
- * MODULE:       d.rast.arrow
- * AUTHOR(S):    Chris Rewerts, Agricultural Engineering, Purdue University
- * PURPOSE:      Draw arrows on slope/aspect maps. 
- * COPYRIGHT:    (C) 2000 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.
- *
- *****************************************************************************/
-
-/* some minor cleanup done by Andreas Lange, andreas.lange at rhein-main.de
- * Update to handle NULLs and floating point aspect maps: Hamish Bowman, Aug 2004
- * Update for 360 degree arrows and magnitude scaling:  Hamish Bowman, Oct 2005
- */
-
-/*
- *   Chris Rewerts, Agricultural Engineering, Purdue University
- *   rewerts at ecn.purdue.edu  March 1991
- *
- *   d.rast.arrow
- *
- *   Usage:  d.rast.arrow
- * 
- *   This program used Dgrid's sources as a beginning. Purpose of Darrow
- *   is to read an aspect layer produced by slope.aspect or by the 
- *   programs created for the ANSWERS or AGNPS Hydrology Toolbox
- *   endeavors.  d.rast.arrow draws an arrow on the graphic display
- *   of each cell, so that the flow pattern computed as an aspect
- *   layer can be easily seen. Other symbols ("?", "X") may be drawn
- *   as needed.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/display.h>
-#include <grass/colors.h>
-#include <grass/glocale.h>
-
-# define RpD ((2 * M_PI) / 360.)	/* radians/degree */
-# define D2R(d) (double)(d * RpD)	/* degrees->radians */
-
-static void arrow_mag(double, double);
-static void arrow_360(double);
-static void arrow_se(void);
-static void arrow_ne(void);
-static void arrow_nw(void);
-static void arrow_sw(void);
-static void arrow_e(void);
-static void arrow_w(void);
-static void arrow_s(void);
-static void arrow_n(void);
-static void draw_x(void);
-static void unknown_(void);
-
-int D_x, D_y;
-double D_ew, D_ns;
-char *mapset;
-char layer_name[128];
-int map_type, arrow_color, grid_color, x_color, unknown_color;
-
-
-int main(int argc, char **argv)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    struct Cell_head window;
-    double t, b, l, r;
-    RASTER_MAP_TYPE raster_type, mag_raster_type = -1;
-    int layer_fd;
-    void *raster_row, *ptr;
-    int nrows, ncols, row, col;
-    int aspect_c = -1;
-    float aspect_f = -1.0;
-    double ew_res, ns_res;
-    double D_south, D_west;
-    double D_north, D_east;
-    double U_to_D_xconv, U_to_D_yconv;
-    double U_west, U_south;
-    double U_east, U_north;
-    double U_start;
-    double U_x, U_y;
-
-    double scale;
-    int skip, no_arrow;
-    char *mag_map = NULL, *mag_mapset = NULL;
-    void *mag_raster_row = NULL, *mag_ptr = NULL;
-    double length = -1;
-    int mag_fd = -1;
-    struct FPRange range;
-    double mag_min, mag_max;
-
-    struct GModule *module;
-    struct Option *opt1, *opt2, *opt3, *opt4, *opt5,
-	*opt6, *opt7, *opt8, *opt9;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("display");
-    module->description =
-	_("Draws arrows representing cell aspect direction "
-	  "for a raster map containing aspect data.");
-
-    opt1 = G_define_option();
-    opt1->key = "map";
-    opt1->type = TYPE_STRING;
-    opt1->required = YES;
-    opt1->multiple = NO;
-    opt1->gisprompt = "old,cell,raster";
-    opt1->description = _("Name of raster aspect map to be displayed");
-
-    opt2 = G_define_option();
-    opt2->key = "type";
-    opt2->type = TYPE_STRING;
-    opt2->required = NO;
-    opt2->answer = "grass";
-    opt2->options = "grass,compass,agnps,answers";
-    opt2->description = _("Type of existing raster aspect map");
-
-    opt3 = G_define_option();
-    opt3->key = "arrow_color";
-    opt3->type = TYPE_STRING;
-    opt3->required = NO;
-    opt3->answer = "green";
-    opt3->options = D_COLOR_LIST;
-    opt3->description = _("Color for drawing arrows");
-
-    opt4 = G_define_option();
-    opt4->key = "grid_color";
-    opt4->type = TYPE_STRING;
-    opt4->required = NO;
-    opt4->answer = "gray";
-    opt4->options = D_COLOR_LIST ",none";
-    opt4->description = _("Color for drawing grid or \"none\"");
-
-    opt5 = G_define_option();
-    opt5->key = "x_color";
-    opt5->type = TYPE_STRING;
-    opt5->required = NO;
-    opt5->answer = DEFAULT_FG_COLOR;
-    opt5->options = D_COLOR_LIST;
-    opt5->description = _("Color for drawing X's (Null values)");
-
-    opt6 = G_define_option();
-    opt6->key = "unknown_color";
-    opt6->type = TYPE_STRING;
-    opt6->required = NO;
-    opt6->answer = "red";
-    opt6->options = D_COLOR_LIST;
-    opt6->description = _("Color for showing unknown information");
-
-    opt9 = G_define_option();
-    opt9->key = "skip";
-    opt9->type = TYPE_INTEGER;
-    opt9->required = NO;
-    opt9->answer = "1";
-    opt9->description = _("Draw arrow every Nth grid cell");
-
-    opt7 = G_define_option();
-    opt7->key = "magnitude_map";
-    opt7->type = TYPE_STRING;
-    opt7->required = NO;
-    opt7->multiple = NO;
-    opt7->gisprompt = "old,cell,raster";
-    opt7->description =
-	_("Raster map containing values used for arrow length");
-
-    opt8 = G_define_option();
-    opt8->key = "scale";
-    opt8->type = TYPE_DOUBLE;
-    opt8->required = NO;
-    opt8->answer = "1.0";
-    opt8->description = _("Scale factor for arrows (magnitude map)");
-
-
-    /* Check command line */
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-
-    strncpy(layer_name, opt1->answer, sizeof(layer_name) - 1);
-    if ((mapset = G_find_cell2(layer_name, "")) == NULL)
-	G_fatal_error(_("Raster map <%s> not found"), layer_name);
-
-    arrow_color = D_translate_color(opt3->answer);
-    x_color = D_translate_color(opt5->answer);
-    unknown_color = D_translate_color(opt6->answer);
-
-    if (strcmp("none", opt4->answer) == 0)
-	grid_color = -1;
-    else
-	grid_color = D_translate_color(opt4->answer);
-
-
-    if (strcmp("grass", opt2->answer) == 0)
-	map_type = 1;
-    else if (strcmp("agnps", opt2->answer) == 0)
-	map_type = 2;
-    else if (strcmp("answers", opt2->answer) == 0)
-	map_type = 3;
-    else if (strcmp("compass", opt2->answer) == 0)
-	map_type = 4;
-
-
-    scale = atof(opt8->answer);
-    if (scale <= 0.0)
-	G_fatal_error(_("Illegal value for scale factor"));
-
-    skip = atoi(opt9->answer);
-    if (skip <= 0)
-	G_fatal_error(_("Illegal value for skip factor"));
-
-
-    if (opt7->answer) {
-	if (map_type != 1 && map_type != 4)
-	    G_fatal_error(_("Magnitude is only supported for GRASS and compass aspect maps."));
-
-	mag_map = opt7->answer;
-	if ((mag_mapset = G_find_cell2(mag_map, "")) == NULL)
-	    G_fatal_error(_("Raster map <%s> not found"), mag_map);
-    }
-    else if (scale != 1.0)
-	G_warning(_("Scale option requires magnitude_map"));
-
-
-    /* Setup driver and check important information */
-    if (R_open_driver() != 0)
-	G_fatal_error(_("No graphics device selected"));
-
-    /* Read in the map window associated with window */
-    G_get_window(&window);
-
-    D_check_map_window(&window);
-
-    if (G_set_window(&window) == -1)
-	G_fatal_error(_("Current window not settable"));
-
-    /* Determine conversion factors */
-    if (D_get_screen_window(&t, &b, &l, &r))
-	G_fatal_error(_("Getting screen window"));
-    if (D_do_conversions(&window, t, b, l, r))
-	G_fatal_error(_("Error in calculating conversions"));
-
-    /* where are we, both geographically and on the screen? */
-    D_south = D_get_d_south();
-    D_north = D_get_d_north();
-    D_east = D_get_d_east();
-    D_west = D_get_d_west();
-
-    U_west = D_get_u_west();
-    U_east = D_get_u_east();
-    U_south = D_get_u_south();
-    U_north = D_get_u_north();
-
-    U_to_D_xconv = D_get_u_to_d_xconv();
-    U_to_D_yconv = D_get_u_to_d_yconv();
-
-    /* number of rows and cols in window */
-    nrows = window.rows;
-    ncols = window.cols;
-
-    /*
-       if ((nrows > 75) || (ncols > 75)){ 
-       fprintf (stdout,"\n"); 
-       fprintf (stdout,"Current window size:\n"); 
-       fprintf (stdout,"rows:    %d\n", nrows);
-       fprintf (stdout,"columns: %d\n", ncols);
-       fprintf (stdout,"\n"); 
-       fprintf (stdout,"Your current window setting may be too large.\n"); 
-       fprintf (stdout,"Cells displayed on your graphics window may be too\n"); 
-       fprintf (stdout,"small for arrows to be visible.\n\n"); 
-       if (!G_yes("Do you wish to continue", 0))
-       exit(0);
-       }
-     */
-
-    /* resolutions */
-    ew_res = window.ew_res;
-    ns_res = window.ns_res;
-
-    /* how many screen units of distance for each cell */
-    D_ew = (D_east - D_west) / ncols;
-    D_ns = (D_south - D_north) / nrows;
-
-    /* figure out arrow scaling if using a magnitude map */
-    if (opt7->answer) {
-	G_init_fp_range(&range);	/* really needed? */
-	if (G_read_fp_range(mag_map, mag_mapset, &range) != 1)
-	    G_fatal_error(_("Problem reading range file"));
-	G_get_fp_range_min_max(&range, &mag_min, &mag_max);
-
-	scale *= 1.5 * ((D_ew < D_ns) ? D_ew : D_ns) / fabs(mag_max);
-	G_debug(3, "scaling=%.2f  rast_max=%.2f  D_ew=%.2f", scale, mag_max,
-		D_ew);
-    }
-
-/*------------------------------------------
-    fprintf (stdout,"ew_res:  %.2f\n", window.ew_res);
-    fprintf (stdout,"ns_res:  %.2f\n", window.ns_res);
-    fprintf (stdout,"D_ew:  %f D_ns:  %f \n", D_ew, D_ns); 
-    fprintf (stdout,"nrows:    %d\n", nrows);
-    fprintf (stdout,"ncols:    %d\n", ncols);
-    fprintf (stdout,"t:  %d\n", t);
-    fprintf (stdout,"b:  %d\n", b);
-    fprintf (stdout,"l:  %d\n", l);
-    fprintf (stdout,"r:  %d\n", r);
-    fprintf (stdout,"U_west:	%f\n", U_west);
-    fprintf (stdout,"U_east:	%f\n", U_east);
-    fprintf (stdout,"U_south:	%f\n", U_south);
-    fprintf (stdout,"U_north:	%f\n", U_north);
-    fprintf (stdout,"D_west:	%f\n", D_west);
-    fprintf (stdout,"D_east:	%f\n", D_east);
-    fprintf (stdout,"D_south:	%f\n", D_south);
-    fprintf (stdout,"D_north:	%f\n", D_north);
-    fprintf (stdout,"U_to_D_xconv:	%f\n", U_to_D_xconv);
-    fprintf (stdout,"U_to_D_yconv:	%f\n", U_to_D_yconv);
---------------------------------------------------------*/
-
-    if (grid_color > 0) {	/* ie not "none" */
-	/* Set color */
-	R_standard_color(grid_color);
-
-	/* Draw vertical grids */
-	U_start = U_east;
-	for (U_x = U_start; U_x >= U_west; U_x -= ew_res) {
-	    D_x = (int)((U_x - U_west) * U_to_D_xconv + D_west);
-	    R_move_abs(D_x, (int)D_south);
-	    R_cont_abs(D_x, (int)D_north);
-	}
-
-	/* Draw horizontal grids */
-	U_start = U_north;
-	for (U_y = U_start; U_y >= U_south; U_y -= ns_res) {
-	    D_y = (int)((U_south - U_y) * U_to_D_yconv + D_south);
-	    R_move_abs((int)D_west, D_y);
-	    R_cont_abs((int)D_east, D_y);
-	}
-    }
-
-    /* open the raster map */
-    layer_fd = G_open_cell_old(layer_name, mapset);
-    if (layer_fd < 0)
-	G_fatal_error(_("Unable to open raster map <%s>"), layer_name);
-
-    raster_type = G_get_raster_map_type(layer_fd);
-
-    /* allocate the cell array */
-    raster_row = G_allocate_raster_buf(raster_type);
-
-
-    if (opt7->answer) {
-	/* open the magnitude raster map */
-	mag_fd = G_open_cell_old(mag_map, mag_mapset);
-	if (mag_fd < 0)
-	    G_fatal_error("Unable to open raster map <%s>", mag_map);
-
-	mag_raster_type = G_get_raster_map_type(mag_fd);
-
-	/* allocate the cell array */
-	mag_raster_row = G_allocate_raster_buf(mag_raster_type);
-    }
-
-
-    /* loop through cells, find value, determine direction (n,s,e,w,ne,se,sw,nw),
-       and call appropriate function to draw an arrow on the cell */
-
-    for (row = 0; row < nrows; row++) {
-	G_get_raster_row(layer_fd, raster_row, row, raster_type);
-	ptr = raster_row;
-
-	if (opt7->answer) {
-	    G_get_raster_row(mag_fd, mag_raster_row, row, mag_raster_type);
-	    mag_ptr = mag_raster_row;
-	}
-
-	/* determine screen y coordinate of top of current cell */
-	D_y = (int)(row * D_ns + D_north);
-
-	for (col = 0; col < ncols; col++) {
-
-	    if (row % skip != 0)
-		no_arrow = TRUE;
-	    else
-		no_arrow = FALSE;
-
-	    if (col % skip != 0)
-		no_arrow = TRUE;
-
-	    /* determine screen x coordinate of west side of current cell */
-	    D_x = (int)(col * D_ew + D_west);
-
-	    /* find aspect direction based on cell value */
-	    if (raster_type == CELL_TYPE)
-		aspect_f = *((CELL *) ptr);
-	    else if (raster_type == FCELL_TYPE)
-		aspect_f = *((FCELL *) ptr);
-	    else if (raster_type == DCELL_TYPE)
-		aspect_f = *((DCELL *) ptr);
-
-
-	    if (opt7->answer) {
-
-		if (mag_raster_type == CELL_TYPE)
-		    length = *((CELL *) mag_ptr);
-		else if (mag_raster_type == FCELL_TYPE)
-		    length = *((FCELL *) mag_ptr);
-		else if (mag_raster_type == DCELL_TYPE)
-		    length = *((DCELL *) mag_ptr);
-
-		length *= scale;
-
-		if (G_is_null_value(mag_ptr, mag_raster_type)) {
-		    G_debug(5, "Invalid arrow length [NULL]. Skipping.");
-		    no_arrow = TRUE;
-		}
-		else if (length <= 0.0) {	/* use fabs() or theta+=180? */
-		    G_debug(5, "Illegal arrow length [%.3f]. Skipping.",
-			    length);
-		    no_arrow = TRUE;
-		}
-	    }
-
-	    if (no_arrow) {
-		ptr = G_incr_void_ptr(ptr, G_raster_size(raster_type));
-		if (opt7->answer)
-		    mag_ptr =
-			G_incr_void_ptr(mag_ptr,
-					G_raster_size(mag_raster_type));
-		no_arrow = FALSE;
-		continue;
-	    }
-
-	    /* treat AGNPS and ANSWERS data like old zero-as-null CELL */
-	    /*   TODO: update models */
-	    if (map_type == 2 || map_type == 3) {
-		if (G_is_null_value(ptr, raster_type))
-		    aspect_c = 0;
-		else
-		    aspect_c = (int)(aspect_f + 0.5);
-	    }
-
-
-	    /** Now draw the arrows **/
-
-	    /* case switch for standard GRASS aspect map 
-	       measured in degrees counter-clockwise from east */
-	    if (map_type == 1) {
-		R_standard_color(arrow_color);
-
-		if (G_is_null_value(ptr, raster_type)) {
-		    R_standard_color(x_color);
-		    draw_x();
-		    R_standard_color(arrow_color);
-		}
-		else if (aspect_f >= 0.0 && aspect_f <= 360.0) {
-		    if (opt7->answer)
-			arrow_mag(aspect_f, length);
-		    else
-			arrow_360(aspect_f);
-		}
-		else {
-		    R_standard_color(unknown_color);
-		    unknown_();
-		    R_standard_color(arrow_color);
-		}
-	    }
-
-
-	    /* case switch for AGNPS type aspect map */
-	    else if (map_type == 2) {
-		R_standard_color(arrow_color);
-		switch (aspect_c) {
-		case 0:
-		    R_standard_color(x_color);
-		    draw_x();
-		    R_standard_color(arrow_color);
-		    break;
-		case 1:
-		    arrow_n();
-		    break;
-		case 2:
-		    arrow_ne();
-		    break;
-		case 3:
-		    arrow_e();
-		    break;
-		case 4:
-		    arrow_se();
-		    break;
-		case 5:
-		    arrow_s();
-		    break;
-		case 6:
-		    arrow_sw();
-		    break;
-		case 7:
-		    arrow_w();
-		    break;
-		case 8:
-		    arrow_nw();
-		    break;
-		default:
-		    R_standard_color(unknown_color);
-		    unknown_();
-		    R_standard_color(arrow_color);
-		    break;
-		}
-	    }
-
-
-	    /* case switch for ANSWERS type aspect map */
-	    else if (map_type == 3) {
-		R_standard_color(arrow_color);
-		if (aspect_c >= 15 && aspect_c <= 360)	/* start at zero? */
-		    arrow_360((double)aspect_c);
-		else if (aspect_c == 400) {
-		    R_standard_color(unknown_color);
-		    unknown_();
-		    R_standard_color(arrow_color);
-		}
-		else {
-		    R_standard_color(x_color);
-		    draw_x();
-		    R_standard_color(arrow_color);
-		}
-	    }
-
-	    /* case switch for compass type aspect map
-	       measured in degrees clockwise from north */
-	    else if (map_type == 4) {
-		R_standard_color(arrow_color);
-
-		if (G_is_null_value(ptr, raster_type)) {
-		    R_standard_color(x_color);
-		    draw_x();
-		    R_standard_color(arrow_color);
-		}
-		else if (aspect_f >= 0.0 && aspect_f <= 360.0) {
-		    if (opt7->answer)
-			arrow_mag(90 - aspect_f, length);
-		    else
-			arrow_360(90 - aspect_f);
-		}
-		else {
-		    R_standard_color(unknown_color);
-		    unknown_();
-		    R_standard_color(arrow_color);
-		}
-	    }
-
-	    ptr = G_incr_void_ptr(ptr, G_raster_size(raster_type));
-	    if (opt7->answer)
-		mag_ptr =
-		    G_incr_void_ptr(mag_ptr, G_raster_size(mag_raster_type));
-	}
-    }
-
-    G_close_cell(layer_fd);
-    if (opt7->answer)
-	G_close_cell(mag_fd);
-
-    R_close_driver();
-
-    exit(0);
-}
-
-/* --- end of main --- */
-
-/*---------------------------------------------------------------*/
-
-
-static void arrow_mag(double theta, double length)
-{				/* angle is measured in degrees counter-clockwise from east */
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y, dx, dy, mid_x, mid_y;
-    double theta_offset;
-
-    theta *= -1;		/* display coords use inverse y */
-
-    /* find the display coordinates of the middle of the cell */
-    mid_x = D_x + (int)(D_ew * .5);
-    mid_y = D_y + (int)(D_ns * .5);
-
-    /* tail */
-    R_move_abs(mid_x, mid_y);
-
-    /* head */
-    x = mid_x + (int)(length * cos(D2R(theta)));
-    y = mid_y + (int)(length * sin(D2R(theta)));
-    R_cont_abs(x, y);
-
-    /* fin 1 */
-    theta_offset = theta + 20;
-    dx = mid_x + (int)(0.6 * length * cos(D2R(theta_offset)));
-    dy = mid_y + (int)(0.6 * length * sin(D2R(theta_offset)));
-    R_cont_abs(dx, dy);
-
-    /* fin 2 */
-    R_move_abs(x, y);
-    theta_offset = theta - 20;
-    dx = mid_x + (int)(0.6 * length * cos(D2R(theta_offset)));
-    dy = mid_y + (int)(0.6 * length * sin(D2R(theta_offset)));
-    R_cont_abs(dx, dy);
-}
-
-
-static void arrow_360(double theta)
-{				/* angle is measured in degrees counter-clockwise from east */
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y, dx, dy, mid_x, mid_y;
-    double max_radius, theta_offset;
-
-    theta *= -1;		/* display coords use inverse y */
-    max_radius = ((D_ew < D_ns) ? D_ew : D_ns) * 0.8 / 2;
-
-    /* find the display coordinates of the middle of the cell */
-    mid_x = D_x + (int)(D_ew * 0.5);
-    mid_y = D_y + (int)(D_ns * 0.5);
-
-    /* head */
-    x = mid_x + (int)(max_radius * cos(D2R(theta)));
-    y = mid_y + (int)(max_radius * sin(D2R(theta)));
-    R_move_abs(x, y);
-
-    /* tail */
-    dx = -2 * (int)(max_radius * cos(D2R(theta)));
-    dy = -2 * (int)(max_radius * sin(D2R(theta)));
-    R_cont_rel(dx, dy);
-
-    /* fin 1 */
-    R_move_abs(x, y);
-    theta_offset = theta + 90;
-    dx = mid_x + (int)(0.5 * max_radius * cos(D2R(theta_offset)));
-    dy = mid_y + (int)(0.5 * max_radius * sin(D2R(theta_offset)));
-    R_cont_abs(dx, dy);
-
-    /* fin 2 */
-    R_move_abs(x, y);
-    theta_offset = theta - 90;
-    dx = mid_x + (int)(0.5 * max_radius * cos(D2R(theta_offset)));
-    dy = mid_y + (int)(0.5 * max_radius * sin(D2R(theta_offset)));
-    R_cont_abs(dx, dy);
-
-}
-
-static void arrow_se(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .8);
-    y = D_y + (int)(D_ns * .8);
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.6)), ((int)(D_ns * (-.6))));
-    R_move_abs(x, y);
-    R_cont_rel(0, (int)(D_ns * (-.4)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.4)), 0);
-
-}
-
-static void arrow_ne(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .8);
-    y = D_y + (int)(D_ns * .2);
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.6)), ((int)(D_ns * (.6))));
-    R_move_abs(x, y);
-    R_cont_rel(0, (int)(D_ns * (.4)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.4)), 0);
-
-}
-
-static void arrow_nw(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .2);
-    y = D_y + (int)(D_ns * .2);
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.6)), ((int)(D_ns * (.6))));
-    R_move_abs(x, y);
-    R_cont_rel(0, (int)(D_ns * (.4)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.4)), 0);
-
-}
-
-static void arrow_sw(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .2);
-    y = D_y + (int)(D_ns * .8);
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.6)), ((int)(D_ns * (-.6))));
-    R_move_abs(x, y);
-    R_cont_rel(0, (int)(D_ns * (-.4)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.4)), 0);
-
-}
-static void arrow_e(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .9);
-    y = D_y + (int)(D_ns * .5);
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.8)), 0);
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.3)), (int)(D_ns * (-.3)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.3)), (int)(D_ns * (.3)));
-
-}
-static void arrow_w(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .1);
-    y = D_y + (int)(D_ns * .5);
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.8)), 0);
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.3)), (int)(D_ns * (-.3)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.3)), (int)(D_ns * (.3)));
-
-}
-static void arrow_s(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .5);
-    y = D_y + (int)(D_ns * .9);
-    R_move_abs(x, y);
-    R_cont_rel(0, (int)(D_ns * (-.8)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.3)), (int)(D_ns * (-.3)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.3)), (int)(D_ns * (-.3)));
-
-}
-static void arrow_n(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .5);
-    y = D_y + (int)(D_ns * .1);
-    R_move_abs(x, y);
-    R_cont_rel(0, (int)(D_ns * (.8)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (.3)), (int)(D_ns * (.3)));
-    R_move_abs(x, y);
-    R_cont_rel((int)(D_ew * (-.3)), (int)(D_ns * (.3)));
-
-}
-static void draw_x(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x;
-    y = D_y;
-    R_move_abs(x, y);
-    R_cont_rel((int)D_ew, (int)D_ns);
-    y = D_y + (int)D_ns;
-    R_move_abs(x, y);
-    R_cont_rel((int)D_ew, (int)(D_ns * -1));
-}
-static void unknown_(void)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int x, y;
-
-    x = D_x + (int)(D_ew * .3);
-    y = D_y + (int)(D_ns * .4);
-    R_move_abs(x, y);
-    R_cont_rel(0, (int)(D_ns * (-.15)));
-    R_cont_rel((int)(D_ew * (.1)), (int)(D_ns * (-.1)));
-    R_cont_rel((int)(D_ew * (.2)), 0);
-    R_cont_rel((int)(D_ew * (.1)), (int)(D_ns * (.1)));
-    R_cont_rel(0, (int)(D_ns * (.2)));
-    R_cont_rel((int)(D_ew * (-.1)), (int)(D_ns * (.1)));
-    R_cont_rel((int)(D_ew * (-.1)), 0);
-    R_cont_rel(0, (int)(D_ns * (.25)));
-    R_move_rel(0, (int)(D_ns * (.1)));
-    R_cont_rel(0, (int)(D_ns * (.1)));
-}

Copied: grass/trunk/display/d.rast.arrow/main.c (from rev 32801, grass/trunk/display/d.rast.arrow/arrow.c)
===================================================================
--- grass/trunk/display/d.rast.arrow/main.c	                        (rev 0)
+++ grass/trunk/display/d.rast.arrow/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,819 @@
+/*
+ ****************************************************************************
+ *
+ * MODULE:       d.rast.arrow
+ * AUTHOR(S):    Chris Rewerts, Agricultural Engineering, Purdue University
+ * PURPOSE:      Draw arrows on slope/aspect maps. 
+ * COPYRIGHT:    (C) 2000 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.
+ *
+ *****************************************************************************/
+
+/* some minor cleanup done by Andreas Lange, andreas.lange at rhein-main.de
+ * Update to handle NULLs and floating point aspect maps: Hamish Bowman, Aug 2004
+ * Update for 360 degree arrows and magnitude scaling:  Hamish Bowman, Oct 2005
+ */
+
+/*
+ *   Chris Rewerts, Agricultural Engineering, Purdue University
+ *   rewerts at ecn.purdue.edu  March 1991
+ *
+ *   d.rast.arrow
+ *
+ *   Usage:  d.rast.arrow
+ * 
+ *   This program used Dgrid's sources as a beginning. Purpose of Darrow
+ *   is to read an aspect layer produced by slope.aspect or by the 
+ *   programs created for the ANSWERS or AGNPS Hydrology Toolbox
+ *   endeavors.  d.rast.arrow draws an arrow on the graphic display
+ *   of each cell, so that the flow pattern computed as an aspect
+ *   layer can be easily seen. Other symbols ("?", "X") may be drawn
+ *   as needed.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/display.h>
+#include <grass/colors.h>
+#include <grass/glocale.h>
+
+# define RpD ((2 * M_PI) / 360.)	/* radians/degree */
+# define D2R(d) (double)(d * RpD)	/* degrees->radians */
+
+static void arrow_mag(double, double);
+static void arrow_360(double);
+static void arrow_se(void);
+static void arrow_ne(void);
+static void arrow_nw(void);
+static void arrow_sw(void);
+static void arrow_e(void);
+static void arrow_w(void);
+static void arrow_s(void);
+static void arrow_n(void);
+static void draw_x(void);
+static void unknown_(void);
+
+int D_x, D_y;
+double D_ew, D_ns;
+char *mapset;
+char layer_name[128];
+int map_type, arrow_color, grid_color, x_color, unknown_color;
+
+
+int main(int argc, char **argv)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    struct Cell_head window;
+    double t, b, l, r;
+    RASTER_MAP_TYPE raster_type, mag_raster_type = -1;
+    int layer_fd;
+    void *raster_row, *ptr;
+    int nrows, ncols, row, col;
+    int aspect_c = -1;
+    float aspect_f = -1.0;
+    double ew_res, ns_res;
+    double D_south, D_west;
+    double D_north, D_east;
+    double U_to_D_xconv, U_to_D_yconv;
+    double U_west, U_south;
+    double U_east, U_north;
+    double U_start;
+    double U_x, U_y;
+
+    double scale;
+    int skip, no_arrow;
+    char *mag_map = NULL, *mag_mapset = NULL;
+    void *mag_raster_row = NULL, *mag_ptr = NULL;
+    double length = -1;
+    int mag_fd = -1;
+    struct FPRange range;
+    double mag_min, mag_max;
+
+    struct GModule *module;
+    struct Option *opt1, *opt2, *opt3, *opt4, *opt5,
+	*opt6, *opt7, *opt8, *opt9;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("display");
+    module->description =
+	_("Draws arrows representing cell aspect direction "
+	  "for a raster map containing aspect data.");
+
+    opt1 = G_define_option();
+    opt1->key = "map";
+    opt1->type = TYPE_STRING;
+    opt1->required = YES;
+    opt1->multiple = NO;
+    opt1->gisprompt = "old,cell,raster";
+    opt1->description = _("Name of raster aspect map to be displayed");
+
+    opt2 = G_define_option();
+    opt2->key = "type";
+    opt2->type = TYPE_STRING;
+    opt2->required = NO;
+    opt2->answer = "grass";
+    opt2->options = "grass,compass,agnps,answers";
+    opt2->description = _("Type of existing raster aspect map");
+
+    opt3 = G_define_option();
+    opt3->key = "arrow_color";
+    opt3->type = TYPE_STRING;
+    opt3->required = NO;
+    opt3->answer = "green";
+    opt3->options = D_COLOR_LIST;
+    opt3->description = _("Color for drawing arrows");
+
+    opt4 = G_define_option();
+    opt4->key = "grid_color";
+    opt4->type = TYPE_STRING;
+    opt4->required = NO;
+    opt4->answer = "gray";
+    opt4->options = D_COLOR_LIST ",none";
+    opt4->description = _("Color for drawing grid or \"none\"");
+
+    opt5 = G_define_option();
+    opt5->key = "x_color";
+    opt5->type = TYPE_STRING;
+    opt5->required = NO;
+    opt5->answer = DEFAULT_FG_COLOR;
+    opt5->options = D_COLOR_LIST;
+    opt5->description = _("Color for drawing X's (Null values)");
+
+    opt6 = G_define_option();
+    opt6->key = "unknown_color";
+    opt6->type = TYPE_STRING;
+    opt6->required = NO;
+    opt6->answer = "red";
+    opt6->options = D_COLOR_LIST;
+    opt6->description = _("Color for showing unknown information");
+
+    opt9 = G_define_option();
+    opt9->key = "skip";
+    opt9->type = TYPE_INTEGER;
+    opt9->required = NO;
+    opt9->answer = "1";
+    opt9->description = _("Draw arrow every Nth grid cell");
+
+    opt7 = G_define_option();
+    opt7->key = "magnitude_map";
+    opt7->type = TYPE_STRING;
+    opt7->required = NO;
+    opt7->multiple = NO;
+    opt7->gisprompt = "old,cell,raster";
+    opt7->description =
+	_("Raster map containing values used for arrow length");
+
+    opt8 = G_define_option();
+    opt8->key = "scale";
+    opt8->type = TYPE_DOUBLE;
+    opt8->required = NO;
+    opt8->answer = "1.0";
+    opt8->description = _("Scale factor for arrows (magnitude map)");
+
+
+    /* Check command line */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
+    strncpy(layer_name, opt1->answer, sizeof(layer_name) - 1);
+    if ((mapset = G_find_cell2(layer_name, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), layer_name);
+
+    arrow_color = D_translate_color(opt3->answer);
+    x_color = D_translate_color(opt5->answer);
+    unknown_color = D_translate_color(opt6->answer);
+
+    if (strcmp("none", opt4->answer) == 0)
+	grid_color = -1;
+    else
+	grid_color = D_translate_color(opt4->answer);
+
+
+    if (strcmp("grass", opt2->answer) == 0)
+	map_type = 1;
+    else if (strcmp("agnps", opt2->answer) == 0)
+	map_type = 2;
+    else if (strcmp("answers", opt2->answer) == 0)
+	map_type = 3;
+    else if (strcmp("compass", opt2->answer) == 0)
+	map_type = 4;
+
+
+    scale = atof(opt8->answer);
+    if (scale <= 0.0)
+	G_fatal_error(_("Illegal value for scale factor"));
+
+    skip = atoi(opt9->answer);
+    if (skip <= 0)
+	G_fatal_error(_("Illegal value for skip factor"));
+
+
+    if (opt7->answer) {
+	if (map_type != 1 && map_type != 4)
+	    G_fatal_error(_("Magnitude is only supported for GRASS and compass aspect maps."));
+
+	mag_map = opt7->answer;
+	if ((mag_mapset = G_find_cell2(mag_map, "")) == NULL)
+	    G_fatal_error(_("Raster map <%s> not found"), mag_map);
+    }
+    else if (scale != 1.0)
+	G_warning(_("Scale option requires magnitude_map"));
+
+
+    /* Setup driver and check important information */
+    if (R_open_driver() != 0)
+	G_fatal_error(_("No graphics device selected"));
+
+    /* Read in the map window associated with window */
+    G_get_window(&window);
+
+    D_check_map_window(&window);
+
+    if (G_set_window(&window) == -1)
+	G_fatal_error(_("Current window not settable"));
+
+    /* Determine conversion factors */
+    if (D_get_screen_window(&t, &b, &l, &r))
+	G_fatal_error(_("Getting screen window"));
+    if (D_do_conversions(&window, t, b, l, r))
+	G_fatal_error(_("Error in calculating conversions"));
+
+    /* where are we, both geographically and on the screen? */
+    D_south = D_get_d_south();
+    D_north = D_get_d_north();
+    D_east = D_get_d_east();
+    D_west = D_get_d_west();
+
+    U_west = D_get_u_west();
+    U_east = D_get_u_east();
+    U_south = D_get_u_south();
+    U_north = D_get_u_north();
+
+    U_to_D_xconv = D_get_u_to_d_xconv();
+    U_to_D_yconv = D_get_u_to_d_yconv();
+
+    /* number of rows and cols in window */
+    nrows = window.rows;
+    ncols = window.cols;
+
+    /*
+       if ((nrows > 75) || (ncols > 75)){ 
+       fprintf (stdout,"\n"); 
+       fprintf (stdout,"Current window size:\n"); 
+       fprintf (stdout,"rows:    %d\n", nrows);
+       fprintf (stdout,"columns: %d\n", ncols);
+       fprintf (stdout,"\n"); 
+       fprintf (stdout,"Your current window setting may be too large.\n"); 
+       fprintf (stdout,"Cells displayed on your graphics window may be too\n"); 
+       fprintf (stdout,"small for arrows to be visible.\n\n"); 
+       if (!G_yes("Do you wish to continue", 0))
+       exit(0);
+       }
+     */
+
+    /* resolutions */
+    ew_res = window.ew_res;
+    ns_res = window.ns_res;
+
+    /* how many screen units of distance for each cell */
+    D_ew = (D_east - D_west) / ncols;
+    D_ns = (D_south - D_north) / nrows;
+
+    /* figure out arrow scaling if using a magnitude map */
+    if (opt7->answer) {
+	G_init_fp_range(&range);	/* really needed? */
+	if (G_read_fp_range(mag_map, mag_mapset, &range) != 1)
+	    G_fatal_error(_("Problem reading range file"));
+	G_get_fp_range_min_max(&range, &mag_min, &mag_max);
+
+	scale *= 1.5 * ((D_ew < D_ns) ? D_ew : D_ns) / fabs(mag_max);
+	G_debug(3, "scaling=%.2f  rast_max=%.2f  D_ew=%.2f", scale, mag_max,
+		D_ew);
+    }
+
+/*------------------------------------------
+    fprintf (stdout,"ew_res:  %.2f\n", window.ew_res);
+    fprintf (stdout,"ns_res:  %.2f\n", window.ns_res);
+    fprintf (stdout,"D_ew:  %f D_ns:  %f \n", D_ew, D_ns); 
+    fprintf (stdout,"nrows:    %d\n", nrows);
+    fprintf (stdout,"ncols:    %d\n", ncols);
+    fprintf (stdout,"t:  %d\n", t);
+    fprintf (stdout,"b:  %d\n", b);
+    fprintf (stdout,"l:  %d\n", l);
+    fprintf (stdout,"r:  %d\n", r);
+    fprintf (stdout,"U_west:	%f\n", U_west);
+    fprintf (stdout,"U_east:	%f\n", U_east);
+    fprintf (stdout,"U_south:	%f\n", U_south);
+    fprintf (stdout,"U_north:	%f\n", U_north);
+    fprintf (stdout,"D_west:	%f\n", D_west);
+    fprintf (stdout,"D_east:	%f\n", D_east);
+    fprintf (stdout,"D_south:	%f\n", D_south);
+    fprintf (stdout,"D_north:	%f\n", D_north);
+    fprintf (stdout,"U_to_D_xconv:	%f\n", U_to_D_xconv);
+    fprintf (stdout,"U_to_D_yconv:	%f\n", U_to_D_yconv);
+--------------------------------------------------------*/
+
+    if (grid_color > 0) {	/* ie not "none" */
+	/* Set color */
+	R_standard_color(grid_color);
+
+	/* Draw vertical grids */
+	U_start = U_east;
+	for (U_x = U_start; U_x >= U_west; U_x -= ew_res) {
+	    D_x = (int)((U_x - U_west) * U_to_D_xconv + D_west);
+	    R_move_abs(D_x, (int)D_south);
+	    R_cont_abs(D_x, (int)D_north);
+	}
+
+	/* Draw horizontal grids */
+	U_start = U_north;
+	for (U_y = U_start; U_y >= U_south; U_y -= ns_res) {
+	    D_y = (int)((U_south - U_y) * U_to_D_yconv + D_south);
+	    R_move_abs((int)D_west, D_y);
+	    R_cont_abs((int)D_east, D_y);
+	}
+    }
+
+    /* open the raster map */
+    layer_fd = G_open_cell_old(layer_name, mapset);
+    if (layer_fd < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), layer_name);
+
+    raster_type = G_get_raster_map_type(layer_fd);
+
+    /* allocate the cell array */
+    raster_row = G_allocate_raster_buf(raster_type);
+
+
+    if (opt7->answer) {
+	/* open the magnitude raster map */
+	mag_fd = G_open_cell_old(mag_map, mag_mapset);
+	if (mag_fd < 0)
+	    G_fatal_error("Unable to open raster map <%s>", mag_map);
+
+	mag_raster_type = G_get_raster_map_type(mag_fd);
+
+	/* allocate the cell array */
+	mag_raster_row = G_allocate_raster_buf(mag_raster_type);
+    }
+
+
+    /* loop through cells, find value, determine direction (n,s,e,w,ne,se,sw,nw),
+       and call appropriate function to draw an arrow on the cell */
+
+    for (row = 0; row < nrows; row++) {
+	G_get_raster_row(layer_fd, raster_row, row, raster_type);
+	ptr = raster_row;
+
+	if (opt7->answer) {
+	    G_get_raster_row(mag_fd, mag_raster_row, row, mag_raster_type);
+	    mag_ptr = mag_raster_row;
+	}
+
+	/* determine screen y coordinate of top of current cell */
+	D_y = (int)(row * D_ns + D_north);
+
+	for (col = 0; col < ncols; col++) {
+
+	    if (row % skip != 0)
+		no_arrow = TRUE;
+	    else
+		no_arrow = FALSE;
+
+	    if (col % skip != 0)
+		no_arrow = TRUE;
+
+	    /* determine screen x coordinate of west side of current cell */
+	    D_x = (int)(col * D_ew + D_west);
+
+	    /* find aspect direction based on cell value */
+	    if (raster_type == CELL_TYPE)
+		aspect_f = *((CELL *) ptr);
+	    else if (raster_type == FCELL_TYPE)
+		aspect_f = *((FCELL *) ptr);
+	    else if (raster_type == DCELL_TYPE)
+		aspect_f = *((DCELL *) ptr);
+
+
+	    if (opt7->answer) {
+
+		if (mag_raster_type == CELL_TYPE)
+		    length = *((CELL *) mag_ptr);
+		else if (mag_raster_type == FCELL_TYPE)
+		    length = *((FCELL *) mag_ptr);
+		else if (mag_raster_type == DCELL_TYPE)
+		    length = *((DCELL *) mag_ptr);
+
+		length *= scale;
+
+		if (G_is_null_value(mag_ptr, mag_raster_type)) {
+		    G_debug(5, "Invalid arrow length [NULL]. Skipping.");
+		    no_arrow = TRUE;
+		}
+		else if (length <= 0.0) {	/* use fabs() or theta+=180? */
+		    G_debug(5, "Illegal arrow length [%.3f]. Skipping.",
+			    length);
+		    no_arrow = TRUE;
+		}
+	    }
+
+	    if (no_arrow) {
+		ptr = G_incr_void_ptr(ptr, G_raster_size(raster_type));
+		if (opt7->answer)
+		    mag_ptr =
+			G_incr_void_ptr(mag_ptr,
+					G_raster_size(mag_raster_type));
+		no_arrow = FALSE;
+		continue;
+	    }
+
+	    /* treat AGNPS and ANSWERS data like old zero-as-null CELL */
+	    /*   TODO: update models */
+	    if (map_type == 2 || map_type == 3) {
+		if (G_is_null_value(ptr, raster_type))
+		    aspect_c = 0;
+		else
+		    aspect_c = (int)(aspect_f + 0.5);
+	    }
+
+
+	    /** Now draw the arrows **/
+
+	    /* case switch for standard GRASS aspect map 
+	       measured in degrees counter-clockwise from east */
+	    if (map_type == 1) {
+		R_standard_color(arrow_color);
+
+		if (G_is_null_value(ptr, raster_type)) {
+		    R_standard_color(x_color);
+		    draw_x();
+		    R_standard_color(arrow_color);
+		}
+		else if (aspect_f >= 0.0 && aspect_f <= 360.0) {
+		    if (opt7->answer)
+			arrow_mag(aspect_f, length);
+		    else
+			arrow_360(aspect_f);
+		}
+		else {
+		    R_standard_color(unknown_color);
+		    unknown_();
+		    R_standard_color(arrow_color);
+		}
+	    }
+
+
+	    /* case switch for AGNPS type aspect map */
+	    else if (map_type == 2) {
+		R_standard_color(arrow_color);
+		switch (aspect_c) {
+		case 0:
+		    R_standard_color(x_color);
+		    draw_x();
+		    R_standard_color(arrow_color);
+		    break;
+		case 1:
+		    arrow_n();
+		    break;
+		case 2:
+		    arrow_ne();
+		    break;
+		case 3:
+		    arrow_e();
+		    break;
+		case 4:
+		    arrow_se();
+		    break;
+		case 5:
+		    arrow_s();
+		    break;
+		case 6:
+		    arrow_sw();
+		    break;
+		case 7:
+		    arrow_w();
+		    break;
+		case 8:
+		    arrow_nw();
+		    break;
+		default:
+		    R_standard_color(unknown_color);
+		    unknown_();
+		    R_standard_color(arrow_color);
+		    break;
+		}
+	    }
+
+
+	    /* case switch for ANSWERS type aspect map */
+	    else if (map_type == 3) {
+		R_standard_color(arrow_color);
+		if (aspect_c >= 15 && aspect_c <= 360)	/* start at zero? */
+		    arrow_360((double)aspect_c);
+		else if (aspect_c == 400) {
+		    R_standard_color(unknown_color);
+		    unknown_();
+		    R_standard_color(arrow_color);
+		}
+		else {
+		    R_standard_color(x_color);
+		    draw_x();
+		    R_standard_color(arrow_color);
+		}
+	    }
+
+	    /* case switch for compass type aspect map
+	       measured in degrees clockwise from north */
+	    else if (map_type == 4) {
+		R_standard_color(arrow_color);
+
+		if (G_is_null_value(ptr, raster_type)) {
+		    R_standard_color(x_color);
+		    draw_x();
+		    R_standard_color(arrow_color);
+		}
+		else if (aspect_f >= 0.0 && aspect_f <= 360.0) {
+		    if (opt7->answer)
+			arrow_mag(90 - aspect_f, length);
+		    else
+			arrow_360(90 - aspect_f);
+		}
+		else {
+		    R_standard_color(unknown_color);
+		    unknown_();
+		    R_standard_color(arrow_color);
+		}
+	    }
+
+	    ptr = G_incr_void_ptr(ptr, G_raster_size(raster_type));
+	    if (opt7->answer)
+		mag_ptr =
+		    G_incr_void_ptr(mag_ptr, G_raster_size(mag_raster_type));
+	}
+    }
+
+    G_close_cell(layer_fd);
+    if (opt7->answer)
+	G_close_cell(mag_fd);
+
+    R_close_driver();
+
+    exit(0);
+}
+
+/* --- end of main --- */
+
+/*---------------------------------------------------------------*/
+
+
+static void arrow_mag(double theta, double length)
+{				/* angle is measured in degrees counter-clockwise from east */
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y, dx, dy, mid_x, mid_y;
+    double theta_offset;
+
+    theta *= -1;		/* display coords use inverse y */
+
+    /* find the display coordinates of the middle of the cell */
+    mid_x = D_x + (int)(D_ew * .5);
+    mid_y = D_y + (int)(D_ns * .5);
+
+    /* tail */
+    R_move_abs(mid_x, mid_y);
+
+    /* head */
+    x = mid_x + (int)(length * cos(D2R(theta)));
+    y = mid_y + (int)(length * sin(D2R(theta)));
+    R_cont_abs(x, y);
+
+    /* fin 1 */
+    theta_offset = theta + 20;
+    dx = mid_x + (int)(0.6 * length * cos(D2R(theta_offset)));
+    dy = mid_y + (int)(0.6 * length * sin(D2R(theta_offset)));
+    R_cont_abs(dx, dy);
+
+    /* fin 2 */
+    R_move_abs(x, y);
+    theta_offset = theta - 20;
+    dx = mid_x + (int)(0.6 * length * cos(D2R(theta_offset)));
+    dy = mid_y + (int)(0.6 * length * sin(D2R(theta_offset)));
+    R_cont_abs(dx, dy);
+}
+
+
+static void arrow_360(double theta)
+{				/* angle is measured in degrees counter-clockwise from east */
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y, dx, dy, mid_x, mid_y;
+    double max_radius, theta_offset;
+
+    theta *= -1;		/* display coords use inverse y */
+    max_radius = ((D_ew < D_ns) ? D_ew : D_ns) * 0.8 / 2;
+
+    /* find the display coordinates of the middle of the cell */
+    mid_x = D_x + (int)(D_ew * 0.5);
+    mid_y = D_y + (int)(D_ns * 0.5);
+
+    /* head */
+    x = mid_x + (int)(max_radius * cos(D2R(theta)));
+    y = mid_y + (int)(max_radius * sin(D2R(theta)));
+    R_move_abs(x, y);
+
+    /* tail */
+    dx = -2 * (int)(max_radius * cos(D2R(theta)));
+    dy = -2 * (int)(max_radius * sin(D2R(theta)));
+    R_cont_rel(dx, dy);
+
+    /* fin 1 */
+    R_move_abs(x, y);
+    theta_offset = theta + 90;
+    dx = mid_x + (int)(0.5 * max_radius * cos(D2R(theta_offset)));
+    dy = mid_y + (int)(0.5 * max_radius * sin(D2R(theta_offset)));
+    R_cont_abs(dx, dy);
+
+    /* fin 2 */
+    R_move_abs(x, y);
+    theta_offset = theta - 90;
+    dx = mid_x + (int)(0.5 * max_radius * cos(D2R(theta_offset)));
+    dy = mid_y + (int)(0.5 * max_radius * sin(D2R(theta_offset)));
+    R_cont_abs(dx, dy);
+
+}
+
+static void arrow_se(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .8);
+    y = D_y + (int)(D_ns * .8);
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.6)), ((int)(D_ns * (-.6))));
+    R_move_abs(x, y);
+    R_cont_rel(0, (int)(D_ns * (-.4)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.4)), 0);
+
+}
+
+static void arrow_ne(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .8);
+    y = D_y + (int)(D_ns * .2);
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.6)), ((int)(D_ns * (.6))));
+    R_move_abs(x, y);
+    R_cont_rel(0, (int)(D_ns * (.4)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.4)), 0);
+
+}
+
+static void arrow_nw(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .2);
+    y = D_y + (int)(D_ns * .2);
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.6)), ((int)(D_ns * (.6))));
+    R_move_abs(x, y);
+    R_cont_rel(0, (int)(D_ns * (.4)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.4)), 0);
+
+}
+
+static void arrow_sw(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .2);
+    y = D_y + (int)(D_ns * .8);
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.6)), ((int)(D_ns * (-.6))));
+    R_move_abs(x, y);
+    R_cont_rel(0, (int)(D_ns * (-.4)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.4)), 0);
+
+}
+static void arrow_e(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .9);
+    y = D_y + (int)(D_ns * .5);
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.8)), 0);
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.3)), (int)(D_ns * (-.3)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.3)), (int)(D_ns * (.3)));
+
+}
+static void arrow_w(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .1);
+    y = D_y + (int)(D_ns * .5);
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.8)), 0);
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.3)), (int)(D_ns * (-.3)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.3)), (int)(D_ns * (.3)));
+
+}
+static void arrow_s(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .5);
+    y = D_y + (int)(D_ns * .9);
+    R_move_abs(x, y);
+    R_cont_rel(0, (int)(D_ns * (-.8)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.3)), (int)(D_ns * (-.3)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.3)), (int)(D_ns * (-.3)));
+
+}
+static void arrow_n(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .5);
+    y = D_y + (int)(D_ns * .1);
+    R_move_abs(x, y);
+    R_cont_rel(0, (int)(D_ns * (.8)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (.3)), (int)(D_ns * (.3)));
+    R_move_abs(x, y);
+    R_cont_rel((int)(D_ew * (-.3)), (int)(D_ns * (.3)));
+
+}
+static void draw_x(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x;
+    y = D_y;
+    R_move_abs(x, y);
+    R_cont_rel((int)D_ew, (int)D_ns);
+    y = D_y + (int)D_ns;
+    R_move_abs(x, y);
+    R_cont_rel((int)D_ew, (int)(D_ns * -1));
+}
+static void unknown_(void)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int x, y;
+
+    x = D_x + (int)(D_ew * .3);
+    y = D_y + (int)(D_ns * .4);
+    R_move_abs(x, y);
+    R_cont_rel(0, (int)(D_ns * (-.15)));
+    R_cont_rel((int)(D_ew * (.1)), (int)(D_ns * (-.1)));
+    R_cont_rel((int)(D_ew * (.2)), 0);
+    R_cont_rel((int)(D_ew * (.1)), (int)(D_ns * (.1)));
+    R_cont_rel(0, (int)(D_ns * (.2)));
+    R_cont_rel((int)(D_ew * (-.1)), (int)(D_ns * (.1)));
+    R_cont_rel((int)(D_ew * (-.1)), 0);
+    R_cont_rel(0, (int)(D_ns * (.25)));
+    R_move_rel(0, (int)(D_ns * (.1)));
+    R_cont_rel(0, (int)(D_ns * (.1)));
+}

Copied: grass/trunk/display/d.rast.num/main.c (from rev 32801, grass/trunk/display/d.rast.num/number.c)
===================================================================
--- grass/trunk/display/d.rast.num/main.c	                        (rev 0)
+++ grass/trunk/display/d.rast.num/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,349 @@
+/*
+ ****************************************************************************
+ *
+ * MODULE:       d.rast.num
+ * AUTHOR(S):    Raghavan Srinivasan, Agricultural Engineering, Purdue University
+ * PURPOSE:      Print numbers of category for raster cells
+ * COPYRIGHT:    (C) 2000 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.
+ *
+ *****************************************************************************/
+
+/* updated by Andreas Lange, andreas.lange at rhein-main.de 
+ * for text color support.
+ * updated 2004 my MN for FP support
+ */
+
+/*
+ *   Raghavan Srinivasan, Agricultural Engineering, Purdue University
+ *   srin at ecn.purdue.edu  March 1991
+ *
+ *   d.rast.num
+ *
+ *   Usage:  d.rast.num
+ * 
+ *   This program used Dgrid's sources as a beginning. Purpose of Dnumber
+ *   is to read the cell layer displayed on the graphics monitor and number
+ *   them, if the cell value is other than 0 in an acending order.
+ *   d.rast.num draws a number on the graphic display
+ *   of each cell, so the cell number could be identified when using hydrologic
+ *   models such AGNPS which uses the cell number for all its correspondance.
+ *   
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/display.h>
+#include <grass/colors.h>
+#include <grass/glocale.h>
+
+int draw_number(double, int, RASTER_MAP_TYPE);
+
+int D_x, D_y;
+double D_ew, D_ns;
+
+int main(int argc, char **argv)
+{
+    DCELL *cell;
+    char *mapset;
+    char full_name[128];
+    double D_north, D_east;
+    double D_south, D_west;
+    double U_east, U_north;
+    double U_start;
+    double U_to_D_xconv, U_to_D_yconv;
+    double U_west, U_south;
+    double U_x, U_y;
+    double ew_res, ns_res;
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int fixed_color, grid_color;
+    int R, G, B;
+    int layer_fd;
+    int nrows, ncols, row, col;
+    double t, b, l, r;
+    int digits;
+    struct Cell_head window;
+    struct Colors colors;
+    struct GModule *module;
+    struct Option *opt1, *opt2, *opt3, *prec;
+    struct Flag *text_color;
+    RASTER_MAP_TYPE map_type, inmap_type;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("display");
+    module->description =
+	_("Overlays cell category values on a raster map layer "
+	  "displayed to the graphics monitor.");
+
+    opt1 = G_define_standard_option(G_OPT_R_MAP);
+
+    opt2 = G_define_option();
+    opt2->key = "grid_color";
+    opt2->type = TYPE_STRING;
+    opt2->required = NO;
+    opt2->answer = "gray";
+    opt2->options = D_COLOR_LIST ",none";
+    opt2->key_desc = "color";
+    opt2->description = _("Color for drawing grid, or \"none\"");
+
+    opt3 = G_define_option();
+    opt3->key = "text_color";
+    opt3->type = TYPE_STRING;
+    opt3->required = NO;
+    opt3->answer = DEFAULT_FG_COLOR;
+    opt3->options = D_COLOR_LIST;
+    opt3->key_desc = "color";
+    opt3->description = _("Color for drawing text");
+
+    prec = G_define_option();
+    prec->key = "dp";
+    prec->type = TYPE_INTEGER;
+    prec->required = NO;
+    prec->answer = "1";
+    prec->options = "0,1,2,3,4,5,6,7,8,9";
+    prec->description =
+	_("Number of significant digits (floating point only)");
+
+    text_color = G_define_flag();
+    text_color->key = 'f';
+    text_color->description = _("Get text color from cell color value");
+
+    /* Check command line */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    if (R_open_driver() != 0)
+	G_fatal_error(_("No graphics device selected"));
+
+    strcpy(full_name, opt1->answer);
+
+    if (strcmp("none", opt2->answer) == 0)
+	grid_color = -1;
+    else
+	grid_color = D_translate_color(opt2->answer);
+
+    if (text_color->answer)
+	fixed_color = 0;
+    else
+	fixed_color = 1;
+
+    mapset = G_find_cell(full_name, "");
+    if (mapset == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), full_name);
+
+    layer_fd = G_open_cell_old(full_name, mapset);
+    if (layer_fd < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), full_name);
+
+    /* determine the inputmap type (CELL/FCELL/DCELL) */
+    inmap_type = G_get_raster_map_type(layer_fd);
+    map_type = DCELL_TYPE;
+
+    /* Setup driver and check important information */
+
+    /* Read in the map window associated with window */
+
+    G_get_window(&window);
+
+    D_check_map_window(&window);
+
+    if (G_set_window(&window) == -1)
+	G_fatal_error(_("Current window not settable"));
+
+    /* Determine conversion factors */
+
+    if (D_get_screen_window(&t, &b, &l, &r))
+	G_fatal_error(_("Getting screen window"));
+    if (D_do_conversions(&window, t, b, l, r))
+	G_fatal_error(_("Error in calculating conversions"));
+
+    /* where are we, both geographically and on the screen? */
+
+    D_south = D_get_d_south();
+    D_north = D_get_d_north();
+    D_east = D_get_d_east();
+    D_west = D_get_d_west();
+
+    U_west = D_get_u_west();
+    U_east = D_get_u_east();
+    U_south = D_get_u_south();
+    U_north = D_get_u_north();
+
+    U_to_D_xconv = D_get_u_to_d_xconv();
+    U_to_D_yconv = D_get_u_to_d_yconv();
+
+    /* number of rows and cols in window */
+
+    nrows = window.rows;
+    ncols = window.cols;
+
+    if ((nrows > 75) || (ncols > 75)) {
+	G_warning("!!!");
+	G_message(_("Current window size:"));
+	G_message(_("rows:    %d"), nrows);
+	G_message(_("columns: %d"), ncols);
+
+	G_message(_("\nYour current window setting may be too large."
+		    " Cells displayed on your graphics window may be too"
+		    " small for cell category number to be visible."));
+	G_message(" ");
+    }
+    if ((nrows > 200) || (ncols > 200)) {
+	G_fatal_error(_("Aborting."));
+    }
+
+    /* resolutions */
+    ew_res = window.ew_res;
+    ns_res = window.ns_res;
+
+    /* how many screen units of distance for each cell */
+    D_ew = (D_east - D_west) / ncols;
+    D_ns = (D_south - D_north) / nrows;
+
+    /*set the number of significant digits */
+    sscanf(prec->answer, "%i", &digits);
+
+	/*-- DEBUG ----------------------------------------
+	fprintf (stdout,"ew_res:  %.2f\n", window.ew_res);
+	fprintf (stdout,"ns_res:  %.2f\n", window.ns_res);
+	fprintf (stdout,"D_ew:  %f D_ns:  %f \n", D_ew, D_ns); 
+	fprintf (stdout,"nrows:    %d\n", nrows);
+	fprintf (stdout,"ncols:    %d\n", ncols);
+	fprintf (stdout,"t:  %d\n", t);
+	fprintf (stdout,"b:  %d\n", b);
+	fprintf (stdout,"l:  %d\n", l);
+	fprintf (stdout,"r:  %d\n", r);
+	fprintf (stdout,"U_west:    %f\n", U_west);
+	fprintf (stdout,"U_east:    %f\n", U_east);
+	fprintf (stdout,"U_south:   %f\n", U_south);
+	fprintf (stdout,"U_north:   %f\n", U_north);
+	fprintf (stdout,"D_west:    %f\n", D_west);
+	fprintf (stdout,"D_east:    %f\n", D_east);
+	fprintf (stdout,"D_south:   %f\n", D_south);
+	fprintf (stdout,"D_north:   %f\n", D_north);
+	fprintf (stdout,"U_to_D_xconv:      %f\n", U_to_D_xconv);
+	fprintf (stdout,"U_to_D_yconv:      %f\n", U_to_D_yconv);
+	--------------------------------------------------------*/
+
+    if (grid_color > 0) {	/* ie not "none" */
+	/* Set grid color */
+	R_standard_color(grid_color);
+
+	/* Draw vertical grids */
+	U_start = U_east;
+	for (U_x = U_start; U_x >= U_west; U_x -= ew_res) {
+	    D_x = (U_x - U_west) * U_to_D_xconv + D_west;
+	    R_move_abs(D_x, D_south);
+	    R_cont_abs(D_x, D_north);
+	}
+
+	/* Draw horizontal grids */
+	U_start = U_north;
+	for (U_y = U_start; U_y >= U_south; U_y -= ns_res) {
+	    D_y = (U_south - U_y) * U_to_D_yconv + D_south;
+	    R_move_abs(D_west, D_y);
+	    R_cont_abs(D_east, D_y);
+	}
+    }
+
+    /* allocate the cell array */
+    cell = G_allocate_raster_buf(map_type);
+
+    /* read the color table in the color structures of the displayed map */
+    if (G_read_colors(full_name, mapset, &colors) == -1)
+	G_fatal_error(_("Color file for <%s> not available"), full_name);
+
+    /* fixed text color */
+    if (fixed_color == 1)
+	R_standard_color(D_translate_color(opt3->answer));
+
+    /* loop through cells, find value, and draw text for value */
+    for (row = 0; row < nrows; row++) {
+	G_get_raster_row(layer_fd, cell, row, map_type);
+
+	/* determine screen y coordinate of top of current cell */
+
+	D_y = (int)(row * D_ns + D_north);
+
+	for (col = 0; col < ncols; col++) {
+	    /* determine screen x coordinate of west side of current cell */
+	    D_x = (int)(col * D_ew + D_west);
+
+	    if (fixed_color == 0) {
+		G_get_raster_color(&cell[col], &R, &G, &B, &colors, map_type);
+		R_RGB_color(R, G, B);
+	    }
+
+	    draw_number(cell[col], digits, inmap_type);
+	}
+    }
+
+    G_close_cell(layer_fd);
+
+    R_close_driver();
+
+    exit(EXIT_SUCCESS);
+}
+
+/* --- end of main --- */
+
+
+int draw_number(double number, int prec, RASTER_MAP_TYPE map_type)
+{
+    extern double D_ew, D_ns;
+    extern int D_x, D_y;
+    int len, text_size, rite;
+    double tt, tb, tl, tr;
+    char no[32];
+    double dots_per_line, factor = 0.8;
+    DCELL dcell = number;
+    CELL cell = (int)number;
+
+    R_set_window(D_y, D_y + D_ns * 0.9, D_x, D_x + D_ew * 0.9);
+
+    /* maybe ugly, but works */
+    if (map_type == CELL_TYPE) {
+	if (!G_is_c_null_value(&cell))
+	    sprintf(no, "%d", (int)number);
+	else
+	    sprintf(no, "Null");
+    }
+    else {
+	if (!G_is_d_null_value(&dcell))
+	    sprintf(no, "%.*f", prec, number);
+	else
+	    sprintf(no, "Null");
+    }
+    len = strlen(no);
+
+    dots_per_line = factor * D_ns;
+    text_size = factor * dots_per_line;
+    rite = text_size * len;
+
+    while (rite > D_ew) {
+	factor = factor - 0.01;
+	text_size = factor * dots_per_line;
+	rite = text_size * len;
+    }
+
+    R_text_size(text_size, text_size);
+    R_get_text_box(no, &tt, &tb, &tl, &tr);
+    /*
+       R_get_text_box(num,&tt,&tb,&tl,&tr);
+       R_move_abs(D_x+(int)(D_ew*0.1),D_y+(int)(D_ns*0.5)) ;
+       R_move_abs(D_x,D_y+(int)(dots_per_line - 1)) ;
+     */
+    R_move_abs(D_x + D_ew / 2 - (tr - tl) / 2, D_y + D_ns * 0.7);
+    R_text(no);
+
+    return 0;
+}

Deleted: grass/trunk/display/d.rast.num/number.c
===================================================================
--- grass/trunk/display/d.rast.num/number.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/display/d.rast.num/number.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,349 +0,0 @@
-/*
- ****************************************************************************
- *
- * MODULE:       d.rast.num
- * AUTHOR(S):    Raghavan Srinivasan, Agricultural Engineering, Purdue University
- * PURPOSE:      Print numbers of category for raster cells
- * COPYRIGHT:    (C) 2000 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.
- *
- *****************************************************************************/
-
-/* updated by Andreas Lange, andreas.lange at rhein-main.de 
- * for text color support.
- * updated 2004 my MN for FP support
- */
-
-/*
- *   Raghavan Srinivasan, Agricultural Engineering, Purdue University
- *   srin at ecn.purdue.edu  March 1991
- *
- *   d.rast.num
- *
- *   Usage:  d.rast.num
- * 
- *   This program used Dgrid's sources as a beginning. Purpose of Dnumber
- *   is to read the cell layer displayed on the graphics monitor and number
- *   them, if the cell value is other than 0 in an acending order.
- *   d.rast.num draws a number on the graphic display
- *   of each cell, so the cell number could be identified when using hydrologic
- *   models such AGNPS which uses the cell number for all its correspondance.
- *   
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/display.h>
-#include <grass/colors.h>
-#include <grass/glocale.h>
-
-int draw_number(double, int, RASTER_MAP_TYPE);
-
-int D_x, D_y;
-double D_ew, D_ns;
-
-int main(int argc, char **argv)
-{
-    DCELL *cell;
-    char *mapset;
-    char full_name[128];
-    double D_north, D_east;
-    double D_south, D_west;
-    double U_east, U_north;
-    double U_start;
-    double U_to_D_xconv, U_to_D_yconv;
-    double U_west, U_south;
-    double U_x, U_y;
-    double ew_res, ns_res;
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int fixed_color, grid_color;
-    int R, G, B;
-    int layer_fd;
-    int nrows, ncols, row, col;
-    double t, b, l, r;
-    int digits;
-    struct Cell_head window;
-    struct Colors colors;
-    struct GModule *module;
-    struct Option *opt1, *opt2, *opt3, *prec;
-    struct Flag *text_color;
-    RASTER_MAP_TYPE map_type, inmap_type;
-
-    /* Initialize the GIS calls */
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("display");
-    module->description =
-	_("Overlays cell category values on a raster map layer "
-	  "displayed to the graphics monitor.");
-
-    opt1 = G_define_standard_option(G_OPT_R_MAP);
-
-    opt2 = G_define_option();
-    opt2->key = "grid_color";
-    opt2->type = TYPE_STRING;
-    opt2->required = NO;
-    opt2->answer = "gray";
-    opt2->options = D_COLOR_LIST ",none";
-    opt2->key_desc = "color";
-    opt2->description = _("Color for drawing grid, or \"none\"");
-
-    opt3 = G_define_option();
-    opt3->key = "text_color";
-    opt3->type = TYPE_STRING;
-    opt3->required = NO;
-    opt3->answer = DEFAULT_FG_COLOR;
-    opt3->options = D_COLOR_LIST;
-    opt3->key_desc = "color";
-    opt3->description = _("Color for drawing text");
-
-    prec = G_define_option();
-    prec->key = "dp";
-    prec->type = TYPE_INTEGER;
-    prec->required = NO;
-    prec->answer = "1";
-    prec->options = "0,1,2,3,4,5,6,7,8,9";
-    prec->description =
-	_("Number of significant digits (floating point only)");
-
-    text_color = G_define_flag();
-    text_color->key = 'f';
-    text_color->description = _("Get text color from cell color value");
-
-    /* Check command line */
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    if (R_open_driver() != 0)
-	G_fatal_error(_("No graphics device selected"));
-
-    strcpy(full_name, opt1->answer);
-
-    if (strcmp("none", opt2->answer) == 0)
-	grid_color = -1;
-    else
-	grid_color = D_translate_color(opt2->answer);
-
-    if (text_color->answer)
-	fixed_color = 0;
-    else
-	fixed_color = 1;
-
-    mapset = G_find_cell(full_name, "");
-    if (mapset == NULL)
-	G_fatal_error(_("Raster map <%s> not found"), full_name);
-
-    layer_fd = G_open_cell_old(full_name, mapset);
-    if (layer_fd < 0)
-	G_fatal_error(_("Unable to open raster map <%s>"), full_name);
-
-    /* determine the inputmap type (CELL/FCELL/DCELL) */
-    inmap_type = G_get_raster_map_type(layer_fd);
-    map_type = DCELL_TYPE;
-
-    /* Setup driver and check important information */
-
-    /* Read in the map window associated with window */
-
-    G_get_window(&window);
-
-    D_check_map_window(&window);
-
-    if (G_set_window(&window) == -1)
-	G_fatal_error(_("Current window not settable"));
-
-    /* Determine conversion factors */
-
-    if (D_get_screen_window(&t, &b, &l, &r))
-	G_fatal_error(_("Getting screen window"));
-    if (D_do_conversions(&window, t, b, l, r))
-	G_fatal_error(_("Error in calculating conversions"));
-
-    /* where are we, both geographically and on the screen? */
-
-    D_south = D_get_d_south();
-    D_north = D_get_d_north();
-    D_east = D_get_d_east();
-    D_west = D_get_d_west();
-
-    U_west = D_get_u_west();
-    U_east = D_get_u_east();
-    U_south = D_get_u_south();
-    U_north = D_get_u_north();
-
-    U_to_D_xconv = D_get_u_to_d_xconv();
-    U_to_D_yconv = D_get_u_to_d_yconv();
-
-    /* number of rows and cols in window */
-
-    nrows = window.rows;
-    ncols = window.cols;
-
-    if ((nrows > 75) || (ncols > 75)) {
-	G_warning("!!!");
-	G_message(_("Current window size:"));
-	G_message(_("rows:    %d"), nrows);
-	G_message(_("columns: %d"), ncols);
-
-	G_message(_("\nYour current window setting may be too large."
-		    " Cells displayed on your graphics window may be too"
-		    " small for cell category number to be visible."));
-	G_message(" ");
-    }
-    if ((nrows > 200) || (ncols > 200)) {
-	G_fatal_error(_("Aborting."));
-    }
-
-    /* resolutions */
-    ew_res = window.ew_res;
-    ns_res = window.ns_res;
-
-    /* how many screen units of distance for each cell */
-    D_ew = (D_east - D_west) / ncols;
-    D_ns = (D_south - D_north) / nrows;
-
-    /*set the number of significant digits */
-    sscanf(prec->answer, "%i", &digits);
-
-	/*-- DEBUG ----------------------------------------
-	fprintf (stdout,"ew_res:  %.2f\n", window.ew_res);
-	fprintf (stdout,"ns_res:  %.2f\n", window.ns_res);
-	fprintf (stdout,"D_ew:  %f D_ns:  %f \n", D_ew, D_ns); 
-	fprintf (stdout,"nrows:    %d\n", nrows);
-	fprintf (stdout,"ncols:    %d\n", ncols);
-	fprintf (stdout,"t:  %d\n", t);
-	fprintf (stdout,"b:  %d\n", b);
-	fprintf (stdout,"l:  %d\n", l);
-	fprintf (stdout,"r:  %d\n", r);
-	fprintf (stdout,"U_west:    %f\n", U_west);
-	fprintf (stdout,"U_east:    %f\n", U_east);
-	fprintf (stdout,"U_south:   %f\n", U_south);
-	fprintf (stdout,"U_north:   %f\n", U_north);
-	fprintf (stdout,"D_west:    %f\n", D_west);
-	fprintf (stdout,"D_east:    %f\n", D_east);
-	fprintf (stdout,"D_south:   %f\n", D_south);
-	fprintf (stdout,"D_north:   %f\n", D_north);
-	fprintf (stdout,"U_to_D_xconv:      %f\n", U_to_D_xconv);
-	fprintf (stdout,"U_to_D_yconv:      %f\n", U_to_D_yconv);
-	--------------------------------------------------------*/
-
-    if (grid_color > 0) {	/* ie not "none" */
-	/* Set grid color */
-	R_standard_color(grid_color);
-
-	/* Draw vertical grids */
-	U_start = U_east;
-	for (U_x = U_start; U_x >= U_west; U_x -= ew_res) {
-	    D_x = (U_x - U_west) * U_to_D_xconv + D_west;
-	    R_move_abs(D_x, D_south);
-	    R_cont_abs(D_x, D_north);
-	}
-
-	/* Draw horizontal grids */
-	U_start = U_north;
-	for (U_y = U_start; U_y >= U_south; U_y -= ns_res) {
-	    D_y = (U_south - U_y) * U_to_D_yconv + D_south;
-	    R_move_abs(D_west, D_y);
-	    R_cont_abs(D_east, D_y);
-	}
-    }
-
-    /* allocate the cell array */
-    cell = G_allocate_raster_buf(map_type);
-
-    /* read the color table in the color structures of the displayed map */
-    if (G_read_colors(full_name, mapset, &colors) == -1)
-	G_fatal_error(_("Color file for <%s> not available"), full_name);
-
-    /* fixed text color */
-    if (fixed_color == 1)
-	R_standard_color(D_translate_color(opt3->answer));
-
-    /* loop through cells, find value, and draw text for value */
-    for (row = 0; row < nrows; row++) {
-	G_get_raster_row(layer_fd, cell, row, map_type);
-
-	/* determine screen y coordinate of top of current cell */
-
-	D_y = (int)(row * D_ns + D_north);
-
-	for (col = 0; col < ncols; col++) {
-	    /* determine screen x coordinate of west side of current cell */
-	    D_x = (int)(col * D_ew + D_west);
-
-	    if (fixed_color == 0) {
-		G_get_raster_color(&cell[col], &R, &G, &B, &colors, map_type);
-		R_RGB_color(R, G, B);
-	    }
-
-	    draw_number(cell[col], digits, inmap_type);
-	}
-    }
-
-    G_close_cell(layer_fd);
-
-    R_close_driver();
-
-    exit(EXIT_SUCCESS);
-}
-
-/* --- end of main --- */
-
-
-int draw_number(double number, int prec, RASTER_MAP_TYPE map_type)
-{
-    extern double D_ew, D_ns;
-    extern int D_x, D_y;
-    int len, text_size, rite;
-    double tt, tb, tl, tr;
-    char no[32];
-    double dots_per_line, factor = 0.8;
-    DCELL dcell = number;
-    CELL cell = (int)number;
-
-    R_set_window(D_y, D_y + D_ns * 0.9, D_x, D_x + D_ew * 0.9);
-
-    /* maybe ugly, but works */
-    if (map_type == CELL_TYPE) {
-	if (!G_is_c_null_value(&cell))
-	    sprintf(no, "%d", (int)number);
-	else
-	    sprintf(no, "Null");
-    }
-    else {
-	if (!G_is_d_null_value(&dcell))
-	    sprintf(no, "%.*f", prec, number);
-	else
-	    sprintf(no, "Null");
-    }
-    len = strlen(no);
-
-    dots_per_line = factor * D_ns;
-    text_size = factor * dots_per_line;
-    rite = text_size * len;
-
-    while (rite > D_ew) {
-	factor = factor - 0.01;
-	text_size = factor * dots_per_line;
-	rite = text_size * len;
-    }
-
-    R_text_size(text_size, text_size);
-    R_get_text_box(no, &tt, &tb, &tl, &tr);
-    /*
-       R_get_text_box(num,&tt,&tb,&tl,&tr);
-       R_move_abs(D_x+(int)(D_ew*0.1),D_y+(int)(D_ns*0.5)) ;
-       R_move_abs(D_x,D_y+(int)(dots_per_line - 1)) ;
-     */
-    R_move_abs(D_x + D_ew / 2 - (tr - tl) / 2, D_y + D_ns * 0.7);
-    R_text(no);
-
-    return 0;
-}

Modified: grass/trunk/general/g.mapsets/Makefile
===================================================================
--- grass/trunk/general/g.mapsets/Makefile	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/general/g.mapsets/Makefile	2008-08-16 09:46:03 UTC (rev 32810)
@@ -7,12 +7,6 @@
 LIBES     = $(GISLIB)
 DEPENDENCIES= $(GISDEP)
 
-CMD_OBJS = \
-	main_cmd.o \
-	dsply_path.o \
-	dsply_maps.o \
-	get_maps.o
-
 include $(MODULE_TOPDIR)/include/Make/Module.make
 
 default: cmd $(GUI)

Deleted: grass/trunk/general/g.mapsets/get_path.c
===================================================================
--- grass/trunk/general/g.mapsets/get_path.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/general/g.mapsets/get_path.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,118 +0,0 @@
-#include <string.h>
-#include "local_proto.h"
-#include <stdio.h>
-#include "externs.h"
-#include <grass/gis.h>
-int get_mapset_path(void)
-{
-    static int first = 1;
-    char buf[4096];
-    char *b;
-    char name[GMAPSET_MAX];
-    int n;
-    int action;			/* defines action to be taken in set_path function */
-
-    fprintf(stdout, "Hit RETURN to keep current list, or ");
-    fprintf(stdout, "enter a new list of mapsets\n");
-    if (first) {
-	fprintf(stdout, "(enter the numbers before the mapset name, ");
-	fprintf(stdout, "or the names themselves)\n");
-	fprintf(stdout, "    (to ADD to end of list, use + . . .)\n");
-	fprintf(stdout, "    (to DELETE from list, use - . . .)\n");
-	first = 0;
-    }
-
-    nchoices = 0;
-
-    fprintf(stdout, "\nnew list> ");
-    if (!fgets(b = buf, 4096, stdin))
-	goto same;
-    while (isspace(*b))
-	b++;
-
-    switch (*b) {
-    case '+':			/* preload existing path into choice array */
-	action = ADD;
-	for (n = 0; n < ncurr_mapsets;
-	     choice[nchoices++] = curr_mapset[n++]) ;
-	b++;
-	break;
-    case '-':
-	action = DELETE;
-	b++;
-	break;
-    default:
-	action = REPLACE;
-    }
-
-    while (1) {
-	if (sscanf(b, "%s", name) != 1) {
-	    if (action == DELETE)
-		return delete_choices();
-	    return 1;
-	}
-
-	for (n = 0; n < nmapsets; n++)
-	    if (strcmp(name, mapset_name[n]) == 0) {
-		choice[nchoices++] = n;
-		goto next;
-	    }
-
-	if (scan_int(name, &n)) {
-	    if (n > 0 && n <= nmapsets) {
-		choice[nchoices++] = n - 1;
-		goto next;
-	    }
-	}
-
-	fprintf(stdout, "\n<%s> not found\n\n", name);
-	return -1;
-
-      next:
-	while (*b == ' ' || *b == '\t')
-	    b++;
-	while (*b && *b != ' ' && *b != '\t')
-	    b++;
-    }
-  same:
-    for (n = 0; b = G__mapset_name(n); n++) {
-	int i;
-
-	for (i = 0; i < nmapsets; i++)
-	    if (strcmp(b, mapset_name[i]) == 0) {
-		choice[nchoices++] = i;
-		break;
-	    }
-    }
-    return 1;
-}
-
-
-int delete_choices(void)
-{
-    int i, n;
-    int deletion;		/* map number to be deleted */
-
-    /* action is delete:  modify previous mapset list and write to choice array */
-
-    for (i = 0; i < nchoices; i++) {
-	deletion = choice[i];
-	for (n = 0; n < ncurr_mapsets; n++)
-	    if (curr_mapset[n] == deletion) {	/* delete mapset from path */
-		curr_mapset[n] = -1;
-		break;
-	    }
-	if (n == ncurr_mapsets) {
-	    fprintf(stdout, "\n<%s> not found in search list\n\n",
-		    mapset_name[deletion]);
-	    return -1;
-	}
-    }
-
-    /* prepare choice array list for final processing */
-    nchoices = 0;
-    for (n = 0; n < ncurr_mapsets; n++)
-	if (curr_mapset[n] >= 0)	/* i.e., not deleted */
-	    choice[nchoices++] = curr_mapset[n];
-    return 1;
-}

Copied: grass/trunk/general/g.mapsets/main.c (from rev 32801, grass/trunk/general/g.mapsets/main_cmd.c)
===================================================================
--- grass/trunk/general/g.mapsets/main.c	                        (rev 0)
+++ grass/trunk/general/g.mapsets/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,240 @@
+
+/****************************************************************************
+ *
+ * MODULE:       g.mapsets
+ * AUTHOR(S):    Michael Shapiro (CERL), Greg Koerper (ManTech Environmental
+ *                    Technology) (original contributors), 
+ *               Glynn Clements <glynn gclements.plus.com>
+ *               Hamish Bowman <hamish_nospam yahoo.com>, 
+ *               Markus Neteler <neteler itc.it>, 
+ *               Moritz Lennert <mlennert club.worldonline.be>
+ * PURPOSE:      set current mapset path
+ * COPYRIGHT:    (C) 1994-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 <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <grass/gis.h>
+#include <grass/spawn.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+#include "externs.h"
+
+char *mapset_name[GMAPSET_MAX];
+int nmapsets;
+int choice[GMAPSET_MAX];
+int nchoices;
+int curr_mapset[GMAPSET_MAX];
+int ncurr_mapsets;
+
+static char Path[GPATH_MAX];
+
+int main(int argc, char *argv[])
+{
+    int n;
+    int i;
+    int skip;
+    char *cur_mapset;
+    char **ptr;
+    char **tokens;
+    int no_tokens;
+    FILE *fp;
+    char path[GPATH_MAX];
+    struct GModule *module;
+    struct Option *opt1, *opt2, *opt3;
+    struct Flag *print;
+    struct Flag *list;
+    struct Flag *tcl;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("general, settings");
+    module->description =
+	_("Modifies the user's current mapset "
+	  "search path, affecting the user's access to data existing "
+	  "under the other GRASS mapsets in the current location.");
+
+    opt1 = G_define_option();
+    opt1->key = "mapset";
+    opt1->type = TYPE_STRING;
+    opt1->required = NO;
+    opt1->multiple = YES;
+    opt1->description = _("Name(s) of existing mapset(s)");
+
+    opt2 = G_define_option();
+    opt2->key = "addmapset";
+    opt2->type = TYPE_STRING;
+    opt2->required = NO;
+    opt2->multiple = YES;
+    opt2->description =
+	_("Name(s) of existing mapset(s) to add to search list");
+
+    opt3 = G_define_option();
+    opt3->key = "removemapset";
+    opt3->type = TYPE_STRING;
+    opt3->required = NO;
+    opt3->multiple = YES;
+    opt3->description =
+	_("Name(s) of existing mapset(s) to remove from search list");
+
+    list = G_define_flag();
+    list->key = 'l';
+    list->description = _("List all available mapsets");
+
+    print = G_define_flag();
+    print->key = 'p';
+    print->description = _("Print current mapset search path");
+
+    tcl = G_define_flag();
+    tcl->key = 's';
+    tcl->description = _("Show mapset selection dialog");
+
+    Path[0] = '\0';
+    nchoices = 0;
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    if (list->answer) {
+	get_available_mapsets();
+	display_available_mapsets(0);
+    }
+
+    if (tcl->answer) {
+	sprintf(path, "%s/etc/g.mapsets.tcl", G_gisbase());
+	G_spawn(path, "g.mapsets.tcl", NULL);
+    }
+
+    if (opt1->answer) {
+	for (ptr = opt1->answers; *ptr != NULL; ptr++) {
+	    char *mapset;
+
+	    mapset = *ptr;
+	    if (G__mapset_permissions(mapset) < 0)
+		G_fatal_error(_("Mapset <%s> not found"), mapset);
+	    nchoices++;
+	    strcat(Path, mapset);
+	    strcat(Path, " ");
+	}
+    }
+
+    /* add to existing search path */
+    if (opt2->answer) {
+	char *oldname;
+
+	Path[0] = '\0';
+
+	/* read existing mapsets from SEARCH_PATH */
+	for (n = 0; (oldname = G__mapset_name(n)); n++) {
+	    strcat(Path, oldname);
+	    strcat(Path, " ");
+	}
+
+	/* fetch and add new mapsets from param list */
+	for (ptr = opt2->answers; *ptr != NULL; ptr++) {
+	    char *mapset;
+
+	    mapset = *ptr;
+	    if (G__mapset_permissions(mapset) < 0)
+		G_fatal_error(_("Mapset <%s> not found"), mapset);
+	    else
+		G_verbose_message(_("Mapset <%s> added to search path"),
+				  mapset);
+
+	    nchoices++;
+	    strcat(Path, mapset);
+	    strcat(Path, " ");
+	}
+    }
+
+    /* remove from existing search path */
+    if (opt3->answer) {
+	char *oldname;
+
+	Path[0] = '\0';
+
+	/* read existing mapsets from SEARCH_PATH */
+	for (n = 0; (oldname = G__mapset_name(n)); n++) {
+	    int found = 0;
+
+	    for (ptr = opt3->answers; *ptr; ptr++)
+		if (strcmp(oldname, *ptr) == 0)
+		    found = 1;
+
+	    if (found) {
+		G_verbose_message(_("Mapset <%s> removed from search path"),
+				  oldname);
+		continue;
+	    }
+
+	    nchoices++;
+	    strcat(Path, oldname);
+	    strcat(Path, " ");
+	}
+    }
+
+    /* stuffem sets nchoices */
+
+    if (nchoices == 0) {
+	goto DISPLAY;
+    }
+
+    /* note I'm assuming that mapsets cannot have ' 's in them */
+    tokens = G_tokenize(Path, " ");
+
+    fp = G_fopen_new("", "SEARCH_PATH");
+    if (!fp)
+	G_fatal_error(_("Cannot open SEARCH_PATH for write"));
+
+    cur_mapset = G_mapset();
+
+    /*
+     * make sure current mapset is specified in the list
+     * if not add it to the head of the list
+     */
+
+    skip = 0;
+    for (n = 0; n < nchoices; n++)
+	if (strcmp(cur_mapset, tokens[n]) == 0) {
+	    skip = 1;
+	    break;
+	}
+    if (!skip) {
+	fprintf(fp, "%s\n", cur_mapset);
+    }
+
+    /*
+     * output the list, removing duplicates
+     */
+
+    no_tokens = G_number_of_tokens(tokens);
+
+    for (n = 0; n < no_tokens; n++) {
+	skip = 0;
+	for (i = n; i < no_tokens; i++) {
+	    if (i != n) {
+		if (strcmp(tokens[i], tokens[n]) == 0)
+		    skip = 1;
+	    }
+	}
+
+	if (!skip)
+	    fprintf(fp, "%s\n", tokens[n]);
+    }
+
+    fclose(fp);
+    G_free_tokens(tokens);
+
+  DISPLAY:
+    if (print->answer)
+	display_mapset_path(0);
+
+    exit(EXIT_SUCCESS);
+}

Deleted: grass/trunk/general/g.mapsets/main_cmd.c
===================================================================
--- grass/trunk/general/g.mapsets/main_cmd.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/general/g.mapsets/main_cmd.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,240 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       g.mapsets
- * AUTHOR(S):    Michael Shapiro (CERL), Greg Koerper (ManTech Environmental
- *                    Technology) (original contributors), 
- *               Glynn Clements <glynn gclements.plus.com>
- *               Hamish Bowman <hamish_nospam yahoo.com>, 
- *               Markus Neteler <neteler itc.it>, 
- *               Moritz Lennert <mlennert club.worldonline.be>
- * PURPOSE:      set current mapset path
- * COPYRIGHT:    (C) 1994-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 <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/spawn.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-#include "externs.h"
-
-char *mapset_name[GMAPSET_MAX];
-int nmapsets;
-int choice[GMAPSET_MAX];
-int nchoices;
-int curr_mapset[GMAPSET_MAX];
-int ncurr_mapsets;
-
-static char Path[GPATH_MAX];
-
-int main(int argc, char *argv[])
-{
-    int n;
-    int i;
-    int skip;
-    char *cur_mapset;
-    char **ptr;
-    char **tokens;
-    int no_tokens;
-    FILE *fp;
-    char path[GPATH_MAX];
-    struct GModule *module;
-    struct Option *opt1, *opt2, *opt3;
-    struct Flag *print;
-    struct Flag *list;
-    struct Flag *tcl;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("general, settings");
-    module->description =
-	_("Modifies the user's current mapset "
-	  "search path, affecting the user's access to data existing "
-	  "under the other GRASS mapsets in the current location.");
-
-    opt1 = G_define_option();
-    opt1->key = "mapset";
-    opt1->type = TYPE_STRING;
-    opt1->required = NO;
-    opt1->multiple = YES;
-    opt1->description = _("Name(s) of existing mapset(s)");
-
-    opt2 = G_define_option();
-    opt2->key = "addmapset";
-    opt2->type = TYPE_STRING;
-    opt2->required = NO;
-    opt2->multiple = YES;
-    opt2->description =
-	_("Name(s) of existing mapset(s) to add to search list");
-
-    opt3 = G_define_option();
-    opt3->key = "removemapset";
-    opt3->type = TYPE_STRING;
-    opt3->required = NO;
-    opt3->multiple = YES;
-    opt3->description =
-	_("Name(s) of existing mapset(s) to remove from search list");
-
-    list = G_define_flag();
-    list->key = 'l';
-    list->description = _("List all available mapsets");
-
-    print = G_define_flag();
-    print->key = 'p';
-    print->description = _("Print current mapset search path");
-
-    tcl = G_define_flag();
-    tcl->key = 's';
-    tcl->description = _("Show mapset selection dialog");
-
-    Path[0] = '\0';
-    nchoices = 0;
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    if (list->answer) {
-	get_available_mapsets();
-	display_available_mapsets(0);
-    }
-
-    if (tcl->answer) {
-	sprintf(path, "%s/etc/g.mapsets.tcl", G_gisbase());
-	G_spawn(path, "g.mapsets.tcl", NULL);
-    }
-
-    if (opt1->answer) {
-	for (ptr = opt1->answers; *ptr != NULL; ptr++) {
-	    char *mapset;
-
-	    mapset = *ptr;
-	    if (G__mapset_permissions(mapset) < 0)
-		G_fatal_error(_("Mapset <%s> not found"), mapset);
-	    nchoices++;
-	    strcat(Path, mapset);
-	    strcat(Path, " ");
-	}
-    }
-
-    /* add to existing search path */
-    if (opt2->answer) {
-	char *oldname;
-
-	Path[0] = '\0';
-
-	/* read existing mapsets from SEARCH_PATH */
-	for (n = 0; (oldname = G__mapset_name(n)); n++) {
-	    strcat(Path, oldname);
-	    strcat(Path, " ");
-	}
-
-	/* fetch and add new mapsets from param list */
-	for (ptr = opt2->answers; *ptr != NULL; ptr++) {
-	    char *mapset;
-
-	    mapset = *ptr;
-	    if (G__mapset_permissions(mapset) < 0)
-		G_fatal_error(_("Mapset <%s> not found"), mapset);
-	    else
-		G_verbose_message(_("Mapset <%s> added to search path"),
-				  mapset);
-
-	    nchoices++;
-	    strcat(Path, mapset);
-	    strcat(Path, " ");
-	}
-    }
-
-    /* remove from existing search path */
-    if (opt3->answer) {
-	char *oldname;
-
-	Path[0] = '\0';
-
-	/* read existing mapsets from SEARCH_PATH */
-	for (n = 0; (oldname = G__mapset_name(n)); n++) {
-	    int found = 0;
-
-	    for (ptr = opt3->answers; *ptr; ptr++)
-		if (strcmp(oldname, *ptr) == 0)
-		    found = 1;
-
-	    if (found) {
-		G_verbose_message(_("Mapset <%s> removed from search path"),
-				  oldname);
-		continue;
-	    }
-
-	    nchoices++;
-	    strcat(Path, oldname);
-	    strcat(Path, " ");
-	}
-    }
-
-    /* stuffem sets nchoices */
-
-    if (nchoices == 0) {
-	goto DISPLAY;
-    }
-
-    /* note I'm assuming that mapsets cannot have ' 's in them */
-    tokens = G_tokenize(Path, " ");
-
-    fp = G_fopen_new("", "SEARCH_PATH");
-    if (!fp)
-	G_fatal_error(_("Cannot open SEARCH_PATH for write"));
-
-    cur_mapset = G_mapset();
-
-    /*
-     * make sure current mapset is specified in the list
-     * if not add it to the head of the list
-     */
-
-    skip = 0;
-    for (n = 0; n < nchoices; n++)
-	if (strcmp(cur_mapset, tokens[n]) == 0) {
-	    skip = 1;
-	    break;
-	}
-    if (!skip) {
-	fprintf(fp, "%s\n", cur_mapset);
-    }
-
-    /*
-     * output the list, removing duplicates
-     */
-
-    no_tokens = G_number_of_tokens(tokens);
-
-    for (n = 0; n < no_tokens; n++) {
-	skip = 0;
-	for (i = n; i < no_tokens; i++) {
-	    if (i != n) {
-		if (strcmp(tokens[i], tokens[n]) == 0)
-		    skip = 1;
-	    }
-	}
-
-	if (!skip)
-	    fprintf(fp, "%s\n", tokens[n]);
-    }
-
-    fclose(fp);
-    G_free_tokens(tokens);
-
-  DISPLAY:
-    if (print->answer)
-	display_mapset_path(0);
-
-    exit(EXIT_SUCCESS);
-}

Deleted: grass/trunk/general/g.mapsets/main_inter.c
===================================================================
--- grass/trunk/general/g.mapsets/main_inter.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/general/g.mapsets/main_inter.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,40 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       g.mapsets
- * AUTHOR(S):    Michael Shapiro (CERL), Greg Koerper (ManTech Environmental
- *                    Technology) (original contributors), 
- *               Markus Neteler <neteler itc.it>
- *               Glynn Clements <glynn gclements.plus.com>
- * PURPOSE:      Allow user to select new mapset path
- * COPYRIGHT:    (C) 1994-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 "externs.h"
-#include "local_proto.h"
-#include <grass/gis.h>
-int main(int argc, char **argv)
-{
-    G_gisinit(argv[0]);
-    G_clear_screen();
-    fprintf(stdout, "MAPSET SEARCH LIST UTILITY");
-    fprintf(stdout, "     LOCATION: %s    MAPSET: %s\n\n", G_location(),
-	    G_mapset());
-
-    get_available_mapsets();
-
-    do {
-	display_mapset_path(1);
-	display_available_mapsets(1);
-    }
-    while (get_mapset_path() < 0);
-
-    set_mapset_path();
-
-    return 0;
-}

Deleted: grass/trunk/general/g.mapsets/scan_int.c
===================================================================
--- grass/trunk/general/g.mapsets/scan_int.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/general/g.mapsets/scan_int.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,12 +0,0 @@
-#include "local_proto.h"
-#include <stdio.h>
-int scan_int(char *buf, int *n)
-{
-    char dummy[2];
-
-    *dummy = 0;
-    if (sscanf(buf, "%d%1s", n, dummy) != 1)
-	return 0;
-
-    return (*dummy == 0 ? 1 : 0);
-}

Deleted: grass/trunk/general/g.mapsets/set_path.c
===================================================================
--- grass/trunk/general/g.mapsets/set_path.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/general/g.mapsets/set_path.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,67 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include "externs.h"
-#include <grass/gis.h>
-
-int set_mapset_path(void)
-{
-    char command[4096];
-    int n;
-    int i;
-    int skip;
-    int any;
-    char *cur_mapset;
-
-    if (nchoices == 0)		/* they didn't choose any, exit w/out change */
-	return 0;
-
-    cur_mapset = G_mapset();
-
-    /* build first part of command string */
-    strcpy(command, "g.mapsets -p mapset=");
-    any = 0;
-
-    /*
-     * make sure current mapset is specified in the list
-     * if not add it to the head of the list
-     */
-
-    skip = 0;
-    for (n = 0; n < nchoices; n++)
-	if (strcmp(cur_mapset, mapset_name[choice[n]]) == 0) {
-	    skip = 1;
-	    break;
-	}
-    if (!skip) {
-	if (any++)
-	    strcat(command, ",");
-	strcat(command, cur_mapset);
-    }
-
-    /*
-     * output the list, removing duplicates
-     */
-    for (n = 0; n < nchoices; n++) {
-	skip = 0;
-	for (i = 0; i < n; i++)
-	    if (strcmp(mapset_name[choice[i]], mapset_name[choice[n]]) == 0) {
-		skip = 1;
-		break;
-	    }
-	if (!skip) {
-	    if (any++)
-		strcat(command, ",");
-	    strcat(command, mapset_name[choice[n]]);
-	}
-    }
-
-    fprintf(stdout, "\nMapset search list set to\n ");
-    fflush(stdout);
-    if (system(command) == 0) {
-	return (0);
-    }
-    else {
-	G_warning("call to g.mapsets failed");
-	return (-1);
-    }
-}

Deleted: grass/trunk/imagery/i.fft/fftmain.c
===================================================================
--- grass/trunk/imagery/i.fft/fftmain.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/imagery/i.fft/fftmain.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,284 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       i.fft
- * AUTHOR(S):    David B. Satnik and Ali R. Vali (original contributors),
- *               Markus Neteler <neteler itc.it>
- *               Bernhard Reiter <bernhard intevation.de>, 
- *               Brad Douglas <rez touchofmadness.com>, 
- *               Glynn Clements <glynn gclements.plus.com>
- * PURPOSE:      processes a single input raster map layer
- *               and constructs the real and imaginary Fourier
- *               components in frequency space
- * 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.
- *
- *****************************************************************************/
-/*
-   FFT for GRASS by:
-   Central Washington University GIS Laboratory
-   Programmer: David B. Satnik
-
-   Original FFT function provided by:
-   Programmer : Ali R. Vali
-   Center for Space Research
-   WRW 402
-   University of Texas
-   Austin, TX 78712-1085
-
-   (512) 471-6824
-
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/gmath.h>
-#include <grass/glocale.h>
-#include "globals.h"
-#include "local_proto.h"
-
-char Cellmap_real[GNAME_MAX], Cellmap_imag[GNAME_MAX];
-
-int main(int argc, char *argv[])
-{
-    /* Global variable & function declarations */
-    int Range;
-    char Cellmap_orig[GNAME_MAX];
-    int inputfd, realfd, imagfd;	/* the input and output file descriptors */
-    char *inmapset;		/* the input mapset name */
-    struct Cell_head window;
-    CELL *cell_row, *cell_row2;
-    double max, min, scale, temp;
-
-    int i, j;			/* Loop control variables */
-    int or, oc;			/* Original dimensions of image */
-    int rows, cols;		/* Smallest powers of 2 >= number of rows & columns */
-    long totsize;		/* Total number of data points */
-    double *data[2];		/* Data structure containing real & complex values of FFT */
-    int save_args();		/* function to stash the command line arguments */
-    struct GModule *module;
-    struct Option *op1, *op2, *op3, *op4;
-    int maskfd;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("imagery");
-    module->description =
-	_("Fast Fourier Transform (FFT) for image processing.");
-
-    /* define options */
-    op1 = G_define_option();
-    op1->key = "input_image";
-    op1->type = TYPE_STRING;
-    op1->required = YES;
-    op1->multiple = NO;
-    op1->gisprompt = "old,cell,raster";
-    op1->description = _("Input raster map being fft");
-
-    op2 = G_define_option();
-    op2->key = "real_image";
-    op2->type = TYPE_STRING;
-    op2->required = YES;
-    op2->multiple = NO;
-    op2->gisprompt = "new,cell,raster";
-    op2->description = _("Output real part arrays stored as raster map");
-
-    op3 = G_define_option();
-    op3->key = "imaginary_image";
-    op3->type = TYPE_STRING;
-    op3->required = YES;
-    op3->multiple = NO;
-    op3->gisprompt = "new,cell,raster";
-    op3->description = _("Output imaginary part arrays stored as raster map");
-
-    op4 = G_define_option();
-    op4->key = "range";
-    op4->type = TYPE_INTEGER;
-    op4->required = NO;
-    op4->multiple = NO;
-    op4->answer = "255";
-    op4->description = _("Range of values in output display files");
-
-    /*call parser */
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    strcpy(Cellmap_orig, op1->answer);
-    strcpy(Cellmap_real, op2->answer);
-    strcpy(Cellmap_imag, op3->answer);
-
-    /* open input cell map */
-    if ((inmapset = G_find_cell(Cellmap_orig, "")) == NULL)
-	G_fatal_error(_("Raster map <%s> not found"), Cellmap_orig);
-
-    inputfd = G_open_cell_old(Cellmap_orig, inmapset);
-    if (inputfd < 0)
-	exit(EXIT_FAILURE);
-
-    if ((maskfd = G_maskfd()) >= 0)
-	G_warning(_("Raster MASK found, consider to remove "
-		    "(see man-page). Will continue..."));
-
-
-    /* check command line args for validity */
-    if (G_legal_filename(Cellmap_real) < 0)
-	G_fatal_error(_("Illegal file name for real part: %s"), Cellmap_real);
-
-    if (G_legal_filename(Cellmap_imag) < 0)
-	G_fatal_error(_("Illegal file name for imaginary part: %s"),
-		      Cellmap_imag);
-
-    sscanf(op4->answer, "%d", &Range);
-    if (Range <= 0)
-	G_fatal_error(_("Range less than or equal to zero not allowed."));
-
-    G_get_set_window(&window);	/* get the current window for later */
-    put_orig_window(&window);
-
-    /* get the rows and columns in the current window */
-    or = G_window_rows();
-    oc = G_window_cols();
-    rows = G_math_max_pow2(or);
-    cols = G_math_max_pow2(oc);
-    totsize = rows * cols;
-
-    /*  fprintf(stderr,"Power 2 values : %d rows %d columns\n",rows,cols); */
-
-    /* Allocate appropriate memory for the structure containing
-       the real and complex components of the FFT.  DATA[0] will
-       contain the real, and DATA[1] the complex component.
-     */
-    data[0] = (double *)G_malloc((rows * cols) * sizeof(double));
-    data[1] = (double *)G_malloc((rows * cols) * sizeof(double));
-    if (data[0] == NULL || data[1] == NULL)
-	G_fatal_error(_("Insufficent memory for allocation of data structure"));
-
-    /* Initialize real & complex components to zero */
-    G_message(_("Initializing data...\n"));
-    {
-	register double *dptr1, *dptr0;
-
-	dptr0 = data[0];
-	dptr1 = data[1];
-	for (i = 0; i < totsize; i++) {
-	    *dptr0++ = *dptr1++ = 0.0;
-	}
-    }
-
-    /* allocate the space for one row of cell map data */
-    cell_row = G_allocate_cell_buf();
-
-    /* Read in cell map values */
-    G_message(_("Reading the raster map..."));
-    for (i = 0; i < or; i++) {
-	if (G_get_map_row(inputfd, cell_row, i) < 0)
-	    G_fatal_error(_("Error while reading input raster map."));
-	for (j = 0; j < oc; j++)
-	    *(data[0] + (i * cols) + j) = (double)cell_row[j];
-    }
-    /* close input cell map and release the row buffer */
-    G_close_cell(inputfd);
-    G_free(cell_row);
-
-    /* perform FFT */
-    G_message(_("Starting FFT..."));
-    fft(-1, data, totsize, cols, rows);
-    G_message(_("FFT completed..."));
-
-    /* set up a window for the transform cell map */
-    window.rows = rows;
-    window.cols = cols;
-    window.south = window.north - window.rows * window.ns_res;
-    window.east = window.cols * window.ew_res + window.west;
-    G_set_window(&window);
-
-    /* open the output cell maps and allocate cell row buffers */
-    if ((realfd = G_open_cell_new(Cellmap_real)) < 0)
-	exit(1);
-    if ((imagfd = G_open_cell_new(Cellmap_imag)) < 0)
-	exit(1);
-    cell_row = G_allocate_cell_buf();
-    cell_row2 = G_allocate_cell_buf();
-
-    /* rotate the data array for standard display */
-    G_message(_("Rotating data..."));
-    for (i = 0; i < rows; i++) {
-	for (j = 0; j < cols / 2; j++) {
-	    temp = *(data[0] + i * cols + j);
-	    *(data[0] + i * cols + j) = *(data[0] + i * cols + j + cols / 2);
-	    *(data[0] + i * cols + j + cols / 2) = temp;
-	    temp = *(data[1] + i * cols + j);
-	    *(data[1] + i * cols + j) = *(data[1] + i * cols + j + cols / 2);
-	    *(data[1] + i * cols + j + cols / 2) = temp;
-	}
-    }
-    for (i = 0; i < rows / 2; i++) {
-	for (j = 0; j < cols; j++) {
-	    temp = *(data[0] + i * cols + j);
-	    *(data[0] + i * cols + j) =
-		*(data[0] + (i + rows / 2) * cols + j);
-	    *(data[0] + (i + rows / 2) * cols + j) = temp;
-	    temp = *(data[1] + i * cols + j);
-	    *(data[1] + i * cols + j) =
-		*(data[1] + (i + rows / 2) * cols + j);
-	    *(data[1] + (i + rows / 2) * cols + j) = temp;
-	}
-    }
-
-    G_message(_("Writing transformed data to file..."));
-    /* write out the double arrays to cell_misc/file/FFTREAL and FFTIMAG */
-    max = 0.0;
-    min = 0.0;
-    save_fft(totsize, data, &max, &min);
-
-    G_message(_("Writing viewable versions of transformed data to files..."));
-    /* Write out result to a new cell map */
-    /*
-       for (i=0; i<rows; i++) {
-       for (j=0; j<cols; j++) {
-       *(cell_row+j) = (CELL) (log(1.0+fabs(*(data[0]+i*cols+j)
-       )) * scale);
-       *(cell_row2+j) = (CELL) (log(1.0+fabs(*(data[1]+i*cols+j
-       ))) * scale);
-       }
-     */
-    scale = (double)Range / log(1.0 + max > -min ? max : -min);
-    {
-	register double *data0, *data1;
-	register CELL *cptr1, *cptr2;
-
-	for (i = 0; i < rows; i++) {
-	    data0 = data[0] + i * cols;
-	    data1 = data[1] + i * cols;
-	    cptr1 = cell_row;
-	    cptr2 = cell_row2;
-	    for (j = 0; j < cols; j++) {
-		*cptr1++ = (CELL) (log(1.0 + fabs(*data0++)) * scale);
-		*cptr2++ = (CELL) (log(1.0 + fabs(*data1++)) * scale);
-	    }
-	    G_put_raster_row(realfd, cell_row, CELL_TYPE);
-	    G_put_raster_row(imagfd, cell_row2, CELL_TYPE);
-	}
-    }
-    G_close_cell(realfd);
-    G_close_cell(imagfd);
-    G_free(cell_row);
-    G_free(cell_row2);
-
-    /* set up the color tables for histogram streched grey scale */
-    fft_colors();
-
-    /* Release memory resources */
-    for (i = 0; i < 2; i++)
-	G_free(data[i]);
-
-    G_done_msg(_("Transform successful."));
-
-    exit(EXIT_SUCCESS);
-}

Copied: grass/trunk/imagery/i.fft/main.c (from rev 32804, grass/trunk/imagery/i.fft/fftmain.c)
===================================================================
--- grass/trunk/imagery/i.fft/main.c	                        (rev 0)
+++ grass/trunk/imagery/i.fft/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,284 @@
+
+/****************************************************************************
+ *
+ * MODULE:       i.fft
+ * AUTHOR(S):    David B. Satnik and Ali R. Vali (original contributors),
+ *               Markus Neteler <neteler itc.it>
+ *               Bernhard Reiter <bernhard intevation.de>, 
+ *               Brad Douglas <rez touchofmadness.com>, 
+ *               Glynn Clements <glynn gclements.plus.com>
+ * PURPOSE:      processes a single input raster map layer
+ *               and constructs the real and imaginary Fourier
+ *               components in frequency space
+ * 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.
+ *
+ *****************************************************************************/
+/*
+   FFT for GRASS by:
+   Central Washington University GIS Laboratory
+   Programmer: David B. Satnik
+
+   Original FFT function provided by:
+   Programmer : Ali R. Vali
+   Center for Space Research
+   WRW 402
+   University of Texas
+   Austin, TX 78712-1085
+
+   (512) 471-6824
+
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/gmath.h>
+#include <grass/glocale.h>
+#include "globals.h"
+#include "local_proto.h"
+
+char Cellmap_real[GNAME_MAX], Cellmap_imag[GNAME_MAX];
+
+int main(int argc, char *argv[])
+{
+    /* Global variable & function declarations */
+    int Range;
+    char Cellmap_orig[GNAME_MAX];
+    int inputfd, realfd, imagfd;	/* the input and output file descriptors */
+    char *inmapset;		/* the input mapset name */
+    struct Cell_head window;
+    CELL *cell_row, *cell_row2;
+    double max, min, scale, temp;
+
+    int i, j;			/* Loop control variables */
+    int or, oc;			/* Original dimensions of image */
+    int rows, cols;		/* Smallest powers of 2 >= number of rows & columns */
+    long totsize;		/* Total number of data points */
+    double *data[2];		/* Data structure containing real & complex values of FFT */
+    int save_args();		/* function to stash the command line arguments */
+    struct GModule *module;
+    struct Option *op1, *op2, *op3, *op4;
+    int maskfd;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("imagery");
+    module->description =
+	_("Fast Fourier Transform (FFT) for image processing.");
+
+    /* define options */
+    op1 = G_define_option();
+    op1->key = "input_image";
+    op1->type = TYPE_STRING;
+    op1->required = YES;
+    op1->multiple = NO;
+    op1->gisprompt = "old,cell,raster";
+    op1->description = _("Input raster map being fft");
+
+    op2 = G_define_option();
+    op2->key = "real_image";
+    op2->type = TYPE_STRING;
+    op2->required = YES;
+    op2->multiple = NO;
+    op2->gisprompt = "new,cell,raster";
+    op2->description = _("Output real part arrays stored as raster map");
+
+    op3 = G_define_option();
+    op3->key = "imaginary_image";
+    op3->type = TYPE_STRING;
+    op3->required = YES;
+    op3->multiple = NO;
+    op3->gisprompt = "new,cell,raster";
+    op3->description = _("Output imaginary part arrays stored as raster map");
+
+    op4 = G_define_option();
+    op4->key = "range";
+    op4->type = TYPE_INTEGER;
+    op4->required = NO;
+    op4->multiple = NO;
+    op4->answer = "255";
+    op4->description = _("Range of values in output display files");
+
+    /*call parser */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    strcpy(Cellmap_orig, op1->answer);
+    strcpy(Cellmap_real, op2->answer);
+    strcpy(Cellmap_imag, op3->answer);
+
+    /* open input cell map */
+    if ((inmapset = G_find_cell(Cellmap_orig, "")) == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), Cellmap_orig);
+
+    inputfd = G_open_cell_old(Cellmap_orig, inmapset);
+    if (inputfd < 0)
+	exit(EXIT_FAILURE);
+
+    if ((maskfd = G_maskfd()) >= 0)
+	G_warning(_("Raster MASK found, consider to remove "
+		    "(see man-page). Will continue..."));
+
+
+    /* check command line args for validity */
+    if (G_legal_filename(Cellmap_real) < 0)
+	G_fatal_error(_("Illegal file name for real part: %s"), Cellmap_real);
+
+    if (G_legal_filename(Cellmap_imag) < 0)
+	G_fatal_error(_("Illegal file name for imaginary part: %s"),
+		      Cellmap_imag);
+
+    sscanf(op4->answer, "%d", &Range);
+    if (Range <= 0)
+	G_fatal_error(_("Range less than or equal to zero not allowed."));
+
+    G_get_set_window(&window);	/* get the current window for later */
+    put_orig_window(&window);
+
+    /* get the rows and columns in the current window */
+    or = G_window_rows();
+    oc = G_window_cols();
+    rows = G_math_max_pow2(or);
+    cols = G_math_max_pow2(oc);
+    totsize = rows * cols;
+
+    /*  fprintf(stderr,"Power 2 values : %d rows %d columns\n",rows,cols); */
+
+    /* Allocate appropriate memory for the structure containing
+       the real and complex components of the FFT.  DATA[0] will
+       contain the real, and DATA[1] the complex component.
+     */
+    data[0] = (double *)G_malloc((rows * cols) * sizeof(double));
+    data[1] = (double *)G_malloc((rows * cols) * sizeof(double));
+    if (data[0] == NULL || data[1] == NULL)
+	G_fatal_error(_("Insufficent memory for allocation of data structure"));
+
+    /* Initialize real & complex components to zero */
+    G_message(_("Initializing data...\n"));
+    {
+	register double *dptr1, *dptr0;
+
+	dptr0 = data[0];
+	dptr1 = data[1];
+	for (i = 0; i < totsize; i++) {
+	    *dptr0++ = *dptr1++ = 0.0;
+	}
+    }
+
+    /* allocate the space for one row of cell map data */
+    cell_row = G_allocate_cell_buf();
+
+    /* Read in cell map values */
+    G_message(_("Reading the raster map..."));
+    for (i = 0; i < or; i++) {
+	if (G_get_map_row(inputfd, cell_row, i) < 0)
+	    G_fatal_error(_("Error while reading input raster map."));
+	for (j = 0; j < oc; j++)
+	    *(data[0] + (i * cols) + j) = (double)cell_row[j];
+    }
+    /* close input cell map and release the row buffer */
+    G_close_cell(inputfd);
+    G_free(cell_row);
+
+    /* perform FFT */
+    G_message(_("Starting FFT..."));
+    fft(-1, data, totsize, cols, rows);
+    G_message(_("FFT completed..."));
+
+    /* set up a window for the transform cell map */
+    window.rows = rows;
+    window.cols = cols;
+    window.south = window.north - window.rows * window.ns_res;
+    window.east = window.cols * window.ew_res + window.west;
+    G_set_window(&window);
+
+    /* open the output cell maps and allocate cell row buffers */
+    if ((realfd = G_open_cell_new(Cellmap_real)) < 0)
+	exit(1);
+    if ((imagfd = G_open_cell_new(Cellmap_imag)) < 0)
+	exit(1);
+    cell_row = G_allocate_cell_buf();
+    cell_row2 = G_allocate_cell_buf();
+
+    /* rotate the data array for standard display */
+    G_message(_("Rotating data..."));
+    for (i = 0; i < rows; i++) {
+	for (j = 0; j < cols / 2; j++) {
+	    temp = *(data[0] + i * cols + j);
+	    *(data[0] + i * cols + j) = *(data[0] + i * cols + j + cols / 2);
+	    *(data[0] + i * cols + j + cols / 2) = temp;
+	    temp = *(data[1] + i * cols + j);
+	    *(data[1] + i * cols + j) = *(data[1] + i * cols + j + cols / 2);
+	    *(data[1] + i * cols + j + cols / 2) = temp;
+	}
+    }
+    for (i = 0; i < rows / 2; i++) {
+	for (j = 0; j < cols; j++) {
+	    temp = *(data[0] + i * cols + j);
+	    *(data[0] + i * cols + j) =
+		*(data[0] + (i + rows / 2) * cols + j);
+	    *(data[0] + (i + rows / 2) * cols + j) = temp;
+	    temp = *(data[1] + i * cols + j);
+	    *(data[1] + i * cols + j) =
+		*(data[1] + (i + rows / 2) * cols + j);
+	    *(data[1] + (i + rows / 2) * cols + j) = temp;
+	}
+    }
+
+    G_message(_("Writing transformed data to file..."));
+    /* write out the double arrays to cell_misc/file/FFTREAL and FFTIMAG */
+    max = 0.0;
+    min = 0.0;
+    save_fft(totsize, data, &max, &min);
+
+    G_message(_("Writing viewable versions of transformed data to files..."));
+    /* Write out result to a new cell map */
+    /*
+       for (i=0; i<rows; i++) {
+       for (j=0; j<cols; j++) {
+       *(cell_row+j) = (CELL) (log(1.0+fabs(*(data[0]+i*cols+j)
+       )) * scale);
+       *(cell_row2+j) = (CELL) (log(1.0+fabs(*(data[1]+i*cols+j
+       ))) * scale);
+       }
+     */
+    scale = (double)Range / log(1.0 + max > -min ? max : -min);
+    {
+	register double *data0, *data1;
+	register CELL *cptr1, *cptr2;
+
+	for (i = 0; i < rows; i++) {
+	    data0 = data[0] + i * cols;
+	    data1 = data[1] + i * cols;
+	    cptr1 = cell_row;
+	    cptr2 = cell_row2;
+	    for (j = 0; j < cols; j++) {
+		*cptr1++ = (CELL) (log(1.0 + fabs(*data0++)) * scale);
+		*cptr2++ = (CELL) (log(1.0 + fabs(*data1++)) * scale);
+	    }
+	    G_put_raster_row(realfd, cell_row, CELL_TYPE);
+	    G_put_raster_row(imagfd, cell_row2, CELL_TYPE);
+	}
+    }
+    G_close_cell(realfd);
+    G_close_cell(imagfd);
+    G_free(cell_row);
+    G_free(cell_row2);
+
+    /* set up the color tables for histogram streched grey scale */
+    fft_colors();
+
+    /* Release memory resources */
+    for (i = 0; i < 2; i++)
+	G_free(data[i]);
+
+    G_done_msg(_("Transform successful."));
+
+    exit(EXIT_SUCCESS);
+}

Deleted: grass/trunk/imagery/i.his.rgb/h2rmain.c
===================================================================
--- grass/trunk/imagery/i.his.rgb/h2rmain.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/imagery/i.his.rgb/h2rmain.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,110 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       i.his.rgb
- *
- * AUTHOR(S):    David Satnik, GIS Laboratory, Central Washington University
- *               with acknowledgements to Ali Vali,
- *               Univ. of Texas Space Research Center, for the core routine. 
- *               
- * PURPOSE:      Hue-intensity-saturation (his) to red-green-blue (rgb)
- *               raster map color transformation function.
- *
- * COPYRIGHT:    (C) 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 <stdio.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "globals.h"
-
-int main(int argc, char **argv)
-{
-
-    long i;
-    int rows, cols;
-    CELL *rowbuffer[3];
-    struct Option *opt_hue, *opt_red;
-    struct Option *opt_int, *opt_green;
-    struct Option *opt_sat, *opt_blue;
-    int fd_output[3];
-    int fd_input[3];
-    struct GModule *module;
-
-    G_gisinit(argv[0]);
-
-    /* Set description */
-    module = G_define_module();
-    module->keywords = _("imagery");
-    module->description =
-	_("Hue-intensity-saturation (his) to red-green-blue (rgb) "
-	  "raster map color transformation function.");
-
-    /* Define the different options */
-    opt_hue = G_define_standard_option(G_OPT_R_INPUT);
-    opt_hue->key = "hue_input";
-    opt_hue->description = _("Hue map name");
-
-    opt_int = G_define_standard_option(G_OPT_R_INPUT);
-    opt_int->key = "intensity_input";
-    opt_int->description = _("Intensity map name");
-
-    opt_sat = G_define_standard_option(G_OPT_R_INPUT);
-    opt_sat->key = "saturation_input";
-    opt_sat->description = _("Saturation map name");
-
-    opt_red = G_define_standard_option(G_OPT_R_OUTPUT);
-    opt_red->key = "red_output";
-    opt_red->description = _("Output map representing the red");
-
-    opt_green = G_define_standard_option(G_OPT_R_OUTPUT);
-    opt_green->key = "green_output";
-    opt_green->description = _("Output map representing the green");
-
-    opt_blue = G_define_standard_option(G_OPT_R_OUTPUT);
-    opt_blue->key = "blue_output";
-    opt_blue->description = _("Output map representing the blue");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    /* get dimension of the image */
-    rows = G_window_rows();
-    cols = G_window_cols();
-
-    openfiles(opt_hue->answer, opt_int->answer, opt_sat->answer,
-	      opt_red->answer, opt_green->answer, opt_blue->answer,
-	      fd_input, fd_output, rowbuffer);
-
-    for (i = 0; i < rows; i++) {
-	int band;
-
-	G_percent(i, rows, 2);
-
-	/* read in a row from each cell map */
-	for (band = 0; band < 3; band++)
-	    if (G_get_map_row(fd_input[band], rowbuffer[band], i) < 0)
-		G_fatal_error(_("Cannot read row from raster map"));
-
-	/* process this row of the map */
-	his2rgb(rowbuffer, cols);
-
-	/* write out the new row for each cell map */
-	for (band = 0; band < 3; band++)
-	    if (G_put_raster_row(fd_output[band], rowbuffer[band], CELL_TYPE)
-		< 0)
-		G_fatal_error(_("Cannot write row to raster map"));
-    }
-
-    closefiles(opt_red->answer, opt_green->answer, opt_blue->answer,
-	       fd_output, rowbuffer);
-
-    exit(EXIT_SUCCESS);
-}

Copied: grass/trunk/imagery/i.his.rgb/main.c (from rev 32801, grass/trunk/imagery/i.his.rgb/h2rmain.c)
===================================================================
--- grass/trunk/imagery/i.his.rgb/main.c	                        (rev 0)
+++ grass/trunk/imagery/i.his.rgb/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,110 @@
+
+/****************************************************************************
+ *
+ * MODULE:       i.his.rgb
+ *
+ * AUTHOR(S):    David Satnik, GIS Laboratory, Central Washington University
+ *               with acknowledgements to Ali Vali,
+ *               Univ. of Texas Space Research Center, for the core routine. 
+ *               
+ * PURPOSE:      Hue-intensity-saturation (his) to red-green-blue (rgb)
+ *               raster map color transformation function.
+ *
+ * COPYRIGHT:    (C) 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 <stdio.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "globals.h"
+
+int main(int argc, char **argv)
+{
+
+    long i;
+    int rows, cols;
+    CELL *rowbuffer[3];
+    struct Option *opt_hue, *opt_red;
+    struct Option *opt_int, *opt_green;
+    struct Option *opt_sat, *opt_blue;
+    int fd_output[3];
+    int fd_input[3];
+    struct GModule *module;
+
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("imagery");
+    module->description =
+	_("Hue-intensity-saturation (his) to red-green-blue (rgb) "
+	  "raster map color transformation function.");
+
+    /* Define the different options */
+    opt_hue = G_define_standard_option(G_OPT_R_INPUT);
+    opt_hue->key = "hue_input";
+    opt_hue->description = _("Hue map name");
+
+    opt_int = G_define_standard_option(G_OPT_R_INPUT);
+    opt_int->key = "intensity_input";
+    opt_int->description = _("Intensity map name");
+
+    opt_sat = G_define_standard_option(G_OPT_R_INPUT);
+    opt_sat->key = "saturation_input";
+    opt_sat->description = _("Saturation map name");
+
+    opt_red = G_define_standard_option(G_OPT_R_OUTPUT);
+    opt_red->key = "red_output";
+    opt_red->description = _("Output map representing the red");
+
+    opt_green = G_define_standard_option(G_OPT_R_OUTPUT);
+    opt_green->key = "green_output";
+    opt_green->description = _("Output map representing the green");
+
+    opt_blue = G_define_standard_option(G_OPT_R_OUTPUT);
+    opt_blue->key = "blue_output";
+    opt_blue->description = _("Output map representing the blue");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    /* get dimension of the image */
+    rows = G_window_rows();
+    cols = G_window_cols();
+
+    openfiles(opt_hue->answer, opt_int->answer, opt_sat->answer,
+	      opt_red->answer, opt_green->answer, opt_blue->answer,
+	      fd_input, fd_output, rowbuffer);
+
+    for (i = 0; i < rows; i++) {
+	int band;
+
+	G_percent(i, rows, 2);
+
+	/* read in a row from each cell map */
+	for (band = 0; band < 3; band++)
+	    if (G_get_map_row(fd_input[band], rowbuffer[band], i) < 0)
+		G_fatal_error(_("Cannot read row from raster map"));
+
+	/* process this row of the map */
+	his2rgb(rowbuffer, cols);
+
+	/* write out the new row for each cell map */
+	for (band = 0; band < 3; band++)
+	    if (G_put_raster_row(fd_output[band], rowbuffer[band], CELL_TYPE)
+		< 0)
+		G_fatal_error(_("Cannot write row to raster map"));
+    }
+
+    closefiles(opt_red->answer, opt_green->answer, opt_blue->answer,
+	       fd_output, rowbuffer);
+
+    exit(EXIT_SUCCESS);
+}

Deleted: grass/trunk/imagery/i.ifft/ifftmain.c
===================================================================
--- grass/trunk/imagery/i.ifft/ifftmain.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/imagery/i.ifft/ifftmain.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,246 +0,0 @@
-/*
-   Central Washington University GIS Laboratory
-   Programmer: David B. Satnik
-   and
-   Programmer : Ali R. Vali
-   Center for Space Research
-   WRW 402
-   University of Texas
-   Austin, TX 78712-1085
-
-   (512) 471-6824
-
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/gmath.h>
-#include "globals.h"
-#include "local_proto.h"
-
-char Cellmap_real[GNAME_MAX], Cellmap_imag[GNAME_MAX];
-
-int main(int argc, char *argv[])
-{
-    /* Global variable & function declarations */
-    char Cellmap_orig[GNAME_MAX];
-    FILE *realfp, *imagfp;	/* the input and output file descriptors */
-    int outputfd, maskfd;	/* the input and output file descriptors */
-    char *realmapset, *imagmapset;	/* the input mapset names */
-    struct Cell_head orig_wind, realhead;
-    CELL *cell_row, *maskbuf = NULL;
-
-    int i, j;			/* Loop control variables */
-    int or, oc;			/* Original dimensions of image */
-    int rows, cols;		/* Smallest powers of 2 >= number of rows & columns */
-    long totsize;		/* Total number of data points */
-    int halfrows, halfcols;
-    double *data[2];		/* Data structure containing real & complex values of FFT */
-    struct Option *op1, *op2, *op3;
-    struct GModule *module;
-
-    G_gisinit(argv[0]);
-
-    /* Set description */
-    module = G_define_module();
-    module->keywords = _("imagery");
-    module->description =
-	_("Inverse Fast Fourier Transform (IFFT) for image processing.");
-
-    /* define options */
-    op1 = G_define_option();
-    op1->key = "real_image";
-    op1->type = TYPE_STRING;
-    op1->required = YES;
-    op1->multiple = NO;
-    op1->gisprompt = "old,cell,raster";
-    op1->description = _("Input raster map (image fft, real part)");
-
-    op2 = G_define_option();
-    op2->key = "imaginary_image";
-    op2->type = TYPE_STRING;
-    op2->required = YES;
-    op2->multiple = NO;
-    op2->gisprompt = "old,cell,raster";
-    op2->description = _("Input raster map (image fft, imaginary part");
-
-    op3 = G_define_option();
-    op3->key = "output_image";
-    op3->type = TYPE_STRING;
-    op3->required = YES;
-    op3->multiple = NO;
-    op3->gisprompt = "new,cell,raster";
-    op3->description = _("Output inverse raster map after IFFT");
-
-    /*call parser */
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    strcpy(Cellmap_real, op1->answer);
-    strcpy(Cellmap_imag, op2->answer);
-    strcpy(Cellmap_orig, op3->answer);
-
-    /* open input raster map */
-    if ((realmapset = G_find_cell(Cellmap_real, "")) == NULL)
-	G_fatal_error(_("Unable to find the real-image map <%s>"),
-		      Cellmap_real);
-
-    if ((realfp =
-	 G_fopen_old_misc("cell_misc", "fftreal", Cellmap_real,
-			  realmapset)) == NULL)
-	G_fatal_error(_("Unable to open real-image in the cell_misc directory.\nInput map probably wasn't created by i.fft"));
-
-    if ((imagmapset = G_find_cell(Cellmap_imag, "")) == NULL)
-	G_fatal_error(_("Unable to find the imaginary-image <%s>"),
-		      Cellmap_imag);
-
-    if ((imagfp =
-	 G_fopen_old_misc("cell_misc", "fftimag", Cellmap_imag,
-			  imagmapset)) == NULL)
-	G_fatal_error(_("Unable to open imaginary-image in the cell_misc directory.\nInput map probably wasn't created by i.fft"));
-
-    /* check command line args for validity */
-    if (G_legal_filename(Cellmap_orig) < 0)
-	G_fatal_error(_("<%s> is an illegal file name"), Cellmap_orig);
-
-    /* get and compare the original window data */
-    get_orig_window(&orig_wind, realmapset, imagmapset);
-
-    or = orig_wind.rows;
-    oc = orig_wind.cols;
-    G_get_cellhd(Cellmap_real, realmapset, &realhead);
-    G_set_window(&realhead);	/* set the window to the whole cell map */
-
-    /* get the rows and columns in the current window */
-    rows = G_window_rows();
-    cols = G_window_cols();
-    totsize = rows * cols;
-    halfrows = rows / 2;
-    halfcols = cols / 2;
-
-    G_message(_("Power 2 values : [%d] rows [%d] columns."), rows, cols);
-
-    /* Allocate appropriate memory for the structure containing
-       the real and complex components of the FFT.  DATA[0] will
-       contain the real, and DATA[1] the complex component.
-     */
-    data[0] = (double *)G_malloc((rows * cols) * sizeof(double));
-    data[1] = (double *)G_malloc((rows * cols) * sizeof(double));
-    if (data[0] == NULL || data[1] == NULL)
-	G_fatal_error(_("Insufficent memory for allocation of data structure"));
-
-    /* Initialize real & complex components to zero */
-    G_message(_("Reading the raster maps..."));
-    {
-	fread((char *)data[0], sizeof(double), totsize, realfp);
-	fread((char *)data[1], sizeof(double), totsize, imagfp);
-    }
-
-    /* Read in cell map values */
-    G_message(_("Masking the raster maps..."));
-    maskfd = G_maskfd();
-    if (maskfd >= 0)
-	maskbuf = G_allocate_cell_buf();
-
-    if (maskfd >= 0) {
-	for (i = 0; i < rows; i++) {
-	    double *data0, *data1;
-
-	    data0 = data[0] + i * cols;
-	    data1 = data[1] + i * cols;
-	    G_get_map_row(maskfd, maskbuf, i);
-	    for (j = 0; j < cols; j++, data0++, data1++) {
-		if (maskbuf[j] == (CELL) 0) {
-		    *(data0) = 0.0;
-		    *(data1) = 0.0;
-		}
-	    }
-	}
-    }
-
-    G_message(_("Rotating data arrays..."));
-    /* rotate the data array for standard display */
-    for (i = 0; i < rows; i++) {
-	double temp;
-
-	for (j = 0; j < halfcols; j++) {
-	    temp = *(data[0] + i * cols + j);
-	    *(data[0] + i * cols + j) = *(data[0] + i * cols + j + halfcols);
-	    *(data[0] + i * cols + j + halfcols) = temp;
-	    temp = *(data[1] + i * cols + j);
-	    *(data[1] + i * cols + j) = *(data[1] + i * cols + j + halfcols);
-	    *(data[1] + i * cols + j + halfcols) = temp;
-	}
-    }
-    for (i = 0; i < halfrows; i++) {
-	double temp;
-
-	for (j = 0; j < cols; j++) {
-	    temp = *(data[0] + i * cols + j);
-	    *(data[0] + i * cols + j) =
-		*(data[0] + (i + halfrows) * cols + j);
-	    *(data[0] + (i + halfrows) * cols + j) = temp;
-	    temp = *(data[1] + i * cols + j);
-	    *(data[1] + i * cols + j) =
-		*(data[1] + (i + halfrows) * cols + j);
-	    *(data[1] + (i + halfrows) * cols + j) = temp;
-	}
-    }
-
-
-    /* close input cell maps and release the row buffers */
-    fclose(realfp);
-    fclose(imagfp);
-    if (maskfd >= 0) {
-	G_close_cell(maskfd);
-	G_free(maskbuf);
-    }
-
-    /* perform inverse FFT */
-    G_message(_("Starting Inverse FFT..."));
-    fft(1, data, totsize, cols, rows);
-    G_message(_("Inverse FFT completed..."));
-
-    /* set up a window for the transform cell map */
-    G_set_window(&orig_wind);
-
-    /* open the output cell map and allocate a cell row buffer */
-    if ((outputfd = G_open_cell_new(Cellmap_orig)) < 0)
-	G_fatal_error(_("Unable to open output file."));
-
-    cell_row = G_allocate_cell_buf();
-
-    /* Write out result to a new cell map */
-    G_message(_("Writing data to file..."));
-    for (i = 0; i < or; i++) {
-	for (j = 0; j < oc; j++) {
-	    *(cell_row + j) = (CELL) (*(data[0] + i * cols + j) + 0.5);
-	}
-	G_put_raster_row(outputfd, cell_row, CELL_TYPE);
-    }
-    G_close_cell(outputfd);
-
-    G_free(cell_row);
-    {
-	struct Colors colors;
-	struct Range range;
-	CELL min, max;
-
-	/* make a real component color table */
-	G_read_range(Cellmap_orig, G_mapset(), &range);
-	G_get_range_min_max(&range, &min, &max);
-	G_make_grey_scale_colors(&colors, min, max);
-	G_write_colors(Cellmap_orig, G_mapset(), &colors);
-    }
-
-    /* Release memory resources */
-    G_free(data[0]);
-    G_free(data[1]);
-
-    G_done_msg(_("Transform successful."));
-
-    exit(EXIT_SUCCESS);
-}

Copied: grass/trunk/imagery/i.ifft/main.c (from rev 32804, grass/trunk/imagery/i.ifft/ifftmain.c)
===================================================================
--- grass/trunk/imagery/i.ifft/main.c	                        (rev 0)
+++ grass/trunk/imagery/i.ifft/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,246 @@
+/*
+   Central Washington University GIS Laboratory
+   Programmer: David B. Satnik
+   and
+   Programmer : Ali R. Vali
+   Center for Space Research
+   WRW 402
+   University of Texas
+   Austin, TX 78712-1085
+
+   (512) 471-6824
+
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/gmath.h>
+#include "globals.h"
+#include "local_proto.h"
+
+char Cellmap_real[GNAME_MAX], Cellmap_imag[GNAME_MAX];
+
+int main(int argc, char *argv[])
+{
+    /* Global variable & function declarations */
+    char Cellmap_orig[GNAME_MAX];
+    FILE *realfp, *imagfp;	/* the input and output file descriptors */
+    int outputfd, maskfd;	/* the input and output file descriptors */
+    char *realmapset, *imagmapset;	/* the input mapset names */
+    struct Cell_head orig_wind, realhead;
+    CELL *cell_row, *maskbuf = NULL;
+
+    int i, j;			/* Loop control variables */
+    int or, oc;			/* Original dimensions of image */
+    int rows, cols;		/* Smallest powers of 2 >= number of rows & columns */
+    long totsize;		/* Total number of data points */
+    int halfrows, halfcols;
+    double *data[2];		/* Data structure containing real & complex values of FFT */
+    struct Option *op1, *op2, *op3;
+    struct GModule *module;
+
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("imagery");
+    module->description =
+	_("Inverse Fast Fourier Transform (IFFT) for image processing.");
+
+    /* define options */
+    op1 = G_define_option();
+    op1->key = "real_image";
+    op1->type = TYPE_STRING;
+    op1->required = YES;
+    op1->multiple = NO;
+    op1->gisprompt = "old,cell,raster";
+    op1->description = _("Input raster map (image fft, real part)");
+
+    op2 = G_define_option();
+    op2->key = "imaginary_image";
+    op2->type = TYPE_STRING;
+    op2->required = YES;
+    op2->multiple = NO;
+    op2->gisprompt = "old,cell,raster";
+    op2->description = _("Input raster map (image fft, imaginary part");
+
+    op3 = G_define_option();
+    op3->key = "output_image";
+    op3->type = TYPE_STRING;
+    op3->required = YES;
+    op3->multiple = NO;
+    op3->gisprompt = "new,cell,raster";
+    op3->description = _("Output inverse raster map after IFFT");
+
+    /*call parser */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    strcpy(Cellmap_real, op1->answer);
+    strcpy(Cellmap_imag, op2->answer);
+    strcpy(Cellmap_orig, op3->answer);
+
+    /* open input raster map */
+    if ((realmapset = G_find_cell(Cellmap_real, "")) == NULL)
+	G_fatal_error(_("Unable to find the real-image map <%s>"),
+		      Cellmap_real);
+
+    if ((realfp =
+	 G_fopen_old_misc("cell_misc", "fftreal", Cellmap_real,
+			  realmapset)) == NULL)
+	G_fatal_error(_("Unable to open real-image in the cell_misc directory.\nInput map probably wasn't created by i.fft"));
+
+    if ((imagmapset = G_find_cell(Cellmap_imag, "")) == NULL)
+	G_fatal_error(_("Unable to find the imaginary-image <%s>"),
+		      Cellmap_imag);
+
+    if ((imagfp =
+	 G_fopen_old_misc("cell_misc", "fftimag", Cellmap_imag,
+			  imagmapset)) == NULL)
+	G_fatal_error(_("Unable to open imaginary-image in the cell_misc directory.\nInput map probably wasn't created by i.fft"));
+
+    /* check command line args for validity */
+    if (G_legal_filename(Cellmap_orig) < 0)
+	G_fatal_error(_("<%s> is an illegal file name"), Cellmap_orig);
+
+    /* get and compare the original window data */
+    get_orig_window(&orig_wind, realmapset, imagmapset);
+
+    or = orig_wind.rows;
+    oc = orig_wind.cols;
+    G_get_cellhd(Cellmap_real, realmapset, &realhead);
+    G_set_window(&realhead);	/* set the window to the whole cell map */
+
+    /* get the rows and columns in the current window */
+    rows = G_window_rows();
+    cols = G_window_cols();
+    totsize = rows * cols;
+    halfrows = rows / 2;
+    halfcols = cols / 2;
+
+    G_message(_("Power 2 values : [%d] rows [%d] columns."), rows, cols);
+
+    /* Allocate appropriate memory for the structure containing
+       the real and complex components of the FFT.  DATA[0] will
+       contain the real, and DATA[1] the complex component.
+     */
+    data[0] = (double *)G_malloc((rows * cols) * sizeof(double));
+    data[1] = (double *)G_malloc((rows * cols) * sizeof(double));
+    if (data[0] == NULL || data[1] == NULL)
+	G_fatal_error(_("Insufficent memory for allocation of data structure"));
+
+    /* Initialize real & complex components to zero */
+    G_message(_("Reading the raster maps..."));
+    {
+	fread((char *)data[0], sizeof(double), totsize, realfp);
+	fread((char *)data[1], sizeof(double), totsize, imagfp);
+    }
+
+    /* Read in cell map values */
+    G_message(_("Masking the raster maps..."));
+    maskfd = G_maskfd();
+    if (maskfd >= 0)
+	maskbuf = G_allocate_cell_buf();
+
+    if (maskfd >= 0) {
+	for (i = 0; i < rows; i++) {
+	    double *data0, *data1;
+
+	    data0 = data[0] + i * cols;
+	    data1 = data[1] + i * cols;
+	    G_get_map_row(maskfd, maskbuf, i);
+	    for (j = 0; j < cols; j++, data0++, data1++) {
+		if (maskbuf[j] == (CELL) 0) {
+		    *(data0) = 0.0;
+		    *(data1) = 0.0;
+		}
+	    }
+	}
+    }
+
+    G_message(_("Rotating data arrays..."));
+    /* rotate the data array for standard display */
+    for (i = 0; i < rows; i++) {
+	double temp;
+
+	for (j = 0; j < halfcols; j++) {
+	    temp = *(data[0] + i * cols + j);
+	    *(data[0] + i * cols + j) = *(data[0] + i * cols + j + halfcols);
+	    *(data[0] + i * cols + j + halfcols) = temp;
+	    temp = *(data[1] + i * cols + j);
+	    *(data[1] + i * cols + j) = *(data[1] + i * cols + j + halfcols);
+	    *(data[1] + i * cols + j + halfcols) = temp;
+	}
+    }
+    for (i = 0; i < halfrows; i++) {
+	double temp;
+
+	for (j = 0; j < cols; j++) {
+	    temp = *(data[0] + i * cols + j);
+	    *(data[0] + i * cols + j) =
+		*(data[0] + (i + halfrows) * cols + j);
+	    *(data[0] + (i + halfrows) * cols + j) = temp;
+	    temp = *(data[1] + i * cols + j);
+	    *(data[1] + i * cols + j) =
+		*(data[1] + (i + halfrows) * cols + j);
+	    *(data[1] + (i + halfrows) * cols + j) = temp;
+	}
+    }
+
+
+    /* close input cell maps and release the row buffers */
+    fclose(realfp);
+    fclose(imagfp);
+    if (maskfd >= 0) {
+	G_close_cell(maskfd);
+	G_free(maskbuf);
+    }
+
+    /* perform inverse FFT */
+    G_message(_("Starting Inverse FFT..."));
+    fft(1, data, totsize, cols, rows);
+    G_message(_("Inverse FFT completed..."));
+
+    /* set up a window for the transform cell map */
+    G_set_window(&orig_wind);
+
+    /* open the output cell map and allocate a cell row buffer */
+    if ((outputfd = G_open_cell_new(Cellmap_orig)) < 0)
+	G_fatal_error(_("Unable to open output file."));
+
+    cell_row = G_allocate_cell_buf();
+
+    /* Write out result to a new cell map */
+    G_message(_("Writing data to file..."));
+    for (i = 0; i < or; i++) {
+	for (j = 0; j < oc; j++) {
+	    *(cell_row + j) = (CELL) (*(data[0] + i * cols + j) + 0.5);
+	}
+	G_put_raster_row(outputfd, cell_row, CELL_TYPE);
+    }
+    G_close_cell(outputfd);
+
+    G_free(cell_row);
+    {
+	struct Colors colors;
+	struct Range range;
+	CELL min, max;
+
+	/* make a real component color table */
+	G_read_range(Cellmap_orig, G_mapset(), &range);
+	G_get_range_min_max(&range, &min, &max);
+	G_make_grey_scale_colors(&colors, min, max);
+	G_write_colors(Cellmap_orig, G_mapset(), &colors);
+    }
+
+    /* Release memory resources */
+    G_free(data[0]);
+    G_free(data[1]);
+
+    G_done_msg(_("Transform successful."));
+
+    exit(EXIT_SUCCESS);
+}

Copied: grass/trunk/imagery/i.ortho.photo/menu/main.c (from rev 32801, grass/trunk/imagery/i.ortho.photo/menu/menu.c)
===================================================================
--- grass/trunk/imagery/i.ortho.photo/menu/main.c	                        (rev 0)
+++ grass/trunk/imagery/i.ortho.photo/menu/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,134 @@
+
+/****************************************************************************
+ *
+ * MODULE:       menu
+ * AUTHOR(S):    Mike Baba,  DBA Systems, Inc. (original contributor)
+ *               Markus Neteler <neteler itc.it>,
+ *               Roberto Flor <flor itc.it>,
+ *               Bernhard Reiter <bernhard intevation.de>,
+ *               Glynn Clements <glynn gclements.plus.com>
+ * PURPOSE:      main menu system
+ * 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 <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/imagery.h>
+#include <grass/glocale.h>
+#include "orthophoto.h"
+#include "local_proto.h"
+
+int main(int argc, char **argv)
+{
+    char title[80];
+    char buf[80], *p;
+    struct Ortho_Image_Group group;
+    struct GModule *module;
+    struct Option *group_opt;
+
+    /* must run in a term window */
+    G_putenv("GRASS_UI_TERM", "1");
+
+    /* initialize grass */
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("imagery");
+    module->description = _("Menu driver for the photo imagery programs.");
+
+    group_opt = G_define_standard_option(G_OPT_I_GROUP);
+    group_opt->description =
+	_("Name of imagery group for ortho-rectification");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
+    strncpy(group.name, group_opt->answer, 99);
+    group.name[99] = '\0';
+    /* strip off mapset if it's there: I_() fns only work with current mapset */
+    if ((p = strchr(group.name, '@')))
+	*p = 0;
+
+    /* get and check the group reference files */
+    if (!I_get_group_ref(group.name, &group.group_ref)) {
+	G_warning("Pre-selected group <%s> not found.", group.name);
+	/* clean the wrong name in GROUPFILE */
+	I_put_group("");
+
+	/* ask for new group name */
+	if (!I_ask_group_old
+	    ("Enter imagery group for ortho-rectification", group.name))
+	    exit(0);
+	I_get_group_ref(group.name, &group.group_ref);
+    }
+
+    if (group.group_ref.nfiles <= 0)
+	G_fatal_error("Group [%s] contains no files\n", group.name);
+
+    I_put_group(group.name);
+
+    while (1) {
+	if (!I_get_group(group.name)) {
+	    exit(0);
+	}
+
+	/* print the screen full of options */
+	sprintf(title, "i.ortho.photo -- \tImagery Group = %s ", group.name);
+	G_clear_screen();
+
+	fprintf(stderr, "%s\n\n", title);
+	fprintf(stderr, "Initialization Options:\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "   1.     Select/Modify imagery group\n");
+	fprintf(stderr, "   2.     Select/Modify imagery group target\n");
+	fprintf(stderr, "   3.     Select/Modify target elevation model\n");
+	fprintf(stderr, "   4.     Select/Modify imagery group camera\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Transformation Parameter Computations:\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "   5.     Compute image-to-photo transformation\n");
+	fprintf(stderr, "   6.     Initialize exposure station parameters\n");
+	fprintf(stderr, "   7.     Compute ortho-rectification parameters\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "Ortho-rectification Option:\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "   8.     Ortho-rectify imagery files\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "RETURN   exit\n");
+	fprintf(stderr, "\n> ");
+
+	/* Get the option */
+	if (!G_gets(buf))
+	    continue;
+	if (*buf == 0)		/* exit */
+	    exit(0);
+
+	/* run the program choosen */
+	G_strip(buf);
+	fprintf(stderr, "<%s>\n", buf);
+	if (strcmp(buf, "1") == 0)
+	    run_system("i.group");
+	if (strcmp(buf, "2") == 0)
+	    run_etc_imagery("photo.target", group.name);
+	if (strcmp(buf, "3") == 0)
+	    run_etc_imagery("photo.elev", group.name);
+	if (strcmp(buf, "4") == 0)
+	    run_etc_imagery("photo.camera", group.name);
+	if (strcmp(buf, "5") == 0)
+	    run_etc_imagery("photo.2image", group.name);
+	if (strcmp(buf, "6") == 0)
+	    run_etc_imagery("photo.init", group.name);
+	if (strcmp(buf, "7") == 0)
+	    run_etc_imagery("photo.2target", group.name);
+	if (strcmp(buf, "8") == 0)
+	    run_etc_imagery("photo.rectify", group.name);
+    }
+}

Deleted: grass/trunk/imagery/i.ortho.photo/menu/menu.c
===================================================================
--- grass/trunk/imagery/i.ortho.photo/menu/menu.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/imagery/i.ortho.photo/menu/menu.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,134 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       menu
- * AUTHOR(S):    Mike Baba,  DBA Systems, Inc. (original contributor)
- *               Markus Neteler <neteler itc.it>,
- *               Roberto Flor <flor itc.it>,
- *               Bernhard Reiter <bernhard intevation.de>,
- *               Glynn Clements <glynn gclements.plus.com>
- * PURPOSE:      main menu system
- * 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 <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/imagery.h>
-#include <grass/glocale.h>
-#include "orthophoto.h"
-#include "local_proto.h"
-
-int main(int argc, char **argv)
-{
-    char title[80];
-    char buf[80], *p;
-    struct Ortho_Image_Group group;
-    struct GModule *module;
-    struct Option *group_opt;
-
-    /* must run in a term window */
-    G_putenv("GRASS_UI_TERM", "1");
-
-    /* initialize grass */
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("imagery");
-    module->description = _("Menu driver for the photo imagery programs.");
-
-    group_opt = G_define_standard_option(G_OPT_I_GROUP);
-    group_opt->description =
-	_("Name of imagery group for ortho-rectification");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-
-    strncpy(group.name, group_opt->answer, 99);
-    group.name[99] = '\0';
-    /* strip off mapset if it's there: I_() fns only work with current mapset */
-    if ((p = strchr(group.name, '@')))
-	*p = 0;
-
-    /* get and check the group reference files */
-    if (!I_get_group_ref(group.name, &group.group_ref)) {
-	G_warning("Pre-selected group <%s> not found.", group.name);
-	/* clean the wrong name in GROUPFILE */
-	I_put_group("");
-
-	/* ask for new group name */
-	if (!I_ask_group_old
-	    ("Enter imagery group for ortho-rectification", group.name))
-	    exit(0);
-	I_get_group_ref(group.name, &group.group_ref);
-    }
-
-    if (group.group_ref.nfiles <= 0)
-	G_fatal_error("Group [%s] contains no files\n", group.name);
-
-    I_put_group(group.name);
-
-    while (1) {
-	if (!I_get_group(group.name)) {
-	    exit(0);
-	}
-
-	/* print the screen full of options */
-	sprintf(title, "i.ortho.photo -- \tImagery Group = %s ", group.name);
-	G_clear_screen();
-
-	fprintf(stderr, "%s\n\n", title);
-	fprintf(stderr, "Initialization Options:\n");
-	fprintf(stderr, "\n");
-	fprintf(stderr, "   1.     Select/Modify imagery group\n");
-	fprintf(stderr, "   2.     Select/Modify imagery group target\n");
-	fprintf(stderr, "   3.     Select/Modify target elevation model\n");
-	fprintf(stderr, "   4.     Select/Modify imagery group camera\n");
-	fprintf(stderr, "\n");
-	fprintf(stderr, "Transformation Parameter Computations:\n");
-	fprintf(stderr, "\n");
-	fprintf(stderr, "   5.     Compute image-to-photo transformation\n");
-	fprintf(stderr, "   6.     Initialize exposure station parameters\n");
-	fprintf(stderr, "   7.     Compute ortho-rectification parameters\n");
-	fprintf(stderr, "\n");
-	fprintf(stderr, "Ortho-rectification Option:\n");
-	fprintf(stderr, "\n");
-	fprintf(stderr, "   8.     Ortho-rectify imagery files\n");
-	fprintf(stderr, "\n");
-	fprintf(stderr, "RETURN   exit\n");
-	fprintf(stderr, "\n> ");
-
-	/* Get the option */
-	if (!G_gets(buf))
-	    continue;
-	if (*buf == 0)		/* exit */
-	    exit(0);
-
-	/* run the program choosen */
-	G_strip(buf);
-	fprintf(stderr, "<%s>\n", buf);
-	if (strcmp(buf, "1") == 0)
-	    run_system("i.group");
-	if (strcmp(buf, "2") == 0)
-	    run_etc_imagery("photo.target", group.name);
-	if (strcmp(buf, "3") == 0)
-	    run_etc_imagery("photo.elev", group.name);
-	if (strcmp(buf, "4") == 0)
-	    run_etc_imagery("photo.camera", group.name);
-	if (strcmp(buf, "5") == 0)
-	    run_etc_imagery("photo.2image", group.name);
-	if (strcmp(buf, "6") == 0)
-	    run_etc_imagery("photo.init", group.name);
-	if (strcmp(buf, "7") == 0)
-	    run_etc_imagery("photo.2target", group.name);
-	if (strcmp(buf, "8") == 0)
-	    run_etc_imagery("photo.rectify", group.name);
-    }
-}

Copied: grass/trunk/imagery/i.rgb.his/main.c (from rev 32801, grass/trunk/imagery/i.rgb.his/r2hmain.c)
===================================================================
--- grass/trunk/imagery/i.rgb.his/main.c	                        (rev 0)
+++ grass/trunk/imagery/i.rgb.his/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,108 @@
+
+/****************************************************************************
+ *
+ * MODULE:       i.rgb.his
+ *
+ * AUTHOR(S):    David Satnik, GIS Laboratory, Central Washington University
+ *               with acknowledgements to Ali Vali,
+ *               Univ. of Texas Space Research Center, for the core routine. 
+ *               
+ * PURPOSE:      Red-green-blue (rgb) to hue-intensity-saturation (his) 
+ *               raster map color transformation function
+ *
+ * COPYRIGHT:    (C) 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "globals.h"
+
+int main(int argc, char **argv)
+{
+    long i;
+    int band, rows, cols;
+    CELL *rowbuffer[3];
+    struct Option *opt_hue, *opt_red;
+    struct Option *opt_inten, *opt_green;
+    struct Option *opt_sat, *opt_blue;
+    struct GModule *module;
+    int fd_input[3];
+    int fd_output[3];
+
+    /* Initialize GIS engine */
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("imagery");
+    module->description =
+	_("Red-green-blue (rgb) to hue-intensity-saturation (his) raster "
+	  "map color transformation function");
+
+    /* Define the different options */
+    opt_red = G_define_standard_option(G_OPT_R_INPUT);
+    opt_red->key = "red_input";
+    opt_red->description = _("Red input raster map");
+
+    opt_green = G_define_standard_option(G_OPT_R_INPUT);
+    opt_green->key = "green_input";
+    opt_green->description = _("Green input raster map");
+
+    opt_blue = G_define_standard_option(G_OPT_R_INPUT);
+    opt_blue->key = "blue_input";
+    opt_blue->description = _("Blue input raster map");
+
+    opt_hue = G_define_standard_option(G_OPT_R_OUTPUT);
+    opt_hue->key = "hue_output";
+    opt_hue->description = _("Output hue raster map");
+
+    opt_inten = G_define_standard_option(G_OPT_R_OUTPUT);
+    opt_inten->key = "intensity_output";
+    opt_inten->description = _("Output intensity raster map");
+
+    opt_sat = G_define_standard_option(G_OPT_R_OUTPUT);
+    opt_sat->key = "saturation_output";
+    opt_sat->description = _("Output saturation raster map");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    /* get dimension of the image */
+    rows = G_window_rows();
+    cols = G_window_cols();
+
+    openfiles(opt_red->answer, opt_green->answer, opt_blue->answer,
+	      opt_hue->answer, opt_inten->answer, opt_sat->answer,
+	      fd_input, fd_output, rowbuffer);
+
+    for (i = 0; i < rows; i++) {
+	/* read in a row from each cell map */
+	G_percent(i, rows, 2);
+
+	for (band = 0; band < 3; band++)
+	    if (G_get_map_row(fd_input[band], rowbuffer[band], i) < 0)
+		G_fatal_error(_("Cannot read row from raster map"));
+
+	/* process this row of the map */
+	rgb2his(rowbuffer, cols);
+
+	/* write out the new row for each cell map */
+	for (band = 0; band < 3; band++)
+	    if (G_put_raster_row(fd_output[band], rowbuffer[band], CELL_TYPE)
+		< 0)
+		G_fatal_error(_("Cannot write row to raster map"));
+    }
+
+    closefiles(opt_hue->answer, opt_inten->answer, opt_sat->answer,
+	       fd_output, rowbuffer);
+
+    exit(EXIT_SUCCESS);
+}

Deleted: grass/trunk/imagery/i.rgb.his/r2hmain.c
===================================================================
--- grass/trunk/imagery/i.rgb.his/r2hmain.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/imagery/i.rgb.his/r2hmain.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,108 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       i.rgb.his
- *
- * AUTHOR(S):    David Satnik, GIS Laboratory, Central Washington University
- *               with acknowledgements to Ali Vali,
- *               Univ. of Texas Space Research Center, for the core routine. 
- *               
- * PURPOSE:      Red-green-blue (rgb) to hue-intensity-saturation (his) 
- *               raster map color transformation function
- *
- * COPYRIGHT:    (C) 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "globals.h"
-
-int main(int argc, char **argv)
-{
-    long i;
-    int band, rows, cols;
-    CELL *rowbuffer[3];
-    struct Option *opt_hue, *opt_red;
-    struct Option *opt_inten, *opt_green;
-    struct Option *opt_sat, *opt_blue;
-    struct GModule *module;
-    int fd_input[3];
-    int fd_output[3];
-
-    /* Initialize GIS engine */
-    G_gisinit(argv[0]);
-
-    /* Set description */
-    module = G_define_module();
-    module->keywords = _("imagery");
-    module->description =
-	_("Red-green-blue (rgb) to hue-intensity-saturation (his) raster "
-	  "map color transformation function");
-
-    /* Define the different options */
-    opt_red = G_define_standard_option(G_OPT_R_INPUT);
-    opt_red->key = "red_input";
-    opt_red->description = _("Red input raster map");
-
-    opt_green = G_define_standard_option(G_OPT_R_INPUT);
-    opt_green->key = "green_input";
-    opt_green->description = _("Green input raster map");
-
-    opt_blue = G_define_standard_option(G_OPT_R_INPUT);
-    opt_blue->key = "blue_input";
-    opt_blue->description = _("Blue input raster map");
-
-    opt_hue = G_define_standard_option(G_OPT_R_OUTPUT);
-    opt_hue->key = "hue_output";
-    opt_hue->description = _("Output hue raster map");
-
-    opt_inten = G_define_standard_option(G_OPT_R_OUTPUT);
-    opt_inten->key = "intensity_output";
-    opt_inten->description = _("Output intensity raster map");
-
-    opt_sat = G_define_standard_option(G_OPT_R_OUTPUT);
-    opt_sat->key = "saturation_output";
-    opt_sat->description = _("Output saturation raster map");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    /* get dimension of the image */
-    rows = G_window_rows();
-    cols = G_window_cols();
-
-    openfiles(opt_red->answer, opt_green->answer, opt_blue->answer,
-	      opt_hue->answer, opt_inten->answer, opt_sat->answer,
-	      fd_input, fd_output, rowbuffer);
-
-    for (i = 0; i < rows; i++) {
-	/* read in a row from each cell map */
-	G_percent(i, rows, 2);
-
-	for (band = 0; band < 3; band++)
-	    if (G_get_map_row(fd_input[band], rowbuffer[band], i) < 0)
-		G_fatal_error(_("Cannot read row from raster map"));
-
-	/* process this row of the map */
-	rgb2his(rowbuffer, cols);
-
-	/* write out the new row for each cell map */
-	for (band = 0; band < 3; band++)
-	    if (G_put_raster_row(fd_output[band], rowbuffer[band], CELL_TYPE)
-		< 0)
-		G_fatal_error(_("Cannot write row to raster map"));
-    }
-
-    closefiles(opt_hue->answer, opt_inten->answer, opt_sat->answer,
-	       fd_output, rowbuffer);
-
-    exit(EXIT_SUCCESS);
-}

Deleted: grass/trunk/raster/r.circle/dist.c
===================================================================
--- grass/trunk/raster/r.circle/dist.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/raster/r.circle/dist.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,184 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       r.cats
- *
- * AUTHOR(S):    Bill Brown - CERL (Jan, 1993)
- *               Markus Neteler
- *
- * PURPOSE:      Creates a raster map containing concentric rings
- *	         around a given point.
- *
- * COPYRIGHT:    (C) 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 <strings.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-typedef int FILEDESC;
-static double distance(double *, double *, double, double, int);
-
-#ifndef HUGE_VAL
-#define HUGE_VAL        1.7976931348623157e+308
-#endif
-
-
-int main(int argc, char *argv[])
-{
-
-    struct GModule *module;
-    struct Option *coord, *out_file, *min, *max, *mult;
-    struct Flag *flag;
-    int *int_buf;
-    struct Cell_head w;
-    struct History history;
-    FILEDESC cellfile = (FILEDESC) NULL;
-    double east, north, pt[2], cur[2], row, col, fmult;
-    double fmin, fmax;
-    int binary;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("raster");
-    module->description =
-	_("Creates a raster map containing concentric "
-	  "rings around a given point.");
-
-    out_file = G_define_standard_option(G_OPT_R_OUTPUT);
-
-    coord = G_define_option();
-    coord->key = "coordinate";
-    coord->type = TYPE_STRING;
-    coord->required = YES;
-    coord->key_desc = "x,y";
-    coord->description = _("The coordinate of the center (east,north)");
-
-    min = G_define_option();
-    min->key = "min";
-    min->type = TYPE_DOUBLE;
-    min->required = NO;
-    min->description = _("Minimum radius for ring/circle map (in meters)");
-
-    max = G_define_option();
-    max->key = "max";
-    max->type = TYPE_DOUBLE;
-    max->required = NO;
-    max->description = _("Maximum radius for ring/circle map (in meters)");
-
-    mult = G_define_option();
-    mult->key = "mult";
-    mult->type = TYPE_DOUBLE;
-    mult->required = NO;
-    mult->description = _("Data value multiplier");
-
-    flag = G_define_flag();
-    flag->key = 'b';
-    flag->description = _("Generate binary raster map");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    G_scan_easting(coord->answers[0], &east, G_projection());
-    G_scan_northing(coord->answers[1], &north, G_projection());
-    pt[0] = east;
-    pt[1] = north;
-
-    fmult = 1.0;
-
-    if (min->answer)
-	sscanf(min->answer, "%lf", &fmin);
-    else
-	fmin = 0;
-
-    if (max->answer)
-	sscanf(max->answer, "%lf", &fmax);
-    else
-	fmax = HUGE_VAL;
-
-    if (fmin > fmax)
-	G_fatal_error(_("Please specify a radius in which min < max"));
-
-    if (mult->answer)
-	if (1 != sscanf(mult->answer, "%lf", &fmult))
-	    fmult = 1.0;
-
-    /* nonsense test */
-    if (flag->answer && (!min->answer && !max->answer))
-	G_fatal_error(_("Please specify min and/or max radius when "
-			"using the binary flag"));
-
-    if (flag->answer)
-	binary = 1;		/* generate binary pattern only, useful for MASK */
-    else
-	binary = 0;
-
-    G_get_set_window(&w);
-
-    if ((cellfile = G_open_cell_new(out_file->answer)) == -1)
-	G_fatal_error(_("Unable to create raster map <%s>"),
-		      out_file->answer);
-
-    int_buf = (int *)G_malloc(w.cols * sizeof(int));
-    {
-	int c;
-
-	for (row = 0; row < w.rows; row++) {
-	    G_percent(row, w.rows, 2);
-	    cur[1] = G_row_to_northing(row + 0.5, &w);
-	    for (col = 0; col < w.cols; col++) {
-		c = col;
-		cur[0] = G_col_to_easting(col + 0.5, &w);
-		int_buf[c] =
-		    (int)(distance(pt, cur, fmin, fmax, binary) * fmult);
-		if (int_buf[c] == 0)
-		    G_set_null_value(&int_buf[c], 1, CELL_TYPE);
-	    }
-	    G_put_raster_row(cellfile, int_buf, CELL_TYPE);
-
-	}
-    }
-    G_free(int_buf);
-    G_close_cell(cellfile);
-    G_short_history(out_file->answer, "raster", &history);
-    G_command_history(&history);
-    G_write_history(out_file->answer, &history);
-
-    return (EXIT_SUCCESS);
-}
-
-
-
-/*******************************************************************/
-
-static double distance(double from[2], double to[2], double min, double max,
-		       int binary)
-{
-    static int first = 1;
-    double dist;
-
-    if (first) {
-	first = 0;
-	G_begin_distance_calculations();
-    }
-
-    dist = G_distance(from[0], from[1], to[0], to[1]);
-
-    if ((dist >= min) && (dist <= max))
-	if (!binary)
-	    return dist;
-	else
-	    return 1;
-    else
-	return 0;		/* should be NULL ? */
-}
-
-/**********************************************************************/

Copied: grass/trunk/raster/r.circle/main.c (from rev 32801, grass/trunk/raster/r.circle/dist.c)
===================================================================
--- grass/trunk/raster/r.circle/main.c	                        (rev 0)
+++ grass/trunk/raster/r.circle/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,184 @@
+
+/****************************************************************************
+ *
+ * MODULE:       r.cats
+ *
+ * AUTHOR(S):    Bill Brown - CERL (Jan, 1993)
+ *               Markus Neteler
+ *
+ * PURPOSE:      Creates a raster map containing concentric rings
+ *	         around a given point.
+ *
+ * COPYRIGHT:    (C) 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 <strings.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+typedef int FILEDESC;
+static double distance(double *, double *, double, double, int);
+
+#ifndef HUGE_VAL
+#define HUGE_VAL        1.7976931348623157e+308
+#endif
+
+
+int main(int argc, char *argv[])
+{
+
+    struct GModule *module;
+    struct Option *coord, *out_file, *min, *max, *mult;
+    struct Flag *flag;
+    int *int_buf;
+    struct Cell_head w;
+    struct History history;
+    FILEDESC cellfile = (FILEDESC) NULL;
+    double east, north, pt[2], cur[2], row, col, fmult;
+    double fmin, fmax;
+    int binary;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("raster");
+    module->description =
+	_("Creates a raster map containing concentric "
+	  "rings around a given point.");
+
+    out_file = G_define_standard_option(G_OPT_R_OUTPUT);
+
+    coord = G_define_option();
+    coord->key = "coordinate";
+    coord->type = TYPE_STRING;
+    coord->required = YES;
+    coord->key_desc = "x,y";
+    coord->description = _("The coordinate of the center (east,north)");
+
+    min = G_define_option();
+    min->key = "min";
+    min->type = TYPE_DOUBLE;
+    min->required = NO;
+    min->description = _("Minimum radius for ring/circle map (in meters)");
+
+    max = G_define_option();
+    max->key = "max";
+    max->type = TYPE_DOUBLE;
+    max->required = NO;
+    max->description = _("Maximum radius for ring/circle map (in meters)");
+
+    mult = G_define_option();
+    mult->key = "mult";
+    mult->type = TYPE_DOUBLE;
+    mult->required = NO;
+    mult->description = _("Data value multiplier");
+
+    flag = G_define_flag();
+    flag->key = 'b';
+    flag->description = _("Generate binary raster map");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    G_scan_easting(coord->answers[0], &east, G_projection());
+    G_scan_northing(coord->answers[1], &north, G_projection());
+    pt[0] = east;
+    pt[1] = north;
+
+    fmult = 1.0;
+
+    if (min->answer)
+	sscanf(min->answer, "%lf", &fmin);
+    else
+	fmin = 0;
+
+    if (max->answer)
+	sscanf(max->answer, "%lf", &fmax);
+    else
+	fmax = HUGE_VAL;
+
+    if (fmin > fmax)
+	G_fatal_error(_("Please specify a radius in which min < max"));
+
+    if (mult->answer)
+	if (1 != sscanf(mult->answer, "%lf", &fmult))
+	    fmult = 1.0;
+
+    /* nonsense test */
+    if (flag->answer && (!min->answer && !max->answer))
+	G_fatal_error(_("Please specify min and/or max radius when "
+			"using the binary flag"));
+
+    if (flag->answer)
+	binary = 1;		/* generate binary pattern only, useful for MASK */
+    else
+	binary = 0;
+
+    G_get_set_window(&w);
+
+    if ((cellfile = G_open_cell_new(out_file->answer)) == -1)
+	G_fatal_error(_("Unable to create raster map <%s>"),
+		      out_file->answer);
+
+    int_buf = (int *)G_malloc(w.cols * sizeof(int));
+    {
+	int c;
+
+	for (row = 0; row < w.rows; row++) {
+	    G_percent(row, w.rows, 2);
+	    cur[1] = G_row_to_northing(row + 0.5, &w);
+	    for (col = 0; col < w.cols; col++) {
+		c = col;
+		cur[0] = G_col_to_easting(col + 0.5, &w);
+		int_buf[c] =
+		    (int)(distance(pt, cur, fmin, fmax, binary) * fmult);
+		if (int_buf[c] == 0)
+		    G_set_null_value(&int_buf[c], 1, CELL_TYPE);
+	    }
+	    G_put_raster_row(cellfile, int_buf, CELL_TYPE);
+
+	}
+    }
+    G_free(int_buf);
+    G_close_cell(cellfile);
+    G_short_history(out_file->answer, "raster", &history);
+    G_command_history(&history);
+    G_write_history(out_file->answer, &history);
+
+    return (EXIT_SUCCESS);
+}
+
+
+
+/*******************************************************************/
+
+static double distance(double from[2], double to[2], double min, double max,
+		       int binary)
+{
+    static int first = 1;
+    double dist;
+
+    if (first) {
+	first = 0;
+	G_begin_distance_calculations();
+    }
+
+    dist = G_distance(from[0], from[1], to[0], to[1]);
+
+    if ((dist >= min) && (dist <= max))
+	if (!binary)
+	    return dist;
+	else
+	    return 1;
+    else
+	return 0;		/* should be NULL ? */
+}
+
+/**********************************************************************/

Deleted: grass/trunk/raster/r.flow/calc.c
===================================================================
--- grass/trunk/raster/r.flow/calc.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/raster/r.flow/calc.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,596 +0,0 @@
-/*
- **  Original Algorithm:    H. Mitasova, L. Mitas, J. Hofierka, M. Zlocha 
- **  New GRASS Implementation:  J. Caplan, M. Ruesink  1995
- **
- **  US Army Construction Engineering Research Lab, University of Illinois 
- **
- **  Copyright  J. Caplan, H. Mitasova, L. Mitas, M.Ruesink, J. Hofierka, 
- **     M. Zlocha  1995
- **
- **This program is free software; you can redistribute it and/or
- **modify it under the terms of the GNU General Public License
- **as published by the Free Software Foundation; either version 2
- **of the License, or (at your option) any later version.
- **
- **This program is distributed in the hope that it will be useful,
- **but WITHOUT ANY WARRANTY; without even the implied warranty of
- **MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- **GNU General Public License for more details.
- **
- **You should have received a copy of the GNU General Public License
- **along with this program; if not, write to the Free Software
- **Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
- **
- **  version 13 for GRASS5.0
- **  FP related bugs in slope length output fixed by Helena oct. 1999)
- **  Update MN: commented line 387
- */
-
-#include <stdlib.h>		/* for the random number generation */
-#include <time.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "r.flow.h"
-#include "mem.h"
-#include "io.h"
-#include "aspect.h"
-#include "precomp.h"
-
-#define HORIZ	1		/* \            */
-#define VERT	0		/* |            */
-#define EAST	1		/* |            */
-#define WEST	0		/* |_ magic     */
-#define NORTH	1		/* |  numbers   */
-#define SOUTH	0		/* |            */
-#define ROW	1		/* |            */
-#define COL	0		/* /            */
-
-CELL v;				/* address for segment retrieval macros */
-
-/* heap memory */
-struct Cell_head region;	/* resolution and boundaries            */
-struct Map_info fl;		/* output vector file header            */
-struct BM *bitbar;		/* space-efficient barrier matrix       */
-int lgfd;			/* output length file descriptor        */
-char string[1024];		/* space for strings                    */
-layer el, as, ds;		/* elevation, aspect, density           */
-double *ew_dist;		/* east-west distances for rows         */
-double *epsilon[2];		/* quantization errors for rows         */
-
-/* command-line parameters */
-params parm;
-
-typedef struct
-{
-    int row, col;		/* current matrix address       */
-}
-addr;
-
-typedef int bbox[2][2];		/* current bounding box         */
-
-typedef struct
-{
-    double x, y, z;		/* exact earth coordinates      */
-    double theta;		/* aspect                       */
-    double r, c;		/* cell matrix coordinates      */
-}
-point;
-
-typedef struct
-{
-    double *px, *py;		/* x/y point arrays             */
-    int index;			/* index of next point          */
-}
-flowline;
-
-/***************************** CALCULATION ******************************/
-
-/*
- * height_angle_bounding_box: averages matrix values at sub between
- *      floor(cut) and ceil(cut), based on proximity; adjusts bbox
- * globals r: o, z, parm
- * params  w: p, b
- */
-static void
-height_angle_bounding_box(int sub, double cut, int horiz, point * p, bbox b)
-{
-    int c, f = (int)cut;
-    double r = cut - (double)f;
-    double a1, a2, a, d;
-
-    b[horiz][horiz] = sub - 1;
-    b[horiz][!horiz] = sub + 1;
-    b[!horiz][horiz] = f + 1;
-    c = (b[!horiz][!horiz] = f - (r == 0.)) + 1;
-
-    if (horiz) {
-	a1 = (double)aspect(sub, f);
-	a2 = (double)aspect(sub, c);
-	p->z = (double)get(el, sub, f) * (1. - r) +
-	    (double)get(el, sub, c) * r;
-    }
-    else {
-	a1 = (double)aspect(f, sub);
-	a2 = (double)aspect(c, sub);
-	p->z = (double)get(el, f, sub) * (1. - r) +
-	    (double)get(el, c, sub) * r;
-    }
-
-    if (!(a1 == UNDEF || a2 == UNDEF) &&
-	!(G_is_d_null_value(&a1) || G_is_d_null_value(&a2)))
-	/*    if (!(G_is_d_null_value(&a1) || G_is_d_null_value(&a2))) */
-    {
-	if ((d = a1 - a2) >= D_PI || d <= -D_PI) {
-	    if (a2 > D_PI)
-		a2 -= D2_PI;
-	    else
-		a1 -= D2_PI;
-	}
-	a = r * a2 + (1. - r) * a1;
-	p->theta = a + (a < 0.) * D2_PI;
-    }
-    else
-	p->theta = UNDEF;
-
-    return;
-}
-
-/*
- * sloping: returns elevation condition for continuing current line
- */
-#define sloping(z1, z2) (z1 > z2)
-
-/*
- * on_map: returns map boundary condition for continuing current line
- * globals r:  region
- */
-static int on_map(int sub, double cut, int horiz)
-{
-    return
-	(sub >= 0 && cut >= 0.0 &&
-	 ((horiz && sub < region.rows && cut <= (double)(region.cols - 1)) ||
-	  (!horiz && sub < region.cols && cut <= (double)(region.rows - 1))));
-}
-
-/*
- * add_to_line: puts a new point on the end of the current flowline
- * globals r:  parm
- * params  w:  f
- */
-static void add_to_line(point * p, flowline * f)
-{
-    if (parm.flout) {
-	f->px[f->index] = (double)p->x;
-	f->py[f->index] = (double)p->y;
-    }
-    ++f->index;
-}
-
-/*
- * rectify: correct quantization problems (designed for speed, not elegance)
- */
-static double rectify(double delta, double bd[2], double e)
-{
-    if (delta > 0.) {
-	if (delta > bd[1] + e)
-	    return delta;
-    }
-    else {
-	if (delta < bd[0] - e)
-	    return delta;
-    }
-    if (delta < bd[1] - e)
-	if (delta > bd[0] + e)
-	    return delta;
-	else
-	    return bd[0];
-    else
-	return bd[1];
-}
-
-/*
- * next_point: computes next point based on current point, z, and o
- *      returns continuation condition
- * globals r:  region, bitbar, parm
- * params  w:  p, a, l
- * globals w:  density
- */
-static int next_point(point * p,	/* current/next point               */
-		      addr * a,	/* current/next matrix address      */
-		      bbox b,	/* current/next bounding box        */
-		      double *l	/* current/eventual length          */
-    )
-{
-    int sub;
-    double cut;
-    int horiz;
-    int semi;
-    double length, delta;
-    double deltaz;
-    double tangent;
-
-    double oldz = p->z;
-    double oldtheta = p->theta;
-    double oldr = p->r;
-    double oldc = p->c;
-
-    addr ads;
-    double bdy[2], bdx[2];
-
-    ads = *a;
-    bdy[SOUTH] = (double)(oldr - b[ROW][SOUTH]) * region.ns_res;
-    bdy[NORTH] = (double)(oldr - b[ROW][NORTH]) * region.ns_res;
-    bdx[WEST] = (double)(b[COL][WEST] - oldc) * ew_dist[ads.row];
-    bdx[EAST] = (double)(b[COL][EAST] - oldc) * ew_dist[ads.row];
-
-    semi = oldtheta < 90 || oldtheta >= 270;
-    tangent = tan(oldtheta * DEG2RAD);
-
-    if (oldtheta != 90 && oldtheta != 270 &&	/* north/south */
-	(delta = (bdy[semi] * tangent)) < bdx[EAST] && delta > bdx[WEST]) {
-	delta = rectify(delta, bdx, epsilon[HORIZ][ads.row]);
-	p->x += delta;
-	p->y += bdy[semi];
-	p->r = (double)b[ROW][semi];
-	p->c += delta / ew_dist[ads.row];
-	a->row = b[ROW][semi];
-	a->col = ROUND(p->c);
-	sub = b[ROW][semi];
-	cut = p->c;
-	horiz = HORIZ;
-	if (parm.lgout)
-	    length = hypot(delta, bdy[semi]);
-    }
-    else {			/*  east/west  */
-
-	semi = oldtheta < 180;
-	if (oldtheta == 90 || oldtheta == 270)
-	    delta = 0;
-	else {
-	    /* I don't know if this is right case.
-	     * Anyway, should be avoid from dividing by zero.
-	     * Any hydrologic idea?
-	     */
-	    if (tangent == 0.0)
-		tangent = 0.000001;
-
-	    delta = bdx[semi] / tangent;
-	}
-
-	delta = rectify(delta, bdy, epsilon[VERT][ads.row]);
-	p->y += delta;
-	p->x += bdx[semi];
-	p->r -= delta / region.ns_res;
-	p->c = (double)b[COL][semi];
-	a->row = ROUND(p->r);
-	a->col = b[COL][semi];
-	sub = b[COL][semi];
-	cut = p->r;
-	horiz = VERT;
-	if (parm.lgout)
-	    length = hypot(bdx[semi], delta);
-    }
-
-    if (on_map(sub, cut, horiz) &&
-	(height_angle_bounding_box(sub, cut, horiz, p, b),
-	 sloping(oldz, p->z)) &&
-	!(parm.barin && BM_get(bitbar, a->col, a->row))) {
-	if (parm.dsout && (ads.row != a->row || ads.col != a->col))
-	    put(ds, a->row, a->col, get(ds, a->row, a->col) + 1);
-	/*      if (parm.lgout) 
-	 *      *l += parm.l3d ? hypot(length, oldz - p->z) : length; this did not work, helena*/
-	if (parm.lgout) {
-	    if (parm.l3d) {
-		deltaz = oldz - p->z;	/*fix by helena Dec. 06 */
-		*l += hypot(length, deltaz);
-	    }
-	    else
-		*l += length;
-	}
-	return 1;
-    }
-
-    return 0;
-}
-
-/*
- * calculate: create a flowline for each cell
- * globals r: region, bitbar, parm, lgfd
- */
-static void calculate(void)
-{
-    point pts;
-    addr ads;
-    bbox bbs;
-    flowline fls;
-    int row, col;
-
-    /*    double     x, y, length, xstep, ystep, roffset, coffset; */
-    double x, y, length, xstep, ystep;
-    FCELL *lg = G_allocate_f_raster_buf();
-    struct line_pnts *points = Vect_new_line_struct();
-    struct line_cats *cats = Vect_new_cats_struct();
-    int loopstep = (!parm.dsout && !parm.lgout && parm.flout) ? parm.skip : 1;
-
-    G_message(_("Calculating maps ..."));
-
-    fls.px = (double *)G_calloc(parm.bound, sizeof(double));
-    fls.py = (double *)G_calloc(parm.bound, sizeof(double));
-
-    ystep = region.ns_res * (double)loopstep;
-
-    srand(time(0));
-
-    for (row = 0, y = (double)region.north - (region.ns_res * .5);
-	 row < region.rows; row += loopstep, y -= ystep) {
-	xstep = ew_dist[row] * (double)loopstep;
-	G_percent(row, region.rows, 2);
-
-	for (col = 0, x = (double)region.west + (ew_dist[row] * .5);
-	     col < region.cols; col += loopstep, x += xstep) {
-
-	    length = 0.0;
-	    fls.index = 0;
-
-	    if (!(parm.barin && BM_get(bitbar, col, row))) {
-#ifdef OFFSET
-		/* disabled by helena June 2005 */
-		roffset = parm.offset * (double)region.ew_res
-		    * ((2. * (double)rand() / (double)RAND_MAX) - 1.);
-		coffset = parm.offset * (double)region.ns_res
-		    * ((2. * (double)rand() / (double)RAND_MAX) - 1.);
-#endif
-		pts.x = x;
-		pts.y = y;
-		pts.z = (double)get(el, row, col);
-		pts.theta = (double)aspect(row, col);
-		pts.r = (double)row;	/* + roffset; */
-		pts.c = (double)col;	/*+ coffset; */
-
-		ads.row = row;
-		ads.col = col;
-
-#ifdef OFFSET
-		G_debug(3, "dx: %f  x: %f %f  row: %f %f\n",
-			roffset, x, pts.x, (double)row, pts.r);
-		G_debug(3, "dy: %f  y: %f %f  col: %f %f\n",
-			roffset, y, pts.y, (double)col, pts.c);
-#endif
-
-		bbs[ROW][SOUTH] = row + 1;
-		bbs[ROW][NORTH] = row - 1;
-		bbs[COL][WEST] = col - 1;
-		bbs[COL][EAST] = col + 1;
-
-		do
-		    add_to_line(&pts, &fls);
-		while (fls.index <= parm.bound &&
-		       (pts.z != UNDEFZ && pts.theta >= 0 && pts.theta <= 360)
-		       &&
-		       /*  (!G_is_d_null_value(&pts.z) && pts.theta != UNDEF) && */
-		       next_point(&pts, &ads, bbs, &length));
-	    }
-
-	    if (fls.index > 1 && parm.flout &&
-		(loopstep == parm.skip ||
-		 !(row % parm.skip || col % parm.skip))) {
-		Vect_copy_xyz_to_pnts(points, fls.px, fls.py, NULL,
-				      fls.index);
-		Vect_write_line(&fl, GV_LINE, points, cats);
-	    }
-
-	    if (parm.lgout)
-		lg[col] = (float)length;
-	}
-
-	if (parm.lgout)
-	    G_put_f_raster_row(lgfd, lg);
-    }
-
-    G_free(fls.px);
-    G_free(fls.py);
-    /*    G_free (fls); *//* commented 19/10/99 MN */
-    G_free(lg);
-    Vect_destroy_line_struct(points);
-    Vect_destroy_cats_struct(cats);
-
-    if (parm.lgout)
-	G_close_cell(lgfd);
-}
-
-int main(int argc, char *argv[])
-{
-    struct GModule *module;
-    struct Option *pelevin, *paspin, *pbarin, *pskip, *pbound,
-	*pflout, *plgout, *pdsout;
-    struct Flag *fup, *flg, *fmem;
-    int default_skip, larger, default_bound;
-
-#ifdef OFFSET
-    char *default_offset_ans, *offset_opt;
-#endif
-    char *default_skip_ans, *default_bound_ans, *skip_opt;
-    struct History history;
-
-
-    /* Initialize GIS engine */
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = "raster";
-    module->description =
-	_("Construction of slope curves (flowlines), flowpath lengths, "
-	  "and flowline densities (upslope areas) from a raster "
-	  "digital elevation model (DEM)");
-
-    pelevin = G_define_option();
-    pelevin->key = "elevin";
-    pelevin->type = TYPE_STRING;
-    pelevin->required = YES;
-    pelevin->gisprompt = "old,cell,raster";
-    pelevin->description = _("Input elevation raster map");
-
-    paspin = G_define_option();
-    paspin->key = "aspin";
-    paspin->type = TYPE_STRING;
-    paspin->required = NO;
-    paspin->gisprompt = "old,cell,raster";
-    paspin->description = _("Input aspect raster map");
-
-    pbarin = G_define_option();
-    pbarin->key = "barin";
-    pbarin->type = TYPE_STRING;
-    pbarin->required = NO;
-    pbarin->gisprompt = "old,cell,raster";
-    pbarin->description = _("Input barrier raster map");
-
-    pskip = G_define_option();
-    pskip->key = "skip";
-    pskip->type = TYPE_INTEGER;
-    pskip->required = NO;
-    pskip->options = skip_opt;
-    pskip->description = _("Number of cells between flowlines");
-
-    pbound = G_define_option();
-    pbound->key = "bound";
-    pbound->type = TYPE_INTEGER;
-    pbound->required = NO;
-    pbound->options = default_bound_ans;
-    pbound->description = _("Maximum number of segments per flowline");
-
-    pflout = G_define_option();
-    pflout->key = "flout";
-    pflout->type = TYPE_STRING;
-    pflout->required = NO;
-    pflout->gisprompt = "any,dig,vector";
-    pflout->description = _("Output flowline vector map");
-
-    plgout = G_define_option();
-    plgout->key = "lgout";
-    plgout->type = TYPE_STRING;
-    plgout->required = NO;
-    plgout->gisprompt = "any,cell,raster";
-    plgout->description = _("Output flowpath length raster map");
-
-    pdsout = G_define_option();
-    pdsout->key = "dsout";
-    pdsout->type = TYPE_STRING;
-    pdsout->required = NO;
-    pdsout->gisprompt = "any,cell,raster";
-    pdsout->description = _("Output flowline density raster map");
-
-    fup = G_define_flag();
-    fup->key = 'u';
-    fup->description =
-	_("Compute upslope flowlines instead of default downhill flowlines");
-
-    flg = G_define_flag();
-    flg->key = '3';
-    flg->description = _("3-D lengths instead of 2-D");
-
-    fmem = G_define_flag();
-    fmem->key = 'm';
-    fmem->description = _("Use less memory, at a performance penalty");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-
-    if (G_get_set_window(&region) == -1)
-	G_fatal_error(_("Unable to get current region"));
-
-    larger = ((region.cols < region.rows) ? region.rows : region.cols);
-    default_skip = (larger < 50) ? 1 : (int)(larger / 50);
-
-    default_skip_ans =
-	G_calloc((int)log10((double)default_skip) + 2, sizeof(char));
-    skip_opt = G_calloc((int)log10((double)larger) + 4, sizeof(char));
-
-    sprintf(default_skip_ans, "%d", default_skip);
-    sprintf(skip_opt, "1-%d", larger);
-
-    default_bound = (int)(4. * hypot((double)region.rows,
-				     (double)region.cols));
-    default_bound_ans =
-	G_calloc((int)log10((double)default_bound) + 4, sizeof(char));
-    sprintf(default_bound_ans, "0-%d", default_bound);
-
-#ifdef OFFSET
-    /* below fix changed from 0.0 to 1.0 and its effect disabled in 
-     * calc.c, Helena June 2005 */
-
-    default_offset = 1.0;	/* fixed 20. May 2001 Helena */
-    default_offset_ans =
-	G_calloc((int)log10(default_offset) + 2, sizeof(char));
-    sprintf(default_offset_ans, "%f", default_offset);
-
-    offset_opt = G_calloc((int)log10(default_offset) + 4, sizeof(char));
-    sprintf(offset_opt, "0.0-500.0");
-#endif
-
-    if (!pskip->answer)
-	pskip->answer = default_skip_ans;
-
-    if (!pbound->answer)
-	pbound->answer = default_bound_ans + 2;
-
-    parm.elevin = pelevin->answer;
-    parm.aspin = paspin->answer;
-    parm.barin = pbarin->answer;
-    parm.skip = atoi(pskip->answer);
-    parm.bound = atoi(pbound->answer);
-    parm.flout = pflout->answer;
-    parm.lgout = plgout->answer;
-    parm.dsout = pdsout->answer;
-    parm.up = fup->answer;
-    parm.l3d = flg->answer;
-    parm.mem = fmem->answer;
-
-    if (!pflout->answer && !plgout->answer && !pdsout->answer)
-	G_fatal_error(_("You must select one or more output maps (flout, lgout, dsout)"));
-
-    if (parm.seg)
-	parm.mem = '\0';
-    else if (parm.mem)
-	parm.aspin = NULL;
-
-    el.name = parm.elevin;
-    as.name = (parm.aspin) ? parm.aspin : "internal aspects";
-
-    ds.name = parm.dsout;
-    el.row_offset = el.col_offset = 1;
-    as.row_offset = as.col_offset = 0;
-    ds.row_offset = ds.col_offset = 0;
-
-    if ((G_projection() == PROJECTION_LL))	/* added MN 2005 */
-	G_fatal_error(_("lat/long projection not supported by "
-			"r.flow. Please use 'r.watershed' for calculating "
-			"flow accumulation."));
-
-    if (parm.flout || parm.dsout || parm.lgout) {
-	open_output_files();
-	allocate_heap();
-	read_input_files();
-
-	precompute();
-	calculate();
-	if (parm.dsout)
-	    write_density_file();
-
-	close_files();
-	deallocate_heap();
-    }
-
-    if (parm.dsout) {
-	G_short_history(parm.dsout, "raster", &history);
-	G_command_history(&history);
-	G_write_history(parm.dsout, &history);
-    }
-    if (parm.lgout) {
-	G_short_history(parm.lgout, "raster", &history);
-	G_command_history(&history);
-	G_write_history(parm.lgout, &history);
-    }
-
-    exit(EXIT_SUCCESS);
-}

Copied: grass/trunk/raster/r.flow/main.c (from rev 32804, grass/trunk/raster/r.flow/calc.c)
===================================================================
--- grass/trunk/raster/r.flow/main.c	                        (rev 0)
+++ grass/trunk/raster/r.flow/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,596 @@
+/*
+ **  Original Algorithm:    H. Mitasova, L. Mitas, J. Hofierka, M. Zlocha 
+ **  New GRASS Implementation:  J. Caplan, M. Ruesink  1995
+ **
+ **  US Army Construction Engineering Research Lab, University of Illinois 
+ **
+ **  Copyright  J. Caplan, H. Mitasova, L. Mitas, M.Ruesink, J. Hofierka, 
+ **     M. Zlocha  1995
+ **
+ **This program is free software; you can redistribute it and/or
+ **modify it under the terms of the GNU General Public License
+ **as published by the Free Software Foundation; either version 2
+ **of the License, or (at your option) any later version.
+ **
+ **This program is distributed in the hope that it will be useful,
+ **but WITHOUT ANY WARRANTY; without even the implied warranty of
+ **MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ **GNU General Public License for more details.
+ **
+ **You should have received a copy of the GNU General Public License
+ **along with this program; if not, write to the Free Software
+ **Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
+ **
+ **  version 13 for GRASS5.0
+ **  FP related bugs in slope length output fixed by Helena oct. 1999)
+ **  Update MN: commented line 387
+ */
+
+#include <stdlib.h>		/* for the random number generation */
+#include <time.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "r.flow.h"
+#include "mem.h"
+#include "io.h"
+#include "aspect.h"
+#include "precomp.h"
+
+#define HORIZ	1		/* \            */
+#define VERT	0		/* |            */
+#define EAST	1		/* |            */
+#define WEST	0		/* |_ magic     */
+#define NORTH	1		/* |  numbers   */
+#define SOUTH	0		/* |            */
+#define ROW	1		/* |            */
+#define COL	0		/* /            */
+
+CELL v;				/* address for segment retrieval macros */
+
+/* heap memory */
+struct Cell_head region;	/* resolution and boundaries            */
+struct Map_info fl;		/* output vector file header            */
+struct BM *bitbar;		/* space-efficient barrier matrix       */
+int lgfd;			/* output length file descriptor        */
+char string[1024];		/* space for strings                    */
+layer el, as, ds;		/* elevation, aspect, density           */
+double *ew_dist;		/* east-west distances for rows         */
+double *epsilon[2];		/* quantization errors for rows         */
+
+/* command-line parameters */
+params parm;
+
+typedef struct
+{
+    int row, col;		/* current matrix address       */
+}
+addr;
+
+typedef int bbox[2][2];		/* current bounding box         */
+
+typedef struct
+{
+    double x, y, z;		/* exact earth coordinates      */
+    double theta;		/* aspect                       */
+    double r, c;		/* cell matrix coordinates      */
+}
+point;
+
+typedef struct
+{
+    double *px, *py;		/* x/y point arrays             */
+    int index;			/* index of next point          */
+}
+flowline;
+
+/***************************** CALCULATION ******************************/
+
+/*
+ * height_angle_bounding_box: averages matrix values at sub between
+ *      floor(cut) and ceil(cut), based on proximity; adjusts bbox
+ * globals r: o, z, parm
+ * params  w: p, b
+ */
+static void
+height_angle_bounding_box(int sub, double cut, int horiz, point * p, bbox b)
+{
+    int c, f = (int)cut;
+    double r = cut - (double)f;
+    double a1, a2, a, d;
+
+    b[horiz][horiz] = sub - 1;
+    b[horiz][!horiz] = sub + 1;
+    b[!horiz][horiz] = f + 1;
+    c = (b[!horiz][!horiz] = f - (r == 0.)) + 1;
+
+    if (horiz) {
+	a1 = (double)aspect(sub, f);
+	a2 = (double)aspect(sub, c);
+	p->z = (double)get(el, sub, f) * (1. - r) +
+	    (double)get(el, sub, c) * r;
+    }
+    else {
+	a1 = (double)aspect(f, sub);
+	a2 = (double)aspect(c, sub);
+	p->z = (double)get(el, f, sub) * (1. - r) +
+	    (double)get(el, c, sub) * r;
+    }
+
+    if (!(a1 == UNDEF || a2 == UNDEF) &&
+	!(G_is_d_null_value(&a1) || G_is_d_null_value(&a2)))
+	/*    if (!(G_is_d_null_value(&a1) || G_is_d_null_value(&a2))) */
+    {
+	if ((d = a1 - a2) >= D_PI || d <= -D_PI) {
+	    if (a2 > D_PI)
+		a2 -= D2_PI;
+	    else
+		a1 -= D2_PI;
+	}
+	a = r * a2 + (1. - r) * a1;
+	p->theta = a + (a < 0.) * D2_PI;
+    }
+    else
+	p->theta = UNDEF;
+
+    return;
+}
+
+/*
+ * sloping: returns elevation condition for continuing current line
+ */
+#define sloping(z1, z2) (z1 > z2)
+
+/*
+ * on_map: returns map boundary condition for continuing current line
+ * globals r:  region
+ */
+static int on_map(int sub, double cut, int horiz)
+{
+    return
+	(sub >= 0 && cut >= 0.0 &&
+	 ((horiz && sub < region.rows && cut <= (double)(region.cols - 1)) ||
+	  (!horiz && sub < region.cols && cut <= (double)(region.rows - 1))));
+}
+
+/*
+ * add_to_line: puts a new point on the end of the current flowline
+ * globals r:  parm
+ * params  w:  f
+ */
+static void add_to_line(point * p, flowline * f)
+{
+    if (parm.flout) {
+	f->px[f->index] = (double)p->x;
+	f->py[f->index] = (double)p->y;
+    }
+    ++f->index;
+}
+
+/*
+ * rectify: correct quantization problems (designed for speed, not elegance)
+ */
+static double rectify(double delta, double bd[2], double e)
+{
+    if (delta > 0.) {
+	if (delta > bd[1] + e)
+	    return delta;
+    }
+    else {
+	if (delta < bd[0] - e)
+	    return delta;
+    }
+    if (delta < bd[1] - e)
+	if (delta > bd[0] + e)
+	    return delta;
+	else
+	    return bd[0];
+    else
+	return bd[1];
+}
+
+/*
+ * next_point: computes next point based on current point, z, and o
+ *      returns continuation condition
+ * globals r:  region, bitbar, parm
+ * params  w:  p, a, l
+ * globals w:  density
+ */
+static int next_point(point * p,	/* current/next point               */
+		      addr * a,	/* current/next matrix address      */
+		      bbox b,	/* current/next bounding box        */
+		      double *l	/* current/eventual length          */
+    )
+{
+    int sub;
+    double cut;
+    int horiz;
+    int semi;
+    double length, delta;
+    double deltaz;
+    double tangent;
+
+    double oldz = p->z;
+    double oldtheta = p->theta;
+    double oldr = p->r;
+    double oldc = p->c;
+
+    addr ads;
+    double bdy[2], bdx[2];
+
+    ads = *a;
+    bdy[SOUTH] = (double)(oldr - b[ROW][SOUTH]) * region.ns_res;
+    bdy[NORTH] = (double)(oldr - b[ROW][NORTH]) * region.ns_res;
+    bdx[WEST] = (double)(b[COL][WEST] - oldc) * ew_dist[ads.row];
+    bdx[EAST] = (double)(b[COL][EAST] - oldc) * ew_dist[ads.row];
+
+    semi = oldtheta < 90 || oldtheta >= 270;
+    tangent = tan(oldtheta * DEG2RAD);
+
+    if (oldtheta != 90 && oldtheta != 270 &&	/* north/south */
+	(delta = (bdy[semi] * tangent)) < bdx[EAST] && delta > bdx[WEST]) {
+	delta = rectify(delta, bdx, epsilon[HORIZ][ads.row]);
+	p->x += delta;
+	p->y += bdy[semi];
+	p->r = (double)b[ROW][semi];
+	p->c += delta / ew_dist[ads.row];
+	a->row = b[ROW][semi];
+	a->col = ROUND(p->c);
+	sub = b[ROW][semi];
+	cut = p->c;
+	horiz = HORIZ;
+	if (parm.lgout)
+	    length = hypot(delta, bdy[semi]);
+    }
+    else {			/*  east/west  */
+
+	semi = oldtheta < 180;
+	if (oldtheta == 90 || oldtheta == 270)
+	    delta = 0;
+	else {
+	    /* I don't know if this is right case.
+	     * Anyway, should be avoid from dividing by zero.
+	     * Any hydrologic idea?
+	     */
+	    if (tangent == 0.0)
+		tangent = 0.000001;
+
+	    delta = bdx[semi] / tangent;
+	}
+
+	delta = rectify(delta, bdy, epsilon[VERT][ads.row]);
+	p->y += delta;
+	p->x += bdx[semi];
+	p->r -= delta / region.ns_res;
+	p->c = (double)b[COL][semi];
+	a->row = ROUND(p->r);
+	a->col = b[COL][semi];
+	sub = b[COL][semi];
+	cut = p->r;
+	horiz = VERT;
+	if (parm.lgout)
+	    length = hypot(bdx[semi], delta);
+    }
+
+    if (on_map(sub, cut, horiz) &&
+	(height_angle_bounding_box(sub, cut, horiz, p, b),
+	 sloping(oldz, p->z)) &&
+	!(parm.barin && BM_get(bitbar, a->col, a->row))) {
+	if (parm.dsout && (ads.row != a->row || ads.col != a->col))
+	    put(ds, a->row, a->col, get(ds, a->row, a->col) + 1);
+	/*      if (parm.lgout) 
+	 *      *l += parm.l3d ? hypot(length, oldz - p->z) : length; this did not work, helena*/
+	if (parm.lgout) {
+	    if (parm.l3d) {
+		deltaz = oldz - p->z;	/*fix by helena Dec. 06 */
+		*l += hypot(length, deltaz);
+	    }
+	    else
+		*l += length;
+	}
+	return 1;
+    }
+
+    return 0;
+}
+
+/*
+ * calculate: create a flowline for each cell
+ * globals r: region, bitbar, parm, lgfd
+ */
+static void calculate(void)
+{
+    point pts;
+    addr ads;
+    bbox bbs;
+    flowline fls;
+    int row, col;
+
+    /*    double     x, y, length, xstep, ystep, roffset, coffset; */
+    double x, y, length, xstep, ystep;
+    FCELL *lg = G_allocate_f_raster_buf();
+    struct line_pnts *points = Vect_new_line_struct();
+    struct line_cats *cats = Vect_new_cats_struct();
+    int loopstep = (!parm.dsout && !parm.lgout && parm.flout) ? parm.skip : 1;
+
+    G_message(_("Calculating maps ..."));
+
+    fls.px = (double *)G_calloc(parm.bound, sizeof(double));
+    fls.py = (double *)G_calloc(parm.bound, sizeof(double));
+
+    ystep = region.ns_res * (double)loopstep;
+
+    srand(time(0));
+
+    for (row = 0, y = (double)region.north - (region.ns_res * .5);
+	 row < region.rows; row += loopstep, y -= ystep) {
+	xstep = ew_dist[row] * (double)loopstep;
+	G_percent(row, region.rows, 2);
+
+	for (col = 0, x = (double)region.west + (ew_dist[row] * .5);
+	     col < region.cols; col += loopstep, x += xstep) {
+
+	    length = 0.0;
+	    fls.index = 0;
+
+	    if (!(parm.barin && BM_get(bitbar, col, row))) {
+#ifdef OFFSET
+		/* disabled by helena June 2005 */
+		roffset = parm.offset * (double)region.ew_res
+		    * ((2. * (double)rand() / (double)RAND_MAX) - 1.);
+		coffset = parm.offset * (double)region.ns_res
+		    * ((2. * (double)rand() / (double)RAND_MAX) - 1.);
+#endif
+		pts.x = x;
+		pts.y = y;
+		pts.z = (double)get(el, row, col);
+		pts.theta = (double)aspect(row, col);
+		pts.r = (double)row;	/* + roffset; */
+		pts.c = (double)col;	/*+ coffset; */
+
+		ads.row = row;
+		ads.col = col;
+
+#ifdef OFFSET
+		G_debug(3, "dx: %f  x: %f %f  row: %f %f\n",
+			roffset, x, pts.x, (double)row, pts.r);
+		G_debug(3, "dy: %f  y: %f %f  col: %f %f\n",
+			roffset, y, pts.y, (double)col, pts.c);
+#endif
+
+		bbs[ROW][SOUTH] = row + 1;
+		bbs[ROW][NORTH] = row - 1;
+		bbs[COL][WEST] = col - 1;
+		bbs[COL][EAST] = col + 1;
+
+		do
+		    add_to_line(&pts, &fls);
+		while (fls.index <= parm.bound &&
+		       (pts.z != UNDEFZ && pts.theta >= 0 && pts.theta <= 360)
+		       &&
+		       /*  (!G_is_d_null_value(&pts.z) && pts.theta != UNDEF) && */
+		       next_point(&pts, &ads, bbs, &length));
+	    }
+
+	    if (fls.index > 1 && parm.flout &&
+		(loopstep == parm.skip ||
+		 !(row % parm.skip || col % parm.skip))) {
+		Vect_copy_xyz_to_pnts(points, fls.px, fls.py, NULL,
+				      fls.index);
+		Vect_write_line(&fl, GV_LINE, points, cats);
+	    }
+
+	    if (parm.lgout)
+		lg[col] = (float)length;
+	}
+
+	if (parm.lgout)
+	    G_put_f_raster_row(lgfd, lg);
+    }
+
+    G_free(fls.px);
+    G_free(fls.py);
+    /*    G_free (fls); *//* commented 19/10/99 MN */
+    G_free(lg);
+    Vect_destroy_line_struct(points);
+    Vect_destroy_cats_struct(cats);
+
+    if (parm.lgout)
+	G_close_cell(lgfd);
+}
+
+int main(int argc, char *argv[])
+{
+    struct GModule *module;
+    struct Option *pelevin, *paspin, *pbarin, *pskip, *pbound,
+	*pflout, *plgout, *pdsout;
+    struct Flag *fup, *flg, *fmem;
+    int default_skip, larger, default_bound;
+
+#ifdef OFFSET
+    char *default_offset_ans, *offset_opt;
+#endif
+    char *default_skip_ans, *default_bound_ans, *skip_opt;
+    struct History history;
+
+
+    /* Initialize GIS engine */
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = "raster";
+    module->description =
+	_("Construction of slope curves (flowlines), flowpath lengths, "
+	  "and flowline densities (upslope areas) from a raster "
+	  "digital elevation model (DEM)");
+
+    pelevin = G_define_option();
+    pelevin->key = "elevin";
+    pelevin->type = TYPE_STRING;
+    pelevin->required = YES;
+    pelevin->gisprompt = "old,cell,raster";
+    pelevin->description = _("Input elevation raster map");
+
+    paspin = G_define_option();
+    paspin->key = "aspin";
+    paspin->type = TYPE_STRING;
+    paspin->required = NO;
+    paspin->gisprompt = "old,cell,raster";
+    paspin->description = _("Input aspect raster map");
+
+    pbarin = G_define_option();
+    pbarin->key = "barin";
+    pbarin->type = TYPE_STRING;
+    pbarin->required = NO;
+    pbarin->gisprompt = "old,cell,raster";
+    pbarin->description = _("Input barrier raster map");
+
+    pskip = G_define_option();
+    pskip->key = "skip";
+    pskip->type = TYPE_INTEGER;
+    pskip->required = NO;
+    pskip->options = skip_opt;
+    pskip->description = _("Number of cells between flowlines");
+
+    pbound = G_define_option();
+    pbound->key = "bound";
+    pbound->type = TYPE_INTEGER;
+    pbound->required = NO;
+    pbound->options = default_bound_ans;
+    pbound->description = _("Maximum number of segments per flowline");
+
+    pflout = G_define_option();
+    pflout->key = "flout";
+    pflout->type = TYPE_STRING;
+    pflout->required = NO;
+    pflout->gisprompt = "any,dig,vector";
+    pflout->description = _("Output flowline vector map");
+
+    plgout = G_define_option();
+    plgout->key = "lgout";
+    plgout->type = TYPE_STRING;
+    plgout->required = NO;
+    plgout->gisprompt = "any,cell,raster";
+    plgout->description = _("Output flowpath length raster map");
+
+    pdsout = G_define_option();
+    pdsout->key = "dsout";
+    pdsout->type = TYPE_STRING;
+    pdsout->required = NO;
+    pdsout->gisprompt = "any,cell,raster";
+    pdsout->description = _("Output flowline density raster map");
+
+    fup = G_define_flag();
+    fup->key = 'u';
+    fup->description =
+	_("Compute upslope flowlines instead of default downhill flowlines");
+
+    flg = G_define_flag();
+    flg->key = '3';
+    flg->description = _("3-D lengths instead of 2-D");
+
+    fmem = G_define_flag();
+    fmem->key = 'm';
+    fmem->description = _("Use less memory, at a performance penalty");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
+    if (G_get_set_window(&region) == -1)
+	G_fatal_error(_("Unable to get current region"));
+
+    larger = ((region.cols < region.rows) ? region.rows : region.cols);
+    default_skip = (larger < 50) ? 1 : (int)(larger / 50);
+
+    default_skip_ans =
+	G_calloc((int)log10((double)default_skip) + 2, sizeof(char));
+    skip_opt = G_calloc((int)log10((double)larger) + 4, sizeof(char));
+
+    sprintf(default_skip_ans, "%d", default_skip);
+    sprintf(skip_opt, "1-%d", larger);
+
+    default_bound = (int)(4. * hypot((double)region.rows,
+				     (double)region.cols));
+    default_bound_ans =
+	G_calloc((int)log10((double)default_bound) + 4, sizeof(char));
+    sprintf(default_bound_ans, "0-%d", default_bound);
+
+#ifdef OFFSET
+    /* below fix changed from 0.0 to 1.0 and its effect disabled in 
+     * calc.c, Helena June 2005 */
+
+    default_offset = 1.0;	/* fixed 20. May 2001 Helena */
+    default_offset_ans =
+	G_calloc((int)log10(default_offset) + 2, sizeof(char));
+    sprintf(default_offset_ans, "%f", default_offset);
+
+    offset_opt = G_calloc((int)log10(default_offset) + 4, sizeof(char));
+    sprintf(offset_opt, "0.0-500.0");
+#endif
+
+    if (!pskip->answer)
+	pskip->answer = default_skip_ans;
+
+    if (!pbound->answer)
+	pbound->answer = default_bound_ans + 2;
+
+    parm.elevin = pelevin->answer;
+    parm.aspin = paspin->answer;
+    parm.barin = pbarin->answer;
+    parm.skip = atoi(pskip->answer);
+    parm.bound = atoi(pbound->answer);
+    parm.flout = pflout->answer;
+    parm.lgout = plgout->answer;
+    parm.dsout = pdsout->answer;
+    parm.up = fup->answer;
+    parm.l3d = flg->answer;
+    parm.mem = fmem->answer;
+
+    if (!pflout->answer && !plgout->answer && !pdsout->answer)
+	G_fatal_error(_("You must select one or more output maps (flout, lgout, dsout)"));
+
+    if (parm.seg)
+	parm.mem = '\0';
+    else if (parm.mem)
+	parm.aspin = NULL;
+
+    el.name = parm.elevin;
+    as.name = (parm.aspin) ? parm.aspin : "internal aspects";
+
+    ds.name = parm.dsout;
+    el.row_offset = el.col_offset = 1;
+    as.row_offset = as.col_offset = 0;
+    ds.row_offset = ds.col_offset = 0;
+
+    if ((G_projection() == PROJECTION_LL))	/* added MN 2005 */
+	G_fatal_error(_("lat/long projection not supported by "
+			"r.flow. Please use 'r.watershed' for calculating "
+			"flow accumulation."));
+
+    if (parm.flout || parm.dsout || parm.lgout) {
+	open_output_files();
+	allocate_heap();
+	read_input_files();
+
+	precompute();
+	calculate();
+	if (parm.dsout)
+	    write_density_file();
+
+	close_files();
+	deallocate_heap();
+    }
+
+    if (parm.dsout) {
+	G_short_history(parm.dsout, "raster", &history);
+	G_command_history(&history);
+	G_write_history(parm.dsout, &history);
+    }
+    if (parm.lgout) {
+	G_short_history(parm.lgout, "raster", &history);
+	G_command_history(&history);
+	G_write_history(parm.lgout, &history);
+    }
+
+    exit(EXIT_SUCCESS);
+}

Copied: grass/trunk/raster/r.null/main.c (from rev 32801, grass/trunk/raster/r.null/null.c)
===================================================================
--- grass/trunk/raster/r.null/main.c	                        (rev 0)
+++ grass/trunk/raster/r.null/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,333 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "mask.h"
+#include "local_proto.h"
+
+d_Mask d_mask;
+DCELL new_null;
+
+static struct Cell_head cellhd;
+static int parse_vallist(char **, d_Mask *);
+
+int main(int argc, char *argv[])
+{
+    char *name, *mapset;
+    char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
+    char path[GPATH_MAX];
+    int row, col, null_fd;
+    unsigned char *null_bits;
+    RASTER_MAP_TYPE map_type;
+    int change_null = 0, create, remove, only_int, only_fp, only_null;
+    int is_reclass;
+
+    struct GModule *module;
+    struct
+    {
+	struct Option *map;
+	struct Option *setnull;
+	struct Option *null;
+    } parms;
+    struct
+    {
+	struct Flag *f;
+	struct Flag *n;
+	struct Flag *i;
+	struct Flag *c;
+	struct Flag *r;
+    } flags;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("raster");
+    module->description = _("Creates explicitly the NULL-value bitmap file.");
+
+    parms.map = G_define_option();
+    parms.map->key = "map";
+    parms.map->type = TYPE_STRING;
+    parms.map->required = YES;
+    parms.map->multiple = NO;
+    parms.map->gisprompt = "old,cell,raster";
+    parms.map->description = _("Raster map for which to edit null file");
+
+    parms.setnull = G_define_option();
+    parms.setnull->key = "setnull";
+    parms.setnull->key_desc = "val[-val]";
+    parms.setnull->type = TYPE_STRING;
+    parms.setnull->required = NO;
+    parms.setnull->multiple = YES;
+    parms.setnull->description = _("List of cell values to be set to NULL");
+
+    parms.null = G_define_option();
+    parms.null->key = "null";
+    parms.null->type = TYPE_DOUBLE;
+    parms.null->required = NO;
+    parms.null->multiple = NO;
+    parms.null->description = _("The value to replace the null value by");
+
+    flags.f = G_define_flag();
+    flags.f->key = 'f';
+    flags.f->description = _("Only do the work if the map is floating-point");
+
+    flags.i = G_define_flag();
+    flags.i->key = 'i';
+    flags.i->description = _("Only do the work if the map is integer");
+
+    flags.n = G_define_flag();
+    flags.n->key = 'n';
+    flags.n->description =
+	_("Only do the work if the map doesn't have a NULL-value bitmap file");
+
+    flags.c = G_define_flag();
+    flags.c->key = 'c';
+    flags.c->description =
+	_("Create NULL-value bitmap file validating all data cells");
+
+    flags.r = G_define_flag();
+    flags.r->key = 'r';
+    flags.r->description = _("Remove NULL-value bitmap file");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    only_int = flags.i->answer;
+    only_fp = flags.f->answer;
+    only_null = flags.n->answer;
+    create = flags.c->answer;
+    remove = flags.r->answer;
+
+    name = parms.map->answer;
+    mapset = G_find_cell2(name, "");
+    if (mapset == NULL)
+	G_fatal_error(_("Raster map <%s> not found"), name);
+
+    is_reclass = (G_is_reclass(name, mapset, rname, rmapset) > 0);
+    if (is_reclass)
+	G_fatal_error
+	    ("%s is a reclass of map <%s> in mapset <%s>. Consider to generate a copy with r.mapcalc. Exiting.",
+	     name, rname, rmapset);
+
+
+    if (strcmp(mapset, G_mapset()) != 0)
+	G_fatal_error("%s is not in your mapset (%s)", name, G_mapset());
+
+    if (parms.null->answer) {
+	if (sscanf(parms.null->answer, "%lf", &new_null) == 1)
+	    change_null = 1;
+	else
+	    G_fatal_error("%s is illegal entry for null", parms.null->answer);
+    }
+
+    map_type = G_raster_map_type(name, mapset);
+
+    if (only_null && G_find_file_misc("cell_misc", "null", name, mapset))
+	G_fatal_error("%s already has a null bitmap file!", name);
+
+    if (map_type == CELL_TYPE) {
+	if (only_fp)
+	    G_fatal_error("%s is integer!", name);
+
+	if ((double)((int)new_null) != new_null) {
+	    G_warning("%s is an integer map! Using null=%d", name,
+		      (int)new_null);
+	    new_null = (double)((int)new_null);
+	}
+    }
+    else if (only_int)
+	G_fatal_error("%s is floating point!", name);
+
+    parse_vallist(parms.setnull->answers, &d_mask);
+
+    if (G_get_cellhd(name, mapset, &cellhd) < 0)
+	G_fatal_error("Can't read cell header for %s", name);
+
+    if (create) {
+	/* write a file of no-nulls */
+	null_bits = (unsigned char *)G__allocate_null_bits(cellhd.cols);
+	/* init all cells to 0's */
+	for (col = 0; col < G__null_bitstream_size(cellhd.cols); col++)
+	    null_bits[col] = 0;
+
+	null_fd = G_open_new_misc("cell_misc", "null", name);
+
+	G_message("Writing new null file for [%s]... ", name);
+
+	for (row = 0; row < cellhd.rows; row++) {
+	    G_percent(row, cellhd.rows, 1);
+	    if (G__write_null_bits(null_fd, null_bits, row, cellhd.cols, 0) <
+		0)
+		G_fatal_error("Error writing null row %d", row);
+	}
+	G_percent(row, cellhd.rows, 1);
+	close(null_fd);
+	G_message("Done");
+	exit(EXIT_SUCCESS);
+    }
+
+    if (remove) {
+	/* write a file of no-nulls */
+	G_message("Removing null file for [%s]... ", name);
+	null_fd = G_open_new_misc("cell_misc", "null", name);
+	G__file_name_misc(path, "cell_misc", "null", name, mapset);
+	unlink(path);
+	G_message("Done");
+	exit(EXIT_SUCCESS);
+    }
+
+    process(name, mapset, change_null, map_type);
+    exit(EXIT_SUCCESS);
+}
+
+static int parse_vallist(char **vallist, d_Mask * d_mask)
+{
+    char buf[1024];
+    char x[2];
+    FILE *fd;
+
+    init_d_mask_rules(d_mask);
+    if (vallist == NULL)
+	return 1;
+
+    for (; *vallist; vallist++) {
+	if (*vallist[0] == '/') {
+	    fd = fopen(*vallist, "r");
+	    if (fd == NULL) {
+		perror(*vallist);
+		G_usage();
+		exit(1);
+	    }
+	    while (fgets(buf, sizeof buf, fd)) {
+		if (sscanf(buf, "%1s", x) != 1 || *x == '#')
+		    continue;
+		parse_d_mask_rule(buf, d_mask, *vallist);
+	    }
+	    fclose(fd);
+	}
+	else
+	    parse_d_mask_rule(*vallist, d_mask, (char *)NULL);
+    }
+
+    return 0;
+}
+
+int parse_d_mask_rule(char *vallist, d_Mask * d_mask, char *where)
+{
+    double a, b;
+    char junk[128];
+
+    /* #-# */
+    if (sscanf(vallist, "%lf-%lf", &a, &b) == 2)
+	add_d_mask_rule(d_mask, a, b, 0);
+    /* inf-# */
+    else if (sscanf(vallist, "%[^ -\t]-%lf", junk, &a) == 2)
+	add_d_mask_rule(d_mask, a, a, -1);
+
+    /* #-inf */
+    else if (sscanf(vallist, "%lf-%[^ \t]", &a, junk) == 2)
+	add_d_mask_rule(d_mask, a, a, 1);
+
+    /* # */
+    else if (sscanf(vallist, "%lf", &a) == 1)
+	add_d_mask_rule(d_mask, a, a, 0);
+
+    else {
+	if (where)
+	    G_fatal_error("%s: %s: illegal value spec", where, vallist);
+	else
+	    G_fatal_error("%s: illegal value spec", vallist);
+    }
+
+    return 0;
+}
+
+int
+process(char *name, char *mapset, int change_null, RASTER_MAP_TYPE map_type)
+{
+    struct Colors colr;
+    struct History hist;
+    struct Categories cats;
+    struct Quant quant;
+    int colr_ok;
+    int hist_ok;
+    int cats_ok;
+    int quant_ok;
+
+    G_suppress_warnings(1);
+    colr_ok = G_read_colors(name, mapset, &colr) > 0;
+    hist_ok = G_read_history(name, mapset, &hist) >= 0;
+    cats_ok = G_read_raster_cats(name, mapset, &cats) >= 0;
+
+    if (map_type != CELL_TYPE) {
+	G_quant_init(&quant);
+	quant_ok = G_read_quant(name, mapset, &quant);
+	G_suppress_warnings(0);
+    }
+
+    if (doit(name, mapset, change_null, map_type))
+	return 1;
+
+    if (colr_ok) {
+	G_write_colors(name, mapset, &colr);
+	G_free_colors(&colr);
+    }
+    if (hist_ok)
+	G_write_history(name, &hist);
+    if (cats_ok) {
+	cats.num = G_number_of_cats(name, mapset);
+	G_write_raster_cats(name, &cats);
+	G_free_cats(&cats);
+    }
+    if (map_type != CELL_TYPE && quant_ok)
+	G_write_quant(name, mapset, &quant);
+
+    return 0;
+}
+
+int doit(char *name, char *mapset, int change_null, RASTER_MAP_TYPE map_type)
+{
+    int new, old, row;
+    void *rast;
+
+    G_set_window(&cellhd);
+
+    old = G_open_cell_old(name, mapset);
+    if (old < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), name);
+
+    new = G_open_raster_new(name, map_type);
+
+    if (new < 0)
+	G_fatal_error(_("Unable to create raster map <%s>"), name);
+
+    rast = G_allocate_raster_buf(map_type);
+
+    G_message("Writing new data for [%s]... ", name);
+    /* the null file is written automatically */
+    for (row = 0; row < cellhd.rows; row++) {
+	G_percent(row, cellhd.rows, 1);
+
+	if (G_get_raster_row_nomask(old, rast, row, map_type) < 0) {
+	    G_warning("Can't read row %d", row);
+	    break;
+	}
+
+	mask_raster_array(rast, cellhd.cols, change_null, map_type);
+
+	if (G_put_raster_row(new, rast, map_type) < 0) {
+	    G_warning("Can't write row %d", row);
+	    break;
+	}
+    }
+    G_percent(row, cellhd.rows, 1);
+    G_free(rast);
+    G_close_cell(old);
+    if (row < cellhd.rows) {
+	G_unopen_cell(new);
+	return 1;
+    }
+    G_close_cell(new);
+    return 0;
+}

Deleted: grass/trunk/raster/r.null/null.c
===================================================================
--- grass/trunk/raster/r.null/null.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/raster/r.null/null.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,333 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "mask.h"
-#include "local_proto.h"
-
-d_Mask d_mask;
-DCELL new_null;
-
-static struct Cell_head cellhd;
-static int parse_vallist(char **, d_Mask *);
-
-int main(int argc, char *argv[])
-{
-    char *name, *mapset;
-    char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
-    char path[GPATH_MAX];
-    int row, col, null_fd;
-    unsigned char *null_bits;
-    RASTER_MAP_TYPE map_type;
-    int change_null = 0, create, remove, only_int, only_fp, only_null;
-    int is_reclass;
-
-    struct GModule *module;
-    struct
-    {
-	struct Option *map;
-	struct Option *setnull;
-	struct Option *null;
-    } parms;
-    struct
-    {
-	struct Flag *f;
-	struct Flag *n;
-	struct Flag *i;
-	struct Flag *c;
-	struct Flag *r;
-    } flags;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("raster");
-    module->description = _("Creates explicitly the NULL-value bitmap file.");
-
-    parms.map = G_define_option();
-    parms.map->key = "map";
-    parms.map->type = TYPE_STRING;
-    parms.map->required = YES;
-    parms.map->multiple = NO;
-    parms.map->gisprompt = "old,cell,raster";
-    parms.map->description = _("Raster map for which to edit null file");
-
-    parms.setnull = G_define_option();
-    parms.setnull->key = "setnull";
-    parms.setnull->key_desc = "val[-val]";
-    parms.setnull->type = TYPE_STRING;
-    parms.setnull->required = NO;
-    parms.setnull->multiple = YES;
-    parms.setnull->description = _("List of cell values to be set to NULL");
-
-    parms.null = G_define_option();
-    parms.null->key = "null";
-    parms.null->type = TYPE_DOUBLE;
-    parms.null->required = NO;
-    parms.null->multiple = NO;
-    parms.null->description = _("The value to replace the null value by");
-
-    flags.f = G_define_flag();
-    flags.f->key = 'f';
-    flags.f->description = _("Only do the work if the map is floating-point");
-
-    flags.i = G_define_flag();
-    flags.i->key = 'i';
-    flags.i->description = _("Only do the work if the map is integer");
-
-    flags.n = G_define_flag();
-    flags.n->key = 'n';
-    flags.n->description =
-	_("Only do the work if the map doesn't have a NULL-value bitmap file");
-
-    flags.c = G_define_flag();
-    flags.c->key = 'c';
-    flags.c->description =
-	_("Create NULL-value bitmap file validating all data cells");
-
-    flags.r = G_define_flag();
-    flags.r->key = 'r';
-    flags.r->description = _("Remove NULL-value bitmap file");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    only_int = flags.i->answer;
-    only_fp = flags.f->answer;
-    only_null = flags.n->answer;
-    create = flags.c->answer;
-    remove = flags.r->answer;
-
-    name = parms.map->answer;
-    mapset = G_find_cell2(name, "");
-    if (mapset == NULL)
-	G_fatal_error(_("Raster map <%s> not found"), name);
-
-    is_reclass = (G_is_reclass(name, mapset, rname, rmapset) > 0);
-    if (is_reclass)
-	G_fatal_error
-	    ("%s is a reclass of map <%s> in mapset <%s>. Consider to generate a copy with r.mapcalc. Exiting.",
-	     name, rname, rmapset);
-
-
-    if (strcmp(mapset, G_mapset()) != 0)
-	G_fatal_error("%s is not in your mapset (%s)", name, G_mapset());
-
-    if (parms.null->answer) {
-	if (sscanf(parms.null->answer, "%lf", &new_null) == 1)
-	    change_null = 1;
-	else
-	    G_fatal_error("%s is illegal entry for null", parms.null->answer);
-    }
-
-    map_type = G_raster_map_type(name, mapset);
-
-    if (only_null && G_find_file_misc("cell_misc", "null", name, mapset))
-	G_fatal_error("%s already has a null bitmap file!", name);
-
-    if (map_type == CELL_TYPE) {
-	if (only_fp)
-	    G_fatal_error("%s is integer!", name);
-
-	if ((double)((int)new_null) != new_null) {
-	    G_warning("%s is an integer map! Using null=%d", name,
-		      (int)new_null);
-	    new_null = (double)((int)new_null);
-	}
-    }
-    else if (only_int)
-	G_fatal_error("%s is floating point!", name);
-
-    parse_vallist(parms.setnull->answers, &d_mask);
-
-    if (G_get_cellhd(name, mapset, &cellhd) < 0)
-	G_fatal_error("Can't read cell header for %s", name);
-
-    if (create) {
-	/* write a file of no-nulls */
-	null_bits = (unsigned char *)G__allocate_null_bits(cellhd.cols);
-	/* init all cells to 0's */
-	for (col = 0; col < G__null_bitstream_size(cellhd.cols); col++)
-	    null_bits[col] = 0;
-
-	null_fd = G_open_new_misc("cell_misc", "null", name);
-
-	G_message("Writing new null file for [%s]... ", name);
-
-	for (row = 0; row < cellhd.rows; row++) {
-	    G_percent(row, cellhd.rows, 1);
-	    if (G__write_null_bits(null_fd, null_bits, row, cellhd.cols, 0) <
-		0)
-		G_fatal_error("Error writing null row %d", row);
-	}
-	G_percent(row, cellhd.rows, 1);
-	close(null_fd);
-	G_message("Done");
-	exit(EXIT_SUCCESS);
-    }
-
-    if (remove) {
-	/* write a file of no-nulls */
-	G_message("Removing null file for [%s]... ", name);
-	null_fd = G_open_new_misc("cell_misc", "null", name);
-	G__file_name_misc(path, "cell_misc", "null", name, mapset);
-	unlink(path);
-	G_message("Done");
-	exit(EXIT_SUCCESS);
-    }
-
-    process(name, mapset, change_null, map_type);
-    exit(EXIT_SUCCESS);
-}
-
-static int parse_vallist(char **vallist, d_Mask * d_mask)
-{
-    char buf[1024];
-    char x[2];
-    FILE *fd;
-
-    init_d_mask_rules(d_mask);
-    if (vallist == NULL)
-	return 1;
-
-    for (; *vallist; vallist++) {
-	if (*vallist[0] == '/') {
-	    fd = fopen(*vallist, "r");
-	    if (fd == NULL) {
-		perror(*vallist);
-		G_usage();
-		exit(1);
-	    }
-	    while (fgets(buf, sizeof buf, fd)) {
-		if (sscanf(buf, "%1s", x) != 1 || *x == '#')
-		    continue;
-		parse_d_mask_rule(buf, d_mask, *vallist);
-	    }
-	    fclose(fd);
-	}
-	else
-	    parse_d_mask_rule(*vallist, d_mask, (char *)NULL);
-    }
-
-    return 0;
-}
-
-int parse_d_mask_rule(char *vallist, d_Mask * d_mask, char *where)
-{
-    double a, b;
-    char junk[128];
-
-    /* #-# */
-    if (sscanf(vallist, "%lf-%lf", &a, &b) == 2)
-	add_d_mask_rule(d_mask, a, b, 0);
-    /* inf-# */
-    else if (sscanf(vallist, "%[^ -\t]-%lf", junk, &a) == 2)
-	add_d_mask_rule(d_mask, a, a, -1);
-
-    /* #-inf */
-    else if (sscanf(vallist, "%lf-%[^ \t]", &a, junk) == 2)
-	add_d_mask_rule(d_mask, a, a, 1);
-
-    /* # */
-    else if (sscanf(vallist, "%lf", &a) == 1)
-	add_d_mask_rule(d_mask, a, a, 0);
-
-    else {
-	if (where)
-	    G_fatal_error("%s: %s: illegal value spec", where, vallist);
-	else
-	    G_fatal_error("%s: illegal value spec", vallist);
-    }
-
-    return 0;
-}
-
-int
-process(char *name, char *mapset, int change_null, RASTER_MAP_TYPE map_type)
-{
-    struct Colors colr;
-    struct History hist;
-    struct Categories cats;
-    struct Quant quant;
-    int colr_ok;
-    int hist_ok;
-    int cats_ok;
-    int quant_ok;
-
-    G_suppress_warnings(1);
-    colr_ok = G_read_colors(name, mapset, &colr) > 0;
-    hist_ok = G_read_history(name, mapset, &hist) >= 0;
-    cats_ok = G_read_raster_cats(name, mapset, &cats) >= 0;
-
-    if (map_type != CELL_TYPE) {
-	G_quant_init(&quant);
-	quant_ok = G_read_quant(name, mapset, &quant);
-	G_suppress_warnings(0);
-    }
-
-    if (doit(name, mapset, change_null, map_type))
-	return 1;
-
-    if (colr_ok) {
-	G_write_colors(name, mapset, &colr);
-	G_free_colors(&colr);
-    }
-    if (hist_ok)
-	G_write_history(name, &hist);
-    if (cats_ok) {
-	cats.num = G_number_of_cats(name, mapset);
-	G_write_raster_cats(name, &cats);
-	G_free_cats(&cats);
-    }
-    if (map_type != CELL_TYPE && quant_ok)
-	G_write_quant(name, mapset, &quant);
-
-    return 0;
-}
-
-int doit(char *name, char *mapset, int change_null, RASTER_MAP_TYPE map_type)
-{
-    int new, old, row;
-    void *rast;
-
-    G_set_window(&cellhd);
-
-    old = G_open_cell_old(name, mapset);
-    if (old < 0)
-	G_fatal_error(_("Unable to open raster map <%s>"), name);
-
-    new = G_open_raster_new(name, map_type);
-
-    if (new < 0)
-	G_fatal_error(_("Unable to create raster map <%s>"), name);
-
-    rast = G_allocate_raster_buf(map_type);
-
-    G_message("Writing new data for [%s]... ", name);
-    /* the null file is written automatically */
-    for (row = 0; row < cellhd.rows; row++) {
-	G_percent(row, cellhd.rows, 1);
-
-	if (G_get_raster_row_nomask(old, rast, row, map_type) < 0) {
-	    G_warning("Can't read row %d", row);
-	    break;
-	}
-
-	mask_raster_array(rast, cellhd.cols, change_null, map_type);
-
-	if (G_put_raster_row(new, rast, map_type) < 0) {
-	    G_warning("Can't write row %d", row);
-	    break;
-	}
-    }
-    G_percent(row, cellhd.rows, 1);
-    G_free(rast);
-    G_close_cell(old);
-    if (row < cellhd.rows) {
-	G_unopen_cell(new);
-	return 1;
-    }
-    G_close_cell(new);
-    return 0;
-}

Copied: grass/trunk/raster/r.out.png/main.c (from rev 32801, grass/trunk/raster/r.out.png/r.out.png.c)
===================================================================
--- grass/trunk/raster/r.out.png/main.c	                        (rev 0)
+++ grass/trunk/raster/r.out.png/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,369 @@
+/*
+ ****************************************************************************
+ *
+ * MODULE:       r.out.png
+ * AUTHOR(S):    Bill Brown - USA-CERL
+ *               Alex Shevlakov - sixote at yahoo.com
+ * PURPOSE:      Export GRASS raster as non-georeferenced PNG image.
+ * COPYRIGHT:    (C) 2000 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.out.ppm by
+ * Written by Bill Brown, USA-CERL March 21, 1994
+ * 
+ */
+
+/* Use to convert grass raster map to PNG
+ * uses currently selected region
+ */
+
+/*              Alex Shevlakov, sixote at yahoo.com, 03/2000 
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef _MYINCLUDE_H
+#define _MYINCLUDE_H
+#include <png.h>
+#include "pngfunc.h"
+/* #include <pnm.h> this is already included from pngfunc.h */
+#endif /* _MYINCLUDE_H */
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#define DEF_RED 255
+#define DEF_GRN 255
+#define DEF_BLU 255
+
+typedef int FILEDESC;
+
+int main(int argc, char *argv[])
+{
+    struct GModule *module;
+    struct Option *rast, *png_file;
+    char *cellmap, *map, *p, *basename = NULL, *ofile;
+    char rastermap[1024];
+    unsigned char *set, *ored, *ogrn, *oblu;
+    CELL *cell_buf;
+    FCELL *fcell_buf;
+    DCELL *dcell_buf;
+    void *voidc;
+    int rtype, row, col, do_stdout = 0;
+    struct Cell_head w;
+    FILEDESC cellfile = 0;
+    FILE *fp;
+
+    /* now goes from pnmtopng.c* -A.Sh */
+    /*
+     * ** pnmtopng.c -
+     * ** read a portable anymap and produce a Portable Network Graphics file
+     * **
+     * ** derived from pnmtorast.c (c) 1990,1991 by Jef Poskanzer and some
+     * ** parts derived from ppmtogif.c by Marcel Wijkstra <wijkstra at fwi.uva.nl>
+     * ** thanks to Greg Roelofs <newt at pobox.com> for contributions and bug-fixes
+     * **
+     * ** Copyright (C) 1995-1998 by Alexander Lehmann <alex at hal.rhein-main.de>
+     * **                        and Willem van Schaik <willem at schaik.com>
+     * **
+     * ** Permission to use, copy, modify, and distribute this software and its
+     * ** documentation for any purpose and without fee is hereby granted, provided
+     * ** that the above copyright notice appear in all copies and that both that
+     * ** copyright notice and this permission notice appear in supporting
+     * ** documentation.  This software is provided "as is" without express or
+     * ** implied warranty.
+     */
+
+    png_struct *png_ptr;
+    png_info *info_ptr;
+
+    png_byte *line;
+    png_byte *pp;
+
+    /* these variables are declared static because gcc wasn't kidding
+     * about "variable XXX might be clobbered by `longjmp' or `vfork'"
+     * (stack corruption observed on Solaris 2.6 with gcc 2.8.1, even
+     * in the absence of any other error condition) */
+    static xelval maxmaxval;
+
+    static int depth;
+    static int filter;
+
+    /* these guys are initialized to quiet compiler warnings: */
+    maxmaxval = 255;
+    depth = 0;
+
+    G_gisinit(argv[0]);
+
+    rast = G_define_option();
+    rast->key = "input";
+    rast->type = TYPE_STRING;
+    rast->required = YES;
+    rast->multiple = NO;
+    rast->gisprompt = "old,cell,Raster";
+    rast->description = "Raster file to be converted.";
+
+    png_file = G_define_option();
+    png_file->key = "output";
+    png_file->type = TYPE_STRING;
+    png_file->required = NO;
+    png_file->multiple = NO;
+    png_file->answer = "<rasterfilename>.png";
+    png_file->description = "Name for new PNG file. (use out=- for stdout)";
+
+    /* see what can be done to convert'em -A.Sh.
+     * gscale = G_define_flag ();
+     * gscale->key = 'G';
+     * gscale->description = "Output greyscale instead of color";
+     */
+
+    module = G_define_module();
+    module->keywords = _("raster");
+    module->description =
+	"Export GRASS raster as non-georeferenced PNG image format.";
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    strncpy(rastermap, rast->answer, 1024 * sizeof(char));
+
+    if (strcmp(png_file->answer, "<rasterfilename>.png")) {
+	if (strcmp(png_file->answer, "-"))
+	    basename = G_store(png_file->answer);
+	else
+	    do_stdout = 1;
+    }
+    else {
+	map = p = rast->answer;
+	/* knock off any GRASS location suffix */
+	if ((char *)NULL != (p = strrchr(map, '@'))) {
+	    if (p != map)
+		*p = '\0';
+	}
+	basename = G_store(map);
+    }
+
+    if (basename) {
+	G_basename(basename, "png");
+	ofile = G_malloc(strlen(basename) + 5);
+	sprintf(ofile, "%s.png", basename);
+	G_free(basename);
+    }
+
+    /*G_get_set_window (&w); *//* 10/99 MN: check for current region */
+    G_get_window(&w);
+
+    G_message(_("rows = %d, cols = %d"), w.rows, w.cols);
+
+    /* open raster map for reading */
+    {
+	cellmap = G_find_file2("cell", rastermap, "");
+	if (!cellmap)
+	    G_fatal_error("Couldn't find raster map %s", rastermap);
+
+	if ((cellfile = G_open_cell_old(rast->answer, cellmap)) == -1)
+	    G_fatal_error("Not able to open cellfile for [%s]", rastermap);
+    }
+
+    cell_buf = G_allocate_c_raster_buf();
+    fcell_buf = G_allocate_f_raster_buf();
+    dcell_buf = G_allocate_d_raster_buf();
+
+    ored = (unsigned char *)G_malloc(w.cols * sizeof(unsigned char));
+    ogrn = (unsigned char *)G_malloc(w.cols * sizeof(unsigned char));
+    oblu = (unsigned char *)G_malloc(w.cols * sizeof(unsigned char));
+    set = (unsigned char *)G_malloc(w.cols * sizeof(unsigned char));
+
+    /* open png file for writing */
+    {
+	if (do_stdout)
+	    fp = stdout;
+	else if (NULL == (fp = fopen(ofile, "w")))
+	    G_fatal_error("Not able to open file for [%s]", ofile);
+	else
+	    G_free(ofile);
+    }
+
+    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
+				      &pnmtopng_jmpbuf_struct,
+				      pnmtopng_error_handler, NULL);
+    if (png_ptr == NULL) {
+	fclose(fp);
+	G_fatal_error("cannot allocate LIBPNG structure");
+    }
+
+    info_ptr = png_create_info_struct(png_ptr);
+    if (info_ptr == NULL) {
+	png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
+	fclose(fp);
+	G_fatal_error("cannot allocate LIBPNG structure");
+    }
+
+    if (setjmp(pnmtopng_jmpbuf_struct.jmpbuf)) {
+	png_destroy_write_struct(&png_ptr, &info_ptr);
+	fclose(fp);
+	G_fatal_error("setjmp returns error condition (1)");
+    }
+
+    depth = 8;			/*really??? */
+
+#ifdef OLDPNG
+    png_write_init(png_ptr);
+    png_info_init(info_ptr);
+#endif
+    png_init_io(png_ptr, fp);
+    info_ptr->width = w.cols;
+    info_ptr->height = w.rows;
+    info_ptr->bit_depth = depth;
+
+    /* explicit filter-type (or none) required */
+    if ((filter >= 0) && (filter <= 4)) {
+	png_set_filter(png_ptr, 0, filter);
+    }
+
+    /* zlib compression-level (or none) required */
+    /* ((compression >= -1) && (compression <= 9)) */
+    /* { */
+    png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
+    /* } */
+
+    G_message(_("Converting %s..."), rast->answer);
+
+    {
+	struct Colors colors;
+
+	G_read_colors(rast->answer, cellmap, &colors);
+
+	rtype = G_get_raster_map_type(cellfile);
+	if (rtype == CELL_TYPE)
+	    voidc = (CELL *) cell_buf;
+	else if (rtype == FCELL_TYPE)
+	    voidc = (FCELL *) fcell_buf;
+	else if (rtype == DCELL_TYPE)
+	    voidc = (DCELL *) dcell_buf;
+	else
+	    exit(EXIT_FAILURE);
+
+	/*if(!gscale->answer){ *//* 24BIT COLOR IMAGE */
+
+	if (1) {
+
+	    info_ptr->color_type = PNG_COLOR_TYPE_RGB;
+
+	    /* write the png-info struct */
+	    png_write_info(png_ptr, info_ptr);
+
+	    /* let libpng take care of, e.g., bit-depth conversions */
+	    png_set_packing(png_ptr);
+
+	    /* max: 3 color channels, one alpha channel, 16-bit */
+	    line = (png_byte *) G_malloc(w.cols * 8 * sizeof(char));
+
+	    for (row = 0; row < w.rows; row++) {
+
+		G_percent(row, w.rows, 5);
+		if (G_get_raster_row(cellfile, (void *)voidc, row, rtype) < 0)
+		    exit(EXIT_FAILURE);
+		G_lookup_raster_colors((void *)voidc, ored, ogrn, oblu, set,
+				       w.cols, &colors, rtype);
+
+		pp = line;
+
+		for (col = 0; col < w.cols; col++) {
+
+		    if (set[col]) {
+			*pp++ = ored[col];
+			*pp++ = ogrn[col];
+			*pp++ = oblu[col];
+		    }
+		    else {
+			*pp++ = DEF_RED;
+			*pp++ = DEF_GRN;
+			*pp++ = DEF_BLU;
+		    }
+
+
+		}
+
+		png_write_row(png_ptr, line);
+
+	    }
+
+	}
+	else {			/* GREYSCALE IMAGE */
+
+	    /*    
+	     * info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
+	     * 
+	     */
+
+
+	    /* pm_message ("don't know yet how to write grey - yumm!!"); */
+	    G_warning("don't know how to write grey scale!\n");
+	}
+
+	G_free_colors(&colors);
+
+    }
+    G_free(cell_buf);
+    G_free(fcell_buf);
+    G_free(dcell_buf);
+    G_free(ored);
+    G_free(ogrn);
+    G_free(oblu);
+    G_free(set);
+    G_close_cell(cellfile);
+
+
+
+    png_write_end(png_ptr, info_ptr);
+    /* png_write_destroy (png_ptr); this is no longer supported with libpng, al 11/2000 */
+    /* flush first because G_free (png_ptr) can segfault due to jmpbuf problems
+     * in png_write_destroy */
+    fflush(stdout);
+    /* G_free (png_ptr); */
+    /* G_free (info_ptr); */
+    png_destroy_write_struct(&png_ptr, &info_ptr);	/* al 11/2000 */
+
+
+    fclose(fp);
+
+    return (0);
+}
+
+#ifdef __STDC__
+static void pnmtopng_error_handler(png_structp png_ptr, png_const_charp msg)
+#else
+static void pnmtopng_error_handler(png_ptr, msg)
+     png_structp png_ptr;
+     png_const_charp msg;
+#endif
+{
+    jmpbuf_wrapper *jmpbuf_ptr;
+
+    /* this function, aside from the extra step of retrieving the "error
+     * pointer" (below) and the fact that it exists within the application
+     * rather than within libpng, is essentially identical to libpng's
+     * default error handler.  The second point is critical:  since both
+     * setjmp() and longjmp() are called from the same code, they are
+     * guaranteed to have compatible notions of how big a jmp_buf is,
+     * regardless of whether _BSD_SOURCE or anything else has (or has not)
+     * been defined. */
+
+    G_warning("pnmtopng:  fatal libpng error: %s", msg);
+
+    jmpbuf_ptr = png_get_error_ptr(png_ptr);
+    if (jmpbuf_ptr == NULL) {	/* we are completely hosed now */
+	G_fatal_error
+	    ("pnmtopng:  EXTREMELY fatal error: jmpbuf unrecoverable; terminating.");
+    }
+
+    longjmp(jmpbuf_ptr->jmpbuf, 1);
+}

Deleted: grass/trunk/raster/r.out.png/r.out.png.c
===================================================================
--- grass/trunk/raster/r.out.png/r.out.png.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/raster/r.out.png/r.out.png.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,369 +0,0 @@
-/*
- ****************************************************************************
- *
- * MODULE:       r.out.png
- * AUTHOR(S):    Bill Brown - USA-CERL
- *               Alex Shevlakov - sixote at yahoo.com
- * PURPOSE:      Export GRASS raster as non-georeferenced PNG image.
- * COPYRIGHT:    (C) 2000 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.out.ppm by
- * Written by Bill Brown, USA-CERL March 21, 1994
- * 
- */
-
-/* Use to convert grass raster map to PNG
- * uses currently selected region
- */
-
-/*              Alex Shevlakov, sixote at yahoo.com, 03/2000 
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-#ifndef _MYINCLUDE_H
-#define _MYINCLUDE_H
-#include <png.h>
-#include "pngfunc.h"
-/* #include <pnm.h> this is already included from pngfunc.h */
-#endif /* _MYINCLUDE_H */
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-#define DEF_RED 255
-#define DEF_GRN 255
-#define DEF_BLU 255
-
-typedef int FILEDESC;
-
-int main(int argc, char *argv[])
-{
-    struct GModule *module;
-    struct Option *rast, *png_file;
-    char *cellmap, *map, *p, *basename = NULL, *ofile;
-    char rastermap[1024];
-    unsigned char *set, *ored, *ogrn, *oblu;
-    CELL *cell_buf;
-    FCELL *fcell_buf;
-    DCELL *dcell_buf;
-    void *voidc;
-    int rtype, row, col, do_stdout = 0;
-    struct Cell_head w;
-    FILEDESC cellfile = 0;
-    FILE *fp;
-
-    /* now goes from pnmtopng.c* -A.Sh */
-    /*
-     * ** pnmtopng.c -
-     * ** read a portable anymap and produce a Portable Network Graphics file
-     * **
-     * ** derived from pnmtorast.c (c) 1990,1991 by Jef Poskanzer and some
-     * ** parts derived from ppmtogif.c by Marcel Wijkstra <wijkstra at fwi.uva.nl>
-     * ** thanks to Greg Roelofs <newt at pobox.com> for contributions and bug-fixes
-     * **
-     * ** Copyright (C) 1995-1998 by Alexander Lehmann <alex at hal.rhein-main.de>
-     * **                        and Willem van Schaik <willem at schaik.com>
-     * **
-     * ** Permission to use, copy, modify, and distribute this software and its
-     * ** documentation for any purpose and without fee is hereby granted, provided
-     * ** that the above copyright notice appear in all copies and that both that
-     * ** copyright notice and this permission notice appear in supporting
-     * ** documentation.  This software is provided "as is" without express or
-     * ** implied warranty.
-     */
-
-    png_struct *png_ptr;
-    png_info *info_ptr;
-
-    png_byte *line;
-    png_byte *pp;
-
-    /* these variables are declared static because gcc wasn't kidding
-     * about "variable XXX might be clobbered by `longjmp' or `vfork'"
-     * (stack corruption observed on Solaris 2.6 with gcc 2.8.1, even
-     * in the absence of any other error condition) */
-    static xelval maxmaxval;
-
-    static int depth;
-    static int filter;
-
-    /* these guys are initialized to quiet compiler warnings: */
-    maxmaxval = 255;
-    depth = 0;
-
-    G_gisinit(argv[0]);
-
-    rast = G_define_option();
-    rast->key = "input";
-    rast->type = TYPE_STRING;
-    rast->required = YES;
-    rast->multiple = NO;
-    rast->gisprompt = "old,cell,Raster";
-    rast->description = "Raster file to be converted.";
-
-    png_file = G_define_option();
-    png_file->key = "output";
-    png_file->type = TYPE_STRING;
-    png_file->required = NO;
-    png_file->multiple = NO;
-    png_file->answer = "<rasterfilename>.png";
-    png_file->description = "Name for new PNG file. (use out=- for stdout)";
-
-    /* see what can be done to convert'em -A.Sh.
-     * gscale = G_define_flag ();
-     * gscale->key = 'G';
-     * gscale->description = "Output greyscale instead of color";
-     */
-
-    module = G_define_module();
-    module->keywords = _("raster");
-    module->description =
-	"Export GRASS raster as non-georeferenced PNG image format.";
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    strncpy(rastermap, rast->answer, 1024 * sizeof(char));
-
-    if (strcmp(png_file->answer, "<rasterfilename>.png")) {
-	if (strcmp(png_file->answer, "-"))
-	    basename = G_store(png_file->answer);
-	else
-	    do_stdout = 1;
-    }
-    else {
-	map = p = rast->answer;
-	/* knock off any GRASS location suffix */
-	if ((char *)NULL != (p = strrchr(map, '@'))) {
-	    if (p != map)
-		*p = '\0';
-	}
-	basename = G_store(map);
-    }
-
-    if (basename) {
-	G_basename(basename, "png");
-	ofile = G_malloc(strlen(basename) + 5);
-	sprintf(ofile, "%s.png", basename);
-	G_free(basename);
-    }
-
-    /*G_get_set_window (&w); *//* 10/99 MN: check for current region */
-    G_get_window(&w);
-
-    G_message(_("rows = %d, cols = %d"), w.rows, w.cols);
-
-    /* open raster map for reading */
-    {
-	cellmap = G_find_file2("cell", rastermap, "");
-	if (!cellmap)
-	    G_fatal_error("Couldn't find raster map %s", rastermap);
-
-	if ((cellfile = G_open_cell_old(rast->answer, cellmap)) == -1)
-	    G_fatal_error("Not able to open cellfile for [%s]", rastermap);
-    }
-
-    cell_buf = G_allocate_c_raster_buf();
-    fcell_buf = G_allocate_f_raster_buf();
-    dcell_buf = G_allocate_d_raster_buf();
-
-    ored = (unsigned char *)G_malloc(w.cols * sizeof(unsigned char));
-    ogrn = (unsigned char *)G_malloc(w.cols * sizeof(unsigned char));
-    oblu = (unsigned char *)G_malloc(w.cols * sizeof(unsigned char));
-    set = (unsigned char *)G_malloc(w.cols * sizeof(unsigned char));
-
-    /* open png file for writing */
-    {
-	if (do_stdout)
-	    fp = stdout;
-	else if (NULL == (fp = fopen(ofile, "w")))
-	    G_fatal_error("Not able to open file for [%s]", ofile);
-	else
-	    G_free(ofile);
-    }
-
-    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
-				      &pnmtopng_jmpbuf_struct,
-				      pnmtopng_error_handler, NULL);
-    if (png_ptr == NULL) {
-	fclose(fp);
-	G_fatal_error("cannot allocate LIBPNG structure");
-    }
-
-    info_ptr = png_create_info_struct(png_ptr);
-    if (info_ptr == NULL) {
-	png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
-	fclose(fp);
-	G_fatal_error("cannot allocate LIBPNG structure");
-    }
-
-    if (setjmp(pnmtopng_jmpbuf_struct.jmpbuf)) {
-	png_destroy_write_struct(&png_ptr, &info_ptr);
-	fclose(fp);
-	G_fatal_error("setjmp returns error condition (1)");
-    }
-
-    depth = 8;			/*really??? */
-
-#ifdef OLDPNG
-    png_write_init(png_ptr);
-    png_info_init(info_ptr);
-#endif
-    png_init_io(png_ptr, fp);
-    info_ptr->width = w.cols;
-    info_ptr->height = w.rows;
-    info_ptr->bit_depth = depth;
-
-    /* explicit filter-type (or none) required */
-    if ((filter >= 0) && (filter <= 4)) {
-	png_set_filter(png_ptr, 0, filter);
-    }
-
-    /* zlib compression-level (or none) required */
-    /* ((compression >= -1) && (compression <= 9)) */
-    /* { */
-    png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
-    /* } */
-
-    G_message(_("Converting %s..."), rast->answer);
-
-    {
-	struct Colors colors;
-
-	G_read_colors(rast->answer, cellmap, &colors);
-
-	rtype = G_get_raster_map_type(cellfile);
-	if (rtype == CELL_TYPE)
-	    voidc = (CELL *) cell_buf;
-	else if (rtype == FCELL_TYPE)
-	    voidc = (FCELL *) fcell_buf;
-	else if (rtype == DCELL_TYPE)
-	    voidc = (DCELL *) dcell_buf;
-	else
-	    exit(EXIT_FAILURE);
-
-	/*if(!gscale->answer){ *//* 24BIT COLOR IMAGE */
-
-	if (1) {
-
-	    info_ptr->color_type = PNG_COLOR_TYPE_RGB;
-
-	    /* write the png-info struct */
-	    png_write_info(png_ptr, info_ptr);
-
-	    /* let libpng take care of, e.g., bit-depth conversions */
-	    png_set_packing(png_ptr);
-
-	    /* max: 3 color channels, one alpha channel, 16-bit */
-	    line = (png_byte *) G_malloc(w.cols * 8 * sizeof(char));
-
-	    for (row = 0; row < w.rows; row++) {
-
-		G_percent(row, w.rows, 5);
-		if (G_get_raster_row(cellfile, (void *)voidc, row, rtype) < 0)
-		    exit(EXIT_FAILURE);
-		G_lookup_raster_colors((void *)voidc, ored, ogrn, oblu, set,
-				       w.cols, &colors, rtype);
-
-		pp = line;
-
-		for (col = 0; col < w.cols; col++) {
-
-		    if (set[col]) {
-			*pp++ = ored[col];
-			*pp++ = ogrn[col];
-			*pp++ = oblu[col];
-		    }
-		    else {
-			*pp++ = DEF_RED;
-			*pp++ = DEF_GRN;
-			*pp++ = DEF_BLU;
-		    }
-
-
-		}
-
-		png_write_row(png_ptr, line);
-
-	    }
-
-	}
-	else {			/* GREYSCALE IMAGE */
-
-	    /*    
-	     * info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
-	     * 
-	     */
-
-
-	    /* pm_message ("don't know yet how to write grey - yumm!!"); */
-	    G_warning("don't know how to write grey scale!\n");
-	}
-
-	G_free_colors(&colors);
-
-    }
-    G_free(cell_buf);
-    G_free(fcell_buf);
-    G_free(dcell_buf);
-    G_free(ored);
-    G_free(ogrn);
-    G_free(oblu);
-    G_free(set);
-    G_close_cell(cellfile);
-
-
-
-    png_write_end(png_ptr, info_ptr);
-    /* png_write_destroy (png_ptr); this is no longer supported with libpng, al 11/2000 */
-    /* flush first because G_free (png_ptr) can segfault due to jmpbuf problems
-     * in png_write_destroy */
-    fflush(stdout);
-    /* G_free (png_ptr); */
-    /* G_free (info_ptr); */
-    png_destroy_write_struct(&png_ptr, &info_ptr);	/* al 11/2000 */
-
-
-    fclose(fp);
-
-    return (0);
-}
-
-#ifdef __STDC__
-static void pnmtopng_error_handler(png_structp png_ptr, png_const_charp msg)
-#else
-static void pnmtopng_error_handler(png_ptr, msg)
-     png_structp png_ptr;
-     png_const_charp msg;
-#endif
-{
-    jmpbuf_wrapper *jmpbuf_ptr;
-
-    /* this function, aside from the extra step of retrieving the "error
-     * pointer" (below) and the fact that it exists within the application
-     * rather than within libpng, is essentially identical to libpng's
-     * default error handler.  The second point is critical:  since both
-     * setjmp() and longjmp() are called from the same code, they are
-     * guaranteed to have compatible notions of how big a jmp_buf is,
-     * regardless of whether _BSD_SOURCE or anything else has (or has not)
-     * been defined. */
-
-    G_warning("pnmtopng:  fatal libpng error: %s", msg);
-
-    jmpbuf_ptr = png_get_error_ptr(png_ptr);
-    if (jmpbuf_ptr == NULL) {	/* we are completely hosed now */
-	G_fatal_error
-	    ("pnmtopng:  EXTREMELY fatal error: jmpbuf unrecoverable; terminating.");
-    }
-
-    longjmp(jmpbuf_ptr->jmpbuf, 1);
-}

Copied: grass/trunk/raster/r.out.tiff/main.c (from rev 32801, grass/trunk/raster/r.out.tiff/r.out.tiff.c)
===================================================================
--- grass/trunk/raster/r.out.tiff/main.c	                        (rev 0)
+++ grass/trunk/raster/r.out.tiff/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,416 @@
+
+/****************************************************************************
+ *
+ * MODULE:       r.out.tiff
+ *   
+ * AUTHOR(S):    Sam Leffler
+ *               Updated by Marco Valagussa <marco duffy.crcc.it>,
+ *               Markus Neteler, Eric G. Miller, Luca Cristelli
+ *
+ * PURPOSE:      Exports a GRASS raster map to a 8/24bit TIFF image file
+ *               at the pixel resolution of the currently defined region.
+
+ * 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.
+ *
+ *****************************************************************************/
+/* 
+ * Added support for Tiled TIFF output ( -l switch )
+ * Luca Cristelli (luca.cristelli ies.it) 1/2001
+ * 
+ * Added flag to write a TIFF World file like r.out.arctiff
+ * Eric G. Miller 4-Nov-2000
+ *
+ * removed LZW support 5/5000
+ *
+ * Corrected G_set_window to G_get_window to make r.out.tiff sensitive
+ * to region settings.   - Markus Neteler  (neteler geog.uni-hannover.de
+ * 8/98        
+ *
+ * This r.tiff version uses the standard libtiff from your system.
+ *  8. June 98 Marco Valagussa <marco duffy.crcc.it>
+ *
+ * Original version:
+ * Portions Copyright (c) 1988, 1990 by Sam Leffler.
+ * All rights reserved.
+ *
+ * This file is provided for unrestricted use provided that this
+ * legend is included on all tape media and as a part of the
+ * software program in whole or part.  Users may copy, modify or
+ * distribute this file at will.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <float.h>
+#include <sys/types.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "rasterfile.h"
+#include "tiffio.h"
+
+
+/* global variables */
+#ifdef __MINGW32__
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned long u_long;
+#endif
+
+#define MAX_TILE_LENGTH 512
+
+#define	howmany(x, y)	(((x)+((y)-1))/(y))
+#define	streq(a,b)	(strcmp(a,b) == 0)
+
+u_short config = PLANARCONFIG_CONTIG;
+u_short compression = -1;
+u_short rowsperstrip = 0;
+
+/* global functions */
+static int write_tfw(const char *, const struct Cell_head *);
+
+int main(int argc, char *argv[])
+{
+    u_char *buf, *tmpptr;
+    int row, linebytes;
+    TIFF *out;
+    int in;
+    struct rasterfile h;
+    struct Option *inopt, *outopt, *compopt;
+    struct Flag *pflag, *lflag, *tflag;
+    CELL *cell, *cellptr, *cells[MAX_TILE_LENGTH];
+    struct Cell_head cellhd;
+    struct GModule *module;
+    int col, tfw, palette, tiled;
+    char *mapset, *basename, *filename;
+    struct Colors colors;
+    int red, grn, blu, mapsize, isfp;
+
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("raster, export");
+    module->description =
+	_("Exports a GRASS raster map to a 8/24bit TIFF image file "
+	  "at the pixel resolution of the currently defined region.");
+
+    inopt = G_define_standard_option(G_OPT_R_INPUT);
+
+    outopt = G_define_option();
+    outopt->key = "output";
+    outopt->type = TYPE_STRING;
+    outopt->required = YES;
+    outopt->gisprompt = "new_file,tiff,tiff";
+    outopt->description = _("Name for new TIFF file");
+
+    compopt = G_define_option();
+    compopt->key = "compression";
+    compopt->type = TYPE_STRING;
+    compopt->required = NO;
+    compopt->options = "none,packbit,deflate,lzw";
+    compopt->description = _("TIFF file compression");
+    compopt->answer = "none";
+
+    pflag = G_define_flag();
+    pflag->key = 'p';
+    pflag->description = _("TIFF Palette output (8bit instead of 24bit).");
+
+    tflag = G_define_flag();
+    tflag->key = 't';
+    tflag->description = _("Output TIFF world file");
+
+    lflag = G_define_flag();
+    lflag->key = 'l';
+    lflag->description = _("Output Tiled TIFF");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    if (strncmp(compopt->answer, "packbit", 7) == 0)
+	compression = COMPRESSION_PACKBITS;
+    else if (strncmp(compopt->answer, "deflate", 7) == 0)
+	compression = COMPRESSION_DEFLATE;
+    else if (strncmp(compopt->answer, "lzw", 3) == 0)
+	compression = COMPRESSION_LZW;
+    else
+	compression = COMPRESSION_NONE;
+
+    tiled = lflag->answer;
+    palette = pflag->answer;
+    tfw = tflag->answer;
+
+    mapset = G_find_cell(inopt->answer, "");
+    if (!mapset)
+	G_fatal_error(_("Raster map <%s> not found"), inopt->answer);
+
+    if ((G_get_cellhd(inopt->answer, mapset, &cellhd) < 0))
+	G_fatal_error(_("Unable to read header of raster map <%s>"),
+		      inopt->answer);
+
+    if ((G_get_window(&cellhd) < 0))
+	G_fatal_error(_("Can't set window"));
+
+    G_read_colors(inopt->answer, mapset, &colors);
+    if ((isfp = G_raster_map_is_fp(inopt->answer, mapset)))
+	G_warning(_("Raster map <%s> in mapset <%s> is a floating point "
+		    "map. Decimal values will be rounded to integer!"),
+		  inopt->answer, mapset);
+
+    G_set_null_value_color(255, 255, 255, &colors);
+    if (palette && (colors.cmax - colors.cmin > 255))
+	G_fatal_error(_("Color map for palette must have less "
+			"than 256 colors for the available range of data"));
+
+    cell = G_allocate_cell_buf();
+    if ((in = G_open_cell_old(inopt->answer, mapset)) < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), inopt->answer);
+
+    basename = G_store(outopt->answer);
+    G_basename(basename, "tiff");
+    G_basename(basename, "tif");
+    filename = G_malloc(strlen(basename) + 5);
+    sprintf(filename, "%s.tif", basename);
+
+    out = TIFFOpen(filename, "w");
+    if (out == NULL)
+	G_fatal_error(_("Unable to open TIFF file <%s>"), filename);
+
+    h.ras_width = cellhd.cols;
+    h.ras_height = cellhd.rows;
+    h.ras_depth = 24;
+    if (pflag->answer)
+	h.ras_depth = 8;
+
+    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, h.ras_width);
+    TIFFSetField(out, TIFFTAG_IMAGELENGTH, h.ras_height);
+    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
+    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, h.ras_depth > 8 ? 3 : 1);
+    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, h.ras_depth > 1 ? 8 : 1);
+    TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
+    mapsize = 1 << h.ras_depth;
+
+    if (palette) {
+	register u_short *redp, *grnp, *blup, *mapptr;
+	register int i;
+
+	G_debug(1, "max %f min %f mapsize %d",
+		colors.cmax, colors.cmin, mapsize);
+
+	mapptr = (u_short *) G_calloc(mapsize * 3, sizeof(u_short));
+	redp = mapptr;
+	grnp = redp + mapsize;
+	blup = redp + mapsize * 2;
+
+	/* XXX -- set pointers up before we step through arrays */
+#define	SCALE(x)	(((x)*((1L<<16)-1))/255)
+
+	for (i = colors.cmin; i <= colors.cmax; i++, redp++, grnp++, blup++) {
+	    G_get_color(i, &red, &grn, &blu, &colors);
+	    *redp = (u_short) (SCALE(red));
+	    *grnp = (u_short) (SCALE(grn));
+	    *blup = (u_short) (SCALE(blu));
+
+	    G_debug(1, " %d : %d %d %d   %d %d %d",
+		    i, red, grn, blu, *redp, *grnp, *blup);
+	}
+
+	TIFFSetField(out, TIFFTAG_COLORMAP,
+		     mapptr, mapptr + mapsize, mapptr + mapsize * 2);
+	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE);
+	TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
+    }
+    else {
+	/* XXX this is bogus... */
+	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, h.ras_depth == 24 ?
+		     PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK);
+	TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
+    }
+
+    if (tiled) {
+	int tilewidth = 128;
+	int tilelength = 128;
+	int imagewidth, imagelength;
+	int spp;
+	char *obuf;
+	char *tptr;
+	uint32 col, oskew, width, i, j;
+
+	imagewidth = h.ras_width;
+	imagelength = h.ras_height;
+	spp = h.ras_depth;
+
+	TIFFSetField(out, TIFFTAG_TILEWIDTH, tilewidth);
+	TIFFSetField(out, TIFFTAG_TILELENGTH, tilelength);
+	obuf = (char *)_TIFFmalloc(TIFFTileSize(out));
+
+	G_debug(1, "Tile buff size: %d", TIFFTileSize(out));
+
+	/* allocate cell buffers */
+	for (i = 0; i < tilelength; i++)
+	    cells[i] = G_allocate_cell_buf();
+
+	/* build tiff tiles from grass buffer */
+	for (row = 0; row < imagelength; row += tilelength) {
+	    uint32 nrow =
+		(row + tilelength >
+		 imagelength) ? imagelength - row : tilelength;
+	    uint32 colb = 0;
+
+	    for (i = 0; i < nrow; i++) {
+		if (G_get_c_raster_row(in, cells[i], row + i) < 0)
+		    G_fatal_error(_("Reading raster map..."));
+	    }
+
+	    for (col = 0; col < imagewidth; col += tilewidth) {
+		tsample_t s;
+
+		i = nrow;
+		tptr = obuf;
+		spp = 1;
+		s = 0;
+		oskew = 0;
+		width = tilewidth;
+
+		G_debug(1, "Tile #: r %d, c %d, s %d", row, col, s);
+
+		/*
+		 * Tile is clipped horizontally.  Calculate
+		 * visible portion and skewing factors.
+		 */
+		if (colb + tilewidth > imagewidth) {
+		    width = (imagewidth - colb);
+		    oskew = tilewidth - width;
+		}
+
+		for (i = 0; i < nrow; i++) {
+		    cellptr = cells[i];
+
+		    if (palette) {
+			cellptr += col;
+			for (j = 0; j < width; j++)
+			    *tptr++ = (u_char) * cellptr++;
+
+			tptr += oskew;
+		    }
+		    else {
+			for (j = 0; j < width; j++) {
+			    G_get_color(cellptr[col + j], &red, &grn, &blu,
+					&colors);
+			    *tptr++ = (u_char) red;
+			    *tptr++ = (u_char) grn;
+			    *tptr++ = (u_char) blu;
+			}
+
+			tptr += oskew * 3;
+		    }
+
+		    G_debug(3, "row #: i %d tptr %lx", i, (long)tptr);
+		}
+
+		G_debug(1, "Write Tile #: col %d row %d s %d", col, row, s);
+
+		if (TIFFWriteTile(out, obuf, col, row, 0, s) < 0) {
+		    _TIFFfree(obuf);
+		    return (-1);
+		}
+
+		G_percent(row, h.ras_height, 1);
+	    }
+
+	    colb += tilewidth;
+	}
+    }
+    else {
+	linebytes = ((h.ras_depth * h.ras_width + 15) >> 3) & ~1;
+
+	G_debug(1, "linebytes = %d, TIFFscanlinesize = %d", linebytes,
+		TIFFScanlineSize(out));
+
+	if (TIFFScanlineSize(out) > linebytes)
+	    buf = (u_char *) G_malloc(linebytes);
+	else
+	    buf = (u_char *) G_malloc(TIFFScanlineSize(out));
+
+	if (rowsperstrip != (u_short) - 1)
+	    rowsperstrip = (u_short) (8 * 1024 / linebytes);
+
+	G_debug(1, "rowsperstrip = %d", rowsperstrip);
+
+	TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
+		     rowsperstrip == 0 ? 1 : rowsperstrip);
+
+	for (row = 0; row < h.ras_height; row++) {
+	    tmpptr = buf;
+
+	    G_percent(row, h.ras_height, 2);
+
+	    if (G_get_c_raster_row(in, cell, row) < 0)
+		exit(EXIT_FAILURE);
+
+	    cellptr = cell;
+	    if (palette) {
+		for (col = 0; col < h.ras_width; col++)
+		    *tmpptr++ = (u_char) (*cellptr++ - colors.cmin);
+	    }
+	    else {
+		for (col = 0; col < h.ras_width; col++) {
+		    G_get_color(cell[col], &red, &grn, &blu, &colors);
+		    *tmpptr++ = (u_char) red;
+		    *tmpptr++ = (u_char) grn;
+		    *tmpptr++ = (u_char) blu;
+		}
+	    }
+
+	    if (TIFFWriteScanline(out, buf, row, 0) < 0)
+		break;
+	}
+
+	G_percent(row, h.ras_height, 2);
+    }
+
+    (void)TIFFClose(out);
+
+    if (tfw) {
+	sprintf(filename, "%s.tfw", basename);
+	write_tfw(filename, &cellhd);
+    }
+
+    G_free(filename);
+    G_free(basename);
+
+    G_done_msg(" ");
+
+    exit(EXIT_SUCCESS);
+}
+
+
+static int write_tfw(const char *fname, const struct Cell_head *win)
+{
+    int width = DBL_DIG;
+    FILE *outfile;
+
+    G_message(_("Writing TIFF World file"));
+
+    if (fname == NULL)
+	G_fatal_error(_("Got null file name"));
+    if (win == NULL)
+	G_fatal_error(_("Got null region struct"));
+
+    if ((outfile = fopen(fname, "w")) == NULL)
+	G_fatal_error(_("Unable to open TIFF world file for writing"));
+
+    fprintf(outfile, "%36.*f \n", width, win->ew_res);
+    fprintf(outfile, "%36.*f \n", width, 0.0);
+    fprintf(outfile, "%36.*f \n", width, 0.0);
+    fprintf(outfile, "%36.*f \n", width, -1 * win->ns_res);
+    fprintf(outfile, "%36.*f \n", width, win->west + win->ew_res / 2.0);
+    fprintf(outfile, "%36.*f \n", width, win->north - win->ns_res / 2.0);
+
+    fclose(outfile);
+    return 0;
+}

Deleted: grass/trunk/raster/r.out.tiff/r.out.tiff.c
===================================================================
--- grass/trunk/raster/r.out.tiff/r.out.tiff.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/raster/r.out.tiff/r.out.tiff.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,416 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       r.out.tiff
- *   
- * AUTHOR(S):    Sam Leffler
- *               Updated by Marco Valagussa <marco duffy.crcc.it>,
- *               Markus Neteler, Eric G. Miller, Luca Cristelli
- *
- * PURPOSE:      Exports a GRASS raster map to a 8/24bit TIFF image file
- *               at the pixel resolution of the currently defined region.
-
- * 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.
- *
- *****************************************************************************/
-/* 
- * Added support for Tiled TIFF output ( -l switch )
- * Luca Cristelli (luca.cristelli ies.it) 1/2001
- * 
- * Added flag to write a TIFF World file like r.out.arctiff
- * Eric G. Miller 4-Nov-2000
- *
- * removed LZW support 5/5000
- *
- * Corrected G_set_window to G_get_window to make r.out.tiff sensitive
- * to region settings.   - Markus Neteler  (neteler geog.uni-hannover.de
- * 8/98        
- *
- * This r.tiff version uses the standard libtiff from your system.
- *  8. June 98 Marco Valagussa <marco duffy.crcc.it>
- *
- * Original version:
- * Portions Copyright (c) 1988, 1990 by Sam Leffler.
- * All rights reserved.
- *
- * This file is provided for unrestricted use provided that this
- * legend is included on all tape media and as a part of the
- * software program in whole or part.  Users may copy, modify or
- * distribute this file at will.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <float.h>
-#include <sys/types.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "rasterfile.h"
-#include "tiffio.h"
-
-
-/* global variables */
-#ifdef __MINGW32__
-typedef unsigned char u_char;
-typedef unsigned short u_short;
-typedef unsigned long u_long;
-#endif
-
-#define MAX_TILE_LENGTH 512
-
-#define	howmany(x, y)	(((x)+((y)-1))/(y))
-#define	streq(a,b)	(strcmp(a,b) == 0)
-
-u_short config = PLANARCONFIG_CONTIG;
-u_short compression = -1;
-u_short rowsperstrip = 0;
-
-/* global functions */
-static int write_tfw(const char *, const struct Cell_head *);
-
-int main(int argc, char *argv[])
-{
-    u_char *buf, *tmpptr;
-    int row, linebytes;
-    TIFF *out;
-    int in;
-    struct rasterfile h;
-    struct Option *inopt, *outopt, *compopt;
-    struct Flag *pflag, *lflag, *tflag;
-    CELL *cell, *cellptr, *cells[MAX_TILE_LENGTH];
-    struct Cell_head cellhd;
-    struct GModule *module;
-    int col, tfw, palette, tiled;
-    char *mapset, *basename, *filename;
-    struct Colors colors;
-    int red, grn, blu, mapsize, isfp;
-
-    G_gisinit(argv[0]);
-
-    /* Set description */
-    module = G_define_module();
-    module->keywords = _("raster, export");
-    module->description =
-	_("Exports a GRASS raster map to a 8/24bit TIFF image file "
-	  "at the pixel resolution of the currently defined region.");
-
-    inopt = G_define_standard_option(G_OPT_R_INPUT);
-
-    outopt = G_define_option();
-    outopt->key = "output";
-    outopt->type = TYPE_STRING;
-    outopt->required = YES;
-    outopt->gisprompt = "new_file,tiff,tiff";
-    outopt->description = _("Name for new TIFF file");
-
-    compopt = G_define_option();
-    compopt->key = "compression";
-    compopt->type = TYPE_STRING;
-    compopt->required = NO;
-    compopt->options = "none,packbit,deflate,lzw";
-    compopt->description = _("TIFF file compression");
-    compopt->answer = "none";
-
-    pflag = G_define_flag();
-    pflag->key = 'p';
-    pflag->description = _("TIFF Palette output (8bit instead of 24bit).");
-
-    tflag = G_define_flag();
-    tflag->key = 't';
-    tflag->description = _("Output TIFF world file");
-
-    lflag = G_define_flag();
-    lflag->key = 'l';
-    lflag->description = _("Output Tiled TIFF");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    if (strncmp(compopt->answer, "packbit", 7) == 0)
-	compression = COMPRESSION_PACKBITS;
-    else if (strncmp(compopt->answer, "deflate", 7) == 0)
-	compression = COMPRESSION_DEFLATE;
-    else if (strncmp(compopt->answer, "lzw", 3) == 0)
-	compression = COMPRESSION_LZW;
-    else
-	compression = COMPRESSION_NONE;
-
-    tiled = lflag->answer;
-    palette = pflag->answer;
-    tfw = tflag->answer;
-
-    mapset = G_find_cell(inopt->answer, "");
-    if (!mapset)
-	G_fatal_error(_("Raster map <%s> not found"), inopt->answer);
-
-    if ((G_get_cellhd(inopt->answer, mapset, &cellhd) < 0))
-	G_fatal_error(_("Unable to read header of raster map <%s>"),
-		      inopt->answer);
-
-    if ((G_get_window(&cellhd) < 0))
-	G_fatal_error(_("Can't set window"));
-
-    G_read_colors(inopt->answer, mapset, &colors);
-    if ((isfp = G_raster_map_is_fp(inopt->answer, mapset)))
-	G_warning(_("Raster map <%s> in mapset <%s> is a floating point "
-		    "map. Decimal values will be rounded to integer!"),
-		  inopt->answer, mapset);
-
-    G_set_null_value_color(255, 255, 255, &colors);
-    if (palette && (colors.cmax - colors.cmin > 255))
-	G_fatal_error(_("Color map for palette must have less "
-			"than 256 colors for the available range of data"));
-
-    cell = G_allocate_cell_buf();
-    if ((in = G_open_cell_old(inopt->answer, mapset)) < 0)
-	G_fatal_error(_("Unable to open raster map <%s>"), inopt->answer);
-
-    basename = G_store(outopt->answer);
-    G_basename(basename, "tiff");
-    G_basename(basename, "tif");
-    filename = G_malloc(strlen(basename) + 5);
-    sprintf(filename, "%s.tif", basename);
-
-    out = TIFFOpen(filename, "w");
-    if (out == NULL)
-	G_fatal_error(_("Unable to open TIFF file <%s>"), filename);
-
-    h.ras_width = cellhd.cols;
-    h.ras_height = cellhd.rows;
-    h.ras_depth = 24;
-    if (pflag->answer)
-	h.ras_depth = 8;
-
-    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, h.ras_width);
-    TIFFSetField(out, TIFFTAG_IMAGELENGTH, h.ras_height);
-    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
-    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, h.ras_depth > 8 ? 3 : 1);
-    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, h.ras_depth > 1 ? 8 : 1);
-    TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
-    mapsize = 1 << h.ras_depth;
-
-    if (palette) {
-	register u_short *redp, *grnp, *blup, *mapptr;
-	register int i;
-
-	G_debug(1, "max %f min %f mapsize %d",
-		colors.cmax, colors.cmin, mapsize);
-
-	mapptr = (u_short *) G_calloc(mapsize * 3, sizeof(u_short));
-	redp = mapptr;
-	grnp = redp + mapsize;
-	blup = redp + mapsize * 2;
-
-	/* XXX -- set pointers up before we step through arrays */
-#define	SCALE(x)	(((x)*((1L<<16)-1))/255)
-
-	for (i = colors.cmin; i <= colors.cmax; i++, redp++, grnp++, blup++) {
-	    G_get_color(i, &red, &grn, &blu, &colors);
-	    *redp = (u_short) (SCALE(red));
-	    *grnp = (u_short) (SCALE(grn));
-	    *blup = (u_short) (SCALE(blu));
-
-	    G_debug(1, " %d : %d %d %d   %d %d %d",
-		    i, red, grn, blu, *redp, *grnp, *blup);
-	}
-
-	TIFFSetField(out, TIFFTAG_COLORMAP,
-		     mapptr, mapptr + mapsize, mapptr + mapsize * 2);
-	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE);
-	TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
-    }
-    else {
-	/* XXX this is bogus... */
-	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, h.ras_depth == 24 ?
-		     PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK);
-	TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
-    }
-
-    if (tiled) {
-	int tilewidth = 128;
-	int tilelength = 128;
-	int imagewidth, imagelength;
-	int spp;
-	char *obuf;
-	char *tptr;
-	uint32 col, oskew, width, i, j;
-
-	imagewidth = h.ras_width;
-	imagelength = h.ras_height;
-	spp = h.ras_depth;
-
-	TIFFSetField(out, TIFFTAG_TILEWIDTH, tilewidth);
-	TIFFSetField(out, TIFFTAG_TILELENGTH, tilelength);
-	obuf = (char *)_TIFFmalloc(TIFFTileSize(out));
-
-	G_debug(1, "Tile buff size: %d", TIFFTileSize(out));
-
-	/* allocate cell buffers */
-	for (i = 0; i < tilelength; i++)
-	    cells[i] = G_allocate_cell_buf();
-
-	/* build tiff tiles from grass buffer */
-	for (row = 0; row < imagelength; row += tilelength) {
-	    uint32 nrow =
-		(row + tilelength >
-		 imagelength) ? imagelength - row : tilelength;
-	    uint32 colb = 0;
-
-	    for (i = 0; i < nrow; i++) {
-		if (G_get_c_raster_row(in, cells[i], row + i) < 0)
-		    G_fatal_error(_("Reading raster map..."));
-	    }
-
-	    for (col = 0; col < imagewidth; col += tilewidth) {
-		tsample_t s;
-
-		i = nrow;
-		tptr = obuf;
-		spp = 1;
-		s = 0;
-		oskew = 0;
-		width = tilewidth;
-
-		G_debug(1, "Tile #: r %d, c %d, s %d", row, col, s);
-
-		/*
-		 * Tile is clipped horizontally.  Calculate
-		 * visible portion and skewing factors.
-		 */
-		if (colb + tilewidth > imagewidth) {
-		    width = (imagewidth - colb);
-		    oskew = tilewidth - width;
-		}
-
-		for (i = 0; i < nrow; i++) {
-		    cellptr = cells[i];
-
-		    if (palette) {
-			cellptr += col;
-			for (j = 0; j < width; j++)
-			    *tptr++ = (u_char) * cellptr++;
-
-			tptr += oskew;
-		    }
-		    else {
-			for (j = 0; j < width; j++) {
-			    G_get_color(cellptr[col + j], &red, &grn, &blu,
-					&colors);
-			    *tptr++ = (u_char) red;
-			    *tptr++ = (u_char) grn;
-			    *tptr++ = (u_char) blu;
-			}
-
-			tptr += oskew * 3;
-		    }
-
-		    G_debug(3, "row #: i %d tptr %lx", i, (long)tptr);
-		}
-
-		G_debug(1, "Write Tile #: col %d row %d s %d", col, row, s);
-
-		if (TIFFWriteTile(out, obuf, col, row, 0, s) < 0) {
-		    _TIFFfree(obuf);
-		    return (-1);
-		}
-
-		G_percent(row, h.ras_height, 1);
-	    }
-
-	    colb += tilewidth;
-	}
-    }
-    else {
-	linebytes = ((h.ras_depth * h.ras_width + 15) >> 3) & ~1;
-
-	G_debug(1, "linebytes = %d, TIFFscanlinesize = %d", linebytes,
-		TIFFScanlineSize(out));
-
-	if (TIFFScanlineSize(out) > linebytes)
-	    buf = (u_char *) G_malloc(linebytes);
-	else
-	    buf = (u_char *) G_malloc(TIFFScanlineSize(out));
-
-	if (rowsperstrip != (u_short) - 1)
-	    rowsperstrip = (u_short) (8 * 1024 / linebytes);
-
-	G_debug(1, "rowsperstrip = %d", rowsperstrip);
-
-	TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
-		     rowsperstrip == 0 ? 1 : rowsperstrip);
-
-	for (row = 0; row < h.ras_height; row++) {
-	    tmpptr = buf;
-
-	    G_percent(row, h.ras_height, 2);
-
-	    if (G_get_c_raster_row(in, cell, row) < 0)
-		exit(EXIT_FAILURE);
-
-	    cellptr = cell;
-	    if (palette) {
-		for (col = 0; col < h.ras_width; col++)
-		    *tmpptr++ = (u_char) (*cellptr++ - colors.cmin);
-	    }
-	    else {
-		for (col = 0; col < h.ras_width; col++) {
-		    G_get_color(cell[col], &red, &grn, &blu, &colors);
-		    *tmpptr++ = (u_char) red;
-		    *tmpptr++ = (u_char) grn;
-		    *tmpptr++ = (u_char) blu;
-		}
-	    }
-
-	    if (TIFFWriteScanline(out, buf, row, 0) < 0)
-		break;
-	}
-
-	G_percent(row, h.ras_height, 2);
-    }
-
-    (void)TIFFClose(out);
-
-    if (tfw) {
-	sprintf(filename, "%s.tfw", basename);
-	write_tfw(filename, &cellhd);
-    }
-
-    G_free(filename);
-    G_free(basename);
-
-    G_done_msg(" ");
-
-    exit(EXIT_SUCCESS);
-}
-
-
-static int write_tfw(const char *fname, const struct Cell_head *win)
-{
-    int width = DBL_DIG;
-    FILE *outfile;
-
-    G_message(_("Writing TIFF World file"));
-
-    if (fname == NULL)
-	G_fatal_error(_("Got null file name"));
-    if (win == NULL)
-	G_fatal_error(_("Got null region struct"));
-
-    if ((outfile = fopen(fname, "w")) == NULL)
-	G_fatal_error(_("Unable to open TIFF world file for writing"));
-
-    fprintf(outfile, "%36.*f \n", width, win->ew_res);
-    fprintf(outfile, "%36.*f \n", width, 0.0);
-    fprintf(outfile, "%36.*f \n", width, 0.0);
-    fprintf(outfile, "%36.*f \n", width, -1 * win->ns_res);
-    fprintf(outfile, "%36.*f \n", width, win->west + win->ew_res / 2.0);
-    fprintf(outfile, "%36.*f \n", width, win->north - win->ns_res / 2.0);
-
-    fclose(outfile);
-    return 0;
-}

Deleted: grass/trunk/raster/r.support/front.c
===================================================================
--- grass/trunk/raster/r.support/front.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/raster/r.support/front.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,360 +0,0 @@
-/*
- **********************************************************************
- *
- * MODULE:       r.support (GRASS core)
- *
- * AUTHOR(S):    Original by Michael Shapiro - CERL
- *               Preliminary parser support by Markus Neteler, rast parameter
- *               Port to 6.x by Brad Douglas
- *
- * PURPOSE:      Build support files for raster map
- *               - Edit header
- *               - Update status (histogram, range)
- *
- * COPYRIGHT:    (C) 2000-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 <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-
-/* two less than lib/gis/put_title.c  G_put_cell_title()
-   if only one less a newline gets appended in the cats file. bug? */
-#define MAX_TITLE_LEN 1022
-
-int main(int argc, char *argv[])
-{
-    char rname[GNAME_MAX];	/* Reclassed map name */
-    char rmapset[GMAPSET_MAX];	/* Reclassed mapset   */
-    char *mapset;		/* Raster mapset      */
-    struct Cell_head cellhd;
-    struct GModule *module;
-    struct Option *raster, *title_opt, *history_opt;
-    struct Option *datasrc1_opt, *datasrc2_opt, *datadesc_opt;
-    struct Option *map_opt, *units_opt, *vdatum_opt;
-    struct Option *load_opt, *save_opt;
-    struct Flag *stats_flag, *null_flag, *del_flag;
-    int cellhd_ok;		/* Is cell header OK? */
-    int is_reclass;		/* Is raster reclass? */
-    char *infile;
-    char title[MAX_TITLE_LEN + 1], datasrc[RECORD_LEN + 1];
-    struct History hist;
-
-    /* Initialize GIS engine */
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("raster, metadata");
-    module->description = _("Allows creation and/or modification of "
-			    "raster map layer support files.");
-
-    raster = G_define_standard_option(G_OPT_R_MAP);
-
-    title_opt = G_define_option();
-    title_opt->key = "title";
-    title_opt->key_desc = "\"phrase\"";
-    title_opt->type = TYPE_STRING;
-    title_opt->required = NO;
-    title_opt->description = _("Text to use for map title");
-
-    history_opt = G_define_option();
-    history_opt->key = "history";
-    history_opt->key_desc = "\"phrase\"";
-    history_opt->type = TYPE_STRING;
-    history_opt->required = NO;
-    history_opt->description =
-	_("Text to append to the next line of the map's metadata file");
-
-    units_opt = G_define_option();
-    units_opt->key = "units";
-    units_opt->type = TYPE_STRING;
-    units_opt->required = NO;
-    units_opt->description = _("Text to use for map data units");
-
-    vdatum_opt = G_define_option();
-    vdatum_opt->key = "vdatum";
-    vdatum_opt->type = TYPE_STRING;
-    vdatum_opt->required = NO;
-    vdatum_opt->description = _("Text to use for map vertical datum");
-
-    datasrc1_opt = G_define_option();
-    datasrc1_opt->key = "source1";
-    datasrc1_opt->key_desc = "\"phrase\"";
-    datasrc1_opt->type = TYPE_STRING;
-    datasrc1_opt->required = NO;
-    datasrc1_opt->description = _("Text to use for data source, line 1");
-
-    datasrc2_opt = G_define_option();
-    datasrc2_opt->key = "source2";
-    datasrc2_opt->key_desc = "\"phrase\"";
-    datasrc2_opt->type = TYPE_STRING;
-    datasrc2_opt->required = NO;
-    datasrc2_opt->description = _("Text to use for data source, line 2");
-
-    datadesc_opt = G_define_option();
-    datadesc_opt->key = "description";
-    datadesc_opt->key_desc = "\"phrase\"";
-    datadesc_opt->type = TYPE_STRING;
-    datadesc_opt->required = NO;
-    datadesc_opt->description =
-	_("Text to use for data description or keyword(s)");
-
-    map_opt = G_define_option();
-    map_opt->key = "raster";
-    map_opt->type = TYPE_STRING;
-    map_opt->required = NO;
-    map_opt->gisprompt = "old,cell,raster";
-    map_opt->description = _("Raster map from which to copy category table");
-
-    load_opt = G_define_standard_option(G_OPT_F_INPUT);
-    load_opt->key = "loadhistory";
-    load_opt->required = NO;
-    load_opt->description = _("Text file from which to load history");
-
-    save_opt = G_define_standard_option(G_OPT_F_OUTPUT);
-    save_opt->key = "savehistory";
-    save_opt->required = NO;
-    save_opt->description = _("Text file in which to save history");
-
-    stats_flag = G_define_flag();
-    stats_flag->key = 's';
-    stats_flag->description = _("Update statistics (histogram, range)");
-
-    null_flag = G_define_flag();
-    null_flag->key = 'n';
-    null_flag->description = _("Create/reset the null file");
-
-    del_flag = G_define_flag();
-    del_flag->key = 'd';
-    del_flag->description = _("Delete the null file");
-
-    /* Parse command-line options */
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    /* Make sure raster exists and set mapset */
-    infile = raster->answer;
-    mapset = G_find_cell2(infile, G_mapset());	/* current mapset only for editing */
-    if (!mapset || strcmp(mapset, G_mapset()) != 0)
-	G_fatal_error(_("Raster map <%s> not found in current mapset"), infile);
-
-    cellhd_ok = (G_get_cellhd(raster->answer, "", &cellhd) >= 0);
-    is_reclass = (G_is_reclass(raster->answer, "", rname, rmapset) > 0);
-
-    if (title_opt->answer) {
-	strncpy(title, title_opt->answer, MAX_TITLE_LEN);
-	title[MAX_TITLE_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
-	G_strip(title);
-	G_debug(3, "map title= [%s]  (%d chars)", title, strlen(title));
-	G_put_cell_title(raster->answer, title);
-    }
-
-    if (save_opt->answer) {
-	FILE *fp = fopen(save_opt->answer, "w");
-	int i;
-
-	if (!fp)
-	    G_fatal_error(_("Unable to open output file <%s>"), save_opt->answer);
-
-	G_read_history(raster->answer, "", &hist);
-
-	for (i = 0; i < hist.edlinecnt; i++)
-	    fprintf(fp, "%s\n", hist.edhist[i]);
-
-	fclose(fp);
-    }
-
-    if (load_opt->answer) {
-	FILE *fp = fopen(load_opt->answer, "r");
-	int i;
-
-	if (!fp)
-	    G_fatal_error(_("Unable to open input file <%s>"), load_opt->answer);
-
-	G_read_history(raster->answer, "", &hist);
-
-	for (i = 0; ; i++) {
-	    if (i >= MAXEDLINES) {
-		G_warning(_("Not enough room in history file"));
-		break;
-	    }
-	    if (!G_getl2(hist.edhist[i], RECORD_LEN - 2, fp))
-		break;
-	}
-
-	fclose(fp);
-
-	hist.edlinecnt = i;
-
-	G_write_history(raster->answer, &hist);
-    }
-
-    if (history_opt->answer) {
-	G_read_history(raster->answer, "", &hist);
-
-	if (hist.edlinecnt >= MAXEDLINES)
-	    G_fatal_error(_("Not enough room in history file"));
-
-	/* two less than defined as if only one less a newline gets appended in the hist file. bug? */
-	/* Should be RECORD_LEN, but r.info truncates at > 71 chars */
-	if (strlen(history_opt->answer) > 71) {
-	    int i;
-
-	    for (i = 0; i < strlen(history_opt->answer); i += 71) {
-		char *tmp = &history_opt->answer[i];
-
-		strncpy(hist.edhist[hist.edlinecnt], tmp, 71);
-
-		/* strncpy doesn't null terminate oversized input */
-		hist.edhist[hist.edlinecnt][RECORD_LEN - 2] = '\0';
-		hist.edlinecnt++;
-
-		G_debug(3, "new history line= [%s] (%d chars)",
-			hist.edhist[hist.edlinecnt],
-			strlen(hist.edhist[hist.edlinecnt]));
-	    }
-	}
-	else {
-	    strncpy(hist.edhist[hist.edlinecnt], history_opt->answer,
-		    RECORD_LEN - 2);
-
-	    /* strncpy doesn't null terminate oversized input */
-	    hist.edhist[hist.edlinecnt][RECORD_LEN - 2] = '\0';
-	    hist.edlinecnt++;
-
-	    G_debug(3, "new history line= [%s] (%d chars)",
-		    hist.edhist[hist.edlinecnt],
-		    strlen(hist.edhist[hist.edlinecnt]));
-	}
-
-	G_write_history(raster->answer, &hist);
-    }
-
-    if (units_opt->answer)
-	G_write_raster_units(raster->answer, units_opt->answer);
-
-    if (vdatum_opt->answer)
-	G_write_raster_vdatum(raster->answer, vdatum_opt->answer);
-
-    if (datasrc1_opt->answer || datasrc2_opt->answer || datadesc_opt->answer) {
-	G_read_history(raster->answer, "", &hist);
-
-	if (datasrc1_opt->answer) {
-	    strncpy(datasrc, datasrc1_opt->answer, RECORD_LEN);
-	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
-	    G_strip(datasrc);
-	    G_debug(3, "map datasrc1= [%s]  (%d chars)", datasrc,
-		    strlen(datasrc));
-	    strncpy(hist.datsrc_1, datasrc, RECORD_LEN);
-	}
-	if (datasrc2_opt->answer) {
-	    strncpy(datasrc, datasrc2_opt->answer, RECORD_LEN);
-	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
-	    G_strip(datasrc);
-	    G_debug(3, "map datasrc2= [%s]  (%d chars)", datasrc,
-		    strlen(datasrc));
-	    strncpy(hist.datsrc_2, datasrc, RECORD_LEN);
-	}
-
-	if (datadesc_opt->answer) {
-	    strncpy(datasrc, datadesc_opt->answer, RECORD_LEN);
-	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
-	    G_strip(datasrc);
-	    G_debug(3, "map datadesc= [%s]  (%d chars)", datasrc,
-		    strlen(datasrc));
-	    strncpy(hist.keywrd, datasrc, RECORD_LEN);
-	}
-
-	G_write_history(raster->answer, &hist);
-    }
-
-    if (map_opt->answer) {	/* use cats from another map */
-	int fd;
-	struct Categories cats;
-
-	if ((fd = G_open_cell_old(infile, "")) < 0)
-	    G_fatal_error(_("Unable to open raster map <%s>"), infile);
-	G_init_cats((CELL) 0, "", &cats);
-	if (G_read_cats(map_opt->answer, "", &cats) < 0)
-	    G_fatal_error(_("Unable to read category file of raster map <%s>"),
-			  map_opt->answer);
-
-	if (G_write_cats(infile, &cats) >= 0)
-	    G_message(_("cats table for [%s] set to %s"), infile,
-		      map_opt->answer);
-	G_close_cell(fd);
-	G_free_cats(&cats);
-    }
-
-
-    if (title_opt->answer || history_opt->answer || units_opt->answer
-	|| vdatum_opt->answer || datasrc1_opt->answer || datasrc2_opt->answer
-	|| datadesc_opt->answer || map_opt->answer)
-	exit(EXIT_SUCCESS);
-
-
-    /* Check the histogram and range */
-    if (stats_flag->answer)
-	check_stats(raster->answer);
-
-    /* null file */
-    if (null_flag->answer) {
-	unsigned char *null_bits;
-	int row, col;
-	int null_fd;
-
-	if (is_reclass)
-	    G_fatal_error(_("[%s] is a reclass of another map. Exiting."),
-			  raster->answer);
-
-	/* Create a file of no-nulls */
-	null_bits = G__allocate_null_bits(cellhd.cols);
-	for (col = 0; col < G__null_bitstream_size(cellhd.cols); col++)
-	    null_bits[col] = 0;
-
-	/* Open null file for writing */
-	null_fd = G_open_new_misc("cell_misc", "null", raster->answer);
-
-	G_message(_("Writing new null file for [%s]... "), raster->answer);
-	for (row = 0; row < cellhd.rows; row++) {
-	    G_percent(row, cellhd.rows, 1);
-	    if (G__write_null_bits(null_fd, null_bits, row, cellhd.cols, 0) <
-		0)
-		G_fatal_error(_("Error writing null row [%d]."), row);
-	}
-	G_percent(row, cellhd.rows, 1);
-
-	/* Cleanup */
-	close(null_fd);
-	G_free(null_bits);
-    }
-
-    if (del_flag->answer) {
-	int null_fd;
-	char path[GPATH_MAX];
-
-	if (is_reclass)
-	    G_fatal_error(_("[%s] is a reclass of another map. Exiting."),
-			  raster->answer);
-
-	/* Write a file of no-nulls */
-	G_message(_("Removing null file for [%s]...\n"), raster->answer);
-
-	null_fd = G_open_new_misc("cell_misc", "null", raster->answer);
-	G__file_name_misc(path, "cell_misc", "null", raster->answer, G_mapset());
-	unlink(path);
-	close(null_fd);
-
-	G_done_msg(_("Done."));
-    }
-
-    return EXIT_SUCCESS;
-}

Copied: grass/trunk/raster/r.support/main.c (from rev 32801, grass/trunk/raster/r.support/front.c)
===================================================================
--- grass/trunk/raster/r.support/main.c	                        (rev 0)
+++ grass/trunk/raster/r.support/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,360 @@
+/*
+ **********************************************************************
+ *
+ * MODULE:       r.support (GRASS core)
+ *
+ * AUTHOR(S):    Original by Michael Shapiro - CERL
+ *               Preliminary parser support by Markus Neteler, rast parameter
+ *               Port to 6.x by Brad Douglas
+ *
+ * PURPOSE:      Build support files for raster map
+ *               - Edit header
+ *               - Update status (histogram, range)
+ *
+ * COPYRIGHT:    (C) 2000-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 <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+/* two less than lib/gis/put_title.c  G_put_cell_title()
+   if only one less a newline gets appended in the cats file. bug? */
+#define MAX_TITLE_LEN 1022
+
+int main(int argc, char *argv[])
+{
+    char rname[GNAME_MAX];	/* Reclassed map name */
+    char rmapset[GMAPSET_MAX];	/* Reclassed mapset   */
+    char *mapset;		/* Raster mapset      */
+    struct Cell_head cellhd;
+    struct GModule *module;
+    struct Option *raster, *title_opt, *history_opt;
+    struct Option *datasrc1_opt, *datasrc2_opt, *datadesc_opt;
+    struct Option *map_opt, *units_opt, *vdatum_opt;
+    struct Option *load_opt, *save_opt;
+    struct Flag *stats_flag, *null_flag, *del_flag;
+    int cellhd_ok;		/* Is cell header OK? */
+    int is_reclass;		/* Is raster reclass? */
+    char *infile;
+    char title[MAX_TITLE_LEN + 1], datasrc[RECORD_LEN + 1];
+    struct History hist;
+
+    /* Initialize GIS engine */
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("raster, metadata");
+    module->description = _("Allows creation and/or modification of "
+			    "raster map layer support files.");
+
+    raster = G_define_standard_option(G_OPT_R_MAP);
+
+    title_opt = G_define_option();
+    title_opt->key = "title";
+    title_opt->key_desc = "\"phrase\"";
+    title_opt->type = TYPE_STRING;
+    title_opt->required = NO;
+    title_opt->description = _("Text to use for map title");
+
+    history_opt = G_define_option();
+    history_opt->key = "history";
+    history_opt->key_desc = "\"phrase\"";
+    history_opt->type = TYPE_STRING;
+    history_opt->required = NO;
+    history_opt->description =
+	_("Text to append to the next line of the map's metadata file");
+
+    units_opt = G_define_option();
+    units_opt->key = "units";
+    units_opt->type = TYPE_STRING;
+    units_opt->required = NO;
+    units_opt->description = _("Text to use for map data units");
+
+    vdatum_opt = G_define_option();
+    vdatum_opt->key = "vdatum";
+    vdatum_opt->type = TYPE_STRING;
+    vdatum_opt->required = NO;
+    vdatum_opt->description = _("Text to use for map vertical datum");
+
+    datasrc1_opt = G_define_option();
+    datasrc1_opt->key = "source1";
+    datasrc1_opt->key_desc = "\"phrase\"";
+    datasrc1_opt->type = TYPE_STRING;
+    datasrc1_opt->required = NO;
+    datasrc1_opt->description = _("Text to use for data source, line 1");
+
+    datasrc2_opt = G_define_option();
+    datasrc2_opt->key = "source2";
+    datasrc2_opt->key_desc = "\"phrase\"";
+    datasrc2_opt->type = TYPE_STRING;
+    datasrc2_opt->required = NO;
+    datasrc2_opt->description = _("Text to use for data source, line 2");
+
+    datadesc_opt = G_define_option();
+    datadesc_opt->key = "description";
+    datadesc_opt->key_desc = "\"phrase\"";
+    datadesc_opt->type = TYPE_STRING;
+    datadesc_opt->required = NO;
+    datadesc_opt->description =
+	_("Text to use for data description or keyword(s)");
+
+    map_opt = G_define_option();
+    map_opt->key = "raster";
+    map_opt->type = TYPE_STRING;
+    map_opt->required = NO;
+    map_opt->gisprompt = "old,cell,raster";
+    map_opt->description = _("Raster map from which to copy category table");
+
+    load_opt = G_define_standard_option(G_OPT_F_INPUT);
+    load_opt->key = "loadhistory";
+    load_opt->required = NO;
+    load_opt->description = _("Text file from which to load history");
+
+    save_opt = G_define_standard_option(G_OPT_F_OUTPUT);
+    save_opt->key = "savehistory";
+    save_opt->required = NO;
+    save_opt->description = _("Text file in which to save history");
+
+    stats_flag = G_define_flag();
+    stats_flag->key = 's';
+    stats_flag->description = _("Update statistics (histogram, range)");
+
+    null_flag = G_define_flag();
+    null_flag->key = 'n';
+    null_flag->description = _("Create/reset the null file");
+
+    del_flag = G_define_flag();
+    del_flag->key = 'd';
+    del_flag->description = _("Delete the null file");
+
+    /* Parse command-line options */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    /* Make sure raster exists and set mapset */
+    infile = raster->answer;
+    mapset = G_find_cell2(infile, G_mapset());	/* current mapset only for editing */
+    if (!mapset || strcmp(mapset, G_mapset()) != 0)
+	G_fatal_error(_("Raster map <%s> not found in current mapset"), infile);
+
+    cellhd_ok = (G_get_cellhd(raster->answer, "", &cellhd) >= 0);
+    is_reclass = (G_is_reclass(raster->answer, "", rname, rmapset) > 0);
+
+    if (title_opt->answer) {
+	strncpy(title, title_opt->answer, MAX_TITLE_LEN);
+	title[MAX_TITLE_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
+	G_strip(title);
+	G_debug(3, "map title= [%s]  (%d chars)", title, strlen(title));
+	G_put_cell_title(raster->answer, title);
+    }
+
+    if (save_opt->answer) {
+	FILE *fp = fopen(save_opt->answer, "w");
+	int i;
+
+	if (!fp)
+	    G_fatal_error(_("Unable to open output file <%s>"), save_opt->answer);
+
+	G_read_history(raster->answer, "", &hist);
+
+	for (i = 0; i < hist.edlinecnt; i++)
+	    fprintf(fp, "%s\n", hist.edhist[i]);
+
+	fclose(fp);
+    }
+
+    if (load_opt->answer) {
+	FILE *fp = fopen(load_opt->answer, "r");
+	int i;
+
+	if (!fp)
+	    G_fatal_error(_("Unable to open input file <%s>"), load_opt->answer);
+
+	G_read_history(raster->answer, "", &hist);
+
+	for (i = 0; ; i++) {
+	    if (i >= MAXEDLINES) {
+		G_warning(_("Not enough room in history file"));
+		break;
+	    }
+	    if (!G_getl2(hist.edhist[i], RECORD_LEN - 2, fp))
+		break;
+	}
+
+	fclose(fp);
+
+	hist.edlinecnt = i;
+
+	G_write_history(raster->answer, &hist);
+    }
+
+    if (history_opt->answer) {
+	G_read_history(raster->answer, "", &hist);
+
+	if (hist.edlinecnt >= MAXEDLINES)
+	    G_fatal_error(_("Not enough room in history file"));
+
+	/* two less than defined as if only one less a newline gets appended in the hist file. bug? */
+	/* Should be RECORD_LEN, but r.info truncates at > 71 chars */
+	if (strlen(history_opt->answer) > 71) {
+	    int i;
+
+	    for (i = 0; i < strlen(history_opt->answer); i += 71) {
+		char *tmp = &history_opt->answer[i];
+
+		strncpy(hist.edhist[hist.edlinecnt], tmp, 71);
+
+		/* strncpy doesn't null terminate oversized input */
+		hist.edhist[hist.edlinecnt][RECORD_LEN - 2] = '\0';
+		hist.edlinecnt++;
+
+		G_debug(3, "new history line= [%s] (%d chars)",
+			hist.edhist[hist.edlinecnt],
+			strlen(hist.edhist[hist.edlinecnt]));
+	    }
+	}
+	else {
+	    strncpy(hist.edhist[hist.edlinecnt], history_opt->answer,
+		    RECORD_LEN - 2);
+
+	    /* strncpy doesn't null terminate oversized input */
+	    hist.edhist[hist.edlinecnt][RECORD_LEN - 2] = '\0';
+	    hist.edlinecnt++;
+
+	    G_debug(3, "new history line= [%s] (%d chars)",
+		    hist.edhist[hist.edlinecnt],
+		    strlen(hist.edhist[hist.edlinecnt]));
+	}
+
+	G_write_history(raster->answer, &hist);
+    }
+
+    if (units_opt->answer)
+	G_write_raster_units(raster->answer, units_opt->answer);
+
+    if (vdatum_opt->answer)
+	G_write_raster_vdatum(raster->answer, vdatum_opt->answer);
+
+    if (datasrc1_opt->answer || datasrc2_opt->answer || datadesc_opt->answer) {
+	G_read_history(raster->answer, "", &hist);
+
+	if (datasrc1_opt->answer) {
+	    strncpy(datasrc, datasrc1_opt->answer, RECORD_LEN);
+	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
+	    G_strip(datasrc);
+	    G_debug(3, "map datasrc1= [%s]  (%d chars)", datasrc,
+		    strlen(datasrc));
+	    strncpy(hist.datsrc_1, datasrc, RECORD_LEN);
+	}
+	if (datasrc2_opt->answer) {
+	    strncpy(datasrc, datasrc2_opt->answer, RECORD_LEN);
+	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
+	    G_strip(datasrc);
+	    G_debug(3, "map datasrc2= [%s]  (%d chars)", datasrc,
+		    strlen(datasrc));
+	    strncpy(hist.datsrc_2, datasrc, RECORD_LEN);
+	}
+
+	if (datadesc_opt->answer) {
+	    strncpy(datasrc, datadesc_opt->answer, RECORD_LEN);
+	    datasrc[RECORD_LEN] = '\0';	/* strncpy doesn't null terminate oversized input */
+	    G_strip(datasrc);
+	    G_debug(3, "map datadesc= [%s]  (%d chars)", datasrc,
+		    strlen(datasrc));
+	    strncpy(hist.keywrd, datasrc, RECORD_LEN);
+	}
+
+	G_write_history(raster->answer, &hist);
+    }
+
+    if (map_opt->answer) {	/* use cats from another map */
+	int fd;
+	struct Categories cats;
+
+	if ((fd = G_open_cell_old(infile, "")) < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), infile);
+	G_init_cats((CELL) 0, "", &cats);
+	if (G_read_cats(map_opt->answer, "", &cats) < 0)
+	    G_fatal_error(_("Unable to read category file of raster map <%s>"),
+			  map_opt->answer);
+
+	if (G_write_cats(infile, &cats) >= 0)
+	    G_message(_("cats table for [%s] set to %s"), infile,
+		      map_opt->answer);
+	G_close_cell(fd);
+	G_free_cats(&cats);
+    }
+
+
+    if (title_opt->answer || history_opt->answer || units_opt->answer
+	|| vdatum_opt->answer || datasrc1_opt->answer || datasrc2_opt->answer
+	|| datadesc_opt->answer || map_opt->answer)
+	exit(EXIT_SUCCESS);
+
+
+    /* Check the histogram and range */
+    if (stats_flag->answer)
+	check_stats(raster->answer);
+
+    /* null file */
+    if (null_flag->answer) {
+	unsigned char *null_bits;
+	int row, col;
+	int null_fd;
+
+	if (is_reclass)
+	    G_fatal_error(_("[%s] is a reclass of another map. Exiting."),
+			  raster->answer);
+
+	/* Create a file of no-nulls */
+	null_bits = G__allocate_null_bits(cellhd.cols);
+	for (col = 0; col < G__null_bitstream_size(cellhd.cols); col++)
+	    null_bits[col] = 0;
+
+	/* Open null file for writing */
+	null_fd = G_open_new_misc("cell_misc", "null", raster->answer);
+
+	G_message(_("Writing new null file for [%s]... "), raster->answer);
+	for (row = 0; row < cellhd.rows; row++) {
+	    G_percent(row, cellhd.rows, 1);
+	    if (G__write_null_bits(null_fd, null_bits, row, cellhd.cols, 0) <
+		0)
+		G_fatal_error(_("Error writing null row [%d]."), row);
+	}
+	G_percent(row, cellhd.rows, 1);
+
+	/* Cleanup */
+	close(null_fd);
+	G_free(null_bits);
+    }
+
+    if (del_flag->answer) {
+	int null_fd;
+	char path[GPATH_MAX];
+
+	if (is_reclass)
+	    G_fatal_error(_("[%s] is a reclass of another map. Exiting."),
+			  raster->answer);
+
+	/* Write a file of no-nulls */
+	G_message(_("Removing null file for [%s]...\n"), raster->answer);
+
+	null_fd = G_open_new_misc("cell_misc", "null", raster->answer);
+	G__file_name_misc(path, "cell_misc", "null", raster->answer, G_mapset());
+	unlink(path);
+	close(null_fd);
+
+	G_done_msg(_("Done."));
+    }
+
+    return EXIT_SUCCESS;
+}

Deleted: grass/trunk/vector/v.in.ascii/in.c
===================================================================
--- grass/trunk/vector/v.in.ascii/in.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/vector/v.in.ascii/in.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,542 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       v.in.ascii
- *               
- * AUTHOR(S):    Original authors Michael Higgins, James Westervelt (CERL)
- *               Updated to GRASS 5.7 Radim Blazek, ITC-Irst, Trento, Italy
- * PURPOSE:      Converts a vector map in ASCII format to a vector map
- *               in binary format
- *
- * COPYRIGHT:    (C) 2000-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 <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <grass/gis.h>
-#include <grass/dbmi.h>
-#include <grass/Vect.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-
-#define	A_DIR	"dig_ascii"
-
-int main(int argc, char *argv[])
-{
-    FILE *ascii;
-    struct GModule *module;
-    struct Option *old, *new, *delim_opt, *columns_opt, *xcol_opt,
-	*ycol_opt, *zcol_opt, *catcol_opt, *format_opt, *skip_opt;
-    int xcol, ycol, zcol, catcol, format, skip_lines;
-    struct Flag *zcoorf, *t_flag, *e_flag, *noheader_flag, *notopol_flag,
-	*region_flag;
-    char *table;
-    char *fs;
-    int zcoor = WITHOUT_Z, make_table;
-
-    struct Map_info Map;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("vector, import");
-    module->description =
-	_("Creates a vector map from ASCII points file or ASCII vector file.");
-
-    /************************** Command Parser ************************************/
-    old = G_define_standard_option(G_OPT_F_INPUT);
-    old->required = NO;
-    old->description =
-	_("ASCII file to be imported, if not given reads from standard input");
-    old->guisection = _("Required");
-
-    new = G_define_standard_option(G_OPT_V_OUTPUT);
-
-    format_opt = G_define_option();
-    format_opt->key = "format";
-    format_opt->type = TYPE_STRING;
-    format_opt->required = NO;
-    format_opt->multiple = NO;
-    format_opt->options = "point,standard";
-    format_opt->descriptions = _("point;simple x,y[,z] list;"
-				 "standard;GRASS's vector ASCII format");
-    format_opt->answer = "point";
-    format_opt->description = _("Input file format");
-
-    delim_opt = G_define_standard_option(G_OPT_F_SEP);
-
-    skip_opt = G_define_option();
-    skip_opt->key = "skip";
-    skip_opt->type = TYPE_INTEGER;
-    skip_opt->required = NO;
-    skip_opt->multiple = NO;
-    skip_opt->answer = "0";
-    skip_opt->description =
-	_("Number of header lines to skip at top of input file (points mode)");
-
-    columns_opt = G_define_standard_option(G_OPT_COLUMNS);
-    columns_opt->multiple = NO;
-    columns_opt->guisection = _("Columns");
-    columns_opt->label = _("Column definition in SQL style (points mode)");
-    columns_opt->description = _("For example: "
-				 "'x double precision, y double precision, cat int, "
-				 "name varchar(10)'");
-
-    xcol_opt = G_define_option();
-    xcol_opt->key = "x";
-    xcol_opt->type = TYPE_INTEGER;
-    xcol_opt->required = NO;
-    xcol_opt->multiple = NO;
-    xcol_opt->answer = "1";
-    xcol_opt->guisection = _("Columns");
-    xcol_opt->description =
-	_("Number of column used as x coordinate (first column is 1) for points mode");
-
-    ycol_opt = G_define_option();
-    ycol_opt->key = "y";
-    ycol_opt->type = TYPE_INTEGER;
-    ycol_opt->required = NO;
-    ycol_opt->multiple = NO;
-    ycol_opt->answer = "2";
-    ycol_opt->guisection = _("Columns");
-    ycol_opt->description =
-	_("Number of column used as y coordinate (first column is 1) for points mode");
-
-    zcol_opt = G_define_option();
-    zcol_opt->key = "z";
-    zcol_opt->type = TYPE_INTEGER;
-    zcol_opt->required = NO;
-    zcol_opt->multiple = NO;
-    zcol_opt->answer = "0";
-    zcol_opt->guisection = _("Columns");
-    zcol_opt->label =
-	_("Number of column used as z coordinate (first column is 1) for "
-	  "points mode");
-    zcol_opt->description = _("If 0, z coordinate is not used");
-
-    catcol_opt = G_define_option();
-    catcol_opt->key = "cat";
-    catcol_opt->type = TYPE_INTEGER;
-    catcol_opt->required = NO;
-    catcol_opt->multiple = NO;
-    catcol_opt->answer = "0";
-    catcol_opt->guisection = _("Columns");
-    catcol_opt->label =
-	_("Number of column used as category (first column is 1) for points mode");
-    catcol_opt->description =
-	_("If 0, unique category is assigned to each row and written to new column 'cat'");
-
-    zcoorf = G_define_flag();
-    zcoorf->key = 'z';
-    zcoorf->description = _("Create 3D vector map");
-
-    e_flag = G_define_flag();
-    e_flag->key = 'e';
-    e_flag->description =
-	_("Create a new empty vector map and exit. Nothing is read from input");
-
-    noheader_flag = G_define_flag();
-    noheader_flag->key = 'n';
-    noheader_flag->description =
-	_("Don't expect a header when reading in standard format");
-
-    t_flag = G_define_flag();
-    t_flag->key = 't';
-    t_flag->description = _("Do not create table in points mode");
-    t_flag->guisection = _("Columns");
-
-    notopol_flag = G_define_flag();
-    notopol_flag->key = 'b';
-    notopol_flag->description = _("Do not build topology in points mode");
-
-    region_flag = G_define_flag();
-    region_flag->key = 'r';
-    region_flag->description =
-	_("Only import points falling within current region (points mode)");
-
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-
-    if (format_opt->answer[0] == 'p')
-	format = FORMAT_POINT;
-    else
-	format = FORMAT_ALL;
-
-    skip_lines = atoi(skip_opt->answer);
-    if (skip_lines < 0)
-	G_fatal_error(_("Please specify reasonable number of lines to skip"));
-
-    if (zcoorf->answer && format == FORMAT_POINT && !zcol_opt->answer)
-	G_fatal_error(_("Please specify z column"));
-
-    xcol = atoi(xcol_opt->answer) - 1;
-    ycol = atoi(ycol_opt->answer) - 1;
-    zcol = atoi(zcol_opt->answer) - 1;
-
-    /* specifying zcol= implies that a 3D map is needed */
-    if (zcol >= 0 && !zcoorf->answer)
-	zcoorf->answer = 1;
-
-    if (zcoorf->answer && format == FORMAT_POINT && zcol < 0)
-	G_fatal_error(_("Please specify reasonable z column"));
-
-    catcol = atoi(catcol_opt->answer) - 1;
-
-    if (old->answer != NULL) {
-	if ((ascii = fopen(old->answer, "r")) == NULL) {
-	    G_fatal_error(_("Unable to open ASCII file <%s>"), old->answer);
-	}
-    }
-    else {
-	ascii = stdin;
-    }
-
-    fs = delim_opt->answer;
-    if (strcmp(fs, "\\t") == 0)
-	fs = "\t";
-    if (strcmp(fs, "tab") == 0)
-	fs = "\t";
-    if (strcmp(fs, "space") == 0)
-	fs = " ";
-    if (strcmp(fs, "comma") == 0)
-	fs = ",";
-
-    /* check dimension */
-    if (zcoorf->answer) {
-	zcoor = 1;
-    }
-
-    Vect_open_new(&Map, new->answer, zcoor);
-    Vect_hist_command(&Map);
-
-    if (e_flag->answer) {
-	Vect_build(&Map, stderr);
-	Vect_close(&Map);
-	exit(EXIT_SUCCESS);
-    }
-
-    if (format == FORMAT_POINT) {
-	int i, rowlen, ncols, minncols, *coltype, *coltype2, *collen, nrows;
-	int n_int = 0, n_double = 0, n_string = 0;
-	char buf[1000];
-	struct field_info *Fi;
-	char *tmp, *key;
-	dbDriver *driver;
-	dbString sql;
-	FILE *tmpascii;
-
-	/* Open temporary file */
-	tmp = G_tempfile();
-	if (NULL == (tmpascii = fopen(tmp, "w+"))) {
-	    G_fatal_error(_("Unable to open temporary file <%s>"), tmp);
-	}
-	unlink(tmp);
-
-	points_analyse(ascii, tmpascii, fs, &rowlen, &ncols, &minncols,
-		       &nrows, &coltype, &collen, skip_lines, xcol, ycol,
-		       region_flag->answer);
-
-	G_message(_("Maximum input row length: %d"), rowlen);
-	G_message(_("Maximum number of columns: %d"), ncols);
-	G_message(_("Minimum number of columns: %d"), minncols);
-
-	/* check column numbers */
-	if (xcol >= minncols) {
-	    Vect_delete(new->answer);
-	    G_fatal_error(_("x column number > minimum last column number\n(incorrect field separator?)"));
-	}
-	if (ycol >= minncols) {
-	    Vect_delete(new->answer);
-	    G_fatal_error(_("y column number > minimum last column number\n(incorrect field separator?)"));
-	}
-	if (zcol >= minncols) {
-	    Vect_delete(new->answer);
-	    G_fatal_error(_("z column number > minimum last column number "
-			    "(incorrect field separator?)"));
-	}
-	if (catcol >= minncols) {
-	    Vect_delete(new->answer);
-	    G_fatal_error(_("cat column number > minimum last column number "
-			    "(incorrect field separator?)"));
-	}
-
-	if (coltype[xcol] == DB_C_TYPE_STRING) {
-	    Vect_delete(new->answer);
-	    G_fatal_error(_("x column is not of number type"));
-	}
-	if (coltype[ycol] == DB_C_TYPE_STRING) {
-	    Vect_delete(new->answer);
-	    G_fatal_error(_("y column is not of number type"));
-	}
-	if (zcol >= 0 && coltype[zcol] == DB_C_TYPE_STRING) {
-	    Vect_delete(new->answer);
-	    G_fatal_error(_("z column is not of number type"));
-	}
-	if (catcol >= 0 && coltype[catcol] == DB_C_TYPE_STRING) {
-	    Vect_delete(new->answer);
-	    G_fatal_error(_("cat column is not of number type"));
-	}
-
-	/* Create table */
-	make_table = 0;
-	for (i = 0; i < ncols; i++) {
-	    if (xcol != i && ycol != i && zcol != i && catcol != i) {
-		make_table = 1;
-		break;
-	    }
-	}
-	if (t_flag->answer) {
-	    make_table = 0;
-	}
-
-	if (make_table) {
-	    Fi = Vect_default_field_info(&Map, 1, NULL, GV_1TABLE);
-	    driver =
-		db_start_driver_open_database(Fi->driver,
-					      Vect_subst_var(Fi->database,
-							     &Map));
-	    if (driver == NULL) {
-		Vect_delete(new->answer);
-		G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
-			      Vect_subst_var(Fi->database, &Map), Fi->driver);
-	    }
-	    db_begin_transaction(driver);
-
-	    db_init_string(&sql);
-	    sprintf(buf, "create table %s ( ", Fi->table);
-	    db_append_string(&sql, buf);
-
-	    if (catcol < 0) {
-		db_append_string(&sql, "cat integer, ");
-	    }
-
-	    for (i = 0; i < ncols; i++) {
-		if (i > 0 && !columns_opt->answer) {
-		    db_append_string(&sql, ", ");
-		}
-		if (catcol == i && coltype[i] != DB_C_TYPE_INT) {
-		    Vect_delete(new->answer);
-		    G_fatal_error(_("Category column is not of integer type"));
-		}
-
-		switch (coltype[i]) {
-		case DB_C_TYPE_INT:
-		    G_verbose_message("Column: %d  type: integer", i + 1);
-		    if (!columns_opt->answer) {
-			sprintf(buf, "int_%d integer", n_int + 1);
-			db_append_string(&sql, buf);
-			if (catcol == i) {
-			    sprintf(buf, "int_%d", n_int + 1);
-			    key = G_store(buf);
-			}
-		    }
-		    n_int++;
-		    break;
-		case DB_C_TYPE_DOUBLE:
-		    G_verbose_message("Column: %d  type: double", i + 1);
-		    if (!columns_opt->answer) {
-			sprintf(buf, "dbl_%d double precision", n_double + 1);
-			db_append_string(&sql, buf);
-		    }
-		    n_double++;
-		    break;
-		case DB_C_TYPE_STRING:
-		    G_verbose_message("Column: %d  type: string length: %d",
-				      i + 1, collen[i]);
-		    if (!columns_opt->answer) {
-			sprintf(buf, "str_%d varchar(%d)", n_string + 1,
-				collen[i]);
-			db_append_string(&sql, buf);
-		    }
-		    n_string++;
-		    break;
-		}
-	    }
-	    if (columns_opt->answer) {
-		db_append_string(&sql, columns_opt->answer);
-	    }
-	    db_append_string(&sql, " )");
-
-	    /* this link is added with default 'cat' key, later deleted and replaced by true key name,
-	     * otherwise if module crashes when the table exists but link is not written it makes troubles */
-	    Vect_map_add_dblink(&Map, 1, NULL, Fi->table, "cat", Fi->database,
-				Fi->driver);
-
-	    /* Create table */
-	    G_debug(3, db_get_string(&sql));
-	    if (db_execute_immediate(driver, &sql) != DB_OK) {
-		Vect_delete(new->answer);
-		G_fatal_error(_("Unable to create table: %s"),
-			      db_get_string(&sql));
-	    }
-
-	    /* Grant */
-	    if (db_grant_on_table
-		(driver, Fi->table, DB_PRIV_SELECT,
-		 DB_GROUP | DB_PUBLIC) != DB_OK) {
-		Vect_delete(new->answer);
-		G_fatal_error(_("Unable to grant privileges on table <%s>"),
-			      Fi->table);
-	    }
-
-	    /* Check column types */
-	    if (columns_opt->answer) {
-		int nc;
-		dbTable *table;
-		dbColumn *column;
-
-		db_set_string(&sql, Fi->table);
-		if (db_describe_table(driver, &sql, &table) != DB_OK) {
-		    Vect_delete(new->answer);
-		    G_fatal_error(_("Unable to describe table <%s>"),
-				  Fi->table);
-		}
-
-		nc = db_get_table_number_of_columns(table);
-
-		if ((catcol >= 0 && nc != ncols) ||
-		    (catcol < 0 && (nc - 1) != ncols)) {
-		    Vect_delete(new->answer);
-		    G_fatal_error(_("Number of columns defined (%d) does not match number "
-				   "of columns (%d) in input"),
-				  catcol < 0 ? nc - 1 : nc, ncols);
-		}
-
-		coltype2 = (int *)G_malloc(ncols * sizeof(int));
-
-		for (i = 0; i < ncols; i++) {
-		    int dbcol, ctype, length;
-
-		    if (catcol < 0)
-			dbcol = i + 1;	/* first is category */
-		    else
-			dbcol = i;
-
-		    column = db_get_table_column(table, dbcol);
-		    ctype =
-			db_sqltype_to_Ctype(db_get_column_sqltype(column));
-		    length = db_get_column_length(column);
-		    coltype2[i] = ctype;
-
-		    if (catcol == i) {	/* if catcol == -1 it cannot be tru */
-			key = G_store(db_get_column_name(column));
-		    }
-
-		    switch (coltype[i]) {
-		    case DB_C_TYPE_INT:
-			if (ctype == DB_C_TYPE_DOUBLE) {
-			    G_warning(_("Column number %d <%s> defined as double "
-				       "has only integer values"), i + 1,
-				      db_get_column_name(column));
-			}
-			else if (ctype == DB_C_TYPE_STRING) {
-			    G_warning(_("Column number %d <%s> defined as string "
-				       "has only integer values"), i + 1,
-				      db_get_column_name(column));
-			}
-			break;
-		    case DB_C_TYPE_DOUBLE:
-			if (ctype == DB_C_TYPE_INT) {
-			    Vect_delete(new->answer);
-			    G_fatal_error(_("Column number %d <%s> defined as integer "
-					   "has double values"), i + 1,
-					  db_get_column_name(column));
-			}
-			else if (ctype == DB_C_TYPE_STRING) {
-			    G_warning(_("Column number %d <%s> defined as string "
-				       "has double values"), i + 1,
-				      db_get_column_name(column));
-			}
-			break;
-		    case DB_C_TYPE_STRING:
-			if (ctype == DB_C_TYPE_INT) {
-			    Vect_delete(new->answer);
-			    G_fatal_error(_("Column number %d <%s> defined as integer "
-					   "has string values"), i + 1,
-					  db_get_column_name(column));
-			}
-			else if (ctype == DB_C_TYPE_DOUBLE) {
-			    Vect_delete(new->answer);
-			    G_fatal_error(_("Column number %d <%s> defined as double "
-					   "has string values"), i + 1,
-					  db_get_column_name(column));
-			}
-			if (length < collen[i]) {
-			    Vect_delete(new->answer);
-			    G_fatal_error(_("Length of column %d <%s> (%d) is less than "
-					   "maximum value " "length (%d)"),
-					  i + 1, db_get_column_name(column),
-					  length, collen[i]);
-			}
-			break;
-		    }
-		}
-	    }
-	    else {
-		coltype2 = coltype;
-	    }
-
-	    if (catcol < 0) {
-		key = "cat";
-	    }
-	    else if (!columns_opt->answer) {
-
-
-	    }
-
-	    if (db_create_index2(driver, Fi->table, key) != DB_OK)
-		G_warning(_("Unable to create index for table <%s>, key <%s>"),
-			  Fi->table, key);
-
-	    Vect_map_del_dblink(&Map, 1);
-	    Vect_map_add_dblink(&Map, 1, NULL, Fi->table, key, Fi->database,
-				Fi->driver);
-
-	    table = Fi->table;
-	}
-	else {
-	    driver = NULL;
-	    table = NULL;
-	}
-
-	points_to_bin(tmpascii, rowlen, &Map, driver, table, fs, nrows, ncols,
-		      coltype2, xcol, ycol, zcol, catcol, skip_lines);
-
-	if (driver) {
-	    G_message(_("Populating table..."));
-	    db_commit_transaction(driver);
-	    db_close_database_shutdown_driver(driver);
-	}
-	fclose(tmpascii);
-    }
-
-    else {			/* FORMAT_ALL (standard mode) */
-	if (!noheader_flag->answer)
-	    read_head(ascii, &Map);
-
-	asc_to_bin(ascii, &Map);
-    }
-
-    if (old->answer != NULL)
-	fclose(ascii);
-
-    if (notopol_flag->answer) {
-	Vect_close(&Map);
-    }
-    else {
-	Vect_build(&Map, stderr);
-	Vect_close(&Map);
-    }
-
-    G_done_msg(" ");
-
-    exit(EXIT_SUCCESS);
-}

Copied: grass/trunk/vector/v.in.ascii/main.c (from rev 32801, grass/trunk/vector/v.in.ascii/in.c)
===================================================================
--- grass/trunk/vector/v.in.ascii/main.c	                        (rev 0)
+++ grass/trunk/vector/v.in.ascii/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,542 @@
+
+/****************************************************************************
+ *
+ * MODULE:       v.in.ascii
+ *               
+ * AUTHOR(S):    Original authors Michael Higgins, James Westervelt (CERL)
+ *               Updated to GRASS 5.7 Radim Blazek, ITC-Irst, Trento, Italy
+ * PURPOSE:      Converts a vector map in ASCII format to a vector map
+ *               in binary format
+ *
+ * COPYRIGHT:    (C) 2000-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 <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/Vect.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+#define	A_DIR	"dig_ascii"
+
+int main(int argc, char *argv[])
+{
+    FILE *ascii;
+    struct GModule *module;
+    struct Option *old, *new, *delim_opt, *columns_opt, *xcol_opt,
+	*ycol_opt, *zcol_opt, *catcol_opt, *format_opt, *skip_opt;
+    int xcol, ycol, zcol, catcol, format, skip_lines;
+    struct Flag *zcoorf, *t_flag, *e_flag, *noheader_flag, *notopol_flag,
+	*region_flag;
+    char *table;
+    char *fs;
+    int zcoor = WITHOUT_Z, make_table;
+
+    struct Map_info Map;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("vector, import");
+    module->description =
+	_("Creates a vector map from ASCII points file or ASCII vector file.");
+
+    /************************** Command Parser ************************************/
+    old = G_define_standard_option(G_OPT_F_INPUT);
+    old->required = NO;
+    old->description =
+	_("ASCII file to be imported, if not given reads from standard input");
+    old->guisection = _("Required");
+
+    new = G_define_standard_option(G_OPT_V_OUTPUT);
+
+    format_opt = G_define_option();
+    format_opt->key = "format";
+    format_opt->type = TYPE_STRING;
+    format_opt->required = NO;
+    format_opt->multiple = NO;
+    format_opt->options = "point,standard";
+    format_opt->descriptions = _("point;simple x,y[,z] list;"
+				 "standard;GRASS's vector ASCII format");
+    format_opt->answer = "point";
+    format_opt->description = _("Input file format");
+
+    delim_opt = G_define_standard_option(G_OPT_F_SEP);
+
+    skip_opt = G_define_option();
+    skip_opt->key = "skip";
+    skip_opt->type = TYPE_INTEGER;
+    skip_opt->required = NO;
+    skip_opt->multiple = NO;
+    skip_opt->answer = "0";
+    skip_opt->description =
+	_("Number of header lines to skip at top of input file (points mode)");
+
+    columns_opt = G_define_standard_option(G_OPT_COLUMNS);
+    columns_opt->multiple = NO;
+    columns_opt->guisection = _("Columns");
+    columns_opt->label = _("Column definition in SQL style (points mode)");
+    columns_opt->description = _("For example: "
+				 "'x double precision, y double precision, cat int, "
+				 "name varchar(10)'");
+
+    xcol_opt = G_define_option();
+    xcol_opt->key = "x";
+    xcol_opt->type = TYPE_INTEGER;
+    xcol_opt->required = NO;
+    xcol_opt->multiple = NO;
+    xcol_opt->answer = "1";
+    xcol_opt->guisection = _("Columns");
+    xcol_opt->description =
+	_("Number of column used as x coordinate (first column is 1) for points mode");
+
+    ycol_opt = G_define_option();
+    ycol_opt->key = "y";
+    ycol_opt->type = TYPE_INTEGER;
+    ycol_opt->required = NO;
+    ycol_opt->multiple = NO;
+    ycol_opt->answer = "2";
+    ycol_opt->guisection = _("Columns");
+    ycol_opt->description =
+	_("Number of column used as y coordinate (first column is 1) for points mode");
+
+    zcol_opt = G_define_option();
+    zcol_opt->key = "z";
+    zcol_opt->type = TYPE_INTEGER;
+    zcol_opt->required = NO;
+    zcol_opt->multiple = NO;
+    zcol_opt->answer = "0";
+    zcol_opt->guisection = _("Columns");
+    zcol_opt->label =
+	_("Number of column used as z coordinate (first column is 1) for "
+	  "points mode");
+    zcol_opt->description = _("If 0, z coordinate is not used");
+
+    catcol_opt = G_define_option();
+    catcol_opt->key = "cat";
+    catcol_opt->type = TYPE_INTEGER;
+    catcol_opt->required = NO;
+    catcol_opt->multiple = NO;
+    catcol_opt->answer = "0";
+    catcol_opt->guisection = _("Columns");
+    catcol_opt->label =
+	_("Number of column used as category (first column is 1) for points mode");
+    catcol_opt->description =
+	_("If 0, unique category is assigned to each row and written to new column 'cat'");
+
+    zcoorf = G_define_flag();
+    zcoorf->key = 'z';
+    zcoorf->description = _("Create 3D vector map");
+
+    e_flag = G_define_flag();
+    e_flag->key = 'e';
+    e_flag->description =
+	_("Create a new empty vector map and exit. Nothing is read from input");
+
+    noheader_flag = G_define_flag();
+    noheader_flag->key = 'n';
+    noheader_flag->description =
+	_("Don't expect a header when reading in standard format");
+
+    t_flag = G_define_flag();
+    t_flag->key = 't';
+    t_flag->description = _("Do not create table in points mode");
+    t_flag->guisection = _("Columns");
+
+    notopol_flag = G_define_flag();
+    notopol_flag->key = 'b';
+    notopol_flag->description = _("Do not build topology in points mode");
+
+    region_flag = G_define_flag();
+    region_flag->key = 'r';
+    region_flag->description =
+	_("Only import points falling within current region (points mode)");
+
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
+    if (format_opt->answer[0] == 'p')
+	format = FORMAT_POINT;
+    else
+	format = FORMAT_ALL;
+
+    skip_lines = atoi(skip_opt->answer);
+    if (skip_lines < 0)
+	G_fatal_error(_("Please specify reasonable number of lines to skip"));
+
+    if (zcoorf->answer && format == FORMAT_POINT && !zcol_opt->answer)
+	G_fatal_error(_("Please specify z column"));
+
+    xcol = atoi(xcol_opt->answer) - 1;
+    ycol = atoi(ycol_opt->answer) - 1;
+    zcol = atoi(zcol_opt->answer) - 1;
+
+    /* specifying zcol= implies that a 3D map is needed */
+    if (zcol >= 0 && !zcoorf->answer)
+	zcoorf->answer = 1;
+
+    if (zcoorf->answer && format == FORMAT_POINT && zcol < 0)
+	G_fatal_error(_("Please specify reasonable z column"));
+
+    catcol = atoi(catcol_opt->answer) - 1;
+
+    if (old->answer != NULL) {
+	if ((ascii = fopen(old->answer, "r")) == NULL) {
+	    G_fatal_error(_("Unable to open ASCII file <%s>"), old->answer);
+	}
+    }
+    else {
+	ascii = stdin;
+    }
+
+    fs = delim_opt->answer;
+    if (strcmp(fs, "\\t") == 0)
+	fs = "\t";
+    if (strcmp(fs, "tab") == 0)
+	fs = "\t";
+    if (strcmp(fs, "space") == 0)
+	fs = " ";
+    if (strcmp(fs, "comma") == 0)
+	fs = ",";
+
+    /* check dimension */
+    if (zcoorf->answer) {
+	zcoor = 1;
+    }
+
+    Vect_open_new(&Map, new->answer, zcoor);
+    Vect_hist_command(&Map);
+
+    if (e_flag->answer) {
+	Vect_build(&Map, stderr);
+	Vect_close(&Map);
+	exit(EXIT_SUCCESS);
+    }
+
+    if (format == FORMAT_POINT) {
+	int i, rowlen, ncols, minncols, *coltype, *coltype2, *collen, nrows;
+	int n_int = 0, n_double = 0, n_string = 0;
+	char buf[1000];
+	struct field_info *Fi;
+	char *tmp, *key;
+	dbDriver *driver;
+	dbString sql;
+	FILE *tmpascii;
+
+	/* Open temporary file */
+	tmp = G_tempfile();
+	if (NULL == (tmpascii = fopen(tmp, "w+"))) {
+	    G_fatal_error(_("Unable to open temporary file <%s>"), tmp);
+	}
+	unlink(tmp);
+
+	points_analyse(ascii, tmpascii, fs, &rowlen, &ncols, &minncols,
+		       &nrows, &coltype, &collen, skip_lines, xcol, ycol,
+		       region_flag->answer);
+
+	G_message(_("Maximum input row length: %d"), rowlen);
+	G_message(_("Maximum number of columns: %d"), ncols);
+	G_message(_("Minimum number of columns: %d"), minncols);
+
+	/* check column numbers */
+	if (xcol >= minncols) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("x column number > minimum last column number\n(incorrect field separator?)"));
+	}
+	if (ycol >= minncols) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("y column number > minimum last column number\n(incorrect field separator?)"));
+	}
+	if (zcol >= minncols) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("z column number > minimum last column number "
+			    "(incorrect field separator?)"));
+	}
+	if (catcol >= minncols) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("cat column number > minimum last column number "
+			    "(incorrect field separator?)"));
+	}
+
+	if (coltype[xcol] == DB_C_TYPE_STRING) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("x column is not of number type"));
+	}
+	if (coltype[ycol] == DB_C_TYPE_STRING) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("y column is not of number type"));
+	}
+	if (zcol >= 0 && coltype[zcol] == DB_C_TYPE_STRING) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("z column is not of number type"));
+	}
+	if (catcol >= 0 && coltype[catcol] == DB_C_TYPE_STRING) {
+	    Vect_delete(new->answer);
+	    G_fatal_error(_("cat column is not of number type"));
+	}
+
+	/* Create table */
+	make_table = 0;
+	for (i = 0; i < ncols; i++) {
+	    if (xcol != i && ycol != i && zcol != i && catcol != i) {
+		make_table = 1;
+		break;
+	    }
+	}
+	if (t_flag->answer) {
+	    make_table = 0;
+	}
+
+	if (make_table) {
+	    Fi = Vect_default_field_info(&Map, 1, NULL, GV_1TABLE);
+	    driver =
+		db_start_driver_open_database(Fi->driver,
+					      Vect_subst_var(Fi->database,
+							     &Map));
+	    if (driver == NULL) {
+		Vect_delete(new->answer);
+		G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+			      Vect_subst_var(Fi->database, &Map), Fi->driver);
+	    }
+	    db_begin_transaction(driver);
+
+	    db_init_string(&sql);
+	    sprintf(buf, "create table %s ( ", Fi->table);
+	    db_append_string(&sql, buf);
+
+	    if (catcol < 0) {
+		db_append_string(&sql, "cat integer, ");
+	    }
+
+	    for (i = 0; i < ncols; i++) {
+		if (i > 0 && !columns_opt->answer) {
+		    db_append_string(&sql, ", ");
+		}
+		if (catcol == i && coltype[i] != DB_C_TYPE_INT) {
+		    Vect_delete(new->answer);
+		    G_fatal_error(_("Category column is not of integer type"));
+		}
+
+		switch (coltype[i]) {
+		case DB_C_TYPE_INT:
+		    G_verbose_message("Column: %d  type: integer", i + 1);
+		    if (!columns_opt->answer) {
+			sprintf(buf, "int_%d integer", n_int + 1);
+			db_append_string(&sql, buf);
+			if (catcol == i) {
+			    sprintf(buf, "int_%d", n_int + 1);
+			    key = G_store(buf);
+			}
+		    }
+		    n_int++;
+		    break;
+		case DB_C_TYPE_DOUBLE:
+		    G_verbose_message("Column: %d  type: double", i + 1);
+		    if (!columns_opt->answer) {
+			sprintf(buf, "dbl_%d double precision", n_double + 1);
+			db_append_string(&sql, buf);
+		    }
+		    n_double++;
+		    break;
+		case DB_C_TYPE_STRING:
+		    G_verbose_message("Column: %d  type: string length: %d",
+				      i + 1, collen[i]);
+		    if (!columns_opt->answer) {
+			sprintf(buf, "str_%d varchar(%d)", n_string + 1,
+				collen[i]);
+			db_append_string(&sql, buf);
+		    }
+		    n_string++;
+		    break;
+		}
+	    }
+	    if (columns_opt->answer) {
+		db_append_string(&sql, columns_opt->answer);
+	    }
+	    db_append_string(&sql, " )");
+
+	    /* this link is added with default 'cat' key, later deleted and replaced by true key name,
+	     * otherwise if module crashes when the table exists but link is not written it makes troubles */
+	    Vect_map_add_dblink(&Map, 1, NULL, Fi->table, "cat", Fi->database,
+				Fi->driver);
+
+	    /* Create table */
+	    G_debug(3, db_get_string(&sql));
+	    if (db_execute_immediate(driver, &sql) != DB_OK) {
+		Vect_delete(new->answer);
+		G_fatal_error(_("Unable to create table: %s"),
+			      db_get_string(&sql));
+	    }
+
+	    /* Grant */
+	    if (db_grant_on_table
+		(driver, Fi->table, DB_PRIV_SELECT,
+		 DB_GROUP | DB_PUBLIC) != DB_OK) {
+		Vect_delete(new->answer);
+		G_fatal_error(_("Unable to grant privileges on table <%s>"),
+			      Fi->table);
+	    }
+
+	    /* Check column types */
+	    if (columns_opt->answer) {
+		int nc;
+		dbTable *table;
+		dbColumn *column;
+
+		db_set_string(&sql, Fi->table);
+		if (db_describe_table(driver, &sql, &table) != DB_OK) {
+		    Vect_delete(new->answer);
+		    G_fatal_error(_("Unable to describe table <%s>"),
+				  Fi->table);
+		}
+
+		nc = db_get_table_number_of_columns(table);
+
+		if ((catcol >= 0 && nc != ncols) ||
+		    (catcol < 0 && (nc - 1) != ncols)) {
+		    Vect_delete(new->answer);
+		    G_fatal_error(_("Number of columns defined (%d) does not match number "
+				   "of columns (%d) in input"),
+				  catcol < 0 ? nc - 1 : nc, ncols);
+		}
+
+		coltype2 = (int *)G_malloc(ncols * sizeof(int));
+
+		for (i = 0; i < ncols; i++) {
+		    int dbcol, ctype, length;
+
+		    if (catcol < 0)
+			dbcol = i + 1;	/* first is category */
+		    else
+			dbcol = i;
+
+		    column = db_get_table_column(table, dbcol);
+		    ctype =
+			db_sqltype_to_Ctype(db_get_column_sqltype(column));
+		    length = db_get_column_length(column);
+		    coltype2[i] = ctype;
+
+		    if (catcol == i) {	/* if catcol == -1 it cannot be tru */
+			key = G_store(db_get_column_name(column));
+		    }
+
+		    switch (coltype[i]) {
+		    case DB_C_TYPE_INT:
+			if (ctype == DB_C_TYPE_DOUBLE) {
+			    G_warning(_("Column number %d <%s> defined as double "
+				       "has only integer values"), i + 1,
+				      db_get_column_name(column));
+			}
+			else if (ctype == DB_C_TYPE_STRING) {
+			    G_warning(_("Column number %d <%s> defined as string "
+				       "has only integer values"), i + 1,
+				      db_get_column_name(column));
+			}
+			break;
+		    case DB_C_TYPE_DOUBLE:
+			if (ctype == DB_C_TYPE_INT) {
+			    Vect_delete(new->answer);
+			    G_fatal_error(_("Column number %d <%s> defined as integer "
+					   "has double values"), i + 1,
+					  db_get_column_name(column));
+			}
+			else if (ctype == DB_C_TYPE_STRING) {
+			    G_warning(_("Column number %d <%s> defined as string "
+				       "has double values"), i + 1,
+				      db_get_column_name(column));
+			}
+			break;
+		    case DB_C_TYPE_STRING:
+			if (ctype == DB_C_TYPE_INT) {
+			    Vect_delete(new->answer);
+			    G_fatal_error(_("Column number %d <%s> defined as integer "
+					   "has string values"), i + 1,
+					  db_get_column_name(column));
+			}
+			else if (ctype == DB_C_TYPE_DOUBLE) {
+			    Vect_delete(new->answer);
+			    G_fatal_error(_("Column number %d <%s> defined as double "
+					   "has string values"), i + 1,
+					  db_get_column_name(column));
+			}
+			if (length < collen[i]) {
+			    Vect_delete(new->answer);
+			    G_fatal_error(_("Length of column %d <%s> (%d) is less than "
+					   "maximum value " "length (%d)"),
+					  i + 1, db_get_column_name(column),
+					  length, collen[i]);
+			}
+			break;
+		    }
+		}
+	    }
+	    else {
+		coltype2 = coltype;
+	    }
+
+	    if (catcol < 0) {
+		key = "cat";
+	    }
+	    else if (!columns_opt->answer) {
+
+
+	    }
+
+	    if (db_create_index2(driver, Fi->table, key) != DB_OK)
+		G_warning(_("Unable to create index for table <%s>, key <%s>"),
+			  Fi->table, key);
+
+	    Vect_map_del_dblink(&Map, 1);
+	    Vect_map_add_dblink(&Map, 1, NULL, Fi->table, key, Fi->database,
+				Fi->driver);
+
+	    table = Fi->table;
+	}
+	else {
+	    driver = NULL;
+	    table = NULL;
+	}
+
+	points_to_bin(tmpascii, rowlen, &Map, driver, table, fs, nrows, ncols,
+		      coltype2, xcol, ycol, zcol, catcol, skip_lines);
+
+	if (driver) {
+	    G_message(_("Populating table..."));
+	    db_commit_transaction(driver);
+	    db_close_database_shutdown_driver(driver);
+	}
+	fclose(tmpascii);
+    }
+
+    else {			/* FORMAT_ALL (standard mode) */
+	if (!noheader_flag->answer)
+	    read_head(ascii, &Map);
+
+	asc_to_bin(ascii, &Map);
+    }
+
+    if (old->answer != NULL)
+	fclose(ascii);
+
+    if (notopol_flag->answer) {
+	Vect_close(&Map);
+    }
+    else {
+	Vect_build(&Map, stderr);
+	Vect_close(&Map);
+    }
+
+    G_done_msg(" ");
+
+    exit(EXIT_SUCCESS);
+}

Copied: grass/trunk/vector/v.out.ascii/main.c (from rev 32801, grass/trunk/vector/v.out.ascii/out.c)
===================================================================
--- grass/trunk/vector/v.out.ascii/main.c	                        (rev 0)
+++ grass/trunk/vector/v.out.ascii/main.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -0,0 +1,176 @@
+/*
+ ****************************************************************************
+ *
+ * MODULE:     v.out.ascii
+ * AUTHOR(S):  Michael Higgins, U.S. Army Construction Engineering Research Laboratory
+ *             James Westervelt, U.S. Army Construction Engineering Research Laboratory
+ *             Radim Blazek, ITC-Irst, Trento, Italy
+ *
+ * PURPOSE:    v.out.ascii: writes GRASS vector data as ASCII files
+ * COPYRIGHT:  (C) 2000-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.
+ *
+ ****************************************************************************
+ */
+/*  @(#)b_a_dig.c       2.1  6/26/87  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/Vect.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+int main(int argc, char *argv[])
+{
+    FILE *ascii, *att;
+    struct Option *input, *output, *format_opt, *dp_opt, *delim_opt;
+    struct Flag *verf, *region_flag;
+    int format, dp;
+    char *fs;
+    struct Map_info Map;
+    int ver = 5, pnt = 0;
+    struct GModule *module;
+
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("vector");
+    module->description =
+	_("Converts a GRASS binary vector map to a GRASS ASCII vector map.");
+
+    input = G_define_standard_option(G_OPT_V_INPUT);
+
+    output = G_define_option();
+    output->key = "output";
+    output->type = TYPE_STRING;
+    output->required = NO;
+    output->multiple = NO;
+    output->gisprompt = "new_file,file,output";
+    output->description =
+	_("Path to resulting ASCII file or ASCII vector name if '-o' is defined");
+
+    format_opt = G_define_option();
+    format_opt->key = "format";
+    format_opt->type = TYPE_STRING;
+    format_opt->required = NO;
+    format_opt->multiple = NO;
+    format_opt->options = "point,standard";
+    format_opt->answer = "point";
+    format_opt->description = _("Output format");
+
+    delim_opt = G_define_option();
+    delim_opt->key = "fs";
+    delim_opt->type = TYPE_STRING;
+    delim_opt->required = NO;
+    delim_opt->description = _("Field separator (points mode)");
+    delim_opt->answer = "|";
+
+    dp_opt = G_define_option();
+    dp_opt->key = "dp";
+    dp_opt->type = TYPE_INTEGER;
+    dp_opt->required = NO;
+    dp_opt->options = "0-32";
+    dp_opt->answer = "8";	/*This value is taken from the lib settings in G_format_easting() */
+    dp_opt->description =
+	_("Number of significant digits (floating point only)");
+
+    verf = G_define_flag();
+    verf->key = 'o';
+    verf->description = _("Create old (version 4) ASCII file");
+
+    region_flag = G_define_flag();
+    region_flag->key = 'r';
+    region_flag->description =
+	_("Only export points falling within current 3D region (points mode)");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    if (format_opt->answer[0] == 'p')
+	format = FORMAT_POINT;
+    else
+	format = FORMAT_ALL;
+
+    if (verf->answer)
+	ver = 4;
+
+    if (ver == 4 && format == FORMAT_POINT) {
+	G_fatal_error(_("Format 'point' is not supported for old version"));
+    }
+
+    if (ver == 4 && output->answer == NULL) {
+	G_fatal_error(_("'output' must be given for old version"));
+    }
+
+    /* the field separator */
+    fs = delim_opt->answer;
+    if (strcmp(fs, "\\t") == 0)
+	fs = "\t";
+    if (strcmp(fs, "tab") == 0)
+	fs = "\t";
+    if (strcmp(fs, "space") == 0)
+	fs = " ";
+
+    /*The precision of the output */
+    if (dp_opt->answer) {
+	if (sscanf(dp_opt->answer, "%d", &dp) != 1)
+	    G_fatal_error(_("Failed to interprete 'dp' parameter as an integer"));
+    }
+
+
+    Vect_set_open_level(1);	/* only need level I */
+    Vect_open_old(&Map, input->answer, "");
+
+
+    if (output->answer) {
+	if (ver == 4) {
+	    ascii = G_fopen_new("dig_ascii", output->answer);
+	}
+	else if (strcmp(output->answer, "-") == 0) {
+	    ascii = stdout;
+	}
+	else {
+	    ascii = fopen(output->answer, "w");
+	}
+
+	if (ascii == NULL) {
+	    G_fatal_error(_("Unable to open file <%s>"), output->answer);
+	}
+    }
+    else {
+	ascii = stdout;
+    }
+
+    if (format == FORMAT_ALL) {
+	write_head(ascii, &Map);
+	fprintf(ascii, "VERTI:\n");
+    }
+
+    /* Open dig_att */
+    att = NULL;
+    if (ver == 4 && !pnt) {
+	if (G_find_file("dig_att", output->answer, G_mapset()) != NULL)
+	    G_fatal_error(_("dig_att file already exist"));
+
+	if ((att = G_fopen_new("dig_att", output->answer)) == NULL)
+	    G_fatal_error(_("Unable to open dig_att file <%s>\n"),
+			  output->answer);
+    }
+
+    bin_to_asc(ascii, att, &Map, ver, format, dp, fs, region_flag->answer);
+
+    if (ascii != NULL)
+	fclose(ascii);
+    if (att != NULL)
+	fclose(att);
+
+    Vect_close(&Map);
+
+    exit(EXIT_SUCCESS);
+}

Deleted: grass/trunk/vector/v.out.ascii/out.c
===================================================================
--- grass/trunk/vector/v.out.ascii/out.c	2008-08-16 08:30:46 UTC (rev 32809)
+++ grass/trunk/vector/v.out.ascii/out.c	2008-08-16 09:46:03 UTC (rev 32810)
@@ -1,176 +0,0 @@
-/*
- ****************************************************************************
- *
- * MODULE:     v.out.ascii
- * AUTHOR(S):  Michael Higgins, U.S. Army Construction Engineering Research Laboratory
- *             James Westervelt, U.S. Army Construction Engineering Research Laboratory
- *             Radim Blazek, ITC-Irst, Trento, Italy
- *
- * PURPOSE:    v.out.ascii: writes GRASS vector data as ASCII files
- * COPYRIGHT:  (C) 2000-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.
- *
- ****************************************************************************
- */
-/*  @(#)b_a_dig.c       2.1  6/26/87  */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/Vect.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-
-int main(int argc, char *argv[])
-{
-    FILE *ascii, *att;
-    struct Option *input, *output, *format_opt, *dp_opt, *delim_opt;
-    struct Flag *verf, *region_flag;
-    int format, dp;
-    char *fs;
-    struct Map_info Map;
-    int ver = 5, pnt = 0;
-    struct GModule *module;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    module->keywords = _("vector");
-    module->description =
-	_("Converts a GRASS binary vector map to a GRASS ASCII vector map.");
-
-    input = G_define_standard_option(G_OPT_V_INPUT);
-
-    output = G_define_option();
-    output->key = "output";
-    output->type = TYPE_STRING;
-    output->required = NO;
-    output->multiple = NO;
-    output->gisprompt = "new_file,file,output";
-    output->description =
-	_("Path to resulting ASCII file or ASCII vector name if '-o' is defined");
-
-    format_opt = G_define_option();
-    format_opt->key = "format";
-    format_opt->type = TYPE_STRING;
-    format_opt->required = NO;
-    format_opt->multiple = NO;
-    format_opt->options = "point,standard";
-    format_opt->answer = "point";
-    format_opt->description = _("Output format");
-
-    delim_opt = G_define_option();
-    delim_opt->key = "fs";
-    delim_opt->type = TYPE_STRING;
-    delim_opt->required = NO;
-    delim_opt->description = _("Field separator (points mode)");
-    delim_opt->answer = "|";
-
-    dp_opt = G_define_option();
-    dp_opt->key = "dp";
-    dp_opt->type = TYPE_INTEGER;
-    dp_opt->required = NO;
-    dp_opt->options = "0-32";
-    dp_opt->answer = "8";	/*This value is taken from the lib settings in G_format_easting() */
-    dp_opt->description =
-	_("Number of significant digits (floating point only)");
-
-    verf = G_define_flag();
-    verf->key = 'o';
-    verf->description = _("Create old (version 4) ASCII file");
-
-    region_flag = G_define_flag();
-    region_flag->key = 'r';
-    region_flag->description =
-	_("Only export points falling within current 3D region (points mode)");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    if (format_opt->answer[0] == 'p')
-	format = FORMAT_POINT;
-    else
-	format = FORMAT_ALL;
-
-    if (verf->answer)
-	ver = 4;
-
-    if (ver == 4 && format == FORMAT_POINT) {
-	G_fatal_error(_("Format 'point' is not supported for old version"));
-    }
-
-    if (ver == 4 && output->answer == NULL) {
-	G_fatal_error(_("'output' must be given for old version"));
-    }
-
-    /* the field separator */
-    fs = delim_opt->answer;
-    if (strcmp(fs, "\\t") == 0)
-	fs = "\t";
-    if (strcmp(fs, "tab") == 0)
-	fs = "\t";
-    if (strcmp(fs, "space") == 0)
-	fs = " ";
-
-    /*The precision of the output */
-    if (dp_opt->answer) {
-	if (sscanf(dp_opt->answer, "%d", &dp) != 1)
-	    G_fatal_error(_("Failed to interprete 'dp' parameter as an integer"));
-    }
-
-
-    Vect_set_open_level(1);	/* only need level I */
-    Vect_open_old(&Map, input->answer, "");
-
-
-    if (output->answer) {
-	if (ver == 4) {
-	    ascii = G_fopen_new("dig_ascii", output->answer);
-	}
-	else if (strcmp(output->answer, "-") == 0) {
-	    ascii = stdout;
-	}
-	else {
-	    ascii = fopen(output->answer, "w");
-	}
-
-	if (ascii == NULL) {
-	    G_fatal_error(_("Unable to open file <%s>"), output->answer);
-	}
-    }
-    else {
-	ascii = stdout;
-    }
-
-    if (format == FORMAT_ALL) {
-	write_head(ascii, &Map);
-	fprintf(ascii, "VERTI:\n");
-    }
-
-    /* Open dig_att */
-    att = NULL;
-    if (ver == 4 && !pnt) {
-	if (G_find_file("dig_att", output->answer, G_mapset()) != NULL)
-	    G_fatal_error(_("dig_att file already exist"));
-
-	if ((att = G_fopen_new("dig_att", output->answer)) == NULL)
-	    G_fatal_error(_("Unable to open dig_att file <%s>\n"),
-			  output->answer);
-    }
-
-    bin_to_asc(ascii, att, &Map, ver, format, dp, fs, region_flag->answer);
-
-    if (ascii != NULL)
-	fclose(ascii);
-    if (att != NULL)
-	fclose(att);
-
-    Vect_close(&Map);
-
-    exit(EXIT_SUCCESS);
-}



More information about the grass-commit mailing list