]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/atmosphere/FGMSIS.cpp
Sync with JSBSim cvs + Anders' patch to get it working with FlightGear.
[flightgear.git] / src / FDM / JSBSim / models / atmosphere / FGMSIS.cpp
index 2c86c6ddf04fd428548b59904b797b74f93560c3..390a11449709a7ee2502aeda5a5a1d56beb86cbe 100755 (executable)
@@ -58,15 +58,15 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGMSIS.h"
-#include "FGState.h"
-#include <math.h>          /* maths functions */
-#include <stdlib.h>        /* for malloc/free */
-#include <stdio.h>         /* for printf      */
+#include "models/FGAuxiliary.h"
+#include <cmath>          /* maths functions */
 #include <iostream>        // for cout, endl
 
+using namespace std;
+
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGMSIS.cpp,v 1.13 2010/02/25 05:21:36 jberndt Exp $";
 static const char *IdHdr = ID_MSIS;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -103,7 +103,6 @@ MSIS::MSIS(FGFDMExec* fdmex) : FGAtmosphere(fdmex)
 
 MSIS::~MSIS()
 {
-  unbind();
   Debug(1);
 }
 
@@ -137,7 +136,7 @@ bool MSIS::InitModel(void)
   pressure = &intPressure;
   density = &intDensity;
 
-  useExternal=false;
+  UseInternal();
 
   return true;
 }
@@ -149,6 +148,8 @@ bool MSIS::Run(void)
   if (FGModel::Run()) return true;
   if (FDMExec->Holding()) return false;
 
+  RunPreFunctions();
+
   //do temp, pressure, and density first
   if (!useExternal) {
     // get sea-level values
@@ -169,25 +170,19 @@ bool MSIS::Run(void)
     // get at-altitude values
     Calculate(Auxiliary->GetDayOfYear(),
               Auxiliary->GetSecondsInDay(),
-              Propagate->Geth(),
+              Propagate->GetAltitudeASL(),
               Propagate->GetLocation().GetLatitudeDeg(),
               Propagate->GetLocation().GetLongitudeDeg());
     intTemperature = output.t[1] * 1.8;
     intDensity     = output.d[5] * 1.940321;
     intPressure    = 1716.488 * intDensity * intTemperature;
-    soundspeed     = sqrt(2403.0832 * intTemperature);
     //cout << "T=" << intTemperature << " D=" << intDensity << " P=";
     //cout << intPressure << " a=" << soundspeed << endl;
   }
 
-  if (turbType != ttNone) {
-    Turbulence();
-    vWindNED += vTurbulence;
-  }
-
-  if (vWindNED(1) != 0.0) psiw = atan2( vWindNED(2), vWindNED(1) );
+  CalculateDerived();
 
-  if (psiw < 0) psiw += 2*M_PI;
+  RunPostFunctions();
 
   Debug(2);
 
@@ -331,7 +326,7 @@ double MSIS::dnet (double dd, double dm, double zhm, double xmm, double xm)
   double ylog;
   a  = zhm / (xmm-xm);
   if (!((dm>0) && (dd>0))) {
-    printf("dnet log error %e %e %e\n",dm,dd,xm);
+    cerr << "dnet log error " << dm << ' ' << dd << ' ' << xm << ' ' << endl;
     if ((dd==0) && (dm==0))
       dd=1;
     if (dm==0)
@@ -409,7 +404,7 @@ void MSIS::splint (double *xa, double *ya, double *y2a, int n, double x, double
   }
   h = xa[khi] - xa[klo];
   if (h==0.0)
-    printf("bad XA input to splint");
+    cerr << "bad XA input to splint" << endl;
   a = (xa[khi] - x)/h;
   b = (x - xa[klo])/h;
   yi = a * ya[klo] + b * ya[khi] + ((a*a*a - a) * y2a[klo] + (b*b*b - b) * y2a[khi]) * h * h/6.0;
@@ -431,9 +426,9 @@ void MSIS::spline (double *x, double *y, int n, double yp1, double ypn, double *
   double *u;
   double sig, p, qn, un;
   int i, k;
-  u=(double*)malloc(sizeof(double)*n);
+  u=new double[n];
   if (u==NULL) {
-    printf("Out Of Memory in spline - ERROR");
+    cerr << "Out Of Memory in spline - ERROR" << endl;
     return;
   }
   if (yp1>0.99E30) {
@@ -460,7 +455,7 @@ void MSIS::spline (double *x, double *y, int n, double yp1, double ypn, double *
   for (k=n-2;k>=0;k--)
     y2[k] = y2[k] * y2[k+1] + u[k];
 
-  free(u);
+  delete u;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -973,7 +968,7 @@ double MSIS::glob7s(double *p, struct nrlmsise_input *input,
   if (p[99]==0)
     p[99]=pset;
   if (p[99]!=pset) {
-    printf("Wrong parameter set for glob7s\n");
+    cerr << "Wrong parameter set for glob7s" << endl;
     return -1;
   }
   for (j=0;j<14;j++)
@@ -1256,7 +1251,7 @@ void MSIS::ghp7(struct nrlmsise_input *input, struct nrlmsise_flags *flags,
     if (sqrt(diff*diff)<test)
       return;
     if (l==ltest) {
-      printf("ERROR: ghp7 not converging for press %e, diff %e",press,diff);
+      cerr << "ERROR: ghp7 not converging for press " << press << ", diff " << diff << endl;
       return;
     }
     xm = output->d[5] / xn / 1.66E-24;
@@ -1644,14 +1639,14 @@ void MSIS::Debug(int from)
   }
   if (debug_lvl & 32) { // Turbulence
     if (first_pass && from == 2) {
-      cout << "vTurbulence(X), vTurbulence(Y), vTurbulence(Z), "
+      cout << "vTurbulenceNED(X), vTurbulenceNED(Y), vTurbulenceNED(Z), "
            << "vTurbulenceGrad(X), vTurbulenceGrad(Y), vTurbulenceGrad(Z), "
            << "vDirection(X), vDirection(Y), vDirection(Z), "
            << "Magnitude, "
            << "vTurbPQR(P), vTurbPQR(Q), vTurbPQR(R), " << endl;
     }
     if (from == 2) {
-      cout << vTurbulence << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl;
+      cout << vTurbulenceNED << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl;
     }
   }
   if (debug_lvl & 64) {