[GRASS-SVN] r33273 -
grass/branches/develbranch_6/display/d.thematic.area
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Sep 5 06:45:27 EDT 2008
Author: mlennert
Date: 2008-09-05 06:45:27 -0400 (Fri, 05 Sep 2008)
New Revision: 33273
Modified:
grass/branches/develbranch_6/display/d.thematic.area/main.c
Log:
bug fix and code cleanup
(backport of 33246 and 33272 from trunk)
Modified: grass/branches/develbranch_6/display/d.thematic.area/main.c
===================================================================
--- grass/branches/develbranch_6/display/d.thematic.area/main.c 2008-09-05 10:21:18 UTC (rev 33272)
+++ grass/branches/develbranch_6/display/d.thematic.area/main.c 2008-09-05 10:45:27 UTC (rev 33273)
@@ -67,8 +67,7 @@
dbCatValArray cvarr;
struct Cell_head window;
BOUND_BOX box;
- double overlap, *breakpoints, min = 0, max = 0, *data = NULL, class_info =
- 0.0;
+ double overlap, *breakpoints, *data = NULL, class_info = 0.0;
struct GASTATS stats;
FILE *fd;
@@ -108,7 +107,7 @@
"std;standard deviations;"
"qua;quantiles;"
"equ;equiprobable (normal distribution);");
-/*currently disabled because of bugs "dis;discontinuities");*/
+ /*currently disabled because of bugs "dis;discontinuities"); */
nbclass_opt = G_define_option();
nbclass_opt->key = "nbclasses";
@@ -263,6 +262,28 @@
val.d));
}
+ /*Get the sorted data */
+ ret = db_CatValArray_sort_by_value(&cvarr);
+ if (ret == DB_FAILED)
+ G_fatal_error("Could not sort array of values..");
+
+
+ data = (double *)G_malloc((nrec) * sizeof(double));
+ for (i = 0; i < nrec; i++)
+ data[i] = 0.0;
+
+ ctype = cvarr.ctype;
+ if (ctype == DB_C_TYPE_INT) {
+ for (i = 0; i < nrec; i++)
+ data[i] = cvarr.value[i].val.i;
+ }
+ else {
+ for (i = 0; i < nrec; i++)
+ data[i] = cvarr.value[i].val.d;
+ }
+ db_CatValArray_sort(&cvarr);
+
+
/*Get the list of relevant cats if where option is given */
if (where_opt->answer) {
ncat = db_select_int(driver, fi->table, fi->key, where_opt->answer,
@@ -323,38 +344,7 @@
if (algo_opt->answer && nbclass_opt->answer) {
- ret = db_CatValArray_sort_by_value(&cvarr);
- if (ret == DB_FAILED)
- G_fatal_error("Could not sort array of values..");
-
- data = (double *)G_malloc((nrec) * sizeof(double));
- for (i = 0; i < nrec; i++)
- data[i] = 0.0;
-
- ctype = cvarr.ctype;
- if (ctype == DB_C_TYPE_INT) {
- for (i = 0; i < nrec; i++)
- data[i] = cvarr.value[i].val.i;
- }
- else {
- for (i = 0; i < nrec; i++)
- data[i] = cvarr.value[i].val.d;
- }
-
-
- /* min and max are needed later for the legend */
- if (cvarr.ctype == DB_C_TYPE_INT) {
- min = cvarr.value[0].val.i;
- max = cvarr.value[cvarr.n_values - 1].val.i;
- }
- else {
- min = cvarr.value[0].val.d;
- max = cvarr.value[cvarr.n_values - 1].val.d;
- }
-
- db_CatValArray_sort(&cvarr);
-
nclass = atoi(nbclass_opt->answer);
nbreaks = nclass - 1; /* we need one less classbreaks (min and
* max exluded) than classes */
@@ -456,7 +446,7 @@
frequencies[i] = 0.0;
class_frequencies(data, nrec, nbreaks, breakpoints, frequencies);
- /*Get basic statistics about the data*/
+ /*Get basic statistics about the data */
basic_stats(data, nrec, &stats);
if (legend_flag->answer) {
@@ -484,8 +474,8 @@
}
fprintf(stdout, "%f|%f|%i|%d:%d:%d\n",
- stats.min, breakpoints[0], frequencies[0], colors[0].r, colors[0].g,
- colors[0].b);
+ stats.min, breakpoints[0], frequencies[0], colors[0].r,
+ colors[0].g, colors[0].b);
for (i = 1; i < nbreaks; i++) {
fprintf(stdout, "%f|%f|%i|%d:%d:%d\n",
@@ -506,7 +496,7 @@
fprintf(fd, "symbol basic/box %i 5 %i black %d:%d:%d\n", boxsize,
ypos, colors[0].r, colors[0].g, colors[0].b);
fprintf(fd, "move 8 %f \n", ypos - textsize / 2.5);
- fprintf(fd, "text %f - %f | %i\n", min, breakpoints[0],
+ fprintf(fd, "text %f - %f | %i\n", stats.min, breakpoints[0],
frequencies[0]);
for (i = 1; i < nbreaks; i++) {
ypos = 10 + i * 6;
@@ -521,8 +511,8 @@
ypos, colors[nbreaks].r, colors[nbreaks].g,
colors[nbreaks].b);
fprintf(fd, "move 8 %f\n", ypos - textsize / 2.5);
- fprintf(fd, "text %f - %f | %i\n", breakpoints[nbreaks - 1], max,
- frequencies[nbreaks]);
+ fprintf(fd, "text %f - %f | %i\n", breakpoints[nbreaks - 1],
+ stats.max, frequencies[nbreaks]);
fclose(fd);
}
More information about the grass-commit
mailing list