39{
41
44 bool multicolumn;
45 bool header;
46 string title;
48
49 try {
50
51 JParser<> zap(
"Auxiliary program to create TGraph from input file with ASCII data.");
52
59
60 zap(argc, argv);
61 }
62 catch(const exception &error) {
63 FATAL(error.what() << endl);
64 }
65
67
69
70
72
73 const string gname = (title !=
"" ? title : getFilename(*file_name));
74
75 ifstream in(file_name->c_str());
76
77 while (in.peek() == '#') {
79 }
80
82
83 if (header) {
84
86
87 string buffer;
88
90
92
93 for (
string key; is >>
key; ) {
95 }
96 }
97
98 } else {
99
101 }
102 }
103
104
106
108
113
114 for (
string buffer;
getline(in,buffer); ) {
115
117
118 if (is >> x) X .push_back(x);
119 if (is >> y) Y .push_back(y);
120 if (is >>
ex) EX.push_back(
ex);
121 if (is >>
ey) EY.push_back(
ey);
122 }
123
124 if (X.size() != Y.size()) {
125 FATAL(
"Number of points " << X.size() <<
' ' << Y.size() <<
endl);
126 }
127
128
130
131 if (EX.empty()) {
132
133 graph =
new TGraph(X.size(), X.data(), Y.data());
134
135 } else {
136
137 if (X.size() != EX.size()) {
138 FATAL(
"Number of x points " << X.size() <<
' ' << EX.size() <<
endl);
139 }
140
141 if (EY.empty()) {
142 EY.swap(EX);
143 EX.resize(X.size(), 0.0);
144 }
145
146 if (Y.size() != EY.size()) {
147 FATAL(
"Number of y points " << Y.size() <<
' ' << EY.size() <<
endl);
148 }
149
150 graph =
new TGraphErrors(X.size(), X.data(), Y.data(), EX.data(), EY.data());
151 }
152
154
156
158
160
162 }
163
164 } else {
165
168
169 for (
string buffer;
getline(in,buffer); ) {
170
172
173 if (is >> x) {
174
175 X.push_back(x);
176
177 size_t i = 0;
178
179 for ( ; is >>
y; ++i) {
180
181 if (i == Y.size()) {
182 Y.resize(i+1);
183 }
184
185 Y[i].push_back(y);
186 }
187 }
188 }
189
190 if (header) {
191 if (
column.size() != 1 + Y.size()) {
192 FATAL(
"Number of colums " <<
column.size() <<
" != " << 1 + Y.size() <<
endl);
193 }
194 }
195
196 for (size_t i = 0; i != Y.size(); ++i) {
197 if (X.size() != Y[i].size()) {
198 FATAL(
"Number of rows " << X.size() <<
" != " << Y[i].size() <<
endl);
199 }
200 }
201
202 for (size_t i = 0; i != Y.size(); ++i) {
203
204 TGraph*
graph =
new TGraph(X.size(), X.data(), Y[i].data());
205
206 ostringstream os;
207
209
210 graph->SetName(os.str().c_str());
211
213
215
217 }
218 }
219
220 in.close();
221 }
222
223 out.Write();
224 out.Close();
225}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
#define MAKE_STRING(A)
Make string.
Template definition of a multi-dimensional oscillation probability interpolation table.
Utility class to parse command line options.
void setLimits(TGraph &g1)
Set limits of TGraph.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).