From 451ebabe95902b38f7732ef4025dc5029577e6bf Mon Sep 17 00:00:00 2001
From: david <david>
Date: Sat, 19 Jan 2002 18:26:30 +0000
Subject: [PATCH] Fix use of properties for fuel-tank levels.

---
 src/FDM/JSBSim.cxx  | 22 +++++++++++++++++-----
 src/FDM/LaRCsim.cxx |  4 ++--
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx
index 42eec349a..da4bd24f4 100644
--- a/src/FDM/JSBSim.cxx
+++ b/src/FDM/JSBSim.cxx
@@ -123,6 +123,14 @@ FGJSBsim::FGJSBsim( double dt )
         
     
     init_gear();
+
+				// Set initial fuel levels if provided.
+    for (int i = 0; i < Propulsion->GetNumTanks(); i++) {
+      SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
+      if (node->getChild("level-gal_us", 0, false) != 0)
+	Propulsion->GetTank(i)
+	  ->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
+    }
     
     fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd());
     fgSetDouble("/fdm/trim/throttle",   FCS->GetThrottleCmd(0));
@@ -327,9 +335,10 @@ bool FGJSBsim::copy_to_JSBsim() {
 //                  << get_V_down_airmass() );
 
     for (i = 0; i < Propulsion->GetNumTanks(); i++) {
+      SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
       FGTank * tank = Propulsion->GetTank(i);
-      tank->SetContents(fgGetNode("consumables/fuel/tank", i, true)
-			->getDoubleValue());
+      tank->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
+//       tank->SetContents(node->getDoubleValue("level-lb"));
     }
 
     return true;
@@ -455,9 +464,12 @@ bool FGJSBsim::copy_from_JSBsim() {
     }
 
 				// Copy the fuel levels from JSBSim.
-    for (i = 0; i < Propulsion->GetNumTanks(); i++)
-      fgGetNode("consumables/fuel/tank", i, true)
-	->setDoubleValue(Propulsion->GetTank(i)->GetContents());
+    for (i = 0; i < Propulsion->GetNumTanks(); i++) {
+      SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
+      double contents = Propulsion->GetTank(i)->GetContents();
+      node->setDoubleValue("level-gal_us", contents/6.6);
+//       node->setDoubleValue("level-lb", contents);
+    }
 
     update_gear();
     
diff --git a/src/FDM/LaRCsim.cxx b/src/FDM/LaRCsim.cxx
index d76287819..7d11ce73c 100644
--- a/src/FDM/LaRCsim.cxx
+++ b/src/FDM/LaRCsim.cxx
@@ -120,11 +120,11 @@ void FGLaRCsim::update( int multiloop ) {
 	fgSetDouble("/engines/engine/cranking", eng.getCrankingFlag());
 
         //Assume we are using both tanks equally for now
-	fgSetDouble("/consumables/fuel/tank[0]",
+	fgSetDouble("/consumables/fuel/tank[0]/level-gal_us",
 		    fgGetDouble("/consumables/fuel/tank[0]")
 		    - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
 		    * get_delta_t());
-	fgSetDouble("/consumables/fuel/tank[1]",
+	fgSetDouble("/consumables/fuel/tank[1]/level-gal_us",
 		    fgGetDouble("/consumables/fuel/tank[1]")
 		    - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
 		    * get_delta_t());