]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGOutputFile.cpp
Fix for bug 1304 - crash loading XML route
[flightgear.git] / src / FDM / JSBSim / input_output / 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.6 2014/01/13 10:46:00 ehofman Exp $");
51 IDENT(IdHdr,ID_OUTPUTFILE);
52
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 CLASS IMPLEMENTATION
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
57 FGOutputFile::FGOutputFile(FGFDMExec* fdmex) :
58   FGOutputType(fdmex),
59   runID_postfix(0)
60 {
61 }
62
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
65 bool FGOutputFile::InitModel(void)
66 {
67   if (FGOutputType::InitModel())
68     return OpenFile();
69
70   return false;
71 }
72
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74
75 void FGOutputFile::SetStartNewOutput(void)
76 {
77   if (Filename.size() > 0) {
78     ostringstream buf;
79     string::size_type dot = Name.find_last_of('.');
80     if (dot != string::npos) {
81       buf << Name.substr(0, dot) << '_' << runID_postfix++ << Name.substr(dot);
82     } else {
83       buf << Name << '_' << runID_postfix++;
84     }
85     Filename = buf.str();
86     CloseFile();
87   }
88 }
89
90 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
92 bool FGOutputFile::Load(Element* el)
93 {
94   if (!FGOutputType::Load(el))
95     return false;
96   
97   SetOutputName(el->GetAttributeValue("name"));
98   
99   return true;
100 }
101
102 }