conv/many suite: convert (m)any seismic data format(s)
structgapanalysis.h
Go to the documentation of this file.
1 
39 // include guard
40 #ifndef TF_STRUCTGAPANALYSIS_H_VERSION
41 
42 #define TF_STRUCTGAPANALYSIS_H_VERSION \
43  "TF_STRUCTGAPANALYSIS_H V1.1"
44 
45 #include <tfxx/stringfunc.h>
46 #include <libtime++.h>
47 #include <list>
48 #include <vector>
49 #include <iostream>
50 
53 struct Contiguous {
54  libtime::TAbsoluteTime first, last;
55  libtime::TRelativeTime dt;
56  std::string station, channel, auxid;
57 }; // struct Contiguous
58 
61 typedef std::list<Contiguous> TContiguouslist;
62 
73 struct Gapid {
74  Gapid() { }
75  Gapid(const Contiguous& c):
76  ID(tfxx::string::trimws(c.channel)
77  +":"+tfxx::string::trimws(c.station)
78  +":"+tfxx::string::trimws(c.auxid)),
80  { }
81  bool operator==(const Gapid& other) const
82  { return((this->ID == other.ID) && (this->dt == other.dt)); }
83  bool operator!=(const Gapid& other) const
84  { return(!this->operator==(other)); }
85  std::string ID;
86  libtime::TRelativeTime dt;
87  std::string station() const { return Mstation; }
88  std::string channel() const { return Mchannel; }
89  std::string auxid() const { return Mauxid; }
90  private:
91  std::string Mstation, Mchannel, Mauxid;
92 }; // struct Gapid
93 
94 /*----------------------------------------------------------------------*/
95 
97 struct Gap {
98  // true, if no sample is missing (just a break in contiguous data)
99  bool isbreak() const { return (last<=(first+ID.dt)); }
100  // time span from first missing sample to last missing sample + one sample
101  // interval (represents gaps size in terms of missing sample intervals)
102  libtime::TRelativeTime tmissing() const
103  {
104  libtime::TRelativeTime retval(0);
105  if (!this->isbreak()) { retval=last-first+ID.dt; }
106  return(retval);
107  }
108  // number of missing samples, taking irregular sampling into account
109  unsigned int nmissing() const
110  {
111  unsigned int retval=0;
112  if (!this->isbreak()) { retval=(this->tmissing()+(ID.dt/2))/ID.dt; }
113  return retval;
114  }
115  // data
116  libtime::TAbsoluteTime first, last;
118 }; // struct Gap
119 
120 /*----------------------------------------------------------------------*/
121 
123 struct Gapsummary {
124  Gapsummary(const libtime::TAbsoluteTime& earliest,
125  const libtime::TAbsoluteTime& latest,
126  const libtime::TRelativeTime& indt)
127  : ngaps(0), nbreaks(0), nmissing(0), nexpected(1+((latest-earliest)/indt)),
128  tspan(latest-earliest), tmissing(0), dt(indt)
129  { }
131  unsigned int ngaps;
133  unsigned int nbreaks;
135  unsigned int nmissing;
137  unsigned int nexpected;
139  libtime::TRelativeTime tspan;
141  libtime::TRelativeTime tmissing;
143  libtime::TRelativeTime dt;
144 }; // struct Gapsummary
145 
146 /*----------------------------------------------------------------------*/
147 
149 struct Gapsofstream {
150  typedef std::vector<Gap> Tvecofgap;
151  Gapsofstream(const Gapid& id,
152  const libtime::TAbsoluteTime& earliest,
153  const libtime::TAbsoluteTime& latest)
154  : ID(id), Mearliest(earliest), Mlatest(latest)
155  {
156  this->gap.clear();
157  }
159  Gapsummary summarize() const;
162  private:
163  libtime::TAbsoluteTime Mearliest;
164  libtime::TAbsoluteTime Mlatest;
165 }; // struct Gapsofstream
166 
167 /*----------------------------------------------------------------------*/
168 
170 typedef std::vector<Gapsofstream> Tvecofgaps;
171 
172 /*----------------------------------------------------------------------*/
173 // output operators
174 
176 std::ostream& operator<<(std::ostream& os, const Gapid& id);
177 
179 std::ostream& operator<<(std::ostream& os, const Contiguous& chunk);
180 
182 std::ostream& operator<<(std::ostream& os, const Gap& gap);
183 
184 #endif // TF_STRUCTGAPANALYSIS_H_VERSION (includeguard)
185 
186 /* ----- END OF structgapanalysis.h ----- */
libtime::TRelativeTime dt
std::ostream & operator<<(std::ostream &os, const Gapid &id)
print stream ID
bool operator!=(const Gapid &other) const
libtime::TRelativeTime tspan
time span of analysis
unsigned int ngaps
total number of gaps
Gapsummary(const libtime::TAbsoluteTime &earliest, const libtime::TAbsoluteTime &latest, const libtime::TRelativeTime &indt)
libtime::TRelativeTime dt
sampling interval
std::string Mauxid
Gapsofstream(const Gapid &id, const libtime::TAbsoluteTime &earliest, const libtime::TAbsoluteTime &latest)
Gapsummary summarize() const
provide a summary for this stream
std::string Mchannel
struct to hold gaps of one stream
std::string station() const
std::vector< Gap > Tvecofgap
ID to identify stream.
unsigned int nbreaks
total number of breaks
libtime::TAbsoluteTime first
libtime::TAbsoluteTime first
struct to present a summary
Indicate a contiguous set of data.
std::string ID
libtime::TAbsoluteTime Mlatest
bool operator==(const Gapid &other) const
std::string channel
unsigned int nmissing
number of missing samples
std::string channel() const
Gapid(const Contiguous &c)
std::string auxid() const
struct to hold one gap
libtime::TAbsoluteTime last
std::list< Contiguous > TContiguouslist
A list to store information on all sequences of contiguous data.
libtime::TRelativeTime dt
libtime::TAbsoluteTime Mearliest
std::vector< Gapsofstream > Tvecofgaps
vector to hold all gaps
std::string Mstation
Gapid ID
std::string auxid
unsigned int nmissing() const
unsigned int nexpected
number of expected samples
bool isbreak() const
libtime::TRelativeTime tmissing
time span not covered with samples
std::string station
libtime::TAbsoluteTime last
libtime::TRelativeTime tmissing() const