From bc31bdbbbbd97f08bbcb77aea34b60de9fa9fb1f Mon Sep 17 00:00:00 2001
From: Torsten Dreyer <Torsten@t3r.de>
Date: Thu, 12 Aug 2010 13:03:26 +0200
Subject: [PATCH 1/3] use simgear::strutils::rpad() instead of strncpy()

---
 src/Instrumentation/navradio.cxx | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/Instrumentation/navradio.cxx b/src/Instrumentation/navradio.cxx
index d10076278..0970cae5a 100644
--- a/src/Instrumentation/navradio.cxx
+++ b/src/Instrumentation/navradio.cxx
@@ -37,6 +37,7 @@
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/structure/exception.hxx>
 #include <simgear/math/interpolater.hxx>
+#include <simgear/misc/strutils.hxx>
 
 #include <Navaids/navrecord.hxx>
 
@@ -878,12 +879,12 @@ void FGNavRadio::search()
   }
   
   _navaid = nav;
-  char identBuffer[5] = "    ";
+  string identBuffer(4, ' ');
   if (nav) {
     _dme = globals->get_dmelist()->findByFreq(freq, pos);
     
     nav_id_node->setStringValue(nav->get_ident());
-    strncpy(identBuffer, nav->ident().c_str(), 5);
+    identBuffer =  simgear::strutils::rpad( nav->ident(), 4, ' ' );
     
     effective_range = adjustNavRange(nav->get_elev_ft(), pos.getElevationM(), nav->get_range());
     loc_node->setBoolValue(nav->type() != FGPositioned::VOR);

From 71fbacc6dc5afe0eda851c9b1a42d73a3ed463db Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Sat, 14 Aug 2010 10:23:13 +0100
Subject: [PATCH 2/3] Thorsten Brehm: GPWS: Fixed permanent blocking of lower
 prio warnings Only block callouts which were actually issued to the pilot.
 When multiple callouts trigger at the same time, allow lower prio warnings to
 be issued once the higher prio ones are resolved. => Gear/flap warnings are
 now working reliably (no longer blocked permanently when altitude callouts
 are enabled).

---
 src/Instrumentation/mk_viii.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Instrumentation/mk_viii.cxx b/src/Instrumentation/mk_viii.cxx
index 55f0208b5..12f3ef050 100755
--- a/src/Instrumentation/mk_viii.cxx
+++ b/src/Instrumentation/mk_viii.cxx
@@ -2956,7 +2956,7 @@ MK_VIII::AlertHandler::update ()
 
   // set new state
 
-  old_alerts = alerts;
+  old_alerts = voice_alerts;
   repeated_alerts = 0;
   altitude_callout_voice = NULL;
 }

From 63b3f802ec9412b47c089d7c82f740a6c41f3e3e Mon Sep 17 00:00:00 2001
From: Erik Hofman <erik@ehofman.com>
Date: Sat, 14 Aug 2010 14:09:58 +0200
Subject: [PATCH 3/3] sync again

---
 .../JSBSim/input_output/FGPropertyManager.cpp | 22 +++++------
 src/FDM/JSBSim/math/FGColumnVector3.cpp       |  7 +---
 src/FDM/JSBSim/models/FGAtmosphere.cpp        |  6 ++-
 src/FDM/JSBSim/models/FGFCS.cpp               | 14 +++----
 src/FDM/JSBSim/models/FGMassBalance.cpp       |  6 ++-
 src/FDM/JSBSim/models/FGMassBalance.h         | 39 +++++++++++++------
 src/FDM/JSBSim/models/FGPropagate.cpp         | 18 +++------
 7 files changed, 63 insertions(+), 49 deletions(-)

diff --git a/src/FDM/JSBSim/input_output/FGPropertyManager.cpp b/src/FDM/JSBSim/input_output/FGPropertyManager.cpp
index 6e62fef03..11e566965 100755
--- a/src/FDM/JSBSim/input_output/FGPropertyManager.cpp
+++ b/src/FDM/JSBSim/input_output/FGPropertyManager.cpp
@@ -74,7 +74,7 @@ FGPropertyManager::GetNode (const string &path, bool create)
 {
   SGPropertyNode* node=this->getNode(path.c_str(), create);
   if (node == 0 && !suppress_warning) {
-    cout << "FGPropertyManager::GetNode() No node found for " << path << endl;
+    cerr << "FGPropertyManager::GetNode() No node found for " << path << endl;
   }
   return (FGPropertyManager*)node;
 }
@@ -256,8 +256,8 @@ void FGPropertyManager::SetArchivable (const string &name, bool state )
 {
   SGPropertyNode * node = getNode(name.c_str());
   if (node == 0)
-    cout <<
-           "Attempt to set archive flag for non-existant property "
+    cerr <<
+           "Attempt to set archive flag for non-existent property "
            << name << endl;
   else
     node->setAttribute(SGPropertyNode::ARCHIVE, state);
@@ -269,7 +269,7 @@ void FGPropertyManager::SetReadable (const string &name, bool state )
 {
   SGPropertyNode * node = getNode(name.c_str());
   if (node == 0)
-    cout <<
+    cerr <<
            "Attempt to set read flag for non-existant property "
            << name << endl;
   else
@@ -282,7 +282,7 @@ void FGPropertyManager::SetWritable (const string &name, bool state )
 {
   SGPropertyNode * node = getNode(name.c_str());
   if (node == 0)
-    cout <<
+    cerr <<
            "Attempt to set write flag for non-existant property "
            << name << endl;
   else
@@ -294,7 +294,7 @@ void FGPropertyManager::SetWritable (const string &name, bool state )
 void FGPropertyManager::Untie (const string &name)
 {
   if (!untie(name.c_str()))
-    cout << "Failed to untie property " << name << endl;
+    cerr << "Failed to untie property " << name << endl;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -302,7 +302,7 @@ void FGPropertyManager::Untie (const string &name)
 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
 {
   if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
   else if (debug_lvl & 0x20)
     cout << name << endl;
 }
@@ -313,7 +313,7 @@ void FGPropertyManager::Tie (const string &name, int *pointer,
                                           bool useDefault )
 {
   if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
   else if (debug_lvl & 0x20)
     cout << name << endl;
 }
@@ -324,7 +324,7 @@ void FGPropertyManager::Tie (const string &name, long *pointer,
                                           bool useDefault )
 {
   if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
   else if (debug_lvl & 0x20)
     cout << name << endl;
 }
@@ -335,7 +335,7 @@ void FGPropertyManager::Tie (const string &name, float *pointer,
                                           bool useDefault )
 {
   if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
   else if (debug_lvl & 0x20)
     cout << name << endl;
 }
@@ -345,7 +345,7 @@ void FGPropertyManager::Tie (const string &name, float *pointer,
 void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault)
 {
   if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
   else if (debug_lvl & 0x20)
     cout << name << endl;
 }
diff --git a/src/FDM/JSBSim/math/FGColumnVector3.cpp b/src/FDM/JSBSim/math/FGColumnVector3.cpp
index 1e41cd193..5b91dcdb6 100644
--- a/src/FDM/JSBSim/math/FGColumnVector3.cpp
+++ b/src/FDM/JSBSim/math/FGColumnVector3.cpp
@@ -47,7 +47,7 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGColumnVector3.cpp,v 1.12 2010/06/30 03:13:40 jberndt Exp $";
+static const char *IdSrc = "$Id: FGColumnVector3.cpp,v 1.13 2010/08/08 00:19:21 jberndt Exp $";
 static const char *IdHdr = ID_COLUMNVECTOR3;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -110,10 +110,7 @@ FGColumnVector3& FGColumnVector3::operator/=(const double scalar)
 
 double FGColumnVector3::Magnitude(void) const
 {
-  if (data[0] == 0.0 && data[1] == 0.0 && data[2] == 0.0)
-    return 0.0;
-  else
-    return sqrt( data[0]*data[0] +  data[1]*data[1] +  data[2]*data[2] );
+  return sqrt( data[0]*data[0] +  data[1]*data[1] +  data[2]*data[2] );
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/FDM/JSBSim/models/FGAtmosphere.cpp b/src/FDM/JSBSim/models/FGAtmosphere.cpp
index 601658922..2db1c65d9 100644
--- a/src/FDM/JSBSim/models/FGAtmosphere.cpp
+++ b/src/FDM/JSBSim/models/FGAtmosphere.cpp
@@ -61,7 +61,7 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGAtmosphere.cpp,v 1.33 2010/02/25 05:21:36 jberndt Exp $";
+static const char *IdSrc = "$Id: FGAtmosphere.cpp,v 1.35 2010/08/11 11:51:33 jberndt Exp $";
 static const char *IdHdr = ID_ATMOSPHERE;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -277,7 +277,9 @@ void FGAtmosphere::Calculate(double altitude)
 void FGAtmosphere::CalculateDerived(void)
 {
   T_dev = (*temperature) - GetTemperature(h);
-  density_altitude = h + T_dev * 66.7;
+
+  if (T_dev == 0.0) density_altitude = h;
+  else              density_altitude = 518.4/0.00357 * (1.0 - pow(GetDensityRatio(),0.235));
 
   if (turbType != ttNone) Turbulence();
 
diff --git a/src/FDM/JSBSim/models/FGFCS.cpp b/src/FDM/JSBSim/models/FGFCS.cpp
index f5bbba07d..4d71ca97d 100644
--- a/src/FDM/JSBSim/models/FGFCS.cpp
+++ b/src/FDM/JSBSim/models/FGFCS.cpp
@@ -63,7 +63,7 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGFCS.cpp,v 1.68 2010/03/18 13:21:24 jberndt Exp $";
+static const char *IdSrc = "$Id: FGFCS.cpp,v 1.69 2010/08/10 12:39:07 jberndt Exp $";
 static const char *IdHdr = ID_FCS;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -705,18 +705,18 @@ string FGFCS::FindSystemFullPathname(const string& sysfilename)
     system_filename.append(".xml");
   }
 
-  system_file.open(string(fullpath + system_filename).c_str());
+  system_file.open(string(localpath + system_filename).c_str());
   if ( !system_file.is_open()) {
-    system_file.open(string(localpath + system_filename).c_str());
+    system_file.open(string(fullpath + system_filename).c_str());
       if ( !system_file.is_open()) {
         cerr << " Could not open system file: " << system_filename << " in path "
              << fullpath << " or " << localpath << endl;
         return string("");
       } else {
-        return string(localpath + system_filename);
+        return string(fullpath + system_filename);
       }
   }
-  return string(fullpath + system_filename);
+  return string(localpath + system_filename);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -736,9 +736,9 @@ ifstream* FGFCS::FindSystemFile(const string& sysfilename)
     system_filename.append(".xml");
   }
 
-  system_file->open(string(fullpath + system_filename).c_str());
+  system_file->open(string(localpath + system_filename).c_str());
   if ( !system_file->is_open()) {
-    system_file->open(string(localpath + system_filename).c_str());
+    system_file->open(string(fullpath + system_filename).c_str());
       if ( !system_file->is_open()) {
         cerr << " Could not open system file: " << system_filename << " in path "
              << fullpath << " or " << localpath << endl;
diff --git a/src/FDM/JSBSim/models/FGMassBalance.cpp b/src/FDM/JSBSim/models/FGMassBalance.cpp
index 24727547c..9e485c1a6 100644
--- a/src/FDM/JSBSim/models/FGMassBalance.cpp
+++ b/src/FDM/JSBSim/models/FGMassBalance.cpp
@@ -51,7 +51,7 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGMassBalance.cpp,v 1.31 2010/02/19 00:30:00 jberndt Exp $";
+static const char *IdSrc = "$Id: FGMassBalance.cpp,v 1.32 2010/08/12 04:07:11 jberndt Exp $";
 static const char *IdHdr = ID_MASSBALANCE;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -280,6 +280,10 @@ void FGMassBalance::AddPointMass(Element* el)
       pm->SetPointMassShapeType(PointMass::esSphere);
       pm->SetRadius(radius);
       pm->CalculateShapeInertia();
+    } else if (shape == "ball") {
+      pm->SetPointMassShapeType(PointMass::esBall);
+      pm->SetRadius(radius);
+      pm->CalculateShapeInertia();
     } else {
     }
   }
diff --git a/src/FDM/JSBSim/models/FGMassBalance.h b/src/FDM/JSBSim/models/FGMassBalance.h
index c49fe2904..be461a1e8 100644
--- a/src/FDM/JSBSim/models/FGMassBalance.h
+++ b/src/FDM/JSBSim/models/FGMassBalance.h
@@ -49,7 +49,7 @@ INCLUDES
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.20 2010/02/04 13:09:26 jberndt Exp $"
+#define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.21 2010/08/12 04:07:11 jberndt Exp $"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 FORWARD DECLARATIONSS
@@ -65,7 +65,11 @@ CLASS DOCUMENTATION
 
 /** Models weight, balance and moment of inertia information.  Maintains a vector
     of point masses. Sums the contribution of all, and provides this to FGPropagate.
-    Loads the \<mass_balance> section of the aircraft configuration file.
+    Loads the \<mass_balance> section of the aircraft configuration file. There
+    can be any number of <pointmasses>. Each can also have a shape which - if
+    present - causes an associated moment of inertia to be calculated based on
+    the shape. Note that a cylinder is solid, a tube is hollow, a ball is solid
+    and a sphere is hollow.
 
     <h3>Configuration File Format:</h3>
 @code
@@ -77,20 +81,24 @@ CLASS DOCUMENTATION
         <ixz unit="{SLUG*FT2 | KG*M2}"> {number} </ixz>
         <iyz unit="{SLUG*FT2 | KG*M2}"> {number} </iyz>
         <emptywt unit="{LBS | KG"> {number} </emptywt>
-        <location name="CG" unit="{IN | M}">
+        <location name="CG" unit="{IN | FT | M}">
             <x> {number} </x>
             <y> {number} </y>
             <z> {number} </z>
         </location>
-        <pointmass name="{string}">
+        [<pointmass name="{string}">
+            <form shape="{tube | cylinder | sphere | ball}">
+               <radius unit="{IN | FT | M}"> {number} </radius>
+               <length unit="{IN | FT | M}"> {number} </length>
+            </form> 
             <weight unit="{LBS | KG}"> {number} </weight>
-            <location name="POINTMASS" unit="{IN | M}">
+            <location name="{string}" unit="{IN | FT | M}">
                 <x> {number} </x>
                 <y> {number} </y>
                 <z> {number} </z>
             </location>
         </pointmass>
-        ... other point masses ...
+        ... other point masses ...]
     </mass_balance>
 @endcode
   */
@@ -197,21 +205,30 @@ private:
     void CalculateShapeInertia(void) {
       switch(eShapeType) {
         case esTube:
-          mPMInertia(1,1) = (Weight/(32.16))*Radius*Radius; // mr^2
-          mPMInertia(2,2) = (Weight/(32.16*12))*(6*Radius*Radius + Length*Length);
+          mPMInertia(1,1) = (Weight/(slugtolb))*Radius*Radius; // mr^2
+          mPMInertia(2,2) = (Weight/(slugtolb*12))*(6*Radius*Radius + Length*Length);
           mPMInertia(3,3) = mPMInertia(2,2);
           break;
         case esCylinder:
-          mPMInertia(1,1) = (Weight/(32.16*2))*Radius*Radius; // 0.5*mr^2
-          mPMInertia(2,2) = (Weight/(32.16*12))*(3*Radius*Radius + Length*Length);
+          mPMInertia(1,1) = (Weight/(slugtolb*2))*Radius*Radius; // 0.5*mr^2
+          mPMInertia(2,2) = (Weight/(slugtolb*12))*(3*Radius*Radius + Length*Length);
           mPMInertia(3,3) = mPMInertia(2,2);
           break;
+        case esSphere:
+          mPMInertia(1,1) = (Weight/(slugtolb*3))*Radius*Radius*2; // (2mr^2)/3
+          mPMInertia(2,2) = mPMInertia(1,1);
+          mPMInertia(3,3) = mPMInertia(1,1);
+        case esBall:
+          mPMInertia(1,1) = (Weight/(slugtolb*5))*Radius*Radius*2; // (2mr^2)/5
+          mPMInertia(2,2) = mPMInertia(1,1);
+          mPMInertia(3,3) = mPMInertia(1,1);
+          break;
         default:
           break;
       }
     }
 
-    enum esShape {esUnspecified, esTube, esCylinder, esSphere} eShapeType;
+    enum esShape {esUnspecified, esTube, esCylinder, esSphere, esBall} eShapeType;
     FGColumnVector3 Location;
     double Weight; /// Weight in pounds.
     double Radius; /// Radius in feet.
diff --git a/src/FDM/JSBSim/models/FGPropagate.cpp b/src/FDM/JSBSim/models/FGPropagate.cpp
index 9c7543c48..ebb83211b 100644
--- a/src/FDM/JSBSim/models/FGPropagate.cpp
+++ b/src/FDM/JSBSim/models/FGPropagate.cpp
@@ -71,7 +71,7 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGPropagate.cpp,v 1.59 2010/07/30 11:50:01 jberndt Exp $";
+static const char *IdSrc = "$Id: FGPropagate.cpp,v 1.60 2010/08/12 19:11:22 andgi Exp $";
 static const char *IdHdr = ID_PROPAGATE;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -259,8 +259,6 @@ Inertial.
 
 bool FGPropagate::Run(void)
 {
-static int ctr;
-
   if (FGModel::Run()) return true;  // Fast return if we have nothing to do ...
   if (FDMExec->Holding()) return false;
 
@@ -498,11 +496,11 @@ void FGPropagate::ResolveFrictionForces(double dt)
   // If no gears are in contact with the ground then return
   if (!n) return;
 
-  double *a = new double[n*n]; // Will contain J*M^-1*J^T
-  double *eta = new double[n];
-  double *lambda = new double[n];
-  double *lambdaMin = new double[n];
-  double *lambdaMax = new double[n];
+  vector<double> a(n*n); // Will contain J*M^-1*J^T
+  vector<double> eta(n);
+  vector<double> lambda(n);
+  vector<double> lambdaMin(n);
+  vector<double> lambdaMax(n);
 
   // Initializes the Lagrange multipliers
   i = 0;
@@ -519,8 +517,6 @@ void FGPropagate::ResolveFrictionForces(double dt)
     // First compute the ground velocity below the aircraft center of gravity
     FGLocation contact;
     FGColumnVector3 normal, cvel;
-    double t = FDMExec->GetSimTime();
-    double height = FDMExec->GetGroundCallback()->GetAGLevel(t, VState.vLocation, contact, normal, cvel);
 
     // Instruct the algorithm to zero out the relative movement between the
     // aircraft and the ground.
@@ -587,8 +583,6 @@ void FGPropagate::ResolveFrictionForces(double dt)
     (*it)->value = lambda[i++];
 
   GroundReactions->UpdateForcesAndMoments();
-
-  delete a, eta, lambda, lambdaMin, lambdaMax;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%