JSBSim Flight Dynamics Model  1.0 (02 March 2017)
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 IDENT(IdSrc,"$Id: FGOutputFile.cpp,v 1.10 2017/02/25 14:23:18 bcoconni Exp $");
51 IDENT(IdHdr,ID_OUTPUTFILE);
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 CLASS IMPLEMENTATION
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
57 FGOutputFile::FGOutputFile(FGFDMExec* fdmex) :
58  FGOutputType(fdmex),
59  runID_postfix(-1)
60 {
61 }
62 
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 
66 {
68  if (Filename.isNull()) {
69  Filename = SGPath(Name);
70  runID_postfix = 0;
71  }
72  return OpenFile();
73  }
74 
75  return false;
76 }
77 
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 
81 {
82  if (runID_postfix >= 0) {
83  ostringstream buf;
84  string::size_type dot = Name.find_last_of('.');
85  if (dot != string::npos) {
86  buf << Name.substr(0, dot) << '_' << runID_postfix++ << Name.substr(dot);
87  } else {
88  buf << Name << '_' << runID_postfix++;
89  }
90  Filename = SGPath(buf.str());
91  }
92 
93  CloseFile();
94 }
95 
96 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 
99 {
100  if (!FGOutputType::Load(el))
101  return false;
102 
103  SetOutputName(el->GetAttributeValue("name"));
104 
105  return true;
106 }
107 
108 }
void SetStartNewOutput(void)
Reset the output prior to a restart of the simulation.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
virtual bool InitModel(void)
Init the output model according to its configitation.
bool InitModel(void)
Initializes the instance.
STL namespace.
virtual void CloseFile(void)
Closes the file.
Definition: FGOutputFile.h:124
void SetOutputName(const std::string &fname)
Overwrites the name identifier under which the output will be logged.
Definition: FGOutputFile.h:108
bool Load(Element *el)
Init the output directives from an XML file.
virtual bool Load(Element *el)
Init the output directives from an XML file (implement the FGModel interface).
Abstract class to provide functions generic to all the output directives.
Definition: FGOutputType.h:95
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
virtual bool OpenFile(void)=0
Opens the file.