46#if !defined(__GNUC__) && !defined(sgi) && !defined(_MSC_VER)
54#elif defined(__GNUC__) && !defined(sgi)
58#if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
59# define WIN32_LEAN_AND_MEAN
63# include <sys/types.h>
64# include <sys/timeb.h>
110#if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
115 return tm_ptr.time + tm_ptr.millitm*0.001;
123 gettimeofday(&tval, &tz);
124 return (tval.tv_sec + tval.tv_usec*1e-6);
128#if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
131 Sleep((DWORD)(nanosec*1e-6));
136 struct timespec ts, ts1;
139 ts.tv_nsec = nanosec;
140 nanosleep(&ts, &ts1);
151 if (document && document->
GetName() ==
"runscript") result =
true;
158 if (document && document->
GetName() ==
"output") result =
true;
165 if (document && document->
GetName() ==
"fdm_config") result =
true;
172 if (document && document->
GetName() ==
"initialize") result =
true;
277int main(
int argc,
char* argv[])
281 _controlfp(_controlfp(0, 0) & ~(_EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW),
283#elif defined(__GNUC__) && !defined(sgi) && !defined(__APPLE__)
284 feenableexcept(FE_DIVBYZERO | FE_INVALID);
289 }
catch (
string& msg) {
290 std::cerr <<
"FATAL ERROR: JSBSim terminated with an exception."
291 << std::endl <<
"The message was: " << msg << std::endl;
294 std::cerr <<
"FATAL ERROR: JSBSim terminated with an unknown exception."
310 bool result =
false, success;
311 bool was_paused =
false;
313 double frame_duration;
315 double new_five_second_value = 0.0;
316 double actual_elapsed_time = 0;
317 double initial_seconds = 0;
318 double current_seconds = 0.0;
319 double paused_seconds = 0.0;
320 double sim_lag_time = 0;
321 double cycle_duration = 0.0;
322 double override_sim_rate_value = 0.0;
323 long sleep_nseconds = 0;
341 FDMExec->SetAircraftPath(SGPath(
"aircraft"));
342 FDMExec->SetEnginePath(SGPath(
"engine"));
343 FDMExec->SetSystemsPath(SGPath(
"systems"));
344 FDMExec->GetPropertyManager()->Tie(
"simulation/frame_start_time", &actual_elapsed_time);
345 FDMExec->GetPropertyManager()->Tie(
"simulation/cycle_duration", &cycle_duration);
373 cerr <<
"Script file " <<
ScriptName <<
" was not successfully loaded" << endl;
383 if ( !
FDMExec->LoadModel(SGPath(
"aircraft"),
387 cerr <<
" JSBSim could not be started" << endl << endl;
393 FDMExec->PrintPropertyCatalog();
401 cerr <<
"Initialization unsuccessful" << endl;
406 cout <<
" No Aircraft, Script, or Reset information given" << endl << endl;
415 cout <<
"Output directives not properly set in file " <<
LogDirectiveName[
i] << endl;
427 string old_filename =
FDMExec->GetOutputFileName(
i);
429 cout <<
"Output filename could not be set" << endl;
431 cout <<
"Output filename change from " << old_filename <<
" from aircraft"
433 " command line" << endl;
453 FDMExec->PrintSimulationConfiguration();
456 FDMExec->GetPropagate()->DumpState();
465 if (
FDMExec->GetDebugLevel() > 0)
469 }
catch (
string& msg) {
470 cerr << endl << msg << endl << endl;
476 <<
"---- JSBSim Execution beginning ... --------------------------------------------"
487 strftime(s, 99,
"%A %B %d %Y %X", localtime(&tod));
488 cout <<
"Start: " << s <<
" (HH:MM:SS)" << endl;
490 frame_duration =
FDMExec->GetDeltaT();
491 if (
realtime) sleep_nseconds = (long)(frame_duration*1e9);
504 FDMExec->CheckIncrementalHold();
521 initial_seconds += paused_seconds;
525 actual_elapsed_time = current_seconds - initial_seconds;
526 sim_lag_time = actual_elapsed_time -
FDMExec->GetSimTime();
528 for (
int i=0;
i<(int)(sim_lag_time/frame_duration);
i++) {
537 if (
FDMExec->GetSimTime() >= new_five_second_value) {
538 cout <<
"Simulation elapsed time: " <<
FDMExec->GetSimTime() << endl;
539 new_five_second_value += 5.0;
553 strftime(s, 99,
"%A %B %d %Y %X", localtime(&tod));
554 cout <<
"End: " << s <<
" (HH:MM:SS)" << endl;
564#define gripe cerr << "Option '" << keyword \
565 << "' requires a value, as in '" \
566 << keyword << "=something'" << endl << endl;
578 cout.setf(ios_base::fixed);
580 for (
i=1;
i<count;
i++) {
581 string argument = string(arg[
i]);
582 string keyword(argument);
584 string::size_type n=argument.find(
"=");
586 if (n != string::npos && n > 0) {
587 keyword = argument.substr(0, n);
588 value = argument.substr(n+1);
591 if (keyword ==
"--help") {
594 }
else if (keyword ==
"--version") {
595 cout << endl <<
" JSBSim Version: " <<
FDMExec->GetVersion() << endl << endl;
597 }
else if (keyword ==
"--realtime") {
599 }
else if (keyword ==
"--nice") {
601 if (n != string::npos) {
605 cerr << endl <<
" Invalid sleep period given!" << endl << endl;
611 }
else if (keyword ==
"--suspend") {
613 }
else if (keyword ==
"--nohighlight") {
615 }
else if (keyword ==
"--outputlogfile") {
616 if (n != string::npos) {
619 }
else if (keyword ==
"--logdirectivefile") {
620 if (n != string::npos) {
626 }
else if (keyword ==
"--root") {
627 if (n != string::npos) {
628 RootDir = SGPath::fromLocal8Bit(value.c_str());
633 }
else if (keyword ==
"--aircraft") {
634 if (n != string::npos) {
640 }
else if (keyword ==
"--script") {
641 if (n != string::npos) {
642 ScriptName = SGPath::fromLocal8Bit(value.c_str());
647 }
else if (keyword ==
"--initfile") {
648 if (n != string::npos) {
649 ResetName = SGPath::fromLocal8Bit(value.c_str());
655 }
else if (keyword ==
"--property") {
656 if (n != string::npos) {
657 string propName = value.substr(0,value.find(
"="));
658 string propValueString = value.substr(value.find(
"=")+1);
659 double propValue =
atof(propValueString.c_str());
667 }
else if (keyword.substr(0,5) ==
"--end") {
668 if (n != string::npos) {
672 cerr << endl <<
" Invalid end time given!" << endl << endl;
680 }
else if (keyword ==
"--simulation-rate") {
681 if (n != string::npos) {
686 cerr << endl <<
" Invalid simulation rate given!" << endl << endl;
694 }
else if (keyword ==
"--catalog") {
697 }
else if (keyword.substr(0,2) !=
"--" && value.empty() ) {
701 SGPath path = SGPath::fromLocal8Bit(keyword.c_str());
709 cerr <<
"The argument \"" << keyword <<
"\" cannot be interpreted as a file name or option." << endl;
717 cerr <<
"The argument \"" << keyword <<
"\" cannot be interpreted as a file name or option." << endl;
726 cerr <<
"Cannot specify catalog with script option" << endl << endl;
730 cerr <<
"You must specify an initialization file with the aircraft name." << endl << endl;
734 cerr <<
"You cannot specify an aircraft file with a script." << endl;
746 cout << endl <<
" JSBSim version " <<
FDMExec->GetVersion() << endl << endl;
747 cout <<
" Usage: jsbsim [script file name] [output file names] <options>" << endl << endl;
748 cout <<
" options:" << endl;
749 cout <<
" --help returns this message" << endl;
750 cout <<
" --version returns the version number" << endl;
751 cout <<
" --outputlogfile=<filename> sets (overrides) the name of a data output file" << endl;
752 cout <<
" --logdirectivefile=<filename> specifies the name of a data logging directives file" << endl;
753 cout <<
" (can appear multiple times)" << endl;
754 cout <<
" --root=<path> specifies the JSBSim root directory (where aircraft/, engine/, etc. reside)" << endl;
755 cout <<
" --aircraft=<filename> specifies the name of the aircraft to be modeled" << endl;
756 cout <<
" --script=<filename> specifies a script to run" << endl;
757 cout <<
" --realtime specifies to run in actual real world time" << endl;
758 cout <<
" --nice specifies to run at lower CPU usage" << endl;
759 cout <<
" --nohighlight specifies that console output should be pure text only (no color)" << endl;
760 cout <<
" --suspend specifies to suspend the simulation after initialization" << endl;
761 cout <<
" --initfile=<filename> specifies an initilization file" << endl;
762 cout <<
" --catalog specifies that all properties for this aircraft model should be printed" << endl;
763 cout <<
" (catalog=aircraftname is an optional format)" << endl;
764 cout <<
" --property=<name=value> e.g. --property=simulation/integrator/rate/rotational=1" << endl;
765 cout <<
" --simulation-rate=<rate (double)> specifies the sim dT time or frequency" << endl;
766 cout <<
" If rate specified is less than 1, it is interpreted as" << endl;
767 cout <<
" a time step size, otherwise it is assumed to be a rate in Hertz." << endl;
768 cout <<
" --end=<time (double)> specifies the sim end time" << endl << endl;
770 cout <<
" NOTE: There can be no spaces around the = sign when" << endl;
771 cout <<
" an option is followed by a filename" << endl << endl;
JSBSim::FGFDMExec * FDMExec
void sim_nsleep(long nanosec)
double getcurrentseconds(void)
vector< SGPath > LogDirectiveName
bool options(int, char **)
vector< string > LogOutputName
int real_main(int argc, char *argv[])
vector< string > CommandLineProperties
vector< double > CommandLinePropertyValues
const std::string & GetName(void) const
Retrieves the element name.
bool Load(const SGPath &rstname, bool useStoredPath=true)
Loads the initial conditions.
static char highint[5]
highlights text
static char reset[5]
resets text properties
static char fggreen[6]
green text
The trimming routine for JSBSim.
Element * LoadXMLDocument(const SGPath &XML_filename, bool verbose=true)
This class is solely for the purpose of determining what type of file is given on the command line.
bool IsLogDirectiveFile(const SGPath &filename)
bool IsAircraftFile(const SGPath &filename)
bool IsInitFile(const SGPath &filename)
bool IsScriptFile(const SGPath &filename)
static double atof(const string &str)