http://www.koders.com/cpp/fidA13D4EAB41 ... aspx?s=F16
Κώδικας: Επιλογή όλων
/*
Copyright 2002 - Jason Richard Neuhaus, MaxJenius@users.sourceforge.net
This file is part of vsim.
Vsim is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Vsim is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with vsim; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// F16 Engine Test
#include "F16Engine.h"
#include <math.h>
#include <fstream>
#include <vector>
int main ()
{
static const double time_step = 0.125; // (sec)
static const double stop_time = 20.0; // (sec)
F16Engine* f16_engine = new F16Engine(time_step);
double pla_input = 0.0; // PLA input
double altitude = 0.0; // (m)
double mach = 0.5;
// Output file
ofstream output("f16_engine_test.m");
if ( output.bad() )
{
cerr << "Error opening output file f16_engine_test.m" << endl;
return -1;
}
// Array sizes to store data
vector<double> time_out;
vector<double> pla_command_out;
vector<double> altitude_out;
vector<double> mach_out;
vector<double> pla_out;
vector<double> thrust_out;
for ( double time = 0.0 ; time <= stop_time ; time += time_step )
{
if ( time >= 2.0 )
{
if ( time < 5.0 )
{
pla_input = 49.0;
}
else if ( time < 10.0 )
{
pla_input = 15.0;
}
else
{
pla_input = 100.0;
}
}
f16_engine->putPLACommand(pla_input);
f16_engine->putAltitude(altitude);
f16_engine->putMach(mach);
f16_engine->calculateContribution();
time_out.push_back(time);
pla_command_out.push_back(pla_input);
altitude_out.push_back(altitude);
mach_out.push_back(mach);
pla_out.push_back(f16_engine->getPLA());
thrust_out.push_back(f16_engine->getThrust());
}
output << "time = [\n";
for ( vector<double>::const_iterator iter =
time_out.begin() ;
iter != time_out.end() ;
iter++ )
{
output << (*iter) << ",\n";
}
output << "];\n";
output << "placom = [\n";
for ( vector<double>::const_iterator iter =
pla_command_out.begin() ;
iter != pla_command_out.end() ;
iter++ )
{
output << (*iter) << ",\n";
}
output << "];\n";
output << "altitude = [\n";
for ( vector<double>::const_iterator iter =
altitude_out.begin() ;
iter != altitude_out.end() ;
iter++ )
{
output << (*iter) << ",\n";
}
output << "];\n";
output << "mach = [\n";
for ( vector<double>::const_iterator iter =
mach_out.begin() ;
iter != mach_out.end() ;
iter++ )
{
output << (*iter) << ",\n";
}
output << "];\n";
output << "pla = [\n";
for ( vector<double>::const_iterator iter =
pla_out.begin() ;
iter != pla_out.end() ;
iter++ )
{
output << (*iter) << ",\n";
}
output << "];\n";
output << "thrust = [\n";
for ( vector<double>::const_iterator iter =
thrust_out.begin() ;
iter != thrust_out.end() ;
iter++ )
{
output << (*iter) << ",\n";
}
output << "];\n";
output.close();
cout << "Output written to f16_engine_test.m" << endl;
return 0;
}


