readmodel.cpp
3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/***************************************************************************
* readmodel.cpp - Illustrates how to read a model *
* ----------------------------------------------------------------------- *
* copyright (C) 2013-2016 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file readmodel.cpp
* @brief Illustrates how to read a model
* @author Juergen Knoedlseder
*/
/* __ Includes ___________________________________________________________ */
#include <iostream>
#include <fstream>
#include "GammaLib.hpp"
/***********************************************************************//**
* @brief Create XML file
*
* Creates XML file that should be read back to avoid shipping of a test
* XML file.
***************************************************************************/
void create_xml_file(void)
{
// Open ASCII file
std::ofstream file("example_source.xml");
// Write file if file is open
if (file.is_open()) {
// Write XML file
file << "<?xml version=\"1.0\" standalone=\"no\"?>\n";
file << "<source_library title=\"source library\">\n";
file << " <source name=\"1FGL J0005.7+3815\" type=\"PointSource\">\n";
file << " <spectrum type=\"PowerLaw\">\n";
file << " <parameter scale=\"1e-07\" name=\"Prefactor\"";
file << " min=\"1e-07\" max=\"1000.0\" value=\"1.73\" free=\"1\"/>\n";
file << " <parameter scale=\"1.0\" name=\"Index\" min=\"-5.0\"";
file << " max=\"+5.0\" value=\"-2.1\" free=\"1\"/>\n";
file << " <parameter scale=\"1.0\" name=\"Scale\" min=\"10.0\"";
file << " max=\"1000000.0\" value=\"100.0\" free=\"0\"/>\n";
file << " </spectrum>\n";
file << " <spatialModel type=\"PointSource\">\n";
file << " <parameter free=\"0\" max=\"360\" min=\"-360\"";
file << " name=\"RA\" scale=\"1\" value=\"83.6331\"/>\n";
file << " <parameter free=\"0\" max=\"90\" min=\"-90\"";
file << " name=\"DEC\" scale=\"1\" value=\"22.0145\" />\n";
file << " </spatialModel>\n";
file << " </source>\n";
file << "</source_library>\n";
// Close file
file.close();
} // endif: file was open
// Return
return;
}
/***********************************************************************//**
* @brief Read XML model
***************************************************************************/
int main(void)
{
// Create XML file
create_xml_file();
// Read XML model
GModels models("example_source.xml");
std::cout << models << std::endl;
// Return
return 0;
}