From 507c15cbe5d80562daa2e9067eb998139ce89f4e Mon Sep 17 00:00:00 2001
From: Luc Maisonobe <luc@orekit.org>
Date: Fri, 6 Feb 2015 16:44:44 +0100
Subject: [PATCH] Added ellipsoid dump.

---
 .../java/org/orekit/rugged/errors/Dump.java   | 22 +++++++++++++++++--
 .../org/orekit/rugged/errors/DumpManager.java | 10 +++++++++
 .../rugged/utils/ExtendedEllipsoid.java       | 13 +++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/orekit/rugged/errors/Dump.java b/src/main/java/org/orekit/rugged/errors/Dump.java
index 39b99308..cd4aa850 100644
--- a/src/main/java/org/orekit/rugged/errors/Dump.java
+++ b/src/main/java/org/orekit/rugged/errors/Dump.java
@@ -25,6 +25,7 @@ import java.util.TimeZone;
 
 import org.apache.commons.math3.util.OpenIntToDoubleHashMap;
 import org.orekit.rugged.raster.Tile;
+import org.orekit.rugged.utils.ExtendedEllipsoid;
 
 /**
  * Dump data class.
@@ -38,12 +39,16 @@ class Dump {
     /** Tiles map. */
     private final List<DumpedTileData> tiles;
 
+    /** Flag for dumped ellipsoid. */
+    private boolean ellipsoidDumped;
+
     /** Simple constructor.
      * @param writer writer to the dump file
      */
     public Dump(final PrintWriter writer) {
-        this.writer = writer;
-        this.tiles  = new ArrayList<DumpedTileData>();
+        this.writer          = writer;
+        this.tiles           = new ArrayList<DumpedTileData>();
+        this.ellipsoidDumped = false;
         dumpHeader();
     }
 
@@ -69,6 +74,19 @@ class Dump {
         getTileData(tile).setElevation(latitudeIndex, longitudeIndex, elevation);
     }
 
+    /** Dump ellipsoid data.
+     * @param ellipsoid ellipsoid to dump
+     */
+    public void dumpEllipsoid(final ExtendedEllipsoid ellipsoid) {
+        if (!ellipsoidDumped) {
+            writer.format(Locale.US,
+                          "ellipsoid: ae = %22.15e f = %22.15e frame = %s%n",
+                          ellipsoid.getA(), ellipsoid.getFlattening(),
+                          ellipsoid.getBodyFrame().getName());            
+            ellipsoidDumped = true;
+        }
+    }
+
     /** Get tile data.
      * @param tile tile to which the cell belongs
      * @return index of the tile
diff --git a/src/main/java/org/orekit/rugged/errors/DumpManager.java b/src/main/java/org/orekit/rugged/errors/DumpManager.java
index 03610f7b..7e49ea7d 100644
--- a/src/main/java/org/orekit/rugged/errors/DumpManager.java
+++ b/src/main/java/org/orekit/rugged/errors/DumpManager.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.PrintWriter;
 
 import org.orekit.rugged.raster.Tile;
+import org.orekit.rugged.utils.ExtendedEllipsoid;
 
 /**
  * Class managing debug dumps.
@@ -95,4 +96,13 @@ public class DumpManager {
         }
     }
 
+    /** Dump ellipsoid data.
+     * @param ellipsoid ellipsoid to dump
+     */
+    public static void dumpEllipsoid(final ExtendedEllipsoid ellipsoid) {
+        if (isActive()) {
+            DUMP.get().dumpEllipsoid(ellipsoid);
+        }
+    }
+
 }
diff --git a/src/main/java/org/orekit/rugged/utils/ExtendedEllipsoid.java b/src/main/java/org/orekit/rugged/utils/ExtendedEllipsoid.java
index f37744c0..3ead84ed 100644
--- a/src/main/java/org/orekit/rugged/utils/ExtendedEllipsoid.java
+++ b/src/main/java/org/orekit/rugged/utils/ExtendedEllipsoid.java
@@ -23,6 +23,7 @@ import org.orekit.bodies.GeodeticPoint;
 import org.orekit.bodies.OneAxisEllipsoid;
 import org.orekit.errors.OrekitException;
 import org.orekit.frames.Frame;
+import org.orekit.rugged.errors.DumpManager;
 import org.orekit.rugged.errors.RuggedException;
 import org.orekit.rugged.errors.RuggedMessages;
 import org.orekit.time.AbsoluteDate;
@@ -70,6 +71,8 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid {
                                     final double latitude, final Vector3D closeReference)
         throws RuggedException {
 
+        DumpManager.dumpEllipsoid(this);
+
         // find apex of iso-latitude cone, somewhere along polar axis
         final GeodeticPoint groundPoint = new GeodeticPoint(latitude, 0, 0);
         final Vector3D gpCartesian = transform(groundPoint);
@@ -139,6 +142,8 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid {
     public Vector3D pointAtLongitude(final Vector3D position, final Vector3D los, final double longitude)
         throws RuggedException {
 
+        DumpManager.dumpEllipsoid(this);
+
         // normal to meridian
         final Vector3D normal = new Vector3D(-FastMath.sin(longitude), FastMath.cos(longitude), 0);
         final double d = Vector3D.dotProduct(los, normal);
@@ -164,6 +169,7 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid {
                                                  final double centralLongitude)
         throws RuggedException {
         try {
+            DumpManager.dumpEllipsoid(this);
             final GeodeticPoint gp =
                     getIntersectionPoint(new Line(position, new Vector3D(1, position, 1e6, los), 1.0e-12),
                                          position, getBodyFrame(), null);
@@ -188,6 +194,8 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid {
         throws RuggedException {
         try {
 
+            DumpManager.dumpEllipsoid(this);
+
             // point on line closest to origin
             final double   los2   = los.getNormSq();
             final double   dot    = Vector3D.dotProduct(position, los);
@@ -239,6 +247,8 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid {
      */
     public Vector3D convertLos(final GeodeticPoint point, final Vector3D los) {
 
+        DumpManager.dumpEllipsoid(this);
+
         // Cartesian coordinates of the topocentric frame origin
         final Vector3D p3D = transform(point);
 
@@ -272,6 +282,8 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid {
         throws RuggedException {
         try {
 
+            DumpManager.dumpEllipsoid(this);
+
             // switch to geodetic coordinates using primary point as reference
             final GeodeticPoint point = transform(primary, getBodyFrame(), null);
             final Vector3D      los   = secondary.subtract(primary);
@@ -296,6 +308,7 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid {
     public NormalizedGeodeticPoint transform(final Vector3D point, final Frame frame, final AbsoluteDate date,
                                              final double centralLongitude)
         throws OrekitException {
+        DumpManager.dumpEllipsoid(this);
         final GeodeticPoint gp = transform(point, frame, date);
         return new NormalizedGeodeticPoint(gp.getLatitude(), gp.getLongitude(), gp.getAltitude(),
                                            centralLongitude);
-- 
GitLab