]> 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 e3197404d2a131c3c6f5373a47cd9553591e94f5..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;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -148,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
@@ -168,7 +170,7 @@ 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;
@@ -180,6 +182,8 @@ bool MSIS::Run(void)
 
   CalculateDerived();
 
+  RunPostFunctions();
+
   Debug(2);
 
   return false;
@@ -322,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)
@@ -400,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;
@@ -422,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) {
@@ -451,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;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -964,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++)
@@ -1247,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;