altoslib: Add 'gauss' units for magnetic field strength
authorKeith Packard <keithp@keithp.com>
Thu, 13 Feb 2020 03:59:19 +0000 (19:59 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 13 Feb 2020 04:53:51 +0000 (20:53 -0800)
Compute in gauss, but display in nT (G * 100000)

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosConvert.java
altoslib/AltosGauss.java [new file with mode: 0644]
altoslib/Makefile.am

index ce1b8f7f14f7733a29722e6eedd62090733ed63f..89f36a6c4a373f66a90dc2612ae6e39e66d92506 100644 (file)
@@ -473,7 +473,7 @@ public class AltosConvert {
 
        public static AltosPyroName pyro_name = new AltosPyroName();
 
-       public static AltosUnits magnetic_field = null;
+       public static AltosUnits magnetic_field = new AltosGauss();
 
        public static String show_gs(String format, double a) {
                a = meters_to_g(a);
diff --git a/altoslib/AltosGauss.java b/altoslib/AltosGauss.java
new file mode 100644 (file)
index 0000000..0eed3fa
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2020 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.altoslib_13;
+
+import java.io.*;
+
+public class AltosGauss extends AltosUnits {
+
+       public double value(double v, boolean imperial_units) {
+               return v;
+       }
+
+       public double inverse(double v, boolean imperial_units) {
+               return v;
+       }
+
+       public String show_units(boolean imperial_units) {
+               return "G";
+       }
+
+       public String say_units(boolean imperial_units) {
+               return "gauss";
+       }
+
+       public int show_fraction(int width, boolean imperial_units) {
+               return width - 1;
+       }
+
+       public AltosGauss() {
+               range_metric = new AltosUnitsRange[1];
+
+               range_metric[0] = new AltosUnitsRange(0, "γ", "nano tesla") {
+                               double value(double v) {
+                                       return v * 100000;
+                               }
+                               int show_fraction(int width) {
+                                       return width / 9;
+                               }
+                               int say_fraction() {
+                                       return 0;
+                               }
+                       };
+
+               range_imperial = range_metric;
+       }
+}
index 59a3b2ca89ab3e09a39887108fecc74d2208b9b5..b7d30051f87d351da8c061e129a6b6a9a9e4e2d4 100644 (file)
@@ -70,6 +70,7 @@ altoslib_JAVA = \
        AltosGPS.java \
        AltosGPSTimeValue.java \
        AltosGPSSat.java \
+       AltosGauss.java \
        AltosGreatCircle.java \
        AltosHexfile.java \
        AltosHexsym.java \