|
@@ -15,13 +15,9 @@
|
|
|
#include <string.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <stdio.h>
|
|
|
-
|
|
|
#include <grass/gis.h>
|
|
|
#include <grass/raster.h>
|
|
|
|
|
|
-#define PRECISION 30
|
|
|
-#define THRESHOLD .0000000000000000000000000000005 /* .5 * 10 ^(-30) */
|
|
|
-
|
|
|
static void write_rules(FILE *, struct _Color_Rule_ *, DCELL, DCELL);
|
|
|
static void write_new_colors(FILE *, struct Colors *);
|
|
|
static void write_old_colors(FILE *, struct Colors *);
|
|
@@ -128,7 +124,7 @@ static void write_new_colors(FILE * fd, struct Colors *colors)
|
|
|
fprintf(fd, "%% %s %s\n", str1, str2);
|
|
|
|
|
|
if (colors->shift) {
|
|
|
- sprintf(str2, "%.10f", (double)colors->shift);
|
|
|
+ sprintf(str2, "%.15g", (double)colors->shift);
|
|
|
G_trim_decimal(str2);
|
|
|
fprintf(fd, "shift:%s\n", str2);
|
|
|
}
|
|
@@ -175,7 +171,7 @@ static void write_rules(FILE * fd, struct _Color_Rule_ *crules, DCELL dmin,
|
|
|
if (rule->low.value == dmin)
|
|
|
format_min(str, (double)rule->low.value);
|
|
|
else {
|
|
|
- sprintf(str, "%.10f", (double)rule->low.value);
|
|
|
+ sprintf(str, "%.15g", (double)rule->low.value);
|
|
|
G_trim_decimal(str);
|
|
|
}
|
|
|
fprintf(fd, "%s:%d", str, (int)rule->low.red);
|
|
@@ -186,7 +182,7 @@ static void write_rules(FILE * fd, struct _Color_Rule_ *crules, DCELL dmin,
|
|
|
if (rule->high.value == dmax)
|
|
|
format_max(str, (double)rule->high.value);
|
|
|
else {
|
|
|
- sprintf(str, "%.10f", (double)rule->high.value);
|
|
|
+ sprintf(str, "%.15g", (double)rule->high.value);
|
|
|
G_trim_decimal(str);
|
|
|
}
|
|
|
fprintf(fd, " %s:%d", str, (int)rule->high.red);
|
|
@@ -243,28 +239,28 @@ static void forced_write_old_colors(FILE * fd, struct Colors *colors)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
static void format_min(char *str, double dval)
|
|
|
{
|
|
|
double dtmp;
|
|
|
|
|
|
- sprintf(str, "%.*f", PRECISION, dval);
|
|
|
+ sprintf(str, "%.15g", dval);
|
|
|
G_trim_decimal(str);
|
|
|
sscanf(str, "%lf", &dtmp);
|
|
|
- if (dtmp != dval) { /* if no zeros after decimal point were trimmed */
|
|
|
- sprintf(str, "%.*f", PRECISION, dval - THRESHOLD);
|
|
|
- /* because precision is probably higher than PRECISION */
|
|
|
+ if (dtmp != dval) { /* if no zeros after decimal point were trimmed */
|
|
|
+ sprintf(str, "%.15g", dval - GRASS_EPSILON);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
static void format_max(char *str, double dval)
|
|
|
{
|
|
|
double dtmp;
|
|
|
|
|
|
- sprintf(str, "%.*f", PRECISION, dval);
|
|
|
+ sprintf(str, "%.15g", dval);
|
|
|
G_trim_decimal(str);
|
|
|
sscanf(str, "%lf", &dtmp);
|
|
|
- if (dtmp != dval) { /* if no zeros after decimal point were trimmed */
|
|
|
- sprintf(str, "%.*f", PRECISION, dval + THRESHOLD);
|
|
|
- /* because precision is probably higher than PRECISION */
|
|
|
+ if (dtmp != dval) { /* if no zeros after decimal point were trimmed */
|
|
|
+ sprintf(str, "%.15g", dval + GRASS_EPSILON);
|
|
|
}
|
|
|
}
|