conv/many suite: convert (m)any seismic data format(s)
completenessbins.cc
Go to the documentation of this file.
1 
37 #define TF_COMPLETENESSBINS_CC_VERSION \
38  "TF_COMPLETENESSBINS_CC V1.0 "
39 
40 #include <tfxx/error.h>
41 #include "completenessbins.h"
42 
44 CompletenessBins::CompletenessBins(const libtime::TAbsoluteTime& earliest,
45  const libtime::TAbsoluteTime& latest,
46  const libtime::TRelativeTime& binsize)
47 {
50  this->Mbinsize=binsize;
51 
52  // initialize beginning of first bin
53  // align to midnight
54  this->Mfirstbin=libtime::TAbsoluteTime(earliest.year(),
55  earliest.month(),
56  earliest.day());
57  // find appropriate first bin
58  while (Mfirstbin < earliest)
59  {
60  Mfirstbin += binsize;
61  }
62 
63  // find number of bins required to span the entire interval
64  Mnbins=1;
65  libtime::TAbsoluteTime current=Mfirstbin+binsize;
66  while (current <= latest)
67  {
68  Mnbins++;
69  current += binsize;
70  }
71 } // CompletenessBins::CompletenessBins
72 
73 /*----------------------------------------------------------------------*/
74 
75 libtime::TAbsoluteTime CompletenessBins::bin(const unsigned int& i) const
76 {
77  TFXX_assert((i>=0) && (i<this->nbins()), "illegal bin index");
78  libtime::TAbsoluteTime retval=this->firstbin();
79  retval += i*this->binsize();
80  return(retval);
81 } // libtime::TAbsoluteTime CompletenessBins::bin(const unsigned int& i) const
82 
83 /*----------------------------------------------------------------------*/
84 
85 libtime::TAbsoluteTime CompletenessBins::nextbin(const unsigned int& i) const
86 {
87  libtime::TAbsoluteTime nextbin=this->bin(i)+this->binsize();
88  return(nextbin);
89 } // libtime::TAbsoluteTime CompletenessBins::nextbin(const unsigned int& i)
90  // const
91 
92 /*----------------------------------------------------------------------*/
93 
94 bool CompletenessBins::isinbin(const libtime::TAbsoluteTime& d,
95  const unsigned int& i) const
96 {
97  libtime::TAbsoluteTime thisbin=this->bin(i);
98  libtime::TAbsoluteTime nextbin=this->nextbin(i);
99  return((d>=thisbin) && (d<nextbin));
100 } // bool CompletenessBins::isinbin(const libtime::TAbsoluteTime& d,
101  // const unsigned int& i) const
102 
103 /*----------------------------------------------------------------------*/
104 
105 unsigned int CompletenessBins::bin(const libtime::TAbsoluteTime& d) const
106 {
107  TFXX_assert((d >= this->earliest()) && (d <= this->latest()),
108  "date is out of range");
109  unsigned int retval=0;
110  while ((retval<Mnbins) && !this->isinbin(d, retval)) { ++retval; }
111  return(retval);
112 } // unsigned int CompletenessBins::bin(const libtime::TAbsoluteTime& d) const
113 
114 /*----------------------------------------------------------------------*/
115 
116 unsigned int
117 CompletenessBins::samplesinbin(const unsigned int& i,
118  const libtime::TRelativeTime dt) const
119 {
120  libtime::TRelativeTime binsize=this->binsize();
121  if (i==0)
122  {
123  binsize=this->nextbin(i)-this->earliest();
124  }
125  else if ((i+1)==this->nbins())
126  {
127  binsize=dt+this->latest()-this->bin(i);
128  }
129  unsigned int nsamples=binsize/dt;
130  nsamples = nsamples > 0 ? nsamples : 1;
131  return(nsamples);
132 } // unsigned int
133  // CompletenessBins::samplesinbin(const unsigned int& i,
134  // const libtime::TRelativeTime dt) const
135 
136 /*----------------------------------------------------------------------*/
137 
138 unsigned int
139 CompletenessBins::samplesinbin(const libtime::TRelativeTime dt) const
140 {
141  libtime::TRelativeTime binsize=this->binsize();
142  unsigned int nsamples=binsize/dt;
143  nsamples = nsamples > 0 ? nsamples : 1;
144  return(nsamples);
145 } // unsigned int
146  // CompletenessBins::samplesinbin(const libtime::TRelativeTime dt) const
147 
148 /* ----- END OF completenessbins.cc ----- */
libtime::TAbsoluteTime firstbin() const
libtime::TAbsoluteTime Mearliest
libtime::TAbsoluteTime earliest() const
unsigned int nbins() const
class to define completenessbins (prototypes)
libtime::TRelativeTime Mbinsize
CompletenessBins(const libtime::TAbsoluteTime &earliest, const libtime::TAbsoluteTime &latest, const libtime::TRelativeTime &binsize)
constructor
libtime::TAbsoluteTime bin(const unsigned int &i) const
beginnig of bin (according to bin raster)
libtime::TAbsoluteTime Mlatest
bool isinbin(const libtime::TAbsoluteTime &d, const unsigned int &i) const
libtime::TAbsoluteTime latest() const
libtime::TAbsoluteTime Mfirstbin
unsigned int samplesinbin(const libtime::TRelativeTime dt) const
number of samples to be expected in a bin
unsigned int Mnbins
libtime::TRelativeTime binsize() const
libtime::TAbsoluteTime nextbin(const unsigned int &i) const
start of bin (will be earliest for fisrt bin)