Index: ps/ps.map/get_scalebar.c
===================================================================
--- ps/ps.map/get_scalebar.c	(revision 31201)
+++ ps/ps.map/get_scalebar.c	(working copy)
@@ -40,6 +40,7 @@
    sb.x = PS.page_width/2.;
    sb.y = 2.;
    sb.bgcolor = 1; /* default is "on" [white|none] (TODO: multi-color) */
+   sb.scaleunits = 1; /* scale units e.g. meters to Kilometers */
 
 
     while (input(2, buf, help))
@@ -119,6 +120,26 @@
 		continue;
 	}
 
+        if (KEY("scaleunits"))
+	        {
+	    	
+            if (sscanf(data, "%lf", &sb.scaleunits) != 1 || sb.scaleunits <= 0. )
+	        {
+                       error(key, data, "illegal scaleunits request");
+	        }
+                else continue;
+        }
+
+	if (KEY("unitslabel"))
+	        {
+	        sscanf(data, "%s", &sb.unitslabel); 
+	        continue;
+	}
+
+	
+	     
+	 
+
 	error(key, data, "illegal request (scalebar)");
 	
      }
Index: ps/ps.map/description.html
===================================================================
--- ps/ps.map/description.html	(revision 31201)
+++ ps/ps.map/description.html	(working copy)
@@ -1031,6 +1031,8 @@
 	<B>numbers</B> #
 	<B>fontsize</B> font size
 	<B>background</B> [Y|n]
+	<B>scaleunits</B> scale units by this factor
+	<B>unitslabel</B> label for units
 	<B>end</B>
 </PRE>
 Draw one of two types of scale bar.
@@ -1050,8 +1052,8 @@
 <P>
 NOTE: The scalebar is centered on the location given.
 <P>
-This example draws a simple scalebar 1000 meters (for a metered database, like UTM) long,
-with tics every 200 meters, labeled every second tic. The scalebar is drawn 5 inches from the top and 4 inches from the left and is 0.25 inches high.
+This example draws a simple scalebar 1000 meters (for a metered database, like UTM) long, with tics every 200 meters, labeled every second tic. The scalebar is drawn 5 inches from the top and 4 inches from the left and is 0.25 inches high.
+Under the scalebar a label shows the name of the unit (Meters).
 <PRE>
 EXAMPLE:
 	<B>scalebar</B> s
@@ -1060,6 +1062,7 @@
 	<B>height</B> 0.25
 	<B>segment</B> 5
 	<B>numbers</B> 2
+	<B>unitslabel</B> meters
 	<B>end</B>
 </PRE>
 
Index: ps/ps.map/do_scalebar.c
===================================================================
--- ps/ps.map/do_scalebar.c	(revision 31201)
+++ ps/ps.map/do_scalebar.c	(working copy)
@@ -75,9 +75,12 @@
 
 	    /* do text */
 	    if (i == 0 || lab == sb.numbers) {
-		sprintf(num, "%s", nice_number((sb.length / sb.segment) * i));
-		text_box_path(x1, y2 + margin, CENTER, LOWER, num, sb.fontsize, 0);
-		if(sb.bgcolor) { /* TODO: take bg color, not just [white|none] */
+		sprintf(num, "%s",
+			nice_number(((sb.length / sb.segment) * i) /
+				    sb.scaleunits));
+		text_box_path(x1, y2 + margin, CENTER, LOWER, num, sb.fontsize,
+			      0);
+		if (sb.bgcolor) {	/* TODO: take bg color, not just [white|none] */
 		    set_rgb_color(WHITE);
 		    fprintf(PS.fp, "F ");
 		}
@@ -88,9 +91,10 @@
 
 	    if ((lab > 0 && i == seg - 1) || (sb.numbers == 1 && i == seg - 1)) {
 		/* special case for last label */
-		sprintf(num, "%s", nice_number(sb.length));
-		text_box_path(x2, y2 + margin, CENTER, LOWER, num, sb.fontsize, 0);
-		if(sb.bgcolor) {
+		sprintf(num, "%s", nice_number(sb.length / sb.scaleunits));
+		text_box_path(x2, y2 + margin, CENTER, LOWER, num, sb.fontsize,
+			      0);
+		if (sb.bgcolor) {
 		    set_rgb_color(WHITE);
 		    fprintf(PS.fp, "F ");
 		}
@@ -113,7 +117,7 @@
 
 	/* draw label */
 	text_box_path(x1, y1 + margin, CENTER, LOWER, "0", sb.fontsize, 0);
-	if(sb.bgcolor) {
+	if (sb.bgcolor) {
 	    set_rgb_color(WHITE);
 	    fprintf(PS.fp, "F ");
 	}
@@ -134,9 +138,9 @@
 	fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);
 
 	/* draw label */
-	sprintf(num, "%s", nice_number(sb.length));
+	sprintf(num, "%s", nice_number(sb.length / sb.scaleunits));
 	text_box_path(x1, y2 + margin, CENTER, LOWER, num, sb.fontsize, 0);
-	if(sb.bgcolor) {
+	if (sb.bgcolor) {
 	    set_rgb_color(WHITE);
 	    fprintf(PS.fp, "F ");
 	}
@@ -157,30 +161,51 @@
 
 	    /* do text */
 	    if (lab == sb.numbers) {
-		sprintf(num, "%s", nice_number((sb.length / sb.segment) * i));
+		sprintf(num, "%s",
+			nice_number((sb.length / sb.segment) * i /
+				    sb.scaleunits));
 
-		text_box_path(x1, y3 + margin, CENTER, LOWER, num, sb.fontsize, 0);
-		if(sb.bgcolor) {
-	    	    set_rgb_color(WHITE);
-	    	    fprintf(PS.fp, "F ");
+		text_box_path(x1, y3 + margin, CENTER, LOWER, num, sb.fontsize,
+			      0);
+		if (sb.bgcolor) {
+		    set_rgb_color(WHITE);
+		    fprintf(PS.fp, "F ");
 		}
 		set_rgb_color(BLACK);
 		fprintf(PS.fp, "TIB\n");
 		lab = 0;
 	    }
 
+
 	}
     }
 
+    sprintf(num, "%s", sb.unitslabel);
+    text_box_path(72.0 * (x + length / 2), 72.0 * (PS.page_height - sb.y),
+		  CENTER, UPPER, num, sb.fontsize, 0);
+    if (sb.bgcolor) {
+	set_rgb_color(WHITE);
+	fprintf(PS.fp, "F ");
+    }
+    set_rgb_color(BLACK);
+    fprintf(PS.fp, "TIB\n");
 
+
     return 0;
 }
 
 /* Make a nice number -- reduce to less than 3 decimal places */
-static char *nice_number(double val)
+static char *nice_number(double inval)
 {
     static char text[50];
 
+    /* If we're not going to have more than 3 decimal places, let's
+     * just go ahead and round to that many. This is so that values
+     * like 3.0000000092 are printed as "3" */
+
+    double val;
+    val = (double)((int)(inval * 1000.0 + 0.5)) / 1000.0;
+
     if (val == (int)val)
 	sprintf(text, "%.0f", val);
     else if ((val * 10.) == (int)(val * 10))
Index: ps/ps.map/decorate.h
===================================================================
--- ps/ps.map/decorate.h	(revision 31201)
+++ ps/ps.map/decorate.h	(working copy)
@@ -14,6 +14,8 @@
 	double width;
 	int fontsize;
 	int color, bgcolor;
+	double scaleunits;
+	char unitslabel[32];
 };
 
 #ifdef MAIN
