JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGOutputFile.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGOutputFile.cpp
4  Author: Bertrand Coconnier
5  Date started: 09/10/11
6  Purpose: Manage output of sim parameters to a file
7  Called by: FGOutput
8 
9  ------------- Copyright (C) 2011 Bertrand Coconnier -------------
10 
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU Lesser General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15 
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19  details.
20 
21  You should have received a copy of the GNU Lesser General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA 02111-1307, USA.
24 
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27 
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This is the place where you create output routines to dump data for perusal
31 later.
32 
33 HISTORY
34 --------------------------------------------------------------------------------
35 09/10/11 BC Created
36 
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 
41 #include <sstream>
42 
43 #include "FGOutputFile.h"
44 #include "input_output/FGXMLElement.h"
45 
46 using namespace std;
47 
48 namespace JSBSim {
49 
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 CLASS IMPLEMENTATION
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 
54 FGOutputFile::FGOutputFile(FGFDMExec* fdmex) :
55  FGOutputType(fdmex),
56  runID_postfix(-1)
57 {
58 }
59 
60 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 
63 {
65  if (Filename.isNull()) {
66  Filename = SGPath(Name);
67  runID_postfix = 0;
68  }
69  return OpenFile();
70  }
71 
72  return false;
73 }
74 
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 
78 {
79  if (runID_postfix >= 0) {
80  ostringstream buf;
81  string::size_type dot = Name.find_last_of('.');
82  if (dot != string::npos) {
83  buf << Name.substr(0, dot) << '_' << runID_postfix++ << Name.substr(dot);
84  } else {
85  buf << Name << '_' << runID_postfix++;
86  }
87  Filename = SGPath(buf.str());
88  }
89 
90  CloseFile();
91 }
92 
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 
96 {
97  if (!FGOutputType::Load(el))
98  return false;
99 
100  SetOutputName(el->GetAttributeValue("name"));
101 
102  return true;
103 }
104 
105 }
JSBSim::FGOutputFile::CloseFile
virtual void CloseFile(void)
Closes the file.
Definition: FGOutputFile.h:118
JSBSim::FGFDMExec
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:185
JSBSim::FGOutputType
Abstract class to provide functions generic to all the output directives.
Definition: FGOutputType.h:90
JSBSim::Element::GetAttributeValue
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Definition: FGXMLElement.cpp:260
JSBSim::FGOutputType::InitModel
bool InitModel(void) override
Init the output model according to its configitation.
Definition: FGOutputType.cpp:178
JSBSim::FGOutputFile::InitModel
bool InitModel(void) override
Initializes the instance.
Definition: FGOutputFile.cpp:62
JSBSim::FGOutputFile::OpenFile
virtual bool OpenFile(void)=0
Opens the file.
JSBSim::FGOutputFile::SetOutputName
void SetOutputName(const std::string &fname) override
Overwrites the name identifier under which the output will be logged.
Definition: FGOutputFile.h:102
JSBSim::FGOutputFile::Load
bool Load(Element *el) override
Init the output directives from an XML file.
Definition: FGOutputFile.cpp:95
JSBSim::FGOutputFile::SetStartNewOutput
void SetStartNewOutput(void) override
Reset the output prior to a restart of the simulation.
Definition: FGOutputFile.cpp:77
JSBSim::FGOutputType::Load
bool Load(Element *el) override
Init the output directives from an XML file (implement the FGModel interface).
Definition: FGOutputType.cpp:102
JSBSim::Element
Definition: FGXMLElement.h:143