20 #include "SheafSystem/plot.h" 22 #include "SheafSystem/assert_contract.h" 23 #include "SheafSystem/std_iostream.h" 24 #include "SheafSystem/std_sstream.h" 25 #include "SheafSystem/std_string.h" 56 const char** xcurve_labels,
65 require(xnum_curves > 0);
66 require(unexecutable(
"length of xcurve_labels == xnum_curves"));
67 require(unexecutable(
"xtypes == 0 || size of xtypes == xnum_curves"));
73 _num_curves = xnum_curves;
78 bool lhas_quadratic =
false;
80 for(
int i = 0; i < _num_curves; i++)
84 ltypes[i] = QUADRATIC;
85 lhas_quadratic =
true;
89 ltypes[i] = xtypes[i];
90 if(ltypes[i] == QUADRATIC)
91 lhas_quadratic =
true;
97 stringstream ldata_file_name_stream;
98 ldata_file_name_stream << xdriver <<
".dat";
100 string ldata_file_name;
101 ldata_file_name_stream >> ldata_file_name;
103 _data_file =
new ofstream(ldata_file_name.c_str());
107 stringstream lplot_file_name_stream;
108 lplot_file_name_stream << xdriver <<
".gnu";
110 string lplot_file_name;
111 lplot_file_name_stream >> lplot_file_name;
113 ofstream lplot_file(lplot_file_name.c_str());
115 lplot_file <<
"set xlabel \"" << xxlabel <<
"\"" << endl;
116 lplot_file <<
"set ylabel \"" << xylabel <<
"\"" << endl;
117 lplot_file <<
"set key bottom horizontal outside box" << endl;
118 lplot_file <<
"set title \"" << xdriver <<
"\"" << endl;
119 lplot_file <<
"FIT_LIMIT = 1e-6" << endl << endl;
123 lplot_file <<
"set fit logfile \"" << xdriver
124 <<
".fit\" noerrorvariables" << endl;
126 for(
int i = 0; i < _num_curves; i++)
131 lplot_file <<
"f" << i <<
"(x) = a" << i <<
"*x**2 + b" 132 << i <<
"*x + c" << i << endl;
134 lplot_file <<
"fit f" << i <<
"(x) \"" << ldata_file_name
135 <<
"\" using 1:" << i+2 <<
" via a" << i <<
", b" << i
136 <<
", c" << i << endl;
140 lplot_file <<
"f" << i <<
"(x) = a" << i <<
"*x + b" << i << endl;
142 lplot_file <<
"fit f" << i <<
"(x) \"" << ldata_file_name
143 <<
"\" using 1:" << i+2 <<
" via a" << i <<
", b" << i << endl;
147 lplot_file <<
"f" << i <<
"(x) = a" << i << endl;
149 lplot_file <<
"fit f" << i <<
"(x) \"" << ldata_file_name
150 <<
"\" using 1:" << i+2 <<
" via a" << i << endl;
157 lplot_file << endl <<
"plot ";
159 for(
int i = 0; i < _num_curves; i++)
161 lplot_file <<
"\"" << ldata_file_name <<
"\" u 1:" << i+2
162 <<
" t \"" << xcurve_labels[i] <<
"\" with points, f" 165 if(i+1 < _num_curves)
169 lplot_file << endl << endl;
173 lplot_file <<
"set terminal png size 800,600" << endl;
174 lplot_file <<
"set output \"" << xdriver <<
".png\"" << endl;
175 lplot_file <<
"replot" << endl << endl;
179 lplot_file <<
"set terminal pdf" << endl;
180 lplot_file <<
"set output \"" << xdriver <<
".pdf\"" << endl;
181 lplot_file <<
"replot" << endl << endl;
185 lplot_file <<
"set print \"" << xdriver <<
".html\"" << endl;
186 lplot_file <<
"print \"<html><title>" << xdriver <<
"</title><body>\"" << endl;
187 lplot_file <<
"print \"<img src=\\\"" << xdriver <<
".png\\\"" 189 lplot_file <<
"print \"<br><br>\"" << endl << endl;
191 for(
int i = 0; i < _num_curves; i++)
196 lplot_file <<
"if(a" << i
197 <<
">1e-6) print \"<font size=-1 color=red>\"; else " 198 <<
"print \"<font size=-1>\"" << endl;
200 lplot_file <<
"print \"f" << i <<
"(x) = (\", a" << i
201 <<
", \")*x^2 + (\", b" << i <<
", \")*x + (\", c" 202 << i <<
", \")<br></font>\"" << endl << endl;
207 lplot_file <<
"print \"<font size=-1>\"" << endl;
209 lplot_file <<
"print \"f" << i <<
"(x) = (\", a" 210 << i <<
", \")*x + (\", b" 211 << i <<
", \")<br></font>\"" << endl << endl;
216 lplot_file <<
"print \"<font size=-1>\"" << endl;
218 lplot_file <<
"print \"f" << i <<
"(x) = (\", a" 219 << i <<
", \")<br></font>\"" << endl << endl;
225 lplot_file <<
"print \"</body></html>\"" << endl << endl;
231 lplot_file <<
"set print" << endl;
233 for(
int i = 0; i < _num_curves; i++)
235 if(ltypes[i] == QUADRATIC)
237 lplot_file <<
"a" << i <<
">1e-6";
239 if(i+1 < _num_curves)
240 lplot_file <<
" || ";
244 lplot_file <<
") print \"\\nWARNING: Quadratic behavior!\"" << endl;
288 double* result =
new double[_num_curves+1];
293 ensure(unexecutable(
"length of result == _num_curves+1"));
307 require(unexecutable(
"length of xpoint == _num_curves+1"));
311 for(
int i = 0; i < _num_curves+1; i++)
313 *_data_file << xpoint[i] <<
" ";
plot_type
Type of curve to fit.
double * create_point()
An empty array for point data.
plot(const char *xdriver, const char **xcurve_labels, int xnum_curves=1, const char *xxlabel="", const char *xylabel="", const plot_type *xtypes=0)
Constructor.
void add_point(double *xpoint)
Add a data point.
virtual ~plot()
Destructor.
virtual bool invariant() const
Class invariant.