[GRASS-SVN] r33095 - grass/trunk/display/d.profile
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 26 13:25:49 EDT 2008
Author: glynn
Date: 2008-08-26 13:25:48 -0400 (Tue, 26 Aug 2008)
New Revision: 33095
Removed:
grass/trunk/display/d.profile/DrawText.c
grass/trunk/display/d.profile/DumpProfile.c
grass/trunk/display/d.profile/ExtractProf.c
grass/trunk/display/d.profile/InitProfile.c
grass/trunk/display/d.profile/PlotProfile.c
grass/trunk/display/d.profile/Range.c
grass/trunk/display/d.profile/What.c
grass/trunk/display/d.profile/bnw_line.c
grass/trunk/display/d.profile/profile.h
grass/trunk/display/d.profile/utils.c
Modified:
grass/trunk/display/d.profile/d.profile.html
grass/trunk/display/d.profile/main.c
Log:
Replace d.profile with non-interactive version
Deleted: grass/trunk/display/d.profile/DrawText.c
===================================================================
--- grass/trunk/display/d.profile/DrawText.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/DrawText.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,54 +0,0 @@
-#include <grass/raster.h>
-#include <grass/display.h>
-
-/* DrawText.c
- *
- * function defined:
- *
- * DrawText(size,row,col,text)
- *
- * int size, - size of text (percent of window height)
- * row, - text row
- * col; - text col
- * char *text; - text string
- *
- * PURPOSE: To display a text string in the currently selected on-screen
- * window, in much the same way that the Dtext program works. Just like
- * Dtext the text size is expressed as a percentage of the window height.
- * The number of text rows and columns in a window are determined by the
- * text size.
- *
- * NOTES:
- *
- * 1) Assumes that R_open_driver has already been called.
- *
- * 2)
- *
- * Dave Johnson
- * DBA Systems, Inc.
- * 10560 Arrowhead Drive
- * Fairfax, Virginia 22030
- *
- */
-
-int DrawText(int size, int row, int col, char *text)
-{
- int b, t, l, r;
- int tsize;
- int dots_per_line;
- int cur_dot_row;
-
-#ifdef DEBUG
- fprintf(stdout, "DrawText: %s\n", text);
-#endif
-
- D_get_screen_window(&t, &b, &l, &r);
- dots_per_line = (int)(size / 100.0 * (float)(b - t));
- tsize = (int)(.8 * (float)dots_per_line);
- cur_dot_row = t + dots_per_line * row;
- R_text_size(tsize, tsize);
- R_move_abs(l + col * tsize, cur_dot_row);
- R_text(text);
-
- return 0;
-}
Deleted: grass/trunk/display/d.profile/DumpProfile.c
===================================================================
--- grass/trunk/display/d.profile/DumpProfile.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/DumpProfile.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,111 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <float.h>
-#include "profile.h"
-
-#define UCAT_STR_SIZE 50
-
-char *_fmt_ucat(UCAT *, UCAT *, char *);
-
-int WriteProfile(char *raster, char *mapset,
- char *fname, char letter, struct Profile *profile)
-{
- int proj;
- char *buf = G_calloc(UCAT_STR_SIZE, sizeof(char));
- char *buf2 = G_calloc(UCAT_STR_SIZE, sizeof(char));
- char *outfile = G_calloc(strlen(fname) + 3, sizeof(char));
- char coords[4][80];
- FILE *outFile;
- struct ProfileNode *ptr;
-
- memset(coords[0], 0, 80);
- memset(coords[1], 0, 80);
- memset(coords[2], 0, 80);
- memset(coords[3], 0, 80);
-
- /* Something's wrong if all of these are not NULL */
- if (raster == NULL || mapset == NULL || fname == NULL || profile == NULL)
- return -1;
-
- /* If no profiles were done, do nothing */
- if (profile->ptr == NULL || profile->count == 0)
- return 0;
-
- /* Each profile has the letter appended to the name */
- sprintf(outfile, "%s.%c", fname, letter);
- outFile = fopen(outfile, "w");
- if (outFile == NULL)
- return -1;
-
- proj = G_projection();
-
- /* Do the Header */
- fprintf(outFile, "# Profile %c of %s@%s\n", letter, raster, mapset);
- G_format_easting(profile->e1, coords[0], proj);
- G_format_northing(profile->n1, coords[1], proj);
- G_format_easting(profile->e2, coords[2], proj);
- G_format_northing(profile->n2, coords[3], proj);
- fprintf(outFile, "# From (%s, %s) to (%s, %s)\n",
- coords[0], coords[1], coords[2], coords[3]);
- fprintf(outFile, "# Stats: Count = %ld, Min = %s, Max = %s\n",
- profile->count,
- _fmt_ucat(&profile->MinCat, &profile->MinCat, buf),
- _fmt_ucat(&profile->MaxCat, &profile->MinCat, buf2));
- fprintf(outFile, "# dist value east north\n");
-
- /* Now loop through the nodes, one value per line */
- for (ptr = profile->ptr; ptr != NULL; ptr = ptr->next) {
- fprintf(outFile, "%f %s %f %f\n",
- ptr->dist,
- _fmt_ucat(&ptr->cat, &profile->MinCat, buf),
- ptr->east, ptr->north);
- }
-
- G_free(buf);
- G_free(buf2);
- G_free(outfile);
-
- fclose(outFile);
-
- return 0;
-} /* WriteProfile() */
-
-
-/* Pointer should have space for at least 20 chars.
- * First UCAT is the value we're formatting.
- * Second UCAT is a minimum value (use it if NULL)
- * The char *s in is the same that goes out
- */
-char *_fmt_ucat(UCAT * c, UCAT * min, char *s)
-{
- memset(s, 0, UCAT_STR_SIZE);
- switch (c->type) {
- case CELL_TYPE:
- if (c->val.c == INT_MIN)
- sprintf(s, "%d", min->val.c);
- else
- sprintf(s, "%d", c->val.c);
- break;
- case FCELL_TYPE:
- if (c->val.f == FLT_MIN)
- sprintf(s, "%f", min->val.f);
- else
- sprintf(s, "%f", c->val.f);
- break;
- case DCELL_TYPE:
- if (c->val.d == DBL_MIN)
- sprintf(s, "%lf", min->val.d);
- else
- sprintf(s, "%lf", c->val.d);
- break;
- default: /* Shouldn't happen */
- *s = '\0';
- }
-
- return s;
-}
-
-
-/* vim: set softtabstop=4 shiftwidth=4 expandtab: */
Deleted: grass/trunk/display/d.profile/ExtractProf.c
===================================================================
--- grass/trunk/display/d.profile/ExtractProf.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/ExtractProf.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,357 +0,0 @@
-
-/* ExtractProfile.c
- *
- * function defined:
- *
- * ExtractProfile(profile,name,mapset)
- *
- * struct Profile *profile; - pointer in initialized profile struct
- * char *name, - cell-file map name
- * *mapset; - mapset name
- *
- * PURPOSE: To extract a profile from a cell-file. A profile is a list
- * of all the cell-values along a given line drawn across a cell-file.
- * The number of cell-values is determined by the end-points of the line
- * and the current window definition.
- *
- * NOTES:
- *
- * 1) Assumes that profile is a pointer to a profile structure that has
- * been initialized through a call to the routine InitProfile. The
- * profile structure is defined in profile.h.
- *
- * 2) ExtractProfile returns 0 upon successful completion, or a negative
- * value if an error is encountered:
- *
- * -1 profile end-point outside the current window
- * -2 unable to open cell-file
- * -3 error reading from cell-file
- * -4 profile's window does not match current window
- *
- * Dave Johnson
- * DBA Systems, Inc.
- * 10560 Arrowhead Drive
- * Fairfax, Virginia 22030
- *
- */
-
-#include <stdlib.h>
-#include <limits.h>
-#include <float.h>
-#include <grass/glocale.h>
-#include "profile.h"
-
-void ucat_max(UCAT *, UCAT *);
-void ucat_min(UCAT *, UCAT *);
-
-int ExtractProfile(struct Profile *profile, char *name, char *mapset)
-{
- int fd; /* cell-file desciptor */
- struct Cell_head window; /* current GIS window */
- RASTER_MAP_PTR buf; /* storage for one cell-file row */
- UCAT theCell; /* storage of the current cell of interest - for NULL fix */
- struct ProfileNode *ptr = NULL;
- int stop;
- int row1, col1;
- int row2, col2;
- int row, col; /* keep track of profile line position */
- float slope; /* for profile line equation */
- int incr;
-
- G_get_set_window(&window);
-
- /* make sure profile`s window matches currently set window */
- if (profile->window.north != window.north ||
- profile->window.south != window.south ||
- profile->window.east != window.east ||
- profile->window.west != window.west ||
- profile->window.ew_res != window.ew_res ||
- profile->window.ns_res != window.ns_res)
- return (-4);
-
- /* make sure profile's end-points are not outside the current window */
- if (profile->n1 > window.north || profile->n1 < window.south ||
- profile->e1 > window.east || profile->e1 < window.west ||
- profile->n2 > window.north || profile->n2 < window.south ||
- profile->e2 > window.east || profile->e2 < window.west)
- return (-1);
-
- /* figure row and column coords. of end-points */
- row1 = (profile->window.north - profile->n1) / profile->window.ns_res;
- col1 = (profile->e1 - profile->window.west) / profile->window.ew_res;
- row2 = (profile->window.north - profile->n2) / profile->window.ns_res;
- col2 = (profile->e2 - profile->window.west) / profile->window.ew_res;
-
-#ifdef DEBUG
- fprintf(stdout, "ExtractProfile: from (%d,%d) to ", row1, col1);
- fprintf(stdout, "(%d,%d)\n", row2, col2);
-#endif
-
- /* open the cel file, return -2 if problem */
- fd = G_open_cell_old(name, mapset);
- if (fd < 0) {
- G_warning(_("Unable to open raster map <%s>"), name);
- return (-2);
- }
- theCell.type = buf.type = G_get_raster_map_type(fd);
- buf.data.v = G_allocate_raster_buf(buf.type);
-
- /*
- * this section loops through a line between (row1,col1) and (row2,col2)
- * adding category values along line to linked-list that represents
- * the profile
- *
- * two cases:
- * 1) line crosses more rows than columns.
- * 2) line crosses more columns than rows.
- *
- */
-
- /* CASE 1: line crosses more rows than columns. */
- if ((row1 != row2) && (abs(row1 - row2) > abs(col1 - col2))) {
- if (row2 < row1)
- incr = -1; /* line goes "up" */
- else
- incr = 1; /* line goes "down" */
-
- if (row1 == row2)
- slope = (float)0.0; /* line is horizontal */
- else
- slope = (float)((float)(col2 - col1) / (float)(row2 - row1));
-
-# ifdef DEBUG
- fprintf(stdout, "CASE 1: slope=%f\n", slope);
-# endif
-
- /* LOOP through profile line by rows */
- stop = row2 + incr;
- for (row = row1; row != stop; row += incr) {
- profile->count++;
- col = (int)(slope * (float)(row - row1) + col1);
-
- if (G_get_raster_row(fd, buf.data.v, row, buf.type) < 0)
- return (-3);
-
- /* Test if NULL, if so set to the minimum value */
- if (is_null_value(&buf, col)) {
- switch (buf.type) {
- case CELL_TYPE:
- theCell.val.c = INT_MIN;
- break;
- case FCELL_TYPE:
- theCell.val.f = FLT_MIN;
- break;
- case DCELL_TYPE:
- theCell.val.d = DBL_MIN;
- break;
- }
- }
- else {
- switch (buf.type) {
- case CELL_TYPE:
- theCell.val.c = buf.data.c[col];
- break;
- case FCELL_TYPE:
- theCell.val.f = buf.data.f[col];
- break;
- case DCELL_TYPE:
- theCell.val.d = buf.data.d[col];
- break;
- }
- }
-
-
- /* set mins and maxes */
- if (row == row1) {
- profile->MaxCat = theCell;
- profile->MinCat = theCell;
- }
- else {
- ucat_max(&profile->MaxCat, &theCell);
- ucat_min(&profile->MinCat, &theCell);
- }
-
- /* add to linked list */
- if (profile->ptr == NULL) { /* add to linked list */
- /* first in list */
- profile->ptr = (struct ProfileNode *)
- G_malloc(sizeof(struct ProfileNode));
- profile->ptr->cat = theCell;
- profile->ptr->next = NULL;
- /* Start info for Plotfile output */
- profile->ptr->east = G_col_to_easting((double)0.5 + col,
- &profile->window);
- profile->ptr->north = G_row_to_northing((double)0.5 + row,
- &profile->window);
- profile->ptr->dist = (double)0.0;
- ptr = profile->ptr;
- }
- else {
- /* not first in list */
- ptr->next = (struct ProfileNode *)
- G_malloc(sizeof(struct ProfileNode));
- ptr->next->cat = theCell;
- /* Do row/cell conversion for coordinates, Add .5 to get center */
- ptr->next->north = G_row_to_northing((double)0.5 + row,
- &profile->window);
- ptr->next->east = G_col_to_easting((double)0.5 + col,
- &profile->window);
- G_begin_distance_calculations();
- ptr->next->dist =
- G_distance(profile->ptr->east, profile->ptr->north,
- ptr->east, ptr->north);
- ptr->next->next = NULL;
- ptr = ptr->next;
- }
- }
- }
-
- /* CASE 2: line crosses more columns than rows */
- else {
- if (col2 < col1)
- incr = -1; /* line goes "left" */
- else
- incr = 1; /* line goes "right" */
-
- if (col1 == col2)
- slope = (float)0.0; /* line is vertical */
- else
- slope = (float)((float)(row2 - row1) / (float)(col2 - col1));
-
-# ifdef DEBUG
- fprintf(stdout, "CASE 2: slope=%f\n", slope);
-# endif
-
- /* LOOP through profile line by columns */
- stop = col2 + incr;
- for (col = col1; col != stop; col += incr) {
- profile->count++;
- row = (int)(slope * (float)(col - col1) + row1);
-
- if (G_get_raster_row(fd, buf.data.v, row, buf.type) < 0)
- return (-3);
-
- /* Test if NULL, if so set to the minimum value */
- if (is_null_value(&buf, col)) {
- switch (buf.type) {
- case CELL_TYPE:
- theCell.val.c = INT_MIN;
- break;
- case FCELL_TYPE:
- theCell.val.f = FLT_MIN;
- break;
- case DCELL_TYPE:
- theCell.val.d = DBL_MIN;
- break;
- }
- }
- else {
- switch (buf.type) {
- case CELL_TYPE:
- theCell.val.c = buf.data.c[col];
- break;
- case FCELL_TYPE:
- theCell.val.f = buf.data.f[col];
- break;
- case DCELL_TYPE:
- theCell.val.d = buf.data.d[col];
- break;
- }
- }
-
- /* set mins and maxes */
- if (row == row1) {
- profile->MaxCat = theCell;
- profile->MinCat = theCell;
- }
- else {
- ucat_max(&profile->MaxCat, &theCell);
- ucat_min(&profile->MinCat, &theCell);
- }
-
- /* add to linked list */
- if (profile->ptr == NULL) {
- /* first in list */
- profile->ptr = (struct ProfileNode *)
- G_malloc(sizeof(struct ProfileNode));
- profile->ptr->cat = theCell;
- profile->ptr->next = NULL;
- /* Start info for Plotfile output */
- profile->ptr->east = G_col_to_easting((double)0.5 + col,
- &profile->window);
- profile->ptr->north = G_row_to_northing((double)0.5 + row,
- &profile->window);
- profile->ptr->dist = (double)0.0;
- ptr = profile->ptr;
- }
- else {
- /* not first in list */
- ptr->next = (struct ProfileNode *)
- G_malloc(sizeof(struct ProfileNode));
- ptr->next->cat = theCell;
- /* Do row/cell conversion for coordinates, Add .5 to get center */
- ptr->next->north = G_row_to_northing((double)0.5 + row,
- &profile->window);
- ptr->next->east = G_col_to_easting((double)0.5 + col,
- &profile->window);
- G_begin_distance_calculations();
- ptr->next->dist =
- G_distance(profile->ptr->east, profile->ptr->north,
- ptr->east, ptr->north);
- ptr->next->next = NULL;
- ptr = ptr->next;
- }
- }
- }
-#ifdef DEBUG
- fprintf(stdout, "\n");
-#endif
-
- G_unopen_cell(fd);
- return (0);
-}
-
-void ucat_max(UCAT * to, UCAT * from)
-{
- switch (to->type) {
- case CELL_TYPE:
- if (to->val.c == INT_MIN)
- to->val.c = from->val.c;
- else if (from->val.c > to->val.c)
- to->val.c = from->val.c;
- break;
- case FCELL_TYPE:
- if (to->val.f == FLT_MIN)
- to->val.f = from->val.f;
- else if (from->val.f > to->val.f)
- to->val.f = from->val.f;
- break;
- case DCELL_TYPE:
- if (to->val.d == DBL_MIN)
- to->val.d = from->val.d;
- else if (from->val.d > to->val.d)
- to->val.d = from->val.d;
- break;
- }
-}
-
-
-void ucat_min(UCAT * to, UCAT * from)
-{
- switch (from->type) {
- case CELL_TYPE:
- if (from->val.c != INT_MIN && from->val.c < to->val.c)
- to->val.c = from->val.c;
- break;
- case FCELL_TYPE:
- if (from->val.f != FLT_MIN && from->val.f < to->val.f)
- to->val.f = from->val.f;
- break;
- case DCELL_TYPE:
- if (from->val.d != DBL_MIN && from->val.d < to->val.d)
- to->val.d = from->val.d;
- break;
- }
-}
-
-/* vim: set softtabstop=4 shiftwidth=4 expandtab: */
Deleted: grass/trunk/display/d.profile/InitProfile.c
===================================================================
--- grass/trunk/display/d.profile/InitProfile.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/InitProfile.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,51 +0,0 @@
-
-/* InitProfile.c
- *
- * function defined:
- *
- * InitProfile(profile,window,north1,east1,north2,east2)
- *
- * struct Profile *profile; - pointer to profile structure
- * struct Cell_head window; - current window definition
- * double north1, - coords. of point #1
- * east1,
- * north2, - coords. of point #2
- * east2;
- *
- * PURPOSE: To initialize a profile structure with profile-line
- * end-points and the current window definition.
- *
- * NOTES:
- *
- * 1) The profile structure is defined in the file profile.h.
- *
- * 2)
- *
- * Dave Johnson
- * DBA Systems, Inc.
- * 10560 Arrowhead Drive
- * Fairfax, Virginia 22030
- *
- */
-
-#include "profile.h"
-
-int
-InitProfile(struct Profile *profile, struct Cell_head window, double north1,
- double east1, double north2, double east2)
-{
- profile->window.north = window.north;
- profile->window.south = window.south;
- profile->window.west = window.west;
- profile->window.east = window.east;
- profile->window.ew_res = window.ew_res;
- profile->window.ns_res = window.ns_res;
- profile->n1 = north1;
- profile->e1 = east1;
- profile->n2 = north2;
- profile->e2 = east2;
- profile->count = 0;
- profile->ptr = NULL;
-
- return 0;
-}
Deleted: grass/trunk/display/d.profile/PlotProfile.c
===================================================================
--- grass/trunk/display/d.profile/PlotProfile.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/PlotProfile.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,166 +0,0 @@
-/* PlotProfile.c
- *
- * function defined:
- *
- * PlotProfile(profile,letter,min,max)
- *
- * struct Profile profile; - profile structure
- * int min, - min cell-file value
- * max; - max cell-file calue
- *
- * PURPOSE: To plot a profile in the currently chosen on-screen window.
- * The profile's length is scaled to fit along the x-axis. The profile
- * is scaled to fit the maximum and minimum cell-file values (instead of
- * the maximum and minimum profile values) on the y-axis.
- *
- * NOTES:
- *
- * 1) assumes that R_open_driver has already been called.
- *
- * 2) assumes that the profile structure has been both initialized by
- * a call to InitProfile, and filled with data by a call to ExtractProfile.
- *
- * Dave Johnson
- * DBA Systems, Inc.
- * 10560 Arrowhead Drive
- * Fairfax, Virginia 22030
- *
- */
-
-#include <limits.h>
-#include <grass/raster.h>
-#include <grass/display.h>
-#include "profile.h"
-
-#define ORIGIN_X 0.13
-#define ORIGIN_Y 0.07
-#define YAXIS_END 0.77
-#define XAXIS_END 0.95
-#define TEXT_HEIGHT 0.11
-#define TEXT_COLUMN 0.07
-
-double _get_cat(UCAT *, int);
-
-int PlotProfile(struct Profile profile, char *letter, int min, int max)
-{
- struct ProfileNode *ptr;
- char txt_buf[512];
- int done;
- int text_width,
- text_height,
- i, t, b, l, r, tt, tb, tl, tr, height, width, x_line[3], y_line[3];
- double yoffset, xoffset, xscale, yscale;
-
- /* get current graphics window coordinates */
- D_get_screen_window(&t, &b, &l, &r);
- R_set_window(t, b, l, r);
-
- /* erase current graphics window to black */
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
-
- /* create axis lines */
- 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);
- D_use_color(D_translate_color(DEFAULT_FG_COLOR));
-
- /* figure scaling factors and offsets for profile line */
- xscale = ((double)(x_line[2] - x_line[1]) / ((double)profile.count));
- yscale = ((double)(y_line[1] - y_line[0])) / ((double)(max - min));
- yoffset = (double)(y_line[1]);
- xoffset = (double)x_line[1];
-
- /* plot profile */
- ptr = profile.ptr;
- R_move_abs((int)xoffset, (int)yoffset);
- for (i = 0; i <= profile.count; i++) {
- if (ptr == NULL)
- break;
- if (xscale > 1) {
- R_cont_abs((int)(xoffset + xscale * i),
- (int)(yoffset - yscale * _get_cat(&ptr->cat, min)));
- R_cont_abs((int)(xoffset + xscale * (i + 1.0)),
- (int)(yoffset - yscale * _get_cat(&ptr->cat, min)));
- }
- else
- R_cont_abs((int)(xoffset + xscale * i),
- (int)(yoffset - yscale * _get_cat(&ptr->cat, min)));
- ptr = ptr->next;
- }
- D_use_color(D_translate_color("red"));
- R_polyline_abs(x_line, y_line, 3);
-
- /* loop until coordinate text is sized correctly to fit in window */
- text_height = TEXT_HEIGHT * (b - t);
- text_width = text_height * 0.8;
- D_use_color(D_translate_color(DEFAULT_FG_COLOR));
- sprintf(txt_buf, "%s: From (%10.2f,%10.2f) to (%10.2f,%10.2f)",
- letter, profile.e1, profile.n1, profile.e2, profile.n2);
- done = 0;
- do {
- R_get_text_box(txt_buf, &tt, &tb, &tl, &tr);
- if ((tr - tl) >= (r - l)) {
- text_height *= 0.95;
- text_width *= 0.95;
- R_text_size(text_width, text_height);
- }
- else
- done = 1;
- }
- while (!done);
- R_move_abs((int)(l + 0.5 * (r - l) - .5 * (tr - tl)),
- (int)(t + .12 * (b - t)));
- R_text(txt_buf);
-
- /* set text size for y-axis labels */
- text_height = TEXT_HEIGHT * (b - t);
- text_width = text_height * 0.8;
- R_text_size(text_width, text_height);
-
- /* plot y-axis label (bottom) */
- sprintf(txt_buf, "%d", min);
- R_get_text_box(txt_buf, &tt, &tb, &tl, &tr);
- R_move_abs((int)(l + TEXT_COLUMN * (r - l) - .5 * (tr - tl)),
- (int)(yoffset + .5 * (tb - tt)));
- R_text(txt_buf);
-
- /* plot y-axis label (top) */
- sprintf(txt_buf, "%d", max);
- R_get_text_box(txt_buf, &tt, &tb, &tl, &tr);
- R_move_abs((int)(l + TEXT_COLUMN * (r - l) - .5 * (tr - tl)),
- (int)(y_line[0] + .5 * (tb - tt)));
- R_text(txt_buf);
- R_flush();
-
- return 0;
-}
-
-
-double _get_cat(UCAT * theCat, int min)
-{
- switch (theCat->type) {
- case CELL_TYPE:
- if (theCat->val.c >= min)
- return (double)(theCat->val.c - (double)min);
- else
- return (double)0.0;
- case FCELL_TYPE:
- if (theCat->val.f >= min)
- return (double)(theCat->val.f - (double)min);
- else
- return (double)0.0;
- case DCELL_TYPE:
- if (theCat->val.d >= min)
- return (theCat->val.d - (double)min);
- else
- return (double)0.0;
- default: /* Shouldn't happen */
- return (double)0.0;
- }
-}
-
-/* vim: set softtabstop=4 shiftwidth=4 expandtab: */
Deleted: grass/trunk/display/d.profile/Range.c
===================================================================
--- grass/trunk/display/d.profile/Range.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/Range.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,109 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-int WindowRange(char *name, char *mapset, long *min, long *max)
-{
- char inbuf[512]; /* input buffer for reading stats */
- int done = 0;
- char stats_cmd[512]; /* string for r.stats command */
- char *temp_fname; /* temp file name */
- FILE *temp_file; /* temp file pointer */
- long int cat; /* a category value */
- long int stat; /* a category stat value */
- int first;
-
- /* write stats to a temp file */
- temp_fname = G_tempfile();
- sprintf(stats_cmd, "r.stats -ci %s > %s\n", name, temp_fname);
- system(stats_cmd);
-
- /* open temp file and read the stats into a linked list */
- temp_file = fopen(temp_fname, "r");
-
- first = 1;
- while (!done) {
- if (fgets(inbuf, 1024, temp_file) != NULL) {
- if (sscanf(inbuf, "%ld %ld", &cat, &stat) == 2) {
- if (first) {
- *max = cat;
- *min = cat;
- first = 0;
- }
- else {
- if (cat > *max)
- *max = cat;
- if (cat < *min)
- *min = cat;
- }
- }
- else
- done = 1;
- }
- else
- done = 1;
- }
-
- return 0;
-}
-
-int quick_range(char *name, char *mapset, long *min, long *max)
-{
- struct Range range;
- struct FPRange fprange;
- CELL xmin, xmax;
- DCELL fpxmin, fpxmax;
-
- switch (G_raster_map_type(name, mapset)) {
- case CELL_TYPE:
- if (G_read_range(name, mapset, &range) <= 0)
- return 0;
- G_get_range_min_max(&range, &xmin, &xmax);
- *max = xmax;
- *min = xmin;
- break;
- default:
- if (G_read_fp_range(name, mapset, &fprange) <= 0)
- return 0;
- G_get_fp_range_min_max(&fprange, &fpxmin, &fpxmax);
- *max = (long)fpxmax;
- *min = (long)fpxmin;
- break;
- }
- return 1;
-}
-
-int slow_range(char *name, char *mapset, long *min, long *max)
-{
- FILE *fd;
- int first;
- long n;
- int ok;
- char buf[512];
-
- *min = *max = 0;
-
- G_message(_("one moment ..."));
- sprintf(buf, "Gdescribe -r -1 '%s in %s'", name, mapset);
- fd = popen(buf, "r");
- if (fd == NULL)
- return 0;
- ok = 1;
- first = 1;
- while (ok && fgets(buf, sizeof(buf), fd)) {
- ok = (sscanf(buf, "%ld", &n) == 1);
- if (!ok)
- break;
- if (n == 0)
- continue;
- *max = n;
- if (first)
- *min = n;
- first = 0;
- }
- pclose(fd);
- if (!ok)
- *min = *max = 0;
- return ok;
-}
Deleted: grass/trunk/display/d.profile/What.c
===================================================================
--- grass/trunk/display/d.profile/What.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/What.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,52 +0,0 @@
-#include <stdio.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/display.h>
-#include <grass/glocale.h>
-#include "profile.h"
-
-int What(char *name,
- char *mapset, struct Cell_head window, double east, double north)
-{
- struct Categories cat;
- int NoCatStrings = 0, row, col, fd;
- CELL *buf;
- char txt_buf[1024];
-
- row = (window.north - north) / window.ns_res;
- col = (east - window.west) / window.ew_res;
-
- buf = G_allocate_cell_buf();
-
- fd = G_open_cell_old(name, mapset);
- if (fd < 0)
- G_fatal_error(_("Unable to open raster map <%s>"), name);
-
- if (G_read_cats(name, mapset, &cat) < 0)
- NoCatStrings = 1;
-
- if (G_get_map_row(fd, buf, row) < 0)
- G_fatal_error(_("Error reading raster map"));
- else {
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
- D_use_color(D_translate_color("red"));
- R_flush();
- sprintf(txt_buf, "%s in mapset %s", name, mapset);
- DrawText(22, 1, 1, txt_buf);
- D_use_color(D_translate_color(DEFAULT_FG_COLOR));
- sprintf(txt_buf, "EAST: %10.2f", east);
- DrawText(22, 2, 1, txt_buf);
- sprintf(txt_buf, "NORTH: %10.2f", north);
- DrawText(22, 3, 1, txt_buf);
- if (NoCatStrings)
- sprintf(txt_buf, "(%d)", buf[col]);
- else
- sprintf(txt_buf, "(%d) %s", buf[col], G_get_cat(buf[col], &cat));
- DrawText(22, 4, 1, txt_buf);
- R_flush();
- }
- G_unopen_cell(fd);
-
- return 0;
-}
Deleted: grass/trunk/display/d.profile/bnw_line.c
===================================================================
--- grass/trunk/display/d.profile/bnw_line.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/bnw_line.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,24 +0,0 @@
-#include <stdlib.h>
-#include <grass/raster.h>
-#include <grass/display.h>
-
-int black_and_white_line(int screen_x, int screen_y,
- int cur_screen_x, int cur_screen_y)
-{
- D_use_color(D_translate_color(DEFAULT_FG_COLOR));
- R_move_abs(cur_screen_x, cur_screen_y);
- R_cont_abs(screen_x, screen_y);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- if (abs(screen_y - cur_screen_y) <= abs(screen_x - cur_screen_x)) {
- R_move_abs(cur_screen_x, cur_screen_y - 1);
- R_cont_abs(screen_x, screen_y - 1);
- }
- else {
- R_move_abs(cur_screen_x + 1, cur_screen_y);
- R_cont_abs(screen_x + 1, screen_y);
- }
-
- R_flush();
-
- return 0;
-}
Modified: grass/trunk/display/d.profile/d.profile.html
===================================================================
--- grass/trunk/display/d.profile/d.profile.html 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/d.profile.html 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,194 +1,16 @@
<H2>DESCRIPTION</H2>
-This command works only interactively. It clears the entire
-graphics screen and provides a graphical interaction
-allowing the selection of transects for which profiles are
-then generated. Input parameters can be specified on the command line
-for quicker start-up.
+This command displays the profile for a specified transect.
-<H2>USER PROMPTS</H2>
-
-First, you will be presented with a prompt asking you to
-choose a raster map layer to be profiled. Then you will be
-prompted for an optional display raster. The optional display raster
-will be shown rather than the profiled raster. This is useful
-to be able to more easily see ground features, such as might be visible
-in an aerial photo or satellite image. Finally, you will
-be prompted for the name prefix for output file(s) containing the profile
-data. This is an optional feature.
-
-<P>
-
-After parameters are given, the raster layer will be
-displayed in the left half of the graphics monitor, and the
-right half will be divided into four
-frames. There will also be two frames along the top of the
-monitor: a mouse-button menu frame on the left, and a
-status frame on the right.
-
-<P>
-
-The mouse-button menu initially offers you three options:
-
-<DL>
-<DD>
-Mouse Buttons: <BR>
-Left: Where am I? <BR>
-Middle: Mark FIRST Point of Profile Line. <BR>
-Right: QUIT this. <BR>
-</DL>
-
-You may query the displayed raster map layer by indicating
-points with the left mouse-button. The coordinates and
-category value of each point that you indicate will be
-displayed on in the status frame. If you mark the first
-point of the profile line you will be presented with the
-following mouse-button menu:
-
-<DL>
-<DD>
-Mouse Buttons: <BR>
-Left: Where am I? <BR>
-Middle: Mark SECOND Point of Profile Line. <BR>
-Right: QUIT this. <BR>
-</DL>
-
-Once you mark the second point of the profile line, the
-profile line will be labeled (with a letter from A to D)
-and displayed in one of the four display frames on the
-right hand side of the screen. You will then be presented
-with a third mouse-button menu:
-
-<DL>
-<DD>
-Mouse Buttons: <BR>
-Left: DO ANOTHER <BR>
-Middle: CLEAR DISPLAY <BR>
-Right: QUIT this. <BR>
-</DL>
-
-If you would like to view another profile, click on the
-left mouse-button. If you would like to redisplay the
-raster map layer and clear out the four profile frames,
-click on the middle mouse-button. If you would like to
-quit, then click on the right button.
-
-<P>
-
-If you selected the <B>plotfile</B> option, you will have up to
-four files starting with the <EM>name</EM> and followed by a suffix
-of the plot letter <EM>A, B, C,</EM> or <EM>D</EM>. The plots that
-are written to these files reflect the last of each plot done with that
-letter (i.e. They will match what's in the display when you quit).
-
-<P>
-The format of the plot files is not geared toward any particular software,
-but should be easy to coax into a number of other programs. The first
-three lines contain some header information about the plot, each prefixed
-with a <TT>#</TT> sign to denote a comment. A fourth comment line describes
-the data that follows. It consists of the distance (always in meters),
-the cell value (in whatever units it is in), the easting in decimal format,
-and the northing in decimal format.
-The number of values will vary depending on the length of the profile, cell
-resolution and the slope angle of the profile line. Below is an example
-of a plotfile:
-<P>
-<TT>
-# Profile A of elev.ft at snows<BR>
-# From (702879.29679757, 4287317.55920185) to (702722.40973589, 4287061.72632285)<BR>
-# Stats: Count = 644, Min = 2424.658936, Max = 2513.246094<BR>
-# dist value east north<BR>
-0.000000 2513.246094 702879.102364 4287317.516912<BR>
-0.000000 2513.246094 702878.713496 4287317.118970<BR>
-0.556395 2513.246094 702878.324629 4287316.721029<BR>
-1.112790 2513.246094 702878.324629 4287316.323088<BR>
-...<P>
-</TT>
-
-<H2>NOTES</H2>
-
-You might notice the first two 'dist' values in the profile output above are
-both zero. This is due to the fact the cell resolution for this file is
-less than one meter, and so the function that calculates the distance
-considers the distance between the first cell and the second to be zero.
-You might also notice, the coordinates given in the header and displayed on
-screen are slightly different from the first and last coordinates given in
-the profile data output. This is because the profile data output finds the
-eastings and northings for the center of the cells while the coordinate
-transformations from mouse clicks might yield slightly different coordinates
-which still fall within the same cell boundaries. The difference should
-always be less than the distance between the center and any corner (not
-edge!) of the cell at the resolution of the profiled raster.
-
-<P>
-
-Only four output plotfiles can be made. Each time a new profile is run, the
-plotfile is immediately written to the file <EM>name</EM>.<EM>letter</EM>.
-One can take advantage of this fact to create an unlimited number of
-plotfiles simply by renaming the output files before running more profiles.
-This may not always be the case, but it is at the time of this writing.
-
-<P>
-
-Useful enhancements to <EM>d.profile</EM> would include:
-
-<OL>
-
-<LI>Adding an option to display profiles using category
-colors, like a bar-chart.
-
-<LI>Allowing profile lines to be defined by a series of
-points, not just two.
-
-<LI>Allowing profiles to be saved in a file, for later
-viewing by GRASS.
-
-<LI>Allowing the user to enter profile line points by
-typing coordinates.
-
-</OL>
-
-<H3>Perl Script to convert output to a site_list</H3>
-
-The script below will convert the <B>plotfile</B> output to the site_list format.
-It probably won't work 100% for lat/lon datasets.
-
-<P>
-
-<TT>
-<B>#! /usr/bin/perl -w</B><BR>
-# prof2sites.pl: converts the output of d.profile to a site_list
-<P>
-<B>my</B> (<EM>$dist</EM>, <EM>$elev</EM>, <EM>$east</EM>, <EM>$north</EM>);
-<P>
-<B>while</B> (<<B>STDIN</B>>)<BR>
-{<BR>
- <B>if</B> (m/^#/)<BR>
- {<BR>
- <B>print</B> "<EM>$_</EM>";<BR>
- }<BR>
- <B>else</B><BR>
- {<BR>
- <B>chomp</B>;<BR>
- (<EM>$dist</EM>, <EM>$elev</EM>, <EM>$east</EM>, <EM>$north</EM>) = <B>split</B> / /;<BR>
- <B>print</B> "<EM>$east</EM>|<EM>$north</EM>|<EM>$elev</EM>|#1 \%<EM>$dist</EM> \@Profile\n";<BR>
- }<BR>
-}<BR>
-</TT>
-
<H2>BUGS</H2>
None known.
<H2>AUTHOR</H2>
-Dave Johnson
-<BR> DBA Systems, Inc. <BR>
-10560 Arrowhead Drive <BR>
-Fairfax, Virginia 22030
+Glynn Clements
-<P>
-Modified by Eric G. Miller for profile output, support of
-floating point rasters, and optional display raster (02-Dec-2000).
+This program has been completely re-written for 7.0. It bears no
+relation to the interactive d.profile module in previous versions.
<p><i>Last changed: $Date$</i>
Modified: grass/trunk/display/d.profile/main.c
===================================================================
--- grass/trunk/display/d.profile/main.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/main.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -19,8 +19,6 @@
*****************************************************************************/
-#define DEBUG
-#define USE_OLD_CODE /* Frame set-up still needs old code ATM. */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@@ -28,439 +26,287 @@
#include <grass/raster.h>
#include <grass/display.h>
#include <grass/glocale.h>
-#include "profile.h"
-struct windows windows[] = {
- {"mou", 85, 100, 0, 50},
- {"sta", 85, 100, 50, 100},
- {"map", 0, 85, 0, 50},
- {"orig", 0, 100, 0, 1009}
-};
+static char *mapname;
+static double min, max;
-struct windows profiles[] = {
- {"pro1", 64, 85, 50, 100},
- {"pro2", 43, 64, 50, 100},
- {"pro3", 22, 43, 50, 100},
- {"pro4", 0, 22, 50, 100}
+struct point
+{
+ double x, y;
+ double d;
};
-struct Profile profile;
-
-void myDcell(char *name, char *mapset, int overlay);
-
-int main(int argc, char **argv)
+static void get_region_range(int fd)
{
- char *old_mapset, *old_mapname, *d_mapset, *d_mapname;
- double cur_ux, cur_uy;
- double ux, uy;
- char ltr[10];
- int text_width, text_height;
- int err, doplot;
- int button;
- int cur_screen_x, cur_screen_y;
- int screen_x, screen_y;
- struct Cell_head window;
- int t, b, l, r;
- int i, CurrentWin = 0;
- long min, max;
- struct Option *map, *dmap, *plotfile;
- struct GModule *module;
+ DCELL *buf = G_allocate_d_raster_buf();
+ int nrows = G_window_rows();
+ int ncols = G_window_cols();
+ int row, col;
- /* Initialize the GIS calls */
- G_gisinit(argv[0]);
+ min = 1e300;
+ max = -1e300;
- /* Set description */
- module = G_define_module();
- module->keywords = _("display");
- module->description =
- _("Interactive profile plotting utility with optional output.");
+ for (row = 0; row < nrows; row++) {
+ G_get_d_raster_row(fd, buf, row);
+ for (col = 0; col < ncols; col++) {
+ if (min > buf[col])
+ min = buf[col];
+ if (max < buf[col])
+ max = buf[col];
+ }
+ }
+}
- /* set up command line */
- map = G_define_option();
- map->key = "rast";
- map->type = TYPE_STRING;
- map->required = YES;
- map->gisprompt = "old,cell,raster";
- map->description = _("Raster map to be profiled");
+static void get_map_range(void)
+{
+ if (G_raster_map_type(mapname, "") == CELL_TYPE) {
+ struct Range range;
+ CELL xmin, xmax;
- dmap = G_define_option();
- dmap->key = "drast";
- dmap->type = TYPE_STRING;
- dmap->required = NO;
- dmap->gisprompt = "old,cell,raster";
- dmap->description = _("Optional display raster");
+ if (G_read_range(mapname, "", &range) <= 0)
+ G_fatal_error(_("Unable to read range for %s"), mapname);
- plotfile = G_define_option();
- plotfile->key = "plotfile";
- plotfile->type = TYPE_STRING;
- plotfile->required = NO;
- plotfile->description =
- _("Output profile data to file(s) with prefix 'name'");
+ G_get_range_min_max(&range, &xmin, &xmax);
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
+ max = xmax;
+ min = xmin;
+ }
+ else {
+ struct FPRange fprange;
- old_mapname = map->answer;
+ if (G_read_fp_range(mapname, "", &fprange) <= 0)
+ G_fatal_error(_("Unable to read FP range for %s"), mapname);
- old_mapset = G_find_cell2(old_mapname, "");
- if (old_mapset == NULL)
- G_fatal_error(_("Raster map <%s> not found"), old_mapname);
+ G_get_fp_range_min_max(&fprange, &min, &max);
+ }
+}
- if (plotfile->answer != NULL)
- doplot = 1;
- else
- doplot = 0;
+static void plot_axes(void)
+{
+ char str[64];
+ double scale;
+ double t, b, l, r;
- /* If the user wants to display a different raster */
- if (dmap->answer != NULL) {
- d_mapname = dmap->answer;
- d_mapset = G_find_cell2(d_mapname, "");
- if (d_mapset == NULL) {
- G_warning(_("Display raster [%s] not found. Using profile raster."),
- d_mapname);
- d_mapname = old_mapname;
- d_mapset = old_mapset;
- }
- }
- else {
- d_mapname = old_mapname;
- d_mapset = old_mapset;
- }
+ D_use_color(D_translate_color("red"));
- /* get cell-file range */
- WindowRange(old_mapname, old_mapset, &min, &max);
+ D_move_abs(0, 1);
+ D_cont_abs(0, 0);
+ D_cont_abs(1, 0);
- /* the following code should not be used to get fp range correctly.
- if (!quick_range(old_mapname,old_mapset,&min,&max))
- {
- if (!slow_range(old_mapname,old_mapset,&min,&max))
- G_fatal_error(_("Unable to read from cell-file"));
- }
- if (min > 0) min = 0;
- if (max < 0) max = 0;
- */
+ D_use_color(D_translate_color(DEFAULT_FG_COLOR));
- G_message(_("\n\nUse mouse to choose action"));
+ /* set text size for y-axis labels */
+ scale = fabs(D_get_u_to_d_yconv());
+ R_text_size(scale * 0.04, scale * 0.05);
- /* establish connection with graphics driver */
- if (R_open_driver() != 0)
- G_fatal_error(_("No graphics device selected"));
+ /* plot y-axis label (bottom) */
+ sprintf(str, "%.1f", min);
+ D_get_text_box(str, &t, &b, &l, &r);
+ D_move_abs(-0.02 - (r - l), 0 - (t - b) / 2);
+ R_text(str);
- /* Make sure screen is clear */
- D_remove_windows();
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- R_erase();
+ /* plot y-axis label (top) */
+ sprintf(str, "%.1f", max);
+ D_get_text_box(str, &t, &b, &l, &r);
+ D_move_abs(-0.02 - (r - l), 1 - (t - b) / 2);
+ R_text(str);
+}
- /* Establish windows on screen */
-#ifdef USE_OLD_CODE
- D_new_window_percent(MOU.name, MOU.bot, MOU.top, MOU.left, MOU.right);
- D_new_window_percent(STA.name, STA.bot, STA.top, STA.left, STA.right);
- D_new_window_percent(MAP.name, MAP.bot, MAP.top, MAP.left, MAP.right);
- D_new_window_percent(ORIG.name, ORIG.bot, ORIG.top, ORIG.left,
- ORIG.right);
- for (i = 0; i <= 3; i++)
- D_new_window_percent(profiles[i].name, profiles[i].bot,
- profiles[i].top, profiles[i].left,
- profiles[i].right);
-#else
- /* This operates different than above, expect real world coords ? */
- D_new_window(MOU.name, MOU.top, MOU.bot, MOU.left, MOU.right);
- D_new_window(STA.name, STA.top, STA.bot, STA.left, STA.right);
- D_new_window(MAP.name, MAP.top, MAP.bot, MAP.left, MAP.right);
- D_new_window(ORIG.name, ORIG.top, ORIG.bot, ORIG.left, ORIG.right);
- for (i = 0; i < 4; i++)
- D_new_window(profiles[i].name, profiles[i].top,
- profiles[i].bot, profiles[i].left, profiles[i].right);
-#endif
+static int get_cell(DCELL *result, int fd, double x, double y)
+{
+ static DCELL *row1, *row2;
+ static int cur_row = -1;
+ static int row, col;
+ DCELL *tmp;
- /* Plot cell-file in map window */
- D_set_cur_wind(MAP.name);
- myDcell(d_mapname, d_mapset, 1);
+ if (!row1) {
+ row1 = G_allocate_d_raster_buf();
+ row2 = G_allocate_d_raster_buf();
+ }
+ col = (int)floor(x - 0.5);
+ row = (int)floor(y - 0.5);
+ x -= col + 0.5;
+ y -= row + 0.5;
- /* loop until user wants to quit */
- for (;;) {
- /* display mouse-menu in mouse-menu window */
- D_set_cur_wind(MOU.name);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
- D_use_color(D_translate_color("red"));
- DrawText(25, 1, 1, "GRASS PROGRAM: profile");
- D_use_color(D_translate_color(DEFAULT_FG_COLOR));
- DrawText(15, 3, 1, "MOUSE | Left: Where am I?");
- DrawText(15, 4, 1, "BUTTON | Middle: Set FIRST point");
- DrawText(15, 5, 1, "MENU | Right: Quit this\n");
- R_flush();
+ if (row < 0 || row + 1 >= G_window_rows() ||
+ col < 0 || col + 1 >= G_window_cols()) {
+ G_set_d_null_value(result, 1);
+ return 0;
+ }
- /* LOOP to get first point of line */
- do {
+ if (cur_row != row) {
+ if (cur_row == row + 1) {
+ tmp = row1; row1 = row2; row2 = tmp;
+ G_get_d_raster_row(fd, row1, row);
+ }
+ else if (cur_row == row - 1) {
+ tmp = row1; row1 = row2; row2 = tmp;
+ G_get_d_raster_row(fd, row2, row + 1);
+ }
+ else {
+ G_get_d_raster_row(fd, row1, row);
+ G_get_d_raster_row(fd, row2, row + 1);
+ }
+ cur_row = row;
+ }
- /* choose map window and set up conversion factors */
- D_set_cur_wind(MAP.name);
- G_get_set_window(&window);
- D_get_screen_window(&t, &b, &l, &r);
- screen_y = (t + b) / 2;
- screen_x = (l + r) / 2;
- D_do_conversions(&window, t, b, l, r);
+ if (G_is_d_null_value(&row1[col]) || G_is_d_null_value(&row1[col+1]) ||
+ G_is_d_null_value(&row2[col]) || G_is_d_null_value(&row2[col+1])) {
+ G_set_d_null_value(result, 1);
+ return 0;
+ }
- /* get a point from the mouse */
- R_get_location_with_pointer(&screen_x, &screen_y, &button);
+ *result = G_interp_bilinear(x, y,
+ row1[col], row1[col+1],
+ row2[col], row2[col+1]);
- /* exit if user hit left mouse button */
- if (button == 3) {
- D_set_cur_wind(ORIG.name);
- G_message(_("Use 'd.frame -e' to remove left over frames"));
- exit(EXIT_SUCCESS);
- }
+ return 1;
+}
- /* convert to (easting,northing) coordinates */
- cur_uy = D_d_to_u_row((double)screen_y);
- cur_ux = D_d_to_u_col((double)screen_x);
+int main(int argc, char **argv)
+{
+ struct GModule *module;
+ struct Option *map, *profile;
+ struct Flag *stored;
+ struct Cell_head window;
+ struct point *points = NULL;
+ int num_points, max_points = 0;
+ double length;
+ double t, b, l, r;
+ int fd;
+ int i;
+ double sx;
+ int last;
- if (cur_ux > window.east || cur_ux < window.west ||
- cur_uy > window.north || cur_uy < window.south) {
- D_set_cur_wind(STA.name);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
- D_use_color(D_translate_color("red"));
- DrawText(25, 1, 1, "OUTSIDE CURRENT WINDOW");
- R_flush();
- button = 1;
- }
- else {
- /* print "earth" coords. and category info. in status window */
- D_set_cur_wind(STA.name);
- What(old_mapname, old_mapset, window, cur_ux, cur_uy);
- }
+ /* Initialize the GIS calls */
+ G_gisinit(argv[0]);
- } while (button != 2);
+ /* Set description */
+ module = G_define_module();
+ module->keywords = _("display");
+ module->description = _("Plots profile of a transect.");
- /* display mouse-menu in mouse-menu window */
- D_set_cur_wind(MOU.name);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
- D_use_color(D_translate_color("red"));
- DrawText(25, 1, 1, "GRASS PROGRAM: profile");
- D_use_color(D_translate_color(DEFAULT_FG_COLOR));
- DrawText(15, 3, 1, "MOUSE | Left: Where am I?");
- DrawText(15, 4, 1, "BUTTON | Middle: Set SECOND point");
- DrawText(15, 5, 1, "MENU | Right: Quit this\n");
- R_flush();
+ /* set up command line */
+ map = G_define_standard_option(G_OPT_R_INPUT);
+ map->description = _("Raster map to be profiled");
- /* move graphics position to first point chosen */
- R_move_abs(screen_x, screen_y);
- cur_screen_x = screen_x;
- cur_screen_y = screen_y;
+ profile = G_define_option();
+ profile->key = "profile";
+ profile->type = TYPE_DOUBLE;
+ profile->required = YES;
+ profile->multiple = YES;
+ profile->key_desc = "east,north";
+ profile->description = _("Profile coordinate pairs");
- /* LOOP to get second point of line */
- do {
- /* choose map window and set up conversion factors */
- D_set_cur_wind(MAP.name);
- G_get_window(&window);
- D_get_screen_window(&t, &b, &l, &r);
- D_do_conversions(&window, t, b, l, r);
+ stored = G_define_flag();
+ stored->key = 'r';
+ stored->description = _("Use map's range recorded range");
- R_get_location_with_line(cur_screen_x, cur_screen_y,
- &screen_x, &screen_y, &button);
- uy = D_d_to_u_row((double)screen_y);
- ux = D_d_to_u_col((double)screen_x);
- if (ux > window.east || ux < window.west ||
- uy > window.north || uy < window.south) {
- D_set_cur_wind(STA.name);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
- D_use_color(D_translate_color("red"));
- DrawText(25, 1, 1, "OUTSIDE CURRENT WINDOW");
- button = 1;
- }
- else {
- if (button == 1) {
- /* print "earth" coords. and category info. in status window */
- D_set_cur_wind(STA.name);
- What(old_mapname, old_mapset, window, ux, uy);
- }
- else if (button == 2) {
- /* get profile data */
- InitProfile(&profile, window, cur_uy, cur_ux, uy, ux);
- if ((err =
- ExtractProfile(&profile, old_mapname,
- old_mapset)) == -1) {
- D_set_cur_wind(STA.name);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
- D_use_color(D_translate_color("red"));
- DrawText(25, 1, 1, "ERROR: end-point outside");
- DrawText(25, 2, 1, " of current window");
- }
- else if (err == -2)
- G_fatal_error(_("Error opening cell-file"));
- else if (err == -3)
- G_fatal_error(_("Error reading from cell-file"));
- else if (err == -4)
- G_fatal_error(_("Mysterious window inconsistancy error"));
- else {
- /* draw profile line on cell-file */
- black_and_white_line(screen_x, screen_y, cur_screen_x,
- cur_screen_y);
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
- /* select letter for current profile label */
- switch (CurrentWin) {
- case 0:
- ltr[0] = 'A';
- ltr[1] = 0;
- break;
- case 1:
- ltr[0] = 'B';
- ltr[1] = 0;
- break;
- case 2:
- ltr[0] = 'C';
- ltr[1] = 0;
- break;
- case 3:
- ltr[0] = 'D';
- ltr[1] = 0;
- break;
- default:
- ltr[0] = '?';
- ltr[1] = 0;
- break;
- }
+ mapname = map->answer;
- /* plot label in black */
- text_height = (int)(0.03 * (b - t));
- text_width = (int)(0.03 * (r - l));
- D_set_cur_wind(MAP.name);
- R_move_abs(screen_x, screen_y);
- if (screen_x <= cur_screen_x &&
- screen_y >= cur_screen_y)
- R_move_rel(-(text_width + 2), (text_height + 2));
- else if (screen_x < cur_screen_x &&
- screen_y <= cur_screen_y)
- R_move_rel(-(text_width + 2), 2);
- else if (screen_x > cur_screen_x)
- R_move_rel(3, 0);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- R_text_size(text_width, text_height);
- R_text(ltr);
- D_use_color(D_translate_color(DEFAULT_FG_COLOR));
+ fd = G_open_cell_old(mapname, "");
+ if (fd < 0)
+ G_fatal_error(_("Unable to open raster map <%s>"), mapname);
- /* plot label in white */
- R_move_abs(screen_x, screen_y);
- if (screen_x <= cur_screen_x &&
- screen_y >= cur_screen_y)
- R_move_rel(-(text_width + 2), (text_height + 2));
- else if (screen_x < cur_screen_x &&
- screen_y <= cur_screen_y)
- R_move_rel(-(text_width + 2), 2);
- else if (screen_x > cur_screen_x)
- R_move_rel(3, 0);
- R_move_rel(1, 1);
- R_text(ltr);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
+ if (stored->answer)
+ get_map_range();
+ else
+ get_region_range(fd);
- /*length = hypot(cur_ux - ux, cur_uy - uy); */
+ G_get_window(&window);
- /* tell user about profile being plotted */
- D_set_cur_wind(STA.name);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
- D_use_color(D_translate_color("red"));
- DrawText(25, 1, 1, "PLOTTING PROFILE");
+ num_points = 0;
+ length = 0;
+ for (i = 0; profile->answers[i]; i += 2) {
+ struct point *p;
+ double x, y;
- /* plot profile data in profile window */
- D_set_cur_wind(profiles[CurrentWin++].name);
- /* dump profile if requested */
- if (doplot)
- WriteProfile(old_mapname, old_mapset,
- plotfile->answer, ltr[0], &profile);
- PlotProfile(profile, ltr, min, max);
- if (CurrentWin > 3)
- CurrentWin = 0;
+ if (num_points >= max_points) {
+ max_points = num_points + 100;
+ points = G_realloc(points, max_points * sizeof(struct point));
+ }
- cur_screen_x = screen_x;
- cur_screen_y = screen_y;
- cur_ux = ux;
- cur_uy = uy;
- }
- }
- }
- R_flush();
- } while (button != 3 && button != 2);
+ p = &points[num_points];
- /* display mouse-menu in mouse-menu window */
- D_set_cur_wind(MOU.name);
- D_use_color(D_translate_color(DEFAULT_BG_COLOR));
- D_erase_window();
- D_use_color(D_translate_color("red"));
- DrawText(25, 1, 1, "GRASS PROGRAM: profile");
- D_use_color(D_translate_color(DEFAULT_FG_COLOR));
- DrawText(15, 3, 1, "MOUSE | Left: DO ANOTHER");
- DrawText(15, 4, 1, "BUTTON | Middle: CLEAR DISPLAY");
- DrawText(15, 5, 1, "MENU | Right: QUIT");
- R_flush();
+ G_scan_easting( profile->answers[i+0], &x, G_projection());
+ G_scan_northing(profile->answers[i+1], &y, G_projection());
- R_get_location_with_pointer(&screen_x, &screen_y, &button);
- if (button == 3) {
- D_set_cur_wind(ORIG.name);
- G_message(_("Use 'd.frame -e' to remove left over frames"));
- exit(EXIT_SUCCESS);
+ p->x = G_easting_to_col (x, &window);
+ p->y = G_northing_to_row(y, &window);
+
+ if (num_points > 0) {
+ const struct point *prev = &points[num_points-1];
+ double dx = fabs(p->x - prev->x);
+ double dy = fabs(p->y - prev->y);
+ double d = sqrt(dx * dx + dy * dy);
+ length += d;
+ p->d = length;
}
- else if (button == 2) {
- D_set_cur_wind(MAP.name);
- D_erase(DEFAULT_BG_COLOR);
- myDcell(d_mapname, d_mapset, 1);
- for (i = 0; i <= 3; i++) {
- D_set_cur_wind(profiles[i].name);
- D_erase(DEFAULT_BG_COLOR);
- }
- CurrentWin = 0;
- }
- else {
- G_free(profile.ptr);
- }
+
+ num_points++;
}
+ points[0].d = 0;
- exit(EXIT_SUCCESS);
-}
+ if (num_points < 2)
+ G_fatal_error(_("At least two points are required"));
-void myDcell(char *name, char *mapset, int overlay)
-{
- int fd, i, code;
- CELL *cell;
- struct Colors clr;
+ /* establish connection with graphics driver */
+ if (R_open_driver() != 0)
+ G_fatal_error(_("No graphics device selected"));
- D_setup(!overlay);
- D_set_overlay_mode(overlay);
+ D_setup2(1, 0, 1.05, -0.05, -0.15, 1.05);
- cell = G_allocate_c_raster_buf();
+ plot_axes();
- if ((fd = G_open_cell_old(name, mapset)) < 0)
- G_fatal_error(_("%s: Couldn't open raster <%s@%s>"),
- G_program_name(), name, mapset);
+ D_use_color(D_translate_color(DEFAULT_FG_COLOR));
- if (G_read_colors(name, mapset, &clr) < 0)
- G_fatal_error(_("%s: Couldn't read color table for <%s@%s>"),
- G_program_name(), name, mapset);
+ D_get_src(&t, &b, &l, &r);
+ t -= 0.1 * (t - b);
+ b += 0.1 * (t - b);
+ l += 0.1 * (r - l);
+ r -= 0.1 * (r - l);
- D_cell_draw_begin();
- for (i = 0; i >= 0;) {
- code = G_get_c_raster_row(fd, cell, i);
- if (code < 0)
- break;
- else if (code == 0) {
+ i = 0;
+ last = 0;
+ for (sx = 0; sx < 1; sx += D_get_d_to_u_xconv()) {
+ double d = length * (sx - l);
+ const struct point *p, *next;
+ double k, sy, x, y;
+ DCELL v;
+
+ for (;;) {
+ p = &points[i];
+ next = &points[i + 1];
+ k = (d - p->d) / (next->d - p->d);
+ if (k < 1)
+ break;
i++;
+ }
+
+ x = p->x * (1 - k) + next->x * k;
+ y = p->y * (1 - k) + next->y * k;
+
+ if (!get_cell(&v, fd, x, y)) {
+ last = 0;
continue;
}
- i = D_draw_cell(i, cell, &clr);
+
+ sy = (v - min) / (max - min);
+
+ if (last)
+ D_cont_abs(sx, sy);
+ else
+ D_move_abs(sx, sy);
+
+ last = 1;
}
- D_cell_draw_end();
- /* Only one cell, always set the name */
- D_set_cell_name(G_fully_qualified_name(name, mapset));
+ R_close_driver();
- G_close_cell(fd);
- G_free(cell);
+ exit(EXIT_SUCCESS);
}
-/* vim: set softtabstop=4 shiftwidth=4 expandtab: */
Deleted: grass/trunk/display/d.profile/profile.h
===================================================================
--- grass/trunk/display/d.profile/profile.h 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/profile.h 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,91 +0,0 @@
-#include <grass/gis.h>
-#include <grass/config.h>
-
-typedef struct _ucat
-{
- RASTER_MAP_TYPE type;
- union
- {
- CELL c;
- FCELL f;
- DCELL d;
- } val;
-} UCAT;
-
-typedef union _raster_ptr
-{
- void *v;
- CELL *c;
- FCELL *f;
- DCELL *d;
-} RASTER_PTR;
-
-typedef struct _raster_map_ptr
-{
- RASTER_MAP_TYPE type;
- RASTER_PTR data;
-} RASTER_MAP_PTR;
-
-struct windows
-{
- char *name;
- float bot, top, left, right;
-};
-
-struct ProfileNode
-{
- double north, east, dist;
- UCAT cat;
- struct ProfileNode *next;
-};
-
-struct Profile
-{
- struct Cell_head window;
- double n1, e1, n2, e2;
- struct ProfileNode *ptr;
- long int count;
- UCAT MinCat, MaxCat;
-};
-
-extern struct windows windows[];
-extern struct windows profiles[];
-
-#define MOU windows[0]
-#define STA windows[1]
-#define MAP windows[2]
-#define ORIG windows[3]
-
-/* DrawText.c */
-int DrawText(int, int, int, char *);
-
-/* DumpProfile.c */
-int WriteProfile(char *, char *, char *, char, struct Profile *);
-
-/* ExtractProf.c */
-int ExtractProfile(struct Profile *, char *, char *);
-
-/* InitProfile.c */
-int InitProfile(struct Profile *, struct Cell_head, double, double, double,
- double);
-/* PlotProfile.c */
-int PlotProfile(struct Profile, char *, int, int);
-
-/* Range.c */
-int WindowRange(char *, char *, long *, long *);
-int quick_range(char *, char *, long *, long *);
-int slow_range(char *, char *, long *, long *);
-
-/* What.c */
-int What(char *, char *, struct Cell_head, double, double);
-
-/* bnw_line.c */
-int black_and_white_line(int, int, int, int);
-
-/* show.c */
-int show_cat(int, char *, int, char *);
-int show_utm(double, double);
-int show_mouse(void);
-
-/* utils.c */
-int is_null_value(RASTER_MAP_PTR *, int);
Deleted: grass/trunk/display/d.profile/utils.c
===================================================================
--- grass/trunk/display/d.profile/utils.c 2008-08-26 15:43:43 UTC (rev 33094)
+++ grass/trunk/display/d.profile/utils.c 2008-08-26 17:25:48 UTC (rev 33095)
@@ -1,29 +0,0 @@
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "profile.h"
-
-int is_null_value(RASTER_MAP_PTR * ptr, int col)
-{
- if (ptr == NULL)
- G_fatal_error(_("%s: 'is_null_value()' got NULL pointer!"),
- G_program_name());
- if (col < 0)
- G_fatal_error(_("%s: 'is_null_value()' got negative column index"),
- G_program_name());
-
- switch (ptr->type) {
- case CELL_TYPE:
- return G_is_c_null_value(&ptr->data.c[col]);
- case FCELL_TYPE:
- return G_is_f_null_value(&ptr->data.f[col]);
- case DCELL_TYPE:
- return G_is_d_null_value(&ptr->data.d[col]);
- default:
- G_fatal_error(_("%s: 'is_null_value()' Unknown "
- "RASTER_MAP_TYPE '%d'"), G_program_name(), ptr->type);
- }
-
- return 0;
-}
-
-/* vim: set softtabstop=4 shiftwidth=4 expandtab: */
More information about the grass-commit
mailing list