Index: trunk/Ohana/src/opihi/cmd.data/grid.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/grid.c	(revision 20936)
+++ trunk/Ohana/src/opihi/cmd.data/grid.c	(revision 26258)
@@ -1,9 +1,38 @@
 # include "data.h"
+
+int SetGridScales (double *major, double *minor, double range) {
+
+  double lrange, factor, mantis, fmantis, power;
+
+  lrange = log10(MAX(fabs(range), 1e-30));
+  factor = (int) (lrange);
+  if (lrange < 0) { factor -= 1; }
+  mantis = lrange - factor;
+  power = pow(10.0, factor);
+  fmantis = pow(10.0, mantis);
+  if ((fmantis >= 1.0) && (fmantis <=  2.0)) {
+    *major = 0.5 * power;
+    *minor = 0.1 * power;
+  }
+  if ((fmantis > 2.0) && (fmantis <=  4.0)) {
+    *major = 1.0 * power;
+    *minor = 0.2 * power;
+  }
+  if ((fmantis > 4.0) && (fmantis <=  6.0)) {
+    *major = 1.0 * power;
+    *minor = 0.5 * power;
+  }
+  if ((fmantis > 6.0) && (fmantis <=  10.0)) {
+    *major = 2.0 * power;
+    *minor = 0.5 * power;
+  }
+  return TRUE;
+}
 
 int grid (int argc, char **argv) {
   
+  double range, major, minor, first, next;
   int j, kapa, N, MinorTick, MajorTick;
   Vector Xvec, Yvec;
-  double range, lrange, factor, mantis, fmantis, power, major, minor, first, next;
   Graphdata graphmode;
 
@@ -28,26 +57,5 @@
   major = minor = 1;
   range = graphmode.xmax - graphmode.xmin;
-  lrange = log10(MAX(fabs(range), 1e-30));
-  factor = (int) (lrange);
-  if (lrange < 0) { factor -= 1; }
-  mantis = lrange - factor;
-  power = pow(10.0, factor);
-  fmantis = pow(10.0, mantis);
-  if ((fmantis >= 1.0) && (fmantis <=  2.0)) {
-    major = 0.5 * power;
-    minor = 0.1 * power;
-  }
-  if ((fmantis > 2.0) && (fmantis <=  4.0)) {
-    major = 1.0 * power;
-    minor = 0.2 * power;
-  }
-  if ((fmantis > 4.0) && (fmantis <=  6.0)) {
-    major = 1.0 * power;
-    minor = 0.5 * power;
-  }
-  if ((fmantis > 6.0) && (fmantis <=  10.0)) {
-    major = 2.0 * power;
-    minor = 0.5 * power;
-  }
+  SetGridScales (&major, &minor, range);
   if (graphmode.xmin > 0)
     first = minor + minor*((int)(graphmode.xmin/minor));
@@ -108,26 +116,5 @@
 
   range = graphmode.ymax - graphmode.ymin;
-  lrange = log10(MAX(fabs(range), 1e-30));
-  factor = (int) (lrange);
-  if (lrange < 0) { factor -= 1; }
-  mantis = lrange - factor;
-  power = pow(10.0, factor);
-  fmantis = pow(10.0, mantis);
-  if ((fmantis >= 1.0) && (fmantis <=  2.0)) {
-    major = 0.5 * power;
-    minor = 0.1 * power;
-  }
-  if ((fmantis > 2.0) && (fmantis <=  4.0)) {
-    major = 1.0 * power;
-    minor = 0.2 * power;
-  }
-  if ((fmantis > 4.0) && (fmantis <=  6.0)) {
-    major = 1.0 * power;
-    minor = 0.5 * power;
-  }
-  if ((fmantis > 6.0) && (fmantis <=  10.0)) {
-    major = 2.0 * power;
-    minor = 0.5 * power;
-  }
+  SetGridScales (&major, &minor, range);
   if (graphmode.ymin > 0)
     first = minor + minor*((int)(graphmode.ymin/minor));
