conv/many suite: convert (m)any seismic data format(s)
fngnuplotplot.cc
Go to the documentation of this file.
1 
39 #define TF_FNGNUPLOTPLOT_CC_VERSION \
40  "TF_FNGNUPLOTPLOT_CC V1.2"
41 
42 #include <gapfunctions.h>
43 #include <aff/functions/max.h>
44 
45 void gnuplotplot(std::ostream& os,
46  const std::string& psname,
47  const CompletenessBins& cb,
48  const Tvecofgaps& vog)
49 {
50  // find limits
51  Tvecofgaps::const_iterator I=vog.begin();
52  GapSeries::Tgapseries total(0,cb.nbins()-1);
53  total=0;
54  I=vog.begin();
55  while (I!=vog.end())
56  {
58  for (unsigned j=0; j<cb.nbins(); ++j)
59  {
60  total(j)+=gs.gapseries(j);
61  }
62  ++I;
63  }
64  int maxval=aff::func::max(total);
65  bool gapsexist=(maxval>0);
66  maxval = maxval > 1 ? maxval : 1;
67 
68  // are there gaps or breaks?
69  unsigned int ntotalbreaks=0;
70  for (Tvecofgaps::const_iterator I=vog.begin(); I!=vog.end(); ++I)
71  {
72  Gapsummary summary=I->summarize();
73  ntotalbreaks += summary.nbreaks;
74  } // for (Tvecofgaps::const_iterator I=vog.begin(); I!=vog.end(); ++I)
75  bool breaksexist=(ntotalbreaks>0);
76 
77  // create header
78  os << "set terminal postscript color solid\n";
79  os << "set output \"" << psname << "\"\n";
80  os << "set title \"data gaps in bins of "
81  << cb.binsize().timestring() << "\\n"
82  << "between "
83  << cb.earliest().timestring().substr(4)
84  << " and "
85  << cb.latest().timestring().substr(4)
86  << "\"\n";
87  os << "set ylabel \"number of missing samples\"\n";
88  os << "set timefmt \"%Y/%m/%d-%H:%M:%S\"\n";
89  os << "set xdata time\n";
90  libtime::TRelativeTime dur=cb.latest()-cb.earliest();
91  if (dur > libtime::TRelativeTime(5))
92  {
93  os << "set format x \"%d.%m.%y\"\n";
94  }
95  else if (dur > libtime::TRelativeTime(1))
96  {
97  os << "set format x \"%d.%m.%y %H\"\n";
98  }
99  else
100  {
101  os << "set format x \"%d.%m.%y %H:%M\"\n";
102  }
103  os << "set boxwidth 0.9 relative\n";
104  os << "set style fill solid 0.2 border -1\n";
105  os << "set xtic rotate by -45 scale 0\n";
106  os << "set grid\n";
107  os << "set key outside enhanced horizontal\n";
108  os << "set auto x\n";
109  os << "set yrange [" << -0.05 * maxval << ":" << 1.05*maxval << "]\n";
110  os << "plot ";
111 
112  bool printlabels=(cb.nbins()<20);
113 
114  // setup plot command
115  I=vog.begin();
116  while (I!=vog.end())
117  {
118  os << "\'-\' using 1:3 title \"" << I->ID.ID << "\" with boxes";
119  if (printlabels)
120  {
121  os << ", \\\n";
122  os << " \'-\' using 1:3:2 with labels center offset 0,-0.8 notitle";
123  }
124  ++I;
125  if (I!=vog.end() || breaksexist || gapsexist)
126  {
127  os << ", \\\n ";
128  }
129  else
130  {
131  os << "\n";
132  }
133  }
134  if (gapsexist)
135  {
136  os << " \'-\' using 1:2 title \"gaps\" with points ps 2 pt 13 lt 1";
137  if (breaksexist)
138  {
139  os << ", \\\n ";
140  }
141  else
142  {
143  os << "\n";
144  }
145  }
146  if (breaksexist)
147  {
148  os << " \'-\' using 1:2 title \"breaks\" with points ps 1 pt 8 lt 3\n";
149  }
150 
151  // setup data
152  // ==========
153  //
154  // number of missing samples
155  // -------------------------
156  unsigned int nperstream=1;
157  if (printlabels) { nperstream=2; }
158  I=vog.begin();
159  while (I!=vog.end())
160  {
162  for (unsigned int i=0; i<nperstream; ++i)
163  {
164  for (unsigned int j=0; j<cb.nbins(); ++j)
165  {
166  libtime::TAbsoluteTime time=cb.bin(j)+cb.binsize()/2;
167  os << time.hierarchicalstring()
168  << " " << gs.gapseries(j) << " " << total(j) << "\n";
169  }
170  os << "e\n";
171  }
172  for (unsigned int j=0; j<cb.nbins(); ++j)
173  {
174  total(j)-=gs.gapseries(j);
175  }
176  ++I;
177  }
178 
179  //
180  // gap indicators
181  // --------------
182  if (gapsexist)
183  {
184  I=vog.begin();
185  while (I!=vog.end())
186  {
188  for (unsigned int j=0; j<cb.nbins(); ++j)
189  {
190  if (gs.gapseries(j)>0)
191  {
192  libtime::TAbsoluteTime time=cb.bin(j)+cb.binsize()/2;
193  os << time.hierarchicalstring() << " 0\n";
194  }
195  }
196  ++I;
197  }
198  os << "e\n";
199  }
200 
201  //
202  // gap break indicators
203  // --------------------
204  if (breaksexist)
205  {
206  I=vog.begin();
207  while (I!=vog.end())
208  {
209  for (Gapsofstream::Tvecofgap::const_iterator J=I->gap.begin();
210  J!=I->gap.end(); ++J)
211  {
212  if (J->isbreak())
213  {
214  libtime::TAbsoluteTime time=J->first;
215  os << time.hierarchicalstring() << " 0\n";
216  }
217  }
218  ++I;
219  }
220  os << "e\n";
221  }
222 }
223 
224 /* ----- END OF fngnuplotplot.cc ----- */
Tgapseries gapseries
a class to hold a gap series for one stream
libtime::TAbsoluteTime earliest() const
unsigned int nbins() const
libtime::TAbsoluteTime bin(const unsigned int &i) const
beginnig of bin (according to bin raster)
GapSeries seriesofmissingsamples(const Gapsofstream &gos, const CompletenessBins &cb, const bool &debug)
Function to extract a GapSeries from given Gapsofstream.
class to define the time axis of the completeness time series.
unsigned int nbreaks
total number of breaks
libtime::TAbsoluteTime latest() const
struct to present a summary
::aff::Series< int > Tgapseries
std::vector< Gapsofstream > Tvecofgaps
vector to hold all gaps
void gnuplotplot(std::ostream &os, const std::string &psname, const CompletenessBins &cb, const Tvecofgaps &vog)
libtime::TRelativeTime binsize() const
function prototypes used in gap analysis (prototypes)