rheolef  6.5
branch_seq_visu_gnuplot.cc
Go to the documentation of this file.
1 #include "rheolef/branch.h"
2 #include "rheolef/pstream.h"
3 #include "rheolef/rheostream.h"
4 namespace rheolef {
5 using namespace std;
6 
7 // yet hard-coded ! TODO: use a -select-contour option
8 template <class T>
9 void
11 {
12  ostream& out = ops.os();
15  string basename = iorheo::getbasename(out);
16  if (basename == "") basename = "output";
17  bool do_verbose = iorheo::getverbose(clog);
18  bool do_execute = iorheo::getexecute(clog);
19  bool do_clean = iorheo::getclean (clog);
20  string tmp = (do_clean ? get_tmpdir() + "/" : "");
21 
22  string plot_name = tmp+basename + ".plot";
23  b._p_ctrl_out = new_macro (ofstream(plot_name.c_str()));
24  do_verbose && clog << "! file `" << plot_name << "' created" << endl;
25  *(b._p_ctrl_out) << setbasename(basename)
26  << setprecision(numeric_limits<Float>::digits10)
27  << "dt_pause = 0.25 # in seconds" << endl;
28 
29  string gdat_name = tmp+basename + ".gdat";
30  b._p_data_out = new_macro (ofstream(gdat_name.c_str()));
31  do_verbose && clog << "! file `" << gdat_name << "' created" << endl;
32  *(b._p_data_out) << setbasename(basename)
33  << setprecision(numeric_limits<Float>::digits10);
34 }
35 template <class T>
36 void
38 {
40  if (b.n_field() == 0) return;
41  const space_basic<T,sequential>& Xh = b[0].second.get_space();
42  const geo_basic<T,sequential>& omega = Xh.get_geo();
43  const array<point_basic<T>,sequential>& xdof = Xh.get_xdofs();
44 
45  bool do_clean = iorheo::getclean (clog);
46  string basename = iorheo::getbasename(ops.os());
47  if (basename == "") basename = "output";
48  string tmp = (do_clean ? get_tmpdir() + "/" : "");
49  string gdat_name = tmp+basename + ".gdat";
50  if (b._count_value == 0) {
51  T all_min = std::numeric_limits<T>::max();
52  T all_max = std::numeric_limits<T>::min();
53  for (size_t ifld = 0, nfld = b.n_field(); ifld < nfld; ifld++) {
54  const field_basic<T,sequential>& u = b[ifld].second;
55  all_min = std::min (all_min, u.min());
56  all_max = std::max (all_max, u.max());
57  }
58  if (b._u_range.first != std::numeric_limits<T>::min()) {
59  all_min = b._u_range.first;
60  }
61  if (b._u_range.second != std::numeric_limits<T>::max()) {
62  all_max = b._u_range.second;
63  }
64  if (fabs(all_max) - fabs(all_min) < 1e-7) {
65  all_max = all_min + 1;
66  }
67  *(b._p_ctrl_out) << "set xrange [" << omega.xmin()[0] << ":" << omega.xmax()[0] << "]" << endl
68  << "set yrange [" << all_min << ":" << all_max << "]" << endl;
69  }
70  *(b._p_ctrl_out) << "plot \\" << endl;
71  const string& pname = b.parameter_name() + itos(b._count_value)
72  + "=" + ftos(b.parameter());
73  for (size_t ifld = 0, nfld = b.n_field(); ifld < nfld; ifld++) {
74  const string& uname = b[ifld].first;
75  *(b._p_ctrl_out) << (ifld == 0 ? " " : ",")
76  << " \"" << gdat_name << "\""
77  << " i " << b._count_value
78  << " u 1:" << ifld+2
79  << " t \"" << uname << "(" << pname << ")\""
80  << " w l"
81  << (ifld < nfld-1 ? " \\" : "")
82  << endl;
83  }
84  *(b._p_ctrl_out) << "pause dt_pause" << endl;
85  // TODO: Pk is buggy if edges are not ordered from left to right... to fix !
86  size_type ndof_P1 = omega.n_vertex();
87  for (size_type idof = 0, ndof = ndof_P1; idof < ndof; idof++) {
88  *(b._p_data_out) << xdof[idof][0];
89  for (size_t ifld = 0, nfld = b.n_field(); ifld < nfld; ifld++) {
90  const field_basic<T,sequential>& u = b[ifld].second;
91  *(b._p_data_out) << " " << u.dof(idof);
92  }
93  *(b._p_data_out) << endl;
94  }
95  *(b._p_data_out) << endl << endl;
96 }
97 template <class T>
98 void
100 {
101  string basename = iorheo::getbasename(ops.os());
102  if (basename == "") basename = "output";
103  bool do_verbose = iorheo::getverbose(clog);
104  bool do_execute = iorheo::getexecute(clog);
105  bool do_clean = iorheo::getclean(clog);
106  bool reader_on_stdin = iorheo::getreader_on_stdin(ops.os());
107  if (! reader_on_stdin) {
108  *(b._p_ctrl_out) << "pause -1 \"<end>\"" << endl;
109  }
110  string tmp = (do_clean ? get_tmpdir() + "/" : "");
111  int status = 0;
112  string command;
113  if (do_execute) {
114  command = "gnuplot ";
115  if (reader_on_stdin) command += "-persist ";
116  command += tmp + basename + ".plot";
117  if (do_verbose) clog << "! " << command << endl;
118  cin.sync();
119  status = system (command.c_str());
120  }
121  if (!do_execute && do_clean) {
122  string tmp = get_tmpdir() + "/";
123  if (!do_clean) tmp = "";
124  string command = "/bin/rm -f " + tmp+basename + ".plot "
125  + tmp+basename + ".gdat";
126  do_verbose && clog << "! " << command << endl;
127  int status = system (command.c_str());
128  }
131  b._p_ctrl_out = 0;
132  b._p_data_out = 0;
133 }
134 template void put_header_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
135 template void put_event_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
136 template void put_finalize_gnuplot (odiststream&, const branch_basic<Float,sequential>&);
137 
138 } // namespace rheolef
139