]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGCoefficient.cpp
FG_HAVE_STD_INCLUDES -> SG_HAVE_STD_INCLUDES
[flightgear.git] / src / FDM / JSBSim / FGCoefficient.cpp
index a87a0ff31cc30d08480e1c2991f49527cdf4d03a..d29812e62587a43f56033e1680d98e04986e4282 100644 (file)
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  Module:       FGCoefficient.cpp
  Author:       Jon S. Berndt
@@ -40,27 +40,33 @@ HISTORY
 --------------------------------------------------------------------------------
 12/28/98   JSB   Created
 
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGCoefficient.h"
 #include "FGState.h"
 #include "FGFDMExec.h"
 
+#include <iomanip.h>
+
 static const char *IdSrc = "$Header$";
 static const char *IdHdr = "ID_COEFFICIENT";
 
-/*******************************************************************************
-************************************ CODE **************************************
-*******************************************************************************/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS IMPLEMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg)
 {
   int r, c, start, end, n;
   float ftrashcan;
   string multparms;
-
+  char nullstring[13] = "            ";
+  
+  bias =0.0;
+  gain = 1.0;
+  
   FDMExec     = fdex;
   State       = FDMExec->GetState();
   Table = 0;
@@ -72,7 +78,22 @@ FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg)
     AC_cfg->GetNextConfigLine();
     *AC_cfg >> description;
 
-    cout << "   " << name << endl;
+    char bolden[5];
+    char unbolden[5];
+
+    bolden[0] = 27;
+    bolden[1] = '[';
+    bolden[2] = '1';
+    bolden[3] = 'm';
+    bolden[4] = '\0';
+
+    unbolden[0] = 27;
+    unbolden[1] = '[';
+    unbolden[2] = '0';
+    unbolden[3] = 'm';
+    unbolden[4] = '\0';
+
+    cout << "   " << bolden << name << unbolden << endl;
     cout << "   " << description << endl;
     cout << "   " << method << endl;
 
@@ -150,19 +171,41 @@ FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg)
       Allocate(rows, columns);
 
       Table[0][0] = 0.0;
-      for (c=1;c<=columns;c++) {
+
+      // Read the table in -- it should be in matrix format with the row
+      // independents as the first column and the column independents in
+      // the first row.  The implication of this layout is that there should
+      // be no value in the upper left corner of the matrix e.g:
+      //      0  10  20 30 ...
+      // -5   1  2   3  4  ...
+      //  ...
+
+      for (r=0; r<=rows; r++) {
+        for (c=0; c <= columns; c++) {
+          if ( !((r == 0) && (c == 0)) ) {
+            *AC_cfg >> Table[r][c];
+          }
+        }
+      }   
+      
+      /* for (c=1;c<=columns;c++) {
         *AC_cfg >> Table[0][c];
         for (r=1;r<=rows;r++) {
           if ( c==1 ) *AC_cfg >> Table[r][0];
           else *AC_cfg >> ftrashcan;
           *AC_cfg >> Table[r][c];
         }
-      }
-
+      } */
+      
       for (r=0;r<=rows;r++) {
         cout << "      ";
         for (c=0;c<=columns;c++) {
-          cout << Table[r][c] << "     ";
+          if( ((r == 0) && (c == 0)) ) {
+             cout << nullstring;
+          } else {
+             cout.flags(ios::left);
+             cout << setw(12) << Table[r][c];
+          }
         }
         cout << endl;
       }
@@ -177,13 +220,13 @@ FGCoefficient::FGCoefficient(FGFDMExec* fdex, FGConfigFile* AC_cfg)
   }
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 FGCoefficient::~FGCoefficient(void) {
   DeAllocate();
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 bool FGCoefficient::DeAllocate(void)
 {
@@ -196,7 +239,7 @@ bool FGCoefficient::DeAllocate(void)
   return true;
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 bool FGCoefficient::Allocate(int r, int c)
 {
@@ -207,7 +250,7 @@ bool FGCoefficient::Allocate(int r, int c)
   return true;
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 float FGCoefficient::Value(float rVal, float cVal)
 {
@@ -219,7 +262,8 @@ float FGCoefficient::Value(float rVal, float cVal)
 
   for (r=1;r<=rows;r++) if (Table[r][0] >= rVal) break;
   for (c=1;c<=columns;c++) if (Table[0][c] >= cVal) break;
-
+  //cout << "Value(): rVal: " << rVal << " cVal: " << cVal << endl;
+  //cout << "Value(): r: " << r << " c: " << c << endl;
   c = c < 2 ? 2 : (c > columns ? columns : c);
   r = r < 2 ? 2 : (r > rows    ? rows    : r);
 
@@ -229,8 +273,10 @@ float FGCoefficient::Value(float rVal, float cVal)
   col1temp = rFactor*(Table[r][c-1] - Table[r-1][c-1]) + Table[r-1][c-1];
   col2temp = rFactor*(Table[r][c] - Table[r-1][c]) + Table[r-1][c];
 
-  SD = Value = col1temp + cFactor*(col2temp - col1temp);
-
+  Value = col1temp + cFactor*(col2temp - col1temp);
+  Value = (Value + bias)*gain;
+  SD = Value;
+  
   for (midx=0; midx < multipliers.size(); midx++) {
     Value *= State->GetParameter(multipliers[midx]);
   }
@@ -238,7 +284,7 @@ float FGCoefficient::Value(float rVal, float cVal)
   return Value;
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 float FGCoefficient::Value(float Val)
 {
@@ -260,7 +306,10 @@ float FGCoefficient::Value(float Val)
     Factor = 1.0;
   }
 
-  SD = Value = Factor*(Table[r][1] - Table[r-1][1]) + Table[r-1][1];
+  Value = Factor*(Table[r][1] - Table[r-1][1]) + Table[r-1][1];
+  Value = (Value + bias)*gain;
+  SD = Value;
+
   for (midx=0; midx < multipliers.size(); midx++) {
     Value *= State->GetParameter(multipliers[midx]);
 
@@ -269,14 +318,16 @@ float FGCoefficient::Value(float Val)
   return Value;
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 float FGCoefficient::Value(void)
 {
        float Value;
        unsigned midx;
 
-       SD = Value = StaticValue;
+       Value = StaticValue;
+  Value = (Value + bias)*gain;
+  SD = Value;
 
   for (midx=0; midx < multipliers.size(); midx++) {
     Value *= State->GetParameter(multipliers[midx]);
@@ -285,7 +336,7 @@ float FGCoefficient::Value(void)
   return Value;
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 float FGCoefficient::TotalValue()
 {
@@ -304,12 +355,12 @@ float FGCoefficient::TotalValue()
   return 0;
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 void FGCoefficient::DumpSD(void)
 {
   cout << "   " << name << ": " << SD << endl;
 }
 
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%