From 6f670c8b86387ac9886d8b08971017d5b4c10ffb Mon Sep 17 00:00:00 2001
From: sesteves <sroesteves@gmail.com>
Date: Tue, 12 Jul 2016 00:18:38 +0100
Subject: [PATCH] fixed exception handling

---
 .../MultiLayerModel.java                      | 131 ++++++++----------
 1 file changed, 60 insertions(+), 71 deletions(-)

diff --git a/src/main/java/org/orekit/rugged/atmosphericrefraction/MultiLayerModel.java b/src/main/java/org/orekit/rugged/atmosphericrefraction/MultiLayerModel.java
index 48876237..d6ed85c3 100644
--- a/src/main/java/org/orekit/rugged/atmosphericrefraction/MultiLayerModel.java
+++ b/src/main/java/org/orekit/rugged/atmosphericrefraction/MultiLayerModel.java
@@ -16,6 +16,7 @@
  */
 package org.orekit.rugged.atmosphericrefraction;
 
+import com.sun.org.apache.xpath.internal.operations.Mult;
 import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.math3.util.FastMath;
 import org.orekit.bodies.OneAxisEllipsoid;
@@ -37,90 +38,78 @@ import java.util.*;
 public class MultiLayerModel implements AtmosphericRefraction {
 
     // maps altitude (lower bound) to refraction index
-    private static final Map<Double, Double> meanAtmosphericRefractions;
-
-    private static final Map<Double, ExtendedEllipsoid> atmosphericEllipsoids;
-
-    static {
-        Map<Double, Double> refractions = new TreeMap(Collections.reverseOrder());
-        refractions.put(-1000.00000000000, 1.00030600000);
-        refractions.put(0.00000000000, 1.00027800000);
-        refractions.put(1000.00000000000, 1.00025200000);
-        refractions.put(3000.00000000000, 1.00020600000);
-        refractions.put(5000.00000000000, 1.00016700000);
-        refractions.put(7000.00000000000, 1.00013400000);
-        refractions.put(9000.00000000000, 1.00010600000);
-        refractions.put(11000.00000000000, 1.00008300000);
-        refractions.put(14000.00000000000, 1.00005200000);
-        refractions.put(18000.00000000000, 1.00002800000);
-        refractions.put(23000.00000000000, 1.00001200000);
-        refractions.put(30000.00000000000, 1.00000400000);
-        refractions.put(40000.00000000000, 1.00000100000);
-        refractions.put(50000.00000000000, 1.00000000000);
-        refractions.put(100000.00000000000, 1.00000000000);
-        meanAtmosphericRefractions = Collections.unmodifiableMap(refractions);
-
-        Map<Double, ExtendedEllipsoid> ellipsoids = new HashMap<Double, ExtendedEllipsoid>();
-        try {
-            for (Double altitude : refractions.keySet()) {
-                OneAxisEllipsoid ellipsoid = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS + altitude,
-                        Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
-                ellipsoid = new ExtendedEllipsoid(ellipsoid.getEquatorialRadius(), ellipsoid.getFlattening(),
-                        ellipsoid.getBodyFrame());
-                ellipsoids.put(altitude, (ExtendedEllipsoid) ellipsoid);
-            }
-        } catch (OrekitException e) {
-            e.printStackTrace();
+    private static Map<Double, Double> meanAtmosphericRefractions;
+
+    private static Map<Double, ExtendedEllipsoid> atmosphericEllipsoids;
+
+    public MultiLayerModel() throws OrekitException {
+        Map<Double, Double> meanAtmosphericRefractions = new TreeMap(Collections.reverseOrder());
+        meanAtmosphericRefractions.put(-1000.00000000000, 1.00030600000);
+        meanAtmosphericRefractions.put(0.00000000000, 1.00027800000);
+        meanAtmosphericRefractions.put(1000.00000000000, 1.00025200000);
+        meanAtmosphericRefractions.put(3000.00000000000, 1.00020600000);
+        meanAtmosphericRefractions.put(5000.00000000000, 1.00016700000);
+        meanAtmosphericRefractions.put(7000.00000000000, 1.00013400000);
+        meanAtmosphericRefractions.put(9000.00000000000, 1.00010600000);
+        meanAtmosphericRefractions.put(11000.00000000000, 1.00008300000);
+        meanAtmosphericRefractions.put(14000.00000000000, 1.00005200000);
+        meanAtmosphericRefractions.put(18000.00000000000, 1.00002800000);
+        meanAtmosphericRefractions.put(23000.00000000000, 1.00001200000);
+        meanAtmosphericRefractions.put(30000.00000000000, 1.00000400000);
+        meanAtmosphericRefractions.put(40000.00000000000, 1.00000100000);
+        meanAtmosphericRefractions.put(50000.00000000000, 1.00000000000);
+        meanAtmosphericRefractions.put(100000.00000000000, 1.00000000000);
+
+        Map<Double, ExtendedEllipsoid> atmosphericEllipsoids = new HashMap<Double, ExtendedEllipsoid>();
+        for (Double altitude : meanAtmosphericRefractions.keySet()) {
+            OneAxisEllipsoid ellipsoid = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS + altitude,
+                    Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
+            ellipsoid = new ExtendedEllipsoid(ellipsoid.getEquatorialRadius(), ellipsoid.getFlattening(),
+                    ellipsoid.getBodyFrame());
+            atmosphericEllipsoids.put(altitude, (ExtendedEllipsoid) ellipsoid);
         }
-        atmosphericEllipsoids = Collections.unmodifiableMap(ellipsoids);
     }
 
     @Override
     public NormalizedGeodeticPoint getPointOnGround(Vector3D initialPos, Vector3D initialLos, Vector3D initialZenith,
-                                                double altitude, Tile tile) {
-        NormalizedGeodeticPoint newGeodeticPoint = null;
-        try {
-
-            Vector3D pos = initialPos;
-            Vector3D los = initialLos;
-            Vector3D zenith = initialZenith;
-            double theta1 = Vector3D.angle(los, zenith), theta2;
-            double previousRefractionIndex = -1;
-            NormalizedGeodeticPoint gp = null;
-            for (Map.Entry<Double, Double> entry : meanAtmosphericRefractions.entrySet()) {
-                if (pos.getZ() < entry.getKey()) {
-                    continue;
-                }
+                                                    double altitude, Tile tile) throws RuggedException {
+
+        Vector3D pos = initialPos;
+        Vector3D los = initialLos;
+        Vector3D zenith = initialZenith;
+        double theta1 = Vector3D.angle(los, zenith), theta2;
+        double previousRefractionIndex = -1;
+        NormalizedGeodeticPoint gp = null;
+        for (Map.Entry<Double, Double> entry : meanAtmosphericRefractions.entrySet()) {
+            if (pos.getZ() < entry.getKey()) {
+                continue;
+            }
 
-                if (previousRefractionIndex > 0) {
-                    theta2 = FastMath.asin(previousRefractionIndex * FastMath.sin(theta1) / entry.getValue());
+            if (previousRefractionIndex > 0) {
+                theta2 = FastMath.asin(previousRefractionIndex * FastMath.sin(theta1) / entry.getValue());
 
-                    // get los
-                    double a = FastMath.sqrt((1 - FastMath.pow(FastMath.cos(theta2), 2)) /
-                                             (1 - FastMath.pow(FastMath.cos(theta1), 2)));
-                    double b = a * FastMath.cos(theta1) - FastMath.cos(theta2);
-                    los = new Vector3D(a, los, b, zenith);
+                // get los
+                double a = FastMath.sqrt((1 - FastMath.pow(FastMath.cos(theta2), 2)) /
+                        (1 - FastMath.pow(FastMath.cos(theta1), 2)));
+                double b = a * FastMath.cos(theta1) - FastMath.cos(theta2);
+                los = new Vector3D(a, los, b, zenith);
 
-                    theta1 = theta2;
-                }
+                theta1 = theta2;
+            }
 
-                // get intersection point
-                ExtendedEllipsoid ellipsoid = atmosphericEllipsoids.get(entry.getKey());
-                gp = ellipsoid.pointOnGround(pos, los, 0.0);
-                pos = ellipsoid.transform(gp);
-                zenith = gp.getZenith();
+            // get intersection point
+            ExtendedEllipsoid ellipsoid = atmosphericEllipsoids.get(entry.getKey());
+            gp = ellipsoid.pointOnGround(pos, los, 0.0);
+            pos = ellipsoid.transform(gp);
+            zenith = gp.getZenith();
 
-                if (altitude > entry.getKey()) {
-                    break;
-                }
-                previousRefractionIndex = entry.getValue();
+            if (altitude > entry.getKey()) {
+                break;
             }
-
-            newGeodeticPoint = tile.cellIntersection(gp, los, 0, 0);
-        } catch (RuggedException e) {
-            e.printStackTrace();
+            previousRefractionIndex = entry.getValue();
         }
 
+        NormalizedGeodeticPoint newGeodeticPoint = tile.cellIntersection(gp, los, 0, 0);
         return newGeodeticPoint;
     }
 }
-- 
GitLab