Nov 13, 2008 at 12:56am UTC
I am writing a program to out put data in order to make graphs. We must compute all values that we arent given in the program. We also have to use smaller functions as a part of a small condensed main program.
My issue occurs when I compute a set of values. Inside the smaller program, they calculate fine and come out to the right values. But when I check them again back inside the main program they are jumbled and do not equal the same thing. The values are fairly close, they just dont match up with the correct variable.
My output is:
AR = 7.46914
rho = 1.225
sigma = 1
a_o = 0.102459
vstall = 23.6769
vmax = 76.5125
h = 0meters
AR = 3.11446e-317
rho = 7.46914
sigma = 76.5125
a_o = 1.225
vstall = 0.102459
vmax = 23.6769
AR = 7.46914
rho = 1.00645
sigma = 0.821594
a_o = 0.102459
vstall = 23.6769
vmax = 76.5125
h = 2000meters
AR = 3.11446e-317
rho = 7.46914
sigma = 76.5125
a_o = 1.00645
vstall = 0.102459
vmax = 23.6769
AR = 7.46914
rho = 0.819066
sigma = 0.668625
a_o = 0.102459
vstall = 23.6769
vmax = 76.5125
h = 4000meters
AR = 3.11446e-317
rho = 7.46914
sigma = 76.5125
a_o = 0.819066
vstall = 0.102459
vmax = 23.6769
My main program is:
#include <iostream>
#include <fstream>
#include <cmath>
#include "inputoutput.hpp"
#include "performancecalc.hpp"
#include "aspectratio.hpp"
#include "standardatmosphere.hpp"
#include "clvsalpha.hpp"
#include "velocity.hpp"
using namespace std;
int main()
{
double W, S, b, e, C_Do, alpha_Tconst, a, T_sl, d_sl, go, R, x1, Y1, x2, y2, C_lmax, pi, alpha_Lo, P_Aactual, np;
fileout.open ( "assn5output.m" );
input( "aircraftspecs.dat", W, S, b, e, C_Do, alpha_Tconst, a, T_sl, d_sl, go, R, x1, Y1, x2, y2, C_lmax, pi, alpha_Lo, P_Aactual, np );
/*cout << W << endl
<< S << endl
<< b << endl
<< e << endl
<< C_Do << endl
<< alpha_Tconst << endl
<< a << endl
<< T_sl << endl
<< d_sl << endl
<< go << endl
<< R << endl
<< x1 << endl
<< Y1 << endl
<< x2 << endl
<< y2 << endl
<< C_lmax << endl
<< pi << endl
<< alpha_Lo << endl
<< P_Aactual << endl
<< np << endl;*/
double alt, h, P_A;
for ( alt = 0; alt <= 2; alt++ )
{
h = alt * 2000;
P_A = P_Aactual;
double AR, rho, a_o, vstall, vmax, sigma;
double rho_o;
calculations( b, S, d_sl, T_sl, go, a, R, h, Y1, y2, x1, x2, P_A, C_Do, W, C_lmax, AR, rho, a_o, vstall, vmax, sigma, rho_o );
cout << "h =" << " " << h << "meters" << endl
<< "AR =" << " " << AR << endl
<< "rho =" << " " << rho << endl
<< "sigma =" << " " << sigma << endl
<< "a_o =" << " " << a_o << endl
<< "vstall =" << " " << vstall << endl
<< "vmax =" << " " << vmax << endl;
double v;
for ( v = vstall; v <= vmax; v++ )
{
//cout << vstall << " " << vmax << endl;
double D, T_R, C_D, LD, alpha, C_L, L, alpha_T, a_new, C_Lold, tol, P_Amax, P_Rmax;
PERFORMANCE( W, rho, v, S, a_o, alpha_Lo, alpha_Tconst, C_Do, e, AR, pi, D, T_R, C_D, LD, alpha, C_L, L, alpha_T, a_new, C_Lold, tol, P_Amax, P_A, np, sigma, P_Rmax );
double hnew, vnew, v_max, E_max, RC_max, P_Amaxnew, P_Rmaxnew, v_maxnew, E_maxnew, RC_maxnew;
output( h, v, P_Amax, P_Rmax, hnew, vnew, P_Amaxnew, P_Rmaxnew );
}
}
fileout.close ();
return 0;
}
//, v_maxnew, E_maxnew, RC_maxnew
//, v_max, E_max, RC_max,
The function that is computing the values is:
#include "inputoutput.hpp"
using namespace std;
ofstream fileout;
double W, S, b, e, C_Do, alpha_Tconst, a, T_sl, d_sl, go, R, x1, Y1, x2, y2, C_lmax, pi, alpha_Lo, P_A, np;
void input( const char* aircraftspecs, double& W, double& S, double& b, double& e, double& C_Do, double& alpha_Tconst, double& a, double& T_sl, double& d_sl, double& go, double& R, double& x1, double& Y1, double& x2, double& y2, double& C_lmax, double& pi, double& alpha_Lo, double& P_Aactual, double& np )
{
double inputfile[20];
ifstream filein;
filein.open( aircraftspecs );
filein >> inputfile[0]
>> inputfile[1]
>> inputfile[2]
>> inputfile[3]
>> inputfile[4]
>> inputfile[5]
>> inputfile[6]
>> inputfile[7]
>> inputfile[8]
>> inputfile[9]
>> inputfile[10]
>> inputfile[11]
>> inputfile[12]
>> inputfile[13]
>> inputfile[14]
>> inputfile[15]
>> inputfile[16]
>> inputfile[17]
>> inputfile[18]
>> inputfile[19];
filein.close();
W = inputfile[0];
S = inputfile[1];
b = inputfile[2];
e = inputfile[3];
C_Do = inputfile[4];
alpha_Tconst = inputfile[5];
a = inputfile[6];
T_sl = inputfile[7];
d_sl = inputfile[8];
go = inputfile[9];
R = inputfile[10];
x1 = inputfile[11];
Y1 = inputfile[12];
x2 = inputfile[13];
y2 = inputfile[14];
C_lmax = inputfile[15];
pi = inputfile[16];
alpha_Lo = inputfile[17];
P_Aactual = inputfile[18];
np = inputfile[19];
return;
}
double calculations( double b, double S, double d_sl, double T_sl, double go, double a, double R, double h, double Y1, double y2, double x1, double x2, double P_A, double C_Do, double W, double C_lmax, double rho_o, double& AR, double& rho, double& a_o, double& vstall, double& vmax, double& sigma )
{
AR = Aspect( b, S );
rho = dens( d_sl, T_sl, go, a, R, h );
sigma = densratio( rho_o, d_sl, T_sl, go, a, R, h );
a_o = slope_a_o( Y1, y2, x1, x2 );
vstall = VSTALL( W, d_sl, S, C_lmax );
vmax = VMAX( P_A, C_Do, d_sl, S );
cout << "AR =" << " " << AR << endl
<< "rho =" << " " << rho << endl
<< "sigma =" << " " << sigma << endl
<< "a_o =" << " " << a_o << endl
<< "vstall =" << " " << vstall << endl
<< "vmax =" << " " << vmax << endl;
return ( AR, rho, sigma, a_o, vstall, vmax );
}
void output( double h, double v, double P_Amax, double P_Rmax, double hnew, double vnew, double P_Amaxnew, double P_Rmaxnew )
{
hnew = h;
vnew = v;
P_Amaxnew = P_Amax;
P_Rmaxnew = P_Rmax;
//v_maxnew = v_max;
//E_maxnew = E_max;
//RC_maxnew = RC_max;
fileout << hnew << " " << vnew << " " << P_Amaxnew << " " << P_Rmaxnew << endl;
//fileout << hnew << " " << vnew << " " << P_Amaxnew << " " << P_Rmaxnew << " " << v_maxnew << " " << E_maxnew << " " << RC_maxnew << " " << endl;
return;
}
//double v_maxnew, double E_maxnew, double RC_maxnew
//double v_max, double E_max, double RC_max
Any help would be great! Thanks