]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/flight_control/FGFilter.cpp
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / flight_control / FGFilter.cpp
index 6122e15d0c9408e4973288555d66efc6ce9ce814..54739e837236b6c08f3d2c56c8eb349367dda039 100644 (file)
@@ -38,10 +38,17 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGFilter.h"
+#include "input_output/FGXMLElement.h"
+#include "input_output/FGPropertyManager.h"
+
+#include <iostream>
+#include <string>
+
+using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGFilter.cpp,v 1.15 2009/10/24 22:59:30 jberndt Exp $";
 static const char *IdHdr = ID_FILTER;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -54,9 +61,10 @@ FGFilter::FGFilter(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
   DynamicFilter = false;
 
   C[1] = C[2] = C[3] = C[4] = C[5] = C[6] = 0.0;
-  for (int i=0; i<7; i++) {
+  for (int i=1; i<7; i++) {
     PropertySign[i] = 1.0;
     PropertyNode[i] = 0L;
+    ReadFilterCoefficients(element, i);
   }
 
   if      (Type == "LAG_FILTER")          FilterType = eLag        ;
@@ -66,13 +74,6 @@ FGFilter::FGFilter(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
   else if (Type == "INTEGRATOR")          FilterType = eIntegrator ;
   else                                    FilterType = eUnknown    ;
 
-  ReadFilterCoefficients(element, 1);
-  ReadFilterCoefficients(element, 2);
-  ReadFilterCoefficients(element, 3);
-  ReadFilterCoefficients(element, 4);
-  ReadFilterCoefficients(element, 5);
-  ReadFilterCoefficients(element, 6);
-
   if (element->FindElement("trigger")) {
     Trigger =  PropertyManager->GetNode(element->FindElementValue("trigger"));
   }
@@ -97,13 +98,13 @@ FGFilter::~FGFilter()
 
 void FGFilter::ReadFilterCoefficients(Element* element, int index)
 {
-  char buf[3];
-  sprintf(buf, "c%d", index);
-  string coefficient = string(buf);
-  string property_string="";
-
+  // index is known to be 1-7. 
+  // A stringstream would be overkill, but also trying to avoid sprintf
+  string coefficient = "c0";
+  coefficient[1] += index;
+  
   if ( element->FindElement(coefficient) ) {
-    property_string = element->FindElementValue(coefficient);
+    string property_string = element->FindElementValue(coefficient);
     if (!is_number(property_string)) { // property
       if (property_string[0] == '-') {
        PropertySign[index] = -1.0;
@@ -258,7 +259,7 @@ void FGFilter::Debug(int from)
 
   if (debug_lvl & 1) { // Standard console startup message output
     if (from == 0) { // Constructor
-      cout << "      INPUT: " << InputNodes[0]->getName() << endl;
+      cout << "      INPUT: " << InputNodes[0]->GetName() << endl;
         switch (FilterType) {
         case eLag:
           if (PropertySign[1] < 0.0) sgn="-";