From 09cdc04e91e55d7b43b4a4dba4dcc1e9bbb51c2e Mon Sep 17 00:00:00 2001
From: Anders Gidenstam <anders@gidenstam.org>
Date: Sat, 22 Oct 2016 23:42:19 +0200
Subject: [PATCH] Fixed some FPE prone spots in the generic JSBSim
 hydrodynamics systems.

Signed-off-by: Anders Gidenstam <anders@gidenstam.org>
---
 .../Systems/hydrodynamic-planing-floats.xml    | 18 +++++++++++++++++-
 .../JSBSim/Systems/hydrodynamic-planing.xml    | 14 +++++++++++++-
 .../Generic/JSBSim/Systems/hydrodynamics.xml   |  7 +++++--
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/Aircraft/Generic/JSBSim/Systems/hydrodynamic-planing-floats.xml b/Aircraft/Generic/JSBSim/Systems/hydrodynamic-planing-floats.xml
index 78f7add41..aa95a48c2 100644
--- a/Aircraft/Generic/JSBSim/Systems/hydrodynamic-planing-floats.xml
+++ b/Aircraft/Generic/JSBSim/Systems/hydrodynamic-planing-floats.xml
@@ -3,7 +3,7 @@
 
   Model of hydrodynamic planing based on [Wagner:1933:POW] for JSBSim.
 
-    Copyright (C) 2015  Anders Gidenstam  (anders(at)gidenstam.org)
+    Copyright (C) 2015 - 2016  Anders Gidenstam  (anders(at)gidenstam.org)
 
     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
@@ -88,6 +88,10 @@
      <tan><property>hydro/floats/pitch-rad[0]</property></tan>
     </quotient>
    </function>
+   <clipto> <!-- We don't want to get +/-inf out of this function. -->
+    <min>-10000.0</min>
+    <max>10000.0</max>
+   </clipto>
   </fcs_function>
   <fcs_function name="hydro/planing-floats/afterbody-entry-point-x-ft[0]">
    <function>
@@ -103,6 +107,10 @@
      <tan><property>hydro/floats/pitch-rad[0]</property></tan>
     </quotient>
    </function>
+   <clipto> <!-- We don't want to get +/-inf out of this function. -->
+    <min>-10000.0</min>
+    <max>10000.0</max>
+   </clipto>
   </fcs_function>
 
   <fcs_function name="hydro/planing-floats/forebody-entry-point-x-ft[1]">
@@ -119,6 +127,10 @@
      <tan><property>hydro/floats/pitch-rad[1]</property></tan>
     </quotient>
    </function>
+   <clipto> <!-- We don't want to get +/-inf out of this function. -->
+    <min>-10000.0</min>
+    <max>10000.0</max>
+   </clipto>
   </fcs_function>
   <fcs_function name="hydro/planing-floats/afterbody-entry-point-x-ft[1]">
    <function>
@@ -134,6 +146,10 @@
      <tan><property>hydro/floats/pitch-rad[1]</property></tan>
     </quotient>
    </function>
+   <clipto> <!-- We don't want to get +/-inf out of this function. -->
+    <min>-10000.0</min>
+    <max>10000.0</max>
+   </clipto>
   </fcs_function>
 
   <fcs_function name="hydro/planing-floats/forebody-wetted-keel-ft[0]">
diff --git a/Aircraft/Generic/JSBSim/Systems/hydrodynamic-planing.xml b/Aircraft/Generic/JSBSim/Systems/hydrodynamic-planing.xml
index bcc0e12a5..ccac056e3 100644
--- a/Aircraft/Generic/JSBSim/Systems/hydrodynamic-planing.xml
+++ b/Aircraft/Generic/JSBSim/Systems/hydrodynamic-planing.xml
@@ -3,7 +3,7 @@
 
   Model of hydrodynamic planing based on [Wagner:1933:POW] for JSBSim.
 
-    Copyright (C) 2015  Anders Gidenstam  (anders(at)gidenstam.org)
+    Copyright (C) 2015 - 2016  Anders Gidenstam  (anders(at)gidenstam.org)
 
     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
@@ -77,6 +77,10 @@
      <tan><property>hydro/hull/pitch-rad</property></tan>
     </quotient>
    </function>
+   <clipto> <!-- We don't want to get +/-inf out of this function. -->
+    <min>-10000.0</min>
+    <max>10000.0</max>
+   </clipto>
   </fcs_function>
   <fcs_function name="hydro/planing/middlebody-entry-point-x-ft">
    <function>
@@ -92,6 +96,10 @@
      <tan><property>hydro/hull/pitch-rad</property></tan>
     </quotient>
    </function>
+   <clipto> <!-- We don't want to get +/-inf out of this function. -->
+    <min>-10000.0</min>
+    <max>10000.0</max>
+   </clipto>
   </fcs_function>
   <fcs_function name="hydro/planing/afterbody-entry-point-x-ft">
    <function>
@@ -107,6 +115,10 @@
      <tan><property>hydro/hull/pitch-rad</property></tan>
     </quotient>
    </function>
+   <clipto> <!-- We don't want to get +/-inf out of this function. -->
+    <min>-10000.0</min>
+    <max>10000.0</max>
+   </clipto>
   </fcs_function>
 
   <fcs_function name="hydro/planing/forebody-wetted-keel-ft">
diff --git a/Aircraft/Generic/JSBSim/Systems/hydrodynamics.xml b/Aircraft/Generic/JSBSim/Systems/hydrodynamics.xml
index fdd510236..8c28f2299 100644
--- a/Aircraft/Generic/JSBSim/Systems/hydrodynamics.xml
+++ b/Aircraft/Generic/JSBSim/Systems/hydrodynamics.xml
@@ -3,7 +3,7 @@
 
   Hydrodynamics section for JSBSim.
 
-    Copyright (C) 2008 - 2015  Anders Gidenstam  (anders(at)gidenstam.org)
+    Copyright (C) 2008 - 2016  Anders Gidenstam  (anders(at)gidenstam.org)
 
     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
@@ -364,7 +364,10 @@
      <!-- Mix in hull-angular-offset-rad to simplify uses below. -->
      <quotient>
       <property>hydro/environment/wave/hull-angular-offset-rad</property>
-      <property>simulation/sim-time-sec</property>
+      <max> <!-- To avoid divison by 0 at time 0. -->
+       <value>0.1</value>
+       <property>simulation/sim-time-sec</property>
+      </max>
      </quotient>
     </sum>
    </function>